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/uno/Any.h>
18 #include <com/sun/star/uno/Type.h>
27 class SwFormatContent
;
49 * A TextBox is a TextFrame, that is tied to a drawinglayer shape.
51 * This class provides helper methods to create, query and maintain such
54 class SW_DLLPUBLIC SwTextBoxHelper
57 /// Maps a draw format to a fly format.
58 using SavedLink
= std::map
<const SwFrameFormat
*, const SwFrameFormat
*>;
59 /// Maps a draw format to content.
60 using SavedContent
= std::map
<const SwFrameFormat
*, SwFormatContent
>;
61 /// Create a TextBox for a shape.
62 static void create(SwFrameFormat
* pShape
);
63 /// Destroy a TextBox for a shape.
64 static void destroy(SwFrameFormat
* pShape
);
65 /// Get interface of a shape's TextBox, if there is any.
66 static css::uno::Any
queryInterface(const SwFrameFormat
* pShape
, const css::uno::Type
& rType
);
68 /// Sync property of TextBox with the one of the shape.
69 static void syncProperty(SwFrameFormat
* pShape
, sal_uInt16 nWID
, sal_uInt8 nMemberID
,
70 const css::uno::Any
& rValue
);
71 /// Does the same, but works on properties which lack an sw-specific WID / MemberID.
72 static void syncProperty(SwFrameFormat
* pShape
, const OUString
& rPropertyName
,
73 const css::uno::Any
& rValue
);
74 /// Get a property of the underlying TextFrame.
75 static void getProperty(SwFrameFormat
const* pShape
, sal_uInt16 nWID
, sal_uInt8 nMemberID
,
76 css::uno::Any
& rValue
);
78 /// Similar to syncProperty(), but used by the internal API (e.g. for UI purposes).
79 static void syncFlyFrameAttr(SwFrameFormat
& rShape
, SfxItemSet
const& rSet
);
82 * If we have an associated TextFrame, then return that.
84 * @param nType Expected frame format type.
85 * Valid types are RES_DRAWFRMFMT and RES_FLYFRMFMT.
89 static SwFrameFormat
* getOtherTextBoxFormat(const SwFrameFormat
* pFormat
, sal_uInt16 nType
);
90 /// If we have an associated TextFrame, then return that.
92 getOtherTextBoxFormat(css::uno::Reference
<css::drawing::XShape
> const& xShape
);
93 /// Return the textbox rectangle of a draw shape (in twips).
94 static tools::Rectangle
getTextRectangle(SwFrameFormat
* pShape
, bool bAbsolute
= true);
97 * Is the frame format a text box?
99 * A text box consists of a coupled fly and draw format. Most times you
100 * just want to check for a single type, otherwise you get duplicate results.
102 * @param nType Expected frame format input type.
103 * Valid types are RES_DRAWFRMFMT and RES_FLYFRMFMT.
105 static bool isTextBox(const SwFrameFormat
* pFormat
, sal_uInt16 nType
);
107 /// Count number of shapes in the document, excluding TextBoxes.
108 static sal_Int32
getCount(const SwDoc
* pDoc
);
109 /// Count number of shapes on the page, excluding TextBoxes.
110 static sal_Int32
getCount(SdrPage
const* pPage
);
111 /// Get a shape by index, excluding TextBoxes.
113 /// @throws css::lang::IndexOutOfBoundsException
114 static css::uno::Any
getByIndex(SdrPage
const* pPage
, sal_Int32 nIndex
);
115 /// Get the order of the shape, excluding TextBoxes.
116 static sal_Int32
getOrdNum(const SdrObject
* pObject
);
117 /// If pTextBox is a textbox, then set rWrapThrough to the surround of its shape.
118 static void getShapeWrapThrough(const SwFrameFormat
* pTextBox
, bool& rWrapThrough
);
120 /// Saves the current shape -> textbox links in a map, so they can be restored later.
121 static void saveLinks(const SwFrameFormats
& rFormats
,
122 std::map
<const SwFrameFormat
*, const SwFrameFormat
*>& rLinks
);
123 /// Undo the effect of saveLinks() + individual resetLink() calls.
124 static void restoreLinks(std::set
<ZSortFly
>& rOld
, std::vector
<SwFrameFormat
*>& rNew
,
125 SavedLink
& rSavedLinks
);
128 #endif // INCLUDED_SW_INC_TEXTBOXHELPER_HXX
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */