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