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