Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/inc/frmfmt.hxx
Line
Count
Source
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
#ifndef INCLUDED_SW_INC_FRMFMT_HXX
20
#define INCLUDED_SW_INC_FRMFMT_HXX
21
22
#include <memory>
23
#include <com/sun/star/text/PositionLayoutDir.hpp>
24
#include <cppuhelper/weakref.hxx>
25
#include <tools/gen.hxx>
26
namespace sw
27
{
28
    template<class T> class FrameFormats;
29
    class SpzFrameFormat;
30
}
31
#include "format.hxx"
32
#include "hintids.hxx"
33
#include "swdllapi.h"
34
#include <list>
35
#include "textboxhelper.hxx"
36
37
class Graphic;
38
class IMapObject;
39
class ImageMap;
40
class SdrObject;
41
class SwAnchoredObject;
42
class SwDrawFrameFormat;
43
class SwFlyDrawContact;
44
class SwFlyFrame;
45
class SwFlyFrameFormat;
46
class SwRect;
47
class SwRootFrame;
48
class SwTableBox;
49
50
namespace sw
51
{
52
    class DocumentLayoutManager;
53
    // This is cheating: we are not really decoupling much with this hint.
54
    // SwDrawFrameFormat should probably bookkeep its SdrObject (and
55
    // SwDrawFrameFormat too) as members
56
    struct SW_DLLPUBLIC FindSdrObjectHint final : SfxHint
57
    {
58
        SdrObject*& m_rpObject;
59
        FindSdrObjectHint(SdrObject*& rpObject)
60
627k
            : SfxHint(SfxHintId::SwFindSdrObject), m_rpObject(rpObject) {};
61
        virtual ~FindSdrObjectHint() override;
62
    };
63
}
64
class SwFormatsBase;
65
class SwTableFormat;
66
67
/// Style of a layout element.
68
class SW_DLLPUBLIC SwFrameFormat
69
    : public SwFormat
70
{
71
    friend class SwDoc;
72
    friend class SwPageDesc;    ///< Is allowed to call protected CTor.
73
    friend class ::sw::DocumentLayoutManager; ///< Is allowed to call protected CTor.
74
    friend class sw::FrameFormats<SwTableFormat*>;     ///< Is allowed to update the list backref.
75
    friend class sw::FrameFormats<sw::SpzFrameFormat*>;     ///< Is allowed to update the list backref.
76
    friend class sw::FrameFormats<SwFrameFormat*>;     ///< Is allowed to update the list backref.
77
    friend class SwTextBoxHelper;
78
    friend class SwUndoFlyBase; ///< calls SetOtherTextBoxFormat
79
80
    css::uno::WeakReference<css::uno::XInterface> m_wXObject;
81
82
    // DrawingLayer FillAttributes in a preprocessed form for primitive usage
83
    drawinglayer::attribute::SdrAllFillAttributesHelperPtr  maFillAttributes;
84
85
    // The assigned SwFrmFmt list.
86
    SwFormatsBase* m_ffList;
87
88
    std::shared_ptr< SwTextBoxNode > m_pOtherTextBoxFormats;
89
90
protected:
91
    SwFrameFormat(
92
        SwAttrPool& rPool,
93
        const UIName &rFormatNm,
94
        SwFrameFormat *pDrvdFrame,
95
        sal_uInt16 nFormatWhich = RES_FRMFMT,
96
        const WhichRangesContainer& pWhichRange = aFrameFormatSetRange);
97
98
    virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
99
100
public:
101
102
1.06M
    const std::shared_ptr< SwTextBoxNode >& GetOtherTextBoxFormats() const { return m_pOtherTextBoxFormats; };
103
812
    void SetOtherTextBoxFormats(const std::shared_ptr<SwTextBoxNode>& rNew) { m_pOtherTextBoxFormats = rNew; };
104
105
    virtual ~SwFrameFormat() override;
106
107
558k
    SwFrameFormat(SwFrameFormat const &) = default;
108
    SwFrameFormat(SwFrameFormat &&) = default;
109
304k
    SwFrameFormat & operator =(SwFrameFormat const &) = default;
110
    SwFrameFormat & operator =(SwFrameFormat &&) = default;
111
112
    /// Destroys all Frames in aDepend (Frames are identified via dynamic_cast).
113
    virtual void DelFrames();
114
115
    /// Creates the views.
116
    virtual void MakeFrames();
117
118
    virtual Graphic MakeGraphic( ImageMap* pMap = nullptr, const sal_uInt32 nMaximumQuadraticPixels = 500000, const std::optional<Size>& rTargetDPI = std::nullopt );
119
120
    /**  @return the IMapObject defined at format (Fly)
121
        in the ImageMap at position Point.
122
        rPoint - test on DocPosition.
123
        pFly - optional FlyFrame, in case it is already known. */
124
    IMapObject* GetIMapObject( const Point& rPoint,
125
                                const SwFlyFrame *pFly = nullptr ) const;
126
127
    /** @return the real size of the frame - or an empty rectangle
128
       if no layout exists.
129
       If pPoint is given, look for the frame closest to it. */
130
    SwRect FindLayoutRect( const bool bPrtArea = false,
131
                           const Point* pPoint = nullptr ) const;
132
133
    /** @return the SdrObject, that is connected to the ContactObject.
134
       Only DrawFrameFormats are connected to the "real SdrObject". FlyFrameFormats
135
       are connected to a Master and all FlyFrames has the "real SdrObject".
136
       "Real SdrObject" has position and a Z-order. */
137
    SdrObject* FindSdrObject()
138
627k
    {
139
627k
        SdrObject* pObject(nullptr);
140
627k
        CallSwClientNotify(sw::FindSdrObjectHint(pObject));
141
627k
        return pObject;
142
627k
    }
143
    const SdrObject *FindSdrObject() const
144
10.3k
        { return const_cast<SwFrameFormat*>(this)->FindSdrObject(); }
145
146
          SdrObject *FindRealSdrObject();
147
    const SdrObject *FindRealSdrObject() const
148
47.1k
        { return const_cast<SwFrameFormat*>(this)->FindRealSdrObject(); }
149
150
    bool IsLowerOf( const SwFrameFormat& rFormat ) const;
151
152
    enum tLayoutDir
153
    {
154
        HORI_L2R,
155
        HORI_R2L,
156
        VERT_R2L
157
    };
158
159
    virtual SwFrameFormat::tLayoutDir GetLayoutDir() const;
160
    virtual void SetLayoutDir( const SwFrameFormat::tLayoutDir _eLayoutDir );
161
162
    virtual sal_Int16 GetPositionLayoutDir() const;
163
    virtual void SetPositionLayoutDir( const sal_Int16 _nPositionLayoutDir );
164
165
    virtual OUString GetDescription() const;
166
167
    SAL_DLLPRIVATE css::uno::WeakReference<css::uno::XInterface> const& GetXObject() const
168
56.6k
            { return m_wXObject; }
169
    SAL_DLLPRIVATE void SetXObject(css::uno::Reference<css::uno::XInterface> const& xObject)
170
56.5k
            { m_wXObject = xObject; }
171
172
    void RegisterToFormat( SwFormat& rFormat );
173
174
    // Access to DrawingLayer FillAttributes in a preprocessed form for primitive usage
175
    virtual drawinglayer::attribute::SdrAllFillAttributesHelperPtr getSdrAllFillAttributesHelper() const override;
176
    virtual bool supportsFullDrawingLayerFillAttributeSet() const override;
177
178
    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
179
180
    virtual void SetFormatName( const UIName& rNewName, bool bBroadcast=false ) override;
181
    void MoveTableBox(SwTableBox& rTableBox, const SwFrameFormat* pOldFormat);
182
    virtual bool IsVisible() const;
183
};
184
185
namespace sw
186
{
187
    class SW_DLLPUBLIC SpzFrameFormat: public SwFrameFormat {
188
        friend ::SwDrawFrameFormat;
189
        friend ::SwFlyFrameFormat;
190
        SpzFrameFormat(
191
            SwAttrPool& rPool,
192
            const UIName& rFormatName,
193
            SwFrameFormat* pDerivedFrame,
194
            sal_uInt16 nFormatWhich)
195
500k
            : SwFrameFormat(rPool, rFormatName, pDerivedFrame, nFormatWhich)
196
500k
        {
197
500k
            assert(nFormatWhich == RES_DRAWFRMFMT || nFormatWhich == RES_FLYFRMFMT);
198
500k
        };
199
    };
200
}
201
// The FlyFrame-Format
202
203
class SW_DLLPUBLIC SwFlyFrameFormat final : public sw::SpzFrameFormat
204
{
205
    friend class SwDoc;
206
    OUString msTitle;
207
    OUString msDesc;
208
    /// A tooltip has priority over an SwFormatURL and is not persisted to files.
209
    OUString msTooltip;
210
211
    /** Stores the previous position of Prt rectangle from RequestObjectResize
212
       so it can be used to move frames of non-resizable objects to align them correctly
213
       when they get borders (this is done in SwWrtShell::CalcAndGetScale) */
214
    Point   m_aLastFlyFramePrtRectPos;
215
    std::unique_ptr<SwFlyDrawContact> m_pContact;
216
217
    SwFlyFrameFormat( const SwFlyFrameFormat &rCpy ) = delete;
218
    SwFlyFrameFormat &operator=( const SwFlyFrameFormat &rCpy ) = delete;
219
220
    SwFlyFrameFormat( SwAttrPool& rPool, const UIName &rFormatNm, SwFrameFormat *pDrvdFrame );
221
222
public:
223
    virtual ~SwFlyFrameFormat() override;
224
225
    /// Creates the views.
226
    virtual void MakeFrames() override;
227
228
    SwFlyFrame* GetFrame( const Point* pDocPos = nullptr ) const;
229
230
    SwAnchoredObject* GetAnchoredObj() const;
231
232
    virtual Graphic MakeGraphic( ImageMap* pMap = nullptr, const sal_uInt32 nMaximumQuadraticPixels = 500000, const std::optional<Size>& rTargetDPI = std::nullopt ) override;
233
234
    OUString GetObjTitle() const;
235
    void SetObjTitle( const OUString& rTitle, bool bBroadcast = false );
236
237
    const OUString & GetObjTooltip() const;
238
    void SetObjTooltip(const OUString& rTooltip);
239
240
    OUString GetObjDescription() const;
241
    void SetObjDescription( const OUString& rDescription, bool bBroadcast = false );
242
243
    bool IsDecorative() const;
244
    void SetObjDecorative(bool isDecorative);
245
246
    /** SwFlyFrameFormat::IsBackgroundTransparent
247
248
        Override virtual method and its default implementation,
249
        because format of fly frame provides transparent backgrounds.
250
        Method determines, if background of fly frame is transparent.
251
252
        @return true, if background color is transparent, but not "no fill"
253
        or an existing background graphic is transparent.
254
    */
255
    virtual bool IsBackgroundTransparent() const override;
256
257
    /** SwFlyFrameFormat::IsBackgroundBrushInherited
258
259
        Method to determine, if the brush for drawing the
260
        background is "inherited" from its parent/grandparent.
261
        This is the case, if no background graphic is set and the background
262
        color is "no fill"/"auto fill"
263
264
        @return true, if background brush is "inherited" from parent/grandparent
265
    */
266
    bool IsBackgroundBrushInherited() const;
267
268
0
    const Point & GetLastFlyFramePrtRectPos() const       { return m_aLastFlyFramePrtRectPos; }
269
0
    void SetLastFlyFramePrtRectPos( const Point &rPoint ) { m_aLastFlyFramePrtRectPos = rPoint; }
270
271
    SwFlyDrawContact* GetOrCreateContact();
272
273
    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
274
};
275
276
//The DrawFrame-Format
277
278
279
class SwDrawFrameFormat;
280
class SwDrawContact;
281
class SdrTextObj;
282
283
namespace sw
284
{
285
    enum class DrawFrameFormatHintId {
286
        DYING,
287
        PREPPASTING,
288
        PREP_INSERT_FLY,
289
        PREP_DELETE_FLY,
290
        PAGE_OUT_OF_BOUNDS,
291
        MAKE_FRAMES,
292
        DELETE_FRAMES,
293
        POST_RESTORE_FLY_ANCHOR,
294
    };
295
    struct DrawFrameFormatHint final: SfxHint
296
    {
297
        DrawFrameFormatHintId m_eId;
298
        DrawFrameFormatHint(DrawFrameFormatHintId eId)
299
387k
            : SfxHint(SfxHintId::SwDrawFrameFormat), m_eId(eId) {};
300
        virtual ~DrawFrameFormatHint() override;
301
    };
302
    struct CheckDrawFrameFormatLayerHint final: SfxHint
303
    {
304
        bool* m_bCheckControlLayer;
305
        CheckDrawFrameFormatLayerHint(bool* bCheckControlLayer)
306
18.4k
            : SfxHint(SfxHintId::SwCheckDrawFrameFormatLayer),
307
18.4k
              m_bCheckControlLayer(bCheckControlLayer) {};
308
        virtual ~CheckDrawFrameFormatLayerHint() override;
309
    };
310
    struct ContactChangedHint final: SfxHint
311
    {
312
        SdrObject** m_ppObject;
313
        ContactChangedHint(SdrObject** ppObject)
314
0
            : SfxHint(SfxHintId::SwContactChanged),
315
0
              m_ppObject(ppObject) {};
316
        virtual ~ContactChangedHint() override;
317
    };
318
    struct DrawFormatLayoutCopyHint final : SfxHint
319
    {
320
        SwDrawFrameFormat& m_rDestFormat;
321
        SwDoc& m_rDestDoc;
322
        DrawFormatLayoutCopyHint(SwDrawFrameFormat& rDestFormat, SwDoc& rDestDoc)
323
9.73k
            : SfxHint(SfxHintId::SwDrawFormatLayoutCopy),
324
9.73k
              m_rDestFormat(rDestFormat), m_rDestDoc(rDestDoc) {};
325
        virtual ~DrawFormatLayoutCopyHint() override;
326
    };
327
    enum class WW8AnchorConv
328
    {
329
        NO_CONV,
330
        CONV2PG,
331
        CONV2COL_OR_PARA,
332
        CONV2CHAR,
333
        CONV2LINE,
334
        RELTOTABLECELL
335
    };
336
    struct WW8AnchorConvResult final
337
    {
338
        WW8AnchorConv m_eHoriConv;
339
        WW8AnchorConv m_eVertConv;
340
        bool m_bConverted;
341
        Point m_aPos;
342
0
        WW8AnchorConvResult(WW8AnchorConv eHoriConv, WW8AnchorConv eVertConv) : m_eHoriConv(eHoriConv), m_eVertConv(eVertConv), m_bConverted(false) {};
343
    };
344
    struct SW_DLLPUBLIC WW8AnchorConvHint final : SfxHint
345
    {
346
        WW8AnchorConvResult& m_rResult;
347
        WW8AnchorConvHint(WW8AnchorConvResult& rResult)
348
0
            : SfxHint(SfxHintId::SwWW8AnchorConv),
349
0
              m_rResult(rResult) {};
350
        virtual ~WW8AnchorConvHint() override;
351
    };
352
    struct RestoreFlyAnchorHint final : SfxHint
353
    {
354
        const Point m_aPos;
355
        RestoreFlyAnchorHint(Point aPos)
356
0
            : SfxHint(SfxHintId::SwRestoreFlyAnchor),
357
0
              m_aPos(aPos) {};
358
        virtual ~RestoreFlyAnchorHint() override;
359
    };
360
    struct CreatePortionHint final : SfxHint
361
    {
362
        SwDrawContact** m_ppContact;
363
        CreatePortionHint(SwDrawContact** ppContact)
364
32
            : SfxHint(SfxHintId::SwCreatePortion),
365
32
              m_ppContact(ppContact) {};
366
        virtual ~CreatePortionHint() override;
367
    };
368
    struct CollectTextObjectsHint final : SfxHint
369
    {
370
        std::list<SdrTextObj*>& m_rTextObjects;
371
        CollectTextObjectsHint(std::list<SdrTextObj*>& rTextObjects)
372
0
            : SfxHint(SfxHintId::SwCollectTextObjects),
373
0
              m_rTextObjects(rTextObjects) {};
374
        virtual ~CollectTextObjectsHint() override;
375
    };
376
    struct GetZOrderHint final : SfxHint
377
    {
378
        sal_uInt32& m_rnZOrder;
379
        GetZOrderHint(sal_uInt32& rnZOrder)
380
21.4k
            : SfxHint(SfxHintId::SwGetZOrder),
381
21.4k
              m_rnZOrder(rnZOrder) {};
382
        virtual ~GetZOrderHint() override;
383
    };
384
    struct GetObjectConnectedHint final : SfxHint
385
    {
386
        bool& m_risConnected;
387
        const SwRootFrame* m_pRoot;
388
        GetObjectConnectedHint(bool& risConnected, const SwRootFrame* pRoot)
389
304
            : SfxHint(SfxHintId::SwGetObjectConnected),
390
304
              m_risConnected(risConnected), m_pRoot(pRoot) {};
391
        virtual ~GetObjectConnectedHint() override;
392
    };
393
}
394
395
class SW_DLLPUBLIC SwDrawFrameFormat final : public sw::SpzFrameFormat
396
{
397
    friend class SwDoc;
398
399
    mutable const SdrObject * m_pSdrObjectCached;
400
    mutable OUString m_sSdrObjectCachedComment;
401
402
    SwDrawFrameFormat( const SwDrawFrameFormat &rCpy ) = delete;
403
    SwDrawFrameFormat &operator=( const SwDrawFrameFormat &rCpy ) = delete;
404
405
    SwFrameFormat::tLayoutDir meLayoutDir;
406
407
    sal_Int16 mnPositionLayoutDir;
408
409
    bool mbPosAttrSet;
410
411
    SwDrawFrameFormat(SwAttrPool& rPool, const UIName& rFormatName, SwFrameFormat* pDerivedFrame)
412
201k
        : sw::SpzFrameFormat(rPool, rFormatName, pDerivedFrame, RES_DRAWFRMFMT),
413
201k
          m_pSdrObjectCached(nullptr),
414
201k
          meLayoutDir(SwFrameFormat::HORI_L2R),
415
201k
          mnPositionLayoutDir(css::text::PositionLayoutDir::PositionInLayoutDirOfAnchor),
416
201k
          mbPosAttrSet(false)
417
201k
    {}
418
419
public:
420
    virtual ~SwDrawFrameFormat() override;
421
422
    /** DrawObjects are removed from the arrays at the layout.
423
     The DrawObjects are marked as deleted. */
424
    virtual void DelFrames() override;
425
426
    /** Register DrawObjects in the arrays at layout.
427
     Reset delete marks. */
428
    virtual void MakeFrames() override;
429
430
    virtual Graphic MakeGraphic( ImageMap* pMap = nullptr, const sal_uInt32 nMaximumQuadraticPixels = 500000, const std::optional<Size>& rTargetDPI = std::nullopt ) override;
431
432
    virtual SwFrameFormat::tLayoutDir GetLayoutDir() const override;
433
    virtual void SetLayoutDir( const SwFrameFormat::tLayoutDir _eLayoutDir ) override;
434
435
    virtual sal_Int16 GetPositionLayoutDir() const override;
436
    virtual void SetPositionLayoutDir( const sal_Int16 _nPositionLayoutDir ) override;
437
438
10.1k
    bool IsPosAttrSet() const { return mbPosAttrSet; }
439
22.3k
    void PosAttrSet() { mbPosAttrSet = true; }
440
441
    virtual OUString GetDescription() const override;
442
};
443
444
namespace sw {
445
446
SW_DLLPUBLIC bool IsFlyFrameFormatInHeader(const SwFrameFormat& rFormat);
447
448
void CheckAnchoredFlyConsistency(SwDoc const& rDoc);
449
450
}
451
452
#endif
453
454
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */