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