xref: /trunk/main/sw/source/filter/ww8/writerhelper.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 /// @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 multitude 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 it's 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 error prone. 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         {
254             if (!rItem.IsA(STATICTYPE(T)))
255                 throw std::bad_cast();
256             return static_cast<const T &>(rItem);
257         }
258 
259         /** Provide a dynamic_cast style cast for SfxPoolItems
260 
261             A SfxPoolItem generally need to be cast back to its original type
262             to be useful, which is both tedious and errorprone. So item_cast is
263             a helper template to aid the process and test if the cast is
264             correct.
265 
266             @param pItem
267             The SfxPoolItem which is to be casted
268 
269             @tplparam T
270             A SfxPoolItem derived class to cast pItem to
271 
272             @return A pItem upcasted back to a T or 0 if pItem was not a T
273 
274             @author
275             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
276         */
item_cast(const SfxPoolItem * pItem)277         template<class T> const T * item_cast(const SfxPoolItem *pItem)
278         {
279             if (pItem && !pItem->IsA(STATICTYPE(T)))
280                 pItem = 0;
281             return static_cast<const T *>(pItem);
282         }
283 
284         /** Extract a SfxPoolItem derived property from a SwCntntNode
285 
286             Writer's attributes are retrieved by passing a numeric identifier
287             and receiving a SfxPoolItem reference which must then typically be
288             cast back to its original type which is both tedious and verbose.
289 
290             ItemGet uses item_cast () on the retrieved reference to test that the
291             retrieved property is of the type that the developer thinks it is.
292 
293             @param rNode
294             The SwCntntNode to retrieve the property from
295 
296             @param eType
297             The numeric identifier of the property to be retrieved
298 
299             @tplparam T
300             A SfxPoolItem derived class of the retrieved property
301 
302             @exception std::bad_cast Thrown if the property was not a T
303 
304             @return The T requested
305 
306             @author
307             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
308         */
ItemGet(const SwCntntNode & rNode,sal_uInt16 eType)309         template<class T> const T & ItemGet(const SwCntntNode &rNode,
310             sal_uInt16 eType)
311         {
312             return item_cast<T>(rNode.GetAttr(eType));
313         }
314 
315         /** Extract a SfxPoolItem derived property from a SwFmt
316 
317             Writer's attributes are retrieved by passing a numeric identifier
318             and receiving a SfxPoolItem reference which must then typically be
319             cast back to its original type which is both tedious and verbose.
320 
321             ItemGet uses item_cast () on the retrieved reference to test that the
322             retrieved property is of the type that the developer thinks it is.
323 
324             @param rFmt
325             The SwFmt to retrieve the property from
326 
327             @param eType
328             The numeric identifier of the property to be retrieved
329 
330             @tplparam T
331             A SfxPoolItem derived class of the retrieved property
332 
333             @exception std::bad_cast Thrown if the property was not a T
334 
335             @author
336             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
337         */
ItemGet(const SwFmt & rFmt,sal_uInt16 eType)338         template<class T> const T & ItemGet(const SwFmt &rFmt,
339             sal_uInt16 eType)
340         {
341             return item_cast<T>(rFmt.GetFmtAttr(eType));
342         }
343 
344         /** Extract a SfxPoolItem derived property from a SfxItemSet
345 
346             Writer's attributes are retrieved by passing a numeric identifier
347             and receiving a SfxPoolItem reference which must then typically be
348             cast back to its original type which is both tedious and verbose.
349 
350             ItemGet uses item_cast () on the retrieved reference to test that the
351             retrieved property is of the type that the developer thinks it is.
352 
353             @param rSet
354             The SfxItemSet to retrieve the property from
355 
356             @param eType
357             The numeric identifier of the property to be retrieved
358 
359             @tplparam T
360             A SfxPoolItem derived class of the retrieved property
361 
362             @exception std::bad_cast Thrown if the property was not a T
363 
364             @return The T requested
365 
366             @author
367             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
368         */
ItemGet(const SfxItemSet & rSet,sal_uInt16 eType)369         template<class T> const T & ItemGet(const SfxItemSet &rSet,
370             sal_uInt16 eType)
371         {
372             return item_cast<T>(rSet.Get(eType));
373         }
374 
375         /** Extract a default SfxPoolItem derived property from a SfxItemPool
376 
377             Writer's attributes are retrieved by passing a numeric identifier
378             and receiving a SfxPoolItem reference which must then typically be
379             cast back to its original type which is both tedious and verbose.
380 
381             DefaultItemGet returns a reference to the default property of a
382             given SfxItemPool for a given property id, e.g. default fontsize
383 
384             DefaultItemGet uses item_cast () on the retrieved reference to test
385             that the retrieved property is of the type that the developer thinks
386             it is.
387 
388             @param rPool
389             The SfxItemPool whose default property we want
390 
391             @param eType
392             The numeric identifier of the default property to be retrieved
393 
394             @tplparam T
395             A SfxPoolItem derived class of the retrieved property
396 
397             @exception std::bad_cast Thrown if the property was not a T
398 
399             @return The T requested
400 
401             @author
402             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
403         */
DefaultItemGet(const SfxItemPool & rPool,sal_uInt16 eType)404         template<class T> const T & DefaultItemGet(const SfxItemPool &rPool,
405             sal_uInt16 eType)
406         {
407             return item_cast<T>(rPool.GetDefaultItem(eType));
408         }
409 
410         /** Extract a default SfxPoolItem derived property from a SwDoc
411 
412             Writer's attributes are retrieved by passing a numeric identifier
413             and receiving a SfxPoolItem reference which must then typically be
414             cast back to its original type which is both tedious and verbose.
415 
416             DefaultItemGet returns a reference to the default property of a
417             given SwDoc (Writer Document) for a given property id, e.g default
418             fontsize
419 
420             DefaultItemGet uses item_cast () on the retrieved reference to test
421             that the retrieved property is of the type that the developer thinks
422             it is.
423 
424             @param rPool
425             The SfxItemPool whose default property we want
426 
427             @param eType
428             The numeric identifier of the default property to be retrieved
429 
430             @tplparam T
431             A SfxPoolItem derived class of the retrieved property
432 
433             @exception std::bad_cast Thrown if the property was not a T
434 
435             @return The T requested
436 
437             @author
438             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
439         */
DefaultItemGet(const SwDoc & rDoc,sal_uInt16 eType)440         template<class T> const T & DefaultItemGet(const SwDoc &rDoc,
441             sal_uInt16 eType)
442         {
443             return DefaultItemGet<T>(rDoc.GetAttrPool(), eType);
444         }
445 
446         /** Return a pointer to a SfxPoolItem derived class if it exists in an
447             SfxItemSet
448 
449             Writer's attributes are retrieved by passing a numeric identifier
450             and receiving a SfxPoolItem reference which must then typically be
451             cast back to its original type which is both tedious and verbose.
452 
453             HasItem returns a pointer to the requested SfxPoolItem for a given
454             property id if it exists in the SfxItemSet or its chain of parents,
455             e.g. fontsize
456 
457             HasItem uses item_cast () on the retrieved pointer to test that the
458             retrieved property is of the type that the developer thinks it is.
459 
460             @param rSet
461             The SfxItemSet whose property we want
462 
463             @param eType
464             The numeric identifier of the default property to be retrieved
465 
466             @tplparam T
467             A SfxPoolItem derived class of the retrieved property
468 
469             @return The T requested or 0 if no T found with id eType
470 
471             @author
472             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
473         */
HasItem(const SfxItemSet & rSet,sal_uInt16 eType)474         template<class T> const T* HasItem(const SfxItemSet &rSet,
475             sal_uInt16 eType)
476         {
477             return item_cast<T>(rSet.GetItem(eType));
478         }
479 
480         /** Return a pointer to a SfxPoolItem derived class if it exists in an
481             SwFmt
482 
483             Writer's attributes are retrieved by passing a numeric identifier
484             and receiving a SfxPoolItem reference which must then typically be
485             cast back to its original type which is both tedious and verbose.
486 
487             HasItem returns a pointer to the requested SfxPoolItem for a given
488             property id if it exists in the SwFmt e.g. fontsize
489 
490             HasItem uses item_cast () on the retrieved pointer to test that the
491             retrieved property is of the type that the developer thinks it is.
492 
493             @param rSet
494             The SwFmt whose property we want
495 
496             @param eType
497             The numeric identifier of the default property to be retrieved
498 
499             @tplparam T
500             A SfxPoolItem derived class of the retrieved property
501 
502             @return The T requested or 0 if no T found with id eType
503 
504             @author
505             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
506         */
HasItem(const SwFmt & rFmt,sal_uInt16 eType)507         template<class T> const T* HasItem(const SwFmt &rFmt,
508             sal_uInt16 eType)
509         {
510             return HasItem<T>(rFmt.GetAttrSet(), eType);
511         }
512 
513         /** Get the Paragraph Styles of a SwDoc
514 
515             Writer's styles are in one of those dreaded macro based pre-STL
516             containers. Give me an STL container of the paragraph styles
517             instead.
518 
519             @param rDoc
520             The SwDoc document to get the styles from
521 
522             @return A ParaStyles containing the SwDoc's Paragraph Styles
523 
524             @author
525             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
526         */
527         ParaStyles GetParaStyles(const SwDoc &rDoc);
528 
529 
530         /** Get a Paragraph Style which fits a given name
531 
532             Its surprisingly tricky to get a style when all you have is a name,
533             but that's what this does
534 
535             @param rDoc
536             The SwDoc document to search in
537 
538             @param rName
539             The name of the style to search for
540 
541             @return A Paragraph Style if one exists which matches the name
542 
543             @author
544             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
545         */
546         SwTxtFmtColl* GetParaStyle(SwDoc &rDoc, const String& rName);
547 
548         /** Get a Character Style which fits a given name
549 
550             It's surprisingly tricky to get a style when all you have is a name,
551             but that's what this does
552 
553             @param rDoc
554             The SwDoc document to search in
555 
556             @param rName
557             The name of the style to search for
558 
559             @return A Character Style if one exists which matches the name
560 
561             @author
562             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
563         */
564         SwCharFmt* GetCharStyle(SwDoc &rDoc, const String& rName);
565 
566         /** Sort sequence of Paragraph Styles by assigned outline style list level
567 
568             Sort ParaStyles in ascending order of assigned outline style list level,
569             e.g.  given Normal/Heading1/Heading2/.../Heading10 at their default
570             assigned outline style list levels of body level/level 1/level 2/.../level 10
571 
572             OD 2009-02-04 #i98791#
573             adjust the sorting algorithm due to introduced outline level attribute
574 
575             @param rStyles
576             The ParaStyles to sort
577 
578             @author
579             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
580         */
581         void SortByAssignedOutlineStyleListLevel(ParaStyles &rStyles);
582 
583         /** Get the SfxPoolItems of a SfxItemSet
584 
585             Writer's SfxPoolItems (attributes) are in one of those dreaded
586             macro based pre-STL containers. Give me an STL container of the
587             items instead.
588 
589             @param rSet
590             The SfxItemSet to get the items from
591 
592             @param rItems
593             The sw::PoolItems to put the items into
594 
595             @author
596             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
597         */
598         void GetPoolItems(const SfxItemSet &rSet, PoolItems &rItems, bool bExportParentItemSet );
599 
600         const SfxPoolItem *SearchPoolItems(const PoolItems &rItems,
601             sal_uInt16 eType);
602 
HasItem(const sw::PoolItems & rItems,sal_uInt16 eType)603         template<class T> const T* HasItem(const sw::PoolItems &rItems,
604             sal_uInt16 eType)
605         {
606             return item_cast<T>(SearchPoolItems(rItems, eType));
607         }
608 
609 
610         /** Remove properties from an SfxItemSet which a SwFmtCharFmt overrides
611 
612             Given an SfxItemSet and a SwFmtCharFmt remove from the rSet all the
613             properties which the SwFmtCharFmt would override. An SfxItemSet
614             contains attributes, and a SwFmtCharFmt is a "Character Style",
615             so if the SfxItemSet contains bold and so does the character style
616             then delete bold from the SfxItemSet
617 
618             @param
619             rFmt the SwFmtCharFmt which describes the Character Style
620 
621             @param
622             rSet the SfxItemSet from which we want to remove any properties
623             which the rFmt would override
624 
625             @author
626             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
627 
628             @see #i24291# for examples
629         */
630         void ClearOverridesFromSet(const SwFmtCharFmt &rFmt, SfxItemSet &rSet);
631 
632         /** Get the Floating elements in a SwDoc
633 
634             Writer's FrmFmts may or may not be anchored to some text content,
635             e.g. Page Anchored elements will not be. For the winword export we
636             need them to have something to be anchored to. So this method
637             returns all the floating elements in a document as a STL container
638             of sw::Frames which are guaranteed to have an appropriate anchor.
639 
640             @param rDoc
641             The SwDoc document to get the styles from
642 
643             @param pPaM
644             The SwPam to describe the selection in the document to get the
645             elements from. 0 means the entire document.
646 
647             @return A Frames containing the selections Floating elements
648 
649             @author
650             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
651         */
652         Frames GetFrames(const SwDoc &rDoc, SwPaM *pPaM = 0);
653 
654         /** Get the Frames anchored to a given node
655 
656             Given a container of frames, find the ones anchored to a given node
657 
658             @param rFrames
659             The container of frames to search in
660 
661             @param rNode
662             The SwNode to check for anchors to
663 
664             @return the Frames in rFrames anchored to rNode
665 
666             @author
667             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
668         */
669         Frames GetFramesInNode(const Frames &rFrames, const SwNode &rNode);
670 
671 #if 0
672         /** Get the Frames anchored for all nodes between two points
673 
674             Given a container of frames, find the ones anchored to the nodes
675             from start to end. Half open sequence, i.e. those anchored to
676             start, but not those anchored to end
677 
678             @param rFrames
679             The container of frames to search in
680 
681             @param rStart
682             The SwNode to start check for anchors from
683 
684             @param rEnd
685             The SwNode to end check for anchors from
686 
687             @return the Frames in rFrames anchored to rNode
688 
689             @author
690             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
691         */
692         Frames GetFramesBetweenNodes(const Frames &rFrames,
693                 const SwNode &rStart, const SwNode &rEnd);
694 #endif
695         /** Get the Numbering Format used on a paragraph
696 
697             There are two differing types of numbering formats that may be on a
698             paragraph, normal and outline. The outline is that numbering you
699             see in tools->outline numbering. Theres no difference in the
700             numbering itself, just how you get it from the SwTxtNode. Needless
701             to say the filter generally couldn't care less what type of
702             numbering is in use.
703 
704             @param rTxtNode
705             The SwTxtNode that is the paragraph
706 
707             @return A SwNumFmt pointer that describes the numbering level
708             on this paragraph, or 0 if there is none.
709 
710             @author
711             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
712         */
713         const SwNumFmt* GetNumFmtFromTxtNode(const SwTxtNode &rTxtNode);
714 
715         const SwNumRule* GetNumRuleFromTxtNode(const SwTxtNode &rTxtNd);
716         const SwNumRule* GetNormalNumRuleFromTxtNode(const SwTxtNode &rTxtNd);
717 
718 
719         /** Get the SwNoTxtNode associated with a SwFrmFmt if here is one
720 
721             There are two differing types of numbering formats that may be on a
722             paragraph, normal and outline. The outline is that numbering you
723             see in tools->outline numbering. Theres no difference in the
724             numbering itself, just how you get it from the SwTxtNode. Needless
725             to say the filter generally couldn't care less what type of
726             numbering is in use.
727 
728             @param rFmt
729             The SwFrmFmt that may describe a graphic
730 
731             @return A SwNoTxtNode pointer that describes the graphic of this
732             frame if there is one, or 0 if there is none.
733 
734             @author
735             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
736         */
737         SwNoTxtNode *GetNoTxtNodeFromSwFrmFmt(const SwFrmFmt &rFmt);
738 
739         /** Does a node have a "page break before" applied
740 
741             Both text nodes and tables in Writer can have "page break before"
742             This function gives a unified view to both entities
743 
744             @param rNode
745             The SwNode to query the page break of
746 
747             @return true if there is a page break, false otherwise
748 
749             @author
750             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
751         */
752         bool HasPageBreak(const SwNode &rNode);
753 
754 
755         /** Make a best fit Polygon from a PolyPolygon
756 
757             For custom contours in Writer we use a PolyPolygon, while word uses
758             a simple polygon, so we need to try and make the best polygon from
759             a PolyPolygon
760 
761             @param rPolyPoly
762             The PolyPolygon to try and turn into a Polygon
763 
764             @return best fit Polygon from rPolyPoly
765 
766             @author
767             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
768         */
769         Polygon PolygonFromPolyPolygon(const PolyPolygon &rPolyPoly);
770 
771         /** Determine if the font is the special Star|Open Symbol font
772 
773             @param rFontName
774             The FontName to test for being Star|Open Symbol
775 
776             @return true if this is Star|Open Symbol
777 
778             @author
779             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
780         */
781         bool IsStarSymbol(const String &rFontName);
782 
783         /** Make setting a drawing object's layer in a Writer document easy
784 
785 
786             Word has the simple concept of a drawing object either in the
787             foreground and in the background. We have an additional complexity
788             that form components live in a separate layer, which seems
789             unnecessarily complicated. So in the winword filter we set the
790             object's layer through this class with either SendObjectToHell for
791             the bottom layer and SendObjectToHeaven for the top and we don't
792             worry about the odd form layer design wrinkle.
793 
794             @author
795             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
796         */
797         class SetLayer
798         {
799         private:
800             sal_uInt8 mnHeavenLayer, mnHellLayer, mnFormLayer;
801             enum Layer {eHeaven, eHell};
802             void SetObjectLayer(SdrObject &rObject, Layer eLayer) const;
803             void Swap(SetLayer &rOther) throw();
804         public:
805 
806             /** Make Object live in the bottom drawing layer
807 
808                 @param rObject
809                 The object to be set to the bottom layer
810             */
811             void SendObjectToHell(SdrObject &rObject) const;
812 
813             /** Make Object lives in the top top layer
814 
815                 @param rObject
816                 The object to be set to the bottom layer
817             */
818             void SendObjectToHeaven(SdrObject &rObject) const;
819 
820             /** Normal constructor
821 
822                 @param rDoc
823                 The Writer document whose drawing layers we will be inserting
824                 objects into
825             */
826             SetLayer(const SwDoc &rDoc);
827 
828             SetLayer(const SetLayer &rOther) throw();
829             SetLayer& operator=(const SetLayer &rOther) throw();
830         };
831     }
832 
833     namespace hack
834     {
835             /** Map an ID valid in one SfxItemPool to its equivalent in another
836 
837             Given a WhichId (the id that identifies a property e.g. bold) which
838             is correct in a given SfxItemPool, get the equivalent whichId in
839             another SfxItemPool
840 
841             This arises because the drawing layer uses the same properties as
842             Writer e.g. SvxWeight, but for some reason uses different ids
843             for the same properties as Writer.
844 
845             @param rDestPool
846             The SfxItemPool in whose terms the Id is returned
847 
848             @param rSrcPool
849             The SfxItemPool in whose terms the Id is passed in
850 
851             @param nWhich
852             The Id to transform from source to dest
853 
854             @return 0 on failure, the correct property Id on success
855 
856             @author
857             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
858         */
859         sal_uInt16 TransformWhichBetweenPools(const SfxItemPool &rDestPool,
860             const SfxItemPool &rSrcPool, sal_uInt16 nWhich);
861 
862         /** Map a SwDoc WhichId to the equivalent Id for a given SfxItemSet
863 
864             Given a WhichId (the id that identifies a property e.g. bold) which
865             is correct for a Writer document, get the equivalent whichId which
866             for a given SfxItemSet.
867 
868             This arises because the drawing layer uses the same properties as
869             Writer e.g. SvxWeight, but for some reason uses different ids
870             for the same properties as Writer.
871 
872             This is effectively the same as TransformWhichBetweenPools except
873             at a slightly different layer.
874 
875             @param rSet
876             The SfxItemSet in whose terms the Id is returned
877 
878             @param rDoc
879             The SwDoc in whose terms the Id is passed in
880 
881             @param nWhich
882             The Id to transform from Writer to the SfxItemSet's domain
883 
884             @return 0 on failure, the correct SfxItemSet Id on success
885 
886             @author
887             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
888         */
889         sal_uInt16 GetSetWhichFromSwDocWhich(const SfxItemSet &rSet,
890             const SwDoc &rDoc, sal_uInt16 nWhich);
891 
892 
893         /** Make inserting an OLE object into a Writer document easy
894 
895             The rest of Office uses SdrOle2Obj for their OLE objects, Writer
896             doesn't, which makes things a bit difficult as this is the type of
897             object that the escher import code shared by the MSOffice filters
898             produces when it imports an OLE object.
899 
900             This utility class takes ownership of the OLE object away from a
901             SdrOle2Obj and can massage it into the condition best suited to
902             insertion into Writer.
903 
904             If the object was not transferred into Writer then it is deleted
905             during destruction.
906 
907             @author
908             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
909         */
910         class DrawingOLEAdaptor
911         {
912         private:
913             String msOrigPersistName;
914             com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject > mxIPRef;
915             SfxObjectShell& mrPers;
916             Graphic* mpGraphic;
917         public:
918             /** Take ownership of a SdrOle2Objs OLE object
919 
920                 @param rObj
921                 The SdrOle2Obj whose OLE object we want to take control of
922 
923                 @param rPers
924                 The SvPersist of a SwDoc (SwDoc::GetPersist()) into which we
925                 may want to move the object, or remove it from if unwanted.
926             */
927             DrawingOLEAdaptor(SdrOle2Obj &rObj, SfxObjectShell &rPers);
928 
929             /// Destructor will destroy the owned OLE object if not transferred
930             ~DrawingOLEAdaptor();
931 
932             /** Transfer ownership of the OLE object to a document's SvPersist
933 
934                 TransferToDoc moves the object into the persist under the name
935                 passed in. This name is then suitable to be used as an argument
936                 to SwDoc::InsertOLE.
937 
938                 The object is no longer owned by the adaptor after this call,
939                 subsequent calls are an error and return false.
940 
941                 @param rName
942                 The name to store the object under in the document.
943 
944                 @return On success true is returned, otherwise false. On
945                 success rName is then suitable for user with SwDoc::InsertOLE
946             */
947             bool TransferToDoc(::rtl::OUString &rName);
948         private:
949             /// No assigning allowed
950             DrawingOLEAdaptor& operator=(const DrawingOLEAdaptor&);
951             /// No copying allowed
952             DrawingOLEAdaptor(const DrawingOLEAdaptor &rDoc);
953         };
954 
955 #ifdef DEBUGDUMP
956         /** Create a SvStream to dump data to during debugging
957 
958             This creates a file in the program dir of AOO, delete the SvStream
959             after you are done with it
960 
961             @param rSuffix
962             The suffix that will be appended to this debugging file
963 
964             @return a SvStream to dump data to
965 
966             @author
967             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
968         */
969         SvStream *CreateDebuggingStream(const String &rSuffix);
970 
971         /** Dump one SvStream to another
972 
973             @param rSrc
974             The source stream
975 
976             @param rDest
977             The destination stream
978 
979             @param nLen
980             Optional Length of data to copy from rSrc to rDest, if unused copy
981             all available data from rSrc
982 
983             @author
984             <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
985         */
986         void DumpStream(const SvStream &rSrc, SvStream &rDest,
987             sal_uInt32 nLen = STREAM_SEEK_TO_END);
988 #endif
989     }
990 }
991 
992 #endif
993 /* vi:set tabstop=4 shiftwidth=4 expandtab: */
994