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 "pagemake.hxx"
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <ary/cpp/c_gate.hxx>
34 #include <ary/cpp/c_namesp.hxx>
35 #include <ary/cpp/c_class.hxx>
36 #include <ary/cpp/c_enum.hxx>
37 #include <ary/cpp/c_tydef.hxx>
38 #include <ary/cpp/cp_ce.hxx>
39 #include <ary/loc/loc_file.hxx>
40 #include <display/corframe.hxx>
41 #include "hd_chlst.hxx"
42 #include "hd_docu.hxx"
43 #include "hdimpl.hxx"
44 #include "html_kit.hxx"
45 #include "navibar.hxx"
46 #include "opageenv.hxx"
47 #include "outfile.hxx"
48 #include "pm_aldef.hxx"
49 #include "pm_class.hxx"
50 #include "pm_help.hxx"
51 #include "pm_index.hxx"
52 #include "pm_namsp.hxx"
53 #include "pm_start.hxx"
54 #include "strconst.hxx"
55 
56 
57 using namespace csi;
58 using csi::html::Link;
59 using csi::html::HorizontalLine;
60 
61 
62 const int C_nNrOfIndexLetters = 27;
63 
64 
65 template <class SPECIAL_MAKER>
66 inline void
67 Make_SpecialPage( DYN SPECIAL_MAKER * let_dpMaker )
68 {
69     Dyn< SPECIAL_MAKER > pMaker( let_dpMaker );
70     pMaker->MakePage();
71     pMaker = 0;
72 }
73 
74 
75 PageDisplay::PageDisplay( OuputPage_Environment & io_rEnv )
76     :   HtmlDisplay_Impl( io_rEnv ),
77         pMyFile( new HtmlDocuFile )
78 {
79 }
80 
81 PageDisplay::~PageDisplay()
82 {
83 
84 }
85 
86 void
87 PageDisplay::Create_OverviewFile()
88 {
89     Env().SetFile_Overview();
90     File().SetLocation( Env().CurPath(), 0 );
91 
92     SetupFileOnCurEnv( C_sHFTitle_Overview );
93     Make_SpecialPage( new PageMaker_Overview(*this) );
94     Create_File();
95 }
96 
97 void
98 PageDisplay::Create_AllDefsFile()
99 {
100     // This method is a provisorium, because later this will
101     //   be spreaded over the files.
102 
103     Env().MoveDir_2Root();
104     Env().SetFile_AllDefs();
105     File().SetLocation( Env().CurPath(), 0 );
106 
107     SetupFileOnCurEnv( "Defines and Macros" );
108     Make_SpecialPage( new PageMaker_AllDefs(*this) );
109     Create_File();
110 }
111 
112 void
113 PageDisplay::Create_IndexFiles()
114 {
115     Env().MoveDir_2Index();
116 
117     for ( int i = 0; i < C_nNrOfIndexLetters; ++i )
118         Create_IndexFile(i);
119 }
120 
121 void
122 PageDisplay::Create_HelpFile()
123 {
124     Env().SetFile_Help();
125     File().SetLocation( Env().CurPath(), 0 );
126 
127     SetupFileOnCurEnv( C_sHFTitle_Help );
128     Make_SpecialPage( new PageMaker_Help(*this) );
129     Create_File();
130 }
131 
132 void
133 PageDisplay::Create_NamespaceFile()
134 {
135     csv_assert( Env().CurNamespace() != 0 );
136     Env().SetFile_CurNamespace();
137     File().SetLocation( Env().CurPath(), Env().Depth() );
138     if (Env().CurNamespace()->Owner().IsValid())
139     {
140         StreamLock sNsp(100);
141         SetupFileOnCurEnv( sNsp() << C_sHFTypeTitle_Namespace
142                                   << " "
143                                   << Env().CurNamespace()->LocalName()
144                                   << c_str );
145     }
146     else
147     {
148         SetupFileOnCurEnv( C_sHFTitle_GlobalNamespaceCpp );
149     }
150 
151     Make_SpecialPage( new PageMaker_Namespace(*this) );
152 
153     Create_File();
154 }
155 
156 void
157 PageDisplay::Setup_OperationsFile_for( const ary::loc::File & i_rFile )
158 {
159     csv_assert( Env().CurNamespace() != 0 );
160     Env().SetFile_Operations(&i_rFile);
161     File().SetLocation( Env().CurPath(), Env().Depth() );
162 
163     StreamLock sOpFile(100);
164     SetupFileOnCurEnv( sOpFile() << "Global Functions in Namespace "
165                                  << Env().CurNamespace()->LocalName()
166                                  << " in Sourcefile "
167                                  << i_rFile.LocalName()
168                                  << c_str );
169     NavigationBar
170             aNavi( Env(),
171                    NavigationBar::CEGT_operations );
172     aNavi.Write( CurOut() );
173     CurOut() << new HorizontalLine;
174 
175     adcdisp::PageTitle_Std fTitle;
176     csi::xml::Element & rTitle = fTitle( CurOut() );
177     if (Env().CurNamespace()->Owner().IsValid())
178     {
179      	rTitle << "Global Functions in Namespace "
180                << Env().CurNamespace()->LocalName();
181     }
182     else
183     {
184         rTitle << "Global Functions in Global Namespace C++";
185     }
186 
187     rTitle << new html::LineBreak
188            << "in Sourcefile "
189            << i_rFile.LocalName();
190     CurOut() << new HorizontalLine;
191 }
192 
193 void
194 PageDisplay::Setup_OperationsFile_for( const ary::cpp::Class & i_rClass )
195 {
196     csv_assert( Env().CurNamespace() != 0 );
197     Env().SetFile_Operations(0);
198     File().SetLocation( Env().CurPath(), Env().Depth() );
199 
200     StreamLock sOpFile(100);
201     SetupFileOnCurEnv( sOpFile() << "Methods of Class "
202                                  << i_rClass.LocalName()
203                                  << c_str );
204     NavigationBar
205             aNavi( Env(),
206                    NavigationBar::CEGT_operations );
207     aNavi.Write( CurOut() );
208     CurOut() << new HorizontalLine;
209 
210     adcdisp::PageTitle_Std fTitle;
211     fTitle( CurOut(), "Methods of Class", i_rClass.LocalName() );
212 
213     CurOut() << new HorizontalLine;
214 }
215 
216 void
217 PageDisplay::Setup_DataFile_for( const ary::loc::File & i_rFile )
218 {
219     csv_assert( Env().CurNamespace() != 0 );
220     Env().SetFile_Data(&i_rFile);
221     File().SetLocation( Env().CurPath(), Env().Depth() );
222 
223     StreamLock sDataFile(100);
224     SetupFileOnCurEnv( sDataFile() << "Global Data in Namespace "
225                                    << Env().CurNamespace()->LocalName()
226                                    << " in Sourcefile "
227                                    << i_rFile.LocalName()
228                                    << c_str );
229     NavigationBar
230             aNavi( Env(),
231                    NavigationBar::CEGT_data );
232     aNavi.Write( CurOut() );
233     CurOut() << new HorizontalLine;
234 
235     adcdisp::PageTitle_Std fTitle;
236     csi::xml::Element & rTitle = fTitle( CurOut() );
237     if ( Env().CurNamespace()->Owner().IsValid() )
238     {
239      	rTitle << "Global Data in Namespace "
240                << Env().CurNamespace()->LocalName();
241     }
242     else
243     {
244         rTitle << "Global Data in Global Namespace C++";
245     }
246 
247     rTitle
248         << new html::LineBreak
249         << "in Sourcefile "
250         << i_rFile.LocalName();
251     CurOut() << new HorizontalLine;
252 }
253 
254 void
255 PageDisplay::Setup_DataFile_for( const ary::cpp::Class & i_rClass )
256 {
257     csv_assert( Env().CurNamespace() != 0 );
258     Env().SetFile_Data(0);
259     File().SetLocation( Env().CurPath(), Env().Depth() );
260 
261     StreamLock sDataFile(100);
262     SetupFileOnCurEnv( sDataFile() << "Data of Class "
263                                    << i_rClass.LocalName()
264                                    << c_str );
265 
266     NavigationBar
267             aNavi( Env(),
268                    NavigationBar::CEGT_data );
269     aNavi.Write( CurOut() );
270     CurOut() << new HorizontalLine;
271 
272     adcdisp::PageTitle_Std fTitle;
273     fTitle( CurOut(), "Data of Class", i_rClass.LocalName() );
274 
275     CurOut() << new HorizontalLine;
276 }
277 
278 void
279 PageDisplay::Create_File()
280 {
281     Easy().Leave();
282     File().CreateFile();
283 }
284 
285 void
286 PageDisplay::do_Process(const ary::cpp::Class & i_rData)
287 {
288     Env().SetFile_Class(i_rData);
289     File().SetLocation( Env().CurPath(), Env().Depth() );
290 
291     const char *
292             sTypeTitle = i_rData.ClassKey() == ary::cpp::CK_class
293                             ?   C_sHFTypeTitle_Class
294                             :   i_rData.ClassKey() == ary::cpp::CK_struct
295                                     ?   C_sHFTypeTitle_Struct
296                                     :   C_sHFTypeTitle_Union;
297     StreamLock sClassFile(60);
298     SetupFileOnCurEnv( sClassFile() << sTypeTitle
299                                     << " "
300                                     << i_rData.LocalName()
301                                     << c_str );
302 
303     Make_SpecialPage( new PageMaker_Class(*this, i_rData) );
304 
305     Create_File();
306 }
307 
308 void
309 PageDisplay::do_Process(const ary::cpp::Enum & i_rData)
310 {
311     if ( Ce_IsInternal(i_rData) )
312         return;
313 
314     Env().SetFile_Enum(i_rData);
315     File().SetLocation( Env().CurPath(), Env().Depth() );
316 
317     StreamLock sEnumFile(100);
318     SetupFileOnCurEnv( sEnumFile() << C_sHFTypeTitle_Enum
319                                    << " "
320                                    << i_rData.LocalName()
321                                    << c_str );
322     Write_NavBar_Enum(i_rData);
323     Write_TopArea_Enum(i_rData);
324     Write_DocuArea_Enum(i_rData);
325     Write_ChildList_Enum(i_rData);
326 
327     Create_File();
328 }
329 
330 void
331 PageDisplay::do_Process(const ary::cpp::Typedef & i_rData)
332 {
333     if ( Ce_IsInternal(i_rData) )
334         return;
335 
336     Env().SetFile_Typedef(i_rData);
337     File().SetLocation( Env().CurPath(), Env().Depth() );
338 
339     StreamLock sTypedefFile(100);
340     SetupFileOnCurEnv( sTypedefFile() << C_sHFTypeTitle_Typedef
341                                       << " "
342                                       << i_rData.LocalName()
343                                       << c_str );
344     Write_NavBar_Typedef(i_rData);
345     Write_TopArea_Typedef(i_rData);
346     Write_DocuArea_Typedef(i_rData);
347 
348 
349     Create_File();
350 }
351 
352 void
353 PageDisplay::Write_NameChainWithLinks( const ary::cpp::CodeEntity & i_rCe )
354 {
355     if ( Env().CurNamespace()->Id() != i_rCe.Id() )
356     {
357         RecursiveWrite_NamespaceLink( Env().CurNamespace() );
358         if ( Env().CurClass() != 0 )
359         {
360             CurOut() << new html::Sbr;
361             RecursiveWrite_ClassLink( Env().CurClass(), 1 );
362         }
363     }
364     else
365     {
366         RecursiveWrite_NamespaceLink( Env().CurNamespace()->Parent() );
367     }
368 }
369 
370 const ary::cpp::Gate *
371 PageDisplay::inq_Get_ReFinder() const
372 {
373  	return &Env().Gate();
374 }
375 
376 void
377 PageDisplay::RecursiveWrite_NamespaceLink( const ary::cpp::Namespace * i_pNamespace )
378 {
379     if ( i_pNamespace == 0 )
380     {
381         return;
382     }
383     else if (NOT i_pNamespace->Owner().IsValid())
384     {   // Global namespace:
385         StreamLock sNspDir(50);
386         CurOut()
387             >> *new Link( PathPerRoot(Env(),
388                                       sNspDir() << C_sDIR_NamespacesCpp
389                                                 << "/"
390                                                 << C_sHFN_Namespace
391                                                 << c_str) )
392                     << new xml::AnAttribute( "alt", C_sHFTitle_GlobalNamespaceCpp )
393                     >> *new html::Font
394                             << new html::SizeAttr("+1")
395                             >> *new html::Bold
396                                     << "::";
397         CurOut()
398             << " ";
399         return;
400     }
401     else
402     {
403         RecursiveWrite_NamespaceLink( i_pNamespace->Parent() );
404     }
405 
406     uintt nLevelDistance = Env().Depth() - ( i_pNamespace->Depth() + 1 );
407     csv_assert( nLevelDistance < 100 );
408     CurOut()
409         >> *new Link( PathPerLevelsUp(nLevelDistance, C_sHFN_Namespace) )
410                 << new xml::AnAttribute( "alt", C_sHFTypeTitle_Namespace)
411                 >> *new html::Font
412                         << new html::SizeAttr("+1")
413                         >> *new html::Bold
414                                 << i_pNamespace->LocalName();
415     CurOut()
416         >> *new html::Font
417                 << new html::SizeAttr("+1")
418                 << " :: ";
419 }
420 
421 void
422 PageDisplay::RecursiveWrite_ClassLink( const ary::cpp::Class * i_pClass,
423                                        uintt                   i_nLevelDistance )
424 {
425  	if ( i_pClass == 0 )
426         return;
427 
428     if ( i_pClass->Protection() != ary::cpp::PROTECT_global )
429     {
430      	RecursiveWrite_ClassLink(
431             dynamic_cast< const ary::cpp::Class* >(
432                 Env().Gate().Ces().Search_Ce(i_pClass->Owner())),
433             i_nLevelDistance + 1 );
434     }
435 
436     CurOut()
437         >> *new Link( Path2Class(i_nLevelDistance, i_pClass->LocalName()) )
438             << new html::ClassAttr("nqclass")
439             << i_pClass->LocalName()
440             << " :: ";
441 }
442 
443 void
444 PageDisplay::SetupFileOnCurEnv( const char * i_sTitle )
445 {
446     File().SetLocation( Env().CurPath(), Env().Depth() );
447     File().SetTitle( i_sTitle );
448     File().SetCopyright( Env().Layout().CopyrightText() );
449     File().EmptyBody();
450 
451     // This sets CurOut() to the contents of <body></body>
452     //   in File() :
453     Easy().Enter( File().Body() );
454 }
455 
456 void
457 PageDisplay::Write_NavBar_Enum( const ary::cpp::Enum & i_rData )
458 {
459     NavigationBar   aNavi( Env(), i_rData );
460     aNavi.MakeSubRow("List of");
461     aNavi.AddItem( C_sTitle_EnumValues, C_sLabel_EnumValues, true );
462     aNavi.Write( CurOut(), true );
463 
464     CurOut() << new HorizontalLine;
465 }
466 
467 void
468 PageDisplay::Write_TopArea_Enum( const ary::cpp::Enum & i_rData )
469 {
470     Write_NameChainWithLinks( i_rData );
471 
472     adcdisp::PageTitle_Std fTitle;
473     fTitle( CurOut(), C_sHFTypeTitle_Enum, i_rData.LocalName() );
474 
475     CurOut() << new HorizontalLine;
476 }
477 
478 void
479 PageDisplay::Write_DocuArea_Enum( const ary::cpp::Enum & i_rData )
480 {
481     Docu_Display aDocuShow( Env() );
482 
483     aDocuShow.Assign_Out(CurOut());
484     aDocuShow.Process(i_rData.Docu());
485     aDocuShow.Unassign_Out();
486 
487     CurOut() << new HorizontalLine;
488 }
489 
490 void
491 PageDisplay::Write_ChildList_Enum( const ary::cpp::Enum & i_rData )
492 {
493     bool    bChildrenExist = false;
494     ChildList_Display::Area_Result
495             aResult( bChildrenExist, CurOut() );
496 
497     ChildList_Display aDisplay(Env(), i_rData);
498     aDisplay.Run_Simple( aResult,
499                          ary::cpp::Enum::SLOT_Values,
500                          C_sLabel_EnumValues,
501                          C_sTitle_EnumValues );
502 
503     if (NOT bChildrenExist)
504         CurOut() >> *new html::Headline(4) << "This enum has no values.";
505     CurOut() << new HorizontalLine;
506 }
507 
508 void
509 PageDisplay::Write_NavBar_Typedef( const ary::cpp::Typedef & i_rData )
510 {
511     NavigationBar   aNavi( Env(), i_rData );
512     aNavi.Write( CurOut(), true );
513 
514     CurOut() << new HorizontalLine;
515 }
516 
517 void
518 PageDisplay::Write_TopArea_Typedef( const ary::cpp::Typedef & i_rData )
519 {
520     Write_NameChainWithLinks( i_rData );
521 
522     adcdisp::PageTitle_Std fTitle;
523     fTitle( CurOut(), C_sHFTypeTitle_Typedef, i_rData.LocalName() );
524 
525     CurOut() << new HorizontalLine;
526 }
527 
528 void
529 PageDisplay::Write_DocuArea_Typedef( const ary::cpp::Typedef & i_rData )
530 {
531     adcdisp::ExplanationList aDef( CurOut() );
532     aDef.AddEntry("Definition:");
533     xml::Element & rDef = aDef.Def();
534 
535     ary::cpp::Type_id
536         nDefiningType = i_rData.DescribingType();
537 
538     const ary::cpp::CodeEntity *
539         pRelatedCe = Env().Gate().Search_RelatedCe(nDefiningType);
540     if ( pRelatedCe != 0 )
541     {
542         const char * sTypeKey = Get_TypeKey(*pRelatedCe);
543         if ( NOT csv::no_str(sTypeKey) )
544             rDef << sTypeKey << " ";
545     }
546 
547     dshelp::Get_LinkedTypeText( rDef, Env(), nDefiningType );
548 
549     Docu_Display aDocuShow( Env() );
550 
551     aDocuShow.Assign_Out(CurOut());
552     aDocuShow.Process(i_rData.Docu());
553     aDocuShow.Unassign_Out();
554 
555     CurOut() << new HorizontalLine;
556 }
557 
558 void
559 PageDisplay::Create_IndexFile( int i_nLetter )
560 {
561     static char aLetters[C_nNrOfIndexLetters+1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
562     csv_assert( 0 <= i_nLetter AND i_nLetter < C_nNrOfIndexLetters );
563 
564     char cCurLetter = aLetters[i_nLetter];
565     Env().SetFile_Index( cCurLetter );
566 
567     static char sIndexFileTitle[] = "Global Index X";
568     const int nPositionOfLetterInTitle = 13;
569     sIndexFileTitle[nPositionOfLetterInTitle] = cCurLetter;
570     SetupFileOnCurEnv( sIndexFileTitle );
571 
572     Make_SpecialPage( new PageMaker_Index(*this, cCurLetter ) );
573 
574     Create_File();
575 }
576 
577