Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/editeng/boxitem.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
20
#ifndef INCLUDED_EDITENG_BOXITEM_HXX
21
#define INCLUDED_EDITENG_BOXITEM_HXX
22
23
#include <svl/poolitem.hxx>
24
#include <editeng/editengdllapi.h>
25
#include <com/sun/star/table/BorderLine2.hpp>
26
#include <o3tl/typed_flags_set.hxx>
27
#include <docmodel/color/ComplexColor.hxx>
28
#include <memory>
29
#include <array>
30
31
32
namespace editeng { class SvxBorderLine; }
33
34
// class SvxBoxItem ------------------------------------------------------
35
36
/*  [Description]
37
38
    This item describes a border attribute
39
    (all four edges and the inward distance)
40
*/
41
enum class SvxBoxItemLine
42
{
43
    TOP, BOTTOM, LEFT, RIGHT, LAST = RIGHT
44
};
45
46
/**
47
This version causes SvxBoxItem to store the 4 cell spacing distances separately
48
when serializing to stream.
49
*/
50
constexpr sal_uInt16 BOX_4DISTS_VERSION = 1;
51
/**
52
This version causes SvxBoxItem to store the styles for its border lines when
53
serializing to stream.
54
*/
55
constexpr sal_uInt16 BOX_BORDER_STYLE_VERSION = 2;
56
57
class EDITENG_DLLPUBLIC SvxBoxItem final : public SfxPoolItem
58
{
59
    std::unique_ptr<editeng::SvxBorderLine> mpTopBorderLine;
60
    std::unique_ptr<editeng::SvxBorderLine> mpBottomBorderLine;
61
    std::unique_ptr<editeng::SvxBorderLine> mpLeftBorderLine;
62
    std::unique_ptr<editeng::SvxBorderLine> mpRightBorderLine;
63
64
    sal_Int16 mnTopDistance = 0;
65
    sal_Int16 mnBottomDistance = 0;
66
    sal_Int16 mnLeftDistance = 0;
67
    sal_Int16 mnRightDistance = 0;
68
69
    // Store complex colors until lines are created...
70
    std::array<model::ComplexColor, 4> maTempComplexColors;
71
72
    bool mbRemoveAdjCellBorder = false;
73
74
    void tryMigrateComplexColor(SvxBoxItemLine eLine);
75
76
public:
77
    static SfxPoolItem* CreateDefault();
78
79
    DECLARE_ITEM_TYPE_FUNCTION(SvxBoxItem)
80
    explicit SvxBoxItem( const sal_uInt16 nId );
81
    SvxBoxItem( const SvxBoxItem &rCpy );
82
    virtual ~SvxBoxItem() override;
83
84
    // "pure virtual Methods" from SfxPoolItem
85
    virtual bool            operator==( const SfxPoolItem& ) const override;
86
162k
    virtual bool            supportsHashCode() const override { return true; }
87
    virtual size_t          hashCode() const override;
88
    virtual bool            QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
89
    virtual bool            PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
90
91
    virtual bool GetPresentation( SfxItemPresentation ePres,
92
                                    MapUnit eCoreMetric,
93
                                    MapUnit ePresMetric,
94
                                    OUString &rText, const IntlWrapper& ) const override;
95
96
    virtual SvxBoxItem*      Clone( SfxItemPool *pPool = nullptr ) const override;
97
98
    virtual void             ScaleMetrics(double fScale) override;
99
    virtual bool             HasMetrics() const override;
100
101
    const editeng::SvxBorderLine* GetTop() const
102
133M
    {
103
133M
        return mpTopBorderLine.get();
104
133M
    }
105
    const editeng::SvxBorderLine* GetBottom() const
106
22.1M
    {
107
22.1M
        return mpBottomBorderLine.get();
108
22.1M
    }
109
    const editeng::SvxBorderLine* GetLeft() const
110
7.66M
    {
111
7.66M
        return mpLeftBorderLine.get();
112
7.66M
    }
113
    const editeng::SvxBorderLine* GetRight() const
114
4.98M
    {
115
4.98M
        return mpRightBorderLine.get();
116
4.98M
    }
117
118
    editeng::SvxBorderLine* GetTop()
119
129k
    {
120
129k
        ASSERT_CHANGE_REFCOUNTED_ITEM;
121
129k
        return mpTopBorderLine.get();
122
129k
    }
123
    editeng::SvxBorderLine* GetBottom()
124
129k
    {
125
129k
        ASSERT_CHANGE_REFCOUNTED_ITEM;
126
129k
        return mpBottomBorderLine.get();
127
129k
    }
128
    editeng::SvxBorderLine* GetLeft()
129
129k
    {
130
129k
        ASSERT_CHANGE_REFCOUNTED_ITEM;
131
129k
        return mpLeftBorderLine.get();
132
129k
    }
133
    editeng::SvxBorderLine* GetRight()
134
129k
    {
135
129k
        ASSERT_CHANGE_REFCOUNTED_ITEM;
136
129k
        return mpRightBorderLine.get();
137
129k
    }
138
139
    const   editeng::SvxBorderLine* GetLine( SvxBoxItemLine nLine ) const;
140
141
    //The Pointers are being copied!
142
    void    SetLine( const editeng::SvxBorderLine* pNew, SvxBoxItemLine nLine );
143
144
    sal_Int16  GetDistance( SvxBoxItemLine nLine, bool bAllowNegative = false ) const;
145
    sal_uInt16  GetSmallestDistance() const;
146
147
0
    bool IsRemoveAdjacentCellBorder() const { return mbRemoveAdjCellBorder; }
148
149
    void    SetDistance( sal_Int16 nNew, SvxBoxItemLine nLine );
150
    void SetAllDistances(sal_Int16 nNew)
151
460k
    {
152
460k
        ASSERT_CHANGE_REFCOUNTED_ITEM;
153
460k
        mnTopDistance = mnBottomDistance = mnLeftDistance = mnRightDistance = nNew;
154
460k
    }
155
156
0
    void SetRemoveAdjacentCellBorder( bool bSet ) { ASSERT_CHANGE_REFCOUNTED_ITEM; mbRemoveAdjCellBorder = bSet; }
157
158
    // Line width plus Space plus inward distance
159
    // bEvenIfNoLine = TRUE -> Also return distance, when no Line is set
160
    sal_uInt16  CalcLineWidth( SvxBoxItemLine nLine ) const;
161
    sal_Int16  CalcLineSpace( SvxBoxItemLine nLine, bool bEvenIfNoLine = false, bool bAllowNegative = false ) const;
162
    bool HasBorder( bool bTreatPaddingAsBorder ) const;
163
    static css::table::BorderLine2 SvxLineToLine( const editeng::SvxBorderLine* pLine, bool bConvert );
164
    static bool LineToSvxLine(const css::table::BorderLine& rLine, editeng::SvxBorderLine& rSvxLine, bool bConvert);
165
    static bool LineToSvxLine(const css::table::BorderLine2& rLine, editeng::SvxBorderLine& rSvxLine, bool bConvert);
166
167
    virtual boost::property_tree::ptree dumpAsJSON() const override;
168
    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
169
};
170
171
// class SvxBoxInfoItem --------------------------------------------------
172
173
/*  [Description]
174
175
    Another item for the border. This item has only limited functionality.
176
    On one hand, the general Dialog is told by the item which options it
177
    should offer. On the other hand, this attribute  may be used to
178
    transported the borderline for the inner horizontal and vertical lines.
179
*/
180
181
enum class SvxBoxInfoItemLine
182
{
183
    HORI, VERT, LAST = VERT
184
};
185
186
enum class SvxBoxInfoItemValidFlags
187
{
188
    NONE          = 0x00,
189
    TOP           = 0x01,
190
    BOTTOM        = 0x02,
191
    LEFT          = 0x04,
192
    RIGHT         = 0x08,
193
    HORI          = 0x10,
194
    VERT          = 0x20,
195
    DISTANCE      = 0x40,
196
    DISABLE       = 0x80,
197
    ALL           = 0xff
198
};
199
namespace o3tl
200
{
201
    template<> struct typed_flags<SvxBoxInfoItemValidFlags> : is_typed_flags<SvxBoxInfoItemValidFlags, 0xff> {};
202
}
203
204
class EDITENG_DLLPUBLIC SvxBoxInfoItem final : public SfxPoolItem
205
{
206
    std::unique_ptr<editeng::SvxBorderLine> mpHorizontalLine; //inner horizontal Line
207
    std::unique_ptr<editeng::SvxBorderLine> mpVerticalLine; //inner vertical Line
208
209
    bool mbEnableHorizontalLine = false; /// true = Enable inner horizontal line.
210
    bool mbEnableVerticalLine = false; /// true = Enable inner vertical line.
211
212
    /*
213
     Currently only for StarWriter: distance inward from SvxBoxItem. If the
214
     distance is requested, then the field for the distance from the dialog be
215
     activated. nDefDist is regarded as a default value. If any line is
216
     turned on or will be turned on it must this distance be set to default.
217
     bMinDist indicates whether the user can go below this value or not.
218
     With NDIST is the current distance from the app transported back and
219
     forth to the dialogue.
220
    */
221
222
    bool mbDistance :1;  // TRUE, Unlock Distance.
223
    bool mbMinimumDistance :1;  // TRUE, Going below minimum Distance is prohibited
224
225
    SvxBoxInfoItemValidFlags mnValidFlags;
226
    sal_uInt16 mnDefaultMinimumDistance = 0; // The default or minimum distance.
227
228
public:
229
    static SfxPoolItem* CreateDefault();
230
231
    DECLARE_ITEM_TYPE_FUNCTION(SvxBoxInfoItem)
232
    explicit SvxBoxInfoItem( const sal_uInt16 nId );
233
    SvxBoxInfoItem( const SvxBoxInfoItem &rCpy );
234
    virtual ~SvxBoxInfoItem() override;
235
236
    // "pure virtual Methods" from SfxPoolItem
237
    virtual bool            operator==( const SfxPoolItem& ) const override;
238
    virtual bool            GetPresentation( SfxItemPresentation ePres,
239
                                    MapUnit eCoreMetric,
240
                                    MapUnit ePresMetric,
241
                                    OUString &rText, const IntlWrapper& ) const override;
242
    virtual bool            QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId = 0 ) const override;
243
    virtual bool            PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) override;
244
245
    virtual SvxBoxInfoItem* Clone( SfxItemPool *pPool = nullptr ) const override;
246
    virtual void            ScaleMetrics(double fScale) override;
247
    virtual bool            HasMetrics() const override;
248
249
3.33M
    const editeng::SvxBorderLine*   GetHori() const { return mpHorizontalLine.get(); }
250
2.76M
    const editeng::SvxBorderLine*   GetVert() const { return mpVerticalLine.get(); }
251
252
    //The Pointers are being copied!
253
    void                    SetLine( const editeng::SvxBorderLine* pNew, SvxBoxInfoItemLine nLine );
254
255
0
    bool IsTable() const { return mbEnableHorizontalLine && mbEnableVerticalLine; }
256
1.14M
    void SetTable(bool bNew) { mbEnableHorizontalLine = mbEnableVerticalLine = bNew; }
257
258
0
    bool IsHorEnabled() const { return mbEnableHorizontalLine; }
259
0
    void EnableHor( bool bEnable ) { mbEnableHorizontalLine = bEnable; }
260
0
    bool IsVerEnabled() const { return mbEnableVerticalLine; }
261
0
    void EnableVer( bool bEnable ) { mbEnableVerticalLine = bEnable; }
262
263
0
    bool IsDist() const { return mbDistance; }
264
    void SetDist(bool bNew)
265
1.14M
    {
266
1.14M
        mbDistance = bNew;
267
1.14M
    }
268
0
    bool IsMinDist() const { return mbMinimumDistance; }
269
1.02M
    void SetMinDist(bool bNew) { mbMinimumDistance = bNew; }
270
0
    sal_uInt16 GetDefDist() const { return mnDefaultMinimumDistance; }
271
1.02M
    void SetDefDist(sal_uInt16 nNew) { mnDefaultMinimumDistance = nNew; }
272
273
    bool IsValid( SvxBoxInfoItemValidFlags nValid ) const
274
27.6k
    {
275
27.6k
        return bool(mnValidFlags & nValid);
276
27.6k
    }
277
    void SetValid(SvxBoxInfoItemValidFlags nValid, bool bValid = true)
278
1.26M
    {
279
1.26M
        if (bValid)
280
1.25M
            mnValidFlags |= nValid;
281
6.43k
        else
282
6.43k
            mnValidFlags &= ~nValid;
283
1.26M
    }
284
    void ResetFlags();
285
286
    virtual boost::property_tree::ptree dumpAsJSON() const override;
287
};
288
289
namespace editeng
290
{
291
292
void EDITENG_DLLPUBLIC BorderDistanceFromWord(bool bFromEdge, sal_Int32& nMargin,
293
    sal_Int32& nBorderDistance, sal_Int32 nBorderWidth);
294
295
struct EDITENG_DLLPUBLIC WordPageMargins final
296
{
297
    sal_uInt16 nLeft = 0;
298
    sal_uInt16 nRight = 0;
299
    sal_uInt16 nTop = 0;
300
    sal_uInt16 nBottom = 0;
301
};
302
303
struct EDITENG_DLLPUBLIC WordBorderDistances final
304
{
305
    bool bFromEdge = false;
306
    sal_uInt16 nLeft = 0;
307
    sal_uInt16 nRight = 0;
308
    sal_uInt16 nTop = 0;
309
    sal_uInt16 nBottom = 0;
310
};
311
312
// Heuristics to decide if we need to use "from edge" offset of borders. All sizes in twips
313
void EDITENG_DLLPUBLIC BorderDistancesToWord(const SvxBoxItem& rBox, const WordPageMargins& rMargins,
314
    WordBorderDistances& rDistances);
315
316
}
317
318
#endif
319
320
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */