Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "htmlex.hxx"
21 : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
22 : #include <com/sun/star/document/XExporter.hpp>
23 : #include <com/sun/star/document/XFilter.hpp>
24 : #include <com/sun/star/drawing/GraphicExportFilter.hpp>
25 : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
26 :
27 : #include <rtl/uri.hxx>
28 : #include <comphelper/processfactory.hxx>
29 : #include <osl/file.hxx>
30 : #include <unotools/pathoptions.hxx>
31 : #include <vcl/FilterConfigItem.hxx>
32 : #include <unotools/ucbstreamhelper.hxx>
33 : #include <unotools/localfilehelper.hxx>
34 : #include <com/sun/star/frame/XStorable.hpp>
35 : #include <sfx2/app.hxx>
36 : #include <sfx2/dispatch.hxx>
37 : #include <sfx2/docfile.hxx>
38 : #include <sfx2/fcontnr.hxx>
39 : #include <sfx2/frmhtmlw.hxx>
40 : #include <sfx2/progress.hxx>
41 : #include <vcl/wrkwin.hxx>
42 : #include <svl/aeitem.hxx>
43 : #include <svx/svditer.hxx>
44 : #include <svtools/imaprect.hxx>
45 : #include <svtools/imapcirc.hxx>
46 : #include <svtools/imappoly.hxx>
47 : #include <vcl/msgbox.hxx>
48 : #include <editeng/outlobj.hxx>
49 : #include <editeng/editobj.hxx>
50 : #include <svx/svdopath.hxx>
51 : #include <svx/xoutbmp.hxx>
52 : #include <svtools/htmlout.hxx>
53 : #include <vcl/cvtgrf.hxx>
54 : #include <svtools/colorcfg.hxx>
55 : #include <vcl/graphicfilter.hxx>
56 : #include <editeng/colritem.hxx>
57 : #include <editeng/editeng.hxx>
58 : #include <editeng/wghtitem.hxx>
59 : #include <editeng/udlnitem.hxx>
60 : #include <editeng/postitem.hxx>
61 : #include <editeng/crossedoutitem.hxx>
62 : #include <editeng/flditem.hxx>
63 : #include <svl/style.hxx>
64 : #include <editeng/frmdiritem.hxx>
65 : #include <svx/svdoutl.hxx>
66 : #include <svx/svdogrp.hxx>
67 : #include <svx/svdotable.hxx>
68 : #include <tools/urlobj.hxx>
69 : #include <vcl/bmpacc.hxx>
70 : #include <svtools/sfxecode.hxx>
71 : #include <com/sun/star/beans/PropertyState.hpp>
72 : #include <tools/resmgr.hxx>
73 : #include <comphelper/anytostring.hxx>
74 : #include <cppuhelper/exc_hlp.hxx>
75 : #include <basegfx/polygon/b2dpolygon.hxx>
76 :
77 : #include "drawdoc.hxx"
78 : #include "htmlpublishmode.hxx"
79 : #include "Outliner.hxx"
80 : #include "sdpage.hxx"
81 : #include "sdattr.hxx"
82 : #include "glob.hrc"
83 : #include "anminfo.hxx"
84 : #include "imapinfo.hxx"
85 : #include "sdresid.hxx"
86 : #include "buttonset.hxx"
87 :
88 : using namespace ::com::sun::star;
89 : using namespace ::com::sun::star::uno;
90 : using namespace ::com::sun::star::beans;
91 : using namespace ::com::sun::star::frame;
92 : using namespace ::com::sun::star::lang;
93 : using namespace ::com::sun::star::document;
94 :
95 : using namespace sdr::table;
96 :
97 : // get parameter from Itemset
98 : #define RESTOHTML( res ) StringToHTMLString(SD_RESSTR(res))
99 :
100 : const char *pButtonNames[] =
101 : {
102 : "first-inactive.png",
103 : "first.png",
104 : "left-inactive.png",
105 : "left.png",
106 : "right-inactive.png",
107 : "right.png",
108 : "last-inactive.png",
109 : "last.png",
110 : "home.png",
111 : "text.png",
112 : "expand.png",
113 : "collapse.png",
114 : };
115 :
116 : #define BTN_FIRST_0 0
117 : #define BTN_FIRST_1 1
118 : #define BTN_PREV_0 2
119 : #define BTN_PREV_1 3
120 : #define BTN_NEXT_0 4
121 : #define BTN_NEXT_1 5
122 : #define BTN_LAST_0 6
123 : #define BTN_LAST_1 7
124 : #define BTN_INDEX 8
125 : #define BTN_TEXT 9
126 : #define BTN_MORE 10
127 : #define BTN_LESS 11
128 :
129 : // Helper class for the simple creation of files local/remote
130 : class EasyFile
131 : {
132 : private:
133 : SvStream* pOStm;
134 : SfxMedium* pMedium;
135 : bool bOpen;
136 :
137 : public:
138 :
139 : EasyFile();
140 : ~EasyFile();
141 :
142 : sal_uLong createStream( const OUString& rUrl, SvStream*& rpStr );
143 : sal_uLong createFileName( const OUString& rUrl, OUString& rFileName );
144 : sal_uLong close();
145 : };
146 :
147 : // Helper class for the embedding of text attributes into the html output
148 52 : class HtmlState
149 : {
150 : private:
151 : bool mbColor;
152 : bool mbWeight;
153 : bool mbItalic;
154 : bool mbUnderline;
155 : bool mbStrike;
156 : bool mbLink;
157 : Color maColor;
158 : Color maDefColor;
159 : OUString maLink;
160 : OUString maTarget;
161 :
162 : public:
163 : HtmlState( Color aDefColor );
164 :
165 : OUString SetWeight( bool bWeight );
166 : OUString SetItalic( bool bItalic );
167 : OUString SetUnderline( bool bUnderline );
168 : OUString SetColor( Color aColor );
169 : OUString SetStrikeout( bool bStrike );
170 : OUString SetLink( const OUString& aLink, const OUString& aTarget );
171 : OUString Flush();
172 : };
173 :
174 : // close all still open tags
175 52 : OUString HtmlState::Flush()
176 : {
177 52 : OUString aStr;
178 :
179 52 : aStr += SetWeight(false);
180 52 : aStr += SetItalic(false);
181 52 : aStr += SetUnderline(false);
182 52 : aStr += SetStrikeout(false);
183 52 : aStr += SetColor(maDefColor);
184 52 : aStr += SetLink("","");
185 :
186 52 : return aStr;
187 : }
188 :
189 : // c'tor with default color for the page
190 52 : HtmlState::HtmlState( Color aDefColor )
191 : {
192 52 : mbColor = false;
193 52 : mbWeight = false;
194 52 : mbItalic = false;
195 52 : mbUnderline = false;
196 52 : mbLink = false;
197 52 : mbStrike = false;
198 52 : maDefColor = aDefColor;
199 52 : }
200 :
201 : // enables/disables bold print
202 104 : OUString HtmlState::SetWeight( bool bWeight )
203 : {
204 104 : OUString aStr;
205 :
206 104 : if(bWeight && !mbWeight)
207 0 : aStr = "<b>";
208 104 : else if(!bWeight && mbWeight)
209 0 : aStr = "</b>";
210 :
211 104 : mbWeight = bWeight;
212 104 : return aStr;
213 : }
214 :
215 : // enables/disables italic
216 :
217 104 : OUString HtmlState::SetItalic( bool bItalic )
218 : {
219 104 : OUString aStr;
220 :
221 104 : if(bItalic && !mbItalic)
222 0 : aStr = "<i>";
223 104 : else if(!bItalic && mbItalic)
224 0 : aStr = "</i>";
225 :
226 104 : mbItalic = bItalic;
227 104 : return aStr;
228 : }
229 :
230 : // enables/disables underlines
231 :
232 104 : OUString HtmlState::SetUnderline( bool bUnderline )
233 : {
234 104 : OUString aStr;
235 :
236 104 : if(bUnderline && !mbUnderline)
237 0 : aStr = "<u>";
238 104 : else if(!bUnderline && mbUnderline)
239 0 : aStr = "</u>";
240 :
241 104 : mbUnderline = bUnderline;
242 104 : return aStr;
243 : }
244 :
245 : // enables/disables strike through
246 104 : OUString HtmlState::SetStrikeout( bool bStrike )
247 : {
248 104 : OUString aStr;
249 :
250 104 : if(bStrike && !mbStrike)
251 0 : aStr = "<strike>";
252 104 : else if(!bStrike && mbStrike)
253 0 : aStr = "</strike>";
254 :
255 104 : mbStrike = bStrike;
256 104 : return aStr;
257 : }
258 :
259 : // Sets the specified text color
260 52 : OUString HtmlState::SetColor( Color aColor )
261 : {
262 52 : OUString aStr;
263 :
264 52 : if(mbColor && aColor == maColor)
265 0 : return aStr;
266 :
267 52 : if(mbColor)
268 : {
269 0 : aStr = "</font>";
270 0 : mbColor = false;
271 : }
272 :
273 52 : if(aColor != maDefColor)
274 : {
275 0 : maColor = aColor;
276 0 : aStr += "<font color=\"" + HtmlExport::ColorToHTMLString(aColor) + "\">";
277 0 : mbColor = true;
278 : }
279 :
280 52 : return aStr;
281 : }
282 :
283 : // enables/disables a hyperlink
284 104 : OUString HtmlState::SetLink( const OUString& aLink, const OUString& aTarget )
285 : {
286 104 : OUString aStr;
287 :
288 104 : if(mbLink&&maLink == aLink&&maTarget==aTarget)
289 0 : return aStr;
290 :
291 104 : if(mbLink)
292 : {
293 0 : aStr = "</a>";
294 0 : mbLink = false;
295 : }
296 :
297 104 : if (!aLink.isEmpty())
298 : {
299 0 : aStr += "<a href=\"" + aLink;
300 0 : if (!aTarget.isEmpty())
301 : {
302 0 : aStr += "\" target=\"" + aTarget;
303 : }
304 0 : aStr += "\">";
305 0 : mbLink = true;
306 0 : maLink = aLink;
307 0 : maTarget = aTarget;
308 : }
309 :
310 104 : return aStr;
311 : }
312 : namespace
313 : {
314 :
315 50 : OUString getParagraphStyle( SdrOutliner* pOutliner, sal_Int32 nPara )
316 : {
317 50 : SfxItemSet aParaSet( pOutliner->GetParaAttribs( nPara ) );
318 :
319 50 : OUString sStyle;
320 :
321 50 : if( static_cast<const SvxFrameDirectionItem*>(aParaSet.GetItem( EE_PARA_WRITINGDIR ))->GetValue() == FRMDIR_HORI_RIGHT_TOP )
322 : {
323 :
324 0 : sStyle = "direction: rtl;";
325 : }
326 : else
327 : {
328 : // This is the default so don't write it out
329 : // sStyle += "direction: ltr;";
330 : }
331 50 : return sStyle;
332 : }
333 :
334 50 : void lclAppendStyle(OUStringBuffer& aBuffer, const OUString& aTag, const OUString& aStyle)
335 : {
336 50 : if (aStyle.isEmpty())
337 44 : aBuffer.append("<" + aTag + ">");
338 : else
339 6 : aBuffer.append("<" + aTag + " style=\"" + aStyle + "\">");
340 50 : }
341 :
342 : } // anonymous namespace
343 :
344 : // constructor for the html export helper classes
345 2 : HtmlExport::HtmlExport(
346 : const OUString& aPath,
347 : const Sequence< PropertyValue >& rParams,
348 : SdDrawDocument* pExpDoc,
349 : sd::DrawDocShell* pDocShell )
350 : : maPath( aPath ),
351 : mpDoc(pExpDoc),
352 : mpDocSh( pDocShell ),
353 : meEC(NULL),
354 : meMode( PUBLISH_SINGLE_DOCUMENT ),
355 : mbContentsPage(false),
356 : mnButtonThema(-1),
357 : mnWidthPixel( PUB_MEDRES_WIDTH ),
358 : meFormat( FORMAT_JPG ),
359 : mbNotes(false),
360 : mnCompression( -1 ),
361 : mbDownload( false ),
362 : mbSlideSound(true),
363 : mbHiddenSlides(true),
364 : mbUserAttr(false),
365 : maTextColor(COL_BLACK),
366 : maBackColor(COL_WHITE),
367 : mbDocColors(false),
368 : maHTMLExtension(SdResId(STR_HTMLEXP_DEFAULT_EXTENSION)),
369 : maIndexUrl("index"),
370 : meScript( SCRIPT_ASP ),
371 : maHTMLHeader(
372 : "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\r\n"
373 : " \"http://www.w3.org/TR/html4/transitional.dtd\">\r\n"
374 : "<html>\r\n<head>\r\n" ),
375 2 : mpButtonSet( new ButtonSet() )
376 : {
377 2 : bool bChange = mpDoc->IsChanged();
378 :
379 2 : maIndexUrl += maHTMLExtension;
380 :
381 2 : InitExportParameters( rParams );
382 :
383 2 : switch( meMode )
384 : {
385 : case PUBLISH_HTML:
386 : case PUBLISH_FRAMES:
387 0 : ExportHtml();
388 0 : break;
389 : case PUBLISH_WEBCAST:
390 0 : ExportWebCast();
391 0 : break;
392 : case PUBLISH_KIOSK:
393 0 : ExportKiosk();
394 0 : break;
395 : case PUBLISH_SINGLE_DOCUMENT:
396 2 : ExportSingleDocument();
397 2 : break;
398 : }
399 :
400 2 : mpDoc->SetChanged(bChange);
401 2 : }
402 :
403 2 : HtmlExport::~HtmlExport()
404 : {
405 2 : }
406 :
407 : // get common export parameters from item set
408 2 : void HtmlExport::InitExportParameters( const Sequence< PropertyValue >& rParams )
409 : {
410 2 : mbImpress = mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS;
411 :
412 2 : sal_Int32 nArgs = rParams.getLength();
413 2 : const PropertyValue* pParams = rParams.getConstArray();
414 2 : OUString aStr;
415 4 : while( nArgs-- )
416 : {
417 0 : if ( pParams->Name == "PublishMode" )
418 : {
419 0 : sal_Int32 temp = 0;
420 0 : pParams->Value >>= temp;
421 0 : meMode = (HtmlPublishMode)temp;
422 : }
423 0 : else if ( pParams->Name == "IndexURL" )
424 : {
425 0 : pParams->Value >>= aStr;
426 0 : maIndexUrl = aStr;
427 : }
428 0 : else if ( pParams->Name == "Format" )
429 : {
430 0 : sal_Int32 temp = 0;
431 0 : pParams->Value >>= temp;
432 0 : meFormat = (PublishingFormat)temp;
433 : }
434 0 : else if ( pParams->Name == "Compression" )
435 : {
436 0 : pParams->Value >>= aStr;
437 0 : OUString aTmp( aStr );
438 0 : if(!aTmp.isEmpty())
439 : {
440 0 : aTmp = aTmp.replaceFirst("%", "");
441 0 : mnCompression = (sal_Int16)aTmp.toInt32();
442 0 : }
443 : }
444 0 : else if ( pParams->Name == "Width" )
445 : {
446 0 : sal_Int32 temp = 0;
447 0 : pParams->Value >>= temp;
448 0 : mnWidthPixel = (sal_uInt16)temp;
449 : }
450 0 : else if ( pParams->Name == "UseButtonSet" )
451 : {
452 0 : sal_Int32 temp = 0;
453 0 : pParams->Value >>= temp;
454 0 : mnButtonThema = (sal_Int16)temp;
455 : }
456 0 : else if ( pParams->Name == "IsExportNotes" )
457 : {
458 0 : if( mbImpress )
459 : {
460 0 : bool temp = false;
461 0 : pParams->Value >>= temp;
462 0 : mbNotes = temp;
463 : }
464 : }
465 0 : else if ( pParams->Name == "IsExportContentsPage" )
466 : {
467 0 : bool temp = false;
468 0 : pParams->Value >>= temp;
469 0 : mbContentsPage = temp;
470 : }
471 0 : else if ( pParams->Name == "Author" )
472 : {
473 0 : pParams->Value >>= aStr;
474 0 : maAuthor = aStr;
475 : }
476 0 : else if ( pParams->Name == "EMail" )
477 : {
478 0 : pParams->Value >>= aStr;
479 0 : maEMail = aStr;
480 : }
481 0 : else if ( pParams->Name == "HomepageURL" )
482 : {
483 0 : pParams->Value >>= aStr;
484 0 : maHomePage = aStr;
485 : }
486 0 : else if ( pParams->Name == "UserText" )
487 : {
488 0 : pParams->Value >>= aStr;
489 0 : maInfo = aStr;
490 : }
491 0 : else if ( pParams->Name == "EnableDownload" )
492 : {
493 0 : bool temp = false;
494 0 : pParams->Value >>= temp;
495 0 : mbDownload = temp;
496 : }
497 0 : else if ( pParams->Name == "SlideSound" )
498 : {
499 0 : bool temp = true;
500 0 : pParams->Value >>= temp;
501 0 : mbSlideSound = temp;
502 : }
503 0 : else if ( pParams->Name == "HiddenSlides" )
504 : {
505 0 : bool temp = true;
506 0 : pParams->Value >>= temp;
507 0 : mbHiddenSlides = temp;
508 : }
509 0 : else if ( pParams->Name == "BackColor" )
510 : {
511 0 : sal_Int32 temp = 0;
512 0 : pParams->Value >>= temp;
513 0 : maBackColor = temp;
514 0 : mbUserAttr = true;
515 : }
516 0 : else if ( pParams->Name == "TextColor" )
517 : {
518 0 : sal_Int32 temp = 0;
519 0 : pParams->Value >>= temp;
520 0 : maTextColor = temp;
521 0 : mbUserAttr = true;
522 : }
523 0 : else if ( pParams->Name == "LinkColor" )
524 : {
525 0 : sal_Int32 temp = 0;
526 0 : pParams->Value >>= temp;
527 0 : maLinkColor = temp;
528 0 : mbUserAttr = true;
529 : }
530 0 : else if ( pParams->Name == "VLinkColor" )
531 : {
532 0 : sal_Int32 temp = 0;
533 0 : pParams->Value >>= temp;
534 0 : maVLinkColor = temp;
535 0 : mbUserAttr = true;
536 : }
537 0 : else if ( pParams->Name == "ALinkColor" )
538 : {
539 0 : sal_Int32 temp = 0;
540 0 : pParams->Value >>= temp;
541 0 : maALinkColor = temp;
542 0 : mbUserAttr = true;
543 : }
544 0 : else if ( pParams->Name == "IsUseDocumentColors" )
545 : {
546 0 : bool temp = false;
547 0 : pParams->Value >>= temp;
548 0 : mbDocColors = temp;
549 : }
550 0 : else if ( pParams->Name == "KioskSlideDuration" )
551 : {
552 0 : double temp = 0.0;
553 0 : pParams->Value >>= temp;
554 0 : mfSlideDuration = temp;
555 0 : mbAutoSlide = true;
556 : }
557 0 : else if ( pParams->Name == "KioskEndless" )
558 : {
559 0 : bool temp = false;
560 0 : pParams->Value >>= temp;
561 0 : mbEndless = temp;
562 : }
563 0 : else if ( pParams->Name == "WebCastCGIURL" )
564 : {
565 0 : pParams->Value >>= aStr;
566 0 : maCGIPath = aStr;
567 : }
568 0 : else if ( pParams->Name == "WebCastTargetURL" )
569 : {
570 0 : pParams->Value >>= aStr;
571 0 : maURLPath = aStr;
572 : }
573 0 : else if ( pParams->Name == "WebCastScriptLanguage" )
574 : {
575 0 : pParams->Value >>= aStr;
576 0 : if ( aStr == "asp" )
577 : {
578 0 : meScript = SCRIPT_ASP;
579 : }
580 : else
581 : {
582 0 : meScript = SCRIPT_PERL;
583 : }
584 : }
585 : else
586 : {
587 : OSL_FAIL("Unknown property for html export detected!");
588 : }
589 :
590 0 : pParams++;
591 : }
592 :
593 2 : if( meMode == PUBLISH_KIOSK )
594 : {
595 0 : mbContentsPage = false;
596 0 : mbNotes = false;
597 :
598 : }
599 :
600 : // calculate image sizes
601 2 : SdPage* pPage = mpDoc->GetSdPage(0, PK_STANDARD);
602 2 : Size aTmpSize( pPage->GetSize() );
603 2 : double dRatio=((double)aTmpSize.Width())/aTmpSize.Height();
604 :
605 2 : mnHeightPixel = (sal_uInt16)(mnWidthPixel/dRatio);
606 :
607 : // we come up with a destination...
608 :
609 4 : INetURLObject aINetURLObj( maPath );
610 : DBG_ASSERT( aINetURLObj.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
611 :
612 2 : maExportPath = aINetURLObj.GetPartBeforeLastName(); // with trailing '/'
613 2 : maIndex = aINetURLObj.GetLastName();
614 :
615 2 : mnSdPageCount = mpDoc->GetSdPageCount( PK_STANDARD );
616 10 : for( sal_uInt16 nPage = 0; nPage < mnSdPageCount; nPage++ )
617 : {
618 8 : pPage = mpDoc->GetSdPage( nPage, PK_STANDARD );
619 :
620 8 : if( mbHiddenSlides || !pPage->IsExcluded() )
621 : {
622 8 : maPages.push_back( pPage );
623 8 : maNotesPages.push_back( mpDoc->GetSdPage( nPage, PK_NOTES ) );
624 : }
625 : }
626 2 : mnSdPageCount = maPages.size();
627 :
628 2 : mbFrames = meMode == PUBLISH_FRAMES;
629 :
630 4 : maDocFileName = maIndex;
631 2 : }
632 :
633 2 : void HtmlExport::ExportSingleDocument()
634 : {
635 2 : SdrOutliner* pOutliner = mpDoc->GetInternalOutliner();
636 :
637 2 : maPageNames.resize(mnSdPageCount);
638 :
639 2 : mnPagesWritten = 0;
640 2 : InitProgress(mnSdPageCount);
641 :
642 2 : OUStringBuffer aStr(maHTMLHeader);
643 2 : aStr.append(DocumentMetadata());
644 2 : aStr.append("\r\n");
645 2 : aStr.append("</head>\r\n");
646 2 : aStr.append(CreateBodyTag());
647 :
648 10 : for(sal_uInt16 nSdPage = 0; nSdPage < mnSdPageCount; ++nSdPage)
649 : {
650 8 : SdPage* pPage = maPages[nSdPage];
651 8 : maPageNames[nSdPage] = pPage->GetName();
652 :
653 8 : if( mbDocColors )
654 : {
655 0 : SetDocColors( pPage );
656 : }
657 :
658 : // page title
659 8 : OUString sTitleText(CreateTextForTitle(pOutliner, pPage, pPage->GetPageBackgroundColor()));
660 16 : OUString sStyle;
661 :
662 8 : if (nSdPage != 0) // First page - no need for a page brake here
663 6 : sStyle += "page-break-before:always; ";
664 8 : sStyle += getParagraphStyle(pOutliner, 0);
665 :
666 8 : lclAppendStyle(aStr, "h1", sStyle);
667 :
668 8 : aStr.append(sTitleText);
669 8 : aStr.append("</h1>\r\n");
670 :
671 : // write outline text
672 8 : aStr.append(CreateTextForPage( pOutliner, pPage, true, pPage->GetPageBackgroundColor() ));
673 :
674 : // notes
675 8 : if(mbNotes)
676 : {
677 0 : SdPage* pNotesPage = maNotesPages[ nSdPage ];
678 0 : OUString aNotesStr( CreateTextForNotesPage( pOutliner, pNotesPage, true, maBackColor) );
679 :
680 0 : if (!aNotesStr.isEmpty())
681 : {
682 0 : aStr.append("<br>\r\n<h3>");
683 0 : aStr.append(RESTOHTML(STR_HTMLEXP_NOTES));
684 0 : aStr.append(":</h3>\r\n");
685 :
686 0 : aStr.append(aNotesStr);
687 0 : }
688 : }
689 :
690 8 : if (mpProgress)
691 8 : mpProgress->SetState(++mnPagesWritten);
692 :
693 8 : }
694 :
695 : // close page
696 2 : aStr.append("</body>\r\n</html>");
697 :
698 2 : WriteHtml(maDocFileName, false, aStr.makeStringAndClear());
699 :
700 2 : pOutliner->Clear();
701 2 : ResetProgress();
702 2 : }
703 :
704 : // exports the (in the c'tor specified impress document) to html
705 0 : void HtmlExport::ExportHtml()
706 : {
707 0 : if(mbUserAttr)
708 : {
709 0 : if( maTextColor == COL_AUTO )
710 : {
711 0 : if( !maBackColor.IsDark() )
712 0 : maTextColor = COL_BLACK;
713 : }
714 : }
715 0 : else if( mbDocColors )
716 : {
717 : // default colors for the color schema 'From Document'
718 0 : SetDocColors();
719 0 : maFirstPageColor = maBackColor;
720 : }
721 :
722 : // get name for downloadable presentation if needed
723 0 : if( mbDownload )
724 : {
725 : // fade out separator search and extension
726 0 : sal_Int32 nSepPos = maDocFileName.indexOf('.');
727 0 : if (nSepPos != -1)
728 0 : maDocFileName = maDocFileName.copy(0, nSepPos);
729 :
730 0 : maDocFileName += ".odp";
731 : }
732 :
733 0 : sal_uInt16 nProgrCount = mnSdPageCount;
734 0 : nProgrCount += mbImpress?mnSdPageCount:0;
735 0 : nProgrCount += mbContentsPage?1:0;
736 0 : nProgrCount += (mbFrames && mbNotes)?mnSdPageCount:0;
737 0 : nProgrCount += (mbFrames)?8:0;
738 0 : InitProgress( nProgrCount );
739 :
740 0 : mpDocSh->SetWaitCursor( true );
741 :
742 : // Exceptions are cool...
743 :
744 0 : CreateFileNames();
745 :
746 : // this is not a true while
747 : while( true )
748 : {
749 0 : if( checkForExistingFiles() )
750 0 : break;
751 :
752 0 : if( !CreateImagesForPresPages() )
753 0 : break;
754 :
755 0 : if( mbContentsPage &&
756 0 : !CreateImagesForPresPages( true ) )
757 0 : break;
758 :
759 0 : if( !CreateHtmlForPresPages() )
760 0 : break;
761 :
762 0 : if( mbImpress )
763 0 : if( !CreateHtmlTextForPresPages() )
764 0 : break;
765 :
766 0 : if( mbFrames )
767 : {
768 0 : if( !CreateFrames() )
769 0 : break;
770 :
771 0 : if( !CreateOutlinePages() )
772 0 : break;
773 :
774 0 : if( !CreateNavBarFrames() )
775 0 : break;
776 :
777 0 : if( mbNotes && mbImpress )
778 0 : if( !CreateNotesPages() )
779 0 : break;
780 :
781 : }
782 :
783 0 : if( mbContentsPage )
784 0 : if( !CreateContentPage() )
785 0 : break;
786 :
787 0 : if( !CreateBitmaps() )
788 0 : break;
789 :
790 0 : mpDocSh->SetWaitCursor( false );
791 0 : ResetProgress();
792 :
793 0 : if( mbDownload )
794 0 : SavePresentation();
795 :
796 0 : return;
797 : }
798 :
799 : // if we get to this point the export was
800 : // canceled by the user after an error
801 0 : mpDocSh->SetWaitCursor( false );
802 0 : ResetProgress();
803 : }
804 :
805 0 : void HtmlExport::SetDocColors( SdPage* pPage )
806 : {
807 0 : if( pPage == NULL )
808 0 : pPage = mpDoc->GetSdPage(0, PK_STANDARD);
809 :
810 0 : svtools::ColorConfig aConfig;
811 0 : maVLinkColor = Color(aConfig.GetColorValue(svtools::LINKSVISITED).nColor);
812 0 : maALinkColor = Color(aConfig.GetColorValue(svtools::LINKS).nColor);
813 0 : maLinkColor = Color(aConfig.GetColorValue(svtools::LINKS).nColor);
814 0 : maTextColor = Color(COL_BLACK);
815 :
816 0 : SfxStyleSheet* pSheet = NULL;
817 :
818 0 : if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
819 : {
820 : // default text color from the outline template of the first page
821 0 : pSheet = pPage->GetStyleSheetForPresObj(PRESOBJ_OUTLINE);
822 0 : if(pSheet == NULL)
823 0 : pSheet = pPage->GetStyleSheetForPresObj(PRESOBJ_TEXT);
824 0 : if(pSheet == NULL)
825 0 : pSheet = pPage->GetStyleSheetForPresObj(PRESOBJ_TITLE);
826 : }
827 :
828 0 : if(pSheet == NULL)
829 0 : pSheet = mpDoc->GetDefaultStyleSheet();
830 :
831 0 : if(pSheet)
832 : {
833 0 : SfxItemSet& rSet = pSheet->GetItemSet();
834 0 : if(rSet.GetItemState(EE_CHAR_COLOR,true) == SfxItemState::SET)
835 0 : maTextColor = ((SvxColorItem*)rSet.GetItem(EE_CHAR_COLOR,true))->GetValue();
836 : }
837 :
838 : // default background from the background of the master page of the first page
839 0 : maBackColor = pPage->GetPageBackgroundColor();
840 :
841 0 : if( maTextColor == COL_AUTO )
842 : {
843 0 : if( !maBackColor.IsDark() )
844 0 : maTextColor = COL_BLACK;
845 0 : }
846 0 : }
847 :
848 2 : void HtmlExport::InitProgress( sal_uInt16 nProgrCount )
849 : {
850 2 : mpProgress = new SfxProgress( mpDocSh, SD_RESSTR(STR_CREATE_PAGES), nProgrCount );
851 2 : }
852 :
853 2 : void HtmlExport::ResetProgress()
854 : {
855 2 : delete mpProgress;
856 2 : mpProgress = NULL;
857 2 : }
858 :
859 0 : void HtmlExport::ExportKiosk()
860 : {
861 0 : mnPagesWritten = 0;
862 0 : InitProgress( 2*mnSdPageCount );
863 :
864 0 : CreateFileNames();
865 0 : if( !checkForExistingFiles() )
866 : {
867 0 : if( CreateImagesForPresPages() )
868 0 : CreateHtmlForPresPages();
869 : }
870 :
871 0 : ResetProgress();
872 0 : }
873 :
874 : // Export Document with WebCast (TM) Technology
875 0 : void HtmlExport::ExportWebCast()
876 : {
877 0 : mnPagesWritten = 0;
878 0 : InitProgress( mnSdPageCount + 9 );
879 :
880 0 : mpDocSh->SetWaitCursor( true );
881 :
882 0 : CreateFileNames();
883 :
884 0 : if (maCGIPath.isEmpty())
885 0 : maCGIPath = ".";
886 :
887 0 : if (!maCGIPath.endsWith("/"))
888 0 : maCGIPath += "/";
889 :
890 0 : if( meScript == SCRIPT_ASP )
891 : {
892 0 : maURLPath = "./";
893 : }
894 : else
895 : {
896 0 : if (maURLPath.isEmpty())
897 0 : maURLPath = ".";
898 :
899 0 : if (!maURLPath.endsWith("/"))
900 0 : maURLPath += "/";
901 : }
902 :
903 : // this is not a true while
904 : while(true)
905 : {
906 0 : if( checkForExistingFiles() )
907 0 : break;
908 :
909 0 : if(!CreateImagesForPresPages())
910 0 : break;
911 :
912 0 : if( meScript == SCRIPT_ASP )
913 : {
914 0 : if(!CreateASPScripts())
915 0 : break;
916 : }
917 : else
918 : {
919 0 : if(!CreatePERLScripts())
920 0 : break;
921 : }
922 :
923 0 : if(!CreateImageFileList())
924 0 : break;
925 :
926 0 : if(!CreateImageNumberFile())
927 0 : break;
928 :
929 0 : break;
930 : }
931 :
932 0 : mpDocSh->SetWaitCursor( false );
933 0 : ResetProgress();
934 0 : }
935 :
936 : // Save the presentation as a downloadable file in the dest directory
937 0 : bool HtmlExport::SavePresentation()
938 : {
939 0 : meEC.SetContext( STR_HTMLEXP_ERROR_CREATE_FILE, maDocFileName );
940 :
941 0 : OUString aURL(maExportPath + maDocFileName);
942 :
943 0 : mpDocSh->EnableSetModified( true );
944 :
945 : try
946 : {
947 0 : uno::Reference< frame::XStorable > xStorable( mpDoc->getUnoModel(), uno::UNO_QUERY );
948 0 : if( xStorable.is() )
949 : {
950 0 : uno::Sequence< beans::PropertyValue > aProperties( 2 );
951 0 : aProperties[ 0 ].Name = "Overwrite";
952 0 : aProperties[ 0 ].Value <<= true;
953 0 : aProperties[ 1 ].Name = "FilterName";
954 0 : aProperties[ 1 ].Value <<= OUString("impress8");
955 0 : xStorable->storeToURL( aURL, aProperties );
956 :
957 0 : mpDocSh->EnableSetModified( false );
958 :
959 0 : return true;
960 0 : }
961 : }
962 0 : catch( Exception& )
963 : {
964 : }
965 :
966 0 : mpDocSh->EnableSetModified( false );
967 :
968 0 : return false;
969 : }
970 :
971 : // create image files
972 0 : bool HtmlExport::CreateImagesForPresPages( bool bThumbnail)
973 : {
974 : try
975 : {
976 0 : Reference < XComponentContext > xContext = ::comphelper::getProcessComponentContext();
977 :
978 0 : Reference< drawing::XGraphicExportFilter > xGraphicExporter = drawing::GraphicExportFilter::create( xContext );
979 :
980 0 : Sequence< PropertyValue > aFilterData(((meFormat==FORMAT_JPG)&&(mnCompression != -1))? 3 : 2);
981 0 : aFilterData[0].Name = "PixelWidth";
982 0 : aFilterData[0].Value <<= (sal_Int32)(bThumbnail ? PUB_THUMBNAIL_WIDTH : mnWidthPixel );
983 0 : aFilterData[1].Name = "PixelHeight";
984 0 : aFilterData[1].Value <<= (sal_Int32)(bThumbnail ? PUB_THUMBNAIL_HEIGHT : mnHeightPixel);
985 0 : if((meFormat==FORMAT_JPG)&&(mnCompression != -1))
986 : {
987 0 : aFilterData[2].Name = "Quality";
988 0 : aFilterData[2].Value <<= (sal_Int32)mnCompression;
989 : }
990 :
991 0 : Sequence< PropertyValue > aDescriptor( 3 );
992 0 : aDescriptor[0].Name = "URL";
993 0 : aDescriptor[1].Name = "FilterName";
994 0 : OUString sFormat;
995 0 : if( meFormat == FORMAT_PNG )
996 0 : sFormat = "PNG";
997 0 : else if( meFormat == FORMAT_GIF )
998 0 : sFormat = "GIF";
999 : else
1000 0 : sFormat = "JPG";
1001 :
1002 0 : aDescriptor[1].Value <<= sFormat;
1003 0 : aDescriptor[2].Name = "FilterData";
1004 0 : aDescriptor[2].Value <<= aFilterData;
1005 :
1006 0 : for (sal_uInt16 nSdPage = 0; nSdPage < mnSdPageCount; nSdPage++)
1007 : {
1008 0 : SdPage* pPage = maPages[ nSdPage ];
1009 :
1010 0 : OUString aFull(maExportPath);
1011 0 : if (bThumbnail)
1012 0 : aFull += maThumbnailFiles[nSdPage];
1013 : else
1014 0 : aFull += maImageFiles[nSdPage];
1015 :
1016 0 : aDescriptor[0].Value <<= aFull;
1017 :
1018 0 : Reference< XComponent > xPage( pPage->getUnoPage(), UNO_QUERY );
1019 0 : xGraphicExporter->setSourceDocument( xPage );
1020 0 : xGraphicExporter->filter( aDescriptor );
1021 :
1022 0 : if (mpProgress)
1023 0 : mpProgress->SetState(++mnPagesWritten);
1024 0 : }
1025 : }
1026 0 : catch( Exception& )
1027 : {
1028 0 : return false;
1029 : }
1030 :
1031 0 : return true;
1032 : }
1033 :
1034 : // get SdrTextObject with layout text of this page
1035 0 : SdrTextObj* HtmlExport::GetLayoutTextObject(SdrPage* pPage)
1036 : {
1037 0 : const size_t nObjectCount = pPage->GetObjCount();
1038 0 : SdrObject* pObject = NULL;
1039 0 : SdrTextObj* pResult = NULL;
1040 :
1041 0 : for (size_t nObject = 0; nObject < nObjectCount; ++nObject)
1042 : {
1043 0 : pObject = pPage->GetObj(nObject);
1044 0 : if (pObject->GetObjInventor() == SdrInventor &&
1045 0 : pObject->GetObjIdentifier() == OBJ_OUTLINETEXT)
1046 : {
1047 0 : pResult = (SdrTextObj*)pObject;
1048 0 : break;
1049 : }
1050 : }
1051 0 : return pResult;
1052 : }
1053 :
1054 : // create HTML text version of impress pages
1055 0 : OUString HtmlExport::CreateMetaCharset() const
1056 : {
1057 0 : OUString aStr;
1058 0 : const sal_Char *pCharSet = rtl_getBestMimeCharsetFromTextEncoding( RTL_TEXTENCODING_UTF8 );
1059 0 : if ( pCharSet )
1060 : {
1061 0 : aStr = " <meta HTTP-EQUIV=CONTENT-TYPE CONTENT=\"text/html; charset=" +
1062 0 : OUString::createFromAscii(pCharSet) + "\">\r\n";
1063 : }
1064 0 : return aStr;
1065 : }
1066 :
1067 2 : OUString HtmlExport::DocumentMetadata() const
1068 : {
1069 2 : SvMemoryStream aStream;
1070 :
1071 4 : uno::Reference<document::XDocumentProperties> xDocProps;
1072 2 : if (mpDocSh)
1073 : {
1074 : uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
1075 2 : mpDocSh->GetModel(), uno::UNO_QUERY_THROW);
1076 2 : xDocProps.set(xDPS->getDocumentProperties());
1077 : }
1078 :
1079 4 : OUString aNonConvertableCharacters;
1080 :
1081 : SfxFrameHTMLWriter::Out_DocInfo(aStream, maDocFileName, xDocProps,
1082 : " ", RTL_TEXTENCODING_UTF8,
1083 2 : &aNonConvertableCharacters);
1084 :
1085 4 : OString aData(reinterpret_cast<const char*>(aStream.GetData()), aStream.GetSize());
1086 :
1087 4 : return OStringToOUString(aData, RTL_TEXTENCODING_UTF8);
1088 : }
1089 :
1090 0 : bool HtmlExport::CreateHtmlTextForPresPages()
1091 : {
1092 0 : bool bOk = true;
1093 :
1094 0 : SdrOutliner* pOutliner = mpDoc->GetInternalOutliner();
1095 :
1096 0 : for(sal_uInt16 nSdPage = 0; nSdPage < mnSdPageCount && bOk; nSdPage++)
1097 : {
1098 0 : SdPage* pPage = maPages[ nSdPage ];
1099 :
1100 0 : if( mbDocColors )
1101 : {
1102 0 : SetDocColors( pPage );
1103 : }
1104 :
1105 : // HTML head
1106 0 : OUStringBuffer aStr(maHTMLHeader);
1107 0 : aStr.append(CreateMetaCharset());
1108 0 : aStr.append(" <title>");
1109 0 : aStr.append(StringToHTMLString(maPageNames[nSdPage]));
1110 0 : aStr.append("</title>\r\n");
1111 0 : aStr.append("</head>\r\n");
1112 0 : aStr.append(CreateBodyTag());
1113 :
1114 : // navigation bar
1115 0 : aStr.append(CreateNavBar(nSdPage, true));
1116 :
1117 : // page title
1118 0 : OUString sTitleText( CreateTextForTitle(pOutliner,pPage, pPage->GetPageBackgroundColor()) );
1119 0 : lclAppendStyle(aStr, "h1", getParagraphStyle(pOutliner, 0));
1120 0 : aStr.append(sTitleText);
1121 0 : aStr.append("</h1>\r\n");
1122 :
1123 : // write outline text
1124 0 : aStr.append(CreateTextForPage( pOutliner, pPage, true, pPage->GetPageBackgroundColor() ));
1125 :
1126 : // notes
1127 0 : if(mbNotes)
1128 : {
1129 0 : SdPage* pNotesPage = maNotesPages[ nSdPage ];
1130 0 : OUString aNotesStr( CreateTextForNotesPage( pOutliner, pNotesPage, true, maBackColor) );
1131 :
1132 0 : if (!aNotesStr.isEmpty())
1133 : {
1134 0 : aStr.append("<br>\r\n<h3>");
1135 0 : aStr.append(RESTOHTML(STR_HTMLEXP_NOTES));
1136 0 : aStr.append(":</h3>\r\n");
1137 :
1138 0 : aStr.append(aNotesStr);
1139 0 : }
1140 : }
1141 :
1142 : // close page
1143 0 : aStr.append("</body>\r\n</html>");
1144 :
1145 0 : bOk = WriteHtml(maTextFiles[nSdPage], false, aStr.makeStringAndClear());
1146 :
1147 0 : if (mpProgress)
1148 0 : mpProgress->SetState(++mnPagesWritten);
1149 :
1150 0 : }
1151 :
1152 0 : pOutliner->Clear();
1153 :
1154 0 : return bOk;
1155 : }
1156 :
1157 : /** exports the given html data into a non unicode file in the current export path with
1158 : the given filename */
1159 2 : bool HtmlExport::WriteHtml( const OUString& rFileName, bool bAddExtension, const OUString& rHtmlData )
1160 : {
1161 2 : sal_uLong nErr = 0;
1162 :
1163 2 : OUString aFileName( rFileName );
1164 2 : if( bAddExtension )
1165 0 : aFileName += maHTMLExtension;
1166 :
1167 2 : meEC.SetContext( STR_HTMLEXP_ERROR_CREATE_FILE, rFileName );
1168 4 : EasyFile aFile;
1169 : SvStream* pStr;
1170 4 : OUString aFull(maExportPath + aFileName);
1171 2 : nErr = aFile.createStream(aFull , pStr);
1172 2 : if(nErr == 0)
1173 : {
1174 : OString aStr(OUStringToOString(rHtmlData,
1175 2 : RTL_TEXTENCODING_UTF8));
1176 2 : pStr->WriteCharPtr( aStr.getStr() );
1177 2 : nErr = aFile.close();
1178 : }
1179 :
1180 2 : if( nErr != 0 )
1181 0 : ErrorHandler::HandleError(nErr);
1182 :
1183 4 : return nErr == 0;
1184 : }
1185 :
1186 : /** creates a outliner text for the title objects of a page
1187 : */
1188 8 : OUString HtmlExport::CreateTextForTitle( SdrOutliner* pOutliner, SdPage* pPage, const Color& rBackgroundColor )
1189 : {
1190 8 : SdrTextObj* pTO = (SdrTextObj*)pPage->GetPresObj(PRESOBJ_TITLE);
1191 8 : if(!pTO)
1192 0 : pTO = GetLayoutTextObject(pPage);
1193 :
1194 8 : if (pTO && !pTO->IsEmptyPresObj())
1195 : {
1196 8 : OutlinerParaObject* pOPO = pTO->GetOutlinerParaObject();
1197 8 : if(pOPO && pOutliner->GetParagraphCount() != 0)
1198 : {
1199 8 : pOutliner->Clear();
1200 8 : pOutliner->SetText(*pOPO);
1201 8 : return ParagraphToHTMLString(pOutliner,0, rBackgroundColor);
1202 : }
1203 : }
1204 :
1205 0 : return OUString();
1206 : }
1207 :
1208 : // creates a outliner text for a page
1209 8 : OUString HtmlExport::CreateTextForPage(SdrOutliner* pOutliner, SdPage* pPage,
1210 : bool bHeadLine, const Color& rBackgroundColor)
1211 : {
1212 8 : OUStringBuffer aStr;
1213 :
1214 24 : for (size_t i = 0; i <pPage->GetObjCount(); ++i )
1215 : {
1216 16 : SdrObject* pObject = pPage->GetObj(i);
1217 16 : PresObjKind eKind = pPage->GetPresObjKind(pObject);
1218 :
1219 16 : switch (eKind)
1220 : {
1221 : case PRESOBJ_NONE:
1222 : {
1223 0 : if (pObject->GetObjIdentifier() == OBJ_GRUP)
1224 : {
1225 0 : SdrObjGroup* pObjectGroup = (SdrObjGroup*) pObject;
1226 0 : WriteObjectGroup(aStr, pObjectGroup, pOutliner, rBackgroundColor, false);
1227 : }
1228 0 : else if (pObject->GetObjIdentifier() == OBJ_TABLE)
1229 : {
1230 0 : SdrTableObj* pTableObject = (SdrTableObj*) pObject;
1231 0 : WriteTable(aStr, pTableObject, pOutliner, rBackgroundColor);
1232 : }
1233 : else
1234 : {
1235 0 : if (pObject->GetOutlinerParaObject())
1236 : {
1237 0 : WriteOutlinerParagraph(aStr, pOutliner, pObject->GetOutlinerParaObject(), rBackgroundColor, false);
1238 : }
1239 : }
1240 : }
1241 0 : break;
1242 :
1243 : case PRESOBJ_TABLE:
1244 : {
1245 2 : SdrTableObj* pTableObject = (SdrTableObj*) pObject;
1246 2 : WriteTable(aStr, pTableObject, pOutliner, rBackgroundColor);
1247 : }
1248 2 : break;
1249 :
1250 : case PRESOBJ_TEXT:
1251 : case PRESOBJ_OUTLINE:
1252 : {
1253 4 : SdrTextObj* pTextObject = (SdrTextObj*) pObject;
1254 4 : if (pTextObject->IsEmptyPresObj())
1255 0 : continue;
1256 4 : WriteOutlinerParagraph(aStr, pOutliner, pTextObject->GetOutlinerParaObject(), rBackgroundColor, bHeadLine);
1257 : }
1258 4 : break;
1259 :
1260 : default:
1261 10 : break;
1262 : }
1263 : }
1264 8 : return aStr.makeStringAndClear();
1265 : }
1266 :
1267 2 : void HtmlExport::WriteTable(OUStringBuffer& aStr, SdrTableObj* pTableObject, SdrOutliner* pOutliner, const Color& rBackgroundColor)
1268 : {
1269 2 : CellPos aStart, aEnd;
1270 :
1271 2 : aStart = pTableObject->getFirstCell();
1272 2 : aEnd = pTableObject->getLastCell();
1273 :
1274 2 : sal_Int32 nColCount = pTableObject->getColumnCount();
1275 2 : aStr.append("<table>\r\n");
1276 12 : for (sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++)
1277 : {
1278 10 : aStr.append(" <tr>\r\n");
1279 30 : for (sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++)
1280 : {
1281 20 : aStr.append(" <td>\r\n");
1282 20 : sal_Int32 nCellIndex = nRow * nColCount + nCol;
1283 20 : SdrText* pText = pTableObject->getText(nCellIndex);
1284 :
1285 20 : if (pText == NULL)
1286 0 : continue;
1287 20 : WriteOutlinerParagraph(aStr, pOutliner, pText->GetOutlinerParaObject(), rBackgroundColor, false);
1288 20 : aStr.append(" </td>\r\n");
1289 : }
1290 10 : aStr.append(" </tr>\r\n");
1291 : }
1292 2 : aStr.append("</table>\r\n");
1293 2 : }
1294 :
1295 0 : void HtmlExport::WriteObjectGroup(OUStringBuffer& aStr, SdrObjGroup* pObjectGroup, SdrOutliner* pOutliner,
1296 : const Color& rBackgroundColor, bool bHeadLine)
1297 : {
1298 0 : SdrObjListIter aGroupIterator(*pObjectGroup->GetSubList(), IM_DEEPNOGROUPS);
1299 0 : while (aGroupIterator.IsMore())
1300 : {
1301 0 : SdrObject* pCurrentObject = aGroupIterator.Next();
1302 0 : if (pCurrentObject->GetObjIdentifier() == OBJ_GRUP)
1303 : {
1304 0 : SdrObjGroup* pCurrentGroupObject = (SdrObjGroup*) pCurrentObject;
1305 0 : WriteObjectGroup(aStr, pCurrentGroupObject, pOutliner, rBackgroundColor, bHeadLine);
1306 : }
1307 : else
1308 : {
1309 0 : OutlinerParaObject* pOutlinerParagraphObject = pCurrentObject->GetOutlinerParaObject();
1310 0 : if (pOutlinerParagraphObject != NULL)
1311 : {
1312 0 : WriteOutlinerParagraph(aStr, pOutliner, pOutlinerParagraphObject, rBackgroundColor, bHeadLine);
1313 : }
1314 : }
1315 0 : }
1316 0 : }
1317 :
1318 24 : void HtmlExport::WriteOutlinerParagraph(OUStringBuffer& aStr, SdrOutliner* pOutliner,
1319 : OutlinerParaObject* pOutlinerParagraphObject,
1320 : const Color& rBackgroundColor, bool bHeadLine)
1321 : {
1322 24 : if (pOutlinerParagraphObject == NULL)
1323 24 : return;
1324 :
1325 24 : pOutliner->SetText(*pOutlinerParagraphObject);
1326 :
1327 24 : sal_Int32 nCount = pOutliner->GetParagraphCount();
1328 :
1329 24 : Paragraph* pParagraph = NULL;
1330 :
1331 24 : sal_Int16 nCurrentDepth = -1;
1332 :
1333 68 : for (sal_Int32 nIndex = 0; nIndex < nCount; nIndex++)
1334 : {
1335 44 : pParagraph = pOutliner->GetParagraph(nIndex);
1336 44 : if(pParagraph == NULL)
1337 2 : continue;
1338 :
1339 44 : const sal_Int16 nDepth = (sal_uInt16) pOutliner->GetDepth(nIndex);
1340 44 : OUString aParaText = ParagraphToHTMLString(pOutliner, nIndex, rBackgroundColor);
1341 :
1342 44 : if (aParaText.isEmpty())
1343 2 : continue;
1344 :
1345 42 : if (nDepth < 0)
1346 : {
1347 14 : OUString aTag = bHeadLine ? OUString("h2") : OUString("p");
1348 14 : lclAppendStyle(aStr, aTag, getParagraphStyle(pOutliner, nIndex));
1349 :
1350 14 : aStr.append(aParaText);
1351 14 : aStr.append("</" + aTag + ">\r\n");
1352 : }
1353 : else
1354 : {
1355 70 : while(nCurrentDepth < nDepth)
1356 : {
1357 14 : aStr.append("<ul>\r\n");
1358 14 : nCurrentDepth++;
1359 : }
1360 60 : while(nCurrentDepth > nDepth)
1361 : {
1362 4 : aStr.append("</ul>\r\n");
1363 4 : nCurrentDepth--;
1364 : }
1365 28 : lclAppendStyle(aStr, "li", getParagraphStyle(pOutliner, nIndex));
1366 28 : aStr.append(aParaText);
1367 28 : aStr.append("</li>\r\n");
1368 : }
1369 42 : }
1370 58 : while(nCurrentDepth >= 0)
1371 : {
1372 10 : aStr.append("</ul>\r\n");
1373 10 : nCurrentDepth--;
1374 : }
1375 24 : pOutliner->Clear();
1376 : }
1377 :
1378 : // creates a outliner text for a note page
1379 0 : OUString HtmlExport::CreateTextForNotesPage( SdrOutliner* pOutliner,
1380 : SdPage* pPage,
1381 : bool,
1382 : const Color& rBackgroundColor )
1383 : {
1384 0 : OUStringBuffer aStr;
1385 :
1386 0 : SdrTextObj* pTO = (SdrTextObj*)pPage->GetPresObj(PRESOBJ_NOTES);
1387 :
1388 0 : if (pTO && !pTO->IsEmptyPresObj())
1389 : {
1390 0 : OutlinerParaObject* pOPO = pTO->GetOutlinerParaObject();
1391 0 : if (pOPO)
1392 : {
1393 0 : pOutliner->Clear();
1394 0 : pOutliner->SetText( *pOPO );
1395 :
1396 0 : sal_Int32 nCount = pOutliner->GetParagraphCount();
1397 0 : for (sal_Int32 nPara = 0; nPara < nCount; nPara++)
1398 : {
1399 0 : lclAppendStyle(aStr, "p", getParagraphStyle(pOutliner, nPara));
1400 0 : aStr.append(ParagraphToHTMLString(pOutliner, nPara, rBackgroundColor));
1401 0 : aStr.append("</p>\r\n");
1402 : }
1403 : }
1404 : }
1405 :
1406 0 : return aStr.makeStringAndClear();
1407 : }
1408 :
1409 : // converts a paragraph of the outliner to html
1410 52 : OUString HtmlExport::ParagraphToHTMLString( SdrOutliner* pOutliner, sal_Int32 nPara, const Color& rBackgroundColor )
1411 : {
1412 52 : OUStringBuffer aStr;
1413 :
1414 52 : if(NULL == pOutliner)
1415 0 : return OUString();
1416 :
1417 : // TODO: MALTE!!!
1418 52 : EditEngine& rEditEngine = *(EditEngine*)&pOutliner->GetEditEngine();
1419 52 : bool bOldUpdateMode = rEditEngine.GetUpdateMode();
1420 52 : rEditEngine.SetUpdateMode(true);
1421 :
1422 52 : Paragraph* pPara = pOutliner->GetParagraph(nPara);
1423 52 : if(NULL == pPara)
1424 0 : return OUString();
1425 :
1426 104 : HtmlState aState( (mbUserAttr || mbDocColors) ? maTextColor : Color(COL_BLACK) );
1427 104 : std::vector<sal_Int32> aPortionList;
1428 52 : rEditEngine.GetPortions( nPara, aPortionList );
1429 :
1430 52 : sal_Int32 nPos1 = 0;
1431 104 : for( std::vector<sal_Int32>::const_iterator it( aPortionList.begin() ); it != aPortionList.end(); ++it )
1432 : {
1433 52 : sal_Int32 nPos2 = *it;
1434 :
1435 52 : ESelection aSelection( nPara, nPos1, nPara, nPos2);
1436 :
1437 52 : SfxItemSet aSet( rEditEngine.GetAttribs( aSelection ) );
1438 :
1439 104 : OUString aPortion(StringToHTMLString(rEditEngine.GetText( aSelection )));
1440 :
1441 52 : aStr.append(TextAttribToHTMLString( &aSet, &aState, rBackgroundColor ));
1442 52 : aStr.append(aPortion);
1443 :
1444 52 : nPos1 = nPos2;
1445 52 : }
1446 52 : aStr.append(aState.Flush());
1447 52 : rEditEngine.SetUpdateMode(bOldUpdateMode);
1448 :
1449 104 : return aStr.makeStringAndClear();
1450 : }
1451 :
1452 : // Depending on the attributes of the specified set and the specified
1453 : // HtmlState, it creates the needed html tags in order to get the
1454 : // attributes
1455 52 : OUString HtmlExport::TextAttribToHTMLString( SfxItemSet* pSet, HtmlState* pState, const Color& rBackgroundColor )
1456 : {
1457 52 : OUStringBuffer aStr;
1458 :
1459 52 : if(NULL == pSet)
1460 0 : return OUString();
1461 :
1462 104 : OUString aLink, aTarget;
1463 52 : if ( pSet->GetItemState( EE_FEATURE_FIELD ) == SfxItemState::SET )
1464 : {
1465 0 : SvxFieldItem* pItem = (SvxFieldItem*)pSet->GetItem( EE_FEATURE_FIELD );
1466 0 : if(pItem)
1467 : {
1468 0 : const SvxURLField* pURL = PTR_CAST(SvxURLField, pItem->GetField());
1469 0 : if(pURL)
1470 : {
1471 0 : aLink = pURL->GetURL();
1472 0 : aTarget = pURL->GetTargetFrame();
1473 : }
1474 : }
1475 : }
1476 :
1477 : bool bTemp;
1478 104 : OUString aTemp;
1479 :
1480 52 : if ( pSet->GetItemState( EE_CHAR_WEIGHT ) == SfxItemState::SET )
1481 : {
1482 52 : bTemp = ((const SvxWeightItem&)pSet->Get( EE_CHAR_WEIGHT )).GetWeight() == WEIGHT_BOLD;
1483 52 : aTemp = pState->SetWeight( bTemp );
1484 52 : if( bTemp )
1485 0 : aStr.insert(0, aTemp);
1486 : else
1487 52 : aStr.append(aTemp);
1488 : }
1489 :
1490 52 : if ( pSet->GetItemState( EE_CHAR_UNDERLINE ) == SfxItemState::SET )
1491 : {
1492 52 : bTemp = ((const SvxUnderlineItem&)pSet->Get( EE_CHAR_UNDERLINE )).GetLineStyle() != UNDERLINE_NONE;
1493 52 : aTemp = pState->SetUnderline( bTemp );
1494 52 : if( bTemp )
1495 0 : aStr.insert(0, aTemp);
1496 : else
1497 52 : aStr.append(aTemp);
1498 : }
1499 :
1500 52 : if ( pSet->GetItemState( EE_CHAR_STRIKEOUT ) == SfxItemState::SET )
1501 : {
1502 52 : bTemp = ((const SvxCrossedOutItem&)pSet->Get( EE_CHAR_STRIKEOUT )).GetStrikeout() != STRIKEOUT_NONE;
1503 52 : aTemp = pState->SetStrikeout( bTemp );
1504 52 : if( bTemp )
1505 0 : aStr.insert(0, aTemp);
1506 : else
1507 52 : aStr.append(aTemp);
1508 : }
1509 :
1510 52 : if ( pSet->GetItemState( EE_CHAR_ITALIC ) == SfxItemState::SET )
1511 : {
1512 52 : bTemp = ((const SvxPostureItem&)pSet->Get( EE_CHAR_ITALIC )).GetPosture() != ITALIC_NONE;
1513 52 : aTemp = pState->SetItalic( bTemp );
1514 52 : if( bTemp )
1515 0 : aStr.insert(0, aTemp);
1516 : else
1517 52 : aStr.append(aTemp);
1518 : }
1519 :
1520 52 : if(mbDocColors)
1521 : {
1522 0 : if ( pSet->GetItemState( EE_CHAR_COLOR ) == SfxItemState::SET )
1523 : {
1524 0 : Color aTextColor = ((const SvxColorItem&) pSet->Get( EE_CHAR_COLOR )).GetValue();
1525 0 : if( aTextColor == COL_AUTO )
1526 : {
1527 0 : if( !rBackgroundColor.IsDark() )
1528 0 : aTextColor = COL_BLACK;
1529 : }
1530 0 : aStr.append(pState->SetColor( aTextColor ));
1531 : }
1532 : }
1533 :
1534 52 : if (!aLink.isEmpty())
1535 0 : aStr.insert(0, pState->SetLink(aLink, aTarget));
1536 : else
1537 52 : aStr.append(pState->SetLink(aLink, aTarget));
1538 :
1539 104 : return aStr.makeStringAndClear();
1540 : }
1541 :
1542 : // create HTML wrapper for picture files
1543 0 : bool HtmlExport::CreateHtmlForPresPages()
1544 : {
1545 0 : bool bOk = true;
1546 :
1547 0 : std::vector<SdrObject*> aClickableObjects;
1548 :
1549 0 : for(sal_uInt16 nSdPage = 0; nSdPage < mnSdPageCount && bOk; nSdPage++)
1550 : {
1551 : // find clickable objects (also on the master page) and put it in the
1552 : // list. This in reverse order character order since in html the first
1553 : // area is taken in the case they overlap.
1554 0 : SdPage* pPage = maPages[ nSdPage ];
1555 :
1556 0 : if( mbDocColors )
1557 : {
1558 0 : SetDocColors( pPage );
1559 : }
1560 :
1561 0 : bool bMasterDone = false;
1562 :
1563 0 : while (!bMasterDone)
1564 : {
1565 : // sal_True = backwards
1566 0 : SdrObjListIter aIter(*pPage, IM_DEEPWITHGROUPS, true);
1567 :
1568 0 : SdrObject* pObject = aIter.Next();
1569 0 : while (pObject)
1570 : {
1571 0 : SdAnimationInfo* pInfo = mpDoc->GetAnimationInfo(pObject);
1572 0 : SdIMapInfo* pIMapInfo = mpDoc->GetIMapInfo(pObject);
1573 :
1574 0 : if ((pInfo &&
1575 0 : (pInfo->meClickAction == presentation::ClickAction_BOOKMARK ||
1576 0 : pInfo->meClickAction == presentation::ClickAction_DOCUMENT ||
1577 0 : pInfo->meClickAction == presentation::ClickAction_PREVPAGE ||
1578 0 : pInfo->meClickAction == presentation::ClickAction_NEXTPAGE ||
1579 0 : pInfo->meClickAction == presentation::ClickAction_FIRSTPAGE ||
1580 0 : pInfo->meClickAction == presentation::ClickAction_LASTPAGE)) ||
1581 : pIMapInfo)
1582 : {
1583 0 : aClickableObjects.push_back(pObject);
1584 : }
1585 :
1586 0 : pObject = aIter.Next();
1587 : }
1588 : // now to the master page or finishing
1589 0 : if (!pPage->IsMasterPage())
1590 0 : pPage = (SdPage*)(&(pPage->TRG_GetMasterPage()));
1591 : else
1592 0 : bMasterDone = true;
1593 0 : }
1594 :
1595 : // HTML Head
1596 0 : OUStringBuffer aStr(maHTMLHeader);
1597 0 : aStr.append(CreateMetaCharset());
1598 0 : aStr.append(" <title>" + StringToHTMLString(maPageNames[nSdPage]) + "</title>\r\n");
1599 :
1600 : // insert timing information
1601 0 : pPage = maPages[ nSdPage ];
1602 0 : if( meMode == PUBLISH_KIOSK )
1603 : {
1604 0 : double fSecs = 0;
1605 0 : bool bEndless = false;
1606 0 : if( !mbAutoSlide )
1607 : {
1608 0 : if( pPage->GetPresChange() != PRESCHANGE_MANUAL )
1609 : {
1610 0 : fSecs = pPage->GetTime();
1611 0 : bEndless = mpDoc->getPresentationSettings().mbEndless;
1612 : }
1613 : }
1614 : else
1615 : {
1616 0 : fSecs = mfSlideDuration;
1617 0 : bEndless = mbEndless;
1618 : }
1619 :
1620 0 : if( fSecs != 0 )
1621 : {
1622 0 : if( nSdPage < (mnSdPageCount-1) || bEndless )
1623 : {
1624 0 : aStr.append("<meta http-equiv=\"refresh\" content=\"");
1625 0 : aStr.append(OUString::number(fSecs));
1626 0 : aStr.append("; URL=");
1627 :
1628 0 : int nPage = nSdPage + 1;
1629 0 : if( nPage == mnSdPageCount )
1630 0 : nPage = 0;
1631 :
1632 0 : aStr.append(maHTMLFiles[nPage]);
1633 :
1634 0 : aStr.append("\">\r\n");
1635 : }
1636 : }
1637 : }
1638 :
1639 0 : aStr.append("</head>\r\n");
1640 :
1641 : // HTML Body
1642 0 : aStr.append(CreateBodyTag());
1643 :
1644 0 : if( mbSlideSound && pPage->IsSoundOn() )
1645 0 : aStr.append(InsertSound(pPage->GetSoundFile()));
1646 :
1647 : // navigation bar
1648 0 : if(!mbFrames )
1649 0 : aStr.append(CreateNavBar(nSdPage, false));
1650 : // Image
1651 0 : aStr.append("<center>");
1652 0 : aStr.append("<img src=\"");
1653 0 : aStr.append(maImageFiles[nSdPage]);
1654 0 : aStr.append("\" alt=\"\"");
1655 :
1656 0 : if (!aClickableObjects.empty())
1657 0 : aStr.append(" USEMAP=\"#map0\"");
1658 :
1659 0 : aStr.append("></center>\r\n");
1660 :
1661 : // notes
1662 0 : if(mbNotes && !mbFrames)
1663 : {
1664 0 : SdrOutliner* pOutliner = mpDoc->GetInternalOutliner();
1665 0 : SdPage* pNotesPage = maNotesPages[ nSdPage ];
1666 0 : OUString aNotesStr( CreateTextForNotesPage( pOutliner, pNotesPage, true, maBackColor) );
1667 0 : pOutliner->Clear();
1668 :
1669 0 : if (!aNotesStr.isEmpty())
1670 : {
1671 0 : aStr.append("<h3>");
1672 0 : aStr.append(RESTOHTML(STR_HTMLEXP_NOTES));
1673 0 : aStr.append(":</h3><br>\r\n\r\n<p>");
1674 :
1675 0 : aStr.append(aNotesStr);
1676 0 : aStr.append("\r\n</p>\r\n");
1677 0 : }
1678 : }
1679 :
1680 : // create Imagemap if necessary
1681 0 : if (!aClickableObjects.empty())
1682 : {
1683 0 : aStr.append("<map name=\"map0\">\r\n");
1684 :
1685 0 : for (sal_uInt32 nObject = 0, n = aClickableObjects.size(); nObject < n; nObject++)
1686 : {
1687 0 : SdrObject* pObject = aClickableObjects[nObject];
1688 0 : SdAnimationInfo* pInfo = mpDoc->GetAnimationInfo(pObject);
1689 0 : SdIMapInfo* pIMapInfo = mpDoc->GetIMapInfo(pObject);
1690 :
1691 0 : Rectangle aRect(pObject->GetCurrentBoundRect());
1692 0 : Point aLogPos(aRect.TopLeft());
1693 0 : bool bIsSquare = aRect.GetWidth() == aRect.GetHeight();
1694 :
1695 0 : sal_uLong nPageWidth = pPage->GetSize().Width() - pPage->GetLftBorder() -
1696 0 : pPage->GetRgtBorder();
1697 :
1698 : // BoundRect is relative to the physical page origin, not the
1699 : // origin of ordinates
1700 0 : aRect.Move(-pPage->GetLftBorder(), -pPage->GetUppBorder());
1701 :
1702 0 : double fLogicToPixel = ((double)mnWidthPixel) / nPageWidth;
1703 0 : aRect.Left() = (long)(aRect.Left() * fLogicToPixel);
1704 0 : aRect.Top() = (long)(aRect.Top() * fLogicToPixel);
1705 0 : aRect.Right() = (long)(aRect.Right() * fLogicToPixel);
1706 0 : aRect.Bottom() = (long)(aRect.Bottom() * fLogicToPixel);
1707 0 : long nRadius = aRect.GetWidth() / 2;
1708 :
1709 : /**
1710 : insert areas into Imagemap of the object, if the object has
1711 : such a Imagemap
1712 : */
1713 0 : if (pIMapInfo)
1714 : {
1715 0 : const ImageMap& rIMap = pIMapInfo->GetImageMap();
1716 0 : sal_uInt16 nAreaCount = rIMap.GetIMapObjectCount();
1717 0 : for (sal_uInt16 nArea = 0; nArea < nAreaCount; nArea++)
1718 : {
1719 0 : IMapObject* pArea = rIMap.GetIMapObject(nArea);
1720 0 : sal_uInt16 nType = pArea->GetType();
1721 0 : OUString aURL( pArea->GetURL() );
1722 :
1723 : // if necessary, convert page and object names into the
1724 : // corresponding names of the html file
1725 : bool bIsMasterPage;
1726 0 : sal_uInt16 nPgNum = mpDoc->GetPageByName( aURL, bIsMasterPage );
1727 0 : SdrObject* pObj = NULL;
1728 :
1729 0 : if (nPgNum == SDRPAGE_NOTFOUND)
1730 : {
1731 : // is the bookmark a object?
1732 0 : pObj = mpDoc->GetObj( aURL );
1733 0 : if (pObj)
1734 0 : nPgNum = pObj->GetPage()->GetPageNum();
1735 : }
1736 0 : if (nPgNum != SDRPAGE_NOTFOUND)
1737 : {
1738 0 : nPgNum = (nPgNum - 1) / 2; // SdrPageNum --> SdPageNum
1739 0 : aURL = CreatePageURL(nPgNum);
1740 : }
1741 :
1742 0 : switch(nType)
1743 : {
1744 : case IMAP_OBJ_RECTANGLE:
1745 : {
1746 : Rectangle aArea(((IMapRectangleObject*)pArea)->
1747 0 : GetRectangle(false));
1748 :
1749 : // conversion into pixel coordinates
1750 0 : aArea.Move(aLogPos.X() - pPage->GetLftBorder(),
1751 0 : aLogPos.Y() - pPage->GetUppBorder());
1752 0 : aArea.Left() = (long)(aArea.Left() * fLogicToPixel);
1753 0 : aArea.Top() = (long)(aArea.Top() * fLogicToPixel);
1754 0 : aArea.Right() = (long)(aArea.Right() * fLogicToPixel);
1755 0 : aArea.Bottom() = (long)(aArea.Bottom() * fLogicToPixel);
1756 :
1757 0 : aStr.append(CreateHTMLRectArea(aArea, aURL));
1758 : }
1759 0 : break;
1760 :
1761 : case IMAP_OBJ_CIRCLE:
1762 : {
1763 : Point aCenter(((IMapCircleObject*)pArea)->
1764 0 : GetCenter(false));
1765 0 : aCenter += Point(aLogPos.X() - pPage->GetLftBorder(),
1766 0 : aLogPos.Y() - pPage->GetUppBorder());
1767 0 : aCenter.X() = (long)(aCenter.X() * fLogicToPixel);
1768 0 : aCenter.Y() = (long)(aCenter.Y() * fLogicToPixel);
1769 :
1770 : sal_uLong nCircleRadius = (((IMapCircleObject*)pArea)->
1771 0 : GetRadius(false));
1772 0 : nCircleRadius = (sal_uLong)(nCircleRadius * fLogicToPixel);
1773 : aStr.append(CreateHTMLCircleArea(nCircleRadius,
1774 0 : aCenter.X(), aCenter.Y(),
1775 0 : aURL));
1776 : }
1777 0 : break;
1778 :
1779 : case IMAP_OBJ_POLYGON:
1780 : {
1781 0 : Polygon aArea(((IMapPolygonObject*)pArea)->GetPolygon(false));
1782 0 : aStr.append(CreateHTMLPolygonArea(::basegfx::B2DPolyPolygon(aArea.getB2DPolygon()), Size(aLogPos.X() - pPage->GetLftBorder(), aLogPos.Y() - pPage->GetUppBorder()), fLogicToPixel, aURL));
1783 : }
1784 0 : break;
1785 :
1786 : default:
1787 : {
1788 : DBG_WARNING("unknown IMAP_OBJ_type");
1789 : }
1790 0 : break;
1791 : }
1792 0 : }
1793 : }
1794 :
1795 : /**
1796 : if there is a presentation::ClickAction, determine bookmark
1797 : and create area for the whole object
1798 : */
1799 0 : if( pInfo )
1800 : {
1801 0 : OUString aHRef;
1802 0 : presentation::ClickAction eClickAction = pInfo->meClickAction;
1803 :
1804 0 : switch( eClickAction )
1805 : {
1806 : case presentation::ClickAction_BOOKMARK:
1807 : {
1808 : bool bIsMasterPage;
1809 0 : sal_uInt16 nPgNum = mpDoc->GetPageByName( pInfo->GetBookmark(), bIsMasterPage );
1810 0 : SdrObject* pObj = NULL;
1811 :
1812 0 : if( nPgNum == SDRPAGE_NOTFOUND )
1813 : {
1814 : // is the bookmark a object?
1815 0 : pObj = mpDoc->GetObj(pInfo->GetBookmark());
1816 0 : if (pObj)
1817 0 : nPgNum = pObj->GetPage()->GetPageNum();
1818 : }
1819 :
1820 0 : if( SDRPAGE_NOTFOUND != nPgNum )
1821 0 : aHRef = CreatePageURL(( nPgNum - 1 ) / 2 );
1822 : }
1823 0 : break;
1824 :
1825 : case presentation::ClickAction_DOCUMENT:
1826 0 : aHRef = pInfo->GetBookmark();
1827 0 : break;
1828 :
1829 : case presentation::ClickAction_PREVPAGE:
1830 : {
1831 : sal_uLong nPage;
1832 :
1833 0 : if (nSdPage == 0)
1834 0 : nPage = 0;
1835 : else
1836 0 : nPage = nSdPage - 1;
1837 :
1838 0 : aHRef = CreatePageURL( (sal_uInt16) nPage);
1839 : }
1840 0 : break;
1841 :
1842 : case presentation::ClickAction_NEXTPAGE:
1843 : {
1844 0 : sal_uLong nPage = nSdPage;
1845 0 : if (nSdPage == mnSdPageCount - 1)
1846 0 : nPage = mnSdPageCount - 1;
1847 : else
1848 0 : nPage = nSdPage + 1;
1849 :
1850 0 : aHRef = CreatePageURL( (sal_uInt16) nPage);
1851 : }
1852 0 : break;
1853 :
1854 : case presentation::ClickAction_FIRSTPAGE:
1855 0 : aHRef = CreatePageURL(0);
1856 0 : break;
1857 :
1858 : case presentation::ClickAction_LASTPAGE:
1859 0 : aHRef = CreatePageURL(mnSdPageCount - 1);
1860 0 : break;
1861 :
1862 : default:
1863 0 : break;
1864 : }
1865 :
1866 : // and now the areas
1867 0 : if (!aHRef.isEmpty())
1868 : {
1869 : // a circle?
1870 0 : if (pObject->GetObjInventor() == SdrInventor &&
1871 0 : pObject->GetObjIdentifier() == OBJ_CIRC &&
1872 : bIsSquare )
1873 : {
1874 0 : aStr.append(CreateHTMLCircleArea(aRect.GetWidth() / 2,
1875 0 : aRect.Left() + nRadius,
1876 0 : aRect.Top() + nRadius,
1877 0 : aHRef));
1878 : }
1879 : // a polygon?
1880 0 : else if (pObject->GetObjInventor() == SdrInventor &&
1881 0 : (pObject->GetObjIdentifier() == OBJ_PATHLINE ||
1882 0 : pObject->GetObjIdentifier() == OBJ_PLIN ||
1883 0 : pObject->GetObjIdentifier() == OBJ_POLY))
1884 : {
1885 0 : aStr.append(CreateHTMLPolygonArea(((SdrPathObj*)pObject)->GetPathPoly(), Size(-pPage->GetLftBorder(), -pPage->GetUppBorder()), fLogicToPixel, aHRef));
1886 : }
1887 : // something completely different: use the BoundRect
1888 : else
1889 : {
1890 0 : aStr.append(CreateHTMLRectArea(aRect, aHRef));
1891 : }
1892 :
1893 0 : }
1894 : }
1895 : }
1896 :
1897 0 : aStr.append("</map>\r\n");
1898 : }
1899 0 : aClickableObjects.clear();
1900 :
1901 0 : aStr.append("</body>\r\n</html>");
1902 :
1903 0 : bOk = WriteHtml(maHTMLFiles[nSdPage], false, aStr.makeStringAndClear());
1904 :
1905 0 : if (mpProgress)
1906 0 : mpProgress->SetState(++mnPagesWritten);
1907 0 : }
1908 :
1909 0 : return bOk;
1910 : }
1911 :
1912 : // create overview pages
1913 0 : bool HtmlExport::CreateContentPage()
1914 : {
1915 0 : if( mbDocColors )
1916 0 : SetDocColors();
1917 :
1918 : // html head
1919 0 : OUStringBuffer aStr(maHTMLHeader);
1920 0 : aStr.append(CreateMetaCharset());
1921 0 : aStr.append(" <title>");
1922 0 : aStr.append(StringToHTMLString(maPageNames[0]));
1923 0 : aStr.append("</title>\r\n</head>\r\n");
1924 0 : aStr.append(CreateBodyTag());
1925 :
1926 : // page head
1927 0 : aStr.append("<center>\r\n");
1928 :
1929 0 : if(mbHeader)
1930 : {
1931 0 : aStr.append("<h1>");
1932 0 : aStr.append(getDocumentTitle());
1933 0 : aStr.append("</h1><br>\r\n");
1934 : }
1935 :
1936 0 : aStr.append("<h2>");
1937 :
1938 : // Solaris compiler bug workaround
1939 0 : if( mbFrames )
1940 : aStr.append(CreateLink(maFramePage,
1941 0 : RESTOHTML(STR_HTMLEXP_CLICKSTART)));
1942 : else
1943 0 : aStr.append(CreateLink(StringToHTMLString(maHTMLFiles[0]),
1944 0 : RESTOHTML(STR_HTMLEXP_CLICKSTART)));
1945 :
1946 0 : aStr.append("</h2>\r\n</center>\r\n");
1947 :
1948 0 : aStr.append("<center><table width=\"90%\"><tr>\r\n");
1949 :
1950 : // table of content
1951 0 : aStr.append("<td valign=\"top\" align=\"left\" width=\"25%\">\r\n");
1952 0 : aStr.append("<h3>");
1953 0 : aStr.append(RESTOHTML(STR_HTMLEXP_CONTENTS));
1954 0 : aStr.append("</h3>");
1955 :
1956 0 : for(sal_uInt16 nSdPage = 0; nSdPage < mnSdPageCount; nSdPage++)
1957 : {
1958 0 : OUString aPageName = maPageNames[nSdPage];
1959 0 : aStr.append("<div align=\"left\">");
1960 0 : if(mbFrames)
1961 0 : aStr.append(StringToHTMLString(aPageName));
1962 : else
1963 0 : aStr.append(CreateLink(maHTMLFiles[nSdPage], aPageName));
1964 0 : aStr.append("</div>\r\n");
1965 0 : }
1966 0 : aStr.append("</td>\r\n");
1967 :
1968 : // document information
1969 0 : aStr.append("<td valign=\"top\" align=\"left\" width=\"75%\">\r\n");
1970 :
1971 0 : if (!maAuthor.isEmpty())
1972 : {
1973 0 : aStr.append("<p><strong>");
1974 0 : aStr.append(RESTOHTML(STR_HTMLEXP_AUTHOR));
1975 0 : aStr.append(":</strong> ");
1976 0 : aStr.append(StringToHTMLString(maAuthor));
1977 0 : aStr.append("</p>\r\n");
1978 : }
1979 :
1980 0 : if (!maEMail.isEmpty())
1981 : {
1982 0 : aStr.append("<p><strong>");
1983 0 : aStr.append(RESTOHTML(STR_HTMLEXP_EMAIL));
1984 0 : aStr.append(":</strong> <a href=\"mailto:");
1985 0 : aStr.append(maEMail);
1986 0 : aStr.append("\">");
1987 0 : aStr.append(StringToHTMLString(maEMail));
1988 0 : aStr.append("</a></p>\r\n");
1989 : }
1990 :
1991 0 : if (!maHomePage.isEmpty())
1992 : {
1993 0 : aStr.append("<p><strong>");
1994 0 : aStr.append(RESTOHTML(STR_HTMLEXP_HOMEPAGE));
1995 0 : aStr.append(":</strong> <a href=\"");
1996 0 : aStr.append(maHomePage);
1997 0 : aStr.append("\">");
1998 0 : aStr.append(StringToHTMLString(maHomePage));
1999 0 : aStr.append("</a> </p>\r\n");
2000 : }
2001 :
2002 0 : if (!maInfo.isEmpty())
2003 : {
2004 0 : aStr.append("<p><strong>");
2005 0 : aStr.append(RESTOHTML(STR_HTMLEXP_INFO));
2006 0 : aStr.append(":</strong><br>\r\n");
2007 0 : aStr.append(StringToHTMLString(maInfo));
2008 0 : aStr.append("</p>\r\n");
2009 : }
2010 :
2011 0 : if(mbDownload)
2012 : {
2013 0 : aStr.append("<p><a href=\"");
2014 0 : aStr.append(maDocFileName);
2015 0 : aStr.append("\">");
2016 0 : aStr.append(RESTOHTML(STR_HTMLEXP_DOWNLOAD));
2017 0 : aStr.append("</a></p>\r\n");
2018 : }
2019 :
2020 0 : for(sal_uInt16 nSdPage = 0; nSdPage < mnSdPageCount; nSdPage++)
2021 : {
2022 : OUString aText(
2023 0 : "<img src=\"" +
2024 0 : maThumbnailFiles[nSdPage] +
2025 0 : "\" width=\"256\" height=\"192\" alt=\"" +
2026 0 : StringToHTMLString(maPageNames[nSdPage]) +
2027 0 : "\">");
2028 :
2029 0 : aStr.append(CreateLink(maHTMLFiles[nSdPage], aText));
2030 0 : aStr.append("\r\n");
2031 0 : }
2032 :
2033 0 : aStr.append("</td></tr></table></center>\r\n");
2034 :
2035 0 : aStr.append("</body>\r\n</html>");
2036 :
2037 0 : bool bOk = WriteHtml(maIndex, false, aStr.makeStringAndClear());
2038 :
2039 0 : if (mpProgress)
2040 0 : mpProgress->SetState(++mnPagesWritten);
2041 :
2042 0 : return bOk;
2043 : }
2044 :
2045 : // create note pages (for frames)
2046 :
2047 0 : bool HtmlExport::CreateNotesPages()
2048 : {
2049 0 : bool bOk = true;
2050 :
2051 0 : SdrOutliner* pOutliner = mpDoc->GetInternalOutliner();
2052 0 : for( sal_uInt16 nSdPage = 0; bOk && nSdPage < mnSdPageCount; nSdPage++ )
2053 : {
2054 0 : SdPage* pPage = maNotesPages[nSdPage];
2055 0 : if( mbDocColors )
2056 0 : SetDocColors( pPage );
2057 :
2058 : // Html head
2059 0 : OUStringBuffer aStr(maHTMLHeader);
2060 0 : aStr.append(CreateMetaCharset());
2061 0 : aStr.append(" <title>");
2062 0 : aStr.append(StringToHTMLString(maPageNames[0]));
2063 0 : aStr.append("</title>\r\n</head>\r\n");
2064 0 : aStr.append(CreateBodyTag());
2065 :
2066 0 : if(pPage)
2067 0 : aStr.append(CreateTextForNotesPage( pOutliner, pPage, true, maBackColor ));
2068 :
2069 0 : aStr.append("</body>\r\n</html>");
2070 :
2071 0 : OUString aFileName("note" + OUString::number(nSdPage));
2072 0 : bOk = WriteHtml(aFileName, true, aStr.makeStringAndClear());
2073 :
2074 0 : if (mpProgress)
2075 0 : mpProgress->SetState(++mnPagesWritten);
2076 0 : }
2077 :
2078 0 : pOutliner->Clear();
2079 :
2080 0 : return bOk;
2081 : }
2082 :
2083 : // create outline pages (for frames)
2084 :
2085 0 : bool HtmlExport::CreateOutlinePages()
2086 : {
2087 0 : bool bOk = true;
2088 :
2089 0 : if( mbDocColors )
2090 : {
2091 0 : SetDocColors();
2092 : }
2093 :
2094 : // page 0 will be the closed outline, page 1 the opened
2095 0 : for (sal_Int32 nPage = 0; nPage < (mbImpress?2:1) && bOk; ++nPage)
2096 : {
2097 : // Html head
2098 0 : OUStringBuffer aStr(maHTMLHeader);
2099 0 : aStr.append(CreateMetaCharset());
2100 0 : aStr.append(" <title>");
2101 0 : aStr.append(StringToHTMLString(maPageNames[0]));
2102 0 : aStr.append("</title>\r\n</head>\r\n");
2103 0 : aStr.append(CreateBodyTag());
2104 :
2105 0 : SdrOutliner* pOutliner = mpDoc->GetInternalOutliner();
2106 0 : for(sal_uInt16 nSdPage = 0; nSdPage < mnSdPageCount; nSdPage++)
2107 : {
2108 0 : SdPage* pPage = maPages[ nSdPage ];
2109 :
2110 0 : aStr.append("<div align=\"left\">");
2111 0 : OUString aLink("JavaScript:parent.NavigateAbs(" +
2112 0 : OUString::number(nSdPage) + ")");
2113 :
2114 0 : OUString aTitle = CreateTextForTitle(pOutliner, pPage, maBackColor);
2115 0 : if (aTitle.isEmpty())
2116 0 : aTitle = maPageNames[nSdPage];
2117 :
2118 0 : lclAppendStyle(aStr, "p", getParagraphStyle(pOutliner, 0));
2119 0 : aStr.append(CreateLink(aLink, aTitle));
2120 0 : aStr.append("</p>");
2121 :
2122 0 : if(nPage==1)
2123 : {
2124 0 : aStr.append(CreateTextForPage( pOutliner, pPage, false, maBackColor ));
2125 : }
2126 0 : aStr.append("</div>\r\n");
2127 0 : }
2128 0 : pOutliner->Clear();
2129 :
2130 0 : aStr.append("</body>\r\n</html>");
2131 :
2132 0 : OUString aFileName("outline" + OUString::number(nPage));
2133 0 : bOk = WriteHtml(aFileName, true, aStr.makeStringAndClear());
2134 :
2135 0 : if (mpProgress)
2136 0 : mpProgress->SetState(++mnPagesWritten);
2137 0 : }
2138 :
2139 0 : return bOk;
2140 : }
2141 :
2142 : // set file name
2143 0 : void HtmlExport::CreateFileNames()
2144 : {
2145 : // create lists with new file names
2146 0 : maHTMLFiles.resize(mnSdPageCount);
2147 0 : maImageFiles.resize(mnSdPageCount);
2148 0 : maThumbnailFiles.resize(mnSdPageCount);
2149 0 : maPageNames.resize(mnSdPageCount);
2150 0 : maTextFiles.resize(mnSdPageCount);
2151 :
2152 0 : mbHeader = false; // headline on overview page?
2153 :
2154 0 : for (sal_uInt16 nSdPage = 0; nSdPage < mnSdPageCount; nSdPage++)
2155 : {
2156 0 : OUString aHTMLFileName;
2157 0 : if(nSdPage == 0 && !mbContentsPage && !mbFrames )
2158 0 : aHTMLFileName = maIndex;
2159 : else
2160 : {
2161 0 : aHTMLFileName = "img" + OUString::number(nSdPage) + maHTMLExtension;
2162 : }
2163 :
2164 0 : maHTMLFiles[nSdPage] = aHTMLFileName;
2165 :
2166 0 : OUString aImageFileName = "img" + OUString::number(nSdPage);
2167 0 : if( meFormat==FORMAT_GIF )
2168 0 : aImageFileName += ".gif";
2169 0 : else if( meFormat==FORMAT_JPG )
2170 0 : aImageFileName += ".jpg";
2171 : else
2172 0 : aImageFileName += ".png";
2173 :
2174 0 : maImageFiles[nSdPage] = aImageFileName;
2175 :
2176 0 : OUString aThumbnailFileName = "thumb" + OUString::number(nSdPage);
2177 0 : if( meFormat!=FORMAT_JPG )
2178 0 : aThumbnailFileName += ".png";
2179 : else
2180 0 : aThumbnailFileName += ".jpg";
2181 :
2182 0 : maThumbnailFiles[nSdPage] = aThumbnailFileName;
2183 :
2184 0 : maTextFiles[nSdPage] = "text" + OUString::number(nSdPage) + maHTMLExtension;
2185 :
2186 0 : SdPage* pSdPage = maPages[ nSdPage ];
2187 :
2188 : // get slide title from page name
2189 0 : maPageNames[nSdPage] = pSdPage->GetName();
2190 0 : }
2191 :
2192 0 : if(!mbContentsPage && mbFrames)
2193 0 : maFramePage = maIndex;
2194 : else
2195 : {
2196 0 : maFramePage = "siframes" + maHTMLExtension;
2197 : }
2198 0 : }
2199 :
2200 0 : OUString HtmlExport::getDocumentTitle()
2201 : {
2202 : // check for a title object in this page, if its the first
2203 : // title it becomes this documents title for the content
2204 : // page
2205 0 : if( !mbHeader )
2206 : {
2207 0 : if(mbImpress)
2208 : {
2209 : // if there is a non-empty title object, use their first passage
2210 : // as page title
2211 0 : SdPage* pSdPage = mpDoc->GetSdPage(0, PK_STANDARD);
2212 0 : SdrObject* pTitleObj = pSdPage->GetPresObj(PRESOBJ_TITLE);
2213 0 : if (pTitleObj && !pTitleObj->IsEmptyPresObj())
2214 : {
2215 0 : OutlinerParaObject* pParaObject = pTitleObj->GetOutlinerParaObject();
2216 0 : if (pParaObject)
2217 : {
2218 : const EditTextObject& rEditTextObject =
2219 0 : pParaObject->GetTextObject();
2220 0 : OUString aTest(rEditTextObject.GetText(0));
2221 0 : if (!aTest.isEmpty())
2222 0 : mDocTitle = aTest;
2223 : }
2224 : }
2225 :
2226 0 : mDocTitle = mDocTitle.replace(0xff, ' ');
2227 : }
2228 :
2229 0 : if (mDocTitle.isEmpty())
2230 : {
2231 0 : mDocTitle = maDocFileName;
2232 0 : sal_Int32 nDot = mDocTitle.indexOf('.');
2233 0 : if (nDot > 0)
2234 0 : mDocTitle = mDocTitle.copy(0, nDot);
2235 : }
2236 0 : mbHeader = true;
2237 : }
2238 :
2239 0 : return mDocTitle;
2240 : }
2241 :
2242 : static const char* JS_NavigateAbs =
2243 : "function NavigateAbs( nPage )\r\n"
2244 : "{\r\n"
2245 : " frames[\"show\"].location.href = \"img\" + nPage + \".$EXT\";\r\n"
2246 : " //frames[\"notes\"].location.href = \"note\" + nPage + \".$EXT\";\r\n"
2247 : " nCurrentPage = nPage;\r\n"
2248 : " if(nCurrentPage==0)\r\n"
2249 : " {\r\n"
2250 : " frames[\"navbar1\"].location.href = \"navbar0.$EXT\";\r\n"
2251 : " }\r\n"
2252 : " else if(nCurrentPage==nPageCount-1)\r\n"
2253 : " {\r\n"
2254 : " frames[\"navbar1\"].location.href = \"navbar2.$EXT\";\r\n"
2255 : " }\r\n"
2256 : " else\r\n"
2257 : " {\r\n"
2258 : " frames[\"navbar1\"].location.href = \"navbar1.$EXT\";\r\n"
2259 : " }\r\n"
2260 : "}\r\n\r\n";
2261 :
2262 : static const char* JS_NavigateRel =
2263 : "function NavigateRel( nDelta )\r\n"
2264 : "{\r\n"
2265 : " var nPage = parseInt(nCurrentPage) + parseInt(nDelta);\r\n"
2266 : " if( (nPage >= 0) && (nPage < nPageCount) )\r\n"
2267 : " {\r\n"
2268 : " NavigateAbs( nPage );\r\n"
2269 : " }\r\n"
2270 : "}\r\n\r\n";
2271 :
2272 : static const char* JS_ExpandOutline =
2273 : "function ExpandOutline()\r\n"
2274 : "{\r\n"
2275 : " frames[\"navbar2\"].location.href = \"navbar4.$EXT\";\r\n"
2276 : " frames[\"outline\"].location.href = \"outline1.$EXT\";\r\n"
2277 : "}\r\n\r\n";
2278 :
2279 : static const char * JS_CollapseOutline =
2280 : "function CollapseOutline()\r\n"
2281 : "{\r\n"
2282 : " frames[\"navbar2\"].location.href = \"navbar3.$EXT\";\r\n"
2283 : " frames[\"outline\"].location.href = \"outline0.$EXT\";\r\n"
2284 : "}\r\n\r\n";
2285 :
2286 : // create page with the frames
2287 :
2288 0 : bool HtmlExport::CreateFrames()
2289 : {
2290 0 : OUString aTmp;
2291 : OUStringBuffer aStr(
2292 : "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"\r\n"
2293 : " \"http://www.w3.org/TR/html4/frameset.dtd\">\r\n"
2294 0 : "<html>\r\n<head>\r\n");
2295 :
2296 0 : aStr.append(CreateMetaCharset());
2297 0 : aStr.append(" <title>");
2298 0 : aStr.append(StringToHTMLString(maPageNames[0]));
2299 0 : aStr.append("</title>\r\n");
2300 :
2301 0 : aStr.append("<script type=\"text/javascript\">\r\n<!--\r\n");
2302 :
2303 0 : aStr.append("var nCurrentPage = 0;\r\nvar nPageCount = ");
2304 0 : aStr.append(OUString::number(mnSdPageCount));
2305 0 : aStr.append(";\r\n\r\n");
2306 :
2307 0 : OUString aFunction = OUString::createFromAscii(JS_NavigateAbs);
2308 :
2309 0 : if(mbNotes)
2310 : {
2311 0 : aFunction = aFunction.replaceAll("//", "");
2312 : }
2313 :
2314 : // substitute HTML file extension
2315 0 : OUString aPlaceHolder(".$EXT");
2316 0 : aFunction = aFunction.replaceAll(aPlaceHolder, maHTMLExtension);
2317 0 : aStr.append(aFunction);
2318 :
2319 0 : aTmp = OUString::createFromAscii(JS_NavigateRel);
2320 0 : aTmp = aTmp.replaceAll(aPlaceHolder, maHTMLExtension);
2321 0 : aStr.append(aTmp);
2322 :
2323 0 : if(mbImpress)
2324 : {
2325 0 : aTmp = OUString::createFromAscii(JS_ExpandOutline);
2326 0 : aTmp = aTmp.replaceAll(aPlaceHolder, maHTMLExtension);
2327 0 : aStr.append(aTmp);
2328 :
2329 0 : aTmp = OUString::createFromAscii(JS_CollapseOutline);
2330 0 : aTmp = aTmp.replaceAll(aPlaceHolder, maHTMLExtension);
2331 0 : aStr.append(aTmp);
2332 : }
2333 0 : aStr.append("// -->\r\n</script>\r\n");
2334 :
2335 0 : aStr.append("</head>\r\n");
2336 :
2337 0 : aStr.append("<frameset cols=\"*,");
2338 0 : aStr.append(OUString::number((mnWidthPixel + 16)));
2339 0 : aStr.append("\">\r\n");
2340 0 : if(mbImpress)
2341 : {
2342 0 : aStr.append(" <frameset rows=\"42,*\">\r\n");
2343 0 : aStr.append(" <frame src=\"navbar3");
2344 0 : aStr.append(maHTMLExtension);
2345 0 : aStr.append("\" name=\"navbar2\" marginwidth=\"4\" marginheight=\"4\" scrolling=\"no\">\r\n");
2346 : }
2347 0 : aStr.append(" <frame src=\"outline0");
2348 0 : aStr.append(maHTMLExtension);
2349 0 : aStr.append("\" name=\"outline\">\r\n");
2350 0 : if(mbImpress)
2351 0 : aStr.append(" </frameset>\r\n");
2352 :
2353 0 : if(mbNotes)
2354 : {
2355 0 : aStr.append(" <frameset rows=\"42,");
2356 0 : aStr.append(OUString::number((int)((double)mnWidthPixel * 0.75) + 16));
2357 0 : aStr.append(",*\">\r\n");
2358 : }
2359 : else
2360 0 : aStr.append(" <frameset rows=\"42,*\">\r\n");
2361 :
2362 0 : aStr.append(" <frame src=\"navbar0");
2363 0 : aStr.append(maHTMLExtension);
2364 0 : aStr.append("\" name=\"navbar1\" marginwidth=\"4\" marginheight=\"4\" scrolling=\"no\">\r\n");
2365 :
2366 0 : aStr.append(" <frame src=\"");
2367 0 : aStr.append(maHTMLFiles[0]);
2368 0 : aStr.append("\" name=\"show\" marginwidth=\"4\" marginheight=\"4\">\r\n");
2369 :
2370 0 : if(mbNotes)
2371 : {
2372 0 : aStr.append(" <frame src=\"note0");
2373 0 : aStr.append(maHTMLExtension);
2374 0 : aStr.append("\" name=\"notes\">\r\n");
2375 : }
2376 0 : aStr.append(" </frameset>\r\n");
2377 :
2378 0 : aStr.append("<noframes>\r\n");
2379 0 : aStr.append(CreateBodyTag());
2380 0 : aStr.append(RESTOHTML(STR_HTMLEXP_NOFRAMES));
2381 0 : aStr.append("\r\n</noframes>\r\n</frameset>\r\n</html>");
2382 :
2383 0 : bool bOk = WriteHtml(maFramePage, false, aStr.makeStringAndClear());
2384 :
2385 0 : if (mpProgress)
2386 0 : mpProgress->SetState(++mnPagesWritten);
2387 :
2388 0 : return bOk;
2389 : }
2390 :
2391 : // create button bar for standard
2392 : // we create the following html files
2393 : // navbar0.htm navigation bar graphic for the first page
2394 : // navbar1.htm navigation bar graphic for the second until second last page
2395 : // navbar2.htm navigation bar graphic for the last page
2396 : // navbar3.htm navigation outline closed
2397 : // navbar4.htm navigation outline open
2398 0 : bool HtmlExport::CreateNavBarFrames()
2399 : {
2400 0 : bool bOk = true;
2401 0 : OUString aButton;
2402 :
2403 0 : if( mbDocColors )
2404 : {
2405 0 : SetDocColors();
2406 0 : maBackColor = maFirstPageColor;
2407 : }
2408 :
2409 0 : for( int nFile = 0; nFile < 3 && bOk; nFile++ )
2410 : {
2411 0 : OUStringBuffer aStr(maHTMLHeader);
2412 0 : aStr.append(CreateMetaCharset());
2413 0 : aStr.append(" <title>");
2414 0 : aStr.append(StringToHTMLString(maPageNames[0]));
2415 0 : aStr.append("</title>\r\n</head>\r\n");
2416 0 : aStr.append(CreateBodyTag());
2417 0 : aStr.append("<center>\r\n");
2418 :
2419 : // first page
2420 0 : aButton = SD_RESSTR(STR_HTMLEXP_FIRSTPAGE);
2421 0 : if(mnButtonThema != -1)
2422 0 : aButton = CreateImage(GetButtonName((nFile == 0 || mnSdPageCount == 1?
2423 0 : BTN_FIRST_0:BTN_FIRST_1)), aButton);
2424 :
2425 0 : if(nFile != 0 && mnSdPageCount > 1)
2426 0 : aButton = CreateLink("JavaScript:parent.NavigateAbs(0)", aButton);
2427 :
2428 0 : aStr.append(aButton);
2429 0 : aStr.append("\r\n");
2430 :
2431 : // to the previous page
2432 0 : aButton = SD_RESSTR(STR_PUBLISH_BACK);
2433 0 : if(mnButtonThema != -1)
2434 0 : aButton = CreateImage(GetButtonName((nFile == 0 || mnSdPageCount == 1?
2435 0 : BTN_PREV_0:BTN_PREV_1)), aButton);
2436 :
2437 0 : if(nFile != 0 && mnSdPageCount > 1)
2438 0 : aButton = CreateLink("JavaScript:parent.NavigateRel(-1)", aButton);
2439 :
2440 0 : aStr.append(aButton);
2441 0 : aStr.append("\r\n");
2442 :
2443 : // to the next page
2444 0 : aButton = SD_RESSTR(STR_PUBLISH_NEXT);
2445 0 : if(mnButtonThema != -1)
2446 0 : aButton = CreateImage(GetButtonName((nFile ==2 || mnSdPageCount == 1?
2447 0 : BTN_NEXT_0:BTN_NEXT_1)), aButton);
2448 :
2449 0 : if(nFile != 2 && mnSdPageCount > 1)
2450 0 : aButton = CreateLink("JavaScript:parent.NavigateRel(1)", aButton);
2451 :
2452 0 : aStr.append(aButton);
2453 0 : aStr.append("\r\n");
2454 :
2455 : // to the last page
2456 0 : aButton = SD_RESSTR(STR_HTMLEXP_LASTPAGE);
2457 0 : if(mnButtonThema != -1)
2458 0 : aButton = CreateImage(GetButtonName((nFile ==2 || mnSdPageCount == 1?
2459 0 : BTN_LAST_0:BTN_LAST_1)), aButton);
2460 :
2461 0 : if(nFile != 2 && mnSdPageCount > 1)
2462 : {
2463 0 : OUString aLink("JavaScript:parent.NavigateAbs(" +
2464 0 : OUString::number(mnSdPageCount-1) + ")");
2465 :
2466 0 : aButton = CreateLink(aLink, aButton);
2467 : }
2468 :
2469 0 : aStr.append(aButton);
2470 0 : aStr.append("\r\n");
2471 :
2472 : // content
2473 0 : if (mbContentsPage)
2474 : {
2475 0 : aButton = SD_RESSTR(STR_PUBLISH_OUTLINE);
2476 0 : if(mnButtonThema != -1)
2477 0 : aButton = CreateImage(GetButtonName(BTN_INDEX), aButton);
2478 :
2479 : // to the overview
2480 0 : aStr.append(CreateLink(maIndex, aButton, "_top"));
2481 0 : aStr.append("\r\n");
2482 : }
2483 :
2484 : // text mode
2485 0 : if(mbImpress)
2486 : {
2487 0 : aButton = SD_RESSTR(STR_HTMLEXP_SETTEXT);
2488 0 : if(mnButtonThema != -1)
2489 0 : aButton = CreateImage(GetButtonName(BTN_TEXT), aButton);
2490 :
2491 0 : OUString aText0("text0" + maHTMLExtension);
2492 0 : aStr.append(CreateLink(aText0, aButton, "_top"));
2493 0 : aStr.append("\r\n");
2494 : }
2495 :
2496 : // and finished...
2497 0 : aStr.append("</center>\r\n");
2498 0 : aStr.append("</body>\r\n</html>");
2499 :
2500 0 : OUString aFileName("navbar" + OUString::number(nFile));
2501 :
2502 0 : bOk = WriteHtml(aFileName, true, aStr.makeStringAndClear());
2503 :
2504 0 : if (mpProgress)
2505 0 : mpProgress->SetState(++mnPagesWritten);
2506 0 : }
2507 :
2508 : // the navigation bar outliner closed...
2509 0 : if(bOk)
2510 : {
2511 0 : OUStringBuffer aStr(maHTMLHeader);
2512 0 : aStr.append(CreateMetaCharset());
2513 0 : aStr.append(" <title>");
2514 0 : aStr.append(StringToHTMLString(maPageNames[0]));
2515 0 : aStr.append("</title>\r\n</head>\r\n");
2516 0 : aStr.append(CreateBodyTag());
2517 :
2518 0 : aButton = SD_RESSTR(STR_HTMLEXP_OUTLINE);
2519 0 : if(mnButtonThema != -1)
2520 0 : aButton = CreateImage(GetButtonName(BTN_MORE), aButton);
2521 :
2522 0 : aStr.append(CreateLink("JavaScript:parent.ExpandOutline()", aButton));
2523 0 : aStr.append("</body>\r\n</html>");
2524 :
2525 0 : bOk = WriteHtml("navbar3", true, aStr.makeStringAndClear());
2526 :
2527 0 : if (mpProgress)
2528 0 : mpProgress->SetState(++mnPagesWritten);
2529 : }
2530 :
2531 : // ... and the outliner open
2532 0 : if( bOk )
2533 : {
2534 0 : OUStringBuffer aStr(maHTMLHeader);
2535 0 : aStr.append(CreateMetaCharset());
2536 0 : aStr.append(" <title>");
2537 0 : aStr.append(StringToHTMLString(maPageNames[0]));
2538 0 : aStr.append("</title>\r\n</head>\r\n");
2539 0 : aStr.append(CreateBodyTag());
2540 :
2541 0 : aButton = SD_RESSTR(STR_HTMLEXP_NOOUTLINE);
2542 0 : if(mnButtonThema != -1)
2543 0 : aButton = CreateImage(GetButtonName(BTN_LESS), aButton);
2544 :
2545 0 : aStr.append(CreateLink("JavaScript:parent.CollapseOutline()", aButton));
2546 0 : aStr.append("</body>\r\n</html>");
2547 :
2548 0 : bOk = WriteHtml("navbar4", true, aStr.makeStringAndClear());
2549 :
2550 0 : if (mpProgress)
2551 0 : mpProgress->SetState(++mnPagesWritten);
2552 :
2553 : }
2554 :
2555 0 : return bOk;
2556 : }
2557 :
2558 : // create button bar for standard
2559 0 : OUString HtmlExport::CreateNavBar( sal_uInt16 nSdPage, bool bIsText ) const
2560 : {
2561 : // prepare button bar
2562 0 : OUString aStrNavFirst(SD_RESSTR(STR_HTMLEXP_FIRSTPAGE));
2563 0 : OUString aStrNavPrev(SD_RESSTR(STR_PUBLISH_BACK));
2564 0 : OUString aStrNavNext(SD_RESSTR(STR_PUBLISH_NEXT));
2565 0 : OUString aStrNavLast(SD_RESSTR(STR_HTMLEXP_LASTPAGE));
2566 0 : OUString aStrNavContent(SD_RESSTR(STR_PUBLISH_OUTLINE));
2567 0 : OUString aStrNavText;
2568 0 : if( bIsText )
2569 : {
2570 0 : aStrNavText = SD_RESSTR(STR_HTMLEXP_SETGRAPHIC);
2571 : }
2572 : else
2573 : {
2574 0 : aStrNavText = SD_RESSTR(STR_HTMLEXP_SETTEXT);
2575 : }
2576 :
2577 0 : if(!bIsText && mnButtonThema != -1)
2578 : {
2579 0 : if(nSdPage<1 || mnSdPageCount == 1)
2580 : {
2581 0 : aStrNavFirst = CreateImage(GetButtonName(BTN_FIRST_0), aStrNavFirst);
2582 0 : aStrNavPrev = CreateImage(GetButtonName(BTN_PREV_0), aStrNavPrev);
2583 : }
2584 : else
2585 : {
2586 0 : aStrNavFirst = CreateImage(GetButtonName(BTN_FIRST_1), aStrNavFirst);
2587 0 : aStrNavPrev = CreateImage(GetButtonName(BTN_PREV_1), aStrNavPrev);
2588 : }
2589 :
2590 0 : if(nSdPage == mnSdPageCount-1 || mnSdPageCount == 1)
2591 : {
2592 0 : aStrNavNext = CreateImage(GetButtonName(BTN_NEXT_0), aStrNavNext);
2593 0 : aStrNavLast = CreateImage(GetButtonName(BTN_LAST_0), aStrNavLast);
2594 : }
2595 : else
2596 : {
2597 0 : aStrNavNext = CreateImage(GetButtonName(BTN_NEXT_1), aStrNavNext);
2598 0 : aStrNavLast = CreateImage(GetButtonName(BTN_LAST_1), aStrNavLast);
2599 : }
2600 :
2601 0 : aStrNavContent = CreateImage(GetButtonName(BTN_INDEX), aStrNavContent);
2602 0 : aStrNavText = CreateImage(GetButtonName(BTN_TEXT), aStrNavText);
2603 : }
2604 :
2605 0 : OUStringBuffer aStr("<center>\r\n"); //<table><tr>\r\n");
2606 :
2607 : // first page
2608 0 : if(nSdPage > 0)
2609 0 : aStr.append(CreateLink( bIsText ? maTextFiles[0] : maHTMLFiles[0],aStrNavFirst));
2610 : else
2611 0 : aStr.append(aStrNavFirst);
2612 0 : aStr.append(' ');
2613 :
2614 : // to Previous page
2615 0 : if(nSdPage > 0)
2616 0 : aStr.append(CreateLink( bIsText ? maTextFiles[nSdPage-1]
2617 0 : : maHTMLFiles[nSdPage-1], aStrNavPrev));
2618 : else
2619 0 : aStr.append(aStrNavPrev);
2620 0 : aStr.append(' ');
2621 :
2622 : // to Next page
2623 0 : if(nSdPage < mnSdPageCount-1)
2624 0 : aStr.append(CreateLink( bIsText ? maTextFiles[nSdPage+1]
2625 0 : : maHTMLFiles[nSdPage+1], aStrNavNext));
2626 : else
2627 0 : aStr.append(aStrNavNext);
2628 0 : aStr.append(' ');
2629 :
2630 : // to Last page
2631 0 : if(nSdPage < mnSdPageCount-1)
2632 0 : aStr.append(CreateLink( bIsText ? maTextFiles[mnSdPageCount-1]
2633 0 : : maHTMLFiles[mnSdPageCount-1],
2634 0 : aStrNavLast));
2635 : else
2636 0 : aStr.append(aStrNavLast);
2637 0 : aStr.append(' ');
2638 :
2639 : // to Index page
2640 0 : if (mbContentsPage)
2641 : {
2642 0 : aStr.append(CreateLink(maIndex, aStrNavContent));
2643 0 : aStr.append(' ');
2644 : }
2645 :
2646 : // Text/Graphics
2647 0 : if(mbImpress)
2648 : {
2649 0 : aStr.append(CreateLink( bIsText ? (mbFrames ? maFramePage : maHTMLFiles[nSdPage])
2650 0 : : maTextFiles[nSdPage], aStrNavText));
2651 :
2652 : }
2653 :
2654 0 : aStr.append("</center><br>\r\n");
2655 :
2656 0 : return aStr.makeStringAndClear();
2657 : }
2658 :
2659 : // export navigation graphics from button set
2660 0 : bool HtmlExport::CreateBitmaps()
2661 : {
2662 0 : if(mnButtonThema != -1 && mpButtonSet.get() )
2663 : {
2664 0 : for( int nButton = 0; nButton != SAL_N_ELEMENTS(pButtonNames); nButton++ )
2665 : {
2666 0 : if(!mbFrames && (nButton == BTN_MORE || nButton == BTN_LESS))
2667 0 : continue;
2668 :
2669 0 : if(!mbImpress && (nButton == BTN_TEXT || nButton == BTN_MORE || nButton == BTN_LESS ))
2670 0 : continue;
2671 :
2672 0 : OUString aFull(maExportPath);
2673 0 : aFull += GetButtonName(nButton);
2674 0 : mpButtonSet->exportButton( mnButtonThema, aFull, GetButtonName(nButton) );
2675 0 : }
2676 : }
2677 0 : return true;
2678 : }
2679 :
2680 : // creates the <body> tag, including the specified color attributes
2681 2 : OUString HtmlExport::CreateBodyTag() const
2682 : {
2683 2 : OUStringBuffer aStr( "<body" );
2684 :
2685 2 : if( mbUserAttr || mbDocColors )
2686 : {
2687 0 : Color aTextColor( maTextColor );
2688 0 : if( (aTextColor == COL_AUTO) && (!maBackColor.IsDark()) )
2689 0 : aTextColor = COL_BLACK;
2690 :
2691 0 : aStr.append(" text=\"");
2692 0 : aStr.append(ColorToHTMLString( aTextColor ));
2693 0 : aStr.append("\" bgcolor=\"");
2694 0 : aStr.append(ColorToHTMLString( maBackColor ));
2695 0 : aStr.append("\" link=\"");
2696 0 : aStr.append(ColorToHTMLString( maLinkColor ));
2697 0 : aStr.append("\" vlink=\"");
2698 0 : aStr.append(ColorToHTMLString( maVLinkColor ));
2699 0 : aStr.append("\" alink=\"");
2700 0 : aStr.append(ColorToHTMLString( maALinkColor ));
2701 0 : aStr.append("\"");
2702 : }
2703 :
2704 2 : aStr.append(">\r\n");
2705 :
2706 2 : return aStr.makeStringAndClear();
2707 : }
2708 :
2709 : // creates a hyperlink
2710 0 : OUString HtmlExport::CreateLink( const OUString& aLink,
2711 : const OUString& aText,
2712 : const OUString& aTarget ) const
2713 : {
2714 0 : OUStringBuffer aStr( "<a href=\"" );
2715 0 : aStr.append(aLink);
2716 0 : if (!aTarget.isEmpty())
2717 : {
2718 0 : aStr.append("\" target=\"");
2719 0 : aStr.append(aTarget);
2720 : }
2721 0 : aStr.append("\">");
2722 0 : aStr.append(aText);
2723 0 : aStr.append("</a>");
2724 :
2725 0 : return aStr.makeStringAndClear();
2726 : }
2727 :
2728 : // creates a image tag
2729 0 : OUString HtmlExport::CreateImage( const OUString& aImage, const OUString& aAltText,
2730 : sal_Int16 nWidth,
2731 : sal_Int16 nHeight ) const
2732 : {
2733 0 : OUStringBuffer aStr( "<img src=\"");
2734 0 : aStr.append(aImage);
2735 0 : aStr.append("\" border=0");
2736 :
2737 0 : if (!aAltText.isEmpty())
2738 : {
2739 0 : aStr.append(" alt=\"");
2740 0 : aStr.append(aAltText);
2741 0 : aStr.append('"');
2742 : }
2743 : else
2744 : {
2745 : // Agerskov: HTML 4.01 has to have an alt attribute even if it is an empty string
2746 0 : aStr.append(" alt=\"\"");
2747 : }
2748 :
2749 0 : if(nWidth > -1)
2750 : {
2751 0 : aStr.append(" width=" + OUString::number(nWidth));
2752 : }
2753 :
2754 0 : if(nHeight > -1)
2755 : {
2756 0 : aStr.append(" height=" + OUString::number(nHeight));
2757 : }
2758 :
2759 0 : aStr.append('>');
2760 :
2761 0 : return aStr.makeStringAndClear();
2762 : }
2763 :
2764 : // create area for a circle; we expect pixel coordinates
2765 0 : OUString HtmlExport::ColorToHTMLString( Color aColor )
2766 : {
2767 : static const char hex[] = "0123456789ABCDEF";
2768 0 : OUStringBuffer aStr( "#xxxxxx" );
2769 0 : aStr[1] = hex[(aColor.GetRed() >> 4) & 0xf];
2770 0 : aStr[2] = hex[aColor.GetRed() & 0xf];
2771 0 : aStr[3] = hex[(aColor.GetGreen() >> 4) & 0xf];
2772 0 : aStr[4] = hex[aColor.GetGreen() & 0xf];
2773 0 : aStr[5] = hex[(aColor.GetBlue() >> 4) & 0xf];
2774 0 : aStr[6] = hex[aColor.GetBlue() & 0xf];
2775 :
2776 0 : return aStr.makeStringAndClear();
2777 : }
2778 :
2779 : // create area for a circle; we expect pixel coordinates
2780 0 : OUString HtmlExport::CreateHTMLCircleArea( sal_uLong nRadius,
2781 : sal_uLong nCenterX,
2782 : sal_uLong nCenterY,
2783 : const OUString& rHRef ) const
2784 : {
2785 : OUString aStr(
2786 0 : "<area shape=\"circle\" alt=\"\" coords=\"" +
2787 0 : OUString::number(nCenterX) + "," +
2788 0 : OUString::number(nCenterY) + "," +
2789 0 : OUString::number(nRadius) +
2790 0 : "\" href=\"" + rHRef + "\">\n");
2791 :
2792 0 : return aStr;
2793 : }
2794 :
2795 : // create area for a polygon; we expect pixel coordinates
2796 0 : OUString HtmlExport::CreateHTMLPolygonArea( const ::basegfx::B2DPolyPolygon& rPolyPolygon,
2797 : Size aShift, double fFactor, const OUString& rHRef ) const
2798 : {
2799 0 : OUStringBuffer aStr;
2800 0 : const sal_uInt32 nNoOfPolygons(rPolyPolygon.count());
2801 :
2802 0 : for ( sal_uInt32 nXPoly = 0L; nXPoly < nNoOfPolygons; nXPoly++ )
2803 : {
2804 0 : const ::basegfx::B2DPolygon& aPolygon = rPolyPolygon.getB2DPolygon(nXPoly);
2805 0 : const sal_uInt32 nNoOfPoints(aPolygon.count());
2806 :
2807 0 : aStr.append("<area shape=\"polygon\" alt=\"\" coords=\"");
2808 :
2809 0 : for ( sal_uInt32 nPoint = 0L; nPoint < nNoOfPoints; nPoint++ )
2810 : {
2811 0 : const ::basegfx::B2DPoint aB2DPoint(aPolygon.getB2DPoint(nPoint));
2812 0 : Point aPnt(FRound(aB2DPoint.getX()), FRound(aB2DPoint.getY()));
2813 : // coordinates are relative to the physical page origin, not the
2814 : // origin of ordinates
2815 0 : aPnt.Move(aShift.Width(), aShift.Height());
2816 :
2817 0 : aPnt.X() = (long)(aPnt.X() * fFactor);
2818 0 : aPnt.Y() = (long)(aPnt.Y() * fFactor);
2819 0 : aStr.append(OUString::number(aPnt.X()) + "," + OUString::number(aPnt.Y()));
2820 :
2821 0 : if (nPoint < nNoOfPoints - 1)
2822 0 : aStr.append(',');
2823 0 : }
2824 0 : aStr.append("\" href=\"" + rHRef + "\">\n");
2825 0 : }
2826 :
2827 0 : return aStr.makeStringAndClear();
2828 : }
2829 :
2830 : // create area for a rectangle; we expect pixel coordinates
2831 0 : OUString HtmlExport::CreateHTMLRectArea( const Rectangle& rRect,
2832 : const OUString& rHRef ) const
2833 : {
2834 : OUString aStr(
2835 0 : "<area shape=\"rect\" alt=\"\" coords=\"" +
2836 0 : OUString::number(rRect.Left()) + "," +
2837 0 : OUString::number(rRect.Top()) + "," +
2838 0 : OUString::number(rRect.Right()) + "," +
2839 0 : OUString::number(rRect.Bottom()) +
2840 0 : "\" href=\"" + rHRef + "\">\n");
2841 :
2842 0 : return aStr;
2843 : }
2844 :
2845 : // escapes a string for html
2846 52 : OUString HtmlExport::StringToHTMLString( const OUString& rString )
2847 : {
2848 52 : SvMemoryStream aMemStm;
2849 52 : HTMLOutFuncs::Out_String( aMemStm, rString, RTL_TEXTENCODING_UTF8 );
2850 52 : aMemStm.WriteChar( (char) 0 );
2851 52 : sal_Int32 nLength = strlen((char*)aMemStm.GetData());
2852 52 : return OUString( (char*)aMemStm.GetData(), nLength, RTL_TEXTENCODING_UTF8 );
2853 : }
2854 :
2855 : // creates a url for a specific page
2856 0 : OUString HtmlExport::CreatePageURL( sal_uInt16 nPgNum )
2857 : {
2858 0 : if(mbFrames)
2859 : {
2860 0 : return OUString("JavaScript:parent.NavigateAbs(" +
2861 0 : OUString::number(nPgNum) + ")");
2862 : }
2863 : else
2864 0 : return maHTMLFiles[nPgNum];
2865 : }
2866 :
2867 0 : bool HtmlExport::CopyScript( const OUString& rPath, const OUString& rSource, const OUString& rDest, bool bUnix /* = false */ )
2868 : {
2869 0 : INetURLObject aURL( SvtPathOptions().GetConfigPath() );
2870 0 : OUStringBuffer aScriptBuf;
2871 :
2872 0 : aURL.Append( OUString("webcast") );
2873 0 : aURL.Append( rSource );
2874 :
2875 0 : meEC.SetContext( STR_HTMLEXP_ERROR_OPEN_FILE, rSource );
2876 :
2877 0 : sal_uLong nErr = 0;
2878 0 : SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
2879 :
2880 0 : if( pIStm )
2881 : {
2882 0 : OString aLine;
2883 :
2884 0 : while( pIStm->ReadLine( aLine ) )
2885 : {
2886 0 : aScriptBuf.appendAscii( aLine.getStr() );
2887 0 : if( bUnix )
2888 : {
2889 0 : aScriptBuf.append("\n");
2890 : }
2891 : else
2892 : {
2893 0 : aScriptBuf.append("\r\n");
2894 : }
2895 : }
2896 :
2897 0 : nErr = pIStm->GetError();
2898 0 : delete pIStm;
2899 : }
2900 :
2901 0 : if( nErr != 0 )
2902 : {
2903 0 : ErrorHandler::HandleError( nErr );
2904 0 : return (bool) nErr;
2905 : }
2906 :
2907 0 : OUString aScript(aScriptBuf.makeStringAndClear());
2908 0 : aScript = aScript.replaceAll("$$1", getDocumentTitle());
2909 0 : aScript = aScript.replaceAll("$$2", RESTOHTML(STR_WEBVIEW_SAVE));
2910 0 : aScript = aScript.replaceAll("$$3", maCGIPath);
2911 0 : aScript = aScript.replaceAll("$$4", OUString::number(mnWidthPixel));
2912 0 : aScript = aScript.replaceAll("$$5", OUString::number(mnHeightPixel));
2913 :
2914 0 : OUString aDest(rPath + rDest);
2915 :
2916 0 : meEC.SetContext( STR_HTMLEXP_ERROR_CREATE_FILE, rDest );
2917 : // write script file
2918 : {
2919 0 : EasyFile aFile;
2920 : SvStream* pStr;
2921 0 : nErr = aFile.createStream(aDest, pStr);
2922 0 : if(nErr == 0)
2923 : {
2924 : OString aStr(OUStringToOString(aScript,
2925 0 : RTL_TEXTENCODING_UTF8));
2926 0 : pStr->WriteCharPtr( aStr.getStr() );
2927 :
2928 0 : nErr = aFile.close();
2929 0 : }
2930 : }
2931 :
2932 0 : if (mpProgress)
2933 0 : mpProgress->SetState(++mnPagesWritten);
2934 :
2935 0 : if( nErr != 0 )
2936 0 : ErrorHandler::HandleError( nErr );
2937 :
2938 0 : return nErr == 0;
2939 : }
2940 :
2941 : static const char * ASP_Scripts[] = { "common.inc", "webcast.asp", "show.asp", "savepic.asp", "poll.asp", "editpic.asp" };
2942 :
2943 : /** creates and saves the ASP scripts for WebShow */
2944 0 : bool HtmlExport::CreateASPScripts()
2945 : {
2946 0 : for( sal_uInt16 n = 0; n < (sizeof( ASP_Scripts ) / sizeof(char *)); n++ )
2947 : {
2948 0 : OUString aScript = OUString::createFromAscii(ASP_Scripts[n]);
2949 :
2950 0 : if(!CopyScript(maExportPath, aScript, aScript))
2951 0 : return false;
2952 0 : }
2953 :
2954 0 : if (!CopyScript(maExportPath, "edit.asp", maIndex))
2955 0 : return false;
2956 :
2957 0 : return true;
2958 : }
2959 :
2960 : static const char *PERL_Scripts[] = { "webcast.pl", "common.pl", "editpic.pl", "poll.pl", "savepic.pl", "show.pl" };
2961 :
2962 : // creates and saves the PERL scripts for WebShow
2963 0 : bool HtmlExport::CreatePERLScripts()
2964 : {
2965 0 : for( sal_uInt16 n = 0; n < (sizeof( PERL_Scripts ) / sizeof(char *)); n++ )
2966 : {
2967 0 : OUString aScript = OUString::createFromAscii(PERL_Scripts[n]);
2968 :
2969 0 : if(!CopyScript(maExportPath, aScript, aScript, true))
2970 0 : return false;
2971 0 : }
2972 :
2973 0 : if (!CopyScript(maExportPath, "edit.pl", maIndex, true))
2974 0 : return false;
2975 :
2976 0 : if (!CopyScript(maExportPath, "index.pl", maIndexUrl, true))
2977 0 : return false;
2978 :
2979 0 : return true;
2980 : }
2981 :
2982 : // creates a list with names of the saved images
2983 0 : bool HtmlExport::CreateImageFileList()
2984 : {
2985 0 : OUStringBuffer aStr;
2986 0 : for( sal_uInt16 nSdPage = 0; nSdPage < mnSdPageCount; nSdPage++)
2987 : {
2988 0 : aStr.append(OUString::number(nSdPage + 1));
2989 0 : aStr.append(';');
2990 0 : aStr.append(maURLPath);
2991 0 : aStr.append(maImageFiles[nSdPage]);
2992 0 : aStr.append("\r\n");
2993 : }
2994 :
2995 0 : bool bOk = WriteHtml("picture.txt", false, aStr.makeStringAndClear());
2996 :
2997 0 : if (mpProgress)
2998 0 : mpProgress->SetState(++mnPagesWritten);
2999 :
3000 0 : return bOk;
3001 : }
3002 :
3003 : // creates a file with the actual page number
3004 0 : bool HtmlExport::CreateImageNumberFile()
3005 : {
3006 0 : OUString aFileName("currpic.txt");
3007 0 : OUString aFull(maExportPath + aFileName);
3008 :
3009 0 : meEC.SetContext( STR_HTMLEXP_ERROR_CREATE_FILE, aFileName );
3010 0 : EasyFile aFile;
3011 : SvStream* pStr;
3012 0 : sal_uLong nErr = aFile.createStream(aFull, pStr);
3013 0 : if(nErr == 0)
3014 : {
3015 0 : pStr->WriteCharPtr( (const char *)"1" );
3016 0 : nErr = aFile.close();
3017 : }
3018 :
3019 0 : if (mpProgress)
3020 0 : mpProgress->SetState(++mnPagesWritten);
3021 :
3022 0 : if( nErr != 0 )
3023 0 : ErrorHandler::HandleError( nErr );
3024 :
3025 0 : return nErr == 0;
3026 : }
3027 :
3028 0 : OUString HtmlExport::InsertSound( const OUString& rSoundFile )
3029 : {
3030 0 : if (rSoundFile.isEmpty())
3031 0 : return rSoundFile;
3032 :
3033 0 : INetURLObject aURL( rSoundFile );
3034 0 : OUString aSoundFileName = aURL.getName();
3035 :
3036 : DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
3037 :
3038 0 : OUString aStr("<embed src=\"" + aSoundFileName +
3039 0 : "\" hidden=\"true\" autostart=\"true\">");
3040 :
3041 0 : CopyFile(rSoundFile, maExportPath + aSoundFileName);
3042 :
3043 0 : return aStr;
3044 : }
3045 :
3046 0 : bool HtmlExport::CopyFile( const OUString& rSourceFile, const OUString& rDestFile )
3047 : {
3048 0 : meEC.SetContext( STR_HTMLEXP_ERROR_COPY_FILE, rSourceFile, rDestFile );
3049 0 : osl::FileBase::RC Error = osl::File::copy( rSourceFile, rDestFile );
3050 :
3051 0 : if( Error != osl::FileBase::E_None )
3052 : {
3053 0 : ErrorHandler::HandleError(Error);
3054 0 : return false;
3055 : }
3056 : else
3057 : {
3058 0 : return true;
3059 : }
3060 : }
3061 :
3062 0 : bool HtmlExport::checkFileExists( Reference< ::com::sun::star::ucb::XSimpleFileAccess3 >& xFileAccess, OUString const & aFileName )
3063 : {
3064 : try
3065 : {
3066 0 : OUString url( maExportPath );
3067 0 : url += aFileName;
3068 0 : return xFileAccess->exists( url );
3069 : }
3070 0 : catch( com::sun::star::uno::Exception& )
3071 : {
3072 : OSL_FAIL(OString(OString("sd::HtmlExport::checkFileExists(), exception caught: ") +
3073 : OUStringToOString( comphelper::anyToString( cppu::getCaughtException() ), RTL_TEXTENCODING_UTF8 )).getStr() );
3074 : }
3075 :
3076 0 : return false;
3077 : }
3078 :
3079 0 : bool HtmlExport::checkForExistingFiles()
3080 : {
3081 0 : bool bFound = false;
3082 :
3083 : try
3084 : {
3085 0 : Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
3086 0 : uno::Reference<ucb::XSimpleFileAccess3> xFA(ucb::SimpleFileAccess::create(xContext));
3087 :
3088 : sal_uInt16 nSdPage;
3089 0 : for( nSdPage = 0; !bFound && (nSdPage < mnSdPageCount); nSdPage++)
3090 : {
3091 0 : if( checkFileExists( xFA, maImageFiles[nSdPage] ) ||
3092 0 : checkFileExists( xFA, maHTMLFiles[nSdPage] ) ||
3093 0 : checkFileExists( xFA, maThumbnailFiles[nSdPage] ) ||
3094 0 : checkFileExists( xFA, maPageNames[nSdPage] ) ||
3095 0 : checkFileExists( xFA, maTextFiles[nSdPage] ) )
3096 : {
3097 0 : bFound = true;
3098 : }
3099 : }
3100 :
3101 0 : if( !bFound && mbDownload )
3102 0 : bFound = checkFileExists( xFA, maDocFileName );
3103 :
3104 0 : if( !bFound && mbFrames )
3105 0 : bFound = checkFileExists( xFA, maFramePage );
3106 :
3107 0 : if( bFound )
3108 : {
3109 0 : ResMgr *pResMgr = ResMgr::CreateResMgr( "dbw" );
3110 0 : if( pResMgr )
3111 : {
3112 0 : ResId aResId( 4077, *pResMgr );
3113 0 : OUString aMsg( aResId.toString() );
3114 :
3115 0 : OUString aSystemPath;
3116 0 : osl::FileBase::getSystemPathFromFileURL( maExportPath, aSystemPath );
3117 0 : aMsg = aMsg.replaceFirst( "%FILENAME", aSystemPath );
3118 0 : WarningBox aWarning( 0, WB_YES_NO | WB_DEF_YES, aMsg );
3119 0 : aWarning.SetImage( WarningBox::GetStandardImage() );
3120 0 : bFound = ( RET_NO == aWarning.Execute() );
3121 :
3122 0 : delete pResMgr;
3123 : }
3124 : else
3125 : {
3126 0 : bFound = false;
3127 : }
3128 0 : }
3129 : }
3130 0 : catch( Exception& )
3131 : {
3132 : OSL_FAIL(OString(OString("sd::HtmlExport::checkForExistingFiles(), exception caught: ") +
3133 : OUStringToOString( comphelper::anyToString( cppu::getCaughtException() ), RTL_TEXTENCODING_UTF8 )).getStr() );
3134 0 : bFound = false;
3135 : }
3136 :
3137 0 : return bFound;
3138 : }
3139 :
3140 0 : OUString HtmlExport::GetButtonName( int nButton ) const
3141 : {
3142 0 : return OUString::createFromAscii(pButtonNames[nButton]);
3143 : }
3144 :
3145 2 : EasyFile::EasyFile()
3146 : {
3147 2 : pMedium = NULL;
3148 2 : pOStm = NULL;
3149 2 : bOpen = false;
3150 2 : }
3151 :
3152 2 : EasyFile::~EasyFile()
3153 : {
3154 2 : if( bOpen )
3155 0 : (void)close();
3156 2 : }
3157 :
3158 2 : sal_uLong EasyFile::createStream( const OUString& rUrl, SvStream* &rpStr )
3159 : {
3160 2 : sal_uLong nErr = 0;
3161 :
3162 2 : if(bOpen)
3163 0 : nErr = close();
3164 :
3165 2 : OUString aFileName;
3166 :
3167 2 : if( nErr == 0 )
3168 2 : nErr = createFileName( rUrl, aFileName );
3169 :
3170 2 : if( nErr == 0 )
3171 : {
3172 2 : pOStm = ::utl::UcbStreamHelper::CreateStream( aFileName, STREAM_WRITE | STREAM_TRUNC );
3173 2 : if( pOStm )
3174 : {
3175 2 : bOpen = true;
3176 2 : nErr = pOStm->GetError();
3177 : }
3178 : else
3179 : {
3180 0 : nErr = ERRCODE_SFX_CANTCREATECONTENT;
3181 : }
3182 : }
3183 :
3184 2 : if( nErr != 0 )
3185 : {
3186 0 : bOpen = false;
3187 0 : delete pMedium;
3188 0 : delete pOStm;
3189 0 : pOStm = NULL;
3190 : }
3191 :
3192 2 : rpStr = pOStm;
3193 :
3194 2 : return nErr;
3195 : }
3196 :
3197 2 : sal_uLong EasyFile::createFileName( const OUString& rURL, OUString& rFileName )
3198 : {
3199 2 : sal_uLong nErr = 0;
3200 :
3201 2 : if( bOpen )
3202 0 : nErr = close();
3203 :
3204 2 : if( nErr == 0 )
3205 : {
3206 2 : INetURLObject aURL( rURL );
3207 :
3208 2 : if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
3209 : {
3210 0 : OUString aURLStr;
3211 0 : ::utl::LocalFileHelper::ConvertPhysicalNameToURL( rURL, aURLStr );
3212 0 : aURL = INetURLObject( aURLStr );
3213 : }
3214 : DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
3215 2 : rFileName = aURL.GetMainURL( INetURLObject::NO_DECODE );
3216 : }
3217 :
3218 2 : return nErr;
3219 : }
3220 :
3221 2 : sal_uLong EasyFile::close()
3222 : {
3223 2 : sal_uLong nErr = 0;
3224 :
3225 2 : delete pOStm;
3226 2 : pOStm = NULL;
3227 :
3228 2 : bOpen = false;
3229 :
3230 2 : if( pMedium )
3231 : {
3232 : // transmitted
3233 0 : pMedium->Close();
3234 0 : pMedium->Commit();
3235 :
3236 0 : nErr = pMedium->GetError();
3237 :
3238 0 : delete pMedium;
3239 0 : pMedium = NULL;
3240 : }
3241 :
3242 2 : return nErr;
3243 : }
3244 :
3245 : // This class helps reporting errors during file i/o
3246 2 : HtmlErrorContext::HtmlErrorContext(vcl::Window *_pWin)
3247 2 : : ErrorContext(_pWin)
3248 : {
3249 2 : mnResId = 0;
3250 2 : }
3251 :
3252 0 : bool HtmlErrorContext::GetString( sal_uLong, OUString& rCtxStr )
3253 : {
3254 : DBG_ASSERT( mnResId != 0, "No error context set" );
3255 0 : if( mnResId == 0 )
3256 0 : return false;
3257 :
3258 0 : rCtxStr = SdResId( mnResId ).toString();
3259 :
3260 0 : rCtxStr = rCtxStr.replaceAll( OUString("$(URL1)"), maURL1 );
3261 0 : rCtxStr = rCtxStr.replaceAll( OUString("$(URL2)"), maURL2 );
3262 :
3263 0 : return true;
3264 : }
3265 :
3266 2 : void HtmlErrorContext::SetContext( sal_uInt16 nResId, const OUString& rURL )
3267 : {
3268 2 : mnResId = nResId;
3269 2 : maURL1 = rURL;
3270 2 : maURL2 = "";
3271 2 : }
3272 :
3273 0 : void HtmlErrorContext::SetContext( sal_uInt16 nResId, const OUString& rURL1, const OUString& rURL2 )
3274 : {
3275 0 : mnResId = nResId;
3276 0 : maURL1 = rURL1;
3277 0 : maURL2 = rURL2;
3278 114 : }
3279 :
3280 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|