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 "hdimpl.hxx" 30 31 32 // NOT FULLY DEFINED SERVICES 33 #include <stdlib.h> 34 #include <stdio.h> 35 #include <ary/ceslot.hxx> 36 #include <ary/qualiname.hxx> 37 #include <ary/cpp/c_class.hxx> 38 #include <ary/cpp/c_de.hxx> 39 #include <ary/cpp/c_enum.hxx> 40 #include <ary/cpp/c_funct.hxx> 41 #include <ary/cpp/c_gate.hxx> 42 #include <ary/cpp/cp_ce.hxx> 43 #include <udm/html/htmlitem.hxx> 44 #include "cre_link.hxx" 45 #include "hd_docu.hxx" 46 #include "html_kit.hxx" 47 #include "opageenv.hxx" 48 #include "pagemake.hxx" 49 #include "strconst.hxx" 50 51 52 using namespace csi; 53 54 55 //******************** HtmlDisplay_Impl *********************// 56 57 HtmlDisplay_Impl::~HtmlDisplay_Impl() 58 { 59 } 60 61 HtmlDisplay_Impl::HtmlDisplay_Impl( OuputPage_Environment & io_rEnv ) 62 : pEnv(&io_rEnv) 63 // aWriteHelper 64 { 65 } 66 67 68 //******************** Free Functions *********************// 69 70 71 72 namespace dshelp 73 { 74 75 void 76 DisplaySlot( ary::Display & o_rDisplay, 77 const ary::AryGroup & i_rGroup, 78 ary::SlotAccessId i_nSlot ) 79 { 80 ary::Slot_AutoPtr pSlot( i_rGroup.Create_Slot(i_nSlot) ); 81 pSlot->StoreAt( o_rDisplay ); 82 } 83 84 85 const char * 86 PathUp( uintt i_nLevels ) 87 { 88 static char sResult[300]; 89 90 sResult[0] = NULCH; 91 for ( uintt lev = 0; lev < i_nLevels; ++lev ) 92 { 93 strcat( sResult, "../"); // SAFE STRCAT (#100211# - checked) 94 } 95 return sResult; 96 } 97 98 const char * 99 PathPerLevelsUp( uintt i_nLevels, 100 const char * i_nPathBelowDestinationLevel ) 101 { 102 static char sResult[500]; 103 strcpy( sResult, PathUp(i_nLevels) ); // SAFE STRCPY (#100211# - checked) 104 // KORR_FUTURE: Make it still safer here: 105 strcat( sResult, i_nPathBelowDestinationLevel ); // SAFE STRCAT (#100211# - checked) 106 return sResult; 107 } 108 109 110 const char * 111 PathPerRoot( const OuputPage_Environment & i_rEnv, 112 const char * i_sPathFromRootDir ) 113 { 114 return PathPerLevelsUp( i_rEnv.Depth(), i_sPathFromRootDir ); 115 } 116 117 const char * 118 PathPerNamespace( const OuputPage_Environment & i_rEnv, 119 const char * i_sPathFromNamespaceDir ) 120 { 121 const ary::cpp::Namespace * pNsp = i_rEnv.CurNamespace(); 122 if ( pNsp == 0 ) 123 return ""; 124 125 uintt nCount = i_rEnv.Depth() - (pNsp->Depth() + 1) ; 126 csv_assert( nCount < 100 ); 127 return PathPerLevelsUp( nCount, i_sPathFromNamespaceDir ); 128 } 129 130 const char * 131 HtmlFileName( const char * i_sPrefix, 132 const char * i_sEntityName ) 133 { 134 // KORR_FUTURE: Make it still safer here: 135 static char sResult[300]; 136 strcpy( sResult, i_sPrefix ); // SAFE STRCPY (#100211# - checked) 137 strcat( sResult, i_sEntityName ); // SAFE STRCAT (#100211# - checked) 138 strcat( sResult, ".html" ); // SAFE STRCAT (#100211# - checked) 139 return sResult; 140 } 141 142 const char * 143 Path2Class( uintt i_nLevelsUp, 144 const char * i_sClassLocalName ) 145 { 146 return PathPerLevelsUp( i_nLevelsUp, ClassFileName(i_sClassLocalName) ); 147 } 148 149 const char * 150 Path2Child( const char * i_sFileName, 151 const char * i_sSubDir ) 152 { 153 static char sResult[400]; 154 if ( i_sSubDir != 0 ) 155 { 156 // KORR_FUTURE: Make it still safer here: 157 strcpy( sResult, i_sSubDir ); // SAFE STRCPY (#100211# - checked) 158 strcat( sResult, "/" ); // SAFE STRCAT (#100211# - checked) 159 } 160 else 161 { 162 sResult[0] = NULCH; 163 } 164 165 strcat( sResult, i_sFileName ); // SAFE STRCAT (#100211# - checked) 166 return sResult; 167 } 168 169 const char * 170 Path2ChildNamespace( const char * i_sLocalName ) 171 { 172 return Path2Child( C_sHFN_Namespace, i_sLocalName ); 173 } 174 175 String 176 OperationLink( const ary::cpp::Gate & , 177 const String & i_sOpName, 178 ary::cpp::Ce_id i_nOpId, 179 const char * i_sPrePath ) 180 { 181 StreamLock 182 slResult(3000); 183 StreamStr & 184 sResult = slResult(); 185 186 sResult 187 << i_sPrePath 188 << "#" 189 << i_sOpName 190 << "-" 191 << i_nOpId.Value(); 192 193 194 195 return sResult.c_str(); 196 } 197 198 const char * 199 DataLink( const String & i_sLocalName, 200 const char * i_sPrePath ) 201 { 202 StreamLock 203 slResult(3000); 204 StreamStr & 205 sResult = slResult(); 206 207 sResult 208 << i_sPrePath 209 << "#" 210 << i_sLocalName; 211 212 return sResult.c_str(); 213 } 214 215 void 216 Get_LinkedTypeText( csi::xml::Element & o_rOut, 217 const OuputPage_Environment & i_rEnv, 218 ary::cpp::Type_id i_nId, 219 bool i_bWithAbsolutifier ) 220 { 221 if (NOT i_nId.IsValid()) 222 return; 223 224 const char * sPreName = ""; 225 const char * sName = ""; 226 const char * sPostName = ""; 227 228 bool bTypeExists = Get_TypeText( sPreName, 229 sName, 230 sPostName, 231 i_nId, 232 i_rEnv.Gate() ); 233 if ( NOT bTypeExists ) 234 return; 235 236 if ( NOT i_bWithAbsolutifier AND strncmp(sPreName,"::",2) == 0 ) 237 sPreName+=2; 238 239 const ary::cpp::CodeEntity * 240 pCe = i_rEnv.Gate().Search_RelatedCe(i_nId); 241 242 String sLink; 243 if ( pCe != 0 ) 244 { 245 sLink = Link2Ce(i_rEnv,*pCe); 246 } 247 else 248 { 249 if ( strstr(sPreName,"com::sun::star") != 0 ) 250 { 251 static StreamStr aLink(400); 252 aLink.seekp(0); 253 aLink << PathPerRoot(i_rEnv, "../../common/ref"); 254 if ( *sPreName != ':' ) 255 aLink << '/'; 256 for ( const char * s = sPreName; 257 *s != 0; 258 ++s ) 259 { 260 if ( *s == ':' ) 261 { 262 aLink << '/'; 263 ++s; 264 } 265 else 266 { 267 aLink << *s; 268 } 269 } // end for 270 aLink << sName 271 << ".html"; 272 sLink = aLink.c_str(); 273 } 274 } // endif( pCe != 0 ) 275 276 o_rOut 277 << sPreName; 278 csi::xml::Element & 279 o_Goon = sLink.length() > 0 280 ? o_rOut >> * new html::Link( sLink.c_str() ) 281 : o_rOut; 282 o_Goon 283 << sName; 284 o_rOut 285 << sPostName; 286 } 287 288 void 289 Create_ChildListLabel( csi::xml::Element & o_rParentElement, 290 const char * i_sLabel ) 291 { 292 if ( NOT csv::no_str(i_sLabel) ) 293 { 294 o_rParentElement 295 >> *new html::Label(i_sLabel) 296 << " "; 297 } 298 } 299 300 DYN csi::html::Table & 301 Create_ChildListTable( const char * i_sTitle ) 302 { 303 html::Table * 304 dpTable = new html::Table; 305 *dpTable 306 << new html::ClassAttr( "childlist") 307 << new xml::AnAttribute( "border", "1" ) 308 << new xml::AnAttribute( "cellpadding", "5" ) 309 << new xml::AnAttribute( "cellspacing", "0" ) 310 << new html::WidthAttr( "100%" ); 311 312 html::TableRow & 313 rRow = dpTable->AddRow(); 314 rRow 315 << new html::ClassAttr("subtitle") 316 >> *new html::TableCell 317 << new xml::AnAttribute( "colspan","2" ) 318 >> *new html::Headline(4) 319 << i_sTitle; 320 return *dpTable; 321 } 322 323 const char * 324 Link2Ce( const OuputPage_Environment & i_rEnv, 325 const ary::cpp::CodeEntity & i_rCe ) 326 { 327 const uintt nMaxSize 328 = 3000; 329 static char sLink[nMaxSize]; 330 static LinkCreator aLinkCreator( &sLink[0], nMaxSize ); 331 sLink[0] = NULCH; 332 333 aLinkCreator.SetEnv(i_rEnv); 334 i_rCe.Accept(aLinkCreator); 335 336 return sLink; 337 } 338 339 const char * 340 Link2CppDefinition( const OuputPage_Environment & i_rEnv, 341 const ary::cpp::DefineEntity & i_rDef ) 342 { 343 const uintt nMaxSize 344 = 1000; 345 static char sLink[nMaxSize]; 346 static LinkCreator aLinkCreator( &sLink[0], nMaxSize ); 347 sLink[0] = NULCH; 348 349 aLinkCreator.SetEnv(i_rEnv); 350 i_rDef.Accept(aLinkCreator); 351 352 return sLink; 353 } 354 355 const ary::cpp::CodeEntity * 356 FindUnambiguousCe( const OuputPage_Environment & i_rEnv, 357 const ary::QualifiedName & i_rQuName, 358 const ary::cpp::Class * i_pJustDocumentedClass ) 359 { 360 if ( i_rEnv.CurNamespace() == 0 ) 361 return 0; 362 363 const ary::cpp::CodeEntity * ret = 0; 364 365 if ( NOT i_rQuName.IsQualified() ) 366 { 367 if ( i_pJustDocumentedClass != 0 ) 368 ret = i_rEnv.Gate().Ces().Search_CeLocal( i_rQuName.LocalName(), 369 i_rQuName.IsFunction(), 370 *i_rEnv.CurNamespace(), 371 i_pJustDocumentedClass ); 372 if (ret != 0) 373 return ret; 374 375 ret = i_rEnv.Gate().Ces().Search_CeLocal( i_rQuName.LocalName(), 376 i_rQuName.IsFunction(), 377 *i_rEnv.CurNamespace(), 378 i_rEnv.CurClass() ); 379 } 380 if (ret != 0) 381 return ret; 382 383 return i_rEnv.Gate().Ces().Search_CeAbsolute( *i_rEnv.CurNamespace(), 384 i_rQuName ); 385 } 386 387 void 388 ShowDocu_On( csi::xml::Element & o_rOut, 389 Docu_Display & io_rDisplay, 390 const ary::cpp::CppEntity & i_rRE ) 391 { 392 if (i_rRE.Docu().Data() != 0) 393 { 394 io_rDisplay.Assign_Out( o_rOut ); 395 io_rDisplay.Process(i_rRE.Docu()); 396 io_rDisplay.Unassign_Out(); 397 } 398 } 399 400 void 401 WriteOut_TokenList( csi::xml::Element & o_rOut, 402 const StringVector & i_rTokens, 403 const char * i_sSeparator ) 404 { 405 if ( i_rTokens.size() > 0 ) 406 { 407 StringVector::const_iterator 408 it = i_rTokens.begin(); 409 StringVector::const_iterator 410 itEnd = i_rTokens.end(); 411 412 o_rOut << *it; 413 for ( ++it; it != itEnd; ++it ) 414 { 415 o_rOut << i_sSeparator << *it; 416 } 417 }; 418 419 } 420 421 void 422 EraseLeadingSpace( String & io_rStr ) 423 { 424 if ( *io_rStr.c_str() < 33 AND io_rStr.length() > 0 ) 425 { 426 const unsigned char * pNew; 427 for ( pNew = (const unsigned char * ) io_rStr.c_str(); 428 *pNew < 33 AND *pNew != 0; 429 ++pNew ) {} 430 String sNew( (const char*)pNew ); 431 io_rStr = sNew; 432 } 433 } 434 435 void 436 WriteOut_LinkedFunctionText( csi::xml::Element & o_rTitleOut, 437 adcdisp::ParameterTable & o_rParameters, 438 const ary::cpp::Function & i_rFunction, 439 const OuputPage_Environment & i_rEnv, 440 bool * o_bIsConst, 441 bool * o_bIsVirtual ) 442 { 443 // write pre-name: 444 const ary::cpp::FunctionFlags & rFlags = i_rFunction.Flags(); 445 if ( rFlags.IsStaticLocal() OR rFlags.IsStaticMember() ) 446 o_rTitleOut << "static "; 447 if ( rFlags.IsExplicit() ) 448 o_rTitleOut << "explicit "; 449 if ( rFlags.IsMutable() ) 450 o_rTitleOut << "mutable "; 451 if ( i_rFunction.Virtuality() != ary::cpp::VIRTUAL_none ) 452 o_rTitleOut << "virtual "; 453 // o_rTitleOut << new html::LineBreak; 454 455 Get_LinkedTypeText( o_rTitleOut, i_rEnv, i_rFunction.ReturnType() ); 456 457 // write name: 458 o_rTitleOut 459 << " " 460 >> *new html::Strong 461 << i_rFunction.LocalName(); 462 o_rTitleOut 463 << "("; 464 465 466 csi::xml::Element * pOutLast = &o_rTitleOut; 467 468 // write post-name: 469 FunctionParam_Iterator fit; 470 fit.Assign(i_rFunction); 471 472 if (fit) 473 { 474 o_rParameters.AddEntry(); 475 Get_LinkedTypeText( o_rParameters.Type(), i_rEnv, fit.CurType() ); 476 o_rParameters.Type() << " "; 477 o_rParameters.Name() << " " << fit.CurName(); 478 479 for ( ++fit; fit; ++fit ) 480 { 481 o_rParameters.Name() << ","; 482 o_rParameters.AddEntry(); 483 Get_LinkedTypeText( o_rParameters.Type(), i_rEnv, fit.CurType() ); 484 o_rParameters.Name() << fit.CurName(); 485 } 486 487 pOutLast = &o_rParameters.Name(); 488 o_rParameters.Name() << " "; 489 } 490 491 *pOutLast << ")"; 492 if ( fit.IsFunctionConst() ) 493 { 494 *pOutLast << " const"; 495 if ( o_bIsConst != 0 ) 496 *o_bIsConst = true; 497 } 498 if ( fit.IsFunctionVolatile() ) 499 { 500 *pOutLast << " volatile"; 501 if ( o_bIsVirtual != 0 ) 502 *o_bIsVirtual = true; 503 } 504 505 // write Exceptions: 506 const std::vector< ary::cpp::Type_id > * 507 pThrow = i_rFunction.Exceptions(); 508 if ( pThrow) 509 { 510 std::vector< ary::cpp::Type_id >::const_iterator 511 it = pThrow->begin(); 512 std::vector< ary::cpp::Type_id >::const_iterator 513 it_end = pThrow->end(); 514 515 if (it != it_end) 516 { 517 o_rParameters.AddEntry(); 518 pOutLast = &o_rParameters.Name(); 519 520 o_rParameters.Name() << " throw( "; 521 Get_LinkedTypeText(o_rParameters.Name(), i_rEnv, *it); 522 523 for ( ++it; it != it_end; ++it ) 524 { 525 o_rParameters.Name() << ", "; 526 Get_LinkedTypeText(o_rParameters.Name(), i_rEnv, *it); 527 } 528 o_rParameters.Name() << " )"; 529 } 530 else 531 { 532 *pOutLast << " throw()"; 533 } 534 } // endif // pThrow 535 536 // abstractness: 537 if ( i_rFunction.Virtuality() == ary::cpp::VIRTUAL_abstract ) 538 *pOutLast << " = 0"; 539 540 // finish: 541 *pOutLast << ";"; 542 } 543 544 545 546 } // namespace dshelp 547