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