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