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 SwFormatAnchor;
29class SwFormatContent;
30class SwDoc;
31namespace tools
32{
33class Rectangle;
34}
35class ZSortFly;
37{
38class XShape;
39}
41{
42class XTextFrame;
43}
44namespace sw
45{
46template <class T> class FrameFormats;
47class SpzFrameFormat;
48}
49
57{
58public:
60 using SavedLink = std::map<const SwFrameFormat*, const SwFrameFormat*>;
62 using SavedContent = std::map<const SwFrameFormat*, SwFormatContent>;
66 static void create(SwFrameFormat* pShape, SdrObject* pObject, bool bCopyText = false);
68 static void set(SwFrameFormat* pShape, SdrObject* pObject,
69 css::uno::Reference<css::text::XTextFrame> xNew);
73 static void destroy(const SwFrameFormat* pShape, const SdrObject* pObject);
75 static css::uno::Any queryInterface(const SwFrameFormat* pShape, const css::uno::Type& rType,
76 SdrObject* pObj);
77
79 static void syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID,
80 const css::uno::Any& rValue, SdrObject* pObj = nullptr);
82 static void syncProperty(SwFrameFormat* pShape, std::u16string_view rPropertyName,
83 const css::uno::Any& rValue, SdrObject* pObj = nullptr);
85 static void getProperty(SwFrameFormat const* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID,
86 css::uno::Any& rValue);
88 static css::uno::Any getProperty(SwFrameFormat const* pShape, const OUString& rPropName);
89
91 static css::text::TextContentAnchorType mapAnchorType(const RndStdIds& rAnchorID);
92
94 static void syncFlyFrameAttr(SwFrameFormat& rShape, SfxItemSet const& rSet, SdrObject* pObj);
95
97 static void updateTextBoxMargin(SdrObject* pObj);
98
101 static bool changeAnchor(SwFrameFormat* pShape, SdrObject* pObj);
102
105 static bool doTextBoxPositioning(SwFrameFormat* pShape, SdrObject* pObj);
106
108 static bool syncTextBoxSize(SwFrameFormat* pShape, SdrObject* pObj);
109
110 // Returns true on success. Synchronize z-order of the text frame of the given textbox
111 // by setting it one level higher than the z-order of the shape of the textbox.
112 static bool DoTextBoxZOrderCorrection(SwFrameFormat* pShape, const SdrObject* pObj);
113
125 static SwFrameFormat* getOtherTextBoxFormat(const SwFrameFormat* pFormat, sal_uInt16 nType,
126 const SdrObject* pObject = nullptr);
128 static SwFrameFormat*
129 getOtherTextBoxFormat(css::uno::Reference<css::drawing::XShape> const& xShape);
131 static css::uno::Reference<css::text::XTextFrame>
132 getUnoTextFrame(css::uno::Reference<css::drawing::XShape> const& xShape);
134 static tools::Rectangle getRelativeTextRectangle(SdrObject* pShape);
135
152 static bool isTextBox(const SwFrameFormat* pFormat, sal_uInt16 nType,
153 const SdrObject* pObject = nullptr);
154
156 static bool hasTextFrame(const SdrObject* pObj);
157
159 static sal_Int32 getCount(const SwDoc& rDoc);
161 static sal_Int32 getCount(SdrPage const* pPage);
165 static css::uno::Any getByIndex(SdrPage const* pPage, sal_Int32 nIndex);
167 static sal_Int32 getOrdNum(const SdrObject* pObject);
169 static void getShapeWrapThrough(const SwFrameFormat* pTextBox, bool& rWrapThrough);
170
172 static void saveLinks(const sw::FrameFormats<sw::SpzFrameFormat*>& rFormats,
173 std::map<const SwFrameFormat*, const SwFrameFormat*>& rLinks);
175 static void restoreLinks(std::set<ZSortFly>& rOld, std::vector<SwFrameFormat*>& rNew,
176 SavedLink& rSavedLinks);
177
179 static void synchronizeGroupTextBoxProperty(bool pFunc(SwFrameFormat*, SdrObject*),
180 SwFrameFormat* pFormat, SdrObject* pObj);
181
184 static std::vector<SwFrameFormat*> CollectTextBoxes(const SdrObject* pGroupObject,
185 SwFrameFormat* pFormat);
186
187 // Compares the anchor of the first and second given formats, and decides whether sync needed.
188 static bool isAnchorSyncNeeded(const SwFrameFormat* pFirst, const SwFrameFormat* pSecond);
189};
190
196{
197 friend class SwTextBoxLockGuard;
198
199 // One TextBox-entry
201 {
202 // The textframe format
204 // The Draw object where the textbox belongs to
206 };
207
208 // This vector stores the textboxes what belongs to this node
209 std::vector<SwTextBoxElement> m_pTextBoxes;
210 // This is the pointer to the shape format, which has this node
211 // (and the textboxes)
213
214 // Prevents oscillating during recursive clone calling.
216
217 // Protection against looping
219
220public:
221 // Not needed.
222 SwTextBoxNode() = delete;
223
224 // ctor
225 SwTextBoxNode(SwFrameFormat* pOwnerShapeFormat);
226 // dtor
228
229 // default copy ctor is enough
230 SwTextBoxNode(const SwTextBoxNode&) = default;
231
232 // This method adds a textbox entry to the shape
233 // Parameters:
234 // pDrawObject: The shape what the textbox be added to.
235 // pNewTextBox: The newly created textbox format what will be added to the shape.
236 void AddTextBox(SdrObject* pDrawObject, SwFrameFormat* pNewTextBox);
237
238 // This will remove the textbox entry.
239 // Parameters:
240 // pDrawObject: The shape which have the textbox to be deleted.
241 void DelTextBox(const SdrObject* pDrawObject, bool bDelFromDoc = false);
242
243 // This will remove the textbox entry.
244 // Parameters:
245 // pTextBox: The textbox what have to be deleted.
246 void DelTextBox(const SwFrameFormat* pTextBox, bool bDelFromDoc = false);
247
248 // This will return with the frame format of the textbox what belongs
249 // to the given shape (pDrawObject)
250 SwFrameFormat* GetTextBox(const SdrObject* pDrawObject) const;
251
252 // Clears all textboxes of this node from the doc and also from here.
253 void ClearAll();
254
255 // If this is a group shape, that returns true.
256 bool IsGroupTextBox() const;
257
258 // This returns with the shape what this class belongs to.
260
261 // This will give the current number of textboxes.
262 size_t GetTextBoxCount() const { return m_pTextBoxes.size(); };
263
264 // Returns with a const collection of textboxes owned by this node.
265 std::map<SdrObject*, SwFrameFormat*> GetAllTextBoxes() const;
266
267 // Does the copy, and assign of all textboxes of this node to the given format.
268 // Important: The given format has to be a shape-format, and must have same structure
269 // as the owner shape has. If the structure different, the cloning will be aborted.
270 void Clone(SwDoc* pDoc, const SwFormatAnchor& rNewAnc, SwFrameFormat* o_pTarget, bool bSetAttr,
271 bool bMakeFrame) const;
272
273private:
274 void Clone_Impl(SwDoc* pDoc, const SwFormatAnchor& rNewAnc, SwFrameFormat* o_pTarget,
275 const SdrObject* pSrcObj, SdrObject* pDestObj, bool bSetAttr,
276 bool bMakeFrame) const;
277};
278
279// Helper class for preventing unwanted sync calls.
281{
283
284public:
286 : m_rTextBoxes(rTextBoxes)
287 {
288 m_rTextBoxes.m_bLock = true;
289 }
290
292};
293
294#endif // INCLUDED_SW_INC_TEXTBOXHELPER_HXX
295
296/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: doc.hxx:197
FlyAnchors.
Definition: fmtanchr.hxx:37
Content, content of frame (header, footer, fly).
Definition: fmtcntnt.hxx:32
Style of a layout element.
Definition: frmfmt.hxx:72
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)
Dialog to specify the properties of date form field.
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
RndStdIds
unsigned char sal_uInt8