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 <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>
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
)
53 RectPoint eRP
= RectPoint::LT
;
55 const SfxPoolItem
* pPoolItem
=nullptr;
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();
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());
74 nPosX
+= ( rOriginalSize
.Width
- nSizX
) / 2;
77 nPosX
+= rOriginalSize
.Width
- nSizX
;
80 nPosY
+= ( rOriginalSize
.Height
- nSizY
) / 2;
83 nPosX
+= ( rOriginalSize
.Width
- nSizX
) / 2;
84 nPosY
+= ( rOriginalSize
.Height
- nSizY
) / 2;
87 nPosX
+= rOriginalSize
.Width
- nSizX
;
88 nPosY
+= ( rOriginalSize
.Height
- nSizY
) / 2;
91 nPosY
+= rOriginalSize
.Height
- nSizY
;
94 nPosX
+= ( rOriginalSize
.Width
- nSizX
) / 2;
95 nPosY
+= rOriginalSize
.Height
- nSizY
;
98 nPosX
+= rOriginalSize
.Width
- nSizX
;
99 nPosY
+= rOriginalSize
.Height
- nSizY
;
105 rPosAndSize
= awt::Rectangle(nPosX
,nPosY
,nSizX
,nSizY
);
108 void ChartController::executeDispatch_PositionAndSize()
110 const OUString
aCID( m_aSelection
.getSelectedCID() );
115 awt::Size aSelectedSize
;
116 ExplicitValueProvider
* pProvider( ExplicitValueProvider::getExplicitValueProvider( m_xChartView
) );
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
)),
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();
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
)
169 catch(const uno::Exception
& e
)
171 SAL_WARN("chart2", "Exception caught. " << e
);
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */