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/itemsettools.hxx>
27 #include <tools/debug.hxx>
28 #include <svl/itemset.hxx>
29 #include <svl/whiter.hxx>
30 
31 #include <vector>
32 #include <svx/svdogrp.hxx>
33 #include <svx/svditer.hxx>
34 
35 //////////////////////////////////////////////////////////////////////////////
36 // class to remember broadcast start positions
37 
38 namespace sdr
39 {
40 	namespace properties
41 	{
42 		// helper vector to remember rectangles
43 		typedef ::std::vector< Rectangle > RectangleVector;
44 
45 		ItemChangeBroadcaster::ItemChangeBroadcaster(const SdrObject& rObj)
46 		{
47 			if(rObj.ISA(SdrObjGroup))
48 			{
49 				SdrObjListIter aIter((const SdrObjGroup&)rObj, IM_DEEPNOGROUPS);
50 				mpData = new RectangleVector;
51 				DBG_ASSERT(mpData, "ItemChangeBroadcaster: No memory (!)");
52 				((RectangleVector*)mpData)->reserve(aIter.Count());
53 
54 				while(aIter.IsMore())
55 				{
56 					SdrObject* pObj = aIter.Next();
57 
58 					if(pObj)
59 					{
60 						((RectangleVector*)mpData)->push_back(pObj->GetLastBoundRect());
61 					}
62 				}
63 
64 				mnCount = ((RectangleVector*)mpData)->size();
65 			}
66 			else
67 			{
68 				mpData = new Rectangle(rObj.GetLastBoundRect());
69 				mnCount = 1L;
70 			}
71 		}
72 
73 		ItemChangeBroadcaster::~ItemChangeBroadcaster()
74 		{
75 			if(mnCount > 1)
76 			{
77 				delete ((RectangleVector*)mpData);
78 			}
79 			else
80 			{
81 				delete ((Rectangle*)mpData);
82 			}
83 		}
84 
85 		sal_uInt32 ItemChangeBroadcaster::GetRectangleCount() const
86 		{
87 			return mnCount;
88 		}
89 
90 		const Rectangle& ItemChangeBroadcaster::GetRectangle(sal_uInt32 nIndex) const
91 		{
92 			if(mnCount > 1)
93 			{
94 				return (*((RectangleVector*)mpData))[nIndex];
95 			}
96 			else
97 			{
98 				return *((Rectangle*)mpData);
99 			}
100 		}
101 	} // end of namespace properties
102 } // end of namespace sdr
103 
104 //////////////////////////////////////////////////////////////////////////////
105 
106 namespace sdr
107 {
108 	namespace properties
109 	{
110 		void ScaleItemSet(SfxItemSet& rSet, const Fraction& rScale)
111 		{
112 			sal_Int32 nMul(rScale.GetNumerator());
113 			sal_Int32 nDiv(rScale.GetDenominator());
114 
115 			if(!rScale.IsValid() || !nDiv)
116 			{
117 				return;
118 			}
119 
120 			SfxWhichIter aIter(rSet);
121 			sal_uInt16 nWhich(aIter.FirstWhich());
122 			const SfxPoolItem *pItem = NULL;
123 
124 			while(nWhich)
125 			{
126 				if(SFX_ITEM_SET == rSet.GetItemState(nWhich, sal_False, &pItem))
127 				{
128 					if(pItem->HasMetrics())
129 					{
130 						SfxPoolItem* pNewItem = pItem->Clone();
131 						pNewItem->ScaleMetrics(nMul, nDiv);
132 						rSet.Put(*pNewItem);
133 					}
134 				}
135 				nWhich = aIter.NextWhich();
136 			}
137 		}
138 	} // end of namespace properties
139 } // end of namespace sdr
140 
141 //////////////////////////////////////////////////////////////////////////////
142 // eof
143