Debian Codegraph @

chart2/source/controller/main/ChartController_Position.cxx

raw
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 <ChartController.hxx>
21
22 #include <DrawViewWrapper.hxx>
23 #include <PositionAndSizeHelper.hxx>
24 #include <ChartModel.hxx>
25 #include <ChartView.hxx>
26 #include "UndoGuard.hxx"
27 #include <ObjectNameProvider.hxx>
28 #include <DiagramHelper.hxx>
29 #include <CommonConverters.hxx>
30 #include <svx/ActionDescriptionProvider.hxx>
31
32 #include <svx/svxids.hrc>
33 #include <svx/rectenum.hxx>
34 #include <svl/intitem.hxx>
35 #include <svx/svxdlg.hxx>
36 #include <comphelper/diagnose_ex.hxx>
37 #include <vcl/svapp.hxx>
38 #include <memory>
39
40 namespace chart
41 {
42 using namespace ::com::sun::star;
43
44 static void lcl_getPositionAndSizeFromItemSet( const SfxItemSet& rItemSet, awt::Rectangle& rPosAndSize, const awt::Size& rOriginalSize )
45 {
46 tools::Long nPosX(0);
47 tools::Long nPosY(0);
48 tools::Long nSizX(0);
49 tools::Long nSizY(0);
50
51 RectPoint eRP = RectPoint::LT;
52
53 //read position
54 if (const SfxInt32Item* pPosXItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_POS_X))
55 nPosX = pPosXItem->GetValue();
56 if (const SfxInt32Item* pPosYItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_POS_Y))
57 nPosY = pPosYItem->GetValue();
58 //read size
59 if (const SfxUInt32Item* pWidthItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_WIDTH))
60 nSizX = pWidthItem->GetValue();
61 if (const SfxUInt32Item* pHeightItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_HEIGHT))
62 nSizY = pHeightItem->GetValue();
63 if (const SfxUInt16Item* pSizeItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_SIZE_POINT))
64 eRP=static_cast<RectPoint>(pSizeItem->GetValue());
65
66 switch( eRP )
67 {
68 case RectPoint::LT:
69 break;
70 case RectPoint::MT:
71 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
72 break;
73 case RectPoint::RT:
74 nPosX += rOriginalSize.Width - nSizX;
75 break;
76 case RectPoint::LM:
77 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
78 break;
79 case RectPoint::MM:
80 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
81 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
82 break;
83 case RectPoint::RM:
84 nPosX += rOriginalSize.Width - nSizX;
85 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
86 break;
87 case RectPoint::LB:
88 nPosY += rOriginalSize.Height - nSizY;
89 break;
90 case RectPoint::MB:
91 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
92 nPosY += rOriginalSize.Height - nSizY;
93 break;
94 case RectPoint::RB:
95 nPosX += rOriginalSize.Width - nSizX;
96 nPosY += rOriginalSize.Height - nSizY;
97 break;
98 default:
99 break;
100 }
101
102 rPosAndSize = awt::Rectangle(nPosX,nPosY,nSizX,nSizY);
103 }
104
105 void ChartController::executeDispatch_PositionAndSize(const ::css::uno::Sequence< ::css::beans::PropertyValue >* pArgs)
106 {
107 const OUString aCID( m_aSelection.getSelectedCID() );
108
109 if( aCID.isEmpty() )
110 return;
111
112 ObjectType eObjectType = ObjectIdentifier::getObjectType( aCID );
113
114 UndoGuard aUndoGuard(
115 ActionDescriptionProvider::createDescription(
116 ActionDescriptionProvider::ActionType::PosSize,
117 ObjectNameProvider::getName( eObjectType)),
118 m_xUndoManager );
119
120 try
121 {
122 SfxItemSet aItemSet = m_pDrawViewWrapper->getPositionAndSizeItemSetFromMarkedObject();
123 const SfxItemSet* pOutItemSet = nullptr;
124 if (!pArgs)
125 {
126 //prepare and open dialog
127 SdrView* pSdrView = m_pDrawViewWrapper.get();
128 bool bResizePossible = m_aSelection.isResizeableObjectSelected();
129
130 SolarMutexGuard aGuard;
131 SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
132 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSchTransformTabDialog(
133 GetChartFrame(), &aItemSet, pSdrView, bResizePossible));
134
135 if( pDlg->Execute() == RET_OK )
136 {
137 pOutItemSet = pDlg->GetOutputItemSet();
138 if (pOutItemSet)
139 aItemSet.Put(*pOutItemSet);//overwrite old values with new values (-> all items are set)
140 }
141 }
142 else
143 {
144 const SfxItemPool* pPool = aItemSet.GetPool();
145 if (!pPool)
146 return;
147
148 for (const auto& aProp: *pArgs)
149 {
150 sal_Int32 nValue = 0;
151 aProp.Value >>= nValue;
152 if (aProp.Name == "TransformPosX") {
153 aItemSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_POS_X, nValue));
154 }
155 else if (aProp.Name == "TransformPosY") {
156 aItemSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_POS_Y, nValue));
157 }
158 else if (aProp.Name == "TransformWidth") {
159 aItemSet.Put(SfxUInt32Item(SID_ATTR_TRANSFORM_WIDTH, static_cast<sal_uInt32>(nValue)));
160 }
161 else if (aProp.Name == "TransformHeight") {
162 aItemSet.Put(SfxUInt32Item(SID_ATTR_TRANSFORM_HEIGHT, static_cast<sal_uInt32>(nValue)));
163 }
164 }
165 }
166
167 if(pOutItemSet || pArgs)
168 {
169 awt::Rectangle aOldObjectRect;
170 if( m_xChartView )
171 aOldObjectRect = m_xChartView->getRectangleOfObject(aCID);
172
173 awt::Rectangle aNewObjectRect;
174 lcl_getPositionAndSizeFromItemSet( aItemSet, aNewObjectRect, ToSize(aOldObjectRect) );
175 awt::Size aPageSize( getChartModel()->getPageSize() );
176 awt::Rectangle aPageRect( 0,0,aPageSize.Width,aPageSize.Height );
177
178 bool bChanged = false;
179 if ( eObjectType == OBJECTTYPE_LEGEND )
180 {
181 bChanged = DiagramHelper::switchDiagramPositioningToExcludingPositioning(*getChartModel(), false , true);
182 }
183
184 bool bMoved = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID(), getChartModel()
185 , aNewObjectRect, aOldObjectRect, aPageRect );
186 if( bMoved || bChanged )
187 aUndoGuard.commit();
188 }
189 }
190 catch(const uno::Exception&)
191 {
192 TOOLS_WARN_EXCEPTION("chart2", "" );
193 }
194 }
195
196 } //namespace chart
197
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */