Branch data 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 : 1485 : void CustomShapeProperties::UpdateTextFrameStatus()
36 : : {
37 : 1485 : SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
38 : : SdrTextAutoGrowHeightItem& rAutoGrowHeightItem =
39 : 1485 : (SdrTextAutoGrowHeightItem&)rObj.GetMergedItem( SDRATTR_TEXT_AUTOGROWHEIGHT );
40 : 1485 : rObj.bTextFrame = rAutoGrowHeightItem.GetValue() != 0;
41 : :
42 [ + - ]: 1485 : if ( rObj.bTextFrame )
43 : 1485 : rObj.NbcAdjustTextFrameWidthAndHeight();
44 : 1485 : }
45 : :
46 : 642 : SfxItemSet& CustomShapeProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
47 : : {
48 : : return *(new SfxItemSet(rPool,
49 : :
50 : : // ranges from SdrAttrObj
51 : : SDRATTR_START, SDRATTR_SHADOW_LAST,
52 : : SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
53 : : SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
54 : :
55 : : // Graphic Attributes
56 : : SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
57 : :
58 : : // 3d Properties
59 : : SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
60 : :
61 : : // CustomShape properties
62 : : SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
63 : :
64 : : // range from SdrTextObj
65 : : EE_ITEMS_START, EE_ITEMS_END,
66 : :
67 : : // end
68 [ + - ]: 642 : 0, 0));
69 : : }
70 : 47688 : sal_Bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
71 : : {
72 : 47688 : sal_Bool bAllowItemChange = sal_True;
73 [ + + ]: 47688 : if ( !pNewItem )
74 : : {
75 [ + + ][ + + ]: 37944 : if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) )
76 : 744 : bAllowItemChange = sal_False;
77 : : }
78 [ + + ]: 47688 : if ( bAllowItemChange )
79 : 46944 : bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem );
80 : 47688 : return bAllowItemChange;
81 : : }
82 : 186 : void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich)
83 : : {
84 [ + - ]: 186 : if ( !nWhich )
85 : : {
86 [ + - ]: 186 : SfxWhichIter aIter( *mpItemSet );
87 [ + - ]: 186 : sal_uInt16 nWhich2 = aIter.FirstWhich();
88 [ + + ]: 38130 : while( nWhich2 )
89 : : {
90 [ + - ]: 37944 : TextProperties::ClearObjectItemDirect( nWhich2 );
91 [ + - ]: 37944 : nWhich2 = aIter.NextWhich();
92 : : }
93 [ + - ][ + - ]: 186 : SfxItemSet aSet((SfxItemPool&)(*GetSdrObject().GetObjectItemPool()));
94 [ + - ][ + - ]: 186 : ItemSetChanged(aSet);
[ + - ]
95 : : }
96 : : else
97 : 0 : TextProperties::ClearObjectItem( nWhich );
98 : 186 : }
99 : 0 : void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
100 : : {
101 [ # # ]: 0 : if ( !nWhich )
102 : : {
103 [ # # ]: 0 : SfxWhichIter aIter( *mpItemSet );
104 [ # # ]: 0 : sal_uInt16 nWhich2 = aIter.FirstWhich();
105 [ # # ]: 0 : while( nWhich2 )
106 : : {
107 [ # # ]: 0 : TextProperties::ClearObjectItemDirect( nWhich2 );
108 [ # # ]: 0 : nWhich2 = aIter.NextWhich();
109 [ # # ]: 0 : }
110 : : }
111 : : else
112 : 0 : TextProperties::ClearObjectItemDirect( nWhich );
113 : 0 : }
114 : 2427 : void CustomShapeProperties::ItemSetChanged(const SfxItemSet& rSet)
115 : : {
116 : 2427 : SdrObjCustomShape& rObj = (SdrObjCustomShape&)GetSdrObject();
117 : :
118 [ + + ]: 2427 : if( SFX_ITEM_SET == rSet.GetItemState( SDRATTR_TEXT_AUTOGROWHEIGHT ) )
119 : : {
120 : 816 : rObj.bTextFrame = ((SdrTextAutoGrowHeightItem&)rSet.Get( SDRATTR_TEXT_AUTOGROWHEIGHT )).GetValue() != 0;
121 : : }
122 : :
123 : : // call parent
124 : 2427 : TextProperties::ItemSetChanged(rSet);
125 : :
126 : : // local changes, removing cached objects
127 : 2427 : rObj.InvalidateRenderGeometry();
128 : 2427 : }
129 : 46944 : void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
130 : : {
131 : 46944 : SdrObjCustomShape& rObj = (SdrObjCustomShape&)GetSdrObject();
132 : : //OutlinerParaObject* pParaObj = rObj.GetOutlinerParaObject();
133 : :
134 [ + + ][ + + ]: 46944 : if( pNewItem && ( SDRATTR_TEXT_AUTOGROWHEIGHT == nWhich ) )
135 : : {
136 : 816 : rObj.bTextFrame = ((SdrTextAutoGrowHeightItem*)pNewItem)->GetValue() != 0;
137 : : }
138 : : // call parent
139 : 46944 : TextProperties::ItemChange( nWhich, pNewItem );
140 : :
141 : 46944 : rObj.InvalidateRenderGeometry();
142 : 46944 : }
143 : 843 : void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
144 : : {
145 : 843 : TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr );
146 : 843 : UpdateTextFrameStatus();
147 : 843 : }
148 : 642 : void CustomShapeProperties::ForceDefaultAttributes()
149 : : {
150 : 642 : UpdateTextFrameStatus();
151 : :
152 : : /* SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml
153 : :
154 : : SdrTextObj& rObj = (SdrTextObj&)GetSdrObject();
155 : : sal_Bool bTextFrame(rObj.IsTextFrame());
156 : :
157 : : // force ItemSet
158 : : GetObjectItemSet();
159 : :
160 : : if(bTextFrame)
161 : : {
162 : : mpItemSet->Put(XLineStyleItem(XLINE_NONE));
163 : : mpItemSet->Put(XFillColorItem(String(), Color(COL_WHITE)));
164 : : mpItemSet->Put(XFillStyleItem(XFILL_NONE));
165 : : }
166 : : else
167 : : {
168 : : mpItemSet->Put(SvxAdjustItem(SVX_ADJUST_CENTER));
169 : : mpItemSet->Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_CENTER));
170 : : mpItemSet->Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
171 : : }
172 : : */
173 : 642 : }
174 : 642 : CustomShapeProperties::CustomShapeProperties(SdrObject& rObj)
175 : 642 : : TextProperties(rObj)
176 : : {
177 : 642 : }
178 : :
179 : 0 : CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties& rProps, SdrObject& rObj)
180 : 0 : : TextProperties(rProps, rObj)
181 : : {
182 : 0 : }
183 : :
184 : 630 : CustomShapeProperties::~CustomShapeProperties()
185 : : {
186 [ - + ]: 1260 : }
187 : :
188 : 0 : BaseProperties& CustomShapeProperties::Clone(SdrObject& rObj) const
189 : : {
190 [ # # ]: 0 : return *(new CustomShapeProperties(*this, rObj));
191 : : }
192 : 0 : void CustomShapeProperties::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
193 : : {
194 : 0 : TextProperties::Notify( rBC, rHint );
195 : :
196 : 0 : sal_Bool bRemoveRenderGeometry = sal_False;
197 : :
198 [ # # ][ # # ]: 0 : const SfxStyleSheetHint *pStyleHint = PTR_CAST( SfxStyleSheetHint, &rHint );
199 [ # # ][ # # ]: 0 : const SfxSimpleHint *pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint );
200 [ # # ][ # # ]: 0 : if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() )
[ # # ]
201 : : {
202 [ # # ]: 0 : switch( pStyleHint->GetHint() )
203 : : {
204 : : case SFX_STYLESHEET_MODIFIED :
205 : : case SFX_STYLESHEET_CHANGED :
206 : 0 : bRemoveRenderGeometry = sal_True;
207 : 0 : break;
208 : : };
209 : : }
210 [ # # ][ # # ]: 0 : else if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DATACHANGED )
[ # # ]
211 : : {
212 : 0 : bRemoveRenderGeometry = sal_True;
213 : : }
214 [ # # ]: 0 : if ( bRemoveRenderGeometry )
215 : : {
216 : 0 : UpdateTextFrameStatus();
217 : :
218 : : // local changes, removing cached objects
219 : 0 : SdrObjCustomShape& rObj = (SdrObjCustomShape&)GetSdrObject();
220 : 0 : rObj.InvalidateRenderGeometry();
221 : : }
222 : :
223 : 0 : }
224 : : } // end of namespace properties
225 : : } // end of namespace sdr
226 : :
227 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|