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 .
21 #include "anchoredobject.hxx"
24 namespace tools
{ class Rectangle
; }
26 /** class for the positioning of drawing objects */
27 class SwAnchoredDrawObject final
: public SwAnchoredObject
30 // boolean, indicating that the object position has been invalidated
31 // and that a positioning has to be performed.
34 // rectangle, keeping the last object rectangle after the positioning
35 std::optional
<tools::Rectangle
> maLastObjRect
;
37 // boolean, indicating that anchored drawing object hasn't been attached
38 // to an anchor frame yet. Once, it is attached to an anchor frame the
39 // boolean changes its state.
40 bool mbNotYetAttachedToAnchorFrame
;
42 // boolean, indicating that anchored
43 // drawing object hasn't been positioned yet. Once, it's positioned the
44 // boolean changes its state.
45 bool mbNotYetPositioned
;
47 // boolean, indicating that after change of layout direction the
48 // anchored drawing object has to be captured on the page, if it exceeds
49 // the left or right page margin.
50 // Needed for compatibility option <DoNotCaptureDrawObjsOnPage>
51 bool mbCaptureAfterLayoutDirChange
;
53 /** method for the intrinsic positioning of an at-paragraph|at-character
54 anchored drawing object
56 helper method for method <MakeObjPos> */
57 void MakeObjPosAnchoredAtPara();
59 /** method for the intrinsic positioning of an at-page|at-frame anchored
62 helper method for method <MakeObjPos> */
63 void MakeObjPosAnchoredAtLayout();
65 /** method to set positioning attributes (not for as-character anchored)
67 During load the positioning attributes aren't set.
68 Thus, the positioning attributes are set by the current object geometry.
69 This method is also used for the conversion for drawing objects
70 (not anchored as-character) imported from OpenOffice.org file format
71 once and directly before the first positioning. */
72 void SetPositioningAttr();
74 /** method to set internal anchor position of <SdrObject> instance
77 For drawing objects the internal anchor position of the <SdrObject>
78 instance has to be set.
79 Note: This adjustment is not be done for as-character anchored
80 drawing object - the positioning code takes care of this.
81 #i31698# - API for drawing objects in Writer has
82 been adjusted. Thus, this method will only set the internal anchor
83 position of the <SdrObject> instance to the anchor position given
84 by its anchor frame. */
85 void SetDrawObjAnchor();
87 /** method to invalidate the given page frame */
88 void InvalidatePage_( SwPageFrame
* _pPageFrame
);
90 virtual void ObjectAttachedToAnchorFrame() override
;
92 /** method to assure that anchored object is registered at the correct
95 virtual void RegisterAtCorrectPage() override
;
97 virtual bool SetObjTop_( const SwTwips _nTop
) override
;
98 virtual bool SetObjLeft_( const SwTwips _nLeft
) override
;
100 virtual SwRect
GetObjBoundRect() const override
;
104 SwAnchoredDrawObject();
105 virtual ~SwAnchoredDrawObject() override
;
107 // declaration of pure virtual methods of base class <SwAnchoredObject>
108 virtual void MakeObjPos() override
;
109 virtual void InvalidateObjPos() override
;
110 virtual void RegisterAtPage(SwPageFrame
&) override
;
111 bool IsValidPos() const
116 // accessors to the format
117 virtual SwFrameFormat
* GetFrameFormat() override
;
118 virtual const SwFrameFormat
* GetFrameFormat() const override
;
120 // accessors to the object area and its position
121 virtual SwRect
GetObjRect() const override
;
123 std::optional
<tools::Rectangle
> const & GetLastObjRect() const { return maLastObjRect
;}
124 void SetLastObjRect( const tools::Rectangle
& _rNewObjRect
);
126 /** adjust positioning and alignment attributes for new anchor frame
128 Set horizontal and vertical position/alignment to manual position
129 relative to anchor frame area using the anchor position of the
130 new anchor frame and the current absolute drawing object position.
131 Note: For correct Undo/Redo method should only be called inside a
134 @param <_pNewAnchorFrame>
135 input parameter - new anchor frame for the anchored object.
137 @param <_pNewObjRect>
138 optional input parameter - proposed new object rectangle. If not
139 provided the current object rectangle is taken.
141 void AdjustPositioningAttr( const SwFrame
* _pNewAnchorFrame
,
142 const SwRect
* _pNewObjRect
= nullptr );
144 /** method to notify background of drawing object */
145 virtual void NotifyBackground( SwPageFrame
* _pPageFrame
,
146 const SwRect
& _rRect
,
147 PrepareHint _eHint
) override
;
149 bool NotYetPositioned() const
151 return mbNotYetPositioned
;
154 // change of layout direction needs to be tracked
155 // for setting <mbCaptureAfterLayoutDirChange>.
156 virtual void UpdateLayoutDir() override
;
157 bool IsOutsidePage() const;
160 void ValidateThis() { mbValidPos
= true; }
162 /** The element name to show in the XML dump. */
163 virtual const char* getElementName( ) const override
{ return "SwAnchoredDrawObject"; }
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */