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