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