1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChartController_Position.cxx,v $
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"
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 //.............................................................................
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
)
74 RECT_POINT eRP
= (RECT_POINT
)RP_LT
;
76 const SfxPoolItem
* pPoolItem
=NULL
;
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();
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();
95 nPosX
+= ( aOriginalSize
.Width
- nSizX
) / 2;
98 nPosX
+= aOriginalSize
.Width
- nSizX
;
101 nPosY
+= ( aOriginalSize
.Height
- nSizY
) / 2;
104 nPosX
+= ( aOriginalSize
.Width
- nSizX
) / 2;
105 nPosY
+= ( aOriginalSize
.Height
- nSizY
) / 2;
108 nPosX
+= aOriginalSize
.Width
- nSizX
;
109 nPosY
+= ( aOriginalSize
.Height
- nSizY
) / 2;
112 nPosY
+= aOriginalSize
.Height
- nSizY
;
115 nPosX
+= ( aOriginalSize
.Width
- nSizX
) / 2;
116 nPosY
+= aOriginalSize
.Height
- nSizY
;
119 nPosX
+= aOriginalSize
.Width
- nSizX
;
120 nPosY
+= aOriginalSize
.Height
- nSizY
;
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() )
136 awt::Size aSelectedSize
;
137 ExplicitValueProvider
* pProvider( ExplicitValueProvider::getExplicitValueProvider( m_xChartView
) );
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();
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())
181 aUndoGuard
.commitAction();
186 catch( uno::Exception
& e
)
189 ASSERT_EXCEPTION( e
);
193 //.............................................................................
195 //.............................................................................