merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / controller / main / ChartController_Position.cxx
blobf11efd3f4b5f0e53d528937cdd4deeece56e5a1e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChartController_Position.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "ChartController.hxx"
35 #include "macros.hxx"
36 #include "ChartWindow.hxx"
37 #include "DrawViewWrapper.hxx"
38 #include "PositionAndSizeHelper.hxx"
39 #include "ChartModelHelper.hxx"
40 #include "UndoGuard.hxx"
41 #include "Strings.hrc"
42 #include "ObjectNameProvider.hxx"
43 #include "chartview/ExplicitValueProvider.hxx"
44 #include "CommonConverters.hxx"
45 #include <svx/ActionDescriptionProvider.hxx>
47 // header for define RET_OK
48 #include <vcl/msgbox.hxx>
49 #include <svx/svxids.hrc>
50 #include <svx/rectenum.hxx>
51 #include <svtools/aeitem.hxx>
52 #include <svx/svxdlg.hxx>
53 #include <svx/dialogs.hrc>
54 #include <vcl/svapp.hxx>
55 #include <vos/mutex.hxx>
57 //.............................................................................
58 namespace chart
60 //.............................................................................
61 using namespace ::com::sun::star;
62 using namespace ::com::sun::star::chart2;
64 //-----------------------------------------------------------------------------
65 //-----------------------------------------------------------------------------
67 void lcl_getPositionAndSizeFromItemSet( const SfxItemSet& rItemSet, Rectangle& rPosAndSize, const awt::Size aOriginalSize )
69 long nPosX(0);
70 long nPosY(0);
71 long nSizX(0);
72 long nSizY(0);
74 RECT_POINT eRP = (RECT_POINT)RP_LT;
76 const SfxPoolItem* pPoolItem=NULL;
77 //read position
78 if (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_POS_X,TRUE,&pPoolItem))
79 nPosX=((const SfxInt32Item*)pPoolItem)->GetValue();
80 if (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_POS_Y,TRUE,&pPoolItem))
81 nPosY=((const SfxInt32Item*)pPoolItem)->GetValue();
82 //read size
83 if (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_WIDTH,TRUE,&pPoolItem))
84 nSizX=((const SfxUInt32Item*)pPoolItem)->GetValue();
85 if (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_HEIGHT,TRUE,&pPoolItem))
86 nSizY=((const SfxUInt32Item*)pPoolItem)->GetValue();
87 if (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_SIZE_POINT,TRUE,&pPoolItem))
88 eRP=(RECT_POINT)((const SfxAllEnumItem*)pPoolItem)->GetValue();
90 switch( eRP )
92 case RP_LT:
93 break;
94 case RP_MT:
95 nPosX += ( aOriginalSize.Width - nSizX ) / 2;
96 break;
97 case RP_RT:
98 nPosX += aOriginalSize.Width - nSizX;
99 break;
100 case RP_LM:
101 nPosY += ( aOriginalSize.Height - nSizY ) / 2;
102 break;
103 case RP_MM:
104 nPosX += ( aOriginalSize.Width - nSizX ) / 2;
105 nPosY += ( aOriginalSize.Height - nSizY ) / 2;
106 break;
107 case RP_RM:
108 nPosX += aOriginalSize.Width - nSizX;
109 nPosY += ( aOriginalSize.Height - nSizY ) / 2;
110 break;
111 case RP_LB:
112 nPosY += aOriginalSize.Height - nSizY;
113 break;
114 case RP_MB:
115 nPosX += ( aOriginalSize.Width - nSizX ) / 2;
116 nPosY += aOriginalSize.Height - nSizY;
117 break;
118 case RP_RB:
119 nPosX += aOriginalSize.Width - nSizX;
120 nPosY += aOriginalSize.Height - nSizY;
121 break;
122 default:
123 break;
126 rPosAndSize = Rectangle(Point(nPosX,nPosY),Size(nSizX,nSizY));
129 void SAL_CALL ChartController::executeDispatch_PositionAndSize()
131 const ::rtl::OUString aCID( m_aSelection.getSelectedCID() );
133 if( !aCID.getLength() )
134 return;
136 awt::Size aSelectedSize;
137 ExplicitValueProvider* pProvider( ExplicitValueProvider::getExplicitValueProvider( m_xChartView ) );
138 if( pProvider )
139 aSelectedSize = ToSize( ( pProvider->getRectangleOfObject( aCID ) ) );
141 UndoGuard aUndoGuard(
142 ActionDescriptionProvider::createDescription(
143 ActionDescriptionProvider::POS_SIZE,
144 ObjectNameProvider::getName( ObjectIdentifier::getObjectType( aCID ))),
145 m_xUndoManager, m_aModel->getModel() );
147 SfxAbstractTabDialog * pDlg = NULL;
150 SfxItemSet aItemSet = m_pDrawViewWrapper->getPositionAndSizeItemSetFromMarkedObject();
152 //prepare and open dialog
153 SdrView* pSdrView = m_pDrawViewWrapper;
154 bool bResizePossible = m_aSelection.isResizeableObjectSelected();
156 ::vos::OGuard aGuard( Application::GetSolarMutex());
157 SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
158 DBG_ASSERT( pFact, "No dialog factory" );
159 pDlg = pFact->CreateSchTransformTabDialog(
160 m_pChartWindow, &aItemSet, pSdrView, RID_SCH_TransformTabDLG_SVXPAGE_ANGLE, bResizePossible );
161 DBG_ASSERT( pDlg, "Couldn't create SchTransformTabDialog" );
164 if( pDlg->Execute() == RET_OK )
166 const SfxItemSet* pOutItemSet = pDlg->GetOutputItemSet();
167 if(pOutItemSet)
169 Rectangle aObjectRect;
170 aItemSet.Put(*pOutItemSet);//overwrite old values with new values (-> all items are set)
171 lcl_getPositionAndSizeFromItemSet( aItemSet, aObjectRect, aSelectedSize );
172 awt::Size aPageSize( ChartModelHelper::getPageSize( m_aModel->getModel() ) );
173 Rectangle aPageRect( 0,0,aPageSize.Width,aPageSize.Height );
175 bool bChanged = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID()
176 , m_aModel->getModel()
177 , awt::Rectangle(aObjectRect.getX(),aObjectRect.getY(),aObjectRect.getWidth(),aObjectRect.getHeight())
178 , awt::Rectangle(aPageRect.getX(),aPageRect.getY(),aPageRect.getWidth(),aPageRect.getHeight())
179 , m_xChartView );
180 if( bChanged )
181 aUndoGuard.commitAction();
184 delete pDlg;
186 catch( uno::Exception& e)
188 delete pDlg;
189 ASSERT_EXCEPTION( e );
193 //.............................................................................
194 } //namespace chart
195 //.............................................................................