bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / slideshow / showwin.cxx
blob81b624d695dba352c732ebefd88c92003e31396d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
33 #include "helpids.h"
34 #include "strings.hrc"
35 #include <vcl/virdev.hxx>
37 using namespace ::com::sun::star;
39 namespace sd {
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)
54 , mnFirstMouseMove(0)
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);
65 SetMapMode(aMap);
67 // set HelpId
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!
78 GetParent()->Show();
79 AddEventListener( LINK( this, ShowWindow, EventHdl ) );
82 ShowWindow::~ShowWindow(void)
84 maPauseTimer.Stop();
85 maMouseTimer.Stop();
89 void ShowWindow::KeyInput(const KeyEvent& rKEvt)
91 bool bReturn = false;
93 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode )
95 TerminateShow();
96 bReturn = true;
98 else if( SHOWWINDOWMODE_END == meShowWindowMode )
100 const int nKeyCode = rKEvt.GetKeyCode().GetCode();
101 switch( nKeyCode )
103 case KEY_PAGEUP:
104 case KEY_LEFT:
105 case KEY_UP:
106 case KEY_P:
107 case KEY_HOME:
108 case KEY_END:
109 case awt::Key::CONTEXTMENU:
110 // these keys will be handled by the slide show even
111 // while in end mode
112 break;
113 default:
114 TerminateShow();
115 bReturn = true;
118 else if( SHOWWINDOWMODE_BLANK == meShowWindowMode )
120 RestartShow();
121 bReturn = true;
123 else if( SHOWWINDOWMODE_PAUSE == meShowWindowMode )
125 const int nKeyCode = rKEvt.GetKeyCode().GetCode();
126 switch( nKeyCode )
128 case KEY_ESCAPE:
129 TerminateShow();
130 bReturn = true;
131 break;
132 case KEY_PAGEUP:
133 case KEY_RIGHT:
134 case KEY_UP:
135 case KEY_P:
136 case KEY_HOME:
137 case KEY_END:
138 case awt::Key::CONTEXTMENU:
139 // these keys will be handled by the slide show even
140 // while in end mode
141 break;
142 default:
143 RestartShow();
144 bReturn = true;
145 break;
149 if( !bReturn )
151 if( mxController.is() )
152 bReturn = mxController->keyInput(rKEvt);
154 if( !bReturn )
156 if( mpViewShell )
158 mpViewShell->KeyInput(rKEvt,this);
160 else
162 Window::KeyInput(rKEvt);
167 if( mpViewShell )
168 mpViewShell->SetActiveWindow( this );
172 void ShowWindow::MouseButtonDown(const MouseEvent& /*rMEvt*/)
174 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode )
176 TerminateShow();
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();
205 else
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();
215 else
217 // current mousemove restarts the idle timer to hide the mouse
218 maMouseTimer.Start();
222 if( mpViewShell )
223 mpViewShell->SetActiveWindow( this );
227 void ShowWindow::MouseButtonUp(const MouseEvent& rMEvt)
229 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode )
231 TerminateShow();
233 else if( (SHOWWINDOWMODE_END == meShowWindowMode) && !rMEvt.IsRight() )
235 TerminateShow();
237 else if( (( SHOWWINDOWMODE_BLANK == meShowWindowMode ) || ( SHOWWINDOWMODE_PAUSE == meShowWindowMode ))
238 && !rMEvt.IsRight() )
240 RestartShow();
242 else
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);
265 else
267 DrawWallpaper( rRect, maShowBackground );
269 if( SHOWWINDOWMODE_END == meShowWindowMode )
271 DrawEndScene();
273 else if( SHOWWINDOWMODE_PAUSE == meShowWindowMode )
275 DrawPauseScene( false );
277 else if( SHOWWINDOWMODE_BLANK == meShowWindowMode )
279 DrawBlankScene();
285 long ShowWindow::Notify(NotifyEvent& rNEvt)
287 long nOK = sal_False;
288 if (!nOK)
289 nOK = Window::Notify(rNEvt);
291 return nOK;
295 // -----------------------------------------------------------------------------
297 void ShowWindow::GetFocus()
299 // base class
300 Window::GetFocus();
303 // -----------------------------------------------------------------------------
305 void ShowWindow::LoseFocus()
307 Window::LoseFocus();
309 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode)
310 TerminateShow();
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;
344 Invalidate();
347 return( SHOWWINDOWMODE_END == meShowWindowMode );
350 // -----------------------------------------------------------------------------
352 bool ShowWindow::SetPauseMode( sal_Int32 nPageIndexToRestart, sal_Int32 nTimeout, Graphic* pLogo )
354 rtl::Reference< SlideShow > xSlideShow;
356 if( mpViewShell )
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;
378 if( pLogo )
379 maLogo = *pLogo;
381 Invalidate();
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;
408 Invalidate();
411 return( SHOWWINDOWMODE_BLANK == meShowWindowMode );
414 // -----------------------------------------------------------------------------
416 void ShowWindow::SetPreviewMode()
418 meShowWindowMode = SHOWWINDOWMODE_PREVIEW;
421 // -----------------------------------------------------------------------------
423 void ShowWindow::TerminateShow()
425 maLogo.Clear();
426 maPauseTimer.Stop();
427 maMouseTimer.Stop();
428 Erase();
429 maShowBackground = Wallpaper( Color( COL_BLACK ) );
430 meShowWindowMode = SHOWWINDOWMODE_NORMAL;
431 mnPauseTimeout = SLIDE_NO_TIMEOUT;
433 if( mpViewShell )
435 // show navigator?
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;
463 maLogo.Clear();
464 maPauseTimer.Stop();
465 Erase();
466 maShowBackground = Wallpaper( Color( COL_BLACK ) );
467 meShowWindowMode = SHOWWINDOWMODE_NORMAL;
468 mnPauseTimeout = SLIDE_NO_TIMEOUT;
470 if( mpViewShell )
472 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( mpViewShell->GetViewShellBase() ) );
474 if( xSlideShow.is() )
476 AddWindowToPaintView();
478 if( SHOWWINDOWMODE_BLANK == eOldShowWindowMode )
480 xSlideShow->pause(false);
481 Invalidate();
483 else
485 xSlideShow->jumpToPageIndex( nPageIndexToRestart );
490 mnRestartPageIndex = PAGE_NO_END;
492 // show navigator?
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 ) );
510 bool bDrawn = false;
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 ) )
522 Size aGrfSize;
524 if( maLogo.GetPrefMapMode() == MAP_PIXEL )
525 aGrfSize = PixelToLogic( maLogo.GetPrefSize() );
526 else
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 );
534 else
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 );
563 bDrawn = true;
567 if( !bDrawn )
569 SetFont( aFont );
570 DrawText( Point( aOutOrg.X() + aOffset.Width(), aOutOrg.Y() + aOffset.Height() ), aText );
571 SetFont( aOldFont );
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() );
590 SetFont( aFont );
591 DrawText( Point( aOutOrg.X() + aTextSize.Height(), aOutOrg.Y() + aTextSize.Height() ), aText );
592 SetFont( aOldFont );
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 ) )
607 RestartShow();
608 else
610 DrawPauseScene( true );
611 pTimer->Start();
614 return 0L;
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;
625 else
627 // mouse has been idle to long, hide pointer
628 ShowPointer( sal_False );
629 mbMouseCursorHidden = true;
631 return 0L;
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();
644 return 0L;
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();
658 while( nChild-- )
659 GetChild( nChild )->Show( sal_False );
662 void ShowWindow::AddWindowToPaintView()
664 if( mpViewShell->GetView() )
665 mpViewShell->GetView()->AddWindowToPaintView( this );
667 sal_uInt16 nChild = GetChildCount();
668 while( nChild-- )
669 GetChild( nChild )->Show( sal_True );
672 } // end of namespace sd
674 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */