xref: /trunk/main/sd/source/ui/unoidl/DrawController.cxx (revision 65be1ea226e2cd061072fa82fb007d7a21634124)
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_sd.hxx"
26 
27 #include "DrawController.hxx"
28 #include "DrawDocShell.hxx"
29 
30 #include "DrawSubController.hxx"
31 #include "sdpage.hxx"
32 #include "ViewShellBase.hxx"
33 #include "ViewShellManager.hxx"
34 #include "FormShellManager.hxx"
35 #include "Window.hxx"
36 
37 #include <comphelper/anytostring.hxx>
38 #include <comphelper/processfactory.hxx>
39 #include <comphelper/sequence.hxx>
40 #include <comphelper/stl_types.hxx>
41 #include <cppuhelper/exc_hlp.hxx>
42 #include <cppuhelper/bootstrap.hxx>
43 
44 #include <com/sun/star/beans/PropertyAttribute.hpp>
45 #include <com/sun/star/drawing/framework/ConfigurationController.hpp>
46 #include <com/sun/star/drawing/framework/ModuleController.hpp>
47 #include <com/sun/star/lang/XInitialization.hpp>
48 
49 #include "slideshow.hxx"
50 
51 #include <svx/fmshell.hxx>
52 #include <vos/mutex.hxx>
53 #include <vcl/svapp.hxx>
54 #include <sfx2/sidebar/EnumContext.hxx>
55 #include <svx/sidebar/ContextChangeEventMultiplexer.hxx>
56 
57 #include <boost/shared_ptr.hpp>
58 
59 using namespace ::std;
60 using ::rtl::OUString;
61 using namespace ::cppu;
62 using namespace ::vos;
63 using namespace ::com::sun::star;
64 using namespace ::com::sun::star::uno;
65 using namespace ::com::sun::star::drawing::framework;
66 using ::sfx2::sidebar::EnumContext;
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 void DrawController::BroadcastContextChange (void) const
569 {
570     ::boost::shared_ptr<ViewShell> pViewShell (mpBase->GetMainViewShell());
571     if ( ! pViewShell)
572         return;
573 
574     EnumContext::Context eContext (EnumContext::Context_Unknown);
575     switch (pViewShell->GetShellType())
576     {
577         case ViewShell::ST_IMPRESS:
578         case ViewShell::ST_DRAW:
579             if (mbMasterPageMode)
580                 eContext = EnumContext::Context_MasterPage;
581             else
582                 eContext = EnumContext::Context_DrawPage;
583             break;
584 
585         case ViewShell::ST_NOTES:
586             eContext = EnumContext::Context_NotesPage;
587             break;
588 
589         case ViewShell::ST_HANDOUT:
590             eContext = EnumContext::Context_HandoutPage;
591             break;
592 
593         case ViewShell::ST_OUTLINE:
594             eContext = EnumContext::Context_OutlineText;
595             break;
596 
597         case ViewShell::ST_SLIDE_SORTER:
598             eContext = EnumContext::Context_SlidesorterPage;
599             break;
600 
601         case ViewShell::ST_PRESENTATION:
602         case ViewShell::ST_NONE:
603             eContext = EnumContext::Context_Empty;
604             break;
605     }
606 
607     ContextChangeEventMultiplexer::NotifyContextChange(mpBase, eContext);
608 }
609 
610 
611 
612 
613 ViewShellBase* DrawController::GetViewShellBase (void)
614 {
615     return mpBase;
616 }
617 
618 
619 
620 
621 void DrawController::ReleaseViewShellBase (void)
622 {
623     DisposeFrameworkControllers();
624     mpBase = NULL;
625 }
626 
627 
628 
629 
630 //===== XControllerManager ==============================================================
631 
632 Reference<XConfigurationController> SAL_CALL
633     DrawController::getConfigurationController (void)
634     throw (RuntimeException)
635 {
636     ThrowIfDisposed();
637 
638     return mxConfigurationController;
639 }
640 
641 
642 
643 
644 Reference<XModuleController> SAL_CALL
645     DrawController::getModuleController (void)
646     throw (RuntimeException)
647 {
648     ThrowIfDisposed();
649 
650     return mxModuleController;
651 }
652 
653 
654 
655 
656 //===== XUnoTunnel ============================================================
657 
658 const Sequence<sal_Int8>& DrawController::getUnoTunnelId (void)
659 {
660     static ::com::sun::star::uno::Sequence<sal_Int8>* pSequence = NULL;
661     if (pSequence == NULL)
662     {
663         ::osl::Guard< ::osl::Mutex > aGuard (::osl::Mutex::getGlobalMutex());
664         if (pSequence == NULL)
665         {
666             static ::com::sun::star::uno::Sequence<sal_Int8> aSequence (16);
667             rtl_createUuid((sal_uInt8*)aSequence.getArray(), 0, sal_True);
668             pSequence = &aSequence;
669         }
670     }
671     return *pSequence;
672 }
673 
674 
675 
676 
677 sal_Int64 SAL_CALL DrawController::getSomething (const Sequence<sal_Int8>& rId)
678     throw (RuntimeException)
679 {
680     sal_Int64 nResult = 0;
681 
682     if (rId.getLength() == 16
683         && rtl_compareMemory(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
684     {
685         nResult = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
686     }
687 
688     return nResult;
689 }
690 
691 
692 
693 
694 //===== Properties ============================================================
695 
696 void DrawController::FillPropertyTable (
697     ::std::vector<beans::Property>& rProperties)
698 {
699     rProperties.push_back(
700         beans::Property(
701             OUString( RTL_CONSTASCII_USTRINGPARAM("VisibleArea") ),
702             PROPERTY_WORKAREA,
703             ::getCppuType((const ::com::sun::star::awt::Rectangle*)0),
704             beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY));
705     rProperties.push_back(
706         beans::Property(
707             OUString( RTL_CONSTASCII_USTRINGPARAM("SubController") ),
708             PROPERTY_SUB_CONTROLLER,
709             ::getCppuType((const Reference<drawing::XDrawSubController>*)0),
710             beans::PropertyAttribute::BOUND));
711     rProperties.push_back(
712         beans::Property(
713             OUString( RTL_CONSTASCII_USTRINGPARAM("CurrentPage") ),
714             PROPERTY_CURRENTPAGE,
715             ::getCppuType((const Reference< drawing::XDrawPage > *)0),
716             beans::PropertyAttribute::BOUND ));
717     rProperties.push_back(
718         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("IsLayerMode") ),
719             PROPERTY_LAYERMODE,
720             ::getCppuBooleanType(),
721             beans::PropertyAttribute::BOUND ));
722     rProperties.push_back(
723         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("IsMasterPageMode") ),
724             PROPERTY_MASTERPAGEMODE,
725             ::getCppuBooleanType(),
726             beans::PropertyAttribute::BOUND ));
727     rProperties.push_back(
728         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ActiveLayer") ),
729             PROPERTY_ACTIVE_LAYER,
730             ::getCppuBooleanType(),
731             beans::PropertyAttribute::BOUND ));
732     rProperties.push_back(
733         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ZoomValue") ),
734             PROPERTY_ZOOMVALUE,
735             ::getCppuType((const sal_Int16*)0),
736             beans::PropertyAttribute::BOUND ));
737     rProperties.push_back(
738         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ZoomType") ),
739             PROPERTY_ZOOMTYPE,
740             ::getCppuType((const sal_Int16*)0),
741             beans::PropertyAttribute::BOUND ));
742     rProperties.push_back(
743         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ViewOffset") ),
744             PROPERTY_VIEWOFFSET,
745             ::getCppuType((const ::com::sun::star::awt::Point*)0),
746             beans::PropertyAttribute::BOUND ));
747     rProperties.push_back(
748         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("DrawViewMode") ),
749             PROPERTY_DRAWVIEWMODE,
750             ::getCppuType((const ::com::sun::star::awt::Point*)0),
751             beans::PropertyAttribute::BOUND|beans::PropertyAttribute::READONLY|beans::PropertyAttribute::MAYBEVOID ));
752 }
753 
754 
755 
756 
757 IPropertyArrayHelper & DrawController::getInfoHelper()
758 {
759     OGuard aGuard( Application::GetSolarMutex() );
760 
761     if (mpPropertyArrayHelper.get() == NULL)
762     {
763         ::std::vector<beans::Property> aProperties;
764         FillPropertyTable (aProperties);
765         Sequence<beans::Property> aPropertySequence (aProperties.size());
766         for (unsigned int i=0; i<aProperties.size(); i++)
767             aPropertySequence[i] = aProperties[i];
768         mpPropertyArrayHelper.reset(new OPropertyArrayHelper(aPropertySequence, sal_False));
769     }
770 
771     return *mpPropertyArrayHelper.get();
772 }
773 
774 
775 
776 
777 Reference < beans::XPropertySetInfo >  DrawController::getPropertySetInfo()
778         throw ( ::com::sun::star::uno::RuntimeException)
779 {
780     ::vos::OGuard aGuard( Application::GetSolarMutex() );
781 
782     static Reference < beans::XPropertySetInfo >  xInfo( createPropertySetInfo( getInfoHelper() ) );
783     return xInfo;
784 }
785 
786 
787 uno::Reference< form::runtime::XFormController > SAL_CALL DrawController::getFormController( const uno::Reference< form::XForm >& Form ) throw (uno::RuntimeException)
788 {
789     OGuard aGuard( Application::GetSolarMutex() );
790 
791     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
792     SdrView* pSdrView = mpBase->GetDrawView();
793     ::boost::shared_ptr<ViewShell> pViewShell = mpBase->GetMainViewShell();
794     ::sd::Window* pWindow = pViewShell ? pViewShell->GetActiveWindow() : NULL;
795 
796     uno::Reference< form::runtime::XFormController > xController( NULL );
797     if ( pFormShell && pSdrView && pWindow )
798         xController = pFormShell->GetFormController( Form, *pSdrView, *pWindow );
799     return xController;
800 }
801 
802 ::sal_Bool SAL_CALL DrawController::isFormDesignMode(  ) throw (uno::RuntimeException)
803 {
804     OGuard aGuard( Application::GetSolarMutex() );
805 
806     sal_Bool bIsDesignMode = sal_True;
807 
808     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
809     if ( pFormShell )
810         bIsDesignMode = pFormShell->IsDesignMode();
811 
812     return bIsDesignMode;
813 }
814 
815 void SAL_CALL DrawController::setFormDesignMode( ::sal_Bool _DesignMode ) throw (uno::RuntimeException)
816 {
817     OGuard aGuard( Application::GetSolarMutex() );
818 
819     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
820     if ( pFormShell )
821         pFormShell->SetDesignMode( _DesignMode );
822 }
823 
824 uno::Reference< awt::XControl > SAL_CALL DrawController::getControl( const uno::Reference< awt::XControlModel >& xModel ) throw (container::NoSuchElementException, uno::RuntimeException)
825 {
826     OGuard aGuard( Application::GetSolarMutex() );
827 
828     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
829     SdrView* pSdrView = mpBase->GetDrawView();
830     ::boost::shared_ptr<ViewShell> pViewShell = mpBase->GetMainViewShell();
831     ::sd::Window* pWindow = pViewShell ? pViewShell->GetActiveWindow() : NULL;
832 
833     uno::Reference< awt::XControl > xControl( NULL );
834     if ( pFormShell && pSdrView && pWindow )
835         pFormShell->GetFormControl( xModel, *pSdrView, *pWindow, xControl );
836     return xControl;
837 }
838 
839 
840 
841 
842 sal_Bool DrawController::convertFastPropertyValue (
843     Any & rConvertedValue,
844     Any & rOldValue,
845     sal_Int32 nHandle,
846     const Any& rValue)
847     throw ( com::sun::star::lang::IllegalArgumentException)
848 {
849     sal_Bool bResult = sal_False;
850 
851     if (nHandle == PROPERTY_SUB_CONTROLLER)
852     {
853         rOldValue <<= mxSubController;
854         rConvertedValue <<= Reference<drawing::XDrawSubController>(rValue, UNO_QUERY);
855         bResult = (rOldValue != rConvertedValue);
856     }
857     else if (mxSubController.is())
858     {
859         rConvertedValue = rValue;
860         try
861         {
862             rOldValue = mxSubController->getFastPropertyValue(nHandle);
863             bResult = (rOldValue != rConvertedValue);
864         }
865         catch(beans::UnknownPropertyException aException)
866         {
867             // The prperty is unknown and thus an illegal argument to this method.
868             throw com::sun::star::lang::IllegalArgumentException();
869         }
870     }
871 
872     return bResult;
873 }
874 
875 
876 
877 
878 void DrawController::setFastPropertyValue_NoBroadcast (
879     sal_Int32 nHandle,
880     const Any& rValue)
881     throw ( com::sun::star::uno::Exception)
882 {
883     OGuard aGuard( Application::GetSolarMutex() );
884     if (nHandle == PROPERTY_SUB_CONTROLLER)
885         SetSubController(Reference<drawing::XDrawSubController>(rValue, UNO_QUERY));
886     else if (mxSubController.is())
887         mxSubController->setFastPropertyValue(nHandle, rValue);
888 }
889 
890 
891 
892 
893 void DrawController::getFastPropertyValue (
894     Any & rRet,
895     sal_Int32 nHandle ) const
896 {
897     OGuard aGuard( Application::GetSolarMutex() );
898 
899     switch( nHandle )
900     {
901         case PROPERTY_WORKAREA:
902             rRet <<= awt::Rectangle(
903                 maLastVisArea.Left(),
904                 maLastVisArea.Top(),
905                 maLastVisArea.GetWidth(),
906                 maLastVisArea.GetHeight());
907             break;
908 
909         case PROPERTY_SUB_CONTROLLER:
910             rRet <<= mxSubController;
911             break;
912 
913         default:
914             if (mxSubController.is())
915                 rRet = mxSubController->getFastPropertyValue(nHandle);
916             break;
917     }
918 }
919 
920 
921 
922 
923 //-----------------------------------------------------------------------------
924 
925 void DrawController::ProvideFrameworkControllers (void)
926 {
927     ::vos::OGuard aGuard (Application::GetSolarMutex());
928     try
929     {
930         Reference<XController> xController (this);
931         const Reference<XComponentContext> xContext (
932             ::comphelper::getProcessComponentContext() );
933         mxConfigurationController = ConfigurationController::create(
934             xContext,
935             xController);
936         mxModuleController = ModuleController::create(
937             xContext,
938             xController);
939     }
940     catch (RuntimeException&)
941     {
942         mxConfigurationController = NULL;
943         mxModuleController = NULL;
944     }
945 }
946 
947 
948 
949 
950 void DrawController::DisposeFrameworkControllers (void)
951 {
952     Reference<XComponent> xComponent (mxModuleController, UNO_QUERY);
953     if (xComponent.is())
954         xComponent->dispose();
955 
956     xComponent = Reference<XComponent>(mxConfigurationController, UNO_QUERY);
957     if (xComponent.is())
958         xComponent->dispose();
959 }
960 
961 
962 
963 
964 void DrawController::ThrowIfDisposed (void) const
965     throw (::com::sun::star::lang::DisposedException)
966 {
967     if (rBHelper.bDisposed || rBHelper.bInDispose || mbDisposing)
968     {
969         OSL_TRACE ("Calling disposed DrawController object. Throwing exception:");
970         throw lang::DisposedException (
971             OUString(RTL_CONSTASCII_USTRINGPARAM(
972                 "DrawController object has already been disposed")),
973             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
974     }
975 }
976 
977 
978 
979 
980 
981 } // end of namespace sd
982 
983 
984