vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / chart2 / source / controller / main / ChartController_Position.cxx
blob66884dfb2fa8173c9ff987117446de9e1991d19f
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 <ChartModel.hxx>
26 #include <ChartModelHelper.hxx>
27 #include "UndoGuard.hxx"
28 #include <ObjectNameProvider.hxx>
29 #include <DiagramHelper.hxx>
30 #include <chartview/ExplicitValueProvider.hxx>
31 #include <CommonConverters.hxx>
32 #include <svx/ActionDescriptionProvider.hxx>
34 #include <comphelper/servicehelper.hxx>
35 #include <sal/log.hxx>
36 #include <svx/svxids.hrc>
37 #include <svx/rectenum.hxx>
38 #include <svl/aeitem.hxx>
39 #include <svl/intitem.hxx>
40 #include <svx/svxdlg.hxx>
41 #include <tools/diagnose_ex.h>
42 #include <vcl/svapp.hxx>
43 #include <memory>
45 namespace chart
47 using namespace ::com::sun::star;
48 using namespace ::com::sun::star::chart2;
50 static void lcl_getPositionAndSizeFromItemSet( const SfxItemSet& rItemSet, awt::Rectangle& rPosAndSize, const awt::Size& rOriginalSize )
52 long nPosX(0);
53 long nPosY(0);
54 long nSizX(0);
55 long nSizY(0);
57 RectPoint eRP = RectPoint::LT;
59 const SfxPoolItem* pPoolItem=nullptr;
60 //read position
61 if (rItemSet.GetItemState(SID_ATTR_TRANSFORM_POS_X,true,&pPoolItem)==SfxItemState::SET)
62 nPosX= static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
63 if (rItemSet.GetItemState(SID_ATTR_TRANSFORM_POS_Y,true,&pPoolItem)==SfxItemState::SET)
64 nPosY=static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
65 //read size
66 if (rItemSet.GetItemState(SID_ATTR_TRANSFORM_WIDTH,true,&pPoolItem)==SfxItemState::SET)
67 nSizX=static_cast<const SfxUInt32Item*>(pPoolItem)->GetValue();
68 if (rItemSet.GetItemState(SID_ATTR_TRANSFORM_HEIGHT,true,&pPoolItem)==SfxItemState::SET)
69 nSizY=static_cast<const SfxUInt32Item*>(pPoolItem)->GetValue();
70 if (rItemSet.GetItemState(SID_ATTR_TRANSFORM_SIZE_POINT,true,&pPoolItem)==SfxItemState::SET)
71 eRP=static_cast<RectPoint>(static_cast<const SfxUInt16Item*>(pPoolItem)->GetValue());
73 switch( eRP )
75 case RectPoint::LT:
76 break;
77 case RectPoint::MT:
78 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
79 break;
80 case RectPoint::RT:
81 nPosX += rOriginalSize.Width - nSizX;
82 break;
83 case RectPoint::LM:
84 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
85 break;
86 case RectPoint::MM:
87 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
88 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
89 break;
90 case RectPoint::RM:
91 nPosX += rOriginalSize.Width - nSizX;
92 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
93 break;
94 case RectPoint::LB:
95 nPosY += rOriginalSize.Height - nSizY;
96 break;
97 case RectPoint::MB:
98 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
99 nPosY += rOriginalSize.Height - nSizY;
100 break;
101 case RectPoint::RB:
102 nPosX += rOriginalSize.Width - nSizX;
103 nPosY += rOriginalSize.Height - nSizY;
104 break;
105 default:
106 break;
109 rPosAndSize = awt::Rectangle(nPosX,nPosY,nSizX,nSizY);
112 void ChartController::executeDispatch_PositionAndSize(const ::css::uno::Sequence< ::css::beans::PropertyValue >* pArgs)
114 const OUString aCID( m_aSelection.getSelectedCID() );
116 if( aCID.isEmpty() )
117 return;
119 awt::Size aSelectedSize;
120 ExplicitValueProvider* pProvider( comphelper::getUnoTunnelImplementation<ExplicitValueProvider>( m_xChartView ) );
121 if( pProvider )
122 aSelectedSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
124 ObjectType eObjectType = ObjectIdentifier::getObjectType( aCID );
126 UndoGuard aUndoGuard(
127 ActionDescriptionProvider::createDescription(
128 ActionDescriptionProvider::ActionType::PosSize,
129 ObjectNameProvider::getName( eObjectType)),
130 m_xUndoManager );
134 SfxItemSet aItemSet = m_pDrawViewWrapper->getPositionAndSizeItemSetFromMarkedObject();
135 const SfxItemSet* pOutItemSet = nullptr;
136 if (!pArgs)
138 //prepare and open dialog
139 SdrView* pSdrView = m_pDrawViewWrapper.get();
140 bool bResizePossible = m_aSelection.isResizeableObjectSelected();
142 SolarMutexGuard aGuard;
143 SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
144 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateSchTransformTabDialog(
145 GetChartFrame(), &aItemSet, pSdrView, bResizePossible));
147 if( pDlg->Execute() == RET_OK )
149 pOutItemSet = pDlg->GetOutputItemSet();
150 if (pOutItemSet)
151 aItemSet.Put(*pOutItemSet);//overwrite old values with new values (-> all items are set)
154 else
156 const SfxItemPool* pPool = aItemSet.GetPool();
157 if (!pPool)
158 return;
160 sal_uInt16 nWhich;
161 for (const auto& aProp: *pArgs)
163 sal_Int32 nValue = 0;
164 aProp.Value >>= nValue;
165 if (aProp.Name == "TransformPosX") {
166 nWhich = pPool->GetWhich(SID_ATTR_TRANSFORM_POS_X);
167 aItemSet.Put(SfxInt32Item(nWhich, nValue));
169 else if (aProp.Name == "TransformPosY") {
170 nWhich = pPool->GetWhich(SID_ATTR_TRANSFORM_POS_Y);
171 aItemSet.Put(SfxInt32Item(nWhich, nValue));
173 else if (aProp.Name == "TransformWidth") {
174 nWhich = pPool->GetWhich(SID_ATTR_TRANSFORM_WIDTH);
175 aItemSet.Put(SfxUInt32Item(nWhich, static_cast<sal_uInt32>(nValue)));
177 else if (aProp.Name == "TransformHeight") {
178 nWhich = pPool->GetWhich(SID_ATTR_TRANSFORM_HEIGHT);
179 aItemSet.Put(SfxUInt32Item(nWhich, static_cast<sal_uInt32>(nValue)));
184 if(pOutItemSet || pArgs)
186 awt::Rectangle aObjectRect;
187 lcl_getPositionAndSizeFromItemSet( aItemSet, aObjectRect, aSelectedSize );
188 awt::Size aPageSize( ChartModelHelper::getPageSize( getModel() ) );
189 awt::Rectangle aPageRect( 0,0,aPageSize.Width,aPageSize.Height );
191 bool bChanged = false;
192 if ( eObjectType == OBJECTTYPE_LEGEND )
194 ChartModel& rModel = dynamic_cast<ChartModel&>(*getModel());
195 bChanged = DiagramHelper::switchDiagramPositioningToExcludingPositioning(rModel, false , true);
198 bool bMoved = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID(), getModel()
199 , aObjectRect, aPageRect );
200 if( bMoved || bChanged )
201 aUndoGuard.commit();
204 catch(const uno::Exception&)
206 TOOLS_WARN_EXCEPTION("chart2", "" );
210 } //namespace chart
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */