merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / display / html / hdimpl.cxx
blob27cfcd837360a67f4c2c50ac2a401ccb8b265ebd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hdimpl.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <precomp.h>
32 #include "hdimpl.hxx"
35 // NOT FULLY DEFINED SERVICES
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <ary/ceslot.hxx>
39 #include <ary/qualiname.hxx>
40 #include <ary/cpp/c_class.hxx>
41 #include <ary/cpp/c_de.hxx>
42 #include <ary/cpp/c_enum.hxx>
43 #include <ary/cpp/c_funct.hxx>
44 #include <ary/cpp/c_gate.hxx>
45 #include <ary/cpp/cp_ce.hxx>
46 #include <udm/html/htmlitem.hxx>
47 #include "cre_link.hxx"
48 #include "hd_docu.hxx"
49 #include "html_kit.hxx"
50 #include "opageenv.hxx"
51 #include "pagemake.hxx"
52 #include "strconst.hxx"
55 using namespace csi;
58 //******************** HtmlDisplay_Impl *********************//
60 HtmlDisplay_Impl::~HtmlDisplay_Impl()
64 HtmlDisplay_Impl::HtmlDisplay_Impl( OuputPage_Environment & io_rEnv )
65 : pEnv(&io_rEnv)
66 // aWriteHelper
71 //******************** Free Functions *********************//
75 namespace dshelp
78 void
79 DisplaySlot( ary::Display & o_rDisplay,
80 const ary::AryGroup & i_rGroup,
81 ary::SlotAccessId i_nSlot )
83 ary::Slot_AutoPtr pSlot( i_rGroup.Create_Slot(i_nSlot) );
84 pSlot->StoreAt( o_rDisplay );
88 const char *
89 PathUp( uintt i_nLevels )
91 static char sResult[300];
93 sResult[0] = NULCH;
94 for ( uintt lev = 0; lev < i_nLevels; ++lev )
96 strcat( sResult, "../"); // SAFE STRCAT (#100211# - checked)
98 return sResult;
101 const char *
102 PathPerLevelsUp( uintt i_nLevels,
103 const char * i_nPathBelowDestinationLevel )
105 static char sResult[500];
106 strcpy( sResult, PathUp(i_nLevels) ); // SAFE STRCPY (#100211# - checked)
107 // KORR_FUTURE: Make it still safer here:
108 strcat( sResult, i_nPathBelowDestinationLevel ); // SAFE STRCAT (#100211# - checked)
109 return sResult;
113 const char *
114 PathPerRoot( const OuputPage_Environment & i_rEnv,
115 const char * i_sPathFromRootDir )
117 return PathPerLevelsUp( i_rEnv.Depth(), i_sPathFromRootDir );
120 const char *
121 PathPerNamespace( const OuputPage_Environment & i_rEnv,
122 const char * i_sPathFromNamespaceDir )
124 const ary::cpp::Namespace * pNsp = i_rEnv.CurNamespace();
125 if ( pNsp == 0 )
126 return "";
128 uintt nCount = i_rEnv.Depth() - (pNsp->Depth() + 1) ;
129 csv_assert( nCount < 100 );
130 return PathPerLevelsUp( nCount, i_sPathFromNamespaceDir );
133 const char *
134 HtmlFileName( const char * i_sPrefix,
135 const char * i_sEntityName )
137 // KORR_FUTURE: Make it still safer here:
138 static char sResult[300];
139 strcpy( sResult, i_sPrefix ); // SAFE STRCPY (#100211# - checked)
140 strcat( sResult, i_sEntityName ); // SAFE STRCAT (#100211# - checked)
141 strcat( sResult, ".html" ); // SAFE STRCAT (#100211# - checked)
142 return sResult;
145 const char *
146 Path2Class( uintt i_nLevelsUp,
147 const char * i_sClassLocalName )
149 return PathPerLevelsUp( i_nLevelsUp, ClassFileName(i_sClassLocalName) );
152 const char *
153 Path2Child( const char * i_sFileName,
154 const char * i_sSubDir )
156 static char sResult[400];
157 if ( i_sSubDir != 0 )
159 // KORR_FUTURE: Make it still safer here:
160 strcpy( sResult, i_sSubDir ); // SAFE STRCPY (#100211# - checked)
161 strcat( sResult, "/" ); // SAFE STRCAT (#100211# - checked)
163 else
165 sResult[0] = NULCH;
168 strcat( sResult, i_sFileName ); // SAFE STRCAT (#100211# - checked)
169 return sResult;
172 const char *
173 Path2ChildNamespace( const char * i_sLocalName )
175 return Path2Child( C_sHFN_Namespace, i_sLocalName );
178 String
179 OperationLink( const ary::cpp::Gate & ,
180 const String & i_sOpName,
181 ary::cpp::Ce_id i_nOpId,
182 const char * i_sPrePath )
184 StreamLock
185 slResult(3000);
186 StreamStr &
187 sResult = slResult();
189 sResult
190 << i_sPrePath
191 << "#"
192 << i_sOpName
193 << "-"
194 << i_nOpId.Value();
198 return sResult.c_str();
201 const char *
202 DataLink( const String & i_sLocalName,
203 const char * i_sPrePath )
205 StreamLock
206 slResult(3000);
207 StreamStr &
208 sResult = slResult();
210 sResult
211 << i_sPrePath
212 << "#"
213 << i_sLocalName;
215 return sResult.c_str();
218 void
219 Get_LinkedTypeText( csi::xml::Element & o_rOut,
220 const OuputPage_Environment & i_rEnv,
221 ary::cpp::Type_id i_nId,
222 bool i_bWithAbsolutifier )
224 if (NOT i_nId.IsValid())
225 return;
227 const char * sPreName = "";
228 const char * sName = "";
229 const char * sPostName = "";
231 bool bTypeExists = Get_TypeText( sPreName,
232 sName,
233 sPostName,
234 i_nId,
235 i_rEnv.Gate() );
236 if ( NOT bTypeExists )
237 return;
239 if ( NOT i_bWithAbsolutifier AND strncmp(sPreName,"::",2) == 0 )
240 sPreName+=2;
242 const ary::cpp::CodeEntity *
243 pCe = i_rEnv.Gate().Search_RelatedCe(i_nId);
245 String sLink;
246 if ( pCe != 0 )
248 sLink = Link2Ce(i_rEnv,*pCe);
250 else
252 if ( strstr(sPreName,"com::sun::star") != 0 )
254 static StreamStr aLink(400);
255 aLink.seekp(0);
256 aLink << PathPerRoot(i_rEnv, "../../common/ref");
257 if ( *sPreName != ':' )
258 aLink << '/';
259 for ( const char * s = sPreName;
260 *s != 0;
261 ++s )
263 if ( *s == ':' )
265 aLink << '/';
266 ++s;
268 else
270 aLink << *s;
272 } // end for
273 aLink << sName
274 << ".html";
275 sLink = aLink.c_str();
277 } // endif( pCe != 0 )
279 o_rOut
280 << sPreName;
281 csi::xml::Element &
282 o_Goon = sLink.length() > 0
283 ? o_rOut >> * new html::Link( sLink.c_str() )
284 : o_rOut;
285 o_Goon
286 << sName;
287 o_rOut
288 << sPostName;
291 void
292 Create_ChildListLabel( csi::xml::Element & o_rParentElement,
293 const char * i_sLabel )
295 if ( NOT csv::no_str(i_sLabel) )
297 o_rParentElement
298 >> *new html::Label(i_sLabel)
299 << " ";
303 DYN csi::html::Table &
304 Create_ChildListTable( const char * i_sTitle )
306 html::Table *
307 dpTable = new html::Table;
308 *dpTable
309 << new html::ClassAttr( "childlist")
310 << new xml::AnAttribute( "border", "1" )
311 << new xml::AnAttribute( "cellpadding", "5" )
312 << new xml::AnAttribute( "cellspacing", "0" )
313 << new html::WidthAttr( "100%" );
315 html::TableRow &
316 rRow = dpTable->AddRow();
317 rRow
318 << new html::ClassAttr("subtitle")
319 >> *new html::TableCell
320 << new xml::AnAttribute( "colspan","2" )
321 >> *new html::Headline(4)
322 << i_sTitle;
323 return *dpTable;
326 const char *
327 Link2Ce( const OuputPage_Environment & i_rEnv,
328 const ary::cpp::CodeEntity & i_rCe )
330 const uintt nMaxSize
331 = 3000;
332 static char sLink[nMaxSize];
333 static LinkCreator aLinkCreator( &sLink[0], nMaxSize );
334 sLink[0] = NULCH;
336 aLinkCreator.SetEnv(i_rEnv);
337 i_rCe.Accept(aLinkCreator);
339 return sLink;
342 const char *
343 Link2CppDefinition( const OuputPage_Environment & i_rEnv,
344 const ary::cpp::DefineEntity & i_rDef )
346 const uintt nMaxSize
347 = 1000;
348 static char sLink[nMaxSize];
349 static LinkCreator aLinkCreator( &sLink[0], nMaxSize );
350 sLink[0] = NULCH;
352 aLinkCreator.SetEnv(i_rEnv);
353 i_rDef.Accept(aLinkCreator);
355 return sLink;
358 const ary::cpp::CodeEntity *
359 FindUnambiguousCe( const OuputPage_Environment & i_rEnv,
360 const ary::QualifiedName & i_rQuName,
361 const ary::cpp::Class * i_pJustDocumentedClass )
363 if ( i_rEnv.CurNamespace() == 0 )
364 return 0;
366 const ary::cpp::CodeEntity * ret = 0;
368 if ( NOT i_rQuName.IsQualified() )
370 if ( i_pJustDocumentedClass != 0 )
371 ret = i_rEnv.Gate().Ces().Search_CeLocal( i_rQuName.LocalName(),
372 i_rQuName.IsFunction(),
373 *i_rEnv.CurNamespace(),
374 i_pJustDocumentedClass );
375 if (ret != 0)
376 return ret;
378 ret = i_rEnv.Gate().Ces().Search_CeLocal( i_rQuName.LocalName(),
379 i_rQuName.IsFunction(),
380 *i_rEnv.CurNamespace(),
381 i_rEnv.CurClass() );
383 if (ret != 0)
384 return ret;
386 return i_rEnv.Gate().Ces().Search_CeAbsolute( *i_rEnv.CurNamespace(),
387 i_rQuName );
390 void
391 ShowDocu_On( csi::xml::Element & o_rOut,
392 Docu_Display & io_rDisplay,
393 const ary::cpp::CppEntity & i_rRE )
395 if (i_rRE.Docu().Data() != 0)
397 io_rDisplay.Assign_Out( o_rOut );
398 io_rDisplay.Process(i_rRE.Docu());
399 io_rDisplay.Unassign_Out();
403 void
404 WriteOut_TokenList( csi::xml::Element & o_rOut,
405 const StringVector & i_rTokens,
406 const char * i_sSeparator )
408 if ( i_rTokens.size() > 0 )
410 StringVector::const_iterator
411 it = i_rTokens.begin();
412 StringVector::const_iterator
413 itEnd = i_rTokens.end();
415 o_rOut << *it;
416 for ( ++it; it != itEnd; ++it )
418 o_rOut << i_sSeparator << *it;
424 void
425 EraseLeadingSpace( String & io_rStr )
427 if ( *io_rStr.c_str() < 33 AND io_rStr.length() > 0 )
429 const unsigned char * pNew;
430 for ( pNew = (const unsigned char * ) io_rStr.c_str();
431 *pNew < 33 AND *pNew != 0;
432 ++pNew ) {}
433 String sNew( (const char*)pNew );
434 io_rStr = sNew;
438 void
439 WriteOut_LinkedFunctionText( csi::xml::Element & o_rTitleOut,
440 adcdisp::ParameterTable & o_rParameters,
441 const ary::cpp::Function & i_rFunction,
442 const OuputPage_Environment & i_rEnv,
443 bool * o_bIsConst,
444 bool * o_bIsVirtual )
446 // write pre-name:
447 const ary::cpp::FunctionFlags & rFlags = i_rFunction.Flags();
448 if ( rFlags.IsStaticLocal() OR rFlags.IsStaticMember() )
449 o_rTitleOut << "static ";
450 if ( rFlags.IsExplicit() )
451 o_rTitleOut << "explicit ";
452 if ( rFlags.IsMutable() )
453 o_rTitleOut << "mutable ";
454 if ( i_rFunction.Virtuality() != ary::cpp::VIRTUAL_none )
455 o_rTitleOut << "virtual ";
456 // o_rTitleOut << new html::LineBreak;
458 Get_LinkedTypeText( o_rTitleOut, i_rEnv, i_rFunction.ReturnType() );
460 // write name:
461 o_rTitleOut
462 << " "
463 >> *new html::Strong
464 << i_rFunction.LocalName();
465 o_rTitleOut
466 << "(";
469 csi::xml::Element * pOutLast = &o_rTitleOut;
471 // write post-name:
472 FunctionParam_Iterator fit;
473 fit.Assign(i_rFunction);
475 if (fit)
477 o_rParameters.AddEntry();
478 Get_LinkedTypeText( o_rParameters.Type(), i_rEnv, fit.CurType() );
479 o_rParameters.Type() << " ";
480 o_rParameters.Name() << " " << fit.CurName();
482 for ( ++fit; fit; ++fit )
484 o_rParameters.Name() << ",";
485 o_rParameters.AddEntry();
486 Get_LinkedTypeText( o_rParameters.Type(), i_rEnv, fit.CurType() );
487 o_rParameters.Name() << fit.CurName();
490 pOutLast = &o_rParameters.Name();
491 o_rParameters.Name() << " ";
494 *pOutLast << ")";
495 if ( fit.IsFunctionConst() )
497 *pOutLast << " const";
498 if ( o_bIsConst != 0 )
499 *o_bIsConst = true;
501 if ( fit.IsFunctionVolatile() )
503 *pOutLast << " volatile";
504 if ( o_bIsVirtual != 0 )
505 *o_bIsVirtual = true;
508 // write Exceptions:
509 const std::vector< ary::cpp::Type_id > *
510 pThrow = i_rFunction.Exceptions();
511 if ( pThrow)
513 std::vector< ary::cpp::Type_id >::const_iterator
514 it = pThrow->begin();
515 std::vector< ary::cpp::Type_id >::const_iterator
516 it_end = pThrow->end();
518 if (it != it_end)
520 o_rParameters.AddEntry();
521 pOutLast = &o_rParameters.Name();
523 o_rParameters.Name() << " throw( ";
524 Get_LinkedTypeText(o_rParameters.Name(), i_rEnv, *it);
526 for ( ++it; it != it_end; ++it )
528 o_rParameters.Name() << ", ";
529 Get_LinkedTypeText(o_rParameters.Name(), i_rEnv, *it);
531 o_rParameters.Name() << " )";
533 else
535 *pOutLast << " throw()";
537 } // endif // pThrow
539 // abstractness:
540 if ( i_rFunction.Virtuality() == ary::cpp::VIRTUAL_abstract )
541 *pOutLast << " = 0";
543 // finish:
544 *pOutLast << ";";
549 } // namespace dshelp