1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "DrawController.hxx"
32 #include "DrawDocShell.hxx"
33 
34 #include "DrawSubController.hxx"
35 #include "sdpage.hxx"
36 #include "ViewShellBase.hxx"
37 #include "ViewShellManager.hxx"
38 #include "FormShellManager.hxx"
39 #include "Window.hxx"
40 
41 #include <comphelper/anytostring.hxx>
42 #include <comphelper/processfactory.hxx>
43 #include <comphelper/sequence.hxx>
44 #include <comphelper/stl_types.hxx>
45 #include <cppuhelper/exc_hlp.hxx>
46 #include <cppuhelper/bootstrap.hxx>
47 
48 #include <com/sun/star/beans/PropertyAttribute.hpp>
49 #include <com/sun/star/drawing/framework/ConfigurationController.hpp>
50 #include <com/sun/star/drawing/framework/ModuleController.hpp>
51 #include <com/sun/star/lang/XInitialization.hpp>
52 
53 #include "slideshow.hxx"
54 
55 #include <svx/fmshell.hxx>
56 #include <vos/mutex.hxx>
57 #include <vcl/svapp.hxx>
58 #include <boost/shared_ptr.hpp>
59 
60 using namespace ::std;
61 using ::rtl::OUString;
62 using namespace ::cppu;
63 using namespace ::vos;
64 using namespace ::com::sun::star;
65 using namespace ::com::sun::star::uno;
66 using namespace ::com::sun::star::drawing::framework;
67 
68 namespace {
69 static const ::com::sun::star::uno::Type saComponentTypeIdentifier (
70     ::getCppuType( (Reference<lang::XEventListener > *)0 ));
71 static const ::com::sun::star::uno::Type saSelectionTypeIdentifier (
72     ::getCppuType( (Reference<view::XSelectionChangeListener > *)0 ));
73 
74 } // end of anonymous namespace
75 
76 namespace sd {
77 
78 DrawController::DrawController (ViewShellBase& rBase) throw()
79     : DrawControllerInterfaceBase(&rBase),
80       BroadcastHelperOwner(SfxBaseController::m_aMutex),
81       OPropertySetHelper( static_cast<OBroadcastHelperVar<
82           OMultiTypeInterfaceContainerHelper,
83           OMultiTypeInterfaceContainerHelper::keyType>& >(
84               BroadcastHelperOwner::maBroadcastHelper)),
85       mpBase(&rBase),
86       maLastVisArea(),
87       mpCurrentPage(NULL),
88       mbMasterPageMode(false),
89       mbLayerMode(false),
90       mbDisposing(false),
91       mpPropertyArrayHelper(NULL),
92       mxSubController(),
93       mxConfigurationController(),
94       mxModuleController()
95 {
96     ProvideFrameworkControllers();
97 }
98 
99 
100 
101 
102 DrawController::~DrawController (void) throw()
103 {
104 }
105 
106 
107 
108 
109 void DrawController::SetSubController (
110     const Reference<drawing::XDrawSubController>& rxSubController)
111 {
112     // Update the internal state.
113     mxSubController = rxSubController;
114     mpPropertyArrayHelper.reset();
115     maLastVisArea = Rectangle();
116 
117     // Inform listeners about the changed state.
118     FireSelectionChangeListener();
119 }
120 
121 
122 
123 
124 // XInterface
125 
126 IMPLEMENT_FORWARD_XINTERFACE2(
127     DrawController,
128     DrawControllerInterfaceBase,
129     OPropertySetHelper);
130 
131 
132 // XTypeProvider
133 
134 Sequence<Type> SAL_CALL DrawController::getTypes (void)
135     throw (::com::sun::star::uno::RuntimeException)
136 {
137     ThrowIfDisposed();
138     // OPropertySetHelper does not provide getTypes, so we have to
139     // implement this method manually and list its three interfaces.
140     OTypeCollection aTypeCollection (
141         ::getCppuType (( const Reference<beans::XMultiPropertySet>*)NULL),
142         ::getCppuType (( const Reference<beans::XFastPropertySet>*)NULL),
143         ::getCppuType (( const Reference<beans::XPropertySet>*)NULL));
144 
145     return ::comphelper::concatSequences(
146         SfxBaseController::getTypes(),
147         aTypeCollection.getTypes(),
148         DrawControllerInterfaceBase::getTypes());
149 }
150 
151 IMPLEMENT_GET_IMPLEMENTATION_ID(DrawController);
152 
153 
154 
155 // XComponent
156 
157 
158 void SAL_CALL DrawController::dispose (void)
159 	throw( RuntimeException )
160 {
161 	if( !mbDisposing )
162 	{
163 		OGuard aGuard( Application::GetSolarMutex() );
164 
165 		if( !mbDisposing )
166 		{
167 			mbDisposing = true;
168 
169             boost::shared_ptr<ViewShell> pViewShell = mpBase->GetMainViewShell();
170             if ( pViewShell )
171             {
172                 pViewShell->DeactivateCurrentFunction();
173                 DrawDocShell* pDocShell = pViewShell->GetDocSh();
174                 if ( pDocShell != NULL )
175                     pDocShell->SetDocShellFunction(0);
176             }
177             pViewShell.reset();
178 
179             // When the controller has not been detached from its view
180             // shell, i.e. mpViewShell is not NULL, then tell PaneManager
181             // and ViewShellManager to clear the shell stack.
182             if (mxSubController.is() && mpBase!=NULL)
183             {
184                 mpBase->DisconnectAllClients();
185                 mpBase->GetViewShellManager()->Shutdown();
186             }
187 
188             OPropertySetHelper::disposing();
189 
190             DisposeFrameworkControllers();
191 
192 			SfxBaseController::dispose();
193 		}
194 	}
195 }
196 
197 
198 
199 
200 void SAL_CALL DrawController::addEventListener(
201     const Reference<lang::XEventListener >& xListener)
202     throw (RuntimeException)
203 {
204     ThrowIfDisposed();
205 	SfxBaseController::addEventListener( xListener );
206 }
207 
208 
209 
210 
211 void SAL_CALL DrawController::removeEventListener (
212     const Reference<lang::XEventListener >& aListener)
213     throw (RuntimeException)
214 {
215 	if(!rBHelper.bDisposed && !rBHelper.bInDispose && !mbDisposing)
216 		SfxBaseController::removeEventListener( aListener );
217 }
218 
219 // XController
220 ::sal_Bool SAL_CALL DrawController::suspend( ::sal_Bool Suspend ) throw (::com::sun::star::uno::RuntimeException)
221 {
222 	if( Suspend )
223 	{
224 		ViewShellBase* pViewShellBase = GetViewShellBase();
225 		if( pViewShellBase )
226 		{
227 			// do not allow suspend if a slideshow needs this controller!
228 			rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( *pViewShellBase ) );
229 			if( xSlideShow.is() && xSlideShow->dependsOn(pViewShellBase) )
230 				return sal_False;
231 		}
232 	}
233 
234 	return SfxBaseController::suspend( Suspend );
235 }
236 
237 
238 // XServiceInfo
239 
240 OUString SAL_CALL DrawController::getImplementationName(  ) throw(RuntimeException)
241 {
242     // Do not throw an excepetion at the moment.  This leads to a crash
243     // under Solaris on relead.  See issue i70929 for details.
244     //    ThrowIfDisposed();
245 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "DrawController" ) );
246 }
247 
248 
249 
250 static OUString ssServiceName (OUString::createFromAscii(
251     "com.sun.star.drawing.DrawingDocumentDrawView"));
252 
253 sal_Bool SAL_CALL DrawController::supportsService (
254     const OUString& rsServiceName)
255     throw(RuntimeException)
256 {
257     // Do not throw an excepetion at the moment.  This leads to a crash
258     // under Solaris on relead.  See issue i70929 for details.
259     //    ThrowIfDisposed();
260     return rsServiceName.equals(ssServiceName);
261 }
262 
263 
264 
265 
266 Sequence<OUString> SAL_CALL DrawController::getSupportedServiceNames (void)
267     throw(RuntimeException)
268 {
269     ThrowIfDisposed();
270 	Sequence<OUString> aSupportedServices (1);
271 	OUString* pServices = aSupportedServices.getArray();
272     pServices[0] = ssServiceName;
273 	return aSupportedServices;
274 }
275 
276 
277 
278 
279 //------ XSelectionSupplier --------------------------------------------
280 
281 sal_Bool SAL_CALL DrawController::select (const Any& aSelection)
282 	throw(lang::IllegalArgumentException, RuntimeException)
283 {
284     ThrowIfDisposed();
285 	::vos::OGuard aGuard (Application::GetSolarMutex());
286 
287     if (mxSubController.is())
288         return mxSubController->select(aSelection);
289     else
290         return false;
291 }
292 
293 
294 
295 
296 Any SAL_CALL DrawController::getSelection()
297 	throw(RuntimeException)
298 {
299     ThrowIfDisposed();
300 	::vos::OGuard aGuard (Application::GetSolarMutex());
301 
302     if (mxSubController.is())
303         return mxSubController->getSelection();
304     else
305         return Any();
306 }
307 
308 
309 
310 
311 void SAL_CALL DrawController::addSelectionChangeListener(
312     const Reference< view::XSelectionChangeListener >& xListener)
313 	throw(RuntimeException)
314 {
315 	if( mbDisposing )
316 		throw lang::DisposedException();
317 
318     BroadcastHelperOwner::maBroadcastHelper.addListener (saSelectionTypeIdentifier, xListener);
319 }
320 
321 
322 
323 
324 void SAL_CALL DrawController::removeSelectionChangeListener(
325     const Reference< view::XSelectionChangeListener >& xListener )
326     throw(RuntimeException)
327 {
328     if (rBHelper.bDisposed)
329         throw lang::DisposedException();
330 
331 	BroadcastHelperOwner::maBroadcastHelper.removeListener (saSelectionTypeIdentifier, xListener);
332 }
333 
334 
335 
336 
337 
338 //=====  lang::XEventListener  ================================================
339 
340 void SAL_CALL
341     DrawController::disposing (const lang::EventObject& )
342     throw (uno::RuntimeException)
343 {
344 }
345 
346 
347 
348 
349 //=====  view::XSelectionChangeListener  ======================================
350 
351 void  SAL_CALL
352     DrawController::selectionChanged (const lang::EventObject& rEvent)
353         throw (uno::RuntimeException)
354 {
355     ThrowIfDisposed();
356     // Have to forward the event to our selection change listeners.
357 	OInterfaceContainerHelper* pListeners = BroadcastHelperOwner::maBroadcastHelper.getContainer(
358         ::getCppuType((Reference<view::XSelectionChangeListener>*)0));
359 	if (pListeners)
360 	{
361 		// Re-send the event to all of our listeners.
362 		OInterfaceIteratorHelper aIterator (*pListeners);
363 		while (aIterator.hasMoreElements())
364 		{
365             try
366             {
367                 view::XSelectionChangeListener* pListener =
368                     static_cast<view::XSelectionChangeListener*>(
369                         aIterator.next());
370                 if (pListener != NULL)
371                     pListener->selectionChanged (rEvent);
372             }
373             catch (RuntimeException aException)
374             {
375             }
376 		}
377 	}
378 }
379 
380 
381 
382 
383 // XDrawView
384 
385 void SAL_CALL DrawController::setCurrentPage( const Reference< drawing::XDrawPage >& xPage )
386 	throw(RuntimeException)
387 {
388     ThrowIfDisposed();
389     ::vos::OGuard aGuard (Application::GetSolarMutex());
390 
391     if (mxSubController.is())
392         mxSubController->setCurrentPage(xPage);
393 }
394 
395 
396 
397 
398 Reference< drawing::XDrawPage > SAL_CALL DrawController::getCurrentPage (void)
399 	throw(RuntimeException)
400 {
401     ThrowIfDisposed();
402 	::vos::OGuard aGuard( Application::GetSolarMutex() );
403     Reference<drawing::XDrawPage> xPage;
404 
405     // Get current page from sub controller.
406     if (mxSubController.is())
407         xPage = mxSubController->getCurrentPage();
408 
409     // When there is not yet a sub controller (during initialization) then fall back
410     // to the current page in mpCurrentPage.
411     if ( ! xPage.is() && mpCurrentPage.is())
412         xPage = Reference<drawing::XDrawPage>(mpCurrentPage->getUnoPage(), UNO_QUERY);
413 
414 	return xPage;
415 }
416 
417 
418 
419 
420 void DrawController::FireVisAreaChanged (const Rectangle& rVisArea) throw()
421 {
422 	if( maLastVisArea != rVisArea )
423 	{
424 		Any aNewValue;
425 		aNewValue <<= awt::Rectangle(
426             rVisArea.Left(),
427             rVisArea.Top(),
428             rVisArea.GetWidth(),
429             rVisArea.GetHeight() );
430 
431 		Any aOldValue;
432 		aOldValue <<= awt::Rectangle(
433             maLastVisArea.Left(),
434             maLastVisArea.Top(),
435             maLastVisArea.GetWidth(),
436             maLastVisArea.GetHeight() );
437 
438         FirePropertyChange (PROPERTY_WORKAREA, aNewValue, aOldValue);
439 
440 		maLastVisArea = rVisArea;
441 	}
442 }
443 
444 
445 
446 
447 void DrawController::FireSelectionChangeListener() throw()
448 {
449 	OInterfaceContainerHelper * pLC = BroadcastHelperOwner::maBroadcastHelper.getContainer(
450         saSelectionTypeIdentifier);
451 	if( pLC )
452 	{
453 		Reference< XInterface > xSource( (XWeak*)this );
454 		const lang::EventObject aEvent( xSource );
455 
456 		// Ueber alle Listener iterieren und Events senden
457 		OInterfaceIteratorHelper aIt( *pLC);
458 		while( aIt.hasMoreElements() )
459 		{
460             try
461             {
462                 view::XSelectionChangeListener * pL =
463                     static_cast<view::XSelectionChangeListener*>(aIt.next());
464                 if (pL != NULL)
465                     pL->selectionChanged( aEvent );
466             }
467             catch (RuntimeException aException)
468             {
469             }
470 		}
471 	}
472 }
473 
474 
475 
476 
477 void DrawController::FireChangeEditMode (bool bMasterPageMode) throw()
478 {
479 	if (bMasterPageMode != mbMasterPageMode )
480 	{
481         FirePropertyChange(
482             PROPERTY_MASTERPAGEMODE,
483             makeAny(bMasterPageMode),
484             makeAny(mbMasterPageMode));
485 
486 		mbMasterPageMode = bMasterPageMode;
487 	}
488 }
489 
490 
491 
492 
493 void DrawController::FireChangeLayerMode (bool bLayerMode) throw()
494 {
495 	if (bLayerMode != mbLayerMode)
496 	{
497         FirePropertyChange(
498             PROPERTY_LAYERMODE,
499             makeAny(bLayerMode),
500             makeAny(mbLayerMode));
501 
502 		mbLayerMode = bLayerMode;
503 	}
504 }
505 
506 
507 
508 
509 void DrawController::FireSwitchCurrentPage (SdPage* pNewCurrentPage) throw()
510 {
511     SdrPage* pCurrentPage  = mpCurrentPage.get();
512     if (pNewCurrentPage != pCurrentPage)
513     {
514         try
515         {
516             Any aNewValue (
517                 makeAny(Reference<drawing::XDrawPage>(pNewCurrentPage->getUnoPage(), UNO_QUERY)));
518 
519             Any aOldValue;
520             if (pCurrentPage != NULL)
521             {
522                 Reference<drawing::XDrawPage> xOldPage (pCurrentPage->getUnoPage(), UNO_QUERY);
523                 aOldValue <<= xOldPage;
524             }
525 
526             FirePropertyChange(PROPERTY_CURRENTPAGE, aNewValue, aOldValue);
527 
528             mpCurrentPage.reset(pNewCurrentPage);
529         }
530         catch( uno::Exception& e )
531         {
532             (void)e;
533             DBG_ERROR(
534                 (::rtl::OString("sd::SdUnoDrawView::FireSwitchCurrentPage(), "
535                     "exception caught: ") +
536                     ::rtl::OUStringToOString(
537                         comphelper::anyToString( cppu::getCaughtException() ),
538                         RTL_TEXTENCODING_UTF8 )).getStr() );
539         }
540     }
541 }
542 
543 
544 
545 
546 void DrawController::FirePropertyChange (
547     sal_Int32 nHandle,
548     const Any& rNewValue,
549     const Any& rOldValue)
550 {
551     try
552     {
553         fire (&nHandle, &rNewValue, &rOldValue, 1, sal_False);
554     }
555     catch (RuntimeException aException)
556     {
557         // Ignore this exception.  Exceptions should be handled in the
558         // fire() function so that all listeners are called.  This is
559         // not the case at the moment, so we simply ignore the
560         // exception.
561     }
562 
563 }
564 
565 
566 
567 
568 ViewShellBase* DrawController::GetViewShellBase (void)
569 {
570     return mpBase;
571 }
572 
573 
574 
575 
576 void DrawController::ReleaseViewShellBase (void)
577 {
578     DisposeFrameworkControllers();
579     mpBase = NULL;
580 }
581 
582 
583 
584 
585 //===== XControllerManager ==============================================================
586 
587 Reference<XConfigurationController> SAL_CALL
588     DrawController::getConfigurationController (void)
589     throw (RuntimeException)
590 {
591     ThrowIfDisposed();
592 
593     return mxConfigurationController;
594 }
595 
596 
597 
598 
599 Reference<XModuleController> SAL_CALL
600     DrawController::getModuleController (void)
601     throw (RuntimeException)
602 {
603     ThrowIfDisposed();
604 
605     return mxModuleController;
606 }
607 
608 
609 
610 
611 //===== XUnoTunnel ============================================================
612 
613 const Sequence<sal_Int8>& DrawController::getUnoTunnelId (void)
614 {
615 	static ::com::sun::star::uno::Sequence<sal_Int8>* pSequence = NULL;
616 	if (pSequence == NULL)
617 	{
618 		::osl::Guard< ::osl::Mutex > aGuard (::osl::Mutex::getGlobalMutex());
619 		if (pSequence == NULL)
620 		{
621 			static ::com::sun::star::uno::Sequence<sal_Int8> aSequence (16);
622 			rtl_createUuid((sal_uInt8*)aSequence.getArray(), 0, sal_True);
623 			pSequence = &aSequence;
624 		}
625 	}
626 	return *pSequence;
627 }
628 
629 
630 
631 
632 sal_Int64 SAL_CALL DrawController::getSomething (const Sequence<sal_Int8>& rId)
633     throw (RuntimeException)
634 {
635     sal_Int64 nResult = 0;
636 
637     if (rId.getLength() == 16
638         && rtl_compareMemory(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
639 	{
640 		nResult = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
641 	}
642 
643     return nResult;
644 }
645 
646 
647 
648 
649 //===== Properties ============================================================
650 
651 void DrawController::FillPropertyTable (
652     ::std::vector<beans::Property>& rProperties)
653 {
654     rProperties.push_back(
655         beans::Property(
656             OUString( RTL_CONSTASCII_USTRINGPARAM("VisibleArea") ),
657             PROPERTY_WORKAREA,
658             ::getCppuType((const ::com::sun::star::awt::Rectangle*)0),
659             beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY));
660     rProperties.push_back(
661         beans::Property(
662             OUString( RTL_CONSTASCII_USTRINGPARAM("SubController") ),
663             PROPERTY_SUB_CONTROLLER,
664             ::getCppuType((const Reference<drawing::XDrawSubController>*)0),
665             beans::PropertyAttribute::BOUND));
666     rProperties.push_back(
667         beans::Property(
668             OUString( RTL_CONSTASCII_USTRINGPARAM("CurrentPage") ),
669             PROPERTY_CURRENTPAGE,
670             ::getCppuType((const Reference< drawing::XDrawPage > *)0),
671             beans::PropertyAttribute::BOUND ));
672     rProperties.push_back(
673         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("IsLayerMode") ),
674             PROPERTY_LAYERMODE,
675             ::getCppuBooleanType(),
676             beans::PropertyAttribute::BOUND ));
677     rProperties.push_back(
678         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("IsMasterPageMode") ),
679             PROPERTY_MASTERPAGEMODE,
680             ::getCppuBooleanType(),
681             beans::PropertyAttribute::BOUND ));
682     rProperties.push_back(
683         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ActiveLayer") ),
684             PROPERTY_ACTIVE_LAYER,
685             ::getCppuBooleanType(),
686             beans::PropertyAttribute::BOUND ));
687     rProperties.push_back(
688         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ZoomValue") ),
689 			PROPERTY_ZOOMVALUE,
690             ::getCppuType((const sal_Int16*)0),
691             beans::PropertyAttribute::BOUND ));
692     rProperties.push_back(
693         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ZoomType") ),
694 			PROPERTY_ZOOMTYPE,
695             ::getCppuType((const sal_Int16*)0),
696             beans::PropertyAttribute::BOUND ));
697     rProperties.push_back(
698         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ViewOffset") ),
699 			PROPERTY_VIEWOFFSET,
700             ::getCppuType((const ::com::sun::star::awt::Point*)0),
701             beans::PropertyAttribute::BOUND ));
702     rProperties.push_back(
703         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("DrawViewMode") ),
704 			PROPERTY_DRAWVIEWMODE,
705             ::getCppuType((const ::com::sun::star::awt::Point*)0),
706             beans::PropertyAttribute::BOUND|beans::PropertyAttribute::READONLY|beans::PropertyAttribute::MAYBEVOID ));
707 }
708 
709 
710 
711 
712 IPropertyArrayHelper & DrawController::getInfoHelper()
713 {
714 	OGuard aGuard( Application::GetSolarMutex() );
715 
716     if (mpPropertyArrayHelper.get() == NULL)
717     {
718         ::std::vector<beans::Property> aProperties;
719         FillPropertyTable (aProperties);
720         Sequence<beans::Property> aPropertySequence (aProperties.size());
721         for (unsigned int i=0; i<aProperties.size(); i++)
722             aPropertySequence[i] = aProperties[i];
723         mpPropertyArrayHelper.reset(new OPropertyArrayHelper(aPropertySequence, sal_False));
724     }
725 
726 	return *mpPropertyArrayHelper.get();
727 }
728 
729 
730 
731 
732 Reference < beans::XPropertySetInfo >  DrawController::getPropertySetInfo()
733 		throw ( ::com::sun::star::uno::RuntimeException)
734 {
735 	::vos::OGuard aGuard( Application::GetSolarMutex() );
736 
737 	static Reference < beans::XPropertySetInfo >  xInfo( createPropertySetInfo( getInfoHelper() ) );
738 	return xInfo;
739 }
740 
741 
742 uno::Reference< form::runtime::XFormController > SAL_CALL DrawController::getFormController( const uno::Reference< form::XForm >& Form ) throw (uno::RuntimeException)
743 {
744     OGuard aGuard( Application::GetSolarMutex() );
745 
746     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
747     SdrView* pSdrView = mpBase->GetDrawView();
748     ::boost::shared_ptr<ViewShell> pViewShell = mpBase->GetMainViewShell();
749     ::sd::Window* pWindow = pViewShell ? pViewShell->GetActiveWindow() : NULL;
750 
751     uno::Reference< form::runtime::XFormController > xController( NULL );
752     if ( pFormShell && pSdrView && pWindow )
753         xController = pFormShell->GetFormController( Form, *pSdrView, *pWindow );
754     return xController;
755 }
756 
757 ::sal_Bool SAL_CALL DrawController::isFormDesignMode(  ) throw (uno::RuntimeException)
758 {
759     OGuard aGuard( Application::GetSolarMutex() );
760 
761     sal_Bool bIsDesignMode = sal_True;
762 
763     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
764     if ( pFormShell )
765         bIsDesignMode = pFormShell->IsDesignMode();
766 
767     return bIsDesignMode;
768 }
769 
770 void SAL_CALL DrawController::setFormDesignMode( ::sal_Bool _DesignMode ) throw (uno::RuntimeException)
771 {
772     OGuard aGuard( Application::GetSolarMutex() );
773 
774     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
775     if ( pFormShell )
776         pFormShell->SetDesignMode( _DesignMode );
777 }
778 
779 uno::Reference< awt::XControl > SAL_CALL DrawController::getControl( const uno::Reference< awt::XControlModel >& xModel ) throw (container::NoSuchElementException, uno::RuntimeException)
780 {
781     OGuard aGuard( Application::GetSolarMutex() );
782 
783     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
784     SdrView* pSdrView = mpBase->GetDrawView();
785     ::boost::shared_ptr<ViewShell> pViewShell = mpBase->GetMainViewShell();
786     ::sd::Window* pWindow = pViewShell ? pViewShell->GetActiveWindow() : NULL;
787 
788     uno::Reference< awt::XControl > xControl( NULL );
789     if ( pFormShell && pSdrView && pWindow )
790         pFormShell->GetFormControl( xModel, *pSdrView, *pWindow, xControl );
791     return xControl;
792 }
793 
794 
795 
796 
797 sal_Bool DrawController::convertFastPropertyValue (
798     Any & rConvertedValue,
799 	Any & rOldValue,
800 	sal_Int32 nHandle,
801 	const Any& rValue)
802     throw ( com::sun::star::lang::IllegalArgumentException)
803 {
804     sal_Bool bResult = sal_False;
805 
806     if (nHandle == PROPERTY_SUB_CONTROLLER)
807     {
808         rOldValue <<= mxSubController;
809         rConvertedValue <<= Reference<drawing::XDrawSubController>(rValue, UNO_QUERY);
810         bResult = (rOldValue != rConvertedValue);
811     }
812     else if (mxSubController.is())
813     {
814         rConvertedValue = rValue;
815         try
816         {
817             rOldValue = mxSubController->getFastPropertyValue(nHandle);
818             bResult = (rOldValue != rConvertedValue);
819         }
820         catch(beans::UnknownPropertyException aException)
821         {
822             // The prperty is unknown and thus an illegal argument to this method.
823             throw com::sun::star::lang::IllegalArgumentException();
824         }
825     }
826 
827     return bResult;
828 }
829 
830 
831 
832 
833 void DrawController::setFastPropertyValue_NoBroadcast (
834 	sal_Int32 nHandle,
835 	const Any& rValue)
836     throw ( com::sun::star::uno::Exception)
837 {
838     OGuard aGuard( Application::GetSolarMutex() );
839     if (nHandle == PROPERTY_SUB_CONTROLLER)
840         SetSubController(Reference<drawing::XDrawSubController>(rValue, UNO_QUERY));
841     else if (mxSubController.is())
842         mxSubController->setFastPropertyValue(nHandle, rValue);
843 }
844 
845 
846 
847 
848 void DrawController::getFastPropertyValue (
849     Any & rRet,
850     sal_Int32 nHandle ) const
851 {
852 	OGuard aGuard( Application::GetSolarMutex() );
853 
854 	switch( nHandle )
855 	{
856 		case PROPERTY_WORKAREA:
857 			rRet <<= awt::Rectangle(
858                 maLastVisArea.Left(),
859                 maLastVisArea.Top(),
860                 maLastVisArea.GetWidth(),
861                 maLastVisArea.GetHeight());
862 			break;
863 
864         case PROPERTY_SUB_CONTROLLER:
865             rRet <<= mxSubController;
866             break;
867 
868         default:
869             if (mxSubController.is())
870                 rRet = mxSubController->getFastPropertyValue(nHandle);
871             break;
872     }
873 }
874 
875 
876 
877 
878 //-----------------------------------------------------------------------------
879 
880 void DrawController::ProvideFrameworkControllers (void)
881 {
882 	::vos::OGuard aGuard (Application::GetSolarMutex());
883     try
884     {
885         Reference<XController> xController (this);
886         const Reference<XComponentContext> xContext (
887             ::comphelper::getProcessComponentContext() );
888         mxConfigurationController = ConfigurationController::create(
889             xContext,
890             xController);
891         mxModuleController = ModuleController::create(
892             xContext,
893             xController);
894     }
895     catch (RuntimeException&)
896     {
897         mxConfigurationController = NULL;
898         mxModuleController = NULL;
899     }
900 }
901 
902 
903 
904 
905 void DrawController::DisposeFrameworkControllers (void)
906 {
907     Reference<XComponent> xComponent (mxModuleController, UNO_QUERY);
908     if (xComponent.is())
909         xComponent->dispose();
910 
911     xComponent = Reference<XComponent>(mxConfigurationController, UNO_QUERY);
912     if (xComponent.is())
913         xComponent->dispose();
914 }
915 
916 
917 
918 
919 void DrawController::ThrowIfDisposed (void) const
920     throw (::com::sun::star::lang::DisposedException)
921 {
922 	if (rBHelper.bDisposed || rBHelper.bInDispose || mbDisposing)
923 	{
924         OSL_TRACE ("Calling disposed DrawController object. Throwing exception:");
925         throw lang::DisposedException (
926             OUString(RTL_CONSTASCII_USTRINGPARAM(
927                 "DrawController object has already been disposed")),
928             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
929     }
930 }
931 
932 
933 
934 
935 
936 } // end of namespace sd
937 
938 
939