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>
19 #include <com/sun/star/text/TextContentAnchorType.hpp>
20 #include <svx/swframetypes.hxx>
29 class SwFormatContent
;
36 namespace com::sun::star::drawing
40 namespace com::sun::star::text
46 * A TextBox is a TextFrame, that is tied to a drawinglayer shape.
48 * This class provides helper methods to create, query and maintain such
51 class SW_DLLPUBLIC SwTextBoxHelper
54 /// Maps a draw format to a fly format.
55 using SavedLink
= std::map
<const SwFrameFormat
*, const SwFrameFormat
*>;
56 /// Maps a draw format to content.
57 using SavedContent
= std::map
<const SwFrameFormat
*, SwFormatContent
>;
58 /// Create a TextBox for a shape. If the second parameter is true,
59 /// the original text in the shape will be copied to the frame
60 static void create(SwFrameFormat
* pShape
, bool bCopyText
= false);
61 /// Destroy a TextBox for a shape.
62 static void destroy(SwFrameFormat
* pShape
);
63 /// Get interface of a shape's TextBox, if there is any.
64 static css::uno::Any
queryInterface(const SwFrameFormat
* pShape
, const css::uno::Type
& rType
);
66 /// Sync property of TextBox with the one of the shape.
67 static void syncProperty(SwFrameFormat
* pShape
, sal_uInt16 nWID
, sal_uInt8 nMemberID
,
68 const css::uno::Any
& rValue
);
69 /// Does the same, but works on properties which lack an sw-specific WID / MemberID.
70 static void syncProperty(SwFrameFormat
* pShape
, const OUString
& rPropertyName
,
71 const css::uno::Any
& rValue
);
72 /// Get a property of the underlying TextFrame.
73 static void getProperty(SwFrameFormat
const* pShape
, sal_uInt16 nWID
, sal_uInt8 nMemberID
,
74 css::uno::Any
& rValue
);
76 /// There are two types of enum of anchor type, so this function maps this.
77 static css::text::TextContentAnchorType
mapAnchorType(const RndStdIds
& rAnchorID
);
79 /// Similar to syncProperty(), but used by the internal API (e.g. for UI purposes).
80 static void syncFlyFrameAttr(SwFrameFormat
& rShape
, SfxItemSet
const& rSet
);
82 /// Copy shape attributes to the text frame
83 static void updateTextBoxMargin(SdrObject
* pObj
);
86 * If we have an associated TextFrame, then return that.
88 * @param nType Expected frame format type.
89 * Valid types are RES_DRAWFRMFMT and RES_FLYFRMFMT.
93 static SwFrameFormat
* getOtherTextBoxFormat(const SwFrameFormat
* pFormat
, sal_uInt16 nType
);
94 /// If we have an associated TextFrame, then return that.
96 getOtherTextBoxFormat(css::uno::Reference
<css::drawing::XShape
> const& xShape
);
97 /// If we have an associated TextFrame, then return its XTextFrame.
98 static css::uno::Reference
<css::text::XTextFrame
>
99 getUnoTextFrame(css::uno::Reference
<css::drawing::XShape
> const& xShape
);
100 /// Return the textbox rectangle of a draw shape (in twips).
101 static tools::Rectangle
getTextRectangle(SwFrameFormat
* pShape
, bool bAbsolute
= true);
104 * Is the frame format a text box?
106 * A text box consists of a coupled fly and draw format. Most times you
107 * just want to check for a single type, otherwise you get duplicate results.
109 * @param nType Expected frame format input type.
110 * Valid types are RES_DRAWFRMFMT and RES_FLYFRMFMT.
112 static bool isTextBox(const SwFrameFormat
* pFormat
, sal_uInt16 nType
);
114 /// Returns true if the SdrObject has a SwTextFrame otherwise false
115 static bool hasTextFrame(const SdrObject
* pObj
);
117 /// Count number of shapes in the document, excluding TextBoxes.
118 static sal_Int32
getCount(const SwDoc
& rDoc
);
119 /// Count number of shapes on the page, excluding TextBoxes.
120 static sal_Int32
getCount(SdrPage
const* pPage
);
121 /// Get a shape by index, excluding TextBoxes.
123 /// @throws css::lang::IndexOutOfBoundsException
124 static css::uno::Any
getByIndex(SdrPage
const* pPage
, sal_Int32 nIndex
);
125 /// Get the order of the shape, excluding TextBoxes.
126 static sal_Int32
getOrdNum(const SdrObject
* pObject
);
127 /// If pTextBox is a textbox, then set rWrapThrough to the surround of its shape.
128 static void getShapeWrapThrough(const SwFrameFormat
* pTextBox
, bool& rWrapThrough
);
130 /// Saves the current shape -> textbox links in a map, so they can be restored later.
131 static void saveLinks(const SwFrameFormats
& rFormats
,
132 std::map
<const SwFrameFormat
*, const SwFrameFormat
*>& rLinks
);
133 /// Undo the effect of saveLinks() + individual resetLink() calls.
134 static void restoreLinks(std::set
<ZSortFly
>& rOld
, std::vector
<SwFrameFormat
*>& rNew
,
135 SavedLink
& rSavedLinks
);
138 #endif // INCLUDED_SW_INC_TEXTBOXHELPER_HXX
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */