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 "hi_factory.hxx"
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <ary/idl/i_ce.hxx>
34 #include <toolkit/hf_title.hxx>
35 #include "hfi_doc.hxx"
36 #include "hfi_navibar.hxx"
37 #include "hfi_tag.hxx"
38 #include "hfi_typetext.hxx"
39 #include "hi_linkhelper.hxx"
40 
41 
42 extern const String
43     C_sCellStyle_SummaryLeft("imsum_left");
44 extern const String
45     C_sCellStyle_SummaryRight("imsum_right");
46 extern const String
47     C_sCellStyle_MDetail("imdetail");
48 extern const String
49     C_sMemberTitle("membertitle");
50 
51 
52 namespace
53 {
54 
55 const char C_sSpace[92] = "                              "
56                           "                              "
57                           "                               ";
58 }
59 
60 
61 void
62 HtmlFactory_Idl::produce_SummaryDeclaration( Xml::Element &      o_row,
63 											 const client &      i_ce ) const
64 {
65     produce_InternalLink(o_row, i_ce);
66 }
67 
68 void
69 HtmlFactory_Idl::produce_InternalLink( Xml::Element &  o_screen,
70                                        const client &  i_ce ) const
71 {
72     StreamLock aLocalLink(100);
73     aLocalLink() << "#" << i_ce.LocalName();
74 
75     o_screen
76         >> *new Html::TableCell
77             << new Html::ClassAttr( C_sCellStyle_SummaryLeft )
78             >> *new Html::Link( aLocalLink().c_str() )
79                 << i_ce.LocalName();
80 }
81 
82 void
83 HtmlFactory_Idl::produce_ShortDoc( Xml::Element &   o_screen,
84                                    const client &   i_ce ) const
85 {
86     Xml::Element &
87         rDetailsRowCell = o_screen
88                             >> *new Html::TableCell
89                                 << new Html::ClassAttr( C_sCellStyle_SummaryRight );
90     HF_IdlShortDocu
91         aLinkDoc(Env(), rDetailsRowCell);
92     aLinkDoc.Produce_byData( i_ce );
93 
94     rDetailsRowCell << new Xml::XmlCode("&nbsp;");
95 }
96 
97 // KORR_FUTURE: Does not belong here (implementation inheritance)!
98 void
99 HtmlFactory_Idl::produce_Bases( Xml::Element &   o_screen,
100                                 const client &   i_ce,
101                                 const String &   i_sLabel ) const
102 {
103     ary::idl::Type_id nBaseT = baseOf(i_ce);
104     if ( nBaseT.IsValid() )
105     {
106         HF_DocEntryList
107             aDocList( o_screen );
108         aDocList.Produce_Term(i_sLabel);
109 
110         int nDepth = 0;
111         Xml::Element &
112             rBaseList = aDocList.Produce_Definition()
113                                 >> *new Xml::AnElement("pre")
114                                     << new Xml::AnAttribute("style","font-family:monospace;");
115         rBaseList
116             >> *new Html::Strong
117                 << i_ce.LocalName();
118         rBaseList
119             << "\n";
120         recursive_ShowBases( rBaseList,
121                              nBaseT,
122                              nDepth );
123     }
124 }
125 
126 void
127 HtmlFactory_Idl::produce_Members( ce_list &               it_list,
128                                   const String &          i_summaryTitle,
129                                   const String &          i_summaryLabel,
130                                   const String &          i_detailsTitle,
131                                   const String &          i_detailsLabel,
132                                   const E_MemberViewType  i_viewType ) const
133 {
134     csv_assert( it_list );
135 
136     Dyn< HF_SubTitleTable > pSummary;
137     if  (   ( i_viewType == viewtype_summary )
138         ||  ( i_viewType == viewtype_complete )
139         )
140     {
141         pSummary = new HF_SubTitleTable(
142                 CurOut(),
143                 i_summaryLabel,
144                 i_summaryTitle,
145                 2 );
146     }
147 
148     Dyn< HF_SubTitleTable > pDetails;
149     if  (   ( i_viewType == viewtype_details )
150         ||  ( i_viewType == viewtype_complete )
151         )
152     {
153         pDetails = new HF_SubTitleTable(
154                 CurOut(),
155                 i_detailsLabel,
156                 i_detailsTitle,
157                 1 );
158     }
159 
160     for ( ; it_list.operator bool(); ++it_list )
161     {
162         const ary::idl::CodeEntity &
163             rCe = Env().Data().Find_Ce(*it_list);
164 
165         if ( pSummary )
166         {
167             Xml::Element &
168                 rSummaryRow = pSummary->Add_Row();
169             produce_SummaryDeclaration(rSummaryRow, rCe);
170 //            produce_InternalLink(rSummaryRow, rCe);
171             produce_ShortDoc(rSummaryRow, rCe);
172         }
173 
174         if ( pDetails )
175             produce_MemberDetails(*pDetails, rCe);
176     }
177 }
178 
179 void
180 HtmlFactory_Idl::produce_Title( HF_TitleTable &     o_title,
181                                 const String &      i_label,
182                                 const client &      i_ce ) const
183 {
184     StreamLock
185         slAnnotations(200);
186     get_Annotations(slAnnotations(), i_ce);
187     StreamLock
188         slTitle(200);
189     slTitle() << i_label << " " << i_ce.LocalName();
190     o_title.Produce_Title( slAnnotations().c_str(),
191                            slTitle().c_str() );
192 }
193 
194 void
195 HtmlFactory_Idl::get_Annotations( StreamStr &         o_out,
196                                   const client &      i_ce ) const
197 {
198     const ary::doc::OldIdlDocu *
199         doc = Get_IdlDocu(i_ce.Docu());
200     if (doc != 0)
201     {
202         if (doc->IsDeprecated())
203             o_out << "deprecated ";
204         if (NOT doc->IsPublished())
205             o_out << "unpublished ";
206     }
207 
208     // KORR
209     //  Need to display "unpublished", if there is no docu.
210 }
211 
212 void
213 HtmlFactory_Idl::write_Docu( Xml::Element &     o_screen,
214                              const client &     i_ce ) const
215 {
216     const ary::doc::OldIdlDocu *
217         doc = Get_IdlDocu(i_ce.Docu());
218     if (doc != 0)
219     {
220         HF_DocEntryList
221             aDocuList( o_screen );
222         HF_IdlDocu
223             aDocu( Env(), aDocuList );
224         aDocu.Produce_fromCodeEntity(i_ce);
225     }
226 
227     write_ManualLinks(o_screen, i_ce);
228 }
229 
230 void
231 HtmlFactory_Idl::write_ManualLinks( Xml::Element &  o_screen,
232                                     const client &  i_ce ) const
233 {
234     const StringVector &
235         rLinks2Descrs = i_ce.Secondaries().Links2DescriptionInManual();
236     if ( rLinks2Descrs.size() == 0 )
237         return;
238 
239     o_screen
240         >> *new Html::Label(C_sLocalManualLinks.c_str()+1)  // Leave out the leading '#'.
241             << " ";
242     HF_DocEntryList
243         aDocuList( o_screen );
244     aDocuList.Produce_Term("Developers Guide");
245     csv_assert(rLinks2Descrs.size() % 2 == 0);
246     for ( StringVector::const_iterator it = rLinks2Descrs.begin();
247           it != rLinks2Descrs.end();
248           ++it )
249     {
250         Xml::Element &
251             rLink = aDocuList.Produce_Definition() >> *new Html::Link( Env().Link2Manual(*it));
252         if ( (*(it+1)).empty() )
253             // HACK KORR_FUTURE
254             // Research what happens with manual links which contain normal characters
255             // in non-utf-8 texts. And research, why utfF-8 does not work here.
256             rLink << new Xml::XmlCode(*it);
257         else
258             rLink << new Xml::XmlCode( *(it+1) );
259         ++it;
260     }   // end for
261 }
262 
263 void
264 HtmlFactory_Idl::produce_MemberDetails(  HF_SubTitleTable &  ,
265                                          const client &      ) const
266 {
267     // Dummy, which does not need to do anything.
268 }
269 
270 void
271 HtmlFactory_Idl::recursive_ShowBases( Xml::Element &     o_screen,
272                                       type_id            i_baseType,
273                                       int &              io_nDepth ) const
274 {
275     // Show this base
276     ++io_nDepth;
277     const ary::idl::CodeEntity *
278         pCe = Env().Linker().Search_CeFromType(i_baseType);
279 
280     csv_assert(io_nDepth > 0);
281     if (io_nDepth > 30)
282         io_nDepth = 30;
283     o_screen
284         << (C_sSpace + 93 - 3*io_nDepth)
285         << new csi::xml::XmlCode("&#x2517")
286         << " ";
287 
288     if (pCe == 0)
289     {
290         HF_IdlTypeText
291             aText( Env(), o_screen, false );
292         aText.Produce_byData( i_baseType );
293         o_screen
294             << "\n";
295         --io_nDepth;
296         return;
297     }
298 
299     HF_IdlTypeText
300         aBaseLink( Env(), o_screen, true );
301     aBaseLink.Produce_byData(pCe->CeId());
302     o_screen
303         << "\n";
304 
305     // Bases
306     ary::idl::Type_id
307         nBaseT = baseOf(*pCe);
308     if (nBaseT.IsValid())
309         recursive_ShowBases(o_screen,nBaseT,io_nDepth);
310 
311     --io_nDepth;
312     return;
313 }
314 
315 HtmlFactory_Idl::type_id
316 HtmlFactory_Idl::inq_BaseOf( const client & ) const
317 {
318     // Unused dummy.
319     return type_id(0);
320 }
321 
322