merge the formfield patch from ooo-build
[ooovba.git] / sw / source / filter / rtf / swparrtf.hxx
blob006c721698c147033c4016d0d3e502696079e26a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: swparrtf.hxx,v $
10 * $Revision: 1.34 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
32 #ifndef _SWPARRTF_HXX
33 #define _SWPARRTF_HXX
35 #ifndef __SGI_STL_MAP
36 #include <map>
37 #endif
38 #ifndef __SGI_STL_DEQUE
39 #include <deque>
40 #endif
41 #ifndef __SGI_STL_VECTOR
42 #include <vector>
43 #endif
45 #ifndef _SVSTDARR_HXX
46 #define _SVSTDARR_BOOLS
47 #include <svtools/svstdarr.hxx>
48 #endif
49 #include <svx/svxrtf.hxx>
50 #include <svx/numitem.hxx>
51 #include <svx/boxitem.hxx>
52 #include <redline.hxx>
53 #ifndef __SGI_STL_ALGORITHM
54 #include <algorithm>
55 #endif
56 #include <fltshell.hxx> // fuer den Attribut Stack
57 #include <ndindex.hxx>
58 #include "../inc/msfilter.hxx"
59 #include <svx/svdobj.hxx>
62 extern void GetLineIndex(SvxBoxItem &rBox, short nLineThickness, short nSpace, BYTE nCol, short nIdx,
63 USHORT nOOIndex, USHORT nWWIndex, short *pSize);
65 class Font;
66 class Graphic;
68 class SwNoTxtNode;
69 class Size;
70 class SwPaM;
71 class SwDoc;
72 class SwPageDesc;
73 class SwTxtFmtColl;
74 class SwTableNode;
75 class SwCharFmt;
76 class SwNumRule;
77 class SwRTFParser;
78 class SvxFontItem;
79 class SwRelNumRuleSpaces;
80 class SwNodeNum;
81 class SwTxtNode;
82 struct SvxRTFPictureType;
84 class RtfReader: public Reader
86 virtual ULONG Read( SwDoc &, const String& rBaseURL, SwPaM &,const String &);
89 class SwNodeIdx : public SvxNodeIdx
91 SwNodeIndex aIdx;
92 public:
93 SwNodeIdx( const SwNodeIndex& rIdx ) : aIdx( rIdx ) {}
94 virtual ULONG GetIdx() const;
95 virtual SvxNodeIdx* Clone() const;
98 class BookmarkPosition
100 public:
101 SwNodeIndex maMkNode;
102 xub_StrLen mnMkCntnt;
103 BookmarkPosition(const SwPaM &rPaM);
104 BookmarkPosition(const BookmarkPosition &rEntry);
106 bool operator==(const BookmarkPosition);
107 private:
108 //No assignment
109 BookmarkPosition& operator=(const BookmarkPosition&);
113 class SwxPosition : public SvxPosition
115 SwPaM* pPam;
116 public:
117 SwxPosition( SwPaM* pCrsr ) : pPam( pCrsr ) {}
119 virtual ULONG GetNodeIdx() const;
120 virtual xub_StrLen GetCntIdx() const;
122 // erzeuge von sich selbst eine Kopie
123 virtual SvxPosition* Clone() const;
124 // erzeuge vom NodeIndex eine Kopie
125 virtual SvxNodeIdx* MakeNodeIdx() const;
129 // zum zwischenspeichern der Flys:
130 struct SwFlySave
132 SfxItemSet aFlySet;
133 SwNodeIndex nSttNd, nEndNd;
134 xub_StrLen nEndCnt;
135 SwTwips nPageWidth;
136 USHORT nDropLines, nDropAnchor;
138 SwFlySave( const SwPaM& rPam, SfxItemSet& rSet );
139 int IsEqualFly( const SwPaM& rPos, SfxItemSet& rSet );
140 void SetFlySize( const SwTableNode& rTblNd );
143 struct SwListEntry
145 long nListId, nListTemplateId, nListNo;
146 USHORT nListDocPos;
147 BOOL bRuleUsed;
149 SwListEntry()
150 : nListId( 0 ), nListTemplateId( 0 ), nListNo( 0 ), nListDocPos( 0 ),
151 bRuleUsed( FALSE )
153 SwListEntry( long nLstId, long nLstTmplId, USHORT nLstDocPos )
154 : nListId( nLstId ), nListTemplateId( nLstTmplId ), nListNo( 0 ),
155 nListDocPos( nLstDocPos ), bRuleUsed( FALSE )
158 void Clear() { nListId = nListTemplateId = nListNo = 0, nListDocPos = 0;
159 bRuleUsed = FALSE; }
162 DECLARE_TABLE( SwRTFStyleTbl, SwTxtFmtColl* )
163 DECLARE_TABLE( SwRTFCharStyleTbl, SwCharFmt* )
164 typedef SwFlySave* SwFlySavePtr;
165 SV_DECL_PTRARR_DEL( SwFlySaveArr, SwFlySavePtr, 0, 20 )
166 SV_DECL_VARARR( SwListArr, SwListEntry, 0, 20 )
168 struct DocPageInformation
170 SvxBoxItem maBox;
171 long mnPaperw;
172 long mnPaperh;
173 long mnMargl;
174 long mnMargr;
175 long mnMargt;
176 long mnMargb;
177 long mnGutter;
178 long mnPgnStart;
179 bool mbFacingp;
180 bool mbLandscape;
181 bool mbRTLdoc;
182 DocPageInformation();
185 struct SectPageInformation
187 std::vector<long> maColumns;
188 SvxBoxItem maBox;
189 SvxNumberType maNumType;
190 SwPageDesc *mpTitlePageHdFt;
191 SwPageDesc *mpPageHdFt;
192 long mnPgwsxn;
193 long mnPghsxn;
194 long mnMarglsxn;
195 long mnMargrsxn;
196 long mnMargtsxn;
197 long mnMargbsxn;
198 long mnGutterxsn;
199 long mnHeadery;
200 long mnFootery;
201 long mnPgnStarts;
202 long mnCols;
203 long mnColsx;
204 long mnStextflow;
205 int mnBkc;
206 bool mbLndscpsxn;
207 bool mbTitlepg;
208 bool mbFacpgsxn;
209 bool mbRTLsection;
210 bool mbPgnrestart;
211 bool mbTitlePageHdFtUsed;
212 bool mbPageHdFtUsed;
213 SectPageInformation(const DocPageInformation &rDoc);
214 SectPageInformation(const SectPageInformation &rSect);
217 class rtfSection
219 public:
220 rtfSection(const SwPosition &rPos,
221 const SectPageInformation &rPageInfo);
222 SwNodeIndex maStart;
223 SectPageInformation maPageInfo;
224 SwSection *mpSection;
225 SwPageDesc *mpTitlePage;
226 SwPageDesc *mpPage;
228 bool IsContinous() const { return maPageInfo.mnBkc == 0; }
229 long NoCols() const { return maPageInfo.mnCols; }
230 long StandardColSeperation() const { return maPageInfo.mnColsx; }
231 bool HasTitlePage() const { return maPageInfo.mbTitlepg; }
232 long PageStartAt() const { return maPageInfo.mnPgnStarts; }
233 bool PageRestartNo() const { return maPageInfo.mbPgnrestart; }
234 bool IsBiDi() const { return maPageInfo.mbRTLsection; }
235 long GetPageWidth() const { return maPageInfo.mnPgwsxn; }
236 long GetPageHeight() const { return maPageInfo.mnPghsxn; }
237 long GetPageLeft() const { return maPageInfo.mnMarglsxn; }
238 long GetPageRight() const { return maPageInfo.mnMargrsxn; }
239 bool IsLandScape() const { return maPageInfo.mbLndscpsxn; }
242 class rtfSections
244 private:
245 SwRTFParser &mrReader;
246 std::deque<rtfSection> maSegments;
247 typedef std::deque<rtfSection>::iterator mySegIter;
248 typedef std::deque<rtfSection>::reverse_iterator mySegrIter;
250 struct wwULSpaceData
252 bool bHasHeader, bHasFooter;
253 short nSwHLo, nHdUL, nSwFUp, nFtUL, nSwUp, nSwLo;
254 wwULSpaceData() : bHasHeader(false), bHasFooter(false) {}
257 void SetSegmentToPageDesc(const rtfSection &rSection, bool bTitlePage,
258 bool bIgnoreCols);
259 SwSectionFmt *InsertSection(SwPaM& rMyPaM, rtfSection &rSection);
260 void SetPage(SwPageDesc &rInPageDesc, SwFrmFmt &rFmt,
261 const rtfSection &rSection, bool bIgnoreCols);
262 void GetPageULData(const rtfSection &rSection, bool bFirst,
263 wwULSpaceData& rData);
264 void SetPageULSpaceItems(SwFrmFmt &rFmt, wwULSpaceData& rData);
265 bool SetCols(SwFrmFmt &rFmt, const rtfSection &rSection,
266 USHORT nNettoWidth);
267 void SetHdFt(rtfSection &rSection);
268 void CopyFrom(const SwPageDesc &rFrom, SwPageDesc &rDest);
269 void MoveFrom(SwPageDesc &rFrom, SwPageDesc &rDest);
270 public:
271 bool empty() const { return maSegments.empty(); }
272 int size() const { return maSegments.size(); }
273 void push_back(const rtfSection &rSect);
274 void pop_back() { maSegments.pop_back(); }
275 rtfSection& back() { return maSegments.back(); }
276 const rtfSection& back() const { return maSegments.back(); }
277 void InsertSegments(bool bIsNewDoc);
278 rtfSections(SwRTFParser &rReader) : mrReader(rReader) {}
279 std::vector<sal_uInt16> maDummyPageNos;
280 typedef std::vector<sal_uInt16>::reverse_iterator myrDummyIter;
281 void PrependedInlineNode(const SwPosition &rPos,
282 const SwNode &rNode);
288 class SwRTFParser : public SvxRTFParser
291 Knows which writer style a given word style should be imported as.
293 sw::util::ParaStyleMapper maParaStyleMapper;
294 sw::util::CharStyleMapper maCharStyleMapper;
296 std::vector<String> aRevTbl;
298 friend class rtfSections;
299 DocPageInformation maPageDefaults;
300 rtfSections maSegments;
302 sw::util::InsertedTablesManager maInsertedTables;
303 SwRTFStyleTbl aTxtCollTbl;
304 SwRTFCharStyleTbl aCharFmtTbl;
305 SwFlySaveArr aFlyArr; // Flys als Letzes im Doc setzen
306 SvBools aMergeBoxes; // Flags fuer gemergte Zellen
307 SwListArr aListArr;
308 SvPtrarr aTblFmts;
309 SvPtrarr aRubyCharFmts;
310 BookmarkPosition* mpBookmarkStart;
311 sw::util::RedlineStack *mpRedlineStack;
312 sw::util::AuthorInfos* pAuthorInfos;
314 SfxItemSet* pGrfAttrSet;
315 SwTableNode* pTableNode, *pOldTblNd; // fuers Lesen von Tabellen: akt. Tab
316 SwNodeIndex* pSttNdIdx;
317 SwNodeIndex* pRegionEndIdx;
318 SwDoc* pDoc;
319 SwPaM* pPam; // SwPosition duerfte doch reichen, oder ??
320 SwRelNumRuleSpaces* pRelNumRule; // Liste aller benannten NumRules
322 String sNestedFieldStr;
323 SwFltRedline *pRedlineInsert;
324 SwFltRedline *pRedlineDelete;
326 String sBaseURL;
328 USHORT nAktPageDesc, nAktFirstPageDesc;
329 USHORT nAktBox; // akt. Box
330 USHORT nInsTblRow; // beim nach \row kein \pard -> neue Line anlegen
331 USHORT nNewNumSectDef; // jeder SectionWechsel kann neue Rules definieren
332 USHORT nRowsToRepeat;
334 bool bSwPageDesc;
335 bool bReadSwFly; // lese Swg-Fly (wichtig fuer Bitmaps!)
336 // --> OD 2008-12-22 #i83368#
337 bool mbReadCellWhileReadSwFly;
338 // <--
339 bool mbReadNoTbl; // verhinder Tabelle in Tabelle/FootNote
340 bool mbIsFootnote;
341 bool bFootnoteAutoNum; // automatische Numerierung ?
342 bool bStyleTabValid; // Styles schon erzeugt ?
343 bool bInPgDscTbl; // beim PageDescTbl lesen
344 bool bNewNumList; // Word 7.0 NumList gelesen, 6.0 ueberspringen
345 bool bFirstContinue; // 1.Call ins Continue
346 bool bContainsPara; // If there is no paragraph in the section
347 bool bContainsTablePara; // If there is an table in this section
348 bool bForceNewTable; // Forces a beginning of a new table
349 bool bNestedField;
350 bool bTrowdRead; // True, iff an \trowd definition was read after the last \row
352 int nReadFlyDepth;
354 int nZOrder;
356 #i9243#
357 In a footnote tables are not possible (for some obscure reason!)
359 bool CantUseTables() const { return mbReadNoTbl || mbIsFootnote; }
361 virtual void InsertPara();
362 virtual void InsertText();
363 virtual void MovePos( int bForward = TRUE );
364 virtual void SetEndPrevPara( SvxNodeIdx*& rpNodePos, xub_StrLen& rCntPos );
365 void EnterEnvironment();
366 void LeaveEnvironment();
368 SwFmtPageDesc* GetCurrentPageDesc(SwPaM *pPam);
369 void CheckInsNewTblLine();
371 // setze RTF-Werte auf Swg-Werte
372 void SetSwgValues( SfxItemSet& rSet );
374 virtual void ReadInfo( const sal_Char* pChkForVerNo = 0 );
376 void ReadUserProperties();
378 void ReadListLevel( SwNumRule& rRule, BYTE nLvl );
379 void SetBorderLine(SvxBoxItem& rBox, sal_uInt16 nLine);
380 void ReadListTable();
381 USHORT ReadRevTbl();
382 void ReadShpRslt();
383 void ReadShpTxt(String &shpTxt);
384 void ReadDrawingObject();
385 void InsertShpObject(SdrObject* pStroke, int nZOrder);
386 void ReadShapeObject();
387 void ReadListOverrideTable();
388 SwNumRule *ReadNumSecLevel( int nToken );
389 SwNumRule* GetNumRuleOfListNo( long nListNo,
390 BOOL bRemoveFromList = FALSE );
391 void RemoveUnusedNumRule( SwNumRule* );
392 void RemoveUnusedNumRules();
393 const Font* FindFontOfItem( const SvxFontItem& rItem ) const;
395 // 3 Methoden zum Aufbauen der Styles
396 SwTxtFmtColl* MakeColl( const String&, USHORT nPos, BYTE nOutlineLevel,
397 bool& rbCollExist );
398 SwCharFmt* MakeCharFmt( const String& rName, USHORT nPos,
399 int& rbCollExist );
400 void SetStyleAttr( SfxItemSet& rCollSet,
401 const SfxItemSet& rStyleSet,
402 const SfxItemSet& rDerivedSet );
403 SwTxtFmtColl* MakeStyle( USHORT nNo, const SvxRTFStyleType& rStyle );
404 SwCharFmt* MakeCharStyle( USHORT nNo, const SvxRTFStyleType& rStyle );
405 void MakeStyleTab();
407 int MakeFieldInst( String& rFieldStr );
409 // einlesen/einfuegen von Bitmaps
410 void InsPicture( const String& rNm,
411 const Graphic* = 0, const SvxRTFPictureType* = 0 );
412 void _SetPictureSize( const SwNoTxtNode& rNd, const SwNodeIndex& rAnchor,
413 SfxItemSet& rSet, const SvxRTFPictureType* = 0 );
415 void SetFlysInDoc();
416 void GetPageSize( Size& rSize ); // Groesse der PagePrintArea
418 // fuers Einlesen von Tabellen
419 void GotoNextBox();
420 void NewTblLine();
422 void DelLastNode(); // loesche den letzten Node (Tabelle/Fly/Ftn/..)
424 void AddNumRule( SwNumRule* pRule );
425 void SetNumRelSpaces();
426 void SetOultineRelSpaces( const SwNodeIndex& rStt,
427 const SwNodeIndex& rEnd );
428 void SetNumLSpace( SwTxtNode& rNd, const SwNodeNum& rNum,
429 const SwNumRule& rRule );
430 long GetSafePos(long nPos);
432 protected:
433 // wird fuer jedes Token gerufen, das in CallParser erkannt wird
434 virtual void NextToken( int nToken );
436 // virtual void ReadUnknownData();
437 virtual void ReadBitmapData();
438 #ifdef READ_OLE_OBJECT
439 virtual void ReadOLEData();
440 #endif
441 virtual void SetAttrInDoc( SvxRTFItemStackType &rSet );
442 virtual bool UncompressableStackEntry(const SvxRTFItemStackType &rSet) const;
443 // fuer Tokens, die im ReadAttr nicht ausgewertet werden
444 virtual void UnknownAttrToken( int nToken, SfxItemSet* pSet );
446 void ReadPrtData();
447 void ReadField();
448 void ReadXEField();
449 void ReadHeaderFooter( int nToken, SwPageDesc* pPageDesc = 0 );
450 void ReadDocControls( int nToken );
451 void SetPageInformationAsDefault(const DocPageInformation &rInfo);
452 void ReadSectControls( int nToken );
453 void DoHairyWriterPageDesc(int nToken);
454 void ReadFly( int nToken, SfxItemSet* pFillSet = 0 );
455 void ReadTable( int nToken );
456 void ReadPageDescTbl();
457 void SkipPageDescTbl();
458 bool IsBorderToken(int nToken);
460 const String& GetBaseURL() const { return sBaseURL;}
462 virtual ~SwRTFParser();
464 public:
465 SwRTFParser( SwDoc* pD,
466 ::com::sun::star::uno::Reference<
467 ::com::sun::star::document::XDocumentProperties> i_xDocProps,
468 const SwPaM& rCrsr, SvStream& rIn,
469 const String& rBaseURL,
470 int bReadNewDoc = TRUE );
472 virtual SvParserState CallParser(); // Aufruf des Parsers
473 virtual int IsEndPara( SvxNodeIdx* pNd, xub_StrLen nCnt ) const;
475 // fuers asynchrone lesen aus dem SvStream
476 // virtual void SaveState( int nToken );
477 // virtual void RestoreState();
478 virtual void Continue( int nToken );
482 #endif
484 /* vi:set tabstop=4 shiftwidth=4 expandtab: */