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"
23 #include <boost/optional.hpp>
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 boost::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
;
98 virtual bool SetObjTop_( const SwTwips _nTop
) override
;
99 virtual bool SetObjLeft_( const SwTwips _nLeft
) override
;
101 virtual SwRect
GetObjBoundRect() const override
;
105 SwAnchoredDrawObject();
106 virtual ~SwAnchoredDrawObject() override
;
108 // declaration of pure virtual methods of base class <SwAnchoredObject>
109 virtual void MakeObjPos() override
;
110 virtual void InvalidateObjPos() 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 boost::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"; }
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */