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 "hfi_interface.hxx"
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <ary/idl/i_ce.hxx>
34 #include <ary/idl/i_gate.hxx>
35 #include <ary/idl/ik_function.hxx>
36 #include <ary/idl/ik_interface.hxx>
37 #include <ary/idl/ip_ce.hxx>
38 #include <ary/idl/ip_type.hxx>
39 #include <toolkit/hf_docentry.hxx>
40 #include <toolkit/hf_linachain.hxx>
41 #include <toolkit/hf_navi_sub.hxx>
42 #include <toolkit/hf_title.hxx>
43 #include "hfi_doc.hxx"
44 #include "hfi_hierarchy.hxx"
45 #include "hfi_method.hxx"
46 #include "hfi_navibar.hxx"
47 #include "hfi_property.hxx"
48 #include "hfi_tag.hxx"
49 #include "hfi_typetext.hxx"
50 #include "hi_linkhelper.hxx"
51 
52 
53 extern const String
54     C_sCePrefix_Interface("interface");
55 
56 namespace
57 {
58 
59 const String
60     C_sBaseInterface("Base Interfaces");
61 const String
62     C_sList_BaseComments("Comments on Base Interfaces");
63 const String
64     C_sList_Methods("Methods' Summary");
65 const String
66     C_sList_Methods_Label("MethodsSummary");
67 const String
68     C_sDetails_Methods("Methods' Details");
69 const String
70     C_sDetails_Methods_Label("MethodsDetails");
71 
72 const String
73     C_sList_Attributes("Attributes' Summary");
74 const String
75     C_sList_Attributes_Label("AttributesSummary");
76 const String
77     C_sList_AttributesDetails("Attributes' Details");
78 const String
79     C_sList_AttributesDetails_Label("AttributesDetails");
80 
81 
82 
83 enum E_SubListIndices
84 {
85     sli_MethodsSummay = 0,
86     sli_AttributesSummary = 1,
87     sli_MethodDetails = 2,
88     sli_AttributesDetails = 3
89 };
90 
91 } //anonymous namespace
92 
93 
94 
95 
96 HF_IdlInterface::HF_IdlInterface( Environment &         io_rEnv,
97                                   Xml::Element &        o_rOut )
98     :   HtmlFactory_Idl(io_rEnv, &o_rOut),
99         eCurProducedMembers(mem_none)
100 {
101 }
102 
103 HF_IdlInterface::~HF_IdlInterface()
104 {
105 }
106 
107 void
108 HF_IdlInterface::Produce_byData( const client & i_ce ) const
109 {
110     Dyn<HF_NaviSubRow>
111         pNaviSubRow( &make_Navibar(i_ce) );
112 
113     HF_TitleTable
114         aTitle(CurOut());
115 
116     HF_LinkedNameChain
117         aNameChain(aTitle.Add_Row());
118     aNameChain.Produce_CompleteChain(Env().CurPosition(), nameChainLinker);
119 
120     produce_Title(aTitle, C_sCePrefix_Interface, i_ce);
121 
122     produce_BaseHierarchy( aTitle.Add_Row(),
123 						   i_ce,
124 						   C_sBaseInterface );
125 
126     write_Docu(aTitle.Add_Row(), i_ce);
127     CurOut() << new Html::HorizontalLine();
128 
129     dyn_ce_list dpFunctions;
130     ary::idl::ifc_interface::attr::Get_Functions(dpFunctions, i_ce);
131     if ( (*dpFunctions).operator bool() )
132     {
133         eCurProducedMembers = mem_Functions;
134 
135         produce_Members( *dpFunctions,
136                          C_sList_Methods,
137                          C_sList_Methods_Label,
138                          C_sDetails_Methods,
139                          C_sDetails_Methods_Label,
140                          HtmlFactory_Idl::viewtype_summary );
141         pNaviSubRow->SwitchOn(sli_MethodsSummay);
142     }
143 
144     dyn_ce_list
145         dpAttributes;
146     ary::idl::ifc_interface::attr::Get_Attributes(dpAttributes, i_ce);
147     if ( (*dpAttributes).operator bool() )
148     {
149         eCurProducedMembers = mem_Attributes;
150 
151         produce_Members( *dpAttributes,
152                          C_sList_Attributes,
153                          C_sList_Attributes_Label,
154                          C_sList_AttributesDetails,
155                          C_sList_AttributesDetails_Label,
156                          HtmlFactory_Idl::viewtype_summary );
157         pNaviSubRow->SwitchOn(sli_AttributesSummary);
158     }
159 
160     ary::idl::ifc_interface::attr::Get_Functions(dpFunctions, i_ce);
161     if ( (*dpFunctions).operator bool() )
162     {
163         eCurProducedMembers = mem_Functions;
164 
165         produce_Members( *dpFunctions,
166                          C_sList_Methods,
167                          C_sList_Methods_Label,
168                          C_sDetails_Methods,
169                          C_sDetails_Methods_Label,
170                          HtmlFactory_Idl::viewtype_details );
171         pNaviSubRow->SwitchOn(sli_MethodDetails);
172     }
173 
174     ary::idl::ifc_interface::attr::Get_Attributes(dpAttributes, i_ce);
175     if ( (*dpAttributes).operator bool() )
176     {
177         eCurProducedMembers = mem_Attributes;
178 
179         produce_Members( *dpAttributes,
180                          C_sList_Attributes,
181                          C_sList_Attributes_Label,
182                          C_sList_AttributesDetails,
183                          C_sList_AttributesDetails_Label,
184                          HtmlFactory_Idl::viewtype_details );
185         pNaviSubRow->SwitchOn(sli_AttributesDetails);
186     }
187 
188     eCurProducedMembers = mem_none;
189 
190     pNaviSubRow->Produce_Row();
191 }
192 
193 DYN HF_NaviSubRow &
194 HF_IdlInterface::make_Navibar( const client & i_ce ) const
195 {
196     HF_IdlNavigationBar
197         aNaviBar(Env(), CurOut());
198     aNaviBar.Produce_CeMainRow(i_ce);
199 
200     DYN HF_NaviSubRow &
201         ret = aNaviBar.Add_SubRow();
202     ret.AddItem(C_sList_Methods, C_sList_Methods_Label, false);
203     ret.AddItem(C_sList_Attributes, C_sList_Attributes_Label, false);
204     ret.AddItem(C_sDetails_Methods, C_sDetails_Methods_Label, false);
205     ret.AddItem(C_sList_AttributesDetails, C_sList_AttributesDetails_Label, false);
206 
207     CurOut() << new Html::HorizontalLine();
208     return ret;
209 }
210 
211 void
212 HF_IdlInterface::produce_MemberDetails( HF_SubTitleTable &  o_table,
213                                         const client &      i_ce ) const
214 {
215     switch (eCurProducedMembers)
216     {
217         case mem_Functions:
218                     break;
219         case mem_Attributes:
220         {
221                     HF_IdlAttribute
222                         aAttribute( Env(), o_table);
223                     aAttribute.Produce_byData( i_ce );
224                     return;
225         };
226         default:    //Won't happen.
227                     return;
228     }   // end switch
229 
230     typedef ary::idl::ifc_function::attr    funcAttr;
231 
232     HF_IdlMethod
233         aFunction(  Env(),
234                     o_table.Add_Row()
235                         >> *new Html::TableCell
236                            << new Html::ClassAttr(C_sCellStyle_MDetail) );
237 
238     ary::Dyn_StdConstIterator<ary::idl::Parameter>
239         pParameters;
240     funcAttr::Get_Parameters(pParameters, i_ce);
241 
242     ary::Dyn_StdConstIterator<ary::idl::Type_id>
243         pExceptions;
244     funcAttr::Get_Exceptions(pExceptions, i_ce);
245 
246     aFunction.Produce_byData( i_ce.LocalName(),
247                               funcAttr::ReturnType(i_ce),
248                               *pParameters,
249                               *pExceptions,
250                               funcAttr::IsOneway(i_ce),
251                               funcAttr::HasEllipse(i_ce),
252                               i_ce );
253 }
254 
255 void
256 HF_IdlInterface::produce_BaseHierarchy( Xml::Element &      o_screen,
257 										const client &      i_ce,
258 										const String &      i_sLabel ) const
259 {
260     ary::Dyn_StdConstIterator<ary::idl::CommentedRelation>
261         pHelp;
262     ary::idl::ifc_interface::attr::Get_Bases(pHelp, i_ce);
263     if (NOT (*pHelp).operator bool())
264         return;
265 
266     // Check for XInterface as only base:
267     ary::StdConstIterator<ary::idl::CommentedRelation> &
268         itTest = *pHelp;
269     ary::idl::Ce_id
270         nCe = Env().Gate().Types().Search_CeRelatedTo((*itTest).Type());
271     if (nCe.IsValid())
272     {
273         // KORR_FUTURE
274         //   Rather check for id(!) of com::sun::star::uno::XInterface.
275         if (Env().Gate().Ces().Find_Ce(nCe).LocalName() == "XInterface")
276         {
277             ++itTest;
278             if (NOT itTest.operator bool())
279                 return;
280         }
281     }
282 
283     // Write hierarchy:
284 
285     HF_DocEntryList
286         aDocList( o_screen );
287     aDocList.Produce_Term(i_sLabel);
288     Xml::Element &
289         rBaseList = aDocList.Produce_Definition();
290 
291 // NEW
292     Write_BaseHierarchy(rBaseList, Env(), i_ce);
293 
294     // Write comments:
295         // KORR_FUTURE: Make sure, no empty table is constructed when comments list is empty.
296     HF_SubTitleTable
297         aBaseTable( aDocList.Produce_Definition(),
298                 "",
299                 C_sList_BaseComments,
300                 2,
301                 HF_SubTitleTable::sublevel_3 );
302 
303     ary::Dyn_StdConstIterator<ary::idl::CommentedRelation>
304         pBases;
305     ary::idl::ifc_interface::attr::Get_Bases(pBases, i_ce);
306     for ( ary::StdConstIterator<ary::idl::CommentedRelation> & it = *pBases;
307           it.operator bool();
308           ++it )
309     {
310         Xml::Element &
311             rRow = aBaseTable.Add_Row();
312 
313         Xml::Element &
314             rTerm = rRow
315                         >> *new Html::TableCell
316                             << new Html::ClassAttr(C_sCellStyle_SummaryLeft);
317         HF_IdlTypeText
318             aTypeDisplay( Env(), rTerm, false, 0);
319         aTypeDisplay.Produce_byData((*it).Type());
320 
321         Xml::Element &
322             rDocu = rRow
323                         >> *new Html::TableCell
324                             << new Html::ClassAttr(C_sCellStyle_SummaryRight);
325 
326         HF_DocEntryList
327             aDocuList(rDocu);
328 
329         if ((*it).Info() != 0)
330         {
331 //          aDocuList.Produce_Term("Comment on Base Reference");
332 
333             HF_IdlDocu
334                 aDocuDisplay(Env(), aDocuList);
335             aDocuDisplay.Produce_fromReference(*(*it).Info(), i_ce);
336         }
337         else
338         {
339             const client *
340                 pCe = Env().Linker().Search_CeFromType((*it).Type());
341             const ce_info *
342                 pShort = pCe != 0
343                             ?   Get_IdlDocu(pCe->Docu())
344                             :   (const ce_info *)(0);
345             if ( pShort != 0 )
346             {
347                 aDocuList.Produce_NormalTerm("(referenced interface's summary:)");
348 
349                 Xml::Element &
350                     rDef = aDocuList.Produce_Definition();
351                 HF_IdlDocuTextDisplay
352                     aShortDisplay( Env(), &rDef, *pCe);
353                 pShort->Short().DisplayAt(aShortDisplay);
354             }   // end if (pShort != 0)
355         }   // endif ( (*i_commentedRef).Info() != 0 ) else
356     }   // end for
357 }
358