Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include <svx/sdr/properties/itemsettools.hxx>
21 : : #include <tools/debug.hxx>
22 : : #include <svl/itemset.hxx>
23 : : #include <svl/whiter.hxx>
24 : :
25 : : #include <vector>
26 : : #include <svx/svdogrp.hxx>
27 : : #include <svx/svditer.hxx>
28 : :
29 : : //////////////////////////////////////////////////////////////////////////////
30 : : // class to remember broadcast start positions
31 : :
32 : : namespace sdr
33 : : {
34 : : namespace properties
35 : : {
36 : : // helper vector to remember rectangles
37 : : typedef ::std::vector< Rectangle > RectangleVector;
38 : :
39 : 95330 : ItemChangeBroadcaster::ItemChangeBroadcaster(const SdrObject& rObj)
40 : : {
41 [ - + ]: 95330 : if(rObj.ISA(SdrObjGroup))
42 : : {
43 [ # # ]: 0 : SdrObjListIter aIter((const SdrObjGroup&)rObj, IM_DEEPNOGROUPS);
44 [ # # ][ # # ]: 0 : mpData = new RectangleVector;
45 : : DBG_ASSERT(mpData, "ItemChangeBroadcaster: No memory (!)");
46 [ # # ]: 0 : ((RectangleVector*)mpData)->reserve(aIter.Count());
47 : :
48 [ # # ]: 0 : while(aIter.IsMore())
49 : : {
50 [ # # ]: 0 : SdrObject* pObj = aIter.Next();
51 : :
52 [ # # ]: 0 : if(pObj)
53 : : {
54 [ # # ][ # # ]: 0 : ((RectangleVector*)mpData)->push_back(pObj->GetLastBoundRect());
55 : : }
56 : : }
57 : :
58 : 0 : mnCount = ((RectangleVector*)mpData)->size();
59 : : }
60 : : else
61 : : {
62 : 95330 : mpData = new Rectangle(rObj.GetLastBoundRect());
63 : 95330 : mnCount = 1L;
64 : : }
65 : 95330 : }
66 : :
67 : 95330 : ItemChangeBroadcaster::~ItemChangeBroadcaster()
68 : : {
69 [ - + ]: 95330 : if(mnCount > 1)
70 : : {
71 [ # # ]: 0 : delete ((RectangleVector*)mpData);
72 : : }
73 : : else
74 : : {
75 : 95330 : delete ((Rectangle*)mpData);
76 : : }
77 : 95330 : }
78 : :
79 : 95330 : sal_uInt32 ItemChangeBroadcaster::GetRectangleCount() const
80 : : {
81 : 95330 : return mnCount;
82 : : }
83 : :
84 : 95330 : const Rectangle& ItemChangeBroadcaster::GetRectangle(sal_uInt32 nIndex) const
85 : : {
86 [ - + ]: 95330 : if(mnCount > 1)
87 : : {
88 : 0 : return (*((RectangleVector*)mpData))[nIndex];
89 : : }
90 : : else
91 : : {
92 : 95330 : return *((Rectangle*)mpData);
93 : : }
94 : : }
95 : : } // end of namespace properties
96 : : } // end of namespace sdr
97 : :
98 : : //////////////////////////////////////////////////////////////////////////////
99 : :
100 : : namespace sdr
101 : : {
102 : : namespace properties
103 : : {
104 : 0 : void ScaleItemSet(SfxItemSet& rSet, const Fraction& rScale)
105 : : {
106 : 0 : sal_Int32 nMul(rScale.GetNumerator());
107 : 0 : sal_Int32 nDiv(rScale.GetDenominator());
108 : :
109 [ # # ][ # # ]: 0 : if(!rScale.IsValid() || !nDiv)
[ # # ][ # # ]
110 : : {
111 : 0 : return;
112 : : }
113 : :
114 [ # # ]: 0 : SfxWhichIter aIter(rSet);
115 [ # # ]: 0 : sal_uInt16 nWhich(aIter.FirstWhich());
116 : 0 : const SfxPoolItem *pItem = NULL;
117 : :
118 [ # # ]: 0 : while(nWhich)
119 : : {
120 [ # # ][ # # ]: 0 : if(SFX_ITEM_SET == rSet.GetItemState(nWhich, sal_False, &pItem))
121 : : {
122 [ # # ][ # # ]: 0 : if(pItem->HasMetrics())
123 : : {
124 [ # # ]: 0 : SfxPoolItem* pNewItem = pItem->Clone();
125 [ # # ]: 0 : pNewItem->ScaleMetrics(nMul, nDiv);
126 [ # # ]: 0 : rSet.Put(*pNewItem);
127 : : }
128 : : }
129 [ # # ]: 0 : nWhich = aIter.NextWhich();
130 [ # # ]: 0 : }
131 : : }
132 : : } // end of namespace properties
133 : : } // end of namespace sdr
134 : :
135 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|