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