1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include <precomp.h>
23 #include "navibar.hxx"
24 
25 
26 // NOT FULLY DEFINED SERVICES
27 #include <cosv/tpl/tpltools.hxx>
28 #include "nav_main.hxx"
29 #include "opageenv.hxx"
30 
31 
32 using namespace csi::xml;
33 using namespace csi::html;
34 
35 
36 namespace
37 {
38 
39 //************************      SubRowItem      ***************************//
40 
41 class SubRowItem
42 {
43   public:
44                         SubRowItem(
45                             const char *        i_sText,
46                             const char *        i_sLink,
47                             bool                i_bActive,
48                             bool                i_bFirstOfRow = false );
49                         ~SubRowItem();
50 
51     void                Write2(
52                             Element &           o_rOut ) const;
53   private:
54     String              sText;
55     String              sLink;
56     bool                bIsActive;
57     bool                bFirstOfRow;
58 };
59 
SubRowItem(const char * i_sText,const char * i_sLink,bool i_bActive,bool i_bFirstOfRow)60 SubRowItem::SubRowItem( const char *        i_sText,
61                         const char *        i_sLink,
62                         bool                i_bActive,
63                         bool                i_bFirstOfRow )
64     :   sText(i_sText),
65         sLink(i_sLink),
66         bIsActive(i_bActive),
67         bFirstOfRow(i_bFirstOfRow)
68 {
69     csv_assert( NOT csv::no_str(i_sLink) );
70 }
71 
~SubRowItem()72 SubRowItem::~SubRowItem()
73 {
74 }
75 
76 void
Write2(Element & o_rOut) const77 SubRowItem::Write2( Element & o_rOut ) const
78 {
79     o_rOut << new Sbr;
80     if ( NOT bFirstOfRow )
81         o_rOut << new XmlCode( "|&nbsp;" );
82     else
83         o_rOut << new XmlCode( "&nbsp;" );
84 
85     if ( bIsActive )
86     {
87         o_rOut
88             >> *new Link( sLink.c_str() )
89                 >> *new AnElement( "font" )
90                     << new AnAttribute("size","-2")
91                     >> *new Bold
92                         << sText.c_str();
93     }
94     else
95     {
96         o_rOut
97             >> *new AnElement( "font" )
98                 << new AnAttribute("size","-2")
99                 << sText.c_str();
100     }
101 }
102 
103 
104 
105 //************************      SubRow      ***************************//
106 
107 class SubRow
108 {
109   public:
110                         SubRow(
111                             const char *        i_sTitle );
112                         ~SubRow();
113 
114     void                AddItem(
115                             const char *        i_sText,
116                             const char *        i_sLink,
117                             bool                i_bActive );
118     void                Write2(
119                             Table &             o_rOut ) const;
120   private:
121     typedef std::vector< DYN SubRowItem * >   List_Items;
122 
123     List_Items          aItemList;
124     String              sTitle;
125 };
126 
SubRow(const char * i_sTitle)127 SubRow::SubRow( const char * i_sTitle )
128 //  :   // aItemList,
129         // sTitle
130 {
131     StreamStr sUp(i_sTitle,0);
132     sUp.to_upper();
133     sTitle = sUp.c_str();
134 }
135 
~SubRow()136 SubRow::~SubRow()
137 {
138     for ( List_Items::iterator it = aItemList.begin();
139           it != aItemList.end();
140           ++it )
141     {
142      	delete (*it);
143     }
144 }
145 
146 inline void
AddItem(const char * i_sText,const char * i_sLink,bool i_bActive)147 SubRow::AddItem( const char *        i_sText,
148                  const char *        i_sLink,
149                  bool                i_bActive )
150 {
151     aItemList.push_back( new SubRowItem(i_sText, i_sLink, i_bActive, aItemList.empty()) );
152 }
153 
154 void
Write2(Table & o_rOut) const155 SubRow::Write2( Table & o_rOut ) const
156 {
157     TableRow * pRow = new TableRow;
158     o_rOut << pRow;
159 
160     if (sTitle.length() > 0)
161     {
162         Element & rCell1 = pRow->AddCell();
163         rCell1
164             << new WidthAttr("20%")
165             >> *new AnElement( "font" )
166                     << new AnAttribute("size","-2")
167                        << sTitle
168                        << ":";
169     }
170 
171     Element & rCell2 = pRow->AddCell();
172     for ( List_Items::const_iterator it = aItemList.begin();
173           it != aItemList.end();
174           ++it )
175     {
176      	(*it)->Write2( rCell2 );
177     }
178 }
179 
180 
181 }   // anonymous namespace
182 
183 
184 
185 //*************************      CheshireCat     ***********************//
186 
187 
188 typedef std::vector< DYN SubRow * >   List_SubRows;
189 
190 struct NavigationBar::CheshireCat
191 {
192     MainRow             aMainRow;
193     List_SubRows        aSubRows;
194     const OuputPage_Environment *
195                         pEnv;
196 
197 
198                         CheshireCat(
199                             const OuputPage_Environment &
200                                                 i_rEnv );
201                         ~CheshireCat();
202 };
203 
204 NavigationBar::
CheshireCat(const OuputPage_Environment & i_rEnv)205 CheshireCat::CheshireCat( const OuputPage_Environment & i_rEnv )
206     :   aMainRow( i_rEnv ),
207         pEnv( & i_rEnv )
208 {
209 }
210 
211 NavigationBar::
~CheshireCat()212 CheshireCat::~CheshireCat()
213 {
214     csv::erase_container_of_heap_ptrs( aSubRows );
215 }
216 
217 
218 //************************       NavigationBar       *******************//
219 
NavigationBar(const OuputPage_Environment & i_rEnv,E_GlobalLocation i_eLocation)220 NavigationBar::NavigationBar( const OuputPage_Environment & i_rEnv,
221                               E_GlobalLocation              i_eLocation )
222     :   pi( new CheshireCat(i_rEnv) )
223 {
224     switch (i_eLocation)
225     {
226      	case LOC_Overview:  pi->aMainRow.SetupItems_Overview();  break;
227      	case LOC_AllDefs:   pi->aMainRow.SetupItems_AllDefs();   break;
228         case LOC_Index:     pi->aMainRow.SetupItems_Index();     break;
229         case LOC_Help:      pi->aMainRow.SetupItems_Help();      break;
230         default:
231                             csv_assert(false);
232     }
233 }
234 
NavigationBar(const OuputPage_Environment & i_rEnv,const ary::cpp::CodeEntity & i_rCe)235 NavigationBar::NavigationBar( const OuputPage_Environment & i_rEnv,
236                               const ary::cpp::CodeEntity &  i_rCe  )
237     :   pi( new CheshireCat(i_rEnv) )
238 {
239     pi->aMainRow.SetupItems_Ce( i_rCe );
240 }
241 
NavigationBar(const OuputPage_Environment & i_rEnv,E_CeGatheringType i_eCeGatheringType)242 NavigationBar::NavigationBar( const OuputPage_Environment & i_rEnv,
243                               E_CeGatheringType             i_eCeGatheringType )
244     :   pi( new CheshireCat(i_rEnv) )
245 {
246     switch (i_eCeGatheringType)
247     {
248  	    case CEGT_operations:   pi->aMainRow.SetupItems_FunctionGroup();  break;
249         case CEGT_data:         pi->aMainRow.SetupItems_DataGroup();      break;
250         default:
251                                 csv_assert(false);
252     }
253 }
254 
~NavigationBar()255 NavigationBar::~NavigationBar()
256 {
257     csv::erase_container_of_heap_ptrs( pi->aSubRows );
258 }
259 
260 void
MakeSubRow(const char * i_sTitle)261 NavigationBar::MakeSubRow( const char * i_sTitle )
262 {
263     pi->aSubRows.push_back( new SubRow(i_sTitle) );
264 }
265 
266 void
AddItem(const char * i_sName,const char * i_sLink,bool i_bValid)267 NavigationBar::AddItem( const char *		i_sName,
268                         const char *        i_sLink,
269                         bool                i_bValid )
270 {
271     csv_assert( pi->aSubRows.size() > 0 );
272     StreamStr sName(i_sName, 0);
273     sName.to_upper();
274 
275     StreamLock aSum(100);
276     pi->aSubRows.back()->AddItem( sName.c_str(),
277                                   aSum() << "#" << i_sLink << c_str,
278                                   i_bValid );
279 }
280 
281 void
Write(Element & o_rOut,bool i_bWithSubRows) const282 NavigationBar::Write( Element &  o_rOut,
283                       bool       i_bWithSubRows ) const
284 {
285     pi->aMainRow.Write2( o_rOut );
286 
287     const_cast< NavigationBar* >(this)->pSubRowsTable = new Table;
288     o_rOut << pSubRowsTable;
289     *pSubRowsTable
290         << new AnAttribute( "class", "navisub" )
291         << new AnAttribute( "cellpadding", "0" )
292         << new AnAttribute( "cellspacing", "3" );
293 
294     if (i_bWithSubRows)
295     {
296         Write_SubRows();
297     }
298 }
299 
300 void
Write_SubRows() const301 NavigationBar::Write_SubRows() const
302 {
303     for ( List_SubRows::const_iterator it = pi->aSubRows.begin();
304           it != pi->aSubRows.end();
305           ++it )
306     {
307      	(*it)->Write2( *pSubRowsTable );
308     }
309 }
310