LibreOffice Module chart2 (master) 1
ChartController_Position.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <ChartController.hxx>
21
22#include <DrawViewWrapper.hxx>
24#include <ChartModel.hxx>
25#include <ChartModelHelper.hxx>
26#include <ChartView.hxx>
27#include "UndoGuard.hxx"
29#include <DiagramHelper.hxx>
31#include <CommonConverters.hxx>
33
35#include <svx/svxids.hrc>
36#include <svx/rectenum.hxx>
37#include <svl/intitem.hxx>
38#include <svx/svxdlg.hxx>
40#include <vcl/svapp.hxx>
41#include <memory>
42
43namespace chart
44{
45using namespace ::com::sun::star;
46using namespace ::com::sun::star::chart2;
47
48static void lcl_getPositionAndSizeFromItemSet( const SfxItemSet& rItemSet, awt::Rectangle& rPosAndSize, const awt::Size& rOriginalSize )
49{
50 tools::Long nPosX(0);
51 tools::Long nPosY(0);
52 tools::Long nSizX(0);
53 tools::Long nSizY(0);
54
55 RectPoint eRP = RectPoint::LT;
56
57 //read position
58 if (const SfxInt32Item* pPosXItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_POS_X))
59 nPosX = pPosXItem->GetValue();
60 if (const SfxInt32Item* pPosYItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_POS_Y))
61 nPosY = pPosYItem->GetValue();
62 //read size
63 if (const SfxUInt32Item* pWidthItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_WIDTH))
64 nSizX = pWidthItem->GetValue();
65 if (const SfxUInt32Item* pHeightItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_HEIGHT))
66 nSizY = pHeightItem->GetValue();
67 if (const SfxUInt16Item* pSizeItem = rItemSet.GetItemIfSet(SID_ATTR_TRANSFORM_SIZE_POINT))
68 eRP=static_cast<RectPoint>(pSizeItem->GetValue());
69
70 switch( eRP )
71 {
72 case RectPoint::LT:
73 break;
74 case RectPoint::MT:
75 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
76 break;
77 case RectPoint::RT:
78 nPosX += rOriginalSize.Width - nSizX;
79 break;
80 case RectPoint::LM:
81 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
82 break;
83 case RectPoint::MM:
84 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
85 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
86 break;
87 case RectPoint::RM:
88 nPosX += rOriginalSize.Width - nSizX;
89 nPosY += ( rOriginalSize.Height - nSizY ) / 2;
90 break;
91 case RectPoint::LB:
92 nPosY += rOriginalSize.Height - nSizY;
93 break;
94 case RectPoint::MB:
95 nPosX += ( rOriginalSize.Width - nSizX ) / 2;
96 nPosY += rOriginalSize.Height - nSizY;
97 break;
98 case RectPoint::RB:
99 nPosX += rOriginalSize.Width - nSizX;
100 nPosY += rOriginalSize.Height - nSizY;
101 break;
102 default:
103 break;
104 }
105
106 rPosAndSize = awt::Rectangle(nPosX,nPosY,nSizX,nSizY);
107}
108
109void ChartController::executeDispatch_PositionAndSize(const ::css::uno::Sequence< ::css::beans::PropertyValue >* pArgs)
110{
111 const OUString aCID( m_aSelection.getSelectedCID() );
112
113 if( aCID.isEmpty() )
114 return;
115
116 ObjectType eObjectType = ObjectIdentifier::getObjectType( aCID );
117
118 UndoGuard aUndoGuard(
121 ObjectNameProvider::getName( eObjectType)),
123
124 try
125 {
126 SfxItemSet aItemSet = m_pDrawViewWrapper->getPositionAndSizeItemSetFromMarkedObject();
127 const SfxItemSet* pOutItemSet = nullptr;
128 if (!pArgs)
129 {
130 //prepare and open dialog
131 SdrView* pSdrView = m_pDrawViewWrapper.get();
132 bool bResizePossible = m_aSelection.isResizeableObjectSelected();
133
134 SolarMutexGuard aGuard;
137 GetChartFrame(), &aItemSet, pSdrView, bResizePossible));
138
139 if( pDlg->Execute() == RET_OK )
140 {
141 pOutItemSet = pDlg->GetOutputItemSet();
142 if (pOutItemSet)
143 aItemSet.Put(*pOutItemSet);//overwrite old values with new values (-> all items are set)
144 }
145 }
146 else
147 {
148 const SfxItemPool* pPool = aItemSet.GetPool();
149 if (!pPool)
150 return;
151
152 for (const auto& aProp: *pArgs)
153 {
154 sal_Int32 nValue = 0;
155 aProp.Value >>= nValue;
156 if (aProp.Name == "TransformPosX") {
157 aItemSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_POS_X, nValue));
158 }
159 else if (aProp.Name == "TransformPosY") {
160 aItemSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_POS_Y, nValue));
161 }
162 else if (aProp.Name == "TransformWidth") {
163 aItemSet.Put(SfxUInt32Item(SID_ATTR_TRANSFORM_WIDTH, static_cast<sal_uInt32>(nValue)));
164 }
165 else if (aProp.Name == "TransformHeight") {
166 aItemSet.Put(SfxUInt32Item(SID_ATTR_TRANSFORM_HEIGHT, static_cast<sal_uInt32>(nValue)));
167 }
168 }
169 }
170
171 if(pOutItemSet || pArgs)
172 {
173 awt::Rectangle aOldObjectRect;
174 if( m_xChartView )
175 aOldObjectRect = m_xChartView->getRectangleOfObject(aCID);
176
177 awt::Rectangle aNewObjectRect;
178 lcl_getPositionAndSizeFromItemSet( aItemSet, aNewObjectRect, ToSize(aOldObjectRect) );
179 awt::Size aPageSize( ChartModelHelper::getPageSize( getChartModel() ) );
180 awt::Rectangle aPageRect( 0,0,aPageSize.Width,aPageSize.Height );
181
182 bool bChanged = false;
183 if ( eObjectType == OBJECTTYPE_LEGEND )
184 {
186 }
187
189 , aNewObjectRect, aOldObjectRect, aPageRect );
190 if( bMoved || bChanged )
191 aUndoGuard.commit();
192 }
193 }
194 catch(const uno::Exception&)
195 {
196 TOOLS_WARN_EXCEPTION("chart2", "" );
197 }
198}
199
200} //namespace chart
201
202/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static OUString createDescription(ActionType eActionType, std::u16string_view rObjectName)
SfxItemPool * GetPool() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual VclPtr< SfxAbstractTabDialog > CreateSchTransformTabDialog(weld::Window *pParent, const SfxItemSet *pAttr, const SdrView *pSdrView, bool bSizeTabPage)=0
static SvxAbstractDialogFactory * Create()
rtl::Reference<::chart::ChartModel > getChartModel()
std::unique_ptr< DrawViewWrapper > m_pDrawViewWrapper
css::uno::Reference< css::document::XUndoManager > m_xUndoManager
rtl::Reference<::chart::ChartView > m_xChartView
weld::Window * GetChartFrame()
void executeDispatch_PositionAndSize(const ::css::uno::Sequence< ::css::beans::PropertyValue > *pArgs=nullptr)
static css::awt::Size getPageSize(const rtl::Reference<::chart::ChartModel > &xModel)
static bool switchDiagramPositioningToExcludingPositioning(ChartModel &rModel, bool bResetModifiedState, bool bConvertAlsoFromAutoPositioning)
ObjectType getObjectType() const
static OUString getName(ObjectType eObjectType, bool bPlural=false)
static bool moveObject(ObjectType eObjectType, const css::uno::Reference< css::beans::XPropertySet > &xObjectProp, const css::awt::Rectangle &rNewPositionAndSize, const css::awt::Rectangle &rOldPositionAndSize, const css::awt::Rectangle &rPageRectangle)
OUString const & getSelectedCID() const
bool isResizeableObjectSelected() const
A guard which does nothing, unless you explicitly call commitAction.
Definition: UndoGuard.hxx:37
#define TOOLS_WARN_EXCEPTION(area, stream)
sal_Int16 nValue
OOO_DLLPUBLIC_CHARTTOOLS css::awt::Size ToSize(const css::awt::Rectangle &rRectangle)
awt::Rect --> awt::Size (2D)
static void lcl_getPositionAndSizeFromItemSet(const SfxItemSet &rItemSet, awt::Rectangle &rPosAndSize, const awt::Size &rOriginalSize)
long Long
RectPoint
RET_OK