1cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3cde9e8dcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4cde9e8dcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5cde9e8dcSAndrew Rist  * distributed with this work for additional information
6cde9e8dcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7cde9e8dcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8cde9e8dcSAndrew Rist  * "License"); you may not use this file except in compliance
9cde9e8dcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cde9e8dcSAndrew Rist  *
11cde9e8dcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cde9e8dcSAndrew Rist  *
13cde9e8dcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14cde9e8dcSAndrew Rist  * software distributed under the License is distributed on an
15cde9e8dcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16cde9e8dcSAndrew Rist  * KIND, either express or implied.  See the License for the
17cde9e8dcSAndrew Rist  * specific language governing permissions and limitations
18cde9e8dcSAndrew Rist  * under the License.
19cde9e8dcSAndrew Rist  *
20cde9e8dcSAndrew Rist  *************************************************************/
21cde9e8dcSAndrew Rist 
22cde9e8dcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir #include "ChartController.hxx"
27cdf0e10cSrcweir #include "servicenames.hxx"
28cdf0e10cSrcweir #include "ResId.hxx"
29cdf0e10cSrcweir #include "dlg_DataSource.hxx"
30cdf0e10cSrcweir #include "ChartModelHelper.hxx"
31cdf0e10cSrcweir #include "ControllerCommandDispatch.hxx"
32cdf0e10cSrcweir #include "Strings.hrc"
33cdf0e10cSrcweir #include "chartview/ExplicitValueProvider.hxx"
34cdf0e10cSrcweir #include "ChartViewHelper.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "ChartWindow.hxx"
37cdf0e10cSrcweir #include "chartview/DrawModelWrapper.hxx"
38cdf0e10cSrcweir #include "DrawViewWrapper.hxx"
39cdf0e10cSrcweir #include "ObjectIdentifier.hxx"
40cdf0e10cSrcweir #include "DiagramHelper.hxx"
41cdf0e10cSrcweir #include "ControllerLockGuard.hxx"
42cdf0e10cSrcweir #include "UndoGuard.hxx"
43cdf0e10cSrcweir #include "ChartDropTargetHelper.hxx"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include "macros.hxx"
46cdf0e10cSrcweir #include "dlg_CreationWizard.hxx"
47cdf0e10cSrcweir #include "dlg_ChartType.hxx"
48cdf0e10cSrcweir #include "AccessibleChartView.hxx"
49cdf0e10cSrcweir #include "DrawCommandDispatch.hxx"
50cdf0e10cSrcweir #include "ShapeController.hxx"
51cdf0e10cSrcweir #include "UndoActions.hxx"
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #include <comphelper/InlineContainer.hxx>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
56cdf0e10cSrcweir #include <com/sun/star/chart2/XChartDocument.hpp>
57cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataReceiver.hpp>
58cdf0e10cSrcweir #include <com/sun/star/frame/XLoadable.hpp>
59cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp>
60cdf0e10cSrcweir #include <com/sun/star/embed/XEmbeddedClient.hpp>
61cdf0e10cSrcweir #include <com/sun/star/util/XModeChangeBroadcaster.hpp>
62cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp>
63cdf0e10cSrcweir #include <com/sun/star/frame/LayoutManagerEvents.hpp>
64cdf0e10cSrcweir #include <com/sun/star/document/XUndoManagerSupplier.hpp>
65cdf0e10cSrcweir #include <com/sun/star/document/XUndoAction.hpp>
66cdf0e10cSrcweir 
67cdf0e10cSrcweir //-------
68cdf0e10cSrcweir // header for define RET_OK
69cdf0e10cSrcweir #include <vcl/msgbox.hxx>
70cdf0e10cSrcweir //-------
71cdf0e10cSrcweir 
72cdf0e10cSrcweir //-------
73cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
74cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
75cdf0e10cSrcweir #include <vcl/svapp.hxx>
76cdf0e10cSrcweir #include <vos/mutex.hxx>
77cdf0e10cSrcweir //-------
78cdf0e10cSrcweir #include <com/sun/star/frame/XLayoutManager.hpp>
79cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
80cdf0e10cSrcweir 
81cdf0e10cSrcweir // this is needed to properly destroy the auto_ptr to the AcceleratorExecute
82cdf0e10cSrcweir // object in the DTOR
83cdf0e10cSrcweir #include <svtools/acceleratorexecute.hxx>
84cdf0e10cSrcweir #include <svx/ActionDescriptionProvider.hxx>
85cdf0e10cSrcweir #include <tools/diagnose_ex.h>
86cdf0e10cSrcweir 
87cdf0e10cSrcweir // enable the following define to let the controller listen to model changes and
88cdf0e10cSrcweir // react on this by rebuilding the view
89cdf0e10cSrcweir #define TEST_ENABLE_MODIFY_LISTENER
90cdf0e10cSrcweir 
91cdf0e10cSrcweir /*
92cdf0e10cSrcweir #include <vcl/svapp.hxx>
93cdf0e10cSrcweir */
94cdf0e10cSrcweir 
95cdf0e10cSrcweir //.............................................................................
96cdf0e10cSrcweir namespace chart
97cdf0e10cSrcweir {
98cdf0e10cSrcweir //.............................................................................
99cdf0e10cSrcweir 
100cdf0e10cSrcweir using namespace ::com::sun::star;
101cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
102cdf0e10cSrcweir using namespace ::com::sun::star::chart2;
103cdf0e10cSrcweir using ::com::sun::star::uno::Any;
104cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
105cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
DBG_NAME(ChartController)106cdf0e10cSrcweir DBG_NAME(ChartController)
107cdf0e10cSrcweir //-----------------------------------------------------------------
108cdf0e10cSrcweir // ChartController Constructor and Destructor
109cdf0e10cSrcweir //-----------------------------------------------------------------
110cdf0e10cSrcweir 
111cdf0e10cSrcweir ChartController::ChartController(uno::Reference<uno::XComponentContext> const & xContext)
112cdf0e10cSrcweir 	: m_aLifeTimeManager( NULL )
113cdf0e10cSrcweir 	, m_bSuspended( sal_False )
114cdf0e10cSrcweir 	, m_bCanClose( sal_True )
115cdf0e10cSrcweir 	, m_xCC(xContext) //@todo is it allowed to hold this context??
116cdf0e10cSrcweir 	, m_xFrame( NULL )
117cdf0e10cSrcweir 	, m_aModelMutex()
118cdf0e10cSrcweir 	, m_aModel( NULL, m_aModelMutex )
119cdf0e10cSrcweir 	, m_pChartWindow( NULL )
120cdf0e10cSrcweir 	, m_xViewWindow()
121cdf0e10cSrcweir     , m_xChartView()
122cdf0e10cSrcweir     , m_pDrawModelWrapper()
123cdf0e10cSrcweir     , m_pDrawViewWrapper(NULL)
124cdf0e10cSrcweir     , m_eDragMode(SDRDRAG_MOVE)
125cdf0e10cSrcweir     , m_bWaitingForDoubleClick(false)
126cdf0e10cSrcweir     , m_bWaitingForMouseUp(false)
127cdf0e10cSrcweir     , m_bConnectingToView(false)
128cdf0e10cSrcweir     , m_xUndoManager( 0 )
129cdf0e10cSrcweir     , m_aDispatchContainer( m_xCC, this )
130cdf0e10cSrcweir     , m_eDrawMode( CHARTDRAW_SELECT )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     DBG_CTOR(ChartController,NULL);
133cdf0e10cSrcweir     m_aDoubleClickTimer.SetTimeoutHdl( LINK( this, ChartController, DoubleClickWaitingHdl ) );
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
~ChartController()136cdf0e10cSrcweir ChartController::~ChartController()
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     DBG_DTOR(ChartController,NULL);
139cdf0e10cSrcweir     stopDoubleClickWaiting();
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir //-----------------------------------------------------------------
143cdf0e10cSrcweir 
RefCountable()144cdf0e10cSrcweir ChartController::RefCountable::RefCountable() : m_nRefCount(0)
145cdf0e10cSrcweir {
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
~RefCountable()148cdf0e10cSrcweir ChartController::RefCountable::~RefCountable()
149cdf0e10cSrcweir {
150cdf0e10cSrcweir }
acquire()151cdf0e10cSrcweir void ChartController::RefCountable::acquire()
152cdf0e10cSrcweir {
153cdf0e10cSrcweir 	m_nRefCount++;
154cdf0e10cSrcweir }
release()155cdf0e10cSrcweir void ChartController::RefCountable::release()
156cdf0e10cSrcweir {
157cdf0e10cSrcweir 	m_nRefCount--;
158cdf0e10cSrcweir 	if(!m_nRefCount)
159cdf0e10cSrcweir 		delete this;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir //-----------------------------------------------------------------
163cdf0e10cSrcweir 
TheModel(const uno::Reference<frame::XModel> & xModel)164cdf0e10cSrcweir ChartController::TheModel::TheModel( const uno::Reference< frame::XModel > & xModel )
165cdf0e10cSrcweir 	: m_xModel( xModel )
166cdf0e10cSrcweir 	, m_xCloseable( NULL )
167cdf0e10cSrcweir 	, m_bOwnership( sal_True )
168cdf0e10cSrcweir 	, m_bOwnershipIsWellKnown( sal_False )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir 	m_xCloseable =
171cdf0e10cSrcweir 		uno::Reference< util::XCloseable >( xModel, uno::UNO_QUERY );
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
~TheModel()174cdf0e10cSrcweir ChartController::TheModel::~TheModel()
175cdf0e10cSrcweir {
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
SetOwnerShip(sal_Bool bGetsOwnership)178cdf0e10cSrcweir void ChartController::TheModel::SetOwnerShip( sal_Bool bGetsOwnership )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir 	m_bOwnership				= bGetsOwnership;
181cdf0e10cSrcweir 	m_bOwnershipIsWellKnown	= sal_True;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
addListener(ChartController * pController)184cdf0e10cSrcweir void ChartController::TheModel::addListener( ChartController* pController )
185cdf0e10cSrcweir {
186cdf0e10cSrcweir 	if(m_xCloseable.is())
187cdf0e10cSrcweir 	{
188cdf0e10cSrcweir 		//if you need to be able to veto against the destruction of the model
189cdf0e10cSrcweir 		// you must add as a close listener
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 		//otherwise you 'can' add as closelistener or 'must' add as dispose event listener
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 		m_xCloseable->addCloseListener(
194cdf0e10cSrcweir 			static_cast<util::XCloseListener*>(pController) );
195cdf0e10cSrcweir 	}
196cdf0e10cSrcweir 	else if( m_xModel.is() )
197cdf0e10cSrcweir 	{
198cdf0e10cSrcweir 		//we need to add as dispose event listener
199cdf0e10cSrcweir 		m_xModel->addEventListener(
200cdf0e10cSrcweir 			static_cast<util::XCloseListener*>(pController) );
201cdf0e10cSrcweir 	}
202cdf0e10cSrcweir 
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
removeListener(ChartController * pController)205cdf0e10cSrcweir void ChartController::TheModel::removeListener(  ChartController* pController )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir 	if(m_xCloseable.is())
208cdf0e10cSrcweir 		m_xCloseable->removeCloseListener(
209cdf0e10cSrcweir 			static_cast<util::XCloseListener*>(pController) );
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	else if( m_xModel.is() )
212cdf0e10cSrcweir 		m_xModel->removeEventListener(
213cdf0e10cSrcweir 			static_cast<util::XCloseListener*>(pController) );
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
tryTermination()216cdf0e10cSrcweir void ChartController::TheModel::tryTermination()
217cdf0e10cSrcweir {
218cdf0e10cSrcweir 	if(!m_bOwnership)
219cdf0e10cSrcweir 		return;
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 	try
222cdf0e10cSrcweir 	{
223cdf0e10cSrcweir 		if(m_xCloseable.is())
224cdf0e10cSrcweir 		{
225cdf0e10cSrcweir 			try
226cdf0e10cSrcweir 			{
227cdf0e10cSrcweir 				//@todo ? are we allowed to use sal_True here if we have the explicit ownership?
228cdf0e10cSrcweir 				//I think yes, because there might be other closelistners later in the list which might be interested still
229cdf0e10cSrcweir 				//but make sure that we do not throw the CloseVetoException here ourselfs
230cdf0e10cSrcweir 				//so stop listening before trying to terminate or check the source of queryclosing event
231cdf0e10cSrcweir 				m_xCloseable->close(sal_True);
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 				m_bOwnership				= false;
234cdf0e10cSrcweir 				m_bOwnershipIsWellKnown	= sal_True;
235cdf0e10cSrcweir 			}
236cdf0e10cSrcweir 			catch( util::CloseVetoException& )
237cdf0e10cSrcweir 			{
238cdf0e10cSrcweir 				//since we have indicated to give up the ownership with paramter true in close call
239cdf0e10cSrcweir 				//the one who has thrown the CloseVetoException is the new owner
240cdf0e10cSrcweir 
241cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2
242cdf0e10cSrcweir 				OSL_ENSURE( !m_bOwnership,
243cdf0e10cSrcweir 					"INFO: a well known owner has catched a CloseVetoException after calling close(true)" );
244cdf0e10cSrcweir #endif
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 				m_bOwnership				= false;
247cdf0e10cSrcweir 				m_bOwnershipIsWellKnown	= sal_True;
248cdf0e10cSrcweir 				return;
249cdf0e10cSrcweir 			}
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 		}
252cdf0e10cSrcweir 		else if( m_xModel.is() )
253cdf0e10cSrcweir 		{
254cdf0e10cSrcweir 			//@todo correct??
255cdf0e10cSrcweir 			m_xModel->dispose();
256cdf0e10cSrcweir 			return;
257cdf0e10cSrcweir 		}
258cdf0e10cSrcweir 	}
259cdf0e10cSrcweir 	catch( uno::Exception& ex)
260cdf0e10cSrcweir 	{
261cdf0e10cSrcweir         (void)(ex); // no warning in non-debug builds
262cdf0e10cSrcweir 		OSL_ENSURE( sal_False, ( rtl::OString("Termination of model failed: ")
263cdf0e10cSrcweir 			+ rtl::OUStringToOString( ex.Message, RTL_TEXTENCODING_ASCII_US ) ).getStr() );
264cdf0e10cSrcweir 	}
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir //-----------------------------------------------------------------
268cdf0e10cSrcweir 
TheModelRef(TheModel * pTheModel,::osl::Mutex & rMutex)269cdf0e10cSrcweir ChartController::TheModelRef::TheModelRef( TheModel* pTheModel, ::osl::Mutex& rMutex )
270cdf0e10cSrcweir 		: m_pTheModel(pTheModel), m_rModelMutex(rMutex)
271cdf0e10cSrcweir {
272cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( m_rModelMutex );
273cdf0e10cSrcweir 	if(m_pTheModel)
274cdf0e10cSrcweir 		m_pTheModel->acquire();
275cdf0e10cSrcweir }
TheModelRef(const TheModelRef & rTheModel,::osl::Mutex & rMutex)276cdf0e10cSrcweir ChartController::TheModelRef::TheModelRef( const TheModelRef& rTheModel, ::osl::Mutex& rMutex )
277cdf0e10cSrcweir 		: m_rModelMutex(rMutex)
278cdf0e10cSrcweir {
279cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( m_rModelMutex );
280cdf0e10cSrcweir 	m_pTheModel=rTheModel.operator->();
281cdf0e10cSrcweir 	if(m_pTheModel)
282cdf0e10cSrcweir 		m_pTheModel->acquire();
283cdf0e10cSrcweir }
operator =(TheModel * pTheModel)284cdf0e10cSrcweir ChartController::TheModelRef& ChartController::TheModelRef::operator=(TheModel* pTheModel)
285cdf0e10cSrcweir {
286cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( m_rModelMutex );
287cdf0e10cSrcweir 	if(m_pTheModel==pTheModel)
288cdf0e10cSrcweir 		return *this;
289cdf0e10cSrcweir 	if(m_pTheModel)
290cdf0e10cSrcweir 		m_pTheModel->release();
291cdf0e10cSrcweir 	m_pTheModel=pTheModel;
292cdf0e10cSrcweir 	if(m_pTheModel)
293cdf0e10cSrcweir 		m_pTheModel->acquire();
294cdf0e10cSrcweir 	return *this;
295cdf0e10cSrcweir }
operator =(const TheModelRef & rTheModel)296cdf0e10cSrcweir ChartController::TheModelRef& ChartController::TheModelRef::operator=(const TheModelRef& rTheModel)
297cdf0e10cSrcweir {
298cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( m_rModelMutex );
299cdf0e10cSrcweir 	TheModel* pNew=rTheModel.operator->();
300cdf0e10cSrcweir 	if(m_pTheModel==pNew)
301cdf0e10cSrcweir 		return *this;
302cdf0e10cSrcweir 	if(m_pTheModel)
303cdf0e10cSrcweir 		m_pTheModel->release();
304cdf0e10cSrcweir 	m_pTheModel=pNew;
305cdf0e10cSrcweir 	if(m_pTheModel)
306cdf0e10cSrcweir 		m_pTheModel->acquire();
307cdf0e10cSrcweir 	return *this;
308cdf0e10cSrcweir }
~TheModelRef()309cdf0e10cSrcweir ChartController::TheModelRef::~TheModelRef()
310cdf0e10cSrcweir {
311cdf0e10cSrcweir 	::osl::Guard< ::osl::Mutex > aGuard( m_rModelMutex );
312cdf0e10cSrcweir 	if(m_pTheModel)
313cdf0e10cSrcweir 		m_pTheModel->release();
314cdf0e10cSrcweir }
is() const315cdf0e10cSrcweir sal_Bool ChartController::TheModelRef::is() const
316cdf0e10cSrcweir {
317cdf0e10cSrcweir 	return (m_pTheModel != 0);
318cdf0e10cSrcweir }
319cdf0e10cSrcweir 
320cdf0e10cSrcweir 
321cdf0e10cSrcweir //-----------------------------------------------------------------
322cdf0e10cSrcweir // private methods
323cdf0e10cSrcweir //-----------------------------------------------------------------
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 	sal_Bool ChartController
impl_isDisposedOrSuspended() const326cdf0e10cSrcweir ::impl_isDisposedOrSuspended() const
327cdf0e10cSrcweir {
328cdf0e10cSrcweir 	if( m_aLifeTimeManager.impl_isDisposed() )
329cdf0e10cSrcweir 		return sal_True;
330cdf0e10cSrcweir 
331cdf0e10cSrcweir 	if( m_bSuspended )
332cdf0e10cSrcweir 	{
333cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "This Controller is suspended" );
334cdf0e10cSrcweir 		return sal_True;
335cdf0e10cSrcweir 	}
336cdf0e10cSrcweir 	return sal_False;
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir //-----------------------------------------------------------------
340cdf0e10cSrcweir // lang::XServiceInfo
341cdf0e10cSrcweir //-----------------------------------------------------------------
342cdf0e10cSrcweir 
APPHELPER_XSERVICEINFO_IMPL(ChartController,CHART_CONTROLLER_SERVICE_IMPLEMENTATION_NAME)343cdf0e10cSrcweir APPHELPER_XSERVICEINFO_IMPL(ChartController,CHART_CONTROLLER_SERVICE_IMPLEMENTATION_NAME)
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 	uno::Sequence< rtl::OUString > ChartController
346cdf0e10cSrcweir ::getSupportedServiceNames_Static()
347cdf0e10cSrcweir {
348cdf0e10cSrcweir 	uno::Sequence< rtl::OUString > aSNS( 2 );
349cdf0e10cSrcweir 	aSNS.getArray()[ 0 ] = CHART_CONTROLLER_SERVICE_NAME;
350cdf0e10cSrcweir 	aSNS.getArray()[ 1 ] = ::rtl::OUString::createFromAscii("com.sun.star.frame.Controller");
351cdf0e10cSrcweir 	//// @todo : add additional services if you support any further
352cdf0e10cSrcweir 	return aSNS;
353cdf0e10cSrcweir }
354cdf0e10cSrcweir 
355cdf0e10cSrcweir //-----------------------------------------------------------------
356cdf0e10cSrcweir // XController
357cdf0e10cSrcweir //-----------------------------------------------------------------
358cdf0e10cSrcweir 
359cdf0e10cSrcweir 		void SAL_CALL ChartController
attachFrame(const uno::Reference<frame::XFrame> & xFrame)360cdf0e10cSrcweir ::attachFrame( const uno::Reference<frame::XFrame>& xFrame )
361cdf0e10cSrcweir 		throw(uno::RuntimeException)
362cdf0e10cSrcweir {
363cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex());
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 	if( impl_isDisposedOrSuspended() ) //@todo? allow attaching the frame while suspended?
366cdf0e10cSrcweir 		return; //behave passive if already disposed or suspended
367cdf0e10cSrcweir 
368cdf0e10cSrcweir 	if(m_xFrame.is()) //what happens, if we do have a Frame already??
369cdf0e10cSrcweir 	{
370cdf0e10cSrcweir 		//@todo? throw exception?
371cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "there is already a frame attached to the controller" );
372cdf0e10cSrcweir 		return;
373cdf0e10cSrcweir 	}
374cdf0e10cSrcweir 
375cdf0e10cSrcweir 	//--attach frame
376cdf0e10cSrcweir 	m_xFrame = xFrame; //the frameloader is responsible to call xFrame->setComponent
377cdf0e10cSrcweir 
378cdf0e10cSrcweir 	//add as disposelistener to the frame (due to persistent reference) ??...:
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 	//the frame is considered to be owner of this controller and will live longer than we do
381cdf0e10cSrcweir 	//the frame or the disposer of the frame has the duty to call suspend and dispose on this object
382cdf0e10cSrcweir 	//so we do not need to add as lang::XEventListener for DisposingEvents right?
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 	//@todo nothing right???
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 
387cdf0e10cSrcweir 
388cdf0e10cSrcweir 	//--------------------------------------------------
389cdf0e10cSrcweir 	//create view @todo is this the correct place here??
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 	Window* pParent = NULL;
392cdf0e10cSrcweir 	//get the window parent from the frame to use as parent for our new window
393cdf0e10cSrcweir     if(xFrame.is())
394cdf0e10cSrcweir 	{
395cdf0e10cSrcweir 		uno::Reference< awt::XWindow > xContainerWindow = xFrame->getContainerWindow();
396cdf0e10cSrcweir 		VCLXWindow* pParentComponent = VCLXWindow::GetImplementation(xContainerWindow);
397cdf0e10cSrcweir 		pParentComponent->setVisible(sal_True);
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 		pParent = VCLUnoHelper::GetWindow( xContainerWindow );
400cdf0e10cSrcweir 	}
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 	if(m_pChartWindow)
403cdf0e10cSrcweir 	{
404cdf0e10cSrcweir 		//@todo delete ...
405cdf0e10cSrcweir         m_pChartWindow->clear();
406cdf0e10cSrcweir         m_apDropTargetHelper.reset();
407cdf0e10cSrcweir 	}
408cdf0e10cSrcweir 	{
409cdf0e10cSrcweir         awt::Size aPageSize( ChartModelHelper::getPageSize(getModel()) );
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 		// calls to VCL
412cdf0e10cSrcweir 		::vos::OGuard aSolarGuard( Application::GetSolarMutex());
413cdf0e10cSrcweir 		m_pChartWindow = new ChartWindow(this,pParent,pParent?pParent->GetStyle():0);
414cdf0e10cSrcweir 		m_pChartWindow->SetBackground();//no Background
415cdf0e10cSrcweir 		m_xViewWindow = uno::Reference< awt::XWindow >( m_pChartWindow->GetComponentInterface(), uno::UNO_QUERY );
416cdf0e10cSrcweir 		m_pChartWindow->Show();
417cdf0e10cSrcweir         m_apDropTargetHelper.reset(
418cdf0e10cSrcweir             new ChartDropTargetHelper( m_pChartWindow->GetDropTarget(),
419cdf0e10cSrcweir                                        uno::Reference< chart2::XChartDocument >( getModel(), uno::UNO_QUERY )));
420cdf0e10cSrcweir 
421cdf0e10cSrcweir         impl_createDrawViewController();
422cdf0e10cSrcweir 	}
423cdf0e10cSrcweir 
424cdf0e10cSrcweir     //create the menu
425cdf0e10cSrcweir     {
426cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
427cdf0e10cSrcweir         if( xPropSet.is() )
428cdf0e10cSrcweir         {
429cdf0e10cSrcweir             try
430cdf0e10cSrcweir             {
431cdf0e10cSrcweir                 uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
432cdf0e10cSrcweir                 xPropSet->getPropertyValue( C2U( "LayoutManager" ) ) >>= xLayoutManager;
433cdf0e10cSrcweir                 if ( xLayoutManager.is() )
434cdf0e10cSrcweir                 {
435cdf0e10cSrcweir 					xLayoutManager->lock();
436cdf0e10cSrcweir                     xLayoutManager->requestElement( C2U( "private:resource/menubar/menubar" ) );
437cdf0e10cSrcweir                     //@todo: createElement should become unnecessary, remove when #i79198# is fixed
438cdf0e10cSrcweir                     xLayoutManager->createElement(  C2U( "private:resource/toolbar/standardbar" ) );
439cdf0e10cSrcweir                     xLayoutManager->requestElement( C2U( "private:resource/toolbar/standardbar" ) );
440cdf0e10cSrcweir                     //@todo: createElement should become unnecessary, remove when #i79198# is fixed
441cdf0e10cSrcweir                     xLayoutManager->createElement(  C2U( "private:resource/toolbar/toolbar" ) );
442cdf0e10cSrcweir                     xLayoutManager->requestElement( C2U( "private:resource/toolbar/toolbar" ) );
443cdf0e10cSrcweir 
444cdf0e10cSrcweir                     // #i12587# support for shapes in chart
445cdf0e10cSrcweir                     xLayoutManager->createElement(  C2U( "private:resource/toolbar/drawbar" ) );
446cdf0e10cSrcweir                     xLayoutManager->requestElement( C2U( "private:resource/toolbar/drawbar" ) );
447cdf0e10cSrcweir 
448cdf0e10cSrcweir                     xLayoutManager->requestElement( C2U( "private:resource/statusbar/statusbar" ) );
449cdf0e10cSrcweir                     xLayoutManager->unlock();
450cdf0e10cSrcweir 
451cdf0e10cSrcweir                     // add as listener to get notified when
452cdf0e10cSrcweir                     m_xLayoutManagerEventBroadcaster.set( xLayoutManager, uno::UNO_QUERY );
453cdf0e10cSrcweir                     if( m_xLayoutManagerEventBroadcaster.is())
454cdf0e10cSrcweir                         m_xLayoutManagerEventBroadcaster->addLayoutManagerEventListener( this );
455cdf0e10cSrcweir                 }
456cdf0e10cSrcweir             }
457cdf0e10cSrcweir             catch( uno::Exception & ex )
458cdf0e10cSrcweir 		    {
459cdf0e10cSrcweir                 ASSERT_EXCEPTION( ex );
460cdf0e10cSrcweir 		    }
461cdf0e10cSrcweir         }
462cdf0e10cSrcweir     }
463cdf0e10cSrcweir }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir //XModeChangeListener
modeChanged(const util::ModeChangeEvent & rEvent)466cdf0e10cSrcweir void SAL_CALL ChartController::modeChanged( const util::ModeChangeEvent& rEvent )
467cdf0e10cSrcweir     throw ( uno::RuntimeException )
468cdf0e10cSrcweir {
469cdf0e10cSrcweir     //adjust controller to view status changes
470cdf0e10cSrcweir 
471cdf0e10cSrcweir     if( rEvent.NewMode.equals(C2U("dirty")) )
472cdf0e10cSrcweir     {
473cdf0e10cSrcweir         //the view has become dirty, we should repaint it if we have a window
474cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
475cdf0e10cSrcweir         if( m_pChartWindow )
476cdf0e10cSrcweir             m_pChartWindow->ForceInvalidate();
477cdf0e10cSrcweir     }
478cdf0e10cSrcweir     else if( rEvent.NewMode.equals(C2U("invalid")) )
479cdf0e10cSrcweir     {
480cdf0e10cSrcweir         //the view is about to become invalid so end all actions on it
481cdf0e10cSrcweir         impl_invalidateAccessible();
482cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex());
483cdf0e10cSrcweir 	    if( m_pDrawViewWrapper && m_pDrawViewWrapper->IsTextEdit() )
484cdf0e10cSrcweir             this->EndTextEdit();
485cdf0e10cSrcweir         if( m_pDrawViewWrapper )
486cdf0e10cSrcweir         {
487cdf0e10cSrcweir             m_pDrawViewWrapper->UnmarkAll();
488cdf0e10cSrcweir             //m_pDrawViewWrapper->hideMarkHandles(); todo??
489cdf0e10cSrcweir             m_pDrawViewWrapper->HideSdrPage();
490cdf0e10cSrcweir         }
491cdf0e10cSrcweir     }
492cdf0e10cSrcweir     else
493cdf0e10cSrcweir     {
494cdf0e10cSrcweir         //the view was rebuild so we can start some actions on it again
495cdf0e10cSrcweir         if( !m_bConnectingToView )
496cdf0e10cSrcweir         {
497cdf0e10cSrcweir             if(m_pChartWindow && m_aModel.is() )
498cdf0e10cSrcweir             {
499cdf0e10cSrcweir                 m_bConnectingToView = true;
500cdf0e10cSrcweir 
501cdf0e10cSrcweir                 GetDrawModelWrapper();
502cdf0e10cSrcweir                 if(m_pDrawModelWrapper)
503cdf0e10cSrcweir                 {
504cdf0e10cSrcweir                     {
505cdf0e10cSrcweir                         ::vos::OGuard aGuard( Application::GetSolarMutex());
506cdf0e10cSrcweir                         if( m_pDrawViewWrapper )
507cdf0e10cSrcweir                             m_pDrawViewWrapper->ReInit();
508cdf0e10cSrcweir                     }
509cdf0e10cSrcweir 
510cdf0e10cSrcweir                     //reselect object
511cdf0e10cSrcweir                     if( m_aSelection.hasSelection() )
512cdf0e10cSrcweir                         this->impl_selectObjectAndNotiy();
513cdf0e10cSrcweir                     else
514cdf0e10cSrcweir                         ChartModelHelper::triggerRangeHighlighting( getModel() );
515cdf0e10cSrcweir 
516cdf0e10cSrcweir                     impl_initializeAccessible();
517cdf0e10cSrcweir 
518cdf0e10cSrcweir                     {
519cdf0e10cSrcweir                         ::vos::OGuard aGuard( Application::GetSolarMutex() );
520cdf0e10cSrcweir                         if( m_pChartWindow )
521cdf0e10cSrcweir                             m_pChartWindow->Invalidate();
522cdf0e10cSrcweir                     }
523cdf0e10cSrcweir                 }
524cdf0e10cSrcweir 
525cdf0e10cSrcweir                 m_bConnectingToView = false;
526cdf0e10cSrcweir             }
527cdf0e10cSrcweir         }
528cdf0e10cSrcweir     }
529cdf0e10cSrcweir }
530cdf0e10cSrcweir 
531cdf0e10cSrcweir 		sal_Bool SAL_CALL ChartController
attachModel(const uno::Reference<frame::XModel> & xModel)532cdf0e10cSrcweir ::attachModel( const uno::Reference< frame::XModel > & xModel )
533cdf0e10cSrcweir 		throw(uno::RuntimeException)
534cdf0e10cSrcweir {
535cdf0e10cSrcweir     impl_invalidateAccessible();
536cdf0e10cSrcweir 
537cdf0e10cSrcweir 	//is called to attach the controller to a new model.
538cdf0e10cSrcweir 	//return true if attach was successfully, false otherwise (e.g. if you do not work with a model)
539cdf0e10cSrcweir 
540cdf0e10cSrcweir     ::vos::OClearableGuard aClearableGuard( Application::GetSolarMutex());
541cdf0e10cSrcweir 	if( impl_isDisposedOrSuspended() ) //@todo? allow attaching a new model while suspended?
542cdf0e10cSrcweir 		return sal_False; //behave passive if already disposed or suspended
543cdf0e10cSrcweir 	aClearableGuard.clear();
544cdf0e10cSrcweir 
545cdf0e10cSrcweir 
546cdf0e10cSrcweir 	TheModelRef aNewModelRef( new TheModel( xModel), m_aModelMutex);
547cdf0e10cSrcweir 	TheModelRef aOldModelRef(m_aModel,m_aModelMutex);
548cdf0e10cSrcweir 	m_aModel = aNewModelRef;
549cdf0e10cSrcweir 
550cdf0e10cSrcweir 	//--handle relations to the old model if any
551cdf0e10cSrcweir 	if( aOldModelRef.is() )
552cdf0e10cSrcweir 	{
553cdf0e10cSrcweir         uno::Reference< util::XModeChangeBroadcaster > xViewBroadcaster( m_xChartView, uno::UNO_QUERY );
554cdf0e10cSrcweir         if( xViewBroadcaster.is() )
555cdf0e10cSrcweir             xViewBroadcaster->removeModeChangeListener(this);
556cdf0e10cSrcweir         m_pDrawModelWrapper.reset();
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 		aOldModelRef->removeListener( this );
559cdf0e10cSrcweir 		//@todo?? termination correct?
560cdf0e10cSrcweir // 		aOldModelRef->tryTermination();
561cdf0e10cSrcweir #ifdef TEST_ENABLE_MODIFY_LISTENER
562cdf0e10cSrcweir         uno::Reference< util::XModifyBroadcaster > xMBroadcaster( aOldModelRef->getModel(),uno::UNO_QUERY );
563cdf0e10cSrcweir         if( xMBroadcaster.is())
564cdf0e10cSrcweir             xMBroadcaster->removeModifyListener( this );
565cdf0e10cSrcweir #endif
566cdf0e10cSrcweir 	}
567cdf0e10cSrcweir 
568cdf0e10cSrcweir 	//--handle relations to the new model
569cdf0e10cSrcweir 	aNewModelRef->addListener( this );
570cdf0e10cSrcweir 
571cdf0e10cSrcweir     // set new model at dispatchers
572cdf0e10cSrcweir     m_aDispatchContainer.setModel( aNewModelRef->getModel());
573cdf0e10cSrcweir     ControllerCommandDispatch * pDispatch = new ControllerCommandDispatch( m_xCC, this, &m_aDispatchContainer );
574cdf0e10cSrcweir     pDispatch->initialize();
575cdf0e10cSrcweir 
576cdf0e10cSrcweir     // the dispatch container will return "this" for all commands returned by
577cdf0e10cSrcweir     // impl_getAvailableCommands().  That means, for those commands dispatch()
578cdf0e10cSrcweir     // is called here at the ChartController.
579cdf0e10cSrcweir     m_aDispatchContainer.setChartDispatch( pDispatch, impl_getAvailableCommands() );
580cdf0e10cSrcweir 
581cdf0e10cSrcweir     DrawCommandDispatch* pDrawDispatch = new DrawCommandDispatch( m_xCC, this );
582cdf0e10cSrcweir     if ( pDrawDispatch )
583cdf0e10cSrcweir     {
584cdf0e10cSrcweir         pDrawDispatch->initialize();
585cdf0e10cSrcweir         m_aDispatchContainer.setDrawCommandDispatch( pDrawDispatch );
586cdf0e10cSrcweir     }
587cdf0e10cSrcweir 
588cdf0e10cSrcweir     ShapeController* pShapeController = new ShapeController( m_xCC, this );
589cdf0e10cSrcweir     if ( pShapeController )
590cdf0e10cSrcweir     {
591cdf0e10cSrcweir         pShapeController->initialize();
592cdf0e10cSrcweir         m_aDispatchContainer.setShapeController( pShapeController );
593cdf0e10cSrcweir     }
594cdf0e10cSrcweir 
595cdf0e10cSrcweir #ifdef TEST_ENABLE_MODIFY_LISTENER
596cdf0e10cSrcweir     uno::Reference< util::XModifyBroadcaster > xMBroadcaster( aNewModelRef->getModel(),uno::UNO_QUERY );
597cdf0e10cSrcweir     if( xMBroadcaster.is())
598cdf0e10cSrcweir         xMBroadcaster->addModifyListener( this );
599cdf0e10cSrcweir #endif
600cdf0e10cSrcweir 
601e38bffedSArmin Le Grand     // #119999# Do not do this per default to allow the user to deselect the chart OLE with a single press to ESC
602e38bffedSArmin Le Grand     // select chart area per default:
603e38bffedSArmin Le Grand     // select( uno::makeAny( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_PAGE, rtl::OUString() ) ) );
604cdf0e10cSrcweir 
605cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xFact( getModel(), uno::UNO_QUERY );
606cdf0e10cSrcweir 	if( xFact.is())
607cdf0e10cSrcweir     {
608cdf0e10cSrcweir         m_xChartView = xFact->createInstance( CHART_VIEW_SERVICE_NAME );
609cdf0e10cSrcweir         GetDrawModelWrapper();
610cdf0e10cSrcweir         uno::Reference< util::XModeChangeBroadcaster > xViewBroadcaster( m_xChartView, uno::UNO_QUERY );
611cdf0e10cSrcweir         if( xViewBroadcaster.is() )
612cdf0e10cSrcweir             xViewBroadcaster->addModeChangeListener(this);
613cdf0e10cSrcweir     }
614cdf0e10cSrcweir 
615cdf0e10cSrcweir 	//the frameloader is responsible to call xModel->connectController
616cdf0e10cSrcweir     {
617cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
618cdf0e10cSrcweir         if( m_pChartWindow )
619cdf0e10cSrcweir             m_pChartWindow->Invalidate();
620cdf0e10cSrcweir     }
621cdf0e10cSrcweir 
622cdf0e10cSrcweir     uno::Reference< document::XUndoManagerSupplier > xSuppUndo( getModel(), uno::UNO_QUERY_THROW );
623cdf0e10cSrcweir     m_xUndoManager.set( xSuppUndo->getUndoManager(), uno::UNO_QUERY_THROW );
624cdf0e10cSrcweir 
625cdf0e10cSrcweir 	return sal_True;
626cdf0e10cSrcweir }
627cdf0e10cSrcweir 
628cdf0e10cSrcweir 		uno::Reference< frame::XFrame > SAL_CALL ChartController
getFrame()629cdf0e10cSrcweir ::getFrame()	throw(uno::RuntimeException)
630cdf0e10cSrcweir {
631cdf0e10cSrcweir 	//provides access to owner frame of this controller
632cdf0e10cSrcweir 	//return the frame containing this controller
633cdf0e10cSrcweir 
634cdf0e10cSrcweir 	return m_xFrame;
635cdf0e10cSrcweir }
636cdf0e10cSrcweir 
637cdf0e10cSrcweir 		uno::Reference< frame::XModel > SAL_CALL ChartController
getModel()638cdf0e10cSrcweir ::getModel()	throw(uno::RuntimeException)
639cdf0e10cSrcweir {
640cdf0e10cSrcweir 	//provides access to currently attached model
641cdf0e10cSrcweir 	//returns the currently attached model
642cdf0e10cSrcweir 
643cdf0e10cSrcweir 	//return nothing, if you do not have a model
644cdf0e10cSrcweir 	TheModelRef aModelRef( m_aModel, m_aModelMutex);
645cdf0e10cSrcweir 	if(aModelRef.is())
646cdf0e10cSrcweir 		return aModelRef->getModel();
647cdf0e10cSrcweir 
648cdf0e10cSrcweir 	return uno::Reference< frame::XModel > ();
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir 		uno::Any SAL_CALL ChartController
getViewData()652cdf0e10cSrcweir ::getViewData() throw(uno::RuntimeException)
653cdf0e10cSrcweir {
654cdf0e10cSrcweir 	//provides access to current view status
655cdf0e10cSrcweir 	//set of data that can be used to restore the current view status at later time
656cdf0e10cSrcweir 	//	by using XController::restoreViewData()
657cdf0e10cSrcweir 
658cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex());
659cdf0e10cSrcweir 	if( impl_isDisposedOrSuspended() )
660cdf0e10cSrcweir 		return uno::Any(); //behave passive if already disposed or suspended //@todo? or throw an exception??
661cdf0e10cSrcweir 
662cdf0e10cSrcweir 	//-- collect current view state
663cdf0e10cSrcweir 	uno::Any aRet;
664cdf0e10cSrcweir 	//// @todo integrate specialized implementation
665cdf0e10cSrcweir 
666cdf0e10cSrcweir 	return aRet;
667cdf0e10cSrcweir }
668cdf0e10cSrcweir 
669cdf0e10cSrcweir 		void SAL_CALL ChartController
restoreViewData(const uno::Any &)670cdf0e10cSrcweir ::restoreViewData( const uno::Any& /* Value */ )
671cdf0e10cSrcweir 		throw(uno::RuntimeException)
672cdf0e10cSrcweir {
673cdf0e10cSrcweir 	//restores the view status using the data gotten from a previous call to XController::getViewData()
674cdf0e10cSrcweir 
675cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex());
676cdf0e10cSrcweir 	if( impl_isDisposedOrSuspended() )
677cdf0e10cSrcweir 		return; //behave passive if already disposed or suspended //@todo? or throw an exception??
678cdf0e10cSrcweir 
679cdf0e10cSrcweir 	//// @todo integrate specialized implementation
680cdf0e10cSrcweir }
681cdf0e10cSrcweir 
682cdf0e10cSrcweir 		sal_Bool SAL_CALL ChartController
suspend(sal_Bool bSuspend)683cdf0e10cSrcweir ::suspend( sal_Bool bSuspend )
684cdf0e10cSrcweir 		throw(uno::RuntimeException)
685cdf0e10cSrcweir {
686cdf0e10cSrcweir 	//is called to prepare the controller for closing the view
687cdf0e10cSrcweir 	//bSuspend==true: force the controller to suspend his work
688cdf0e10cSrcweir 	//bSuspend==false try to reactivate the controller
689cdf0e10cSrcweir 	//returns true if request was accepted and of course successfully finished, false otherwise
690cdf0e10cSrcweir 
691cdf0e10cSrcweir     //we may show dialogs here to ask the user for saving changes ... @todo?
692cdf0e10cSrcweir 
693cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex());
694cdf0e10cSrcweir 	if( m_aLifeTimeManager.impl_isDisposed() )
695cdf0e10cSrcweir 		return sal_False; //behave passive if already disposed, return false because request was not accepted //@todo? correct
696cdf0e10cSrcweir 
697cdf0e10cSrcweir 	if(bSuspend==m_bSuspended)
698cdf0e10cSrcweir 	{
699cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "new suspend mode equals old suspend mode" );
700cdf0e10cSrcweir 		return sal_True;
701cdf0e10cSrcweir 	}
702cdf0e10cSrcweir 
703cdf0e10cSrcweir 	//change suspend mode
704cdf0e10cSrcweir 	if(bSuspend)
705cdf0e10cSrcweir 	{
706cdf0e10cSrcweir 		//aGuard.clear();
707cdf0e10cSrcweir 		//@todo ???  try to stop all what may prevent me from becoming disposed
708cdf0e10cSrcweir 		//aGuard.reset();
709cdf0e10cSrcweir 
710cdf0e10cSrcweir 		m_bSuspended = bSuspend;
711cdf0e10cSrcweir 		return sal_True;
712cdf0e10cSrcweir 	}
713cdf0e10cSrcweir 	else
714cdf0e10cSrcweir 	{
715cdf0e10cSrcweir 		//aGuard.clear();
716cdf0e10cSrcweir 		//@todo ??? redo what was made in section bSuspend==true
717cdf0e10cSrcweir 		//aGuard.reset();
718cdf0e10cSrcweir 
719cdf0e10cSrcweir 		m_bSuspended = bSuspend;
720cdf0e10cSrcweir 	}
721cdf0e10cSrcweir     return sal_True;
722cdf0e10cSrcweir 
723cdf0e10cSrcweir 
724cdf0e10cSrcweir 	/*
725cdf0e10cSrcweir 	if ( bSuspend )
726cdf0e10cSrcweir 		getFrame()->removeFrameActionListener( pImp );
727cdf0e10cSrcweir 	else
728cdf0e10cSrcweir 		getFrame()->addFrameActionListener( pImp );
729cdf0e10cSrcweir 		*/
730cdf0e10cSrcweir }
731cdf0e10cSrcweir 
732cdf0e10cSrcweir 
impl_createDrawViewController()733cdf0e10cSrcweir void ChartController::impl_createDrawViewController()
734cdf0e10cSrcweir {
735cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex());
736cdf0e10cSrcweir     if(!m_pDrawViewWrapper)
737cdf0e10cSrcweir     {
738cdf0e10cSrcweir         if( m_pDrawModelWrapper )
739cdf0e10cSrcweir         {
740cdf0e10cSrcweir             m_pDrawViewWrapper = new DrawViewWrapper(&m_pDrawModelWrapper->getSdrModel(),m_pChartWindow,true);
741cdf0e10cSrcweir             m_pDrawViewWrapper->attachParentReferenceDevice( getModel() );
742cdf0e10cSrcweir         }
743cdf0e10cSrcweir     }
744cdf0e10cSrcweir }
impl_deleteDrawViewController()745cdf0e10cSrcweir void ChartController::impl_deleteDrawViewController()
746cdf0e10cSrcweir {
747cdf0e10cSrcweir     if( m_pDrawViewWrapper )
748cdf0e10cSrcweir     {
749cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex());
750cdf0e10cSrcweir         if( m_pDrawViewWrapper->IsTextEdit() )
751cdf0e10cSrcweir             this->EndTextEdit();
752cdf0e10cSrcweir         DELETEZ( m_pDrawViewWrapper );
753cdf0e10cSrcweir     }
754cdf0e10cSrcweir }
755cdf0e10cSrcweir 
756cdf0e10cSrcweir //-----------------------------------------------------------------
757cdf0e10cSrcweir // XComponent (base of XController)
758cdf0e10cSrcweir //-----------------------------------------------------------------
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 		void SAL_CALL ChartController
dispose()761cdf0e10cSrcweir ::dispose() throw(uno::RuntimeException)
762cdf0e10cSrcweir {
763cdf0e10cSrcweir     try
764cdf0e10cSrcweir     {
765cdf0e10cSrcweir         //This object should release all resources and references in the
766cdf0e10cSrcweir         //easiest possible manner
767cdf0e10cSrcweir         //This object must notify all registered listeners using the method
768cdf0e10cSrcweir         //<member>XEventListener::disposing</member>
769cdf0e10cSrcweir 
770cdf0e10cSrcweir         //hold no mutex
771cdf0e10cSrcweir         if( !m_aLifeTimeManager.dispose() )
772cdf0e10cSrcweir             return;
773cdf0e10cSrcweir 
774cdf0e10cSrcweir //	OSL_ENSURE( m_bSuspended, "dispose was called but controller is not suspended" );
775cdf0e10cSrcweir 
776cdf0e10cSrcweir         this->stopDoubleClickWaiting();
777cdf0e10cSrcweir 
778cdf0e10cSrcweir         //end range highlighting
779cdf0e10cSrcweir         if( m_aModel.is())
780cdf0e10cSrcweir         {
781cdf0e10cSrcweir             uno::Reference< view::XSelectionChangeListener > xSelectionChangeListener;
782cdf0e10cSrcweir             uno::Reference< chart2::data::XDataReceiver > xDataReceiver( getModel(), uno::UNO_QUERY );
783cdf0e10cSrcweir             if( xDataReceiver.is() )
784cdf0e10cSrcweir                 xSelectionChangeListener = uno::Reference< view::XSelectionChangeListener >( xDataReceiver->getRangeHighlighter(), uno::UNO_QUERY );
785cdf0e10cSrcweir             if( xSelectionChangeListener.is() )
786cdf0e10cSrcweir             {
787cdf0e10cSrcweir                 uno::Reference< frame::XController > xController( this );
788cdf0e10cSrcweir                 uno::Reference< lang::XComponent > xComp( xController, uno::UNO_QUERY );
789cdf0e10cSrcweir                 //lang::EventObject aEvent( static_cast< lang::XComponent* >( this ) );
790cdf0e10cSrcweir                 lang::EventObject aEvent( xComp );
791cdf0e10cSrcweir                 xSelectionChangeListener->disposing( aEvent );
792cdf0e10cSrcweir             }
793cdf0e10cSrcweir         }
794cdf0e10cSrcweir 
795cdf0e10cSrcweir         //--release all resources and references
796cdf0e10cSrcweir         {
797cdf0e10cSrcweir             uno::Reference< util::XModeChangeBroadcaster > xViewBroadcaster( m_xChartView, uno::UNO_QUERY );
798cdf0e10cSrcweir             if( xViewBroadcaster.is() )
799cdf0e10cSrcweir                 xViewBroadcaster->removeModeChangeListener(this);
800cdf0e10cSrcweir             // /--
801cdf0e10cSrcweir             impl_invalidateAccessible();
802cdf0e10cSrcweir             ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
803cdf0e10cSrcweir             impl_deleteDrawViewController();
804cdf0e10cSrcweir             m_pDrawModelWrapper.reset();
805cdf0e10cSrcweir 
806cdf0e10cSrcweir             m_apDropTargetHelper.reset();
807cdf0e10cSrcweir 
808cdf0e10cSrcweir             //the accessible view is disposed within window destructor of m_pChartWindow
809cdf0e10cSrcweir             m_pChartWindow->clear();
810cdf0e10cSrcweir             m_pChartWindow = NULL;//m_pChartWindow is deleted via UNO due to dispose of m_xViewWindow (trigerred by Framework (Controller pretends to be XWindow also))
811cdf0e10cSrcweir             m_xViewWindow->dispose();
812cdf0e10cSrcweir             m_xChartView.clear();
813cdf0e10cSrcweir             // \--
814cdf0e10cSrcweir         }
815cdf0e10cSrcweir 
816cdf0e10cSrcweir         // remove as listener to layout manager events
817cdf0e10cSrcweir         if( m_xLayoutManagerEventBroadcaster.is())
818cdf0e10cSrcweir         {
819cdf0e10cSrcweir             m_xLayoutManagerEventBroadcaster->removeLayoutManagerEventListener( this );
820cdf0e10cSrcweir             m_xLayoutManagerEventBroadcaster.set( 0 );
821cdf0e10cSrcweir         }
822cdf0e10cSrcweir 
823cdf0e10cSrcweir         m_xFrame.clear();
824cdf0e10cSrcweir         m_xUndoManager.clear();
825cdf0e10cSrcweir 
826cdf0e10cSrcweir         TheModelRef aModelRef( m_aModel, m_aModelMutex);
827cdf0e10cSrcweir         m_aModel = NULL;
828cdf0e10cSrcweir 
829cdf0e10cSrcweir         if( aModelRef.is())
830cdf0e10cSrcweir         {
831cdf0e10cSrcweir             uno::Reference< frame::XModel > xModel( aModelRef->getModel() );
832cdf0e10cSrcweir             if(xModel.is())
833cdf0e10cSrcweir                 xModel->disconnectController( uno::Reference< frame::XController >( this ));
834cdf0e10cSrcweir 
835cdf0e10cSrcweir             aModelRef->removeListener( this );
836cdf0e10cSrcweir #ifdef TEST_ENABLE_MODIFY_LISTENER
837cdf0e10cSrcweir             try
838cdf0e10cSrcweir             {
839cdf0e10cSrcweir                 uno::Reference< util::XModifyBroadcaster > xMBroadcaster( aModelRef->getModel(),uno::UNO_QUERY );
840cdf0e10cSrcweir                 if( xMBroadcaster.is())
841cdf0e10cSrcweir                     xMBroadcaster->removeModifyListener( this );
842cdf0e10cSrcweir             }
843cdf0e10cSrcweir             catch( const uno::Exception & ex )
844cdf0e10cSrcweir             {
845cdf0e10cSrcweir                 ASSERT_EXCEPTION( ex );
846cdf0e10cSrcweir             }
847cdf0e10cSrcweir #endif
848cdf0e10cSrcweir             aModelRef->tryTermination();
849cdf0e10cSrcweir         }
850cdf0e10cSrcweir 
851cdf0e10cSrcweir         //// @todo integrate specialized implementation
852cdf0e10cSrcweir         //e.g. release further resources and references
853cdf0e10cSrcweir 
854cdf0e10cSrcweir         m_aDispatchContainer.DisposeAndClear();
855cdf0e10cSrcweir     }
856cdf0e10cSrcweir     catch( const uno::Exception & ex )
857cdf0e10cSrcweir     {
858cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
859cdf0e10cSrcweir     }
860cdf0e10cSrcweir  }
861cdf0e10cSrcweir 
862cdf0e10cSrcweir 		void SAL_CALL ChartController
addEventListener(const uno::Reference<lang::XEventListener> & xListener)863cdf0e10cSrcweir ::addEventListener( const uno::Reference<lang::XEventListener>& xListener )
864cdf0e10cSrcweir 		throw(uno::RuntimeException)
865cdf0e10cSrcweir {
866cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex());
867cdf0e10cSrcweir 	if( impl_isDisposedOrSuspended() )//@todo? allow adding of listeners in suspend mode?
868cdf0e10cSrcweir 		return; //behave passive if already disposed or suspended
869cdf0e10cSrcweir 
870cdf0e10cSrcweir 	//--add listener
871cdf0e10cSrcweir 	m_aLifeTimeManager.m_aListenerContainer.addInterface( ::getCppuType((const uno::Reference< lang::XEventListener >*)0), xListener );
872cdf0e10cSrcweir }
873cdf0e10cSrcweir 
874cdf0e10cSrcweir 		void SAL_CALL ChartController
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)875cdf0e10cSrcweir ::removeEventListener( const uno::Reference<
876cdf0e10cSrcweir 		lang::XEventListener>& xListener )
877cdf0e10cSrcweir 		throw(uno::RuntimeException)
878cdf0e10cSrcweir {
879cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex());
880cdf0e10cSrcweir     if( m_aLifeTimeManager.impl_isDisposed(false) )
881cdf0e10cSrcweir 		return; //behave passive if already disposed or suspended
882cdf0e10cSrcweir 
883cdf0e10cSrcweir 	//--remove listener
884cdf0e10cSrcweir 	m_aLifeTimeManager.m_aListenerContainer.removeInterface( ::getCppuType((const uno::Reference< lang::XEventListener >*)0), xListener );
885cdf0e10cSrcweir }
886cdf0e10cSrcweir 
887cdf0e10cSrcweir 
888cdf0e10cSrcweir //-----------------------------------------------------------------
889cdf0e10cSrcweir // util::XCloseListener
890cdf0e10cSrcweir //-----------------------------------------------------------------
891cdf0e10cSrcweir 		void SAL_CALL ChartController
queryClosing(const lang::EventObject & rSource,sal_Bool bGetsOwnership)892cdf0e10cSrcweir ::queryClosing( const lang::EventObject& rSource, sal_Bool bGetsOwnership )
893cdf0e10cSrcweir 		throw(util::CloseVetoException, uno::RuntimeException)
894cdf0e10cSrcweir {
895cdf0e10cSrcweir 	//do not use the m_aControllerMutex here because this call is not allowed to block
896cdf0e10cSrcweir 
897cdf0e10cSrcweir 	TheModelRef aModelRef( m_aModel, m_aModelMutex);
898cdf0e10cSrcweir 
899cdf0e10cSrcweir 	if( !aModelRef.is() )
900cdf0e10cSrcweir 		return;
901cdf0e10cSrcweir 
902cdf0e10cSrcweir 	if( !(aModelRef->getModel() == rSource.Source) )
903cdf0e10cSrcweir 	{
904cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "queryClosing was called on a controller from an unknown source" );
905cdf0e10cSrcweir 		return;
906cdf0e10cSrcweir 	}
907cdf0e10cSrcweir 
908cdf0e10cSrcweir 	if( !m_bCanClose )//@todo tryaqcuire mutex
909cdf0e10cSrcweir 	{
910cdf0e10cSrcweir 		if( bGetsOwnership )
911cdf0e10cSrcweir 		{
912cdf0e10cSrcweir 			aModelRef->SetOwnerShip( bGetsOwnership );
913cdf0e10cSrcweir 		}
914cdf0e10cSrcweir 
915cdf0e10cSrcweir 		throw util::CloseVetoException();
916cdf0e10cSrcweir 	}
917cdf0e10cSrcweir 	else
918cdf0e10cSrcweir 	{
919cdf0e10cSrcweir 		//@ todo prepare to to closing model -> don't start any further hindering actions
920cdf0e10cSrcweir 	}
921cdf0e10cSrcweir }
922cdf0e10cSrcweir 
923cdf0e10cSrcweir 		void SAL_CALL ChartController
notifyClosing(const lang::EventObject & rSource)924cdf0e10cSrcweir ::notifyClosing( const lang::EventObject& rSource )
925cdf0e10cSrcweir 		throw(uno::RuntimeException)
926cdf0e10cSrcweir {
927cdf0e10cSrcweir 	//Listener should deregister himself and relaese all references to the closing object.
928cdf0e10cSrcweir 
929cdf0e10cSrcweir 	TheModelRef aModelRef( m_aModel, m_aModelMutex);
930cdf0e10cSrcweir     if( impl_releaseThisModel( rSource.Source ) )
931cdf0e10cSrcweir     {
932cdf0e10cSrcweir 	    //--stop listening to the closing model
933cdf0e10cSrcweir 	    aModelRef->removeListener( this );
934cdf0e10cSrcweir 
935cdf0e10cSrcweir         // #i79087# If the model using this controller is closed, the frame is
936cdf0e10cSrcweir         // expected to be closed as well
937cdf0e10cSrcweir         Reference< util::XCloseable > xFrameCloseable( m_xFrame, uno::UNO_QUERY );
938cdf0e10cSrcweir         if( xFrameCloseable.is())
939cdf0e10cSrcweir         {
940cdf0e10cSrcweir             try
941cdf0e10cSrcweir             {
942cdf0e10cSrcweir                 xFrameCloseable->close( sal_False /* DeliverOwnership */ );
943cdf0e10cSrcweir                 m_xFrame.clear();
944cdf0e10cSrcweir             }
945cdf0e10cSrcweir             catch( util::CloseVetoException & )
946cdf0e10cSrcweir             {
947cdf0e10cSrcweir                 // closing was vetoed
948cdf0e10cSrcweir             }
949cdf0e10cSrcweir         }
950cdf0e10cSrcweir     }
951cdf0e10cSrcweir }
952cdf0e10cSrcweir 
impl_releaseThisModel(const uno::Reference<uno::XInterface> & xModel)953cdf0e10cSrcweir bool ChartController::impl_releaseThisModel( const uno::Reference< uno::XInterface > & xModel )
954cdf0e10cSrcweir {
955cdf0e10cSrcweir     bool bReleaseModel = sal_False;
956cdf0e10cSrcweir 	{
957cdf0e10cSrcweir 		::osl::Guard< ::osl::Mutex > aGuard( m_aModelMutex );
958cdf0e10cSrcweir 		if( m_aModel.is() && m_aModel->getModel() == xModel )
959cdf0e10cSrcweir 		{
960cdf0e10cSrcweir 			m_aModel = NULL;
961cdf0e10cSrcweir             m_xUndoManager.clear();
962cdf0e10cSrcweir 			bReleaseModel = true;
963cdf0e10cSrcweir 		}
964cdf0e10cSrcweir 	}
965cdf0e10cSrcweir     if( bReleaseModel )
966cdf0e10cSrcweir         m_aDispatchContainer.setModel( 0 );
967cdf0e10cSrcweir     return bReleaseModel;
968cdf0e10cSrcweir }
969cdf0e10cSrcweir 
970cdf0e10cSrcweir //-----------------------------------------------------------------
971cdf0e10cSrcweir // util::XEventListener (base of XCloseListener)
972cdf0e10cSrcweir //-----------------------------------------------------------------
973cdf0e10cSrcweir 		void SAL_CALL ChartController
disposing(const lang::EventObject & rSource)974cdf0e10cSrcweir ::disposing( const lang::EventObject& rSource )
975cdf0e10cSrcweir 		throw(uno::RuntimeException)
976cdf0e10cSrcweir {
977cdf0e10cSrcweir     if( !impl_releaseThisModel( rSource.Source ))
978cdf0e10cSrcweir     {
979cdf0e10cSrcweir         if( rSource.Source == m_xLayoutManagerEventBroadcaster )
980cdf0e10cSrcweir             m_xLayoutManagerEventBroadcaster.set( 0 );
981cdf0e10cSrcweir     }
982cdf0e10cSrcweir }
983cdf0e10cSrcweir 
layoutEvent(const lang::EventObject & aSource,::sal_Int16 eLayoutEvent,const uno::Any &)984cdf0e10cSrcweir void SAL_CALL ChartController::layoutEvent( const lang::EventObject& aSource, ::sal_Int16 eLayoutEvent, const uno::Any& /* aInfo */ )
985cdf0e10cSrcweir     throw (uno::RuntimeException)
986cdf0e10cSrcweir {
987cdf0e10cSrcweir     if( eLayoutEvent == frame::LayoutManagerEvents::MERGEDMENUBAR )
988cdf0e10cSrcweir     {
989cdf0e10cSrcweir         Reference< frame::XLayoutManager > xLM( aSource.Source, uno::UNO_QUERY );
990cdf0e10cSrcweir         if( xLM.is())
991cdf0e10cSrcweir         {
992cdf0e10cSrcweir             xLM->createElement( C2U("private:resource/statusbar/statusbar"));
993cdf0e10cSrcweir             xLM->requestElement( C2U("private:resource/statusbar/statusbar"));
994cdf0e10cSrcweir         }
995cdf0e10cSrcweir     }
996cdf0e10cSrcweir }
997cdf0e10cSrcweir 
998cdf0e10cSrcweir 
999cdf0e10cSrcweir //-----------------------------------------------------------------
1000cdf0e10cSrcweir // XDispatchProvider (required interface)
1001cdf0e10cSrcweir //-----------------------------------------------------------------
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir namespace
1004cdf0e10cSrcweir {
lcl_isFormatObjectCommand(const rtl::OString & aCommand)1005cdf0e10cSrcweir bool lcl_isFormatObjectCommand( const rtl::OString& aCommand )
1006cdf0e10cSrcweir {
1007cdf0e10cSrcweir     if(    aCommand.equals("MainTitle")
1008cdf0e10cSrcweir         || aCommand.equals("SubTitle")
1009cdf0e10cSrcweir         || aCommand.equals("XTitle")
1010cdf0e10cSrcweir         || aCommand.equals("YTitle")
1011cdf0e10cSrcweir         || aCommand.equals("ZTitle")
1012cdf0e10cSrcweir         || aCommand.equals("SecondaryXTitle")
1013cdf0e10cSrcweir         || aCommand.equals("SecondaryYTitle")
1014cdf0e10cSrcweir         || aCommand.equals("AllTitles")
1015cdf0e10cSrcweir         || aCommand.equals("DiagramAxisX")
1016cdf0e10cSrcweir         || aCommand.equals("DiagramAxisY")
1017cdf0e10cSrcweir         || aCommand.equals("DiagramAxisZ")
1018cdf0e10cSrcweir         || aCommand.equals("DiagramAxisA")
1019cdf0e10cSrcweir         || aCommand.equals("DiagramAxisB")
1020cdf0e10cSrcweir         || aCommand.equals("DiagramAxisAll")
1021cdf0e10cSrcweir         || aCommand.equals("DiagramGridXMain")
1022cdf0e10cSrcweir         || aCommand.equals("DiagramGridYMain")
1023cdf0e10cSrcweir         || aCommand.equals("DiagramGridZMain")
1024cdf0e10cSrcweir         || aCommand.equals("DiagramGridXHelp")
1025cdf0e10cSrcweir         || aCommand.equals("DiagramGridYHelp")
1026cdf0e10cSrcweir         || aCommand.equals("DiagramGridZHelp")
1027cdf0e10cSrcweir         || aCommand.equals("DiagramGridAll")
1028cdf0e10cSrcweir 
1029cdf0e10cSrcweir         || aCommand.equals("DiagramWall")
1030cdf0e10cSrcweir         || aCommand.equals("DiagramFloor")
1031cdf0e10cSrcweir         || aCommand.equals("DiagramArea")
1032cdf0e10cSrcweir         || aCommand.equals("Legend")
1033cdf0e10cSrcweir 
1034cdf0e10cSrcweir         || aCommand.equals("FormatWall")
1035cdf0e10cSrcweir         || aCommand.equals("FormatFloor")
1036cdf0e10cSrcweir         || aCommand.equals("FormatChartArea")
1037cdf0e10cSrcweir         || aCommand.equals("FormatLegend")
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir         || aCommand.equals("FormatTitle")
1040cdf0e10cSrcweir         || aCommand.equals("FormatAxis")
1041cdf0e10cSrcweir         || aCommand.equals("FormatDataSeries")
1042cdf0e10cSrcweir         || aCommand.equals("FormatDataPoint")
1043cdf0e10cSrcweir         || aCommand.equals("FormatDataLabels")
1044cdf0e10cSrcweir         || aCommand.equals("FormatDataLabel")
1045cdf0e10cSrcweir         || aCommand.equals("FormatYErrorBars")
1046cdf0e10cSrcweir         || aCommand.equals("FormatMeanValue")
1047cdf0e10cSrcweir         || aCommand.equals("FormatTrendline")
1048cdf0e10cSrcweir         || aCommand.equals("FormatTrendlineEquation")
1049cdf0e10cSrcweir         || aCommand.equals("FormatStockLoss")
1050cdf0e10cSrcweir         || aCommand.equals("FormatStockGain")
1051cdf0e10cSrcweir         || aCommand.equals("FormatMajorGrid")
1052cdf0e10cSrcweir         || aCommand.equals("FormatMinorGrid")
1053cdf0e10cSrcweir         )
1054cdf0e10cSrcweir     return true;
1055cdf0e10cSrcweir 
1056cdf0e10cSrcweir     // else
1057cdf0e10cSrcweir     return false;
1058cdf0e10cSrcweir }
1059cdf0e10cSrcweir } // anonymous namespace
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir 		uno::Reference<frame::XDispatch> SAL_CALL ChartController
queryDispatch(const util::URL & rURL,const rtl::OUString & rTargetFrameName,sal_Int32)1062cdf0e10cSrcweir ::queryDispatch( const util::URL& rURL
1063cdf0e10cSrcweir 		, const rtl::OUString& rTargetFrameName
1064cdf0e10cSrcweir 		, sal_Int32 /* nSearchFlags */)
1065cdf0e10cSrcweir 		throw(uno::RuntimeException)
1066cdf0e10cSrcweir {
1067cdf0e10cSrcweir 	if ( !m_aLifeTimeManager.impl_isDisposed() && getModel().is() )
1068cdf0e10cSrcweir 	{
1069*9ec58d04SHerbert Dürr         if( !rTargetFrameName.isEmpty() &&
1070cdf0e10cSrcweir             rTargetFrameName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("_self")))
1071cdf0e10cSrcweir             return m_aDispatchContainer.getDispatchForURL( rURL );
1072cdf0e10cSrcweir 	}
1073cdf0e10cSrcweir 	return uno::Reference< frame::XDispatch > ();
1074cdf0e10cSrcweir }
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir 		uno::Sequence<uno::Reference<frame::XDispatch > >	ChartController
queryDispatches(const uno::Sequence<frame::DispatchDescriptor> & xDescripts)1077cdf0e10cSrcweir ::queryDispatches( const uno::Sequence<
1078cdf0e10cSrcweir 		frame::DispatchDescriptor>& xDescripts)
1079cdf0e10cSrcweir 		throw(uno::RuntimeException)
1080cdf0e10cSrcweir {
1081cdf0e10cSrcweir 	if ( !m_aLifeTimeManager.impl_isDisposed() )
1082cdf0e10cSrcweir 	{
1083cdf0e10cSrcweir         return m_aDispatchContainer.getDispatchesForURLs( xDescripts );
1084cdf0e10cSrcweir 	}
1085cdf0e10cSrcweir     return uno::Sequence<uno::Reference<frame::XDispatch > > ();
1086cdf0e10cSrcweir }
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir //-----------------------------------------------------------------
1089cdf0e10cSrcweir // frame::XDispatch
1090cdf0e10cSrcweir //-----------------------------------------------------------------
1091cdf0e10cSrcweir 
1092cdf0e10cSrcweir 	void SAL_CALL ChartController
dispatch(const util::URL & rURL,const uno::Sequence<beans::PropertyValue> & rArgs)1093cdf0e10cSrcweir ::dispatch( const util::URL& rURL
1094cdf0e10cSrcweir 			, const uno::Sequence< beans::PropertyValue >& rArgs )
1095cdf0e10cSrcweir 			throw (uno::RuntimeException)
1096cdf0e10cSrcweir {
1097cdf0e10cSrcweir     //@todo avoid OString (see Mathias mail on bug #104387#)
1098cdf0e10cSrcweir 	rtl::OString aCommand( rtl::OUStringToOString( rURL.Path, RTL_TEXTENCODING_ASCII_US ) );
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir     if(aCommand.equals("Paste"))
1101cdf0e10cSrcweir         this->executeDispatch_Paste();
1102cdf0e10cSrcweir     else if(aCommand.equals("Copy"))
1103cdf0e10cSrcweir         this->executeDispatch_Copy();
1104cdf0e10cSrcweir     else if(aCommand.equals("Cut"))
1105cdf0e10cSrcweir         this->executeDispatch_Cut();
1106cdf0e10cSrcweir     else if(aCommand.equals("DataRanges"))
1107cdf0e10cSrcweir         this->executeDispatch_SourceData();
1108cdf0e10cSrcweir     //----------------------------------
1109cdf0e10cSrcweir     else if(aCommand.equals("Update")) //Update Chart
1110cdf0e10cSrcweir 	{
1111cdf0e10cSrcweir         ChartViewHelper::setViewToDirtyState( getModel() );
1112cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
1113cdf0e10cSrcweir         if( m_pChartWindow )
1114cdf0e10cSrcweir             m_pChartWindow->Invalidate();
1115cdf0e10cSrcweir 	}
1116cdf0e10cSrcweir     else if(aCommand.equals("DiagramData"))
1117cdf0e10cSrcweir         this->executeDispatch_EditData();
1118cdf0e10cSrcweir     //insert objects
1119cdf0e10cSrcweir     else if( aCommand.equals("InsertTitles")
1120cdf0e10cSrcweir         || aCommand.equals("InsertMenuTitles") )
1121cdf0e10cSrcweir         this->executeDispatch_InsertTitles();
1122cdf0e10cSrcweir     else if( aCommand.equals("InsertMenuLegend") )
1123cdf0e10cSrcweir         this->executeDispatch_OpenLegendDialog();
1124cdf0e10cSrcweir     else if( aCommand.equals("InsertLegend") )
1125cdf0e10cSrcweir         this->executeDispatch_InsertLegend();
1126cdf0e10cSrcweir     else if( aCommand.equals("DeleteLegend") )
1127cdf0e10cSrcweir         this->executeDispatch_DeleteLegend();
1128cdf0e10cSrcweir     else if( aCommand.equals("InsertMenuDataLabels"))
1129cdf0e10cSrcweir         this->executeDispatch_InsertMenu_DataLabels();
1130cdf0e10cSrcweir     else if( aCommand.equals("InsertMenuAxes")
1131cdf0e10cSrcweir         || aCommand.equals("InsertRemoveAxes") )
1132cdf0e10cSrcweir         this->executeDispatch_InsertAxes();
1133cdf0e10cSrcweir     else if( aCommand.equals("InsertMenuGrids"))
1134cdf0e10cSrcweir         this->executeDispatch_InsertGrid();
1135cdf0e10cSrcweir     else if( aCommand.equals("InsertMenuTrendlines"))
1136cdf0e10cSrcweir         this->executeDispatch_InsertMenu_Trendlines();
1137cdf0e10cSrcweir     else if( aCommand.equals("InsertMenuMeanValues"))
1138cdf0e10cSrcweir         this->executeDispatch_InsertMenu_MeanValues();
1139cdf0e10cSrcweir     else if( aCommand.equals("InsertMenuYErrorBars"))
1140cdf0e10cSrcweir         this->executeDispatch_InsertMenu_YErrorBars();
1141cdf0e10cSrcweir     else if( aCommand.equals("InsertSymbol"))
1142cdf0e10cSrcweir          this->executeDispatch_InsertSpecialCharacter();
1143cdf0e10cSrcweir     else if( aCommand.equals("InsertTrendline"))
1144cdf0e10cSrcweir          this->executeDispatch_InsertTrendline();
1145cdf0e10cSrcweir     else if( aCommand.equals("DeleteTrendline"))
1146cdf0e10cSrcweir          this->executeDispatch_DeleteTrendline();
1147cdf0e10cSrcweir     else if( aCommand.equals("InsertMeanValue"))
1148cdf0e10cSrcweir         this->executeDispatch_InsertMeanValue();
1149cdf0e10cSrcweir     else if( aCommand.equals("DeleteMeanValue"))
1150cdf0e10cSrcweir         this->executeDispatch_DeleteMeanValue();
1151cdf0e10cSrcweir     else if( aCommand.equals("InsertYErrorBars"))
1152cdf0e10cSrcweir         this->executeDispatch_InsertYErrorBars();
1153cdf0e10cSrcweir     else if( aCommand.equals("DeleteYErrorBars"))
1154cdf0e10cSrcweir         this->executeDispatch_DeleteYErrorBars();
1155cdf0e10cSrcweir     else if( aCommand.equals("InsertTrendlineEquation"))
1156cdf0e10cSrcweir          this->executeDispatch_InsertTrendlineEquation();
1157cdf0e10cSrcweir     else if( aCommand.equals("DeleteTrendlineEquation"))
1158cdf0e10cSrcweir          this->executeDispatch_DeleteTrendlineEquation();
1159cdf0e10cSrcweir     else if( aCommand.equals("InsertTrendlineEquationAndR2"))
1160cdf0e10cSrcweir          this->executeDispatch_InsertTrendlineEquation( true );
1161cdf0e10cSrcweir     else if( aCommand.equals("InsertR2Value"))
1162cdf0e10cSrcweir          this->executeDispatch_InsertR2Value();
1163cdf0e10cSrcweir     else if( aCommand.equals("DeleteR2Value"))
1164cdf0e10cSrcweir          this->executeDispatch_DeleteR2Value();
1165cdf0e10cSrcweir     else if( aCommand.equals("InsertDataLabels") )
1166cdf0e10cSrcweir         this->executeDispatch_InsertDataLabels();
1167cdf0e10cSrcweir     else if( aCommand.equals("InsertDataLabel") )
1168cdf0e10cSrcweir         this->executeDispatch_InsertDataLabel();
1169cdf0e10cSrcweir     else if( aCommand.equals("DeleteDataLabels") )
1170cdf0e10cSrcweir         this->executeDispatch_DeleteDataLabels();
1171cdf0e10cSrcweir     else if( aCommand.equals("DeleteDataLabel") )
1172cdf0e10cSrcweir         this->executeDispatch_DeleteDataLabel();
1173cdf0e10cSrcweir     else if( aCommand.equals("ResetAllDataPoints") )
1174cdf0e10cSrcweir         this->executeDispatch_ResetAllDataPoints();
1175cdf0e10cSrcweir     else if( aCommand.equals("ResetDataPoint") )
1176cdf0e10cSrcweir         this->executeDispatch_ResetDataPoint();
1177cdf0e10cSrcweir     else if( aCommand.equals("InsertAxis") )
1178cdf0e10cSrcweir         this->executeDispatch_InsertAxis();
1179cdf0e10cSrcweir     else if( aCommand.equals("InsertMajorGrid") )
1180cdf0e10cSrcweir         this->executeDispatch_InsertMajorGrid();
1181cdf0e10cSrcweir     else if( aCommand.equals("InsertMinorGrid") )
1182cdf0e10cSrcweir         this->executeDispatch_InsertMinorGrid();
1183cdf0e10cSrcweir     else if( aCommand.equals("InsertAxisTitle") )
1184cdf0e10cSrcweir         this->executeDispatch_InsertAxisTitle();
1185cdf0e10cSrcweir     else if( aCommand.equals("DeleteAxis") )
1186cdf0e10cSrcweir         this->executeDispatch_DeleteAxis();
1187cdf0e10cSrcweir     else if( aCommand.equals("DeleteMajorGrid") )
1188cdf0e10cSrcweir         this->executeDispatch_DeleteMajorGrid();
1189cdf0e10cSrcweir     else if( aCommand.equals("DeleteMinorGrid") )
1190cdf0e10cSrcweir         this->executeDispatch_DeleteMinorGrid();
1191cdf0e10cSrcweir     //format objects
1192cdf0e10cSrcweir     else if( aCommand.equals("FormatSelection") )
1193cdf0e10cSrcweir         this->executeDispatch_ObjectProperties();
1194cdf0e10cSrcweir     else if( aCommand.equals("TransformDialog"))
1195cdf0e10cSrcweir     {
1196cdf0e10cSrcweir         if ( isShapeContext() )
1197cdf0e10cSrcweir         {
1198cdf0e10cSrcweir             this->impl_ShapeControllerDispatch( rURL, rArgs );
1199cdf0e10cSrcweir         }
1200cdf0e10cSrcweir         else
1201cdf0e10cSrcweir         {
1202cdf0e10cSrcweir             this->executeDispatch_PositionAndSize();
1203cdf0e10cSrcweir         }
1204cdf0e10cSrcweir     }
1205cdf0e10cSrcweir     else if( lcl_isFormatObjectCommand(aCommand) )
1206cdf0e10cSrcweir         this->executeDispatch_FormatObject(rURL.Path);
1207cdf0e10cSrcweir     //more format
1208cdf0e10cSrcweir //MENUCHANGE    else if(aCommand.equals("SelectSourceRanges"))
1209cdf0e10cSrcweir //MENUCHANGE        this->executeDispatch_SourceData();
1210cdf0e10cSrcweir     else if( aCommand.equals("DiagramType"))
1211cdf0e10cSrcweir         this->executeDispatch_ChartType();
1212cdf0e10cSrcweir     else if( aCommand.equals("View3D"))
1213cdf0e10cSrcweir         this->executeDispatch_View3D();
1214cdf0e10cSrcweir     else if ( aCommand.equals( "Forward" ) )
1215cdf0e10cSrcweir     {
1216cdf0e10cSrcweir         if ( isShapeContext() )
1217cdf0e10cSrcweir         {
1218cdf0e10cSrcweir             this->impl_ShapeControllerDispatch( rURL, rArgs );
1219cdf0e10cSrcweir         }
1220cdf0e10cSrcweir         else
1221cdf0e10cSrcweir         {
1222cdf0e10cSrcweir             this->executeDispatch_MoveSeries( sal_True );
1223cdf0e10cSrcweir         }
1224cdf0e10cSrcweir     }
1225cdf0e10cSrcweir     else if ( aCommand.equals( "Backward" ) )
1226cdf0e10cSrcweir     {
1227cdf0e10cSrcweir         if ( isShapeContext() )
1228cdf0e10cSrcweir         {
1229cdf0e10cSrcweir             this->impl_ShapeControllerDispatch( rURL, rArgs );
1230cdf0e10cSrcweir         }
1231cdf0e10cSrcweir         else
1232cdf0e10cSrcweir         {
1233cdf0e10cSrcweir             this->executeDispatch_MoveSeries( sal_False );
1234cdf0e10cSrcweir         }
1235cdf0e10cSrcweir     }
1236cdf0e10cSrcweir     else if( aCommand.equals("NewArrangement"))
1237cdf0e10cSrcweir         this->executeDispatch_NewArrangement();
1238cdf0e10cSrcweir     else if( aCommand.equals("ToggleLegend"))
1239cdf0e10cSrcweir         this->executeDispatch_ToggleLegend();
1240cdf0e10cSrcweir     else if( aCommand.equals("ToggleGridHorizontal"))
1241cdf0e10cSrcweir         this->executeDispatch_ToggleGridHorizontal();
1242cdf0e10cSrcweir     else if( aCommand.equals("ScaleText"))
1243cdf0e10cSrcweir         this->executeDispatch_ScaleText();
1244cdf0e10cSrcweir     else if( aCommand.equals("StatusBarVisible"))
1245cdf0e10cSrcweir     {
1246cdf0e10cSrcweir         // workaround: this should not be necessary.
1247cdf0e10cSrcweir         uno::Reference< beans::XPropertySet > xPropSet( m_xFrame, uno::UNO_QUERY );
1248cdf0e10cSrcweir         if( xPropSet.is() )
1249cdf0e10cSrcweir         {
1250cdf0e10cSrcweir             uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
1251cdf0e10cSrcweir             xPropSet->getPropertyValue( C2U( "LayoutManager" ) ) >>= xLayoutManager;
1252cdf0e10cSrcweir             if ( xLayoutManager.is() )
1253cdf0e10cSrcweir             {
1254cdf0e10cSrcweir                 bool bIsVisible( xLayoutManager->isElementVisible( C2U("private:resource/statusbar/statusbar")));
1255cdf0e10cSrcweir                 if( bIsVisible )
1256cdf0e10cSrcweir                 {
1257cdf0e10cSrcweir                     xLayoutManager->hideElement( C2U( "private:resource/statusbar/statusbar"));
1258cdf0e10cSrcweir                     xLayoutManager->destroyElement( C2U( "private:resource/statusbar/statusbar"));
1259cdf0e10cSrcweir                 }
1260cdf0e10cSrcweir                 else
1261cdf0e10cSrcweir                 {
1262cdf0e10cSrcweir                     xLayoutManager->createElement( C2U( "private:resource/statusbar/statusbar"));
1263cdf0e10cSrcweir                     xLayoutManager->showElement( C2U( "private:resource/statusbar/statusbar"));
1264cdf0e10cSrcweir                 }
1265cdf0e10cSrcweir                 // @todo: update menu state (checkmark next to "Statusbar").
1266cdf0e10cSrcweir             }
1267cdf0e10cSrcweir         }
1268cdf0e10cSrcweir     }
1269cdf0e10cSrcweir 
1270cdf0e10cSrcweir     /*
1271cdf0e10cSrcweir     case SID_TEXTEDIT:
1272cdf0e10cSrcweir         this->executeDispatch_EditText();
1273cdf0e10cSrcweir     */
1274cdf0e10cSrcweir }
1275cdf0e10cSrcweir 
1276cdf0e10cSrcweir 	void SAL_CALL ChartController
addStatusListener(const uno::Reference<frame::XStatusListener> &,const util::URL &)1277cdf0e10cSrcweir ::addStatusListener( const uno::Reference<frame::XStatusListener >& /* xControl */
1278cdf0e10cSrcweir 			, const util::URL& /* aURL */ )
1279cdf0e10cSrcweir 			throw (uno::RuntimeException)
1280cdf0e10cSrcweir {
1281cdf0e10cSrcweir //     // TODO: add listener by URL !
1282cdf0e10cSrcweir // 	::vos::OGuard aGuard( Application::GetSolarMutex());
1283cdf0e10cSrcweir // 	if( impl_isDisposedOrSuspended() )//@todo? allow adding of listeners in suspend mode?
1284cdf0e10cSrcweir // 		return; //behave passive if already disposed or suspended
1285cdf0e10cSrcweir 
1286cdf0e10cSrcweir // 	//--add listener
1287cdf0e10cSrcweir //  	m_aLifeTimeManager.m_aListenerContainer.addInterface( ::getCppuType( & xControl ), xControl );
1288cdf0e10cSrcweir }
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir 	void SAL_CALL ChartController
removeStatusListener(const uno::Reference<frame::XStatusListener> &,const util::URL &)1291cdf0e10cSrcweir ::removeStatusListener( const uno::Reference<frame::XStatusListener >& /* xControl */
1292cdf0e10cSrcweir 			, const util::URL& /* aURL */ )
1293cdf0e10cSrcweir 			throw (uno::RuntimeException)
1294cdf0e10cSrcweir {
1295cdf0e10cSrcweir //     // TODO: remove listener by URL !
1296cdf0e10cSrcweir // 	::vos::OGuard aGuard( Application::GetSolarMutex());
1297cdf0e10cSrcweir //     if( m_aLifeTimeManager.impl_isDisposed() )
1298cdf0e10cSrcweir // 		return; //behave passive if already disposed or suspended
1299cdf0e10cSrcweir 
1300cdf0e10cSrcweir // 	//--remove listener
1301cdf0e10cSrcweir // 	m_aLifeTimeManager.m_aListenerContainer.removeInterface( ::getCppuType( & xControl ), xControl );
1302cdf0e10cSrcweir }
1303cdf0e10cSrcweir 
1304cdf0e10cSrcweir //-----------------------------------------------------------------
1305cdf0e10cSrcweir // XContextMenuInterception (optional interface)
1306cdf0e10cSrcweir //-----------------------------------------------------------------
1307cdf0e10cSrcweir 		void SAL_CALL ChartController
registerContextMenuInterceptor(const uno::Reference<ui::XContextMenuInterceptor> &)1308cdf0e10cSrcweir ::registerContextMenuInterceptor( const uno::Reference<
1309cdf0e10cSrcweir 		ui::XContextMenuInterceptor > & /* xInterceptor */)
1310cdf0e10cSrcweir 		throw(uno::RuntimeException)
1311cdf0e10cSrcweir {
1312cdf0e10cSrcweir 	//@todo
1313cdf0e10cSrcweir }
1314cdf0e10cSrcweir 
1315cdf0e10cSrcweir 		void SAL_CALL ChartController
releaseContextMenuInterceptor(const uno::Reference<ui::XContextMenuInterceptor> &)1316cdf0e10cSrcweir ::releaseContextMenuInterceptor( const uno::Reference<
1317cdf0e10cSrcweir 		ui::XContextMenuInterceptor > & /* xInterceptor */)
1318cdf0e10cSrcweir 		throw(uno::RuntimeException)
1319cdf0e10cSrcweir {
1320cdf0e10cSrcweir 	//@todo
1321cdf0e10cSrcweir }
1322cdf0e10cSrcweir 
1323cdf0e10cSrcweir // ____ XEmbeddedClient ____
1324cdf0e10cSrcweir // implementation see: ChartController_EditData.cxx
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir //-----------------------------------------------------------------------------
1327cdf0e10cSrcweir //-----------------------------------------------------------------------------
1328cdf0e10cSrcweir //-----------------------------------------------------------------------------
1329cdf0e10cSrcweir 
executeDispatch_ChartType()1330cdf0e10cSrcweir void SAL_CALL ChartController::executeDispatch_ChartType()
1331cdf0e10cSrcweir {
1332cdf0e10cSrcweir     // using assignment for broken gcc 3.3
1333cdf0e10cSrcweir     UndoLiveUpdateGuard aUndoGuard = UndoLiveUpdateGuard(
1334cdf0e10cSrcweir         String( SchResId( STR_ACTION_EDIT_CHARTTYPE )), m_xUndoManager );
1335cdf0e10cSrcweir 
1336cdf0e10cSrcweir     // /--
1337cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
1338cdf0e10cSrcweir     //prepare and open dialog
1339cdf0e10cSrcweir     ChartTypeDialog aDlg( m_pChartWindow, getModel(), m_xCC );
1340cdf0e10cSrcweir     if( aDlg.Execute() == RET_OK )
1341cdf0e10cSrcweir     {
1342cdf0e10cSrcweir         impl_adaptDataSeriesAutoResize();
1343cdf0e10cSrcweir         aUndoGuard.commit();
1344cdf0e10cSrcweir     }
1345cdf0e10cSrcweir     // \--
1346cdf0e10cSrcweir }
1347cdf0e10cSrcweir 
executeDispatch_SourceData()1348cdf0e10cSrcweir void SAL_CALL ChartController::executeDispatch_SourceData()
1349cdf0e10cSrcweir {
1350cdf0e10cSrcweir     //-------------------------------------------------------------
1351cdf0e10cSrcweir     //convert properties to ItemSet
1352cdf0e10cSrcweir     uno::Reference< XChartDocument >   xChartDoc( getModel(), uno::UNO_QUERY );
1353cdf0e10cSrcweir     DBG_ASSERT( xChartDoc.is(), "Invalid XChartDocument" );
1354cdf0e10cSrcweir     if( !xChartDoc.is())
1355cdf0e10cSrcweir         return;
1356cdf0e10cSrcweir 
1357cdf0e10cSrcweir     // using assignment for broken gcc 3.3
1358cdf0e10cSrcweir     UndoLiveUpdateGuard aUndoGuard = UndoLiveUpdateGuard(
1359cdf0e10cSrcweir         String( SchResId( STR_ACTION_EDIT_DATA_RANGES )), m_xUndoManager );
1360cdf0e10cSrcweir     if( xChartDoc.is())
1361cdf0e10cSrcweir     {
1362cdf0e10cSrcweir         // /--
1363cdf0e10cSrcweir 		::vos::OGuard aSolarGuard( Application::GetSolarMutex());
1364cdf0e10cSrcweir         ::chart::DataSourceDialog aDlg( m_pChartWindow, xChartDoc, m_xCC );
1365cdf0e10cSrcweir         if( aDlg.Execute() == RET_OK )
1366cdf0e10cSrcweir         {
1367cdf0e10cSrcweir             impl_adaptDataSeriesAutoResize();
1368cdf0e10cSrcweir             aUndoGuard.commit();
1369cdf0e10cSrcweir         }
1370cdf0e10cSrcweir         // \--
1371cdf0e10cSrcweir     }
1372cdf0e10cSrcweir }
1373cdf0e10cSrcweir 
executeDispatch_MoveSeries(sal_Bool bForward)1374cdf0e10cSrcweir void SAL_CALL ChartController::executeDispatch_MoveSeries( sal_Bool bForward )
1375cdf0e10cSrcweir {
1376cdf0e10cSrcweir     ControllerLockGuard aCLGuard( getModel() );
1377cdf0e10cSrcweir 
1378cdf0e10cSrcweir     //get selected series
1379cdf0e10cSrcweir 	::rtl::OUString aObjectCID(m_aSelection.getSelectedCID());
1380cdf0e10cSrcweir     uno::Reference< XDataSeries > xGivenDataSeries( ObjectIdentifier::getDataSeriesForCID( //yyy todo also legendentries and labels?
1381cdf0e10cSrcweir             aObjectCID, getModel() ) );
1382cdf0e10cSrcweir 
1383cdf0e10cSrcweir     UndoGuardWithSelection aUndoGuard(
1384cdf0e10cSrcweir         ActionDescriptionProvider::createDescription(
1385cdf0e10cSrcweir             (bForward ? ActionDescriptionProvider::MOVE_TOTOP : ActionDescriptionProvider::MOVE_TOBOTTOM),
1386cdf0e10cSrcweir             String( SchResId( STR_OBJECT_DATASERIES ))),
1387cdf0e10cSrcweir         m_xUndoManager );
1388cdf0e10cSrcweir 
1389cdf0e10cSrcweir     bool bChanged = DiagramHelper::moveSeries( ChartModelHelper::findDiagram( getModel() ), xGivenDataSeries, bForward );
1390cdf0e10cSrcweir     if( bChanged )
1391cdf0e10cSrcweir     {
1392cdf0e10cSrcweir         m_aSelection.setSelection( ObjectIdentifier::getMovedSeriesCID( aObjectCID, bForward ) );
1393cdf0e10cSrcweir         aUndoGuard.commit();
1394cdf0e10cSrcweir     }
1395cdf0e10cSrcweir }
1396cdf0e10cSrcweir 
1397cdf0e10cSrcweir // ____ XMultiServiceFactory ____
1398cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL
createInstance(const::rtl::OUString & aServiceSpecifier)1399cdf0e10cSrcweir     ChartController::createInstance( const ::rtl::OUString& aServiceSpecifier )
1400cdf0e10cSrcweir     throw (uno::Exception,
1401cdf0e10cSrcweir            uno::RuntimeException)
1402cdf0e10cSrcweir {
1403cdf0e10cSrcweir     uno::Reference< uno::XInterface > xResult;
1404cdf0e10cSrcweir 
1405cdf0e10cSrcweir     if( aServiceSpecifier.equals( CHART_ACCESSIBLE_TEXT_SERVICE_NAME ))
1406cdf0e10cSrcweir         xResult.set( impl_createAccessibleTextContext());
1407cdf0e10cSrcweir     return xResult;
1408cdf0e10cSrcweir }
1409cdf0e10cSrcweir 
1410cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL
createInstanceWithArguments(const::rtl::OUString & ServiceSpecifier,const uno::Sequence<uno::Any> &)1411cdf0e10cSrcweir     ChartController::createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier,
1412cdf0e10cSrcweir                                  const uno::Sequence< uno::Any >& /* Arguments */ )
1413cdf0e10cSrcweir     throw (uno::Exception,
1414cdf0e10cSrcweir            uno::RuntimeException)
1415cdf0e10cSrcweir {
1416cdf0e10cSrcweir     // ignore Arguments
1417cdf0e10cSrcweir     return createInstance( ServiceSpecifier );
1418cdf0e10cSrcweir }
1419cdf0e10cSrcweir 
1420cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL
getAvailableServiceNames()1421cdf0e10cSrcweir     ChartController::getAvailableServiceNames()
1422cdf0e10cSrcweir     throw (uno::RuntimeException)
1423cdf0e10cSrcweir {
1424cdf0e10cSrcweir     static uno::Sequence< ::rtl::OUString > aServiceNames;
1425cdf0e10cSrcweir 
1426cdf0e10cSrcweir     if( aServiceNames.getLength() == 0 )
1427cdf0e10cSrcweir     {
1428cdf0e10cSrcweir         aServiceNames.realloc(1);
1429cdf0e10cSrcweir         aServiceNames[0] = CHART_ACCESSIBLE_TEXT_SERVICE_NAME;
1430cdf0e10cSrcweir     }
1431cdf0e10cSrcweir 
1432cdf0e10cSrcweir     return aServiceNames;
1433cdf0e10cSrcweir }
1434cdf0e10cSrcweir 
1435cdf0e10cSrcweir // ____ XModifyListener ____
modified(const lang::EventObject &)1436cdf0e10cSrcweir void SAL_CALL ChartController::modified( const lang::EventObject& /* aEvent */ )
1437cdf0e10cSrcweir     throw (uno::RuntimeException)
1438cdf0e10cSrcweir {
1439cdf0e10cSrcweir     // the source can also be a subobject of the ChartModel
1440cdf0e10cSrcweir     // @todo: change the source in ChartModel to always be the model itself ?
1441cdf0e10cSrcweir //     if( getModel() == aEvent.Source )
1442cdf0e10cSrcweir 
1443cdf0e10cSrcweir 
1444cdf0e10cSrcweir     //todo? update menu states ?
1445cdf0e10cSrcweir }
1446cdf0e10cSrcweir 
1447cdf0e10cSrcweir //-----------------------------------------------------------------------------
1448cdf0e10cSrcweir //-----------------------------------------------------------------------------
1449cdf0e10cSrcweir //-----------------------------------------------------------------------------
1450cdf0e10cSrcweir 
IMPL_LINK(ChartController,NotifyUndoActionHdl,SdrUndoAction *,pUndoAction)1451cdf0e10cSrcweir IMPL_LINK( ChartController, NotifyUndoActionHdl, SdrUndoAction*, pUndoAction )
1452cdf0e10cSrcweir {
1453cdf0e10cSrcweir     ENSURE_OR_RETURN( pUndoAction, "invalid Undo action", 1L );
1454cdf0e10cSrcweir 
1455cdf0e10cSrcweir     ::rtl::OUString aObjectCID = m_aSelection.getSelectedCID();
1456*9ec58d04SHerbert Dürr     if ( aObjectCID.isEmpty() )
1457cdf0e10cSrcweir     {
1458cdf0e10cSrcweir         try
1459cdf0e10cSrcweir         {
1460cdf0e10cSrcweir             const Reference< document::XUndoManagerSupplier > xSuppUndo( getModel(), uno::UNO_QUERY_THROW );
1461cdf0e10cSrcweir             const Reference< document::XUndoManager > xUndoManager( xSuppUndo->getUndoManager(), uno::UNO_QUERY_THROW );
1462cdf0e10cSrcweir             const Reference< document::XUndoAction > xAction( new impl::ShapeUndoElement( *pUndoAction ) );
1463cdf0e10cSrcweir             xUndoManager->addUndoAction( xAction );
1464cdf0e10cSrcweir         }
1465cdf0e10cSrcweir         catch( const uno::Exception& )
1466cdf0e10cSrcweir         {
1467cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
1468cdf0e10cSrcweir         }
1469cdf0e10cSrcweir     }
1470cdf0e10cSrcweir     return 0L;
1471cdf0e10cSrcweir }
1472cdf0e10cSrcweir 
GetDrawModelWrapper()1473cdf0e10cSrcweir DrawModelWrapper* ChartController::GetDrawModelWrapper()
1474cdf0e10cSrcweir {
1475cdf0e10cSrcweir     if( !m_pDrawModelWrapper.get() )
1476cdf0e10cSrcweir     {
1477cdf0e10cSrcweir         ExplicitValueProvider* pProvider = ExplicitValueProvider::getExplicitValueProvider( m_xChartView );
1478cdf0e10cSrcweir         if( pProvider )
1479cdf0e10cSrcweir             m_pDrawModelWrapper = pProvider->getDrawModelWrapper();
1480cdf0e10cSrcweir         if ( m_pDrawModelWrapper.get() )
1481cdf0e10cSrcweir         {
1482cdf0e10cSrcweir             m_pDrawModelWrapper->getSdrModel().SetNotifyUndoActionHdl( LINK( this, ChartController, NotifyUndoActionHdl ) );
1483cdf0e10cSrcweir         }
1484cdf0e10cSrcweir     }
1485cdf0e10cSrcweir     return m_pDrawModelWrapper.get();
1486cdf0e10cSrcweir }
1487cdf0e10cSrcweir 
GetDrawViewWrapper()1488cdf0e10cSrcweir DrawViewWrapper* ChartController::GetDrawViewWrapper()
1489cdf0e10cSrcweir {
1490cdf0e10cSrcweir     if ( !m_pDrawViewWrapper )
1491cdf0e10cSrcweir     {
1492cdf0e10cSrcweir         impl_createDrawViewController();
1493cdf0e10cSrcweir     }
1494cdf0e10cSrcweir     return m_pDrawViewWrapper;
1495cdf0e10cSrcweir }
1496cdf0e10cSrcweir 
CreateAccessible()1497cdf0e10cSrcweir uno::Reference< XAccessible > ChartController::CreateAccessible()
1498cdf0e10cSrcweir {
1499cdf0e10cSrcweir     uno::Reference< XAccessible > xResult = new AccessibleChartView( m_xCC, GetDrawViewWrapper() );
1500cdf0e10cSrcweir     impl_initializeAccessible( uno::Reference< lang::XInitialization >( xResult, uno::UNO_QUERY ) );
1501cdf0e10cSrcweir     return xResult;
1502cdf0e10cSrcweir }
1503cdf0e10cSrcweir 
impl_invalidateAccessible()1504cdf0e10cSrcweir void ChartController::impl_invalidateAccessible()
1505cdf0e10cSrcweir {
1506cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
1507cdf0e10cSrcweir     if( m_pChartWindow )
1508cdf0e10cSrcweir     {
1509cdf0e10cSrcweir         Reference< lang::XInitialization > xInit( m_pChartWindow->GetAccessible(false), uno::UNO_QUERY );
1510cdf0e10cSrcweir         if(xInit.is())
1511cdf0e10cSrcweir         {
1512cdf0e10cSrcweir             uno::Sequence< uno::Any > aArguments(3);//empty arguments -> invalid accessible
1513cdf0e10cSrcweir             xInit->initialize(aArguments);
1514cdf0e10cSrcweir         }
1515cdf0e10cSrcweir     }
1516cdf0e10cSrcweir }
impl_initializeAccessible()1517cdf0e10cSrcweir void ChartController::impl_initializeAccessible()
1518cdf0e10cSrcweir {
1519cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
1520cdf0e10cSrcweir     if( m_pChartWindow )
1521cdf0e10cSrcweir         this->impl_initializeAccessible( Reference< lang::XInitialization >( m_pChartWindow->GetAccessible(false), uno::UNO_QUERY ) );
1522cdf0e10cSrcweir }
impl_initializeAccessible(const uno::Reference<lang::XInitialization> & xInit)1523cdf0e10cSrcweir void ChartController::impl_initializeAccessible( const uno::Reference< lang::XInitialization >& xInit )
1524cdf0e10cSrcweir {
1525cdf0e10cSrcweir     if(xInit.is())
1526cdf0e10cSrcweir     {
1527cdf0e10cSrcweir         uno::Sequence< uno::Any > aArguments(5);
1528cdf0e10cSrcweir         uno::Reference<view::XSelectionSupplier> xSelectionSupplier(this);
1529cdf0e10cSrcweir         aArguments[0]=uno::makeAny(xSelectionSupplier);
1530cdf0e10cSrcweir         uno::Reference<frame::XModel> xModel(getModel());
1531cdf0e10cSrcweir         aArguments[1]=uno::makeAny(xModel);
1532cdf0e10cSrcweir         aArguments[2]=uno::makeAny(m_xChartView);
1533cdf0e10cSrcweir         uno::Reference< XAccessible > xParent;
1534cdf0e10cSrcweir         {
1535cdf0e10cSrcweir             ::vos::OGuard aGuard( Application::GetSolarMutex() );
1536cdf0e10cSrcweir             if( m_pChartWindow )
1537cdf0e10cSrcweir             {
1538cdf0e10cSrcweir                 Window* pParentWin( m_pChartWindow->GetAccessibleParentWindow());
1539cdf0e10cSrcweir                 if( pParentWin )
1540cdf0e10cSrcweir                     xParent.set( pParentWin->GetAccessible());
1541cdf0e10cSrcweir             }
1542cdf0e10cSrcweir         }
1543cdf0e10cSrcweir         aArguments[3]=uno::makeAny(xParent);
1544cdf0e10cSrcweir         aArguments[4]=uno::makeAny(m_xViewWindow);
1545cdf0e10cSrcweir 
1546cdf0e10cSrcweir         xInit->initialize(aArguments);
1547cdf0e10cSrcweir     }
1548cdf0e10cSrcweir }
1549cdf0e10cSrcweir 
impl_getAvailableCommands()1550cdf0e10cSrcweir ::std::set< ::rtl::OUString > ChartController::impl_getAvailableCommands()
1551cdf0e10cSrcweir {
1552cdf0e10cSrcweir     return ::comphelper::MakeSet< ::rtl::OUString >
1553cdf0e10cSrcweir         // commands for container forward
1554cdf0e10cSrcweir         ( C2U("AddDirect"))           ( C2U("NewDoc"))                ( C2U("Open"))
1555cdf0e10cSrcweir         ( C2U("Save"))                ( C2U("SaveAs"))                ( C2U("SendMail"))
1556cdf0e10cSrcweir         ( C2U("EditDoc"))             ( C2U("ExportDirectToPDF"))     ( C2U("PrintDefault"))
1557cdf0e10cSrcweir 
1558cdf0e10cSrcweir         // own commands
1559cdf0e10cSrcweir         ( C2U("Cut") )                ( C2U("Copy") )                 ( C2U("Paste") )
1560cdf0e10cSrcweir         ( C2U("DataRanges") )         ( C2U("DiagramData") )
1561cdf0e10cSrcweir         // insert objects
1562cdf0e10cSrcweir         ( C2U("InsertMenuTitles") )   ( C2U("InsertTitles") )
1563cdf0e10cSrcweir         ( C2U("InsertMenuLegend") )   ( C2U("InsertLegend") )         ( C2U("DeleteLegend") )
1564cdf0e10cSrcweir         ( C2U("InsertMenuDataLabels") )
1565cdf0e10cSrcweir         ( C2U("InsertMenuAxes") )     ( C2U("InsertRemoveAxes") )         ( C2U("InsertMenuGrids") )
1566cdf0e10cSrcweir         ( C2U("InsertSymbol") )
1567cdf0e10cSrcweir         ( C2U("InsertTrendlineEquation") )  ( C2U("InsertTrendlineEquationAndR2") )
1568cdf0e10cSrcweir         ( C2U("InsertR2Value") )      ( C2U("DeleteR2Value") )
1569cdf0e10cSrcweir         ( C2U("InsertMenuTrendlines") )  ( C2U("InsertTrendline") )
1570cdf0e10cSrcweir         ( C2U("InsertMenuMeanValues") ) ( C2U("InsertMeanValue") )
1571cdf0e10cSrcweir         ( C2U("InsertMenuYErrorBars") )   ( C2U("InsertYErrorBars") )
1572cdf0e10cSrcweir         ( C2U("InsertDataLabels") )   ( C2U("InsertDataLabel") )
1573cdf0e10cSrcweir         ( C2U("DeleteTrendline") )    ( C2U("DeleteMeanValue") )      ( C2U("DeleteTrendlineEquation") )
1574cdf0e10cSrcweir         ( C2U("DeleteYErrorBars") )
1575cdf0e10cSrcweir         ( C2U("DeleteDataLabels") )   ( C2U("DeleteDataLabel") )
1576cdf0e10cSrcweir         //format objects
1577cdf0e10cSrcweir //MENUCHANGE            ( C2U("SelectSourceRanges") )
1578cdf0e10cSrcweir         ( C2U("FormatSelection") )     ( C2U("TransformDialog") )
1579cdf0e10cSrcweir         ( C2U("DiagramType") )        ( C2U("View3D") )
1580cdf0e10cSrcweir         ( C2U("Forward") )            ( C2U("Backward") )
1581cdf0e10cSrcweir         ( C2U("MainTitle") )          ( C2U("SubTitle") )
1582cdf0e10cSrcweir         ( C2U("XTitle") )             ( C2U("YTitle") )               ( C2U("ZTitle") )
1583cdf0e10cSrcweir         ( C2U("SecondaryXTitle") )    ( C2U("SecondaryYTitle") )
1584cdf0e10cSrcweir         ( C2U("AllTitles") )          ( C2U("Legend") )
1585cdf0e10cSrcweir         ( C2U("DiagramAxisX") )       ( C2U("DiagramAxisY") )         ( C2U("DiagramAxisZ") )
1586cdf0e10cSrcweir         ( C2U("DiagramAxisA") )       ( C2U("DiagramAxisB") )         ( C2U("DiagramAxisAll") )
1587cdf0e10cSrcweir         ( C2U("DiagramGridXMain") )   ( C2U("DiagramGridYMain") )     ( C2U("DiagramGridZMain") )
1588cdf0e10cSrcweir         ( C2U("DiagramGridXHelp") )   ( C2U("DiagramGridYHelp") )     ( C2U("DiagramGridZHelp") )
1589cdf0e10cSrcweir         ( C2U("DiagramGridAll") )
1590cdf0e10cSrcweir         ( C2U("DiagramWall") )        ( C2U("DiagramFloor") )         ( C2U("DiagramArea") )
1591cdf0e10cSrcweir 
1592cdf0e10cSrcweir         //context menu - format objects entries
1593cdf0e10cSrcweir         ( C2U("FormatWall") )        ( C2U("FormatFloor") )         ( C2U("FormatChartArea") )
1594cdf0e10cSrcweir         ( C2U("FormatLegend") )
1595cdf0e10cSrcweir 
1596cdf0e10cSrcweir         ( C2U("FormatAxis") )           ( C2U("FormatTitle") )
1597cdf0e10cSrcweir         ( C2U("FormatDataSeries") )     ( C2U("FormatDataPoint") )
1598cdf0e10cSrcweir         ( C2U("ResetAllDataPoints") )   ( C2U("ResetDataPoint") )
1599cdf0e10cSrcweir         ( C2U("FormatDataLabels") )     ( C2U("FormatDataLabel") )
1600cdf0e10cSrcweir         ( C2U("FormatMeanValue") )      ( C2U("FormatTrendline") )      ( C2U("FormatTrendlineEquation") )
1601cdf0e10cSrcweir         ( C2U("FormatYErrorBars") )
1602cdf0e10cSrcweir         ( C2U("FormatStockLoss") )      ( C2U("FormatStockGain") )
1603cdf0e10cSrcweir 
1604cdf0e10cSrcweir         ( C2U("FormatMajorGrid") )      ( C2U("InsertMajorGrid") )      ( C2U("DeleteMajorGrid") )
1605cdf0e10cSrcweir         ( C2U("FormatMinorGrid") )      ( C2U("InsertMinorGrid") )      ( C2U("DeleteMinorGrid") )
1606cdf0e10cSrcweir         ( C2U("InsertAxis") )           ( C2U("DeleteAxis") )           ( C2U("InsertAxisTitle") )
1607cdf0e10cSrcweir 
1608cdf0e10cSrcweir         // toolbar commands
1609cdf0e10cSrcweir         ( C2U("ToggleGridHorizontal"))( C2U("ToggleLegend") )         ( C2U("ScaleText") )
1610cdf0e10cSrcweir         ( C2U("NewArrangement") )     ( C2U("Update") )
1611cdf0e10cSrcweir         ( C2U("DefaultColors") )      ( C2U("BarWidth") )             ( C2U("NumberOfLines") )
1612cdf0e10cSrcweir         ( C2U("ArrangeRow") )
1613cdf0e10cSrcweir         ( C2U("StatusBarVisible") )
1614cdf0e10cSrcweir         ( C2U("ChartElementSelector") )
1615cdf0e10cSrcweir         ;
1616cdf0e10cSrcweir }
1617cdf0e10cSrcweir 
1618cdf0e10cSrcweir //.............................................................................
1619cdf0e10cSrcweir } //namespace chart
1620cdf0e10cSrcweir //.............................................................................
1621