merge the formfield patch from ooo-build
[ooovba.git] / sw / source / filter / ww8 / writerhelper.hxx
blob18e73b1e2d56413f06eea3b0023e1e1de3e756df
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: writerhelper.hxx,v $
10 * $Revision: 1.22 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
31 /// @HTML
33 #ifndef SW_WRITERHELPER
34 #define SW_WRITERHELPER
36 #include <typeinfo>
37 #include <vector>
38 #include <map>
39 #include <com/sun/star/embed/XEmbeddedObject.hpp>
41 #include <sfx2/objsh.hxx>
42 #include "types.hxx"
43 #include <svtools/itempool.hxx> //SfxItemPool
44 #include <svtools/itemset.hxx> //SfxItemSet
45 #include <format.hxx> //SwFmt
46 #include <node.hxx> //SwCntntNode
47 #include <pam.hxx> //SwPaM
48 #include <tools/poly.hxx> //Polygon, PolyPolygon
49 #include <doc.hxx> //SwDoc
51 //Uncomment to dump debugging streams of graphics
52 #if OSL_DEBUG_LEVEL > 1
53 //# define DEBUGDUMP
54 #endif
56 class SwTxtFmtColl;
57 class SwCharFmt;
58 class SdrObject;
59 class SdrOle2Obj;
60 class OutlinerParaObject;
61 class SdrTextObj;
62 class SwNumFmt;
63 class SwTxtNode;
64 class SwNoTxtNode;
65 class SwFmtCharFmt;
66 class Graphic;
67 class SwDoc;
68 class SwNumRule;
70 namespace sw
72 namespace util
74 class ItemSort
75 : public std::binary_function<sal_uInt16, sal_uInt16, bool>
77 public:
78 bool operator()(sal_uInt16 nA, sal_uInt16 nB) const;
83 namespace sw
85 /// STL container of Paragraph Styles (SwTxtFmtColl)
86 typedef std::vector<SwTxtFmtColl *> ParaStyles;
87 /// STL iterator for ParaStyles
88 typedef ParaStyles::iterator ParaStyleIter;
89 /// STL container of SfxPoolItems (Attributes)
90 typedef std::map<sal_uInt16, const SfxPoolItem *, sw::util::ItemSort> PoolItems;
91 /// STL const iterator for ParaStyles
92 typedef PoolItems::const_iterator cPoolItemIter;
95 /** Make exporting a Writer Frame easy
97 In word all frames are effectively anchored to character or as
98 character. This is nice and simple, writer is massively complex in this
99 area, so this sw::Frame simplies matters by providing a single unified
100 view of the multitute of elements in writer and their differing quirks.
102 A sw::Frame wraps a writer frame and is guaranted to have a suitable
103 anchor position available from it. It hides much of the needless
104 complexity of the multitude of floating/inline elements in writer, it...
106 Guarantees an anchor position for a frame.
107 Provides a readable way to see if we are anchored inline. (as character)
108 Provides a simple way to flag what type of entity this frame describes.
109 Provides the size of the element as drawn by writer.
111 @author
112 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
114 class Frame
116 public:
117 enum WriterSource {eTxtBox, eGraphic, eOle, eDrawing, eFormControl};
118 private:
119 const SwFrmFmt* mpFlyFrm;
120 SwPosition maPos;
121 Size maSize;
122 // --> OD 2007-04-19 #i43447#
123 // Size of the frame in the layout.
124 // Especially needed for graphics, whose layout size can differ from its
125 // size, because it is scaled into its environment.
126 Size maLayoutSize;
127 // <--
128 WriterSource meWriterType;
129 const SwNode *mpStartFrameContent;
130 bool mbIsInline;
131 public:
132 Frame(const SwFrmFmt &rFlyFrm, const SwPosition &rPos);
134 /** Get the writer SwFrmFmt that this object describes
136 @return
137 The wrapped SwFrmFmt
139 const SwFrmFmt &GetFrmFmt() const { return *mpFlyFrm; }
141 /** Get the position this frame is anchored at
143 @return
144 The anchor position of this frame
146 const SwPosition &GetPosition() const { return maPos; }
148 /** Get the node this frame is anchored into
150 @return
151 The SwTxtNode this frame is anchored inside
153 const SwCntntNode *GetCntntNode() const
154 { return maPos.nNode.GetNode().GetCntntNode(); }
156 /** Get the type of frame that this wraps
158 @return
159 a WriterSource which describes the source type of this wrapper
161 WriterSource GetWriterType() const { return meWriterType; }
163 /** Is this frame inline (as character)
165 @return
166 whether this is inline or not
168 bool IsInline() const;
171 /** Even if the frame isn't an inline frame, force it to behave as one
173 There are a variety of circumstances where word cannot have
174 anything except inline elements, e.g. inside frames. So its easier
175 to force this sw::Frame into behaving as one, instead of special
176 casing export code all over the place.
179 void ForceTreatAsInline();
181 /** Get the first node of content in the frame
183 @return
184 the first node of content in the frame, might not be any at all.
186 const SwNode *GetContent() const { return mpStartFrameContent; }
189 /** Does this sw::Frame refer to the same writer content as another
191 @return
192 if the two sw::Frames are handling the same writer frame
194 bool RefersToSameFrameAs(const Frame &rOther) const
196 return (mpFlyFrm == rOther.mpFlyFrm);
199 /** The Size of the contained element
201 @return
202 the best size to use to export to word
204 const Size GetSize() const { return maSize; }
206 /** The layout size of the contained element
208 OD 2007-04-19 #i43447#
209 Needed for graphics, which are scaled into its environment
211 @return layout size
213 const Size GetLayoutSize() const
215 return maLayoutSize;
219 /// STL container of Frames
220 typedef std::vector<Frame> Frames;
221 /// STL iterator for Frames
222 typedef std::vector<Frame>::iterator FrameIter;
225 namespace sw
227 namespace util
229 /** Provide a dynamic_cast style cast for SfxPoolItems
231 A SfxPoolItem generally need to be cast back to its original type
232 to be useful, which is both tedious and errorprone. So item_cast is
233 a helper template to aid the process and test if the cast is
234 correct.
236 @param rItem
237 The SfxPoolItem which is to be casted
239 @tplparam T
240 A SfxPoolItem derived class to cast rItem to
242 @return A rItem upcasted back to a T
244 @exception std::bad_cast Thrown if the rItem was not a T
246 @author
247 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
249 template<class T> const T & item_cast(const SfxPoolItem &rItem)
250 throw(std::bad_cast)
252 if (!rItem.IsA(STATICTYPE(T)))
253 throw std::bad_cast();
254 return static_cast<const T &>(rItem);
257 /** Provide a dynamic_cast style cast for SfxPoolItems
259 A SfxPoolItem generally need to be cast back to its original type
260 to be useful, which is both tedious and errorprone. So item_cast is
261 a helper template to aid the process and test if the cast is
262 correct.
264 @param pItem
265 The SfxPoolItem which is to be casted
267 @tplparam T
268 A SfxPoolItem derived class to cast pItem to
270 @return A pItem upcasted back to a T or 0 if pItem was not a T
272 @author
273 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
275 template<class T> const T * item_cast(const SfxPoolItem *pItem)
277 if (pItem && !pItem->IsA(STATICTYPE(T)))
278 pItem = 0;
279 return static_cast<const T *>(pItem);
282 /** Extract a SfxPoolItem derived property from a SwCntntNode
284 Writer's attributes are retrieved by passing a numeric identifier
285 and receiving a SfxPoolItem reference which must then typically be
286 cast back to its original type which is both tedious and verbose.
288 ItemGet uses item_cast () on the retrived reference to test that the
289 retrived property is of the type that the developer thinks it is.
291 @param rNode
292 The SwCntntNode to retrieve the property from
294 @param eType
295 The numeric identifier of the property to be retrieved
297 @tplparam T
298 A SfxPoolItem derived class of the retrieved property
300 @exception std::bad_cast Thrown if the property was not a T
302 @return The T requested
304 @author
305 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
307 template<class T> const T & ItemGet(const SwCntntNode &rNode,
308 sal_uInt16 eType) throw(std::bad_cast)
310 return item_cast<T>(rNode.GetAttr(eType));
313 /** Extract a SfxPoolItem derived property from a SwFmt
315 Writer's attributes are retrieved by passing a numeric identifier
316 and receiving a SfxPoolItem reference which must then typically be
317 cast back to its original type which is both tedious and verbose.
319 ItemGet uses item_cast () on the retrived reference to test that the
320 retrived property is of the type that the developer thinks it is.
322 @param rFmt
323 The SwFmt to retrieve the property from
325 @param eType
326 The numeric identifier of the property to be retrieved
328 @tplparam T
329 A SfxPoolItem derived class of the retrieved property
331 @exception std::bad_cast Thrown if the property was not a T
333 @author
334 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
336 template<class T> const T & ItemGet(const SwFmt &rFmt,
337 sal_uInt16 eType) throw(std::bad_cast)
339 return item_cast<T>(rFmt.GetFmtAttr(eType));
342 /** Extract a SfxPoolItem derived property from a SfxItemSet
344 Writer's attributes are retrieved by passing a numeric identifier
345 and receiving a SfxPoolItem reference which must then typically be
346 cast back to its original type which is both tedious and verbose.
348 ItemGet uses item_cast () on the retrived reference to test that the
349 retrived property is of the type that the developer thinks it is.
351 @param rSet
352 The SfxItemSet to retrieve the property from
354 @param eType
355 The numeric identifier of the property to be retrieved
357 @tplparam T
358 A SfxPoolItem derived class of the retrieved property
360 @exception std::bad_cast Thrown if the property was not a T
362 @return The T requested
364 @author
365 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
367 template<class T> const T & ItemGet(const SfxItemSet &rSet,
368 sal_uInt16 eType) throw(std::bad_cast)
370 return item_cast<T>(rSet.Get(eType));
373 /** Extract a default SfxPoolItem derived property from a SfxItemPool
375 Writer's attributes are retrieved by passing a numeric identifier
376 and receiving a SfxPoolItem reference which must then typically be
377 cast back to its original type which is both tedious and verbose.
379 DefaultItemGet returns a reference to the default property of a
380 given SfxItemPool for a given property id, e.g. default fontsize
382 DefaultItemGet uses item_cast () on the retrived reference to test
383 that the retrived property is of the type that the developer thinks
384 it is.
386 @param rPool
387 The SfxItemPool whose default property we want
389 @param eType
390 The numeric identifier of the default property to be retrieved
392 @tplparam T
393 A SfxPoolItem derived class of the retrieved property
395 @exception std::bad_cast Thrown if the property was not a T
397 @return The T requested
399 @author
400 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
402 template<class T> const T & DefaultItemGet(const SfxItemPool &rPool,
403 sal_uInt16 eType) throw(std::bad_cast)
405 return item_cast<T>(rPool.GetDefaultItem(eType));
408 /** Extract a default SfxPoolItem derived property from a SwDoc
410 Writer's attributes are retrieved by passing a numeric identifier
411 and receiving a SfxPoolItem reference which must then typically be
412 cast back to its original type which is both tedious and verbose.
414 DefaultItemGet returns a reference to the default property of a
415 given SwDoc (Writer Document) for a given property id, e.g default
416 fontsize
418 DefaultItemGet uses item_cast () on the retrived reference to test
419 that the retrived property is of the type that the developer thinks
420 it is.
422 @param rPool
423 The SfxItemPool whose default property we want
425 @param eType
426 The numeric identifier of the default property to be retrieved
428 @tplparam T
429 A SfxPoolItem derived class of the retrieved property
431 @exception std::bad_cast Thrown if the property was not a T
433 @return The T requested
435 @author
436 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
438 template<class T> const T & DefaultItemGet(const SwDoc &rDoc,
439 sal_uInt16 eType) throw(std::bad_cast)
441 return DefaultItemGet<T>(rDoc.GetAttrPool(), eType);
444 /** Return a pointer to a SfxPoolItem derived class if it exists in an
445 SfxItemSet
447 Writer's attributes are retrieved by passing a numeric identifier
448 and receiving a SfxPoolItem reference which must then typically be
449 cast back to its original type which is both tedious and verbose.
451 HasItem returns a pointer to the requested SfxPoolItem for a given
452 property id if it exists in the SfxItemSet or its chain of parents,
453 e.g. fontsize
455 HasItem uses item_cast () on the retrived pointer to test that the
456 retrived property is of the type that the developer thinks it is.
458 @param rSet
459 The SfxItemSet whose property we want
461 @param eType
462 The numeric identifier of the default property to be retrieved
464 @tplparam T
465 A SfxPoolItem derived class of the retrieved property
467 @return The T requested or 0 if no T found with id eType
469 @author
470 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
472 template<class T> const T* HasItem(const SfxItemSet &rSet,
473 sal_uInt16 eType)
475 return item_cast<T>(rSet.GetItem(eType));
478 /** Return a pointer to a SfxPoolItem derived class if it exists in an
479 SwFmt
481 Writer's attributes are retrieved by passing a numeric identifier
482 and receiving a SfxPoolItem reference which must then typically be
483 cast back to its original type which is both tedious and verbose.
485 HasItem returns a pointer to the requested SfxPoolItem for a given
486 property id if it exists in the SwFmt e.g. fontsize
488 HasItem uses item_cast () on the retrived pointer to test that the
489 retrived property is of the type that the developer thinks it is.
491 @param rSet
492 The SwFmt whose property we want
494 @param eType
495 The numeric identifier of the default property to be retrieved
497 @tplparam T
498 A SfxPoolItem derived class of the retrieved property
500 @return The T requested or 0 if no T found with id eType
502 @author
503 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
505 template<class T> const T* HasItem(const SwFmt &rFmt,
506 sal_uInt16 eType)
508 return HasItem<T>(rFmt.GetAttrSet(), eType);
511 /** Get the Paragraph Styles of a SwDoc
513 Writer's styles are in one of those dreaded macro based pre-STL
514 containers. Give me an STL container of the paragraph styles
515 instead.
517 @param rDoc
518 The SwDoc document to get the styles from
520 @return A ParaStyles containing the SwDoc's Paragraph Styles
522 @author
523 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
525 ParaStyles GetParaStyles(const SwDoc &rDoc);
528 /** Get a Paragraph Style which fits a given name
530 Its surprisingly tricky to get a style when all you have is a name,
531 but that's what this does
533 @param rDoc
534 The SwDoc document to search in
536 @param rName
537 The name of the style to search for
539 @return A Paragraph Style if one exists which matches the name
541 @author
542 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
544 SwTxtFmtColl* GetParaStyle(SwDoc &rDoc, const String& rName);
546 /** Get a Character Style which fits a given name
548 Its surprisingly tricky to get a style when all you have is a name,
549 but that's what this does
551 @param rDoc
552 The SwDoc document to search in
554 @param rName
555 The name of the style to search for
557 @return A Character Style if one exists which matches the name
559 @author
560 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
562 SwCharFmt* GetCharStyle(SwDoc &rDoc, const String& rName);
564 /** Sort sequence of Paragraph Styles by assigned outline style list level
566 Sort ParaStyles in ascending order of assigned outline style list level,
567 e.g. given Normal/Heading1/Heading2/.../Heading10 at their default
568 assigned outline style list levels of body level/level 1/level 2/.../level 10
570 OD 2009-02-04 #i98791#
571 adjust the sorting algorithm due to introduced outline level attribute
573 @param rStyles
574 The ParaStyles to sort
576 @author
577 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
579 void SortByAssignedOutlineStyleListLevel(ParaStyles &rStyles);
581 /** Get the SfxPoolItems of a SfxItemSet
583 Writer's SfxPoolItems (attributes) are in one of those dreaded
584 macro based pre-STL containers. Give me an STL container of the
585 items instead.
587 @param rSet
588 The SfxItemSet to get the items from
590 @param rItems
591 The sw::PoolItems to put the items into
593 @author
594 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
596 void GetPoolItems(const SfxItemSet &rSet, PoolItems &rItems);
598 const SfxPoolItem *SearchPoolItems(const PoolItems &rItems,
599 sal_uInt16 eType);
601 template<class T> const T* HasItem(const sw::PoolItems &rItems,
602 sal_uInt16 eType)
604 return item_cast<T>(SearchPoolItems(rItems, eType));
608 /** Remove properties from an SfxItemSet which a SwFmtCharFmt overrides
610 Given an SfxItemSet and a SwFmtCharFmt remove from the rSet all the
611 properties which the SwFmtCharFmt would override. An SfxItemSet
612 contains attributes, and a SwFmtCharFmt is a "Character Style",
613 so if the SfxItemSet contains bold and so does the character style
614 then delete bold from the SfxItemSet
616 @param
617 rFmt the SwFmtCharFmt which describes the Character Style
619 @param
620 rSet the SfxItemSet from which we want to remove any properties
621 which the rFmt would override
623 @author
624 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
626 @see #i24291# for examples
628 void ClearOverridesFromSet(const SwFmtCharFmt &rFmt, SfxItemSet &rSet);
630 /** Get the Floating elements in a SwDoc
632 Writer's FrmFmts may or may not be anchored to some text content,
633 e.g. Page Anchored elements will not be. For the winword export we
634 need them to have something to be anchored to. So this method
635 returns all the floating elements in a document as a STL container
636 of sw::Frames which are guaranteed to have an appropiate anchor.
638 @param rDoc
639 The SwDoc document to get the styles from
641 @param pPaM
642 The SwPam to describe the selection in the document to get the
643 elements from. 0 means the entire document.
645 @return A Frames containing the selections Floating elements
647 @author
648 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
650 Frames GetFrames(const SwDoc &rDoc, SwPaM *pPaM = 0);
652 /** Get the Frames anchored to a given node
654 Given a container of frames, find the ones anchored to a given node
656 @param rFrames
657 The container of frames to search in
659 @param rNode
660 The SwNode to check for anchors to
662 @return the Frames in rFrames anchored to rNode
664 @author
665 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
667 Frames GetFramesInNode(const Frames &rFrames, const SwNode &rNode);
669 /** Get the Frames anchored for all nodes between two points
671 Given a container of frames, find the ones anchored to the nodes
672 from start to end. Half open sequence, i.e. those anchored to
673 start, but not those anchored to end
675 @param rFrames
676 The container of frames to search in
678 @param rStart
679 The SwNode to start check for anchors from
681 @param rEnd
682 The SwNode to end check for anchors from
684 @return the Frames in rFrames anchored to rNode
686 @author
687 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
689 Frames GetFramesBetweenNodes(const Frames &rFrames,
690 const SwNode &rStart, const SwNode &rEnd);
692 /** Get the Numbering Format used on a paragraph
694 There are two differing types of numbering formats that may be on a
695 paragraph, normal and outline. The outline is that numbering you
696 see in tools->outline numbering. Theres no difference in the
697 numbering itself, just how you get it from the SwTxtNode. Needless
698 to say the filter generally couldn't care less what type of
699 numbering is in use.
701 @param rTxtNode
702 The SwTxtNode that is the paragraph
704 @return A SwNumFmt pointer that describes the numbering level
705 on this paragraph, or 0 if there is none.
707 @author
708 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
710 const SwNumFmt* GetNumFmtFromTxtNode(const SwTxtNode &rTxtNode);
712 const SwNumRule* GetNumRuleFromTxtNode(const SwTxtNode &rTxtNd);
713 const SwNumRule* GetNormalNumRuleFromTxtNode(const SwTxtNode &rTxtNd);
716 /** Get the SwNoTxtNode associated with a SwFrmFmt if here is one
718 There are two differing types of numbering formats that may be on a
719 paragraph, normal and outline. The outline is that numbering you
720 see in tools->outline numbering. Theres no difference in the
721 numbering itself, just how you get it from the SwTxtNode. Needless
722 to say the filter generally couldn't care less what type of
723 numbering is in use.
725 @param rFmt
726 The SwFrmFmt that may describe a graphic
728 @return A SwNoTxtNode pointer that describes the graphic of this
729 frame if there is one, or 0 if there is none.
731 @author
732 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
734 SwNoTxtNode *GetNoTxtNodeFromSwFrmFmt(const SwFrmFmt &rFmt);
736 /** Does a node have a "page break before" applied
738 Both text nodes and tables in writer can have "page break before"
739 This function gives a unified view to both entities
741 @param rNode
742 The SwNode to query the page break of
744 @return true if there is a page break, false otherwise
746 @author
747 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
749 bool HasPageBreak(const SwNode &rNode);
752 /** Make a best fit Polygon from a PolyPolygon
754 For custom contours in writer we use a PolyPolygon, while word uses
755 a simple polygon, so we need to try and make the best polygon from
756 a PolyPolygon
758 @param rPolyPoly
759 The PolyPolygon to try and turn into a Polygon
761 @return best fit Polygon from rPolyPoly
763 @author
764 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
766 Polygon PolygonFromPolyPolygon(const PolyPolygon &rPolyPoly);
768 /** Determine if the font is the special Star|Open Symbol font
770 @param rFontName
771 The FontName to test for being Star|Open Symbol
773 @return true if this is Star|Open Symbol
775 @author
776 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
778 bool IsStarSymbol(const String &rFontName);
780 /** Make setting a drawing object's layer in a Writer document easy
783 Word has the simple concept of a drawing object either in the
784 foreground and in the background. We have an additional complexity
785 that form components live in a seperate layer, which seems
786 unnecessarily complicated. So in the winword filter we set the
787 object's layer through this class with either SendObjectToHell for
788 the bottom layer and SendObjectToHeaven for the top and we don't
789 worry about the odd form layer design wrinkle.
791 @author
792 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
794 class SetLayer
796 private:
797 sal_uInt8 mnHeavenLayer, mnHellLayer, mnFormLayer;
798 enum Layer {eHeaven, eHell};
799 void SetObjectLayer(SdrObject &rObject, Layer eLayer) const;
800 void Swap(SetLayer &rOther) throw();
801 public:
803 /** Make Object live in the bottom drawing layer
805 @param rObject
806 The object to be set to the bottom layer
808 void SendObjectToHell(SdrObject &rObject) const;
810 /** Make Object lives in the top top layer
812 @param rObject
813 The object to be set to the bottom layer
815 void SendObjectToHeaven(SdrObject &rObject) const;
817 /** Normal constructor
819 @param rDoc
820 The Writer document whose drawing layers we will be inserting
821 objects into
823 SetLayer(const SwDoc &rDoc);
825 SetLayer(const SetLayer &rOther) throw();
826 SetLayer& operator=(const SetLayer &rOther) throw();
830 namespace hack
832 /** Map an ID valid in one SfxItemPool to its equivalent in another
834 Given a WhichId (the id that identifies a property e.g. bold) which
835 is correct in a given SfxItemPool, get the equivalent whichId in
836 another SfxItemPool
838 This arises because the drawing layer uses the same properties as
839 writer e.g. SvxWeight, but for some reason uses different ids
840 for the same properties as writer.
842 @param rDestPool
843 The SfxItemPool in whose terms the Id is returned
845 @param rSrcPool
846 The SfxItemPool in whose terms the Id is passed in
848 @param nWhich
849 The Id to transform from source to dest
851 @return 0 on failure, the correct property Id on success
853 @author
854 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
856 USHORT TransformWhichBetweenPools(const SfxItemPool &rDestPool,
857 const SfxItemPool &rSrcPool, USHORT nWhich);
859 /** Map a SwDoc WhichId to the equivalent Id for a given SfxItemSet
861 Given a WhichId (the id that identifies a property e.g. bold) which
862 is correct for a Writer document, get the equivalent whichId which
863 for a given SfxItemSet.
865 This arises because the drawing layer uses the same properties as
866 writer e.g. SvxWeight, but for some reason uses different ids
867 for the same properties as writer.
869 This is effectively the same as TransformWhichBetweenPools except
870 at a slightly different layer.
872 @param rSet
873 The SfxItemSet in whose terms the Id is returned
875 @param rDoc
876 The SwDoc in whose terms the Id is passed in
878 @param nWhich
879 The Id to transform from writer to the SfxItemSet's domain
881 @return 0 on failure, the correct SfxItemSet Id on success
883 @author
884 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
886 USHORT GetSetWhichFromSwDocWhich(const SfxItemSet &rSet,
887 const SwDoc &rDoc, USHORT nWhich);
890 /** Make inserting an OLE object into a Writer document easy
892 The rest of Office uses SdrOle2Obj for their OLE objects, Writer
893 doesn't, which makes things a bit difficult as this is the type of
894 object that the escher import code shared by the MSOffice filters
895 produces when it imports an OLE object.
897 This utility class takes ownership of the OLE object away from a
898 SdrOle2Obj and can massage it into the condition best suited to
899 insertion into Writer.
901 If the object was not transferred into Writer then it is deleted
902 during destruction.
904 @author
905 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
907 class DrawingOLEAdaptor
909 private:
910 String msOrigPersistName;
911 com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject > mxIPRef;
912 SfxObjectShell& mrPers;
913 Graphic* mpGraphic;
914 public:
915 /** Take ownership of a SdrOle2Objs OLE object
917 @param rObj
918 The SdrOle2Obj whose OLE object we want to take control of
920 @param rPers
921 The SvPersist of a SwDoc (SwDoc::GetPersist()) into which we
922 may want to move the object, or remove it from if unwanted.
924 DrawingOLEAdaptor(SdrOle2Obj &rObj, SfxObjectShell &rPers);
926 /// Destructor will destroy the owned OLE object if not transferred
927 ~DrawingOLEAdaptor();
929 /** Transfer ownership of the OLE object to a document's SvPersist
931 TransferToDoc moves the object into the persist under the name
932 passed in. This name is then suitable to be used as an argument
933 to SwDoc::InsertOLE.
935 The object is no longer owned by the adaptor after this call,
936 subsequent calls are an error and return false.
938 @param rName
939 The name to store the object under in the document.
941 @return On success true is returned, otherwise false. On
942 success rName is then suitable for user with SwDoc::InsertOLE
944 bool TransferToDoc(::rtl::OUString &rName);
945 private:
946 /// No assigning allowed
947 DrawingOLEAdaptor& operator=(const DrawingOLEAdaptor&);
948 /// No copying allowed
949 DrawingOLEAdaptor(const DrawingOLEAdaptor &rDoc);
952 #ifdef DEBUGDUMP
953 /** Create a SvStream to dump data to during debugging
955 This creates a file in the program dir of OOo, delete the SvStream
956 after you are done with it
958 @param rSuffix
959 The suffix that will be appened to this debugging file
961 @return a SvStream to dump data to
963 @author
964 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
966 SvStream *CreateDebuggingStream(const String &rSuffix);
968 /** Dump one SvStream to another
970 @param rSrc
971 The source stream
973 @param rDest
974 The destination stream
976 @param nLen
977 Optional Length of data to copy from rSrc to rDest, if unused copy
978 all available data from rSrc
980 @author
981 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
983 void DumpStream(const SvStream &rSrc, SvStream &rDest,
984 sal_uInt32 nLen = STREAM_SEEK_TO_END);
985 #endif
989 #endif
990 /* vi:set tabstop=4 shiftwidth=4 expandtab: */