xref: /aoo4110/main/sw/source/filter/rtf/swparrtf.hxx (revision b1cdbd2c)
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 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
24 
25 #ifndef _SWPARRTF_HXX
26 #define _SWPARRTF_HXX
27 
28 #ifndef __SGI_STL_DEQUE
29 #include <deque>
30 #endif
31 #ifndef __SGI_STL_VECTOR
32 #include <vector>
33 #endif
34 
35 #ifndef _SVSTDARR_HXX
36 #define _SVSTDARR_BOOLS
37 #include <svl/svstdarr.hxx>
38 #endif
39 #include <editeng/svxrtf.hxx>
40 #include <editeng/numitem.hxx>
41 #include <editeng/boxitem.hxx>
42 #include <redline.hxx>
43 
44 #include <fltshell.hxx>         // fuer den Attribut Stack
45 #include <ndindex.hxx>
46 #include "../inc/msfilter.hxx"
47 #include <svx/svdobj.hxx>
48 
49 
50 extern void GetLineIndex(SvxBoxItem &rBox, short nLineThickness, short nSpace, sal_uInt8 nCol, short nIdx,
51     sal_uInt16 nOOIndex, sal_uInt16 nWWIndex, short *pSize);
52 
53 class Font;
54 class Graphic;
55 
56 class SwNoTxtNode;
57 class Size;
58 class SwPaM;
59 class SwDoc;
60 class SwPageDesc;
61 class SwTxtFmtColl;
62 class SwTableNode;
63 class SwCharFmt;
64 class SwNumRule;
65 class SwRTFParser;
66 class SvxFontItem;
67 class SwRelNumRuleSpaces;
68 class SwNodeNum;
69 class SwTxtNode;
70 struct SvxRTFPictureType;
71 
72 class RtfReader: public Reader
73 {
74     virtual sal_uLong Read( SwDoc &, const String& rBaseURL, SwPaM &,const String &);
75 public:
76     virtual sal_uLong Read( SvStream* pStrm, SwDoc &, const String& rBaseURL, SwPaM &);
77 };
78 
79 class SwNodeIdx : public SvxNodeIdx
80 {
81 	SwNodeIndex aIdx;
82 public:
SwNodeIdx(const SwNodeIndex & rIdx)83 	SwNodeIdx( const SwNodeIndex& rIdx ) : aIdx( rIdx ) {}
84 	virtual sal_uLong	GetIdx() const;
85 	virtual SvxNodeIdx* Clone() const;
86 };
87 
88 class BookmarkPosition
89 {
90 public:
91     SwNodeIndex maMkNode;
92     xub_StrLen mnMkCntnt;
93     BookmarkPosition(const SwPaM &rPaM);
94     BookmarkPosition(const BookmarkPosition &rEntry);
95 
96 	bool operator==(const BookmarkPosition);
97 private:
98     //No assignment
99     BookmarkPosition& operator=(const BookmarkPosition&);
100 
101 };
102 
103 class SwxPosition : public SvxPosition
104 {
105 	SwPaM* pPam;
106 public:
SwxPosition(SwPaM * pCrsr)107 	SwxPosition( SwPaM* pCrsr )	: pPam( pCrsr ) {}
108 
109 	virtual sal_uLong	GetNodeIdx() const;
110 	virtual xub_StrLen GetCntIdx() const;
111 
112 	// erzeuge von sich selbst eine Kopie
113 	virtual SvxPosition* Clone() const;
114 	// erzeuge vom NodeIndex eine Kopie
115 	virtual SvxNodeIdx* MakeNodeIdx() const;
116 };
117 
118 
119 // zum zwischenspeichern der Flys:
120 struct SwFlySave
121 {
122 	SfxItemSet 	aFlySet;
123 	SwNodeIndex	nSttNd, nEndNd;
124 	xub_StrLen	nEndCnt;
125 	SwTwips		nPageWidth;
126 	sal_uInt16 		nDropLines, nDropAnchor;
127 
128 	SwFlySave( const SwPaM& rPam, SfxItemSet& rSet );
129 	int IsEqualFly( const SwPaM& rPos, SfxItemSet& rSet );
130 	void SetFlySize( const SwTableNode& rTblNd );
131 };
132 
133 struct SwListEntry
134 {
135 	long nListId, nListTemplateId, nListNo;
136 	sal_uInt16 nListDocPos;
137 	sal_Bool bRuleUsed;
138 
SwListEntrySwListEntry139 	SwListEntry()
140 		: nListId( 0 ), nListTemplateId( 0 ), nListNo( 0 ), nListDocPos( 0 ),
141 		bRuleUsed( sal_False )
142 	{}
SwListEntrySwListEntry143 	SwListEntry( long nLstId, long nLstTmplId, sal_uInt16 nLstDocPos )
144 		: nListId( nLstId ), nListTemplateId( nLstTmplId ), nListNo( 0 ),
145 		nListDocPos( nLstDocPos ), bRuleUsed( sal_False )
146 	{}
147 
ClearSwListEntry148 	void Clear() { nListId = nListTemplateId = nListNo = 0, nListDocPos = 0;
149 					bRuleUsed = sal_False; }
150 };
151 
152 DECLARE_TABLE( SwRTFStyleTbl, SwTxtFmtColl* )
153 DECLARE_TABLE( SwRTFCharStyleTbl, SwCharFmt* )
154 typedef SwFlySave* SwFlySavePtr;
155 SV_DECL_PTRARR_DEL( SwFlySaveArr, SwFlySavePtr, 0, 20 )
156 typedef std::deque< SwListEntry > SwListArr;
157 
158 struct DocPageInformation
159 {
160 	SvxBoxItem maBox;
161     long mnPaperw;
162     long mnPaperh;
163     long mnMargl;
164     long mnMargr;
165     long mnMargt;
166     long mnMargb;
167     long mnGutter;
168     long mnPgnStart;
169     bool mbFacingp;
170     bool mbLandscape;
171     bool mbRTLdoc;
172     DocPageInformation();
173 };
174 
175 struct SectPageInformation
176 {
177     std::vector<long> maColumns;
178 	SvxBoxItem maBox;
179     SvxNumberType maNumType;
180     SwPageDesc *mpTitlePageHdFt;
181     SwPageDesc *mpPageHdFt;
182     long mnPgwsxn;
183     long mnPghsxn;
184     long mnMarglsxn;
185     long mnMargrsxn;
186     long mnMargtsxn;
187     long mnMargbsxn;
188     long mnGutterxsn;
189     long mnHeadery;
190     long mnFootery;
191     long mnPgnStarts;
192     long mnCols;
193     long mnColsx;
194     long mnStextflow;
195     int mnBkc;
196     bool mbLndscpsxn;
197     bool mbTitlepg;
198     bool mbFacpgsxn;
199     bool mbRTLsection;
200     bool mbPgnrestart;
201     bool mbTitlePageHdFtUsed;
202     bool mbPageHdFtUsed;
203     SectPageInformation(const DocPageInformation &rDoc);
204     SectPageInformation(const SectPageInformation &rSect);
205 };
206 
207 class rtfSection
208 {
209 public:
210 	rtfSection(const SwPosition &rPos,
211 		const SectPageInformation &rPageInfo);
212 	SwNodeIndex maStart;
213 	SectPageInformation maPageInfo;
214     SwSection *mpSection;
215     SwPageDesc *mpTitlePage;
216     SwPageDesc *mpPage;
217 
IsContinous() const218     bool IsContinous() const { return maPageInfo.mnBkc == 0; }
NoCols() const219     long NoCols() const { return maPageInfo.mnCols; }
StandardColSeperation() const220     long StandardColSeperation() const { return maPageInfo.mnColsx; }
HasTitlePage() const221     bool HasTitlePage() const { return maPageInfo.mbTitlepg; }
PageStartAt() const222     long PageStartAt() const { return maPageInfo.mnPgnStarts; }
PageRestartNo() const223     bool PageRestartNo() const { return maPageInfo.mbPgnrestart; }
IsBiDi() const224     bool IsBiDi() const { return maPageInfo.mbRTLsection; }
GetPageWidth() const225     long GetPageWidth() const { return maPageInfo.mnPgwsxn; }
GetPageHeight() const226     long GetPageHeight() const { return maPageInfo.mnPghsxn; }
GetPageLeft() const227     long GetPageLeft() const { return maPageInfo.mnMarglsxn; }
GetPageRight() const228     long GetPageRight() const { return maPageInfo.mnMargrsxn; }
IsLandScape() const229     bool IsLandScape() const { return maPageInfo.mbLndscpsxn; }
230 };
231 
232 class rtfSections
233 {
234 private:
235     SwRTFParser &mrReader;
236     std::deque<rtfSection> maSegments;
237     typedef std::deque<rtfSection>::iterator mySegIter;
238     typedef std::deque<rtfSection>::reverse_iterator mySegrIter;
239 
240     struct wwULSpaceData
241     {
242         bool bHasHeader, bHasFooter;
243         short nSwHLo, nHdUL, nSwFUp, nFtUL, nSwUp,  nSwLo;
wwULSpaceDatartfSections::wwULSpaceData244         wwULSpaceData() : bHasHeader(false), bHasFooter(false) {}
245     };
246 
247     void SetSegmentToPageDesc(const rtfSection &rSection, bool bTitlePage,
248         bool bIgnoreCols);
249     SwSectionFmt *InsertSection(SwPaM& rMyPaM, rtfSection &rSection);
250     void SetPage(SwPageDesc &rInPageDesc, SwFrmFmt &rFmt,
251         const rtfSection &rSection, bool bIgnoreCols);
252     void GetPageULData(const rtfSection &rSection, bool bFirst,
253         wwULSpaceData& rData);
254     void SetPageULSpaceItems(SwFrmFmt &rFmt, wwULSpaceData& rData);
255     bool SetCols(SwFrmFmt &rFmt, const rtfSection &rSection,
256         sal_uInt16 nNettoWidth);
257     void SetHdFt(rtfSection &rSection);
258     void CopyFrom(const SwPageDesc &rFrom, SwPageDesc &rDest);
259     void MoveFrom(SwPageDesc &rFrom, SwPageDesc &rDest);
260 public:
empty() const261     bool empty() const { return maSegments.empty(); }
size() const262     int size() const { return maSegments.size(); }
263     void push_back(const rtfSection &rSect);
pop_back()264     void pop_back() { maSegments.pop_back(); }
back()265     rtfSection& back() { return maSegments.back(); }
back() const266     const rtfSection& back() const { return maSegments.back(); }
267     void InsertSegments(bool bIsNewDoc);
rtfSections(SwRTFParser & rReader)268     rtfSections(SwRTFParser &rReader) : mrReader(rReader) {}
269     std::vector<sal_uInt16> maDummyPageNos;
270     typedef std::vector<sal_uInt16>::reverse_iterator myrDummyIter;
271     void PrependedInlineNode(const SwPosition &rPos,
272         const SwNode &rNode);
273 };
274 
275 
276 
277 
278 class SwRTFParser : public SvxRTFParser
279 {
280     /*
281      Knows which writer style a given word style should be imported as.
282     */
283     sw::util::ParaStyleMapper maParaStyleMapper;
284     sw::util::CharStyleMapper maCharStyleMapper;
285 
286     std::vector<String> aRevTbl;
287 
288     friend class rtfSections;
289     DocPageInformation maPageDefaults;
290     rtfSections maSegments;
291 
292     sw::util::InsertedTablesManager maInsertedTables;
293 	SwRTFStyleTbl aTxtCollTbl;
294 	SwRTFCharStyleTbl aCharFmtTbl;
295 	SwFlySaveArr aFlyArr;				// Flys als Letzes im Doc setzen
296 	SvBools aMergeBoxes;				// Flags fuer gemergte Zellen
297 	SwListArr aListArr;
298 	SvPtrarr aRubyCharFmts;
299 	BookmarkPosition* mpBookmarkStart;
300     sw::util::RedlineStack *mpRedlineStack;
301     sw::util::AuthorInfos* pAuthorInfos;
302 
303 	SfxItemSet* pGrfAttrSet;
304 	SwTableNode* pTableNode, *pOldTblNd; // fuers Lesen von Tabellen: akt. Tab
305 	SwNodeIndex* pSttNdIdx;
306 	SwNodeIndex* pRegionEndIdx;
307 	SwDoc* 	pDoc;
308 	SwPaM*	pPam;				// SwPosition duerfte doch reichen, oder ??
309 	SwRelNumRuleSpaces* pRelNumRule;	// Liste aller benannten NumRules
310 
311     String sNestedFieldStr;
312     SwFltRedline *pRedlineInsert;
313     SwFltRedline *pRedlineDelete;
314 
315     String sBaseURL;
316 
317 	sal_uInt16 nAktPageDesc, nAktFirstPageDesc;
318     sal_uInt16 m_nCurrentBox;
319 	sal_uInt16 nInsTblRow;		// beim nach \row kein \pard -> neue Line anlegen
320 	sal_uInt16 nNewNumSectDef;	// jeder SectionWechsel kann neue Rules definieren
321     sal_uInt16 nRowsToRepeat;
322 
323 	bool bSwPageDesc;
324 	bool bReadSwFly;		// lese Swg-Fly (wichtig fuer Bitmaps!)
325     // --> OD 2008-12-22 #i83368#
326     bool mbReadCellWhileReadSwFly;
327     // <--
328 	bool mbReadNoTbl;		// verhinder Tabelle in Tabelle/FootNote
329     bool mbIsFootnote;
330 	bool bFootnoteAutoNum;	// automatische Numerierung ?
331 	bool bStyleTabValid;	// Styles schon erzeugt ?
332 	bool bInPgDscTbl;		// beim PageDescTbl lesen
333 	bool bNewNumList;		// Word 7.0 NumList gelesen, 6.0 ueberspringen
334 	bool bFirstContinue;	// 1.Call ins Continue
335     bool bContainsPara;     // If there is no paragraph in the section
336     bool bContainsTablePara;     // If there is an table in this section
337     bool bForceNewTable;     // Forces a beginning of a new table
338     bool bNestedField;
339 	bool bTrowdRead;         // True, iff an \trowd definition was read after the last \row
340 
341     int nReadFlyDepth;
342 
343 	int nZOrder;
344     /*
345      #i9243#
346      In a footnote tables are not possible (for some obscure reason!)
347     */
CantUseTables() const348     bool CantUseTables() const { return mbReadNoTbl || mbIsFootnote; }
349 
350 	virtual void InsertPara();
351 	virtual void InsertText();
352 	virtual void MovePos( int bForward = sal_True );
353 	virtual void SetEndPrevPara( SvxNodeIdx*& rpNodePos, xub_StrLen& rCntPos );
354     void EnterEnvironment();
355     void LeaveEnvironment();
356 
357     SwFmtPageDesc* GetCurrentPageDesc(SwPaM *pPam);
358 	void CheckInsNewTblLine();
359 
360 	// setze RTF-Werte auf Swg-Werte
361 	void SetSwgValues( SfxItemSet& rSet );
362 
363 	virtual void ReadInfo( const sal_Char* pChkForVerNo = 0 );
364 
365     void ReadUserProperties();
366 
367 	void ReadListLevel( SwNumRule& rRule, sal_uInt8 nLvl );
368 	void SetBorderLine(SvxBoxItem& rBox, sal_uInt16 nLine);
369 	void ReadListTable();
370     sal_uInt16 ReadRevTbl();
371     void ReadShpRslt();
372     void ReadShpTxt(String &shpTxt);
373     void ReadDrawingObject();
374 	void InsertShpObject(SdrObject* pStroke, int nZOrder);
375     void ReadShapeObject();
376 	void ReadListOverrideTable();
377 	SwNumRule *ReadNumSecLevel( int nToken );
378 	SwNumRule* GetNumRuleOfListNo( long nListNo,
379 									sal_Bool bRemoveFromList = sal_False );
380 	void RemoveUnusedNumRule( SwNumRule* );
381 	void RemoveUnusedNumRules();
382 	const Font* FindFontOfItem( const SvxFontItem& rItem ) const;
383 
384 	// 3 Methoden zum Aufbauen der Styles
385 	SwTxtFmtColl* MakeColl( const String&, sal_uInt16 nPos, sal_uInt8 nOutlineLevel,
386 							bool& rbCollExist );
387 	SwCharFmt* MakeCharFmt( const String& rName, sal_uInt16 nPos,
388 							int& rbCollExist );
389 	void SetStyleAttr( SfxItemSet& rCollSet,
390 						const SfxItemSet& rStyleSet,
391 						const SfxItemSet& rDerivedSet );
392     SwTxtFmtColl* MakeStyle( sal_uInt16 nNo, const SvxRTFStyleType& rStyle );
393 	SwCharFmt* MakeCharStyle( sal_uInt16 nNo, const SvxRTFStyleType& rStyle );
394 	void MakeStyleTab();
395 
396 	int MakeFieldInst( String& rFieldStr );
397 
398 	// einlesen/einfuegen von Bitmaps
399 	void InsPicture( const String& rNm,
400 					const Graphic* = 0, const SvxRTFPictureType* = 0 );
401 	void _SetPictureSize( const SwNoTxtNode& rNd, const SwNodeIndex& rAnchor,
402 							SfxItemSet& rSet, const SvxRTFPictureType* = 0  );
403 
404 	void SetFlysInDoc();
405 	void GetPageSize( Size& rSize );		// Groesse der PagePrintArea
406 
407 	// fuers Einlesen von Tabellen
408 	void GotoNextBox();
409 	void NewTblLine();
410 
411 	void DelLastNode();			// loesche den letzten Node (Tabelle/Fly/Ftn/..)
412 
413 	void AddNumRule( SwNumRule* pRule );
414 	void SetNumRelSpaces();
415 	void SetOultineRelSpaces( const SwNodeIndex& rStt,
416 								const SwNodeIndex& rEnd );
417 	void SetNumLSpace( SwTxtNode& rNd, const SwNodeNum& rNum,
418 								const SwNumRule& rRule );
419     long GetSafePos(long nPos);
420 
421 protected:
422 	// wird fuer jedes Token gerufen, das in CallParser erkannt wird
423 	virtual void NextToken( int nToken );
424 
425 //	virtual void ReadUnknownData();
426 	virtual void ReadBitmapData();
427 #ifdef READ_OLE_OBJECT
428 	virtual void ReadOLEData();
429 #endif
430 	virtual	void SetAttrInDoc( SvxRTFItemStackType &rSet );
431     virtual bool UncompressableStackEntry(const SvxRTFItemStackType &rSet) const;
432 	// fuer Tokens, die im ReadAttr nicht ausgewertet werden
433 	virtual void UnknownAttrToken( int nToken, SfxItemSet* pSet );
434 
435 	void ReadPrtData();
436 	void ReadField();
437     void ReadXEField();
438 	void ReadHeaderFooter( int nToken, SwPageDesc* pPageDesc = 0 );
439 	void ReadDocControls( int nToken );
440 	void SetPageInformationAsDefault(const DocPageInformation &rInfo);
441 	void ReadSectControls( int nToken );
442 	void DoHairyWriterPageDesc(int nToken);
443 	void ReadFly( int nToken, SfxItemSet* pFillSet = 0 );
444 	void ReadTable( int nToken );
445 	void ReadPageDescTbl();
446     void SkipPageDescTbl();
447     bool IsBorderToken(int nToken);
448 
GetBaseURL() const449     const String& GetBaseURL() const { return sBaseURL;}
450 
451 	virtual ~SwRTFParser();
452 
453 public:
454 	SwRTFParser( SwDoc* pD,
455         ::com::sun::star::uno::Reference<
456             ::com::sun::star::document::XDocumentProperties> i_xDocProps,
457         const SwPaM& rCrsr, SvStream& rIn,
458         const String& rBaseURL,
459         int bReadNewDoc = sal_True );
460 
461 	virtual SvParserState CallParser();	// Aufruf des Parsers
462 	virtual int IsEndPara( SvxNodeIdx* pNd, xub_StrLen nCnt ) const;
463 
464 	// fuers asynchrone lesen aus dem SvStream
465 //	virtual void SaveState( int nToken );
466 //	virtual void RestoreState();
467 	virtual void Continue( int nToken );
468 };
469 
470 
471 #endif
472 
473 /* vi:set tabstop=4 shiftwidth=4 expandtab: */
474