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 <svx/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 0 : void CustomShapeProperties::UpdateTextFrameStatus(bool bInvalidateRenderGeometry)
36 : {
37 0 : SdrObjCustomShape& rObj = static_cast< SdrObjCustomShape& >(GetSdrObject());
38 0 : 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 0 : rObj.bTextFrame = static_cast< const SdrTextAutoGrowHeightItem& >(GetObjectItemSet().Get(SDRATTR_TEXT_AUTOGROWHEIGHT)).GetValue();
43 :
44 : // check if it did change
45 0 : if(rObj.bTextFrame != bOld)
46 : {
47 : // on change also invalidate render geometry
48 0 : 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 0 : rObj.AdaptTextMinSize();
53 : }
54 :
55 0 : if(bInvalidateRenderGeometry)
56 : {
57 : // if asked for or bResizeShapeToFitText changed, make sure that
58 : // the render geometry is reconstructed using changed parameters
59 0 : rObj.InvalidateRenderGeometry();
60 : }
61 0 : }
62 :
63 0 : 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 0 : 0, 0));
86 : }
87 :
88 0 : bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
89 : {
90 0 : sal_Bool bAllowItemChange = sal_True;
91 0 : if ( !pNewItem )
92 : {
93 0 : if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
94 0 : bAllowItemChange = sal_False;
95 : }
96 0 : if ( bAllowItemChange )
97 0 : bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
98 0 : return bAllowItemChange;
99 : }
100 :
101 0 : void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
102 : {
103 0 : if ( !nWhich )
104 : {
105 0 : SfxWhichIter aIter( *mpItemSet );
106 0 : sal_uInt16 nWhich2 = aIter.FirstWhich();
107 0 : while( nWhich2 )
108 : {
109 0 : TextProperties::ClearObjectItemDirect( nWhich2 );
110 0 : nWhich2 = aIter.NextWhich();
111 : }
112 0 : SfxItemSet aSet((SfxItemPool&)(*GetSdrObject().GetObjectItemPool()));
113 0 : ItemSetChanged(aSet);
114 : }
115 : else
116 0 : TextProperties::ClearObjectItem( nWhich );
117 0 : }
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 0 : void CustomShapeProperties::ItemSetChanged(const SfxItemSet& rSet)
136 : {
137 : // call parent
138 0 : TextProperties::ItemSetChanged(rSet);
139 :
140 : // update bTextFrame and RenderGeometry
141 0 : UpdateTextFrameStatus(true);
142 0 : }
143 :
144 0 : void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich)
145 : {
146 0 : switch(nWhich)
147 : {
148 : case SDRATTR_TEXT_AUTOGROWHEIGHT:
149 : {
150 : // #115391# update bTextFrame and RenderGeometry using AdaptTextMinSize()
151 0 : UpdateTextFrameStatus(false);
152 0 : break;
153 : }
154 : default:
155 : {
156 0 : break;
157 : }
158 : }
159 :
160 : // call parent
161 0 : TextProperties::PostItemChange(nWhich);
162 0 : }
163 :
164 0 : void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
165 : {
166 : // call parent
167 0 : TextProperties::ItemChange( nWhich, pNewItem );
168 :
169 : // update bTextFrame and RenderGeometry
170 0 : UpdateTextFrameStatus(true);
171 0 : }
172 :
173 0 : void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
174 : {
175 : // call parent
176 0 : TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
177 :
178 : // update bTextFrame and RenderGeometry
179 0 : UpdateTextFrameStatus(true);
180 0 : }
181 :
182 0 : void CustomShapeProperties::ForceDefaultAttributes()
183 : {
184 : // update bTextFrame and RenderGeometry
185 0 : 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 0 : }
190 :
191 0 : CustomShapeProperties::CustomShapeProperties(SdrObject& rObj)
192 0 : : TextProperties(rObj)
193 : {
194 0 : }
195 :
196 0 : CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties& rProps, SdrObject& rObj)
197 0 : : TextProperties(rProps, rObj)
198 : {
199 0 : }
200 :
201 0 : CustomShapeProperties::~CustomShapeProperties()
202 : {
203 0 : }
204 :
205 0 : BaseProperties& CustomShapeProperties::Clone(SdrObject& rObj) const
206 : {
207 0 : return *(new CustomShapeProperties(*this, rObj));
208 : }
209 :
210 0 : void CustomShapeProperties::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
211 : {
212 0 : TextProperties::Notify( rBC, rHint );
213 :
214 0 : sal_Bool bRemoveRenderGeometry = sal_False;
215 0 : const SfxStyleSheetHint *pStyleHint = PTR_CAST( SfxStyleSheetHint, &rHint );
216 0 : const SfxSimpleHint *pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
217 :
218 0 : if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
219 : {
220 0 : switch( pStyleHint->GetHint() )
221 : {
222 : case SFX_STYLESHEET_MODIFIED :
223 : case SFX_STYLESHEET_CHANGED :
224 0 : bRemoveRenderGeometry = sal_True;
225 0 : break;
226 : };
227 : }
228 0 : else if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DATACHANGED )
229 : {
230 0 : bRemoveRenderGeometry = sal_True;
231 : }
232 :
233 : // update bTextFrame and RenderGeometry
234 0 : UpdateTextFrameStatus(bRemoveRenderGeometry);
235 0 : }
236 : } // end of namespace properties
237 : } // end of namespace sdr
238 :
239 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|