xref: /aoo41x/main/sw/source/filter/ww8/wrtww8.hxx (revision 6d87d7f9)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
28 
29 #ifndef _WRTWW8_HXX
30 #define _WRTWW8_HXX
31 
32 #include <tools/solar.h>        // UINTXX
33 #include <tools/gen.hxx>
34 #ifndef _SVSTDARR_HXX
35 #define _SVSTDARR_ULONGS
36 #include <svl/svstdarr.hxx>
37 #endif
38 #include <editeng/editdata.hxx>
39 
40 #include <map>
41 #include <vector>
42 
43 #include <shellio.hxx>
44 #include <wrt_fn.hxx>
45 #include <filter/msfilter/msocximex.hxx>
46 
47 #include "ww8struc.hxx"
48 #include "ww8scan.hxx"
49 #include "fields.hxx"
50 #include "types.hxx"
51 #include "writerhelper.hxx"
52 #include "../inc/msfilter.hxx"
53 #include <expfld.hxx>
54 
55 // einige Forward Deklarationen
56 namespace msfilter
57 {
58     class MSCodec_Std97;
59 }
60 
61 class WW8SwAttrIter;
62 class AttributeOutputBase;
63 class DocxAttributeOutput;
64 class RtfAttributeOutput;
65 class BitmapPalette;
66 class SwEscherEx;
67 class DateTime;
68 class Font;
69 class MSWordExportBase;
70 class SdrObject;
71 class SfxItemSet;
72 class SvStream;
73 class SvxBorderLine;
74 class SvxFontItem;
75 class SvxBoxItem;
76 class SwAttrSet;
77 class SwCharFmt;
78 class SwCntntNode;
79 class SwField;
80 class SwFmt;
81 class SwFmtCntnt;
82 class SwFmtFtn;
83 class SwFrmFmt;
84 class SwGrfNode;
85 class SwModify;
86 class SwNumFmt;
87 class SwNumRule;
88 class SwNumRuleTbl;
89 class SwPageDesc;
90 class SwFmtPageDesc;
91 class SwOLENode;
92 class SwPostItField;
93 class SwRedlineData;
94 class SwSection;
95 class SwSectionFmt;
96 class SwSectionNode;
97 class SwTableNode;
98 class SwTOXType;
99 class SwTxtAttr;
100 class SwTxtFmtColl;
101 class SwTxtNode;
102 class SwWW8WrGrf;
103 class SwWW8Writer;
104 class MSWordStyles;
105 class WW8AttributeOutput;
106 class WW8Bytes;
107 class WW8Export;
108 class MSWordAttrIter;
109 class WW8_WrFkp;
110 class WW8_WrPlc0;
111 class WW8_WrPlc1;
112 class WW8_WrPlcFld;
113 class WW8_WrMagicTable;
114 class WW8_WrPlcFtnEdn;
115 class WW8_WrPlcPn;
116 class WW8_WrPlcAnnotations;
117 class MSWordSections;
118 class WW8_WrPlcTxtBoxes;
119 class WW8_WrPct;            // Verwaltung
120 class WW8_WrPcPtrs;
121 class WW8_WrtBookmarks;
122 class WW8_WrtRedlineAuthor;
123 class SvxMSExportOLEObjects;
124 class SwMSConvertControls;
125 class WW8OleMaps;
126 class SvStorageRef;
127 struct WW8_PdAttrDesc;
128 class SvxBrushItem;
129 
130 #include "WW8TableInfo.hxx"
131 
132 #define GRF_MAGIC_1 0x12    // 3 magic Bytes fuer PicLocFc-Attribute
133 #define GRF_MAGIC_2 0x34
134 #define GRF_MAGIC_3 0x56
135 #define GRF_MAGIC_321 0x563412L
136 
137 #define OLE_PREVIEW_AS_EMF  //If we want to export ole2 previews as emf in ww8+
138 
139 typedef sal_uInt8 FieldFlags;
140 namespace nsFieldFlags // for InsertField- Method
141 {
142     const FieldFlags WRITEFIELD_START         = 0x01;
143     const FieldFlags WRITEFIELD_CMD_START     = 0x02;
144     const FieldFlags WRITEFIELD_CMD_END     = 0x04;
145     const FieldFlags WRITEFIELD_END         = 0x10;
146     const FieldFlags WRITEFIELD_CLOSE         = 0x20;
147     const FieldFlags WRITEFIELD_ALL         = 0xFF;
148 }
149 
150 enum TxtTypes  //enums for TextTypes
151 {
152     TXT_MAINTEXT = 0, /*TXT_FTNEDN = 1,*/ TXT_HDFT = 2, TXT_FTN = 3,
153     TXT_EDN = 4, TXT_ATN = 5, TXT_TXTBOX = 6, TXT_HFTXTBOX= 7
154 };
155 
156 SV_DECL_VARARR( WW8Bytes, sal_uInt8, 128, 128 )
157 
158 struct WW8_SepInfo
159 {
160     const SwPageDesc* pPageDesc;
161     const SwSectionFmt* pSectionFmt;
162     const SwNode* pPDNd;
163     const SwTxtNode* pNumNd;
164     sal_uLong  nLnNumRestartNo;
165     sal_uInt16 nPgRestartNo;
166 
167     WW8_SepInfo()
168         : pPageDesc(0), pSectionFmt(0), pPDNd(0), pNumNd(0), nLnNumRestartNo(0), nPgRestartNo(0)
169 
170     {}
171 
172     WW8_SepInfo( const SwPageDesc* pPD, const SwSectionFmt* pFmt,
173         sal_uLong nLnRestart, sal_uInt16 nPgRestart = 0, const SwNode* pNd = NULL )
174         : pPageDesc( pPD ), pSectionFmt( pFmt ), pPDNd( pNd ), pNumNd( 0 ),
175           nLnNumRestartNo( nLnRestart ), nPgRestartNo( nPgRestart )
176     {}
177 
178     bool IsProtected() const;
179 };
180 
181 SV_DECL_VARARR( WW8_WrSepInfoPtrs, WW8_SepInfo, 4, 4 )
182 
183 /// Class to collect and output the sections/headers/footers.
184 // Plc fuer PageDescs -> Sepx ( Section Extensions )
185 class MSWordSections
186 {
187 protected:
188     bool mbDocumentIsProtected;
189     WW8_WrSepInfoPtrs aSects;   // PTRARR von SwPageDesc und SwSectionFmt
190 
191     void CheckForFacinPg( WW8Export& rWrt ) const;
192     void WriteOlst( WW8Export& rWrt, const WW8_SepInfo& rSectionInfo );
193     void NeedsDocumentProtected(const WW8_SepInfo &rInfo);
194 
195     //No copy, no assign
196     MSWordSections( const MSWordSections& );
197     MSWordSections& operator=( const MSWordSections& );
198 public:
199     MSWordSections( MSWordExportBase& rExport );
200     virtual ~MSWordSections();
201 
202     void AppendSection( const SwPageDesc* pPd,
203                     const SwSectionFmt* pSectionFmt = 0,
204                     sal_uLong nLnNumRestartNo = 0 );
205     void AppendSection( const SwFmtPageDesc& rPd,
206                     const SwNode& rNd,
207                     const SwSectionFmt* pSectionFmt,
208                     sal_uLong nLnNumRestartNo );
209     void SetNum( const SwTxtNode* pNumNd );
210 
211     /// Number of columns based on the most recent WW8_SepInfo.
212     sal_uInt16 CurrentNumberOfColumns( const SwDoc &rDoc ) const;
213 
214     /// Number of columns of the provided WW8_SepInfo.
215     sal_uInt16 NumberOfColumns( const SwDoc &rDoc, const WW8_SepInfo& rInfo ) const;
216 
217     bool DocumentIsProtected() const { return mbDocumentIsProtected; }
218 
219     /// The most recent WW8_SepInfo.
220     const WW8_SepInfo* CurrentSectionInfo();
221 
222     static void SetHeaderFlag( sal_uInt8& rHeadFootFlags, const SwFmt& rFmt,
223                                   sal_uInt8 nFlag );
224     static void SetFooterFlag( sal_uInt8& rHeadFootFlags, const SwFmt& rFmt,
225                                    sal_uInt8 nFlag );
226 
227     /// Should we output borders?
228     static int HasBorderItem( const SwFmt& rFmt );
229 };
230 
231 class WW8_WrPlcSepx : public MSWordSections
232 {
233     SvULongs aCps;              // PTRARR von CPs
234     WW8_PdAttrDesc* pAttrs;
235     WW8_WrPlc0* pTxtPos;        // Pos der einzelnen Header / Footer
236 
237     // No copy, no assign
238     WW8_WrPlcSepx( const WW8_WrPlcSepx& );
239     WW8_WrPlcSepx& operator=( const WW8_WrPlcSepx& );
240 
241 public:
242     WW8_WrPlcSepx( MSWordExportBase& rExport );
243     ~WW8_WrPlcSepx();
244 
245     void AppendSep( WW8_CP nStartCp,
246                     const SwPageDesc* pPd,
247                     const SwSectionFmt* pSectionFmt = 0,
248                     sal_uLong nLnNumRestartNo = 0 );
249     void AppendSep( WW8_CP nStartCp, const SwFmtPageDesc& rPd,
250                     const SwNode& rNd,
251                     const SwSectionFmt* pSectionFmt,
252                     sal_uLong nLnNumRestartNo );
253     void Finish( WW8_CP nEndCp ) { aCps.Insert( nEndCp, aCps.Count() ); }
254 
255     bool WriteKFTxt( WW8Export& rWrt );
256     void WriteSepx( SvStream& rStrm ) const;
257     void WritePlcSed( WW8Export& rWrt ) const;
258     void WritePlcHdd( WW8Export& rWrt ) const;
259 
260 private:
261     void WriteFtnEndTxt( WW8Export& rWrt, sal_uLong nCpStt );
262 public:
263     void OutHeaderFooter(WW8Export& rWrt, bool bHeader,
264             const SwFmt& rFmt, sal_uLong& rCpPos, sal_uInt8 nHFFlags, sal_uInt8 nFlag,  sal_uInt8 nBreakCode);
265 };
266 
267 //--------------------------------------------------------------------------
268 // class WW8_WrPct zum Aufbau der Piece-Table
269 //--------------------------------------------------------------------------
270 class WW8_WrPct
271 {
272     WW8_WrPcPtrs* pPcts;
273     WW8_FC nOldFc;
274     bool bIsUni;
275 public:
276     WW8_WrPct(WW8_FC nStartFc, bool bSaveUniCode);
277     ~WW8_WrPct();
278     void AppendPc(WW8_FC nStartFc, bool bIsUnicode);
279     void WritePc( WW8Export& rWrt );
280     void SetParaBreak();
281     bool IsUnicode() const  { return bIsUni; }
282     WW8_CP Fc2Cp( sal_uLong nFc ) const;
283 };
284 
285 /// Collects and outputs fonts.
286 class wwFont
287 {
288 //In some future land the stream could be converted to a nice stream interface
289 //and we could have harmony
290 private:
291     sal_uInt8 maWW8_FFN[6];
292     String msFamilyNm;
293     String msAltNm;
294     bool mbAlt;
295     bool mbWrtWW8;
296     FontPitch mePitch;
297     FontFamily meFamily;
298     rtl_TextEncoding meChrSet;
299 public:
300     wwFont( const String &rFamilyName, FontPitch ePitch, FontFamily eFamily,
301         rtl_TextEncoding eChrSet, bool bWrtWW8 );
302     bool Write( SvStream *pTableStram ) const;
303 #ifdef DOCX
304     void WriteDocx( const DocxAttributeOutput* rAttrOutput ) const;
305 #endif
306     void WriteRtf( const RtfAttributeOutput* rAttrOutput ) const;
307     rtl::OUString GetFamilyName() const { return rtl::OUString( msFamilyNm ); }
308     friend bool operator < (const wwFont &r1, const wwFont &r2);
309 };
310 
311 class wwFontHelper
312 {
313 private:
314     /// Keep track of fonts that need to be exported.
315     ::std::map<wwFont, sal_uInt16> maFonts;
316     bool mbWrtWW8;
317 
318     /// Convert from fast insertion map to linear vector in the order that we want to write.
319     ::std::vector< const wwFont* > AsVector() const;
320 
321 public:
322     wwFontHelper() : mbWrtWW8(false), bLoadAllFonts(false) {}
323     /// rDoc used only to get the initial standard font(s) in use.
324     void InitFontTable(bool bWrtWW8, const SwDoc& rDoc);
325     sal_uInt16 GetId(const Font& rFont);
326     sal_uInt16 GetId(const SvxFontItem& rFont);
327     sal_uInt16 GetId(const wwFont& rFont);
328     void WriteFontTable( SvStream *pTableStream, WW8Fib& pFib );
329 #ifdef DOCX
330     void WriteFontTable( const DocxAttributeOutput& rAttrOutput );
331 #endif
332     void WriteFontTable( const RtfAttributeOutput& rAttrOutput );
333 
334     /// If true, all fonts are loaded before processing the document.
335     sal_uInt8 bLoadAllFonts: 1;
336 };
337 
338 class DrawObj
339 {
340 public:
341     WW8_CP mnCp;                // CP-Pos der Verweise
342     sal_uInt32 mnShapeId;           // ShapeId for the SwFrmFmts
343     sw::Frame maCntnt;          // the frame itself
344     Point maParentPos;          // Points
345     sal_Int32 mnThick;              // Border Thicknesses
346     short mnDirection;          // If BiDi or not
347     unsigned int mnHdFtIndex;   // 0 for main text, +1 for each subsequent
348                                 // msword hd/ft
349 
350     DrawObj(const sw::Frame &rCntnt, WW8_CP nCp, Point aParentPos, short nDir,
351             unsigned int nHdFtIndex)
352         : mnCp(nCp), mnShapeId(0), maCntnt(rCntnt), maParentPos(aParentPos),
353         mnThick(0), mnDirection(nDir), mnHdFtIndex(nHdFtIndex) {}
354     void SetShapeDetails(sal_uInt32 nId, sal_Int32 nThick);
355     DrawObj& operator=(const DrawObj &rOther);
356 };
357 
358 typedef std::vector<DrawObj> DrawObjVector;
359 typedef DrawObjVector::iterator DrawObjIter;
360 typedef DrawObjVector::const_iterator cDrawObjIter;
361 
362 typedef std::vector<DrawObj *> DrawObjPointerVector;
363 typedef DrawObjPointerVector::iterator DrawObjPointerIter;
364 
365 class PlcDrawObj // PC for DrawObjects and Text-/OLE-/GRF-Boxes
366 {
367 private:
368     DrawObjVector maDrawObjs;  // vector of drawobjs
369 protected:
370     virtual void RegisterWithFib(WW8Fib &rFib, sal_uInt32 nStart,
371         sal_uInt32 nLen) const = 0;
372     virtual WW8_CP GetCpOffset(const WW8Fib &rFib) const = 0;
373 public:
374     PlcDrawObj() {}
375     void WritePlc( WW8Export& rWrt ) const;
376     bool Append( WW8Export&, WW8_CP nCp, const sw::Frame& rFmt,
377         const Point& rNdTopLeft );
378     int size() { return maDrawObjs.size(); };
379     DrawObjVector &GetObjArr() { return maDrawObjs; }
380     virtual ~PlcDrawObj();
381 private:
382     //No copying
383     PlcDrawObj(const PlcDrawObj&);
384     PlcDrawObj& operator=(const PlcDrawObj&);
385 };
386 
387 class MainTxtPlcDrawObj : public PlcDrawObj
388 {
389 public:
390     MainTxtPlcDrawObj() {}
391 private:
392     virtual void RegisterWithFib(WW8Fib &rFib, sal_uInt32 nStart,
393         sal_uInt32 nLen) const;
394     virtual WW8_CP GetCpOffset(const WW8Fib &) const;
395 private:
396     //No copying
397     MainTxtPlcDrawObj(const MainTxtPlcDrawObj&);
398     MainTxtPlcDrawObj& operator=(const MainTxtPlcDrawObj&);
399 };
400 
401 class HdFtPlcDrawObj : public PlcDrawObj
402 {
403 public:
404     HdFtPlcDrawObj() {}
405 private:
406     virtual void RegisterWithFib(WW8Fib &rFib, sal_uInt32 nStart,
407         sal_uInt32 nLen) const;
408     virtual WW8_CP GetCpOffset(const WW8Fib &rFib) const;
409 private:
410     //No copying
411     HdFtPlcDrawObj(const HdFtPlcDrawObj&);
412     HdFtPlcDrawObj& operator=(const HdFtPlcDrawObj&);
413 };
414 
415 typedef ::std::pair<String, sal_uLong> aPair;
416 typedef std::vector<aPair> SwImplBookmarks;
417 typedef std::vector<aPair>::iterator SwImplBookmarksIter;
418 
419 class WW8_WrtRedlineAuthor : public sw::util::WrtRedlineAuthor
420 {
421     public:
422     virtual void Write(Writer &rWrt);
423 };
424 
425 /** Structure that is used to save some of the WW8Export/DocxExport data.
426 
427     It is used to be able to recurse inside of the WW8Export/DocxExport (eg.
428     for the needs of the tables) - you need to tall WriteText() from there with
429     new values of PaM etc.
430 
431     It must contain all the stuff that might be saved either in WW8Export or in
432     DocxExport, because it makes no sense to do it abstract, and specialize it
433     for each of the cases.  If you implement other *Export, just add the needed
434     members here, and store them in the appropriate SaveData() method.
435  */
436 struct MSWordSaveData
437 {
438     Point* pOldFlyOffset;
439     RndStdIds eOldAnchorType;
440     WW8Bytes* pOOld;                ///< WW8Export only
441     WW8Bytes* mpTableAtOld;         ///< WW8Export only: Additional buffer for the output of the tables
442     sal_uInt16 mnTableStdAtLenOld;  ///< WW8Export only: Standard length of mpTableAt
443     SwPaM* pOldPam, *pOldEnd;
444     const sw::Frame* pOldFlyFmt;
445     const SwPageDesc* pOldPageDesc;
446 
447     sal_uInt8 bOldWriteAll : 1;          ///< WW8Export only
448     sal_uInt8 bOldOutTable : 1;
449     sal_uInt8 bOldIsInTable: 1;
450     sal_uInt8 bOldFlyFrmAttrs : 1;
451     sal_uInt8 bOldStartTOX : 1;
452     sal_uInt8 bOldInWriteTOX : 1;
453     // bOutPageDesc muss nicht gesichert werden, da es nur nicht waehrend der
454     // Ausgabe von Spezial-Texten veraendert wird.
455 };
456 
457 /// Base class for WW8Export and DocxExport
458 class MSWordExportBase
459 {
460 public:
461     wwFontHelper maFontHelper;
462     std::vector<sal_uLong> maChapterFieldLocs;
463     typedef std::vector<sal_uLong>::const_iterator mycCFIter;
464     String aMainStg;
465     SvPtrarr aTOXArr;
466     const SfxItemSet* pISet;    // fuer Doppel-Attribute
467     WW8_WrPct*  pPiece;         // Pointer auf Piece-Table
468     SwNumRuleTbl* pUsedNumTbl;  // alle used NumRules
469     const SwTxtNode *mpTopNodeOfHdFtPage; ///< Top node of host page when in hd/ft
470     std::map< sal_uInt16, sal_uInt16 > aRuleDuplicates; //map to Duplicated numrules
471     std::stack< xub_StrLen > m_aCurrentCharPropStarts; ///< To remember the position in a run.
472     WW8_WrtBookmarks* pBkmks;
473     WW8_WrtRedlineAuthor* pRedlAuthors;
474     BitmapPalette* pBmpPal;
475     boost::shared_ptr<NfKeywordTable> pKeyMap;
476     SvxMSExportOLEObjects* pOLEExp;
477     SwMSConvertControls* pOCXExp;
478     WW8OleMaps* pOleMap;
479     ww8::WW8TableInfo::Pointer_t mpTableInfo;
480 
481     sal_uInt16 nCharFmtStart;
482     sal_uInt16 nFmtCollStart;
483     sal_uInt16 nStyleBeforeFly;     ///< Style-Nummer des Nodes,
484                                 ///<       in/an dem ein Fly verankert ist
485     sal_uInt16 nLastFmtId;          ///< Style of last TxtNode in normal range
486     sal_uInt16 nUniqueList;         ///< current number for creating unique list names
487     unsigned int mnHdFtIndex;
488 
489     sal_uInt16 mnRedlineMode;       ///< Remember the original redline mode
490 
491 public:
492     /* implicit bookmark vector containing pairs of node indexes and bookmark names */
493     SwImplBookmarks maImplicitBookmarks;
494     sw::Frames maFrames;             // The floating frames in this document
495     const SwPageDesc *pAktPageDesc;
496     WW8_WrPlcPn* pPapPlc;
497     WW8_WrPlcPn* pChpPlc;
498     MSWordAttrIter* pChpIter;
499     MSWordStyles* pStyles;
500     WW8_WrPlcAnnotations* pAtn;
501     WW8_WrPlcTxtBoxes *pTxtBxs, *pHFTxtBxs;
502 
503     const sw::Frame *mpParentFrame; //If set we are exporting content inside
504                                     //a frame, e.g. a graphic node
505 
506     Point* pFlyOffset;              // zur Justierung eines im Writer als
507     RndStdIds eNewAnchorType;       // Zeichen gebundenen Flys, der im WW
508                                     // Absatzgebunden wird.
509 
510     WW8_WrPlcFld* pFldMain;         // Felder im Haupttext
511     WW8_WrPlcFld* pFldHdFt;         // Felder in Header/Footer
512     WW8_WrPlcFld* pFldFtn;          // Felder in FootNotes
513     WW8_WrPlcFld* pFldEdn;          // Felder in EndNotes
514     WW8_WrPlcFld* pFldAtn;          // Felder in Annotations
515     WW8_WrPlcFld* pFldTxtBxs;       // fields in textboxes
516     WW8_WrPlcFld* pFldHFTxtBxs;     // fields in header/footer textboxes
517     WW8_WrMagicTable *pMagicTable;  // keeps track of table cell positions, and
518                                     // marks those that contain graphics,
519                                     // which is required to make word display
520                                     // graphics inside tables
521     SwWW8WrGrf* pGrf;
522     const SwAttrSet* pStyAttr;      // StyleAttr fuer Tabulatoren
523     const SwModify* pOutFmtNode;    // write Format or Node
524     const SwFmt *pCurrentStyle;     // iff bStyDef=true, then this store the current style
525 
526     MainTxtPlcDrawObj *pSdrObjs;   // Draw-/Fly-Objects
527     HdFtPlcDrawObj *pHFSdrObjs;     // Draw-/Fly-Objects in header or footer
528 
529     SwEscherEx* pEscher;            // escher export class
530     // --> OD 2007-04-19 #i43447# - removed
531 //    SwTwips nFlyWidth, nFlyHeight;  // Fuer Anpassung Graphic
532     // <--
533 
534     sal_uInt8 nTxtTyp;
535 
536     sal_uInt8 bStyDef : 1;           // wird Style geschrieben ?
537     sal_uInt8 bBreakBefore : 1;      // Breaks werden 2mal ausgegeben
538     sal_uInt8 bOutKF : 1;            // Kopf/Fusstexte werden ausgegeben
539     sal_uInt8 bOutFlyFrmAttrs : 1;   // Rahmen-Attr von Flys werden ausgegeben
540     sal_uInt8 bOutPageDescs : 1;     ///< PageDescs (section properties) are being written
541     sal_uInt8 bOutFirstPage : 1;     // write Attrset of FirstPageDesc
542     sal_uInt8 bOutTable : 1;         // Tabelle wird ausgegeben
543                                 //    ( wird zB bei Flys in Tabelle zurueckgesetzt )
544     sal_uInt8 bOutGrf : 1;           // Grafik wird ausgegeben
545     sal_uInt8 bInWriteEscher : 1;    // in write textboxes
546     sal_uInt8 bStartTOX : 1;         // true: a TOX is startet
547     sal_uInt8 bInWriteTOX : 1;       // true: all content are in a TOX
548     sal_uInt8 bFtnAtTxtEnd : 1;      // true: all FTN at Textend
549     sal_uInt8 bEndAtTxtEnd : 1;      // true: all END at Textend
550     sal_uInt8 bHasHdr : 1;
551     sal_uInt8 bHasFtr : 1;
552     sal_uInt8 bSubstituteBullets : 1; // true: SubstituteBullet() gets called
553 
554     bool mbExportModeRTF;
555     bool mbOutOutlineOnly;   // export outline nodes, only (send outline to clipboard/presentation)
556 
557     SwDoc *pDoc;
558     SwPaM *pCurPam, *pOrigPam;
559 
560     /// Stack to remember the nesting (see MSWordSaveData for more)
561     ::std::stack< MSWordSaveData > maSaveData;
562 
563     /// Used to split the runs according to the bookmarks start and ends
564     typedef std::vector< ::sw::mark::IMark* > IMarkVector;
565     IMarkVector m_rSortedMarksStart;
566     IMarkVector m_rSortedMarksEnd;
567 
568 public:
569     /// The main function to export the document.
570     void ExportDocument( bool bWriteAll );
571 
572     /// Iterate through the nodes and call the appropriate OutputNode() on them.
573     void WriteText();
574 
575     /// Return whether cuurently exported node is in table.
576     bool IsInTable() const;
577 
578     /// Set the pCurPam appropriately and call WriteText().
579     ///
580     /// Used to export paragraphs in footnotes/endnotes/etc.
581     void WriteSpecialText( sal_uLong nStart, sal_uLong nEnd, sal_uInt8 nTTyp );
582 
583     /// Export the pool items to attributes (through an attribute output class).
584     void ExportPoolItemsToCHP( sw::PoolItems &rItems, sal_uInt16 nScript );
585 
586     /// Return the numeric id of the numbering rule
587     sal_uInt16 GetId( const SwNumRule& rNumRule );
588 
589     /// Return the numeric id of the style.
590     sal_uInt16 GetId( const SwTxtFmtColl& rColl ) const;
591 
592     /// Return the numeric id of the style.
593     sal_uInt16 GetId( const SwCharFmt& rFmt ) const;
594 
595     sal_uInt16 GetId( const SwTOXType& rTOXType );
596 
597     const SfxPoolItem& GetItem( sal_uInt16 nWhich ) const;
598 
599     /// Find the reference.
600     bool HasRefToObject( sal_uInt16 nTyp, const String* pName, sal_uInt16 nSeqNo );
601 
602     /// Find the bookmark name.
603     String GetBookmarkName( sal_uInt16 nTyp, const String* pName, sal_uInt16 nSeqNo );
604 
605     /// Add a bookmark converted to a Word name.
606     void AppendWordBookmark( const String& rName );
607 
608     /// Use OutputItem() on an item set according to the parameters.
609     void OutputItemSet( const SfxItemSet& rSet, bool bPapFmt, bool bChpFmt, sal_uInt16 nScript, bool bExportParentItemSet );
610 
611     short GetDefaultFrameDirection( ) const;
612 
613     /// Right to left?
614     short TrueFrameDirection( const SwFrmFmt& rFlyFmt ) const;
615 
616     /// Right to left?
617     short GetCurrentPageDirection() const;
618 
619     /// In case of numbering restart.
620 
621     /// List is set to restart at a particular value so for export make a
622     /// completely new list based on this one and export that instead,
623     /// which duplicates words behaviour in this respect.
624     sal_uInt16 DuplicateNumRule( const SwNumRule *pRule, sal_uInt8 nLevel, sal_uInt16 nVal );
625 
626     /// Access to the attribute output class.
627     virtual AttributeOutputBase& AttrOutput() const = 0;
628 
629     /// Access to the sections/headers/footres.
630     virtual MSWordSections& Sections() const = 0;
631 
632     /// Hack, unfortunately necessary at some places for now.
633     /// FIXME remove it when possible.
634     virtual bool HackIsWW8OrHigher() const = 0;
635 
636     /// Guess the script (asian/western).
637     ///
638     /// Sadly word does not have two different sizes for asian font size and
639     /// western font size, it has two different fonts, but not sizes, so we
640     /// have to use our guess as to the script used and disable the export of
641     /// one type. The same occurs for font weight and posture (bold and
642     /// italic).
643     ///
644     /// In addition WW7- has only one character language identifier while WW8+
645     /// has two
646     virtual bool CollapseScriptsforWordOk( sal_uInt16 nScript, sal_uInt16 nWhich ) = 0;
647 
648     virtual void AppendBookmarks( const SwTxtNode& rNd, xub_StrLen nAktPos, xub_StrLen nLen ) = 0;
649 
650     virtual void AppendBookmark( const rtl::OUString& rName, bool bSkip = false ) = 0;
651 
652     // FIXME probably a hack...
653     virtual void WriteCR( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner = ww8::WW8TableNodeInfoInner::Pointer_t() ) = 0;
654 
655     // FIXME definitely a hack, must not be here - it can't do anything
656     // sensible for docx
657     virtual void WriteChar( sal_Unicode c ) = 0;
658 
659     /// Output attributes.
660     void OutputFormat( const SwFmt& rFmt, bool bPapFmt, bool bChpFmt, bool bFlyFmt = false );
661 
662     /// Getter for pISet.
663     const SfxItemSet* GetCurItemSet() const { return pISet; }
664 
665     /// Setter for pISet.
666     void SetCurItemSet( const SfxItemSet* pS ) { pISet = pS; }
667 
668     /// Remember some of the memebers so that we can recurse in WriteText().
669     virtual void SaveData( sal_uLong nStt, sal_uLong nEnd );
670 
671     /// Restore what was saved in SaveData().
672     virtual void RestoreData();
673 
674     /// The return value indicates, if a follow page desc is written.
675     bool OutputFollowPageDesc( const SfxItemSet* pSet,
676                                const SwTxtNode* pNd );
677 
678     /// Write header/footer text.
679     void WriteHeaderFooterText( const SwFmt& rFmt, bool bHeader);
680 
681     /// Format of the section.
682     const SwSectionFmt* GetSectionFormat( const SwNode& rNd ) const;
683 
684     /// Line number of the section start.
685     sal_uLong GetSectionLineNo( const SfxItemSet* pSet, const SwNode& rNd ) const;
686 
687     /// Start new section.
688     void OutputSectionBreaks( const SfxItemSet *pSet, const SwNode& rNd );
689 
690     /// Write section properties.
691     ///
692     /// pA is ignored for docx.
693     void SectionProperties( const WW8_SepInfo& rSectionInfo, WW8_PdAttrDesc* pA = NULL );
694 
695     /// Output the numbering table.
696     virtual void WriteNumbering() = 0;
697 
698     /// Write static data of SwNumRule - LSTF
699     void NumberingDefinitions();
700 
701     /// Write all Levels for all SwNumRules - LVLF
702     void AbstractNumberingDefinitions();
703 
704     // Convert the bullet according to the font.
705     void SubstituteBullet( String& rNumStr, rtl_TextEncoding& rChrSet,
706         String& rFontName ) const;
707 
708     /// No-op for the newer WW versions.
709     virtual void OutputOlst( const SwNumRule& /*rRule*/ ) {}
710 
711     /// Setup the pA's info.
712     virtual void SetupSectionPositions( WW8_PdAttrDesc* /*pA*/ ) {}
713 
714     /// Top node of host page when in header/footer.
715     void SetHdFtPageRoot( const SwTxtNode *pNd ) { mpTopNodeOfHdFtPage = pNd; }
716 
717     /// Top node of host page when in header/footer.
718     const SwTxtNode *GetHdFtPageRoot() const { return mpTopNodeOfHdFtPage; }
719 
720     /// Output the actual headers and footers.
721     virtual void WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
722             const SwFrmFmt& rFmt, const SwFrmFmt& rLeftFmt, const SwFrmFmt& rFirstPageFmt,
723 	    sal_uInt8 nBreakCode) = 0;
724 
725     /// Write the field
726     virtual void OutputField( const SwField* pFld, ww::eField eFldType,
727             const String& rFldCmd, sal_uInt8 nMode = nsFieldFlags::WRITEFIELD_ALL ) = 0;
728 
729     /// Write the data of the form field
730     virtual void WriteFormData( const ::sw::mark::IFieldmark& rFieldmark ) = 0;
731     virtual void WriteHyperlinkData( const ::sw::mark::IFieldmark& rFieldmark ) = 0;
732 
733     virtual void DoComboBox(const rtl::OUString &rName,
734                     const rtl::OUString &rHelp,
735                     const rtl::OUString &ToolTip,
736                     const rtl::OUString &rSelected,
737                     com::sun::star::uno::Sequence<rtl::OUString> &rListItems) = 0;
738 
739     virtual void DoFormText(const SwInputField * pFld) = 0;
740 
741     static bool NoPageBreakSection( const SfxItemSet *pSet );
742 
743     // Compute the number format for WW dates
744     bool GetNumberFmt(const SwField& rFld, String& rStr);
745 
746     virtual sal_uLong ReplaceCr( sal_uInt8 nChar ) = 0;
747 
748     const SfxPoolItem* HasItem( sal_uInt16 nWhich ) const;
749 
750 
751 protected:
752     /// Format-dependant part of the actual export.
753     virtual void ExportDocument_Impl() = 0;
754 
755     /// Get the next position in the text node to output
756     virtual xub_StrLen GetNextPos( WW8SwAttrIter* pAttrIter, const SwTxtNode& rNode, xub_StrLen nAktPos );
757 
758     /// Update the information for GetNextPos().
759     virtual void UpdatePosition( WW8SwAttrIter* pAttrIter, xub_StrLen nAktPos, xub_StrLen nEnd );
760 
761     /// Output SwTxtNode
762     void OutputTextNode( const SwTxtNode& );
763 
764     /// Output SwTableNode
765     void OutputTableNode( const SwTableNode& );
766 
767     /// Setup the chapter fields (maChapterFieldLocs).
768     void GatherChapterFields();
769 
770     void AddLinkTarget( const String& rURL );
771     void CollectOutlineBookmarks( const SwDoc &rDoc );
772 
773     bool SetAktPageDescFromNode(const SwNode &rNd);
774     bool CntntContainsChapterField(const SwFmtCntnt &rCntnt) const;
775     bool FmtHdFtContainsChapterField(const SwFrmFmt &rFmt) const;
776 
777     virtual void SectionBreaksAndFrames( const SwTxtNode& rNode ) = 0;
778 
779     virtual void PrepareNewPageDesc( const SfxItemSet* pSet,
780                                      const SwNode& rNd,
781                                      const SwFmtPageDesc* pNewPgDescFmt = 0,
782                                      const SwPageDesc* pNewPgDesc = 0 ) = 0;
783 
784     /// Return value indicates if an inherited outline numbering is suppressed.
785     virtual bool DisallowInheritingOutlineNumbering(const SwFmt &rFmt) = 0;
786 
787 protected:
788     /// Output SwStartNode
789     virtual void OutputStartNode( const SwStartNode& );
790 
791     /// Output SwEndNode
792     virtual void OutputEndNode( const SwEndNode& );
793 
794     /// Output SwGrfNode
795     virtual void OutputGrfNode( const SwGrfNode& ) = 0;
796 
797     /// Output SwOLENode
798     virtual void OutputOLENode( const SwOLENode& ) = 0;
799 
800     /// Output SwSectionNode
801     virtual void OutputSectionNode( const SwSectionNode& );
802 
803     virtual void AppendSection( const SwPageDesc *pPageDesc, const SwSectionFmt* pFmt, sal_uLong nLnNum ) = 0;
804 
805     /// Call the right (virtual) function according to the type of the item.
806     ///
807     /// One of OutputTextNode(), OutputGrfNode(), or OutputOLENode()
808     void OutputContentNode( const SwCntntNode& );
809 
810     /// Find the nearest bookmark from the current position.
811     ///
812     /// Returns false when there is no bookmark.
813     bool NearestBookmark( xub_StrLen& rNearest, const xub_StrLen nAktPos, bool bNextPositionOnly );
814 
815     void GetSortedBookmarks( const SwTxtNode& rNd, xub_StrLen nAktPos,
816                 xub_StrLen nLen );
817 
818     bool GetBookmarks( const SwTxtNode& rNd, xub_StrLen nStt, xub_StrLen nEnd,
819             IMarkVector& rArr );
820 
821     const NfKeywordTable & GetNfKeywordTable();
822 
823 public:
824     MSWordExportBase( SwDoc *pDocument, SwPaM *pCurrentPam, SwPaM *pOriginalPam );
825     virtual ~MSWordExportBase();
826 
827     // TODO move as much as possible here from WW8Export! ;-)
828 
829     static void CorrectTabStopInSet( SfxItemSet& rSet, sal_uInt16 nAbsLeft );
830 
831 private:
832     /// No copying.
833     MSWordExportBase( const MSWordExportBase& );
834     /// No copying.
835     MSWordExportBase& operator=( const MSWordExportBase& );
836 };
837 
838 /// The writer class that gets called for the WW8 filter.
839 class SwWW8Writer: public StgWriter
840 {
841 // friends to get access to m_pExport
842 // FIXME avoid that, this is probably not what we want
843 // (if yes, remove the friends, and provide here a GetExport() method)
844 friend void WW8_WrtRedlineAuthor::Write(Writer &rWrt);
845 
846     bool       m_bWrtWW8;
847     WW8Export *m_pExport;
848     SfxMedium *mpMedium;
849 
850 public:
851     SwWW8Writer( const String& rFltName, const String& rBaseURL );
852     virtual ~SwWW8Writer();
853 
854     virtual sal_uLong WriteStorage();
855     virtual sal_uLong WriteMedium( SfxMedium& );
856 
857     // TODO most probably we want to be able to get these in
858     // MSExportFilterBase
859     using Writer::getIDocumentSettingAccess;
860 
861 public:
862 #if 1
863     /// Prefer ww::bytes to WW8Bytes, migrate away from the other ones.
864     static void InsUInt16(ww::bytes &rO, sal_uInt16 n);
865     static void InsUInt32(ww::bytes &rO, sal_uInt32 n);
866     static void InsAsString16(ww::bytes &rO, const String& rStr);
867     static void InsAsString8(ww::bytes & O, const String& rStr,
868         rtl_TextEncoding eCodeSet);
869 #endif
870 
871     static void InsUInt16( WW8Bytes& rO, sal_uInt16 );
872     static void InsUInt32( WW8Bytes& rO, sal_uInt32 );
873     static void InsAsString16( WW8Bytes& rO, const String& );
874     static void InsAsString8( WW8Bytes& rO, const String& rStr,
875                                 rtl_TextEncoding eCodeSet );
876 
877     static sal_uLong FillUntil( SvStream& rStrm, sal_uLong nEndPos = 0 );
878     static void FillCount( SvStream& rStrm, sal_uLong nCount );
879 
880     static void WriteShort( SvStream& rStrm, sal_Int16 nVal ) { rStrm << nVal; }
881     static void WriteShort( SvStream& rStrm, sal_uLong nPos, sal_Int16 nVal );
882 
883     static void WriteLong( SvStream& rStrm, sal_Int32 nVal ) { rStrm << nVal; }
884     static void WriteLong( SvStream& rStrm, sal_uLong nPos, sal_Int32 nVal );
885 
886     static void WriteString16(SvStream& rStrm, const String& rStr,
887         bool bAddZero);
888     static void WriteString8(SvStream& rStrm, const String& rStr,
889         bool bAddZero, rtl_TextEncoding eCodeSet);
890 
891     static void WriteString_xstz(SvStream& rStrm, const String& rStr, bool bAddZero);
892 
893     bool InitStd97CodecUpdateMedium( ::msfilter::MSCodec_Std97& rCodec );
894 
895     using StgWriter::Write;
896     virtual sal_uLong Write( SwPaM&, SfxMedium&, const String* = 0 );
897 
898 private:
899     /// No copying.
900     SwWW8Writer(const SwWW8Writer&);
901     /// No copying.
902     SwWW8Writer& operator=(const SwWW8Writer&);
903 };
904 
905 /// Exporter of the binary Word file formats.
906 class WW8Export : public MSWordExportBase
907 {
908 public:
909     WW8Bytes* pO;                       ///< Buffer
910     WW8Bytes* mpTableAt;                ///< Additional buffer for the output of the tables
911     sal_uInt16 mnTableStdAtLen;         ///< Standard length of mpTableAt
912 
913     SvStream *pTableStrm, *pDataStrm;   ///< Streams for WW97 Export
914 
915     WW8Fib* pFib;                       ///< File Information Block
916     WW8Dop* pDop;                       ///< DOcument Properties
917     WW8_WrPlcFtnEdn *pFtn;              ///< Footnotes - structure to remember them, and output
918     WW8_WrPlcFtnEdn *pEdn;              ///< Endnotes - structure to remember them, and output
919     WW8_WrPlcSepx* pSepx;               ///< Sections/headers/footers
920 
921     sal_uInt8 bWrtWW8 : 1;                   ///< Write WW95 (false) or WW97 (true) file format
922 
923 protected:
924     SwWW8Writer        *m_pWriter;      ///< Pointer to the writer
925     WW8AttributeOutput *m_pAttrOutput;  ///< Converting attributes to stream data
926 
927 public:
928     /// Access to the attribute output class.
929     virtual AttributeOutputBase& AttrOutput() const;
930 
931     /// Access to the sections/headers/footres.
932     virtual MSWordSections& Sections() const;
933 
934     /// False for WW6, true for WW8.
935     virtual bool HackIsWW8OrHigher() const { return bWrtWW8; }
936 
937 private:
938     /// Format-dependant part of the actual export.
939     virtual void ExportDocument_Impl();
940 
941     void PrepareStorage();
942     void WriteFkpPlcUsw();
943     void WriteMainText();
944     void StoreDoc1();
945     void Out_WwNumLvl( sal_uInt8 nWwLevel );
946     void BuildAnlvBulletBase( WW8_ANLV& rAnlv, sal_uInt8*& rpCh, sal_uInt16& rCharLen,
947                               const SwNumFmt& rFmt );
948     static void BuildAnlvBase( WW8_ANLV& rAnlv, sal_uInt8*& rpCh, sal_uInt16& rCharLen,
949                    const SwNumRule& rRul, const SwNumFmt& rFmt, sal_uInt8 nSwLevel );
950 
951     void Out_BorderLine(WW8Bytes& rO, const SvxBorderLine* pLine,
952         sal_uInt16 nDist, sal_uInt16 nSprmNo, bool bShadow);
953 
954     /// Output the numbering table.
955     virtual void WriteNumbering();
956 
957     void OutOverrideListTab();
958     void OutListNamesTab();
959 
960     void RestoreMacroCmds();
961 
962     void InitFontTable();
963 
964     void DoComboBox(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> xPropSet);
965     void DoCheckBox(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> xPropSet);
966 
967 public:
968     virtual void OutputOlst( const SwNumRule& rRule );
969 
970     /// Setup the pA's info.
971     virtual void SetupSectionPositions( WW8_PdAttrDesc* pA );
972 
973     void Out_SwNumLvl( sal_uInt8 nSwLevel );
974     void Out_NumRuleAnld( const SwNumRule& rRul, const SwNumFmt& rFmt,
975                           sal_uInt8 nSwLevel );
976 
977     bool MiserableFormFieldExportHack(const SwFrmFmt& rFrmFmt);
978 
979     SvxMSExportOLEObjects& GetOLEExp()      { return *pOLEExp; }
980     SwMSConvertControls& GetOCXExp()        { return *pOCXExp; }
981     WW8OleMaps& GetOLEMap()                 { return *pOleMap; }
982     void ExportDopTypography(WW8DopTypography &rTypo);
983 
984     using MSWordExportBase::GetId;
985     sal_uInt16 GetId( const SvxFontItem& rFont)
986     {
987         return maFontHelper.GetId(rFont);
988     }
989 
990     sal_uInt16 AddRedlineAuthor( sal_uInt16 nId );
991 
992     void WriteFtnBegin( const SwFmtFtn& rFtn, WW8Bytes* pO = 0 );
993     void WritePostItBegin( WW8Bytes* pO = 0 );
994     const SvxBrushItem* GetCurrentPageBgBrush() const;
995     SvxBrushItem TrueFrameBgBrush(const SwFrmFmt &rFlyFmt) const;
996 
997     /// Output all textframes anchored as character for the winword 7- format.
998     void OutWW6FlyFrmsInCntnt( const SwTxtNode& rNd );
999 
1000     void AppendFlyInFlys(const sw::Frame& rFrmFmt, const Point& rNdTopLeft);
1001     void WriteOutliner(const OutlinerParaObject& rOutliner, sal_uInt8 nTyp);
1002     void WriteSdrTextObj(const SdrObject& rObj, sal_uInt8 nTyp);
1003 
1004     sal_uInt32 GetSdrOrdNum( const SwFrmFmt& rFmt ) const;
1005     void CreateEscher();
1006     void WriteEscher();
1007 
1008     bool Out_SwNum(const SwTxtNode* pNd);
1009 
1010     /// Write the field
1011     virtual void OutputField( const SwField* pFld, ww::eField eFldType,
1012             const String& rFldCmd, sal_uInt8 nMode = nsFieldFlags::WRITEFIELD_ALL );
1013 
1014     void StartCommentOutput( const String& rName );
1015     void EndCommentOutput(   const String& rName );
1016     void OutGrf(const sw::Frame &rFrame);
1017     bool TestOleNeedsGraphic(const SwAttrSet& rSet, SvStorageRef xOleStg,
1018         SvStorageRef xObjStg, String &rStorageName, SwOLENode *pOLENd);
1019 
1020     virtual void AppendBookmarks( const SwTxtNode& rNd, xub_StrLen nAktPos, xub_StrLen nLen );
1021     virtual void AppendBookmark( const rtl::OUString& rName, bool bSkip = false );
1022     void MoveFieldMarks(sal_uLong nFrom, sal_uLong nTo);
1023 
1024     void WriteAsStringTable(const ::std::vector<String>&, sal_Int32& rfcSttbf,
1025         sal_Int32& rlcbSttbf, sal_uInt16 nExtraLen = 0);
1026 
1027     virtual sal_uLong ReplaceCr( sal_uInt8 nChar );
1028 
1029     virtual void WriteCR( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner = ww8::WW8TableNodeInfoInner::Pointer_t() );
1030     void WriteChar( sal_Unicode c );
1031 #if 0
1032     sal_uInt16 StartTableFromFrmFmt(WW8Bytes &rAt, const SwFrmFmt *pFmt,
1033         SwTwips &rPageSize);
1034 #endif
1035 
1036     void OutSwString(const String&, xub_StrLen nStt, xub_StrLen nLen,
1037         bool bUnicode, rtl_TextEncoding eChrSet);
1038 
1039     WW8_CP Fc2Cp( sal_uLong nFc ) const          { return pPiece->Fc2Cp( nFc ); }
1040 
1041             // einige z.T. static halb-interne Funktions-Deklarationen
1042 
1043     void OutSprmBytes( sal_uInt8* pBytes, sal_uInt16 nSiz )
1044                                 { pO->Insert( pBytes, nSiz, pO->Count() ); }
1045 
1046     inline bool IsUnicode() const           { return pPiece->IsUnicode(); }
1047 
1048     virtual void SectionBreaksAndFrames( const SwTxtNode& rNode );
1049 
1050     /// Helper method for OutputSectionBreaks() and OutputFollowPageDesc().
1051     // OD 2007-05-29 #i76300#
1052     virtual void PrepareNewPageDesc( const SfxItemSet* pSet,
1053                                      const SwNode& rNd,
1054                                      const SwFmtPageDesc* pNewPgDescFmt = 0,
1055                                      const SwPageDesc* pNewPgDesc = 0 );
1056 
1057     void Out_SwFmtBox(const SvxBoxItem& rBox, bool bShadow);
1058     void Out_SwFmtTableBox( WW8Bytes& rO, const SvxBoxItem * rBox );
1059     sal_uInt8 TransCol( const Color& rCol );
1060     bool TransBrush(const Color& rCol, WW8_SHD& rShd);
1061     WW8_BRC TranslateBorderLine(const SvxBorderLine& pLine,
1062         sal_uInt16 nDist, bool bShadow);
1063 
1064     // --> OD 2007-06-04 #i77805#
1065     // new return value indicates, if an inherited outline numbering is suppressed
1066     virtual bool DisallowInheritingOutlineNumbering(const SwFmt &rFmt);
1067     // <--
1068 
1069     unsigned int GetHdFtIndex() const { return mnHdFtIndex; }
1070     void SetHdFtIndex(unsigned int nHdFtIndex) { mnHdFtIndex = nHdFtIndex; }
1071     void IncrementHdFtIndex() { ++mnHdFtIndex; }
1072 
1073     static long GetDTTM( const DateTime& rDT );
1074 
1075     /// Convert the SVX numbering type to id
1076     static sal_uInt8 GetNumId( sal_uInt16 eNumType );
1077 
1078     /// Guess the script (asian/western).
1079     virtual bool CollapseScriptsforWordOk( sal_uInt16 nScript, sal_uInt16 nWhich );
1080 
1081     sal_uInt16 DupNumRuleWithLvlStart(const SwNumRule *pRule,sal_uInt8 nLvl,sal_uInt16 nVal);
1082 
1083     SwTwips CurrentPageWidth(SwTwips &rLeft, SwTwips &rRight) const;
1084 
1085     /// Nasty swap for bidi if neccessary
1086     bool MiserableRTLFrmFmtHack(SwTwips &rLeft, SwTwips &rRight,
1087         const sw::Frame &rFrmFmt);
1088 
1089     void InsUInt16( sal_uInt16 n )      { SwWW8Writer::InsUInt16( *pO, n ); }
1090     void InsUInt32( sal_uInt32 n )      { SwWW8Writer::InsUInt32( *pO, n ); }
1091     void InsAsString16( const String& rStr )
1092                         { SwWW8Writer::InsAsString16( *pO, rStr ); }
1093     void InsAsString8( const String& rStr, rtl_TextEncoding eCodeSet )
1094                         { SwWW8Writer::InsAsString8( *pO, rStr, eCodeSet ); }
1095     void WriteStringAsPara( const String& rTxt, sal_uInt16 nStyleId = 0 );
1096 
1097     /// Setup the exporter.
1098     WW8Export( SwWW8Writer *pWriter,
1099             SwDoc *pDocument, SwPaM *pCurrentPam, SwPaM *pOriginalPam,
1100             bool bIsWW8 );
1101     virtual ~WW8Export();
1102 
1103     virtual void DoComboBox(const rtl::OUString &rName,
1104                     const rtl::OUString &rHelp,
1105                     const rtl::OUString &ToolTip,
1106                     const rtl::OUString &rSelected,
1107                     com::sun::star::uno::Sequence<rtl::OUString> &rListItems);
1108 
1109     virtual void DoFormText(const SwInputField * pFld);
1110 
1111     void GetCurrentItems(WW8Bytes &rItems) const;
1112 
1113     /// Write the data of the form field
1114     virtual void WriteFormData( const ::sw::mark::IFieldmark& rFieldmark );
1115     virtual void WriteHyperlinkData( const ::sw::mark::IFieldmark& rFieldmark );
1116 
1117     /// Fields.
1118     WW8_WrPlcFld* CurrentFieldPlc() const;
1119 
1120     SwWW8Writer& GetWriter() const { return *m_pWriter; }
1121     SvStream& Strm() const { return m_pWriter->Strm(); }
1122 
1123     /// Remember some of the memebers so that we can recurse in WriteText().
1124     virtual void SaveData( sal_uLong nStt, sal_uLong nEnd );
1125 
1126     /// Restore what was saved in SaveData().
1127     virtual void RestoreData();
1128 
1129     /// Output the actual headers and footers.
1130     virtual void WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
1131             const SwFrmFmt& rFmt, const SwFrmFmt& rLeftFmt, const SwFrmFmt& rFirstPageFmt,
1132 	    sal_uInt8 nBreakCode);
1133 
1134 protected:
1135     /// Output SwGrfNode
1136     virtual void OutputGrfNode( const SwGrfNode& );
1137 
1138     /// Output SwOLENode
1139     virtual void OutputOLENode( const SwOLENode& );
1140 
1141     virtual void AppendSection( const SwPageDesc *pPageDesc, const SwSectionFmt* pFmt, sal_uLong nLnNum );
1142 
1143 private:
1144     /// No copying.
1145     WW8Export(const WW8Export&);
1146     /// No copying.
1147     WW8Export& operator=(const WW8Export&);
1148 };
1149 
1150 class WW8_WrPlcSubDoc   // Doppel-Plc fuer Foot-/Endnotes und Postits
1151 {
1152 private:
1153     //No copying
1154     WW8_WrPlcSubDoc(const WW8_WrPlcSubDoc&);
1155     WW8_WrPlcSubDoc& operator=(const WW8_WrPlcSubDoc&);
1156 protected:
1157     SvULongs aCps;                  // PTRARR CP-Pos der Verweise
1158     SvPtrarr aCntnt;                // PTRARR von SwFmtFtn/PostIts/..
1159     WW8_WrPlc0* pTxtPos;            // Pos der einzelnen Texte
1160 
1161     WW8_WrPlcSubDoc();
1162     virtual ~WW8_WrPlcSubDoc();
1163 
1164     bool WriteGenericTxt( WW8Export& rWrt, sal_uInt8 nTTyp, WW8_CP& rCount );
1165     void WriteGenericPlc( WW8Export& rWrt, sal_uInt8 nTTyp, WW8_FC& rTxtStt,
1166         sal_Int32& rTxtCnt, WW8_FC& rRefStt, sal_Int32& rRefCnt ) const;
1167 
1168     virtual const SvULongs* GetShapeIdArr() const;
1169 };
1170 
1171 // Doppel-Plc fuer Footnotes/Endnotes
1172 class WW8_WrPlcFtnEdn : public WW8_WrPlcSubDoc
1173 {
1174 private:
1175     sal_uInt8 nTyp;
1176 
1177     //No copying
1178     WW8_WrPlcFtnEdn(const WW8_WrPlcFtnEdn&);
1179     WW8_WrPlcFtnEdn& operator=(WW8_WrPlcFtnEdn &);
1180 public:
1181     WW8_WrPlcFtnEdn( sal_uInt8 nTTyp ) : nTyp( nTTyp ) {}
1182 
1183     bool WriteTxt( WW8Export& rWrt );
1184     void WritePlc( WW8Export& rWrt ) const;
1185 
1186     void Append( WW8_CP nCp, const SwFmtFtn& rFtn );
1187 };
1188 
1189 struct WW8_Annotation
1190 {
1191     const OutlinerParaObject* mpRichText;
1192     String msSimpleText;
1193     String msOwner;
1194     DateTime maDateTime;
1195     WW8_Annotation(const SwPostItField* pPostIt);
1196     WW8_Annotation(const SwRedlineData* pRedline);
1197 };
1198 
1199 class WW8_WrPlcAnnotations : public WW8_WrPlcSubDoc  // Doppel-Plc fuer PostIts
1200 {
1201 private:
1202     //No copying
1203     WW8_WrPlcAnnotations(const WW8_WrPlcAnnotations&);
1204     WW8_WrPlcAnnotations& operator=(WW8_WrPlcAnnotations&);
1205     std::set<const SwRedlineData*> maProcessedRedlines;
1206 public:
1207     WW8_WrPlcAnnotations() {}
1208     ~WW8_WrPlcAnnotations();
1209 
1210     void Append( WW8_CP nCp, const SwPostItField* pPostIt );
1211     void Append( WW8_CP nCp, const SwRedlineData* pRedLine );
1212     bool IsNewRedlineComment( const SwRedlineData* pRedLine );
1213     bool WriteTxt( WW8Export& rWrt );
1214     void WritePlc( WW8Export& rWrt ) const;
1215 };
1216 
1217 class WW8_WrPlcTxtBoxes : public WW8_WrPlcSubDoc // Doppel-Plc fuer Textboxen
1218 {                        // Rahmen/DrawTextboxes!
1219 private:
1220     sal_uInt8 nTyp;
1221     SvULongs aShapeIds;        // VARARR of ShapeIds for the SwFrmFmts
1222     virtual const SvULongs* GetShapeIdArr() const;
1223 
1224     //No copying
1225     WW8_WrPlcTxtBoxes(const WW8_WrPlcTxtBoxes&);
1226     WW8_WrPlcTxtBoxes& operator=(WW8_WrPlcTxtBoxes&);
1227 public:
1228     WW8_WrPlcTxtBoxes( sal_uInt8 nTTyp ) : nTyp( nTTyp ) {}
1229 
1230     bool WriteTxt( WW8Export& rWrt );
1231     void WritePlc( WW8Export& rWrt ) const;
1232     void Append( const SdrObject& rObj, sal_uInt32 nShapeId );
1233     sal_uInt16 Count() const { return aCntnt.Count(); }
1234     sal_uInt16 GetPos( const VoidPtr& p ) const { return aCntnt.GetPos( p ); }
1235 };
1236 
1237 typedef WW8_WrFkp* WW8_FkpPtr;  // Plc fuer Chpx und Papx ( incl PN-Plc )
1238 SV_DECL_PTRARR( WW8_WrFkpPtrs, WW8_FkpPtr, 4, 4 )
1239 
1240 class WW8_WrPlcPn                   // Plc fuer Page Numbers
1241 {
1242 private:
1243     WW8Export& rWrt;
1244     WW8_WrFkpPtrs aFkps;            // PTRARR
1245     sal_uInt16 nFkpStartPage;
1246     ePLCFT ePlc;
1247     bool bWrtWW8;                   // Fuer Writererkennung
1248     sal_uInt16 nMark;
1249 
1250     //No copying
1251     WW8_WrPlcPn(const WW8_WrPlcPn&);
1252     WW8_WrPlcPn& operator=(const WW8_WrPlcPn&);
1253 public:
1254     WW8_WrPlcPn( WW8Export& rWrt, ePLCFT ePl, WW8_FC nStartFc );
1255     ~WW8_WrPlcPn();
1256     void AppendFkpEntry(WW8_FC nEndFc,short nVarLen = 0,const sal_uInt8* pSprms = 0);
1257     void WriteFkps();
1258     void WritePlc();
1259     sal_uInt8 *CopyLastSprms(sal_uInt8 &rLen);
1260 };
1261 
1262 // class WW8_WrPlc1 ist erstmal nur fuer Felder
1263 class WW8_WrPlc1
1264 {
1265 private:
1266     SvULongs aPos;              // PTRARR von CPs
1267     sal_uInt8* pData;                // Inhalte ( Strukturen )
1268     sal_uLong nDataLen;
1269     sal_uInt16 nStructSiz;
1270 
1271     //No copying
1272     WW8_WrPlc1(const WW8_WrPlc1&);
1273     WW8_WrPlc1& operator=(const WW8_WrPlc1&);
1274 protected:
1275     sal_uInt16 Count() const { return aPos.Count(); }
1276     void Write( SvStream& rStrm );
1277     WW8_CP Prev() const;
1278 public:
1279     WW8_WrPlc1( sal_uInt16 nStructSz );
1280     ~WW8_WrPlc1();
1281     void Append( WW8_CP nCp, const void* pData );
1282     void Finish( sal_uLong nLastCp, sal_uLong nStartCp );
1283 };
1284 
1285 // class WW8_WrPlcFld ist fuer Felder
1286 class WW8_WrPlcFld : public WW8_WrPlc1
1287 {
1288 private:
1289     sal_uInt8 nTxtTyp;
1290     sal_uInt16 nResults;
1291 
1292     //No copying
1293     WW8_WrPlcFld(const WW8_WrPlcFld&);
1294     WW8_WrPlcFld& operator=(const WW8_WrPlcFld&);
1295 public:
1296     WW8_WrPlcFld( sal_uInt16 nStructSz, sal_uInt8 nTTyp )
1297         : WW8_WrPlc1( nStructSz ), nTxtTyp( nTTyp ), nResults(0)
1298     {}
1299     bool Write( WW8Export& rWrt );
1300     void ResultAdded() { ++nResults; }
1301     sal_uInt16 ResultCount() const { return nResults; }
1302 };
1303 
1304 class WW8_WrMagicTable : public WW8_WrPlc1
1305 {
1306 private:
1307     //No copying
1308     WW8_WrMagicTable(const WW8_WrMagicTable&);
1309     WW8_WrMagicTable& operator=(const WW8_WrMagicTable&);
1310 public:
1311     WW8_WrMagicTable() : WW8_WrPlc1( 4 ) {Append(0,0);}
1312     void Append( WW8_CP nCp, sal_uLong nData );
1313     bool Write( WW8Export& rWrt );
1314 };
1315 
1316 class GraphicDetails
1317 {
1318 public:
1319     sw::Frame maFly;            // Umgebende FlyFrms dazu
1320     sal_uLong mnPos;                // FilePos der Grafiken
1321     sal_uInt16 mnWid;               // Breite der Grafiken
1322     sal_uInt16 mnHei;               // Hoehe der Grafiken
1323 
1324     GraphicDetails(const sw::Frame &rFly, sal_uInt16 nWid, sal_uInt16 nHei)
1325         : maFly(rFly), mnPos(0), mnWid(nWid), mnHei(nHei)
1326     {}
1327     GraphicDetails& operator=(const GraphicDetails& rOther);
1328 
1329     bool operator==(const GraphicDetails& rIn) const
1330     {
1331         return (
1332                  (mnWid == rIn.mnWid) && (mnHei == rIn.mnHei) &&
1333                  (maFly.RefersToSameFrameAs(rIn.maFly))
1334                );
1335     }
1336 };
1337 
1338 // class SwWW8WrGrf sammelt Grafiken und gibt sie aus
1339 class SwWW8WrGrf
1340 {
1341 private:
1342     /// for access to the variables
1343     WW8Export& rWrt;
1344 
1345     std::vector<GraphicDetails> maDetails;
1346     typedef std::vector<GraphicDetails>::iterator myiter;
1347     sal_uInt16 mnIdx;       // Index in File-Positionen
1348 
1349     void WritePICFHeader(SvStream& rStrm, const sw::Frame &rFly,
1350             sal_uInt16 mm, sal_uInt16 nWidth, sal_uInt16 nHeight,
1351             const SwAttrSet* pAttrSet = 0);
1352     void WriteGraphicNode(SvStream& rStrm, const GraphicDetails &rItem);
1353     void WriteGrfFromGrfNode(SvStream& rStrm, const SwGrfNode &rNd,
1354         const sw::Frame &rFly, sal_uInt16 nWidth, sal_uInt16 nHeight);
1355 
1356     //No copying
1357     SwWW8WrGrf(const SwWW8WrGrf&);
1358     SwWW8WrGrf& operator=(const SwWW8WrGrf&);
1359 public:
1360     SwWW8WrGrf( WW8Export& rW ) : rWrt( rW ), mnIdx( 0 ) {}
1361     void Insert(const sw::Frame &rFly);
1362     void Write();
1363     sal_uLong GetFPos()
1364         { return (mnIdx < maDetails.size()) ? maDetails[mnIdx++].mnPos : 0; }
1365 };
1366 
1367 /** The class MSWordAttrIter is a helper class to build the Fkp.chpx.
1368     This class may be overloaded for output the SwTxtAttrs and the
1369     EditEngineTxtAttrs.
1370 */
1371 class MSWordAttrIter
1372 {
1373 private:
1374     MSWordAttrIter* pOld;
1375     //No copying
1376     MSWordAttrIter(const MSWordAttrIter&);
1377     MSWordAttrIter& operator=(const MSWordAttrIter&);
1378 protected:
1379     MSWordExportBase& m_rExport;
1380 public:
1381     MSWordAttrIter( MSWordExportBase& rExport );
1382     virtual ~MSWordAttrIter();
1383 
1384     virtual const SfxPoolItem* HasTextItem( sal_uInt16 nWhich ) const = 0;
1385     virtual const SfxPoolItem& GetItem( sal_uInt16 nWhich ) const = 0;
1386 };
1387 
1388 class MSWord_SdrAttrIter : public MSWordAttrIter
1389 {
1390 private:
1391     const EditTextObject* pEditObj;
1392     const SfxItemPool* pEditPool;
1393     EECharAttribArray aTxtAtrArr;
1394     SvPtrarr aChrTxtAtrArr;
1395     SvUShorts aChrSetArr;
1396     sal_uInt16 nPara;
1397     xub_StrLen nAktSwPos;
1398     xub_StrLen nTmpSwPos;                   // for HasItem()
1399     rtl_TextEncoding eNdChrSet;
1400     sal_uInt16 nScript;
1401     sal_uInt8 mnTyp;
1402 
1403     xub_StrLen SearchNext( xub_StrLen nStartPos );
1404     void SetCharSet(const EECharAttrib& rTxtAttr, bool bStart);
1405 
1406     //No copying
1407     MSWord_SdrAttrIter(const MSWord_SdrAttrIter&);
1408     MSWord_SdrAttrIter& operator=(const MSWord_SdrAttrIter&);
1409 public:
1410     MSWord_SdrAttrIter( MSWordExportBase& rWr, const EditTextObject& rEditObj,
1411         sal_uInt8 nType );
1412     void NextPara( sal_uInt16 nPar );
1413     void OutParaAttr(bool bCharAttr);
1414     void OutEEField(const SfxPoolItem& rHt);
1415 
1416     bool IsTxtAttr(xub_StrLen nSwPos);
1417 
1418     void NextPos() { nAktSwPos = SearchNext( nAktSwPos + 1 ); }
1419 
1420     void OutAttr( xub_StrLen nSwPos );
1421     virtual const SfxPoolItem* HasTextItem( sal_uInt16 nWhich ) const;
1422     virtual const SfxPoolItem& GetItem( sal_uInt16 nWhich ) const;
1423     bool OutAttrWithRange(xub_StrLen nPos);
1424     xub_StrLen WhereNext() const                { return nAktSwPos; }
1425     rtl_TextEncoding GetNextCharSet() const;
1426     rtl_TextEncoding GetNodeCharSet() const     { return eNdChrSet; }
1427 };
1428 
1429 /// Class to collect and output the styles table.
1430 class MSWordStyles
1431 {
1432     MSWordExportBase& m_rExport;
1433     SwFmt** pFmtA;
1434     sal_uInt16 nUsedSlots;
1435 
1436     /// Create the style table, called from the constructor.
1437     void BuildStylesTable();
1438 
1439     /// Get slot number during building the style table.
1440     sal_uInt16 BuildGetSlot( const SwFmt& rFmt );
1441 
1442     /// Return information about one style.
1443     void GetStyleData( SwFmt* pFmt, bool& bFmtColl, sal_uInt16& nBase, sal_uInt16& nNext );
1444 
1445     /// Outputs attributes of one style.
1446     void WriteProperties( const SwFmt* pFmt, bool bPap, sal_uInt16 nPos, bool bInsDefCharSiz );
1447 
1448     sal_uInt16 GetWWId( const SwFmt& rFmt ) const;
1449 
1450     void SetStyleDefaults( const SwFmt& rFmt, bool bPap );
1451 
1452     /// Outputs one style - called (in a loop) from OutputStylesTable().
1453     void OutputStyle( SwFmt* pFmt, sal_uInt16 nPos );
1454 
1455     // No copying
1456     MSWordStyles( const MSWordStyles& );
1457     MSWordStyles& operator=( const MSWordStyles& );
1458 
1459 public:
1460     MSWordStyles( MSWordExportBase& rExport );
1461     ~MSWordStyles();
1462 
1463     /// Output the styles table.
1464     void OutputStylesTable();
1465 
1466     /// Get id of the style (rFmt).
1467     sal_uInt16 GetSlot( const SwFmt& rFmt ) const;
1468 
1469     SwFmt* GetSwFmt() { return (*pFmtA); }
1470 };
1471 
1472 sal_Int16 GetWordFirstLineOffset(const SwNumFmt &rFmt);
1473 //A bit of a bag on the side for now
1474 String FieldString(ww::eField eIndex);
1475 String BookmarkToWord(const String &rBookmark);
1476 
1477 class WW8SHDLong
1478 {
1479     sal_uInt32 m_cvFore;
1480     sal_uInt32 m_cvBack;
1481     sal_uInt16 m_ipat;
1482 
1483 public:
1484     WW8SHDLong() : m_cvFore(0), m_cvBack(0), m_ipat(0) {}
1485     virtual ~WW8SHDLong() {}
1486 
1487     void Write(WW8Export & rExport);
1488     void setCvFore(sal_uInt32 cvFore) { m_cvFore = cvFore; }
1489     void setCvBack(sal_uInt32 cvBack) { m_cvBack = cvBack; }
1490     void setIPat(sal_uInt16 ipat) { m_ipat = ipat; }
1491 };
1492 
1493 /// For the output of sections.
1494 struct WW8_PdAttrDesc
1495 {
1496     sal_uInt8* pData;
1497     sal_uInt16 nLen;
1498     WW8_FC nSepxFcPos;
1499 };
1500 
1501 #endif  //  _WRTWW8_HXX
1502 
1503 /* vi:set tabstop=4 shiftwidth=4 expandtab: */
1504