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 /// @HTML
25 
26 #ifndef SW_WRITERHELPER
27 #define SW_WRITERHELPER
28 
29 #include <typeinfo>
30 #include <vector>
31 #include <map>
32 #include <com/sun/star/embed/XEmbeddedObject.hpp>
33 
34 #include <sfx2/objsh.hxx>
35 #include "types.hxx"
36 #include <svl/itempool.hxx>     //SfxItemPool
37 #include <svl/itemset.hxx>      //SfxItemSet
38 #include <format.hxx>               //SwFmt
39 #include <node.hxx>                 //SwCntntNode
40 #include <pam.hxx>                  //SwPaM
41 #include <tools/poly.hxx>           //Polygon, PolyPolygon
42 #include <doc.hxx>                  //SwDoc
43 
44 //Uncomment to dump debugging streams of graphics
45 #if OSL_DEBUG_LEVEL > 1
46 //#   define DEBUGDUMP
47 #endif
48 
49 class SwTxtFmtColl;
50 class SwCharFmt;
51 class SdrObject;
52 class SdrOle2Obj;
53 class OutlinerParaObject;
54 class SdrTextObj;
55 class SwNumFmt;
56 class SwTxtNode;
57 class SwNoTxtNode;
58 class SwFmtCharFmt;
59 class Graphic;
60 class SwDoc;
61 class SwNumRule;
62 
63 namespace sw
64 {
65     namespace util
66     {
67         class ItemSort
68             : public std::binary_function<sal_uInt16, sal_uInt16, bool>
69         {
70         public:
71             bool operator()(sal_uInt16 nA, sal_uInt16 nB) const;
72         };
73     }
74 }
75 
76 namespace sw
77 {
78     /// STL container of Paragraph Styles (SwTxtFmtColl)
79     typedef std::vector<SwTxtFmtColl *> ParaStyles;
80     /// STL iterator for ParaStyles
81     typedef ParaStyles::iterator ParaStyleIter;
82     /// STL container of SfxPoolItems (Attributes)
83     typedef std::map<sal_uInt16, const SfxPoolItem *, sw::util::ItemSort> PoolItems;
84     /// STL const iterator for ParaStyles
85     typedef PoolItems::const_iterator cPoolItemIter;
86 
87 
88     /** Make exporting a Writer Frame easy
89 
90         In word all frames are effectively anchored to character or as
91         character. This is nice and simple, writer is massively complex in this
92         area, so this sw::Frame simplies matters by providing a single unified
93         view of the multitute of elements in writer and their differing quirks.
94 
95         A sw::Frame wraps a writer frame and is guaranted to have a suitable
96         anchor position available from it. It hides much of the needless
97         complexity of the multitude of floating/inline elements in writer, it...
98 
99         Guarantees an anchor position for a frame.
100         Provides a readable way to see if we are anchored inline. (as character)
101         Provides a simple way to flag what type of entity this frame describes.
102         Provides the size of the element as drawn by writer.
103 
104         @author
105         <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
106     */
107     class Frame
108     {
109     public:
110         enum WriterSource {eTxtBox, eGraphic, eOle, eDrawing, eFormControl,eBulletGrf};//For i120928,add Grf Bul Type
111     private:
112         const SwFrmFmt* mpFlyFrm;
113         SwPosition maPos;
114         Size maSize;
115         // --> OD 2007-04-19 #i43447#
116         // Size of the frame in the layout.
117         // Especially needed for graphics, whose layout size can differ from its
118         // size, because it is scaled into its environment.
119         Size maLayoutSize;
120         // <--
121         WriterSource meWriterType;
122         const SwNode *mpStartFrameContent;
123         bool mbIsInline;
124 		bool mbForBullet:1;
125 		Graphic maGrf;
126     public:
127         Frame(const SwFrmFmt &rFlyFrm, const SwPosition &rPos);
128 	Frame(const Graphic&, const SwPosition &);
129 	//End
130         /** Get the writer SwFrmFmt that this object describes
131 
132             @return
133             The wrapped SwFrmFmt
134         */
GetFrmFmt() const135         const SwFrmFmt &GetFrmFmt() const { return *mpFlyFrm; }
136 
137         /** Get the position this frame is anchored at
138 
139             @return
140             The anchor position of this frame
141         */
GetPosition() const142         const SwPosition &GetPosition() const { return maPos; }
143 
144         /** Get the node this frame is anchored into
145 
146             @return
147             The SwTxtNode this frame is anchored inside
148         */
GetCntntNode() const149         const SwCntntNode *GetCntntNode() const
150             { return maPos.nNode.GetNode().GetCntntNode(); }
151 
152         /** Get the type of frame that this wraps
153 
154             @return
155             a WriterSource which describes the source type of this wrapper
156         */
GetWriterType() const157         WriterSource GetWriterType() const { return meWriterType; }
158 
159         /** Is this frame inline (as character)
160 
161             @return
162             whether this is inline or not
163         */
164         bool IsInline() const;
165 
166 
167         /** Even if the frame isn't an inline frame, force it to behave as one
168 
169             There are a variety of circumstances where word cannot have
170             anything except inline elements, e.g. inside frames. So its easier
171             to force this sw::Frame into behaving as one, instead of special
172             casing export code all over the place.
173 
174         */
175         void ForceTreatAsInline();
176 
177         /** Get the first node of content in the frame
178 
179          @return
180          the first node of content in the frame, might not be any at all.
181         */
GetContent() const182         const SwNode *GetContent() const { return mpStartFrameContent; }
GetGraphic() const183 	const Graphic &GetGraphic() const { return maGrf; }
HasGraphic() const184 	bool HasGraphic() const { return mbForBullet; }
185 
186 
187         /** Does this sw::Frame refer to the same writer content as another
188 
189          @return
190          if the two sw::Frames are handling the same writer frame
191         */
RefersToSameFrameAs(const Frame & rOther) const192         bool RefersToSameFrameAs(const Frame &rOther) const
193         {
194 		if (mbForBullet && rOther.mbForBullet)
195 			return (maGrf == rOther.maGrf);
196 		else if ((!mbForBullet) && (!rOther.mbForBullet))
197 			return (mpFlyFrm == rOther.mpFlyFrm);
198 
199 		return false;
200         }
201 
202         /** The Size of the contained element
203 
204          @return
205          the best size to use to export to word
206         */
GetSize() const207         const Size GetSize() const { return maSize; }
208 
209         /** The layout size of the contained element
210 
211             OD 2007-04-19 #i43447#
212             Needed for graphics, which are scaled into its environment
213 
214             @return layout size
215         */
GetLayoutSize() const216         const Size GetLayoutSize() const
217         {
218             return maLayoutSize;
219         }
220     };
221 
222     /// STL container of Frames
223     typedef std::vector<Frame> Frames;
224     /// STL iterator for Frames
225     typedef std::vector<Frame>::iterator FrameIter;
226 }
227 
228 namespace sw
229 {
230     namespace util
231     {
232         /** Provide a dynamic_cast style cast for SfxPoolItems
233 
234             A SfxPoolItem generally need to be cast back to its original type
235             to be useful, which is both tedious and errorprone. So item_cast is
236             a helper template to aid the process and test if the cast is
237             correct.
238 
239             @param rItem
240             The SfxPoolItem which is to be casted
241 
242             @tplparam T
243             A SfxPoolItem derived class to cast rItem to
244 
245             @return A rItem upcasted back to a T
246 
247             @exception std::bad_cast Thrown if the rItem was not a T
248 
249             @author
250             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
251         */
item_cast(const SfxPoolItem & rItem)252         template<class T> const T & item_cast(const SfxPoolItem &rItem)
253             throw(std::bad_cast)
254         {
255             if (!rItem.IsA(STATICTYPE(T)))
256                 throw std::bad_cast();
257             return static_cast<const T &>(rItem);
258         }
259 
260         /** Provide a dynamic_cast style cast for SfxPoolItems
261 
262             A SfxPoolItem generally need to be cast back to its original type
263             to be useful, which is both tedious and errorprone. So item_cast is
264             a helper template to aid the process and test if the cast is
265             correct.
266 
267             @param pItem
268             The SfxPoolItem which is to be casted
269 
270             @tplparam T
271             A SfxPoolItem derived class to cast pItem to
272 
273             @return A pItem upcasted back to a T or 0 if pItem was not a T
274 
275             @author
276             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
277         */
item_cast(const SfxPoolItem * pItem)278         template<class T> const T * item_cast(const SfxPoolItem *pItem)
279         {
280             if (pItem && !pItem->IsA(STATICTYPE(T)))
281                 pItem = 0;
282             return static_cast<const T *>(pItem);
283         }
284 
285         /** Extract a SfxPoolItem derived property from a SwCntntNode
286 
287             Writer's attributes are retrieved by passing a numeric identifier
288             and receiving a SfxPoolItem reference which must then typically be
289             cast back to its original type which is both tedious and verbose.
290 
291             ItemGet uses item_cast () on the retrived reference to test that the
292             retrived property is of the type that the developer thinks it is.
293 
294             @param rNode
295             The SwCntntNode to retrieve the property from
296 
297             @param eType
298             The numeric identifier of the property to be retrieved
299 
300             @tplparam T
301             A SfxPoolItem derived class of the retrieved property
302 
303             @exception std::bad_cast Thrown if the property was not a T
304 
305             @return The T requested
306 
307             @author
308             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
309         */
ItemGet(const SwCntntNode & rNode,sal_uInt16 eType)310         template<class T> const T & ItemGet(const SwCntntNode &rNode,
311             sal_uInt16 eType) throw(std::bad_cast)
312         {
313             return item_cast<T>(rNode.GetAttr(eType));
314         }
315 
316         /** Extract a SfxPoolItem derived property from a SwFmt
317 
318             Writer's attributes are retrieved by passing a numeric identifier
319             and receiving a SfxPoolItem reference which must then typically be
320             cast back to its original type which is both tedious and verbose.
321 
322             ItemGet uses item_cast () on the retrived reference to test that the
323             retrived property is of the type that the developer thinks it is.
324 
325             @param rFmt
326             The SwFmt to retrieve the property from
327 
328             @param eType
329             The numeric identifier of the property to be retrieved
330 
331             @tplparam T
332             A SfxPoolItem derived class of the retrieved property
333 
334             @exception std::bad_cast Thrown if the property was not a T
335 
336             @author
337             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
338         */
ItemGet(const SwFmt & rFmt,sal_uInt16 eType)339         template<class T> const T & ItemGet(const SwFmt &rFmt,
340             sal_uInt16 eType) throw(std::bad_cast)
341         {
342             return item_cast<T>(rFmt.GetFmtAttr(eType));
343         }
344 
345         /** Extract a SfxPoolItem derived property from a SfxItemSet
346 
347             Writer's attributes are retrieved by passing a numeric identifier
348             and receiving a SfxPoolItem reference which must then typically be
349             cast back to its original type which is both tedious and verbose.
350 
351             ItemGet uses item_cast () on the retrived reference to test that the
352             retrived property is of the type that the developer thinks it is.
353 
354             @param rSet
355             The SfxItemSet to retrieve the property from
356 
357             @param eType
358             The numeric identifier of the property to be retrieved
359 
360             @tplparam T
361             A SfxPoolItem derived class of the retrieved property
362 
363             @exception std::bad_cast Thrown if the property was not a T
364 
365             @return The T requested
366 
367             @author
368             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
369         */
ItemGet(const SfxItemSet & rSet,sal_uInt16 eType)370         template<class T> const T & ItemGet(const SfxItemSet &rSet,
371             sal_uInt16 eType) throw(std::bad_cast)
372         {
373             return item_cast<T>(rSet.Get(eType));
374         }
375 
376         /** Extract a default SfxPoolItem derived property from a SfxItemPool
377 
378             Writer's attributes are retrieved by passing a numeric identifier
379             and receiving a SfxPoolItem reference which must then typically be
380             cast back to its original type which is both tedious and verbose.
381 
382             DefaultItemGet returns a reference to the default property of a
383             given SfxItemPool for a given property id, e.g. default fontsize
384 
385             DefaultItemGet uses item_cast () on the retrived reference to test
386             that the retrived property is of the type that the developer thinks
387             it is.
388 
389             @param rPool
390             The SfxItemPool whose default property we want
391 
392             @param eType
393             The numeric identifier of the default property to be retrieved
394 
395             @tplparam T
396             A SfxPoolItem derived class of the retrieved property
397 
398             @exception std::bad_cast Thrown if the property was not a T
399 
400             @return The T requested
401 
402             @author
403             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
404         */
DefaultItemGet(const SfxItemPool & rPool,sal_uInt16 eType)405         template<class T> const T & DefaultItemGet(const SfxItemPool &rPool,
406             sal_uInt16 eType) throw(std::bad_cast)
407         {
408             return item_cast<T>(rPool.GetDefaultItem(eType));
409         }
410 
411         /** Extract a default SfxPoolItem derived property from a SwDoc
412 
413             Writer's attributes are retrieved by passing a numeric identifier
414             and receiving a SfxPoolItem reference which must then typically be
415             cast back to its original type which is both tedious and verbose.
416 
417             DefaultItemGet returns a reference to the default property of a
418             given SwDoc (Writer Document) for a given property id, e.g default
419             fontsize
420 
421             DefaultItemGet uses item_cast () on the retrived reference to test
422             that the retrived property is of the type that the developer thinks
423             it is.
424 
425             @param rPool
426             The SfxItemPool whose default property we want
427 
428             @param eType
429             The numeric identifier of the default property to be retrieved
430 
431             @tplparam T
432             A SfxPoolItem derived class of the retrieved property
433 
434             @exception std::bad_cast Thrown if the property was not a T
435 
436             @return The T requested
437 
438             @author
439             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
440         */
DefaultItemGet(const SwDoc & rDoc,sal_uInt16 eType)441         template<class T> const T & DefaultItemGet(const SwDoc &rDoc,
442             sal_uInt16 eType) throw(std::bad_cast)
443         {
444             return DefaultItemGet<T>(rDoc.GetAttrPool(), eType);
445         }
446 
447         /** Return a pointer to a SfxPoolItem derived class if it exists in an
448             SfxItemSet
449 
450             Writer's attributes are retrieved by passing a numeric identifier
451             and receiving a SfxPoolItem reference which must then typically be
452             cast back to its original type which is both tedious and verbose.
453 
454             HasItem returns a pointer to the requested SfxPoolItem for a given
455             property id if it exists in the SfxItemSet or its chain of parents,
456             e.g. fontsize
457 
458             HasItem uses item_cast () on the retrived pointer to test that the
459             retrived property is of the type that the developer thinks it is.
460 
461             @param rSet
462             The SfxItemSet whose property we want
463 
464             @param eType
465             The numeric identifier of the default property to be retrieved
466 
467             @tplparam T
468             A SfxPoolItem derived class of the retrieved property
469 
470             @return The T requested or 0 if no T found with id eType
471 
472             @author
473             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
474         */
HasItem(const SfxItemSet & rSet,sal_uInt16 eType)475         template<class T> const T* HasItem(const SfxItemSet &rSet,
476             sal_uInt16 eType)
477         {
478             return item_cast<T>(rSet.GetItem(eType));
479         }
480 
481         /** Return a pointer to a SfxPoolItem derived class if it exists in an
482             SwFmt
483 
484             Writer's attributes are retrieved by passing a numeric identifier
485             and receiving a SfxPoolItem reference which must then typically be
486             cast back to its original type which is both tedious and verbose.
487 
488             HasItem returns a pointer to the requested SfxPoolItem for a given
489             property id if it exists in the SwFmt e.g. fontsize
490 
491             HasItem uses item_cast () on the retrived pointer to test that the
492             retrived property is of the type that the developer thinks it is.
493 
494             @param rSet
495             The SwFmt whose property we want
496 
497             @param eType
498             The numeric identifier of the default property to be retrieved
499 
500             @tplparam T
501             A SfxPoolItem derived class of the retrieved property
502 
503             @return The T requested or 0 if no T found with id eType
504 
505             @author
506             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
507         */
HasItem(const SwFmt & rFmt,sal_uInt16 eType)508         template<class T> const T* HasItem(const SwFmt &rFmt,
509             sal_uInt16 eType)
510         {
511             return HasItem<T>(rFmt.GetAttrSet(), eType);
512         }
513 
514         /** Get the Paragraph Styles of a SwDoc
515 
516             Writer's styles are in one of those dreaded macro based pre-STL
517             containers. Give me an STL container of the paragraph styles
518             instead.
519 
520             @param rDoc
521             The SwDoc document to get the styles from
522 
523             @return A ParaStyles containing the SwDoc's Paragraph Styles
524 
525             @author
526             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
527         */
528         ParaStyles GetParaStyles(const SwDoc &rDoc);
529 
530 
531         /** Get a Paragraph Style which fits a given name
532 
533             Its surprisingly tricky to get a style when all you have is a name,
534             but that's what this does
535 
536             @param rDoc
537             The SwDoc document to search in
538 
539             @param rName
540             The name of the style to search for
541 
542             @return A Paragraph Style if one exists which matches the name
543 
544             @author
545             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
546         */
547         SwTxtFmtColl* GetParaStyle(SwDoc &rDoc, const String& rName);
548 
549         /** Get a Character Style which fits a given name
550 
551             Its surprisingly tricky to get a style when all you have is a name,
552             but that's what this does
553 
554             @param rDoc
555             The SwDoc document to search in
556 
557             @param rName
558             The name of the style to search for
559 
560             @return A Character Style if one exists which matches the name
561 
562             @author
563             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
564         */
565         SwCharFmt* GetCharStyle(SwDoc &rDoc, const String& rName);
566 
567         /** Sort sequence of Paragraph Styles by assigned outline style list level
568 
569             Sort ParaStyles in ascending order of assigned outline style list level,
570             e.g.  given Normal/Heading1/Heading2/.../Heading10 at their default
571             assigned outline style list levels of body level/level 1/level 2/.../level 10
572 
573             OD 2009-02-04 #i98791#
574             adjust the sorting algorithm due to introduced outline level attribute
575 
576             @param rStyles
577             The ParaStyles to sort
578 
579             @author
580             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
581         */
582         void SortByAssignedOutlineStyleListLevel(ParaStyles &rStyles);
583 
584         /** Get the SfxPoolItems of a SfxItemSet
585 
586             Writer's SfxPoolItems (attributes) are in one of those dreaded
587             macro based pre-STL containers. Give me an STL container of the
588             items instead.
589 
590             @param rSet
591             The SfxItemSet to get the items from
592 
593             @param rItems
594             The sw::PoolItems to put the items into
595 
596             @author
597             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
598         */
599         void GetPoolItems(const SfxItemSet &rSet, PoolItems &rItems, bool bExportParentItemSet );
600 
601         const SfxPoolItem *SearchPoolItems(const PoolItems &rItems,
602             sal_uInt16 eType);
603 
HasItem(const sw::PoolItems & rItems,sal_uInt16 eType)604         template<class T> const T* HasItem(const sw::PoolItems &rItems,
605             sal_uInt16 eType)
606         {
607             return item_cast<T>(SearchPoolItems(rItems, eType));
608         }
609 
610 
611         /** Remove properties from an SfxItemSet which a SwFmtCharFmt overrides
612 
613             Given an SfxItemSet and a SwFmtCharFmt remove from the rSet all the
614             properties which the SwFmtCharFmt would override. An SfxItemSet
615             contains attributes, and a SwFmtCharFmt is a "Character Style",
616             so if the SfxItemSet contains bold and so does the character style
617             then delete bold from the SfxItemSet
618 
619             @param
620             rFmt the SwFmtCharFmt which describes the Character Style
621 
622             @param
623             rSet the SfxItemSet from which we want to remove any properties
624             which the rFmt would override
625 
626             @author
627             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
628 
629             @see #i24291# for examples
630         */
631         void ClearOverridesFromSet(const SwFmtCharFmt &rFmt, SfxItemSet &rSet);
632 
633         /** Get the Floating elements in a SwDoc
634 
635             Writer's FrmFmts may or may not be anchored to some text content,
636             e.g. Page Anchored elements will not be. For the winword export we
637             need them to have something to be anchored to. So this method
638             returns all the floating elements in a document as a STL container
639             of sw::Frames which are guaranteed to have an appropiate anchor.
640 
641             @param rDoc
642             The SwDoc document to get the styles from
643 
644             @param pPaM
645             The SwPam to describe the selection in the document to get the
646             elements from. 0 means the entire document.
647 
648             @return A Frames containing the selections Floating elements
649 
650             @author
651             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
652         */
653         Frames GetFrames(const SwDoc &rDoc, SwPaM *pPaM = 0);
654 
655         /** Get the Frames anchored to a given node
656 
657             Given a container of frames, find the ones anchored to a given node
658 
659             @param rFrames
660             The container of frames to search in
661 
662             @param rNode
663             The SwNode to check for anchors to
664 
665             @return the Frames in rFrames anchored to rNode
666 
667             @author
668             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
669         */
670         Frames GetFramesInNode(const Frames &rFrames, const SwNode &rNode);
671 
672 #if 0
673         /** Get the Frames anchored for all nodes between two points
674 
675             Given a container of frames, find the ones anchored to the nodes
676             from start to end. Half open sequence, i.e. those anchored to
677             start, but not those anchored to end
678 
679             @param rFrames
680             The container of frames to search in
681 
682             @param rStart
683             The SwNode to start check for anchors from
684 
685             @param rEnd
686             The SwNode to end check for anchors from
687 
688             @return the Frames in rFrames anchored to rNode
689 
690             @author
691             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
692         */
693         Frames GetFramesBetweenNodes(const Frames &rFrames,
694                 const SwNode &rStart, const SwNode &rEnd);
695 #endif
696         /** Get the Numbering Format used on a paragraph
697 
698             There are two differing types of numbering formats that may be on a
699             paragraph, normal and outline. The outline is that numbering you
700             see in tools->outline numbering. Theres no difference in the
701             numbering itself, just how you get it from the SwTxtNode. Needless
702             to say the filter generally couldn't care less what type of
703             numbering is in use.
704 
705             @param rTxtNode
706             The SwTxtNode that is the paragraph
707 
708             @return A SwNumFmt pointer that describes the numbering level
709             on this paragraph, or 0 if there is none.
710 
711             @author
712             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
713         */
714         const SwNumFmt* GetNumFmtFromTxtNode(const SwTxtNode &rTxtNode);
715 
716         const SwNumRule* GetNumRuleFromTxtNode(const SwTxtNode &rTxtNd);
717         const SwNumRule* GetNormalNumRuleFromTxtNode(const SwTxtNode &rTxtNd);
718 
719 
720         /** Get the SwNoTxtNode associated with a SwFrmFmt if here is one
721 
722             There are two differing types of numbering formats that may be on a
723             paragraph, normal and outline. The outline is that numbering you
724             see in tools->outline numbering. Theres no difference in the
725             numbering itself, just how you get it from the SwTxtNode. Needless
726             to say the filter generally couldn't care less what type of
727             numbering is in use.
728 
729             @param rFmt
730             The SwFrmFmt that may describe a graphic
731 
732             @return A SwNoTxtNode pointer that describes the graphic of this
733             frame if there is one, or 0 if there is none.
734 
735             @author
736             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
737         */
738         SwNoTxtNode *GetNoTxtNodeFromSwFrmFmt(const SwFrmFmt &rFmt);
739 
740         /** Does a node have a "page break before" applied
741 
742             Both text nodes and tables in writer can have "page break before"
743             This function gives a unified view to both entities
744 
745             @param rNode
746             The SwNode to query the page break of
747 
748             @return true if there is a page break, false otherwise
749 
750             @author
751             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
752         */
753         bool HasPageBreak(const SwNode &rNode);
754 
755 
756         /** Make a best fit Polygon from a PolyPolygon
757 
758             For custom contours in writer we use a PolyPolygon, while word uses
759             a simple polygon, so we need to try and make the best polygon from
760             a PolyPolygon
761 
762             @param rPolyPoly
763             The PolyPolygon to try and turn into a Polygon
764 
765             @return best fit Polygon from rPolyPoly
766 
767             @author
768             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
769         */
770         Polygon PolygonFromPolyPolygon(const PolyPolygon &rPolyPoly);
771 
772         /** Determine if the font is the special Star|Open Symbol font
773 
774             @param rFontName
775             The FontName to test for being Star|Open Symbol
776 
777             @return true if this is Star|Open Symbol
778 
779             @author
780             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
781         */
782         bool IsStarSymbol(const String &rFontName);
783 
784         /** Make setting a drawing object's layer in a Writer document easy
785 
786 
787             Word has the simple concept of a drawing object either in the
788             foreground and in the background. We have an additional complexity
789             that form components live in a seperate layer, which seems
790             unnecessarily complicated. So in the winword filter we set the
791             object's layer through this class with either SendObjectToHell for
792             the bottom layer and SendObjectToHeaven for the top and we don't
793             worry about the odd form layer design wrinkle.
794 
795             @author
796             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
797         */
798         class SetLayer
799         {
800         private:
801             sal_uInt8 mnHeavenLayer, mnHellLayer, mnFormLayer;
802             enum Layer {eHeaven, eHell};
803             void SetObjectLayer(SdrObject &rObject, Layer eLayer) const;
804             void Swap(SetLayer &rOther) throw();
805         public:
806 
807             /** Make Object live in the bottom drawing layer
808 
809                 @param rObject
810                 The object to be set to the bottom layer
811             */
812             void SendObjectToHell(SdrObject &rObject) const;
813 
814             /** Make Object lives in the top top layer
815 
816                 @param rObject
817                 The object to be set to the bottom layer
818             */
819             void SendObjectToHeaven(SdrObject &rObject) const;
820 
821             /** Normal constructor
822 
823                 @param rDoc
824                 The Writer document whose drawing layers we will be inserting
825                 objects into
826             */
827             SetLayer(const SwDoc &rDoc);
828 
829             SetLayer(const SetLayer &rOther) throw();
830             SetLayer& operator=(const SetLayer &rOther) throw();
831         };
832     }
833 
834     namespace hack
835     {
836             /** Map an ID valid in one SfxItemPool to its equivalent in another
837 
838             Given a WhichId (the id that identifies a property e.g. bold) which
839             is correct in a given SfxItemPool, get the equivalent whichId in
840             another SfxItemPool
841 
842             This arises because the drawing layer uses the same properties as
843             writer e.g. SvxWeight, but for some reason uses different ids
844             for the same properties as writer.
845 
846             @param rDestPool
847             The SfxItemPool in whose terms the Id is returned
848 
849             @param rSrcPool
850             The SfxItemPool in whose terms the Id is passed in
851 
852             @param nWhich
853             The Id to transform from source to dest
854 
855             @return 0 on failure, the correct property Id on success
856 
857             @author
858             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
859         */
860         sal_uInt16 TransformWhichBetweenPools(const SfxItemPool &rDestPool,
861             const SfxItemPool &rSrcPool, sal_uInt16 nWhich);
862 
863         /** Map a SwDoc WhichId to the equivalent Id for a given SfxItemSet
864 
865             Given a WhichId (the id that identifies a property e.g. bold) which
866             is correct for a Writer document, get the equivalent whichId which
867             for a given SfxItemSet.
868 
869             This arises because the drawing layer uses the same properties as
870             writer e.g. SvxWeight, but for some reason uses different ids
871             for the same properties as writer.
872 
873             This is effectively the same as TransformWhichBetweenPools except
874             at a slightly different layer.
875 
876             @param rSet
877             The SfxItemSet in whose terms the Id is returned
878 
879             @param rDoc
880             The SwDoc in whose terms the Id is passed in
881 
882             @param nWhich
883             The Id to transform from writer to the SfxItemSet's domain
884 
885             @return 0 on failure, the correct SfxItemSet Id on success
886 
887             @author
888             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
889         */
890         sal_uInt16 GetSetWhichFromSwDocWhich(const SfxItemSet &rSet,
891             const SwDoc &rDoc, sal_uInt16 nWhich);
892 
893 
894         /** Make inserting an OLE object into a Writer document easy
895 
896             The rest of Office uses SdrOle2Obj for their OLE objects, Writer
897             doesn't, which makes things a bit difficult as this is the type of
898             object that the escher import code shared by the MSOffice filters
899             produces when it imports an OLE object.
900 
901             This utility class takes ownership of the OLE object away from a
902             SdrOle2Obj and can massage it into the condition best suited to
903             insertion into Writer.
904 
905             If the object was not transferred into Writer then it is deleted
906             during destruction.
907 
908             @author
909             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
910         */
911         class DrawingOLEAdaptor
912         {
913         private:
914             String msOrigPersistName;
915             com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject > mxIPRef;
916             SfxObjectShell& mrPers;
917             Graphic* mpGraphic;
918         public:
919             /** Take ownership of a SdrOle2Objs OLE object
920 
921                 @param rObj
922                 The SdrOle2Obj whose OLE object we want to take control of
923 
924                 @param rPers
925                 The SvPersist of a SwDoc (SwDoc::GetPersist()) into which we
926                 may want to move the object, or remove it from if unwanted.
927             */
928             DrawingOLEAdaptor(SdrOle2Obj &rObj, SfxObjectShell &rPers);
929 
930             /// Destructor will destroy the owned OLE object if not transferred
931             ~DrawingOLEAdaptor();
932 
933             /** Transfer ownership of the OLE object to a document's SvPersist
934 
935                 TransferToDoc moves the object into the persist under the name
936                 passed in. This name is then suitable to be used as an argument
937                 to SwDoc::InsertOLE.
938 
939                 The object is no longer owned by the adaptor after this call,
940                 subsequent calls are an error and return false.
941 
942                 @param rName
943                 The name to store the object under in the document.
944 
945                 @return On success true is returned, otherwise false. On
946                 success rName is then suitable for user with SwDoc::InsertOLE
947             */
948             bool TransferToDoc(::rtl::OUString &rName);
949         private:
950             /// No assigning allowed
951             DrawingOLEAdaptor& operator=(const DrawingOLEAdaptor&);
952             /// No copying allowed
953             DrawingOLEAdaptor(const DrawingOLEAdaptor &rDoc);
954         };
955 
956 #ifdef DEBUGDUMP
957         /** Create a SvStream to dump data to during debugging
958 
959             This creates a file in the program dir of OOo, delete the SvStream
960             after you are done with it
961 
962             @param rSuffix
963             The suffix that will be appened to this debugging file
964 
965             @return a SvStream to dump data to
966 
967             @author
968             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
969         */
970         SvStream *CreateDebuggingStream(const String &rSuffix);
971 
972         /** Dump one SvStream to another
973 
974             @param rSrc
975             The source stream
976 
977             @param rDest
978             The destination stream
979 
980             @param nLen
981             Optional Length of data to copy from rSrc to rDest, if unused copy
982             all available data from rSrc
983 
984             @author
985             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
986         */
987         void DumpStream(const SvStream &rSrc, SvStream &rDest,
988             sal_uInt32 nLen = STREAM_SEEK_TO_END);
989 #endif
990     }
991 }
992 
993 #endif
994 /* vi:set tabstop=4 shiftwidth=4 expandtab: */
995