xref: /trunk/main/sd/source/ui/unoidl/DrawController.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
DrawController(ViewShellBase & rBase)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 
~DrawController(void)102 DrawController::~DrawController (void) throw()
103 {
104 }
105 
106 
107 
108 
SetSubController(const Reference<drawing::XDrawSubController> & rxSubController)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 
getTypes(void)134 Sequence<Type> SAL_CALL DrawController::getTypes (void)
135 {
136     ThrowIfDisposed();
137     // OPropertySetHelper does not provide getTypes, so we have to
138     // implement this method manually and list its three interfaces.
139     OTypeCollection aTypeCollection (
140         ::getCppuType (( const Reference<beans::XMultiPropertySet>*)NULL),
141         ::getCppuType (( const Reference<beans::XFastPropertySet>*)NULL),
142         ::getCppuType (( const Reference<beans::XPropertySet>*)NULL));
143 
144     return ::comphelper::concatSequences(
145         SfxBaseController::getTypes(),
146         aTypeCollection.getTypes(),
147         DrawControllerInterfaceBase::getTypes());
148 }
149 
150 IMPLEMENT_GET_IMPLEMENTATION_ID(DrawController);
151 
152 
153 
154 // XComponent
155 
156 
dispose(void)157 void SAL_CALL DrawController::dispose (void)
158 {
159     if( !mbDisposing )
160     {
161         OGuard aGuard( Application::GetSolarMutex() );
162 
163         if( !mbDisposing )
164         {
165             mbDisposing = true;
166 
167             boost::shared_ptr<ViewShell> pViewShell = mpBase->GetMainViewShell();
168             if ( pViewShell )
169             {
170                 pViewShell->DeactivateCurrentFunction();
171                 DrawDocShell* pDocShell = pViewShell->GetDocSh();
172                 if ( pDocShell != NULL )
173                     pDocShell->SetDocShellFunction(0);
174             }
175             pViewShell.reset();
176 
177             // When the controller has not been detached from its view
178             // shell, i.e. mpViewShell is not NULL, then tell PaneManager
179             // and ViewShellManager to clear the shell stack.
180             if (mxSubController.is() && mpBase!=NULL)
181             {
182                 mpBase->DisconnectAllClients();
183                 mpBase->GetViewShellManager()->Shutdown();
184             }
185 
186             OPropertySetHelper::disposing();
187 
188             DisposeFrameworkControllers();
189 
190             SfxBaseController::dispose();
191         }
192     }
193 }
194 
195 
196 
197 
addEventListener(const Reference<lang::XEventListener> & xListener)198 void SAL_CALL DrawController::addEventListener(
199     const Reference<lang::XEventListener >& xListener)
200 {
201     ThrowIfDisposed();
202     SfxBaseController::addEventListener( xListener );
203 }
204 
205 
206 
207 
removeEventListener(const Reference<lang::XEventListener> & aListener)208 void SAL_CALL DrawController::removeEventListener (
209     const Reference<lang::XEventListener >& aListener)
210 {
211     if(!rBHelper.bDisposed && !rBHelper.bInDispose && !mbDisposing)
212         SfxBaseController::removeEventListener( aListener );
213 }
214 
215 // XController
suspend(::sal_Bool Suspend)216 ::sal_Bool SAL_CALL DrawController::suspend( ::sal_Bool Suspend )
217 {
218     if( Suspend )
219     {
220         ViewShellBase* pViewShellBase = GetViewShellBase();
221         if( pViewShellBase )
222         {
223             // do not allow suspend if a slideshow needs this controller!
224             rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( *pViewShellBase ) );
225             if( xSlideShow.is() && xSlideShow->dependsOn(pViewShellBase) )
226                 return sal_False;
227         }
228     }
229 
230     return SfxBaseController::suspend( Suspend );
231 }
232 
233 
234 // XServiceInfo
235 
getImplementationName()236 OUString SAL_CALL DrawController::getImplementationName(  )
237 {
238     // Do not throw an excepetion at the moment.  This leads to a crash
239     // under Solaris on relead.  See issue i70929 for details.
240     //    ThrowIfDisposed();
241     return OUString( RTL_CONSTASCII_USTRINGPARAM( "DrawController" ) );
242 }
243 
244 
245 
246 static OUString ssServiceName (OUString::createFromAscii(
247     "com.sun.star.drawing.DrawingDocumentDrawView"));
248 
supportsService(const OUString & rsServiceName)249 sal_Bool SAL_CALL DrawController::supportsService (
250     const OUString& rsServiceName)
251 {
252     // Do not throw an excepetion at the moment.  This leads to a crash
253     // under Solaris on relead.  See issue i70929 for details.
254     //    ThrowIfDisposed();
255     return rsServiceName.equals(ssServiceName);
256 }
257 
258 
259 
260 
getSupportedServiceNames(void)261 Sequence<OUString> SAL_CALL DrawController::getSupportedServiceNames (void)
262 {
263     ThrowIfDisposed();
264     Sequence<OUString> aSupportedServices (1);
265     OUString* pServices = aSupportedServices.getArray();
266     pServices[0] = ssServiceName;
267     return aSupportedServices;
268 }
269 
270 
271 
272 
273 //------ XSelectionSupplier --------------------------------------------
274 
select(const Any & aSelection)275 sal_Bool SAL_CALL DrawController::select (const Any& aSelection)
276 {
277     ThrowIfDisposed();
278     ::vos::OGuard aGuard (Application::GetSolarMutex());
279 
280     if (mxSubController.is())
281         return mxSubController->select(aSelection);
282     else
283         return false;
284 }
285 
286 
287 
288 
getSelection()289 Any SAL_CALL DrawController::getSelection()
290 {
291     ThrowIfDisposed();
292     ::vos::OGuard aGuard (Application::GetSolarMutex());
293 
294     if (mxSubController.is())
295         return mxSubController->getSelection();
296     else
297         return Any();
298 }
299 
300 
301 
302 
addSelectionChangeListener(const Reference<view::XSelectionChangeListener> & xListener)303 void SAL_CALL DrawController::addSelectionChangeListener(
304     const Reference< view::XSelectionChangeListener >& xListener)
305 {
306     if( mbDisposing )
307         throw lang::DisposedException();
308 
309     BroadcastHelperOwner::maBroadcastHelper.addListener (saSelectionTypeIdentifier, xListener);
310 }
311 
312 
313 
314 
removeSelectionChangeListener(const Reference<view::XSelectionChangeListener> & xListener)315 void SAL_CALL DrawController::removeSelectionChangeListener(
316     const Reference< view::XSelectionChangeListener >& xListener )
317 {
318     if (rBHelper.bDisposed)
319         throw lang::DisposedException();
320 
321     BroadcastHelperOwner::maBroadcastHelper.removeListener (saSelectionTypeIdentifier, xListener);
322 }
323 
324 
325 
326 
327 
328 //=====  lang::XEventListener  ================================================
329 
330 void SAL_CALL
disposing(const lang::EventObject &)331     DrawController::disposing (const lang::EventObject& )
332 {
333 }
334 
335 
336 
337 
338 //=====  view::XSelectionChangeListener  ======================================
339 
340 void  SAL_CALL
selectionChanged(const lang::EventObject & rEvent)341     DrawController::selectionChanged (const lang::EventObject& rEvent)
342 {
343     ThrowIfDisposed();
344     // Have to forward the event to our selection change listeners.
345     OInterfaceContainerHelper* pListeners = BroadcastHelperOwner::maBroadcastHelper.getContainer(
346         ::getCppuType((Reference<view::XSelectionChangeListener>*)0));
347     if (pListeners)
348     {
349         // Re-send the event to all of our listeners.
350         OInterfaceIteratorHelper aIterator (*pListeners);
351         while (aIterator.hasMoreElements())
352         {
353             try
354             {
355                 view::XSelectionChangeListener* pListener =
356                     static_cast<view::XSelectionChangeListener*>(
357                         aIterator.next());
358                 if (pListener != NULL)
359                     pListener->selectionChanged (rEvent);
360             }
361             catch (RuntimeException aException)
362             {
363             }
364         }
365     }
366 }
367 
368 
369 
370 
371 // XDrawView
372 
setCurrentPage(const Reference<drawing::XDrawPage> & xPage)373 void SAL_CALL DrawController::setCurrentPage( const Reference< drawing::XDrawPage >& xPage )
374 {
375     ThrowIfDisposed();
376     ::vos::OGuard aGuard (Application::GetSolarMutex());
377 
378     if (mxSubController.is())
379         mxSubController->setCurrentPage(xPage);
380 }
381 
382 
383 
384 
getCurrentPage(void)385 Reference< drawing::XDrawPage > SAL_CALL DrawController::getCurrentPage (void)
386 {
387     ThrowIfDisposed();
388     ::vos::OGuard aGuard( Application::GetSolarMutex() );
389     Reference<drawing::XDrawPage> xPage;
390 
391     // Get current page from sub controller.
392     if (mxSubController.is())
393         xPage = mxSubController->getCurrentPage();
394 
395     // When there is not yet a sub controller (during initialization) then fall back
396     // to the current page in mpCurrentPage.
397     if ( ! xPage.is() && mpCurrentPage.is())
398         xPage = Reference<drawing::XDrawPage>(mpCurrentPage->getUnoPage(), UNO_QUERY);
399 
400     return xPage;
401 }
402 
403 
404 
405 
FireVisAreaChanged(const Rectangle & rVisArea)406 void DrawController::FireVisAreaChanged (const Rectangle& rVisArea) throw()
407 {
408     if( maLastVisArea != rVisArea )
409     {
410         Any aNewValue;
411         aNewValue <<= awt::Rectangle(
412             rVisArea.Left(),
413             rVisArea.Top(),
414             rVisArea.GetWidth(),
415             rVisArea.GetHeight() );
416 
417         Any aOldValue;
418         aOldValue <<= awt::Rectangle(
419             maLastVisArea.Left(),
420             maLastVisArea.Top(),
421             maLastVisArea.GetWidth(),
422             maLastVisArea.GetHeight() );
423 
424         FirePropertyChange (PROPERTY_WORKAREA, aNewValue, aOldValue);
425 
426         maLastVisArea = rVisArea;
427     }
428 }
429 
430 
431 
432 
FireSelectionChangeListener()433 void DrawController::FireSelectionChangeListener() throw()
434 {
435     OInterfaceContainerHelper * pLC = BroadcastHelperOwner::maBroadcastHelper.getContainer(
436         saSelectionTypeIdentifier);
437     if( pLC )
438     {
439         Reference< XInterface > xSource( (XWeak*)this );
440         const lang::EventObject aEvent( xSource );
441 
442         // Ueber alle Listener iterieren und Events senden
443         OInterfaceIteratorHelper aIt( *pLC);
444         while( aIt.hasMoreElements() )
445         {
446             try
447             {
448                 view::XSelectionChangeListener * pL =
449                     static_cast<view::XSelectionChangeListener*>(aIt.next());
450                 if (pL != NULL)
451                     pL->selectionChanged( aEvent );
452             }
453             catch (RuntimeException aException)
454             {
455             }
456         }
457     }
458 }
459 
460 
461 
462 
FireChangeEditMode(bool bMasterPageMode)463 void DrawController::FireChangeEditMode (bool bMasterPageMode) throw()
464 {
465     if (bMasterPageMode != mbMasterPageMode )
466     {
467         FirePropertyChange(
468             PROPERTY_MASTERPAGEMODE,
469             makeAny(bMasterPageMode),
470             makeAny(mbMasterPageMode));
471 
472         mbMasterPageMode = bMasterPageMode;
473     }
474 }
475 
476 
477 
478 
FireChangeLayerMode(bool bLayerMode)479 void DrawController::FireChangeLayerMode (bool bLayerMode) throw()
480 {
481     if (bLayerMode != mbLayerMode)
482     {
483         FirePropertyChange(
484             PROPERTY_LAYERMODE,
485             makeAny(bLayerMode),
486             makeAny(mbLayerMode));
487 
488         mbLayerMode = bLayerMode;
489     }
490 }
491 
492 
493 
494 
FireSwitchCurrentPage(SdPage * pNewCurrentPage)495 void DrawController::FireSwitchCurrentPage (SdPage* pNewCurrentPage) throw()
496 {
497     SdrPage* pCurrentPage  = mpCurrentPage.get();
498     if (pNewCurrentPage != pCurrentPage)
499     {
500         try
501         {
502             Any aNewValue (
503                 makeAny(Reference<drawing::XDrawPage>(pNewCurrentPage->getUnoPage(), UNO_QUERY)));
504 
505             Any aOldValue;
506             if (pCurrentPage != NULL)
507             {
508                 Reference<drawing::XDrawPage> xOldPage (pCurrentPage->getUnoPage(), UNO_QUERY);
509                 aOldValue <<= xOldPage;
510             }
511 
512             FirePropertyChange(PROPERTY_CURRENTPAGE, aNewValue, aOldValue);
513 
514             mpCurrentPage.reset(pNewCurrentPage);
515         }
516         catch( uno::Exception& e )
517         {
518             (void)e;
519             DBG_ERROR(
520                 (::rtl::OString("sd::SdUnoDrawView::FireSwitchCurrentPage(), "
521                     "exception caught: ") +
522                     ::rtl::OUStringToOString(
523                         comphelper::anyToString( cppu::getCaughtException() ),
524                         RTL_TEXTENCODING_UTF8 )).getStr() );
525         }
526     }
527 }
NotifyAccUpdate()528 void DrawController::NotifyAccUpdate()
529 {
530     sal_Int32 nHandle = PROPERTY_UPDATEACC;
531     Any aNewValue, aOldValue;
532     fire (&nHandle, &aNewValue, &aOldValue, 1, sal_False);
533 }
534 
fireChangeLayer(::com::sun::star::uno::Reference<::com::sun::star::drawing::XLayer> * pCurrentLayer)535 void DrawController::fireChangeLayer( ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XLayer>* pCurrentLayer ) throw()
536 {
537     if( pCurrentLayer != mpCurrentLayer )
538     {
539         sal_Int32 nHandle = PROPERTY_ACTIVE_LAYER;
540 
541         Any aNewValue (makeAny( *pCurrentLayer) );
542 
543         Any aOldValue ;
544 
545         fire (&nHandle, &aNewValue, &aOldValue, 1, sal_False);
546 
547         mpCurrentLayer = pCurrentLayer;
548     }
549 }
550 
551 // This method is only called in slide show and outline view
552 //void DrawController::fireSwitchCurrentPage(String pageName ) throw()
fireSwitchCurrentPage(sal_Int32 pageIndex)553 void DrawController::fireSwitchCurrentPage(sal_Int32 pageIndex ) throw()
554 {
555         Any aNewValue;
556         Any aOldValue;
557         //OUString aPageName(  pageName );
558         //aNewValue <<= aPageName ;
559         aNewValue <<= pageIndex;
560 
561         // Use new property to handle page change event
562         sal_Int32 nHandles = PROPERTY_PAGE_CHANGE;
563         fire( &nHandles, &aNewValue, &aOldValue, 1, sal_False );
564 }
565 
FirePropertyChange(sal_Int32 nHandle,const Any & rNewValue,const Any & rOldValue)566 void DrawController::FirePropertyChange (
567     sal_Int32 nHandle,
568     const Any& rNewValue,
569     const Any& rOldValue)
570 {
571     try
572     {
573         fire (&nHandle, &rNewValue, &rOldValue, 1, sal_False);
574     }
575     catch (RuntimeException aException)
576     {
577         // Ignore this exception.  Exceptions should be handled in the
578         // fire() function so that all listeners are called.  This is
579         // not the case at the moment, so we simply ignore the
580         // exception.
581     }
582 
583 }
584 
585 
586 
587 
BroadcastContextChange(void) const588 void DrawController::BroadcastContextChange (void) const
589 {
590     ::boost::shared_ptr<ViewShell> pViewShell (mpBase->GetMainViewShell());
591     if ( ! pViewShell)
592         return;
593 
594     EnumContext::Context eContext (EnumContext::Context_Unknown);
595     switch (pViewShell->GetShellType())
596     {
597         case ViewShell::ST_IMPRESS:
598         case ViewShell::ST_DRAW:
599             if (mbMasterPageMode)
600                 eContext = EnumContext::Context_MasterPage;
601             else
602                 eContext = EnumContext::Context_DrawPage;
603             break;
604 
605         case ViewShell::ST_NOTES:
606             eContext = EnumContext::Context_NotesPage;
607             break;
608 
609         case ViewShell::ST_HANDOUT:
610             eContext = EnumContext::Context_HandoutPage;
611             break;
612 
613         case ViewShell::ST_OUTLINE:
614             eContext = EnumContext::Context_OutlineText;
615             break;
616 
617         case ViewShell::ST_SLIDE_SORTER:
618             eContext = EnumContext::Context_SlidesorterPage;
619             break;
620 
621         case ViewShell::ST_PRESENTATION:
622         case ViewShell::ST_NONE:
623         default:
624             eContext = EnumContext::Context_Empty;
625             break;
626     }
627 
628     ContextChangeEventMultiplexer::NotifyContextChange(mpBase, eContext);
629 }
630 
631 
632 
633 
GetViewShellBase(void)634 ViewShellBase* DrawController::GetViewShellBase (void)
635 {
636     return mpBase;
637 }
638 
639 
640 
641 
ReleaseViewShellBase(void)642 void DrawController::ReleaseViewShellBase (void)
643 {
644     DisposeFrameworkControllers();
645     mpBase = NULL;
646 }
647 
648 
649 
650 
651 //===== XControllerManager ==============================================================
652 
653 Reference<XConfigurationController> SAL_CALL
getConfigurationController(void)654     DrawController::getConfigurationController (void)
655 {
656     ThrowIfDisposed();
657 
658     return mxConfigurationController;
659 }
660 
661 
662 
663 
664 Reference<XModuleController> SAL_CALL
getModuleController(void)665     DrawController::getModuleController (void)
666 {
667     ThrowIfDisposed();
668 
669     return mxModuleController;
670 }
671 
672 
673 
674 
675 //===== XUnoTunnel ============================================================
676 
getUnoTunnelId(void)677 const Sequence<sal_Int8>& DrawController::getUnoTunnelId (void)
678 {
679     static ::com::sun::star::uno::Sequence<sal_Int8>* pSequence = NULL;
680     if (pSequence == NULL)
681     {
682         ::osl::Guard< ::osl::Mutex > aGuard (::osl::Mutex::getGlobalMutex());
683         if (pSequence == NULL)
684         {
685             static ::com::sun::star::uno::Sequence<sal_Int8> aSequence (16);
686             rtl_createUuid((sal_uInt8*)aSequence.getArray(), 0, sal_True);
687             pSequence = &aSequence;
688         }
689     }
690     return *pSequence;
691 }
692 
693 
694 
695 
getSomething(const Sequence<sal_Int8> & rId)696 sal_Int64 SAL_CALL DrawController::getSomething (const Sequence<sal_Int8>& rId)
697 {
698     sal_Int64 nResult = 0;
699 
700     if (rId.getLength() == 16
701         && rtl_compareMemory(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
702     {
703         nResult = sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
704     }
705 
706     return nResult;
707 }
708 
709 
710 
711 
712 //===== Properties ============================================================
713 
FillPropertyTable(::std::vector<beans::Property> & rProperties)714 void DrawController::FillPropertyTable (
715     ::std::vector<beans::Property>& rProperties)
716 {
717     rProperties.push_back(
718         beans::Property(
719             OUString( RTL_CONSTASCII_USTRINGPARAM("VisibleArea") ),
720             PROPERTY_WORKAREA,
721             ::getCppuType((const ::com::sun::star::awt::Rectangle*)0),
722             beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY));
723     rProperties.push_back(
724         beans::Property(
725             OUString( RTL_CONSTASCII_USTRINGPARAM("SubController") ),
726             PROPERTY_SUB_CONTROLLER,
727             ::getCppuType((const Reference<drawing::XDrawSubController>*)0),
728             beans::PropertyAttribute::BOUND));
729     rProperties.push_back(
730         beans::Property(
731             OUString( RTL_CONSTASCII_USTRINGPARAM("CurrentPage") ),
732             PROPERTY_CURRENTPAGE,
733             ::getCppuType((const Reference< drawing::XDrawPage > *)0),
734             beans::PropertyAttribute::BOUND ));
735     rProperties.push_back(
736         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("IsLayerMode") ),
737             PROPERTY_LAYERMODE,
738             ::getCppuBooleanType(),
739             beans::PropertyAttribute::BOUND ));
740     rProperties.push_back(
741         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("IsMasterPageMode") ),
742             PROPERTY_MASTERPAGEMODE,
743             ::getCppuBooleanType(),
744             beans::PropertyAttribute::BOUND ));
745     rProperties.push_back(
746         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ActiveLayer") ),
747             PROPERTY_ACTIVE_LAYER,
748             ::getCppuType((const Reference< drawing::XLayer > *)0),
749             beans::PropertyAttribute::BOUND ));
750     rProperties.push_back(
751         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ZoomValue") ),
752             PROPERTY_ZOOMVALUE,
753             ::getCppuType((const sal_Int16*)0),
754             beans::PropertyAttribute::BOUND ));
755     rProperties.push_back(
756         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ZoomType") ),
757             PROPERTY_ZOOMTYPE,
758             ::getCppuType((const sal_Int16*)0),
759             beans::PropertyAttribute::BOUND ));
760     rProperties.push_back(
761         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("ViewOffset") ),
762             PROPERTY_VIEWOFFSET,
763             ::getCppuType((const ::com::sun::star::awt::Point*)0),
764             beans::PropertyAttribute::BOUND ));
765     rProperties.push_back(
766         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("DrawViewMode") ),
767             PROPERTY_DRAWVIEWMODE,
768             ::getCppuType((const ::com::sun::star::awt::Point*)0),
769             beans::PropertyAttribute::BOUND|beans::PropertyAttribute::READONLY|beans::PropertyAttribute::MAYBEVOID ));
770     // add new property to update current page's acc information
771     rProperties.push_back(
772         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("UpdateAcc") ),
773             PROPERTY_UPDATEACC,
774             ::getCppuType((const sal_Int16*)0),
775             beans::PropertyAttribute::BOUND ));
776     rProperties.push_back(
777         beans::Property( OUString( RTL_CONSTASCII_USTRINGPARAM("PageChange") ),
778             PROPERTY_PAGE_CHANGE,
779             ::getCppuType((const sal_Int16*)0),
780             beans::PropertyAttribute::BOUND ));
781 }
782 
783 
784 
785 
getInfoHelper()786 IPropertyArrayHelper & DrawController::getInfoHelper()
787 {
788     OGuard aGuard( Application::GetSolarMutex() );
789 
790     if (mpPropertyArrayHelper.get() == NULL)
791     {
792         ::std::vector<beans::Property> aProperties;
793         FillPropertyTable (aProperties);
794         Sequence<beans::Property> aPropertySequence (aProperties.size());
795         for (unsigned int i=0; i<aProperties.size(); i++)
796             aPropertySequence[i] = aProperties[i];
797         mpPropertyArrayHelper.reset(new OPropertyArrayHelper(aPropertySequence, sal_False));
798     }
799 
800     return *mpPropertyArrayHelper.get();
801 }
802 
803 
804 
805 
getPropertySetInfo()806 Reference < beans::XPropertySetInfo >  DrawController::getPropertySetInfo()
807 {
808     ::vos::OGuard aGuard( Application::GetSolarMutex() );
809 
810     static Reference < beans::XPropertySetInfo >  xInfo( createPropertySetInfo( getInfoHelper() ) );
811     return xInfo;
812 }
813 
814 
getFormController(const uno::Reference<form::XForm> & Form)815 uno::Reference< form::runtime::XFormController > SAL_CALL DrawController::getFormController( const uno::Reference< form::XForm >& Form )
816 {
817     OGuard aGuard( Application::GetSolarMutex() );
818 
819     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
820     SdrView* pSdrView = mpBase->GetDrawView();
821     ::boost::shared_ptr<ViewShell> pViewShell = mpBase->GetMainViewShell();
822     ::sd::Window* pWindow = pViewShell ? pViewShell->GetActiveWindow() : NULL;
823 
824     uno::Reference< form::runtime::XFormController > xController( NULL );
825     if ( pFormShell && pSdrView && pWindow )
826         xController = pFormShell->GetFormController( Form, *pSdrView, *pWindow );
827     return xController;
828 }
829 
isFormDesignMode()830 ::sal_Bool SAL_CALL DrawController::isFormDesignMode(  )
831 {
832     OGuard aGuard( Application::GetSolarMutex() );
833 
834     sal_Bool bIsDesignMode = sal_True;
835 
836     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
837     if ( pFormShell )
838         bIsDesignMode = pFormShell->IsDesignMode();
839 
840     return bIsDesignMode;
841 }
842 
setFormDesignMode(::sal_Bool _DesignMode)843 void SAL_CALL DrawController::setFormDesignMode( ::sal_Bool _DesignMode )
844 {
845     OGuard aGuard( Application::GetSolarMutex() );
846 
847     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
848     if ( pFormShell )
849         pFormShell->SetDesignMode( _DesignMode );
850 }
851 
getControl(const uno::Reference<awt::XControlModel> & xModel)852 uno::Reference< awt::XControl > SAL_CALL DrawController::getControl( const uno::Reference< awt::XControlModel >& xModel )
853 {
854     OGuard aGuard( Application::GetSolarMutex() );
855 
856     FmFormShell* pFormShell = mpBase->GetFormShellManager()->GetFormShell();
857     SdrView* pSdrView = mpBase->GetDrawView();
858     ::boost::shared_ptr<ViewShell> pViewShell = mpBase->GetMainViewShell();
859     ::sd::Window* pWindow = pViewShell ? pViewShell->GetActiveWindow() : NULL;
860 
861     uno::Reference< awt::XControl > xControl( NULL );
862     if ( pFormShell && pSdrView && pWindow )
863         pFormShell->GetFormControl( xModel, *pSdrView, *pWindow, xControl );
864     return xControl;
865 }
866 
867 
868 
869 
convertFastPropertyValue(Any & rConvertedValue,Any & rOldValue,sal_Int32 nHandle,const Any & rValue)870 sal_Bool DrawController::convertFastPropertyValue (
871     Any & rConvertedValue,
872     Any & rOldValue,
873     sal_Int32 nHandle,
874     const Any& rValue)
875 {
876     sal_Bool bResult = sal_False;
877 
878     if (nHandle == PROPERTY_SUB_CONTROLLER)
879     {
880         rOldValue <<= mxSubController;
881         rConvertedValue <<= Reference<drawing::XDrawSubController>(rValue, UNO_QUERY);
882         bResult = (rOldValue != rConvertedValue);
883     }
884     else if (mxSubController.is())
885     {
886         rConvertedValue = rValue;
887         try
888         {
889             rOldValue = mxSubController->getFastPropertyValue(nHandle);
890             bResult = (rOldValue != rConvertedValue);
891         }
892         catch(beans::UnknownPropertyException aException)
893         {
894             // The prperty is unknown and thus an illegal argument to this method.
895             throw com::sun::star::lang::IllegalArgumentException();
896         }
897     }
898 
899     return bResult;
900 }
901 
902 
903 
904 
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)905 void DrawController::setFastPropertyValue_NoBroadcast (
906     sal_Int32 nHandle,
907     const Any& rValue)
908 {
909     OGuard aGuard( Application::GetSolarMutex() );
910     if (nHandle == PROPERTY_SUB_CONTROLLER)
911         SetSubController(Reference<drawing::XDrawSubController>(rValue, UNO_QUERY));
912     else if (mxSubController.is())
913         mxSubController->setFastPropertyValue(nHandle, rValue);
914 }
915 
916 
917 
918 
getFastPropertyValue(Any & rRet,sal_Int32 nHandle) const919 void DrawController::getFastPropertyValue (
920     Any & rRet,
921     sal_Int32 nHandle ) const
922 {
923     OGuard aGuard( Application::GetSolarMutex() );
924 
925     switch( nHandle )
926     {
927         case PROPERTY_WORKAREA:
928             rRet <<= awt::Rectangle(
929                 maLastVisArea.Left(),
930                 maLastVisArea.Top(),
931                 maLastVisArea.GetWidth(),
932                 maLastVisArea.GetHeight());
933             break;
934 
935         case PROPERTY_SUB_CONTROLLER:
936             rRet <<= mxSubController;
937             break;
938 
939         default:
940             if (mxSubController.is())
941                 rRet = mxSubController->getFastPropertyValue(nHandle);
942             break;
943     }
944 }
945 
946 
947 
948 
949 //-----------------------------------------------------------------------------
950 
ProvideFrameworkControllers(void)951 void DrawController::ProvideFrameworkControllers (void)
952 {
953     ::vos::OGuard aGuard (Application::GetSolarMutex());
954     try
955     {
956         Reference<XController> xController (this);
957         const Reference<XComponentContext> xContext (
958             ::comphelper::getProcessComponentContext() );
959         mxConfigurationController = ConfigurationController::create(
960             xContext,
961             xController);
962         mxModuleController = ModuleController::create(
963             xContext,
964             xController);
965     }
966     catch (RuntimeException&)
967     {
968         mxConfigurationController = NULL;
969         mxModuleController = NULL;
970     }
971 }
972 
973 
974 
975 
DisposeFrameworkControllers(void)976 void DrawController::DisposeFrameworkControllers (void)
977 {
978     Reference<XComponent> xComponent (mxModuleController, UNO_QUERY);
979     if (xComponent.is())
980         xComponent->dispose();
981 
982     xComponent = Reference<XComponent>(mxConfigurationController, UNO_QUERY);
983     if (xComponent.is())
984         xComponent->dispose();
985 }
986 
987 
988 
989 
ThrowIfDisposed(void) const990 void DrawController::ThrowIfDisposed (void) const
991 {
992     if (rBHelper.bDisposed || rBHelper.bInDispose || mbDisposing)
993     {
994         OSL_TRACE ("Calling disposed DrawController object. Throwing exception:");
995         throw lang::DisposedException (
996             OUString(RTL_CONSTASCII_USTRINGPARAM(
997                 "DrawController object has already been disposed")),
998             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
999     }
1000 }
1001 
1002 
1003 
1004 
1005 
1006 } // end of namespace sd
1007