1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "anchoredobject.hxx"
25 namespace tools
{ class Rectangle
; }
27 /** class for the positioning of drawing objects */
28 class SwAnchoredDrawObject final
: public SwAnchoredObject
31 // boolean, indicating that the object position has been invalidated
32 // and that a positioning has to be performed.
35 // rectangle, keeping the last object rectangle after the positioning
36 std::optional
<tools::Rectangle
> maLastObjRect
;
38 // boolean, indicating that anchored drawing object hasn't been attached
39 // to an anchor frame yet. Once, it is attached to an anchor frame the
40 // boolean changes its state.
41 bool mbNotYetAttachedToAnchorFrame
;
43 // boolean, indicating that anchored
44 // drawing object hasn't been positioned yet. Once, it's positioned the
45 // boolean changes its state.
46 bool mbNotYetPositioned
;
48 // boolean, indicating that after change of layout direction the
49 // anchored drawing object has to be captured on the page, if it exceeds
50 // the left or right page margin.
51 // Needed for compatibility option <DoNotCaptureDrawObjsOnPage>
52 bool mbCaptureAfterLayoutDirChange
;
54 /** method for the intrinsic positioning of an at-paragraph|at-character
55 anchored drawing object
57 helper method for method <MakeObjPos> */
58 void MakeObjPosAnchoredAtPara();
60 /** method for the intrinsic positioning of an at-page|at-frame anchored
63 helper method for method <MakeObjPos> */
64 void MakeObjPosAnchoredAtLayout();
66 /** method to set positioning attributes (not for as-character anchored)
68 During load the positioning attributes aren't set.
69 Thus, the positioning attributes are set by the current object geometry.
70 This method is also used for the conversion for drawing objects
71 (not anchored as-character) imported from OpenOffice.org file format
72 once and directly before the first positioning. */
73 void SetPositioningAttr();
75 /** method to set internal anchor position of <SdrObject> instance
78 For drawing objects the internal anchor position of the <SdrObject>
79 instance has to be set.
80 Note: This adjustment is not be done for as-character anchored
81 drawing object - the positioning code takes care of this.
82 #i31698# - API for drawing objects in Writer has
83 been adjusted. Thus, this method will only set the internal anchor
84 position of the <SdrObject> instance to the anchor position given
85 by its anchor frame. */
86 void SetDrawObjAnchor();
88 /** method to invalidate the given page frame */
89 void InvalidatePage_( SwPageFrame
* _pPageFrame
);
91 virtual void ObjectAttachedToAnchorFrame() override
;
93 /** method to assure that anchored object is registered at the correct
96 virtual void RegisterAtCorrectPage() override
;
97 virtual void RegisterAtPage(SwPageFrame
&) override
;
99 virtual bool SetObjTop_( const SwTwips _nTop
) override
;
100 virtual bool SetObjLeft_( const SwTwips _nLeft
) override
;
102 virtual SwRect
GetObjBoundRect() const override
;
106 SwAnchoredDrawObject();
107 virtual ~SwAnchoredDrawObject() override
;
109 // declaration of pure virtual methods of base class <SwAnchoredObject>
110 virtual void MakeObjPos() override
;
111 virtual void InvalidateObjPos() override
;
112 bool IsValidPos() const
117 // accessors to the format
118 virtual SwFrameFormat
& GetFrameFormat() override
;
119 virtual const SwFrameFormat
& GetFrameFormat() const override
;
121 // accessors to the object area and its position
122 virtual SwRect
GetObjRect() const override
;
124 std::optional
<tools::Rectangle
> const & GetLastObjRect() const { return maLastObjRect
;}
125 void SetLastObjRect( const tools::Rectangle
& _rNewObjRect
);
127 /** adjust positioning and alignment attributes for new anchor frame
129 Set horizontal and vertical position/alignment to manual position
130 relative to anchor frame area using the anchor position of the
131 new anchor frame and the current absolute drawing object position.
132 Note: For correct Undo/Redo method should only be called inside a
135 @param <_pNewAnchorFrame>
136 input parameter - new anchor frame for the anchored object.
138 @param <_pNewObjRect>
139 optional input parameter - proposed new object rectangle. If not
140 provided the current object rectangle is taken.
142 void AdjustPositioningAttr( const SwFrame
* _pNewAnchorFrame
,
143 const SwRect
* _pNewObjRect
= nullptr );
145 /** method to notify background of drawing object */
146 virtual void NotifyBackground( SwPageFrame
* _pPageFrame
,
147 const SwRect
& _rRect
,
148 PrepareHint _eHint
) override
;
150 bool NotYetPositioned() const
152 return mbNotYetPositioned
;
155 // change of layout direction needs to be tracked
156 // for setting <mbCaptureAfterLayoutDirChange>.
157 virtual void UpdateLayoutDir() override
;
158 bool IsOutsidePage() const;
161 void ValidateThis() { mbValidPos
= true; }
163 /** The element name to show in the XML dump. */
164 virtual const char* getElementName( ) const override
{ return "SwAnchoredDrawObject"; }
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */