Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svx/sdr/properties/defaultproperties.hxx>
30 : : #include <svx/sdr/properties/itemsettools.hxx>
31 : : #include <svl/itemset.hxx>
32 : : #include <svl/whiter.hxx>
33 : :
34 : : #include <vector>
35 : : #include <svx/svdobj.hxx>
36 : : #include <svx/svddef.hxx>
37 : : #include <svx/svdpool.hxx>
38 : : #include <editeng/eeitem.hxx>
39 : :
40 : : //////////////////////////////////////////////////////////////////////////////
41 : :
42 : : namespace sdr
43 : : {
44 : : namespace properties
45 : : {
46 : 0 : SfxItemSet& DefaultProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
47 : : {
48 : : // Basic implementation; Basic object has NO attributes
49 [ # # ]: 0 : return *(new SfxItemSet(rPool));
50 : : }
51 : :
52 : 94935 : DefaultProperties::DefaultProperties(SdrObject& rObj)
53 : : : BaseProperties(rObj),
54 : 94935 : mpItemSet(0L)
55 : : {
56 : 94935 : }
57 : :
58 : 6 : DefaultProperties::DefaultProperties(const DefaultProperties& rProps, SdrObject& rObj)
59 : : : BaseProperties(rObj),
60 : 6 : mpItemSet(0L)
61 : : {
62 [ + - ]: 6 : if(rProps.mpItemSet)
63 : : {
64 [ + - ]: 6 : mpItemSet = rProps.mpItemSet->Clone(sal_True);
65 : :
66 : : // do not keep parent info, this may be changed by later construrtors.
67 : : // This class just copies the ItemSet, ignore parent.
68 [ + - ][ - + ]: 6 : if(mpItemSet && mpItemSet->GetParent())
[ - + ]
69 : : {
70 : 0 : mpItemSet->SetParent(0L);
71 : : }
72 : : }
73 : 6 : }
74 : :
75 : 0 : BaseProperties& DefaultProperties::Clone(SdrObject& rObj) const
76 : : {
77 [ # # ]: 0 : return *(new DefaultProperties(*this, rObj));
78 : : }
79 : :
80 : 94844 : DefaultProperties::~DefaultProperties()
81 : : {
82 [ + + ]: 94844 : if(mpItemSet)
83 : : {
84 [ + - ][ + - ]: 60030 : delete mpItemSet;
85 : 60030 : mpItemSet = 0L;
86 : : }
87 [ - + ]: 94844 : }
88 : :
89 : 6505436 : const SfxItemSet& DefaultProperties::GetObjectItemSet() const
90 : : {
91 [ + + ]: 6505436 : if(!mpItemSet)
92 : : {
93 : 60121 : ((DefaultProperties*)this)->mpItemSet = &(((DefaultProperties*)this)->CreateObjectSpecificItemSet(*GetSdrObject().GetObjectItemPool()));
94 : 60121 : ((DefaultProperties*)this)->ForceDefaultAttributes();
95 : : }
96 : :
97 : : DBG_ASSERT(mpItemSet, "Could not create an SfxItemSet(!)");
98 : :
99 : 6505436 : return *mpItemSet;
100 : : }
101 : :
102 : 53893 : void DefaultProperties::SetObjectItem(const SfxPoolItem& rItem)
103 : : {
104 : 53893 : const sal_uInt16 nWhichID(rItem.Which());
105 : :
106 [ + - ]: 53893 : if(AllowItemChange(nWhichID, &rItem))
107 : : {
108 [ + - ]: 53893 : ItemChange(nWhichID, &rItem);
109 [ + - ]: 53893 : PostItemChange(nWhichID);
110 : :
111 [ + - ][ + - ]: 53893 : SfxItemSet aSet(*GetSdrObject().GetObjectItemPool(), nWhichID, nWhichID);
112 [ + - ]: 53893 : aSet.Put(rItem);
113 [ + - ][ + - ]: 53893 : ItemSetChanged(aSet);
114 : : }
115 : 53893 : }
116 : :
117 : 73588 : void DefaultProperties::SetObjectItemDirect(const SfxPoolItem& rItem)
118 : : {
119 : 73588 : const sal_uInt16 nWhichID(rItem.Which());
120 : :
121 [ + - ]: 73588 : if(AllowItemChange(nWhichID, &rItem))
122 : : {
123 : 73588 : ItemChange(nWhichID, &rItem);
124 : : }
125 : 73588 : }
126 : :
127 : 368 : void DefaultProperties::ClearObjectItem(const sal_uInt16 nWhich)
128 : : {
129 [ + - ]: 368 : if(AllowItemChange(nWhich))
130 : : {
131 : 368 : ItemChange(nWhich);
132 : 368 : PostItemChange(nWhich);
133 : :
134 [ - + ]: 368 : if(nWhich)
135 : : {
136 [ # # ][ # # ]: 0 : SfxItemSet aSet(*GetSdrObject().GetObjectItemPool(), nWhich, nWhich, 0, 0);
137 [ # # ][ # # ]: 0 : ItemSetChanged(aSet);
138 : : }
139 : : }
140 : 368 : }
141 : :
142 : 37944 : void DefaultProperties::ClearObjectItemDirect(const sal_uInt16 nWhich)
143 : : {
144 [ + + ]: 37944 : if(AllowItemChange(nWhich))
145 : : {
146 : 37200 : ItemChange(nWhich);
147 : : }
148 : 37944 : }
149 : :
150 : 98837 : void DefaultProperties::SetObjectItemSet(const SfxItemSet& rSet)
151 : : {
152 [ + - ]: 98837 : SfxWhichIter aWhichIter(rSet);
153 [ + - ]: 98837 : sal_uInt16 nWhich(aWhichIter.FirstWhich());
154 : : const SfxPoolItem *pPoolItem;
155 [ + - ]: 98837 : std::vector< sal_uInt16 > aPostItemChangeList;
156 : 98837 : sal_Bool bDidChange(sal_False);
157 [ + - ][ + - ]: 98837 : SfxItemSet aSet(*GetSdrObject().GetObjectItemPool(), SDRATTR_START, EE_ITEMS_END);
158 : :
159 : : // give a hint to STL_Vector
160 [ + - ]: 98837 : aPostItemChangeList.reserve(rSet.Count());
161 : :
162 [ + + ]: 6892565 : while(nWhich)
163 : : {
164 [ + - ][ + + ]: 6793728 : if(SFX_ITEM_SET == rSet.GetItemState(nWhich, sal_False, &pPoolItem))
165 : : {
166 [ + - ][ + - ]: 1272023 : if(AllowItemChange(nWhich, pPoolItem))
167 : : {
168 : 1272023 : bDidChange = sal_True;
169 [ + - ]: 1272023 : ItemChange(nWhich, pPoolItem);
170 [ + - ]: 1272023 : aPostItemChangeList.push_back( nWhich );
171 [ + - ]: 1272023 : aSet.Put(*pPoolItem);
172 : : }
173 : : }
174 : :
175 [ + - ]: 6793728 : nWhich = aWhichIter.NextWhich();
176 : : }
177 : :
178 [ + - ]: 98837 : if(bDidChange)
179 : : {
180 : 98837 : std::vector< sal_uInt16 >::iterator aIter = aPostItemChangeList.begin();
181 : 98837 : const std::vector< sal_uInt16 >::iterator aEnd = aPostItemChangeList.end();
182 : :
183 [ + - ][ + + ]: 1370860 : while(aIter != aEnd)
184 : : {
185 [ + - ][ + - ]: 1272023 : PostItemChange(*aIter);
186 [ + - ]: 1272023 : ++aIter;
187 : : }
188 : :
189 [ + - ]: 98837 : ItemSetChanged(aSet);
190 [ + - ][ + - ]: 98837 : }
191 : 98837 : }
192 : :
193 : 0 : void DefaultProperties::ItemSetChanged(const SfxItemSet& /*rSet*/)
194 : : {
195 : 0 : }
196 : :
197 : 1437072 : sal_Bool DefaultProperties::AllowItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/) const
198 : : {
199 : 1437072 : return sal_True;
200 : : }
201 : :
202 : 0 : void DefaultProperties::ItemChange(const sal_uInt16 /*nWhich*/, const SfxPoolItem* /*pNewItem*/)
203 : : {
204 : 0 : }
205 : :
206 : 1326284 : void DefaultProperties::PostItemChange(const sal_uInt16 nWhich )
207 : : {
208 [ + + ][ + - ]: 1326284 : if( (nWhich == XATTR_FILLSTYLE) && (mpItemSet != NULL) )
209 : 48810 : CleanupFillProperties(*mpItemSet);
210 : 1326284 : }
211 : :
212 : 0 : void DefaultProperties::SetStyleSheet(SfxStyleSheet* /*pNewStyleSheet*/, sal_Bool /*bDontRemoveHardAttr*/)
213 : : {
214 : : // no StyleSheet in DefaultProperties
215 : 0 : }
216 : :
217 : 0 : SfxStyleSheet* DefaultProperties::GetStyleSheet() const
218 : : {
219 : : // no StyleSheet in DefaultProperties
220 : 0 : return 0L;
221 : : }
222 : :
223 : 2675 : void DefaultProperties::ForceDefaultAttributes()
224 : : {
225 : 2675 : }
226 : :
227 : 0 : void DefaultProperties::Scale(const Fraction& rScale)
228 : : {
229 [ # # ]: 0 : if(mpItemSet)
230 : : {
231 : 0 : ScaleItemSet(*mpItemSet, rScale);
232 : : }
233 : 0 : }
234 : : } // end of namespace properties
235 : : } // end of namespace sdr
236 : :
237 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|