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/groupproperties.hxx> 27 #include <svl/itemset.hxx> 28 #include <svl/whiter.hxx> 29 #include <svx/svddef.hxx> 30 #include <editeng/eeitem.hxx> 31 #include <svx/svdogrp.hxx> 32 #include <svx/svdpool.hxx> 33 #include <svx/svdpage.hxx> 34 35 ////////////////////////////////////////////////////////////////////////////// 36 37 namespace sdr 38 { 39 namespace properties 40 { 41 // create a new itemset CreateObjectSpecificItemSet(SfxItemPool & rPool)42 SfxItemSet& GroupProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool) 43 { 44 // Groups have in principle no ItemSet. To support methods like 45 // GetMergedItemSet() the local one is used. Thus, all items in the pool 46 // may be used and a pool itemset is created. 47 return *(new SfxItemSet(rPool)); 48 } 49 GroupProperties(SdrObject & rObj)50 GroupProperties::GroupProperties(SdrObject& rObj) 51 : DefaultProperties(rObj) 52 { 53 } 54 GroupProperties(const GroupProperties & rProps,SdrObject & rObj)55 GroupProperties::GroupProperties(const GroupProperties& rProps, SdrObject& rObj) 56 : DefaultProperties(rProps, rObj) 57 { 58 } 59 ~GroupProperties()60 GroupProperties::~GroupProperties() 61 { 62 } 63 Clone(SdrObject & rObj) const64 BaseProperties& GroupProperties::Clone(SdrObject& rObj) const 65 { 66 return *(new GroupProperties(*this, rObj)); 67 } 68 GetObjectItemSet() const69 const SfxItemSet& GroupProperties::GetObjectItemSet() const 70 { 71 DBG_ASSERT(sal_False, "GroupProperties::GetObjectItemSet() should never be called (!)"); 72 return DefaultProperties::GetObjectItemSet(); 73 } 74 GetMergedItemSet() const75 const SfxItemSet& GroupProperties::GetMergedItemSet() const 76 { 77 // prepare ItemSet 78 if(mpItemSet) 79 { 80 // clear local itemset for merge 81 mpItemSet->ClearItem(); 82 } 83 else 84 { 85 // force local itemset 86 DefaultProperties::GetObjectItemSet(); 87 } 88 89 // collect all ItemSets in mpItemSet 90 const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList(); 91 const sal_uInt32 nCount(pSub->GetObjCount()); 92 93 for(sal_uInt32 a(0L); a < nCount; a++) 94 { 95 const SfxItemSet& rSet = pSub->GetObj(a)->GetMergedItemSet(); 96 SfxWhichIter aIter(rSet); 97 sal_uInt16 nWhich(aIter.FirstWhich()); 98 99 while(nWhich) 100 { 101 if(SFX_ITEM_DONTCARE == rSet.GetItemState(nWhich, sal_False)) 102 { 103 mpItemSet->InvalidateItem(nWhich); 104 } 105 else 106 { 107 mpItemSet->MergeValue(rSet.Get(nWhich), sal_True); 108 } 109 110 nWhich = aIter.NextWhich(); 111 } 112 } 113 114 // For group proerties, do not call parent since groups do 115 // not have local ItemSets. 116 return *mpItemSet; 117 } 118 SetMergedItemSet(const SfxItemSet & rSet,sal_Bool bClearAllItems)119 void GroupProperties::SetMergedItemSet(const SfxItemSet& rSet, sal_Bool bClearAllItems) 120 { 121 // iterate over contained SdrObjects 122 const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList(); 123 const sal_uInt32 nCount(pSub->GetObjCount()); 124 125 for(sal_uInt32 a(0L); a < nCount; a++) 126 { 127 SdrObject* pObj = pSub->GetObj(a); 128 129 if(pObj) 130 { 131 // Set merged ItemSet at contained object 132 pObj->SetMergedItemSet(rSet, bClearAllItems); 133 } 134 } 135 136 // Do not call parent here. Group objects do not have local ItemSets 137 // where items need to be set. 138 // DefaultProperties::SetMergedItemSet(rSet, bClearAllItems); 139 } 140 SetObjectItem(const SfxPoolItem &)141 void GroupProperties::SetObjectItem(const SfxPoolItem& /*rItem*/) 142 { 143 DBG_ASSERT(sal_False, "GroupProperties::SetObjectItem() should never be called (!)"); 144 } 145 SetObjectItemDirect(const SfxPoolItem &)146 void GroupProperties::SetObjectItemDirect(const SfxPoolItem& /*rItem*/) 147 { 148 DBG_ASSERT(sal_False, "GroupProperties::SetObjectItemDirect() should never be called (!)"); 149 } 150 ClearObjectItem(const sal_uInt16)151 void GroupProperties::ClearObjectItem(const sal_uInt16 /*nWhich*/) 152 { 153 DBG_ASSERT(sal_False, "GroupProperties::ClearObjectItem() should never be called (!)"); 154 } 155 ClearObjectItemDirect(const sal_uInt16)156 void GroupProperties::ClearObjectItemDirect(const sal_uInt16 /*nWhich*/) 157 { 158 DBG_ASSERT(sal_False, "GroupProperties::ClearObjectItemDirect() should never be called (!)"); 159 } 160 SetMergedItem(const SfxPoolItem & rItem)161 void GroupProperties::SetMergedItem(const SfxPoolItem& rItem) 162 { 163 const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList(); 164 const sal_uInt32 nCount(pSub->GetObjCount()); 165 166 for(sal_uInt32 a(0L); a < nCount; a++) 167 { 168 pSub->GetObj(a)->GetProperties().SetMergedItem(rItem); 169 } 170 } 171 ClearMergedItem(const sal_uInt16 nWhich)172 void GroupProperties::ClearMergedItem(const sal_uInt16 nWhich) 173 { 174 const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList(); 175 const sal_uInt32 nCount(pSub->GetObjCount()); 176 177 for(sal_uInt32 a(0L); a < nCount; a++) 178 { 179 pSub->GetObj(a)->GetProperties().ClearMergedItem(nWhich); 180 } 181 } 182 SetObjectItemSet(const SfxItemSet &)183 void GroupProperties::SetObjectItemSet(const SfxItemSet& /*rSet*/) 184 { 185 DBG_ASSERT(sal_False, "GroupProperties::SetObjectItemSet() should never be called (!)"); 186 } 187 ItemSetChanged(const SfxItemSet &)188 void GroupProperties::ItemSetChanged(const SfxItemSet& /*rSet*/) 189 { 190 DBG_ASSERT(sal_False, "GroupProperties::ItemSetChanged() should never be called (!)"); 191 } 192 AllowItemChange(const sal_uInt16,const SfxPoolItem *) const193 sal_Bool GroupProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const 194 { 195 DBG_ASSERT(sal_False, "GroupProperties::AllowItemChange() should never be called (!)"); 196 return sal_False; 197 } 198 ItemChange(const sal_uInt16,const SfxPoolItem *)199 void GroupProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) 200 { 201 DBG_ASSERT(sal_False, "GroupProperties::ItemChange() should never be called (!)"); 202 } 203 PostItemChange(const sal_uInt16)204 void GroupProperties::PostItemChange(const sal_uInt16 /*nWhich*/) 205 { 206 DBG_ASSERT(sal_False, "GroupProperties::PostItemChange() should never be called (!)"); 207 } 208 GetStyleSheet() const209 SfxStyleSheet* GroupProperties::GetStyleSheet() const 210 { 211 SfxStyleSheet* pRetval = 0L; 212 213 const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList(); 214 const sal_uInt32 nCount(pSub->GetObjCount()); 215 216 for(sal_uInt32 a(0L); a < nCount; a++) 217 { 218 SfxStyleSheet* pCandidate = pSub->GetObj(a)->GetStyleSheet(); 219 220 if(pRetval) 221 { 222 if(pCandidate != pRetval) 223 { 224 // different StyleSheelts, return none 225 return 0L; 226 } 227 } 228 else 229 { 230 pRetval = pCandidate; 231 } 232 } 233 234 return pRetval; 235 } 236 SetStyleSheet(SfxStyleSheet * pNewStyleSheet,sal_Bool bDontRemoveHardAttr)237 void GroupProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr) 238 { 239 const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList(); 240 const sal_uInt32 nCount(pSub->GetObjCount()); 241 242 for(sal_uInt32 a(0L); a < nCount; a++) 243 { 244 pSub->GetObj(a)->SetStyleSheet(pNewStyleSheet, bDontRemoveHardAttr); 245 } 246 } 247 ForceDefaultAttributes()248 void GroupProperties::ForceDefaultAttributes() 249 { 250 // nothing to do here, groups have no items and thus no default items, too. 251 } 252 MoveToItemPool(SfxItemPool * pSrcPool,SfxItemPool * pDestPool,SdrModel * pNewModel)253 void GroupProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel) 254 { 255 if(pSrcPool && pDestPool && (pSrcPool != pDestPool)) 256 { 257 const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList(); 258 const sal_uInt32 nCount(pSub->GetObjCount()); 259 260 for(sal_uInt32 a(0L); a < nCount; a++) 261 { 262 pSub->GetObj(a)->GetProperties().MoveToItemPool(pSrcPool, pDestPool, pNewModel); 263 } 264 265 // also clear local ItemSet, it's only temporary for group objects anyways. 266 if(mpItemSet) 267 { 268 // #121905# 269 // copy/paste is still using clone operators and MoveToItemPool functionality. 270 // Since SfxItemSet contains a pool pointer, ClearItem is not enough here. 271 // The ItemSet for merge is constructed on demand, so it's enough here to 272 // just delete it and set to 0L. 273 // mpItemSet->ClearItem(); 274 delete mpItemSet; 275 mpItemSet = 0L; 276 } 277 } 278 } 279 ForceStyleToHardAttributes()280 void GroupProperties::ForceStyleToHardAttributes() 281 { 282 const SdrObjList* pSub = ((const SdrObjGroup&)GetSdrObject()).GetSubList(); 283 const sal_uInt32 nCount(pSub->GetObjCount()); 284 285 for(sal_uInt32 a(0L); a < nCount; a++) 286 { 287 pSub->GetObj(a)->GetProperties().ForceStyleToHardAttributes(); 288 } 289 } 290 } // end of namespace properties 291 } // end of namespace sdr 292 293 ////////////////////////////////////////////////////////////////////////////// 294 // eof 295