1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 #include <svx/sdr/properties/customshapeproperties.hxx> 27 #include <svl/itemset.hxx> 28 #include <svl/style.hxx> 29 #include <svx/svdoashp.hxx> 30 #include <editeng/eeitem.hxx> 31 #include <svx/sdtagitm.hxx> 32 #include <svl/whiter.hxx> 33 #include <svl/itemset.hxx> 34 #include <svl/smplhint.hxx> 35 36 ////////////////////////////////////////////////////////////////////////////// 37 38 namespace sdr 39 { 40 namespace properties 41 { 42 void CustomShapeProperties::UpdateTextFrameStatus() 43 { 44 SdrObjCustomShape& rObj = static_cast< SdrObjCustomShape& >(GetSdrObject()); 45 const bool bOld(rObj.bTextFrame); 46 47 rObj.bTextFrame = 0 != static_cast< const SdrTextAutoGrowHeightItem& >(GetObjectItemSet().Get(SDRATTR_TEXT_AUTOGROWHEIGHT)).GetValue(); 48 49 if(rObj.bTextFrame != bOld) 50 { 51 rObj.InvalidateRenderGeometry(); 52 53 // #115391# Potential recursuin, since it calls SetObjectItemSet again, but rObj.bTextFrame 54 // will not change again, thus it will be only one level and terminate 55 rObj.AdaptTextMinSize(); 56 } 57 } 58 59 SfxItemSet& CustomShapeProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool) 60 { 61 return *(new SfxItemSet(rPool, 62 63 // ranges from SdrAttrObj 64 SDRATTR_START, SDRATTR_SHADOW_LAST, 65 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST, 66 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION, 67 68 // Graphic Attributes 69 SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST, 70 71 // 3d Properties 72 SDRATTR_3D_FIRST, SDRATTR_3D_LAST, 73 74 // CustomShape properties 75 SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST, 76 77 // range from SdrTextObj 78 EE_ITEMS_START, EE_ITEMS_END, 79 80 // end 81 0, 0)); 82 } 83 84 sal_Bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const 85 { 86 sal_Bool bAllowItemChange = sal_True; 87 if ( !pNewItem ) 88 { 89 if ( ( nWhich >= SDRATTR_CUSTOMSHAPE_FIRST ) && ( nWhich <= SDRATTR_CUSTOMSHAPE_LAST ) ) 90 bAllowItemChange = sal_False; 91 } 92 if ( bAllowItemChange ) 93 bAllowItemChange = TextProperties::AllowItemChange( nWhich, pNewItem ); 94 return bAllowItemChange; 95 } 96 97 void CustomShapeProperties::ClearObjectItem(const sal_uInt16 nWhich) 98 { 99 if ( !nWhich ) 100 { 101 SfxWhichIter aIter( *mpItemSet ); 102 sal_uInt16 nWhich2 = aIter.FirstWhich(); 103 while( nWhich2 ) 104 { 105 TextProperties::ClearObjectItemDirect( nWhich2 ); 106 nWhich2 = aIter.NextWhich(); 107 } 108 SfxItemSet aSet((SfxItemPool&)(*GetSdrObject().GetObjectItemPool())); 109 ItemSetChanged(aSet); 110 } 111 else 112 TextProperties::ClearObjectItem( nWhich ); 113 } 114 115 void CustomShapeProperties::ClearObjectItemDirect(const sal_uInt16 nWhich) 116 { 117 if ( !nWhich ) 118 { 119 SfxWhichIter aIter( *mpItemSet ); 120 sal_uInt16 nWhich2 = aIter.FirstWhich(); 121 while( nWhich2 ) 122 { 123 TextProperties::ClearObjectItemDirect( nWhich2 ); 124 nWhich2 = aIter.NextWhich(); 125 } 126 } 127 else 128 TextProperties::ClearObjectItemDirect( nWhich ); 129 } 130 131 void CustomShapeProperties::ItemSetChanged(const SfxItemSet& rSet) 132 { 133 // call parent 134 TextProperties::ItemSetChanged(rSet); 135 136 // update bTextFrame and RenderGeometry 137 UpdateTextFrameStatus(); 138 } 139 140 void CustomShapeProperties::PostItemChange(const sal_uInt16 nWhich) 141 { 142 switch(nWhich) 143 { 144 case SDRATTR_TEXT_AUTOGROWHEIGHT: 145 { 146 // #115391# update bTextFrame and RenderGeometry using AdaptTextMinSize() 147 UpdateTextFrameStatus(); 148 break; 149 } 150 default: 151 { 152 break; 153 } 154 } 155 156 // call parent 157 TextProperties::PostItemChange(nWhich); 158 } 159 160 void CustomShapeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem) 161 { 162 // call parent 163 TextProperties::ItemChange( nWhich, pNewItem ); 164 165 // update bTextFrame and RenderGeometry 166 UpdateTextFrameStatus(); 167 } 168 169 void CustomShapeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr) 170 { 171 // call parent 172 TextProperties::SetStyleSheet( pNewStyleSheet, bDontRemoveHardAttr ); 173 174 // update bTextFrame and RenderGeometry 175 UpdateTextFrameStatus(); 176 } 177 178 void CustomShapeProperties::ForceDefaultAttributes() 179 { 180 // update bTextFrame and RenderGeometry 181 UpdateTextFrameStatus(); 182 183 // SJ: Following is no good if creating customshapes, leading to objects that are white after loading via xml 184 // This means: Do *not* call parent here is by purpose... 185 } 186 187 CustomShapeProperties::CustomShapeProperties(SdrObject& rObj) 188 : TextProperties(rObj) 189 { 190 } 191 192 CustomShapeProperties::CustomShapeProperties(const CustomShapeProperties& rProps, SdrObject& rObj) 193 : TextProperties(rProps, rObj) 194 { 195 } 196 197 CustomShapeProperties::~CustomShapeProperties() 198 { 199 } 200 201 BaseProperties& CustomShapeProperties::Clone(SdrObject& rObj) const 202 { 203 return *(new CustomShapeProperties(*this, rObj)); 204 } 205 206 void CustomShapeProperties::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) 207 { 208 TextProperties::Notify( rBC, rHint ); 209 210 sal_Bool bRemoveRenderGeometry = sal_False; 211 const SfxStyleSheetHint *pStyleHint = PTR_CAST( SfxStyleSheetHint, &rHint ); 212 const SfxSimpleHint *pSimpleHint = PTR_CAST( SfxSimpleHint, &rHint ); 213 214 if ( pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet() ) 215 { 216 switch( pStyleHint->GetHint() ) 217 { 218 case SFX_STYLESHEET_MODIFIED : 219 case SFX_STYLESHEET_CHANGED : 220 bRemoveRenderGeometry = sal_True; 221 break; 222 }; 223 } 224 else if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DATACHANGED ) 225 { 226 bRemoveRenderGeometry = sal_True; 227 } 228 229 if ( bRemoveRenderGeometry ) 230 { 231 // update bTextFrame and RenderGeometry 232 UpdateTextFrameStatus(); 233 } 234 } 235 } // end of namespace properties 236 } // end of namespace sdr 237 238 ////////////////////////////////////////////////////////////////////////////// 239 // eof 240