1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #ifndef INCLUDED_SW_INC_TEXTBOXHELPER_HXX
11 #define INCLUDED_SW_INC_TEXTBOXHELPER_HXX
17 #include <com/sun/star/drawing/XShape.hpp>
18 #include <com/sun/star/uno/Any.h>
19 #include <com/sun/star/uno/Type.h>
20 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29 class SwFormatContent
;
36 * A TextBox is a TextFrame, that is tied to a drawinglayer shape.
38 * This class provides helper methods to create, query and maintain such
41 class SW_DLLPUBLIC SwTextBoxHelper
44 /// Maps a draw format to a fly format.
45 typedef std::map
<const SwFrameFormat
*, const SwFrameFormat
*> SavedLink
;
46 /// Maps a draw format to content.
47 typedef std::map
<const SwFrameFormat
*, SwFormatContent
> SavedContent
;
48 /// Create a TextBox for a shape.
49 static void create(SwFrameFormat
* pShape
);
50 /// Destroy a TextBox for a shape.
51 static void destroy(SwFrameFormat
* pShape
);
52 /// Get interface of a shape's TextBox, if there is any.
53 static css::uno::Any
queryInterface(SwFrameFormat
* pShape
, const css::uno::Type
& rType
);
55 /// Sync property of TextBox with the one of the shape.
56 static void syncProperty(SwFrameFormat
* pShape
, sal_uInt16 nWID
, sal_uInt8 nMemberID
, const css::uno::Any
& rValue
);
57 /// Does the same, but works on properties which lack an sw-specific WID / MemberID.
58 static void syncProperty(SwFrameFormat
* pShape
, const OUString
& rPropertyName
, const css::uno::Any
& rValue
);
59 /// Get a property of the underlying TextFrame.
60 static void getProperty(SwFrameFormat
* pShape
, sal_uInt16 nWID
, sal_uInt8 nMemberID
, css::uno::Any
& rValue
);
62 /// Similar to syncProperty(), but used by the internal API (e.g. for UI purposes).
63 static void syncFlyFrmAttr(SwFrameFormat
& rShape
, SfxItemSet
& rSet
);
65 /// If we have an associated TextFrame, then return that.
66 static SwFrameFormat
* findTextBox(const SwFrameFormat
* pShape
);
67 static SwFrameFormat
* findTextBox(css::uno::Reference
<css::drawing::XShape
> xShape
);
68 /// Return the textbox rectangle of a draw shape (in twips).
69 static Rectangle
getTextRectangle(SwFrameFormat
* pShape
, bool bAbsolute
= true);
71 /// Look up TextFrames in a document, which are in fact TextBoxes.
72 static std::set
<const SwFrameFormat
*> findTextBoxes(const SwDoc
* pDoc
);
74 * Look up TextFrames in a document, which are in fact TextBoxes.
76 * If rNode has a matching SwContentFrm, then only TextBoxes of rNode are
79 static std::set
<const SwFrameFormat
*> findTextBoxes(const SwNode
& rNode
);
80 /// Is pObject a textbox of a drawinglayer shape?
81 static bool isTextBox(const SdrObject
* pObject
);
82 /// Build a textbox -> shape format map.
83 static std::map
<SwFrameFormat
*, SwFrameFormat
*> findShapes(const SwDoc
* pDoc
);
84 /// Count number of shapes in the document, excluding TextBoxes.
85 static sal_Int32
getCount(SdrPage
* pPage
, std::set
<const SwFrameFormat
*>& rTextBoxes
);
86 /// Get a shape by index, excluding TextBoxes.
87 static css::uno::Any
getByIndex(SdrPage
* pPage
, sal_Int32 nIndex
, std::set
<const SwFrameFormat
*>& rTextBoxes
) throw(css::lang::IndexOutOfBoundsException
);
88 /// Get the order of the shape, excluding TextBoxes.
89 static sal_Int32
getOrdNum(const SdrObject
* pObject
, std::set
<const SwFrameFormat
*>& rTextBoxes
);
91 /// Saves the current shape -> textbox links in a map, so they can be restored later.
92 static void saveLinks(const SwFrameFormats
& rFormats
, std::map
<const SwFrameFormat
*, const SwFrameFormat
*>& rLinks
);
93 /// Reset the shape -> textbox link on the shape, and save it to the map, so it can be restored later.
94 static void resetLink(SwFrameFormat
* pShape
, std::map
<const SwFrameFormat
*, SwFormatContent
>& rOldContent
);
95 /// Undo the effect of saveLinks() + individual resetLink() calls.
96 static void restoreLinks(std::set
<_ZSortFly
>& rOld
, std::vector
<SwFrameFormat
*>& rNew
, SavedLink
& rSavedLinks
, SavedContent
& rResetContent
);
99 #endif // INCLUDED_SW_INC_TEXTBOXHELPER_HXX
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */