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