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 //IAccessibility2 Implementation 2009-----
543 void DrawController::NotifyAccUpdate()
544 {
545 	sal_Int32 nHandle = PROPERTY_UPDATEACC;
546 	Any aNewValue, aOldValue;
547 	fire (&nHandle, &aNewValue, &aOldValue, 1, sal_False);
548 }
549 
550 void DrawController::fireChangeLayer( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XLayer>* pCurrentLayer ) throw()
551 {
552 	if( pCurrentLayer != mpCurrentLayer )
553 	{
554 		sal_Int32 nHandle = PROPERTY_ACTIVE_LAYER;
555 
556 		Any aNewValue (makeAny( *pCurrentLayer) );
557 
558 		Any aOldValue ;
559 
560 		fire (&nHandle, &aNewValue, &aOldValue, 1, sal_False);
561 
562 		mpCurrentLayer = pCurrentLayer;
563 	}
564 }
565 
566 // This method is only called in slide show and outline view
567 //void DrawController::fireSwitchCurrentPage(String pageName ) throw()
568 void DrawController::fireSwitchCurrentPage(sal_Int32 pageIndex ) throw()
569 {
570 		Any aNewValue;
571 		Any aOldValue;
572 		//OUString aPageName(  pageName );
573 		//aNewValue <<= aPageName ;
574 		aNewValue <<= pageIndex;
575 
576 		// Use new property to handle page change event
577 		sal_Int32 nHandles = PROPERTY_PAGE_CHANGE;
578 		fire( &nHandles, &aNewValue, &aOldValue, 1, sal_False );
579 }
580 //-----IAccessibility2 Implementation 2009
581 
582 void DrawController::FirePropertyChange (
583     sal_Int32 nHandle,
584     const Any& rNewValue,
585     const Any& rOldValue)
586 {
587     try
588     {
589         fire (&nHandle, &rNewValue, &rOldValue, 1, sal_False);
590     }
591     catch (RuntimeException aException)
592     {
593         // Ignore this exception.  Exceptions should be handled in the
594         // fire() function so that all listeners are called.  This is
595         // not the case at the moment, so we simply ignore the
596         // exception.
597     }
598 
599 }
600 
601 
602 
603 
604 void DrawController::BroadcastContextChange (void) const
605 {
606     ::boost::shared_ptr<ViewShell> pViewShell (mpBase->GetMainViewShell());
607     if ( ! pViewShell)
608         return;
609 
610     EnumContext::Context eContext (EnumContext::Context_Unknown);
611     switch (pViewShell->GetShellType())
612     {
613         case ViewShell::ST_IMPRESS:
614         case ViewShell::ST_DRAW:
615             if (mbMasterPageMode)
616                 eContext = EnumContext::Context_MasterPage;
617             else
618                 eContext = EnumContext::Context_DrawPage;
619             break;
620 
621         case ViewShell::ST_NOTES:
622             eContext = EnumContext::Context_NotesPage;
623             break;
624 
625         case ViewShell::ST_HANDOUT:
626             eContext = EnumContext::Context_HandoutPage;
627             break;
628 
629         case ViewShell::ST_OUTLINE:
630             eContext = EnumContext::Context_OutlineText;
631             break;
632 
633         case ViewShell::ST_SLIDE_SORTER:
634             eContext = EnumContext::Context_SlidesorterPage;
635             break;
636 
637         case ViewShell::ST_PRESENTATION:
638         case ViewShell::ST_NONE:
639         default:
640             eContext = EnumContext::Context_Empty;
641             break;
642     }
643 
644     ContextChangeEventMultiplexer::NotifyContextChange(mpBase, eContext);
645 }
646 
647 
648 
649 
650 ViewShellBase* DrawController::GetViewShellBase (void)
651 {
652     return mpBase;
653 }
654 
655 
656 
657 
658 void DrawController::ReleaseViewShellBase (void)
659 {
660     DisposeFrameworkControllers();
661     mpBase = NULL;
662 }
663 
664 
665 
666 
667 //===== XControllerManager ==============================================================
668 
669 Reference<XConfigurationController> SAL_CALL
670     DrawController::getConfigurationController (void)
671     throw (RuntimeException)
672 {
673     ThrowIfDisposed();
674 
675     return mxConfigurationController;
676 }
677 
678 
679 
680 
681 Reference<XModuleController> SAL_CALL
682     DrawController::getModuleController (void)
683     throw (RuntimeException)
684 {
685     ThrowIfDisposed();
686 
687     return mxModuleController;
688 }
689 
690 
691 
692 
693 //===== XUnoTunnel ============================================================
694 
695 const Sequence<sal_Int8>& DrawController::getUnoTunnelId (void)
696 {
697 	static ::com::sun::star::uno::Sequence<sal_Int8>* pSequence = NULL;
698 	if (pSequence == NULL)
699 	{
700 		::osl::Guard< ::osl::Mutex > aGuard (::osl::Mutex::getGlobalMutex());
701 		if (pSequence == NULL)
702 		{
703 			static ::com::sun::star::uno::Sequence<sal_Int8> aSequence (16);
704 			rtl_createUuid((sal_uInt8*)aSequence.getArray(), 0, sal_True);
705 			pSequence = &aSequence;
706 		}
707 	}
708 	return *pSequence;
709 }
710 
711 
712 
713 
714 sal_Int64 SAL_CALL DrawController::getSomething (const Sequence<sal_Int8>& rId)
715     throw (RuntimeException)
716 {
717     sal_Int64 nResult = 0;
718 
719     if (rId.getLength() == 16
720         && rtl_compareMemory(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
721 	{
722 		nResult = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
723 	}
724 
725     return nResult;
726 }
727 
728 
729 
730 
731 //===== Properties ============================================================
732 
733 void DrawController::FillPropertyTable (
734     ::std::vector<beans::Property>& rProperties)
735 {
736     rProperties.push_back(
737         beans::Property(
738             OUString( RTL_CONSTASCII_USTRINGPARAM("VisibleArea") ),
739             PROPERTY_WORKAREA,
740             ::getCppuType((const ::com::sun::star::awt::Rectangle*)0),
741             beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY));
742     rProperties.push_back(
743         beans::Property(
744             OUString( RTL_CONSTASCII_USTRINGPARAM("SubController") ),
745             PROPERTY_SUB_CONTROLLER,
746             ::getCppuType((const Reference<drawing::XDrawSubController>*)0),
747             beans::PropertyAttribute::BOUND));
748     rProperties.push_back(
749         beans::Property(
750             OUString( RTL_CONSTASCII_USTRINGPARAM("CurrentPage") ),
751             PROPERTY_CURRENTPAGE,
752             ::getCppuType((const Reference< drawing::XDrawPage > *)0),
753             beans::PropertyAttribute::BOUND ));
754     rProperties.push_back(
755         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("IsLayerMode") ),
756             PROPERTY_LAYERMODE,
757             ::getCppuBooleanType(),
758             beans::PropertyAttribute::BOUND ));
759     rProperties.push_back(
760         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("IsMasterPageMode") ),
761             PROPERTY_MASTERPAGEMODE,
762             ::getCppuBooleanType(),
763             beans::PropertyAttribute::BOUND ));
764     rProperties.push_back(
765         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ActiveLayer") ),
766             PROPERTY_ACTIVE_LAYER,
767             ::getCppuBooleanType(),
768             beans::PropertyAttribute::BOUND ));
769     rProperties.push_back(
770         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ZoomValue") ),
771 			PROPERTY_ZOOMVALUE,
772             ::getCppuType((const sal_Int16*)0),
773             beans::PropertyAttribute::BOUND ));
774     rProperties.push_back(
775         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ZoomType") ),
776 			PROPERTY_ZOOMTYPE,
777             ::getCppuType((const sal_Int16*)0),
778             beans::PropertyAttribute::BOUND ));
779     rProperties.push_back(
780         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ViewOffset") ),
781 			PROPERTY_VIEWOFFSET,
782             ::getCppuType((const ::com::sun::star::awt::Point*)0),
783             beans::PropertyAttribute::BOUND ));
784     rProperties.push_back(
785         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("DrawViewMode") ),
786 			PROPERTY_DRAWVIEWMODE,
787             ::getCppuType((const ::com::sun::star::awt::Point*)0),
788             beans::PropertyAttribute::BOUND|beans::PropertyAttribute::READONLY|beans::PropertyAttribute::MAYBEVOID ));
789 	    //IAccessibility2 Implementation 2009-----
790 	// add new property to update current page's acc information
791     rProperties.push_back(
792         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("UpdateAcc") ),
793 			PROPERTY_UPDATEACC,
794             ::getCppuType((const sal_Int16*)0),
795             beans::PropertyAttribute::BOUND ));
796 	rProperties.push_back(
797         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("PageChange") ),
798 			PROPERTY_PAGE_CHANGE,
799             ::getCppuType((const sal_Int16*)0),
800             beans::PropertyAttribute::BOUND ));
801 	    //-----IAccessibility2 Implementation 2009
802 }
803 
804 
805 
806 
807 IPropertyArrayHelper & DrawController::getInfoHelper()
808 {
809 	OGuard aGuard( Application::GetSolarMutex() );
810 
811     if (mpPropertyArrayHelper.get() == NULL)
812     {
813         ::std::vector<beans::Property> aProperties;
814         FillPropertyTable (aProperties);
815         Sequence<beans::Property> aPropertySequence (aProperties.size());
816         for (unsigned int i=0; i<aProperties.size(); i++)
817             aPropertySequence[i] = aProperties[i];
818         mpPropertyArrayHelper.reset(new OPropertyArrayHelper(aPropertySequence, sal_False));
819     }
820 
821 	return *mpPropertyArrayHelper.get();
822 }
823 
824 
825 
826 
827 Reference < beans::XPropertySetInfo >  DrawController::getPropertySetInfo()
828 		throw ( ::com::sun::star::uno::RuntimeException)
829 {
830 	::vos::OGuard aGuard( Application::GetSolarMutex() );
831 
832 	static Reference < beans::XPropertySetInfo >  xInfo( createPropertySetInfo( getInfoHelper() ) );
833 	return xInfo;
834 }
835 
836 
837 uno::Reference< form::runtime::XFormController > SAL_CALL DrawController::getFormController( const uno::Reference< form::XForm >& Form ) throw (uno::RuntimeException)
838 {
839     OGuard aGuard( Application::GetSolarMutex() );
840 
841     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
842     SdrView* pSdrView = mpBase->GetDrawView();
843     ::boost::shared_ptr<ViewShell> pViewShell = mpBase->GetMainViewShell();
844     ::sd::Window* pWindow = pViewShell ? pViewShell->GetActiveWindow() : NULL;
845 
846     uno::Reference< form::runtime::XFormController > xController( NULL );
847     if ( pFormShell && pSdrView && pWindow )
848         xController = pFormShell->GetFormController( Form, *pSdrView, *pWindow );
849     return xController;
850 }
851 
852 ::sal_Bool SAL_CALL DrawController::isFormDesignMode(  ) throw (uno::RuntimeException)
853 {
854     OGuard aGuard( Application::GetSolarMutex() );
855 
856     sal_Bool bIsDesignMode = sal_True;
857 
858     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
859     if ( pFormShell )
860         bIsDesignMode = pFormShell->IsDesignMode();
861 
862     return bIsDesignMode;
863 }
864 
865 void SAL_CALL DrawController::setFormDesignMode( ::sal_Bool _DesignMode ) throw (uno::RuntimeException)
866 {
867     OGuard aGuard( Application::GetSolarMutex() );
868 
869     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
870     if ( pFormShell )
871         pFormShell->SetDesignMode( _DesignMode );
872 }
873 
874 uno::Reference< awt::XControl > SAL_CALL DrawController::getControl( const uno::Reference< awt::XControlModel >& xModel ) throw (container::NoSuchElementException, uno::RuntimeException)
875 {
876     OGuard aGuard( Application::GetSolarMutex() );
877 
878     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
879     SdrView* pSdrView = mpBase->GetDrawView();
880     ::boost::shared_ptr<ViewShell> pViewShell = mpBase->GetMainViewShell();
881     ::sd::Window* pWindow = pViewShell ? pViewShell->GetActiveWindow() : NULL;
882 
883     uno::Reference< awt::XControl > xControl( NULL );
884     if ( pFormShell && pSdrView && pWindow )
885         pFormShell->GetFormControl( xModel, *pSdrView, *pWindow, xControl );
886     return xControl;
887 }
888 
889 
890 
891 
892 sal_Bool DrawController::convertFastPropertyValue (
893     Any & rConvertedValue,
894 	Any & rOldValue,
895 	sal_Int32 nHandle,
896 	const Any& rValue)
897     throw ( com::sun::star::lang::IllegalArgumentException)
898 {
899     sal_Bool bResult = sal_False;
900 
901     if (nHandle == PROPERTY_SUB_CONTROLLER)
902     {
903         rOldValue <<= mxSubController;
904         rConvertedValue <<= Reference<drawing::XDrawSubController>(rValue, UNO_QUERY);
905         bResult = (rOldValue != rConvertedValue);
906     }
907     else if (mxSubController.is())
908     {
909         rConvertedValue = rValue;
910         try
911         {
912             rOldValue = mxSubController->getFastPropertyValue(nHandle);
913             bResult = (rOldValue != rConvertedValue);
914         }
915         catch(beans::UnknownPropertyException aException)
916         {
917             // The prperty is unknown and thus an illegal argument to this method.
918             throw com::sun::star::lang::IllegalArgumentException();
919         }
920     }
921 
922     return bResult;
923 }
924 
925 
926 
927 
928 void DrawController::setFastPropertyValue_NoBroadcast (
929 	sal_Int32 nHandle,
930 	const Any& rValue)
931     throw ( com::sun::star::uno::Exception)
932 {
933     OGuard aGuard( Application::GetSolarMutex() );
934     if (nHandle == PROPERTY_SUB_CONTROLLER)
935         SetSubController(Reference<drawing::XDrawSubController>(rValue, UNO_QUERY));
936     else if (mxSubController.is())
937         mxSubController->setFastPropertyValue(nHandle, rValue);
938 }
939 
940 
941 
942 
943 void DrawController::getFastPropertyValue (
944     Any & rRet,
945     sal_Int32 nHandle ) const
946 {
947 	OGuard aGuard( Application::GetSolarMutex() );
948 
949 	switch( nHandle )
950 	{
951 		case PROPERTY_WORKAREA:
952 			rRet <<= awt::Rectangle(
953                 maLastVisArea.Left(),
954                 maLastVisArea.Top(),
955                 maLastVisArea.GetWidth(),
956                 maLastVisArea.GetHeight());
957 			break;
958 
959         case PROPERTY_SUB_CONTROLLER:
960             rRet <<= mxSubController;
961             break;
962 
963         default:
964             if (mxSubController.is())
965                 rRet = mxSubController->getFastPropertyValue(nHandle);
966             break;
967     }
968 }
969 
970 
971 
972 
973 //-----------------------------------------------------------------------------
974 
975 void DrawController::ProvideFrameworkControllers (void)
976 {
977 	::vos::OGuard aGuard (Application::GetSolarMutex());
978     try
979     {
980         Reference<XController> xController (this);
981         const Reference<XComponentContext> xContext (
982             ::comphelper::getProcessComponentContext() );
983         mxConfigurationController = ConfigurationController::create(
984             xContext,
985             xController);
986         mxModuleController = ModuleController::create(
987             xContext,
988             xController);
989     }
990     catch (RuntimeException&)
991     {
992         mxConfigurationController = NULL;
993         mxModuleController = NULL;
994     }
995 }
996 
997 
998 
999 
1000 void DrawController::DisposeFrameworkControllers (void)
1001 {
1002     Reference<XComponent> xComponent (mxModuleController, UNO_QUERY);
1003     if (xComponent.is())
1004         xComponent->dispose();
1005 
1006     xComponent = Reference<XComponent>(mxConfigurationController, UNO_QUERY);
1007     if (xComponent.is())
1008         xComponent->dispose();
1009 }
1010 
1011 
1012 
1013 
1014 void DrawController::ThrowIfDisposed (void) const
1015     throw (::com::sun::star::lang::DisposedException)
1016 {
1017 	if (rBHelper.bDisposed || rBHelper.bInDispose || mbDisposing)
1018 	{
1019         OSL_TRACE ("Calling disposed DrawController object. Throwing exception:");
1020         throw lang::DisposedException (
1021             OUString(RTL_CONSTASCII_USTRINGPARAM(
1022                 "DrawController object has already been disposed")),
1023             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
1024     }
1025 }
1026 
1027 
1028 
1029 
1030 
1031 } // end of namespace sd
1032 
1033 
1034