1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 #include "ChartController.hxx"
27 
28 #include "macros.hxx"
29 #include "ChartWindow.hxx"
30 #include "DrawViewWrapper.hxx"
31 #include "PositionAndSizeHelper.hxx"
32 #include "ChartModelHelper.hxx"
33 #include "UndoGuard.hxx"
34 #include "Strings.hrc"
35 #include "ObjectNameProvider.hxx"
36 #include "DiagramHelper.hxx"
37 #include "chartview/ExplicitValueProvider.hxx"
38 #include "CommonConverters.hxx"
39 #include <svx/ActionDescriptionProvider.hxx>
40 
41 // header for define RET_OK
42 #include <vcl/msgbox.hxx>
43 #include <svx/svxids.hrc>
44 #include <svx/rectenum.hxx>
45 #include <svl/aeitem.hxx>
46 #include <svx/svxdlg.hxx>
47 #include <svx/dialogs.hrc>
48 #include <vcl/svapp.hxx>
49 #include <vos/mutex.hxx>
50 
51 //.............................................................................
52 namespace chart
53 {
54 //.............................................................................
55 using namespace ::com::sun::star;
56 using namespace ::com::sun::star::chart2;
57 
58 //-----------------------------------------------------------------------------
59 //-----------------------------------------------------------------------------
60 
lcl_getPositionAndSizeFromItemSet(const SfxItemSet & rItemSet,awt::Rectangle & rPosAndSize,const awt::Size aOriginalSize)61 void lcl_getPositionAndSizeFromItemSet( const SfxItemSet& rItemSet, awt::Rectangle& rPosAndSize, const awt::Size aOriginalSize )
62 {
63     long nPosX(0);
64 	long nPosY(0);
65 	long nSizX(0);
66 	long nSizY(0);
67 
68     RECT_POINT eRP = (RECT_POINT)RP_LT;
69 
70     const SfxPoolItem* pPoolItem=NULL;
71     //read position
72     if (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_POS_X,sal_True,&pPoolItem))
73 		nPosX=((const SfxInt32Item*)pPoolItem)->GetValue();
74 	if (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_POS_Y,sal_True,&pPoolItem))
75 		nPosY=((const SfxInt32Item*)pPoolItem)->GetValue();
76 	//read size
77 	if (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_WIDTH,sal_True,&pPoolItem))
78 		nSizX=((const SfxUInt32Item*)pPoolItem)->GetValue();
79 	if (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_HEIGHT,sal_True,&pPoolItem))
80 		nSizY=((const SfxUInt32Item*)pPoolItem)->GetValue();
81     if (SFX_ITEM_SET==rItemSet.GetItemState(SID_ATTR_TRANSFORM_SIZE_POINT,sal_True,&pPoolItem))
82         eRP=(RECT_POINT)((const SfxAllEnumItem*)pPoolItem)->GetValue();
83 
84     switch( eRP )
85     {
86         case RP_LT:
87             break;
88         case RP_MT:
89             nPosX += ( aOriginalSize.Width - nSizX ) / 2;
90             break;
91         case RP_RT:
92             nPosX += aOriginalSize.Width - nSizX;
93             break;
94         case RP_LM:
95             nPosY += ( aOriginalSize.Height - nSizY ) / 2;
96             break;
97         case RP_MM:
98             nPosX += ( aOriginalSize.Width  - nSizX ) / 2;
99             nPosY += ( aOriginalSize.Height - nSizY ) / 2;
100             break;
101         case RP_RM:
102             nPosX += aOriginalSize.Width - nSizX;
103             nPosY += ( aOriginalSize.Height - nSizY ) / 2;
104             break;
105         case RP_LB:
106             nPosY += aOriginalSize.Height - nSizY;
107             break;
108         case RP_MB:
109             nPosX += ( aOriginalSize.Width - nSizX ) / 2;
110             nPosY += aOriginalSize.Height - nSizY;
111             break;
112         case RP_RB:
113             nPosX += aOriginalSize.Width - nSizX;
114             nPosY += aOriginalSize.Height - nSizY;
115             break;
116         default:
117             break;
118     }
119 
120     rPosAndSize = awt::Rectangle(nPosX,nPosY,nSizX,nSizY);
121 }
122 
executeDispatch_PositionAndSize()123 void SAL_CALL ChartController::executeDispatch_PositionAndSize()
124 {
125     const ::rtl::OUString aCID( m_aSelection.getSelectedCID() );
126 
127     if( aCID.isEmpty() )
128         return;
129 
130     awt::Size aSelectedSize;
131     ExplicitValueProvider* pProvider( ExplicitValueProvider::getExplicitValueProvider( m_xChartView ) );
132     if( pProvider )
133         aSelectedSize = ToSize( ( pProvider->getRectangleOfObject( aCID ) ) );
134 
135     ObjectType eObjectType = ObjectIdentifier::getObjectType( aCID );
136 
137     UndoGuard aUndoGuard(
138         ActionDescriptionProvider::createDescription(
139             ActionDescriptionProvider::POS_SIZE,
140             ObjectNameProvider::getName( eObjectType)),
141         m_xUndoManager );
142 
143     SfxAbstractTabDialog * pDlg = NULL;
144     try
145     {
146         SfxItemSet aItemSet = m_pDrawViewWrapper->getPositionAndSizeItemSetFromMarkedObject();
147 
148         //prepare and open dialog
149         SdrView* pSdrView = m_pDrawViewWrapper;
150         bool bResizePossible = m_aSelection.isResizeableObjectSelected();
151 
152         ::vos::OGuard aGuard( Application::GetSolarMutex());
153         SvxAbstractDialogFactory * pFact = SvxAbstractDialogFactory::Create();
154         DBG_ASSERT( pFact, "No dialog factory" );
155         pDlg = pFact->CreateSchTransformTabDialog(
156             m_pChartWindow, &aItemSet, pSdrView, RID_SCH_TransformTabDLG_SVXPAGE_ANGLE, bResizePossible );
157         DBG_ASSERT( pDlg, "Couldn't create SchTransformTabDialog" );
158 
159 
160         if( pDlg->Execute() == RET_OK )
161         {
162             const SfxItemSet* pOutItemSet = pDlg->GetOutputItemSet();
163             if(pOutItemSet)
164             {
165                 awt::Rectangle aObjectRect;
166                 aItemSet.Put(*pOutItemSet);//overwrite old values with new values (-> all items are set)
167                 lcl_getPositionAndSizeFromItemSet( aItemSet, aObjectRect, aSelectedSize );
168                 awt::Size aPageSize( ChartModelHelper::getPageSize( getModel() ) );
169                 awt::Rectangle aPageRect( 0,0,aPageSize.Width,aPageSize.Height );
170 
171                 bool bChanged = false;
172                 if ( eObjectType == OBJECTTYPE_LEGEND )
173                     bChanged = DiagramHelper::switchDiagramPositioningToExcludingPositioning( getModel(), false , true );
174 
175                 bool bMoved = PositionAndSizeHelper::moveObject( m_aSelection.getSelectedCID(), getModel()
176                             , aObjectRect, aPageRect );
177                 if( bMoved || bChanged )
178                     aUndoGuard.commit();
179             }
180         }
181         delete pDlg;
182     }
183     catch( uno::Exception& e)
184     {
185         delete pDlg;
186         ASSERT_EXCEPTION( e );
187     }
188 }
189 
190 //.............................................................................
191 } //namespace chart
192 //.............................................................................
193