1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
)
57 RectPoint eRP
= RectPoint::LT
;
59 const SfxPoolItem
* pPoolItem
=nullptr;
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();
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());
78 nPosX
+= ( rOriginalSize
.Width
- nSizX
) / 2;
81 nPosX
+= rOriginalSize
.Width
- nSizX
;
84 nPosY
+= ( rOriginalSize
.Height
- nSizY
) / 2;
87 nPosX
+= ( rOriginalSize
.Width
- nSizX
) / 2;
88 nPosY
+= ( rOriginalSize
.Height
- nSizY
) / 2;
91 nPosX
+= rOriginalSize
.Width
- nSizX
;
92 nPosY
+= ( rOriginalSize
.Height
- nSizY
) / 2;
95 nPosY
+= rOriginalSize
.Height
- nSizY
;
98 nPosX
+= ( rOriginalSize
.Width
- nSizX
) / 2;
99 nPosY
+= rOriginalSize
.Height
- nSizY
;
102 nPosX
+= rOriginalSize
.Width
- nSizX
;
103 nPosY
+= rOriginalSize
.Height
- nSizY
;
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() );
119 awt::Size aSelectedSize
;
120 ExplicitValueProvider
* pProvider( comphelper::getUnoTunnelImplementation
<ExplicitValueProvider
>( m_xChartView
) );
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
)),
134 SfxItemSet aItemSet
= m_pDrawViewWrapper
->getPositionAndSizeItemSetFromMarkedObject();
135 const SfxItemSet
* pOutItemSet
= nullptr;
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();
151 aItemSet
.Put(*pOutItemSet
);//overwrite old values with new values (-> all items are set)
156 const SfxItemPool
* pPool
= aItemSet
.GetPool();
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
)
204 catch(const uno::Exception
&)
206 TOOLS_WARN_EXCEPTION("chart2", "" );
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */