xref: /trunk/main/svx/source/sdr/properties/attributeproperties.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include <svx/sdr/properties/attributeproperties.hxx>
27cdf0e10cSrcweir #include <svx/sdr/properties/itemsettools.hxx>
28cdf0e10cSrcweir #include <tools/debug.hxx>
29cdf0e10cSrcweir #include <svl/itemset.hxx>
30cdf0e10cSrcweir #include <svl/style.hxx>
31cdf0e10cSrcweir #include <svl/whiter.hxx>
32cdf0e10cSrcweir #include <svl/poolitem.hxx>
33cdf0e10cSrcweir #include <svx/svdobj.hxx>
34cdf0e10cSrcweir #include <svx/svddef.hxx>
35cdf0e10cSrcweir #include <svx/xit.hxx>
36cdf0e10cSrcweir #include <svx/xbtmpit.hxx>
37cdf0e10cSrcweir #include <svx/xlndsit.hxx>
38cdf0e10cSrcweir #include <svx/xlnstit.hxx>
39cdf0e10cSrcweir #include <svx/xlnedit.hxx>
40cdf0e10cSrcweir #include <svx/xflgrit.hxx>
41cdf0e10cSrcweir #include <svx/xflftrit.hxx>
42cdf0e10cSrcweir #include <svx/xflhtit.hxx>
43cdf0e10cSrcweir #include <svx/xlnasit.hxx>
44cdf0e10cSrcweir #include <svx/xflasit.hxx>
45cdf0e10cSrcweir #include <svx/svdmodel.hxx>
46cdf0e10cSrcweir #include <svx/svdtrans.hxx>
47cdf0e10cSrcweir #include <svx/svdpage.hxx>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir // #114265#
50cdf0e10cSrcweir #include <svl/smplhint.hxx>
51cdf0e10cSrcweir 
52cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
53cdf0e10cSrcweir 
54cdf0e10cSrcweir namespace sdr
55cdf0e10cSrcweir {
56cdf0e10cSrcweir     namespace properties
57cdf0e10cSrcweir     {
ImpAddStyleSheet(SfxStyleSheet * pNewStyleSheet,sal_Bool bDontRemoveHardAttr)58cdf0e10cSrcweir         void AttributeProperties::ImpAddStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
59cdf0e10cSrcweir         {
60cdf0e10cSrcweir             // test if old StyleSheet is cleared, else it would be lost
61cdf0e10cSrcweir             // after this method -> memory leak (!)
62cdf0e10cSrcweir             DBG_ASSERT(!mpStyleSheet, "Old style sheet not deleted before setting new one (!)");
63cdf0e10cSrcweir 
64cdf0e10cSrcweir             if(pNewStyleSheet)
65cdf0e10cSrcweir             {
66cdf0e10cSrcweir                 mpStyleSheet = pNewStyleSheet;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir                 // local ItemSet is needed here, force it
69cdf0e10cSrcweir                 GetObjectItemSet();
70cdf0e10cSrcweir 
71cdf0e10cSrcweir                 // register as listener
72cdf0e10cSrcweir                 StartListening(pNewStyleSheet->GetPool());
73cdf0e10cSrcweir                 StartListening(*pNewStyleSheet);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir                 // Delete hard attributes where items are set in the style sheet
76cdf0e10cSrcweir                 if(!bDontRemoveHardAttr)
77cdf0e10cSrcweir                 {
78cdf0e10cSrcweir                     const SfxItemSet& rStyle = pNewStyleSheet->GetItemSet();
79cdf0e10cSrcweir                     SfxWhichIter aIter(rStyle);
80cdf0e10cSrcweir                     sal_uInt16 nWhich = aIter.FirstWhich();
81cdf0e10cSrcweir 
82cdf0e10cSrcweir                     while(nWhich)
83cdf0e10cSrcweir                     {
84cdf0e10cSrcweir                         if(SFX_ITEM_SET == rStyle.GetItemState(nWhich))
85cdf0e10cSrcweir                         {
86cdf0e10cSrcweir                             mpItemSet->ClearItem(nWhich);
87cdf0e10cSrcweir                         }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir                         nWhich = aIter.NextWhich();
90cdf0e10cSrcweir                     }
91cdf0e10cSrcweir                 }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir                 // set new stylesheet as parent
94cdf0e10cSrcweir                 mpItemSet->SetParent(&pNewStyleSheet->GetItemSet());
95cdf0e10cSrcweir             }
96cdf0e10cSrcweir         }
97cdf0e10cSrcweir 
ImpRemoveStyleSheet()98cdf0e10cSrcweir         void AttributeProperties::ImpRemoveStyleSheet()
99cdf0e10cSrcweir         {
100cdf0e10cSrcweir             // Check type since it is destroyed when the type is deleted
101cdf0e10cSrcweir             if(GetStyleSheet() && HAS_BASE(SfxStyleSheet, mpStyleSheet))
102cdf0e10cSrcweir             {
103cdf0e10cSrcweir                 EndListening(*mpStyleSheet);
104cdf0e10cSrcweir                 EndListening(mpStyleSheet->GetPool());
105cdf0e10cSrcweir 
106cdf0e10cSrcweir                 // reset parent of ItemSet
107cdf0e10cSrcweir                 if(mpItemSet)
108cdf0e10cSrcweir                 {
109cdf0e10cSrcweir                     mpItemSet->SetParent(0L);
110cdf0e10cSrcweir                 }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir                 SdrObject& rObj = GetSdrObject();
113cdf0e10cSrcweir                 rObj.SetBoundRectDirty();
114cdf0e10cSrcweir                 rObj.SetRectsDirty(sal_True);
115cdf0e10cSrcweir             }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir             mpStyleSheet = 0L;
118cdf0e10cSrcweir         }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         // create a new itemset
CreateObjectSpecificItemSet(SfxItemPool & rPool)121cdf0e10cSrcweir         SfxItemSet& AttributeProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
122cdf0e10cSrcweir         {
123cdf0e10cSrcweir             return *(new SfxItemSet(rPool,
124cdf0e10cSrcweir 
125cdf0e10cSrcweir                 // ranges from SdrAttrObj
126cdf0e10cSrcweir                 SDRATTR_START, SDRATTR_SHADOW_LAST,
127cdf0e10cSrcweir                 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
128cdf0e10cSrcweir                 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
129cdf0e10cSrcweir 
130cdf0e10cSrcweir                 // end
131cdf0e10cSrcweir                 0, 0));
132cdf0e10cSrcweir         }
133cdf0e10cSrcweir 
AttributeProperties(SdrObject & rObj)134cdf0e10cSrcweir         AttributeProperties::AttributeProperties(SdrObject& rObj)
135cdf0e10cSrcweir         :   DefaultProperties(rObj),
136cdf0e10cSrcweir             mpStyleSheet(0L)
137cdf0e10cSrcweir         {
138cdf0e10cSrcweir         }
139cdf0e10cSrcweir 
AttributeProperties(const AttributeProperties & rProps,SdrObject & rObj)140cdf0e10cSrcweir         AttributeProperties::AttributeProperties(const AttributeProperties& rProps, SdrObject& rObj)
141cdf0e10cSrcweir         :   DefaultProperties(rProps, rObj),
142cdf0e10cSrcweir             mpStyleSheet(0L)
143cdf0e10cSrcweir         {
144cdf0e10cSrcweir             if(rProps.GetStyleSheet())
145cdf0e10cSrcweir             {
146cdf0e10cSrcweir                 ImpAddStyleSheet(rProps.GetStyleSheet(), sal_True);
147cdf0e10cSrcweir             }
148cdf0e10cSrcweir         }
149cdf0e10cSrcweir 
~AttributeProperties()150cdf0e10cSrcweir         AttributeProperties::~AttributeProperties()
151cdf0e10cSrcweir         {
152cdf0e10cSrcweir             ImpRemoveStyleSheet();
153cdf0e10cSrcweir         }
154cdf0e10cSrcweir 
Clone(SdrObject & rObj) const155cdf0e10cSrcweir         BaseProperties& AttributeProperties::Clone(SdrObject& rObj) const
156cdf0e10cSrcweir         {
157cdf0e10cSrcweir             return *(new AttributeProperties(*this, rObj));
158cdf0e10cSrcweir         }
159cdf0e10cSrcweir 
ItemSetChanged(const SfxItemSet &)160cdf0e10cSrcweir         void AttributeProperties::ItemSetChanged(const SfxItemSet& /*rSet*/)
161cdf0e10cSrcweir         {
162cdf0e10cSrcweir             // own modifications
163cdf0e10cSrcweir             SdrObject& rObj = GetSdrObject();
164cdf0e10cSrcweir 
165cdf0e10cSrcweir             rObj.SetBoundRectDirty();
166cdf0e10cSrcweir             rObj.SetRectsDirty(sal_True);
167cdf0e10cSrcweir             rObj.SetChanged();
168cdf0e10cSrcweir         }
169cdf0e10cSrcweir 
ItemChange(const sal_uInt16 nWhich,const SfxPoolItem * pNewItem)170cdf0e10cSrcweir         void AttributeProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
171cdf0e10cSrcweir         {
172cdf0e10cSrcweir             if(pNewItem)
173cdf0e10cSrcweir             {
174cdf0e10cSrcweir                 const SfxPoolItem* pItem = pNewItem;
175cdf0e10cSrcweir                 SdrModel* pModel = GetSdrObject().GetModel();
176cdf0e10cSrcweir 
177cdf0e10cSrcweir                 switch( nWhich )
178cdf0e10cSrcweir                 {
179cdf0e10cSrcweir                     case XATTR_FILLBITMAP:
180cdf0e10cSrcweir                     {
181cdf0e10cSrcweir                         pItem = ((XFillBitmapItem*)pItem)->checkForUniqueItem( pModel );
182cdf0e10cSrcweir                         break;
183cdf0e10cSrcweir                     }
184cdf0e10cSrcweir                     case XATTR_LINEDASH:
185cdf0e10cSrcweir                     {
186cdf0e10cSrcweir                         pItem = ((XLineDashItem*)pItem)->checkForUniqueItem( pModel );
187cdf0e10cSrcweir                         break;
188cdf0e10cSrcweir                     }
189cdf0e10cSrcweir                     case XATTR_LINESTART:
190cdf0e10cSrcweir                     {
191cdf0e10cSrcweir                         pItem = ((XLineStartItem*)pItem)->checkForUniqueItem( pModel );
192cdf0e10cSrcweir                         break;
193cdf0e10cSrcweir                     }
194cdf0e10cSrcweir                     case XATTR_LINEEND:
195cdf0e10cSrcweir                     {
196cdf0e10cSrcweir                         pItem = ((XLineEndItem*)pItem)->checkForUniqueItem( pModel );
197cdf0e10cSrcweir                         break;
198cdf0e10cSrcweir                     }
199cdf0e10cSrcweir                     case XATTR_FILLGRADIENT:
200cdf0e10cSrcweir                     {
201cdf0e10cSrcweir                         pItem = ((XFillGradientItem*)pItem)->checkForUniqueItem( pModel );
202cdf0e10cSrcweir                         break;
203cdf0e10cSrcweir                     }
204cdf0e10cSrcweir                     case XATTR_FILLFLOATTRANSPARENCE:
205cdf0e10cSrcweir                     {
206cdf0e10cSrcweir                         // #85953# allow all kinds of XFillFloatTransparenceItem to be set
207cdf0e10cSrcweir                         pItem = ((XFillFloatTransparenceItem*)pItem)->checkForUniqueItem( pModel );
208cdf0e10cSrcweir                         break;
209cdf0e10cSrcweir                     }
210cdf0e10cSrcweir                     case XATTR_FILLHATCH:
211cdf0e10cSrcweir                     {
212cdf0e10cSrcweir                         pItem = ((XFillHatchItem*)pItem)->checkForUniqueItem( pModel );
213cdf0e10cSrcweir                         break;
214cdf0e10cSrcweir                     }
215cdf0e10cSrcweir                 }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir                 // set item
218cdf0e10cSrcweir                 if(pItem)
219cdf0e10cSrcweir                 {
220cdf0e10cSrcweir                     // force ItemSet
221cdf0e10cSrcweir                     GetObjectItemSet();
222cdf0e10cSrcweir                     mpItemSet->Put(*pItem);
223cdf0e10cSrcweir 
224cdf0e10cSrcweir                     // delete item if it was a generated one
225cdf0e10cSrcweir                     if(pItem != pNewItem)
226cdf0e10cSrcweir                     {
227cdf0e10cSrcweir                         delete (SfxPoolItem*)pItem;
228cdf0e10cSrcweir                     }
229cdf0e10cSrcweir                 }
230cdf0e10cSrcweir             }
231cdf0e10cSrcweir             else
232cdf0e10cSrcweir             {
233cdf0e10cSrcweir                 // clear item if ItemSet exists
234cdf0e10cSrcweir                 if(mpItemSet)
235cdf0e10cSrcweir                 {
236cdf0e10cSrcweir                     mpItemSet->ClearItem(nWhich);
237cdf0e10cSrcweir                 }
238cdf0e10cSrcweir             }
239cdf0e10cSrcweir         }
240cdf0e10cSrcweir 
SetStyleSheet(SfxStyleSheet * pNewStyleSheet,sal_Bool bDontRemoveHardAttr)241cdf0e10cSrcweir         void AttributeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr)
242cdf0e10cSrcweir         {
243cdf0e10cSrcweir             ImpRemoveStyleSheet();
244cdf0e10cSrcweir             ImpAddStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);
245cdf0e10cSrcweir 
246cdf0e10cSrcweir             SdrObject& rObj = GetSdrObject();
247cdf0e10cSrcweir             rObj.SetBoundRectDirty();
248cdf0e10cSrcweir             rObj.SetRectsDirty(sal_True);
249cdf0e10cSrcweir         }
250cdf0e10cSrcweir 
GetStyleSheet() const251cdf0e10cSrcweir         SfxStyleSheet* AttributeProperties::GetStyleSheet() const
252cdf0e10cSrcweir         {
253cdf0e10cSrcweir             return mpStyleSheet;
254cdf0e10cSrcweir         }
255cdf0e10cSrcweir 
MoveToItemPool(SfxItemPool * pSrcPool,SfxItemPool * pDestPool,SdrModel * pNewModel)256cdf0e10cSrcweir         void AttributeProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
257cdf0e10cSrcweir         {
258cdf0e10cSrcweir             OSL_ASSERT(pNewModel!=NULL);
259cdf0e10cSrcweir 
260cdf0e10cSrcweir             if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
261cdf0e10cSrcweir             {
262cdf0e10cSrcweir                 if(mpItemSet)
263cdf0e10cSrcweir                 {
264cdf0e10cSrcweir                     // migrate ItemSet to new pool. Scaling is NOT necessary
265cdf0e10cSrcweir                     // because this functionality is used by UNDO only. Thus
266cdf0e10cSrcweir                     // objects and ItemSets would be moved back to their original
267cdf0e10cSrcweir                     // pool before usage.
268cdf0e10cSrcweir                     SfxItemSet* pOldSet = mpItemSet;
269cdf0e10cSrcweir                     SfxStyleSheet* pStySheet = GetStyleSheet();
270cdf0e10cSrcweir 
271cdf0e10cSrcweir                     if(pStySheet)
272cdf0e10cSrcweir                     {
273cdf0e10cSrcweir                         ImpRemoveStyleSheet();
274cdf0e10cSrcweir                     }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir                     mpItemSet = mpItemSet->Clone(sal_False, pDestPool);
277cdf0e10cSrcweir                     GetSdrObject().GetModel()->MigrateItemSet(pOldSet, mpItemSet, pNewModel);
278cdf0e10cSrcweir 
279cdf0e10cSrcweir                     // set stylesheet (if used)
280cdf0e10cSrcweir                     if(pStySheet)
281cdf0e10cSrcweir                     {
282cdf0e10cSrcweir                         // #i109515#
283cdf0e10cSrcweir                         SfxItemPool* pStyleSheetPool = &pStySheet->GetPool().GetPool();
284cdf0e10cSrcweir 
285cdf0e10cSrcweir                         if(pStyleSheetPool == pDestPool)
286cdf0e10cSrcweir                         {
287cdf0e10cSrcweir                             // just re-set stylesheet
288cdf0e10cSrcweir                             ImpAddStyleSheet(pStySheet, sal_True);
289cdf0e10cSrcweir                         }
290cdf0e10cSrcweir                         else
291cdf0e10cSrcweir                         {
292cdf0e10cSrcweir                             // StyleSheet is NOT from the correct pool.
293cdf0e10cSrcweir                             // Look one up in the right pool with the same
294cdf0e10cSrcweir                             // name or use the default.
295cdf0e10cSrcweir 
296cdf0e10cSrcweir                             // Look up the style in the new document.
297cdf0e10cSrcweir                             OSL_ASSERT(pNewModel->GetStyleSheetPool() != NULL);
298cdf0e10cSrcweir                             SfxStyleSheet* pNewStyleSheet = dynamic_cast<SfxStyleSheet*>(
299cdf0e10cSrcweir                                 pNewModel->GetStyleSheetPool()->Find(
300cdf0e10cSrcweir                                     pStySheet->GetName(),
301cdf0e10cSrcweir                                     SFX_STYLE_FAMILY_ALL));
302cdf0e10cSrcweir                             if (pNewStyleSheet == NULL
303cdf0e10cSrcweir                                 || &pNewStyleSheet->GetPool().GetPool() != pDestPool)
304cdf0e10cSrcweir                             {
305cdf0e10cSrcweir                                 // There is no copy of the style in the new
306cdf0e10cSrcweir                                 // document.  Use the default as a fallback.
307cdf0e10cSrcweir                                 pNewStyleSheet = pNewModel->GetDefaultStyleSheet();
308cdf0e10cSrcweir                             }
309cdf0e10cSrcweir                             ImpAddStyleSheet(pNewStyleSheet, sal_True);
310cdf0e10cSrcweir                         }
311cdf0e10cSrcweir                     }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir                     delete pOldSet;
314cdf0e10cSrcweir                 }
315cdf0e10cSrcweir             }
316cdf0e10cSrcweir         }
317cdf0e10cSrcweir 
SetModel(SdrModel * pOldModel,SdrModel * pNewModel)318cdf0e10cSrcweir         void AttributeProperties::SetModel(SdrModel* pOldModel, SdrModel* pNewModel)
319cdf0e10cSrcweir         {
320cdf0e10cSrcweir             if(pOldModel != pNewModel && pNewModel && !pNewModel->IsLoading())
321cdf0e10cSrcweir             {
322cdf0e10cSrcweir                 // For a living model move the items from one pool to the other
323cdf0e10cSrcweir                 if(pOldModel)
324cdf0e10cSrcweir                 {
325cdf0e10cSrcweir                     // If metric has changed, scale items.
326cdf0e10cSrcweir                     MapUnit aOldUnit(pOldModel->GetScaleUnit());
327cdf0e10cSrcweir                     MapUnit aNewUnit(pNewModel->GetScaleUnit());
328cdf0e10cSrcweir                     sal_Bool bScaleUnitChanged(aNewUnit != aOldUnit);
329cdf0e10cSrcweir                     Fraction aMetricFactor;
330cdf0e10cSrcweir 
331cdf0e10cSrcweir                     if(bScaleUnitChanged)
332cdf0e10cSrcweir                     {
333cdf0e10cSrcweir                         aMetricFactor = GetMapFactor(aOldUnit, aNewUnit).X();
334cdf0e10cSrcweir                         Scale(aMetricFactor);
335cdf0e10cSrcweir                     }
336cdf0e10cSrcweir 
337cdf0e10cSrcweir                     // Move all styles which are used by the object to the new
338cdf0e10cSrcweir                     // StyleSheet pool
339cdf0e10cSrcweir                     SfxStyleSheet* pOldStyleSheet = GetStyleSheet();
340cdf0e10cSrcweir 
341cdf0e10cSrcweir                     if(pOldStyleSheet)
342cdf0e10cSrcweir                     {
343cdf0e10cSrcweir                         SfxStyleSheetBase* pSheet = pOldStyleSheet;
344cdf0e10cSrcweir                         SfxStyleSheetBasePool* pOldPool = pOldModel->GetStyleSheetPool();
345cdf0e10cSrcweir                         SfxStyleSheetBasePool* pNewPool = pNewModel->GetStyleSheetPool();
346cdf0e10cSrcweir                         DBG_ASSERT(pOldPool, "Properties::SetModel(): Object has StyleSheet but no StyleSheetPool (!)");
347cdf0e10cSrcweir 
348cdf0e10cSrcweir                         if(pOldPool && pNewPool)
349cdf0e10cSrcweir                         {
350cdf0e10cSrcweir                             // build a list of to-be-copied Styles
351cdf0e10cSrcweir                             List aList;
352cdf0e10cSrcweir                             SfxStyleSheetBase* pAnchor = 0L;
353cdf0e10cSrcweir 
354cdf0e10cSrcweir                             while(pSheet)
355cdf0e10cSrcweir                             {
356cdf0e10cSrcweir                                 pAnchor = pNewPool->Find(pSheet->GetName(), pSheet->GetFamily());
357cdf0e10cSrcweir 
358cdf0e10cSrcweir                                 if(!pAnchor)
359cdf0e10cSrcweir                                 {
360cdf0e10cSrcweir                                     aList.Insert(pSheet, LIST_APPEND);
361cdf0e10cSrcweir                                     pSheet = pOldPool->Find(pSheet->GetParent(), pSheet->GetFamily());
362cdf0e10cSrcweir                                 }
363cdf0e10cSrcweir                                 else
364cdf0e10cSrcweir                                 {
365cdf0e10cSrcweir                                     // the style does exist
366cdf0e10cSrcweir                                     pSheet = 0L;
367cdf0e10cSrcweir                                 }
368cdf0e10cSrcweir                             }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir                             // copy and set the parents
371cdf0e10cSrcweir                             pSheet = (SfxStyleSheetBase*)aList.First();
372cdf0e10cSrcweir                             SfxStyleSheetBase* pNewSheet = 0L;
373cdf0e10cSrcweir                             SfxStyleSheetBase* pLastSheet = 0L;
374cdf0e10cSrcweir                             SfxStyleSheetBase* pForThisObject = 0L;
375cdf0e10cSrcweir 
376cdf0e10cSrcweir                             while(pSheet)
377cdf0e10cSrcweir                             {
378cdf0e10cSrcweir                                 pNewSheet = &pNewPool->Make(pSheet->GetName(), pSheet->GetFamily(), pSheet->GetMask());
379cdf0e10cSrcweir                                 pNewSheet->GetItemSet().Put(pSheet->GetItemSet(), sal_False);
380cdf0e10cSrcweir 
381cdf0e10cSrcweir                                 if(bScaleUnitChanged)
382cdf0e10cSrcweir                                 {
383cdf0e10cSrcweir                                     sdr::properties::ScaleItemSet(pNewSheet->GetItemSet(), aMetricFactor);
384cdf0e10cSrcweir                                 }
385cdf0e10cSrcweir 
386cdf0e10cSrcweir                                 if(pLastSheet)
387cdf0e10cSrcweir                                 {
388cdf0e10cSrcweir                                     pLastSheet->SetParent(pNewSheet->GetName());
389cdf0e10cSrcweir                                 }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir                                 if(!pForThisObject)
392cdf0e10cSrcweir                                 {
393cdf0e10cSrcweir                                     pForThisObject = pNewSheet;
394cdf0e10cSrcweir                                 }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir                                 pLastSheet = pNewSheet;
397cdf0e10cSrcweir                                 pSheet = (SfxStyleSheetBase*)aList.Next();
398cdf0e10cSrcweir                             }
399cdf0e10cSrcweir 
400cdf0e10cSrcweir                             // Set link to the Style found in the Pool
401cdf0e10cSrcweir                             if(pAnchor && pLastSheet)
402cdf0e10cSrcweir                             {
403cdf0e10cSrcweir                                 pLastSheet->SetParent(pAnchor->GetName());
404cdf0e10cSrcweir                             }
405cdf0e10cSrcweir 
406cdf0e10cSrcweir                             // if list was empty (all Styles exist in destination pool)
407cdf0e10cSrcweir                             // pForThisObject is not yet set
408cdf0e10cSrcweir                             if(!pForThisObject && pAnchor)
409cdf0e10cSrcweir                             {
410cdf0e10cSrcweir                                 pForThisObject = pAnchor;
411cdf0e10cSrcweir                             }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir                             // De-register at old and register at new Style
414cdf0e10cSrcweir                             if(GetStyleSheet() != pForThisObject)
415cdf0e10cSrcweir                             {
416cdf0e10cSrcweir                                 ImpRemoveStyleSheet();
417cdf0e10cSrcweir                                 ImpAddStyleSheet((SfxStyleSheet*)pForThisObject, sal_True);
418cdf0e10cSrcweir                             }
419cdf0e10cSrcweir                         }
420cdf0e10cSrcweir                         else
421cdf0e10cSrcweir                         {
422cdf0e10cSrcweir                             // there is no StyleSheetPool in the new model, thus set
423cdf0e10cSrcweir                             // all items as hard items in the object
424cdf0e10cSrcweir                             List aList;
425cdf0e10cSrcweir                             const SfxItemSet* pItemSet = &pOldStyleSheet->GetItemSet();
426cdf0e10cSrcweir 
427cdf0e10cSrcweir                             while(pItemSet)
428cdf0e10cSrcweir                             {
429cdf0e10cSrcweir                                 aList.Insert((void*)pItemSet, CONTAINER_APPEND);
430cdf0e10cSrcweir                                 pItemSet = pItemSet->GetParent();
431cdf0e10cSrcweir                             }
432cdf0e10cSrcweir 
433cdf0e10cSrcweir                             SfxItemSet* pNewSet = &CreateObjectSpecificItemSet(pNewModel->GetItemPool());
434cdf0e10cSrcweir                             pItemSet = (SfxItemSet*)aList.Last();
435cdf0e10cSrcweir 
436cdf0e10cSrcweir                             while(pItemSet)
437cdf0e10cSrcweir                             {
438cdf0e10cSrcweir                                 pNewSet->Put(*pItemSet);
439cdf0e10cSrcweir                                 pItemSet = (SfxItemSet*)aList.Prev();
440cdf0e10cSrcweir                             }
441cdf0e10cSrcweir 
442cdf0e10cSrcweir                             // Items which were hard attributes before need to stay
443cdf0e10cSrcweir                             if(mpItemSet)
444cdf0e10cSrcweir                             {
445cdf0e10cSrcweir                                 SfxWhichIter aIter(*mpItemSet);
446cdf0e10cSrcweir                                 sal_uInt16 nWhich = aIter.FirstWhich();
447cdf0e10cSrcweir 
448cdf0e10cSrcweir                                 while(nWhich)
449cdf0e10cSrcweir                                 {
450cdf0e10cSrcweir                                     if(mpItemSet->GetItemState(nWhich, sal_False) == SFX_ITEM_SET)
451cdf0e10cSrcweir                                     {
452cdf0e10cSrcweir                                         pNewSet->Put(mpItemSet->Get(nWhich));
453cdf0e10cSrcweir                                     }
454cdf0e10cSrcweir 
455cdf0e10cSrcweir                                     nWhich = aIter.NextWhich();
456cdf0e10cSrcweir                                 }
457cdf0e10cSrcweir                             }
458cdf0e10cSrcweir 
459cdf0e10cSrcweir                             if(bScaleUnitChanged)
460cdf0e10cSrcweir                             {
461cdf0e10cSrcweir                                 ScaleItemSet(*pNewSet, aMetricFactor);
462cdf0e10cSrcweir                             }
463cdf0e10cSrcweir 
464cdf0e10cSrcweir                             if(mpItemSet)
465cdf0e10cSrcweir                             {
466cdf0e10cSrcweir                                 if(GetStyleSheet())
467cdf0e10cSrcweir                                 {
468cdf0e10cSrcweir                                     ImpRemoveStyleSheet();
469cdf0e10cSrcweir                                 }
470cdf0e10cSrcweir 
471cdf0e10cSrcweir                                 delete mpItemSet;
472cdf0e10cSrcweir                                 mpItemSet = 0L;
473cdf0e10cSrcweir                             }
474cdf0e10cSrcweir 
475cdf0e10cSrcweir                             mpItemSet = pNewSet;
476cdf0e10cSrcweir                         }
477cdf0e10cSrcweir                     }
478cdf0e10cSrcweir                 }
479cdf0e10cSrcweir 
480cdf0e10cSrcweir                 // each object gets the default Style if there is none set yet.
481ba200a2dSJürgen Schmidt                 if(!GetStyleSheet() && pNewModel && !pNewModel->IsLoading())
482cdf0e10cSrcweir                 {
483ba200a2dSJürgen Schmidt                     GetObjectItemSet(); // #118414# force ItemSet to allow style to be set
484cdf0e10cSrcweir                     SetStyleSheet(pNewModel->GetDefaultStyleSheet(), sal_True);
485cdf0e10cSrcweir                 }
486cdf0e10cSrcweir             }
487cdf0e10cSrcweir         }
488cdf0e10cSrcweir 
ForceStyleToHardAttributes()489cdf0e10cSrcweir         void AttributeProperties::ForceStyleToHardAttributes()
490cdf0e10cSrcweir         {
491cdf0e10cSrcweir             if(GetStyleSheet() && HAS_BASE(SfxStyleSheet, mpStyleSheet))
492cdf0e10cSrcweir             {
493cdf0e10cSrcweir                 // prepare copied, new itemset, but WITHOUT parent
494cdf0e10cSrcweir                 GetObjectItemSet();
495cdf0e10cSrcweir                 SfxItemSet* pDestItemSet = new SfxItemSet(*mpItemSet);
496cdf0e10cSrcweir                 pDestItemSet->SetParent(0L);
497cdf0e10cSrcweir 
498cdf0e10cSrcweir                 // pepare forgetting the current stylesheet like in RemoveStyleSheet()
499cdf0e10cSrcweir                 EndListening(*mpStyleSheet);
500cdf0e10cSrcweir                 EndListening(mpStyleSheet->GetPool());
501cdf0e10cSrcweir 
502cdf0e10cSrcweir                 // prepare the iter; use the mpObjectItemSet which may have less
503cdf0e10cSrcweir                 // WhichIDs than the style.
504cdf0e10cSrcweir                 SfxWhichIter aIter(*pDestItemSet);
505cdf0e10cSrcweir                 sal_uInt16 nWhich(aIter.FirstWhich());
506cdf0e10cSrcweir                 const SfxPoolItem *pItem = NULL;
507cdf0e10cSrcweir 
508cdf0e10cSrcweir                 // now set all hard attributes of the current at the new itemset
509cdf0e10cSrcweir                 while(nWhich)
510cdf0e10cSrcweir                 {
511cdf0e10cSrcweir                     // #i61284# use mpItemSet with parents, makes things easier and reduces to
512cdf0e10cSrcweir                     // one loop
513cdf0e10cSrcweir                     if(SFX_ITEM_SET == mpItemSet->GetItemState(nWhich, true, &pItem))
514cdf0e10cSrcweir                     {
515cdf0e10cSrcweir                         pDestItemSet->Put(*pItem);
516cdf0e10cSrcweir                     }
517cdf0e10cSrcweir 
518cdf0e10cSrcweir                     nWhich = aIter.NextWhich();
519cdf0e10cSrcweir                 }
520cdf0e10cSrcweir 
521cdf0e10cSrcweir                 // replace itemsets
522cdf0e10cSrcweir                 delete mpItemSet;
523cdf0e10cSrcweir                 mpItemSet = pDestItemSet;
524cdf0e10cSrcweir 
525cdf0e10cSrcweir                 // set necessary changes like in RemoveStyleSheet()
526cdf0e10cSrcweir                 GetSdrObject().SetBoundRectDirty();
527cdf0e10cSrcweir                 GetSdrObject().SetRectsDirty(sal_True);
528cdf0e10cSrcweir 
529cdf0e10cSrcweir                 mpStyleSheet = NULL;
530cdf0e10cSrcweir             }
531cdf0e10cSrcweir         }
532cdf0e10cSrcweir 
Notify(SfxBroadcaster & rBC,const SfxHint & rHint)533cdf0e10cSrcweir         void AttributeProperties::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
534cdf0e10cSrcweir         {
535cdf0e10cSrcweir             sal_Bool bHintUsed(sal_False);
536cdf0e10cSrcweir 
537cdf0e10cSrcweir             SfxStyleSheetHint *pStyleHint = PTR_CAST(SfxStyleSheetHint, &rHint);
538cdf0e10cSrcweir 
539cdf0e10cSrcweir             if(pStyleHint && pStyleHint->GetStyleSheet() == GetStyleSheet())
540cdf0e10cSrcweir             {
541cdf0e10cSrcweir                 SdrObject& rObj = GetSdrObject();
542cdf0e10cSrcweir                 //SdrPage* pPage = rObj.GetPage();
543cdf0e10cSrcweir 
544cdf0e10cSrcweir                 switch(pStyleHint->GetHint())
545cdf0e10cSrcweir                 {
546cdf0e10cSrcweir                     case SFX_STYLESHEET_CREATED         :
547cdf0e10cSrcweir                     {
548cdf0e10cSrcweir                         // cannot happen, nothing to do
549cdf0e10cSrcweir                         break;
550cdf0e10cSrcweir                     }
551cdf0e10cSrcweir                     case SFX_STYLESHEET_MODIFIED        :
552cdf0e10cSrcweir                     case SFX_STYLESHEET_CHANGED         :
553cdf0e10cSrcweir                     {
554cdf0e10cSrcweir                         // notify change
555cdf0e10cSrcweir                         break;
556cdf0e10cSrcweir                     }
557cdf0e10cSrcweir                     case SFX_STYLESHEET_ERASED          :
558cdf0e10cSrcweir                     case SFX_STYLESHEET_INDESTRUCTION   :
559cdf0e10cSrcweir                     {
560cdf0e10cSrcweir                         // Style needs to be exchanged
561cdf0e10cSrcweir                         SfxStyleSheet* pNewStSh = 0L;
562cdf0e10cSrcweir                         SdrModel* pModel = rObj.GetModel();
563cdf0e10cSrcweir 
564cdf0e10cSrcweir                         // #111111#
565cdf0e10cSrcweir                         // Do nothing if object is in destruction, else a StyleSheet may be found from
566cdf0e10cSrcweir                         // a StyleSheetPool which is just being deleted itself. and thus it would be fatal
567cdf0e10cSrcweir                         // to register as listener to that new StyleSheet.
568cdf0e10cSrcweir                         if(pModel && !rObj.IsInDestruction())
569cdf0e10cSrcweir                         {
570cdf0e10cSrcweir                             if(HAS_BASE(SfxStyleSheet, GetStyleSheet()))
571cdf0e10cSrcweir                             {
572cdf0e10cSrcweir                                 pNewStSh = (SfxStyleSheet*)pModel->GetStyleSheetPool()->Find(
573cdf0e10cSrcweir                                     GetStyleSheet()->GetParent(), GetStyleSheet()->GetFamily());
574cdf0e10cSrcweir                             }
575cdf0e10cSrcweir 
576cdf0e10cSrcweir                             if(!pNewStSh)
577cdf0e10cSrcweir                             {
578cdf0e10cSrcweir                                 pNewStSh = pModel->GetDefaultStyleSheet();
579cdf0e10cSrcweir                             }
580cdf0e10cSrcweir                         }
581cdf0e10cSrcweir 
582cdf0e10cSrcweir                         // remove used style, it's erased or in destruction
583cdf0e10cSrcweir                         ImpRemoveStyleSheet();
584cdf0e10cSrcweir 
585cdf0e10cSrcweir                         if(pNewStSh)
586cdf0e10cSrcweir                         {
587cdf0e10cSrcweir                             ImpAddStyleSheet(pNewStSh, sal_True);
588cdf0e10cSrcweir                         }
589cdf0e10cSrcweir 
590cdf0e10cSrcweir                         break;
591cdf0e10cSrcweir                     }
592cdf0e10cSrcweir                 }
593cdf0e10cSrcweir 
594cdf0e10cSrcweir                 // Get old BoundRect. Do this after the style change is handled
595cdf0e10cSrcweir                 // in the ItemSet parts because GetBoundRect() may calculate a new
596cdf0e10cSrcweir                 Rectangle aBoundRect = rObj.GetLastBoundRect();
597cdf0e10cSrcweir 
598cdf0e10cSrcweir                 rObj.SetRectsDirty(sal_True);
599cdf0e10cSrcweir 
600cdf0e10cSrcweir                 // tell the object about the change
601cdf0e10cSrcweir                 rObj.SetChanged();
602cdf0e10cSrcweir                 rObj.BroadcastObjectChange();
603cdf0e10cSrcweir 
604cdf0e10cSrcweir                 //if(pPage && pPage->IsInserted())
605cdf0e10cSrcweir                 //{
606cdf0e10cSrcweir                 //  rObj.BroadcastObjectChange();
607cdf0e10cSrcweir                 //}
608cdf0e10cSrcweir 
609cdf0e10cSrcweir                 rObj.SendUserCall(SDRUSERCALL_CHGATTR, aBoundRect);
610cdf0e10cSrcweir 
611cdf0e10cSrcweir                 bHintUsed = sal_True;
612cdf0e10cSrcweir             }
613cdf0e10cSrcweir 
614cdf0e10cSrcweir             if(!bHintUsed)
615cdf0e10cSrcweir             {
616cdf0e10cSrcweir                 // forward to SdrObject ATM. Not sure if this will be necessary
617cdf0e10cSrcweir                 // in the future.
618cdf0e10cSrcweir                 GetSdrObject().Notify(rBC, rHint);
619cdf0e10cSrcweir             }
620cdf0e10cSrcweir         }
621cdf0e10cSrcweir     } // end of namespace properties
622cdf0e10cSrcweir } // end of namespace sdr
623cdf0e10cSrcweir 
624cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
625cdf0e10cSrcweir // eof
626