Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / anchoreddrawobject.hxx
blobbc52043255a07b7c1ba3209b702584b156942635
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_SW_INC_ANCHOREDDRAWOBJECT_HXX
20 #define INCLUDED_SW_INC_ANCHOREDDRAWOBJECT_HXX
22 #include <memory>
23 #include <anchoredobject.hxx>
25 namespace tools { class Rectangle; }
27 /** class for the positioning of drawing objects
29 @author OD
31 class SW_DLLPUBLIC SwAnchoredDrawObject : public SwAnchoredObject
33 private:
34 // boolean, indicating that the object position has been invalidated
35 // and that a positioning has to be performed.
36 bool mbValidPos;
38 // rectangle, keeping the last object rectangle after the positioning
39 std::unique_ptr<tools::Rectangle> mpLastObjRect;
41 // boolean, indicating that anchored drawing object hasn't been attached
42 // to a anchor frame yet. Once, it is attached to a anchor frame the
43 // boolean changes its state.
44 bool mbNotYetAttachedToAnchorFrame;
46 // boolean, indicating that anchored
47 // drawing object hasn't been positioned yet. Once, it's positioned the
48 // boolean changes its state.
49 bool mbNotYetPositioned;
51 // boolean, indicating that after change of layout direction the
52 // anchored drawing object has to be captured on the page, if it exceeds
53 // the left or right page margin.
54 // Needed for compatibility option <DoNotCaptureDrawObjsOnPage>
55 bool mbCaptureAfterLayoutDirChange;
57 /** method for the intrinsic positioning of a at-paragraph|at-character
58 anchored drawing object
60 helper method for method <MakeObjPos>
62 @author OD
64 void MakeObjPosAnchoredAtPara();
66 /** method for the intrinsic positioning of a at-page|at-frame anchored
67 drawing object
69 helper method for method <MakeObjPos>
71 @author OD
73 void MakeObjPosAnchoredAtLayout();
75 /** method to set positioning attributes (not for as-character anchored)
77 During load the positioning attributes aren't set.
78 Thus, the positioning attributes are set by the current object geometry.
79 This method is also used for the conversion for drawing objects
80 (not anchored as-character) imported from OpenOffice.org file format
81 once and directly before the first positioning.
83 @author OD
85 void SetPositioningAttr();
87 /** method to set internal anchor position of <SdrObject> instance
88 of the drawing object
90 For drawing objects the internal anchor position of the <SdrObject>
91 instance has to be set.
92 Note: This adjustment is not be done for as-character anchored
93 drawing object - the positioning code takes care of this.
94 #i31698# - API for drawing objects in Writer has
95 been adjusted. Thus, this method will only set the internal anchor
96 position of the <SdrObject> instance to the anchor position given
97 by its anchor frame.
99 @author OD
101 void SetDrawObjAnchor();
103 /** method to invalidate the given page frame
105 @author OD
107 void InvalidatePage_( SwPageFrame* _pPageFrame );
109 protected:
110 virtual void ObjectAttachedToAnchorFrame() override;
112 /** method to assure that anchored object is registered at the correct
113 page frame
115 @author OD
117 virtual void RegisterAtCorrectPage() override;
119 virtual bool SetObjTop_( const SwTwips _nTop) override;
120 virtual bool SetObjLeft_( const SwTwips _nLeft) override;
122 virtual const SwRect GetObjBoundRect() const override;
124 public:
126 SwAnchoredDrawObject();
127 virtual ~SwAnchoredDrawObject() override;
129 // declaration of pure virtual methods of base class <SwAnchoredObject>
130 virtual void MakeObjPos() override;
131 virtual void InvalidateObjPos() override;
132 bool IsValidPos() const
134 return mbValidPos;
137 // accessors to the format
138 virtual SwFrameFormat& GetFrameFormat() override;
139 virtual const SwFrameFormat& GetFrameFormat() const override;
141 // accessors to the object area and its position
142 virtual const SwRect GetObjRect() const override;
143 // Return value can be NULL.
144 const tools::Rectangle* GetLastObjRect() const { return mpLastObjRect.get();}
146 void SetLastObjRect( const tools::Rectangle& _rNewObjRect );
148 /** adjust positioning and alignment attributes for new anchor frame
150 Set horizontal and vertical position/alignment to manual position
151 relative to anchor frame area using the anchor position of the
152 new anchor frame and the current absolute drawing object position.
153 Note: For correct Undo/Redo method should only be called inside a
154 Undo-/Redo-action.
156 @author OD
158 @param <_pNewAnchorFrame>
159 input parameter - new anchor frame for the anchored object.
161 @param <_pNewObjRect>
162 optional input parameter - proposed new object rectangle. If not
163 provided the current object rectangle is taken.
165 void AdjustPositioningAttr( const SwFrame* _pNewAnchorFrame,
166 const SwRect* _pNewObjRect = nullptr );
168 /** method to notify background of drawing object
170 @author OD
172 virtual void NotifyBackground( SwPageFrame* _pPageFrame,
173 const SwRect& _rRect,
174 PrepareHint _eHint ) override;
176 bool NotYetPositioned() const
178 return mbNotYetPositioned;
181 // change of layout direction needs to be tracked
182 // for setting <mbCaptureAfterLayoutDirChange>.
183 virtual void UpdateLayoutDir() override;
184 bool IsOutsidePage() const;
186 // new Loop control
187 void ValidateThis() { mbValidPos = true; }
189 /** The element name to show in the XML dump.
191 virtual const char* getElementName( ) const override { return "SwAnchoredDrawObject"; }
194 #endif
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */