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 "pm_index.hxx" 30 31 32 // NOT FULLY DEFINED SERVICES 33 #include <ary/cpp/c_gate.hxx> 34 #include <ary/cpp/c_class.hxx> 35 #include <ary/cpp/c_define.hxx> 36 #include <ary/cpp/c_enum.hxx> 37 #include <ary/cpp/c_enuval.hxx> 38 #include <ary/cpp/c_funct.hxx> 39 #include <ary/cpp/c_macro.hxx> 40 #include <ary/cpp/c_namesp.hxx> 41 #include <ary/cpp/c_tydef.hxx> 42 #include <ary/cpp/c_vari.hxx> 43 #include <ary/cpp/cp_ce.hxx> 44 #include "aryattrs.hxx" 45 #include "hd_chlst.hxx" 46 #include "hd_docu.hxx" 47 #include "html_kit.hxx" 48 #include "navibar.hxx" 49 #include "opageenv.hxx" 50 #include "pagemake.hxx" 51 #include "strconst.hxx" 52 53 using namespace csi; 54 using ary::GlobalId; 55 56 57 58 59 namespace 60 { 61 62 inline const char * 63 F_CK_Text( ary::cpp::E_ClassKey i_eCK ) 64 { 65 switch (i_eCK) 66 { 67 case ary::cpp::CK_class: return "class"; 68 case ary::cpp::CK_struct: return "struct"; 69 case ary::cpp::CK_union: return "union"; 70 } // end switch 71 return ""; 72 } 73 74 template <class CE> 75 inline const char * 76 F_OwnerType( const CE & i_rData, const ary::cpp::Gate & i_rGate ) 77 { 78 if ( i_rData.Protection() == ary::cpp::PROTECT_global ) 79 return "namespace "; 80 81 const ary::cpp::Class * 82 pClass = dynamic_cast< const ary::cpp::Class* >( 83 i_rGate.Ces().Search_Ce(i_rData.Owner()) ); 84 if (pClass != 0) 85 return F_CK_Text(pClass->ClassKey()); 86 return ""; 87 } 88 89 } // anonymous namespace 90 91 PageMaker_Index::PageMaker_Index( PageDisplay & io_rPage, 92 char i_c ) 93 : SpecializedPageMaker(io_rPage), 94 pNavi(0), 95 c(i_c), 96 pCurIndex(0) 97 { 98 } 99 100 PageMaker_Index::~PageMaker_Index() 101 { 102 } 103 104 void 105 PageMaker_Index::MakePage() 106 { 107 pNavi = new NavigationBar( Env(), NavigationBar::LOC_Index ); 108 109 Write_NavBar(); 110 Write_TopArea(); 111 Write_CompleteAlphabeticalList(); 112 } 113 114 void 115 PageMaker_Index::do_Process( const ary::cpp::Namespace & i_rData ) 116 { 117 Write_CeIndexEntry( i_rData, "namespace", "namespace" ); 118 } 119 120 void 121 PageMaker_Index::do_Process( const ary::cpp::Class & i_rData ) 122 { 123 // KORR_FUTURE 124 // Really throw out all anonymous classes from index? 125 126 if ( strncmp(i_rData.LocalName().c_str()+1,"_Anonymous",10) == 0 ) 127 return; 128 129 Write_CeIndexEntry( i_rData, 130 F_CK_Text(i_rData.ClassKey()), 131 F_OwnerType(i_rData, Env().Gate()) ); 132 } 133 134 void 135 PageMaker_Index::do_Process( const ary::cpp::Enum & i_rData ) 136 { 137 Write_CeIndexEntry( i_rData, "enum", F_OwnerType(i_rData, Env().Gate()) ); 138 } 139 140 void 141 PageMaker_Index::do_Process( const ary::cpp::Typedef & i_rData ) 142 { 143 Write_CeIndexEntry( i_rData, "typedef", F_OwnerType(i_rData, Env().Gate()) ); 144 } 145 146 void 147 PageMaker_Index::do_Process( const ary::cpp::Function & i_rData ) 148 { 149 Write_CeIndexEntry( i_rData, "function", F_OwnerType(i_rData, Env().Gate()) ); 150 } 151 152 void 153 PageMaker_Index::do_Process( const ary::cpp::Variable & i_rData ) 154 { 155 Write_CeIndexEntry( i_rData, "variable", F_OwnerType(i_rData, Env().Gate()) ); 156 } 157 158 void 159 PageMaker_Index::do_Process( const ary::cpp::EnumValue & i_rData ) 160 { 161 Write_CeIndexEntry( i_rData, "enum value", "" ); 162 } 163 164 void 165 PageMaker_Index::do_Process( const ary::cpp::Define & i_rData ) 166 { 167 String sFileName; 168 169 pCurIndex->AddEntry(); 170 pCurIndex->Term() 171 >> *new html::Link( Link2CppDefinition(Env(), i_rData) ) 172 >> *new html::Bold 173 << i_rData.LocalName(); 174 pCurIndex->Term() 175 << " - define"; 176 pCurIndex->Def() << " "; 177 } 178 179 void 180 PageMaker_Index::do_Process( const ary::cpp::Macro & i_rData ) 181 { 182 String sFileName; 183 184 pCurIndex->AddEntry(); 185 pCurIndex->Term() 186 >> *new html::Link( Link2CppDefinition(Env(), i_rData) ) 187 >> *new html::Bold 188 << i_rData.LocalName(); 189 pCurIndex->Term() 190 << " - macro"; 191 192 pCurIndex->Def() << " "; 193 } 194 195 const ary::cpp::Gate * 196 PageMaker_Index::inq_Get_ReFinder() const 197 { 198 return &Env().Gate(); 199 } 200 201 void 202 PageMaker_Index::Write_NavBar() 203 { 204 pNavi->Write( CurOut() ); 205 CurOut() << new html::HorizontalLine; 206 } 207 208 209 const String C_sAlphabet( 210 "<a href=\"index-1.html\"><B>A</B></a> <a href=\"index-2.html\"><B>B</B></a> <a href=\"index-3.html\"><B>C</B></a> <a href=\"index-4.html\"><B>D</B></a> <a href=\"index-5.html\"><B>E</B></a> " 211 "<a href=\"index-6.html\"><B>F</B></a> <a href=\"index-7.html\"><B>G</B></a> <a href=\"index-8.html\"><B>H</B></a> <a href=\"index-9.html\"><B>I</B></a> <a href=\"index-10.html\"><B>J</B></a> " 212 "<a href=\"index-11.html\"><B>K</B></a> <a href=\"index-12.html\"><B>L</B></a> <a href=\"index-13.html\"><B>M</B></a> <a href=\"index-14.html\"><B>N</B></a> <a href=\"index-15.html\"><B>O</B></a> " 213 "<a href=\"index-16.html\"><B>P</B></a> <a href=\"index-17.html\"><B>Q</B></a> <a href=\"index-18.html\"><B>R</B></a> <a href=\"index-19.html\"><B>S</B></a> <a href=\"index-20.html\"><B>T</B></a> " 214 "<a href=\"index-21.html\"><B>U</B></a> <a href=\"index-22.html\"><B>V</B></a> <a href=\"index-23.html\"><B>W</B></a> <a href=\"index-24.html\"><B>X</B></a> <a href=\"index-25.html\"><B>Y</B></a> " 215 "<a href=\"index-26.html\"><B>Z</B></a> <a href=\"index-27.html\"><B>_</B></a>" ); 216 217 void 218 PageMaker_Index::Write_TopArea() 219 { 220 String sLetter(&c, 1); 221 222 adcdisp::PageTitle_Std fTitle; 223 fTitle( CurOut(), "Global Index", sLetter ); 224 225 CurOut() >>* new html::Paragraph 226 << new html::AlignAttr("center") 227 << new xml::XmlCode(C_sAlphabet); 228 229 CurOut() << new html::HorizontalLine; 230 } 231 232 void 233 PageMaker_Index::Write_CompleteAlphabeticalList() 234 { 235 std::vector<GlobalId> 236 aThisPagesItems; 237 const ary::cpp::Gate & 238 rGate = Env().Gate(); 239 240 static char sBegin[] = "X"; 241 static char sEnd[] = "Y"; 242 243 switch ( c ) 244 { 245 case 'Z': sBegin[0] = 'Z'; 246 sEnd[0] = '_'; 247 break; 248 case '_': sBegin[0] = '_'; 249 sEnd[0] = '0'; 250 break; 251 default: sBegin[0] = c; 252 sEnd[0] = char(c + 1); 253 break; 254 } 255 256 uintt 257 nCount = rGate.Get_AlphabeticalList( aThisPagesItems, sBegin, sEnd ); 258 if (nCount > 0 ) 259 { 260 adcdisp::IndexList 261 aIndex(CurOut()); 262 pCurIndex = &aIndex; 263 264 std::vector<GlobalId>::const_iterator itEnd = aThisPagesItems.end(); 265 for ( std::vector<GlobalId>::const_iterator it = aThisPagesItems.begin(); 266 it != itEnd; 267 ++it ) 268 { 269 const ary::Entity * 270 pRe = rGate.Search_Entity( *it ); 271 if ( pRe != 0 ) 272 pRe->Accept(*this); 273 } // end for 274 275 pCurIndex = 0; 276 } // endif (nCount > 0) 277 } 278 279 void 280 PageMaker_Index::Write_CeIndexEntry( const ary::cpp::CodeEntity & 281 i_rCe, 282 const char * i_sType, 283 const char * i_sOwnerType ) 284 { 285 if ( Ce_IsInternal(i_rCe) ) 286 return; 287 288 static csv::StreamStr aQualification(500); 289 290 const ary::cpp::CodeEntity & 291 rOwner = Env().Gate().Ces().Find_Ce(i_rCe.Owner()); 292 293 pCurIndex->AddEntry(); 294 pCurIndex->Term() 295 >> *new html::Link( Link2Ce(Env(), i_rCe) ) 296 >> *new html::Bold 297 << i_rCe.LocalName(); 298 pCurIndex->Term() 299 << " - " 300 << i_sType; 301 302 if ( rOwner.Owner().IsValid() ) 303 { 304 aQualification.seekp(0); 305 Env().Gate().Ces().Get_QualifiedName( aQualification, 306 rOwner.LocalName(), 307 rOwner.Owner() ); 308 309 pCurIndex->Term() 310 << " in " 311 << i_sOwnerType 312 << " " 313 << aQualification.c_str(); 314 } 315 316 pCurIndex->Def() << " "; 317 } 318