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 $
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 -*- */
38 #ifndef __SGI_STL_DEQUE
41 #ifndef __SGI_STL_VECTOR
46 #define _SVSTDARR_BOOLS
47 #include <svtools/svstdarr.hxx>
49 #include <svx/svxrtf.hxx>
50 #include <svx/numitem.hxx>
51 #include <svx/boxitem.hxx>
52 #include <redline.hxx>
53 #ifndef __SGI_STL_ALGORITHM
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
);
79 class SwRelNumRuleSpaces
;
82 struct SvxRTFPictureType
;
84 class RtfReader
: public Reader
86 virtual ULONG
Read( SwDoc
&, const String
& rBaseURL
, SwPaM
&,const String
&);
89 class SwNodeIdx
: public SvxNodeIdx
93 SwNodeIdx( const SwNodeIndex
& rIdx
) : aIdx( rIdx
) {}
94 virtual ULONG
GetIdx() const;
95 virtual SvxNodeIdx
* Clone() const;
98 class BookmarkPosition
101 SwNodeIndex maMkNode
;
102 xub_StrLen mnMkCntnt
;
103 BookmarkPosition(const SwPaM
&rPaM
);
104 BookmarkPosition(const BookmarkPosition
&rEntry
);
106 bool operator==(const BookmarkPosition
);
109 BookmarkPosition
& operator=(const BookmarkPosition
&);
113 class SwxPosition
: public SvxPosition
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:
133 SwNodeIndex nSttNd
, nEndNd
;
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
);
145 long nListId
, nListTemplateId
, nListNo
;
150 : nListId( 0 ), nListTemplateId( 0 ), nListNo( 0 ), nListDocPos( 0 ),
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;
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
182 DocPageInformation();
185 struct SectPageInformation
187 std::vector
<long> maColumns
;
189 SvxNumberType maNumType
;
190 SwPageDesc
*mpTitlePageHdFt
;
191 SwPageDesc
*mpPageHdFt
;
211 bool mbTitlePageHdFtUsed
;
213 SectPageInformation(const DocPageInformation
&rDoc
);
214 SectPageInformation(const SectPageInformation
&rSect
);
220 rtfSection(const SwPosition
&rPos
,
221 const SectPageInformation
&rPageInfo
);
223 SectPageInformation maPageInfo
;
224 SwSection
*mpSection
;
225 SwPageDesc
*mpTitlePage
;
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
; }
245 SwRTFParser
&mrReader
;
246 std::deque
<rtfSection
> maSegments
;
247 typedef std::deque
<rtfSection
>::iterator mySegIter
;
248 typedef std::deque
<rtfSection
>::reverse_iterator mySegrIter
;
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
,
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
,
267 void SetHdFt(rtfSection
&rSection
);
268 void CopyFrom(const SwPageDesc
&rFrom
, SwPageDesc
&rDest
);
269 void MoveFrom(SwPageDesc
&rFrom
, SwPageDesc
&rDest
);
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
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
;
319 SwPaM
* pPam
; // SwPosition duerfte doch reichen, oder ??
320 SwRelNumRuleSpaces
* pRelNumRule
; // Liste aller benannten NumRules
322 String sNestedFieldStr
;
323 SwFltRedline
*pRedlineInsert
;
324 SwFltRedline
*pRedlineDelete
;
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
;
335 bool bReadSwFly
; // lese Swg-Fly (wichtig fuer Bitmaps!)
336 // --> OD 2008-12-22 #i83368#
337 bool mbReadCellWhileReadSwFly
;
339 bool mbReadNoTbl
; // verhinder Tabelle in Tabelle/FootNote
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
350 bool bTrowdRead
; // True, iff an \trowd definition was read after the last \row
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();
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
,
398 SwCharFmt
* MakeCharFmt( const String
& rName
, USHORT nPos
,
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
);
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 );
416 void GetPageSize( Size
& rSize
); // Groesse der PagePrintArea
418 // fuers Einlesen von Tabellen
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
);
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();
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
);
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();
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
);
484 /* vi:set tabstop=4 shiftwidth=4 expandtab: */