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 <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>
43 using namespace ::com::sun::star
;
45 static void lcl_getPositionAndSizeFromItemSet( const SfxItemSet
& rItemSet
, awt::Rectangle
& rPosAndSize
, const awt::Size
& rOriginalSize
)
52 RectPoint eRP
= RectPoint::LT
;
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();
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());
72 nPosX
+= ( rOriginalSize
.Width
- nSizX
) / 2;
75 nPosX
+= rOriginalSize
.Width
- nSizX
;
78 nPosY
+= ( rOriginalSize
.Height
- nSizY
) / 2;
81 nPosX
+= ( rOriginalSize
.Width
- nSizX
) / 2;
82 nPosY
+= ( rOriginalSize
.Height
- nSizY
) / 2;
85 nPosX
+= rOriginalSize
.Width
- nSizX
;
86 nPosY
+= ( rOriginalSize
.Height
- nSizY
) / 2;
89 nPosY
+= rOriginalSize
.Height
- nSizY
;
92 nPosX
+= ( rOriginalSize
.Width
- nSizX
) / 2;
93 nPosY
+= rOriginalSize
.Height
- nSizY
;
96 nPosX
+= rOriginalSize
.Width
- nSizX
;
97 nPosY
+= rOriginalSize
.Height
- nSizY
;
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() );
113 ObjectType eObjectType
= ObjectIdentifier::getObjectType( aCID
);
115 UndoGuard
aUndoGuard(
116 ActionDescriptionProvider::createDescription(
117 ActionDescriptionProvider::ActionType::PosSize
,
118 ObjectNameProvider::getName( eObjectType
)),
123 SfxItemSet aItemSet
= m_pDrawViewWrapper
->getPositionAndSizeItemSetFromMarkedObject();
124 const SfxItemSet
* pOutItemSet
= nullptr;
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();
140 aItemSet
.Put(*pOutItemSet
);//overwrite old values with new values (-> all items are set)
145 const SfxItemPool
* pPool
= aItemSet
.GetPool();
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
;
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
)
191 catch(const uno::Exception
&)
193 TOOLS_WARN_EXCEPTION("chart2", "" );
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */