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 "nav_main.hxx"
24
25
26 // NOT FULLY DEFINED SERVICES
27 #include <cosv/tpl/tpltools.hxx>
28 #include <ary/cpp/c_ce.hxx>
29 #include <ary/cpp/c_gate.hxx>
30 #include <ary/cpp/c_namesp.hxx>
31 #include <ary/cpp/c_class.hxx>
32 #include <ary/loc/loc_file.hxx>
33 #include <udm/html/htmlitem.hxx>
34 #include "hdimpl.hxx"
35 #include "opageenv.hxx"
36 #include "strconst.hxx"
37
38
39 using namespace ::csi::html;
40 using namespace ::csi::xml;
41
42
43 const String sOverview("Overview");
44 const String sNamespace("Namespace");
45 const String sClass("Class");
46 const String sTree("Tree");
47 const String sProject("Project");
48 const String sFile("File");
49 const String sIndex("Index");
50 const String sHelp("Help");
51
52
53
54 //******************** MainItem and derived ones ***************//
55 class MainItem
56 {
57 public:
~MainItem()58 virtual ~MainItem() {}
59 void Write2(
60 TableRow & o_rOut );
61 private:
62 virtual void do_Write2(
63 TableRow & o_rOut ) = 0;
64 };
65
66 inline void
Write2(TableRow & o_rOut)67 MainItem::Write2( TableRow & o_rOut )
68 { do_Write2(o_rOut); }
69
70
71 namespace
72 {
73
74 class MainRowItem : public MainItem
75 {
76 public:
77 MainRowItem(
78 const String & i_sText,
79 const char * i_sLink,
80 const char * i_sTip );
81 ~MainRowItem();
82 private:
83 enum E_Style { eSelf, eNo, eStd };
84
85 virtual void do_Write2(
86 TableRow & o_rOut );
87 String sText;
88 String sLink;
89 String sTip;
90 };
91
MainRowItem(const String & i_sText,const char * i_sLink,const char * i_sTip)92 MainRowItem::MainRowItem( const String & i_sText,
93 const char * i_sLink,
94 const char * i_sTip )
95 : sText(i_sText),
96 sLink(i_sLink),
97 sTip(i_sTip)
98 {
99 }
100
~MainRowItem()101 MainRowItem::~MainRowItem()
102 {
103 }
104
105 void
do_Write2(TableRow & o_rOut)106 MainRowItem::do_Write2( TableRow & o_rOut )
107 {
108 TableCell & rCell = o_rOut.AddCell();
109
110 rCell
111 << new ClassAttr( "navimain" )
112 << new XmlCode(" ")
113 >> *new Link(sLink.c_str())
114 << sText.c_str();
115 rCell
116 << new XmlCode(" ");
117 }
118
119
120 class SelectedItem : public MainItem
121 {
122 public:
SelectedItem(const String & i_sText)123 SelectedItem(
124 const String & i_sText )
125 : sText(i_sText) {}
126 private:
127 virtual void do_Write2(
128 TableRow & o_rOut );
129 String sText;
130 };
131
132 void
do_Write2(TableRow & o_rOut)133 SelectedItem::do_Write2( TableRow & o_rOut )
134 {
135 TableCell & rCell = o_rOut.AddCell();
136
137 rCell
138 << new ClassAttr( "navimainself" )
139 << new XmlCode(" ")
140 << sText.c_str()
141 << new XmlCode(" ");
142 }
143
144 class UnavailableItem : public MainItem
145 {
146 public:
UnavailableItem(const String & i_sText)147 UnavailableItem(
148 const String & i_sText )
149 : sText(i_sText) {}
150 private:
151 virtual void do_Write2(
152 TableRow & o_rOut );
153 String sText;
154 };
155
156 void
do_Write2(TableRow & o_rOut)157 UnavailableItem::do_Write2( TableRow & o_rOut )
158 {
159 TableCell & rCell = o_rOut.AddCell();
160
161 rCell
162 << new ClassAttr( "navimainnone" )
163 << new XmlCode(" ")
164 << sText.c_str()
165 << new XmlCode(" ");
166 }
167
168 } // anonymous namespace
169
170 //************************ MainRow ***************************//
171
MainRow(const OuputPage_Environment & i_rEnv)172 MainRow::MainRow( const OuputPage_Environment & i_rEnv )
173 : // aItems,
174 pEnv(&i_rEnv)
175 {
176 }
177
~MainRow()178 MainRow::~MainRow()
179 {
180 csv::erase_container_of_heap_ptrs(aItems);
181 }
182
183 void
SetupItems_Overview()184 MainRow::SetupItems_Overview()
185 {
186 Create_ItemList_Global( eSelf, eStd, eStd );
187 }
188
189 void
SetupItems_AllDefs()190 MainRow::SetupItems_AllDefs()
191 {
192 Create_ItemList_Global( eStd, eStd, eStd );
193 }
194
195 void
SetupItems_Index()196 MainRow::SetupItems_Index()
197 {
198 Create_ItemList_Global( eStd, eSelf, eStd );
199 }
200
201 void
SetupItems_Help()202 MainRow::SetupItems_Help()
203 {
204 Create_ItemList_Global( eStd, eStd, eSelf );
205 }
206
207 void
SetupItems_Ce(const ary::cpp::CodeEntity & i_rCe)208 MainRow::SetupItems_Ce( const ary::cpp::CodeEntity & i_rCe )
209 {
210 csv_assert( pEnv->CurNamespace() != 0 );
211 bool bIsNamespace = i_rCe.Id() == pEnv->CurNamespace()->Id();
212 bool bHasClass = pEnv->CurClass() != 0;
213 bool bIsClass = dynamic_cast< const ary::cpp::Class * >(&i_rCe) != 0;
214
215 Create_ItemList_InDirTree_Cpp(
216 ( bIsNamespace ? eSelf : eStd ),
217 ( bIsClass ? eSelf : bHasClass ? eStd : eNo ),
218 eNo, 0 );
219 }
220
221 void
SetupItems_FunctionGroup()222 MainRow::SetupItems_FunctionGroup()
223 {
224 Create_ItemList_InDirTree_Cpp(
225 eStd,
226 (pEnv->CurClass() != 0 ? eStd : eNo),
227 eNo, 0 );
228 }
229
230 void
SetupItems_DataGroup()231 MainRow::SetupItems_DataGroup()
232 {
233 SetupItems_FunctionGroup();
234 }
235
236 void
Write2(csi::xml::Element & o_rOut) const237 MainRow::Write2( csi::xml::Element & o_rOut ) const
238 {
239 Table * pTable = new Table;
240 o_rOut
241 >> *pTable
242 << new AnAttribute( "class", "navimain" )
243 << new AnAttribute( "border", "0" )
244 << new AnAttribute( "cellpadding", "1" )
245 << new AnAttribute( "cellspacing", "0" );
246 TableRow & rRow = pTable->AddRow();
247 rRow
248 << new AnAttribute( "align", "center" )
249 << new AnAttribute( "valign", "top" );
250 for ( ItemList::const_iterator it = aItems.begin();
251 it != aItems.end();
252 ++it )
253 {
254 (*it)->Write2( rRow );
255 }
256 }
257
258 void
Create_ItemList_Global(E_Style i_eOverview,E_Style i_eIndex,E_Style i_eHelp)259 MainRow::Create_ItemList_Global( E_Style i_eOverview,
260 E_Style i_eIndex,
261 E_Style i_eHelp )
262 {
263 if ( i_eOverview == eStd )
264 {
265 String sLinkOverview = ( i_eIndex == eSelf
266 ? dshelp::PathPerLevelsUp(
267 1,
268 C_sHFN_Overview )
269 : C_sHFN_Overview );
270 Add_Item( i_eOverview, sOverview, sLinkOverview.c_str(), "" );
271 }
272 else
273 {
274 Add_Item( i_eOverview, sOverview, "", "" );
275 }
276
277 if ( i_eIndex == eSelf )
278 Add_Item( eStd, sNamespace, "../names/index.html", "" );
279 else
280 Add_Item( eStd, sNamespace, "names/index.html", "" );
281
282 Add_Item( eNo, sClass, "", "" );
283
284 if ( i_eIndex == eStd )
285 {
286 Add_Item( i_eIndex, sIndex, C_sPath_Index, "" );
287 }
288 else
289 {
290 Add_Item( i_eIndex, sIndex, "", "" );
291 }
292
293 if ( i_eHelp == eStd )
294 {
295 String sLinkHelp = ( i_eIndex == eSelf
296 ? PathPerLevelsUp(1,C_sHFN_Help)
297 : C_sHFN_Help );
298 Add_Item( i_eHelp, sHelp, sLinkHelp.c_str(), "" );
299 }
300 else
301 {
302 Add_Item( i_eHelp, sHelp, "", "" );
303 }
304 }
305
306 void
Create_ItemList_InDirTree_Cpp(E_Style i_eNsp,E_Style i_eClass,E_Style,const char *)307 MainRow::Create_ItemList_InDirTree_Cpp( E_Style i_eNsp,
308 E_Style i_eClass,
309 E_Style ,
310 const char * )
311 {
312 String
313 sLinkOverview = PathPerRoot(*pEnv, C_sHFN_Overview);
314 Add_Item( eStd, sOverview, sLinkOverview.c_str(), "" );
315
316 if (i_eNsp == eStd)
317 {
318 String sLinkNamespace = PathPerNamespace(*pEnv, "index.html");
319 Add_Item( i_eNsp, sNamespace, sLinkNamespace.c_str(), "" );
320 }
321 else
322 {
323 Add_Item( i_eNsp, sNamespace, "", "" );
324 }
325
326 if (i_eClass == eStd)
327 {
328 csv_assert( pEnv->CurClass() != 0 );
329
330 StreamLock sLinkClass(300);
331 sLinkClass() << PathPerNamespace(*pEnv, "c-")
332 << pEnv->CurClass()->LocalName()
333 << ".html";
334 StreamLock sTipClass(300);
335 sTipClass() << "Class "
336 << pEnv->CurClass()->LocalName();
337 Add_Item( i_eClass, sClass, sLinkClass().c_str(), sTipClass().c_str() );
338 }
339 else
340 {
341 Add_Item( i_eClass, sClass, "", "" );
342 }
343
344
345 Add_Item( eStd, sIndex, PathPerRoot(*pEnv, C_sPath_Index), "" );
346 String
347 sLinkHelp = PathPerRoot(*pEnv, "help.html");
348 Add_Item( eStd, sHelp, sLinkHelp.c_str(), "" );
349 }
350
351 void
Add_Item(E_Style i_eStyle,const String & i_sText,const char * i_sLink,const char * i_sTip)352 MainRow::Add_Item( E_Style i_eStyle,
353 const String & i_sText,
354 const char * i_sLink,
355 const char * i_sTip )
356 {
357 switch (i_eStyle)
358 {
359 case eStd: aItems.push_back( new MainRowItem(i_sText, i_sLink, i_sTip) );
360 break;
361 case eNo: aItems.push_back( new UnavailableItem(i_sText) );
362 break;
363 case eSelf: aItems.push_back( new SelectedItem(i_sText) );
364 break;
365 default:
366 csv_assert(false);
367 }
368 }
369
370
371
372