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