Coverage Report

Created: 2025-07-07 10:01

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