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 "hd_chlst.hxx"
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <ary/ceslot.hxx>
34 #include <ary/cpp/c_gate.hxx>
35 #include <ary/cpp/c_namesp.hxx>
36 #include <ary/cpp/c_class.hxx>
37 #include <ary/cpp/c_enum.hxx>
38 #include <ary/cpp/c_tydef.hxx>
39 #include <ary/cpp/c_funct.hxx>
40 #include <ary/cpp/c_vari.hxx>
41 #include <ary/cpp/c_enuval.hxx>
42 #include <ary/loc/loc_file.hxx>
43 #include <ary/loc/locp_le.hxx>
44 #include <ary/doc/d_oldcppdocu.hxx>
45 #include <ary/info/ci_attag.hxx>
46 #include <ary/info/ci_text.hxx>
47 #include <ary/info/all_dts.hxx>
48 #include "hd_docu.hxx"
49 #include "opageenv.hxx"
50 #include "protarea.hxx"
51 #include "strconst.hxx"
52 
53 
54 using namespace csi;
55 using html::Table;
56 using html::TableRow;
57 using html::TableCell;
58 using html::Font;
59 using html::SizeAttr;
60 using html::BgColorAttr;
61 using html::WidthAttr;
62 
63 
64 const int   ixPublic = 0;
65 const int   ixProtected = 1;
66 const int   ixPrivate = 2;
67 
68 struct ChildList_Display::S_AreaCo
69 {
70   public:
71     ProtectionArea      aArea;
72     Area_Result *       pResult;
73 
74                         S_AreaCo(
75                             Area_Result &       o_rResult,
76                             const char *        i_sLabel,
77                             const char *        i_sTitle );
78                         ~S_AreaCo();
79 
80     void                PerformResult();
81 
82   private:
83     csi::xml::Element & Out()                   { return pResult->rOut; }
84 };
85 
86 
87 const ary::info::DocuText &
88 ShortDocu( const ary::cpp::CodeEntity & i_rCe )
89 {
90     static const ary::info::DocuText
91         aNull_;
92 
93     const ary::doc::OldCppDocu *
94             pInfo = dynamic_cast< const ary::doc::OldCppDocu* >( i_rCe.Docu().Data() );
95     if (pInfo == 0)
96         return aNull_;
97 
98     return pInfo->Short().CText();
99 }
100 
101 
102 ChildList_Display::ChildList_Display( OuputPage_Environment & io_rEnv )
103     :   HtmlDisplay_Impl( io_rEnv ),
104         pShortDocu_Display( new Docu_Display(io_rEnv) ),
105         pActiveParentClass(0),
106         pActiveParentEnum(0),
107         // pSglArea,
108         // aMemberAreas,
109         peClassesFilter(0)
110 {
111 }
112 
113 ChildList_Display::ChildList_Display( OuputPage_Environment & io_rEnv,
114                                       const ary::cpp::Class & i_rClass )
115     :   HtmlDisplay_Impl( io_rEnv ),
116         pShortDocu_Display( new Docu_Display(io_rEnv) ),
117         pActiveParentClass(&i_rClass),
118         pActiveParentEnum(0),
119         // pSglArea,
120         // aMemberAreas,
121         peClassesFilter(0)
122 {
123 }
124 
125 ChildList_Display::ChildList_Display( OuputPage_Environment & io_rEnv,
126                                       const ary::cpp::Enum &  i_rEnum )
127     :   HtmlDisplay_Impl( io_rEnv ),
128         pShortDocu_Display( new Docu_Display(io_rEnv) ),
129         pActiveParentClass(0),
130         pActiveParentEnum(&i_rEnum),
131         // pSglArea,
132         // aMemberAreas,
133         peClassesFilter(0)
134 {
135 }
136 
137 ChildList_Display::~ChildList_Display()
138 {
139 }
140 
141 void
142 ChildList_Display::Run_Simple( Area_Result &       o_rResult,
143                                ary::SlotAccessId   i_nSlot,
144                                const char *        i_sListLabel,
145                                const char *        i_sListTitle )
146 {
147 	ary::Slot_AutoPtr
148             pSlot( ActiveParent().Create_Slot( i_nSlot ) );
149     if ( pSlot->Size() == 0 )
150         return;
151 
152     pSglArea = new S_AreaCo( o_rResult,
153                              i_sListLabel,
154                              i_sListTitle );
155 
156     pSlot->StoreAt(*this);
157 
158     pSglArea->PerformResult();
159     pSglArea = 0;
160 }
161 
162 void
163 ChildList_Display::Run_GlobalClasses( Area_Result &        o_rResult,
164                                       ary::SlotAccessId    i_nSlot,
165                                       const char *         i_sListLabel,
166                                       const char *         i_sListTitle,
167                                       ary::cpp::E_ClassKey i_eFilter )
168 {
169 	ary::Slot_AutoPtr
170             pSlot( ActiveParent().Create_Slot( i_nSlot ) );
171     if ( pSlot->Size() == 0 )
172         return;
173 
174     pSglArea = new S_AreaCo( o_rResult,
175                              i_sListLabel,
176                              i_sListTitle );
177 
178     SetClassesFilter(i_eFilter);
179     pSlot->StoreAt(*this);
180     UnsetClassesFilter();
181 
182     pSglArea->PerformResult();
183     pSglArea = 0;
184 }
185 
186 void
187 ChildList_Display::Run_Members( Area_Result &           o_rResult_public,
188                                 Area_Result &           o_rResult_protected,
189                                 Area_Result &           o_rResult_private,
190                                 ary::SlotAccessId       i_nSlot,
191                                 const char *            i_sListLabel_public,
192                                 const char *            i_sListLabel_protected,
193                                 const char *            i_sListLabel_private,
194                                 const char *            i_sListTitle )
195 {
196 	ary::Slot_AutoPtr
197             pSlot( ActiveParent().Create_Slot(i_nSlot) );
198     if ( pSlot->Size() == 0 )
199         return;
200 
201     aMemberAreas[ixPublic] = new S_AreaCo( o_rResult_public,
202                                          i_sListLabel_public,
203                                          i_sListTitle );
204     aMemberAreas[ixProtected] = new S_AreaCo( o_rResult_protected,
205                                             i_sListLabel_protected,
206                                             i_sListTitle );
207     aMemberAreas[ixPrivate] = new S_AreaCo( o_rResult_private,
208                                           i_sListLabel_private,
209                                           i_sListTitle );
210 
211     pSlot->StoreAt(*this);
212 
213     aMemberAreas[ixPublic]->PerformResult();
214     aMemberAreas[ixProtected]->PerformResult();
215     aMemberAreas[ixPrivate]->PerformResult();
216 
217     aMemberAreas[ixPublic] = 0;
218     aMemberAreas[ixProtected] = 0;
219     aMemberAreas[ixPrivate] = 0;
220 }
221 
222 void
223 ChildList_Display::Run_MemberClasses( Area_Result &         o_rResult_public,
224                                       Area_Result &         o_rResult_protected,
225                                       Area_Result &         o_rResult_private,
226                                       ary::SlotAccessId     i_nSlot,
227                                       const char *          i_sListLabel_public,
228                                       const char *          i_sListLabel_protected,
229                                       const char *          i_sListLabel_private,
230                                       const char *          i_sListTitle,
231                                       ary::cpp::E_ClassKey  i_eFilter )
232 {
233 	ary::Slot_AutoPtr
234             pSlot( ActiveParent().Create_Slot(i_nSlot) );
235     if ( pSlot->Size() == 0 )
236         return;
237 
238     aMemberAreas[ixPublic] = new S_AreaCo( o_rResult_public,
239                                            i_sListLabel_public,
240                                            i_sListTitle );
241     aMemberAreas[ixProtected] = new S_AreaCo( o_rResult_protected,
242                                               i_sListLabel_protected,
243                                               i_sListTitle );
244     aMemberAreas[ixPrivate] = new S_AreaCo( o_rResult_private,
245                                             i_sListLabel_private,
246                                             i_sListTitle );
247 
248     SetClassesFilter(i_eFilter);
249     pSlot->StoreAt(*this);
250     UnsetClassesFilter();
251 
252     aMemberAreas[ixPublic]->PerformResult();
253     aMemberAreas[ixProtected]->PerformResult();
254     aMemberAreas[ixPrivate]->PerformResult();
255 
256     aMemberAreas[ixPublic] = 0;
257     aMemberAreas[ixProtected] = 0;
258     aMemberAreas[ixPrivate] = 0;
259 }
260 
261 void
262 ChildList_Display::do_Process( const ary::cpp::Namespace & i_rData )
263 {
264     Write_ListItem( i_rData.LocalName(),
265                     Path2ChildNamespace(i_rData.LocalName()),
266                     ShortDocu( i_rData ),
267                     GetArea().GetTable() );
268 }
269 
270 void
271 ChildList_Display::do_Process( const ary::cpp::Class & i_rData )
272 {
273     if ( Ce_IsInternal(i_rData) )
274         return;
275 
276     if (peClassesFilter)
277     {
278      	if (*peClassesFilter != i_rData.ClassKey() )
279             return;
280     }
281 
282     String  sLink;
283     if ( i_rData.Protection() == ary::cpp::PROTECT_global )
284     {
285         sLink = ClassFileName(i_rData.LocalName());
286 
287     }
288     else
289     {
290         csv_assert( pActiveParentClass != 0 );
291         sLink = Path2Child( ClassFileName(i_rData.LocalName()), pActiveParentClass->LocalName() );
292     }
293 
294     if (peClassesFilter)
295     {
296         Write_ListItem( i_rData.LocalName(),
297                         sLink,
298                         ShortDocu( i_rData ),
299                         GetArea(i_rData.Protection())
300                             .GetTable() );
301     }
302     else
303     {
304         Write_ListItem( i_rData.LocalName(),
305                         sLink,
306                         ShortDocu( i_rData ),
307                         GetArea(i_rData.Protection())
308                             .GetTable(i_rData.ClassKey()) );
309     }
310 }
311 
312 void
313 ChildList_Display::do_Process( const ary::cpp::Enum & i_rData )
314 {
315     if ( Ce_IsInternal(i_rData) )
316         return;
317 
318     String  sLink;
319     if ( i_rData.Protection() == ary::cpp::PROTECT_global )
320     {
321         sLink = EnumFileName(i_rData.LocalName());
322     }
323     else
324     {
325         csv_assert( pActiveParentClass != 0 );
326         sLink = Path2Child( EnumFileName(i_rData.LocalName()),
327                             pActiveParentClass->LocalName() );
328     }
329 
330     Write_ListItem( i_rData.LocalName(),
331                     sLink,
332                     ShortDocu( i_rData ),
333                     GetArea(i_rData.Protection()).GetTable() );
334 }
335 
336 void
337 ChildList_Display::do_Process( const ary::cpp::Typedef & i_rData )
338 {
339     if ( Ce_IsInternal(i_rData) )
340         return;
341 
342     String  sLink;
343     if ( i_rData.Protection() == ary::cpp::PROTECT_global )
344     {
345         sLink = TypedefFileName(i_rData.LocalName());
346     }
347     else
348     {
349         csv_assert( pActiveParentClass != 0 );
350         sLink = Path2Child( TypedefFileName(i_rData.LocalName()),
351                             pActiveParentClass->LocalName() );
352     }
353 
354     Write_ListItem( i_rData.LocalName(),
355                     sLink,
356                     ShortDocu( i_rData ),
357                     GetArea(i_rData.Protection()).GetTable() );
358 }
359 
360 void
361 ChildList_Display::do_Process( const ary::cpp::Function & i_rData )
362 {
363     if ( Ce_IsInternal(i_rData) )
364         return;
365 
366     String  sLinkPrePath;
367     if ( i_rData.Protection() == ary::cpp::PROTECT_global )
368     {
369         const ary::loc::File &
370                 rFile = Env().Gate().Locations().Find_File( i_rData.Location() );
371         sLinkPrePath = HtmlFileName( "o-", rFile.LocalName() );
372     }
373     else
374     {
375         csv_assert( pActiveParentClass != 0 );
376         sLinkPrePath = Path2Child( HtmlFileName( "o", "" ),
377                                    pActiveParentClass->LocalName() );
378     }
379 
380     // Out
381     Table & rOut = GetArea(i_rData.Protection()).GetTable();
382     TableRow * dpRow = new TableRow;
383     rOut << dpRow;
384     TableCell & rCell1 = dpRow->AddCell();
385 
386     rCell1
387         << SyntaxText_PreName( i_rData, Env().Gate() )
388         << new html::LineBreak;
389     rCell1
390         >> *new html::Link( OperationLink(
391                                 Env().Gate(),
392                                 i_rData.LocalName(),
393                                 i_rData.CeId(),
394                                 sLinkPrePath) )
395             << i_rData.LocalName();
396     rCell1
397         << SyntaxText_PostName( i_rData, Env().Gate() );
398     TableCell &
399         rCell2 = dpRow->AddCell();
400     rCell2
401         << new WidthAttr("50%")
402         << " ";
403 
404     pShortDocu_Display->Assign_Out( rCell2 );
405     ShortDocu( i_rData ).StoreAt( *pShortDocu_Display );
406     pShortDocu_Display->Unassign_Out();
407 }
408 
409 void
410 ChildList_Display::do_Process( const ary::cpp::Variable & i_rData )
411 {
412     if ( Ce_IsInternal(i_rData) )
413         return;
414 
415     String  sLinkPrePath;
416     if ( i_rData.Protection() == ary::cpp::PROTECT_global )
417     {
418         const ary::loc::File &
419             rFile = Env().Gate().Locations().Find_File( i_rData.Location() );
420         sLinkPrePath = HtmlFileName( "d-", rFile.LocalName() );
421     }
422     else
423     {
424         csv_assert( pActiveParentClass != 0 );
425         sLinkPrePath = Path2Child( HtmlFileName( "d", "" ),
426                                    pActiveParentClass->LocalName() );
427     }
428 
429     TableRow * dpRow = new TableRow;
430     GetArea(i_rData.Protection()).GetTable() << dpRow;
431 
432     *dpRow << new html::BgColorAttr("white");
433     csi::xml::Element &
434         rCell1 = dpRow->AddCell();
435 
436     dshelp::Get_LinkedTypeText( rCell1, Env(), i_rData.Type() );
437     rCell1
438         << " "
439         >> *new html::Link( DataLink(i_rData.LocalName(), sLinkPrePath.c_str()) )
440             >> *new html::Strong
441                 << i_rData.LocalName()
442                 << ";";
443 
444     TableCell & rShortDocu = dpRow->AddCell();
445     pShortDocu_Display->Assign_Out( rShortDocu );
446     ShortDocu( i_rData ).StoreAt( *pShortDocu_Display );
447     pShortDocu_Display->Unassign_Out();
448 }
449 
450 void
451 ChildList_Display::do_Process( const ary::cpp::EnumValue & i_rData )
452 {
453     if ( Ce_IsInternal(i_rData) )
454         return;
455 
456     Table & rOut = GetArea().GetTable();
457 
458     TableRow * dpRow = new TableRow;
459     rOut << dpRow;
460 
461     *dpRow << new html::BgColorAttr("white");
462     dpRow->AddCell()
463         << new WidthAttr("20%")
464         << new xml::AnAttribute("valign", "top")
465         >> *new html::Label(i_rData.LocalName())
466             >> *new html::Bold
467                 << i_rData.LocalName();
468 
469     TableCell & rValueDocu = dpRow->AddCell();
470     pShortDocu_Display->Assign_Out( rValueDocu );
471     i_rData.Docu().Accept( *pShortDocu_Display );
472     pShortDocu_Display->Unassign_Out();
473 }
474 
475 void
476 ChildList_Display::do_StartSlot()
477 {
478 }
479 
480 void
481 ChildList_Display::do_FinishSlot()
482 {
483 }
484 
485 const ary::cpp::Gate *
486 ChildList_Display::inq_Get_ReFinder() const
487 {
488     return & Env().Gate();
489 }
490 
491 void
492 ChildList_Display::Write_ListItem( const String &               i_sLeftText,
493                                    const char *                 i_sLink,
494                                    const ary::info::DocuText &  i_rRightText,
495                                    csi::xml::Element &          o_rOut )
496 {
497     TableRow * dpRow = new TableRow;
498     o_rOut << dpRow;
499 
500     *dpRow << new html::BgColorAttr("white");
501     dpRow->AddCell()
502         << new WidthAttr("20%")
503         >> *new html::Link( i_sLink )
504                 >> *new html::Bold
505                         << i_sLeftText;
506 
507     TableCell & rShortDocu = dpRow->AddCell();
508     pShortDocu_Display->Assign_Out( rShortDocu );
509     i_rRightText.StoreAt( *pShortDocu_Display );
510     pShortDocu_Display->Unassign_Out();
511 }
512 
513 const ary::AryGroup &
514 ChildList_Display::ActiveParent()
515 {
516     return pActiveParentClass != 0
517                 ?   static_cast< const ary::AryGroup& >(*pActiveParentClass)
518                 :   pActiveParentEnum != 0
519                         ?   static_cast< const ary::AryGroup& >(*pActiveParentEnum)
520                         :   static_cast< const ary::AryGroup& >(*Env().CurNamespace());
521 }
522 
523 ProtectionArea &
524 ChildList_Display::GetArea()
525 {
526     return pSglArea->aArea;
527 }
528 
529 ProtectionArea &
530 ChildList_Display::GetArea( ary::cpp::E_Protection i_eProtection )
531 {
532     switch ( i_eProtection )
533     {
534      	case ary::cpp::PROTECT_public:
535                         return aMemberAreas[ixPublic]->aArea;
536      	case ary::cpp::PROTECT_protected:
537                         return aMemberAreas[ixProtected]->aArea;
538      	case ary::cpp::PROTECT_private:
539                         return aMemberAreas[ixPrivate]->aArea;
540         default:
541                         return pSglArea->aArea;
542     }
543 }
544 
545 
546 //*******************               ********************//
547 
548 ChildList_Display::
549 S_AreaCo::S_AreaCo( Area_Result &       o_rResult,
550                     const char *        i_sLabel,
551                     const char *        i_sTitle )
552     :   aArea(i_sLabel, i_sTitle),
553         pResult(&o_rResult)
554 {
555 }
556 
557 ChildList_Display::
558 S_AreaCo::~S_AreaCo()
559 {
560 }
561 
562 void
563 ChildList_Display::
564 S_AreaCo::PerformResult()
565 {
566     bool bUsed = aArea.WasUsed_Area();
567     pResult->rChildrenExist = bUsed;
568     if ( bUsed )
569     {
570         Create_ChildListLabel( Out(), aArea.Label() );
571 
572         if ( aArea.Size() == 1 )
573         {
574             Out() << aArea.ReleaseTable();
575         }
576         else
577         {
578          	Table * pTable = aArea.ReleaseTable( ary::cpp::CK_class );
579             if (pTable != 0)
580                 Out() << pTable;
581          	pTable = aArea.ReleaseTable( ary::cpp::CK_struct );
582             if (pTable != 0)
583                 Out() << pTable;
584          	pTable = aArea.ReleaseTable( ary::cpp::CK_union );
585             if (pTable != 0)
586                 Out() << pTable;
587         }
588     }
589 }
590