1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/awt/Key.hpp>
23 #include "showwindow.hxx"
25 #include <unotools/syslocale.hxx>
26 #include <sfx2/viewfrm.hxx>
29 #include "res_bmp.hrc"
30 #include "slideshow.hxx"
31 #include "ViewShellBase.hxx"
32 #include "sdresid.hxx"
34 #include "strings.hrc"
35 #include <vcl/virdev.hxx>
37 using namespace ::com::sun::star
;
41 static const sal_uLong HIDE_MOUSE_TIMEOUT
= 10000;
42 static const sal_uLong SHOW_MOUSE_TIMEOUT
= 1000;
44 // =============================================================================
46 ShowWindow::ShowWindow( const ::rtl::Reference
< SlideshowImpl
>& xController
, ::Window
* pParent
)
47 : ::sd::Window( pParent
)
48 , mnPauseTimeout( SLIDE_NO_TIMEOUT
)
49 , mnRestartPageIndex( PAGE_NO_END
)
50 , meShowWindowMode(SHOWWINDOWMODE_NORMAL
)
51 , mbShowNavigatorAfterSpecialMode( false )
52 , mbMouseAutoHide(true)
53 , mbMouseCursorHidden(false)
55 , mxController( xController
)
57 SetOutDevViewType( OUTDEV_VIEWTYPE_SLIDESHOW
);
59 // Do never mirror the preview window. This explicitly includes right
60 // to left writing environments.
61 EnableRTL (sal_False
);
63 MapMode
aMap(GetMapMode());
64 aMap
.SetMapUnit(MAP_100TH_MM
);
68 SetHelpId( HID_SD_WIN_PRESENTATION
);
69 SetUniqueId( HID_SD_WIN_PRESENTATION
);
71 maPauseTimer
.SetTimeoutHdl( LINK( this, ShowWindow
, PauseTimeoutHdl
) );
72 maPauseTimer
.SetTimeout( 1000 );
73 maMouseTimer
.SetTimeoutHdl( LINK( this, ShowWindow
, MouseTimeoutHdl
) );
74 maMouseTimer
.SetTimeout( HIDE_MOUSE_TIMEOUT
);
76 maShowBackground
= Wallpaper( Color( COL_BLACK
) );
77 SetBackground(); // avoids that VCL paints any background!
79 AddEventListener( LINK( this, ShowWindow
, EventHdl
) );
82 ShowWindow::~ShowWindow(void)
89 void ShowWindow::KeyInput(const KeyEvent
& rKEvt
)
93 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
98 else if( SHOWWINDOWMODE_END
== meShowWindowMode
)
100 const int nKeyCode
= rKEvt
.GetKeyCode().GetCode();
109 case awt::Key::CONTEXTMENU
:
110 // these keys will be handled by the slide show even
118 else if( SHOWWINDOWMODE_BLANK
== meShowWindowMode
)
123 else if( SHOWWINDOWMODE_PAUSE
== meShowWindowMode
)
125 const int nKeyCode
= rKEvt
.GetKeyCode().GetCode();
138 case awt::Key::CONTEXTMENU
:
139 // these keys will be handled by the slide show even
151 if( mxController
.is() )
152 bReturn
= mxController
->keyInput(rKEvt
);
158 mpViewShell
->KeyInput(rKEvt
,this);
162 Window::KeyInput(rKEvt
);
168 mpViewShell
->SetActiveWindow( this );
172 void ShowWindow::MouseButtonDown(const MouseEvent
& /*rMEvt*/)
174 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
178 else if( mpViewShell
)
180 mpViewShell
->SetActiveWindow( this );
185 void ShowWindow::MouseMove(const MouseEvent
& /*rMEvt*/)
187 if( mbMouseAutoHide
)
189 if( mbMouseCursorHidden
)
191 if( mnFirstMouseMove
)
193 // if this is not the first mouse move while hidden, see if
194 // enough time has pasted to show mouse pointer again
195 sal_uLong nTime
= Time::GetSystemTicks();
196 if( (nTime
- mnFirstMouseMove
) >= SHOW_MOUSE_TIMEOUT
)
198 ShowPointer( sal_True
);
199 mnFirstMouseMove
= 0;
200 mbMouseCursorHidden
= false;
201 maMouseTimer
.SetTimeout( HIDE_MOUSE_TIMEOUT
);
202 maMouseTimer
.Start();
207 // if this is the first mouse move, note current
208 // time and start idle timer to cancel show mouse pointer
209 // again if not enough mouse movement is measured
210 mnFirstMouseMove
= Time::GetSystemTicks();
211 maMouseTimer
.SetTimeout( 2*SHOW_MOUSE_TIMEOUT
);
212 maMouseTimer
.Start();
217 // current mousemove restarts the idle timer to hide the mouse
218 maMouseTimer
.Start();
223 mpViewShell
->SetActiveWindow( this );
227 void ShowWindow::MouseButtonUp(const MouseEvent
& rMEvt
)
229 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
233 else if( (SHOWWINDOWMODE_END
== meShowWindowMode
) && !rMEvt
.IsRight() )
237 else if( (( SHOWWINDOWMODE_BLANK
== meShowWindowMode
) || ( SHOWWINDOWMODE_PAUSE
== meShowWindowMode
))
238 && !rMEvt
.IsRight() )
244 if( mxController
.is() )
245 mxController
->mouseButtonUp( rMEvt
);
250 * if FuSlideShow is still available, forward it
252 void ShowWindow::Paint(const Rectangle
& rRect
)
254 if( (meShowWindowMode
== SHOWWINDOWMODE_NORMAL
) || (meShowWindowMode
== SHOWWINDOWMODE_PREVIEW
) )
256 if( mxController
.is() )
258 mxController
->paint(rRect
);
260 else if(mpViewShell
)
262 mpViewShell
->Paint(rRect
, this);
267 DrawWallpaper( rRect
, maShowBackground
);
269 if( SHOWWINDOWMODE_END
== meShowWindowMode
)
273 else if( SHOWWINDOWMODE_PAUSE
== meShowWindowMode
)
275 DrawPauseScene( false );
277 else if( SHOWWINDOWMODE_BLANK
== meShowWindowMode
)
285 long ShowWindow::Notify(NotifyEvent
& rNEvt
)
287 long nOK
= sal_False
;
289 nOK
= Window::Notify(rNEvt
);
295 // -----------------------------------------------------------------------------
297 void ShowWindow::GetFocus()
303 // -----------------------------------------------------------------------------
305 void ShowWindow::LoseFocus()
309 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
313 // -----------------------------------------------------------------------------
315 void ShowWindow::Resize()
317 ::sd::Window::Resize();
320 // -----------------------------------------------------------------------------
322 void ShowWindow::Move()
324 ::sd::Window::Move();
327 // -----------------------------------------------------------------------------
329 bool ShowWindow::SetEndMode()
331 if( ( SHOWWINDOWMODE_NORMAL
== meShowWindowMode
) && mpViewShell
&& mpViewShell
->GetView() )
333 DeleteWindowFromPaintView();
334 meShowWindowMode
= SHOWWINDOWMODE_END
;
335 maShowBackground
= Wallpaper( Color( COL_BLACK
) );
337 // hide navigator if it is visible
338 if( mpViewShell
->GetViewFrame()->GetChildWindow( SID_NAVIGATOR
) )
340 mpViewShell
->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR
, sal_False
);
341 mbShowNavigatorAfterSpecialMode
= true;
347 return( SHOWWINDOWMODE_END
== meShowWindowMode
);
350 // -----------------------------------------------------------------------------
352 bool ShowWindow::SetPauseMode( sal_Int32 nPageIndexToRestart
, sal_Int32 nTimeout
, Graphic
* pLogo
)
354 rtl::Reference
< SlideShow
> xSlideShow
;
357 xSlideShow
= SlideShow::GetSlideShow( mpViewShell
->GetViewShellBase() );
359 if( xSlideShow
.is() && !nTimeout
)
361 xSlideShow
->jumpToPageIndex( nPageIndexToRestart
);
363 else if( ( SHOWWINDOWMODE_NORMAL
== meShowWindowMode
) && mpViewShell
&& mpViewShell
->GetView() )
365 DeleteWindowFromPaintView();
366 mnPauseTimeout
= nTimeout
;
367 mnRestartPageIndex
= nPageIndexToRestart
;
368 meShowWindowMode
= SHOWWINDOWMODE_PAUSE
;
369 maShowBackground
= Wallpaper( Color( COL_BLACK
) );
371 // hide navigator if it is visible
372 if( mpViewShell
->GetViewFrame()->GetChildWindow( SID_NAVIGATOR
) )
374 mpViewShell
->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR
, sal_False
);
375 mbShowNavigatorAfterSpecialMode
= true;
383 if( SLIDE_NO_TIMEOUT
!= mnPauseTimeout
)
384 maPauseTimer
.Start();
387 return( SHOWWINDOWMODE_PAUSE
== meShowWindowMode
);
390 // -----------------------------------------------------------------------------
392 bool ShowWindow::SetBlankMode( sal_Int32 nPageIndexToRestart
, const Color
& rBlankColor
)
394 if( ( SHOWWINDOWMODE_NORMAL
== meShowWindowMode
) && mpViewShell
&& mpViewShell
->GetView() )
396 DeleteWindowFromPaintView();
397 mnRestartPageIndex
= nPageIndexToRestart
;
398 meShowWindowMode
= SHOWWINDOWMODE_BLANK
;
399 maShowBackground
= Wallpaper( rBlankColor
);
401 // hide navigator if it is visible
402 if( mpViewShell
->GetViewFrame()->GetChildWindow( SID_NAVIGATOR
) )
404 mpViewShell
->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR
, sal_False
);
405 mbShowNavigatorAfterSpecialMode
= true;
411 return( SHOWWINDOWMODE_BLANK
== meShowWindowMode
);
414 // -----------------------------------------------------------------------------
416 void ShowWindow::SetPreviewMode()
418 meShowWindowMode
= SHOWWINDOWMODE_PREVIEW
;
421 // -----------------------------------------------------------------------------
423 void ShowWindow::TerminateShow()
429 maShowBackground
= Wallpaper( Color( COL_BLACK
) );
430 meShowWindowMode
= SHOWWINDOWMODE_NORMAL
;
431 mnPauseTimeout
= SLIDE_NO_TIMEOUT
;
436 if( mbShowNavigatorAfterSpecialMode
)
438 mpViewShell
->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR
, sal_True
);
439 mbShowNavigatorAfterSpecialMode
= false;
443 if( mxController
.is() )
444 mxController
->endPresentation();
446 mnRestartPageIndex
= PAGE_NO_END
;
449 // -----------------------------------------------------------------------------
451 void ShowWindow::RestartShow()
453 RestartShow( mnRestartPageIndex
);
456 // -----------------------------------------------------------------------------
458 void ShowWindow::RestartShow( sal_Int32 nPageIndexToRestart
)
461 ShowWindowMode eOldShowWindowMode
= meShowWindowMode
;
466 maShowBackground
= Wallpaper( Color( COL_BLACK
) );
467 meShowWindowMode
= SHOWWINDOWMODE_NORMAL
;
468 mnPauseTimeout
= SLIDE_NO_TIMEOUT
;
472 rtl::Reference
< SlideShow
> xSlideShow( SlideShow::GetSlideShow( mpViewShell
->GetViewShellBase() ) );
474 if( xSlideShow
.is() )
476 AddWindowToPaintView();
478 if( SHOWWINDOWMODE_BLANK
== eOldShowWindowMode
)
480 xSlideShow
->pause(false);
485 xSlideShow
->jumpToPageIndex( nPageIndexToRestart
);
490 mnRestartPageIndex
= PAGE_NO_END
;
493 if( mbShowNavigatorAfterSpecialMode
)
495 mpViewShell
->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR
, sal_True
);
496 mbShowNavigatorAfterSpecialMode
= false;
500 // -----------------------------------------------------------------------------
502 void ShowWindow::DrawPauseScene( bool bTimeoutOnly
)
504 const MapMode
& rMap
= GetMapMode();
505 const Point
aOutOrg( PixelToLogic( Point() ) );
506 const Size
aOutSize( GetOutputSize() );
507 const Size
aTextSize( LogicToLogic( Size( 0, 14 ), MAP_POINT
, rMap
) );
508 const Size
aOffset( LogicToLogic( Size( 1000, 1000 ), MAP_100TH_MM
, rMap
) );
509 String
aText( SdResId( STR_PRES_PAUSE
) );
512 Font
aFont( GetSettings().GetStyleSettings().GetMenuFont() );
513 const Font
aOldFont( GetFont() );
515 aFont
.SetSize( aTextSize
);
516 aFont
.SetColor( COL_WHITE
);
517 aFont
.SetCharSet( aOldFont
.GetCharSet() );
518 aFont
.SetLanguage( aOldFont
.GetLanguage() );
520 if( !bTimeoutOnly
&& ( maLogo
.GetType() != GRAPHIC_NONE
) )
524 if( maLogo
.GetPrefMapMode() == MAP_PIXEL
)
525 aGrfSize
= PixelToLogic( maLogo
.GetPrefSize() );
527 aGrfSize
= LogicToLogic( maLogo
.GetPrefSize(), maLogo
.GetPrefMapMode(), rMap
);
529 const Point
aGrfPos( std::max( aOutOrg
.X() + aOutSize
.Width() - aGrfSize
.Width() - aOffset
.Width(), aOutOrg
.X() ),
530 std::max( aOutOrg
.Y() + aOutSize
.Height() - aGrfSize
.Height() - aOffset
.Height(), aOutOrg
.Y() ) );
532 if( maLogo
.IsAnimated() )
533 maLogo
.StartAnimation( this, aGrfPos
, aGrfSize
, (long) this );
535 maLogo
.Draw( this, aGrfPos
, aGrfSize
);
538 if( SLIDE_NO_TIMEOUT
!= mnPauseTimeout
)
540 MapMode
aVMap( rMap
);
541 VirtualDevice
aVDev( *this );
543 aVMap
.SetOrigin( Point() );
544 aVDev
.SetMapMode( aVMap
);
545 aVDev
.SetBackground( Wallpaper( Color( COL_BLACK
) ) );
547 // set font first, to determine real output height
548 aVDev
.SetFont( aFont
);
550 const Size
aVDevSize( aOutSize
.Width(), aVDev
.GetTextHeight() );
552 if( aVDev
.SetOutputSize( aVDevSize
) )
554 // Note: if performance gets an issue here, we can use NumberFormatter directly
555 SvtSysLocale aSysLocale
;
556 const LocaleDataWrapper
& aLocaleData
= aSysLocale
.GetLocaleData();
558 aText
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " ( " ));
559 aText
+= aLocaleData
.getDuration( Time( 0, 0, mnPauseTimeout
) );
560 aText
.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " )" ));
561 aVDev
.DrawText( Point( aOffset
.Width(), 0 ), aText
);
562 DrawOutDev( Point( aOutOrg
.X(), aOffset
.Height() ), aVDevSize
, Point(), aVDevSize
, aVDev
);
570 DrawText( Point( aOutOrg
.X() + aOffset
.Width(), aOutOrg
.Y() + aOffset
.Height() ), aText
);
575 // -----------------------------------------------------------------------------
577 void ShowWindow::DrawEndScene()
579 const Font
aOldFont( GetFont() );
580 Font
aFont( GetSettings().GetStyleSettings().GetMenuFont() );
582 const Point
aOutOrg( PixelToLogic( Point() ) );
583 const Size
aTextSize( LogicToLogic( Size( 0, 14 ), MAP_POINT
, GetMapMode() ) );
584 const String
aText( SdResId( STR_PRES_SOFTEND
) );
586 aFont
.SetSize( aTextSize
);
587 aFont
.SetColor( COL_WHITE
);
588 aFont
.SetCharSet( aOldFont
.GetCharSet() );
589 aFont
.SetLanguage( aOldFont
.GetLanguage() );
591 DrawText( Point( aOutOrg
.X() + aTextSize
.Height(), aOutOrg
.Y() + aTextSize
.Height() ), aText
);
595 // -----------------------------------------------------------------------------
597 void ShowWindow::DrawBlankScene()
599 // just blank through background color => nothing to be done here
602 // -----------------------------------------------------------------------------
604 IMPL_LINK( ShowWindow
, PauseTimeoutHdl
, Timer
*, pTimer
)
606 if( !( --mnPauseTimeout
) )
610 DrawPauseScene( true );
617 IMPL_LINK_NOARG(ShowWindow
, MouseTimeoutHdl
)
619 if( mbMouseCursorHidden
)
621 // not enough mouse movements since first recording so
622 // cancel show mouse pointer for now
623 mnFirstMouseMove
= 0;
627 // mouse has been idle to long, hide pointer
628 ShowPointer( sal_False
);
629 mbMouseCursorHidden
= true;
634 IMPL_LINK( ShowWindow
, EventHdl
, VclWindowEvent
*, pEvent
)
636 if( mbMouseAutoHide
)
638 if (pEvent
->GetId() == VCLEVENT_WINDOW_SHOW
)
640 maMouseTimer
.SetTimeout( HIDE_MOUSE_TIMEOUT
);
641 maMouseTimer
.Start();
647 void ShowWindow::SetPresentationArea( const Rectangle
& rPresArea
)
649 maPresArea
= rPresArea
;
652 void ShowWindow::DeleteWindowFromPaintView()
654 if( mpViewShell
->GetView() )
655 mpViewShell
->GetView()->DeleteWindowFromPaintView( this );
657 sal_uInt16 nChild
= GetChildCount();
659 GetChild( nChild
)->Show( sal_False
);
662 void ShowWindow::AddWindowToPaintView()
664 if( mpViewShell
->GetView() )
665 mpViewShell
->GetView()->AddWindowToPaintView( this );
667 sal_uInt16 nChild
= GetChildCount();
669 GetChild( nChild
)->Show( sal_True
);
672 } // end of namespace sd
674 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */