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 
24 class SdrPage;
25 class SdrObject;
26 class SfxItemSet;
27 class SwFrameFormat;
28 class SwFrameFormats;
29 class SwFormatContent;
30 class SwDoc;
31 namespace tools
32 {
33 class Rectangle;
34 }
35 class ZSortFly;
37 {
38 class XShape;
39 }
40 namespace com::sun::star::text
41 {
42 class XTextFrame;
43 }
44 
52 {
53 public:
55  using SavedLink = std::map<const SwFrameFormat*, const SwFrameFormat*>;
57  using SavedContent = std::map<const SwFrameFormat*, SwFormatContent>;
61  static void create(SwFrameFormat* pShape, SdrObject* pObject, bool bCopyText = false);
63  static void set(SwFrameFormat* pShape, SdrObject* pObject,
64  css::uno::Reference<css::text::XTextFrame> xNew);
68  static void destroy(const SwFrameFormat* pShape, const SdrObject* pObject);
70  static css::uno::Any queryInterface(const SwFrameFormat* pShape, const css::uno::Type& rType,
71  SdrObject* pObj);
72 
74  static void syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID,
75  const css::uno::Any& rValue, SdrObject* pObj = nullptr);
77  static void syncProperty(SwFrameFormat* pShape, std::u16string_view rPropertyName,
78  const css::uno::Any& rValue, SdrObject* pObj = nullptr);
80  static void getProperty(SwFrameFormat const* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID,
81  css::uno::Any& rValue);
83  static css::uno::Any getProperty(SwFrameFormat const* pShape, const OUString& rPropName);
84 
86  static css::text::TextContentAnchorType mapAnchorType(const RndStdIds& rAnchorID);
87 
89  static void syncFlyFrameAttr(SwFrameFormat& rShape, SfxItemSet const& rSet, SdrObject* pObj);
90 
92  static void updateTextBoxMargin(SdrObject* pObj);
93 
96  static bool changeAnchor(SwFrameFormat* pShape, SdrObject* pObj);
97 
100  static bool doTextBoxPositioning(SwFrameFormat* pShape, SdrObject* pObj);
101 
103  static bool syncTextBoxSize(SwFrameFormat* pShape, SdrObject* pObj);
104 
105  // Returns true on success. Synchronize z-order of the text frame of the given textbox
106  // by setting it one level higher than the z-order of the shape of the textbox.
107  static bool DoTextBoxZOrderCorrection(SwFrameFormat* pShape, const SdrObject* pObj);
108 
120  static SwFrameFormat* getOtherTextBoxFormat(const SwFrameFormat* pFormat, sal_uInt16 nType,
121  const SdrObject* pObject = nullptr);
123  static SwFrameFormat*
124  getOtherTextBoxFormat(css::uno::Reference<css::drawing::XShape> const& xShape);
126  static css::uno::Reference<css::text::XTextFrame>
127  getUnoTextFrame(css::uno::Reference<css::drawing::XShape> const& xShape);
129  static tools::Rectangle getRelativeTextRectangle(SdrObject* pShape);
130 
147  static bool isTextBox(const SwFrameFormat* pFormat, sal_uInt16 nType,
148  const SdrObject* pObject = nullptr);
149 
151  static bool hasTextFrame(const SdrObject* pObj);
152 
154  static sal_Int32 getCount(const SwDoc& rDoc);
156  static sal_Int32 getCount(SdrPage const* pPage);
160  static css::uno::Any getByIndex(SdrPage const* pPage, sal_Int32 nIndex);
162  static sal_Int32 getOrdNum(const SdrObject* pObject);
164  static void getShapeWrapThrough(const SwFrameFormat* pTextBox, bool& rWrapThrough);
165 
167  static void saveLinks(const SwFrameFormats& rFormats,
168  std::map<const SwFrameFormat*, const SwFrameFormat*>& rLinks);
170  static void restoreLinks(std::set<ZSortFly>& rOld, std::vector<SwFrameFormat*>& rNew,
171  SavedLink& rSavedLinks);
172 
174  static void synchronizeGroupTextBoxProperty(bool pFunc(SwFrameFormat*, SdrObject*),
175  SwFrameFormat* pFormat, SdrObject* pObj);
176 
179  static std::vector<SwFrameFormat*> CollectTextBoxes(const SdrObject* pGroupObject,
180  SwFrameFormat* pFormat);
181 };
182 
188 {
189  // One TextBox-entry
191  {
192  // The textframe format
194  // The Draw object where the textbox belongs to
196  // This is for indicating if the textbox is in special case: for example during undo.
198  };
199 
200  // This vector stores the textboxes what belongs to this node
201  std::vector<SwTextBoxElement> m_pTextBoxes;
202  // This is the pointer to the shape format, which has this node
203  // (and the textboxes)
205 
206 public:
207  // Not needed.
208  SwTextBoxNode() = delete;
209 
210  // ctor
211  SwTextBoxNode(SwFrameFormat* pOwnerShapeFormat);
212  // dtor
213  ~SwTextBoxNode();
214 
215  // default copy ctor is enough
216  SwTextBoxNode(const SwTextBoxNode&) = default;
217 
218  // This method adds a textbox entry to the shape
219  // Parameters:
220  // pDrawObject: The shape what the textbox be added to.
221  // pNewTextBox: The newly created textbox format what will be added to the shape.
222  void AddTextBox(SdrObject* pDrawObject, SwFrameFormat* pNewTextBox);
223 
224  // This will remove the textbox entry.
225  // Parameters:
226  // pDrawObject: The shape which have the textbox to be deleted.
227  void DelTextBox(const SdrObject* pDrawObject, bool bDelFromDoc = false);
228 
229  // This will remove the textbox entry.
230  // Parameters:
231  // pTextBox: The textbox what have to be deleted.
232  void DelTextBox(const SwFrameFormat* pTextBox, bool bDelFromDoc = false);
233 
234  // This will return with the frame format of the textbox what belongs
235  // to the given shape (pDrawObject)
236  SwFrameFormat* GetTextBox(const SdrObject* pDrawObject) const;
237 
238  // Is this textbox has special state, undo for example?
239  bool IsTextBoxActive(const SdrObject* pDrawObject) const;
240 
241  // Setters for the state flag.
242  void SetTextBoxInactive(const SdrObject* pDrawObject);
243  void SetTextBoxActive(const SdrObject* pDrawObject);
244 
245  // If this is a group shape, that returns true.
246  bool IsGroupTextBox() const;
247  // This returns with the shape what this class belongs to.
249  // This will give the current number of textboxes.
250  size_t GetTextBoxCount() const { return m_pTextBoxes.size(); };
251  // Returns with a const collection of textboxes owned by this node.
252  std::map<SdrObject*, SwFrameFormat*> GetAllTextBoxes() const;
253 };
254 
255 #endif // INCLUDED_SW_INC_TEXTBOXHELPER_HXX
256 
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwFrameFormat * GetTextBox(const SdrObject *pDrawObject) const
Definition: doc.hxx:187
Textboxes are basically textframe + shape pairs.
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
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
void SetTextBoxActive(const SdrObject *pDrawObject)
bool IsGroupTextBox() const
RndStdIds
std::map< SdrObject *, SwFrameFormat * > GetAllTextBoxes() const
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
void SetTextBoxInactive(const SdrObject *pDrawObject)
void set(css::uno::UnoInterfaceReference const &value)
void DelTextBox(const SdrObject *pDrawObject, bool bDelFromDoc=false)