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