Line data Source code
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 <sdr/properties/customshapeproperties.hxx>
21 : #include <svl/itemset.hxx>
22 : #include <svl/style.hxx>
23 : #include <svx/svdoashp.hxx>
24 : #include <editeng/eeitem.hxx>
25 : #include <svx/sdtagitm.hxx>
26 : #include <svl/whiter.hxx>
27 : #include <svl/smplhint.hxx>
28 :
29 :
30 :
31 : namespace sdr
32 : {
33 : namespace properties
34 : {
35 170241 : void CustomShapeProperties::UpdateTextFrameStatus(bool bInvalidateRenderGeometry)
36 : {
37 170241 : SdrObjCustomShape& rObj = static_cast< SdrObjCustomShape& >(GetSdrObject());
38 170241 : const bool bOld(rObj.bTextFrame);
39 :
40 : // change TextFrame flag when bResizeShapeToFitText changes (which is mapped
41 : // on the item SDRATTR_TEXT_AUTOGROWHEIGHT for custom shapes, argh)
42 170241 : rObj.bTextFrame = static_cast< const SdrOnOffItem& >(GetObjectItemSet().Get(SDRATTR_TEXT_AUTOGROWHEIGHT)).GetValue();
43 :
44 : // check if it did change
45 170241 : if(rObj.bTextFrame != bOld)
46 : {
47 : // on change also invalidate render geometry
48 3121 : bInvalidateRenderGeometry = true;
49 :
50 : // #115391# Potential recursion, since it calls SetObjectItemSet again, but rObj.bTextFrame
51 : // will not change again. Thus it will be only one level and terminate safely
52 3121 : rObj.AdaptTextMinSize();
53 : }
54 :
55 170241 : if(bInvalidateRenderGeometry)
56 : {
57 : // if asked for or bResizeShapeToFitText changed, make sure that
58 : // the render geometry is reconstructed using changed parameters
59 164040 : rObj.InvalidateRenderGeometry();
60 : }
61 170241 : }
62 :
63 3225 : SfxItemSet* CustomShapeProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
64 : {
65 : return new SfxItemSet(rPool,
66 :
67 : // ranges from SdrAttrObj
68 : SDRATTR_START, SDRATTR_SHADOW_LAST,
69 : SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
70 : SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
71 :
72 : // Graphic Attributes
73 : SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
74 :
75 : // 3d Properties
76 : SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
77 :
78 : // CustomShape properties
79 : SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
80 :
81 : // range from SdrTextObj
82 : EE_ITEMS_START, EE_ITEMS_END,
83 :
84 : // end
85 3225 : 0, 0);
86 : }
87 :
88 124492 : bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
89 : {
90 124492 : bool bAllowItemChange = true;
91 124492 : if ( !pNewItem )
92 : {
93 23805 : if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
94 460 : bAllowItemChange = false;
95 : }
96 124492 : if ( bAllowItemChange )
97 124032 : bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
98 124492 : return bAllowItemChange;
99 : }
100 :
101 115 : void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
102 : {
103 115 : if ( !nWhich )
104 : {
105 115 : SfxWhichIter aIter( *mpItemSet );
106 115 : sal_uInt16 nWhich2 = aIter.FirstWhich();
107 24035 : while( nWhich2 )
108 : {
109 23805 : TextProperties::ClearObjectItemDirect( nWhich2 );
110 23805 : nWhich2 = aIter.NextWhich();
111 : }
112 230 : SfxItemSet aSet(GetSdrObject().GetObjectItemPool());
113 230 : ItemSetChanged(aSet);
114 : }
115 : else
116 0 : TextProperties::ClearObjectItem( nWhich );
117 115 : }
118 :
119 0 : void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
120 : {
121 0 : if ( !nWhich )
122 : {
123 0 : SfxWhichIter aIter( *mpItemSet );
124 0 : sal_uInt16 nWhich2 = aIter.FirstWhich();
125 0 : while( nWhich2 )
126 : {
127 0 : TextProperties::ClearObjectItemDirect( nWhich2 );
128 0 : nWhich2 = aIter.NextWhich();
129 0 : }
130 : }
131 : else
132 0 : TextProperties::ClearObjectItemDirect( nWhich );
133 0 : }
134 :
135 33046 : void CustomShapeProperties::ItemSetChanged(const SfxItemSet& rSet)
136 : {
137 : // call parent
138 33046 : TextProperties::ItemSetChanged(rSet);
139 :
140 : // update bTextFrame and RenderGeometry
141 33046 : UpdateTextFrameStatus(true);
142 33046 : }
143 :
144 92467 : void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich)
145 : {
146 92467 : switch(nWhich)
147 : {
148 : case SDRATTR_TEXT_AUTOGROWHEIGHT:
149 : {
150 : // #115391# update bTextFrame and RenderGeometry using AdaptTextMinSize()
151 5948 : UpdateTextFrameStatus(false);
152 5948 : break;
153 : }
154 : default:
155 : {
156 86519 : break;
157 : }
158 : }
159 :
160 : // call parent
161 92467 : TextProperties::PostItemChange(nWhich);
162 92467 : }
163 :
164 124032 : void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
165 : {
166 : // call parent
167 124032 : TextProperties::ItemChange( nWhich, pNewItem );
168 :
169 : // update bTextFrame and RenderGeometry
170 124032 : UpdateTextFrameStatus(true);
171 124032 : }
172 :
173 3737 : void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
174 : {
175 : // call parent
176 3737 : TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
177 :
178 : // update bTextFrame and RenderGeometry
179 3737 : UpdateTextFrameStatus(true);
180 3737 : }
181 :
182 3225 : void CustomShapeProperties::ForceDefaultAttributes()
183 : {
184 : // update bTextFrame and RenderGeometry
185 3225 : UpdateTextFrameStatus(true);
186 :
187 : // SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
188 : // This means: Do *not* call parent here is by purpose...
189 3225 : }
190 :
191 3225 : CustomShapeProperties::CustomShapeProperties(SdrObject& rObj)
192 3225 : : TextProperties(rObj)
193 : {
194 3225 : }
195 :
196 223 : CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties& rProps, SdrObject& rObj)
197 223 : : TextProperties(rProps, rObj)
198 : {
199 223 : }
200 :
201 6890 : CustomShapeProperties::~CustomShapeProperties()
202 : {
203 6890 : }
204 :
205 223 : BaseProperties& CustomShapeProperties::Clone(SdrObject& rObj) const
206 : {
207 223 : return *(new CustomShapeProperties(*this, rObj));
208 : }
209 :
210 253 : void CustomShapeProperties::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
211 : {
212 253 : TextProperties::Notify( rBC, rHint );
213 :
214 253 : bool bRemoveRenderGeometry = false;
215 253 : const SfxStyleSheetHint* pStyleHint = dynamic_cast<const SfxStyleSheetHint*>(&rHint);
216 253 : const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
217 :
218 253 : if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
219 : {
220 0 : switch( pStyleHint->GetHint() )
221 : {
222 : case SfxStyleSheetHintId::MODIFIED :
223 : case SfxStyleSheetHintId::CHANGED :
224 0 : bRemoveRenderGeometry = true;
225 0 : break;
226 : };
227 : }
228 253 : else if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DATACHANGED )
229 : {
230 0 : bRemoveRenderGeometry = true;
231 : }
232 :
233 : // update bTextFrame and RenderGeometry
234 253 : UpdateTextFrameStatus(bRemoveRenderGeometry);
235 253 : }
236 : } // end of namespace properties
237 435 : } // end of namespace sdr
238 :
239 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|