merge the formfield patch from ooo-build
[ooovba.git] / sd / source / filter / html / htmlex.cxx
blob9c9e4d609dc46dc2f89852377a22168a5885bca6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: htmlex.cxx,v $
10 * $Revision: 1.34.80.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "htmlex.hxx"
35 #include <com/sun/star/document/XExporter.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/document/XFilter.hpp>
39 #include <rtl/uri.hxx>
40 #include <comphelper/processfactory.hxx>
41 #include <osl/file.hxx>
42 #include <tools/fsys.hxx>
43 #include <svtools/pathoptions.hxx>
44 #include <svtools/FilterConfigItem.hxx>
45 #ifndef _UNOTOOLS_UCBSTREAMHELPER_HXX
46 #include <unotools/ucbstreamhelper.hxx>
47 #endif
48 #include <unotools/localfilehelper.hxx>
49 #include <com/sun/star/frame/XStorable.hpp>
50 #include <sfx2/progress.hxx>
51 #include <sfx2/progress.hxx>
52 #include <vcl/wrkwin.hxx>
53 #include <svtools/aeitem.hxx>
54 #include <svx/svditer.hxx>
55 #include <svtools/imaprect.hxx>
56 #include <svtools/imapcirc.hxx>
57 #include <svtools/imappoly.hxx>
58 #include <vcl/msgbox.hxx>
59 #include <sfx2/app.hxx>
60 #include <svx/outlobj.hxx>
61 #include <svx/editobj.hxx>
62 #include <svx/svdopath.hxx>
63 #include <svx/xoutbmp.hxx>
64 #include <svtools/htmlout.hxx>
65 #include <sfx2/docfile.hxx>
66 #include <vcl/cvtgrf.hxx>
67 #include <svtools/colorcfg.hxx>
68 #include <svtools/filter.hxx>
69 #include <svx/colritem.hxx>
70 #include <svx/editeng.hxx>
71 #include <svx/wghtitem.hxx>
72 #include <svx/udlnitem.hxx>
73 #include <svx/postitem.hxx>
74 #include <svx/crsditem.hxx>
75 #include <svx/flditem.hxx>
76 #include <sfx2/dispatch.hxx>
77 #include <sfx2/fcontnr.hxx>
78 #include <svtools/style.hxx>
79 #define _SVSTDARR_USHORTS
80 #include <svtools/svstdarr.hxx>
81 //#ifndef _SVDETC_HXX
82 //#include <svx/svdetc.hxx>
83 //#endif
84 #include <svx/frmdiritem.hxx>
85 #include <svx/svdoutl.hxx>
86 #include <svx/impgrf.hxx> // FillFilter()
87 #include <tools/urlobj.hxx> // INetURLObject
88 #include <vcl/bmpacc.hxx>
89 #include <svtools/sfxecode.hxx>
90 #include <svx/impgrf.hxx>
91 #include <com/sun/star/beans/PropertyState.hpp>
92 #include <tools/resmgr.hxx>
93 #include "comphelper/anytostring.hxx"
94 #include "cppuhelper/exc_hlp.hxx"
96 #include "drawdoc.hxx"
97 #include "Outliner.hxx"
98 #include "sdpage.hxx"
99 #include "sdattr.hxx"
100 #include "glob.hrc"
101 #include "anminfo.hxx"
102 #include "imapinfo.hxx"
103 #include "sdresid.hxx"
104 #include "buttonset.hxx"
105 #include <basegfx/polygon/b2dpolygon.hxx>
107 using ::rtl::OUString;
108 using ::rtl::OString;
109 using namespace ::com::sun::star;
110 using namespace ::com::sun::star::uno;
111 using namespace ::com::sun::star::beans;
112 using namespace ::com::sun::star::frame;
113 using namespace ::com::sun::star::lang;
114 using namespace ::com::sun::star::document;
116 #define KEY_QUALITY "JPG-EXPORT-QUALITY"
118 // Parameter aus Itemset abfragen
120 #define RESTOHTML( res ) StringToHTMLString(String(SdResId(res)))
121 #define S2H( str ) StringToHTMLString( str )
123 // bei Aenderungen auch NUM_BUTTONS in pubdlg.hxx aendern!!
124 const char *pButtonNames[NUM_BUTTONS] =
126 "first-inactive.png",
127 "first.png",
128 "left-inactive.png",
129 "left.png",
130 "right-inactive.png",
131 "right.png",
132 "last-inactive.png",
133 "last.png",
134 "home.png",
135 "text.png",
136 "expand.png",
137 "collapse.png",
140 #define BTN_FIRST_0 0
141 #define BTN_FIRST_1 1
142 #define BTN_PREV_0 2
143 #define BTN_PREV_1 3
144 #define BTN_NEXT_0 4
145 #define BTN_NEXT_1 5
146 #define BTN_LAST_0 6
147 #define BTN_LAST_1 7
148 #define BTN_INDEX 8
149 #define BTN_TEXT 9
150 #define BTN_MORE 10
151 #define BTN_LESS 11
153 // Fuer Detectfilter
154 #define CALC_OPTIONS "9,34,SYSTEM"
156 // *********************************************************************
157 // Hilfsklasse fuer das simple erzeugen von Dateien lokal/remote
158 // *********************************************************************
159 class EasyFile
161 private:
162 SvStream* pOStm;
163 SfxMedium* pMedium;
164 bool bOpen;
166 public:
168 EasyFile();
169 ~EasyFile();
171 ULONG createStream( const String& rUrl, SvStream*& rpStr );
172 ULONG createFileName( const String& rUrl, String& rFileName );
173 ULONG close();
176 // *********************************************************************
177 // Hilfsklasse fuer das einbinden von Textattributen in die Html-Ausgabe
178 // *********************************************************************
179 class HtmlState
181 private:
182 bool mbColor;
183 bool mbWeight;
184 bool mbItalic;
185 bool mbUnderline;
186 bool mbStrike;
187 bool mbLink;
188 Color maColor;
189 Color maDefColor;
190 String maLink;
191 String maTarget;
193 public:
194 HtmlState( Color aDefColor );
196 String SetWeight( bool bWeight );
197 String SetItalic( bool bItalic );
198 String SetUnderline( bool bUnderline );
199 String SetColor( Color aColor );
200 String SetStrikeout( bool bStrike );
201 String SetLink( const String& aLink, const String& aTarget );
202 String Flush();
205 // =====================================================================
206 // alle noch offennen Tags schliessen
207 // =====================================================================
208 String HtmlState::Flush()
210 String aStr, aEmpty;
212 aStr += SetWeight(false);
213 aStr += SetItalic(false);
214 aStr += SetUnderline(false);
215 aStr += SetStrikeout(false);
216 aStr += SetColor(maDefColor);
217 aStr += SetLink(aEmpty,aEmpty);
219 return aStr;
222 // =====================================================================
223 // c'tor mit Defaultfarbe fuer die Seite
224 // =====================================================================
225 HtmlState::HtmlState( Color aDefColor )
227 mbColor = false;
228 mbWeight = false;
229 mbItalic = false;
230 mbUnderline = false;
231 mbLink = false;
232 mbStrike = false;
233 maDefColor = aDefColor;
236 // =====================================================================
237 // aktiviert/deaktiviert Fettdruck
238 // =====================================================================
239 String HtmlState::SetWeight( bool bWeight )
241 String aStr;
243 if(bWeight && !mbWeight)
244 aStr.AppendAscii( "<b>" );
245 else if(!bWeight && mbWeight)
246 aStr.AppendAscii( "</b>" );
248 mbWeight = bWeight;
249 return aStr;
252 // =====================================================================
253 // aktiviert/deaktiviert Italic
254 // =====================================================================
255 String HtmlState::SetItalic( bool bItalic )
257 String aStr;
259 if(bItalic && !mbItalic)
260 aStr.AppendAscii( "<i>" );
261 else if(!bItalic && mbItalic)
262 aStr.AppendAscii( "</i>" );
264 mbItalic = bItalic;
265 return aStr;
268 // =====================================================================
269 // aktiviert/deaktiviert Unterstrichen
270 // =====================================================================
271 String HtmlState::SetUnderline( bool bUnderline )
273 String aStr;
275 if(bUnderline && !mbUnderline)
276 aStr.AppendAscii( "<u>" );
277 else if(!bUnderline && mbUnderline)
278 aStr.AppendAscii( "</u>" );
280 mbUnderline = bUnderline;
281 return aStr;
284 // =====================================================================
285 // aktiviert/deaktiviert Durchstreichen
286 // =====================================================================
287 String HtmlState::SetStrikeout( bool bStrike )
289 String aStr;
291 if(bStrike && !mbStrike)
292 aStr.AppendAscii( "<strike>" );
293 else if(!bStrike && mbStrike)
294 aStr.AppendAscii( "</strike>" );
296 mbStrike = bStrike;
297 return aStr;
300 // =====================================================================
301 // Setzt die angegebenne Textfarbe
302 // =====================================================================
303 String HtmlState::SetColor( Color aColor )
305 String aStr;
307 if(mbColor && aColor == maColor)
308 return aStr;
310 if(mbColor)
312 aStr.AppendAscii( "</font>" );
313 mbColor = false;
316 if(aColor != maDefColor)
318 maColor = aColor;
320 aStr.AppendAscii( "<font color=\"" );
321 aStr += HtmlExport::ColorToHTMLString(aColor);
322 aStr.AppendAscii( "\">" );
324 mbColor = true;
327 return aStr;
330 // =====================================================================
331 // aktiviert/deaktiviert einen Hyperlink
332 // =====================================================================
333 String HtmlState::SetLink( const String& aLink, const String& aTarget )
335 String aStr;
337 if(mbLink&&maLink == aLink&&maTarget==aTarget)
338 return aStr;
340 if(mbLink)
342 aStr.AppendAscii( "</a>" );
343 mbLink = false;
346 if(aLink.Len())
348 aStr.AppendAscii( "<a href=\"" );
349 aStr += HtmlExport::StringToURL(aLink);
350 if(aTarget.Len())
352 aStr.AppendAscii( "\" target=\"" );
353 aStr += aTarget;
355 aStr.AppendAscii( "\">" );
356 mbLink = true;
357 maLink = aLink;
358 maTarget = aTarget;
361 return aStr;
364 // *********************************************************************
365 // class HtmlExport Methoden
366 // *********************************************************************
368 static String getParagraphStyle( SdrOutliner* pOutliner, USHORT nPara )
370 SfxItemSet aParaSet( pOutliner->GetParaAttribs( nPara ) );
372 String sStyle( RTL_CONSTASCII_USTRINGPARAM("direction:") );
373 if( static_cast<const SvxFrameDirectionItem*>(aParaSet.GetItem( EE_PARA_WRITINGDIR ))->GetValue() == FRMDIR_HORI_RIGHT_TOP )
375 sStyle += String( RTL_CONSTASCII_USTRINGPARAM("rtl;") );
377 else
379 sStyle += String( RTL_CONSTASCII_USTRINGPARAM("ltr;") );
381 return sStyle;
384 // =====================================================================
385 // Konstruktor fuer die Html Export Hilfsklasse
386 // =====================================================================
387 HtmlExport::HtmlExport(
388 OUString aPath,
389 const Sequence< PropertyValue >& rParams,
390 SdDrawDocument* pExpDoc,
391 ::sd::DrawDocShell* pDocShell )
392 : maPath( aPath ),
393 mpDoc(pExpDoc),
394 mpDocSh( pDocShell ),
395 meEC(NULL),
396 meMode( PUBLISH_HTML ),
397 mbContentsPage(false),
398 mnButtonThema(-1),
399 mnWidthPixel( PUB_LOWRES_WIDTH ),
400 meFormat( FORMAT_JPG ),
401 mbNotes(false),
402 mnCompression( -1 ),
403 mbDownload( false ),
404 mbSlideSound(true),
405 mbHiddenSlides(true),
406 mbUserAttr(false),
407 mbDocColors(false),
408 maHTMLExtension(SdResId(STR_HTMLEXP_DEFAULT_EXTENSION)),
409 mpHTMLFiles(NULL),
410 mpImageFiles(NULL),
411 mpPageNames(NULL),
412 mpTextFiles(NULL),
413 maIndexUrl(RTL_CONSTASCII_USTRINGPARAM("index")),
414 meScript( SCRIPT_ASP ),
415 maHTMLHeader( RTL_CONSTASCII_USTRINGPARAM(
416 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\r\n"
417 " \"http://www.w3.org/TR/html4/transitional.dtd\">\r\n"
418 "<html>\r\n<head>\r\n" ) ),
419 mpButtonSet( new ButtonSet() )
421 bool bChange = mpDoc->IsChanged();
423 maIndexUrl += maHTMLExtension;
425 InitExportParameters( rParams );
427 switch( meMode )
429 case PUBLISH_HTML:
430 case PUBLISH_FRAMES:
431 ExportHtml();
432 break;
433 case PUBLISH_WEBCAST:
434 ExportWebCast();
435 break;
436 case PUBLISH_KIOSK:
437 ExportKiosk();
438 break;
441 mpDoc->SetChanged(bChange);
444 HtmlExport::~HtmlExport()
446 // ------------------------------------------------------------------
447 // Listen loeschen
448 // ------------------------------------------------------------------
449 if(mpImageFiles && mpHTMLFiles && mpPageNames && mpTextFiles)
451 for ( USHORT nSdPage = 0; nSdPage < mnSdPageCount; nSdPage++)
453 delete mpImageFiles[nSdPage];
454 delete mpHTMLFiles[nSdPage];
455 delete mpPageNames[nSdPage];
456 delete mpTextFiles[nSdPage];
460 delete[] mpImageFiles;
461 delete[] mpHTMLFiles;
462 delete[] mpPageNames;
463 delete[] mpTextFiles;
466 /** get common export parameters from item set */
467 void HtmlExport::InitExportParameters( const Sequence< PropertyValue >& rParams )
469 mbImpress = mpDoc && mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS;
471 sal_Int32 nArgs = rParams.getLength();
472 const PropertyValue* pParams = rParams.getConstArray();
473 OUString aStr;
474 while( nArgs-- )
476 if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "PublishMode" ) ) )
478 sal_Int32 temp = 0;
479 pParams->Value >>= temp;
480 meMode = (HtmlPublishMode)temp;
482 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IndexURL" ) ) )
484 pParams->Value >>= aStr;
485 maIndexUrl = aStr;
487 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Format" ) ) )
489 sal_Int32 temp = 0;
490 pParams->Value >>= temp;
491 meFormat = (PublishingFormat)temp;
493 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Compression" ) ) )
495 pParams->Value >>= aStr;
496 String aTmp( aStr );
497 if(aTmp.Len())
499 xub_StrLen nPos = aTmp.Search( '%' );
500 if(nPos != STRING_NOTFOUND)
501 aTmp.Erase(nPos,1);
502 mnCompression = (INT16)aTmp.ToInt32();
505 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Width" ) ) )
507 sal_Int32 temp = 0;
508 pParams->Value >>= temp;
509 mnWidthPixel = (sal_uInt16)temp;
511 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "UseButtonSet" ) ) )
513 sal_Int32 temp = 0;
514 pParams->Value >>= temp;
515 mnButtonThema = (sal_Int16)temp;
517 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsExportNotes" ) ) )
519 if( mbImpress )
521 sal_Bool temp = sal_False;
522 pParams->Value >>= temp;
523 mbNotes = temp;
526 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsExportContentsPage" ) ) )
528 sal_Bool temp = sal_False;
529 pParams->Value >>= temp;
530 mbContentsPage = temp;
532 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Author" ) ) )
534 pParams->Value >>= aStr;
535 maAuthor = aStr;
537 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "EMail" ) ) )
539 pParams->Value >>= aStr;
540 maEMail = aStr;
542 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "HomepageURL" ) ) )
544 pParams->Value >>= aStr;
545 maHomePage = aStr;
547 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "UserText" ) ) )
549 pParams->Value >>= aStr;
550 maInfo = aStr;
552 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "EnableDownload" ) ) )
554 sal_Bool temp = sal_False;
555 pParams->Value >>= temp;
556 mbDownload = temp;
558 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "SlideSound" ) ) )
560 sal_Bool temp = sal_True;
561 pParams->Value >>= temp;
562 mbSlideSound = temp;
564 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "HiddenSlides" ) ) )
566 sal_Bool temp = sal_True;
567 pParams->Value >>= temp;
568 mbHiddenSlides = temp;
570 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "BackColor" ) ) )
572 sal_Int32 temp = 0;
573 pParams->Value >>= temp;
574 maBackColor = temp;
575 mbUserAttr = true;
577 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "TextColor" ) ) )
579 sal_Int32 temp = 0;
580 pParams->Value >>= temp;
581 maTextColor = temp;
582 mbUserAttr = true;
584 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "LinkColor" ) ) )
586 sal_Int32 temp = 0;
587 pParams->Value >>= temp;
588 maLinkColor = temp;
589 mbUserAttr = true;
591 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "VLinkColor" ) ) )
593 sal_Int32 temp = 0;
594 pParams->Value >>= temp;
595 maVLinkColor = temp;
596 mbUserAttr = true;
598 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ALinkColor" ) ) )
600 sal_Int32 temp = 0;
601 pParams->Value >>= temp;
602 maALinkColor = temp;
603 mbUserAttr = true;
605 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsUseDocumentColors" ) ) )
607 sal_Bool temp = sal_False;
608 pParams->Value >>= temp;
609 mbDocColors = temp;
611 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "KioskSlideDuration" ) ) )
613 sal_Int32 temp = sal_False;
614 pParams->Value >>= temp;
615 mnSlideDuration = temp;
616 mbAutoSlide = true;
618 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "KioskEndless" ) ) )
620 sal_Bool temp = sal_False;
621 pParams->Value >>= temp;
622 mbEndless = temp;
624 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "WebCastCGIURL" ) ) )
626 pParams->Value >>= aStr;
627 maCGIPath = aStr;
629 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "WebCastTargetURL" ) ) )
631 pParams->Value >>= aStr;
632 maURLPath = aStr;
634 else if( pParams->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "WebCastScriptLanguage" ) ) )
636 pParams->Value >>= aStr;
637 if( aStr.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM( "asp" ) ) )
639 meScript = SCRIPT_ASP;
641 else
643 meScript = SCRIPT_PERL;
646 else
648 DBG_ERROR("Unknown property for html export detected!");
651 pParams++;
654 if( meMode == PUBLISH_KIOSK )
656 mbContentsPage = false;
657 mbNotes = false;
661 // calculate image sizes
662 SdPage* pPage = mpDoc->GetSdPage(0, PK_STANDARD);
663 Size aTmpSize( pPage->GetSize() );
664 double dRatio=((double)aTmpSize.Width())/aTmpSize.Height();
667 switch( mnWidthPixel )
669 case 800:
670 mnWidthPixel = 640;
671 break;
672 case 1024:
673 mnWidthPixel = 800;
674 break;
675 case 640:
676 default:
677 mnWidthPixel = 512;
678 break;
681 mnHeightPixel = (USHORT)(mnWidthPixel/dRatio);
683 //------------------------------------------------------------------
684 // Ziel ausklamuestern...
686 INetURLObject aINetURLObj( maPath );
687 DBG_ASSERT( aINetURLObj.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
689 maExportPath = aINetURLObj.GetPartBeforeLastName(); // with trailing '/'
690 maIndex = aINetURLObj.GetLastName();
692 mnSdPageCount = mpDoc->GetSdPageCount( PK_STANDARD );
693 // USHORT nHiddenSlides = 0;
694 for( USHORT nPage = 0; nPage < mnSdPageCount; nPage++ )
696 pPage = mpDoc->GetSdPage( nPage, PK_STANDARD );
698 if( mbHiddenSlides || !pPage->IsExcluded() )
700 maPages.push_back( pPage );
701 maNotesPages.push_back( mpDoc->GetSdPage( nPage, PK_NOTES ) );
704 mnSdPageCount = maPages.size();
706 mbFrames = meMode == PUBLISH_FRAMES;
708 maDocFileName = maIndex;
711 ///////////////////////////////////////////////////////////////////////
712 // Exportiert das im Konstruktor angegebenne Impress Dokument nach HTML
713 ///////////////////////////////////////////////////////////////////////
714 void HtmlExport::ExportHtml()
716 if(mbUserAttr)
718 if( maTextColor == COL_AUTO )
720 if( !maBackColor.IsDark() )
721 maTextColor = COL_BLACK;
724 else if( mbDocColors )
726 // Standard Farben fuer das Farbschema 'Aus Dokument'
727 SetDocColors();
728 maFirstPageColor = maBackColor;
731 // get name for downloadable presentation if needed
732 if( mbDownload )
734 // Separator such und Extension ausblenden
735 USHORT nSepPos = maDocFileName.Search( sal_Unicode('.') );
737 if(nSepPos != STRING_NOTFOUND)
738 maDocFileName.Erase(nSepPos);
740 maDocFileName.AppendAscii( ".odp" );
743 //////
745 USHORT nProgrCount = mnSdPageCount;
746 nProgrCount += mbImpress?mnSdPageCount:0;
747 nProgrCount += mbContentsPage?1:0;
748 nProgrCount += (mbFrames && mbNotes)?mnSdPageCount:0;
749 nProgrCount += (mbFrames)?8:0;
750 InitProgress( nProgrCount );
752 mpDocSh->SetWaitCursor( true );
754 //------------------------------------------------------------------
755 // Exceptions sind doch was schoennes...
757 CreateFileNames();
759 // this is not a true while
760 while( 1 )
762 if( checkForExistingFiles() )
763 break;
765 if( !CreateImagesForPresPages() )
766 break;
768 if( !CreateHtmlForPresPages() )
769 break;
771 if( mbImpress )
772 if( !CreateHtmlTextForPresPages() )
773 break;
775 if( mbFrames )
777 if( !CreateFrames() )
778 break;
780 if( !CreateOutlinePages() )
781 break;
783 if( !CreateNavBarFrames() )
784 break;
786 if( mbNotes && mbImpress )
787 if( !CreateNotesPages() )
788 break;
792 if( mbContentsPage )
793 if( !CreateContentPage() )
794 break;
796 if( !CreateBitmaps() )
797 break;
799 mpDocSh->SetWaitCursor( false );
800 ResetProgress();
802 if( mbDownload )
803 SavePresentation();
805 return;
808 // if we get to this point the export was
809 // canceled by the user after an error
810 mpDocSh->SetWaitCursor( false );
811 ResetProgress();
814 ///////////////////////////////////////////////////////////////////////
816 void HtmlExport::SetDocColors( SdPage* pPage )
818 if( pPage == NULL )
819 pPage = mpDoc->GetSdPage(0, PK_STANDARD);
821 svtools::ColorConfig aConfig;
822 maVLinkColor = Color(aConfig.GetColorValue(svtools::LINKSVISITED).nColor);
823 maALinkColor = Color(aConfig.GetColorValue(svtools::LINKS).nColor);
824 maLinkColor = Color(aConfig.GetColorValue(svtools::LINKS).nColor);
825 maTextColor = Color(COL_BLACK);
827 SfxStyleSheet* pSheet = NULL;
829 if( mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS )
831 // Standard Textfarbe aus Outline-Vorlage der ersten Seite
832 pSheet = pPage->GetStyleSheetForPresObj(PRESOBJ_OUTLINE);
833 if(pSheet == NULL)
834 pSheet = pPage->GetStyleSheetForPresObj(PRESOBJ_TEXT);
835 if(pSheet == NULL)
836 pSheet = pPage->GetStyleSheetForPresObj(PRESOBJ_TITLE);
839 if(pSheet == NULL)
840 pSheet = mpDoc->GetDefaultStyleSheet();
842 if(pSheet)
844 SfxItemSet& rSet = pSheet->GetItemSet();
845 if(rSet.GetItemState(EE_CHAR_COLOR,TRUE) == SFX_ITEM_ON)
846 maTextColor = ((SvxColorItem*)rSet.GetItem(EE_CHAR_COLOR,TRUE))->GetValue();
849 // Standard Hintergrundfarbe aus Background der MasterPage der ersten Seite
850 maBackColor = pPage->GetPageBackgroundColor();
852 if( maTextColor == COL_AUTO )
854 if( !maBackColor.IsDark() )
855 maTextColor = COL_BLACK;
859 ///////////////////////////////////////////////////////////////////////
861 void HtmlExport::InitProgress( USHORT nProgrCount )
863 String aStr(SdResId(STR_CREATE_PAGES));
864 mpProgress = new SfxProgress( mpDocSh, aStr, nProgrCount );
867 ///////////////////////////////////////////////////////////////////////
869 void HtmlExport::ResetProgress()
871 delete mpProgress;
872 mpProgress = NULL;
875 ///////////////////////////////////////////////////////////////////////
877 void HtmlExport::ExportKiosk()
879 mnPagesWritten = 0;
880 InitProgress( 2*mnSdPageCount );
882 CreateFileNames();
883 if( !checkForExistingFiles() )
885 if( CreateImagesForPresPages() )
886 CreateHtmlForPresPages();
889 ResetProgress();
892 ///////////////////////////////////////////////////////////////////////
893 // Export Document with WebCast (TM) Technology
894 ///////////////////////////////////////////////////////////////////////
895 void HtmlExport::ExportWebCast()
897 mnPagesWritten = 0;
898 InitProgress( mnSdPageCount + 9 );
900 mpDocSh->SetWaitCursor( TRUE );
902 CreateFileNames();
904 String aEmpty;
905 if(maCGIPath.Len() == 0)
906 maCGIPath.Assign( sal_Unicode('.') );
908 if( maCGIPath.GetChar( maCGIPath.Len() - 1 ) != sal_Unicode('/') )
909 maCGIPath.Append( sal_Unicode('/') );
911 if( meScript == SCRIPT_ASP )
913 maURLPath.AssignAscii( "./" );
915 else
917 String aEmpty2;
918 if(maURLPath.Len() == 0)
919 maURLPath.Assign( sal_Unicode('.') );
921 if( maURLPath.GetChar( maURLPath.Len() - 1 ) != sal_Unicode('/') )
922 maURLPath.Append( sal_Unicode('/') );
925 // this is not a true while
926 while(1)
928 if( checkForExistingFiles() )
929 break;
931 if(!CreateImagesForPresPages())
932 break;
934 if( meScript == SCRIPT_ASP )
936 if(!CreateASPScripts())
937 break;
939 else
941 if(!CreatePERLScripts())
942 break;
945 if(!CreateImageFileList())
946 break;
948 if(!CreateImageNumberFile())
949 break;
951 break;
954 mpDocSh->SetWaitCursor( false );
955 ResetProgress();
958 ///////////////////////////////////////////////////////////////////////
959 // Save the presentation as a downloadable file in the dest directory
960 ///////////////////////////////////////////////////////////////////////
962 bool HtmlExport::SavePresentation()
964 meEC.SetContext( STR_HTMLEXP_ERROR_CREATE_FILE, maDocFileName );
966 OUString aURL( maExportPath );
967 aURL += maDocFileName;
970 mpDocSh->EnableSetModified( true );
974 uno::Reference< frame::XStorable > xStorable( mpDoc->getUnoModel(), uno::UNO_QUERY );
975 if( xStorable.is() )
977 uno::Sequence< beans::PropertyValue > aProperties( 2 );
978 aProperties[ 0 ].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("Overwrite"));
979 aProperties[ 0 ].Value <<= (sal_Bool)sal_True;
980 aProperties[ 1 ].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("FilterName"));
981 aProperties[ 1 ].Value <<= OUString(RTL_CONSTASCII_USTRINGPARAM("impress8"));
982 xStorable->storeToURL( aURL, aProperties );
984 mpDocSh->EnableSetModified( false );
986 return true;
989 catch( Exception& )
993 mpDocSh->EnableSetModified( false );
995 return false;
998 // =====================================================================
999 // Image-Dateien anlegen
1000 // =====================================================================
1001 bool HtmlExport::CreateImagesForPresPages()
1005 Reference < XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory() );
1006 if( !xMSF.is() )
1007 return false;
1009 Reference< XExporter > xGraphicExporter( xMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.GraphicExportFilter") ) ), UNO_QUERY );
1010 Reference< XFilter > xFilter( xGraphicExporter, UNO_QUERY );
1012 DBG_ASSERT( xFilter.is(), "no com.sun.star.drawing.GraphicExportFilter?" );
1013 if( !xFilter.is() )
1014 return false;
1016 Sequence< PropertyValue > aFilterData(((meFormat==FORMAT_JPG)&&(mnCompression != -1))? 3 : 2);
1017 aFilterData[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("PixelWidth") );
1018 aFilterData[0].Value <<= (sal_Int32)mnWidthPixel;
1019 aFilterData[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("PixelHeight") );
1020 aFilterData[1].Value <<= (sal_Int32)mnHeightPixel;
1021 if((meFormat==FORMAT_JPG)&&(mnCompression != -1))
1023 aFilterData[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("Quality") );
1024 aFilterData[2].Value <<= (sal_Int32)mnCompression;
1027 Sequence< PropertyValue > aDescriptor( 3 );
1028 aDescriptor[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("URL") );
1029 aDescriptor[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("FilterName") );
1030 OUString sFormat;
1031 if( meFormat == FORMAT_PNG )
1032 sFormat = OUString( RTL_CONSTASCII_USTRINGPARAM("PNG") );
1033 else if( meFormat == FORMAT_GIF )
1034 sFormat = OUString( RTL_CONSTASCII_USTRINGPARAM("GIF") );
1035 else
1036 sFormat = OUString( RTL_CONSTASCII_USTRINGPARAM("JPG") );
1038 aDescriptor[1].Value <<= sFormat;
1039 aDescriptor[2].Name = OUString( RTL_CONSTASCII_USTRINGPARAM("FilterData") );
1040 aDescriptor[2].Value <<= aFilterData;
1042 for (USHORT nSdPage = 0; nSdPage < mnSdPageCount; nSdPage++)
1044 SdPage* pPage = maPages[ nSdPage ];
1046 OUString aFull(maExportPath);
1047 aFull += *mpImageFiles[nSdPage];
1049 aDescriptor[0].Value <<= aFull;
1051 Reference< XComponent > xPage( pPage->getUnoPage(), UNO_QUERY );
1052 xGraphicExporter->setSourceDocument( xPage );
1053 xFilter->filter( aDescriptor );
1055 if (mpProgress)
1056 mpProgress->SetState(++mnPagesWritten);
1059 catch( Exception& )
1061 return false;
1064 return true;
1067 // =====================================================================
1068 // Ermittelt das SdrTextObject mit dem Layout Text dieser Seite
1069 // =====================================================================
1070 SdrTextObj* HtmlExport::GetLayoutTextObject(SdrPage* pPage)
1072 ULONG nObjectCount = pPage->GetObjCount();
1073 SdrObject* pObject = NULL;
1074 SdrTextObj* pResult = NULL;
1076 for (ULONG nObject = 0; nObject < nObjectCount; nObject++)
1078 pObject = pPage->GetObj(nObject);
1079 if (pObject->GetObjInventor() == SdrInventor &&
1080 pObject->GetObjIdentifier() == OBJ_OUTLINETEXT)
1082 pResult = (SdrTextObj*)pObject;
1083 break;
1086 return pResult;
1089 // =====================================================================
1090 // HTML-Text Versionen fuer Impress Seiten erzeugen
1091 // =====================================================================
1093 String HtmlExport::WriteMetaCharset() const
1095 String aStr;
1096 const sal_Char *pCharSet = rtl_getBestMimeCharsetFromTextEncoding( RTL_TEXTENCODING_UTF8 );
1097 if ( pCharSet )
1099 aStr.AppendAscii( " <meta HTTP-EQUIV=CONTENT-TYPE CONTENT=\"text/html; charset=" );
1100 aStr.AppendAscii( pCharSet );
1101 aStr.AppendAscii( "\">\r\n" );
1103 return aStr;
1106 bool HtmlExport::CreateHtmlTextForPresPages()
1108 bool bOk = true;
1110 SdrOutliner* pOutliner = mpDoc->GetInternalOutliner();
1112 for(USHORT nSdPage = 0; nSdPage < mnSdPageCount && bOk; nSdPage++)
1114 SdPage* pPage = maPages[ nSdPage ];
1116 if( mbDocColors )
1118 SetDocColors( pPage );
1119 // maBackColor = pPage->GetPageBackgroundColor();
1122 // HTML Kopf
1123 String aStr(maHTMLHeader);
1124 aStr += WriteMetaCharset();
1125 aStr.AppendAscii( " <title>" );
1126 aStr += StringToHTMLString( *mpPageNames[nSdPage] );
1127 aStr.AppendAscii( "</title>\r\n" );
1128 aStr.AppendAscii( "</head>\r\n" );
1129 aStr += CreateBodyTag();
1131 // Navigationsleiste
1132 aStr += CreateNavBar(nSdPage, true);
1134 // Seitentitel
1135 String sTitleText( CreateTextForTitle(pOutliner,pPage, pPage->GetPageBackgroundColor()) );
1136 aStr.AppendAscii( "<h1 style=\"");
1137 aStr.Append( getParagraphStyle( pOutliner, 0 ) );
1138 aStr.AppendAscii( "\">" );
1139 aStr += sTitleText;
1140 aStr.AppendAscii( "</h1>\r\n" );
1142 // Gliederungstext schreiben
1143 aStr += CreateTextForPage( pOutliner, pPage, true, pPage->GetPageBackgroundColor() );
1145 // Notizen
1146 if(mbNotes)
1148 SdPage* pNotesPage = maNotesPages[ nSdPage ];
1149 String aNotesStr( CreateTextForNotesPage( pOutliner, pNotesPage, true, maBackColor) );
1151 if( aNotesStr.Len() )
1153 aStr.AppendAscii( "<br>\r\n<h3>" );
1154 aStr += RESTOHTML(STR_HTMLEXP_NOTES);
1155 aStr.AppendAscii( ":</h3>\r\n" );
1157 aStr += aNotesStr;
1161 // Seite beenden
1162 aStr.AppendAscii( "</body>\r\n</html>" );
1164 bOk = WriteHtml( *mpTextFiles[nSdPage], false, aStr );
1166 if (mpProgress)
1167 mpProgress->SetState(++mnPagesWritten);
1171 pOutliner->Clear();
1173 return bOk;
1176 /** exports the given html data into a non unicode file in the current export path with
1177 the given filename */
1178 bool HtmlExport::WriteHtml( const String& rFileName, bool bAddExtension, const String& rHtmlData )
1180 ULONG nErr = 0;
1182 String aFileName( rFileName );
1183 if( bAddExtension )
1184 aFileName += maHTMLExtension;
1186 meEC.SetContext( STR_HTMLEXP_ERROR_CREATE_FILE, rFileName );
1187 EasyFile aFile;
1188 SvStream* pStr;
1189 String aFull( maExportPath );
1190 aFull += aFileName;
1191 nErr = aFile.createStream(aFull , pStr);
1192 if(nErr == 0)
1194 ByteString aStr( rHtmlData , RTL_TEXTENCODING_UTF8 ) ;
1195 *pStr << aStr.GetBuffer();
1196 nErr = aFile.close();
1199 if( nErr != 0 )
1200 ErrorHandler::HandleError(nErr);
1202 return nErr == 0;
1205 // =====================================================================
1207 /** Erzeugt den Outliner Text fuer das Titelobjekt einer Seite
1209 String HtmlExport::CreateTextForTitle( SdrOutliner* pOutliner, SdPage* pPage, const Color& rBackgroundColor )
1211 SdrTextObj* pTO = (SdrTextObj*)pPage->GetPresObj(PRESOBJ_TITLE);
1212 if(!pTO)
1213 pTO = GetLayoutTextObject(pPage);
1215 if (pTO && !pTO->IsEmptyPresObj())
1217 OutlinerParaObject* pOPO = pTO->GetOutlinerParaObject();
1218 if(pOPO && pOutliner->GetParagraphCount() != 0)
1220 pOutliner->Clear();
1221 pOutliner->SetText(*pOPO);
1222 return ParagraphToHTMLString(pOutliner,0, rBackgroundColor);
1226 return String();
1229 // =====================================================================
1230 // Erzeugt den Outliner Text fuer eine Seite
1231 // =====================================================================
1232 String HtmlExport::CreateTextForPage( SdrOutliner* pOutliner,
1233 SdPage* pPage,
1234 bool bHeadLine, const Color& rBackgroundColor )
1236 String aStr;
1238 SdrTextObj* pTO = (SdrTextObj*)pPage->GetPresObj(PRESOBJ_TEXT);
1239 if(!pTO)
1240 pTO = GetLayoutTextObject(pPage);
1242 if (pTO && !pTO->IsEmptyPresObj())
1244 OutlinerParaObject* pOPO = pTO->GetOutlinerParaObject();
1245 if (pOPO)
1247 pOutliner->Clear();
1248 pOutliner->SetText( *pOPO );
1250 ULONG nCount = pOutliner->GetParagraphCount();
1252 Paragraph* pPara = NULL;
1253 sal_Int16 nActDepth = -1;
1255 String aParaText;
1256 for (ULONG nPara = 0; nPara < nCount; nPara++)
1258 pPara = pOutliner->GetParagraph(nPara);
1259 if(pPara == 0)
1260 continue;
1262 const sal_Int16 nDepth = (USHORT) pOutliner->GetDepth( (USHORT) nPara );
1263 aParaText = ParagraphToHTMLString(pOutliner,nPara,rBackgroundColor);
1265 if(aParaText.Len() == 0)
1266 continue;
1268 if(nDepth < nActDepth )
1272 aStr.AppendAscii( "</ul>" );
1273 nActDepth--;
1275 while(nDepth < nActDepth);
1277 else if(nDepth > nActDepth )
1281 aStr.AppendAscii( "<ul>" );
1282 nActDepth++;
1284 while( nDepth > nActDepth );
1287 String sStyle( getParagraphStyle( pOutliner, nPara ) );
1288 if(nActDepth >= 0 )
1290 aStr.AppendAscii( "<li style=\"");
1291 aStr.Append( sStyle );
1292 aStr.AppendAscii( "\">" );
1295 if(nActDepth <= 0 && bHeadLine)
1297 if( nActDepth == 0 )
1299 aStr.AppendAscii( "<h2>" );
1301 else
1303 aStr.AppendAscii( "<h2 style=\"");
1304 aStr.Append( sStyle );
1305 aStr.AppendAscii( "\">" );
1308 aStr += aParaText;
1309 if(nActDepth == 0 && bHeadLine)
1310 aStr.AppendAscii( "</h2>" );
1311 if(nActDepth >= 0 )
1312 aStr.AppendAscii( "</li>" );
1313 aStr.AppendAscii( "\r\n" );
1316 while( nActDepth >= 0 )
1318 aStr.AppendAscii( "</ul>" );
1319 nActDepth--;
1324 return aStr;
1327 // =====================================================================
1328 // Erzeugt den Outliner Text fuer eine Notizseite
1329 // =====================================================================
1330 String HtmlExport::CreateTextForNotesPage( SdrOutliner* pOutliner,
1331 SdPage* pPage,
1332 bool,
1333 const Color& rBackgroundColor )
1335 String aStr;
1337 SdrTextObj* pTO = (SdrTextObj*)pPage->GetPresObj(PRESOBJ_NOTES);
1339 if (pTO && !pTO->IsEmptyPresObj())
1341 OutlinerParaObject* pOPO = pTO->GetOutlinerParaObject();
1342 if (pOPO)
1344 pOutliner->Clear();
1345 pOutliner->SetText( *pOPO );
1347 ULONG nCount = pOutliner->GetParagraphCount();
1348 for (ULONG nPara = 0; nPara < nCount; nPara++)
1350 aStr.AppendAscii("<p style=\"");
1351 aStr.Append( getParagraphStyle( pOutliner, nPara ) );
1352 aStr.AppendAscii("\">");
1353 aStr += ParagraphToHTMLString( pOutliner, nPara,rBackgroundColor );
1354 aStr.AppendAscii( "</p>\r\n" );
1359 return aStr;
1362 // =====================================================================
1363 // Wandelt einen Paragraphen des Outliners in Html
1364 // =====================================================================
1365 String HtmlExport::ParagraphToHTMLString( SdrOutliner* pOutliner, ULONG nPara, const Color& rBackgroundColor )
1367 String aStr;
1369 if(NULL == pOutliner)
1370 return aStr;
1372 // TODO: MALTE!!!
1373 EditEngine& rEditEngine = *(EditEngine*)&pOutliner->GetEditEngine();
1374 bool bOldUpdateMode = rEditEngine.GetUpdateMode();
1375 rEditEngine.SetUpdateMode(TRUE);
1377 Paragraph* pPara = pOutliner->GetParagraph(nPara);
1378 if(NULL == pPara)
1379 return aStr;
1381 HtmlState aState( (mbUserAttr || mbDocColors) ? maTextColor : Color(COL_BLACK) );
1382 SvUShorts aPortionList;
1383 rEditEngine.GetPortions( (USHORT) nPara, aPortionList );
1384 USHORT nPortionCount = aPortionList.Count();
1386 USHORT nPos1 = 0;
1387 for( USHORT nPortion = 0; nPortion < nPortionCount; nPortion++ )
1389 USHORT nPos2 = aPortionList.GetObject(nPortion);
1391 ESelection aSelection( (USHORT) nPara, nPos1, (USHORT) nPara, nPos2);
1393 SfxItemSet aSet( rEditEngine.GetAttribs( aSelection ) );
1395 String aPortion(StringToHTMLString(rEditEngine.GetText( aSelection )));
1397 aStr += TextAttribToHTMLString( &aSet, &aState, rBackgroundColor );
1398 aStr += aPortion;
1400 nPos1 = nPos2;
1402 aStr += aState.Flush();
1403 rEditEngine.SetUpdateMode(bOldUpdateMode);
1405 return aStr;
1408 // =====================================================================
1409 // Erzeugt anhand der Attribute im angegebennen Set und dem gegebennen
1410 // HtmlState die noetigen Html-Tags um die Attribute zu uebernehmen
1411 // =====================================================================
1412 String HtmlExport::TextAttribToHTMLString( SfxItemSet* pSet, HtmlState* pState, const Color& rBackgroundColor )
1414 String aStr;
1416 if(NULL == pSet)
1417 return aStr;
1419 String aLink, aTarget;
1420 if ( pSet->GetItemState( EE_FEATURE_FIELD ) == SFX_ITEM_ON )
1422 SvxFieldItem* pItem = (SvxFieldItem*)pSet->GetItem( EE_FEATURE_FIELD );
1423 if(pItem)
1425 SvxURLField* pURL = PTR_CAST(SvxURLField, pItem->GetField());
1426 if(pURL)
1428 aLink = pURL->GetURL();
1429 aTarget = pURL->GetTargetFrame();
1434 bool bTemp;
1435 String aTemp;
1437 if ( pSet->GetItemState( EE_CHAR_WEIGHT ) == SFX_ITEM_ON )
1439 bTemp = ((const SvxWeightItem&)pSet->Get( EE_CHAR_WEIGHT )).GetWeight() == WEIGHT_BOLD;
1440 aTemp = pState->SetWeight( bTemp );
1441 if( bTemp )
1442 aStr.Insert( aTemp, 0 );
1443 else
1444 aStr += aTemp;
1447 if ( pSet->GetItemState( EE_CHAR_UNDERLINE ) == SFX_ITEM_ON )
1449 bTemp = ((const SvxUnderlineItem&)pSet->Get( EE_CHAR_UNDERLINE )).GetLineStyle() != UNDERLINE_NONE;
1450 aTemp = pState->SetUnderline( bTemp );
1451 if( bTemp )
1452 aStr.Insert( aTemp, 0 );
1453 else
1454 aStr += aTemp;
1457 if ( pSet->GetItemState( EE_CHAR_STRIKEOUT ) == SFX_ITEM_ON )
1459 bTemp = ((const SvxCrossedOutItem&)pSet->Get( EE_CHAR_STRIKEOUT )).GetStrikeout() != STRIKEOUT_NONE;
1460 aTemp = pState->SetStrikeout( bTemp );
1461 if( bTemp )
1462 aStr.Insert( aTemp, 0 );
1463 else
1464 aStr += aTemp;
1467 if ( pSet->GetItemState( EE_CHAR_ITALIC ) == SFX_ITEM_ON )
1469 bTemp = ((const SvxPostureItem&)pSet->Get( EE_CHAR_ITALIC )).GetPosture() != ITALIC_NONE;
1470 aTemp = pState->SetItalic( bTemp );
1471 if( bTemp )
1472 aStr.Insert( aTemp, 0 );
1473 else
1474 aStr += aTemp;
1477 if(mbDocColors)
1479 if ( pSet->GetItemState( EE_CHAR_COLOR ) == SFX_ITEM_ON )
1481 Color aTextColor = ((const SvxColorItem&) pSet->Get( EE_CHAR_COLOR )).GetValue();
1482 if( aTextColor == COL_AUTO )
1484 if( !rBackgroundColor.IsDark() )
1485 aTextColor = COL_BLACK;
1487 aStr += pState->SetColor( aTextColor );
1491 if( aLink.Len() )
1492 aStr.Insert( pState->SetLink(aLink, aTarget), 0 );
1493 else
1494 aStr += pState->SetLink(aLink, aTarget);
1496 return aStr;
1499 // =====================================================================
1500 // HTML-Wrapper fuer Bild-Dateien erzeugen
1501 // =====================================================================
1502 bool HtmlExport::CreateHtmlForPresPages()
1504 bool bOk = true;
1506 List aClickableObjects;
1508 for(USHORT nSdPage = 0; nSdPage < mnSdPageCount && bOk; nSdPage++)
1510 // Klickbare Objekte finden (auch auf der Masterpage) und
1511 // in Liste stellen. In umgekehrter Zeichenreihenfolge in
1512 // die Liste stellen, da in HTML bei Ueberlappungen die
1513 // _erstgenannte_ Area wirkt.
1515 SdPage* pPage = maPages[ nSdPage ];
1517 if( mbDocColors )
1519 SetDocColors( pPage );
1522 bool bMasterDone = false;
1524 while (!bMasterDone)
1526 // TRUE = rueckwaerts
1527 SdrObjListIter aIter(*pPage, IM_DEEPWITHGROUPS, TRUE);
1529 SdrObject* pObject = aIter.Next();
1530 while (pObject)
1532 SdAnimationInfo* pInfo = mpDoc->GetAnimationInfo(pObject);
1533 SdIMapInfo* pIMapInfo = mpDoc->GetIMapInfo(pObject);
1535 if ((pInfo &&
1536 (pInfo->meClickAction == presentation::ClickAction_BOOKMARK ||
1537 pInfo->meClickAction == presentation::ClickAction_DOCUMENT ||
1538 pInfo->meClickAction == presentation::ClickAction_PREVPAGE ||
1539 pInfo->meClickAction == presentation::ClickAction_NEXTPAGE ||
1540 pInfo->meClickAction == presentation::ClickAction_FIRSTPAGE ||
1541 pInfo->meClickAction == presentation::ClickAction_LASTPAGE)) ||
1542 pIMapInfo)
1544 aClickableObjects.Insert(pObject, LIST_APPEND);
1547 pObject = aIter.Next();
1549 // jetzt zur Masterpage oder beenden
1550 if (!pPage->IsMasterPage())
1551 pPage = (SdPage*)(&(pPage->TRG_GetMasterPage()));
1552 else
1553 bMasterDone = true;
1555 ULONG nClickableObjectCount = aClickableObjects.Count();
1557 // HTML Head
1558 String aStr(maHTMLHeader);
1559 aStr += WriteMetaCharset();
1560 aStr.AppendAscii( " <title>" );
1561 aStr += StringToHTMLString(*mpPageNames[nSdPage]);
1562 aStr.AppendAscii( "</title>\r\n" );
1564 // insert timing information
1565 pPage = maPages[ nSdPage ];
1566 if( meMode == PUBLISH_KIOSK )
1568 ULONG nSecs = 0;
1569 bool bEndless = false;
1570 if( !mbAutoSlide )
1572 if( pPage->GetPresChange() != PRESCHANGE_MANUAL )
1574 nSecs = pPage->GetTime();
1575 bEndless = mpDoc->getPresentationSettings().mbEndless;
1578 else
1580 nSecs = mnSlideDuration;
1581 bEndless = mbEndless;
1584 if( nSecs != 0 )
1586 if( nSdPage < (mnSdPageCount-1) || bEndless )
1588 aStr.AppendAscii( "<meta http-equiv=\"refresh\" content=\"" );
1589 aStr += String::CreateFromInt32(nSecs);
1590 aStr.AppendAscii( "; URL=" );
1592 int nPage = nSdPage + 1;
1593 if( nPage == mnSdPageCount )
1594 nPage = 0;
1596 aStr += StringToURL(*mpHTMLFiles[nPage]);
1598 aStr.AppendAscii( "\">\r\n" );
1603 aStr.AppendAscii( "</head>\r\n" );
1605 // HTML Body
1606 aStr += CreateBodyTag();
1608 if( mbSlideSound && pPage->IsSoundOn() )
1609 aStr += InsertSound( pPage->GetSoundFile() );
1611 // Navigationsleiste
1612 if(!mbFrames )
1613 aStr += CreateNavBar( nSdPage, false );
1614 // Image
1615 aStr.AppendAscii( "<center>" );
1616 aStr.AppendAscii( "<img src=\"" );
1617 aStr += StringToURL( *mpImageFiles[nSdPage] );
1618 aStr.AppendAscii( "\" alt=\"\"" );
1620 if (nClickableObjectCount > 0)
1621 aStr.AppendAscii( " USEMAP=\"#map0\"" );
1623 aStr.AppendAscii( "></center>\r\n" );
1625 // Notizen
1626 if(mbNotes && !mbFrames)
1628 SdrOutliner* pOutliner = mpDoc->GetInternalOutliner();
1629 SdPage* pNotesPage = maNotesPages[ nSdPage ];
1630 String aNotesStr( CreateTextForNotesPage( pOutliner, pNotesPage, true, maBackColor) );
1631 pOutliner->Clear();
1633 if( aNotesStr.Len() )
1635 aStr.AppendAscii( "<h3>" );
1636 aStr += RESTOHTML(STR_HTMLEXP_NOTES);
1637 aStr.AppendAscii( ":</h3><br>\r\n\r\n<p>" );
1639 aStr += aNotesStr;
1640 aStr.AppendAscii( "\r\n</p>\r\n" );
1644 // ggfs. Imagemap erzeugen
1645 if (nClickableObjectCount > 0)
1647 aStr.AppendAscii( "<map name=\"map0\">\r\n" );
1649 for (ULONG nObject = 0; nObject < nClickableObjectCount; nObject++)
1651 SdrObject* pObject = (SdrObject*)aClickableObjects.GetObject(nObject);
1652 SdAnimationInfo* pInfo = mpDoc->GetAnimationInfo(pObject);
1653 SdIMapInfo* pIMapInfo = mpDoc->GetIMapInfo(pObject);
1655 Rectangle aRect(pObject->GetCurrentBoundRect());
1656 Point aLogPos(aRect.TopLeft());
1657 bool bIsSquare = aRect.GetWidth() == aRect.GetHeight();
1659 ULONG nPageWidth = pPage->GetSize().Width() - pPage->GetLftBorder() -
1660 pPage->GetRgtBorder();
1662 // das BoundRect bezieht sich auf den physikalischen
1663 // Seitenursprung, nicht auf den Koordinatenursprung
1664 aRect.Move(-pPage->GetLftBorder(), -pPage->GetUppBorder());
1666 double fLogicToPixel = ((double)mnWidthPixel) / nPageWidth;
1667 aRect.Left() = (long)(aRect.Left() * fLogicToPixel);
1668 aRect.Top() = (long)(aRect.Top() * fLogicToPixel);
1669 aRect.Right() = (long)(aRect.Right() * fLogicToPixel);
1670 aRect.Bottom() = (long)(aRect.Bottom() * fLogicToPixel);
1671 long nRadius = aRect.GetWidth() / 2;
1674 /*************************************************************
1675 |* wenn das Objekt eine eigene Imagemap enthaelt, werden ihre
1676 |* Areas in diese Imagemap eingefuegt
1677 \************************************************************/
1678 if (pIMapInfo)
1680 const ImageMap& rIMap = pIMapInfo->GetImageMap();
1681 UINT16 nAreaCount = rIMap.GetIMapObjectCount();
1682 for (UINT16 nArea = 0; nArea < nAreaCount; nArea++)
1684 IMapObject* pArea = rIMap.GetIMapObject(nArea);
1685 UINT16 nType = pArea->GetType();
1686 String aURL( pArea->GetURL() );
1688 // ggfs. Seiten- oder Objektnamen umwandeln in den
1689 // Namen der entsprechenden HTML-Datei
1690 BOOL bIsMasterPage;
1691 USHORT nPgNum = mpDoc->GetPageByName( aURL, bIsMasterPage );
1692 SdrObject* pObj = NULL;
1694 if (nPgNum == SDRPAGE_NOTFOUND)
1696 // Ist das Bookmark ein Objekt?
1697 pObj = mpDoc->GetObj( aURL );
1698 if (pObj)
1699 nPgNum = pObj->GetPage()->GetPageNum();
1701 if (nPgNum != SDRPAGE_NOTFOUND)
1703 nPgNum = (nPgNum - 1) / 2; // SdrPageNum --> SdPageNum
1704 aURL = CreatePageURL(nPgNum);
1707 switch(nType)
1709 case IMAP_OBJ_RECTANGLE:
1711 Rectangle aArea(((IMapRectangleObject*)pArea)->
1712 GetRectangle(false));
1714 // Umrechnung in Pixelkoordinaten
1715 aArea.Move(aLogPos.X() - pPage->GetLftBorder(),
1716 aLogPos.Y() - pPage->GetUppBorder());
1717 aArea.Left() = (long)(aArea.Left() * fLogicToPixel);
1718 aArea.Top() = (long)(aArea.Top() * fLogicToPixel);
1719 aArea.Right() = (long)(aArea.Right() * fLogicToPixel);
1720 aArea.Bottom() = (long)(aArea.Bottom() * fLogicToPixel);
1722 aStr += CreateHTMLRectArea(aArea, aURL);
1724 break;
1726 case IMAP_OBJ_CIRCLE:
1728 Point aCenter(((IMapCircleObject*)pArea)->
1729 GetCenter(false));
1730 aCenter += Point(aLogPos.X() - pPage->GetLftBorder(),
1731 aLogPos.Y() - pPage->GetUppBorder());
1732 aCenter.X() = (long)(aCenter.X() * fLogicToPixel);
1733 aCenter.Y() = (long)(aCenter.Y() * fLogicToPixel);
1735 ULONG nCircleRadius = (((IMapCircleObject*)pArea)->
1736 GetRadius(false));
1737 nCircleRadius = (ULONG)(nCircleRadius * fLogicToPixel);
1738 aStr += CreateHTMLCircleArea(nCircleRadius,
1739 aCenter.X(), aCenter.Y(),
1740 aURL);
1742 break;
1744 case IMAP_OBJ_POLYGON:
1746 Polygon aArea(((IMapPolygonObject*)pArea)->GetPolygon(false));
1747 aStr += CreateHTMLPolygonArea(::basegfx::B2DPolyPolygon(aArea.getB2DPolygon()), Size(aLogPos.X() - pPage->GetLftBorder(), aLogPos.Y() - pPage->GetUppBorder()), fLogicToPixel, aURL);
1749 break;
1751 default:
1753 DBG_WARNING("unbekannter IMAP_OBJ_Typ");
1755 break;
1762 /*************************************************************
1763 |* wenn es eine presentation::ClickAction gibt, Bookmark bestimmen und eine
1764 |* Area fuer das ganze Objekt erzeugen
1765 \************************************************************/
1766 if( pInfo )
1768 String aHRef;
1769 presentation::ClickAction eClickAction = pInfo->meClickAction;
1771 switch( eClickAction )
1773 case presentation::ClickAction_BOOKMARK:
1775 BOOL bIsMasterPage;
1776 USHORT nPgNum = mpDoc->GetPageByName( pInfo->GetBookmark(), bIsMasterPage );
1777 SdrObject* pObj = NULL;
1779 if( nPgNum == SDRPAGE_NOTFOUND )
1781 // Ist das Bookmark ein Objekt?
1782 pObj = mpDoc->GetObj(pInfo->GetBookmark());
1783 if (pObj)
1784 nPgNum = pObj->GetPage()->GetPageNum();
1787 if( SDRPAGE_NOTFOUND != nPgNum )
1788 aHRef = CreatePageURL(( nPgNum - 1 ) / 2 );
1790 break;
1792 case presentation::ClickAction_DOCUMENT:
1793 aHRef = pInfo->GetBookmark();
1794 break;
1796 case presentation::ClickAction_PREVPAGE:
1798 ULONG nPage = nSdPage;
1799 if (nSdPage == 0)
1800 nPage = 0;
1801 else
1802 nPage = nSdPage - 1;
1804 aHRef = CreatePageURL( (USHORT) nPage);
1806 break;
1808 case presentation::ClickAction_NEXTPAGE:
1810 ULONG nPage = nSdPage;
1811 if (nSdPage == mnSdPageCount - 1)
1812 nPage = mnSdPageCount - 1;
1813 else
1814 nPage = nSdPage + 1;
1816 aHRef = CreatePageURL( (USHORT) nPage);
1818 break;
1820 case presentation::ClickAction_FIRSTPAGE:
1821 aHRef = CreatePageURL(0);
1822 break;
1824 case presentation::ClickAction_LASTPAGE:
1825 aHRef = CreatePageURL(mnSdPageCount - 1);
1826 break;
1828 default:
1829 break;
1832 // jetzt die Areas
1833 if( aHRef.Len() )
1835 // ein Kreis?
1836 if (pObject->GetObjInventor() == SdrInventor &&
1837 pObject->GetObjIdentifier() == OBJ_CIRC &&
1838 bIsSquare )
1840 aStr += CreateHTMLCircleArea(aRect.GetWidth() / 2,
1841 aRect.Left() + nRadius,
1842 aRect.Top() + nRadius,
1843 aHRef);
1845 // ein Polygon?
1846 else if (pObject->GetObjInventor() == SdrInventor &&
1847 (pObject->GetObjIdentifier() == OBJ_PATHLINE ||
1848 pObject->GetObjIdentifier() == OBJ_PLIN ||
1849 pObject->GetObjIdentifier() == OBJ_POLY))
1851 aStr += CreateHTMLPolygonArea(((SdrPathObj*)pObject)->GetPathPoly(), Size(-pPage->GetLftBorder(), -pPage->GetUppBorder()), fLogicToPixel, aHRef);
1853 // was anderes: das BoundRect nehmen
1854 else
1856 aStr += CreateHTMLRectArea(aRect, aHRef);
1863 aStr.AppendAscii( "</map>\r\n" );
1865 aClickableObjects.Clear();
1867 aStr.AppendAscii( "</body>\r\n</html>" );
1869 bOk = WriteHtml( *mpHTMLFiles[nSdPage], false, aStr );
1871 if (mpProgress)
1872 mpProgress->SetState(++mnPagesWritten);
1875 return bOk;
1878 // =====================================================================
1879 // Uebersichtsseite erzeugen
1880 // =====================================================================
1881 bool HtmlExport::CreateContentPage()
1883 // Parameter
1884 String aEmpty;
1886 if( mbDocColors )
1887 SetDocColors();
1889 // Html Kopf
1890 String aStr(maHTMLHeader);
1891 aStr += WriteMetaCharset();
1892 aStr.AppendAscii( " <title>" );
1893 aStr += StringToHTMLString(*mpPageNames[0]);
1894 aStr.AppendAscii( "</title>\r\n</head>\r\n" );
1895 aStr += CreateBodyTag();
1897 // Seitenkopf
1898 aStr.AppendAscii( "<center>\r\n" );
1900 if(mbHeader)
1902 aStr.AppendAscii( "<h1>" );
1903 aStr += getDocumentTitle();
1904 aStr.AppendAscii( "</h1><br>\r\n" );
1907 aStr.AppendAscii( "<h2>" );
1909 // #92564# Solaris compiler bug workaround
1910 if( mbFrames )
1911 aStr += CreateLink( maFramePage,
1912 RESTOHTML(STR_HTMLEXP_CLICKSTART) );
1913 else
1914 aStr += CreateLink( StringToHTMLString(*mpHTMLFiles[0]),
1915 RESTOHTML(STR_HTMLEXP_CLICKSTART) );
1917 aStr.AppendAscii( "</h2>\r\n</center>\r\n" );
1919 aStr.AppendAscii( "<center><table width=\"90%\"><tr>\r\n" );
1921 // Inhaltsverzeichnis
1922 aStr.AppendAscii( "<td valign=\"top\" align=\"left\" width=\"50%\">\r\n" );
1923 aStr.AppendAscii( "<h3>" );
1924 aStr += RESTOHTML(STR_HTMLEXP_CONTENTS);
1925 aStr.AppendAscii( "</h3>" );
1927 for(USHORT nSdPage = 0; nSdPage < mnSdPageCount; nSdPage++)
1929 String aPageName = *mpPageNames[nSdPage];
1930 aStr.AppendAscii( "<div align=\"left\">" );
1931 if(mbFrames)
1932 aStr += StringToHTMLString(aPageName);
1933 else
1934 aStr += CreateLink(*mpHTMLFiles[nSdPage], aPageName);
1935 aStr.AppendAscii( "</div>\r\n" );
1937 aStr.AppendAscii( "</td>\r\n" );
1939 // Dokument Infos
1940 aStr.AppendAscii( "<td valign=\"top\" width=\"50%\">\r\n" );
1942 if(maAuthor.Len())
1944 aStr.AppendAscii( "<p><strong>" );
1945 aStr += RESTOHTML(STR_HTMLEXP_AUTHOR);
1946 aStr.AppendAscii( ":</strong> " );
1947 aStr += StringToHTMLString(maAuthor);
1948 aStr.AppendAscii( "</p>\r\n" );
1951 if(maEMail.Len())
1953 aStr.AppendAscii( "<p><strong>" );
1954 aStr += RESTOHTML(STR_HTMLEXP_EMAIL);
1955 aStr.AppendAscii( ":</strong> <a href=\"mailto:" );
1956 aStr += StringToURL(maEMail);
1957 aStr.AppendAscii( "\">" );
1958 aStr += StringToHTMLString(maEMail);
1959 aStr.AppendAscii( "</a></p>\r\n" );
1962 if(maHomePage.Len())
1964 aStr.AppendAscii( "<p><strong>" );
1965 aStr += RESTOHTML(STR_HTMLEXP_HOMEPAGE);
1966 aStr.AppendAscii( ":</strong> <a href=\"" );
1967 aStr += StringToURL(maHomePage);
1968 aStr.AppendAscii( "\">" );
1969 aStr += StringToHTMLString(maHomePage);
1970 aStr.AppendAscii( "</a> </p>\r\n" );
1973 if(maInfo.Len())
1975 aStr.AppendAscii( "<p><strong>" );
1976 aStr += RESTOHTML(STR_HTMLEXP_INFO);
1977 aStr.AppendAscii( ":</strong><br>\r\n" );
1978 aStr += StringToHTMLString(maInfo);
1979 aStr.AppendAscii( "</p>\r\n" );
1982 if(mbDownload)
1984 aStr.AppendAscii( "<p><a href=\"" );
1985 aStr += StringToURL(maDocFileName);
1986 aStr.AppendAscii( "\">" );
1987 aStr += RESTOHTML(STR_HTMLEXP_DOWNLOAD);
1988 aStr.AppendAscii( "</a></p>\r\n" );
1991 aStr.AppendAscii( "</td></tr></table></center>\r\n" );
1993 aStr.AppendAscii( "</body>\r\n</html>" );
1995 bool bOk = WriteHtml( maIndex, false, aStr );
1997 if (mpProgress)
1998 mpProgress->SetState(++mnPagesWritten);
2000 return bOk;
2003 // =====================================================================
2004 // Notiz Seiten erzeugen (fuer Frames)
2005 // =====================================================================
2006 bool HtmlExport::CreateNotesPages()
2008 bool bOk = true;
2010 SdrOutliner* pOutliner = mpDoc->GetInternalOutliner();
2011 for( USHORT nSdPage = 0; bOk && nSdPage < mnSdPageCount; nSdPage++ )
2013 SdPage* pPage = maNotesPages[nSdPage];
2014 if( mbDocColors )
2015 SetDocColors( pPage );
2017 // Html Kopf
2018 String aStr(maHTMLHeader);
2019 aStr += WriteMetaCharset();
2020 aStr.AppendAscii( " <title>" );
2021 aStr += StringToHTMLString(*mpPageNames[0]);
2022 aStr.AppendAscii( "</title>\r\n</head>\r\n" );
2023 aStr += CreateBodyTag();
2025 if(pPage)
2026 aStr += CreateTextForNotesPage( pOutliner, pPage, true, maBackColor );
2028 aStr.AppendAscii( "</body>\r\n</html>" );
2030 String aFileName( RTL_CONSTASCII_USTRINGPARAM("note") );
2031 aFileName += String::CreateFromInt32(nSdPage);
2032 bOk = WriteHtml( aFileName, true, aStr );
2034 if (mpProgress)
2035 mpProgress->SetState(++mnPagesWritten);
2038 pOutliner->Clear();
2040 return bOk;
2043 // =====================================================================
2044 // Outline Seiten erzeugen (fuer Frames)
2045 // =====================================================================
2046 bool HtmlExport::CreateOutlinePages()
2048 bool bOk = true;
2050 if( mbDocColors )
2052 SetDocColors();
2055 // Seite 0 wird der zugeklappte Outline, Seite 1 der aufgeklappte
2056 for( int nPage = 0; nPage < (mbImpress?2:1) && bOk; nPage++ )
2058 // Html Kopf
2059 String aStr(maHTMLHeader);
2060 aStr += WriteMetaCharset();
2061 aStr.AppendAscii( " <title>" );
2062 aStr += StringToHTMLString(*mpPageNames[0]);
2063 aStr.AppendAscii( "</title>\r\n</head>\r\n" );
2064 aStr += CreateBodyTag();
2066 SdrOutliner* pOutliner = mpDoc->GetInternalOutliner();
2067 for(USHORT nSdPage = 0; nSdPage < mnSdPageCount; nSdPage++)
2069 SdPage* pPage = maPages[ nSdPage ];
2071 aStr.AppendAscii( "<div align=\"left\">" );
2072 String aLink( RTL_CONSTASCII_USTRINGPARAM( "JavaScript:parent.NavigateAbs(" ) );
2073 aLink += String::CreateFromInt32(nSdPage);
2074 aLink.Append( sal_Unicode(')') );
2076 String aTitle = CreateTextForTitle(pOutliner,pPage, maBackColor);
2077 if(aTitle.Len() == 0)
2078 aTitle = *mpPageNames[nSdPage];
2080 aStr.AppendAscii("<p style=\"");
2081 aStr.Append( getParagraphStyle( pOutliner, 0 ) );
2082 aStr.AppendAscii("\">");
2083 aStr += CreateLink(aLink, aTitle);
2084 aStr.AppendAscii("</p>");
2086 if(nPage==1)
2088 aStr += CreateTextForPage( pOutliner, pPage, false, maBackColor );
2090 aStr.AppendAscii( "</div>\r\n" );
2092 pOutliner->Clear();
2094 aStr.AppendAscii( "</body>\r\n</html>" );
2096 String aFileName( RTL_CONSTASCII_USTRINGPARAM("outline") );
2097 aFileName += String::CreateFromInt32(nPage);
2098 bOk = WriteHtml( aFileName, true, aStr );
2100 if (mpProgress)
2101 mpProgress->SetState(++mnPagesWritten);
2104 return bOk;
2107 // =====================================================================
2108 // Dateinamen festlegen
2109 // =====================================================================
2110 void HtmlExport::CreateFileNames()
2112 // Listen mit neuen Dateinamen anlegen
2113 mpHTMLFiles = new String*[mnSdPageCount];
2114 mpImageFiles = new String*[mnSdPageCount];
2115 mpPageNames = new String*[mnSdPageCount];
2116 mpTextFiles = new String*[mnSdPageCount];
2118 mbHeader = false; // Ueberschrift auf Uebersichtsseite?
2120 for (USHORT nSdPage = 0; nSdPage < mnSdPageCount; nSdPage++)
2122 String* pName;
2123 if(nSdPage == 0 && !mbContentsPage && !mbFrames )
2124 pName = new String(maIndex);
2125 else
2127 pName = new String( RTL_CONSTASCII_USTRINGPARAM("img") );
2128 *pName += String::CreateFromInt32(nSdPage);
2129 *pName += maHTMLExtension;
2132 mpHTMLFiles[nSdPage] = pName;
2134 pName = new String( RTL_CONSTASCII_USTRINGPARAM("img") );
2135 *pName += String::CreateFromInt32(nSdPage);
2136 if( meFormat==FORMAT_GIF )
2137 pName->AppendAscii( ".gif" );
2138 else if( meFormat==FORMAT_JPG )
2139 pName->AppendAscii( ".jpg" );
2140 else
2141 pName->AppendAscii( ".png" );
2143 mpImageFiles[nSdPage] = pName;
2145 pName = new String( RTL_CONSTASCII_USTRINGPARAM("text"));
2146 *pName += String::CreateFromInt32(nSdPage);
2147 *pName += maHTMLExtension;
2148 mpTextFiles[nSdPage] = pName;
2150 SdPage* pSdPage = maPages[ nSdPage ];
2152 // get slide title from page name
2153 String* pPageTitle = new String();
2154 *pPageTitle = pSdPage->GetName();
2155 mpPageNames[nSdPage] = pPageTitle;
2158 if(!mbContentsPage && mbFrames)
2159 maFramePage = maIndex;
2160 else
2162 maFramePage.AssignAscii( "siframes" );
2163 maFramePage += maHTMLExtension;
2167 String HtmlExport::getDocumentTitle()
2169 // check for a title object in this page, if its the first
2170 // title it becomes this documents title for the content
2171 // page
2172 if( !mbHeader )
2174 if(mbImpress)
2176 // falls es ein nicht-leeres Titelobjekt gibt, dessen ersten Absatz
2177 // als Seitentitel benutzen
2178 SdPage* pSdPage = mpDoc->GetSdPage(0, PK_STANDARD);
2179 SdrObject* pTitleObj = pSdPage->GetPresObj(PRESOBJ_TITLE);
2180 if (pTitleObj && !pTitleObj->IsEmptyPresObj())
2182 OutlinerParaObject* pParaObject = pTitleObj->GetOutlinerParaObject();
2183 if (pParaObject)
2185 const EditTextObject& rEditTextObject =
2186 pParaObject->GetTextObject();
2187 if (&rEditTextObject)
2189 String aTest(rEditTextObject.GetText(0));
2190 if (aTest.Len() > 0)
2191 mDocTitle = aTest;
2196 for( UINT16 i = 0; i < mDocTitle.Len(); i++ )
2197 if( mDocTitle.GetChar(i) == (sal_Unicode)0xff)
2198 mDocTitle.SetChar(i, sal_Unicode(' ') );
2201 if( !mDocTitle.Len() )
2203 mDocTitle = maDocFileName;
2204 int nDot = mDocTitle.Search( '.' );
2205 if( nDot > 0 )
2206 mDocTitle.Erase( (USHORT)nDot );
2208 mbHeader = true;
2211 return mDocTitle;
2215 var nCurrentPage = 0;
2216 var nPageCount = JSCRIPT2;
2218 function NavigateAbs( nPage )
2220 frames[\"show\"].location.href = \"img\" + nPage + \".htm\";
2221 frames[\"notes\"].location.href = \"note\" + nPage + \".htm\";
2222 nCurrentPage = nPage;
2223 if(nCurrentPage==0)
2225 frames[\"navbar1\"].location.href = \"navbar0.htm\";
2227 else if(nCurrentPage==nPageCount-1)
2229 frames[\"navbar1\"].location.href = \"navbar2.htm\";
2231 else
2232 frames[\"navbar1\"].location.href = \"navbar1.htm\";
2236 function NavigateRel( nDelta )
2238 var nPage = parseInt(nCurrentPage) + parseInt(nDelta);
2239 if( (nPage >= 0) && (nPage < nPageCount) )
2241 NavigateAbs( nPage );
2245 function ExpandOutline()
2247 frames[\"navbar2\"].location.href = \"navbar4.htm\";
2248 frames[\"outline\"].location.href = \"outline1.htm\";
2251 function CollapseOutline()
2253 frames[\"navbar2\"].location.href = \"navbar3.htm\";
2254 frames[\"outline\"].location.href = \"outline0.htm\";
2258 static const char* JS_NavigateAbs =
2259 "function NavigateAbs( nPage )\r\n"
2260 "{\r\n"
2261 " frames[\"show\"].location.href = \"img\" + nPage + \".$EXT\";\r\n"
2262 " //frames[\"notes\"].location.href = \"note\" + nPage + \".$EXT\";\r\n"
2263 " nCurrentPage = nPage;\r\n"
2264 " if(nCurrentPage==0)\r\n"
2265 " {\r\n"
2266 " frames[\"navbar1\"].location.href = \"navbar0.$EXT\";\r\n"
2267 " }\r\n"
2268 " else if(nCurrentPage==nPageCount-1)\r\n"
2269 " {\r\n"
2270 " frames[\"navbar1\"].location.href = \"navbar2.$EXT\";\r\n"
2271 " }\r\n"
2272 " else\r\n"
2273 " {\r\n"
2274 " frames[\"navbar1\"].location.href = \"navbar1.$EXT\";\r\n"
2275 " }\r\n"
2276 "}\r\n\r\n";
2278 static const char* JS_NavigateRel =
2279 "function NavigateRel( nDelta )\r\n"
2280 "{\r\n"
2281 " var nPage = parseInt(nCurrentPage) + parseInt(nDelta);\r\n"
2282 " if( (nPage >= 0) && (nPage < nPageCount) )\r\n"
2283 " {\r\n"
2284 " NavigateAbs( nPage );\r\n"
2285 " }\r\n"
2286 "}\r\n\r\n";
2288 static const char* JS_ExpandOutline =
2289 "function ExpandOutline()\r\n"
2290 "{\r\n"
2291 " frames[\"navbar2\"].location.href = \"navbar4.$EXT\";\r\n"
2292 " frames[\"outline\"].location.href = \"outline1.$EXT\";\r\n"
2293 "}\r\n\r\n";
2295 static const char * JS_CollapseOutline =
2296 "function CollapseOutline()\r\n"
2297 "{\r\n"
2298 " frames[\"navbar2\"].location.href = \"navbar3.$EXT\";\r\n"
2299 " frames[\"outline\"].location.href = \"outline0.$EXT\";\r\n"
2300 "}\r\n\r\n";
2302 // ====================================================================
2303 // Seite mit den Frames erzeugen
2304 // ====================================================================
2305 bool HtmlExport::CreateFrames()
2307 String aTmp;
2308 String aStr( RTL_CONSTASCII_USTRINGPARAM(
2309 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\"\r\n"
2310 " \"http://www.w3.org/TR/html4/frameset.dtd\">\r\n"
2311 "<html>\r\n<head>\r\n" ) );
2313 aStr += WriteMetaCharset();
2314 aStr.AppendAscii( " <title>" );
2315 aStr += StringToHTMLString(*mpPageNames[0]);
2316 aStr.AppendAscii( "</title>\r\n" );
2318 aStr.AppendAscii( "<script type=\"text/javascript\">\r\n<!--\r\n" );
2320 aStr.AppendAscii( "var nCurrentPage = 0;\r\nvar nPageCount = " );
2321 aStr += String::CreateFromInt32(mnSdPageCount);
2322 aStr.AppendAscii( ";\r\n\r\n" );
2324 String aFunction;
2325 aFunction.AssignAscii(JS_NavigateAbs);
2327 if(mbNotes)
2329 String aEmpty;
2330 String aSlash( RTL_CONSTASCII_USTRINGPARAM( "//" ) );
2331 aFunction.SearchAndReplaceAll( aSlash, aEmpty);
2334 // substitute HTML file extension
2335 String aPlaceHolder(RTL_CONSTASCII_USTRINGPARAM(".$EXT"));
2336 aFunction.SearchAndReplaceAll(aPlaceHolder, maHTMLExtension);
2337 aStr += aFunction;
2339 aTmp.AssignAscii( JS_NavigateRel );
2340 aTmp.SearchAndReplaceAll(aPlaceHolder, maHTMLExtension);
2341 aStr += aTmp;
2343 if(mbImpress)
2345 aTmp.AssignAscii( JS_ExpandOutline );
2346 aTmp.SearchAndReplaceAll(aPlaceHolder, maHTMLExtension);
2347 aStr += aTmp;
2349 aTmp.AssignAscii( JS_CollapseOutline );
2350 aTmp.SearchAndReplaceAll(aPlaceHolder, maHTMLExtension);
2351 aStr += aTmp;
2353 aStr.AppendAscii( "// -->\r\n</script>\r\n" );
2355 aStr.AppendAscii( "</head>\r\n" );
2357 aStr.AppendAscii( "<frameset cols=\"*," );
2358 aStr += String::CreateFromInt32((mnWidthPixel + 16));
2359 aStr.AppendAscii( "\">\r\n" );
2360 if(mbImpress)
2362 aStr.AppendAscii( " <frameset rows=\"42,*\">\r\n" );
2363 aStr.AppendAscii( " <frame src=\"navbar3" );
2364 aStr += StringToURL(maHTMLExtension);
2365 aStr.AppendAscii( "\" name=\"navbar2\" marginwidth=\"4\" marginheight=\"4\" scrolling=\"no\">\r\n" );
2367 aStr.AppendAscii( " <frame src=\"outline0" );
2368 aStr += StringToURL(maHTMLExtension);
2369 aStr.AppendAscii( "\" name=\"outline\">\r\n" );
2370 if(mbImpress)
2371 aStr.AppendAscii( " </frameset>\r\n" );
2373 if(mbNotes)
2375 aStr.AppendAscii( " <frameset rows=\"42," );
2376 aStr += String::CreateFromInt32((int)((double)mnWidthPixel * 0.75) + 16);
2377 aStr.AppendAscii( ",*\">\r\n" );
2379 else
2380 aStr.AppendAscii( " <frameset rows=\"42,*\">\r\n" );
2382 aStr.AppendAscii( " <frame src=\"navbar0" );
2383 aStr += StringToURL(maHTMLExtension);
2384 aStr.AppendAscii( "\" name=\"navbar1\" marginwidth=\"4\" marginheight=\"4\" scrolling=\"no\">\r\n" );
2386 aStr.AppendAscii( " <frame src=\"" );
2387 aStr += StringToURL(*mpHTMLFiles[0]);
2388 aStr.AppendAscii( "\" name=\"show\" marginwidth=\"4\" marginheight=\"4\">\r\n" );
2390 if(mbNotes)
2392 aStr.AppendAscii( " <frame src=\"note0" );
2393 aStr += StringToURL(maHTMLExtension);
2394 aStr.AppendAscii( "\" name=\"notes\">\r\n" );
2396 aStr.AppendAscii( " </frameset>\r\n" );
2398 aStr.AppendAscii( "<noframes>\r\n" );
2399 aStr += CreateBodyTag();
2400 aStr += RESTOHTML(STR_HTMLEXP_NOFRAMES);
2401 aStr.AppendAscii( "\r\n</noframes>\r\n</frameset>\r\n</html>" );
2403 bool bOk = WriteHtml( maFramePage, false, aStr );
2405 if (mpProgress)
2406 mpProgress->SetState(++mnPagesWritten);
2408 return bOk;
2411 // ====================================================================
2412 // Buttonleiste fuer Standard ausgeben
2413 // Es werden 4 html files erstellt
2414 // navbar0.htm Navigationsleiste Grafik fuer erste Seite
2415 // navbar1.htm Navigationsleiste Grafik fuer zweite bis vorletzte Seite
2416 // navbar2.htm Navigationsleiste Grafik fuer letzte Seite
2417 // navbar3.htm Navigationsleiste Outline zugeklappt
2418 // navbar4.htm Navigationsleiste Outline aufgeklappt
2419 // ====================================================================
2420 bool HtmlExport::CreateNavBarFrames()
2422 bool bOk = true;
2423 String aButton;
2425 if( mbDocColors )
2427 SetDocColors();
2428 maBackColor = maFirstPageColor;
2431 for( int nFile = 0; nFile < 3 && bOk; nFile++ )
2433 String aStr(maHTMLHeader);
2434 aStr += WriteMetaCharset();
2435 aStr.AppendAscii( " <title>" );
2436 aStr += StringToHTMLString(*mpPageNames[0]);
2437 aStr.AppendAscii( "</title>\r\n</head>\r\n" );
2438 aStr += CreateBodyTag();
2439 aStr.AppendAscii( "<center>\r\n" );
2441 // erste Seite
2442 aButton = String(SdResId(STR_HTMLEXP_FIRSTPAGE));
2443 if(mnButtonThema != -1)
2444 aButton = CreateImage(GetButtonName((nFile == 0 || mnSdPageCount == 1?
2445 BTN_FIRST_0:BTN_FIRST_1)), aButton);
2447 if(nFile != 0 && mnSdPageCount > 1)
2448 aButton = CreateLink( String(RTL_CONSTASCII_USTRINGPARAM("JavaScript:parent.NavigateAbs(0)")), aButton);
2450 aStr += aButton;
2451 aStr.AppendAscii( "\r\n" );
2453 // zur vorherigen Seite
2454 aButton = String(SdResId(STR_PUBLISH_BACK));
2455 if(mnButtonThema != -1)
2456 aButton = CreateImage(GetButtonName((nFile == 0 || mnSdPageCount == 1?
2457 BTN_PREV_0:BTN_PREV_1)), aButton);
2459 if(nFile != 0 && mnSdPageCount > 1)
2460 aButton = CreateLink( String(RTL_CONSTASCII_USTRINGPARAM("JavaScript:parent.NavigateRel(-1)")), aButton);
2462 aStr += aButton;
2463 aStr.AppendAscii( "\r\n" );
2465 // zur naechsten Seite
2466 aButton = String(SdResId(STR_PUBLISH_NEXT));
2467 if(mnButtonThema != -1)
2468 aButton = CreateImage(GetButtonName((nFile ==2 || mnSdPageCount == 1?
2469 BTN_NEXT_0:BTN_NEXT_1)), aButton);
2471 if(nFile != 2 && mnSdPageCount > 1)
2472 aButton = CreateLink(String(RTL_CONSTASCII_USTRINGPARAM("JavaScript:parent.NavigateRel(1)")), aButton);
2474 aStr += aButton;
2475 aStr.AppendAscii( "\r\n" );
2477 // zur letzten Seite
2478 aButton = String(SdResId(STR_HTMLEXP_LASTPAGE));
2479 if(mnButtonThema != -1)
2480 aButton = CreateImage(GetButtonName((nFile ==2 || mnSdPageCount == 1?
2481 BTN_LAST_0:BTN_LAST_1)), aButton);
2483 if(nFile != 2 && mnSdPageCount > 1)
2485 String aLink(RTL_CONSTASCII_USTRINGPARAM("JavaScript:parent.NavigateAbs("));
2486 aLink += String::CreateFromInt32(mnSdPageCount-1);
2487 aLink.AppendAscii( ")" );
2488 aButton = CreateLink( aLink, aButton);
2491 aStr += aButton;
2492 aStr.AppendAscii( "\r\n" );
2494 // Inhalt
2495 if (mbContentsPage)
2497 aButton = String(SdResId(STR_PUBLISH_OUTLINE));
2498 if(mnButtonThema != -1)
2499 aButton = CreateImage(GetButtonName(BTN_INDEX), aButton);
2501 // zur Uebersicht
2502 aStr += CreateLink(maIndex, aButton, String(RTL_CONSTASCII_USTRINGPARAM("_top")));
2503 aStr.AppendAscii( "\r\n" );
2506 // Textmodus
2507 if(mbImpress)
2509 aButton = String(SdResId(STR_HTMLEXP_SETTEXT));
2510 if(mnButtonThema != -1)
2511 aButton = CreateImage(GetButtonName(BTN_TEXT), aButton);
2513 String aText0( RTL_CONSTASCII_USTRINGPARAM("text0"));
2514 aText0 += maHTMLExtension;
2515 aStr += CreateLink( aText0, aButton, String(RTL_CONSTASCII_USTRINGPARAM("_top")));
2516 aStr.AppendAscii( "\r\n" );
2519 // Und fertich...
2520 aStr.AppendAscii( "</center>\r\n" );
2521 aStr.AppendAscii( "</body>\r\n</html>" );
2523 String aFileName( RTL_CONSTASCII_USTRINGPARAM("navbar") );
2524 aFileName += String::CreateFromInt32(nFile);
2526 bOk = WriteHtml( aFileName, true, aStr );
2528 if (mpProgress)
2529 mpProgress->SetState(++mnPagesWritten);
2532 // Jetzt kommt die Navigatonsleiste Outliner zugeklappt...
2533 if(bOk)
2535 String aStr(maHTMLHeader);
2536 aStr += WriteMetaCharset();
2537 aStr.AppendAscii( " <title>" );
2538 aStr += StringToHTMLString(*mpPageNames[0]);
2539 aStr.AppendAscii( "</title>\r\n</head>\r\n" );
2540 aStr += CreateBodyTag();
2542 aButton = String(SdResId(STR_HTMLEXP_OUTLINE));
2543 if(mnButtonThema != -1)
2544 aButton = CreateImage(GetButtonName(BTN_MORE), aButton);
2546 aStr += CreateLink(String(RTL_CONSTASCII_USTRINGPARAM("JavaScript:parent.ExpandOutline()")), aButton);
2547 aStr.AppendAscii( "</body>\r\n</html>" );
2549 String aFileName( RTL_CONSTASCII_USTRINGPARAM("navbar3") );
2551 bOk = WriteHtml( aFileName, true, aStr );
2553 if (mpProgress)
2554 mpProgress->SetState(++mnPagesWritten);
2557 // ... und jetzt Outliner aufgeklappt
2558 if( bOk )
2560 String aStr(maHTMLHeader);
2561 aStr += WriteMetaCharset();
2562 aStr.AppendAscii( " <title>" );
2563 aStr += StringToHTMLString(*mpPageNames[0]);
2564 aStr.AppendAscii( "</title>\r\n</head>\r\n" );
2565 aStr += CreateBodyTag();
2567 aButton = String(SdResId(STR_HTMLEXP_NOOUTLINE));
2568 if(mnButtonThema != -1)
2569 aButton = CreateImage(GetButtonName(BTN_LESS), aButton);
2571 aStr += CreateLink(String(RTL_CONSTASCII_USTRINGPARAM("JavaScript:parent.CollapseOutline()")), aButton);
2572 aStr.AppendAscii( "</body>\r\n</html>" );
2574 String aFileName( RTL_CONSTASCII_USTRINGPARAM("navbar4") );
2575 bOk = WriteHtml( aFileName, true, aStr );
2577 if (mpProgress)
2578 mpProgress->SetState(++mnPagesWritten);
2582 return bOk;
2585 // ====================================================================
2586 // Buttonleiste fuer Standard ausgeben
2587 // ====================================================================
2588 String HtmlExport::CreateNavBar( USHORT nSdPage, bool bIsText ) const
2590 // Navigationsleiste vorbereiten
2591 String aStrNavFirst( SdResId(STR_HTMLEXP_FIRSTPAGE) );
2592 String aStrNavPrev( SdResId(STR_PUBLISH_BACK) );
2593 String aStrNavNext( SdResId(STR_PUBLISH_NEXT) );
2594 String aStrNavLast( SdResId(STR_HTMLEXP_LASTPAGE) );
2595 String aStrNavContent( SdResId(STR_PUBLISH_OUTLINE) );
2596 String aStrNavText;
2597 if( bIsText )
2599 aStrNavText = String( SdResId(STR_HTMLEXP_SETGRAPHIC) );
2601 else
2603 aStrNavText = String( SdResId(STR_HTMLEXP_SETTEXT) );
2606 if(!bIsText && mnButtonThema != -1)
2608 if(nSdPage<1 || mnSdPageCount == 1)
2610 aStrNavFirst = CreateImage(GetButtonName(BTN_FIRST_0), aStrNavFirst);
2611 aStrNavPrev = CreateImage(GetButtonName(BTN_PREV_0), aStrNavPrev);
2613 else
2615 aStrNavFirst = CreateImage(GetButtonName(BTN_FIRST_1), aStrNavFirst);
2616 aStrNavPrev = CreateImage(GetButtonName(BTN_PREV_1), aStrNavPrev);
2619 if(nSdPage == mnSdPageCount-1 || mnSdPageCount == 1)
2621 aStrNavNext = CreateImage(GetButtonName(BTN_NEXT_0), aStrNavNext);
2622 aStrNavLast = CreateImage(GetButtonName(BTN_LAST_0), aStrNavLast);
2624 else
2626 aStrNavNext = CreateImage(GetButtonName(BTN_NEXT_1), aStrNavNext);
2627 aStrNavLast = CreateImage(GetButtonName(BTN_LAST_1), aStrNavLast);
2630 aStrNavContent = CreateImage(GetButtonName(BTN_INDEX), aStrNavContent);
2631 aStrNavText = CreateImage(GetButtonName(BTN_TEXT), aStrNavText);
2634 String aStr( RTL_CONSTASCII_USTRINGPARAM("<center>\r\n")); //<table><tr>\r\n");
2636 // erste Seite
2637 if(nSdPage > 0)
2638 aStr += CreateLink(bIsText?*mpTextFiles[0]:*mpHTMLFiles[0],aStrNavFirst);
2639 else
2640 aStr += aStrNavFirst;
2641 aStr.Append(sal_Unicode(' '));
2643 // to Previous page
2644 if(nSdPage > 0)
2645 aStr += CreateLink( bIsText?*mpTextFiles[nSdPage-1]:
2646 *mpHTMLFiles[nSdPage-1], aStrNavPrev);
2647 else
2648 aStr += aStrNavPrev;
2649 aStr.Append(sal_Unicode(' '));
2651 // to Next page
2652 if(nSdPage < mnSdPageCount-1)
2653 aStr += CreateLink( bIsText?*mpTextFiles[nSdPage+1]:
2654 *mpHTMLFiles[nSdPage+1], aStrNavNext);
2655 else
2656 aStr += aStrNavNext;
2657 aStr.Append(sal_Unicode(' '));
2659 // to Last page
2660 if(nSdPage < mnSdPageCount-1)
2661 aStr += CreateLink( bIsText?*mpTextFiles[mnSdPageCount-1]:
2662 *mpHTMLFiles[mnSdPageCount-1],
2663 aStrNavLast );
2664 else
2665 aStr += aStrNavLast;
2666 aStr.Append(sal_Unicode(' '));
2668 // to Index page
2669 if (mbContentsPage)
2671 aStr += CreateLink(maIndex, aStrNavContent);
2672 aStr.Append(sal_Unicode(' '));
2675 // Text/Graphics
2676 if(mbImpress)
2678 aStr += CreateLink( bIsText?(mbFrames?maFramePage:*mpHTMLFiles[nSdPage]):
2679 *mpTextFiles[nSdPage], aStrNavText);
2683 aStr.AppendAscii( "</center><br>\r\n" );
2685 return aStr;
2688 /** export navigation graphics from button set */
2689 bool HtmlExport::CreateBitmaps()
2691 if(mnButtonThema != -1 && mpButtonSet.get() )
2693 for( int nButton = 0; nButton < NUM_BUTTONS; nButton++ )
2695 if(!mbFrames && (nButton == BTN_MORE || nButton == BTN_LESS))
2696 continue;
2698 if(!mbImpress && (nButton == BTN_TEXT || nButton == BTN_MORE || nButton == BTN_LESS ))
2699 continue;
2701 OUString aFull(maExportPath);
2702 aFull += GetButtonName(nButton);
2703 mpButtonSet->exportButton( mnButtonThema, aFull, GetButtonName(nButton) );
2706 return true;
2709 // =====================================================================
2710 // Erzeugt den <body> Tag, inkl. der eingestellten Farbattribute
2711 // =====================================================================
2712 String HtmlExport::CreateBodyTag() const
2714 String aStr( RTL_CONSTASCII_USTRINGPARAM("<body") );
2716 if( mbUserAttr || mbDocColors )
2718 Color aTextColor( maTextColor );
2719 if( (aTextColor == COL_AUTO) && (!maBackColor.IsDark()) )
2720 aTextColor = COL_BLACK;
2722 aStr.AppendAscii( " text=\"" );
2723 aStr += ColorToHTMLString( aTextColor );
2724 aStr.AppendAscii( "\" bgcolor=\"" );
2725 aStr += ColorToHTMLString( maBackColor );
2726 aStr.AppendAscii( "\" link=\"" );
2727 aStr += ColorToHTMLString( maLinkColor );
2728 aStr.AppendAscii( "\" vlink=\"" );
2729 aStr += ColorToHTMLString( maVLinkColor );
2730 aStr.AppendAscii( "\" alink=\"" );
2731 aStr += ColorToHTMLString( maALinkColor );
2732 aStr.AppendAscii( "\"" );
2735 aStr.AppendAscii( ">\r\n" );
2737 return aStr;
2740 // =====================================================================
2741 // Erzeugt einen Hyperlink
2742 // =====================================================================
2743 String HtmlExport::CreateLink( const String& aLink,
2744 const String& aText,
2745 const String& aTarget ) const
2747 String aStr( RTL_CONSTASCII_USTRINGPARAM("<a href=\""));
2748 aStr += StringToURL(aLink);
2749 if(aTarget.Len())
2751 aStr.AppendAscii( "\" target=\"" );
2752 aStr += aTarget;
2754 aStr.AppendAscii( "\">" );
2755 aStr += aText;
2756 aStr.AppendAscii( "</a>" );
2758 return aStr;
2761 // =====================================================================
2762 // Erzeugt ein Image-tag
2763 // =====================================================================
2764 String HtmlExport::CreateImage( const String& aImage, const String& aAltText,
2765 INT16 nWidth,
2766 INT16 nHeight ) const
2768 String aStr( RTL_CONSTASCII_USTRINGPARAM("<img src=\""));
2769 aStr += StringToURL(aImage);
2770 aStr.AppendAscii( "\" border=0" );
2772 if( aAltText.Len())
2774 aStr.AppendAscii( " alt=\"" );
2775 aStr += aAltText;
2776 aStr.Append(sal_Unicode('"'));
2778 else
2780 // Agerskov: HTML 4.01 has to have an alt attribut even if it is an empty string
2781 aStr.AppendAscii( " alt=\"\"" );
2784 if(nWidth > -1)
2786 aStr.AppendAscii( " width=" );
2787 aStr += String::CreateFromInt32(nWidth);
2790 if(nHeight > -1)
2792 aStr.AppendAscii( " height=" );
2793 aStr += String::CreateFromInt32(nHeight);
2796 aStr.Append(sal_Unicode('>'));
2798 return aStr;
2801 // =====================================================================
2802 // Area fuer Kreis erzeugen; es werden Pixelkoordinaten erwartet
2803 // =====================================================================
2804 String HtmlExport::ColorToHTMLString( Color aColor )
2806 static char hex[] = "0123456789ABCDEF";
2807 String aStr( RTL_CONSTASCII_USTRINGPARAM("#xxxxxx"));
2808 aStr.SetChar(1, hex[(aColor.GetRed() >> 4) & 0xf] );
2809 aStr.SetChar(2, hex[aColor.GetRed() & 0xf] );
2810 aStr.SetChar(3, hex[(aColor.GetGreen() >> 4) & 0xf] );
2811 aStr.SetChar(4, hex[aColor.GetGreen() & 0xf] );
2812 aStr.SetChar(5, hex[(aColor.GetBlue() >> 4) & 0xf] );
2813 aStr.SetChar(6, hex[aColor.GetBlue() & 0xf] );
2815 return aStr;
2818 // =====================================================================
2819 // Area fuer Kreis erzeugen; es werden Pixelkoordinaten erwartet
2820 // =====================================================================
2821 String HtmlExport::CreateHTMLCircleArea( ULONG nRadius,
2822 ULONG nCenterX,
2823 ULONG nCenterY,
2824 const String& rHRef ) const
2826 String aStr( RTL_CONSTASCII_USTRINGPARAM("<area shape=\"circle\" alt=\"\" coords=\"" ));
2828 aStr += String::CreateFromInt32(nCenterX);
2829 aStr.Append(sal_Unicode(','));
2830 aStr += String::CreateFromInt32(nCenterY);
2831 aStr.Append(sal_Unicode(','));
2832 aStr += String::CreateFromInt32(nRadius);
2833 aStr.AppendAscii( "\" href=\"" );
2834 aStr += StringToURL(rHRef);
2835 aStr.AppendAscii( "\">\n" );
2837 return aStr;
2841 // =====================================================================
2842 // Area fuer Polygon erzeugen; es werden Pixelkoordinaten erwartet
2843 // =====================================================================
2844 String HtmlExport::CreateHTMLPolygonArea( const ::basegfx::B2DPolyPolygon& rPolyPolygon,
2845 Size aShift, double fFactor, const String& rHRef ) const
2847 String aStr;
2848 const sal_uInt32 nNoOfPolygons(rPolyPolygon.count());
2850 for ( sal_uInt32 nXPoly = 0L; nXPoly < nNoOfPolygons; nXPoly++ )
2852 const ::basegfx::B2DPolygon& aPolygon = rPolyPolygon.getB2DPolygon(nXPoly);
2853 const sal_uInt32 nNoOfPoints(aPolygon.count());
2855 aStr.AppendAscii( "<area shape=\"polygon\" alt=\"\" coords=\"" );
2857 for ( sal_uInt32 nPoint = 0L; nPoint < nNoOfPoints; nPoint++ )
2859 const ::basegfx::B2DPoint aB2DPoint(aPolygon.getB2DPoint(nPoint));
2860 Point aPnt(FRound(aB2DPoint.getX()), FRound(aB2DPoint.getY()));
2861 // das Koordinaten beziehen sich auf den
2862 // physikalischen Seitenursprung, nicht auf den
2863 // Koordinatenursprung
2864 aPnt.Move(aShift.Width(), aShift.Height());
2866 aPnt.X() = (long)(aPnt.X() * fFactor);
2867 aPnt.Y() = (long)(aPnt.Y() * fFactor);
2868 aStr += String::CreateFromInt32(aPnt.X());
2869 aStr.Append(sal_Unicode(','));
2870 aStr += String::CreateFromInt32(aPnt.Y());
2872 if (nPoint < nNoOfPoints - 1)
2873 aStr.Append( sal_Unicode(',') );
2875 aStr.AppendAscii( "\" href=\"" );
2876 aStr += StringToURL(rHRef);
2877 aStr.AppendAscii( "\">\n" );
2880 return aStr;
2883 // =====================================================================
2884 // Area fuer Rechteck erzeugen; es werden Pixelkoordinaten erwartet
2885 // =====================================================================
2886 String HtmlExport::CreateHTMLRectArea( const Rectangle& rRect,
2887 const String& rHRef ) const
2889 String aStr( RTL_CONSTASCII_USTRINGPARAM("<area shape=\"rect\" alt=\"\" coords=\"") );
2891 aStr += String::CreateFromInt32(rRect.Left());
2892 aStr.Append(sal_Unicode(','));
2893 aStr += String::CreateFromInt32(rRect.Top());
2894 aStr.Append(sal_Unicode(','));
2895 aStr += String::CreateFromInt32(rRect.Right());
2896 aStr.Append(sal_Unicode(','));
2897 aStr += String::CreateFromInt32(rRect.Bottom());
2898 aStr.AppendAscii( "\" href=\"" );
2899 aStr += StringToURL(rHRef);
2900 aStr.AppendAscii( "\">\n" );
2902 return aStr;
2905 // =====================================================================
2906 // StringToHTMLString, konvertiert einen String in
2907 // seine HTML-Repraesentation (Umlaute etc.)
2908 // =====================================================================
2909 String HtmlExport::StringToHTMLString( const String& rString )
2911 SvMemoryStream aMemStm;
2912 HTMLOutFuncs::Out_String( aMemStm, rString, RTL_TEXTENCODING_UTF8 );
2913 aMemStm << (char) 0;
2914 return String( (char*)aMemStm.GetData(), RTL_TEXTENCODING_UTF8 );
2917 // =====================================================================
2918 // Erzeugt die URL einer bestimmten Seite
2919 // =====================================================================
2920 String HtmlExport::CreatePageURL( USHORT nPgNum )
2922 if(mbFrames)
2924 String aUrl( RTL_CONSTASCII_USTRINGPARAM("JavaScript:parent.NavigateAbs("));
2925 aUrl += String::CreateFromInt32(nPgNum);
2926 aUrl.Append(sal_Unicode(')'));
2927 return aUrl;
2929 else
2930 return *mpHTMLFiles[nPgNum];
2933 bool HtmlExport::CopyScript( const String& rPath, const String& rSource, const String& rDest, bool bUnix /* = false */ )
2935 INetURLObject aURL( SvtPathOptions().GetConfigPath() );
2936 String aScript;
2938 aURL.Append( String( RTL_CONSTASCII_USTRINGPARAM("webcast") ) );
2939 aURL.Append( rSource );
2941 meEC.SetContext( STR_HTMLEXP_ERROR_OPEN_FILE, rSource );
2943 ULONG nErr = 0;
2944 SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
2946 if( pIStm )
2948 ByteString aLine;
2950 while( pIStm->ReadLine( aLine ) )
2952 aScript.AppendAscii( aLine.GetBuffer() );
2953 if( bUnix )
2955 aScript.AppendAscii( "\n" );
2957 else
2959 aScript.AppendAscii( "\r\n" );
2963 nErr = pIStm->GetError();
2964 delete pIStm;
2967 if( nErr != 0 )
2969 ErrorHandler::HandleError( nErr );
2970 return (bool) nErr;
2974 aScript.SearchAndReplaceAll( String(RTL_CONSTASCII_USTRINGPARAM("$$1")), getDocumentTitle() );
2976 const String aSaveStr( RESTOHTML( STR_WEBVIEW_SAVE ));
2977 aScript.SearchAndReplaceAll( String(RTL_CONSTASCII_USTRINGPARAM("$$2")), aSaveStr );
2979 aScript.SearchAndReplaceAll( String(RTL_CONSTASCII_USTRINGPARAM("$$3")), maCGIPath );
2981 aScript.SearchAndReplaceAll( String(RTL_CONSTASCII_USTRINGPARAM("$$4")), String::CreateFromInt32(mnWidthPixel) );
2982 aScript.SearchAndReplaceAll( String(RTL_CONSTASCII_USTRINGPARAM("$$5")), String::CreateFromInt32(mnHeightPixel) );
2985 String aDest( rPath );
2986 aDest += rDest;
2988 meEC.SetContext( STR_HTMLEXP_ERROR_CREATE_FILE, rDest );
2989 // write script file
2991 EasyFile aFile;
2992 SvStream* pStr;
2993 nErr = aFile.createStream(aDest, pStr);
2994 if(nErr == 0)
2996 ByteString aStr( aScript, RTL_TEXTENCODING_UTF8 );
2997 *pStr << aStr.GetBuffer();
2999 nErr = aFile.close();
3003 if (mpProgress)
3004 mpProgress->SetState(++mnPagesWritten);
3006 if( nErr != 0 )
3007 ErrorHandler::HandleError( nErr );
3009 return nErr == 0;
3012 static const char * ASP_Scripts[] = { "common.inc", "webcast.asp", "show.asp", "savepic.asp", "poll.asp", "editpic.asp" };
3014 /** erzeugt und speichert die f�r WebShow ben�tigte ASP Scripte */
3015 bool HtmlExport::CreateASPScripts()
3017 for( USHORT n = 0; n < (sizeof( ASP_Scripts ) / sizeof(char *)); n++ )
3019 String aScript;
3021 aScript.AssignAscii( ASP_Scripts[n] );
3022 if(!CopyScript(maExportPath, aScript, aScript))
3023 return false;
3026 if(!CopyScript(maExportPath, String(RTL_CONSTASCII_USTRINGPARAM("edit.asp")), maIndex ))
3027 return false;
3029 return true;
3033 static const char *PERL_Scripts[] = { "webcast.pl", "common.pl", "editpic.pl", "poll.pl", "savepic.pl", "show.pl" };
3035 /** erzeugt und speichert die f�r WebShow ben�tigte PERL Scripte */
3036 bool HtmlExport::CreatePERLScripts()
3038 for( USHORT n = 0; n < (sizeof( PERL_Scripts ) / sizeof(char *)); n++ )
3040 String aScript;
3041 aScript.AssignAscii( PERL_Scripts[n] );
3042 if(!CopyScript(maExportPath, aScript, aScript, true))
3043 return false;
3046 if(!CopyScript(maExportPath, String( RTL_CONSTASCII_USTRINGPARAM("edit.pl")), maIndex, true ))
3047 return false;
3049 if(!CopyScript(maExportPath, String( RTL_CONSTASCII_USTRINGPARAM("index.pl")), maIndexUrl, true ))
3050 return false;
3052 return true;
3055 /** Erzeugt eine Liste mit den Namen der gespeicherten Images */
3056 bool HtmlExport::CreateImageFileList()
3058 String aStr;
3059 for( USHORT nSdPage = 0; nSdPage < mnSdPageCount; nSdPage++)
3061 aStr += String::CreateFromInt32( nSdPage + 1 );
3062 aStr.Append(sal_Unicode(';'));
3063 aStr += maURLPath;
3064 aStr += *mpImageFiles[nSdPage];
3065 aStr.AppendAscii( "\r\n" );
3068 String aFileName( RTL_CONSTASCII_USTRINGPARAM("picture.txt") );
3069 bool bOk = WriteHtml( aFileName, false, aStr );
3071 if (mpProgress)
3072 mpProgress->SetState(++mnPagesWritten);
3074 return bOk;
3077 /** Erzeugt das File mit der aktuellen Seitennumer */
3078 bool HtmlExport::CreateImageNumberFile()
3080 String aFull( maExportPath );
3081 String aFileName( RTL_CONSTASCII_USTRINGPARAM("currpic.txt") );
3082 aFull += aFileName;
3084 meEC.SetContext( STR_HTMLEXP_ERROR_CREATE_FILE, aFileName );
3085 EasyFile aFile;
3086 SvStream* pStr;
3087 ULONG nErr = aFile.createStream(aFull, pStr);
3088 if(nErr == 0)
3090 *pStr << (const char *)"1";
3091 nErr = aFile.close();
3094 if (mpProgress)
3095 mpProgress->SetState(++mnPagesWritten);
3097 if( nErr != 0 )
3098 ErrorHandler::HandleError( nErr );
3100 return nErr == 0;
3103 // =====================================================================
3105 String HtmlExport::InsertSound( const String& rSoundFile )
3107 if( rSoundFile.Len() == 0 )
3108 return rSoundFile;
3110 String aStr( RTL_CONSTASCII_USTRINGPARAM("<embed src=\"") );
3111 INetURLObject aURL( rSoundFile );
3113 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
3115 aStr += String(aURL.getName());
3116 aStr.AppendAscii( "\" hidden=\"true\" autostart=\"true\">" );
3118 CopyFile( rSoundFile, maExportPath );
3120 return aStr;
3123 // =====================================================================
3125 bool HtmlExport::CopyFile( const String& rSourceFile, const String& rDestPath )
3127 DirEntry aSourceEntry( rSourceFile );
3128 DirEntry aDestEntry( rDestPath );
3130 meEC.SetContext( STR_HTMLEXP_ERROR_COPY_FILE, aSourceEntry.GetName(), rDestPath );
3131 FSysError nError = aSourceEntry.CopyTo( aDestEntry, FSYS_ACTION_COPYFILE );
3133 if( nError != FSYS_ERR_OK )
3135 ErrorHandler::HandleError(nError);
3136 return false;
3138 else
3140 return true;
3144 // =====================================================================
3146 bool HtmlExport::checkFileExists( Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xFileAccess, String const & aFileName )
3150 OUString url( maExportPath );
3151 url += aFileName;
3152 return xFileAccess->exists( url );
3154 catch( com::sun::star::uno::Exception& e )
3156 (void)e;
3157 DBG_ERROR((OString("sd::HtmlExport::checkFileExists(), exception caught: ") +
3158 rtl::OUStringToOString( comphelper::anyToString( cppu::getCaughtException() ), RTL_TEXTENCODING_UTF8 )).getStr() );
3161 return false;
3164 // ---------------------------------------------------------------------
3166 bool HtmlExport::checkForExistingFiles()
3168 bool bFound = false;
3172 Reference< XMultiServiceFactory > xMsf( ::comphelper::getProcessServiceFactory() );
3173 Reference< ::com::sun::star::ucb::XSimpleFileAccess > xFA( xMsf->createInstance(
3174 OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess"))), UNO_QUERY_THROW );
3176 sal_uInt16 nSdPage;
3177 for( nSdPage = 0; !bFound && (nSdPage < mnSdPageCount); nSdPage++)
3179 if( (mpImageFiles[nSdPage] && checkFileExists( xFA, *mpImageFiles[nSdPage] )) ||
3180 (mpHTMLFiles[nSdPage] && checkFileExists( xFA, *mpHTMLFiles[nSdPage] )) ||
3181 (mpPageNames[nSdPage] && checkFileExists( xFA, *mpPageNames[nSdPage] )) ||
3182 (mpTextFiles[nSdPage] && checkFileExists( xFA, *mpTextFiles[nSdPage] )) )
3184 bFound = true;
3188 if( !bFound && mbDownload )
3189 bFound = checkFileExists( xFA, maDocFileName );
3191 if( !bFound && mbFrames )
3192 bFound = checkFileExists( xFA, maFramePage );
3194 if( bFound )
3196 ResMgr *pResMgr = CREATERESMGR( dbw );
3197 if( pResMgr )
3199 ResId aResId( 4077, *pResMgr );
3200 String aMsg( aResId );
3202 OUString aSystemPath;
3203 osl::FileBase::getSystemPathFromFileURL( maExportPath, aSystemPath );
3204 aMsg.SearchAndReplaceAscii( "%FILENAME", aSystemPath );
3205 WarningBox aWarning( 0, WB_YES_NO | WB_DEF_YES, aMsg );
3206 aWarning.SetImage( WarningBox::GetStandardImage() );
3207 bFound = ( RET_NO == aWarning.Execute() );
3209 delete pResMgr;
3211 else
3213 bFound = false;
3217 catch( Exception& e )
3219 (void)e;
3220 DBG_ERROR((OString("sd::HtmlExport::checkForExistingFiles(), exception caught: ") +
3221 rtl::OUStringToOString( comphelper::anyToString( cppu::getCaughtException() ), RTL_TEXTENCODING_UTF8 )).getStr() );
3222 bFound = false;
3225 return bFound;
3228 // ---------------------------------------------------------------------
3230 String HtmlExport::StringToURL( const String& rURL )
3232 return rURL;
3234 return StringToHTMLString(rURL);
3235 OUString aURL( StringToHTMLString(rURL) );
3237 aURL = Uri::encode( aURL, rtl_UriCharClassUric, rtl_UriEncodeCheckEscapes, RTL_TEXTENCODING_UTF8);
3238 return String( aURL );
3242 String HtmlExport::GetButtonName( int nButton ) const
3244 String aName;
3245 aName.AssignAscii( pButtonNames[nButton] );
3246 return aName;
3249 // =====================================================================
3250 EasyFile::EasyFile()
3252 pMedium = NULL;
3253 pOStm = NULL;
3254 bOpen = false;
3257 // =====================================================================
3258 EasyFile::~EasyFile()
3260 if( bOpen )
3261 close();
3264 // =====================================================================
3265 ULONG EasyFile::createStream( const String& rUrl, SvStream* &rpStr )
3267 ULONG nErr = 0;
3269 if(bOpen)
3270 nErr = close();
3272 String aFileName;
3274 if( nErr == 0 )
3275 nErr = createFileName( rUrl, aFileName );
3277 if( nErr == 0 )
3279 pOStm = ::utl::UcbStreamHelper::CreateStream( aFileName, STREAM_WRITE | STREAM_TRUNC );
3280 if( pOStm )
3282 bOpen = true;
3283 nErr = pOStm->GetError();
3285 else
3287 nErr = ERRCODE_SFX_CANTCREATECONTENT;
3291 if( nErr != 0 )
3293 bOpen = false;
3294 delete pMedium;
3295 delete pOStm;
3296 pOStm = NULL;
3299 rpStr = pOStm;
3301 return nErr;
3304 // =====================================================================
3305 ULONG EasyFile::createFileName( const String& rURL, String& rFileName )
3307 ULONG nErr = 0;
3309 if( bOpen )
3310 nErr = close();
3312 if( nErr == 0 )
3314 INetURLObject aURL( rURL );
3316 if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
3318 String aURLStr;
3319 ::utl::LocalFileHelper::ConvertPhysicalNameToURL( rURL, aURLStr );
3320 aURL = INetURLObject( aURLStr );
3322 DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
3323 rFileName = aURL.GetMainURL( INetURLObject::NO_DECODE );
3326 return nErr;
3329 // =====================================================================
3330 ULONG EasyFile::close()
3332 ULONG nErr = 0;
3334 delete pOStm;
3335 pOStm = NULL;
3337 bOpen = false;
3339 if( pMedium )
3341 // uebertragen
3342 pMedium->Close();
3343 pMedium->Commit();
3345 nErr = pMedium->GetError();
3347 delete pMedium;
3348 pMedium = NULL;
3351 return nErr;
3354 // =====================================================================
3355 // This class helps reporting errors during file i/o
3356 // =====================================================================
3358 HtmlErrorContext::HtmlErrorContext(Window *_pWin)
3359 : ErrorContext(_pWin)
3361 mnResId = 0;
3364 // =====================================================================
3366 BOOL HtmlErrorContext::GetString( ULONG, String& rCtxStr )
3368 DBG_ASSERT( mnResId != 0, "No error context set" );
3369 if( mnResId == 0 )
3370 return false;
3372 rCtxStr = String( SdResId( mnResId ) );
3374 rCtxStr.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("$(URL1)")), maURL1 );
3375 rCtxStr.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM("$(URL2)")), maURL2 );
3377 return true;
3380 // =====================================================================
3382 void HtmlErrorContext::SetContext( USHORT nResId )
3384 mnResId = nResId;
3385 maURL1.Erase();
3386 maURL2.Erase();
3389 // =====================================================================
3391 void HtmlErrorContext::SetContext( USHORT nResId, const String& rURL )
3393 mnResId = nResId;
3394 maURL1 = rURL;
3395 maURL2.Erase();
3398 // =====================================================================
3400 void HtmlErrorContext::SetContext( USHORT nResId, const String& rURL1, const String& rURL2 )
3402 mnResId = nResId;
3403 maURL1 = rURL1;
3404 maURL2 = rURL2;
3407 // =====================================================================