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 <optional>
15 #include <set>
16 #include <vector>
17 
18 #include <com/sun/star/uno/Any.h>
19 #include <com/sun/star/uno/Type.h>
20 #include <com/sun/star/text/TextContentAnchorType.hpp>
21 #include <svx/swframetypes.hxx>
22 
23 #include "swdllapi.h"
24 
25 class SdrPage;
26 class SdrObject;
27 class SfxItemSet;
28 class SwFrameFormat;
29 class SwFrameFormats;
30 class SwFormatContent;
31 class SwDoc;
32 namespace tools
33 {
34 class Rectangle;
35 }
36 class ZSortFly;
38 {
39 class XShape;
40 }
41 namespace com::sun::star::text
42 {
43 class XTextFrame;
44 }
45 
53 {
54 public:
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);
66  static void destroy(SwFrameFormat* pShape, SdrObject* pObject);
68  static css::uno::Any queryInterface(const SwFrameFormat* pShape, const css::uno::Type& rType);
69 
71  static void syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID,
72  const css::uno::Any& rValue, SdrObject* pObj = nullptr);
74  static void syncProperty(SwFrameFormat* pShape, std::u16string_view rPropertyName,
75  const css::uno::Any& rValue, SdrObject* pObj = nullptr);
77  static void getProperty(SwFrameFormat const* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID,
78  css::uno::Any& rValue);
80  static css::uno::Any getProperty(SwFrameFormat const* pShape, const OUString& rPropName);
81 
83  static css::text::TextContentAnchorType mapAnchorType(const RndStdIds& rAnchorID);
84 
86  static void syncFlyFrameAttr(SwFrameFormat& rShape, SfxItemSet const& rSet, SdrObject* pObj);
87 
89  static void updateTextBoxMargin(SdrObject* pObj);
90 
93  static bool setWrapThrough(SwFrameFormat* pShape);
94 
97  static bool changeAnchor(SwFrameFormat* pShape, SdrObject* pObj);
98 
101  static bool doTextBoxPositioning(SwFrameFormat* pShape, SdrObject* pObj);
102 
108  static std::optional<bool> isAnchorTypeDifferent(const SwFrameFormat* pShape);
109 
111  static bool isTextBoxShapeHasValidTextFrame(const SwFrameFormat* pShape);
112 
113  // Returns true on success. Synchronize z-order of the text frame of the given textbox
114  // by setting it one level higher than the z-order of the shape of the textbox.
115  static bool DoTextBoxZOrderCorrection(SwFrameFormat* pShape, SdrObject* pObj);
116 
128  static SwFrameFormat* getOtherTextBoxFormat(const SwFrameFormat* pFormat, sal_uInt16 nType,
129  SdrObject* pObject = nullptr);
131  static SwFrameFormat*
132  getOtherTextBoxFormat(css::uno::Reference<css::drawing::XShape> const& xShape);
134  static css::uno::Reference<css::text::XTextFrame>
135  getUnoTextFrame(css::uno::Reference<css::drawing::XShape> const& xShape);
137  static tools::Rectangle getTextRectangle(SdrObject* pShape, bool bAbsolute = true);
138 
155  static bool isTextBox(const SwFrameFormat* pFormat, sal_uInt16 nType,
156  SdrObject* pObject = nullptr);
157 
159  static bool hasTextFrame(const SdrObject* pObj);
160 
162  static sal_Int32 getCount(const SwDoc& rDoc);
164  static sal_Int32 getCount(SdrPage const* pPage);
168  static css::uno::Any getByIndex(SdrPage const* pPage, sal_Int32 nIndex);
170  static sal_Int32 getOrdNum(const SdrObject* pObject);
172  static void getShapeWrapThrough(const SwFrameFormat* pTextBox, bool& rWrapThrough);
173 
175  static void saveLinks(const SwFrameFormats& rFormats,
176  std::map<const SwFrameFormat*, const SwFrameFormat*>& rLinks);
178  static void restoreLinks(std::set<ZSortFly>& rOld, std::vector<SwFrameFormat*>& rNew,
179  SavedLink& rSavedLinks);
180 };
181 
187 {
188  // One TextBox-entry
190  {
191  // The textframe format
193  // The Draw object where the textbox belongs to
195  // This is for indicating if the textbox is in special case: for example during undo.
197  };
198 
199  // This vector stores the textboxes what belongs to this node
200  std::vector<SwTextBoxElement> m_pTextBoxes;
201  // This is the pointer to the shape format, which has this node
202  // (and the textboxes)
204 
205 public:
206  // Not needed.
207  SwTextBoxNode() = delete;
208 
209  // ctor
210  SwTextBoxNode(SwFrameFormat* pOwnerShapeFormat);
211  // dtor
212  ~SwTextBoxNode();
213 
214  // default copy ctor is enough
215  SwTextBoxNode(SwTextBoxNode&) = default;
216 
217  // This method adds a textbox entry to the shape
218  // Parameters:
219  // pDrawObject: The shape what the textbox be added to.
220  // pNewTextBox: The newly created textbox format what will be added to the shape.
221  void AddTextBox(SdrObject* pDrawObject, SwFrameFormat* pNewTextBox);
222 
223  // This will remove the textbox entry.
224  // Parameters:
225  // pDrawObject: The shape which have the textbox to be deleted.
226  void DelTextBox(SdrObject* pDrawObject);
227 
228  // This will return with the frame format of the textbox what belongs
229  // to the given shape (pDrawObject)
230  SwFrameFormat* GetTextBox(const SdrObject* pDrawObject) const;
231 
232  // Is this textbox has special state, undo for example?
233  bool IsTextBoxActive(const SdrObject* pDrawObject) const;
234 
235  // Setters for the state flag.
236  void SetTextBoxInactive(SdrObject* pDrawObject);
237  void SetTextBoxActive(SdrObject* pDrawObject);
238 
239  // If this is a group shape, that returns true.
240  bool IsGroupTextBox() const;
241  // This returns with the shape what this class belongs to.
243  // This will give the current number of textboxes.
244  size_t GetTextBoxCount() const { return m_pTextBoxes.size(); };
245 };
246 
247 #endif // INCLUDED_SW_INC_TEXTBOXHELPER_HXX
248 
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwFrameFormat * GetTextBox(const SdrObject *pDrawObject) const
Definition: doc.hxx:188
Textboxes are basically textframe + shape pairs.
void DelTextBox(SdrObject *pDrawObject)
Content, content of frame (header, footer, fly).
Definition: fmtcntnt.hxx:31
A TextBox is a TextFrame, that is tied to a drawinglayer shape.
std::vector< SwTextBoxElement > m_pTextBoxes
std::map< const SwFrameFormat *, const SwFrameFormat * > SavedLink
Maps a draw format to a fly format.
void AddTextBox(SdrObject *pDrawObject, SwFrameFormat *pNewTextBox)
Reference< deployment::XPackageRegistry > create(Reference< deployment::XPackageRegistry > const &xRootRegistry, OUString const &context, OUString const &cachePath, Reference< XComponentContext > const &xComponentContext)
OUString getProperty(uno::Reference< beans::XPropertyContainer > const &rxPropertyContainer, OUString const &rName)
Specific frame formats (frames, DrawObjects).
SwFrameFormat * GetOwnerShape()
Style of a layout element.
Definition: frmfmt.hxx:59
SwTextBoxNode()=delete
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
Helper to copy paragraph-bound Flys.
Definition: mvsave.hxx:161
SwFrameFormat * m_pOwnerShapeFormat
void SetTextBoxActive(SdrObject *pDrawObject)
void SetTextBoxInactive(SdrObject *pDrawObject)
size_t GetTextBoxCount() const
std::map< const SwFrameFormat *, SwFormatContent > SavedContent
Maps a draw format to content.
unsigned char sal_uInt8
bool IsTextBoxActive(const SdrObject *pDrawObject) const
bool IsGroupTextBox() const
RndStdIds
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)