LibreOffice Module sw (master) 1
textboxhelper.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10#ifndef INCLUDED_SW_INC_TEXTBOXHELPER_HXX
11#define INCLUDED_SW_INC_TEXTBOXHELPER_HXX
12
13#include <map>
14#include <set>
15#include <vector>
16
17#include <com/sun/star/uno/Any.hxx>
18#include <com/sun/star/uno/Type.h>
19#include <com/sun/star/text/TextContentAnchorType.hpp>
20#include <svx/swframetypes.hxx>
21
22#include "swdllapi.h"
23
24class SdrPage;
25class SdrObject;
26class SfxItemSet;
27class SwFrameFormat;
28class SwFrameFormats;
29class SwFormatAnchor;
30class SwFormatContent;
31class SwDoc;
32namespace tools
33{
34class Rectangle;
35}
36class ZSortFly;
38{
39class XShape;
40}
42{
43class XTextFrame;
44}
45
53{
54public:
56 using SavedLink = std::map<const SwFrameFormat*, const SwFrameFormat*>;
58 using SavedContent = std::map<const SwFrameFormat*, SwFormatContent>;
62 static void create(SwFrameFormat* pShape, SdrObject* pObject, bool bCopyText = false);
64 static void set(SwFrameFormat* pShape, SdrObject* pObject,
65 css::uno::Reference<css::text::XTextFrame> xNew);
69 static void destroy(const SwFrameFormat* pShape, const SdrObject* pObject);
71 static css::uno::Any queryInterface(const SwFrameFormat* pShape, const css::uno::Type& rType,
72 SdrObject* pObj);
73
75 static void syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID,
76 const css::uno::Any& rValue, SdrObject* pObj = nullptr);
78 static void syncProperty(SwFrameFormat* pShape, std::u16string_view rPropertyName,
79 const css::uno::Any& rValue, SdrObject* pObj = nullptr);
81 static void getProperty(SwFrameFormat const* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID,
82 css::uno::Any& rValue);
84 static css::uno::Any getProperty(SwFrameFormat const* pShape, const OUString& rPropName);
85
87 static css::text::TextContentAnchorType mapAnchorType(const RndStdIds& rAnchorID);
88
90 static void syncFlyFrameAttr(SwFrameFormat& rShape, SfxItemSet const& rSet, SdrObject* pObj);
91
93 static void updateTextBoxMargin(SdrObject* pObj);
94
97 static bool changeAnchor(SwFrameFormat* pShape, SdrObject* pObj);
98
101 static bool doTextBoxPositioning(SwFrameFormat* pShape, SdrObject* pObj);
102
104 static bool syncTextBoxSize(SwFrameFormat* pShape, SdrObject* pObj);
105
106 // Returns true on success. Synchronize z-order of the text frame of the given textbox
107 // by setting it one level higher than the z-order of the shape of the textbox.
108 static bool DoTextBoxZOrderCorrection(SwFrameFormat* pShape, const SdrObject* pObj);
109
121 static SwFrameFormat* getOtherTextBoxFormat(const SwFrameFormat* pFormat, sal_uInt16 nType,
122 const SdrObject* pObject = nullptr);
124 static SwFrameFormat*
125 getOtherTextBoxFormat(css::uno::Reference<css::drawing::XShape> const& xShape);
127 static css::uno::Reference<css::text::XTextFrame>
128 getUnoTextFrame(css::uno::Reference<css::drawing::XShape> const& xShape);
130 static tools::Rectangle getRelativeTextRectangle(SdrObject* pShape);
131
148 static bool isTextBox(const SwFrameFormat* pFormat, sal_uInt16 nType,
149 const SdrObject* pObject = nullptr);
150
152 static bool hasTextFrame(const SdrObject* pObj);
153
155 static sal_Int32 getCount(const SwDoc& rDoc);
157 static sal_Int32 getCount(SdrPage const* pPage);
161 static css::uno::Any getByIndex(SdrPage const* pPage, sal_Int32 nIndex);
163 static sal_Int32 getOrdNum(const SdrObject* pObject);
165 static void getShapeWrapThrough(const SwFrameFormat* pTextBox, bool& rWrapThrough);
166
168 static void saveLinks(const SwFrameFormats& rFormats,
169 std::map<const SwFrameFormat*, const SwFrameFormat*>& rLinks);
171 static void restoreLinks(std::set<ZSortFly>& rOld, std::vector<SwFrameFormat*>& rNew,
172 SavedLink& rSavedLinks);
173
175 static void synchronizeGroupTextBoxProperty(bool pFunc(SwFrameFormat*, SdrObject*),
176 SwFrameFormat* pFormat, SdrObject* pObj);
177
180 static std::vector<SwFrameFormat*> CollectTextBoxes(const SdrObject* pGroupObject,
181 SwFrameFormat* pFormat);
182
183 // Compares the anchor of the first and second given formats, and decides whether sync needed.
184 static bool isAnchorSyncNeeded(const SwFrameFormat* pFirst, const SwFrameFormat* pSecond);
185};
186
192{
193 friend class SwTextBoxLockGuard;
194
195 // One TextBox-entry
197 {
198 // The textframe format
200 // The Draw object where the textbox belongs to
202 };
203
204 // This vector stores the textboxes what belongs to this node
205 std::vector<SwTextBoxElement> m_pTextBoxes;
206 // This is the pointer to the shape format, which has this node
207 // (and the textboxes)
209
210 // Prevents oscillating during recursive clone calling.
212
213 // Protection against looping
215
216public:
217 // Not needed.
218 SwTextBoxNode() = delete;
219
220 // ctor
221 SwTextBoxNode(SwFrameFormat* pOwnerShapeFormat);
222 // dtor
224
225 // default copy ctor is enough
226 SwTextBoxNode(const SwTextBoxNode&) = default;
227
228 // This method adds a textbox entry to the shape
229 // Parameters:
230 // pDrawObject: The shape what the textbox be added to.
231 // pNewTextBox: The newly created textbox format what will be added to the shape.
232 void AddTextBox(SdrObject* pDrawObject, SwFrameFormat* pNewTextBox);
233
234 // This will remove the textbox entry.
235 // Parameters:
236 // pDrawObject: The shape which have the textbox to be deleted.
237 void DelTextBox(const SdrObject* pDrawObject, bool bDelFromDoc = false);
238
239 // This will remove the textbox entry.
240 // Parameters:
241 // pTextBox: The textbox what have to be deleted.
242 void DelTextBox(const SwFrameFormat* pTextBox, bool bDelFromDoc = false);
243
244 // This will return with the frame format of the textbox what belongs
245 // to the given shape (pDrawObject)
246 SwFrameFormat* GetTextBox(const SdrObject* pDrawObject) const;
247
248 // Clears all textboxes of this node from the doc and also from here.
249 void ClearAll();
250
251 // If this is a group shape, that returns true.
252 bool IsGroupTextBox() const;
253
254 // This returns with the shape what this class belongs to.
256
257 // This will give the current number of textboxes.
258 size_t GetTextBoxCount() const { return m_pTextBoxes.size(); };
259
260 // Returns with a const collection of textboxes owned by this node.
261 std::map<SdrObject*, SwFrameFormat*> GetAllTextBoxes() const;
262
263 // Does the copy, and assign of all textboxes of this node to the given format.
264 // Important: The given format has to be a shape-format, and must have same structure
265 // as the owner shape has. If the structure different, the cloning will be aborted.
266 void Clone(SwDoc* pDoc, const SwFormatAnchor& rNewAnc, SwFrameFormat* o_pTarget, bool bSetAttr,
267 bool bMakeFrame) const;
268
269private:
270 void Clone_Impl(SwDoc* pDoc, const SwFormatAnchor& rNewAnc, SwFrameFormat* o_pTarget,
271 const SdrObject* pSrcObj, SdrObject* pDestObj, bool bSetAttr,
272 bool bMakeFrame) const;
273};
274
275// Helper class for preventing unwanted sync calls.
277{
279
280public:
282 : m_rTextBoxes(rTextBoxes)
283 {
284 m_rTextBoxes.m_bLock = true;
285 }
286
288};
289
290#endif // INCLUDED_SW_INC_TEXTBOXHELPER_HXX
291
292/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: doc.hxx:192
FlyAnchors.
Definition: fmtanchr.hxx:37
Content, content of frame (header, footer, fly).
Definition: fmtcntnt.hxx:32
Style of a layout element.
Definition: frmfmt.hxx:62
Specific frame formats (frames, DrawObjects).
A TextBox is a TextFrame, that is tied to a drawinglayer shape.
std::map< const SwFrameFormat *, SwFormatContent > SavedContent
Maps a draw format to content.
static SwFrameFormat * getOtherTextBoxFormat(css::uno::Reference< css::drawing::XShape > const &xShape)
If we have an associated TextFrame, then return that.
std::map< const SwFrameFormat *, const SwFrameFormat * > SavedLink
Maps a draw format to a fly format.
SwTextBoxNode & m_rTextBoxes
SwTextBoxLockGuard(SwTextBoxNode &rTextBoxes)
Textboxes are basically textframe + shape pairs.
bool m_bIsCloningInProgress
void AddTextBox(SdrObject *pDrawObject, SwFrameFormat *pNewTextBox)
void Clone_Impl(SwDoc *pDoc, const SwFormatAnchor &rNewAnc, SwFrameFormat *o_pTarget, const SdrObject *pSrcObj, SdrObject *pDestObj, bool bSetAttr, bool bMakeFrame) const
SwFrameFormat * GetTextBox(const SdrObject *pDrawObject) const
std::map< SdrObject *, SwFrameFormat * > GetAllTextBoxes() const
bool IsGroupTextBox() const
void Clone(SwDoc *pDoc, const SwFormatAnchor &rNewAnc, SwFrameFormat *o_pTarget, bool bSetAttr, bool bMakeFrame) const
SwFrameFormat * m_pOwnerShapeFormat
std::vector< SwTextBoxElement > m_pTextBoxes
void DelTextBox(const SdrObject *pDrawObject, bool bDelFromDoc=false)
SwTextBoxNode(const SwTextBoxNode &)=default
SwTextBoxNode()=delete
size_t GetTextBoxCount() const
SwFrameFormat * GetOwnerShape()
Helper to copy paragraph-bound Flys.
Definition: mvsave.hxx:163
void set(css::uno::UnoInterfaceReference const &value)
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
css::uno::Reference< css::deployment::XPackageRegistry > create(css::uno::Reference< css::deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, css::uno::Reference< css::uno::XComponentContext > const &xComponentContext)
SVX_DLLPUBLIC OUString getProperty(css::uno::Reference< css::beans::XPropertyContainer > const &rxPropertyContainer, OUString const &rName)
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
RndStdIds
unsigned char sal_uInt8