Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/sdr/properties/customshapeproperties.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 <sdr/properties/customshapeproperties.hxx>
23
#include <svl/itemset.hxx>
24
#include <svl/style.hxx>
25
#include <svx/svdoashp.hxx>
26
#include <svx/sdooitm.hxx>
27
#include <editeng/eeitem.hxx>
28
#include <svl/whiter.hxx>
29
#include <svl/hint.hxx>
30
31
32
namespace sdr::properties
33
{
34
        void CustomShapeProperties::UpdateTextFrameStatus(bool bInvalidateRenderGeometry)
35
4.78M
        {
36
4.78M
            SdrObjCustomShape& rObj = static_cast< SdrObjCustomShape& >(GetSdrObject());
37
4.78M
            const bool bOld(rObj.mbTextFrame);
38
39
            // change TextFrame flag when bResizeShapeToFitText changes (which is mapped
40
            // on the item SDRATTR_TEXT_AUTOGROWHEIGHT for custom shapes, argh)
41
4.78M
            rObj.mbTextFrame = GetObjectItemSet().Get(SDRATTR_TEXT_AUTOGROWHEIGHT).GetValue();
42
43
            // check if it did change
44
4.78M
            if(rObj.mbTextFrame != bOld)
45
105k
            {
46
                // on change also invalidate render geometry
47
105k
                bInvalidateRenderGeometry = true;
48
49
                // #115391# Potential recursion, since it calls SetObjectItemSet again, but rObj.bTextFrame
50
                // will not change again. Thus it will be only one level and terminate safely
51
105k
                rObj.AdaptTextMinSize();
52
105k
            }
53
54
4.78M
            if(bInvalidateRenderGeometry)
55
3.96M
            {
56
                // if asked for or bResizeShapeToFitText changed, make sure that
57
                // the render geometry is reconstructed using changed parameters
58
3.96M
                rObj.InvalidateRenderGeometry();
59
3.96M
            }
60
4.78M
        }
61
62
        SfxItemSet CustomShapeProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
63
128k
        {
64
128k
            return SfxItemSet(
65
128k
                rPool,
66
128k
                svl::Items<
67
                    // Ranges from SdrAttrObj:
68
128k
                    SDRATTR_START, SDRATTR_SHADOW_LAST,
69
128k
                    SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
70
128k
                    SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
71
                    // Graphic attributes, 3D properties, CustomShape
72
                    // properties:
73
128k
                    SDRATTR_GRAF_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
74
128k
                    SDRATTR_GLOW_FIRST, SDRATTR_GLOW_TEXT_LAST,
75
128k
                    SDRATTR_TEXTCOLUMNS_FIRST, SDRATTR_TEXTCOLUMNS_LAST,
76
128k
                    SDRATTR_WRITINGMODE2, SDRATTR_WRITINGMODE2,
77
                    // Range from SdrTextObj:
78
128k
                    EE_ITEMS_START, EE_ITEMS_END>);
79
128k
        }
80
81
        bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
82
2.95M
        {
83
2.95M
            bool bAllowItemChange = true;
84
2.95M
            if ( !pNewItem )
85
0
            {
86
0
                if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
87
0
                    bAllowItemChange = false;
88
0
            }
89
2.95M
            if ( bAllowItemChange )
90
2.95M
                bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
91
2.95M
            return bAllowItemChange;
92
2.95M
        }
93
94
        void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
95
0
        {
96
0
            if ( !nWhich )
97
0
            {
98
0
                SfxWhichIter aIter( *moItemSet );
99
0
                sal_uInt16 nWhich2 = aIter.FirstWhich();
100
0
                while( nWhich2 )
101
0
                {
102
0
                    TextProperties::ClearObjectItemDirect( nWhich2 );
103
0
                    nWhich2 = aIter.NextWhich();
104
0
                }
105
0
                ItemSetChanged({}, 0);
106
0
            }
107
0
            else
108
0
                TextProperties::ClearObjectItem( nWhich );
109
0
        }
110
111
        void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
112
0
        {
113
0
            if ( !nWhich )
114
0
            {
115
0
                SfxWhichIter aIter( *moItemSet );
116
0
                sal_uInt16 nWhich2 = aIter.FirstWhich();
117
0
                while( nWhich2 )
118
0
                {
119
0
                    TextProperties::ClearObjectItemDirect( nWhich2 );
120
0
                    nWhich2 = aIter.NextWhich();
121
0
                }
122
0
            }
123
0
            else
124
0
                TextProperties::ClearObjectItemDirect( nWhich );
125
0
        }
126
127
        void CustomShapeProperties::ItemSetChanged(std::span< const SfxPoolItem* const > aChangedItems, sal_uInt16 nDeletedWhich, bool bAdjustTextFrameWidthAndHeight)
128
875k
        {
129
            // call parent
130
875k
            TextProperties::ItemSetChanged(aChangedItems, nDeletedWhich, bAdjustTextFrameWidthAndHeight);
131
132
            // update bTextFrame and RenderGeometry
133
875k
            UpdateTextFrameStatus(true);
134
875k
        }
135
136
        void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich)
137
2.67M
        {
138
2.67M
            switch(nWhich)
139
2.67M
            {
140
150k
                case SDRATTR_TEXT_AUTOGROWHEIGHT:
141
150k
                {
142
                    // #115391#  update bTextFrame and RenderGeometry using AdaptTextMinSize()
143
150k
                    UpdateTextFrameStatus(false);
144
150k
                    break;
145
0
                }
146
2.52M
                default:
147
2.52M
                {
148
2.52M
                    break;
149
0
                }
150
2.67M
            }
151
152
            // call parent
153
2.67M
            TextProperties::PostItemChange(nWhich);
154
2.67M
        }
155
156
        void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
157
2.95M
        {
158
            // call parent
159
2.95M
            TextProperties::ItemChange( nWhich, pNewItem );
160
161
            // update bTextFrame and RenderGeometry
162
2.95M
            UpdateTextFrameStatus(true);
163
2.95M
        }
164
165
        void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr,
166
                bool bBroadcast, bool bAdjustTextFrameWidthAndHeight)
167
19.5k
        {
168
            // call parent (always first thing to do, may create the SfxItemSet)
169
19.5k
            TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr, bBroadcast, bAdjustTextFrameWidthAndHeight );
170
171
            // update bTextFrame and RenderGeometry
172
19.5k
            UpdateTextFrameStatus(true);
173
19.5k
        }
174
175
        void CustomShapeProperties::ForceDefaultAttributes()
176
109k
        {
177
            // update bTextFrame and RenderGeometry
178
109k
            UpdateTextFrameStatus(true);
179
180
            // SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
181
            // This means: Do *not* call parent here is by purpose...
182
109k
        }
183
184
        CustomShapeProperties::CustomShapeProperties(SdrObject& rObj)
185
109k
        :   TextProperties(rObj)
186
109k
        {
187
109k
        }
188
189
        CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties& rProps, SdrObject& rObj)
190
4.93k
        :   TextProperties(rProps, rObj)
191
4.93k
        {
192
4.93k
        }
193
194
        CustomShapeProperties::~CustomShapeProperties()
195
114k
        {
196
114k
        }
197
198
        std::unique_ptr<BaseProperties> CustomShapeProperties::Clone(SdrObject& rObj) const
199
4.93k
        {
200
4.93k
            return std::unique_ptr<BaseProperties>(new CustomShapeProperties(*this, rObj));
201
4.93k
        }
202
203
        void CustomShapeProperties::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
204
671k
        {
205
671k
            TextProperties::Notify( rBC, rHint );
206
207
671k
            bool bRemoveRenderGeometry = false;
208
209
671k
            if (rHint.GetId() == SfxHintId::StyleSheetModified ||
210
335k
                rHint.GetId() == SfxHintId::StyleSheetModifiedExtended ||
211
0
                rHint.GetId() == SfxHintId::StyleSheetChanged)
212
671k
            {
213
671k
                const SfxStyleSheetHint* pStyleHint = static_cast<const SfxStyleSheetHint*>(&rHint);
214
671k
                if ( pStyleHint->GetStyleSheet() == GetStyleSheet() )
215
0
                    bRemoveRenderGeometry = true;
216
671k
            }
217
0
            else if ( rHint.GetId() == SfxHintId::DataChanged )
218
0
            {
219
0
                bRemoveRenderGeometry = true;
220
0
            }
221
222
                // update bTextFrame and RenderGeometry
223
671k
            UpdateTextFrameStatus(bRemoveRenderGeometry);
224
671k
        }
225
} // end of namespace
226
227
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */