1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sfx2.hxx"
26 
27 //________________________________________________________________________________________________________
28 //	my own includes
29 //________________________________________________________________________________________________________
30 
31 #include <time.h>
32 #include <sfx2/sfxbasecontroller.hxx>
33 
34 //________________________________________________________________________________________________________
35 //	include of other projects
36 //________________________________________________________________________________________________________
37 #include <com/sun/star/awt/KeyEvent.hpp>
38 #include <com/sun/star/awt/KeyModifier.hpp>
39 #include <com/sun/star/awt/MouseEvent.hpp>
40 #include <com/sun/star/awt/MouseButton.hpp>
41 #include <com/sun/star/util/XCloseable.hpp>
42 #include <com/sun/star/util/XCloseBroadcaster.hpp>
43 #include <com/sun/star/util/XCloseListener.hpp>
44 #include <com/sun/star/util/CloseVetoException.hpp>
45 #include <com/sun/star/document/XViewDataSupplier.hpp>
46 #include <cppuhelper/implbase1.hxx>
47 #include <cppuhelper/implbase2.hxx>
48 #include <com/sun/star/frame/FrameActionEvent.hpp>
49 #include <com/sun/star/frame/FrameAction.hpp>
50 #include <com/sun/star/frame/CommandGroup.hpp>
51 #include <com/sun/star/frame/XFrame.hpp>
52 #include <com/sun/star/frame/XBorderResizeListener.hpp>
53 #include <com/sun/star/lang/DisposedException.hpp>
54 #include <com/sun/star/lang/EventObject.hpp>
55 #include <com/sun/star/lang/XEventListener.hpp>
56 #include <com/sun/star/lang/XComponent.hpp>
57 #include <com/sun/star/container/XIndexAccess.hpp>
58 #include <cppuhelper/interfacecontainer.hxx>
59 #include <cppuhelper/typeprovider.hxx>
60 #include <cppuhelper/implbase1.hxx>
61 #include <basic/sbstar.hxx>
62 #include <uno/mapping.hxx>
63 #include <sfx2/viewsh.hxx>
64 #include <sfx2/docfac.hxx>
65 #include <sfx2/viewfrm.hxx>
66 #include <sfx2/objsh.hxx>
67 #include <sfx2/app.hxx>
68 #include <sfx2/msgpool.hxx>
69 #include <sfx2/dispatch.hxx>
70 #include <sfx2/userinputinterception.hxx>
71 
72 #include <viewimp.hxx>
73 #include <sfx2/unoctitm.hxx>
74 #include <sfx2/childwin.hxx>
75 #include <sfx2/sfxsids.hrc>
76 #include <workwin.hxx>
77 #include <sfx2/objface.hxx>
78 
79 #include <vos/mutex.hxx>
80 #include <osl/mutex.hxx>
81 #include <tools/diagnose_ex.h>
82 #include <comphelper/sequence.hxx>
83 #include <rtl/ustrbuf.hxx>
84 #include <toolkit/helper/convert.hxx>
85 #include <framework/titlehelper.hxx>
86 #include <comphelper/processfactory.hxx>
87 #include <tools/diagnose_ex.h>
88 
89 #include <hash_map>
90 
91 #include <sfx2/event.hxx>
92 #include "sfx2/viewfac.hxx"
93 
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
110 
111 #define TIMEOUT_START_RESCHEDULE	10L	/* 10th s */
112 
113 using namespace ::com::sun::star;
114 using ::com::sun::star::uno::Reference;
115 using ::com::sun::star::uno::RuntimeException;
116 using ::com::sun::star::uno::UNO_QUERY_THROW;
117 using ::com::sun::star::uno::UNO_SET_THROW;
118 using ::com::sun::star::lang::DisposedException;
119 using ::com::sun::star::awt::XWindow;
120 using ::com::sun::star::frame::XController;
121 using ::com::sun::star::frame::XDispatchProvider;
122 using ::com::sun::star::document::XViewDataSupplier;
123 using ::com::sun::star::container::XIndexAccess;
124 using ::com::sun::star::beans::PropertyValue;
125 using ::com::sun::star::uno::Sequence;
126 using ::com::sun::star::uno::UNO_QUERY;
127 using ::com::sun::star::uno::Exception;
128 using ::com::sun::star::frame::XFrame;
129 using ::com::sun::star::frame::XFrameActionListener;
130 using ::com::sun::star::util::XCloseListener;
131 using ::com::sun::star::task::XStatusIndicator;
132 using ::com::sun::star::frame::XTitle;
133 namespace css = ::com::sun::star;
134 
135 struct GroupIDToCommandGroup
136 {
137     sal_Int16   nGroupID;
138     sal_Int16   nCommandGroup;
139 };
140 
141 // Please update when a new command group is added
142 const sal_Int16 MAX_COMMANDGROUP = com::sun::star::frame::CommandGroup::CONTROLS;
143 
144 static sal_Bool                 bGroupIDMapInitialized = sal_False;
145 static GroupIDToCommandGroup    GroupIDCommandGroupMap[] =
146 {
147     { GID_INTERN        ,   com::sun::star::frame::CommandGroup::INTERNAL       },
148     { GID_APPLICATION   ,   com::sun::star::frame::CommandGroup::APPLICATION    },
149     { GID_DOCUMENT      ,   com::sun::star::frame::CommandGroup::DOCUMENT       },
150     { GID_VIEW		    ,   com::sun::star::frame::CommandGroup::VIEW           },
151     { GID_EDIT          ,   com::sun::star::frame::CommandGroup::EDIT           },
152     { GID_MACRO         ,   com::sun::star::frame::CommandGroup::MACRO          },
153     { GID_OPTIONS       ,   com::sun::star::frame::CommandGroup::OPTIONS        },
154     { GID_MATH  		,   com::sun::star::frame::CommandGroup::MATH           },
155     { GID_NAVIGATOR	    ,   com::sun::star::frame::CommandGroup::NAVIGATOR      },
156     { GID_INSERT		,   com::sun::star::frame::CommandGroup::INSERT         },
157     { GID_FORMAT        ,   com::sun::star::frame::CommandGroup::FORMAT         },
158     { GID_TEMPLATE      ,   com::sun::star::frame::CommandGroup::TEMPLATE       },
159     { GID_TEXT          ,   com::sun::star::frame::CommandGroup::TEXT           },
160     { GID_FRAME         ,   com::sun::star::frame::CommandGroup::FRAME          },
161     { GID_GRAPHIC       ,   com::sun::star::frame::CommandGroup::GRAPHIC        },
162     { GID_TABLE         ,   com::sun::star::frame::CommandGroup::TABLE          },
163     { GID_ENUMERATION   ,   com::sun::star::frame::CommandGroup::ENUMERATION    },
164     { GID_DATA          ,   com::sun::star::frame::CommandGroup::DATA           },
165     { GID_SPECIAL       ,   com::sun::star::frame::CommandGroup::SPECIAL        },
166     { GID_IMAGE         ,   com::sun::star::frame::CommandGroup::IMAGE          },
167     { GID_CHART         ,   com::sun::star::frame::CommandGroup::CHART          },
168     { GID_EXPLORER      ,   com::sun::star::frame::CommandGroup::EXPLORER       },
169     { GID_CONNECTOR     ,   com::sun::star::frame::CommandGroup::CONNECTOR      },
170     { GID_MODIFY        ,   com::sun::star::frame::CommandGroup::MODIFY         },
171     { GID_DRAWING       ,   com::sun::star::frame::CommandGroup::DRAWING        },
172     { GID_CONTROLS      ,   com::sun::star::frame::CommandGroup::CONTROLS       },
173     { 0                 ,   0                                                   }
174 };
175 
176 typedef std::hash_map< sal_Int16, sal_Int16 > GroupHashMap;
177 
178 
MapGroupIDToCommandGroup(sal_Int16 nGroupID)179 sal_Int16 MapGroupIDToCommandGroup( sal_Int16 nGroupID )
180 {
181     static GroupHashMap mHashMap;
182 
183     if ( !bGroupIDMapInitialized )
184     {
185         sal_Int32 i = 0;
186         while ( GroupIDCommandGroupMap[i].nGroupID != 0 )
187         {
188             mHashMap.insert( GroupHashMap::value_type(
189                 GroupIDCommandGroupMap[i].nGroupID,
190                 GroupIDCommandGroupMap[i].nCommandGroup ));
191             ++i;
192         }
193     }
194 
195     GroupHashMap::const_iterator pIter = mHashMap.find( nGroupID );
196     if ( pIter != mHashMap.end() )
197         return pIter->second;
198     else
199         return com::sun::star::frame::CommandGroup::INTERNAL;
200 }
201 
MapCommandGroupToGroupID(sal_Int16 nCommandGroup)202 sal_Int16 MapCommandGroupToGroupID( sal_Int16 nCommandGroup )
203 {
204     sal_Int32 i = 0;
205     while ( GroupIDCommandGroupMap[i].nGroupID != 0 )
206     {
207         if ( GroupIDCommandGroupMap[i].nCommandGroup == nCommandGroup )
208             return GroupIDCommandGroupMap[i].nGroupID;
209         ++i;
210     }
211 
212     return -1;
213 }
214 
SupportsCommandGroup(sal_Int16 nCommandGroup)215 sal_Bool SupportsCommandGroup( sal_Int16 nCommandGroup )
216 {
217     if (( nCommandGroup >= 0 ) && ( nCommandGroup <= MAX_COMMANDGROUP ))
218         return sal_True;
219     else
220         return sal_False;
221 }
222 
Get10ThSec()223 sal_uInt32 Get10ThSec()
224 {
225 	sal_uInt32 n10Ticks = 10 * (sal_uInt32)clock();
226 	return n10Ticks / CLOCKS_PER_SEC;
227 }
228 
229 sal_Int32 m_nInReschedule = 0;	///	static counter for rescheduling
230 
reschedule()231 void reschedule()
232 {
233 	if ( m_nInReschedule == 0 )
234 	{
235 		++m_nInReschedule;
236 		Application::Reschedule();
237 		--m_nInReschedule;
238 	}
239 }
240 
241 class SfxStatusIndicator : public ::cppu::WeakImplHelper2< ::com::sun::star::task::XStatusIndicator, ::com::sun::star::lang::XEventListener >
242 {
243 friend class SfxBaseController;
244     ::com::sun::star::uno::Reference < XController > xOwner;
245     ::com::sun::star::uno::Reference < ::com::sun::star::task::XStatusIndicator > xProgress;
246     SfxWorkWindow*          pWorkWindow;
247     sal_Int32               _nRange;
248     sal_Int32               _nValue;
249 	long					_nStartTime;
250 public:
SfxStatusIndicator(SfxBaseController * pController,SfxWorkWindow * pWork)251                             SfxStatusIndicator(SfxBaseController* pController, SfxWorkWindow* pWork)
252                                 : xOwner( pController )
253                                 , pWorkWindow( pWork )
254                             {
255 								++m_refCount;
256 								::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComponent(
257 									SAL_STATIC_CAST(::cppu::OWeakObject*, pController ), ::com::sun::star::uno::UNO_QUERY );
258 								if (xComponent.is())
259 									xComponent->addEventListener(this);
260 								--m_refCount;
261 							}
262 
263     virtual void SAL_CALL   start(const ::rtl::OUString& aText, sal_Int32 nRange) throw(::com::sun::star::uno::RuntimeException);
264     virtual void SAL_CALL   end(void) throw(::com::sun::star::uno::RuntimeException);
265     virtual void SAL_CALL   setText(const ::rtl::OUString& aText) throw(::com::sun::star::uno::RuntimeException);
266     virtual void SAL_CALL   setValue(sal_Int32 nValue) throw(::com::sun::star::uno::RuntimeException);
267     virtual void SAL_CALL   reset() throw(::com::sun::star::uno::RuntimeException);
268 
269 	virtual void SAL_CALL	disposing( const com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
270 };
271 
start(const::rtl::OUString & aText,sal_Int32 nRange)272 void SAL_CALL SfxStatusIndicator::start(const ::rtl::OUString& aText, sal_Int32 nRange) throw(::com::sun::star::uno::RuntimeException)
273 {
274     ::vos::OGuard aGuard( Application::GetSolarMutex() );
275     if ( xOwner.is() )
276 	{
277 		_nRange = nRange;
278 		_nValue = 0;
279 
280         if ( !xProgress.is() )
281             xProgress = pWorkWindow->GetStatusIndicator();
282 
283         if ( xProgress.is() )
284             xProgress->start( aText, nRange );
285 
286 		_nStartTime = Get10ThSec();
287     	reschedule();
288 	}
289 }
290 
end(void)291 void SAL_CALL SfxStatusIndicator::end(void) throw(::com::sun::star::uno::RuntimeException)
292 {
293     ::vos::OGuard aGuard( Application::GetSolarMutex() );
294     if ( xOwner.is() )
295 	{
296         if ( !xProgress.is() )
297             xProgress = pWorkWindow->GetStatusIndicator();
298 
299         if ( xProgress.is() )
300             xProgress->end();
301 
302         reschedule();
303 	}
304 }
305 
setText(const::rtl::OUString & aText)306 void SAL_CALL SfxStatusIndicator::setText(const ::rtl::OUString& aText) throw(::com::sun::star::uno::RuntimeException)
307 {
308     ::vos::OGuard aGuard( Application::GetSolarMutex() );
309     if ( xOwner.is() )
310 	{
311         if ( !xProgress.is() )
312             xProgress = pWorkWindow->GetStatusIndicator();
313 
314         if ( xProgress.is() )
315             xProgress->setText( aText );
316 
317     	reschedule();
318 	}
319 }
320 
setValue(sal_Int32 nValue)321 void SAL_CALL SfxStatusIndicator::setValue( sal_Int32 nValue ) throw(::com::sun::star::uno::RuntimeException)
322 {
323     ::vos::OGuard aGuard( Application::GetSolarMutex() );
324     if ( xOwner.is() )
325 	{
326 		_nValue = nValue;
327 
328         if ( !xProgress.is() )
329             xProgress = pWorkWindow->GetStatusIndicator();
330 
331         if ( xProgress.is() )
332             xProgress->setValue( nValue );
333 
334         sal_Bool bReschedule = (( Get10ThSec() - _nStartTime ) > TIMEOUT_START_RESCHEDULE );
335 		if ( bReschedule )
336 			reschedule();
337 	}
338 }
339 
reset()340 void SAL_CALL SfxStatusIndicator::reset() throw(::com::sun::star::uno::RuntimeException)
341 {
342     ::vos::OGuard aGuard( Application::GetSolarMutex() );
343     if ( xOwner.is() )
344 	{
345         if ( !xProgress.is() )
346             xProgress = pWorkWindow->GetStatusIndicator();
347 
348         if ( xProgress.is() )
349             xProgress->reset();
350 
351         reschedule();
352 	}
353 }
354 
disposing(const com::sun::star::lang::EventObject &)355 void SAL_CALL SfxStatusIndicator::disposing( const com::sun::star::lang::EventObject& /*Source*/ ) throw(::com::sun::star::uno::RuntimeException)
356 {
357     ::vos::OGuard aGuard( Application::GetSolarMutex() );
358 	xOwner = 0;
359     xProgress.clear();
360 }
361 
362 //________________________________________________________________________________________________________
363 //________________________________________________________________________________________________________
364 //	declaration IMPL_SfxBaseController_ListenerHelper
365 //________________________________________________________________________________________________________
366 
367 class IMPL_SfxBaseController_ListenerHelper : public ::cppu::WeakImplHelper1< ::com::sun::star::frame::XFrameActionListener >
368 {
369 public:
370 	IMPL_SfxBaseController_ListenerHelper(	MUTEX&				aMutex		,
371 											SfxBaseController*	pController	) ;
372 	virtual ~IMPL_SfxBaseController_ListenerHelper() ;
373     virtual void SAL_CALL frameAction( const FRAMEACTIONEVENT& aEvent ) throw (RUNTIMEEXCEPTION) ;
374 	virtual void SAL_CALL disposing( const EVENTOBJECT& aEvent ) throw (RUNTIMEEXCEPTION) ;
375 
376 private:
377 
378 	MUTEX&					m_aMutex		;
379 	SfxBaseController*		m_pController	;
380 
381 } ;	// class IMPL_SfxBaseController_ListenerContainer
382 
383 class IMPL_SfxBaseController_CloseListenerHelper : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XCloseListener >
384 {
385 public:
386 	IMPL_SfxBaseController_CloseListenerHelper(	MUTEX&				aMutex		,
387 											SfxBaseController*	pController	) ;
388 	virtual ~IMPL_SfxBaseController_CloseListenerHelper() ;
389     virtual void SAL_CALL queryClosing( const EVENTOBJECT& aEvent, sal_Bool bDeliverOwnership )
390         throw (RUNTIMEEXCEPTION, com::sun::star::util::CloseVetoException) ;
391     virtual void SAL_CALL notifyClosing( const EVENTOBJECT& aEvent ) throw (RUNTIMEEXCEPTION) ;
392 	virtual void SAL_CALL disposing( const EVENTOBJECT& aEvent ) throw (RUNTIMEEXCEPTION) ;
393 
394 private:
395 
396 	MUTEX&					m_aMutex;
397 	SfxBaseController*		m_pController;
398 
399 } ;	// class IMPL_SfxBaseController_ListenerContainer
400 
IMPL_SfxBaseController_CloseListenerHelper(MUTEX & aMutex,SfxBaseController * pController)401 IMPL_SfxBaseController_CloseListenerHelper::IMPL_SfxBaseController_CloseListenerHelper(	MUTEX&				aMutex		,
402 																				SfxBaseController*	pController	)
403 		: m_aMutex		( aMutex		)
404 		, m_pController	( pController	)
405 {
406 }
407 
~IMPL_SfxBaseController_CloseListenerHelper()408 IMPL_SfxBaseController_CloseListenerHelper::~IMPL_SfxBaseController_CloseListenerHelper()
409 {
410 }
411 
disposing(const EVENTOBJECT &)412 void SAL_CALL IMPL_SfxBaseController_CloseListenerHelper::disposing( const EVENTOBJECT& /*aEvent*/ ) throw( ::com::sun::star::uno::RuntimeException )
413 {
414 }
415 
queryClosing(const EVENTOBJECT & aEvent,sal_Bool bDeliverOwnership)416 void SAL_CALL IMPL_SfxBaseController_CloseListenerHelper::queryClosing( const EVENTOBJECT& aEvent, sal_Bool bDeliverOwnership )
417     throw (RUNTIMEEXCEPTION, com::sun::star::util::CloseVetoException)
418 {
419 	::vos::OGuard aGuard( Application::GetSolarMutex() );
420     SfxViewShell* pShell = m_pController->GetViewShell_Impl();
421     if  ( m_pController !=  NULL &&  pShell )
422 	{
423         sal_Bool bCanClose = (sal_Bool) pShell->PrepareClose( sal_False );
424 		if ( !bCanClose )
425 		{
426             if ( bDeliverOwnership && ( !pShell->GetWindow() || !pShell->GetWindow()->IsReallyVisible() ) )
427             {
428                 // ignore OwnerShip in case of visible frame (will be closed by user)
429                 uno::Reference < frame::XModel > xModel( aEvent.Source, uno::UNO_QUERY );
430                 if ( xModel.is() )
431                     pShell->TakeOwnerShip_Impl();
432                 else
433                     pShell->TakeFrameOwnerShip_Impl();
434             }
435 
436 			throw com::sun::star::util::CloseVetoException(::rtl::OUString::createFromAscii("Controller disagree ..."),static_cast< ::cppu::OWeakObject*>(this));
437 		}
438 	}
439 }
440 
notifyClosing(const EVENTOBJECT &)441 void SAL_CALL IMPL_SfxBaseController_CloseListenerHelper::notifyClosing( const EVENTOBJECT& /*aEvent*/ ) throw (RUNTIMEEXCEPTION)
442 {
443 }
444 
445 //________________________________________________________________________________________________________
446 //	declaration IMPL_SfxBaseController_DataContainer
447 //________________________________________________________________________________________________________
448 
449 struct IMPL_SfxBaseController_DataContainer
450 {
451     Reference< XFrame >                     m_xFrame                ;
452     Reference< XFrameActionListener >       m_xListener             ;
453     Reference< XCloseListener >             m_xCloseListener        ;
454     ::sfx2::UserInputInterception           m_aUserInputInterception;
455 	OMULTITYPEINTERFACECONTAINERHELPER		m_aListenerContainer	;
456     OINTERFACECONTAINERHELPER               m_aInterceptorContainer ;
457     Reference< XStatusIndicator >           m_xIndicator            ;
458 	SfxViewShell*							m_pViewShell			;
459 	SfxBaseController*						m_pController			;
460 	sal_Bool								m_bDisposing			;
461 	sal_Bool                                m_bSuspendState         ;
462     Reference< XTitle >                     m_xTitleHelper          ;
463     Sequence< PropertyValue >               m_aCreationArgs         ;
464 
IMPL_SfxBaseController_DataContainerIMPL_SfxBaseController_DataContainer465 	IMPL_SfxBaseController_DataContainer(	MUTEX&				aMutex		,
466 											SfxViewShell*		pViewShell	,
467 											SfxBaseController*	pController	)
468             :   m_xListener                     ( new IMPL_SfxBaseController_ListenerHelper( aMutex, pController ) )
469             ,   m_xCloseListener                ( new IMPL_SfxBaseController_CloseListenerHelper( aMutex, pController ) )
470             ,   m_aUserInputInterception        ( *pController, aMutex                                  )
471             ,   m_aListenerContainer            ( aMutex												)
472             ,   m_aInterceptorContainer         ( aMutex                                                )
473             ,   m_pViewShell			( pViewShell											)
474             ,   m_pController			( pController											)
475             ,   m_bDisposing			( sal_False												)
476             ,   m_bSuspendState                 ( sal_False                                              )
477 	{
478 	}
479 
480 } ;	// struct IMPL_SfxBaseController_DataContainer
481 
482 //________________________________________________________________________________________________________
483 //	IMPL_SfxBaseController_ListenerHelper constructor
484 //________________________________________________________________________________________________________
485 
IMPL_SfxBaseController_ListenerHelper(MUTEX & aMutex,SfxBaseController * pController)486 IMPL_SfxBaseController_ListenerHelper::IMPL_SfxBaseController_ListenerHelper(	MUTEX&				aMutex		,
487 																				SfxBaseController*	pController	)
488 		: m_aMutex		( aMutex		)
489 		, m_pController	( pController	)
490 {
491 }
492 
493 //________________________________________________________________________________________________________
494 //	IMPL_SfxBaseController_ListenerHelper destructor
495 //________________________________________________________________________________________________________
496 
~IMPL_SfxBaseController_ListenerHelper()497 IMPL_SfxBaseController_ListenerHelper::~IMPL_SfxBaseController_ListenerHelper()
498 {
499 }
500 
frameAction(const FRAMEACTIONEVENT & aEvent)501 void SAL_CALL IMPL_SfxBaseController_ListenerHelper::frameAction( const FRAMEACTIONEVENT& aEvent ) throw( RUNTIMEEXCEPTION )
502 {
503 	::vos::OGuard aGuard( Application::GetSolarMutex() );
504 	if	(
505 			( m_pController	!=	NULL ) &&
506 			( aEvent.Frame	==	m_pController->getFrame() )	&&
507             ( m_pController->GetViewShell_Impl() && m_pController->GetViewShell_Impl()->GetWindow() !=  NULL                                                    )
508 		)
509 	{
510         if ( aEvent.Action == ::com::sun::star::frame::FrameAction_FRAME_UI_ACTIVATED )
511 		{
512             if ( !m_pController->GetViewShell_Impl()->GetUIActiveIPClient_Impl() )
513                 m_pController->GetViewShell_Impl()->GetViewFrame()->MakeActive_Impl( sal_False );
514 		}
515         else if ( aEvent.Action == ::com::sun::star::frame::FrameAction_CONTEXT_CHANGED )
516 		{
517 			m_pController->GetViewShell_Impl()->GetViewFrame()->GetBindings().ContextChanged_Impl();
518 		}
519 	}
520 }
521 
522 //________________________________________________________________________________________________________
523 //	IMPL_SfxBaseController_ListenerHelper -> XEventListener
524 //________________________________________________________________________________________________________
525 
disposing(const EVENTOBJECT &)526 void SAL_CALL IMPL_SfxBaseController_ListenerHelper::disposing( const EVENTOBJECT& /*aEvent*/ ) throw( ::com::sun::star::uno::RuntimeException )
527 {
528 	::vos::OGuard aGuard( Application::GetSolarMutex() );
529     if ( m_pController && m_pController->getFrame().is() )
530 		m_pController->getFrame()->removeFrameActionListener( this ) ;
531 }
532 
533 //________________________________________________________________________________________________________
534 //	SfxBaseController -> constructor
535 //________________________________________________________________________________________________________
DBG_NAME(sfx2_SfxBaseController)536 DBG_NAME(sfx2_SfxBaseController)
537 SfxBaseController::SfxBaseController( SfxViewShell* pViewShell )
538     :   m_pData ( new IMPL_SfxBaseController_DataContainer( m_aMutex, pViewShell, this ))
539 {
540     DBG_CTOR(sfx2_SfxBaseController,NULL);
541     m_pData->m_pViewShell->SetController( this );
542 }
543 
544 //________________________________________________________________________________________________________
545 //	SfxBaseController -> destructor
546 //________________________________________________________________________________________________________
547 
~SfxBaseController()548 SfxBaseController::~SfxBaseController()
549 {
550     DBG_DTOR(sfx2_SfxBaseController,NULL);
551 	delete m_pData;
552 }
553 
554 //________________________________________________________________________________________________________
555 //	SfxBaseController -> XController2
556 //________________________________________________________________________________________________________
557 
getComponentWindow()558 Reference< XWindow > SAL_CALL SfxBaseController::getComponentWindow() throw (RuntimeException)
559 {
560 	::vos::OGuard aGuard( Application::GetSolarMutex() );
561     if ( !m_pData->m_pViewShell )
562         throw DisposedException();
563 
564     return Reference< XWindow >( GetViewFrame_Impl().GetFrame().GetWindow().GetComponentInterface(), UNO_QUERY_THROW );
565 }
566 
getViewControllerName()567 ::rtl::OUString SAL_CALL SfxBaseController::getViewControllerName() throw (RuntimeException)
568 {
569 	::vos::OGuard aGuard( Application::GetSolarMutex() );
570     if ( !m_pData->m_pViewShell || !m_pData->m_pViewShell->GetObjectShell() )
571         throw DisposedException();
572 
573     const SfxObjectFactory& rDocFac( m_pData->m_pViewShell->GetObjectShell()->GetFactory() );
574     sal_uInt16 nViewNo = rDocFac.GetViewNo_Impl( GetViewFrame_Impl().GetCurViewId(), rDocFac.GetViewFactoryCount() );
575     OSL_ENSURE( nViewNo < rDocFac.GetViewFactoryCount(), "SfxBaseController::getViewControllerName: view ID not found in view factories!" );
576 
577     ::rtl::OUString sViewName;
578     if ( nViewNo < rDocFac.GetViewFactoryCount() )
579         sViewName = rDocFac.GetViewFactory( nViewNo ).GetAPIViewName();
580 
581     return sViewName;
582 }
583 
getCreationArguments()584 Sequence< PropertyValue > SAL_CALL SfxBaseController::getCreationArguments() throw (RuntimeException)
585 {
586 	::vos::OGuard aGuard( Application::GetSolarMutex() );
587     if ( !m_pData->m_pViewShell || !m_pData->m_pViewShell->GetObjectShell() )
588         throw DisposedException();
589 
590     return m_pData->m_aCreationArgs;
591 }
592 
SetCreationArguments_Impl(const Sequence<PropertyValue> & i_rCreationArgs)593 void SfxBaseController::SetCreationArguments_Impl( const Sequence< PropertyValue >& i_rCreationArgs )
594 {
595     OSL_ENSURE( m_pData->m_aCreationArgs.getLength() == 0, "SfxBaseController::SetCreationArguments_Impl: not intended to be called twice!" );
596     m_pData->m_aCreationArgs = i_rCreationArgs;
597 }
598 
GetViewFrame_Impl() const599 SfxViewFrame& SfxBaseController::GetViewFrame_Impl() const
600 {
601     ENSURE_OR_THROW( m_pData->m_pViewShell, "not to be called without a view shell" );
602     SfxViewFrame* pActFrame = m_pData->m_pViewShell->GetFrame();
603     ENSURE_OR_THROW( pActFrame, "a view shell without a view frame is pretty pathological" );
604     return *pActFrame;
605 }
606 
607 //________________________________________________________________________________________________________
608 //	SfxBaseController -> XController2 -> XController
609 //________________________________________________________________________________________________________
610 
attachFrame(const REFERENCE<XFRAME> & xFrame)611 void SAL_CALL SfxBaseController::attachFrame( const REFERENCE< XFRAME >& xFrame ) throw( ::com::sun::star::uno::RuntimeException )
612 {
613     REFERENCE< XFRAME > xTemp( getFrame() ) ;
614 
615 	::vos::OGuard aGuard( Application::GetSolarMutex() );
616 	if ( xTemp.is() )
617 	{
618         xTemp->removeFrameActionListener( m_pData->m_xListener ) ;
619 		REFERENCE < ::com::sun::star::util::XCloseBroadcaster > xCloseable( xTemp, com::sun::star::uno::UNO_QUERY );
620 		if ( xCloseable.is() )
621 			xCloseable->removeCloseListener( m_pData->m_xCloseListener );
622 	}
623 
624     m_pData->m_xFrame = xFrame;
625 
626 	if ( xFrame.is() )
627 	{
628         xFrame->addFrameActionListener( m_pData->m_xListener ) ;
629 		REFERENCE < ::com::sun::star::util::XCloseBroadcaster > xCloseable( xFrame, com::sun::star::uno::UNO_QUERY );
630 		if ( xCloseable.is() )
631 			xCloseable->addCloseListener( m_pData->m_xCloseListener );
632 
633 		if ( m_pData->m_pViewShell )
634 		{
635             ConnectSfxFrame_Impl( E_CONNECT );
636 
637             // attaching the frame to the controller is the last step in the creation of a new view, so notify this
638             SfxViewEventHint aHint( SFX_EVENT_VIEWCREATED, GlobalEventConfig::GetEventName( STR_EVENT_VIEWCREATED ), m_pData->m_pViewShell->GetObjectShell(), uno::Reference< frame::XController2 >( this ) );
639             SFX_APP()->NotifyEvent( aHint );
640 		}
641 	}
642 }
643 
644 //________________________________________________________________________________________________________
645 //	SfxBaseController -> XController
646 //________________________________________________________________________________________________________
647 
attachModel(const REFERENCE<XMODEL> & xModel)648 sal_Bool SAL_CALL SfxBaseController::attachModel( const REFERENCE< XMODEL >& xModel ) throw( ::com::sun::star::uno::RuntimeException )
649 {
650 	if ( m_pData->m_pViewShell && xModel.is() && xModel != m_pData->m_pViewShell->GetObjectShell()->GetModel() )
651 	{
652 		// don't allow to reattach a model!
653 		DBG_ERROR("Can't reattach model!");
654 		return sal_False;
655 	}
656 
657 	REFERENCE < ::com::sun::star::util::XCloseBroadcaster > xCloseable( xModel, com::sun::star::uno::UNO_QUERY );
658 	if ( xCloseable.is() )
659 		xCloseable->addCloseListener( m_pData->m_xCloseListener );
660 	return sal_True;
661 }
662 
663 //________________________________________________________________________________________________________
664 //	SfxBaseController -> XController
665 //________________________________________________________________________________________________________
666 
suspend(sal_Bool bSuspend)667 sal_Bool SAL_CALL SfxBaseController::suspend( sal_Bool bSuspend ) throw( ::com::sun::star::uno::RuntimeException )
668 {
669 	::vos::OGuard aGuard( Application::GetSolarMutex() );
670 
671 	// ignore dublicate calls, which doesn't change anything real
672 	if (bSuspend == m_pData->m_bSuspendState)
673 	   return sal_True;
674 
675 	if ( bSuspend == sal_True )
676 	{
677         if ( !m_pData->m_pViewShell )
678         {
679             m_pData->m_bSuspendState = sal_True;
680             return sal_True;
681         }
682 
683 		if ( !m_pData->m_pViewShell->PrepareClose() )
684             return sal_False;
685 
686         if ( getFrame().is() )
687             getFrame()->removeFrameActionListener( m_pData->m_xListener ) ;
688         SfxViewFrame* pActFrame = m_pData->m_pViewShell->GetFrame() ;
689 
690         // weitere View auf dasselbe Doc?
691         SfxObjectShell*	pDocShell	=	m_pData->m_pViewShell->GetObjectShell()	;
692         sal_Bool		bOther		=	sal_False								;
693 
694         for ( const SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );	!bOther && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell ) )
695             bOther = (pFrame != pActFrame);
696 
697         sal_Bool bRet = bOther || pDocShell->PrepareClose();
698         if ( bRet )
699         {
700             ConnectSfxFrame_Impl( E_DISCONNECT );
701             m_pData->m_bSuspendState = sal_True;
702         }
703 
704         return bRet;
705 	}
706 	else
707 	{
708 		if ( getFrame().is() )
709         	getFrame()->addFrameActionListener( m_pData->m_xListener ) ;
710 
711 		if ( m_pData->m_pViewShell )
712 		{
713             ConnectSfxFrame_Impl( E_RECONNECT );
714 		}
715 
716         m_pData->m_bSuspendState = sal_False;
717 		return sal_True ;
718 	}
719 }
720 
721 //________________________________________________________________________________________________________
722 //	SfxBaseController -> XController
723 //________________________________________________________________________________________________________
724 
getViewData()725 ANY SfxBaseController::getViewData() throw( ::com::sun::star::uno::RuntimeException )
726 {
727     ANY         aAny;
728 	String		sData1;
729 	::vos::OGuard aGuard( Application::GetSolarMutex() );
730     if ( m_pData->m_pViewShell )
731     {
732         m_pData->m_pViewShell->WriteUserData( sData1 ) ;
733         ::rtl::OUString    sData( sData1 );
734         aAny <<= sData ;
735     }
736 
737 	return aAny ;
738 }
739 
740 //________________________________________________________________________________________________________
741 //	SfxBaseController -> XController
742 //________________________________________________________________________________________________________
743 
restoreViewData(const ANY & aValue)744 void SAL_CALL SfxBaseController::restoreViewData( const ANY& aValue ) throw( ::com::sun::star::uno::RuntimeException )
745 {
746 	::vos::OGuard aGuard( Application::GetSolarMutex() );
747     if ( m_pData->m_pViewShell )
748     {
749         ::rtl::OUString sData;
750         aValue >>= sData ;
751         m_pData->m_pViewShell->ReadUserData( sData ) ;
752     }
753 }
754 
755 //________________________________________________________________________________________________________
756 //	SfxBaseController -> XController
757 //________________________________________________________________________________________________________
758 
getFrame()759 REFERENCE< XFRAME > SAL_CALL SfxBaseController::getFrame() throw( ::com::sun::star::uno::RuntimeException )
760 {
761 	::vos::OGuard aGuard( Application::GetSolarMutex() );
762     return m_pData->m_xFrame;
763 }
764 
765 //________________________________________________________________________________________________________
766 //	SfxBaseController -> XController
767 //________________________________________________________________________________________________________
768 
getModel()769 REFERENCE< XMODEL > SAL_CALL SfxBaseController::getModel() throw( ::com::sun::star::uno::RuntimeException )
770 {
771 	::vos::OGuard aGuard( Application::GetSolarMutex() );
772     return m_pData->m_pViewShell ? m_pData->m_pViewShell->GetObjectShell()->GetModel() : REFERENCE < XMODEL > () ;
773 }
774 
775 //________________________________________________________________________________________________________
776 //	SfxBaseController -> XDispatchProvider
777 //________________________________________________________________________________________________________
778 
queryDispatch(const UNOURL & aURL,const::rtl::OUString & sTargetFrameName,sal_Int32 eSearchFlags)779 REFERENCE< XDISPATCH > SAL_CALL SfxBaseController::queryDispatch(	const	UNOURL&				aURL			,
780 																	const	::rtl::OUString&			sTargetFrameName,
781 																			sal_Int32			eSearchFlags	) throw( RUNTIMEEXCEPTION )
782 {
783 	::vos::OGuard aGuard( Application::GetSolarMutex() );
784     REFERENCE< XDISPATCH >  xDisp;
785     if ( m_pData->m_pViewShell )
786     {
787         SfxViewFrame*           pAct    = m_pData->m_pViewShell->GetViewFrame() ;
788         if ( !m_pData->m_bDisposing )
789         {
790             if ( sTargetFrameName.compareToAscii( "_beamer" ) == COMPARE_EQUAL )
791             {
792                 SfxViewFrame *pFrame = m_pData->m_pViewShell->GetViewFrame();
793                 if ( eSearchFlags & ( ::com::sun::star::frame::FrameSearchFlag::CREATE ))
794                     pFrame->SetChildWindow( SID_BROWSER, sal_True );
795                 SfxChildWindow* pChildWin = pFrame->GetChildWindow( SID_BROWSER );
796                 REFERENCE < XFRAME > xFrame;
797                 if ( pChildWin )
798                     xFrame = ( pChildWin->GetFrame() );
799                 if ( xFrame.is() )
800                     xFrame->setName( sTargetFrameName );
801 
802                 Reference< XDispatchProvider > xProv( xFrame, ::com::sun::star::uno::UNO_QUERY );
803                 if ( xProv.is() )
804                     return xProv->queryDispatch( aURL, sTargetFrameName, ::com::sun::star::frame::FrameSearchFlag::SELF );
805             }
806 
807             if ( aURL.Protocol.compareToAscii( ".uno:" ) == COMPARE_EQUAL )
808             {
809                 rtl::OUString aMasterCommand = SfxOfficeDispatch::GetMasterUnoCommand( aURL );
810                 sal_Bool      bMasterCommand( aMasterCommand.getLength() > 0 );
811 
812                 pAct = m_pData->m_pViewShell->GetViewFrame() ;
813                 SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool( pAct );
814 
815                 const SfxSlot* pSlot( 0 );
816                 if ( bMasterCommand )
817                     pSlot = rSlotPool.GetUnoSlot( aMasterCommand );
818                 else
819                     pSlot = rSlotPool.GetUnoSlot( aURL.Path );
820                 if ( pSlot && ( !pAct->GetFrame().IsInPlace() || !pSlot->IsMode( SFX_SLOT_CONTAINER ) ) )
821                     return pAct->GetBindings().GetDispatch( pSlot, aURL, bMasterCommand );
822 				else
823 				{
824 					// try to find parent SfxViewFrame
825 					uno::Reference< frame::XFrame > xParentFrame;
826 					uno::Reference< frame::XFrame > xOwnFrame = pAct->GetFrame().GetFrameInterface();
827 					if ( xOwnFrame.is() )
828 						xParentFrame = uno::Reference< frame::XFrame >( xOwnFrame->getCreator(), uno::UNO_QUERY );
829 
830 					if ( xParentFrame.is() )
831 					{
832 						// TODO/LATER: in future probably SfxViewFrame hirarchy should be the same as XFrame hirarchy
833 						// SfxViewFrame* pParentFrame = pAct->GetParentViewFrame();
834 
835 						// search the related SfxViewFrame
836 						SfxViewFrame* pParentFrame = NULL;
837 						for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst();
838 								pFrame;
839 								pFrame = SfxViewFrame::GetNext( *pFrame ) )
840 						{
841 							if ( pFrame->GetFrame().GetFrameInterface() == xParentFrame )
842 							{
843 								pParentFrame = pFrame;
844 								break;
845 							}
846 						}
847 
848 						if ( pParentFrame )
849 						{
850                             SfxSlotPool& rFrameSlotPool = SfxSlotPool::GetSlotPool( pParentFrame );
851                             const SfxSlot* pSlot2( 0 );
852                             if ( bMasterCommand )
853                                 pSlot2 = rFrameSlotPool.GetUnoSlot( aMasterCommand );
854                             else
855                                 pSlot2 = rFrameSlotPool.GetUnoSlot( aURL.Path );
856 
857                             if ( pSlot2 )
858                                 return pParentFrame->GetBindings().GetDispatch( pSlot2, aURL, bMasterCommand );
859 						}
860 					}
861 				}
862             }
863             else if ( aURL.Protocol.compareToAscii( "slot:" ) == COMPARE_EQUAL )
864             {
865                 sal_uInt16 nId = (sal_uInt16) aURL.Path.toInt32();
866 
867                 pAct = m_pData->m_pViewShell->GetViewFrame() ;
868                 if (nId >= SID_VERB_START && nId <= SID_VERB_END)
869                 {
870                     const SfxSlot* pSlot = m_pData->m_pViewShell->GetVerbSlot_Impl(nId);
871                     if ( pSlot )
872                         return pAct->GetBindings().GetDispatch( pSlot, aURL, sal_False );
873                 }
874 
875                 SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool( pAct );
876                 const SfxSlot* pSlot = rSlotPool.GetSlot( nId );
877                 if ( pSlot && ( !pAct->GetFrame().IsInPlace() || !pSlot->IsMode( SFX_SLOT_CONTAINER ) ) )
878                     return pAct->GetBindings().GetDispatch( pSlot, aURL, sal_False );
879 				else
880 				{
881 					// try to find parent SfxViewFrame
882 					uno::Reference< frame::XFrame > xParentFrame;
883 					uno::Reference< frame::XFrame > xOwnFrame = pAct->GetFrame().GetFrameInterface();
884 					if ( xOwnFrame.is() )
885 						xParentFrame = uno::Reference< frame::XFrame >( xOwnFrame->getCreator(), uno::UNO_QUERY );
886 
887 					if ( xParentFrame.is() )
888 					{
889 						// TODO/LATER: in future probably SfxViewFrame hirarchy should be the same as XFrame hirarchy
890 						// SfxViewFrame* pParentFrame = pAct->GetParentViewFrame();
891 
892 						// search the related SfxViewFrame
893 						SfxViewFrame* pParentFrame = NULL;
894 						for ( SfxViewFrame* pFrame = SfxViewFrame::GetFirst();
895 								pFrame;
896 								pFrame = SfxViewFrame::GetNext( *pFrame ) )
897 						{
898 							if ( pFrame->GetFrame().GetFrameInterface() == xParentFrame )
899 							{
900 								pParentFrame = pFrame;
901 								break;
902 							}
903 						}
904 
905 						if ( pParentFrame )
906 						{
907                             SfxSlotPool& rSlotPool2 = SfxSlotPool::GetSlotPool( pParentFrame );
908                 			const SfxSlot* pSlot2 = rSlotPool2.GetUnoSlot( aURL.Path );
909                 			if ( pSlot2 )
910                                 return pParentFrame->GetBindings().GetDispatch( pSlot2, aURL, sal_False );
911 						}
912 					}
913 				}
914             }
915             else if( sTargetFrameName.compareToAscii( "_self" )==COMPARE_EQUAL || sTargetFrameName.getLength()==0 )
916             {
917                 // check for already loaded URL ... but with additional jumpmark!
918                 REFERENCE< XMODEL > xModel = getModel();
919                 if( xModel.is() && aURL.Mark.getLength() )
920                 {
921                     SfxSlotPool& rSlotPool = SfxSlotPool::GetSlotPool( pAct );
922                     const SfxSlot* pSlot = rSlotPool.GetSlot( SID_JUMPTOMARK );
923                     if( aURL.Main.getLength() && aURL.Main == xModel->getURL() && pSlot )
924                         return REFERENCE< XDISPATCH >( new SfxOfficeDispatch( pAct->GetBindings(), pAct->GetDispatcher(), pSlot, aURL) );
925                 }
926             }
927         }
928     }
929 
930 	return xDisp;
931 }
932 
933 //________________________________________________________________________________________________________
934 //	SfxBaseController -> XDispatchProvider
935 //________________________________________________________________________________________________________
936 
queryDispatches(const uno::Sequence<DISPATCHDESCRIPTOR> & seqDescripts)937 uno::Sequence< REFERENCE< XDISPATCH > > SAL_CALL SfxBaseController::queryDispatches( const uno::Sequence< DISPATCHDESCRIPTOR >& seqDescripts ) throw( ::com::sun::star::uno::RuntimeException )
938 {
939     // Create return list - which must have same size then the given descriptor
940     // It's not allowed to pack it!
941     sal_Int32 nCount = seqDescripts.getLength();
942     uno::Sequence< REFERENCE< XDISPATCH > > lDispatcher( nCount );
943 
944     for( sal_Int32 i=0; i<nCount; ++i )
945     {
946         lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL  ,
947                                         seqDescripts[i].FrameName   ,
948                                         seqDescripts[i].SearchFlags );
949     }
950 
951     return lDispatcher;
952 }
953 
954 //________________________________________________________________________________________________________
955 //	SfxBaseController -> XControllerBorder
956 //________________________________________________________________________________________________________
957 
getBorder()958 frame::BorderWidths SAL_CALL SfxBaseController::getBorder()
959 	throw ( uno::RuntimeException )
960 {
961 	frame::BorderWidths aResult;
962 
963 	::vos::OGuard aGuard( Application::GetSolarMutex() );
964     if ( m_pData->m_pViewShell )
965 	{
966 		SvBorder aBorder = m_pData->m_pViewShell->GetBorderPixel();
967 		aResult.Left = aBorder.Left();
968 		aResult.Top = aBorder.Top();
969 		aResult.Right = aBorder.Right();
970 		aResult.Bottom = aBorder.Bottom();
971 	}
972 
973 	return aResult;
974 }
975 
addBorderResizeListener(const uno::Reference<frame::XBorderResizeListener> & xListener)976 void SAL_CALL SfxBaseController::addBorderResizeListener( const uno::Reference< frame::XBorderResizeListener >& xListener )
977 	throw ( uno::RuntimeException )
978 {
979 	m_pData->m_aListenerContainer.addInterface( ::getCppuType((const uno::Reference< frame::XBorderResizeListener >*)0),
980 												xListener );
981 }
982 
removeBorderResizeListener(const uno::Reference<frame::XBorderResizeListener> & xListener)983 void SAL_CALL SfxBaseController::removeBorderResizeListener( const uno::Reference< frame::XBorderResizeListener >& xListener )
984 	throw ( uno::RuntimeException )
985 {
986 	m_pData->m_aListenerContainer.removeInterface( ::getCppuType((const uno::Reference< frame::XBorderResizeListener >*)0),
987 												xListener );
988 }
989 
queryBorderedArea(const awt::Rectangle & aPreliminaryRectangle)990 awt::Rectangle SAL_CALL SfxBaseController::queryBorderedArea( const awt::Rectangle& aPreliminaryRectangle )
991 	throw ( uno::RuntimeException )
992 {
993 	::vos::OGuard aGuard( Application::GetSolarMutex() );
994     if ( m_pData->m_pViewShell )
995 	{
996 		Rectangle aTmpRect = VCLRectangle( aPreliminaryRectangle );
997 		m_pData->m_pViewShell->QueryObjAreaPixel( aTmpRect );
998 		return AWTRectangle( aTmpRect );
999 	}
1000 
1001 	return aPreliminaryRectangle;
1002 }
1003 
BorderWidthsChanged_Impl()1004 void SfxBaseController::BorderWidthsChanged_Impl()
1005 {
1006    	::cppu::OInterfaceContainerHelper* pContainer = m_pData->m_aListenerContainer.getContainer(
1007 						::getCppuType( ( const uno::Reference< frame::XBorderResizeListener >*) NULL ) );
1008     if ( pContainer )
1009 	{
1010 		frame::BorderWidths aBWidths = getBorder();
1011 		uno::Reference< uno::XInterface > xThis( static_cast< ::cppu::OWeakObject* >(this), uno::UNO_QUERY );
1012 
1013 	    ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
1014 	    while (pIterator.hasMoreElements())
1015 	    {
1016 	        try
1017 	        {
1018 	            ((frame::XBorderResizeListener*)pIterator.next())->borderWidthsChanged( xThis, aBWidths );
1019 	        }
1020 	        catch( uno::RuntimeException& )
1021 	        {
1022 	            pIterator.remove();
1023 	        }
1024 	    }
1025 	}
1026 }
1027 
1028 //________________________________________________________________________________________________________
1029 //	SfxBaseController -> XComponent
1030 //________________________________________________________________________________________________________
1031 
dispose()1032 void SAL_CALL SfxBaseController::dispose() throw( ::com::sun::star::uno::RuntimeException )
1033 {
1034 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1035     Reference< XController > xTmp( this );
1036 	m_pData->m_bDisposing = sal_True ;
1037 
1038 	EVENTOBJECT aEventObject;
1039     aEventObject.Source = *this ;
1040 	m_pData->m_aListenerContainer.disposeAndClear( aEventObject ) ;
1041 
1042     if ( m_pData->m_pController && m_pData->m_pController->getFrame().is() )
1043         m_pData->m_pController->getFrame()->removeFrameActionListener( m_pData->m_xListener ) ;
1044 
1045     if ( m_pData->m_pViewShell )
1046     {
1047         SfxViewFrame* pFrame = m_pData->m_pViewShell->GetViewFrame() ;
1048         if ( pFrame && pFrame->GetViewShell() == m_pData->m_pViewShell )
1049             pFrame->GetFrame().SetIsClosing_Impl();
1050         m_pData->m_pViewShell->DiscardClients_Impl();
1051         m_pData->m_pViewShell->pImp->m_bControllerSet = false;
1052 
1053         if ( pFrame )
1054         {
1055             EVENTOBJECT aObject;
1056             aObject.Source = *this ;
1057 
1058             SfxObjectShell* pDoc = pFrame->GetObjectShell() ;
1059             SfxViewFrame *pView = SfxViewFrame::GetFirst(pDoc);
1060             while( pView )
1061             {
1062                 // if there is another ViewFrame or currently the ViewShell in my ViewFrame is switched (PagePreview)
1063                 if ( pView != pFrame || pView->GetViewShell() != m_pData->m_pViewShell )
1064                     break;
1065                 pView = SfxViewFrame::GetNext( *pView, pDoc );
1066             }
1067 
1068             SFX_APP()->NotifyEvent( SfxViewEventHint(SFX_EVENT_CLOSEVIEW, GlobalEventConfig::GetEventName( STR_EVENT_CLOSEVIEW ), pDoc, uno::Reference< frame::XController2 >( this ) ) );
1069             if ( !pView )
1070                 SFX_APP()->NotifyEvent( SfxEventHint(SFX_EVENT_CLOSEDOC, GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ), pDoc) );
1071 
1072             REFERENCE< XMODEL > xModel = pDoc->GetModel();
1073 			REFERENCE < ::com::sun::star::util::XCloseable > xCloseable( xModel, com::sun::star::uno::UNO_QUERY );
1074             if ( xModel.is() )
1075 			{
1076                 xModel->disconnectController( this );
1077 				if ( xCloseable.is() )
1078 					xCloseable->removeCloseListener( m_pData->m_xCloseListener );
1079 			}
1080 
1081             REFERENCE < XFRAME > aXFrame;
1082 			attachFrame( aXFrame );
1083 
1084             m_pData->m_xListener->disposing( aObject );
1085             SfxViewShell *pShell = m_pData->m_pViewShell;
1086             m_pData->m_pViewShell = NULL;
1087             if ( pFrame->GetViewShell() == pShell )
1088             {
1089                 // Enter registrations only allowed if we are the owner!
1090                 if ( pFrame->GetFrame().OwnsBindings_Impl() )
1091                     pFrame->GetBindings().ENTERREGISTRATIONS();
1092                 pFrame->GetFrame().SetFrameInterface_Impl(  aXFrame );
1093                 pFrame->GetFrame().DoClose_Impl();
1094             }
1095         }
1096     }
1097 }
1098 
1099 //________________________________________________________________________________________________________
1100 //	SfxBaseController -> XComponent
1101 //________________________________________________________________________________________________________
1102 
addEventListener(const REFERENCE<XEVENTLISTENER> & aListener)1103 void SAL_CALL SfxBaseController::addEventListener( const REFERENCE< XEVENTLISTENER >& aListener ) throw( ::com::sun::star::uno::RuntimeException )
1104 {
1105 	m_pData->m_aListenerContainer.addInterface( ::getCppuType((const REFERENCE< XEVENTLISTENER >*)0), aListener );
1106 }
1107 
1108 //________________________________________________________________________________________________________
1109 //	SfxBaseController -> XComponent
1110 //________________________________________________________________________________________________________
1111 
removeEventListener(const REFERENCE<XEVENTLISTENER> & aListener)1112 void SAL_CALL SfxBaseController::removeEventListener( const REFERENCE< XEVENTLISTENER >& aListener ) throw( ::com::sun::star::uno::RuntimeException )
1113 {
1114 	m_pData->m_aListenerContainer.removeInterface( ::getCppuType((const REFERENCE< XEVENTLISTENER >*)0), aListener );
1115 }
1116 
ReleaseShell_Impl()1117 void SfxBaseController::ReleaseShell_Impl()
1118 {
1119 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1120     if ( m_pData->m_pViewShell )
1121     {
1122         SfxObjectShell* pDoc = m_pData->m_pViewShell->GetObjectShell() ;
1123         REFERENCE< XMODEL > xModel = pDoc->GetModel();
1124         REFERENCE < ::com::sun::star::util::XCloseable > xCloseable( xModel, com::sun::star::uno::UNO_QUERY );
1125         if ( xModel.is() )
1126         {
1127             xModel->disconnectController( this );
1128             if ( xCloseable.is() )
1129                 xCloseable->removeCloseListener( m_pData->m_xCloseListener );
1130         }
1131         m_pData->m_pViewShell = 0;
1132 
1133         REFERENCE < XFRAME > aXFrame;
1134 		attachFrame( aXFrame );
1135     }
1136 }
1137 
GetViewShell_Impl() const1138 SfxViewShell* SfxBaseController::GetViewShell_Impl() const
1139 {
1140     return m_pData->m_pViewShell;
1141 }
1142 
getStatusIndicator()1143 ::com::sun::star::uno::Reference< ::com::sun::star::task::XStatusIndicator > SAL_CALL SfxBaseController::getStatusIndicator(  ) throw (::com::sun::star::uno::RuntimeException)
1144 {
1145 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1146     if ( m_pData->m_pViewShell && !m_pData->m_xIndicator.is() )
1147         m_pData->m_xIndicator = new SfxStatusIndicator( this, m_pData->m_pViewShell->GetViewFrame()->GetFrame().GetWorkWindow_Impl() );
1148     return m_pData->m_xIndicator;
1149 }
1150 
registerContextMenuInterceptor(const REFERENCE<XCONTEXTMENUINTERCEPTOR> & xInterceptor)1151 void SAL_CALL SfxBaseController::registerContextMenuInterceptor( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor ) throw( RUNTIMEEXCEPTION )
1152 
1153 {
1154     m_pData->m_aInterceptorContainer.addInterface( xInterceptor );
1155 
1156 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1157     if ( m_pData->m_pViewShell )
1158         m_pData->m_pViewShell->AddContextMenuInterceptor_Impl( xInterceptor );
1159 }
1160 
releaseContextMenuInterceptor(const REFERENCE<XCONTEXTMENUINTERCEPTOR> & xInterceptor)1161 void SAL_CALL SfxBaseController::releaseContextMenuInterceptor( const REFERENCE< XCONTEXTMENUINTERCEPTOR >& xInterceptor ) throw( RUNTIMEEXCEPTION )
1162 
1163 {
1164     m_pData->m_aInterceptorContainer.removeInterface( xInterceptor );
1165 
1166 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1167     if ( m_pData->m_pViewShell )
1168         m_pData->m_pViewShell->RemoveContextMenuInterceptor_Impl( xInterceptor );
1169 }
1170 
addKeyHandler(const::com::sun::star::uno::Reference<XKEYHANDLER> & xHandler)1171 void SAL_CALL SfxBaseController::addKeyHandler( const ::com::sun::star::uno::Reference< XKEYHANDLER >& xHandler ) throw (::com::sun::star::uno::RuntimeException)
1172 {
1173 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1174     m_pData->m_aUserInputInterception.addKeyHandler( xHandler );
1175 }
1176 
removeKeyHandler(const::com::sun::star::uno::Reference<XKEYHANDLER> & xHandler)1177 void SAL_CALL SfxBaseController::removeKeyHandler( const ::com::sun::star::uno::Reference< XKEYHANDLER >& xHandler ) throw (::com::sun::star::uno::RuntimeException)
1178 {
1179 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1180     m_pData->m_aUserInputInterception.removeKeyHandler( xHandler );
1181 }
1182 
addMouseClickHandler(const::com::sun::star::uno::Reference<::com::sun::star::awt::XMouseClickHandler> & xHandler)1183 void SAL_CALL SfxBaseController::addMouseClickHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseClickHandler >& xHandler ) throw (::com::sun::star::uno::RuntimeException)
1184 {
1185 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1186     m_pData->m_aUserInputInterception.addMouseClickHandler( xHandler );
1187 }
1188 
removeMouseClickHandler(const::com::sun::star::uno::Reference<::com::sun::star::awt::XMouseClickHandler> & xHandler)1189 void SAL_CALL SfxBaseController::removeMouseClickHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseClickHandler >& xHandler ) throw (::com::sun::star::uno::RuntimeException)
1190 {
1191 	::vos::OGuard aGuard( Application::GetSolarMutex() );
1192     m_pData->m_aUserInputInterception.removeMouseClickHandler( xHandler );
1193 }
1194 
getSupportedCommandGroups()1195 ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL SfxBaseController::getSupportedCommandGroups()
1196 throw (::com::sun::star::uno::RuntimeException)
1197 {
1198     ::vos::OGuard aGuard( Application::GetSolarMutex() );
1199 
1200     std::list< sal_Int16 > aGroupList;
1201     SfxViewFrame* pViewFrame( m_pData->m_pViewShell->GetFrame() );
1202     SfxSlotPool*  pPool = &SfxSlotPool::GetSlotPool( pViewFrame );
1203 
1204     SfxSlotPool* pSlotPool = pPool ? pPool : &SFX_SLOTPOOL();
1205     const sal_uIntPtr nMode( SFX_SLOT_TOOLBOXCONFIG|SFX_SLOT_ACCELCONFIG|SFX_SLOT_MENUCONFIG );
1206 
1207     // Gruppe anw"ahlen ( Gruppe 0 ist intern )
1208     for ( sal_uInt16 i=0; i<pSlotPool->GetGroupCount(); i++ )
1209 	{
1210 		String aName = pSlotPool->SeekGroup( i );
1211         const SfxSlot* pSfxSlot = pSlotPool->FirstSlot();
1212         while ( pSfxSlot )
1213 		{
1214             if ( pSfxSlot->GetMode() & nMode )
1215 			{
1216                 sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
1217                 aGroupList.push_back( nCommandGroup );
1218                 break;
1219 			}
1220 			pSfxSlot = pSlotPool->NextSlot();
1221 		}
1222     }
1223 
1224     ::com::sun::star::uno::Sequence< sal_Int16 > aSeq =
1225         comphelper::containerToSequence< sal_Int16 >( aGroupList );
1226     return aSeq;
1227 }
1228 
getConfigurableDispatchInformation(sal_Int16 nCmdGroup)1229 ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchInformation > SAL_CALL SfxBaseController::getConfigurableDispatchInformation( sal_Int16 nCmdGroup )
1230 throw (::com::sun::star::uno::RuntimeException)
1231 {
1232     std::list< ::com::sun::star::frame::DispatchInformation > aCmdList;
1233 
1234     ::vos::OGuard aGuard( Application::GetSolarMutex() );
1235     if ( m_pData->m_pViewShell )
1236     {
1237         const sal_uIntPtr nMode( SFX_SLOT_TOOLBOXCONFIG|SFX_SLOT_ACCELCONFIG|SFX_SLOT_MENUCONFIG );
1238 
1239         SfxViewFrame* pViewFrame( m_pData->m_pViewShell->GetFrame() );
1240         SfxSlotPool*  pPool( &SfxSlotPool::GetSlotPool( pViewFrame ));
1241         rtl::OUString aCmdPrefix( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ));
1242 
1243         SfxSlotPool* pSlotPool = pPool ? pPool : &SFX_SLOTPOOL();
1244         for ( sal_uInt16 i=0; i<pSlotPool->GetGroupCount(); i++ )
1245 		{
1246 			String aName = pSlotPool->SeekGroup( i );
1247 			const SfxSlot* pSfxSlot = pSlotPool->FirstSlot();
1248 			if ( pSfxSlot )
1249 			{
1250                 sal_Int16 nCommandGroup = MapGroupIDToCommandGroup( pSfxSlot->GetGroupId() );
1251                 if ( nCommandGroup == nCmdGroup )
1252                 {
1253                     while ( pSfxSlot )
1254 				    {
1255                         if ( pSfxSlot->GetMode() & nMode )
1256 					    {
1257                             ::com::sun::star::frame::DispatchInformation aCmdInfo;
1258                             ::rtl::OUStringBuffer aBuf( aCmdPrefix );
1259                             aBuf.appendAscii( pSfxSlot->GetUnoName() );
1260                             aCmdInfo.Command = aBuf.makeStringAndClear();
1261                             aCmdInfo.GroupId = nCommandGroup;
1262                             aCmdList.push_back( aCmdInfo );
1263 					    }
1264 					    pSfxSlot = pSlotPool->NextSlot();
1265 				    }
1266                 }
1267 		    }
1268         }
1269     }
1270 
1271     ::com::sun::star::uno::Sequence< ::com::sun::star::frame::DispatchInformation > aSeq =
1272         comphelper::containerToSequence< ::com::sun::star::frame::DispatchInformation, std::list< ::com::sun::star::frame::DispatchInformation > >( aCmdList );
1273 
1274     return aSeq;
1275 }
1276 
HandleEvent_Impl(NotifyEvent & rEvent)1277 sal_Bool SfxBaseController::HandleEvent_Impl( NotifyEvent& rEvent )
1278 {
1279     return m_pData->m_aUserInputInterception.handleNotifyEvent( rEvent );
1280 }
1281 
HasKeyListeners_Impl()1282 sal_Bool SfxBaseController::HasKeyListeners_Impl()
1283 {
1284     return m_pData->m_aUserInputInterception.hasKeyHandlers();
1285 }
1286 
HasMouseClickListeners_Impl()1287 sal_Bool SfxBaseController::HasMouseClickListeners_Impl()
1288 {
1289     return m_pData->m_aUserInputInterception.hasMouseClickListeners();
1290 }
1291 
ConnectSfxFrame_Impl(const ConnectSfxFrame i_eConnect)1292 void SfxBaseController::ConnectSfxFrame_Impl( const ConnectSfxFrame i_eConnect )
1293 {
1294     ENSURE_OR_THROW( m_pData->m_pViewShell, "not to be called without a view shell" );
1295     SfxViewFrame* pViewFrame = m_pData->m_pViewShell->GetFrame();
1296     ENSURE_OR_THROW( pViewFrame, "a view shell without a view frame is pretty pathological" );
1297 
1298     const bool bConnect = ( i_eConnect != E_DISCONNECT );
1299 
1300     // disable window and dispatcher
1301     pViewFrame->Enable( bConnect );
1302     pViewFrame->GetDispatcher()->Lock( !bConnect );
1303 
1304     if ( bConnect )
1305     {
1306         if ( i_eConnect == E_CONNECT )
1307         {
1308             if  (   ( m_pData->m_pViewShell->GetObjectShell() != NULL )
1309                 &&  ( m_pData->m_pViewShell->GetObjectShell()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1310                 )
1311             {
1312                 SfxViewFrame* pViewFrm = m_pData->m_pViewShell->GetViewFrame();
1313                 if ( !pViewFrm->GetFrame().IsInPlace() )
1314                 {
1315                     // for outplace embedded objects, we want the layout manager to keep the content window
1316                     // size constant, if possible
1317                     try
1318                     {
1319                         uno::Reference< beans::XPropertySet > xFrameProps( m_pData->m_xFrame, uno::UNO_QUERY_THROW );
1320                         uno::Reference< beans::XPropertySet > xLayouterProps(
1321                             xFrameProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ) ), uno::UNO_QUERY_THROW );
1322                         xLayouterProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PreserveContentSize" ) ), uno::makeAny( sal_True ) );
1323                     }
1324                     catch( const uno::Exception& )
1325                     {
1326                 	    DBG_UNHANDLED_EXCEPTION();
1327                     }
1328                 }
1329             }
1330         }
1331 
1332         // upon DISCONNECT, we did *not* pop the shells from the stack (this is done elsewhere), so upon
1333         // RECONNECT, we're not allowed to push them
1334         if ( i_eConnect != E_RECONNECT )
1335         {
1336             pViewFrame->GetDispatcher()->Push( *m_pData->m_pViewShell );
1337             if ( m_pData->m_pViewShell->GetSubShell() )
1338                 pViewFrame->GetDispatcher()->Push( *m_pData->m_pViewShell->GetSubShell() );
1339 	        m_pData->m_pViewShell->PushSubShells_Impl();
1340             pViewFrame->GetDispatcher()->Flush();
1341         }
1342 
1343         Window* pEditWin = m_pData->m_pViewShell->GetWindow();
1344         if ( pEditWin && m_pData->m_pViewShell->IsShowView_Impl() )
1345             pEditWin->Show();
1346 
1347         if ( SfxViewFrame::Current() == pViewFrame )
1348             pViewFrame->GetDispatcher()->Update_Impl( sal_True );
1349 
1350         Window* pFrameWin = &pViewFrame->GetWindow();
1351         if ( pFrameWin != &pViewFrame->GetFrame().GetWindow() )
1352 	        pFrameWin->Show();
1353 
1354         if ( i_eConnect == E_CONNECT )
1355         {
1356             ::comphelper::NamedValueCollection aDocumentArgs( getModel()->getArgs() );
1357 
1358             const sal_Int16 nPluginMode = aDocumentArgs.getOrDefault( "PluginMode", sal_Int16( 0 ) );
1359             const bool bHasPluginMode = ( nPluginMode != 0 );
1360 
1361             SfxFrame& rFrame = pViewFrame->GetFrame();
1362             SfxObjectShell& rDoc = *m_pData->m_pViewShell->GetObjectShell();
1363             if ( !rFrame.IsMarkedHidden_Impl() )
1364 	        {
1365                 if ( rDoc.IsHelpDocument() || ( nPluginMode == 2 ) )
1366                     pViewFrame->GetDispatcher()->HideUI( sal_True );
1367                 else
1368                     pViewFrame->GetDispatcher()->HideUI( sal_False );
1369 
1370                 if ( rFrame.IsInPlace() )
1371                     pViewFrame->LockAdjustPosSizePixel();
1372 
1373                 if ( nPluginMode == 3 )
1374                     rFrame.GetWorkWindow_Impl()->SetInternalDockingAllowed( sal_False );
1375 
1376                 if ( !rFrame.IsInPlace() )
1377 			        pViewFrame->GetDispatcher()->Update_Impl();
1378 		        pViewFrame->Show();
1379                 rFrame.GetWindow().Show();
1380                 if ( !rFrame.IsInPlace() || ( nPluginMode == 3 ) )
1381                     pViewFrame->MakeActive_Impl( rFrame.GetFrameInterface()->isActive() );
1382 
1383                 if ( rFrame.IsInPlace() )
1384                 {
1385                     pViewFrame->UnlockAdjustPosSizePixel();
1386                     // force resize for OLE server to fix layout problems of writer and math
1387                     // see i53651
1388                     if ( nPluginMode == 3 )
1389                         pViewFrame->Resize( sal_True );
1390                 }
1391 	        }
1392             else
1393             {
1394                 DBG_ASSERT( !rFrame.IsInPlace() && !bHasPluginMode, "Special modes not compatible with hidden mode!" );
1395                 rFrame.GetWindow().Show();
1396             }
1397 
1398 	        // Jetzt UpdateTitle, hidden TopFrames haben sonst keinen Namen!
1399 	        pViewFrame->UpdateTitle();
1400 
1401             if ( !rFrame.IsInPlace() )
1402                 pViewFrame->Resize( sal_True );
1403 
1404             // if there's a JumpMark given, then, well, jump to it
1405             ::comphelper::NamedValueCollection aViewArgs( getCreationArguments() );
1406             const ::rtl::OUString sJumpMark = aViewArgs.getOrDefault( "JumpMark", ::rtl::OUString() );
1407             const bool bHasJumpMark = ( sJumpMark.getLength() > 0 );
1408             OSL_ENSURE( ( !m_pData->m_pViewShell->GetObjectShell()->IsLoading() )
1409                     ||  ( !sJumpMark.getLength() ),
1410                 "SfxBaseController::ConnectSfxFrame_Impl: so this code wasn't dead?" );
1411                 // Before CWS autorecovery, there was code which postponed jumping to the Mark to a later time
1412                 // (SfxObjectShell::PositionView_Impl), but it seems this branch was never used, since this method
1413                 // here is never called before the load process finished. At least not with a non-empty jump mark
1414             if ( sJumpMark.getLength() )
1415 		        m_pData->m_pViewShell->JumpToMark( sJumpMark );
1416 
1417             // if no plugin mode and no jump mark was supplied, check whether the document itself can provide view data, and
1418             // if so, forward it to the view/shell.
1419             if ( !bHasPluginMode && !bHasJumpMark )
1420             {
1421                 // Note that this might not be the ideal place here. Restoring view data should, IMO, be the
1422                 // responsibility of the loader, not an implementation detail buried here deep within the controller's
1423                 // implementation.
1424                 // What I think should be done to replace the below code:
1425                 // - change SfxBaseController::restoreViewData to also accept a PropertyValue[] (it currently accepts
1426                 //   a string only), and forward it to its ViewShell's ReadUserDataSequence
1427                 // - change the frame loader so that when a new document is loaded (as opposed to an existing
1428                 //   document being loaded into a new frame), the model's view data is examine the very same
1429                 //   way as below, and the proper view data is set via XController::restoreViewData
1430                 // - extend SfxViewFrame::SwitchToViewShell_Impl. Currently, it cares for the case where a non-PrintPreview
1431                 //   view is exchanged, and sets the old view's data at the model. It should also care for the other
1432                 //   way, were the PrintPreview view is left: in this case, the new view should also be initialized
1433                 //   with the model's view data
1434                 try
1435                 {
1436                     Reference< XViewDataSupplier > xViewDataSupplier( getModel(), UNO_QUERY_THROW );
1437                     Reference< XIndexAccess > xViewData( xViewDataSupplier->getViewData() );
1438 
1439                     // find the view data item whose ViewId matches the ID of the view we're just connecting to
1440                     const SfxObjectFactory& rDocFactory( rDoc.GetFactory() );
1441                     const sal_Int32 nCount = xViewData.is() ? xViewData->getCount() : 0;
1442                     sal_Int32 nViewDataIndex = 0;
1443                     for ( sal_Int32 i=0; i<nCount; ++i )
1444                     {
1445                         const ::comphelper::NamedValueCollection aViewData( xViewData->getByIndex(i) );
1446                         ::rtl::OUString sViewId( aViewData.getOrDefault( "ViewId", ::rtl::OUString() ) );
1447                         if ( sViewId.getLength() == 0 )
1448                             continue;
1449 
1450                         const SfxViewFactory* pViewFactory = rDocFactory.GetViewFactoryByViewName( sViewId );
1451                         if ( pViewFactory == NULL )
1452                             continue;
1453 
1454                         if ( pViewFactory->GetOrdinal() == pViewFrame->GetCurViewId() )
1455                         {
1456                             nViewDataIndex = i;
1457                             break;
1458                         }
1459                     }
1460                     if ( nViewDataIndex < nCount )
1461                     {
1462                         Sequence< PropertyValue > aViewData;
1463                         OSL_VERIFY( xViewData->getByIndex( nViewDataIndex ) >>= aViewData );
1464                         if ( aViewData.getLength() > 0 )
1465                             m_pData->m_pViewShell->ReadUserDataSequence( aViewData, sal_True );
1466                     }
1467                 }
1468                 catch( const Exception& )
1469                 {
1470         	        DBG_UNHANDLED_EXCEPTION();
1471                 }
1472             }
1473         }
1474     }
1475 
1476     // invalidate slot corresponding to the view shell
1477     const sal_uInt16 nViewNo = m_pData->m_pViewShell->GetObjectShell()->GetFactory().GetViewNo_Impl( pViewFrame->GetCurViewId(), USHRT_MAX );
1478     DBG_ASSERT( nViewNo != USHRT_MAX, "view shell id not found" );
1479     if ( nViewNo != USHRT_MAX )
1480         pViewFrame->GetBindings().Invalidate( nViewNo + SID_VIEWSHELL0 );
1481 }
1482 
1483 //=============================================================================
impl_getTitleHelper()1484 css::uno::Reference< css::frame::XTitle > SfxBaseController::impl_getTitleHelper ()
1485 {
1486     ::vos::OGuard aGuard( Application::GetSolarMutex() );
1487 
1488     if ( ! m_pData->m_xTitleHelper.is ())
1489     {
1490         css::uno::Reference< css::frame::XModel >           xModel           = getModel ();
1491         css::uno::Reference< css::frame::XUntitledNumbers > xUntitledProvider(xModel                                       , css::uno::UNO_QUERY      );
1492         css::uno::Reference< css::frame::XController >      xThis            (static_cast< css::frame::XController* >(this), css::uno::UNO_QUERY_THROW);
1493 
1494         ::framework::TitleHelper* pHelper                 = new ::framework::TitleHelper(::comphelper::getProcessServiceFactory());
1495                                   m_pData->m_xTitleHelper = css::uno::Reference< css::frame::XTitle >(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
1496 
1497         pHelper->setOwner                   (xThis            );
1498         pHelper->connectWithUntitledNumbers (xUntitledProvider);
1499     }
1500 
1501     return m_pData->m_xTitleHelper;
1502 }
1503 
1504 //=============================================================================
1505 // css::frame::XTitle
getTitle()1506 ::rtl::OUString SAL_CALL SfxBaseController::getTitle()
1507     throw (css::uno::RuntimeException)
1508 {
1509     return impl_getTitleHelper()->getTitle ();
1510 }
1511 
1512 //=============================================================================
1513 // css::frame::XTitle
setTitle(const::rtl::OUString & sTitle)1514 void SAL_CALL SfxBaseController::setTitle(const ::rtl::OUString& sTitle)
1515     throw (css::uno::RuntimeException)
1516 {
1517     impl_getTitleHelper()->setTitle (sTitle);
1518 }
1519 
1520 //=============================================================================
1521 // css::frame::XTitleChangeBroadcaster
addTitleChangeListener(const css::uno::Reference<css::frame::XTitleChangeListener> & xListener)1522 void SAL_CALL SfxBaseController::addTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
1523     throw (css::uno::RuntimeException)
1524 {
1525     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
1526     if (xBroadcaster.is ())
1527         xBroadcaster->addTitleChangeListener (xListener);
1528 }
1529 
1530 //=============================================================================
1531 // css::frame::XTitleChangeBroadcaster
removeTitleChangeListener(const css::uno::Reference<css::frame::XTitleChangeListener> & xListener)1532 void SAL_CALL SfxBaseController::removeTitleChangeListener(const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
1533     throw (css::uno::RuntimeException)
1534 {
1535     css::uno::Reference< css::frame::XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper(), css::uno::UNO_QUERY);
1536     if (xBroadcaster.is ())
1537         xBroadcaster->removeTitleChangeListener (xListener);
1538 }
1539