update credits
[LibreOffice.git] / sw / source / filter / ww8 / writerhelper.hxx
blob52bfba74b6879eb053228a0589a241e49c726dd1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef SW_WRITERHELPER
21 #define SW_WRITERHELPER
23 #include <typeinfo>
24 #include <vector>
25 #include <map>
26 #include <com/sun/star/embed/XEmbeddedObject.hpp>
28 #include <sfx2/objsh.hxx>
29 #include "types.hxx"
30 #include <svl/itempool.hxx> //SfxItemPool
31 #include <svl/itemset.hxx> //SfxItemSet
32 #include <format.hxx> //SwFmt
33 #include <node.hxx> //SwCntntNode
34 #include <pam.hxx> //SwPaM
35 #include <tools/poly.hxx> //Polygon, PolyPolygon
36 #include <doc.hxx> //SwDoc
38 class SwTxtFmtColl;
39 class SwCharFmt;
40 class SdrObject;
41 class SdrOle2Obj;
42 class OutlinerParaObject;
43 class SwNumFmt;
44 class SwTxtNode;
45 class SwNoTxtNode;
46 class SwFmtCharFmt;
47 class Graphic;
48 class SwDoc;
49 class SwNumRule;
51 namespace sw
53 namespace util
55 class ItemSort
56 : public std::binary_function<sal_uInt16, sal_uInt16, bool>
58 public:
59 bool operator()(sal_uInt16 nA, sal_uInt16 nB) const;
64 namespace sw
66 /// STL container of Paragraph Styles (SwTxtFmtColl)
67 typedef std::vector<SwTxtFmtColl *> ParaStyles;
68 /// STL iterator for ParaStyles
69 typedef ParaStyles::iterator ParaStyleIter;
70 /// STL container of SfxPoolItems (Attributes)
71 typedef std::map<sal_uInt16, const SfxPoolItem *, sw::util::ItemSort> PoolItems;
72 /// STL const iterator for ParaStyles
73 typedef PoolItems::const_iterator cPoolItemIter;
76 /** Make exporting a Writer Frame easy
78 In word all frames are effectively anchored to character or as
79 character. This is nice and simple, writer is massively complex in this
80 area, so this sw::Frame simplies matters by providing a single unified
81 view of the multitute of elements in writer and their differing quirks.
83 A sw::Frame wraps a writer frame and is guaranted to have a suitable
84 anchor position available from it. It hides much of the needless
85 complexity of the multitude of floating/inline elements in writer, it...
87 Guarantees an anchor position for a frame.
88 Provides a readable way to see if we are anchored inline. (as character)
89 Provides a simple way to flag what type of entity this frame describes.
90 Provides the size of the element as drawn by writer.
92 @author
93 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
95 class Frame
97 public:
98 enum WriterSource {eTxtBox, eGraphic, eOle, eDrawing, eFormControl,eBulletGrf};
99 private:
100 const SwFrmFmt* mpFlyFrm;
101 SwPosition maPos;
102 Size maSize;
103 // #i43447# - Size of the frame in the layout.
104 // Especially needed for graphics, whose layout size can differ from its
105 // size, because it is scaled into its environment.
106 Size maLayoutSize;
108 WriterSource meWriterType;
109 const SwNode *mpStartFrameContent;
110 bool mbIsInline;
111 bool mbForBullet:1;
112 Graphic maGrf;
113 public:
114 Frame(const SwFrmFmt &rFlyFrm, const SwPosition &rPos);
115 Frame(const Graphic&, const SwPosition &);
117 /** Get the writer SwFrmFmt that this object describes
119 @return
120 The wrapped SwFrmFmt
122 const SwFrmFmt &GetFrmFmt() const { return *mpFlyFrm; }
124 /** Get the position this frame is anchored at
126 @return
127 The anchor position of this frame
129 const SwPosition &GetPosition() const { return maPos; }
131 /** Get the node this frame is anchored into
133 @return
134 The SwTxtNode this frame is anchored inside
136 const SwCntntNode *GetCntntNode() const
137 { return maPos.nNode.GetNode().GetCntntNode(); }
139 /** Get the type of frame that this wraps
141 @return
142 a WriterSource which describes the source type of this wrapper
144 WriterSource GetWriterType() const { return meWriterType; }
146 /** Is this frame inline (as character)
148 @return
149 whether this is inline or not
151 bool IsInline() const;
154 /** Even if the frame isn't an inline frame, force it to behave as one
156 There are a variety of circumstances where word cannot have
157 anything except inline elements, e.g. inside frames. So its easier
158 to force this sw::Frame into behaving as one, instead of special
159 casing export code all over the place.
162 void ForceTreatAsInline();
164 /** Get the first node of content in the frame
166 @return
167 the first node of content in the frame, might not be any at all.
169 const SwNode *GetContent() const { return mpStartFrameContent; }
170 const Graphic &GetGraphic() const { return maGrf; }
171 bool HasGraphic() const { return mbForBullet; }
174 /** Does this sw::Frame refer to the same writer content as another
176 @return
177 if the two sw::Frames are handling the same writer frame
179 bool RefersToSameFrameAs(const Frame &rOther) const
181 if (mbForBullet && rOther.mbForBullet)
182 return (maGrf == rOther.maGrf);
183 else if ((!mbForBullet) && (!rOther.mbForBullet))
184 return (mpFlyFrm == rOther.mpFlyFrm);
186 return false;
189 /** The Size of the contained element
191 @return
192 the best size to use to export to word
194 const Size GetSize() const { return maSize; }
196 /** The layout size of the contained element
198 #i43447# - Needed for graphics, which are scaled into its environment
200 @return layout size
202 const Size GetLayoutSize() const
204 return maLayoutSize;
208 /// STL container of Frames
209 typedef std::vector<Frame> Frames;
210 /// STL iterator for Frames
211 typedef std::vector<Frame>::iterator FrameIter;
214 namespace sw
216 namespace util
218 /** Provide a dynamic_cast style cast for SfxPoolItems
220 A SfxPoolItem generally need to be cast back to its original type
221 to be useful, which is both tedious and errorprone. So item_cast is
222 a helper template to aid the process and test if the cast is
223 correct.
225 @param rItem
226 The SfxPoolItem which is to be casted
228 @tplparam T
229 A SfxPoolItem derived class to cast rItem to
231 @return A rItem upcasted back to a T
233 @exception std::bad_cast Thrown if the rItem was not a T
235 @author
236 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
238 template<class T> const T & item_cast(const SfxPoolItem &rItem)
239 throw(std::bad_cast)
241 if (!rItem.IsA(STATICTYPE(T)))
242 throw std::bad_cast();
243 return static_cast<const T &>(rItem);
246 /** Provide a dynamic_cast style cast for SfxPoolItems
248 A SfxPoolItem generally need to be cast back to its original type
249 to be useful, which is both tedious and errorprone. So item_cast is
250 a helper template to aid the process and test if the cast is
251 correct.
253 @param pItem
254 The SfxPoolItem which is to be casted
256 @tplparam T
257 A SfxPoolItem derived class to cast pItem to
259 @return A pItem upcasted back to a T or 0 if pItem was not a T
261 @author
262 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
264 template<class T> const T * item_cast(const SfxPoolItem *pItem)
266 if (pItem && !pItem->IsA(STATICTYPE(T)))
267 pItem = 0;
268 return static_cast<const T *>(pItem);
271 /** Extract a SfxPoolItem derived property from a SwCntntNode
273 Writer's attributes are retrieved by passing a numeric identifier
274 and receiving a SfxPoolItem reference which must then typically be
275 cast back to its original type which is both tedious and verbose.
277 ItemGet uses item_cast () on the retrived reference to test that the
278 retrived property is of the type that the developer thinks it is.
280 @param rNode
281 The SwCntntNode to retrieve the property from
283 @param eType
284 The numeric identifier of the property to be retrieved
286 @tplparam T
287 A SfxPoolItem derived class of the retrieved property
289 @exception std::bad_cast Thrown if the property was not a T
291 @return The T requested
293 @author
294 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
296 template<class T> const T & ItemGet(const SwCntntNode &rNode,
297 sal_uInt16 eType) throw(std::bad_cast)
299 return item_cast<T>(rNode.GetAttr(eType));
302 /** Extract a SfxPoolItem derived property from a SwFmt
304 Writer's attributes are retrieved by passing a numeric identifier
305 and receiving a SfxPoolItem reference which must then typically be
306 cast back to its original type which is both tedious and verbose.
308 ItemGet uses item_cast () on the retrived reference to test that the
309 retrived property is of the type that the developer thinks it is.
311 @param rFmt
312 The SwFmt to retrieve the property from
314 @param eType
315 The numeric identifier of the property to be retrieved
317 @tplparam T
318 A SfxPoolItem derived class of the retrieved property
320 @exception std::bad_cast Thrown if the property was not a T
322 @author
323 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
325 template<class T> const T & ItemGet(const SwFmt &rFmt,
326 sal_uInt16 eType) throw(std::bad_cast)
328 return item_cast<T>(rFmt.GetFmtAttr(eType));
331 /** Extract a SfxPoolItem derived property from a SfxItemSet
333 Writer's attributes are retrieved by passing a numeric identifier
334 and receiving a SfxPoolItem reference which must then typically be
335 cast back to its original type which is both tedious and verbose.
337 ItemGet uses item_cast () on the retrived reference to test that the
338 retrived property is of the type that the developer thinks it is.
340 @param rSet
341 The SfxItemSet to retrieve the property from
343 @param eType
344 The numeric identifier of the property to be retrieved
346 @tplparam T
347 A SfxPoolItem derived class of the retrieved property
349 @exception std::bad_cast Thrown if the property was not a T
351 @return The T requested
353 @author
354 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
356 template<class T> const T & ItemGet(const SfxItemSet &rSet,
357 sal_uInt16 eType) throw(std::bad_cast)
359 return item_cast<T>(rSet.Get(eType));
362 /** Extract a default SfxPoolItem derived property from a SfxItemPool
364 Writer's attributes are retrieved by passing a numeric identifier
365 and receiving a SfxPoolItem reference which must then typically be
366 cast back to its original type which is both tedious and verbose.
368 DefaultItemGet returns a reference to the default property of a
369 given SfxItemPool for a given property id, e.g. default fontsize
371 DefaultItemGet uses item_cast () on the retrived reference to test
372 that the retrived property is of the type that the developer thinks
373 it is.
375 @param rPool
376 The SfxItemPool whose default property we want
378 @param eType
379 The numeric identifier of the default property to be retrieved
381 @tplparam T
382 A SfxPoolItem derived class of the retrieved property
384 @exception std::bad_cast Thrown if the property was not a T
386 @return The T requested
388 @author
389 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
391 template<class T> const T & DefaultItemGet(const SfxItemPool &rPool,
392 sal_uInt16 eType) throw(std::bad_cast)
394 return item_cast<T>(rPool.GetDefaultItem(eType));
397 /** Extract a default SfxPoolItem derived property from a SwDoc
399 Writer's attributes are retrieved by passing a numeric identifier
400 and receiving a SfxPoolItem reference which must then typically be
401 cast back to its original type which is both tedious and verbose.
403 DefaultItemGet returns a reference to the default property of a
404 given SwDoc (Writer Document) for a given property id, e.g default
405 fontsize
407 DefaultItemGet uses item_cast () on the retrived reference to test
408 that the retrived property is of the type that the developer thinks
409 it is.
411 @param rPool
412 The SfxItemPool whose default property we want
414 @param eType
415 The numeric identifier of the default property to be retrieved
417 @tplparam T
418 A SfxPoolItem derived class of the retrieved property
420 @exception std::bad_cast Thrown if the property was not a T
422 @return The T requested
424 @author
425 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
427 template<class T> const T & DefaultItemGet(const SwDoc &rDoc,
428 sal_uInt16 eType) throw(std::bad_cast)
430 return DefaultItemGet<T>(rDoc.GetAttrPool(), eType);
433 /** Return a pointer to a SfxPoolItem derived class if it exists in an
434 SfxItemSet
436 Writer's attributes are retrieved by passing a numeric identifier
437 and receiving a SfxPoolItem reference which must then typically be
438 cast back to its original type which is both tedious and verbose.
440 HasItem returns a pointer to the requested SfxPoolItem for a given
441 property id if it exists in the SfxItemSet or its chain of parents,
442 e.g. fontsize
444 HasItem uses item_cast () on the retrived pointer to test that the
445 retrived property is of the type that the developer thinks it is.
447 @param rSet
448 The SfxItemSet whose property we want
450 @param eType
451 The numeric identifier of the default property to be retrieved
453 @tplparam T
454 A SfxPoolItem derived class of the retrieved property
456 @return The T requested or 0 if no T found with id eType
458 @author
459 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
461 template<class T> const T* HasItem(const SfxItemSet &rSet,
462 sal_uInt16 eType)
464 return item_cast<T>(rSet.GetItem(eType));
467 /** Return a pointer to a SfxPoolItem derived class if it exists in an
468 SwFmt
470 Writer's attributes are retrieved by passing a numeric identifier
471 and receiving a SfxPoolItem reference which must then typically be
472 cast back to its original type which is both tedious and verbose.
474 HasItem returns a pointer to the requested SfxPoolItem for a given
475 property id if it exists in the SwFmt e.g. fontsize
477 HasItem uses item_cast () on the retrived pointer to test that the
478 retrived property is of the type that the developer thinks it is.
480 @param rSet
481 The SwFmt whose property we want
483 @param eType
484 The numeric identifier of the default property to be retrieved
486 @tplparam T
487 A SfxPoolItem derived class of the retrieved property
489 @return The T requested or 0 if no T found with id eType
491 @author
492 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
494 template<class T> const T* HasItem(const SwFmt &rFmt,
495 sal_uInt16 eType)
497 return HasItem<T>(rFmt.GetAttrSet(), eType);
500 /** Get the Paragraph Styles of a SwDoc
502 Writer's styles are in one of those dreaded macro based pre-STL
503 containers. Give me an STL container of the paragraph styles
504 instead.
506 @param rDoc
507 The SwDoc document to get the styles from
509 @return A ParaStyles containing the SwDoc's Paragraph Styles
511 @author
512 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
514 ParaStyles GetParaStyles(const SwDoc &rDoc);
517 /** Get a Paragraph Style which fits a given name
519 Its surprisingly tricky to get a style when all you have is a name,
520 but that's what this does
522 @param rDoc
523 The SwDoc document to search in
525 @param rName
526 The name of the style to search for
528 @return A Paragraph Style if one exists which matches the name
530 @author
531 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
533 SwTxtFmtColl* GetParaStyle(SwDoc &rDoc, const OUString& rName);
535 /** Get a Character Style which fits a given name
537 Its surprisingly tricky to get a style when all you have is a name,
538 but that's what this does
540 @param rDoc
541 The SwDoc document to search in
543 @param rName
544 The name of the style to search for
546 @return A Character Style if one exists which matches the name
548 @author
549 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
551 SwCharFmt* GetCharStyle(SwDoc &rDoc, const OUString& rName);
553 /** Sort sequence of Paragraph Styles by assigned outline style list level
555 Sort ParaStyles in ascending order of assigned outline style list level,
556 e.g. given Normal/Heading1/Heading2/.../Heading10 at their default
557 assigned outline style list levels of body level/level 1/level 2/.../level 10
559 #i98791#
560 adjust the sorting algorithm due to introduced outline level attribute
562 @param rStyles
563 The ParaStyles to sort
565 @author
566 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
568 void SortByAssignedOutlineStyleListLevel(ParaStyles &rStyles);
570 /** Get the SfxPoolItems of a SfxItemSet
572 Writer's SfxPoolItems (attributes) are in one of those dreaded
573 macro based pre-STL containers. Give me an STL container of the
574 items instead.
576 @param rSet
577 The SfxItemSet to get the items from
579 @param rItems
580 The sw::PoolItems to put the items into
582 @author
583 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
585 void GetPoolItems(const SfxItemSet &rSet, PoolItems &rItems, bool bExportParentItemSet );
587 const SfxPoolItem *SearchPoolItems(const PoolItems &rItems,
588 sal_uInt16 eType);
590 template<class T> const T* HasItem(const sw::PoolItems &rItems,
591 sal_uInt16 eType)
593 return item_cast<T>(SearchPoolItems(rItems, eType));
597 /** Remove properties from an SfxItemSet which a SwFmtCharFmt overrides
599 Given an SfxItemSet and a SwFmtCharFmt remove from the rSet all the
600 properties which the SwFmtCharFmt would override. An SfxItemSet
601 contains attributes, and a SwFmtCharFmt is a "Character Style",
602 so if the SfxItemSet contains bold and so does the character style
603 then delete bold from the SfxItemSet
605 @param
606 rFmt the SwFmtCharFmt which describes the Character Style
608 @param
609 rSet the SfxItemSet from which we want to remove any properties
610 which the rFmt would override
612 @author
613 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
615 @see #i24291# for examples
617 void ClearOverridesFromSet(const SwFmtCharFmt &rFmt, SfxItemSet &rSet);
619 /** Get the Floating elements in a SwDoc
621 Writer's FrmFmts may or may not be anchored to some text content,
622 e.g. Page Anchored elements will not be. For the winword export we
623 need them to have something to be anchored to. So this method
624 returns all the floating elements in a document as a STL container
625 of sw::Frames which are guaranteed to have an appropriate anchor.
627 @param rDoc
628 The SwDoc document to get the styles from
630 @param pPaM
631 The SwPam to describe the selection in the document to get the
632 elements from. 0 means the entire document.
634 @return A Frames containing the selections Floating elements
636 @author
637 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
639 Frames GetFrames(const SwDoc &rDoc, SwPaM *pPaM = 0);
641 /** Get the Frames anchored to a given node
643 Given a container of frames, find the ones anchored to a given node
645 @param rFrames
646 The container of frames to search in
648 @param rNode
649 The SwNode to check for anchors to
651 @return the Frames in rFrames anchored to rNode
653 @author
654 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
656 Frames GetFramesInNode(const Frames &rFrames, const SwNode &rNode);
658 /** Get the Numbering Format used on a paragraph
660 There are two differing types of numbering formats that may be on a
661 paragraph, normal and outline. The outline is that numbering you
662 see in tools->outline numbering. Theres no difference in the
663 numbering itself, just how you get it from the SwTxtNode. Needless
664 to say the filter generally couldn't care less what type of
665 numbering is in use.
667 @param rTxtNode
668 The SwTxtNode that is the paragraph
670 @return A SwNumFmt pointer that describes the numbering level
671 on this paragraph, or 0 if there is none.
673 @author
674 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
676 const SwNumFmt* GetNumFmtFromTxtNode(const SwTxtNode &rTxtNode);
678 /** Get the Numbering Format for a given level from a numbering rule
680 @param rRule
681 The numbering rule
683 @param nLevel
684 The numbering level
686 @return A SwNumFmt pointer that describes the numbering level
687 or 0 if the nLevel is out of range
689 @author
690 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
692 const SwNumFmt* GetNumFmtFromSwNumRuleLevel(const SwNumRule &rRule,
693 int nLevel);
695 const SwNumRule* GetNumRuleFromTxtNode(const SwTxtNode &rTxtNd);
696 const SwNumRule* GetNormalNumRuleFromTxtNode(const SwTxtNode &rTxtNd);
698 /** Get the SwNoTxtNode associated with a SwFrmFmt if here is one
700 There are two differing types of numbering formats that may be on a
701 paragraph, normal and outline. The outline is that numbering you
702 see in tools->outline numbering. Theres no difference in the
703 numbering itself, just how you get it from the SwTxtNode. Needless
704 to say the filter generally couldn't care less what type of
705 numbering is in use.
707 @param rFmt
708 The SwFrmFmt that may describe a graphic
710 @return A SwNoTxtNode pointer that describes the graphic of this
711 frame if there is one, or 0 if there is none.
713 @author
714 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
716 SwNoTxtNode *GetNoTxtNodeFromSwFrmFmt(const SwFrmFmt &rFmt);
718 /** Does a node have a "page break before" applied
720 Both text nodes and tables in writer can have "page break before"
721 This function gives a unified view to both entities
723 @param rNode
724 The SwNode to query the page break of
726 @return true if there is a page break, false otherwise
728 @author
729 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
731 bool HasPageBreak(const SwNode &rNode);
734 /** Make a best fit Polygon from a PolyPolygon
736 For custom contours in writer we use a PolyPolygon, while word uses
737 a simple polygon, so we need to try and make the best polygon from
738 a PolyPolygon
740 @param rPolyPoly
741 The PolyPolygon to try and turn into a Polygon
743 @return best fit Polygon from rPolyPoly
745 @author
746 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
748 Polygon PolygonFromPolyPolygon(const PolyPolygon &rPolyPoly);
750 /** Determine if the font is the special Star|Open Symbol font
752 @param rFontName
753 The FontName to test for being Star|Open Symbol
755 @return true if this is Star|Open Symbol
757 @author
758 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
760 bool IsStarSymbol(const OUString &rFontName);
762 /** Make setting a drawing object's layer in a Writer document easy
765 Word has the simple concept of a drawing object either in the
766 foreground and in the background. We have an additional complexity
767 that form components live in a separate layer, which seems
768 unnecessarily complicated. So in the winword filter we set the
769 object's layer through this class with either SendObjectToHell for
770 the bottom layer and SendObjectToHeaven for the top and we don't
771 worry about the odd form layer design wrinkle.
773 @author
774 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
776 class SetLayer
778 private:
779 sal_uInt8 mnHeavenLayer, mnHellLayer, mnFormLayer;
780 enum Layer {eHeaven, eHell};
781 void SetObjectLayer(SdrObject &rObject, Layer eLayer) const;
782 void Swap(SetLayer &rOther) throw();
783 public:
785 /** Make Object live in the bottom drawing layer
787 @param rObject
788 The object to be set to the bottom layer
790 void SendObjectToHell(SdrObject &rObject) const;
792 /** Make Object lives in the top top layer
794 @param rObject
795 The object to be set to the bottom layer
797 void SendObjectToHeaven(SdrObject &rObject) const;
799 /** Normal constructor
801 @param rDoc
802 The Writer document whose drawing layers we will be inserting
803 objects into
805 SetLayer(const SwDoc &rDoc);
807 SetLayer(const SetLayer &rOther) throw();
808 SetLayer& operator=(const SetLayer &rOther) throw();
812 namespace hack
814 /** Map an ID valid in one SfxItemPool to its equivalent in another
816 Given a WhichId (the id that identifies a property e.g. bold) which
817 is correct in a given SfxItemPool, get the equivalent whichId in
818 another SfxItemPool
820 This arises because the drawing layer uses the same properties as
821 writer e.g. SvxWeight, but for some reason uses different ids
822 for the same properties as writer.
824 @param rDestPool
825 The SfxItemPool in whose terms the Id is returned
827 @param rSrcPool
828 The SfxItemPool in whose terms the Id is passed in
830 @param nWhich
831 The Id to transform from source to dest
833 @return 0 on failure, the correct property Id on success
835 @author
836 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
838 sal_uInt16 TransformWhichBetweenPools(const SfxItemPool &rDestPool,
839 const SfxItemPool &rSrcPool, sal_uInt16 nWhich);
841 /** Map a SwDoc WhichId to the equivalent Id for a given SfxItemSet
843 Given a WhichId (the id that identifies a property e.g. bold) which
844 is correct for a Writer document, get the equivalent whichId which
845 for a given SfxItemSet.
847 This arises because the drawing layer uses the same properties as
848 writer e.g. SvxWeight, but for some reason uses different ids
849 for the same properties as writer.
851 This is effectively the same as TransformWhichBetweenPools except
852 at a slightly different layer.
854 @param rSet
855 The SfxItemSet in whose terms the Id is returned
857 @param rDoc
858 The SwDoc in whose terms the Id is passed in
860 @param nWhich
861 The Id to transform from writer to the SfxItemSet's domain
863 @return 0 on failure, the correct SfxItemSet Id on success
865 @author
866 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
868 sal_uInt16 GetSetWhichFromSwDocWhich(const SfxItemSet &rSet,
869 const SwDoc &rDoc, sal_uInt16 nWhich);
872 /** Make inserting an OLE object into a Writer document easy
874 The rest of Office uses SdrOle2Obj for their OLE objects, Writer
875 doesn't, which makes things a bit difficult as this is the type of
876 object that the escher import code shared by the MSOffice filters
877 produces when it imports an OLE object.
879 This utility class takes ownership of the OLE object away from a
880 SdrOle2Obj and can massage it into the condition best suited to
881 insertion into Writer.
883 If the object was not transferred into Writer then it is deleted
884 during destruction.
886 @author
887 <a href="mailto:cmc@openoffice.org">Caol&aacute;n McNamara</a>
889 class DrawingOLEAdaptor
891 private:
892 OUString msOrigPersistName;
893 com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject > mxIPRef;
894 SfxObjectShell& mrPers;
895 const Graphic* mpGraphic;
896 public:
897 /** Take ownership of a SdrOle2Objs OLE object
899 @param rObj
900 The SdrOle2Obj whose OLE object we want to take control of
902 @param rPers
903 The SvPersist of a SwDoc (SwDoc::GetPersist()) into which we
904 may want to move the object, or remove it from if unwanted.
906 DrawingOLEAdaptor(SdrOle2Obj &rObj, SfxObjectShell &rPers);
908 /// Destructor will destroy the owned OLE object if not transferred
909 ~DrawingOLEAdaptor();
911 /** Transfer ownership of the OLE object to a document's SvPersist
913 TransferToDoc moves the object into the persist under the name
914 passed in. This name is then suitable to be used as an argument
915 to SwDoc::InsertOLE.
917 The object is no longer owned by the adaptor after this call,
918 subsequent calls are an error and return false.
920 @param rName
921 The name to store the object under in the document.
923 @return On success true is returned, otherwise false. On
924 success rName is then suitable for user with SwDoc::InsertOLE
926 bool TransferToDoc(OUString &rName);
927 private:
928 /// No assigning allowed
929 DrawingOLEAdaptor& operator=(const DrawingOLEAdaptor&);
930 /// No copying allowed
931 DrawingOLEAdaptor(const DrawingOLEAdaptor &rDoc);
936 #endif
938 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */