tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / chart2 / source / controller / main / ChartController_Position.cxx
blobdf047d747afdaf8f0922ee11513a579402d5f611
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <ChartController.hxx>
22 #include <DrawViewWrapper.hxx>
23 #include <PositionAndSizeHelper.hxx>
24 #include <ChartModel.hxx>
25 #include <ChartModelHelper.hxx>
26 #include <ChartView.hxx>
27 #include "UndoGuard.hxx"
28 #include <ObjectNameProvider.hxx>
29 #include <DiagramHelper.hxx>
30 #include <CommonConverters.hxx>
31 #include <svx/ActionDescriptionProvider.hxx>
33 #include <svx/svxids.hrc>
34 #include <svx/rectenum.hxx>
35 #include <svl/intitem.hxx>
36 #include <svx/svxdlg.hxx>
37 #include <comphelper/diagnose_ex.hxx>
38 #include <vcl/svapp.hxx>
39 #include <memory>
41 namespace chart
43 using namespace ::com::sun::star;
45 static void lcl_getPositionAndSizeFromItemSet( const SfxItemSet& rItemSet, awt::Rectangle& rPosAndSize, const awt::Size& rOriginalSize )
47 tools::Long nPosX(0);
48 tools::Long nPosY(0);
49 tools::Long nSizX(0);
50 tools::Long nSizY(0);
52 RectPoint eRP = RectPoint::LT;
54 //read position
55 if (const SfxInt32Item* pPosXItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_POS_X))
56 nPosX = pPosXItem->GetValue();
57 if (const SfxInt32Item* pPosYItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_POS_Y))
58 nPosY = pPosYItem->GetValue();
59 //read size
60 if (const SfxUInt32Item* pWidthItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_WIDTH))
61 nSizX = pWidthItem->GetValue();
62 if (const SfxUInt32Item* pHeightItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_HEIGHT))
63 nSizY = pHeightItem->GetValue();
64 if (const SfxUInt16Item* pSizeItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_SIZE_POINT))
65 eRP=static_cast<RectPoint>(pSizeItem->GetValue());
67 switch( eRP )
69 case RectPoint::LT:
70 break;
71 case RectPoint::MT:
72 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
73 break;
74 case RectPoint::RT:
75 nPosX += rOriginalSize.Width - nSizX;
76 break;
77 case RectPoint::LM:
78 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
79 break;
80 case RectPoint::MM:
81 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
82 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
83 break;
84 case RectPoint::RM:
85 nPosX += rOriginalSize.Width - nSizX;
86 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
87 break;
88 case RectPoint::LB:
89 nPosY += rOriginalSize.Height - nSizY;
90 break;
91 case RectPoint::MB:
92 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
93 nPosY += rOriginalSize.Height - nSizY;
94 break;
95 case RectPoint::RB:
96 nPosX += rOriginalSize.Width - nSizX;
97 nPosY += rOriginalSize.Height - nSizY;
98 break;
99 default:
100 break;
103 rPosAndSize = awt::Rectangle(nPosX,nPosY,nSizX,nSizY);
106 void ChartController::executeDispatch_PositionAndSize(const ::css::uno::Sequence< ::css::beans::PropertyValue >* pArgs)
108 const OUString aCID( m_aSelection.getSelectedCID() );
110 if( aCID.isEmpty() )
111 return;
113 ObjectType eObjectType = ObjectIdentifier::getObjectType( aCID );
115 UndoGuard aUndoGuard(
116 ActionDescriptionProvider::createDescription(
117 ActionDescriptionProvider::ActionType::PosSize,
118 ObjectNameProvider::getName( eObjectType)),
119 m_xUndoManager );
123 SfxItemSet aItemSet = m_pDrawViewWrapper->getPositionAndSizeItemSetFromMarkedObject();
124 const SfxItemSet* pOutItemSet = nullptr;
125 if (!pArgs)
127 //prepare and open dialog
128 SdrView* pSdrView = m_pDrawViewWrapper.get();
129 bool bResizePossible = m_aSelection.isResizeableObjectSelected();
131 SolarMutexGuard aGuard;
132 SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
133 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSchTransformTabDialog(
134 GetChartFrame(), &aItemSet, pSdrView, bResizePossible));
136 if( pDlg->Execute() == RET_OK )
138 pOutItemSet = pDlg->GetOutputItemSet();
139 if (pOutItemSet)
140 aItemSet.Put(*pOutItemSet);//overwrite old values with new values (-> all items are set)
143 else
145 const SfxItemPool* pPool = aItemSet.GetPool();
146 if (!pPool)
147 return;
149 for (const auto& aProp: *pArgs)
151 sal_Int32 nValue = 0;
152 aProp.Value >>= nValue;
153 if (aProp.Name == "TransformPosX") {
154 aItemSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_POS_X, nValue));
156 else if (aProp.Name == "TransformPosY") {
157 aItemSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_POS_Y, nValue));
159 else if (aProp.Name == "TransformWidth") {
160 aItemSet.Put(SfxUInt32Item(SID_ATTR_TRANSFORM_WIDTH, static_cast<sal_uInt32>(nValue)));
162 else if (aProp.Name == "TransformHeight") {
163 aItemSet.Put(SfxUInt32Item(SID_ATTR_TRANSFORM_HEIGHT, static_cast<sal_uInt32>(nValue)));
168 if(pOutItemSet || pArgs)
170 awt::Rectangle aOldObjectRect;
171 if( m_xChartView )
172 aOldObjectRect = m_xChartView->getRectangleOfObject(aCID);
174 awt::Rectangle aNewObjectRect;
175 lcl_getPositionAndSizeFromItemSet( aItemSet, aNewObjectRect, ToSize(aOldObjectRect) );
176 awt::Size aPageSize( ChartModelHelper::getPageSize( getChartModel() ) );
177 awt::Rectangle aPageRect( 0,0,aPageSize.Width,aPageSize.Height );
179 bool bChanged = false;
180 if ( eObjectType == OBJECTTYPE_LEGEND )
182 bChanged = DiagramHelper::switchDiagramPositioningToExcludingPositioning(*getChartModel(), false , true);
185 bool bMoved = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID(), getChartModel()
186 , aNewObjectRect, aOldObjectRect, aPageRect );
187 if( bMoved || bChanged )
188 aUndoGuard.commit();
191 catch(const uno::Exception&)
193 TOOLS_WARN_EXCEPTION("chart2", "" );
197 } //namespace chart
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */