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_method.hxx"
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <ary/idl/i_exception.hxx>
34 #include <ary/idl/i_param.hxx>
35 #include <toolkit/hf_docentry.hxx>
36 #include <toolkit/hf_funcdecl.hxx>
37 #include "hfi_doc.hxx"
38 #include "hfi_globalindex.hxx"
39 #include "hfi_typetext.hxx"
40 
41 
42 
43 
44 
45 HF_IdlMethod::HF_IdlMethod( Environment &           io_rEnv,
46                             Xml::Element &          o_cell)
47     :   HtmlFactory_Idl(io_rEnv,&o_cell)
48 {
49 }
50 
51 
52 HF_IdlMethod::~HF_IdlMethod()
53 {
54 }
55 
56 
57 void
58 HF_IdlMethod::Produce_byData( const String &      i_sName,
59                               type_id             i_nReturnType,
60                               param_list &        i_rParams,
61                               type_list &         i_rExceptions,
62                               bool                i_bOneway,
63                               bool                i_bEllipse,
64                               const client &      i_ce ) const
65 {
66     CurOut()
67         >> *new Html::Label(i_sName)
68             << new Html::ClassAttr(C_sMemberTitle)
69             << i_sName;
70     enter_ContentCell();
71     write_Declaration( i_sName,
72                        i_nReturnType,
73                        i_rParams,
74                        i_rExceptions,
75                        i_bOneway,
76                        i_bEllipse );
77     CurOut() << new Html::HorizontalLine;
78     write_Docu(CurOut(), i_ce);
79     leave_ContentCell();
80 }
81 
82 #if 0 // old
83 void
84 HF_IdlMethod::write_Declaration( const String &      i_sName,
85                                  type_id             i_nReturnType,
86                                  param_list &        i_rParams,
87                                  type_list &         i_rExceptions,
88                                  bool                i_bOneway,
89                                  bool				 i_bEllipse ) const
90 {
91     HF_FunctionDeclaration
92         aDecl(CurOut()) ;
93     Xml::Element &
94         front = aDecl.Add_ReturnLine();
95 
96     // Front:
97     if (i_bOneway)
98         front << "[oneway] ";
99     if (i_nReturnType.IsValid())
100     {   // Normal function, but not constructors:
101         HF_IdlTypeText
102             aReturn(Env(), front, true);
103         aReturn.Produce_byData(i_nReturnType);
104         front
105             << new Html::LineBreak;
106 
107     }
108     front
109         >> *new Html::Bold
110             << i_sName;
111 
112     //  Main line:
113     Xml::Element &
114         types = aDecl.Types();
115     Xml::Element &
116         names = aDecl.Names();
117     bool bParams = i_rParams.operator bool();
118     if (bParams)
119     {
120         front
121             << "(";
122         HF_IdlTypeText
123             aType( Env(), types, true );
124 
125         write_Param( aType, names, (*i_rParams) );
126 
127         for (++i_rParams; i_rParams; ++i_rParams)
128         {
129             types
130                 << new Html::LineBreak;
131             names
132                 << ","
133                 << new Html::LineBreak;
134             write_Param( aType, names, (*i_rParams) );
135         }   // end for
136 
137         if (i_bEllipse)
138         {
139             names
140                 << " ...";
141         }
142         names
143             << " )";
144     }
145     else
146         front
147             << "()";
148 
149 
150     if ( i_rExceptions.operator bool() )
151     {
152         Xml::Element &
153             rExcOut = aDecl.Add_RaisesLine("raises", NOT bParams);
154         HF_IdlTypeText
155             aExc(Env(), rExcOut, true);
156         aExc.Produce_byData(*i_rExceptions);
157 
158         for (++i_rExceptions; i_rExceptions; ++i_rExceptions)
159         {
160             rExcOut
161                 << ","
162                 << new Html::LineBreak;
163             aExc.Produce_byData(*i_rExceptions);
164         }   // end for
165 
166         rExcOut << " );";
167     }
168     else
169     {
170         if (bParams)
171             aDecl.Names() << ";";
172         else
173             aDecl.Front() << ";";
174     }
175 }
176 #endif   // 0  old
177 
178 void
179 HF_IdlMethod::write_Declaration( const String &      i_sName,
180                                  type_id             i_nReturnType,
181                                  param_list &        i_rParams,
182                                  type_list &         i_rExceptions,
183                                  bool                i_bOneway,
184                                  bool				 i_bEllipse ) const
185 {
186     HF_FunctionDeclaration
187         aDecl(CurOut(), "raises") ;
188     Xml::Element &
189         rReturnLine = aDecl.ReturnCell();
190 
191     // Return line:
192     if (i_bOneway)
193         rReturnLine << "[oneway] ";
194     if (i_nReturnType.IsValid())
195     {   // Normal function, but not constructors:
196         HF_IdlTypeText
197             aReturn(Env(), rReturnLine, true);
198         aReturn.Produce_byData(i_nReturnType);
199     }
200 
201     //  Main line:
202     Xml::Element &
203         rNameCell = aDecl.NameCell();
204     rNameCell
205         >> *new Html::Bold
206             << i_sName;
207 
208     Xml::Element *
209         pParamEnd  = 0;
210 
211     bool bParams = i_rParams.operator bool();
212     if (bParams)
213     {
214         rNameCell
215             << "(";
216 
217         pParamEnd  = write_Param( aDecl, *i_rParams );
218         for (++i_rParams; i_rParams; ++i_rParams)
219         {
220             *pParamEnd << ",";
221             pParamEnd  = write_Param( aDecl, *i_rParams );
222         }   // end for
223 
224         if (i_bEllipse)
225         {
226             Xml::Element &
227                 rParamType = aDecl.NewParamTypeCell();
228             rParamType
229                 << " ...";
230             pParamEnd = &rParamType;
231         }
232         *pParamEnd
233             << " )";
234     }
235     else
236     {
237         rNameCell
238             << "()";
239     }
240 
241     if ( i_rExceptions.operator bool() )
242     {
243         Xml::Element &
244             rExcOut = aDecl.ExceptionCell();
245         HF_IdlTypeText
246             aExc(Env(), rExcOut, true);
247         aExc.Produce_byData(*i_rExceptions);
248 
249         for (++i_rExceptions; i_rExceptions; ++i_rExceptions)
250         {
251             rExcOut
252                 << ","
253                 << new Html::LineBreak;
254             aExc.Produce_byData(*i_rExceptions);
255         }   // end for
256 
257         rExcOut << " );";
258     }
259     else if (bParams)
260     {
261         *pParamEnd << ";";
262     }
263     else
264     {
265         rNameCell << ";";
266     }
267 }
268 
269 #if 0   // old
270 void
271 HF_IdlMethod::write_Param( HF_IdlTypeText &             o_type,
272                            Xml::Element &               o_names,
273                            const ary::idl::Parameter &  i_param ) const
274 {
275     switch ( i_param.Direction() )
276     {
277         case ary::idl::param_in:
278                     o_type.CurOut() << "[in] ";
279                     break;
280         case ary::idl::param_out:
281                     o_type.CurOut() << "[out] ";
282                     break;
283         case ary::idl::param_inout:
284                     o_type.CurOut() << "[inout] ";
285                     break;
286     }   // end switch
287 
288     o_type.Produce_byData( i_param.Type() );
289     o_names
290         << i_param.Name();
291 }
292 #endif  // 0   old
293 
294 Xml::Element *
295 HF_IdlMethod::write_Param( HF_FunctionDeclaration &     o_decl,
296                            const ary::idl::Parameter &  i_param ) const
297 {
298     Xml::Element &
299         rTypeCell  = o_decl.NewParamTypeCell();
300     Xml::Element &
301         rNameCell  = o_decl.ParamNameCell();
302 
303     switch ( i_param.Direction() )
304     {
305         case ary::idl::param_in:
306                     rTypeCell << "[in] ";
307                     break;
308         case ary::idl::param_out:
309                     rTypeCell << "[out] ";
310                     break;
311         case ary::idl::param_inout:
312                     rTypeCell << "[inout] ";
313                     break;
314     }   // end switch
315 
316     HF_IdlTypeText
317         aTypeWriter(Env(), rTypeCell, true);
318     aTypeWriter.Produce_byData( i_param.Type() );
319 
320     rNameCell
321         << i_param.Name();
322     return &rNameCell;
323 }
324 
325 const String sContentBorder("0");
326 const String sContentWidth("96%");
327 const String sContentPadding("5");
328 const String sContentSpacing("0");
329 
330 const String sBgWhite("#ffffff");
331 const String sCenter("center");
332 
333 void
334 HF_IdlMethod::enter_ContentCell() const
335 {
336 
337     Xml::Element &
338         rContentCell = CurOut()
339                         >> *new Html::Table( sContentBorder,
340                                              sContentWidth,
341                                              sContentPadding,
342                                              sContentSpacing )
343                             << new Html::ClassAttr("table-in-method")
344                             << new Html::BgColorAttr(sBgWhite)
345                             << new Html::AlignAttr(sCenter)
346                             >> *new Html::TableRow
347                                 >> *new Html::TableCell;
348     Out().Enter(rContentCell);
349 }
350 
351 
352 void
353 HF_IdlMethod::leave_ContentCell() const
354 {
355     Out().Leave();
356 }
357 
358