Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/sdr/properties/defaultproperties.cxx
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
#include <sal/config.h>
21
22
#include <svx/sdr/properties/defaultproperties.hxx>
23
#include <sdr/properties/itemsettools.hxx>
24
#include <svl/itemset.hxx>
25
#include <svl/whiter.hxx>
26
#include <vector>
27
#include <svx/svdobj.hxx>
28
#include <libxml/xmlwriter.h>
29
#include <svx/svdmodel.hxx>
30
#include <svx/svdtrans.hxx>
31
#include <svx/xbtmpit.hxx>
32
#include <vcl/vectorgraphicdata.hxx>
33
34
namespace sdr::properties
35
{
36
        SfxItemSet DefaultProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
37
0
        {
38
            // Basic implementation; Basic object has NO attributes
39
0
            return SfxItemSet(rPool);
40
0
        }
41
42
        DefaultProperties::DefaultProperties(SdrObject& rObj)
43
814k
        :   BaseProperties(rObj)
44
814k
        {
45
814k
        }
46
47
        DefaultProperties::DefaultProperties(const DefaultProperties& rProps, SdrObject& rObj)
48
20.6k
        :   BaseProperties(rObj)
49
20.6k
        {
50
20.6k
            if(!rProps.moItemSet)
51
0
                return;
52
53
            // Clone may be to another model and thus another ItemPool.
54
            // SfxItemSet supports that thus we are able to Clone all
55
            // SfxItemState::SET items to the target pool.
56
20.6k
            moItemSet.emplace(rProps.moItemSet->CloneAsValue(
57
20.6k
                true,
58
20.6k
                &rObj.getSdrModelFromSdrObject().GetItemPool()));
59
60
            // React on ModelChange: If metric has changed, scale items.
61
            // As seen above, clone is supported, but scale is not included,
62
            // thus: TTTT maybe add scale to SfxItemSet::Clone() (?)
63
            // tdf#117707 correct ModelChange detection
64
20.6k
            const bool bModelChange(&rObj.getSdrModelFromSdrObject() != &rProps.GetSdrObject().getSdrModelFromSdrObject());
65
66
20.6k
            if(bModelChange)
67
0
            {
68
0
                const MapUnit aOldUnit(rProps.GetSdrObject().getSdrModelFromSdrObject().GetScaleUnit());
69
0
                const MapUnit aNewUnit(rObj.getSdrModelFromSdrObject().GetScaleUnit());
70
0
                const bool bScaleUnitChanged(aNewUnit != aOldUnit);
71
72
0
                if(bScaleUnitChanged)
73
0
                {
74
0
                    const double fMetricFactor(GetMapFactor(aOldUnit, aNewUnit).X());
75
76
0
                    ScaleItemSet(*moItemSet, fMetricFactor);
77
0
                }
78
0
            }
79
80
            // do not keep parent info, this may be changed by later constructors.
81
            // This class just copies the ItemSet, ignore parent.
82
20.6k
            if(moItemSet && moItemSet->GetParent())
83
0
            {
84
0
                moItemSet->SetParent(nullptr);
85
0
            }
86
20.6k
        }
87
88
        std::unique_ptr<BaseProperties> DefaultProperties::Clone(SdrObject& rObj) const
89
0
        {
90
0
            return std::unique_ptr<BaseProperties>(new DefaultProperties(*this, rObj));
91
0
        }
92
93
835k
        DefaultProperties::~DefaultProperties() {}
94
95
        const SfxItemSet& DefaultProperties::GetObjectItemSet() const
96
51.2M
        {
97
51.2M
            if(!moItemSet)
98
798k
            {
99
798k
                moItemSet.emplace(const_cast<DefaultProperties*>(this)->CreateObjectSpecificItemSet(GetSdrObject().GetObjectItemPool()));
100
798k
                const_cast<DefaultProperties*>(this)->ForceDefaultAttributes();
101
798k
            }
102
103
51.2M
            assert(moItemSet && "Could not create an SfxItemSet(!)");
104
105
51.2M
            return *moItemSet;
106
51.2M
        }
107
108
        void DefaultProperties::SetObjectItem(const SfxPoolItem& rItem)
109
2.59M
        {
110
2.59M
            const sal_uInt16 nWhichID(rItem.Which());
111
112
2.59M
            if(!AllowItemChange(nWhichID, &rItem))
113
0
                return;
114
115
2.59M
            ItemChange(nWhichID, &rItem);
116
2.59M
            PostItemChange(nWhichID);
117
118
2.59M
            const SfxPoolItem* pItem = &rItem;
119
2.59M
            ItemSetChanged( {&pItem, 1}, 0);
120
2.59M
        }
121
122
        void DefaultProperties::SetObjectItemDirect(const SfxPoolItem& rItem)
123
2.19M
        {
124
2.19M
            const sal_uInt16 nWhichID(rItem.Which());
125
126
2.19M
            if(AllowItemChange(nWhichID, &rItem))
127
2.19M
            {
128
2.19M
                ItemChange(nWhichID, &rItem);
129
2.19M
            }
130
2.19M
        }
131
132
        void DefaultProperties::ClearObjectItem(const sal_uInt16 nWhich)
133
10.3k
        {
134
10.3k
            if(!AllowItemChange(nWhich))
135
0
                return;
136
137
10.3k
            ItemChange(nWhich);
138
10.3k
            PostItemChange(nWhich);
139
140
10.3k
            if(nWhich)
141
2.49k
            {
142
2.49k
                ItemSetChanged({}, nWhich);
143
2.49k
            }
144
10.3k
        }
145
146
        void DefaultProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
147
4.98k
        {
148
4.98k
            if(AllowItemChange(nWhich))
149
4.98k
            {
150
4.98k
                ItemChange(nWhich);
151
4.98k
            }
152
4.98k
        }
153
154
        void DefaultProperties::SetObjectItemSet(const SfxItemSet& rSet, bool bAdjustTextFrameWidthAndHeight)
155
2.14M
        {
156
2.14M
            if (rSet.HasItem(XATTR_FILLBITMAP))
157
2.55k
            {
158
2.55k
                const XFillBitmapItem* pItem = rSet.GetItem(XATTR_FILLBITMAP);
159
2.55k
                const std::shared_ptr<VectorGraphicData>& pVectorData
160
2.55k
                    = pItem->GetGraphicObject().GetGraphic().getVectorGraphicData();
161
2.55k
                if (pVectorData)
162
0
                {
163
                    // Shape is filled by a vector graphic: tell it our size as a hint.
164
0
                    basegfx::B2DTuple aSizeHint;
165
0
                    aSizeHint.setX(GetSdrObject().GetSnapRect().getOpenWidth());
166
0
                    aSizeHint.setY(GetSdrObject().GetSnapRect().getOpenHeight());
167
0
                    pVectorData->setSizeHint(aSizeHint);
168
0
                }
169
2.55k
            }
170
171
2.14M
            SfxWhichIter aWhichIter(rSet);
172
2.14M
            sal_uInt16 nWhich(aWhichIter.FirstWhich());
173
2.14M
            std::vector< const SfxPoolItem * > aPostItemChangeList;
174
            // give a hint to STL_Vector
175
2.14M
            aPostItemChangeList.reserve(rSet.Count());
176
177
336M
            while(nWhich)
178
334M
            {
179
334M
                const SfxPoolItem* pPoolItem;
180
334M
                if(SfxItemState::SET == aWhichIter.GetItemState(false, &pPoolItem))
181
12.2M
                {
182
12.2M
                    if(AllowItemChange(nWhich, pPoolItem))
183
12.2M
                    {
184
12.2M
                        ItemChange(nWhich, pPoolItem);
185
12.2M
                        aPostItemChangeList.emplace_back( pPoolItem );
186
12.2M
                    }
187
12.2M
                }
188
189
334M
                nWhich = aWhichIter.NextWhich();
190
334M
            }
191
192
2.14M
            if(!aPostItemChangeList.empty())
193
2.14M
            {
194
2.14M
                for (const auto& rItem : aPostItemChangeList)
195
12.2M
                {
196
12.2M
                    PostItemChange(rItem->Which());
197
12.2M
                }
198
199
2.14M
                ItemSetChanged(aPostItemChangeList, 0, bAdjustTextFrameWidthAndHeight);
200
2.14M
            }
201
2.14M
        }
202
203
        void DefaultProperties::ItemSetChanged(std::span< const SfxPoolItem* const > /*aChangedItems*/, sal_uInt16 /*nDeletedWhich*/, bool /*bAdjustTextFrameWidthAndHeight*/)
204
0
        {
205
0
        }
206
207
        bool DefaultProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const
208
17.0M
        {
209
17.0M
            return true;
210
17.0M
        }
211
212
        void DefaultProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/)
213
0
        {
214
0
        }
215
216
        void DefaultProperties::PostItemChange(const sal_uInt16 nWhich )
217
14.8M
        {
218
14.8M
            if( (nWhich == XATTR_FILLSTYLE) && moItemSet )
219
541k
                CleanupFillProperties(*moItemSet);
220
14.8M
        }
221
222
        void DefaultProperties::SetStyleSheet(SfxStyleSheet* /*pNewStyleSheet*/, bool /*bDontRemoveHardAttr*/,
223
                bool /*bBroadcast*/, bool /*bAdjustTextFrameWidthAndHeight*/)
224
0
        {
225
            // no StyleSheet in DefaultProperties
226
0
        }
227
228
        SfxStyleSheet* DefaultProperties::GetStyleSheet() const
229
0
        {
230
            // no StyleSheet in DefaultProperties
231
0
            return nullptr;
232
0
        }
233
234
        void DefaultProperties::ForceDefaultAttributes()
235
12.6k
        {
236
12.6k
        }
237
238
        void DefaultProperties::dumpAsXml(xmlTextWriterPtr pWriter) const
239
0
        {
240
0
            (void)xmlTextWriterStartElement(pWriter, BAD_CAST("DefaultProperties"));
241
0
            BaseProperties::dumpAsXml(pWriter);
242
0
            if (moItemSet)
243
0
            {
244
0
                moItemSet->dumpAsXml(pWriter);
245
0
            }
246
0
            (void)xmlTextWriterEndElement(pWriter);
247
0
        }
248
} // end of namespace
249
250
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */