Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / source / controller / main / ChartController_Position.cxx
blob2304bb72cda062f02a2096e8ec6dbccfadb6f83a
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 <ChartWindow.hxx>
23 #include <DrawViewWrapper.hxx>
24 #include <PositionAndSizeHelper.hxx>
25 #include <ChartModelHelper.hxx>
26 #include "UndoGuard.hxx"
27 #include <ObjectNameProvider.hxx>
28 #include <DiagramHelper.hxx>
29 #include <chartview/ExplicitValueProvider.hxx>
30 #include <CommonConverters.hxx>
31 #include <svx/ActionDescriptionProvider.hxx>
33 #include <svx/svxids.hrc>
34 #include <svx/rectenum.hxx>
35 #include <svl/aeitem.hxx>
36 #include <svx/svxdlg.hxx>
37 #include <svx/dialogs.hrc>
38 #include <vcl/svapp.hxx>
39 #include <memory>
41 namespace chart
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::chart2;
46 void lcl_getPositionAndSizeFromItemSet( const SfxItemSet& rItemSet, awt::Rectangle& rPosAndSize, const awt::Size& rOriginalSize )
48 long nPosX(0);
49 long nPosY(0);
50 long nSizX(0);
51 long nSizY(0);
53 RectPoint eRP = RectPoint::LT;
55 const SfxPoolItem* pPoolItem=nullptr;
56 //read position
57 if (rItemSet.GetItemState(SID_ATTR_TRANSFORM_POS_X,true,&pPoolItem)==SfxItemState::SET)
58 nPosX= static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
59 if (rItemSet.GetItemState(SID_ATTR_TRANSFORM_POS_Y,true,&pPoolItem)==SfxItemState::SET)
60 nPosY=static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
61 //read size
62 if (rItemSet.GetItemState(SID_ATTR_TRANSFORM_WIDTH,true,&pPoolItem)==SfxItemState::SET)
63 nSizX=static_cast<const SfxUInt32Item*>(pPoolItem)->GetValue();
64 if (rItemSet.GetItemState(SID_ATTR_TRANSFORM_HEIGHT,true,&pPoolItem)==SfxItemState::SET)
65 nSizY=static_cast<const SfxUInt32Item*>(pPoolItem)->GetValue();
66 if (rItemSet.GetItemState(SID_ATTR_TRANSFORM_SIZE_POINT,true,&pPoolItem)==SfxItemState::SET)
67 eRP=static_cast<RectPoint>(static_cast<const SfxAllEnumItem*>(pPoolItem)->GetValue());
69 switch( eRP )
71 case RectPoint::LT:
72 break;
73 case RectPoint::MT:
74 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
75 break;
76 case RectPoint::RT:
77 nPosX += rOriginalSize.Width - nSizX;
78 break;
79 case RectPoint::LM:
80 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
81 break;
82 case RectPoint::MM:
83 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
84 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
85 break;
86 case RectPoint::RM:
87 nPosX += rOriginalSize.Width - nSizX;
88 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
89 break;
90 case RectPoint::LB:
91 nPosY += rOriginalSize.Height - nSizY;
92 break;
93 case RectPoint::MB:
94 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
95 nPosY += rOriginalSize.Height - nSizY;
96 break;
97 case RectPoint::RB:
98 nPosX += rOriginalSize.Width - nSizX;
99 nPosY += rOriginalSize.Height - nSizY;
100 break;
101 default:
102 break;
105 rPosAndSize = awt::Rectangle(nPosX,nPosY,nSizX,nSizY);
108 void ChartController::executeDispatch_PositionAndSize()
110 const OUString aCID( m_aSelection.getSelectedCID() );
112 if( aCID.isEmpty() )
113 return;
115 awt::Size aSelectedSize;
116 ExplicitValueProvider* pProvider( ExplicitValueProvider::getExplicitValueProvider( m_xChartView ) );
117 if( pProvider )
118 aSelectedSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
120 ObjectType eObjectType = ObjectIdentifier::getObjectType( aCID );
122 UndoGuard aUndoGuard(
123 ActionDescriptionProvider::createDescription(
124 ActionDescriptionProvider::ActionType::PosSize,
125 ObjectNameProvider::getName( eObjectType)),
126 m_xUndoManager );
130 SfxItemSet aItemSet = m_pDrawViewWrapper->getPositionAndSizeItemSetFromMarkedObject();
132 //prepare and open dialog
133 SdrView* pSdrView = m_pDrawViewWrapper;
134 bool bResizePossible = m_aSelection.isResizeableObjectSelected();
136 SolarMutexGuard aGuard;
137 SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
138 OSL_ENSURE( pFact, "No dialog factory" );
139 vcl::Window* pWin = GetChartWindow();
140 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSchTransformTabDialog(
141 pWin ? pWin->GetFrameWeld() : nullptr, &aItemSet, pSdrView, bResizePossible));
142 OSL_ENSURE( pDlg, "Couldn't create SchTransformTabDialog" );
144 if( pDlg->Execute() == RET_OK )
146 const SfxItemSet* pOutItemSet = pDlg->GetOutputItemSet();
147 if(pOutItemSet)
149 awt::Rectangle aObjectRect;
150 aItemSet.Put(*pOutItemSet);//overwrite old values with new values (-> all items are set)
151 lcl_getPositionAndSizeFromItemSet( aItemSet, aObjectRect, aSelectedSize );
152 awt::Size aPageSize( ChartModelHelper::getPageSize( getModel() ) );
153 awt::Rectangle aPageRect( 0,0,aPageSize.Width,aPageSize.Height );
155 bool bChanged = false;
156 if ( eObjectType == OBJECTTYPE_LEGEND )
158 ChartModel& rModel = dynamic_cast<ChartModel&>(*getModel().get());
159 bChanged = DiagramHelper::switchDiagramPositioningToExcludingPositioning(rModel, false , true);
162 bool bMoved = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID(), getModel()
163 , aObjectRect, aPageRect );
164 if( bMoved || bChanged )
165 aUndoGuard.commit();
169 catch(const uno::Exception& e)
171 SAL_WARN("chart2", "Exception caught. " << e );
175 } //namespace chart
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */