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