xref: /trunk/main/sd/source/ui/slideshow/slideshow.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 //#include <com/sun/star/frame/XController.hpp>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
34 #include <com/sun/star/container/XIndexAccess.hpp>
35 #include <comphelper/serviceinfohelper.hxx>
36 
37 #include <cppuhelper/bootstrap.hxx>
38 
39 #include <comphelper/processfactory.hxx>
40 #include <vos/mutex.hxx>
41 
42 #include <vcl/svapp.hxx>
43 #include <vcl/wrkwin.hxx>
44 #include <svx/svdpool.hxx>
45 #include <svl/itemprop.hxx>
46 
47 #include <sfx2/viewfrm.hxx>
48 
49 #include <toolkit/unohlp.hxx>
50 #include <svx/unoprov.hxx>
51 
52 #include "framework/FrameworkHelper.hxx"
53 
54 #include "FrameView.hxx"
55 #include "unomodel.hxx"
56 #include "slideshow.hxx"
57 #include "slideshowimpl.hxx"
58 #include "sdattr.hrc"
59 #include "FactoryIds.hxx"
60 #include "ViewShell.hxx"
61 #include "SlideShowRestarter.hxx"
62 #include "DrawController.hxx"
63 #include <boost/bind.hpp>
64 
65 using ::com::sun::star::presentation::XSlideShowController;
66 using ::com::sun::star::container::XIndexAccess;
67 using ::sd::framework::FrameworkHelper;
68 using ::rtl::OUString;
69 using ::com::sun::star::awt::XWindow;
70 using namespace ::sd;
71 using namespace ::cppu;
72 using namespace ::vos;
73 using namespace ::com::sun::star::uno;
74 using namespace ::com::sun::star::presentation;
75 using namespace ::com::sun::star::drawing;
76 using namespace ::com::sun::star::beans;
77 using namespace ::com::sun::star::lang;
78 using namespace ::com::sun::star::animations;
79 using namespace ::com::sun::star::drawing::framework;
80 
81 extern String getUiNameFromPageApiNameImpl( const ::rtl::OUString& rApiName );
82 
83 #define C2U(x) OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
84 
85 
86 namespace {
87     /** This local version of the work window overloads DataChanged() so that it
88         can restart the slide show when a display is added or removed.
89     */
90     class FullScreenWorkWindow : public WorkWindow
91     {
92     public:
93         FullScreenWorkWindow (
94             const ::rtl::Reference<SlideShow>& rpSlideShow,
95             ViewShellBase* pViewShellBase)
96             : WorkWindow(NULL, WB_HIDE | WB_CLIPCHILDREN),
97               mpRestarter(new SlideShowRestarter(rpSlideShow, pViewShellBase))
98         {}
99 
100 
101         virtual void DataChanged (const DataChangedEvent& rEvent)
102         {
103             if (rEvent.GetType() == DATACHANGED_DISPLAY)
104             {
105                 mpRestarter->Restart();
106             }
107         }
108 
109     private:
110         ::boost::shared_ptr<SlideShowRestarter> mpRestarter;
111     };
112 
113     /** Return the default display id (or -1 when that can not be
114         determined.)
115     */
116     sal_Int32 GetDefaultDisplay (void)
117     {
118         try
119         {
120             Reference< XMultiServiceFactory > xFactory(::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
121             Reference< XPropertySet > xMonProps(xFactory->createInstance(OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.DisplayAccess" ) ) ), UNO_QUERY_THROW );
122             const OUString sPropertyName( RTL_CONSTASCII_USTRINGPARAM( "DefaultDisplay" ) );
123             sal_Int32 nPrimaryIndex (-1);
124             if (xMonProps->getPropertyValue( sPropertyName ) >>= nPrimaryIndex)
125                 return nPrimaryIndex;
126         }
127         catch( Exception& )
128         {
129         }
130         return -1;
131     }
132 }
133 
134 
135 //////////////////////////////////////////////////////////////////////////////
136 // --------------------------------------------------------------------
137 
138 const SfxItemPropertyMapEntry* ImplGetPresentationPropertyMap()
139 {
140     // NOTE: First member must be sorted
141     static const SfxItemPropertyMapEntry aPresentationPropertyMap_Impl[] =
142     {
143         { MAP_CHAR_LEN("AllowAnimations"),          ATTR_PRESENT_ANIMATION_ALLOWED, &::getBooleanCppuType(),                0, 0 },
144         { MAP_CHAR_LEN("CustomShow"),               ATTR_PRESENT_CUSTOMSHOW,        &::getCppuType((const OUString*)0),     0, 0 },
145         { MAP_CHAR_LEN("Display"),                  ATTR_PRESENT_DISPLAY,           &::getCppuType((const sal_Int32*)0),    0, 0 },
146         { MAP_CHAR_LEN("FirstPage"),                ATTR_PRESENT_DIANAME,           &::getCppuType((const OUString*)0),     0, 0 },
147         { MAP_CHAR_LEN("IsAlwaysOnTop"),            ATTR_PRESENT_ALWAYS_ON_TOP,     &::getBooleanCppuType(),                0, 0 },
148         { MAP_CHAR_LEN("IsAutomatic"),              ATTR_PRESENT_MANUEL,            &::getBooleanCppuType(),                0, 0 },
149         { MAP_CHAR_LEN("IsEndless"),                ATTR_PRESENT_ENDLESS,           &::getBooleanCppuType(),                0, 0 },
150         { MAP_CHAR_LEN("IsFullScreen"),             ATTR_PRESENT_FULLSCREEN,        &::getBooleanCppuType(),                0, 0 },
151         { MAP_CHAR_LEN("IsShowAll"),                ATTR_PRESENT_ALL,               &::getBooleanCppuType(),                0, 0 },
152         { MAP_CHAR_LEN("IsMouseVisible"),           ATTR_PRESENT_MOUSE,             &::getBooleanCppuType(),                0, 0 },
153         { MAP_CHAR_LEN("IsShowLogo"),               ATTR_PRESENT_SHOW_PAUSELOGO,    &::getBooleanCppuType(),                0, 0 },
154         { MAP_CHAR_LEN("IsTransitionOnClick"),      ATTR_PRESENT_CHANGE_PAGE,       &::getBooleanCppuType(),                0, 0 },
155         { MAP_CHAR_LEN("Pause"),                    ATTR_PRESENT_PAUSE_TIMEOUT,     &::getCppuType((const sal_Int32*)0),    0, 0 },
156         { MAP_CHAR_LEN("StartWithNavigator"),       ATTR_PRESENT_NAVIGATOR,         &::getBooleanCppuType(),                0, 0 },
157         { MAP_CHAR_LEN("UsePen"),                   ATTR_PRESENT_PEN,               &::getBooleanCppuType(),                0, 0 },
158         { 0,0,0,0,0,0}
159     };
160 
161     return aPresentationPropertyMap_Impl;
162 }
163 
164 //SfxItemPropertyMap map_impl[] = { { 0,0,0,0,0,0 } };
165 
166 // --------------------------------------------------------------------
167 // class SlideShow
168 // --------------------------------------------------------------------
169 
170 SlideShow::SlideShow( SdDrawDocument* pDoc )
171 : SlideshowBase( m_aMutex )
172 , maPropSet(ImplGetPresentationPropertyMap(), SdrObject::GetGlobalDrawObjectItemPool())
173 , mbIsInStartup(false)
174 , mpDoc( pDoc )
175 , mpCurrentViewShellBase( 0 )
176 , mpFullScreenViewShellBase( 0 )
177 , mpFullScreenFrameView( 0 )
178 , mnInPlaceConfigEvent( 0 )
179 {
180 }
181 
182 // --------------------------------------------------------------------
183 
184 void SlideShow::ThrowIfDisposed() throw (RuntimeException)
185 {
186     if( mpDoc == 0 )
187         throw DisposedException();
188 }
189 
190 // --------------------------------------------------------------------
191 
192 /// used by the model to create a slideshow for it
193 rtl::Reference< SlideShow > SlideShow::Create( SdDrawDocument* pDoc )
194 {
195     return new SlideShow( pDoc );
196 }
197 
198 // --------------------------------------------------------------------
199 
200 rtl::Reference< SlideShow > SlideShow::GetSlideShow( SdDrawDocument* pDocument )
201 {
202     rtl::Reference< SlideShow > xRet;
203 
204     if( pDocument )
205         xRet = rtl::Reference< SlideShow >( dynamic_cast< SlideShow* >( pDocument->getPresentation().get() ) );
206 
207     return xRet;
208 }
209 
210 // --------------------------------------------------------------------
211 
212 rtl::Reference< SlideShow > SlideShow::GetSlideShow( ViewShellBase& rBase )
213 {
214     return GetSlideShow( rBase.GetDocument() );
215 }
216 
217 // --------------------------------------------------------------------
218 
219 ::com::sun::star::uno::Reference< ::com::sun::star::presentation::XSlideShowController > SlideShow::GetSlideShowController(ViewShellBase& rBase )
220 {
221     rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
222 
223     Reference< XSlideShowController > xRet;
224     if( xSlideShow.is() )
225         xRet = xSlideShow->getController();
226 
227     return xRet;
228 }
229 
230 // --------------------------------------------------------------------
231 
232 bool SlideShow::StartPreview( ViewShellBase& rBase,
233     const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& xDrawPage,
234     const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xAnimationNode,
235     ::Window* pParent /* = 0 */ )
236 {
237     rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
238     if( xSlideShow.is() )
239         return xSlideShow->startPreview( xDrawPage, xAnimationNode, pParent );
240 
241     return false;
242 }
243 
244 // --------------------------------------------------------------------
245 
246 void SlideShow::Stop( ViewShellBase& rBase )
247 {
248     rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
249     if( xSlideShow.is() )
250         xSlideShow->end();
251 }
252 
253 // --------------------------------------------------------------------
254 
255 bool SlideShow::IsRunning( ViewShellBase& rBase )
256 {
257     rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
258     return xSlideShow.is() && xSlideShow->isRunning();
259 }
260 
261 // --------------------------------------------------------------------
262 
263 bool SlideShow::IsRunning( ViewShell& rViewShell )
264 {
265     rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rViewShell.GetViewShellBase() ) );
266     return xSlideShow.is() && xSlideShow->isRunning() && (xSlideShow->mxController->getViewShell() == &rViewShell);
267 }
268 
269 // --------------------------------------------------------------------
270 
271 void SlideShow::CreateController(  ViewShell* pViewSh, ::sd::View* pView, ::Window* pParentWindow )
272 {
273     DBG_ASSERT( !mxController.is(), "sd::SlideShow::CreateController(), clean up old controller first!" );
274 
275     Reference< XPresentation2 > xThis( this );
276 
277     rtl::Reference<SlideshowImpl> xController (
278         new SlideshowImpl(xThis, pViewSh, pView, mpDoc, pParentWindow));
279 
280     // Reset mbIsInStartup.  From here mxController.is() is used to prevent
281     // multiple slide show instances for one document.
282     mxController = xController;
283     mbIsInStartup = false;
284 }
285 
286 // --------------------------------------------------------------------
287 // XServiceInfo
288 // --------------------------------------------------------------------
289 
290 OUString SAL_CALL SlideShow::getImplementationName(  ) throw(RuntimeException)
291 {
292     return OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.sd.SlideShow") );
293 }
294 
295 // --------------------------------------------------------------------
296 
297 sal_Bool SAL_CALL SlideShow::supportsService( const OUString& ServiceName ) throw(RuntimeException)
298 {
299     return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames(  ) );
300 }
301 
302 // --------------------------------------------------------------------
303 
304 Sequence< OUString > SAL_CALL SlideShow::getSupportedServiceNames(  ) throw(RuntimeException)
305 {
306     OUString aService( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.Presentation") );
307     Sequence< OUString > aSeq( &aService, 1 );
308     return aSeq;
309 }
310 
311 // --------------------------------------------------------------------
312 // XPropertySet
313 // --------------------------------------------------------------------
314 
315 Reference< XPropertySetInfo > SAL_CALL SlideShow::getPropertySetInfo() throw(RuntimeException)
316 {
317     OGuard aGuard( Application::GetSolarMutex() );
318     static Reference< XPropertySetInfo > xInfo = maPropSet.getPropertySetInfo();
319     return xInfo;
320  }
321 
322 // --------------------------------------------------------------------
323 
324 void SAL_CALL SlideShow::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
325 {
326     OGuard aGuard( Application::GetSolarMutex() );
327     ThrowIfDisposed();
328 
329     sd::PresentationSettings& rPresSettings = mpDoc->getPresentationSettings();
330 
331     const SfxItemPropertySimpleEntry* pEntry = maPropSet.getPropertyMapEntry(aPropertyName);
332 
333     if( pEntry && ((pEntry->nFlags & PropertyAttribute::READONLY) != 0) )
334         throw PropertyVetoException();
335 
336     bool bValuesChanged = false;
337     bool bIllegalArgument = true;
338 
339     switch( pEntry ? pEntry->nWID : -1 )
340     {
341     case ATTR_PRESENT_ALL:
342     {
343         sal_Bool bVal = sal_False;
344 
345         if( aValue >>= bVal )
346         {
347             bIllegalArgument = false;
348 
349             if( rPresSettings.mbAll != bVal )
350             {
351                 rPresSettings.mbAll = bVal;
352                 bValuesChanged = true;
353                 if( bVal )
354                     rPresSettings.mbCustomShow = sal_False;
355             }
356         }
357         break;
358     }
359     case ATTR_PRESENT_CHANGE_PAGE:
360     {
361         sal_Bool bVal = sal_False;
362 
363         if( aValue >>= bVal )
364         {
365             bIllegalArgument = false;
366 
367             if( bVal == rPresSettings.mbLockedPages )
368             {
369                 bValuesChanged = true;
370                 rPresSettings.mbLockedPages = !bVal;
371             }
372         }
373         break;
374     }
375 
376     case ATTR_PRESENT_ANIMATION_ALLOWED:
377     {
378         sal_Bool bVal = sal_False;
379 
380         if( aValue >>= bVal )
381         {
382             bIllegalArgument = false;
383 
384             if(rPresSettings.mbAnimationAllowed != bVal)
385             {
386                 bValuesChanged = true;
387                 rPresSettings.mbAnimationAllowed = bVal;
388             }
389         }
390         break;
391     }
392     case ATTR_PRESENT_CUSTOMSHOW:
393     {
394         OUString aShow;
395         if( aValue >>= aShow )
396         {
397             bIllegalArgument = false;
398 
399             const String aShowName( aShow );
400 
401             List* pCustomShowList = mpDoc->GetCustomShowList(sal_False);
402             if(pCustomShowList)
403             {
404                 SdCustomShow* pCustomShow;
405                 for( pCustomShow = (SdCustomShow*) pCustomShowList->First(); pCustomShow != NULL; pCustomShow = (SdCustomShow*) pCustomShowList->Next() )
406                 {
407                     if( pCustomShow->GetName() == aShowName )
408                         break;
409                 }
410 
411                 rPresSettings.mbCustomShow = sal_True;
412                 bValuesChanged = true;
413             }
414         }
415         break;
416     }
417     case ATTR_PRESENT_ENDLESS:
418     {
419         sal_Bool bVal = sal_False;
420 
421         if( aValue >>= bVal )
422         {
423             bIllegalArgument = false;
424 
425             if( rPresSettings.mbEndless != bVal)
426             {
427                 bValuesChanged = true;
428                 rPresSettings.mbEndless = bVal;
429             }
430         }
431         break;
432     }
433     case ATTR_PRESENT_FULLSCREEN:
434     {
435         sal_Bool bVal = sal_False;
436 
437         if( aValue >>= bVal )
438         {
439             bIllegalArgument = false;
440             if( rPresSettings.mbFullScreen != bVal)
441             {
442                 bValuesChanged = true;
443                 rPresSettings.mbFullScreen = bVal;
444             }
445         }
446         break;
447     }
448     case ATTR_PRESENT_DIANAME:
449     {
450         OUString aPresPage;
451         aValue >>= aPresPage;
452         bIllegalArgument = false;
453         if( (rPresSettings.maPresPage != aPresPage) || !rPresSettings.mbCustomShow || !rPresSettings.mbAll )
454         {
455             bValuesChanged = true;
456             rPresSettings.maPresPage = getUiNameFromPageApiNameImpl(aPresPage);
457             rPresSettings.mbCustomShow = sal_False;
458             rPresSettings.mbAll = sal_False;
459         }
460         break;
461     }
462     case ATTR_PRESENT_MANUEL:
463     {
464         sal_Bool bVal = sal_False;
465 
466         if( aValue >>= bVal )
467         {
468             bIllegalArgument = false;
469 
470             if( rPresSettings.mbManual != bVal)
471             {
472                 bValuesChanged = true;
473                 rPresSettings.mbManual = bVal;
474             }
475         }
476         break;
477     }
478     case ATTR_PRESENT_MOUSE:
479     {
480         sal_Bool bVal = sal_False;
481 
482         if( aValue >>= bVal )
483         {
484             bIllegalArgument = false;
485             if( rPresSettings.mbMouseVisible != bVal)
486             {
487                 bValuesChanged = true;
488                 rPresSettings.mbMouseVisible = bVal;
489             }
490         }
491         break;
492     }
493     case ATTR_PRESENT_ALWAYS_ON_TOP:
494     {
495         sal_Bool bVal = sal_False;
496 
497         if( aValue >>= bVal )
498         {
499             bIllegalArgument = false;
500 
501             if( rPresSettings.mbAlwaysOnTop != bVal)
502             {
503                 bValuesChanged = true;
504                 rPresSettings.mbAlwaysOnTop = bVal;
505             }
506         }
507         break;
508     }
509     case ATTR_PRESENT_NAVIGATOR:
510     {
511         sal_Bool bVal = sal_False;
512 
513         if( aValue >>= bVal )
514         {
515             bIllegalArgument = false;
516 
517             if( rPresSettings.mbStartWithNavigator != bVal)
518             {
519                 bValuesChanged = true;
520                 rPresSettings.mbStartWithNavigator = bVal;
521             }
522         }
523         break;
524     }
525     case ATTR_PRESENT_PEN:
526     {
527         sal_Bool bVal = sal_False;
528 
529         if( aValue >>= bVal )
530         {
531             bIllegalArgument = false;
532 
533             if(rPresSettings.mbMouseAsPen != bVal)
534             {
535                 bValuesChanged = true;
536                 rPresSettings.mbMouseAsPen = bVal;
537             }
538         }
539         break;
540     }
541     case ATTR_PRESENT_PAUSE_TIMEOUT:
542     {
543         sal_Int32 nValue = 0;
544         if( (aValue >>= nValue) && (nValue >= 0) )
545         {
546             bIllegalArgument = false;
547             if( rPresSettings.mnPauseTimeout != nValue )
548             {
549                 bValuesChanged = true;
550                 rPresSettings.mnPauseTimeout = nValue;
551             }
552         }
553         break;
554     }
555     case ATTR_PRESENT_SHOW_PAUSELOGO:
556     {
557         sal_Bool bVal = sal_False;
558 
559         if( aValue >>= bVal )
560         {
561             bIllegalArgument = false;
562 
563             if( rPresSettings.mbShowPauseLogo != bVal )
564             {
565                 bValuesChanged = true;
566                 rPresSettings.mbShowPauseLogo = bVal;
567             }
568         }
569         break;
570     }
571     case ATTR_PRESENT_DISPLAY:
572     {
573         sal_Int32 nDisplay = 0;
574         if( aValue >>= nDisplay )
575         {
576             // Convert value to true display id.
577             if (nDisplay == 0)
578                 nDisplay = GetDefaultDisplay();
579             else if (nDisplay < 0)
580                 nDisplay = -1;
581             else
582                 --nDisplay;
583 
584             bIllegalArgument = false;
585 
586             SdOptions* pOptions = SD_MOD()->GetSdOptions(DOCUMENT_TYPE_IMPRESS);
587             pOptions->SetDisplay( nDisplay );
588         }
589         break;
590     }
591 
592     default:
593         throw UnknownPropertyException();
594     }
595 
596     if( bIllegalArgument )
597         throw IllegalArgumentException();
598 
599     if( bValuesChanged )
600         mpDoc->SetChanged( true );
601 }
602 
603 // --------------------------------------------------------------------
604 
605 Any SAL_CALL SlideShow::getPropertyValue( const OUString& PropertyName ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
606 {
607     OGuard aGuard( Application::GetSolarMutex() );
608     ThrowIfDisposed();
609 
610     const sd::PresentationSettings& rPresSettings = mpDoc->getPresentationSettings();
611 
612     const SfxItemPropertySimpleEntry* pEntry = maPropSet.getPropertyMapEntry(PropertyName);
613 
614     switch( pEntry ? pEntry->nWID : -1 )
615     {
616     case ATTR_PRESENT_ALL:
617         return Any( (sal_Bool) ( !rPresSettings.mbCustomShow && rPresSettings.mbAll ) );
618     case ATTR_PRESENT_CHANGE_PAGE:
619         return Any( (sal_Bool) !rPresSettings.mbLockedPages );
620     case ATTR_PRESENT_ANIMATION_ALLOWED:
621         return Any( rPresSettings.mbAnimationAllowed );
622     case ATTR_PRESENT_CUSTOMSHOW:
623         {
624             List* pList = mpDoc->GetCustomShowList(sal_False);
625             SdCustomShow* pShow = (pList && rPresSettings.mbCustomShow)?(SdCustomShow*)pList->GetCurObject():NULL;
626             OUString aShowName;
627 
628             if(pShow)
629                 aShowName = pShow->GetName();
630 
631             return Any( aShowName );
632         }
633     case ATTR_PRESENT_ENDLESS:
634         return Any( rPresSettings.mbEndless );
635     case ATTR_PRESENT_FULLSCREEN:
636         return Any( rPresSettings.mbFullScreen );
637     case ATTR_PRESENT_DIANAME:
638         {
639             OUString aSlideName;
640 
641             if( !rPresSettings.mbCustomShow && !rPresSettings.mbAll )
642                 aSlideName = getPageApiNameFromUiName( rPresSettings.maPresPage );
643 
644             return Any( aSlideName );
645         }
646     case ATTR_PRESENT_MANUEL:
647         return Any( rPresSettings.mbManual );
648     case ATTR_PRESENT_MOUSE:
649         return Any( rPresSettings.mbMouseVisible );
650     case ATTR_PRESENT_ALWAYS_ON_TOP:
651         return Any( rPresSettings.mbAlwaysOnTop );
652     case ATTR_PRESENT_NAVIGATOR:
653         return Any( rPresSettings.mbStartWithNavigator );
654     case ATTR_PRESENT_PEN:
655         return Any( rPresSettings.mbMouseAsPen );
656     case ATTR_PRESENT_PAUSE_TIMEOUT:
657         return Any( rPresSettings.mnPauseTimeout );
658     case ATTR_PRESENT_SHOW_PAUSELOGO:
659         return Any( rPresSettings.mbShowPauseLogo );
660     case ATTR_PRESENT_DISPLAY:
661     {
662         SdOptions* pOptions = SD_MOD()->GetSdOptions(DOCUMENT_TYPE_IMPRESS);
663         const sal_Int32 nDisplay (pOptions->GetDisplay());
664         // Convert true display id to the previously used schema.
665         if (nDisplay == GetDefaultDisplay())
666             return Any(sal_Int32(0));
667         else if (nDisplay < 0)
668             return Any(sal_Int32(-1));
669         else
670             return Any(nDisplay+1);
671     }
672 
673     default:
674         throw UnknownPropertyException();
675     }
676 }
677 
678 // --------------------------------------------------------------------
679 
680 void SAL_CALL SlideShow::addPropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >&  ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
681 {
682 }
683 
684 // --------------------------------------------------------------------
685 
686 void SAL_CALL SlideShow::removePropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >&  ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
687 {
688 }
689 
690 // --------------------------------------------------------------------
691 
692 void SAL_CALL SlideShow::addVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >&  ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
693 {
694 }
695 
696 // --------------------------------------------------------------------
697 
698 void SAL_CALL SlideShow::removeVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >&  ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
699 {
700 }
701 
702 // --------------------------------------------------------------------
703 // XPresentation
704 // --------------------------------------------------------------------
705 
706 void SAL_CALL SlideShow::start() throw(RuntimeException)
707 {
708     const Sequence< PropertyValue > aArguments;
709     startWithArguments( aArguments );
710 }
711 
712 // --------------------------------------------------------------------
713 
714 void SAL_CALL SlideShow::end() throw(RuntimeException)
715 {
716     OGuard aGuard( Application::GetSolarMutex() );
717 
718     // The mbIsInStartup flag should have been reset during the start of the
719     // slide show.  Reset it here just in case that something has horribly
720     // gone wrong.
721     OSL_ASSERT(!mbIsInStartup);
722     mbIsInStartup = false;
723 
724     rtl::Reference< SlideshowImpl > xController( mxController );
725     if( xController.is() )
726     {
727         mxController.clear();
728 
729         if( mpFullScreenFrameView )
730         {
731             delete mpFullScreenFrameView;
732             mpFullScreenFrameView = 0;
733         }
734 
735         ViewShellBase* pFullScreenViewShellBase = mpFullScreenViewShellBase;
736         mpFullScreenViewShellBase = 0;
737 
738         if( pFullScreenViewShellBase )
739         {
740             PresentationViewShell* pShell = dynamic_cast<PresentationViewShell*>(pFullScreenViewShellBase->GetMainViewShell().get());
741 
742             if( pShell && pShell->GetViewFrame() )
743             {
744                 WorkWindow* pWorkWindow = dynamic_cast<WorkWindow*>(pShell->GetViewFrame()->GetTopFrame().GetWindow().GetParent());
745                 if( pWorkWindow )
746                 {
747                     pWorkWindow->StartPresentationMode( sal_False, isAlwaysOnTop() );
748                 }
749             }
750         }
751 
752         xController->dispose();
753 
754         if( pFullScreenViewShellBase )
755         {
756             PresentationViewShell* pShell = NULL;
757             {
758                 // Get the shell pointer in its own scope to be sure that
759                 // the shared_ptr to the shell is released before DoClose()
760                 // is called.
761                 ::boost::shared_ptr<ViewShell> pSharedView (pFullScreenViewShellBase->GetMainViewShell());
762                 pShell = dynamic_cast<PresentationViewShell*>(pSharedView.get());
763             }
764             if( pShell && pShell->GetViewFrame() )
765                 pShell->GetViewFrame()->DoClose();
766         }
767         else if( mpCurrentViewShellBase )
768         {
769             ViewShell* pViewShell = mpCurrentViewShellBase->GetMainViewShell().get();
770 
771             if( pViewShell )
772             {
773                 FrameView* pFrameView = pViewShell->GetFrameView();
774 
775                 if( pFrameView && (pFrameView->GetPresentationViewShellId() != SID_VIEWSHELL0) )
776                 {
777                     ViewShell::ShellType ePreviousType (pFrameView->GetPreviousViewShellType());
778                     pFrameView->SetPreviousViewShellType(ViewShell::ST_NONE);
779 
780                     pFrameView->SetPresentationViewShellId(SID_VIEWSHELL0);
781                     pFrameView->SetSlotId(SID_OBJECT_SELECT);
782                     pFrameView->SetPreviousViewShellType(pViewShell->GetShellType());
783 
784                     framework::FrameworkHelper::Instance(*mpCurrentViewShellBase)->RequestView(
785                         framework::FrameworkHelper::GetViewURL(ePreviousType),
786                         framework::FrameworkHelper::msCenterPaneURL);
787 
788                     pViewShell->GetViewFrame()->GetBindings().InvalidateAll( sal_True );
789                 }
790             }
791         }
792 
793         if( mpCurrentViewShellBase )
794         {
795             ViewShell* pViewShell = mpCurrentViewShellBase->GetMainViewShell().get();
796             if( pViewShell )
797             {
798                 // invalidate the view shell so the presentation slot will be re-enabled
799                 // and the rehersing will be updated
800                 pViewShell->Invalidate();
801 
802                 if( xController->meAnimationMode ==ANIMATIONMODE_SHOW )
803                 {
804                     // switch to the previously visible Slide
805                     DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>( pViewShell );
806                     if( pDrawViewShell )
807                         pDrawViewShell->SwitchPage( (sal_uInt16)xController->getRestoreSlide() );
808                     else
809                     {
810                         Reference<XDrawView> xDrawView (
811                             Reference<XWeak>(&mpCurrentViewShellBase->GetDrawController()), UNO_QUERY);
812                         if (xDrawView.is())
813                             xDrawView->setCurrentPage(
814                                 Reference<XDrawPage>(
815                                     mpDoc->GetSdPage(xController->getRestoreSlide(), PK_STANDARD)->getUnoPage(),
816                                     UNO_QUERY));
817                     }
818                 }
819             }
820         }
821         mpCurrentViewShellBase = 0;
822     }
823 }
824 
825 // --------------------------------------------------------------------
826 
827 void SAL_CALL SlideShow::rehearseTimings() throw(RuntimeException)
828 {
829     Sequence< PropertyValue > aArguments(1);
830     aArguments[0].Name = C2U("RehearseTimings");
831     aArguments[0].Value <<= sal_True;
832     startWithArguments( aArguments );
833 }
834 
835 // --------------------------------------------------------------------
836 // XPresentation2
837 // --------------------------------------------------------------------
838 
839 void SAL_CALL SlideShow::startWithArguments( const Sequence< PropertyValue >& rArguments ) throw (RuntimeException)
840 {
841     OGuard aGuard( Application::GetSolarMutex() );
842     ThrowIfDisposed();
843 
844     // Stop a running show before starting a new one.
845     if( mxController.is() )
846     {
847         OSL_ASSERT(!mbIsInStartup);
848         end();
849     }
850     else if (mbIsInStartup)
851     {
852         // We are already somewhere in process of starting a slide show but
853         // have not yet got to the point where mxController is set.  There
854         // is not yet a slide show to end so return silently.
855         return;
856     }
857 
858     // Prevent multiple instance of the SlideShow class for one document.
859     mbIsInStartup = true;
860 
861     mxCurrentSettings.reset( new PresentationSettingsEx( mpDoc->getPresentationSettings() ) );
862     mxCurrentSettings->SetArguments( rArguments );
863 
864     // if there is no view shell base set, use the current one or the first using this document
865     if( mpCurrentViewShellBase == 0 )
866     {
867         // first check current
868         ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase( SfxViewFrame::Current() );
869         if( pBase && pBase->GetDocument() == mpDoc )
870         {
871             mpCurrentViewShellBase = pBase;
872         }
873         else
874         {
875             // current is not ours, so get first from ours
876             mpCurrentViewShellBase = ::sd::ViewShellBase::GetViewShellBase( SfxViewFrame::GetFirst( mpDoc->GetDocSh() ) );
877         }
878     }
879 
880     // Start either a full-screen or an in-place show.
881     if(mxCurrentSettings->mbFullScreen && !mxCurrentSettings->mbPreview)
882         StartFullscreenPresentation();
883     else
884         StartInPlacePresentation();
885 }
886 
887 // --------------------------------------------------------------------
888 
889 ::sal_Bool SAL_CALL SlideShow::isRunning(  ) throw (RuntimeException)
890 {
891     OGuard aGuard( Application::GetSolarMutex() );
892     return mxController.is() && mxController->isRunning();
893 }
894 
895 // --------------------------------------------------------------------
896 
897 Reference< XSlideShowController > SAL_CALL SlideShow::getController(  ) throw (RuntimeException)
898 {
899     ThrowIfDisposed();
900 
901     Reference< XSlideShowController > xController( mxController.get() );
902     return xController;
903 }
904 
905 // --------------------------------------------------------------------
906 // XComponent
907 // --------------------------------------------------------------------
908 
909 void SAL_CALL SlideShow::disposing (void)
910 {
911     OGuard aGuard( Application::GetSolarMutex() );
912 
913     if( mnInPlaceConfigEvent )
914     {
915         Application::RemoveUserEvent( mnInPlaceConfigEvent );
916         mnInPlaceConfigEvent = 0;
917     }
918 
919     if( mxController.is() )
920     {
921         mxController->dispose();
922         mxController.clear();
923     }
924 
925     mpCurrentViewShellBase = 0;
926     mpFullScreenViewShellBase = 0;
927     mpDoc = 0;
928 }
929 
930 // ---------------------------------------------------------
931 
932 bool SlideShow::startPreview( const Reference< XDrawPage >& xDrawPage, const Reference< XAnimationNode >& xAnimationNode, ::Window* pParent )
933 {
934     Sequence< PropertyValue > aArguments(4);
935 
936     aArguments[0].Name = C2U("Preview");
937     aArguments[0].Value <<= sal_True;
938 
939     aArguments[1].Name = C2U("FirstPage");
940     aArguments[1].Value <<= xDrawPage;
941 
942     aArguments[2].Name = C2U("AnimationNode");
943     aArguments[2].Value <<= xAnimationNode;
944 
945     Reference< XWindow > xParentWindow;
946     if( pParent )
947         xParentWindow = VCLUnoHelper::GetInterface( pParent );
948 
949     aArguments[3].Name = C2U("ParentWindow");
950     aArguments[3].Value <<= xParentWindow;
951 
952     startWithArguments( aArguments );
953 
954     return true;
955 }
956 
957 // ---------------------------------------------------------
958 
959 ShowWindow* SlideShow::getShowWindow()
960 {
961     return mxController.is() ? mxController->mpShowWindow : 0;
962 }
963 
964 // ---------------------------------------------------------
965 
966 int SlideShow::getAnimationMode()
967 {
968     return mxController.is() ? mxController->meAnimationMode : ANIMATIONMODE_SHOW;
969 }
970 
971 // ---------------------------------------------------------
972 
973 void SlideShow::jumpToPageIndex( sal_Int32 nPageIndex )
974 {
975     if( mxController.is() )
976         mxController->displaySlideIndex( nPageIndex );
977 }
978 
979 // ---------------------------------------------------------
980 
981 void SlideShow::jumpToPageNumber( sal_Int32 nPageNumber )
982 {
983     if( mxController.is() )
984         mxController->displaySlideNumber( nPageNumber );
985 }
986 
987 // ---------------------------------------------------------
988 
989 sal_Int32 SlideShow::getCurrentPageNumber()
990 {
991     return mxController.is() ? mxController->getCurrentSlideNumber() : 0;
992 }
993 
994 // ---------------------------------------------------------
995 
996 void SlideShow::jumpToBookmark( const OUString& sBookmark )
997 {
998     if( mxController.is() )
999         mxController->jumpToBookmark( sBookmark );
1000 }
1001 
1002 // ---------------------------------------------------------
1003 
1004 bool SlideShow::isFullScreen()
1005 {
1006     return mxController.is() ? mxController->maPresSettings.mbFullScreen : false;
1007 }
1008 
1009 // ---------------------------------------------------------
1010 
1011 void SlideShow::resize( const Size &rSize )
1012 {
1013     if( mxController.is() )
1014         mxController->resize( rSize );
1015 }
1016 
1017 // ---------------------------------------------------------
1018 
1019 void SlideShow::activate( ViewShellBase& rBase )
1020 {
1021     if( (mpFullScreenViewShellBase == &rBase) && !mxController.is() )
1022     {
1023         ::boost::shared_ptr<PresentationViewShell> pShell = ::boost::dynamic_pointer_cast<PresentationViewShell>(rBase.GetMainViewShell());
1024         if(pShell.get() != NULL)
1025         {
1026             pShell->FinishInitialization( mpFullScreenFrameView );
1027             mpFullScreenFrameView = 0;
1028 
1029             CreateController( pShell.get(), pShell->GetView(), rBase.GetViewWindow() );
1030 
1031             if( mxController->startShow(mxCurrentSettings.get()) )
1032             {
1033                 pShell->Resize();
1034             }
1035             else
1036             {
1037                 end();
1038                 return;
1039             }
1040         }
1041     }
1042 
1043     if( mxController.is() )
1044         mxController->activate();
1045 }
1046 
1047 // ---------------------------------------------------------
1048 
1049 void SlideShow::deactivate( ViewShellBase& /*rBase*/ )
1050 {
1051     mxController->deactivate();
1052 }
1053 
1054 // ---------------------------------------------------------
1055 
1056 bool SlideShow::keyInput(const KeyEvent& rKEvt)
1057 {
1058     return mxController.is() ? mxController->keyInput(rKEvt) : false;
1059 }
1060 
1061 // ---------------------------------------------------------
1062 
1063 void SlideShow::paint( const Rectangle& rRect )
1064 {
1065     if( mxController.is() )
1066         mxController->paint( rRect );
1067 }
1068 
1069 // ---------------------------------------------------------
1070 
1071 bool SlideShow::isAlwaysOnTop()
1072 {
1073     return mxController.is() ? mxController->maPresSettings.mbAlwaysOnTop : false;
1074 }
1075 
1076 // ---------------------------------------------------------
1077 
1078 bool SlideShow::pause( bool bPause )
1079 {
1080     if( mxController.is() )
1081     {
1082         if( bPause )
1083             mxController->pause();
1084         else
1085             mxController->resume();
1086     }
1087     return true;
1088 }
1089 
1090 // ---------------------------------------------------------
1091 
1092 void SlideShow::receiveRequest(SfxRequest& rReq)
1093 {
1094     if( mxController.is() )
1095         mxController->receiveRequest( rReq );
1096 }
1097 
1098 // ---------------------------------------------------------
1099 
1100 sal_Int32 SlideShow::getFirstPageNumber()
1101 {
1102     return mxController.is() ? mxController->getFirstSlideNumber() : 0;
1103 }
1104 
1105 // ---------------------------------------------------------
1106 
1107 sal_Int32 SlideShow::getLastPageNumber()
1108 {
1109     return mxController.is() ? mxController->getLastSlideNumber() : 0;
1110 }
1111 
1112 // ---------------------------------------------------------
1113 
1114 bool SlideShow::isEndless()
1115 {
1116     return mxController.is() ? mxController->isEndless() : false;
1117 }
1118 
1119 // ---------------------------------------------------------
1120 
1121 bool SlideShow::isDrawingPossible()
1122 {
1123     return mxController.is() ? mxController->getUsePen() : false;
1124 }
1125 
1126 // ---------------------------------------------------------
1127 
1128 void SlideShow::StartInPlacePresentationConfigurationCallback()
1129 {
1130     if( mnInPlaceConfigEvent != 0 )
1131         Application::RemoveUserEvent( mnInPlaceConfigEvent );
1132 
1133     mnInPlaceConfigEvent = Application::PostUserEvent( LINK( this, SlideShow, StartInPlacePresentationConfigurationHdl ) );
1134 }
1135 
1136 // ---------------------------------------------------------
1137 
1138 IMPL_LINK( SlideShow, StartInPlacePresentationConfigurationHdl, void *, EMPTYARG )
1139 {
1140     mnInPlaceConfigEvent = 0;
1141     StartInPlacePresentation();
1142     return 0;
1143 }
1144 
1145 // ---------------------------------------------------------
1146 
1147 void SlideShow::StartInPlacePresentation()
1148 {
1149     if( mpCurrentViewShellBase )
1150     {
1151         // Save the current view shell type so that it can be restored after the
1152         // show has ended.  If there already is a saved shell type then that is
1153         // not overwritten.
1154 
1155         ViewShell::ShellType eShell = ViewShell::ST_NONE;
1156 
1157         ::boost::shared_ptr<FrameworkHelper> pHelper(FrameworkHelper::Instance(*mpCurrentViewShellBase));
1158         ::boost::shared_ptr<ViewShell> pMainViewShell(pHelper->GetViewShell(FrameworkHelper::msCenterPaneURL));
1159 
1160         if( pMainViewShell.get() )
1161             eShell = pMainViewShell->GetShellType();
1162 
1163         if( eShell != ViewShell::ST_IMPRESS )
1164         {
1165             // Switch temporary to a DrawViewShell which supports the in-place presentation.
1166 
1167             if( pMainViewShell.get() )
1168             {
1169                 FrameView* pFrameView = pMainViewShell->GetFrameView();
1170                 pFrameView->SetPresentationViewShellId(SID_VIEWSHELL1);
1171                 pFrameView->SetPreviousViewShellType (pMainViewShell->GetShellType());
1172                 pFrameView->SetPageKind (PK_STANDARD);
1173             }
1174 
1175             pHelper->RequestView( FrameworkHelper::msImpressViewURL, FrameworkHelper::msCenterPaneURL );
1176             pHelper->RunOnConfigurationEvent( FrameworkHelper::msConfigurationUpdateEndEvent, ::boost::bind(&SlideShow::StartInPlacePresentationConfigurationCallback, this) );
1177             return;
1178         }
1179         else
1180         {
1181             ::Window* pParentWindow = mxCurrentSettings->mpParentWindow;
1182             if( pParentWindow == 0 )
1183                 pParentWindow = mpCurrentViewShellBase->GetViewWindow();
1184 
1185             CreateController( pMainViewShell.get(), pMainViewShell->GetView(), pParentWindow );
1186         }
1187     }
1188     else if( mxCurrentSettings->mpParentWindow )
1189     {
1190         // no current view shell, but parent window
1191         CreateController( 0, 0, mxCurrentSettings->mpParentWindow );
1192     }
1193 
1194     if( mxController.is() )
1195     {
1196         sal_Bool bSuccess = sal_False;
1197         if( mxCurrentSettings.get() && mxCurrentSettings->mbPreview )
1198         {
1199             bSuccess = mxController->startPreview(mxCurrentSettings->mxStartPage, mxCurrentSettings->mxAnimationNode, mxCurrentSettings->mpParentWindow );
1200         }
1201         else
1202         {
1203             bSuccess = mxController->startShow(mxCurrentSettings.get());
1204         }
1205 
1206         if( !bSuccess )
1207             end();
1208     }
1209 }
1210 
1211 // ---------------------------------------------------------
1212 
1213 void SlideShow::StartFullscreenPresentation( )
1214 {
1215     // Create the top level window in which the PresentationViewShell(Base)
1216     // will be created.  This is done here explicitly so that we can make it
1217     // fullscreen.
1218     const sal_Int32 nDisplay (GetDisplay());
1219     WorkWindow* pWorkWindow = new FullScreenWorkWindow(this, mpCurrentViewShellBase);
1220     pWorkWindow->SetBackground(Wallpaper(COL_BLACK));
1221     pWorkWindow->StartPresentationMode( sal_True, mpDoc->getPresentationSettings().mbAlwaysOnTop ? PRESENTATION_HIDEALLAPPS : 0, nDisplay);
1222     //    pWorkWindow->ShowFullScreenMode(sal_False, nDisplay);
1223 
1224     if (pWorkWindow->IsVisible())
1225     {
1226         // Initialize the new presentation view shell with a copy of the
1227         // frame view of the current view shell.  This avoids that
1228         // changes made by the presentation have an effect on the other
1229         // view shells.
1230         FrameView* pOriginalFrameView = mpCurrentViewShellBase ? mpCurrentViewShellBase->GetMainViewShell()->GetFrameView() : 0;
1231 
1232         if( mpFullScreenFrameView )
1233             delete mpFullScreenFrameView;
1234         mpFullScreenFrameView = new FrameView(mpDoc, pOriginalFrameView);
1235 
1236 //      Reference<XController> xController;
1237 
1238         // The new frame is created hidden.  To make it visible and activate the
1239         // new view shell--a prerequisite to process slot calls and initialize
1240         // its panes--a GrabFocus() has to be called later on.
1241         SfxFrame* pNewFrame = SfxFrame::Create( *mpDoc->GetDocSh(), *pWorkWindow, PRESENTATION_FACTORY_ID, true );
1242         pNewFrame->SetPresentationMode(sal_True);
1243 
1244         mpFullScreenViewShellBase = static_cast<ViewShellBase*>(pNewFrame->GetCurrentViewFrame()->GetViewShell());
1245         if(mpFullScreenViewShellBase != NULL)
1246         {
1247             // The following GrabFocus() is responsible for activating the
1248             // new view shell.  Without it the screen remains blank (under
1249             // Windows and some Linux variants.)
1250             mpFullScreenViewShellBase->GetWindow()->GrabFocus();
1251         }
1252     }
1253 }
1254 
1255 // ---------------------------------------------------------
1256 
1257 sal_Int32 SlideShow::GetDisplay()
1258 
1259 {
1260     sal_Int32 nDisplay = 0;
1261 
1262     SdOptions* pOptions = SD_MOD()->GetSdOptions(DOCUMENT_TYPE_IMPRESS);
1263     if( pOptions )
1264         nDisplay = pOptions->GetDisplay();
1265 
1266     return nDisplay;
1267 }
1268 
1269 // ---------------------------------------------------------
1270 
1271 
1272 bool SlideShow::dependsOn( ViewShellBase* pViewShellBase )
1273 {
1274     return mxController.is() && (pViewShellBase == mpCurrentViewShellBase) && mpFullScreenViewShellBase;
1275 }
1276 
1277 // ---------------------------------------------------------
1278 
1279 Reference< XPresentation2 > CreatePresentation( const SdDrawDocument& rDocument )
1280 {
1281     return Reference< XPresentation2 >( SlideShow::Create( const_cast< SdDrawDocument* >( &rDocument ) ).get() );
1282 }
1283 
1284 // ---------------------------------------------------------
1285 
1286