merge the formfield patch from ooo-build
[ooovba.git] / sfx2 / source / view / sfxbasecontroller.cxx
blob5a64421423043eca9743ada54e72fc960599a3e8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sfxbasecontroller.cxx,v $
10 * $Revision: 1.76 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 //________________________________________________________________________________________________________
35 // my own includes
36 //________________________________________________________________________________________________________
38 #include <time.h>
39 #include <sfx2/sfxbasecontroller.hxx>
41 //________________________________________________________________________________________________________
42 // include of other projects
43 //________________________________________________________________________________________________________
44 #include <com/sun/star/awt/KeyEvent.hpp>
45 #include <com/sun/star/awt/KeyModifier.hpp>
46 #include <com/sun/star/awt/MouseEvent.hpp>
47 #include <com/sun/star/awt/MouseButton.hpp>
48 #include <com/sun/star/util/XCloseable.hpp>
49 #include <com/sun/star/util/XCloseBroadcaster.hpp>
50 #include <com/sun/star/util/XCloseListener.hpp>
51 #include <com/sun/star/util/CloseVetoException.hpp>
52 #include <cppuhelper/implbase1.hxx>
53 #include <cppuhelper/implbase2.hxx>
54 #include <com/sun/star/frame/FrameActionEvent.hpp>
55 #include <com/sun/star/frame/FrameAction.hpp>
56 #include <com/sun/star/frame/CommandGroup.hpp>
57 #include <com/sun/star/frame/XFrame.hpp>
58 #include <com/sun/star/frame/XBorderResizeListener.hpp>
59 #include <com/sun/star/lang/EventObject.hpp>
60 #include <com/sun/star/lang/XEventListener.hpp>
61 #include <com/sun/star/lang/XComponent.hpp>
62 #include <cppuhelper/interfacecontainer.hxx>
63 #include <cppuhelper/typeprovider.hxx>
64 #include <cppuhelper/implbase1.hxx>
65 #include <basic/sbstar.hxx>
66 #include <uno/mapping.hxx>
67 #include <sfx2/viewsh.hxx>
68 #include <sfx2/viewfrm.hxx>
69 #include <sfx2/objsh.hxx>
70 #include <sfx2/app.hxx>
71 #include <sfx2/msgpool.hxx>
72 #include <sfx2/dispatch.hxx>
73 #include <sfx2/userinputinterception.hxx>
75 #include <viewimp.hxx>
76 #include <sfx2/unoctitm.hxx>
77 #include <sfx2/childwin.hxx>
78 #include <sfx2/sfxsids.hrc>
79 #include <workwin.hxx>
80 #include <sfx2/objface.hxx>
82 #include <vos/mutex.hxx>
83 #include <osl/mutex.hxx>
84 #include <comphelper/sequence.hxx>
85 #include <rtl/ustrbuf.hxx>
86 #include <toolkit/helper/convert.hxx>
87 #include <framework/titlehelper.hxx>
88 #include <comphelper/processfactory.hxx>
90 #include <hash_map>
92 #include <sfx2/event.hxx>
94 #define OMULTITYPEINTERFACECONTAINERHELPER ::cppu::OMultiTypeInterfaceContainerHelper
95 #define OINTERFACECONTAINERHELPER ::cppu::OInterfaceContainerHelper
96 #define XFRAMEACTIONLISTENER ::com::sun::star::frame::XFrameActionListener
97 #define XCLOSELISTENER ::com::sun::star::util::XCloseListener
98 #define FRAMEACTIONEVENT ::com::sun::star::frame::FrameActionEvent
99 #define EVENTOBJECT ::com::sun::star::lang::EventObject
100 #define OTYPECOLLECTION ::cppu::OTypeCollection
101 #define OIMPLEMENTATIONID ::cppu::OImplementationId
102 #define MUTEXGUARD ::osl::MutexGuard
103 #define UNOQUERY ::com::sun::star::uno::UNO_QUERY
104 #define MAPPING ::com::sun::star::uno::Mapping
105 #define XSTATUSINDICATORSUPPLIER ::com::sun::star::task::XStatusIndicatorSupplier
106 #define XCOMPONENT ::com::sun::star::lang::XComponent
107 #define XINTERFACE ::com::sun::star::uno::XInterface
108 #define XKEYHANDLER ::com::sun::star::awt::XKeyHandler
109 #define XMOUSECLICKHANDLER ::com::sun::star::awt::XMouseClickHandler
111 #define TIMEOUT_START_RESCHEDULE 10L /* 10th s */
113 using namespace ::com::sun::star;
114 namespace css = ::com::sun::star;
116 struct GroupIDToCommandGroup
118 sal_Int16 nGroupID;
119 sal_Int16 nCommandGroup;
122 // Please update when a new command group is added
123 const sal_Int16 MAX_COMMANDGROUP = com::sun::star::frame::CommandGroup::CONTROLS;
125 static sal_Bool bGroupIDMapInitialized = sal_False;
126 static GroupIDToCommandGroup GroupIDCommandGroupMap[] =
128 { GID_INTERN , com::sun::star::frame::CommandGroup::INTERNAL },
129 { GID_APPLICATION , com::sun::star::frame::CommandGroup::APPLICATION },
130 { GID_DOCUMENT , com::sun::star::frame::CommandGroup::DOCUMENT },
131 { GID_VIEW , com::sun::star::frame::CommandGroup::VIEW },
132 { GID_EDIT , com::sun::star::frame::CommandGroup::EDIT },
133 { GID_MACRO , com::sun::star::frame::CommandGroup::MACRO },
134 { GID_OPTIONS , com::sun::star::frame::CommandGroup::OPTIONS },
135 { GID_MATH , com::sun::star::frame::CommandGroup::MATH },
136 { GID_NAVIGATOR , com::sun::star::frame::CommandGroup::NAVIGATOR },
137 { GID_INSERT , com::sun::star::frame::CommandGroup::INSERT },
138 { GID_FORMAT , com::sun::star::frame::CommandGroup::FORMAT },
139 { GID_TEMPLATE , com::sun::star::frame::CommandGroup::TEMPLATE },
140 { GID_TEXT , com::sun::star::frame::CommandGroup::TEXT },
141 { GID_FRAME , com::sun::star::frame::CommandGroup::FRAME },
142 { GID_GRAPHIC , com::sun::star::frame::CommandGroup::GRAPHIC },
143 { GID_TABLE , com::sun::star::frame::CommandGroup::TABLE },
144 { GID_ENUMERATION , com::sun::star::frame::CommandGroup::ENUMERATION },
145 { GID_DATA , com::sun::star::frame::CommandGroup::DATA },
146 { GID_SPECIAL , com::sun::star::frame::CommandGroup::SPECIAL },
147 { GID_IMAGE , com::sun::star::frame::CommandGroup::IMAGE },
148 { GID_CHART , com::sun::star::frame::CommandGroup::CHART },
149 { GID_EXPLORER , com::sun::star::frame::CommandGroup::EXPLORER },
150 { GID_CONNECTOR , com::sun::star::frame::CommandGroup::CONNECTOR },
151 { GID_MODIFY , com::sun::star::frame::CommandGroup::MODIFY },
152 { GID_DRAWING , com::sun::star::frame::CommandGroup::DRAWING },
153 { GID_CONTROLS , com::sun::star::frame::CommandGroup::CONTROLS },
154 { 0 , 0 }
157 typedef std::hash_map< sal_Int16, sal_Int16 > GroupHashMap;
160 sal_Int16 MapGroupIDToCommandGroup( sal_Int16 nGroupID )
162 static GroupHashMap mHashMap;
164 if ( !bGroupIDMapInitialized )
166 sal_Int32 i = 0;
167 while ( GroupIDCommandGroupMap[i].nGroupID != 0 )
169 mHashMap.insert( GroupHashMap::value_type(
170 GroupIDCommandGroupMap[i].nGroupID,
171 GroupIDCommandGroupMap[i].nCommandGroup ));
172 ++i;
176 GroupHashMap::const_iterator pIter = mHashMap.find( nGroupID );
177 if ( pIter != mHashMap.end() )
178 return pIter->second;
179 else
180 return com::sun::star::frame::CommandGroup::INTERNAL;
183 sal_Int16 MapCommandGroupToGroupID( sal_Int16 nCommandGroup )
185 sal_Int32 i = 0;
186 while ( GroupIDCommandGroupMap[i].nGroupID != 0 )
188 if ( GroupIDCommandGroupMap[i].nCommandGroup == nCommandGroup )
189 return GroupIDCommandGroupMap[i].nGroupID;
190 ++i;
193 return -1;
196 sal_Bool SupportsCommandGroup( sal_Int16 nCommandGroup )
198 if (( nCommandGroup >= 0 ) && ( nCommandGroup <= MAX_COMMANDGROUP ))
199 return sal_True;
200 else
201 return sal_False;
204 sal_uInt32 Get10ThSec()
206 sal_uInt32 n10Ticks = 10 * (sal_uInt32)clock();
207 return n10Ticks / CLOCKS_PER_SEC;
210 sal_Int32 m_nInReschedule = 0; /// static counter for rescheduling
212 void reschedule()
214 if ( m_nInReschedule == 0 )
216 ++m_nInReschedule;
217 Application::Reschedule();
218 --m_nInReschedule;
222 class SfxStatusIndicator : public ::cppu::WeakImplHelper2< ::com::sun::star::task::XStatusIndicator, ::com::sun::star::lang::XEventListener >
224 friend class SfxBaseController;
225 ::com::sun::star::uno::Reference < XCONTROLLER > xOwner;
226 ::com::sun::star::uno::Reference < ::com::sun::star::task::XStatusIndicator > xProgress;
227 SfxWorkWindow* pWorkWindow;
228 sal_Int32 _nRange;
229 sal_Int32 _nValue;
230 long _nStartTime;
231 public:
232 SfxStatusIndicator(SfxBaseController* pController, SfxWorkWindow* pWork)
233 : xOwner( pController )
234 , pWorkWindow( pWork )
236 ++m_refCount;
237 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComponent(
238 SAL_STATIC_CAST(::cppu::OWeakObject*, pController ), ::com::sun::star::uno::UNO_QUERY );
239 if (xComponent.is())
240 xComponent->addEventListener(this);
241 --m_refCount;
244 virtual void SAL_CALL start(const ::rtl::OUString& aText, sal_Int32 nRange) throw(::com::sun::star::uno::RuntimeException);
245 virtual void SAL_CALL end(void) throw(::com::sun::star::uno::RuntimeException);
246 virtual void SAL_CALL setText(const ::rtl::OUString& aText) throw(::com::sun::star::uno::RuntimeException);
247 virtual void SAL_CALL setValue(sal_Int32 nValue) throw(::com::sun::star::uno::RuntimeException);
248 virtual void SAL_CALL reset() throw(::com::sun::star::uno::RuntimeException);
250 virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
253 void SAL_CALL SfxStatusIndicator::start(const ::rtl::OUString& aText, sal_Int32 nRange) throw(::com::sun::star::uno::RuntimeException)
255 ::vos::OGuard aGuard( Application::GetSolarMutex() );
256 if ( xOwner.is() )
258 _nRange = nRange;
259 _nValue = 0;
261 if ( !xProgress.is() )
262 xProgress = pWorkWindow->GetStatusIndicator();
264 if ( xProgress.is() )
265 xProgress->start( aText, nRange );
267 _nStartTime = Get10ThSec();
268 reschedule();
272 void SAL_CALL SfxStatusIndicator::end(void) throw(::com::sun::star::uno::RuntimeException)
274 ::vos::OGuard aGuard( Application::GetSolarMutex() );
275 if ( xOwner.is() )
277 if ( !xProgress.is() )
278 xProgress = pWorkWindow->GetStatusIndicator();
280 if ( xProgress.is() )
281 xProgress->end();
283 reschedule();
287 void SAL_CALL SfxStatusIndicator::setText(const ::rtl::OUString& aText) throw(::com::sun::star::uno::RuntimeException)
289 ::vos::OGuard aGuard( Application::GetSolarMutex() );
290 if ( xOwner.is() )
292 if ( !xProgress.is() )
293 xProgress = pWorkWindow->GetStatusIndicator();
295 if ( xProgress.is() )
296 xProgress->setText( aText );
298 reschedule();
302 void SAL_CALL SfxStatusIndicator::setValue( sal_Int32 nValue ) throw(::com::sun::star::uno::RuntimeException)
304 ::vos::OGuard aGuard( Application::GetSolarMutex() );
305 if ( xOwner.is() )
307 _nValue = nValue;
309 if ( !xProgress.is() )
310 xProgress = pWorkWindow->GetStatusIndicator();
312 if ( xProgress.is() )
313 xProgress->setValue( nValue );
315 sal_Bool bReschedule = (( Get10ThSec() - _nStartTime ) > TIMEOUT_START_RESCHEDULE );
316 if ( bReschedule )
317 reschedule();
321 void SAL_CALL SfxStatusIndicator::reset() throw(::com::sun::star::uno::RuntimeException)
323 ::vos::OGuard aGuard( Application::GetSolarMutex() );
324 if ( xOwner.is() )
326 if ( !xProgress.is() )
327 xProgress = pWorkWindow->GetStatusIndicator();
329 if ( xProgress.is() )
330 xProgress->reset();
332 reschedule();
336 void SAL_CALL SfxStatusIndicator::disposing( const com::sun::star::lang::EventObject& /*Source*/ ) throw(::com::sun::star::uno::RuntimeException)
338 ::vos::OGuard aGuard( Application::GetSolarMutex() );
339 xOwner = 0;
340 xProgress.clear();
343 //________________________________________________________________________________________________________
344 //________________________________________________________________________________________________________
345 // declaration IMPL_SfxBaseController_ListenerHelper
346 //________________________________________________________________________________________________________
348 class IMPL_SfxBaseController_ListenerHelper : public ::cppu::WeakImplHelper1< ::com::sun::star::frame::XFrameActionListener >
350 public:
351 IMPL_SfxBaseController_ListenerHelper( MUTEX& aMutex ,
352 SfxBaseController* pController ) ;
353 virtual ~IMPL_SfxBaseController_ListenerHelper() ;
354 virtual void SAL_CALL frameAction( const FRAMEACTIONEVENT& aEvent ) throw (RUNTIMEEXCEPTION) ;
355 virtual void SAL_CALL disposing( const EVENTOBJECT& aEvent ) throw (RUNTIMEEXCEPTION) ;
357 private:
359 MUTEX& m_aMutex ;
360 SfxBaseController* m_pController ;
362 } ; // class IMPL_SfxBaseController_ListenerContainer
364 class IMPL_SfxBaseController_CloseListenerHelper : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XCloseListener >
366 public:
367 IMPL_SfxBaseController_CloseListenerHelper( MUTEX& aMutex ,
368 SfxBaseController* pController ) ;
369 virtual ~IMPL_SfxBaseController_CloseListenerHelper() ;
370 virtual void SAL_CALL queryClosing( const EVENTOBJECT& aEvent, sal_Bool bDeliverOwnership )
371 throw (RUNTIMEEXCEPTION, com::sun::star::util::CloseVetoException) ;
372 virtual void SAL_CALL notifyClosing( const EVENTOBJECT& aEvent ) throw (RUNTIMEEXCEPTION) ;
373 virtual void SAL_CALL disposing( const EVENTOBJECT& aEvent ) throw (RUNTIMEEXCEPTION) ;
375 private:
377 MUTEX& m_aMutex;
378 SfxBaseController* m_pController;
380 } ; // class IMPL_SfxBaseController_ListenerContainer
382 IMPL_SfxBaseController_CloseListenerHelper::IMPL_SfxBaseController_CloseListenerHelper( MUTEX& aMutex ,
383 SfxBaseController* pController )
384 : m_aMutex ( aMutex )
385 , m_pController ( pController )
389 IMPL_SfxBaseController_CloseListenerHelper::~IMPL_SfxBaseController_CloseListenerHelper()
393 void SAL_CALL IMPL_SfxBaseController_CloseListenerHelper::disposing( const EVENTOBJECT& /*aEvent*/ ) throw( ::com::sun::star::uno::RuntimeException )
397 void SAL_CALL IMPL_SfxBaseController_CloseListenerHelper::queryClosing( const EVENTOBJECT& aEvent, sal_Bool bDeliverOwnership )
398 throw (RUNTIMEEXCEPTION, com::sun::star::util::CloseVetoException)
400 ::vos::OGuard aGuard( Application::GetSolarMutex() );
401 SfxViewShell* pShell = m_pController->GetViewShell_Impl();
402 if ( m_pController != NULL && pShell )
404 BOOL bCanClose = (BOOL) pShell->PrepareClose( FALSE );
405 if ( !bCanClose )
407 if ( bDeliverOwnership && ( !pShell->GetWindow() || !pShell->GetWindow()->IsReallyVisible() ) )
409 // ignore OwnerShip in case of visible frame (will be closed by user)
410 uno::Reference < frame::XModel > xModel( aEvent.Source, uno::UNO_QUERY );
411 if ( xModel.is() )
412 pShell->TakeOwnerShip_Impl();
413 else
414 pShell->TakeFrameOwnerShip_Impl();
417 throw com::sun::star::util::CloseVetoException(::rtl::OUString::createFromAscii("Controller disagree ..."),static_cast< ::cppu::OWeakObject*>(this));
422 void SAL_CALL IMPL_SfxBaseController_CloseListenerHelper::notifyClosing( const EVENTOBJECT& /*aEvent*/ ) throw (RUNTIMEEXCEPTION)
426 //________________________________________________________________________________________________________
427 // declaration IMPL_SfxBaseController_DataContainer
428 //________________________________________________________________________________________________________
430 struct IMPL_SfxBaseController_DataContainer
432 REFERENCE < XFRAME > m_xFrame;
433 REFERENCE < XFRAMEACTIONLISTENER > m_xListener ;
434 REFERENCE < XCLOSELISTENER > m_xCloseListener ;
435 ::sfx2::UserInputInterception m_aUserInputInterception;
436 OMULTITYPEINTERFACECONTAINERHELPER m_aListenerContainer ;
437 OINTERFACECONTAINERHELPER m_aInterceptorContainer ;
438 REFERENCE < ::com::sun::star::task::XStatusIndicator > m_xIndicator;
439 SfxViewShell* m_pViewShell ;
440 SfxBaseController* m_pController ;
441 sal_Bool m_bDisposing ;
442 sal_Bool m_bSuspendState;
443 /** When this flag is <true/> (the default) then in dispose() the frame
444 and with it the view shell are released together with the
445 controller.
446 A derived class can set the flag to <false/> when it wants to
447 exchange controllers that work on the same view shell. One
448 application is the Impress Multi Pane GUI that changes shells that
449 are stacked on one view shell. Controllers are associated with the
450 stacked shells and thus must not destroy the view shell which is not
451 affected by the switching.
453 sal_Bool m_bIsFrameReleasedWithController;
454 css::uno::Reference< css::frame::XTitle > m_xTitleHelper;
456 IMPL_SfxBaseController_DataContainer( MUTEX& aMutex ,
457 SfxViewShell* pViewShell ,
458 SfxBaseController* pController )
459 : m_xListener ( new IMPL_SfxBaseController_ListenerHelper( aMutex, pController ) )
460 , m_xCloseListener ( new IMPL_SfxBaseController_CloseListenerHelper( aMutex, pController ) )
461 , m_aUserInputInterception ( *pController, aMutex )
462 , m_aListenerContainer ( aMutex )
463 , m_aInterceptorContainer ( aMutex )
464 , m_pViewShell ( pViewShell )
465 , m_pController ( pController )
466 , m_bDisposing ( sal_False )
467 , m_bSuspendState ( sal_False )
468 , m_bIsFrameReleasedWithController( sal_True )
472 } ; // struct IMPL_SfxBaseController_DataContainer
474 //________________________________________________________________________________________________________
475 // IMPL_SfxBaseController_ListenerHelper constructor
476 //________________________________________________________________________________________________________
478 IMPL_SfxBaseController_ListenerHelper::IMPL_SfxBaseController_ListenerHelper( MUTEX& aMutex ,
479 SfxBaseController* pController )
480 : m_aMutex ( aMutex )
481 , m_pController ( pController )
485 //________________________________________________________________________________________________________
486 // IMPL_SfxBaseController_ListenerHelper destructor
487 //________________________________________________________________________________________________________
489 IMPL_SfxBaseController_ListenerHelper::~IMPL_SfxBaseController_ListenerHelper()
493 void SAL_CALL IMPL_SfxBaseController_ListenerHelper::frameAction( const FRAMEACTIONEVENT& aEvent ) throw( RUNTIMEEXCEPTION )
495 ::vos::OGuard aGuard( Application::GetSolarMutex() );
496 if (
497 ( m_pController != NULL ) &&
498 ( aEvent.Frame == m_pController->getFrame() ) &&
499 ( m_pController->GetViewShell_Impl() && m_pController->GetViewShell_Impl()->GetWindow() != NULL )
502 if ( aEvent.Action == ::com::sun::star::frame::FrameAction_FRAME_UI_ACTIVATED )
504 if ( !m_pController->GetViewShell_Impl()->GetUIActiveIPClient_Impl() )
505 m_pController->GetViewShell_Impl()->GetViewFrame()->MakeActive_Impl( FALSE );
507 else if ( aEvent.Action == ::com::sun::star::frame::FrameAction_CONTEXT_CHANGED )
509 m_pController->GetViewShell_Impl()->GetViewFrame()->GetBindings().ContextChanged_Impl();
514 //________________________________________________________________________________________________________
515 // IMPL_SfxBaseController_ListenerHelper -> XEventListener
516 //________________________________________________________________________________________________________
518 void SAL_CALL IMPL_SfxBaseController_ListenerHelper::disposing( const EVENTOBJECT& /*aEvent*/ ) throw( ::com::sun::star::uno::RuntimeException )
520 ::vos::OGuard aGuard( Application::GetSolarMutex() );
521 if ( m_pController && m_pController->getFrame().is() )
522 m_pController->getFrame()->removeFrameActionListener( this ) ;
525 //________________________________________________________________________________________________________
526 // SfxBaseController -> constructor
527 //________________________________________________________________________________________________________
528 DBG_NAME(sfx2_SfxBaseController)
529 SfxBaseController::SfxBaseController( SfxViewShell* pViewShell )
530 : IMPL_SfxBaseController_MutexContainer ( )
531 , m_pData ( new IMPL_SfxBaseController_DataContainer( m_aMutex, pViewShell, this ))
533 DBG_CTOR(sfx2_SfxBaseController,NULL);
534 m_pData->m_pViewShell->SetController( this );
537 //________________________________________________________________________________________________________
538 // SfxBaseController -> destructor
539 //________________________________________________________________________________________________________
541 SfxBaseController::~SfxBaseController()
543 DBG_DTOR(sfx2_SfxBaseController,NULL);
544 delete m_pData;
547 //________________________________________________________________________________________________________
548 // SfxBaseController -> XInterface
549 //________________________________________________________________________________________________________
550 ANY SAL_CALL SfxBaseController::queryInterface( const UNOTYPE& rType ) throw( RUNTIMEEXCEPTION )
552 // Attention:
553 // Don't use mutex or guard in this method!!! Is a method of XInterface.
555 // Ask for my own supported interfaces ...
556 ANY aReturn( ::cppu::queryInterface( rType ,
557 static_cast< XTYPEPROVIDER* > ( this ) ,
558 static_cast< XCOMPONENT* > ( this ) ,
559 static_cast< XCONTROLLER* > ( this ) ,
560 static_cast< XCONTROLLERBORDER* > ( this ) ,
561 static_cast< XUSERINPUTINTERCEPTION* > ( this ) ,
562 static_cast< XSTATUSINDICATORSUPPLIER* > ( this ) ,
563 static_cast< XCONTEXTMENUINTERCEPTION* > ( this ) ,
564 static_cast< XDISPATCHPROVIDER* > ( this ),
565 static_cast< XTITLE* > ( this ),
566 static_cast< XTITLECHANGEBROADCASTER* > ( this ),
567 static_cast< XDISPATCHINFORMATIONPROVIDER* > ( this ) ) ) ;
569 // If searched interface supported by this class ...
570 if ( aReturn.hasValue() == sal_True )
572 // ... return this information.
573 return aReturn ;
575 else
577 // Else; ... ask baseclass for interfaces!
578 return OWeakObject::queryInterface( rType ) ;
582 //________________________________________________________________________________________________________
583 // SfxBaseController -> XInterface
584 //________________________________________________________________________________________________________
586 void SAL_CALL SfxBaseController::acquire() throw()
588 // Attention:
589 // Don't use mutex or guard in this method!!! Is a method of XInterface.
591 // Forward to baseclass
592 OWeakObject::acquire() ;
595 //________________________________________________________________________________________________________
596 // SfxBaseController -> XInterface
597 //________________________________________________________________________________________________________
599 void SAL_CALL SfxBaseController::release() throw()
601 // Attention:
602 // Don't use mutex or guard in this method!!! Is a method of XInterface.
604 // Forward to baseclass
605 OWeakObject::release() ;
608 //________________________________________________________________________________________________________
609 // SfxBaseController -> XTypeProvider
610 //________________________________________________________________________________________________________
612 SEQUENCE< UNOTYPE > SAL_CALL SfxBaseController::getTypes() throw( RUNTIMEEXCEPTION )
614 // Optimize this method !
615 // We initialize a static variable only one time. And we don't must use a mutex at every call!
616 // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
617 static OTYPECOLLECTION* pTypeCollection = NULL ;
619 if ( pTypeCollection == NULL )
621 // Ready for multithreading; get global mutex for first call of this method only! see before
622 MUTEXGUARD aGuard( MUTEX::getGlobalMutex() ) ;
624 // Control these pointer again ... it can be, that another instance will be faster then these!
625 if ( pTypeCollection == NULL )
627 // Create a static typecollection ...
628 static OTYPECOLLECTION aTypeCollection( ::getCppuType(( const REFERENCE< XTYPEPROVIDER >*)NULL ) ,
629 ::getCppuType(( const REFERENCE< XCONTROLLER >*)NULL ) ,
630 ::getCppuType(( const REFERENCE< XCONTROLLERBORDER >*)NULL ) ,
631 ::getCppuType(( const REFERENCE< XDISPATCHPROVIDER >*)NULL ) ,
632 ::getCppuType(( const REFERENCE< XSTATUSINDICATORSUPPLIER >*)NULL ) ,
633 ::getCppuType(( const REFERENCE< XCONTEXTMENUINTERCEPTION >*)NULL ) ,
634 ::getCppuType(( const REFERENCE< XUSERINPUTINTERCEPTION >*)NULL ) ,
635 ::getCppuType(( const REFERENCE< XTITLE >*)NULL ) ,
636 ::getCppuType(( const REFERENCE< XTITLECHANGEBROADCASTER >*)NULL ) ,
637 ::getCppuType(( const REFERENCE< XDISPATCHINFORMATIONPROVIDER >*)NULL ) );
638 // ... and set his address to static pointer!
639 pTypeCollection = &aTypeCollection ;
643 return pTypeCollection->getTypes() ;
646 //________________________________________________________________________________________________________
647 // SfxBaseController -> XTypeProvider
648 //________________________________________________________________________________________________________
650 SEQUENCE< sal_Int8 > SAL_CALL SfxBaseController::getImplementationId() throw( RUNTIMEEXCEPTION )
652 // Create one Id for all instances of this class.
653 // Use ethernet address to do this! (sal_True)
655 // Optimize this method
656 // We initialize a static variable only one time. And we don't must use a mutex at every call!
657 // For the first call; pID is NULL - for the second call pID is different from NULL!
658 static OIMPLEMENTATIONID* pID = NULL ;
660 if ( pID == NULL )
662 // Ready for multithreading; get global mutex for first call of this method only! see before
663 MUTEXGUARD aGuard( MUTEX::getGlobalMutex() ) ;
665 // Control these pointer again ... it can be, that another instance will be faster then these!
666 if ( pID == NULL )
668 // Create a new static ID ...
669 static OIMPLEMENTATIONID aID( sal_False ) ;
670 // ... and set his address to static pointer!
671 pID = &aID ;
675 return pID->getImplementationId() ;
678 //________________________________________________________________________________________________________
679 // SfxBaseController -> XController
680 //________________________________________________________________________________________________________
682 void SAL_CALL SfxBaseController::attachFrame( const REFERENCE< XFRAME >& xFrame ) throw( ::com::sun::star::uno::RuntimeException )
684 REFERENCE< XFRAME > xTemp( getFrame() ) ;
686 ::vos::OGuard aGuard( Application::GetSolarMutex() );
687 if ( xTemp.is() )
689 xTemp->removeFrameActionListener( m_pData->m_xListener ) ;
690 REFERENCE < ::com::sun::star::util::XCloseBroadcaster > xCloseable( xTemp, com::sun::star::uno::UNO_QUERY );
691 if ( xCloseable.is() )
692 xCloseable->removeCloseListener( m_pData->m_xCloseListener );
695 m_pData->m_xFrame = xFrame;
697 if ( xFrame.is() )
699 xFrame->addFrameActionListener( m_pData->m_xListener ) ;
700 REFERENCE < ::com::sun::star::util::XCloseBroadcaster > xCloseable( xFrame, com::sun::star::uno::UNO_QUERY );
701 if ( xCloseable.is() )
702 xCloseable->addCloseListener( m_pData->m_xCloseListener );
704 if ( m_pData->m_pViewShell )
706 SfxViewFrame* pActFrame = m_pData->m_pViewShell->GetFrame() ;
707 pActFrame->Enable( TRUE );
708 pActFrame->GetDispatcher()->Lock( FALSE );
713 //________________________________________________________________________________________________________
714 // SfxBaseController -> XController
715 //________________________________________________________________________________________________________
717 sal_Bool SAL_CALL SfxBaseController::attachModel( const REFERENCE< XMODEL >& xModel ) throw( ::com::sun::star::uno::RuntimeException )
719 if ( m_pData->m_pViewShell && xModel.is() && xModel != m_pData->m_pViewShell->GetObjectShell()->GetModel() )
721 // don't allow to reattach a model!
722 DBG_ERROR("Can't reattach model!");
723 return sal_False;
726 REFERENCE < ::com::sun::star::util::XCloseBroadcaster > xCloseable( xModel, com::sun::star::uno::UNO_QUERY );
727 if ( xCloseable.is() )
728 xCloseable->addCloseListener( m_pData->m_xCloseListener );
729 return sal_True;
732 //________________________________________________________________________________________________________
733 // SfxBaseController -> XController
734 //________________________________________________________________________________________________________
736 sal_Bool SAL_CALL SfxBaseController::suspend( sal_Bool bSuspend ) throw( ::com::sun::star::uno::RuntimeException )
738 ::vos::OGuard aGuard( Application::GetSolarMutex() );
740 // ignore dublicate calls, which doesnt change anything real
741 if (bSuspend == m_pData->m_bSuspendState)
742 return sal_True;
744 if ( bSuspend == sal_True )
746 if ( !m_pData->m_pViewShell )
748 m_pData->m_bSuspendState = sal_True;
749 return sal_True;
752 if ( !m_pData->m_pViewShell->PrepareClose() )
753 return sal_False;
755 if ( getFrame().is() )
756 getFrame()->removeFrameActionListener( m_pData->m_xListener ) ;
757 SfxViewFrame* pActFrame = m_pData->m_pViewShell->GetFrame() ;
759 // weitere View auf dasselbe Doc?
760 SfxObjectShell* pDocShell = m_pData->m_pViewShell->GetObjectShell() ;
761 sal_Bool bOther = sal_False ;
763 for ( const SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell ); !bOther && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell ) )
764 bOther = (pFrame != pActFrame);
766 BOOL bRet = bOther || pDocShell->PrepareClose();
767 if ( bRet )
769 // disable window and dispatcher until suspend call is withdrawn
770 pActFrame->Enable( FALSE );
771 pActFrame->GetDispatcher()->Lock( TRUE );
772 m_pData->m_bSuspendState = sal_True;
775 return bRet;
777 else
779 if ( getFrame().is() )
780 getFrame()->addFrameActionListener( m_pData->m_xListener ) ;
782 if ( m_pData->m_pViewShell )
784 SfxViewFrame* pActFrame = m_pData->m_pViewShell->GetFrame() ;
785 pActFrame->Enable( TRUE );
786 pActFrame->GetDispatcher()->Lock( FALSE );
789 m_pData->m_bSuspendState = sal_False;
790 return sal_True ;
794 //________________________________________________________________________________________________________
795 // SfxBaseController -> XController
796 //________________________________________________________________________________________________________
798 ANY SfxBaseController::getViewData() throw( ::com::sun::star::uno::RuntimeException )
800 ANY aAny;
801 String sData1;
802 ::vos::OGuard aGuard( Application::GetSolarMutex() );
803 if ( m_pData->m_pViewShell )
805 m_pData->m_pViewShell->WriteUserData( sData1 ) ;
806 OUSTRING sData( sData1 );
807 aAny <<= sData ;
810 return aAny ;
813 //________________________________________________________________________________________________________
814 // SfxBaseController -> XController
815 //________________________________________________________________________________________________________
817 void SAL_CALL SfxBaseController::restoreViewData( const ANY& aValue ) throw( ::com::sun::star::uno::RuntimeException )
819 ::vos::OGuard aGuard( Application::GetSolarMutex() );
820 if ( m_pData->m_pViewShell )
822 OUSTRING sData;
823 aValue >>= sData ;
824 m_pData->m_pViewShell->ReadUserData( sData ) ;
828 //________________________________________________________________________________________________________
829 // SfxBaseController -> XController
830 //________________________________________________________________________________________________________
832 REFERENCE< XFRAME > SAL_CALL SfxBaseController::getFrame() throw( ::com::sun::star::uno::RuntimeException )
834 ::vos::OGuard aGuard( Application::GetSolarMutex() );
835 return m_pData->m_xFrame;
838 //________________________________________________________________________________________________________
839 // SfxBaseController -> XController
840 //________________________________________________________________________________________________________
842 REFERENCE< XMODEL > SAL_CALL SfxBaseController::getModel() throw( ::com::sun::star::uno::RuntimeException )
844 ::vos::OGuard aGuard( Application::GetSolarMutex() );
845 return m_pData->m_pViewShell ? m_pData->m_pViewShell->GetObjectShell()->GetModel() : REFERENCE < XMODEL > () ;
848 //________________________________________________________________________________________________________
849 // SfxBaseController -> XDispatchProvider
850 //________________________________________________________________________________________________________
852 REFERENCE< XDISPATCH > SAL_CALL SfxBaseController::queryDispatch( const UNOURL& aURL ,
853 const OUSTRING& sTargetFrameName,
854 sal_Int32 eSearchFlags ) throw( RUNTIMEEXCEPTION )
856 ::vos::OGuard aGuard( Application::GetSolarMutex() );
857 REFERENCE< XDISPATCH > xDisp;
858 if ( m_pData->m_pViewShell )
860 SfxViewFrame* pAct = m_pData->m_pViewShell->GetViewFrame() ;
861 if ( !m_pData->m_bDisposing )
863 if ( sTargetFrameName.compareToAscii( "_beamer" ) == COMPARE_EQUAL )
865 SfxViewFrame *pFrame = m_pData->m_pViewShell->GetViewFrame();
866 if ( eSearchFlags & ( ::com::sun::star::frame::FrameSearchFlag::CREATE ))
867 pFrame->SetChildWindow( SID_BROWSER, TRUE );
868 SfxChildWindow* pChildWin = pFrame->GetChildWindow( SID_BROWSER );
869 REFERENCE < XFRAME > xFrame;
870 if ( pChildWin )
871 xFrame = ( pChildWin->GetFrame() );
872 if ( xFrame.is() )
873 xFrame->setName( sTargetFrameName );
875 REFERENCE < XDISPATCHPROVIDER > xProv( xFrame, ::com::sun::star::uno::UNO_QUERY );
876 if ( xProv.is() )
877 return xProv->queryDispatch( aURL, sTargetFrameName, ::com::sun::star::frame::FrameSearchFlag::SELF );
880 if ( aURL.Protocol.compareToAscii( ".uno:" ) == COMPARE_EQUAL )
882 rtl::OUString aMasterCommand = SfxOfficeDispatch::GetMasterUnoCommand( aURL );
883 sal_Bool bMasterCommand( aMasterCommand.getLength() > 0 );
885 pAct = m_pData->m_pViewShell->GetViewFrame() ;
886 SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool( pAct );
888 const SfxSlot* pSlot( 0 );
889 if ( bMasterCommand )
890 pSlot = rSlotPool.GetUnoSlot( aMasterCommand );
891 else
892 pSlot = rSlotPool.GetUnoSlot( aURL.Path );
893 if ( pSlot && ( !pAct->GetFrame()->IsInPlace() || !pSlot->IsMode( SFX_SLOT_CONTAINER ) ) )
894 return pAct->GetBindings().GetDispatch( pSlot, aURL, bMasterCommand );
895 else
897 // try to find parent SfxViewFrame
898 uno::Reference< frame::XFrame > xParentFrame;
899 uno::Reference< frame::XFrame > xOwnFrame = pAct->GetFrame()->GetFrameInterface();
900 if ( xOwnFrame.is() )
901 xParentFrame = uno::Reference< frame::XFrame >( xOwnFrame->getCreator(), uno::UNO_QUERY );
903 if ( xParentFrame.is() )
905 // TODO/LATER: in future probably SfxViewFrame hirarchy should be the same as XFrame hirarchy
906 // SfxViewFrame* pParentFrame = pAct->GetParentViewFrame();
908 // search the related SfxViewFrame
909 SfxViewFrame* pParentFrame = NULL;
910 for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst();
911 pFrame;
912 pFrame = SfxViewFrame::GetNext( *pFrame ) )
914 if ( pFrame->GetFrame()->GetFrameInterface() == xParentFrame )
916 pParentFrame = pFrame;
917 break;
921 if ( pParentFrame )
923 SfxSlotPool& rFrameSlotPool = SfxSlotPool::GetSlotPool( pParentFrame );
924 const SfxSlot* pSlot2( 0 );
925 if ( bMasterCommand )
926 pSlot2 = rFrameSlotPool.GetUnoSlot( aMasterCommand );
927 else
928 pSlot2 = rFrameSlotPool.GetUnoSlot( aURL.Path );
930 if ( pSlot2 )
931 return pParentFrame->GetBindings().GetDispatch( pSlot2, aURL, bMasterCommand );
936 else if ( aURL.Protocol.compareToAscii( "slot:" ) == COMPARE_EQUAL )
938 USHORT nId = (USHORT) aURL.Path.toInt32();
940 pAct = m_pData->m_pViewShell->GetViewFrame() ;
941 if (nId >= SID_VERB_START && nId <= SID_VERB_END)
943 const SfxSlot* pSlot = m_pData->m_pViewShell->GetVerbSlot_Impl(nId);
944 if ( pSlot )
945 return pAct->GetBindings().GetDispatch( pSlot, aURL, sal_False );
948 SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool( pAct );
949 const SfxSlot* pSlot = rSlotPool.GetSlot( nId );
950 if ( pSlot && ( !pAct->GetFrame()->IsInPlace() || !pSlot->IsMode( SFX_SLOT_CONTAINER ) ) )
951 return pAct->GetBindings().GetDispatch( pSlot, aURL, sal_False );
952 else
954 // try to find parent SfxViewFrame
955 uno::Reference< frame::XFrame > xParentFrame;
956 uno::Reference< frame::XFrame > xOwnFrame = pAct->GetFrame()->GetFrameInterface();
957 if ( xOwnFrame.is() )
958 xParentFrame = uno::Reference< frame::XFrame >( xOwnFrame->getCreator(), uno::UNO_QUERY );
960 if ( xParentFrame.is() )
962 // TODO/LATER: in future probably SfxViewFrame hirarchy should be the same as XFrame hirarchy
963 // SfxViewFrame* pParentFrame = pAct->GetParentViewFrame();
965 // search the related SfxViewFrame
966 SfxViewFrame* pParentFrame = NULL;
967 for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst();
968 pFrame;
969 pFrame = SfxViewFrame::GetNext( *pFrame ) )
971 if ( pFrame->GetFrame()->GetFrameInterface() == xParentFrame )
973 pParentFrame = pFrame;
974 break;
978 if ( pParentFrame )
980 SfxSlotPool& rSlotPool2 = SfxSlotPool::GetSlotPool( pParentFrame );
981 const SfxSlot* pSlot2 = rSlotPool2.GetUnoSlot( aURL.Path );
982 if ( pSlot2 )
983 return pParentFrame->GetBindings().GetDispatch( pSlot2, aURL, sal_False );
988 else if( sTargetFrameName.compareToAscii( "_self" )==COMPARE_EQUAL || sTargetFrameName.getLength()==0 )
990 // check for already loaded URL ... but with additional jumpmark!
991 REFERENCE< XMODEL > xModel = getModel();
992 if( xModel.is() && aURL.Mark.getLength() )
994 SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool( pAct );
995 const SfxSlot* pSlot = rSlotPool.GetSlot( SID_JUMPTOMARK );
996 if( aURL.Main.getLength() && aURL.Main == xModel->getURL() && pSlot )
997 return REFERENCE< XDISPATCH >( new SfxOfficeDispatch( pAct->GetBindings(), pAct->GetDispatcher(), pSlot, aURL) );
1003 return xDisp;
1006 //________________________________________________________________________________________________________
1007 // SfxBaseController -> XDispatchProvider
1008 //________________________________________________________________________________________________________
1010 SEQUENCE< REFERENCE< XDISPATCH > > SAL_CALL SfxBaseController::queryDispatches( const SEQUENCE< DISPATCHDESCRIPTOR >& seqDescripts ) throw( ::com::sun::star::uno::RuntimeException )
1012 // Create return list - which must have same size then the given descriptor
1013 // It's not allowed to pack it!
1014 sal_Int32 nCount = seqDescripts.getLength();
1015 SEQUENCE< REFERENCE< XDISPATCH > > lDispatcher( nCount );
1017 for( sal_Int32 i=0; i<nCount; ++i )
1019 lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL ,
1020 seqDescripts[i].FrameName ,
1021 seqDescripts[i].SearchFlags );
1024 return lDispatcher;
1027 //________________________________________________________________________________________________________
1028 // SfxBaseController -> XControllerBorder
1029 //________________________________________________________________________________________________________
1031 frame::BorderWidths SAL_CALL SfxBaseController::getBorder()
1032 throw ( uno::RuntimeException )
1034 frame::BorderWidths aResult;
1036 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1037 if ( m_pData->m_pViewShell )
1039 SvBorder aBorder = m_pData->m_pViewShell->GetBorderPixel();
1040 aResult.Left = aBorder.Left();
1041 aResult.Top = aBorder.Top();
1042 aResult.Right = aBorder.Right();
1043 aResult.Bottom = aBorder.Bottom();
1046 return aResult;
1049 void SAL_CALL SfxBaseController::addBorderResizeListener( const uno::Reference< frame::XBorderResizeListener >& xListener )
1050 throw ( uno::RuntimeException )
1052 m_pData->m_aListenerContainer.addInterface( ::getCppuType((const uno::Reference< frame::XBorderResizeListener >*)0),
1053 xListener );
1056 void SAL_CALL SfxBaseController::removeBorderResizeListener( const uno::Reference< frame::XBorderResizeListener >& xListener )
1057 throw ( uno::RuntimeException )
1059 m_pData->m_aListenerContainer.removeInterface( ::getCppuType((const uno::Reference< frame::XBorderResizeListener >*)0),
1060 xListener );
1063 awt::Rectangle SAL_CALL SfxBaseController::queryBorderedArea( const awt::Rectangle& aPreliminaryRectangle )
1064 throw ( uno::RuntimeException )
1066 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1067 if ( m_pData->m_pViewShell )
1069 Rectangle aTmpRect = VCLRectangle( aPreliminaryRectangle );
1070 m_pData->m_pViewShell->QueryObjAreaPixel( aTmpRect );
1071 return AWTRectangle( aTmpRect );
1074 return aPreliminaryRectangle;
1077 void SfxBaseController::BorderWidthsChanged_Impl()
1079 ::cppu::OInterfaceContainerHelper* pContainer = m_pData->m_aListenerContainer.getContainer(
1080 ::getCppuType( ( const uno::Reference< frame::XBorderResizeListener >*) NULL ) );
1081 if ( pContainer )
1083 frame::BorderWidths aBWidths = getBorder();
1084 uno::Reference< uno::XInterface > xThis( static_cast< ::cppu::OWeakObject* >(this), uno::UNO_QUERY );
1086 ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
1087 while (pIterator.hasMoreElements())
1091 ((frame::XBorderResizeListener*)pIterator.next())->borderWidthsChanged( xThis, aBWidths );
1093 catch( uno::RuntimeException& )
1095 pIterator.remove();
1101 //________________________________________________________________________________________________________
1102 // SfxBaseController -> XComponent
1103 //________________________________________________________________________________________________________
1105 void SfxBaseController::FrameIsReleasedWithController (sal_Bool bFlag)
1107 m_pData->m_bIsFrameReleasedWithController = bFlag;
1110 void SAL_CALL SfxBaseController::dispose() throw( ::com::sun::star::uno::RuntimeException )
1112 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1113 REFERENCE < XCONTROLLER > xTmp( this );
1114 m_pData->m_bDisposing = sal_True ;
1116 EVENTOBJECT aEventObject;
1117 aEventObject.Source = (XCONTROLLER*)this ;
1118 m_pData->m_aListenerContainer.disposeAndClear( aEventObject ) ;
1120 if ( m_pData->m_pController && m_pData->m_pController->getFrame().is() )
1121 m_pData->m_pController->getFrame()->removeFrameActionListener( m_pData->m_xListener ) ;
1123 if ( m_pData->m_pViewShell )
1125 SfxViewFrame* pFrame = m_pData->m_pViewShell->GetViewFrame() ;
1126 if (m_pData->m_bIsFrameReleasedWithController)
1128 if ( pFrame && pFrame->GetViewShell() == m_pData->m_pViewShell )
1129 pFrame->GetFrame()->SetIsClosing_Impl();
1130 m_pData->m_pViewShell->DiscardClients_Impl();
1131 m_pData->m_pViewShell->pImp->bControllerSet = sal_False ;
1134 if ( pFrame )
1136 EVENTOBJECT aObject;
1137 aObject.Source = (OWEAKOBJECT*)this ;
1139 SfxObjectShell* pDoc = pFrame->GetObjectShell() ;
1140 SfxViewFrame *pView = SfxViewFrame::GetFirst(pDoc);
1141 while( pView )
1143 // if there is another ViewFrame or currently the ViewShell in my ViewFrame is switched (PagePreview)
1144 if ( pView != pFrame || pView->GetViewShell() != m_pData->m_pViewShell )
1145 break;
1146 pView = SfxViewFrame::GetNext( *pView, pDoc );
1149 if ( m_pData->m_bIsFrameReleasedWithController )
1151 SFX_APP()->NotifyEvent( SfxEventHint(SFX_EVENT_CLOSEVIEW, GlobalEventConfig::GetEventName( STR_EVENT_CLOSEVIEW ), pDoc ) );
1152 if ( !pView )
1153 SFX_APP()->NotifyEvent( SfxEventHint(SFX_EVENT_CLOSEDOC, GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ), pDoc) );
1156 REFERENCE< XMODEL > xModel = pDoc->GetModel();
1157 REFERENCE < ::com::sun::star::util::XCloseable > xCloseable( xModel, com::sun::star::uno::UNO_QUERY );
1158 if ( xModel.is() )
1160 xModel->disconnectController( this );
1161 if ( xCloseable.is() )
1162 xCloseable->removeCloseListener( m_pData->m_xCloseListener );
1165 REFERENCE < XFRAME > aXFrame;
1166 attachFrame( aXFrame );
1168 m_pData->m_xListener->disposing( aObject );
1169 SfxViewShell *pShell = m_pData->m_pViewShell;
1170 m_pData->m_pViewShell = NULL;
1171 if ( pFrame->GetViewShell() == pShell
1172 && m_pData->m_bIsFrameReleasedWithController)
1174 // Enter registrations only allowed if we are the owner!
1175 if ( pFrame->GetFrame()->OwnsBindings_Impl() )
1176 pFrame->GetBindings().ENTERREGISTRATIONS();
1177 pFrame->GetFrame()->SetFrameInterface_Impl( aXFrame );
1178 pFrame->GetFrame()->DoClose_Impl();
1184 //________________________________________________________________________________________________________
1185 // SfxBaseController -> XComponent
1186 //________________________________________________________________________________________________________
1188 void SAL_CALL SfxBaseController::addEventListener( const REFERENCE< XEVENTLISTENER >& aListener ) throw( ::com::sun::star::uno::RuntimeException )
1190 m_pData->m_aListenerContainer.addInterface( ::getCppuType((const REFERENCE< XEVENTLISTENER >*)0), aListener );
1193 //________________________________________________________________________________________________________
1194 // SfxBaseController -> XComponent
1195 //________________________________________________________________________________________________________
1197 void SAL_CALL SfxBaseController::removeEventListener( const REFERENCE< XEVENTLISTENER >& aListener ) throw( ::com::sun::star::uno::RuntimeException )
1199 m_pData->m_aListenerContainer.removeInterface( ::getCppuType((const REFERENCE< XEVENTLISTENER >*)0), aListener );
1202 void SfxBaseController::ReleaseShell_Impl()
1204 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1205 if ( m_pData->m_pViewShell )
1207 SfxObjectShell* pDoc = m_pData->m_pViewShell->GetObjectShell() ;
1208 REFERENCE< XMODEL > xModel = pDoc->GetModel();
1209 REFERENCE < ::com::sun::star::util::XCloseable > xCloseable( xModel, com::sun::star::uno::UNO_QUERY );
1210 if ( xModel.is() )
1212 xModel->disconnectController( this );
1213 if ( xCloseable.is() )
1214 xCloseable->removeCloseListener( m_pData->m_xCloseListener );
1216 m_pData->m_pViewShell = 0;
1218 REFERENCE < XFRAME > aXFrame;
1219 attachFrame( aXFrame );
1223 SfxViewShell* SfxBaseController::GetViewShell_Impl() const
1225 return m_pData->m_pViewShell;
1228 ::com::sun::star::uno::Reference< ::com::sun::star::task::XStatusIndicator > SAL_CALL SfxBaseController::getStatusIndicator( ) throw (::com::sun::star::uno::RuntimeException)
1230 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1231 if ( m_pData->m_pViewShell && !m_pData->m_xIndicator.is() )
1232 m_pData->m_xIndicator = new SfxStatusIndicator( this, m_pData->m_pViewShell->GetViewFrame()->GetFrame()->GetWorkWindow_Impl() );
1233 return m_pData->m_xIndicator;
1236 void SAL_CALL SfxBaseController::registerContextMenuInterceptor( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor ) throw( RUNTIMEEXCEPTION )
1239 m_pData->m_aInterceptorContainer.addInterface( xInterceptor );
1241 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1242 if ( m_pData->m_pViewShell )
1243 m_pData->m_pViewShell->AddContextMenuInterceptor_Impl( xInterceptor );
1246 void SAL_CALL SfxBaseController::releaseContextMenuInterceptor( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor ) throw( RUNTIMEEXCEPTION )
1249 m_pData->m_aInterceptorContainer.removeInterface( xInterceptor );
1251 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1252 if ( m_pData->m_pViewShell )
1253 m_pData->m_pViewShell->RemoveContextMenuInterceptor_Impl( xInterceptor );
1256 void SAL_CALL SfxBaseController::addKeyHandler( const ::com::sun::star::uno::Reference< XKEYHANDLER >& xHandler ) throw (::com::sun::star::uno::RuntimeException)
1258 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1259 m_pData->m_aUserInputInterception.addKeyHandler( xHandler );
1262 void SAL_CALL SfxBaseController::removeKeyHandler( const ::com::sun::star::uno::Reference< XKEYHANDLER >& xHandler ) throw (::com::sun::star::uno::RuntimeException)
1264 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1265 m_pData->m_aUserInputInterception.removeKeyHandler( xHandler );
1268 void SAL_CALL SfxBaseController::addMouseClickHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseClickHandler >& xHandler ) throw (::com::sun::star::uno::RuntimeException)
1270 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1271 m_pData->m_aUserInputInterception.addMouseClickHandler( xHandler );
1274 void SAL_CALL SfxBaseController::removeMouseClickHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseClickHandler >& xHandler ) throw (::com::sun::star::uno::RuntimeException)
1276 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1277 m_pData->m_aUserInputInterception.removeMouseClickHandler( xHandler );
1280 ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL SfxBaseController::getSupportedCommandGroups()
1281 throw (::com::sun::star::uno::RuntimeException)
1283 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1285 std::list< sal_Int16 > aGroupList;
1286 SfxViewFrame* pViewFrame( m_pData->m_pViewShell->GetFrame() );
1287 SfxSlotPool* pPool = &SfxSlotPool::GetSlotPool( pViewFrame );
1289 SfxSlotPool* pSlotPool = pPool ? pPool : &SFX_SLOTPOOL();
1290 const ULONG nMode( SFX_SLOT_TOOLBOXCONFIG|SFX_SLOT_ACCELCONFIG|SFX_SLOT_MENUCONFIG );
1292 // Gruppe anw"ahlen ( Gruppe 0 ist intern )
1293 for ( USHORT i=0; i<pSlotPool->GetGroupCount(); i++ )
1295 String aName = pSlotPool->SeekGroup( i );
1296 const SfxSlot* pSfxSlot = pSlotPool->FirstSlot();
1297 while ( pSfxSlot )
1299 if ( pSfxSlot->GetMode() & nMode )
1301 sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
1302 aGroupList.push_back( nCommandGroup );
1303 break;
1305 pSfxSlot = pSlotPool->NextSlot();
1309 ::com::sun::star::uno::Sequence< sal_Int16 > aSeq =
1310 comphelper::containerToSequence< sal_Int16 >( aGroupList );
1311 return aSeq;
1314 ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchInformation > SAL_CALL SfxBaseController::getConfigurableDispatchInformation( sal_Int16 nCmdGroup )
1315 throw (::com::sun::star::uno::RuntimeException)
1317 std::list< ::com::sun::star::frame::DispatchInformation > aCmdList;
1319 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1320 if ( m_pData->m_pViewShell )
1322 const ULONG nMode( SFX_SLOT_TOOLBOXCONFIG|SFX_SLOT_ACCELCONFIG|SFX_SLOT_MENUCONFIG );
1324 SfxViewFrame* pViewFrame( m_pData->m_pViewShell->GetFrame() );
1325 SfxSlotPool* pPool( &SfxSlotPool::GetSlotPool( pViewFrame ));
1326 rtl::OUString aCmdPrefix( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
1328 SfxSlotPool* pSlotPool = pPool ? pPool : &SFX_SLOTPOOL();
1329 for ( USHORT i=0; i<pSlotPool->GetGroupCount(); i++ )
1331 String aName = pSlotPool->SeekGroup( i );
1332 const SfxSlot* pSfxSlot = pSlotPool->FirstSlot();
1333 if ( pSfxSlot )
1335 sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
1336 if ( nCommandGroup == nCmdGroup )
1338 while ( pSfxSlot )
1340 if ( pSfxSlot->GetMode() & nMode )
1342 ::com::sun::star::frame::DispatchInformation aCmdInfo;
1343 ::rtl::OUStringBuffer aBuf( aCmdPrefix );
1344 aBuf.appendAscii( pSfxSlot->GetUnoName() );
1345 aCmdInfo.Command = aBuf.makeStringAndClear();
1346 aCmdInfo.GroupId = nCommandGroup;
1347 aCmdList.push_back( aCmdInfo );
1349 pSfxSlot = pSlotPool->NextSlot();
1356 ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchInformation > aSeq =
1357 comphelper::containerToSequence< ::com::sun::star::frame::DispatchInformation, std::list< ::com::sun::star::frame::DispatchInformation > >( aCmdList );
1359 return aSeq;
1362 BOOL SfxBaseController::HandleEvent_Impl( NotifyEvent& rEvent )
1364 return m_pData->m_aUserInputInterception.handleNotifyEvent( rEvent );
1367 BOOL SfxBaseController::HasKeyListeners_Impl()
1369 return m_pData->m_aUserInputInterception.hasKeyHandlers();
1372 BOOL SfxBaseController::HasMouseClickListeners_Impl()
1374 return m_pData->m_aUserInputInterception.hasMouseClickListeners();
1377 //=============================================================================
1378 css::uno::Reference< css::frame::XTitle > SfxBaseController::impl_getTitleHelper ()
1380 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1382 if ( ! m_pData->m_xTitleHelper.is ())
1384 css::uno::Reference< css::frame::XModel > xModel = getModel ();
1385 css::uno::Reference< css::frame::XUntitledNumbers > xUntitledProvider(xModel , css::uno::UNO_QUERY );
1386 css::uno::Reference< css::frame::XController > xThis (static_cast< css::frame::XController* >(this), css::uno::UNO_QUERY_THROW);
1388 ::framework::TitleHelper* pHelper = new ::framework::TitleHelper(::comphelper::getProcessServiceFactory());
1389 m_pData->m_xTitleHelper = css::uno::Reference< css::frame::XTitle >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
1391 pHelper->setOwner (xThis );
1392 pHelper->connectWithUntitledNumbers (xUntitledProvider);
1395 return m_pData->m_xTitleHelper;
1398 //=============================================================================
1399 // css::frame::XTitle
1400 ::rtl::OUString SAL_CALL SfxBaseController::getTitle()
1401 throw (css::uno::RuntimeException)
1403 return impl_getTitleHelper()->getTitle ();
1406 //=============================================================================
1407 // css::frame::XTitle
1408 void SAL_CALL SfxBaseController::setTitle(const ::rtl::OUString& sTitle)
1409 throw (css::uno::RuntimeException)
1411 impl_getTitleHelper()->setTitle (sTitle);
1414 //=============================================================================
1415 // css::frame::XTitleChangeBroadcaster
1416 void SAL_CALL SfxBaseController::addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
1417 throw (css::uno::RuntimeException)
1419 css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
1420 if (xBroadcaster.is ())
1421 xBroadcaster->addTitleChangeListener (xListener);
1424 //=============================================================================
1425 // css::frame::XTitleChangeBroadcaster
1426 void SAL_CALL SfxBaseController::removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
1427 throw (css::uno::RuntimeException)
1429 css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
1430 if (xBroadcaster.is ())
1431 xBroadcaster->removeTitleChangeListener (xListener);