1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include <precomp.h>
23 #include "outfile.hxx"
24 
25 // NOT FULLY DECLARED SERVICES
26 #include <cosv/file.hxx>
27 #include <udm/html/htmlitem.hxx>
28 #include <toolkit/out_position.hxx>
29 #include "strconst.hxx"
30 
31 
32 namespace
33 {
34 bool            bUse_OOoFrameDiv = true;
35 const String    C_sOOoFrameDiv_CppId("adc-cppref");
36 }
37 
38 
39 using namespace csi;
40 using csi::xml::AnAttribute;
41 
42 
43 
44 #define CRLF "\n"
45 
46 const char * const
47     C_sStdStyle =
48     "body   { background-color:#ffffff; }" CRLF
49     "h1     { font-size:20pt; margin-top:3pt; margin-bottom:7pt; }" CRLF
50     "h2     { font-family:Arial; font-size:16pt; margin-top:3pt; margin-bottom:5pt; }" CRLF
51     "h3     { font-size:13pt; margin-top:2pt; margin-bottom:3pt; }" CRLF
52     "h4     { font-size:10pt; font-weight:bold; margin-top:2pt; margin-bottom:1pt; }" CRLF
53 	"dl     { margin-top:1pt; margin-bottom:1pt; }" CRLF
54 	"dl.member  { margin-top:1pt; margin-bottom:1pt; background-color:#eeeeff; }" CRLF
55     "dt     { font-size:10pt; font-weight:bold; margin-top:2pt; margin-bottom:1pt; }" CRLF
56     "dt.member  { font-size:13pt; font-weight:bold; margin-top:2pt; margin-bottom:1pt; }" CRLF
57     "dt.simple  { font-size:10pt; font-weight:normal; margin-top:2pt; margin-bottom:1pt; }" CRLF
58     "dd     { font-size:10pt; margin-top:1pt; margin-bottom:1pt; }" CRLF
59     "dd.member  { font-size:10pt; margin-top:1pt; margin-bottom:1pt; background-color:#ffffff; }" CRLF
60     "p      { font-size:10pt; margin-top:3pt; margin-bottom:1pt; }" CRLF
61     "pre    { font-family:monospace; font-size:10pt; margin-top:1pt; margin-bottom:1pt; }" CRLF
62     "tr     { font-size:10pt; }" CRLF
63     "td     { font-size:10pt; }" CRLF
64     CRLF
65     "dt.attention   { color:#dd0000; }" CRLF
66     CRLF
67     "div.title      { text-align:center;  line-height:26pt; background-color:#ccccff; }" CRLF
68     ".subtitle      { background-color:#ccccff; }" CRLF
69     CRLF
70     "td.flagname    { background-color:#eeeeff; font-family:Arial; font-size:8pt; font-weight:bold; }" CRLF
71     "td.flagyes     { font-family:Arial; font-size:8pt; font-weight:bold; }" CRLF
72     "td.flagno      { font-family:Arial; font-size:8pt; }" CRLF
73     "td.flagtext    { font-family:Arial; font-size:8pt; font-weight:bold; }" CRLF
74     CRLF
75     "td.navimain, td.navimain a" CRLF
76     "               { background-color:#eeeeff; color:#000000;" CRLF
77     "                 font-family:Arial; font-size:12pt; font-weight:bold; }" CRLF
78     "td.navimainself" CRLF
79     "               { background-color:#2222ad; color:#ffffff;" CRLF
80     "                 font-family:Arial; font-size:12pt; font-weight:bold; }" CRLF
81     "td.navimainnone" CRLF
82     "               { background-color:#eeeeff; color:#000000;" CRLF
83     "                 font-family:Arial; font-size:12pt; }" CRLF
84     CRLF
85     "div.define     { font-family:Arial; background-color:#ccccff; }" CRLF
86     CRLF
87     ".nqclass       { color:#008800; }" CRLF
88     CRLF
89     "h3.help        { background-color:#eeeeff; margin-top:12pt; }" CRLF
90     CRLF
91     ".btpubl        { color:#33ff33; }" CRLF
92     ".btprot        { color:#cc9933; }" CRLF
93     ".btpriv        { color:#ff6666; }" CRLF
94     ".btvpubl       { color:#33ff33; font-style:italic; }" CRLF
95     ".btvprot       { color:#cc9933; font-style:italic; }" CRLF
96     ".btvpriv       { color:#ff6666; font-style:italic; }" CRLF
97     ".btself        { font-weight:bold; }" CRLF
98     ;
99 
100 
101 const char * const
102     C_sCssExplanations =
103     "/* Explanation of CSS classes:" CRLF
104     CRLF
105     "dl.member       provides coloured frame for function descriptions." CRLF
106     "dd.member       makes the content of this frame white" CRLF
107     CRLF
108     "dt.attention    special colour for @attention remarks" CRLF
109     CRLF
110     "div.title       HTML page headline" CRLF
111     ".subtitle       headline of lists of members and similar" CRLF
112     CRLF
113     "                These are for the flagtables in classes:" CRLF
114     "td.flagname     Flag name." CRLF
115     "td.flagyes      flag value \"yes\"" CRLF
116     "td.flagno       flag value \"no\"" CRLF
117     "td.flagtext     other flag value" CRLF
118     CRLF
119     CRLF
120     "                These are for the main navigationbar:" CRLF
121     "td.navimain, td.navimain a" CRLF
122     "                Links in navibar." CRLF
123     "td.navimainself Text in navibar which refers to current page." CRLF
124     "td.navimainnone Text which links to nothing." CRLF
125     CRLF
126     CRLF
127     "div.define      Subtitles on the #define/macro descriptions page" CRLF
128     CRLF
129     ".nqclass        special color for classes in the qualification" CRLF
130     "                on top of type pages like in:" CRLF
131     "                ::nsp1::nsp2::_ClassXY_::" CRLF
132     CRLF
133     "h3.help         Subtitles on the help page" CRLF
134     CRLF
135     "                These are for the base class tree on class pages:" CRLF
136     ".btpubl         public base class" CRLF
137     ".btprot         protected" CRLF
138     ".btpriv         private" CRLF
139     ".btvpubl        virtual public" CRLF
140     ".btvprot        virtual protected" CRLF
141     ".btvpriv        virtual private" CRLF
142     ".btself         placeholder for currently displayed class" CRLF
143     CRLF
144     "*/" CRLF
145     ;
146 
147 
148 const char * const
149     C_sStdStyle_withDivFrame =
150     "body   { background-color:#ffffff; }" CRLF
151     "#adc-cppref h1     { font-size:20pt; margin-top:3pt; margin-bottom:7pt; }" CRLF
152     "#adc-cppref h2     { font-family:Arial; font-size:16pt; margin-top:3pt; margin-bottom:5pt; }" CRLF
153     "#adc-cppref h3     { font-size:13pt; margin-top:2pt; margin-bottom:3pt; }" CRLF
154     "#adc-cppref h4     { font-size:10pt; font-weight:bold; margin-top:2pt; margin-bottom:1pt; }" CRLF
155 	"#adc-cppref dl     { margin-top:1pt; margin-bottom:1pt; }" CRLF
156 	"#adc-cppref dl.member  { margin-top:1pt; margin-bottom:1pt; background-color:#eeeeff; }" CRLF
157     "#adc-cppref dt     { font-size:10pt; font-weight:bold; margin-top:2pt; margin-bottom:1pt; }" CRLF
158     "#adc-cppref dt.member  { font-size:13pt; font-weight:bold; margin-top:2pt; margin-bottom:1pt; }" CRLF
159     "#adc-cppref dt.simple  { font-size:10pt; font-weight:normal; margin-top:2pt; margin-bottom:1pt; }" CRLF
160     "#adc-cppref dd     { font-size:10pt; margin-top:1pt; margin-bottom:1pt; }" CRLF
161     "#adc-cppref dd.member  { font-size:10pt; margin-top:1pt; margin-bottom:1pt; background-color:#ffffff; }" CRLF
162     "#adc-cppref p      { font-size:10pt; margin-top:3pt; margin-bottom:1pt; }" CRLF
163     "#adc-cppref pre    { font-family:monospace; font-size:10pt; margin-top:1pt; margin-bottom:1pt; }" CRLF
164     "#adc-cppref tr     { font-size:10pt; }" CRLF
165     "#adc-cppref td     { font-size:10pt; }" CRLF
166     CRLF
167     "#adc-cppref dt.attention   { color:#dd0000; }" CRLF
168     CRLF
169     "#adc-cppref div.title      { text-align:center;  line-height:26pt; background-color:#ccccff; }" CRLF
170     "#adc-cppref .subtitle      { background-color:#ccccff; }" CRLF
171     CRLF
172     "#adc-cppref td.flagname    { background-color:#eeeeff; font-family:Arial; font-size:8pt; font-weight:bold; }" CRLF
173     "#adc-cppref td.flagyes     { font-family:Arial; font-size:8pt; font-weight:bold; }" CRLF
174     "#adc-cppref td.flagno      { font-family:Arial; font-size:8pt; }" CRLF
175     "#adc-cppref td.flagtext    { font-family:Arial; font-size:8pt; font-weight:bold; }" CRLF
176     CRLF
177     "#adc-cppref td.navimain, #adc-cppref td.navimain a" CRLF
178     "               { background-color:#eeeeff; color:#000000;" CRLF
179     "                 font-family:Arial; font-size:12pt; font-weight:bold; }" CRLF
180     "#adc-cppref td.navimainself" CRLF
181     "               { background-color:#2222ad; color:#ffffff;" CRLF
182     "                 font-family:Arial; font-size:12pt; font-weight:bold; }" CRLF
183     "#adc-cppref td.navimainnone" CRLF
184     "               { background-color:#eeeeff; color:#000000;" CRLF
185     "                 font-family:Arial; font-size:12pt; }" CRLF
186     CRLF
187     "#adc-cppref div.define     { font-family:Arial; background-color:#ccccff; }" CRLF
188     CRLF
189     "#adc-cppref .nqclass       { color:#008800; }" CRLF
190     CRLF
191     "#adc-cppref h3.help        { background-color:#eeeeff; margin-top:12pt; }" CRLF
192     CRLF
193     "#adc-cppref .btpubl        { color:#33ff33; }" CRLF
194     "#adc-cppref .btprot        { color:#cc9933; }" CRLF
195     "#adc-cppref .btpriv        { color:#ff6666; }" CRLF
196     "#adc-cppref .btvpubl       { color:#33ff33; font-style:italic; }" CRLF
197     "#adc-cppref .btvprot       { color:#cc9933; font-style:italic; }" CRLF
198     "#adc-cppref .btvpriv       { color:#ff6666; font-style:italic; }" CRLF
199     "#adc-cppref .btself        { font-weight:bold; }" CRLF
200     "" CRLF
201     "#adc-cppref table { empty-cells:show; }" CRLF
202     "" CRLF
203 	"#adc-cppref .childlist td, " CRLF
204 	"#adc-cppref .commentedlinks td, " CRLF
205 	"#adc-cppref .memberlist td, " CRLF
206 	"#adc-cppref .subtitle td, " CRLF
207 	"#adc-cppref .crosstitle td  { border: .1pt solid #000000; }" CRLF
208     "" CRLF
209 	"#adc-cppref .flag-table td { border: .1pt solid #cccccc; } " CRLF
210     "" CRLF
211 	"#adc-cppref .title-table td, " CRLF
212 	"#adc-cppref .table-in-method td, " CRLF
213 	"#adc-cppref .table-in-data td, " CRLF
214 	"#adc-cppref .navimain td, " CRLF
215 	"#adc-cppref .navisub td, " CRLF
216 	"#adc-cppref .expl-table td, " CRLF
217 	"#adc-cppref .param-table td  { border: none; }" CRLF
218     ;
219 
220 
221 
HtmlDocuFile()222 HtmlDocuFile::HtmlDocuFile()
223 	:	sFilePath(),
224 	    sTitle(),
225         sLocation(),
226         sCopyright(),
227         nDepthInOutputTree(0),
228         aBodyData(),
229         aBuffer(60000)  // Grows dynamically when necessary.
230 {
231 }
232 
233 void
SetLocation(const csv::ploc::Path & i_rFilePath,uintt i_depthInOutputTree)234 HtmlDocuFile::SetLocation( const csv::ploc::Path &  i_rFilePath,
235                            uintt                    i_depthInOutputTree )
236 {
237     static StreamStr sPath_(1000);
238     sPath_.seekp(0);
239     i_rFilePath.Get( sPath_ );
240 
241 	sFilePath = sPath_.c_str();
242 	nDepthInOutputTree = i_depthInOutputTree;
243 }
244 
245 void
SetTitle(const char * i_sTitle)246 HtmlDocuFile::SetTitle( const char * i_sTitle )
247 {
248 	sTitle = i_sTitle;
249 }
250 
251 void
SetCopyright(const char * i_sCopyright)252 HtmlDocuFile::SetCopyright( const char * i_sCopyright )
253 {
254 	sCopyright = i_sCopyright;
255 }
256 
257 void
EmptyBody()258 HtmlDocuFile::EmptyBody()
259 {
260  	aBodyData.SetContent(0);
261 
262  	if (bUse_OOoFrameDiv)
263  	{
264         // Insert <div> tag to allow better formatting for OOo.
265         aBodyData
266             << new xml::XmlCode("<div id=\"")
267             << new xml::XmlCode(C_sOOoFrameDiv_CppId)
268             << new xml::XmlCode("\">\n\n");
269  	}
270 
271     aBodyData
272         >> *new html::Label( "_top_" )
273         << " ";
274 }
275 
276 bool
CreateFile()277 HtmlDocuFile::CreateFile()
278 {
279 	csv::File aFile(sFilePath, csv::CFM_CREATE);
280 	if (NOT aFile.open())
281 	{
282 		Cerr() << "Can't create file " << sFilePath << "." << Endl();
283 		return false;
284 	}
285 
286 	WriteHeader(aFile);
287 	WriteBody(aFile);
288 
289     // Write end
290     static const char sCompletion[] = "\n</html>\n";
291 	aFile.write( sCompletion );
292 
293 	aFile.close();
294     Cout() << '.' << Flush();
295     return true;
296 }
297 
298 void
WriteCssFile(const csv::ploc::Path & i_rFilePath)299 HtmlDocuFile::WriteCssFile(	const csv::ploc::Path & i_rFilePath )
300 {
301     Cout() << "\nCreate css file ..." << Endl();
302 
303     csv::File
304         aCssFile(i_rFilePath, csv::CFM_CREATE);
305     csv::OpenCloseGuard
306         aOpenGuard(aCssFile);
307     if (NOT aOpenGuard)
308     {
309         Cerr() << "Can't create file " << "cpp.css" << "." << Endl();
310         return;
311     }
312 
313     aCssFile.write("/*      Autodoc css file for C++ documentation      */\n\n\n");
314 
315     if (bUse_OOoFrameDiv)
316         aCssFile.write(C_sStdStyle_withDivFrame);
317     else
318         aCssFile.write(C_sStdStyle);
319 
320     aCssFile.write("\n\n\n");
321     aCssFile.write(C_sCssExplanations);
322 }
323 
324 void
WriteHeader(csv::File & io_aFile)325 HtmlDocuFile::WriteHeader( csv::File & io_aFile )
326 {
327     aBuffer.reset();
328 
329     static const char s1[] =
330         "<html>\n<head>\n"
331         "<title>";
332     static const char s2[] =
333         "</title>\n"
334         "<link rel=\"stylesheet\" type=\"text/css\" href=\"";
335     static const char s3[] =
336         "\">\n</head>\n";
337 
338 	aBuffer.write( s1 );
339     aBuffer.write( sTitle );
340     aBuffer.write( s2 );
341     aBuffer.write( output::get_UpLink(nDepthInOutputTree) );
342     aBuffer.write( C_sHFN_Css );
343     aBuffer.write( s3 );
344 
345     io_aFile.write(aBuffer.c_str(), aBuffer.size());
346 }
347 
348 void
WriteBody(csv::File & io_aFile)349 HtmlDocuFile::WriteBody( csv::File & io_aFile )
350 {
351     aBuffer.reset();
352 
353 	aBodyData
354         >> *new html::Link( "#_top_" )
355                 << new html::ClassAttr( "objchapter" )
356                 << "Top of Page";
357 
358     if ( sCopyright.length() > 0 )
359     {
360         aBodyData
361 #ifndef COMPATIBLE_NETSCAPE_47
362             >> *new html::HorizontalLine
363                     <<  new html::SizeAttr( "3" );
364 #else
365             << new xml::XmlCode("<hr size=\"3\">");
366 #endif
367 
368         aBodyData
369             >> *new html::Paragraph
370                     << new html::ClassAttr( "copyright" )
371                     << new xml::AnAttribute( "align", "center" )
372                     << new xml::XmlCode(sCopyright);
373     }
374 
375  	if (bUse_OOoFrameDiv)
376     {
377         // Insert <div> tag to allow better formatting for OOo.
378     	aBodyData
379             << new xml::XmlCode("\n</div> <!-- id=\"")
380             << new xml::XmlCode(C_sOOoFrameDiv_CppId)
381             << new xml::XmlCode("\" -->\n");
382     }
383 
384 	aBodyData.WriteOut(aBuffer);
385     io_aFile.write(aBuffer.c_str(), aBuffer.size());
386 }
387