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_xrefpage.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/ip_ce.hxx>
36 #include <toolkit/hf_title.hxx>
37 #include "hfi_navibar.hxx"
38 #include "hfi_typetext.hxx"
39 #include "hi_env.hxx"
40 
41 
42 namespace
43 {
44 
45 const String
46     C_sTitleStart("uses of ");
47 const String
48     C_sCRLF("\n");
49 const String
50     C_sDevMan("References in Developers Guide");
51 
52 }   // anonymous namespace
53 
54 
55 
56 HF_IdlXrefs::HF_IdlXrefs( Environment &         io_rEnv,
57                           Xml::Element &        o_rOut,
58                           const String &        i_prefix,
59                           const client &        i_ce )
60     :   HtmlFactory_Idl(io_rEnv, &o_rOut),
61         rContentDirectory(*new Html::Paragraph),
62         pClient(&i_ce)
63 {
64     produce_Main(i_prefix, i_ce);
65 }
66 
67 HF_IdlXrefs::~HF_IdlXrefs()
68 {
69 }
70 
71 void
72 HF_IdlXrefs::Write_ManualLinks( const client &  i_ce ) const
73 {
74     const StringVector &
75         rLinks2Refs = i_ce.Secondaries().Links2RefsInManual();
76     if ( rLinks2Refs.size() == 0 )
77     {
78         rContentDirectory
79             << C_sDevMan
80             << new Html::LineBreak
81             << C_sCRLF;
82         return;
83     }
84 
85 
86     rContentDirectory
87         >> *new Html::Link("#devmanrefs")
88             << C_sDevMan
89             << new Html::LineBreak
90             << C_sCRLF;
91 
92     HF_SubTitleTable
93         aList(CurOut(), "devmanrefs", C_sDevMan, 1);
94     Xml::Element &
95         rOutCell = aList.Add_Row() >>* new Html::TableCell;
96 
97     csv_assert(rLinks2Refs.size() % 2 == 0);
98     for ( StringVector::const_iterator it = rLinks2Refs.begin();
99           it != rLinks2Refs.end();
100           ++it )
101     {
102         Xml::Element &
103             rLink = rOutCell >> *new Html::Link( Env().Link2Manual(*it));
104         if ( (*(it+1)).empty() )
105 
106             // HACK KORR_FUTURE
107             // Research what happens with manual links which contain normal characters
108             // in non-utf-8 texts. And research, why utfF-8 does not work here.
109             rLink << new Xml::XmlCode(*it);
110         else
111             // HACK KORR_FUTURE, see above.
112             rLink << new Xml::XmlCode( *(it+1) );
113         rOutCell
114             << new Html::LineBreak
115             << C_sCRLF;
116         ++it;
117     }   // end for
118 }
119 
120 void
121 HF_IdlXrefs::Produce_List( const char *        i_title,
122                            const char *        i_label,
123                            ce_list &           i_iterator ) const
124 {
125     if (NOT i_iterator)
126     {
127         rContentDirectory
128             << i_title
129             << new Html::LineBreak
130             << C_sCRLF;
131         return;
132     }
133 
134     csv_assert(*i_label == '#');
135 
136     rContentDirectory
137         >> *new Html::Link(i_label)
138             << i_title
139             << new Html::LineBreak
140             << C_sCRLF;
141 
142     HF_SubTitleTable
143         aList(CurOut(), i_label+1, i_title, 1);
144     Xml::Element &
145         rOutCell = aList.Add_Row() >>* new Html::TableCell;
146     HF_IdlTypeText
147         aTypeWriter(Env(), rOutCell, true, pClient);
148     for ( ce_list & it = i_iterator; it; ++it )
149     {
150         aTypeWriter.Produce_byData(*it);
151         rOutCell << new Html::LineBreak;
152     }   // end for
153 }
154 
155 void
156 HF_IdlXrefs::Produce_Tree(  const char *        i_title,
157                             const char *        i_label,
158                             const client &      i_ce,
159                             F_GET_SUBLIST       i_sublistcreator ) const
160 {
161     dyn_ce_list pResult;
162     (*i_sublistcreator)(pResult, i_ce);
163 
164     if (NOT (*pResult).operator bool())
165     {
166         rContentDirectory
167             << i_title
168             << new Html::LineBreak
169             << C_sCRLF;
170         return;
171     }
172 
173     csv_assert(*i_label == '#');
174 
175     rContentDirectory
176         >> *new Html::Link(i_label)
177             << i_title
178             << new Html::LineBreak
179             << C_sCRLF;
180 
181     HF_SubTitleTable
182         aList(CurOut(), i_label+1, i_title, 1);
183     Xml::Element &
184         rOut = aList.Add_Row()
185                     >>* new Html::TableCell
186                         >> *new csi::xml::AnElement("pre")
187                             << new csi::html::StyleAttr("font-family:monospace;");
188 
189     recursive_make_ListInTree( rOut,
190 							   0,
191 							   i_ce,
192 							   *pResult,
193 							   i_sublistcreator );
194 }
195 
196 void
197 HF_IdlXrefs::produce_Main( const String &        i_prefix,
198                            const client &        i_ce ) const
199 {
200     make_Navibar(i_ce);
201 
202     HF_TitleTable
203         aTitle(CurOut());
204     StreamLock sl(200);
205     aTitle.Produce_Title( sl()
206 						  << C_sTitleStart
207 						  << i_prefix
208 						  << " "
209 						  << i_ce.LocalName()
210 						  << c_str );
211 
212     aTitle.Add_Row() << &rContentDirectory;
213     sl().reset();
214     rContentDirectory
215         >> *new Html::Link( sl()    << i_ce.LocalName()
216 						            << ".html"
217 						            << c_str )
218             >> *new Html::Bold
219                 << "back to "
220                 << i_prefix
221                 << " "
222                 << i_ce.LocalName();
223     rContentDirectory
224         << new Html::LineBreak
225         << new Html::LineBreak
226         << C_sCRLF;
227 
228     CurOut() << new Html::HorizontalLine();
229 }
230 
231 void
232 HF_IdlXrefs::make_Navibar( const client & i_ce ) const
233 {
234     HF_IdlNavigationBar
235         aNaviBar(Env(), CurOut());
236     aNaviBar.Produce_CeXrefsMainRow(i_ce);
237     CurOut() << new Html::HorizontalLine();
238 }
239 
240 void
241 HF_IdlXrefs::recursive_make_ListInTree( Xml::Element &      o_rDisplay,
242 										uintt               i_level,
243 										const client &      i_ce,
244 										ce_list &           i_iterator,
245 										F_GET_SUBLIST       i_sublistcreator ) const
246 {
247     const char * sLevelIndentation = "    ";
248 
249     HF_IdlTypeText
250         aTypeWriter(Env(), o_rDisplay, true, &i_ce);
251     for ( ; i_iterator.operator bool(); ++i_iterator )
252     {
253         for (uintt i = 0; i < i_level; ++i)
254         {
255             o_rDisplay << sLevelIndentation;
256         }   // end for
257 
258         aTypeWriter.Produce_byData(*i_iterator);
259         o_rDisplay << C_sCRLF;
260 
261         dyn_ce_list     pResult;
262         const client &  rCe = Env().Gate().Ces().Find_Ce(*i_iterator);
263         (*i_sublistcreator)(pResult, rCe);
264         if ( (*pResult).operator bool() )
265         {
266             recursive_make_ListInTree( o_rDisplay,
267 	    							   i_level + 1,
268 	    							   rCe,
269 		    						   *pResult,
270 			    					   i_sublistcreator );
271         }
272     }   // end for
273 }
274