1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SDR_PROPERTIES_PROPERTIES_HXX
29 #define _SDR_PROPERTIES_PROPERTIES_HXX
30 
31 #include <sal/types.h>
32 #include "svx/svxdllapi.h"
33 
34 //////////////////////////////////////////////////////////////////////////////
35 // predeclarations
36 
37 class SdrObject;
38 class SfxItemSet;
39 class SfxPoolItem;
40 class SfxStyleSheet;
41 class Fraction;
42 class SfxItemPool;
43 class SdrModel;
44 
45 namespace sdr
46 {
47 	namespace properties
48 	{
49 		class ItemChangeBroadcaster;
50 	} // end of namespace properties
51 } // end of namespace sdr
52 
53 //////////////////////////////////////////////////////////////////////////////
54 
55 namespace sdr
56 {
57 	namespace properties
58 	{
59 		class SVX_DLLPUBLIC BaseProperties
60 		{
61 		protected:
62 			// the owner of this Properties. Set from constructor and not
63 			// to be changed in any way.
64 			SdrObject&										mrObject;
65 
66 			// create a new object specific itemset with object specific ranges.
67 			virtual SfxItemSet& CreateObjectSpecificItemSet(SfxItemPool& pPool) = 0;
68 
69 			// internal access to SdrObject
70 			SdrObject& GetSdrObject() const
71 			{
72 				return mrObject;
73 			}
74 
75 			// Test changeability for a single item. If a implementation wants to prevent
76 			// changing an item this method may be overloaded.
77 			virtual sal_Bool AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem = 0) const = 0;
78 
79 			// Do the internal ItemChange. If only nWhich is given, the item needs to be cleared.
80 			// Also needs to handle if nWhich and pNewItem is 0, which means to clear all items.
81 			virtual void ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem = 0) = 0;
82 
83 			// Called after ItemChange() is done for all items. Allows local reactions on
84 			// specific item changes
85 			virtual void PostItemChange(const sal_uInt16 nWhich) = 0;
86 
87 			// Internally react on ItemSet changes. The given ItemSet contains all changed items, the new ones.
88 			virtual void ItemSetChanged(const SfxItemSet& rSet) = 0;
89 
90 		public:
91 			// basic constructor, used from SdrObject.
92 			BaseProperties(SdrObject& rObj);
93 
94 			// constructor for copying, but using new object. Used from the Clone()
95 			// method.
96 			BaseProperties(const BaseProperties& rProps, SdrObject& rObj);
97 
98 			// destructor
99 			virtual ~BaseProperties();
100 
101 			// Clone() operator, normally just calls the local copy constructor,
102 			// see above.
103 			virtual BaseProperties& Clone(SdrObject& rObj) const = 0;
104 
105 			// Get the local ItemSet. This directly returns the local ItemSet of the object. No
106 			// merging of ItemSets is done for e.g. Group objects.
107 			virtual const SfxItemSet& GetObjectItemSet() const = 0;
108 
109 			// get merged ItemSet. Normappl, this maps directly to GetObjectItemSet(), but may
110 			// be overloaded e.g for group objects to return a merged ItemSet of the object.
111 			// When using this method the returned ItemSet may contain items in the state
112 			// SFX_ITEM_DONTCARE which means there were several such items with different
113 			// values.
114 			virtual const SfxItemSet& GetMergedItemSet() const;
115 
116 			// Sets all items which are on state SFX_ITEM_SET in rSet at the local ItemSet.
117 			// Uses AllowItemChange(), ItemChange(), PostItemChange() and ItemSetChanged() calls.
118 			virtual void SetObjectItemSet(const SfxItemSet& rSet) = 0;
119 
120 			// Set merged ItemSet. Normally, this maps to SetObjectItemSet().
121 			virtual void SetMergedItemSet(const SfxItemSet& rSet, sal_Bool bClearAllItems = sal_False);
122 
123 			// Set single item at the local ItemSet. Uses AllowItemChange(),
124 			// ItemChange(), PostItemChange() and ItemSetChanged() calls.
125 			virtual void SetObjectItem(const SfxPoolItem& rItem) = 0;
126 
127 			// Set a single item direct. Only uses AllowItemChange() and ItemChange(),
128 			// but not PostItemChange() and ItemSetChanged() calls.
129 			virtual void SetObjectItemDirect(const SfxPoolItem& rItem) = 0;
130 
131 			// Clear a single local item. Uses AllowItemChange(),
132 			// ItemChange(), PostItemChange() and ItemSetChanged() calls.
133 			virtual void ClearObjectItem(const sal_uInt16 nWhich = 0) = 0;
134 
135 			// Set a single item, iterate over hierarchies if necessary. Default
136 			// Implementation falls back to ClearObjectItem().
137 			virtual void SetMergedItem(const SfxPoolItem& rItem);
138 
139 			// Clear a single item, iterate over hierarchies if necessary. Default
140 			// Implementation falls back to ClearObjectItem().
141 			virtual void ClearMergedItem(const sal_uInt16 nWhich = 0);
142 
143 			// Clear single item direct. Only uses AllowItemChange() and ItemChange(),
144 			// but not PostItemChange() and ItemSetChanged() calls.
145 			// Also supports complete deletion of items when default parameter 0 is used.
146 			virtual void ClearObjectItemDirect(const sal_uInt16 nWhich = 0) = 0;
147 
148 			// Set a new StyleSheet. Registers as listener at the StyleSheet to get knowledge
149 			// of StyleSheet changes.
150 			virtual void SetStyleSheet(SfxStyleSheet* pNewStyleSheet, sal_Bool bDontRemoveHardAttr) = 0;
151 
152 			// Get the installed StyleSheet.
153 			virtual SfxStyleSheet* GetStyleSheet() const = 0;
154 
155 			// Scale the local ItemSet as far as it contains metric items. This needs to be
156 			// overloaded to do it for hierarchical objects like e.g. groups.
157 			virtual void Scale(const Fraction& rScale);
158 
159 			// Move local items to a new ItemPool. This needs to be
160 			// overloaded to do it for hierarchical objects like e.g. groups.
161 			virtual void MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel = 0L);
162 
163 			// Set new model.
164 			virtual void SetModel(SdrModel* pOldModel, SdrModel* pNewModel);
165 
166 			// force all attributes which come from styles to hard attributes
167 			// to be able to live without the style.
168 			virtual void ForceStyleToHardAttributes();
169 
170 			// syntactical sugar for ItemSet accesses. Broadcasts before and after the changes
171 			// to invalidate views in old and new BoundRects. As soon as the repaint mechanism
172 			// will be changed these broadcasts will no longer be needed.
173 			//void SetItemAndBroadcast(const SfxPoolItem& rItem);
174 			//void ClearItemAndBroadcast(const sal_uInt16 nWhich = 0);
175 			void SetMergedItemSetAndBroadcast(const SfxItemSet& rSet, sal_Bool bClearAllItems = sal_False);
176 
177 			// Just a convenient shortcut for GetObjectItemSet().Get(nWhich).
178 			const SfxPoolItem& GetItem(const sal_uInt16 nWhich) const;
179 
180 			// support for convenient broadcasting. Used from SetMergedItemAndBroadcast(),
181 			// ClearItemAndBroadcast() and SetItemSetAndBroadcast(), see above.
182 			// But also from inside SdrObjects.
183 			void BroadcastItemChange(const ItemChangeBroadcaster& rChange);
184 
185             // #i101556# add versioning mechanism; used from e.g. text attribute set to
186             // allow detection of e.g. style sheet or single text attribute changes. The
187             // default implementation returns 0 (zero)
188             virtual sal_uInt32 getVersion() const;
189 		};
190 
191 		// checks the FillStyle item and removes unneeded Gradient, FillBitmap and Hatch items
192 		void SVX_DLLPUBLIC CleanupFillProperties( SfxItemSet& rItemSet );
193 
194 	} // end of namespace properties
195 } // end of namespace sdr
196 
197 //////////////////////////////////////////////////////////////////////////////
198 
199 #endif //_SDR_PROPERTIES_PROPERTIES_HXX
200 
201 // eof
202