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