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