1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: showwin.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include <com/sun/star/awt/Key.hpp>
36 #include "showwindow.hxx"
38 #include <svtools/syslocale.hxx>
39 #include <sfx2/viewfrm.hxx>
42 #include "res_bmp.hrc"
43 #include "slideshow.hxx"
44 #include "ViewShellBase.hxx"
45 #include "slideshow.hxx"
46 #include "sdresid.hxx"
48 #include "strings.hrc"
49 #include <vcl/virdev.hxx>
51 using namespace ::com::sun::star
;
55 static const ULONG HIDE_MOUSE_TIMEOUT
= 10000;
56 static const ULONG SHOW_MOUSE_TIMEOUT
= 1000;
58 // =============================================================================
60 ShowWindow::ShowWindow( const ::rtl::Reference
< SlideshowImpl
>& xController
, ::Window
* pParent
)
61 : ::sd::Window( pParent
)
62 , mnPauseTimeout( SLIDE_NO_TIMEOUT
)
63 , mnRestartPageIndex( PAGE_NO_END
)
64 , meShowWindowMode(SHOWWINDOWMODE_NORMAL
)
65 , mbShowNavigatorAfterSpecialMode( FALSE
)
66 , mbMouseAutoHide(true)
67 , mbMouseCursorHidden(false)
69 , mxController( xController
)
71 SetOutDevViewType( OUTDEV_VIEWTYPE_SLIDESHOW
);
73 // Do never mirror the preview window. This explicitly includes right
74 // to left writing environments.
77 MapMode
aMap(GetMapMode());
78 aMap
.SetMapUnit(MAP_100TH_MM
);
82 SetHelpId( HID_SD_WIN_PRESENTATION
);
83 SetUniqueId( HID_SD_WIN_PRESENTATION
);
85 maPauseTimer
.SetTimeoutHdl( LINK( this, ShowWindow
, PauseTimeoutHdl
) );
86 maPauseTimer
.SetTimeout( 1000 );
87 maMouseTimer
.SetTimeoutHdl( LINK( this, ShowWindow
, MouseTimeoutHdl
) );
88 maMouseTimer
.SetTimeout( HIDE_MOUSE_TIMEOUT
);
90 maShowBackground
= Wallpaper( Color( COL_BLACK
) );
91 // SetBackground( Wallpaper( Color( COL_BLACK ) ) );
92 SetBackground(); // avoids that VCL paints any background!
94 AddEventListener( LINK( this, ShowWindow
, EventHdl
) );
97 ShowWindow::~ShowWindow(void)
103 /*************************************************************************
107 \************************************************************************/
109 void ShowWindow::KeyInput(const KeyEvent
& rKEvt
)
111 BOOL bReturn
= FALSE
;
113 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
118 else if( SHOWWINDOWMODE_END
== meShowWindowMode
)
120 const int nKeyCode
= rKEvt
.GetKeyCode().GetCode();
129 case awt::Key::CONTEXTMENU
:
130 // these keys will be handled by the slide show even
138 else if( SHOWWINDOWMODE_BLANK
== meShowWindowMode
)
143 else if( SHOWWINDOWMODE_PAUSE
== meShowWindowMode
)
145 const int nKeyCode
= rKEvt
.GetKeyCode().GetCode();
158 case awt::Key::CONTEXTMENU
:
159 // these keys will be handled by the slide show even
171 if( mxController
.is() )
172 bReturn
= mxController
->keyInput(rKEvt
);
178 mpViewShell
->KeyInput(rKEvt
,this);
182 Window::KeyInput(rKEvt
);
188 mpViewShell
->SetActiveWindow( this );
191 /*************************************************************************
193 |* MouseButtonDown event
195 \************************************************************************/
197 void ShowWindow::MouseButtonDown(const MouseEvent
& /*rMEvt*/)
199 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
203 else if( mpViewShell
)
205 mpViewShell
->SetActiveWindow( this );
209 /*************************************************************************
213 \************************************************************************/
215 void ShowWindow::MouseMove(const MouseEvent
& /*rMEvt*/)
217 if( mbMouseAutoHide
)
219 if( mbMouseCursorHidden
)
221 if( mnFirstMouseMove
)
223 // if this is not the first mouse move while hidden, see if
224 // enough time has pasted to show mouse pointer again
225 ULONG nTime
= Time::GetSystemTicks();
226 if( (nTime
- mnFirstMouseMove
) >= SHOW_MOUSE_TIMEOUT
)
229 mnFirstMouseMove
= 0;
230 mbMouseCursorHidden
= false;
231 maMouseTimer
.SetTimeout( HIDE_MOUSE_TIMEOUT
);
232 maMouseTimer
.Start();
237 // if this is the first mouse move, note current
238 // time and start idle timer to cancel show mouse pointer
239 // again if not enough mouse movement is measured
240 mnFirstMouseMove
= Time::GetSystemTicks();
241 maMouseTimer
.SetTimeout( 2*SHOW_MOUSE_TIMEOUT
);
242 maMouseTimer
.Start();
247 // current mousemove restarts the idle timer to hide the mouse
248 maMouseTimer
.Start();
253 mpViewShell
->SetActiveWindow( this );
256 /*************************************************************************
258 |* MouseButtonUp event
260 \************************************************************************/
262 void ShowWindow::MouseButtonUp(const MouseEvent
& rMEvt
)
264 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
268 else if( (SHOWWINDOWMODE_END
== meShowWindowMode
) && !rMEvt
.IsRight() )
272 else if( (( SHOWWINDOWMODE_BLANK
== meShowWindowMode
) || ( SHOWWINDOWMODE_PAUSE
== meShowWindowMode
))
273 && !rMEvt
.IsRight() )
279 if( mxController
.is() )
280 mxController
->mouseButtonUp( rMEvt
);
284 /*************************************************************************
286 |* Paint-Event: wenn FuSlideShow noch erreichbar ist, weiterleiten
288 \************************************************************************/
290 void ShowWindow::Paint(const Rectangle
& rRect
)
292 if( (meShowWindowMode
== SHOWWINDOWMODE_NORMAL
) || (meShowWindowMode
== SHOWWINDOWMODE_PREVIEW
) )
295 Region aOldClipRegion( GetClipRegion() );
297 Region aClipRegion( rRect );
298 aClipRegion.Exclude( maPresArea );
299 SetClipRegion( aClipRegion );
301 DrawWallpaper( rRect, maShowBackground );
303 SetClipRegion( aOldClipRegion );
305 if( mxController
.is() )
307 mxController
->paint(rRect
);
309 else if(mpViewShell
)
311 mpViewShell
->Paint(rRect
, this);
316 DrawWallpaper( rRect
, maShowBackground
);
318 if( SHOWWINDOWMODE_END
== meShowWindowMode
)
322 else if( SHOWWINDOWMODE_PAUSE
== meShowWindowMode
)
324 DrawPauseScene( FALSE
);
326 else if( SHOWWINDOWMODE_BLANK
== meShowWindowMode
)
333 /*************************************************************************
337 \************************************************************************/
339 long ShowWindow::Notify(NotifyEvent
& rNEvt
)
343 if( mpViewShell && rNEvt.GetType() == EVENT_GETFOCUS )
345 NotifyEvent aNEvt(EVENT_GETFOCUS, this);
346 nOK = mpViewShell->GetViewFrame()->GetWindow().Notify(aNEvt);
350 nOK
= Window::Notify(rNEvt
);
356 // -----------------------------------------------------------------------------
358 void ShowWindow::GetFocus()
365 NotifyEvent aNEvt(EVENT_GETFOCUS, this);
366 mpViewShell->GetViewFrame()->GetWindow().Notify(aNEvt);
371 // -----------------------------------------------------------------------------
373 void ShowWindow::LoseFocus()
377 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
381 // -----------------------------------------------------------------------------
383 void ShowWindow::Resize()
385 ::sd::Window::Resize();
388 // -----------------------------------------------------------------------------
390 void ShowWindow::Move()
392 ::sd::Window::Move();
395 // -----------------------------------------------------------------------------
397 BOOL
ShowWindow::SetEndMode()
399 if( ( SHOWWINDOWMODE_NORMAL
== meShowWindowMode
) && mpViewShell
&& mpViewShell
->GetView() )
401 DeleteWindowFromPaintView();
402 meShowWindowMode
= SHOWWINDOWMODE_END
;
403 // maShowBackground = GetBackground();
404 // SetBackground( Wallpaper( Color( COL_BLACK ) ) );
405 maShowBackground
= Wallpaper( Color( COL_BLACK
) );
407 // hide navigator if it is visible
408 if( mpViewShell
->GetViewFrame()->GetChildWindow( SID_NAVIGATOR
) )
410 mpViewShell
->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR
, FALSE
);
411 mbShowNavigatorAfterSpecialMode
= TRUE
;
417 return( SHOWWINDOWMODE_END
== meShowWindowMode
);
420 // -----------------------------------------------------------------------------
422 BOOL
ShowWindow::SetPauseMode( sal_Int32 nPageIndexToRestart
, sal_Int32 nTimeout
, Graphic
* pLogo
)
424 rtl::Reference
< SlideShow
> xSlideShow
;
427 xSlideShow
= SlideShow::GetSlideShow( mpViewShell
->GetViewShellBase() );
429 if( xSlideShow
.is() && !nTimeout
)
431 xSlideShow
->jumpToPageIndex( nPageIndexToRestart
);
433 else if( ( SHOWWINDOWMODE_NORMAL
== meShowWindowMode
) && mpViewShell
&& mpViewShell
->GetView() )
435 DeleteWindowFromPaintView();
436 mnPauseTimeout
= nTimeout
;
437 mnRestartPageIndex
= nPageIndexToRestart
;
438 meShowWindowMode
= SHOWWINDOWMODE_PAUSE
;
439 // maShowBackground = GetBackground();
440 // SetBackground( Wallpaper( Color( COL_BLACK ) ) );
441 maShowBackground
= Wallpaper( Color( COL_BLACK
) );
443 // hide navigator if it is visible
444 if( mpViewShell
->GetViewFrame()->GetChildWindow( SID_NAVIGATOR
) )
446 mpViewShell
->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR
, FALSE
);
447 mbShowNavigatorAfterSpecialMode
= TRUE
;
455 if( SLIDE_NO_TIMEOUT
!= mnPauseTimeout
)
456 maPauseTimer
.Start();
459 return( SHOWWINDOWMODE_PAUSE
== meShowWindowMode
);
462 // -----------------------------------------------------------------------------
464 BOOL
ShowWindow::SetBlankMode( sal_Int32 nPageIndexToRestart
, const Color
& rBlankColor
)
466 if( ( SHOWWINDOWMODE_NORMAL
== meShowWindowMode
) && mpViewShell
&& mpViewShell
->GetView() )
468 DeleteWindowFromPaintView();
469 mnRestartPageIndex
= nPageIndexToRestart
;
470 meShowWindowMode
= SHOWWINDOWMODE_BLANK
;
471 // maShowBackground = GetBackground();
472 // SetBackground( Wallpaper( rBlankColor ) );
473 maShowBackground
= Wallpaper( rBlankColor
);
475 // hide navigator if it is visible
476 if( mpViewShell
->GetViewFrame()->GetChildWindow( SID_NAVIGATOR
) )
478 mpViewShell
->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR
, FALSE
);
479 mbShowNavigatorAfterSpecialMode
= TRUE
;
485 return( SHOWWINDOWMODE_BLANK
== meShowWindowMode
);
488 // -----------------------------------------------------------------------------
490 void ShowWindow::SetPreviewMode()
492 meShowWindowMode
= SHOWWINDOWMODE_PREVIEW
;
495 // -----------------------------------------------------------------------------
497 void ShowWindow::TerminateShow()
503 // SetBackground( maShowBackground );
504 maShowBackground
= Wallpaper( Color( COL_BLACK
) );
505 meShowWindowMode
= SHOWWINDOWMODE_NORMAL
;
506 mnPauseTimeout
= SLIDE_NO_TIMEOUT
;
511 if( mbShowNavigatorAfterSpecialMode
)
513 mpViewShell
->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR
, TRUE
);
514 mbShowNavigatorAfterSpecialMode
= FALSE
;
518 if( mxController
.is() )
519 mxController
->endPresentation();
521 mnRestartPageIndex
= PAGE_NO_END
;
524 // -----------------------------------------------------------------------------
526 void ShowWindow::RestartShow()
528 RestartShow( mnRestartPageIndex
);
531 // -----------------------------------------------------------------------------
533 void ShowWindow::RestartShow( sal_Int32 nPageIndexToRestart
)
536 ShowWindowMode eOldShowWindowMode
= meShowWindowMode
;
541 // SetBackground( maShowBackground );
542 maShowBackground
= Wallpaper( Color( COL_BLACK
) );
543 meShowWindowMode
= SHOWWINDOWMODE_NORMAL
;
544 mnPauseTimeout
= SLIDE_NO_TIMEOUT
;
548 rtl::Reference
< SlideShow
> xSlideShow( SlideShow::GetSlideShow( mpViewShell
->GetViewShellBase() ) );
550 if( xSlideShow
.is() )
552 AddWindowToPaintView();
554 if( SHOWWINDOWMODE_BLANK
== eOldShowWindowMode
)
556 xSlideShow
->pause(false);
561 xSlideShow
->jumpToPageIndex( nPageIndexToRestart
);
566 mnRestartPageIndex
= PAGE_NO_END
;
569 if( mbShowNavigatorAfterSpecialMode
)
571 mpViewShell
->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR
, TRUE
);
572 mbShowNavigatorAfterSpecialMode
= FALSE
;
576 // -----------------------------------------------------------------------------
578 void ShowWindow::DrawPauseScene( BOOL bTimeoutOnly
)
580 const MapMode
& rMap
= GetMapMode();
581 const Point
aOutOrg( PixelToLogic( Point() ) );
582 const Size
aOutSize( GetOutputSize() );
583 const Size
aTextSize( LogicToLogic( Size( 0, 14 ), MAP_POINT
, rMap
) );
584 const Size
aOffset( LogicToLogic( Size( 1000, 1000 ), MAP_100TH_MM
, rMap
) );
585 String
aText( SdResId( STR_PRES_PAUSE
) );
588 Font
aFont( GetSettings().GetStyleSettings().GetMenuFont() );
589 const Font
aOldFont( GetFont() );
591 aFont
.SetSize( aTextSize
);
592 aFont
.SetColor( COL_WHITE
);
593 aFont
.SetCharSet( aOldFont
.GetCharSet() );
594 aFont
.SetLanguage( aOldFont
.GetLanguage() );
596 if( !bTimeoutOnly
&& ( maLogo
.GetType() != GRAPHIC_NONE
) )
600 if( maLogo
.GetPrefMapMode() == MAP_PIXEL
)
601 aGrfSize
= PixelToLogic( maLogo
.GetPrefSize() );
603 aGrfSize
= LogicToLogic( maLogo
.GetPrefSize(), maLogo
.GetPrefMapMode(), rMap
);
605 const Point
aGrfPos( Max( aOutOrg
.X() + aOutSize
.Width() - aGrfSize
.Width() - aOffset
.Width(), aOutOrg
.X() ),
606 Max( aOutOrg
.Y() + aOutSize
.Height() - aGrfSize
.Height() - aOffset
.Height(), aOutOrg
.Y() ) );
608 if( maLogo
.IsAnimated() )
609 maLogo
.StartAnimation( this, aGrfPos
, aGrfSize
, (long) this );
611 maLogo
.Draw( this, aGrfPos
, aGrfSize
);
614 if( SLIDE_NO_TIMEOUT
!= mnPauseTimeout
)
616 MapMode
aVMap( rMap
);
617 VirtualDevice
aVDev( *this );
619 aVMap
.SetOrigin( Point() );
620 aVDev
.SetMapMode( aVMap
);
621 aVDev
.SetBackground( Wallpaper( Color( COL_BLACK
) ) );
623 // set font first, to determine real output height
624 aVDev
.SetFont( aFont
);
626 const Size
aVDevSize( aOutSize
.Width(), aVDev
.GetTextHeight() );
628 if( aVDev
.SetOutputSize( aVDevSize
) )
630 // Note: if performance gets an issue here, we can use NumberFormatter directly
631 SvtSysLocale aSysLocale
;
632 const LocaleDataWrapper
& aLocaleData
= aSysLocale
.GetLocaleData();
634 aText
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " ( " ));
635 aText
+= aLocaleData
.getDuration( Time( 0, 0, mnPauseTimeout
) );
636 aText
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " )" ));
637 aVDev
.DrawText( Point( aOffset
.Width(), 0 ), aText
);
638 DrawOutDev( Point( aOutOrg
.X(), aOffset
.Height() ), aVDevSize
, Point(), aVDevSize
, aVDev
);
646 DrawText( Point( aOutOrg
.X() + aOffset
.Width(), aOutOrg
.Y() + aOffset
.Height() ), aText
);
651 // -----------------------------------------------------------------------------
653 void ShowWindow::DrawEndScene()
655 const Font
aOldFont( GetFont() );
656 Font
aFont( GetSettings().GetStyleSettings().GetMenuFont() );
658 const Point
aOutOrg( PixelToLogic( Point() ) );
659 const Size
aTextSize( LogicToLogic( Size( 0, 14 ), MAP_POINT
, GetMapMode() ) );
660 const String
aText( SdResId( STR_PRES_SOFTEND
) );
662 aFont
.SetSize( aTextSize
);
663 aFont
.SetColor( COL_WHITE
);
664 aFont
.SetCharSet( aOldFont
.GetCharSet() );
665 aFont
.SetLanguage( aOldFont
.GetLanguage() );
667 DrawText( Point( aOutOrg
.X() + aTextSize
.Height(), aOutOrg
.Y() + aTextSize
.Height() ), aText
);
671 // -----------------------------------------------------------------------------
673 void ShowWindow::DrawBlankScene()
675 // just blank through background color => nothing to be done here
678 // -----------------------------------------------------------------------------
680 IMPL_LINK( ShowWindow
, PauseTimeoutHdl
, Timer
*, pTimer
)
682 if( !( --mnPauseTimeout
) )
686 DrawPauseScene( TRUE
);
693 IMPL_LINK( ShowWindow
, MouseTimeoutHdl
, Timer
*, EMPTYARG
)
695 if( mbMouseCursorHidden
)
697 // not enough mouse movements since first recording so
698 // cancle show mouse pointer for now
699 mnFirstMouseMove
= 0;
703 // mouse has been idle to long, hide pointer
704 ShowPointer( FALSE
);
705 mbMouseCursorHidden
= true;
710 IMPL_LINK( ShowWindow
, EventHdl
, VclWindowEvent
*, pEvent
)
712 if( mbMouseAutoHide
)
714 if (pEvent
->GetId() == VCLEVENT_WINDOW_SHOW
)
716 maMouseTimer
.SetTimeout( HIDE_MOUSE_TIMEOUT
);
717 maMouseTimer
.Start();
723 void ShowWindow::SetPresentationArea( const Rectangle
& rPresArea
)
725 maPresArea
= rPresArea
;
728 void ShowWindow::DeleteWindowFromPaintView()
730 if( mpViewShell
->GetView() )
731 mpViewShell
->GetView()->DeleteWindowFromPaintView( this );
733 USHORT nChild
= GetChildCount();
735 GetChild( nChild
)->Show( FALSE
);
738 void ShowWindow::AddWindowToPaintView()
740 if( mpViewShell
->GetView() )
741 mpViewShell
->GetView()->AddWindowToPaintView( this );
743 USHORT nChild
= GetChildCount();
745 GetChild( nChild
)->Show( TRUE
);
748 } // end of namespace sd