xref: /AOO41X/main/autodoc/source/display/html/navibar.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include <precomp.h>
29*cdf0e10cSrcweir #include "navibar.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir // NOT FULLY DEFINED SERVICES
33*cdf0e10cSrcweir #include <cosv/tpl/tpltools.hxx>
34*cdf0e10cSrcweir #include "nav_main.hxx"
35*cdf0e10cSrcweir #include "opageenv.hxx"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir using namespace csi::xml;
39*cdf0e10cSrcweir using namespace csi::html;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir namespace
43*cdf0e10cSrcweir {
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir //************************      SubRowItem      ***************************//
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir class SubRowItem
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir   public:
50*cdf0e10cSrcweir                         SubRowItem(
51*cdf0e10cSrcweir                             const char *        i_sText,
52*cdf0e10cSrcweir                             const char *        i_sLink,
53*cdf0e10cSrcweir                             bool                i_bActive,
54*cdf0e10cSrcweir                             bool                i_bFirstOfRow = false );
55*cdf0e10cSrcweir                         ~SubRowItem();
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     void                Write2(
58*cdf0e10cSrcweir                             Element &           o_rOut ) const;
59*cdf0e10cSrcweir   private:
60*cdf0e10cSrcweir     String              sText;
61*cdf0e10cSrcweir     String              sLink;
62*cdf0e10cSrcweir     bool                bIsActive;
63*cdf0e10cSrcweir     bool                bFirstOfRow;
64*cdf0e10cSrcweir };
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir SubRowItem::SubRowItem( const char *        i_sText,
67*cdf0e10cSrcweir                         const char *        i_sLink,
68*cdf0e10cSrcweir                         bool                i_bActive,
69*cdf0e10cSrcweir                         bool                i_bFirstOfRow )
70*cdf0e10cSrcweir     :   sText(i_sText),
71*cdf0e10cSrcweir         sLink(i_sLink),
72*cdf0e10cSrcweir         bIsActive(i_bActive),
73*cdf0e10cSrcweir         bFirstOfRow(i_bFirstOfRow)
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir     csv_assert( NOT csv::no_str(i_sLink) );
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir SubRowItem::~SubRowItem()
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir void
83*cdf0e10cSrcweir SubRowItem::Write2( Element & o_rOut ) const
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir     o_rOut << new Sbr;
86*cdf0e10cSrcweir     if ( NOT bFirstOfRow )
87*cdf0e10cSrcweir         o_rOut << new XmlCode( "|&nbsp;" );
88*cdf0e10cSrcweir     else
89*cdf0e10cSrcweir         o_rOut << new XmlCode( "&nbsp;" );
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     if ( bIsActive )
92*cdf0e10cSrcweir     {
93*cdf0e10cSrcweir         o_rOut
94*cdf0e10cSrcweir             >> *new Link( sLink.c_str() )
95*cdf0e10cSrcweir                 >> *new AnElement( "font" )
96*cdf0e10cSrcweir                     << new AnAttribute("size","-2")
97*cdf0e10cSrcweir                     >> *new Bold
98*cdf0e10cSrcweir                         << sText.c_str();
99*cdf0e10cSrcweir     }
100*cdf0e10cSrcweir     else
101*cdf0e10cSrcweir     {
102*cdf0e10cSrcweir         o_rOut
103*cdf0e10cSrcweir             >> *new AnElement( "font" )
104*cdf0e10cSrcweir                 << new AnAttribute("size","-2")
105*cdf0e10cSrcweir                 << sText.c_str();
106*cdf0e10cSrcweir     }
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir //************************      SubRow      ***************************//
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir class SubRow
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir   public:
116*cdf0e10cSrcweir                         SubRow(
117*cdf0e10cSrcweir                             const char *        i_sTitle );
118*cdf0e10cSrcweir                         ~SubRow();
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     void                AddItem(
121*cdf0e10cSrcweir                             const char *        i_sText,
122*cdf0e10cSrcweir                             const char *        i_sLink,
123*cdf0e10cSrcweir                             bool                i_bActive );
124*cdf0e10cSrcweir     void                Write2(
125*cdf0e10cSrcweir                             Table &             o_rOut ) const;
126*cdf0e10cSrcweir   private:
127*cdf0e10cSrcweir     typedef std::vector< DYN SubRowItem * >   List_Items;
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir     List_Items          aItemList;
130*cdf0e10cSrcweir     String              sTitle;
131*cdf0e10cSrcweir };
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir SubRow::SubRow( const char * i_sTitle )
134*cdf0e10cSrcweir //  :   // aItemList,
135*cdf0e10cSrcweir         // sTitle
136*cdf0e10cSrcweir {
137*cdf0e10cSrcweir     StreamStr sUp(i_sTitle,0);
138*cdf0e10cSrcweir     sUp.to_upper();
139*cdf0e10cSrcweir     sTitle = sUp.c_str();
140*cdf0e10cSrcweir }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir SubRow::~SubRow()
143*cdf0e10cSrcweir {
144*cdf0e10cSrcweir     for ( List_Items::iterator it = aItemList.begin();
145*cdf0e10cSrcweir           it != aItemList.end();
146*cdf0e10cSrcweir           ++it )
147*cdf0e10cSrcweir     {
148*cdf0e10cSrcweir      	delete (*it);
149*cdf0e10cSrcweir     }
150*cdf0e10cSrcweir }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir inline void
153*cdf0e10cSrcweir SubRow::AddItem( const char *        i_sText,
154*cdf0e10cSrcweir                  const char *        i_sLink,
155*cdf0e10cSrcweir                  bool                i_bActive )
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir     aItemList.push_back( new SubRowItem(i_sText, i_sLink, i_bActive, aItemList.empty()) );
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir void
161*cdf0e10cSrcweir SubRow::Write2( Table & o_rOut ) const
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir     TableRow * pRow = new TableRow;
164*cdf0e10cSrcweir     o_rOut << pRow;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir     if (sTitle.length() > 0)
167*cdf0e10cSrcweir     {
168*cdf0e10cSrcweir         Element & rCell1 = pRow->AddCell();
169*cdf0e10cSrcweir         rCell1
170*cdf0e10cSrcweir             << new WidthAttr("20%")
171*cdf0e10cSrcweir             >> *new AnElement( "font" )
172*cdf0e10cSrcweir                     << new AnAttribute("size","-2")
173*cdf0e10cSrcweir                        << sTitle
174*cdf0e10cSrcweir                        << ":";
175*cdf0e10cSrcweir     }
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     Element & rCell2 = pRow->AddCell();
178*cdf0e10cSrcweir     for ( List_Items::const_iterator it = aItemList.begin();
179*cdf0e10cSrcweir           it != aItemList.end();
180*cdf0e10cSrcweir           ++it )
181*cdf0e10cSrcweir     {
182*cdf0e10cSrcweir      	(*it)->Write2( rCell2 );
183*cdf0e10cSrcweir     }
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir }   // anonymous namespace
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir //*************************      CheshireCat     ***********************//
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir typedef std::vector< DYN SubRow * >   List_SubRows;
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir struct NavigationBar::CheshireCat
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir     MainRow             aMainRow;
199*cdf0e10cSrcweir     List_SubRows        aSubRows;
200*cdf0e10cSrcweir     const OuputPage_Environment *
201*cdf0e10cSrcweir                         pEnv;
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir                         CheshireCat(
205*cdf0e10cSrcweir                             const OuputPage_Environment &
206*cdf0e10cSrcweir                                                 i_rEnv );
207*cdf0e10cSrcweir                         ~CheshireCat();
208*cdf0e10cSrcweir };
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir NavigationBar::
211*cdf0e10cSrcweir CheshireCat::CheshireCat( const OuputPage_Environment & i_rEnv )
212*cdf0e10cSrcweir     :   aMainRow( i_rEnv ),
213*cdf0e10cSrcweir         pEnv( & i_rEnv )
214*cdf0e10cSrcweir {
215*cdf0e10cSrcweir }
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir NavigationBar::
218*cdf0e10cSrcweir CheshireCat::~CheshireCat()
219*cdf0e10cSrcweir {
220*cdf0e10cSrcweir     csv::erase_container_of_heap_ptrs( aSubRows );
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir //************************       NavigationBar       *******************//
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir NavigationBar::NavigationBar( const OuputPage_Environment & i_rEnv,
227*cdf0e10cSrcweir                               E_GlobalLocation              i_eLocation )
228*cdf0e10cSrcweir     :   pi( new CheshireCat(i_rEnv) )
229*cdf0e10cSrcweir {
230*cdf0e10cSrcweir     switch (i_eLocation)
231*cdf0e10cSrcweir     {
232*cdf0e10cSrcweir      	case LOC_Overview:  pi->aMainRow.SetupItems_Overview();  break;
233*cdf0e10cSrcweir      	case LOC_AllDefs:   pi->aMainRow.SetupItems_AllDefs();   break;
234*cdf0e10cSrcweir         case LOC_Index:     pi->aMainRow.SetupItems_Index();     break;
235*cdf0e10cSrcweir         case LOC_Help:      pi->aMainRow.SetupItems_Help();      break;
236*cdf0e10cSrcweir         default:
237*cdf0e10cSrcweir                             csv_assert(false);
238*cdf0e10cSrcweir     }
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir NavigationBar::NavigationBar( const OuputPage_Environment & i_rEnv,
242*cdf0e10cSrcweir                               const ary::cpp::CodeEntity &  i_rCe  )
243*cdf0e10cSrcweir     :   pi( new CheshireCat(i_rEnv) )
244*cdf0e10cSrcweir {
245*cdf0e10cSrcweir     pi->aMainRow.SetupItems_Ce( i_rCe );
246*cdf0e10cSrcweir }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir NavigationBar::NavigationBar( const OuputPage_Environment & i_rEnv,
249*cdf0e10cSrcweir                               E_CeGatheringType             i_eCeGatheringType )
250*cdf0e10cSrcweir     :   pi( new CheshireCat(i_rEnv) )
251*cdf0e10cSrcweir {
252*cdf0e10cSrcweir     switch (i_eCeGatheringType)
253*cdf0e10cSrcweir     {
254*cdf0e10cSrcweir  	    case CEGT_operations:   pi->aMainRow.SetupItems_FunctionGroup();  break;
255*cdf0e10cSrcweir         case CEGT_data:         pi->aMainRow.SetupItems_DataGroup();      break;
256*cdf0e10cSrcweir         default:
257*cdf0e10cSrcweir                                 csv_assert(false);
258*cdf0e10cSrcweir     }
259*cdf0e10cSrcweir }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir NavigationBar::~NavigationBar()
262*cdf0e10cSrcweir {
263*cdf0e10cSrcweir     csv::erase_container_of_heap_ptrs( pi->aSubRows );
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir void
267*cdf0e10cSrcweir NavigationBar::MakeSubRow( const char * i_sTitle )
268*cdf0e10cSrcweir {
269*cdf0e10cSrcweir     pi->aSubRows.push_back( new SubRow(i_sTitle) );
270*cdf0e10cSrcweir }
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir void
273*cdf0e10cSrcweir NavigationBar::AddItem( const char *		i_sName,
274*cdf0e10cSrcweir                         const char *        i_sLink,
275*cdf0e10cSrcweir                         bool                i_bValid )
276*cdf0e10cSrcweir {
277*cdf0e10cSrcweir     csv_assert( pi->aSubRows.size() > 0 );
278*cdf0e10cSrcweir     StreamStr sName(i_sName, 0);
279*cdf0e10cSrcweir     sName.to_upper();
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir     StreamLock aSum(100);
282*cdf0e10cSrcweir     pi->aSubRows.back()->AddItem( sName.c_str(),
283*cdf0e10cSrcweir                                   aSum() << "#" << i_sLink << c_str,
284*cdf0e10cSrcweir                                   i_bValid );
285*cdf0e10cSrcweir }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir void
288*cdf0e10cSrcweir NavigationBar::Write( Element &  o_rOut,
289*cdf0e10cSrcweir                       bool       i_bWithSubRows ) const
290*cdf0e10cSrcweir {
291*cdf0e10cSrcweir     pi->aMainRow.Write2( o_rOut );
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir     const_cast< NavigationBar* >(this)->pSubRowsTable = new Table;
294*cdf0e10cSrcweir     o_rOut << pSubRowsTable;
295*cdf0e10cSrcweir     *pSubRowsTable
296*cdf0e10cSrcweir         << new AnAttribute( "class", "navisub" )
297*cdf0e10cSrcweir         << new AnAttribute( "cellpadding", "0" )
298*cdf0e10cSrcweir         << new AnAttribute( "cellspacing", "3" );
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir     if (i_bWithSubRows)
301*cdf0e10cSrcweir     {
302*cdf0e10cSrcweir         Write_SubRows();
303*cdf0e10cSrcweir     }
304*cdf0e10cSrcweir }
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir void
307*cdf0e10cSrcweir NavigationBar::Write_SubRows() const
308*cdf0e10cSrcweir {
309*cdf0e10cSrcweir     for ( List_SubRows::const_iterator it = pi->aSubRows.begin();
310*cdf0e10cSrcweir           it != pi->aSubRows.end();
311*cdf0e10cSrcweir           ++it )
312*cdf0e10cSrcweir     {
313*cdf0e10cSrcweir      	(*it)->Write2( *pSubRowsTable );
314*cdf0e10cSrcweir     }
315*cdf0e10cSrcweir }
316