Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef INCLUDED_SW_SOURCE_FILTER_HTML_SWHTML_HXX
20 : #define INCLUDED_SW_SOURCE_FILTER_HTML_SWHTML_HXX
21 :
22 : #include <config_features.h>
23 :
24 : #include <sfx2/sfxhtml.hxx>
25 : #include <svl/macitem.hxx>
26 : #include <editeng/svxenum.hxx>
27 : #include <fmtornt.hxx>
28 : #include <com/sun/star/drawing/XShape.hpp>
29 : #include <com/sun/star/form/XFormComponent.hpp>
30 :
31 : #include "calbck.hxx"
32 : #include "htmlvsh.hxx"
33 :
34 : class SfxMedium;
35 : class SfxViewFrame;
36 : class SdrObject;
37 : class SvxMacroTableDtor;
38 : class SwDoc;
39 : class SwPaM;
40 : class SwViewShell;
41 : class SwStartNode;
42 : class SwFmtColl;
43 : class SwField;
44 : class SwHTMLForm_Impl;
45 : class SwApplet_Impl;
46 : struct SwHTMLFootEndNote_Impl;
47 : class HTMLTableCnts;
48 : struct SwPendingStack;
49 : class SvxCSS1PropertyInfo;
50 :
51 : #define HTML_PARSPACE (MM50)
52 : #define HTML_CJK_PARSPACE (MM50/2)
53 : #define HTML_CTL_PARSPACE (MM50/2)
54 :
55 : #define HTML_DFLT_IMG_WIDTH (MM50*4)
56 : #define HTML_DFLT_IMG_HEIGHT (MM50*2)
57 :
58 : // ein par Sachen, die man oefter mal braucht
59 : extern HTMLOptionEnum aHTMLPAlignTable[];
60 : extern HTMLOptionEnum aHTMLImgHAlignTable[];
61 : extern HTMLOptionEnum aHTMLImgVAlignTable[];
62 :
63 : // der Attribut Stack:
64 :
65 : class _HTMLAttr;
66 : typedef std::deque<_HTMLAttr *> _HTMLAttrs;
67 :
68 : class _HTMLAttr
69 : {
70 : friend class SwHTMLParser;
71 : friend class _CellSaveStruct;
72 :
73 : SwNodeIndex nSttPara, nEndPara;
74 : sal_Int32 nSttCntnt, nEndCntnt;
75 : bool bInsAtStart : 1;
76 : bool bLikePara : 1; // Attribut ueber dem gesamten Absatz setzen
77 : bool bValid : 1; // ist das Attribut gueltig?
78 :
79 : SfxPoolItem* pItem;
80 : sal_uInt16 nCount; // Anzahl noch zu schliessender Attrs mit einem Wert
81 : _HTMLAttr *pNext; // noch zu schliessene Attrs mit unterschiedl. Werten
82 : _HTMLAttr *pPrev; // bereits geschlossene aber noch nicht gesetze Attrs
83 : _HTMLAttr **ppHead; // der Listenkopf
84 :
85 : _HTMLAttr( const SwPosition& rPos, const SfxPoolItem& rItem,
86 : _HTMLAttr **pHd=0 );
87 :
88 : _HTMLAttr( const _HTMLAttr &rAttr, const SwNodeIndex &rEndPara,
89 : sal_Int32 nEndCnt, _HTMLAttr **pHd );
90 :
91 : public:
92 :
93 : ~_HTMLAttr();
94 :
95 : _HTMLAttr *Clone( const SwNodeIndex& rEndPara, sal_Int32 nEndCnt ) const;
96 : void Reset( const SwNodeIndex& rSttPara, sal_Int32 nSttCnt,
97 : _HTMLAttr **pHd );
98 : inline void SetStart( const SwPosition& rPos );
99 :
100 769 : sal_uInt32 GetSttParaIdx() const { return nSttPara.GetIndex(); }
101 259 : sal_uInt32 GetEndParaIdx() const { return nEndPara.GetIndex(); }
102 :
103 2375 : const SwNodeIndex& GetSttPara() const { return nSttPara; }
104 251 : const SwNodeIndex& GetEndPara() const { return nEndPara; }
105 :
106 1682 : sal_Int32 GetSttCnt() const { return nSttCntnt; }
107 12 : sal_Int32 GetEndCnt() const { return nEndCntnt; }
108 :
109 262 : sal_Bool IsLikePara() const { return bLikePara; }
110 1 : void SetLikePara( sal_Bool bPara=sal_True ) { bLikePara = bPara; }
111 :
112 2013 : SfxPoolItem& GetItem() { return *pItem; }
113 275 : const SfxPoolItem& GetItem() const { return *pItem; }
114 :
115 1805 : _HTMLAttr *GetNext() const { return pNext; }
116 2 : void InsertNext( _HTMLAttr *pNxt ) { pNext = pNxt; }
117 :
118 1055 : _HTMLAttr *GetPrev() const { return pPrev; }
119 : void InsertPrev( _HTMLAttr *pPrv );
120 15 : void ClearPrev() { pPrev = 0; }
121 :
122 0 : void SetHead( _HTMLAttr **ppHd ) { ppHead = ppHd; }
123 :
124 : // Beim Setzen von Attributen aus Vorlagen kann es passieren,
125 : // dass Attribute doch nicht mehr gesetzt werden sollen. Die zu loeschen
126 : // waere sehr aufwendig, da man nicht so genau weiss, wo sie eingekettet
127 : // sind. Sie werden deshalb einfach invalidiert und erst beim naechsten
128 : // _SetAttr() geloescht.
129 0 : void Invalidate() { bValid = false; }
130 : sal_Bool IsValid() const { return bValid; }
131 : };
132 :
133 : // Tabelle der Attribute: Hier ist die Reihenfolge wichtig: Die Attribute
134 : // vorne in der Tabelle werden in EndAllAttrs auch zuerst gesetzt.
135 : struct _HTMLAttrTable
136 : {
137 : _HTMLAttr
138 : *pKeep, // ::com::sun::star::frame::Frame-Attribure
139 : *pBox,
140 : *pBrush,
141 : *pBreak,
142 : *pPageDesc,
143 :
144 : *pLRSpace, // Absatz-Attribute
145 : *pULSpace,
146 : *pLineSpacing,
147 : *pAdjust,
148 : *pDropCap,
149 : *pSplit,
150 : *pWidows,
151 : *pOrphans,
152 : *pDirection,
153 :
154 : *pCharFmts, // Text-Attribute
155 : *pINetFmt,
156 :
157 : *pBold, // Zeichen-Attribute
158 : *pBoldCJK,
159 : *pBoldCTL,
160 : *pItalic,
161 : *pItalicCJK,
162 : *pItalicCTL,
163 : *pStrike,
164 : *pUnderline,
165 : *pBlink,
166 : *pFont,
167 : *pFontCJK,
168 : *pFontCTL,
169 : *pFontHeight,
170 : *pFontHeightCJK,
171 : *pFontHeightCTL,
172 : *pFontColor,
173 : *pEscapement,
174 : *pCaseMap,
175 : *pKerning, // (nur fuer SPACER)
176 : *pCharBrush, // Zeichen-Hintergrund
177 : *pLanguage,
178 : *pLanguageCJK,
179 : *pLanguageCTL,
180 : *pCharBox
181 : ;
182 : };
183 :
184 : class _HTMLAttrContext_SaveDoc;
185 :
186 : enum SwHTMLAppendMode {
187 : AM_NORMAL, // keine Absatz-Abstand-Behandlung
188 : AM_NOSPACE, // Abstand hart auf 0cm setzen
189 : AM_SPACE, // Abstand hart auf 0.5cm setzen
190 : AM_SOFTNOSPACE, // Abstand nicht setzen aber 0cm merken
191 : AM_NONE // gar kein Append
192 : };
193 :
194 : class _HTMLAttrContext
195 : {
196 : _HTMLAttrs aAttrs; // die in dem Kontext gestarteten Attribute
197 :
198 : OUString aClass; // die Klasse des Kontexts
199 :
200 : _HTMLAttrContext_SaveDoc *pSaveDocContext;
201 : SfxItemSet *pFrmItemSet;
202 :
203 : sal_uInt16 nToken; // das Token, zu dem der Kontext gehoehrt
204 :
205 : sal_uInt16 nTxtFmtColl; // eine in dem Kontext begonnene Vorlage oder 0
206 :
207 : sal_uInt16 nLeftMargin; // ein veraenderter linker Rand
208 : sal_uInt16 nRightMargin; // ein veraenderter rechter Rand
209 : sal_uInt16 nFirstLineIndent; // ein veraenderter Erstzeilen-Einzug
210 :
211 : sal_uInt16 nUpperSpace;
212 : sal_uInt16 nLowerSpace;
213 :
214 : SwHTMLAppendMode eAppend;
215 :
216 : bool bLRSpaceChanged : 1;// linker/rechtr Rand, Einzug veraendert?
217 : bool bULSpaceChanged : 1;// oberer/unterer Rand veraendert?
218 : bool bDfltTxtFmtColl : 1;// nTxtFmtColl ist nur ein default
219 : bool bSpansSection : 1; // Der Kontext spannt eine SwSection auf
220 : bool bPopStack : 1; // Oberhalb liegende Stack-Elemente entf.
221 : bool bFinishPREListingXMP : 1;
222 : bool bRestartPRE : 1;
223 : bool bRestartXMP : 1;
224 : bool bRestartListing : 1;
225 :
226 : public:
227 : void ClearSaveDocContext();
228 :
229 314 : _HTMLAttrContext( sal_uInt16 nTokn, sal_uInt16 nPoolId, const OUString& rClass,
230 : sal_Bool bDfltColl=sal_False ) :
231 : aClass( rClass ),
232 : pSaveDocContext( 0 ),
233 : pFrmItemSet( 0 ),
234 : nToken( nTokn ),
235 : nTxtFmtColl( nPoolId ),
236 : nLeftMargin( 0 ),
237 : nRightMargin( 0 ),
238 : nFirstLineIndent( 0 ),
239 : nUpperSpace( 0 ),
240 : nLowerSpace( 0 ),
241 : eAppend( AM_NONE ),
242 : bLRSpaceChanged( false ),
243 : bULSpaceChanged( false ),
244 : bDfltTxtFmtColl( bDfltColl ),
245 : bSpansSection( false ),
246 : bPopStack( false ),
247 : bFinishPREListingXMP( false ),
248 : bRestartPRE( false ),
249 : bRestartXMP( false ),
250 314 : bRestartListing( false )
251 314 : {}
252 :
253 250 : _HTMLAttrContext( sal_uInt16 nTokn ) :
254 : pSaveDocContext( 0 ),
255 : pFrmItemSet( 0 ),
256 : nToken( nTokn ),
257 : nTxtFmtColl( 0 ),
258 : nLeftMargin( 0 ),
259 : nRightMargin( 0 ),
260 : nFirstLineIndent( 0 ),
261 : nUpperSpace( 0 ),
262 : nLowerSpace( 0 ),
263 : eAppend( AM_NONE ),
264 : bLRSpaceChanged( false ),
265 : bULSpaceChanged( false ),
266 : bDfltTxtFmtColl( false ),
267 : bSpansSection( false ),
268 : bPopStack( false ),
269 : bFinishPREListingXMP( false ),
270 : bRestartPRE( false ),
271 : bRestartXMP( false ),
272 250 : bRestartListing( false )
273 250 : {}
274 :
275 564 : ~_HTMLAttrContext() { ClearSaveDocContext(); delete pFrmItemSet; }
276 :
277 313 : sal_uInt16 GetToken() const { return nToken; }
278 :
279 856 : sal_uInt16 GetTxtFmtColl() const { return bDfltTxtFmtColl ? 0 : nTxtFmtColl; }
280 957 : sal_uInt16 GetDfltTxtFmtColl() const { return bDfltTxtFmtColl ? nTxtFmtColl : 0; }
281 :
282 317 : const OUString& GetClass() const { return aClass; }
283 :
284 : inline void SetMargins( sal_uInt16 nLeft, sal_uInt16 nRight, short nIndent );
285 :
286 802 : inline sal_Bool IsLRSpaceChanged() const { return bLRSpaceChanged; }
287 : inline void GetMargins( sal_uInt16& nLeft, sal_uInt16& nRight,
288 : short &nIndent ) const;
289 :
290 : inline void SetULSpace( sal_uInt16 nUpper, sal_uInt16 nLower );
291 209 : inline sal_Bool IsULSpaceChanged() const { return bULSpaceChanged; }
292 : inline void GetULSpace( sal_uInt16& rUpper, sal_uInt16& rLower ) const;
293 :
294 564 : sal_Bool HasAttrs() const { return !aAttrs.empty(); }
295 : const _HTMLAttrs& GetAttrs() const { return aAttrs; }
296 1317 : _HTMLAttrs& GetAttrs() { return aAttrs; }
297 :
298 9 : void SetSpansSection( sal_Bool bSet ) { bSpansSection = bSet; }
299 564 : sal_Bool GetSpansSection() const { return bSpansSection; }
300 :
301 1 : void SetPopStack( sal_Bool bSet ) { bPopStack = bSet; }
302 564 : sal_Bool GetPopStack() const { return bPopStack; }
303 :
304 564 : sal_Bool HasSaveDocContext() const { return pSaveDocContext!=0; }
305 : _HTMLAttrContext_SaveDoc *GetSaveDocContext( sal_Bool bCreate=sal_False );
306 :
307 1 : const SfxItemSet *GetFrmItemSet() const { return pFrmItemSet; }
308 : SfxItemSet *GetFrmItemSet( SwDoc *pCreateDoc );
309 :
310 260 : void SetFinishPREListingXMP( sal_Bool bSet ) { bFinishPREListingXMP = bSet; }
311 564 : sal_Bool IsFinishPREListingXMP() const { return bFinishPREListingXMP; }
312 :
313 0 : void SetRestartPRE( sal_Bool bSet ) { bRestartPRE = bSet; }
314 564 : sal_Bool IsRestartPRE() const { return bRestartPRE; }
315 :
316 0 : void SetRestartXMP( sal_Bool bSet ) { bRestartXMP = bSet; }
317 564 : sal_Bool IsRestartXMP() const { return bRestartXMP; }
318 :
319 0 : void SetRestartListing( sal_Bool bSet ) { bRestartListing = bSet; }
320 564 : sal_Bool IsRestartListing() const { return bRestartListing; }
321 :
322 5 : void SetAppendMode( SwHTMLAppendMode eMode=AM_NORMAL ) { eAppend = eMode; }
323 566 : SwHTMLAppendMode GetAppendMode() const { return eAppend; }
324 : };
325 :
326 : typedef std::vector<_HTMLAttrContext *> _HTMLAttrContexts;
327 :
328 : class HTMLTable;
329 : class SwCSS1Parser;
330 : class SwHTMLNumRuleInfo;
331 :
332 : typedef boost::ptr_vector<ImageMap> ImageMaps;
333 : typedef std::vector<SwFrmFmt *> SwHTMLFrmFmts;
334 :
335 : #define HTML_CNTXT_PROTECT_STACK 0x0001
336 : #define HTML_CNTXT_STRIP_PARA 0x0002
337 : #define HTML_CNTXT_KEEP_NUMRULE 0x0004
338 : #define HTML_CNTXT_HEADER_DIST 0x0008
339 : #define HTML_CNTXT_FOOTER_DIST 0x0010
340 : #define HTML_CNTXT_KEEP_ATTRS 0x0020
341 :
342 : #define CONTEXT_FLAGS_ABSPOS \
343 : (HTML_CNTXT_PROTECT_STACK | \
344 : HTML_CNTXT_STRIP_PARA)
345 :
346 : #define HTML_FF_BOX 0x0001
347 : #define HTML_FF_BACKGROUND 0x0002
348 : #define HTML_FF_PADDING 0x0004
349 : #define HTML_FF_DIRECTION 0x0008
350 :
351 : class SwHTMLParser : public SfxHTMLParser, public SwClient
352 : {
353 : friend class _SectionSaveStruct;
354 : friend class _CellSaveStruct;
355 : friend class _CaptionSaveStruct;
356 :
357 : OUString aPathToFile;
358 : OUString sBaseURL;
359 : OUString sSaveBaseURL;
360 : OUString aBasicLib;
361 : OUString aBasicModule;
362 : OUString aScriptSource; // Inhalt des aktuellen Script-Blocks
363 : OUString aScriptType; // Type des gelesenen Scripts (StarBasic/VB/JAVA)
364 : OUString aScriptURL; // URL eines Scripts
365 : OUString aStyleSource; // Inhalt des aktuellen Style-Sheets
366 : OUString aContents; // Text des akteullen Marquee, Feldes etc.
367 : OUString sTitle;
368 : OUString aUnknownToken; // ein gestartetes unbekanntes Token
369 : OUString aBulletGrfs[MAXLEVEL];
370 : OUString sJmpMark;
371 :
372 : std::vector<sal_uInt16> aBaseFontStack; // Stack fuer <BASEFONT>
373 : // Bit 0-2: Fontgroesse (1-7)
374 : std::vector<sal_uInt16> aFontStack; // Stack fuer <FONT>, <BIG>, <SMALL>
375 : // Bit 0-2: Fontgroesse (1-7)
376 : // Bit 15: Fontfarbe wurde gesetzt
377 :
378 : _HTMLAttrs aSetAttrTab;// "geschlossene", noch nicht gesetzte Attr.
379 : _HTMLAttrs aParaAttrs; // vorlauefige Absatz-Attribute
380 : _HTMLAttrTable aAttrTab; // "offene" Attribute
381 : _HTMLAttrContexts aContexts;// der aktuelle Attribut/Token-Kontext
382 : SwHTMLFrmFmts aMoveFlyFrms;// Fly-Frames, the anchor is moved
383 : std::deque<sal_Int32> aMoveFlyCnts;// and the Content-Positions
384 :
385 : SwApplet_Impl *pAppletImpl; // das aktuelle Applet
386 :
387 : SwCSS1Parser *pCSS1Parser; // der Style-Sheet-Parser
388 : SwHTMLNumRuleInfo *pNumRuleInfo;
389 : SwPendingStack *pPendStack;
390 :
391 : SwDoc *pDoc;
392 : SwPaM *pPam; // SwPosition duerfte doch reichen, oder ??
393 : SwViewShell *pActionViewShell; // SwViewShell, an der das StartAction
394 : // gerufen wurde.
395 : SwNodeIndex *pSttNdIdx;
396 :
397 : HTMLTable *pTable; // die aktuelle "auesserste" Tabelle
398 : SwHTMLForm_Impl *pFormImpl;// die aktuelle Form
399 : SdrObject *pMarquee; // aktuelles Marquee
400 : SwField *pField; // aktuelles Feld
401 : ImageMap *pImageMap; // aktuelle Image-Map
402 : ImageMaps *pImageMaps;// alle gelesenen Image-Maps
403 : SwHTMLFootEndNote_Impl *pFootEndNoteImpl;
404 :
405 : Size aHTMLPageSize; // die Seitengroesse der HTML-Vorlage
406 :
407 : sal_uInt32 aFontHeights[7]; // die Font-Hoehen 1-7
408 : sal_uInt32 nScriptStartLineNr; // Zeilennummer eines Script-Blocks
409 : sal_uLong nEventId;
410 :
411 : sal_uInt16 nBaseFontStMin;
412 : sal_uInt16 nFontStMin;
413 : sal_uInt16 nDefListDeep;
414 : sal_uInt16 nFontStHeadStart; // Elemente im Font-Stack bei <Hn>
415 : sal_uInt16 nSBModuleCnt; // Zaehler fuer Basic-Module
416 : sal_uInt16 nMissingImgMaps; // Wie viele Image-Maps fehlen noch?
417 : size_t nParaCnt;
418 : sal_uInt16 nContextStMin; // Untergrenze fuer PopContext
419 : sal_uInt16 nContextStAttrMin; // Untergrenze fuer Attributierung
420 : sal_uInt16 nSelectEntryCnt; // Anzahl der Eintraege der akt. Listbox
421 : sal_uInt16 nOpenParaToken; // ein geoeffnetes Absatz-Element
422 :
423 : enum JumpToMarks { JUMPTO_NONE, JUMPTO_MARK, JUMPTO_TABLE, JUMPTO_FRAME,
424 : JUMPTO_REGION, JUMPTO_GRAPHIC } eJumpTo;
425 :
426 : #ifdef DBG_UTIL
427 : sal_uInt16 m_nContinue; // depth of Continue calls
428 : #endif
429 :
430 : SvxAdjust eParaAdjust; // Ausrichtung des aktuellen Absatz
431 : HTMLScriptLanguage eScriptLang; // die aktuelle Script-Language
432 :
433 : bool bOldIsHTMLMode : 1; // War's mal ein HTML-Dokument?
434 :
435 : bool bDocInitalized : 1; // Dokument bzw. Shell wurden initialisiert
436 : // Flag um doppeltes init durch Rekursion
437 : // zu verhindern.
438 : bool bViewCreated : 1; // die View wurde schon erzeugt (asynchron)
439 : bool bSetCrsr : 1; // Crsr wieder auf den Anfang setzen
440 : bool bSetModEnabled : 1;
441 :
442 : bool bInFloatingFrame : 1; // Wir sind in einen Floating ::com::sun::star::frame::Frame
443 : bool bInField : 1;
444 : bool bKeepUnknown : 1; // unbekannte/nicht unterstuetze Tokens beh.
445 : // 8
446 : bool bCallNextToken : 1; // In Tabellen: NextToken in jedem Fall rufen
447 : bool bIgnoreRawData : 1; // Inhalt eines Scripts/Styles ignorieren.
448 : bool bLBEntrySelected : 1; // Ist der aktuelle Listbox-Eintrag selekt.
449 : bool bTAIgnoreNewPara : 1; // naechstes LF in TextArea ignorieren?
450 : bool bFixMarqueeWidth : 1; // Groesse einer Laufschrift anpassen?
451 : bool bFixMarqueeHeight : 1;
452 :
453 : bool bUpperSpace : 1; // obererer Absatz-Abstand wird benoetigt
454 : bool bNoParSpace : 1;
455 : // 16
456 :
457 : bool bAnyStarBasic : 1; // gibt es ueberhaupt ein StarBasic-Modul
458 : bool bInNoEmbed : 1; // Wir sind in einem NOEMBED-Bereich
459 :
460 : bool bInTitle : 1; // Wir sind im Titel
461 :
462 : bool bChkJumpMark : 1; // springe ggfs. zu einem vorgegebenem Mark
463 : bool bUpdateDocStat : 1;
464 : bool bFixSelectWidth : 1; // Breite eines Selects neu setzen?
465 : bool bFixSelectHeight : 1; // Breite eines Selects neu setzen?
466 : bool bTextArea : 1;
467 : // 24
468 : bool bSelect : 1;
469 : bool bInFootEndNoteAnchor : 1;
470 : bool bInFootEndNoteSymbol : 1;
471 : bool bIgnoreHTMLComments : 1;
472 : bool bRemoveHidden : 1; // the filter implementation might set the hidden flag
473 :
474 : /// the names corresponding to the DOCINFO field subtypes INFO[1-4]
475 : OUString m_InfoNames[4];
476 :
477 : SfxViewFrame* pTempViewFrame;
478 :
479 : void DeleteFormImpl();
480 :
481 : void DocumentDetected();
482 : void Show();
483 : void ShowStatline();
484 : SwViewShell *CallStartAction( SwViewShell *pVSh = 0, sal_Bool bChkPtr = sal_True );
485 : SwViewShell *CallEndAction( sal_Bool bChkAction = sal_False, sal_Bool bChkPtr = sal_True );
486 : SwViewShell *CheckActionViewShell();
487 :
488 : DECL_LINK( AsyncCallback, void* );
489 :
490 : // Attribute am Dok setzen
491 : void _SetAttr( sal_Bool bChkEnd, sal_Bool bBeforeTable, _HTMLAttrs *pPostIts );
492 1111 : inline void SetAttr( sal_Bool bChkEnd = sal_True, sal_Bool bBeforeTable = sal_False,
493 : _HTMLAttrs *pPostIts = 0 )
494 : {
495 1111 : if( !aSetAttrTab.empty() || !aMoveFlyFrms.empty() )
496 234 : _SetAttr( bChkEnd, bBeforeTable, pPostIts );
497 1111 : }
498 :
499 : _HTMLAttr **GetAttrTabEntry( sal_uInt16 nWhich );
500 :
501 : // Einen neuen Textknoten an PaM-Position anlegen
502 : sal_Bool AppendTxtNode( SwHTMLAppendMode eMode=AM_NORMAL, sal_Bool bUpdateNum=sal_True );
503 : void AddParSpace();
504 :
505 : // Ein Attribut beginnen/beenden
506 : // ppDepAttr gibt einen Attribut-Tabellen-Eintrag an, dessen Attribute
507 : // gesetzt sein muessen, bevor das Attribut beendet werden darf
508 : void NewAttr( _HTMLAttr **ppAttr, const SfxPoolItem& rItem );
509 : void EndAttr( _HTMLAttr *pAttr, _HTMLAttr **ppDepAttr=0,
510 : sal_Bool bChkEmpty=sal_True );
511 : void DeleteAttr( _HTMLAttr* pAttr );
512 :
513 : void EndContextAttrs( _HTMLAttrContext *pContext, sal_Bool bRemove=sal_False );
514 : void SaveAttrTab( _HTMLAttrTable& rNewAttrTab );
515 : void SplitAttrTab( const SwPosition& rNewPos );
516 : void SplitAttrTab( _HTMLAttrTable& rNewAttrTab, sal_Bool bMoveEndBack = sal_True );
517 : void RestoreAttrTab( const _HTMLAttrTable& rNewAttrTab,
518 : sal_Bool bSetNewStart = sal_False );
519 : void InsertAttr( const SfxPoolItem& rItem, sal_Bool bLikePara = sal_False,
520 : sal_Bool bInsAtStart=sal_False );
521 : void InsertAttrs( _HTMLAttrs& rAttrs );
522 :
523 : sal_Bool DoPositioning( SfxItemSet &rItemSet,
524 : SvxCSS1PropertyInfo &rPropInfo,
525 : _HTMLAttrContext *pContext );
526 : sal_Bool CreateContainer( const OUString& rClass, SfxItemSet &rItemSet,
527 : SvxCSS1PropertyInfo &rPropInfo,
528 : _HTMLAttrContext *pContext );
529 : sal_Bool EndSection( sal_Bool bLFStripped=sal_False );
530 :
531 : void InsertAttrs( SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo,
532 : _HTMLAttrContext *pContext, sal_Bool bCharLvl=sal_False );
533 : void InsertAttr( _HTMLAttr **ppAttr, const SfxPoolItem & rItem,
534 : _HTMLAttrContext *pCntxt );
535 : void SplitPREListingXMP( _HTMLAttrContext *pCntxt );
536 : void FixHeaderFooterDistance( sal_Bool bHeader, const SwPosition *pOldPos );
537 :
538 : void EndContext( _HTMLAttrContext *pContext );
539 : void ClearContext( _HTMLAttrContext *pContext );
540 :
541 : const SwFmtColl *GetCurrFmtColl() const;
542 :
543 : SwTwips GetCurrentBrowseWidth();
544 :
545 809 : SwHTMLNumRuleInfo& GetNumInfo() { return *pNumRuleInfo; }
546 : // add parameter <bCountedInList>
547 : void SetNodeNum( sal_uInt8 nLevel, bool bCountedInList );
548 :
549 : // Verwalten von Absatz-Vorlagen
550 :
551 : // die Vorlagen auf dem Stack bzw. deren Attribute setzen
552 : void SetTxtCollAttrs( _HTMLAttrContext *pContext = 0 );
553 :
554 : void InsertParaAttrs( const SfxItemSet& rItemSet );
555 :
556 : // Verwalten des Attribut-Kontexts
557 :
558 : // aktuellen Kontext merken
559 : inline void PushContext( _HTMLAttrContext *pCntxt );
560 :
561 : // den obersten/spezifizierten Kontext holen, aber nicht ausserhalb
562 : // des Kontexts mit Token nLimit suchen. Wenn bRemove gesetzt ist,
563 : // wird er entfernt
564 : _HTMLAttrContext *PopContext( sal_uInt16 nToken=0, sal_uInt16 nLimit=0,
565 : sal_Bool bRemove=sal_True );
566 : inline const _HTMLAttrContext *GetTopContext() const;
567 :
568 : sal_Bool GetMarginsFromContext( sal_uInt16 &nLeft, sal_uInt16 &nRight, short& nIndent,
569 : sal_Bool bIgnoreCurrent=sal_False ) const;
570 : sal_Bool GetMarginsFromContextWithNumBul( sal_uInt16 &nLeft, sal_uInt16 &nRight,
571 : short& nIndent ) const;
572 : void GetULSpaceFromContext( sal_uInt16 &rUpper, sal_uInt16 &rLower ) const;
573 :
574 : void MovePageDescAttrs( SwNode *pSrcNd, sal_uLong nDestIdx, sal_Bool bFmtBreak );
575 :
576 : // Behandlung von Tags auf Absatz-Ebene
577 :
578 : // <P> und <H1> bis <H6>
579 : void NewPara();
580 : void EndPara( sal_Bool bReal = sal_False );
581 : void NewHeading( int nToken );
582 : void EndHeading();
583 :
584 : // <ADDRESS>, <BLOCKQUOTE> und <PRE>
585 : void NewTxtFmtColl( int nToken, sal_uInt16 nPoolId );
586 : void EndTxtFmtColl( int nToken );
587 :
588 : // <DIV> und <CENTER>
589 : void NewDivision( int nToken );
590 : void EndDivision( int nToken );
591 :
592 : // Fly-Frames einfuegen/verlassen
593 : void InsertFlyFrame( const SfxItemSet& rItemSet, _HTMLAttrContext *pCntxt,
594 : const OUString& rId, sal_uInt16 nFlags );
595 :
596 : void SaveDocContext( _HTMLAttrContext *pCntxt, sal_uInt16 nFlags,
597 : const SwPosition *pNewPos );
598 : void RestoreDocContext( _HTMLAttrContext *pCntxt );
599 :
600 : // alle durch <DIV> aufgespannten Bereiche verlassen
601 : sal_Bool EndSections( sal_Bool bLFStripped );
602 :
603 : // <MULTICOL>
604 : void NewMultiCol( sal_uInt16 columnsFromCss=0 );
605 : void EndMultiCol();
606 :
607 : // <MARQUEE>
608 : void NewMarquee( HTMLTable *pCurTable=0 );
609 : void EndMarquee();
610 : void InsertMarqueeText();
611 :
612 : // Behandluung von Listen
613 :
614 : // Numerierungs <OL> und Aufzaehlungs-Listen <UL> mit <LI>
615 : void NewNumBulList( int nToken );
616 : void EndNumBulList( int nToken=0 );
617 : void NewNumBulListItem( int nToken );
618 : void EndNumBulListItem( int nToken=0, sal_Bool bSetColl=sal_True,
619 : sal_Bool bLastPara=sal_False );
620 :
621 : // Definitions-Listen <DL> mit <DD>, <DT>
622 : void NewDefList();
623 : void EndDefList();
624 : void NewDefListItem( int nToken );
625 : void EndDefListItem( int nToken=0, sal_Bool bSetColl=sal_True,
626 : sal_Bool bLastPara=sal_False );
627 :
628 : // Behandlung von Tags auf Zeichen-Ebene
629 :
630 : // Tags wie <B>, <I> etc behandeln, die ein bestimmtes Attribut
631 : // an und ausschalten, oder die wie SPAN nur Attribute aus Styles holen
632 : void NewStdAttr( int nToken );
633 : void NewStdAttr( int nToken,
634 : _HTMLAttr **ppAttr, const SfxPoolItem & rItem,
635 : _HTMLAttr **ppAttr2=0, const SfxPoolItem *pItem2=0,
636 : _HTMLAttr **ppAttr3=0, const SfxPoolItem *pItem3=0 );
637 : void EndTag( int nToken );
638 :
639 : // Font-Attribute behandeln
640 : void NewBasefontAttr(); // fuer <BASEFONT>
641 : void EndBasefontAttr();
642 : void NewFontAttr( int nToken ); // fuer <FONT>, <BIG> und <SMALL>
643 : void EndFontAttr( int nToken );
644 :
645 : // Tags, die durch Zeichenvorlagen realisiert werden
646 : void NewCharFmt( int nToken );
647 :
648 : // <SDFIELD>
649 : public:
650 : static sal_uInt16 GetNumType( const OUString& rStr, sal_uInt16 eDfltType );
651 : private:
652 : void NewField();
653 : void EndField();
654 : void InsertFieldText();
655 :
656 : // <SPACER>
657 : void InsertSpacer();
658 :
659 : // Einfuegen von Grafiken, Plugins und Applets
660 :
661 : // Image-Maps suchen und mit Grafik-Nodes verbinden
662 : ImageMap *FindImageMap( const OUString& rURL ) const;
663 : void ConnectImageMaps();
664 :
665 : // Verankerung eines Fly-Frames bestimmen und entsprechende Attribute
666 : // in den Attrset setzen (htmlgrin.cxx)
667 : void SetAnchorAndAdjustment( sal_Int16 eVertOri,
668 : sal_Int16 eHoriOri,
669 : const SfxItemSet &rItemSet,
670 : const SvxCSS1PropertyInfo &rPropInfo,
671 : SfxItemSet& rFrmSet );
672 : void SetAnchorAndAdjustment( sal_Int16 eVertOri,
673 : sal_Int16 eHoriOri,
674 : SfxItemSet& rFrmSet,
675 : sal_Bool bDontAppend=sal_False );
676 : void SetAnchorAndAdjustment( const SfxItemSet &rItemSet,
677 : const SvxCSS1PropertyInfo &rPropInfo,
678 : SfxItemSet &rFrmItemSet );
679 :
680 : void SetFrmFmtAttrs( SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo,
681 : sal_uInt16 nFlags, SfxItemSet &rFrmItemSet );
682 :
683 : // Frames anlegen und Auto-gebundene Rahmen registrieren
684 : void RegisterFlyFrm( SwFrmFmt *pFlyFrm );
685 :
686 : // Die Groesse des Fly-Frames an die Vorgaben und Gegebenheiten anpassen
687 : // (nicht fuer Grafiken, deshalb htmlplug.cxx)
688 : void SetFixSize( const Size& rPixSize, const Size& rTwipDfltSize,
689 : sal_Bool bPrcWidth, sal_Bool bPrcHeight,
690 : SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo,
691 : SfxItemSet& rFlyItemSet );
692 : void SetVarSize( SfxItemSet &rItemSet, SvxCSS1PropertyInfo &rPropInfo,
693 : SfxItemSet& rFlyItemSet, SwTwips nDfltWidth=MINLAY,
694 : sal_uInt8 nDltPrcWidth=0 );
695 : void SetSpace( const Size& rPixSpace, SfxItemSet &rItemSet,
696 : SvxCSS1PropertyInfo &rPropInfo, SfxItemSet& rFlyItemSet );
697 :
698 : sal_uInt16 IncGrfsThatResizeTable();
699 :
700 : void GetDefaultScriptType( ScriptType& rType,
701 : OUString& rTypeStr ) const;
702 :
703 : // die eigentlichen Einfuege-Methoden fuer <IMG>, <EMBED> und <APPLET>
704 : // und <PARAM>
705 : void InsertImage(); // htmlgrin.cxx
706 : void InsertEmbed(); // htmlplug.cxx
707 :
708 : #if HAVE_FEATURE_JAVA
709 : void NewObject(); // htmlplug.cxx
710 : #endif
711 : void EndObject(); // CommandLine mit Applet verkn. (htmlplug.cxx)
712 : #if HAVE_FEATURE_JAVA
713 : void InsertApplet(); // htmlplug.cxx
714 : #endif
715 : void EndApplet(); // CommandLine mit Applet verkn. (htmlplug.cxx)
716 : void InsertParam(); // htmlplug.cxx
717 :
718 : void InsertFloatingFrame();
719 0 : void EndFloatingFrame() { bInFloatingFrame = false; }
720 :
721 : // <BODY>-Tag auswerten: Hintergrund-Grafiken und -Farben setzen (htmlgrin.cxx)
722 : void InsertBodyOptions();
723 :
724 : // Einfuegen von Links und ::com::sun::star::text::Bookmarks (htmlgrin.cxx)
725 :
726 : // <A>-Tag auswerten: einen Link bzw. eine ::com::sun::star::text::Bookmark einfuegen
727 : void NewAnchor();
728 : void EndAnchor();
729 :
730 : // eine ::com::sun::star::text::Bookmark einfuegen
731 : void InsertBookmark( const OUString& rName );
732 :
733 : void InsertCommentText( const sal_Char *pTag = 0 );
734 : void InsertComment( const OUString& rName, const sal_Char *pTag = 0 );
735 :
736 : // sind im aktuellen Absatz ::com::sun::star::text::Bookmarks vorhanden?
737 : sal_Bool HasCurrentParaBookmarks( sal_Bool bIgnoreStack=sal_False ) const;
738 :
739 : // Einfuegen von Script/Basic-Elementen
740 :
741 : // das zueletzt gelsene Basic-Modul parsen (htmlbas.cxx)
742 : void NewScript();
743 : void EndScript();
744 :
745 : void AddScriptSource();
746 :
747 : // ein Event in die SFX-Konfiguation eintragen (htmlbas.cxx)
748 : void InsertBasicDocEvent( const OUString& aEventName, const OUString& rName,
749 : ScriptType eScrType, const OUString& rScrType );
750 :
751 : // ein Event an ein VC-Control anhaengen (htmlform.cxx)
752 : void InsertBasicCtrlEvent( sal_uInt16 nEvent, const OUString& rName );
753 :
754 : // Inserting styles
755 :
756 : // <STYLE>
757 : void NewStyle();
758 : void EndStyle();
759 :
760 : inline sal_Bool HasStyleOptions( const OUString &rStyle, const OUString &rId,
761 : const OUString &rClass, const OUString *pLang=0,
762 : const OUString *pDir=0 );
763 : sal_Bool ParseStyleOptions( const OUString &rStyle, const OUString &rId,
764 : const OUString &rClass, SfxItemSet &rItemSet,
765 : SvxCSS1PropertyInfo &rPropInfo,
766 : const OUString *pLang=0, const OUString *pDir=0 );
767 :
768 : // Inserting Controls and ::com::sun::star::form::Forms (htmlform.cxx)
769 :
770 : // Insert draw object into document
771 : void InsertDrawObject( SdrObject* pNewDrawObj, const Size& rSpace,
772 : sal_Int16 eVertOri,
773 : sal_Int16 eHoriOri,
774 : SfxItemSet& rCSS1ItemSet,
775 : SvxCSS1PropertyInfo& rCSS1PropInfo,
776 : sal_Bool bHidden=sal_False );
777 : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > InsertControl( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormComponent > & rFormComp,
778 : const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & rFCompPropSet,
779 : const Size& rSize,
780 : sal_Int16 eVertOri,
781 : sal_Int16 eHoriOri,
782 : SfxItemSet& rCSS1ItemSet,
783 : SvxCSS1PropertyInfo& rCSS1PropInfo,
784 : const SvxMacroTableDtor& rMacroTbl,
785 : const std::vector<OUString>& rUnoMacroTbl,
786 : const std::vector<OUString>& rUnoMacroParamTbl,
787 : sal_Bool bSetPropSet = sal_True,
788 : sal_Bool bHidden = sal_False );
789 : void SetControlSize( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rShape, const Size& rTextSz,
790 : sal_Bool bMinWidth, sal_Bool bMinHeight );
791 : void SetPendingControlSize();
792 :
793 : public:
794 : void ResizeDrawObject( SdrObject* pObj, SwTwips nWidth );
795 : private:
796 : void RegisterDrawObjectToTable( HTMLTable *pCurTable, SdrObject* pObj,
797 : sal_uInt8 nWidth );
798 :
799 : void NewForm( sal_Bool bAppend=sal_True );
800 : void EndForm( sal_Bool bAppend=sal_True );
801 :
802 : // Insert methods for <INPUT>, <TEXTAREA> und <SELECT>
803 : void InsertInput();
804 :
805 : void NewTextArea();
806 : void InsertTextAreaText( sal_uInt16 nToken );
807 : void EndTextArea();
808 :
809 : void NewSelect();
810 : void InsertSelectOption();
811 : void InsertSelectText();
812 : void EndSelect();
813 :
814 : // Inserting tables (htmltab.cxx)
815 : public:
816 :
817 : // Insert box content after the given node
818 : const SwStartNode *InsertTableSection( const SwStartNode *pPrevStNd );
819 :
820 : // Insert box content at the end of the table containing the PaM
821 : // and move the PaM into the cell
822 : const SwStartNode *InsertTableSection( sal_uInt16 nPoolId );
823 :
824 : // Insert methods for various table tags
825 : HTMLTableCnts *InsertTableContents( sal_Bool bHead );
826 :
827 : private:
828 : // Create a section for the temporary storage of the table caption
829 : SwStartNode *InsertTempTableCaptionSection();
830 :
831 : void BuildTableCell( HTMLTable *pTable, sal_Bool bReadOptions, sal_Bool bHead );
832 : void BuildTableRow( HTMLTable *pTable, sal_Bool bReadOptions,
833 : SvxAdjust eGrpAdjust, sal_Int16 eVertOri );
834 : void BuildTableSection( HTMLTable *pTable, sal_Bool bReadOptions, sal_Bool bHead );
835 : void BuildTableColGroup( HTMLTable *pTable, sal_Bool bReadOptions );
836 : void BuildTableCaption( HTMLTable *pTable );
837 : HTMLTable *BuildTable( SvxAdjust eCellAdjust,
838 : sal_Bool bIsParentHead = sal_False,
839 : sal_Bool bHasParentSection=sal_True,
840 : sal_Bool bIsInMulticol = sal_False,
841 : sal_Bool bHasToFlow = sal_False );
842 :
843 : // misc ...
844 :
845 : void ParseMoreMetaOptions();
846 :
847 : sal_Bool FileDownload( const OUString& rURL, OUString& rStr );
848 : void InsertLink();
849 :
850 : void InsertIDOption();
851 : void InsertLineBreak();
852 : void InsertHorzRule();
853 :
854 : void FillEndNoteInfo( const OUString& rContent );
855 : void FillFootNoteInfo( const OUString& rContent );
856 : void InsertFootEndNote( const OUString& rName, sal_Bool bEndNote, sal_Bool bFixed );
857 : void FinishFootEndNote();
858 : void InsertFootEndNoteText();
859 : SwNodeIndex *GetFootEndNoteSection( const OUString& rName );
860 : void DeleteFootEndNoteImpl();
861 :
862 : sal_Int32 StripTrailingLF();
863 :
864 : // Remove empty paragraph at the PaM position
865 : void StripTrailingPara();
866 :
867 : // Are there fly frames in the current paragraph?
868 : sal_Bool HasCurrentParaFlys( sal_Bool bNoSurroundOnly = sal_False,
869 : sal_Bool bSurroundOnly = sal_False ) const;
870 :
871 : public: // used in tables
872 :
873 : // Create brush item (with new) or 0
874 : SvxBrushItem* CreateBrushItem( const Color *pColor,
875 : const OUString &rImageURL,
876 : const OUString &rStyle,
877 : const OUString &rId,
878 : const OUString &rClass );
879 :
880 : protected:
881 : // Executed for each token recognized by CallParser
882 : virtual void NextToken( int nToken ) SAL_OVERRIDE;
883 : virtual ~SwHTMLParser();
884 :
885 : // If the document is removed, remove the parser as well
886 : virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) SAL_OVERRIDE;
887 :
888 : virtual void AddMetaUserDefined( OUString const & i_rMetaName ) SAL_OVERRIDE;
889 :
890 : public:
891 :
892 : SwHTMLParser( SwDoc* pD, SwPaM & rCrsr, SvStream& rIn,
893 : const OUString& rFileName,
894 : const OUString& rBaseURL,
895 : bool bReadNewDoc = true,
896 : SfxMedium* pMed = 0, sal_Bool bReadUTF8 = sal_False,
897 : sal_Bool bIgnoreHTMLComments = sal_False );
898 :
899 : virtual SvParserState CallParser() SAL_OVERRIDE;
900 :
901 : sal_uInt16 ToTwips( sal_uInt16 nPixel ) const;
902 :
903 : // for reading asynchronously from SvStream
904 : virtual void Continue( int nToken ) SAL_OVERRIDE;
905 :
906 : virtual bool ParseMetaOptions( const ::com::sun::star::uno::Reference<
907 : ::com::sun::star::document::XDocumentProperties>&,
908 : SvKeyValueIterator* ) SAL_OVERRIDE;
909 : };
910 :
911 315 : struct SwPendingStackData
912 : {
913 315 : virtual ~SwPendingStackData() {}
914 : };
915 :
916 : struct SwPendingStack
917 : {
918 : int nToken;
919 : SwPendingStackData* pData;
920 : SwPendingStack* pNext;
921 :
922 0 : SwPendingStack( int nTkn, SwPendingStack* pNxt )
923 0 : : nToken( nTkn ), pData( 0 ), pNext( pNxt )
924 0 : {}
925 : };
926 :
927 769 : inline void _HTMLAttr::SetStart( const SwPosition& rPos )
928 : {
929 769 : nSttPara = rPos.nNode;
930 769 : nSttCntnt = rPos.nContent.GetIndex();
931 769 : nEndPara = nSttPara;
932 769 : nEndCntnt = nSttCntnt;
933 769 : }
934 :
935 1 : inline void _HTMLAttrContext::SetMargins( sal_uInt16 nLeft, sal_uInt16 nRight,
936 : short nIndent )
937 : {
938 1 : nLeftMargin = nLeft;
939 1 : nRightMargin = nRight;
940 1 : nFirstLineIndent = nIndent;
941 1 : bLRSpaceChanged = true;
942 1 : }
943 :
944 2 : inline void _HTMLAttrContext::GetMargins( sal_uInt16& nLeft,
945 : sal_uInt16& nRight,
946 : short& nIndent ) const
947 : {
948 2 : if( bLRSpaceChanged )
949 : {
950 1 : nLeft = nLeftMargin;
951 1 : nRight = nRightMargin;
952 1 : nIndent = nFirstLineIndent;
953 : }
954 2 : }
955 :
956 214 : inline void _HTMLAttrContext::SetULSpace( sal_uInt16 nUpper, sal_uInt16 nLower )
957 : {
958 214 : nUpperSpace = nUpper;
959 214 : nLowerSpace = nLower;
960 214 : bULSpaceChanged = true;
961 214 : }
962 :
963 0 : inline void _HTMLAttrContext::GetULSpace( sal_uInt16& rUpper,
964 : sal_uInt16& rLower ) const
965 : {
966 0 : if( bULSpaceChanged )
967 : {
968 0 : rUpper = nUpperSpace;
969 0 : rLower = nLowerSpace;
970 : }
971 0 : }
972 :
973 829 : inline sal_Bool SwHTMLParser::HasStyleOptions( const OUString &rStyle,
974 : const OUString &rId,
975 : const OUString &rClass,
976 : const OUString *pLang,
977 : const OUString *pDir )
978 : {
979 1169 : return !rStyle.isEmpty() || !rId.isEmpty() || !rClass.isEmpty() ||
980 895 : (pLang && !pLang->isEmpty()) || (pDir && !pDir->isEmpty());
981 : }
982 :
983 : inline const _HTMLAttrContext *SwHTMLParser::GetTopContext() const
984 : {
985 : return aContexts.size() > nContextStMin
986 : ? aContexts.back() : 0;
987 : }
988 :
989 564 : inline void SwHTMLParser::PushContext( _HTMLAttrContext *pCntxt )
990 : {
991 564 : aContexts.push_back( pCntxt );
992 564 : }
993 :
994 : #endif
995 :
996 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|