bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / slideshow / showwin.cxx
bloba0c3745d0c8a2983d644c6407ecc9f4b303aeff6
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 .
20 #include <com/sun/star/awt/Key.hpp>
22 #include "showwindow.hxx"
24 #include <unotools/syslocale.hxx>
25 #include <sfx2/viewfrm.hxx>
27 #include "res_bmp.hrc"
28 #include "slideshow.hxx"
29 #include "ViewShellBase.hxx"
30 #include "sdresid.hxx"
31 #include "helpids.h"
32 #include "strings.hrc"
34 #include <vcl/settings.hxx>
35 #include <vcl/virdev.hxx>
37 using namespace ::com::sun::star;
39 namespace sd {
41 static const sal_uInt64 HIDE_MOUSE_TIMEOUT = 10000;
42 static const sal_uInt64 SHOW_MOUSE_TIMEOUT = 1000;
44 ShowWindow::ShowWindow( const ::rtl::Reference< SlideshowImpl >& xController, vcl::Window* pParent )
45 : ::sd::Window( pParent )
46 , mnPauseTimeout( SLIDE_NO_TIMEOUT )
47 , mnRestartPageIndex( PAGE_NO_END )
48 , meShowWindowMode(SHOWWINDOWMODE_NORMAL)
49 , mbShowNavigatorAfterSpecialMode( false )
50 , mbMouseAutoHide(true)
51 , mbMouseCursorHidden(false)
52 , mnFirstMouseMove(0)
53 , mxController( xController )
55 SetOutDevViewType( OUTDEV_VIEWTYPE_SLIDESHOW );
57 // Do never mirror the preview window. This explicitly includes right
58 // to left writing environments.
59 EnableRTL (false);
61 MapMode aMap(GetMapMode());
62 aMap.SetMapUnit(MAP_100TH_MM);
63 SetMapMode(aMap);
65 // set HelpId
66 SetHelpId( HID_SD_WIN_PRESENTATION );
67 SetUniqueId( HID_SD_WIN_PRESENTATION );
69 maPauseTimer.SetTimeoutHdl( LINK( this, ShowWindow, PauseTimeoutHdl ) );
70 maPauseTimer.SetTimeout( 1000 );
71 maMouseTimer.SetTimeoutHdl( LINK( this, ShowWindow, MouseTimeoutHdl ) );
72 maMouseTimer.SetTimeout( HIDE_MOUSE_TIMEOUT );
74 maShowBackground = Wallpaper( Color( COL_BLACK ) );
75 SetBackground(); // avoids that VCL paints any background!
76 GetParent()->Show();
77 AddEventListener( LINK( this, ShowWindow, EventHdl ) );
80 ShowWindow::~ShowWindow()
82 disposeOnce();
85 void ShowWindow::dispose()
87 maPauseTimer.Stop();
88 maMouseTimer.Stop();
89 ::sd::Window::dispose();
92 void ShowWindow::KeyInput(const KeyEvent& rKEvt)
94 bool bReturn = false;
96 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode )
98 TerminateShow();
99 bReturn = true;
101 else if( SHOWWINDOWMODE_END == meShowWindowMode )
103 const int nKeyCode = rKEvt.GetKeyCode().GetCode();
104 switch( nKeyCode )
106 case KEY_PAGEUP:
107 case KEY_LEFT:
108 case KEY_UP:
109 case KEY_P:
110 case KEY_HOME:
111 case KEY_END:
112 case awt::Key::CONTEXTMENU:
113 // these keys will be handled by the slide show even
114 // while in end mode
115 break;
116 default:
117 TerminateShow();
118 bReturn = true;
121 else if( SHOWWINDOWMODE_BLANK == meShowWindowMode )
123 RestartShow();
124 bReturn = true;
126 else if( SHOWWINDOWMODE_PAUSE == meShowWindowMode )
128 const int nKeyCode = rKEvt.GetKeyCode().GetCode();
129 switch( nKeyCode )
131 case KEY_ESCAPE:
132 TerminateShow();
133 bReturn = true;
134 break;
135 case KEY_PAGEUP:
136 case KEY_RIGHT:
137 case KEY_UP:
138 case KEY_P:
139 case KEY_HOME:
140 case KEY_END:
141 case awt::Key::CONTEXTMENU:
142 // these keys will be handled by the slide show even
143 // while in end mode
144 break;
145 default:
146 RestartShow();
147 bReturn = true;
148 break;
152 if( !bReturn )
154 if( mxController.is() )
155 bReturn = mxController->keyInput(rKEvt);
157 if( !bReturn )
159 if( mpViewShell )
161 mpViewShell->KeyInput(rKEvt,this);
163 else
165 Window::KeyInput(rKEvt);
170 if( mpViewShell )
171 mpViewShell->SetActiveWindow( this );
174 void ShowWindow::MouseButtonDown(const MouseEvent& /*rMEvt*/)
176 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode )
178 TerminateShow();
180 else if( mpViewShell )
182 mpViewShell->SetActiveWindow( this );
186 void ShowWindow::MouseMove(const MouseEvent& /*rMEvt*/)
188 if( mbMouseAutoHide )
190 if( mbMouseCursorHidden )
192 if( mnFirstMouseMove )
194 // if this is not the first mouse move while hidden, see if
195 // enough time has pasted to show mouse pointer again
196 sal_uInt64 nTime = ::tools::Time::GetSystemTicks();
197 if( (nTime - mnFirstMouseMove) >= SHOW_MOUSE_TIMEOUT )
199 ShowPointer( true );
200 mnFirstMouseMove = 0;
201 mbMouseCursorHidden = false;
202 maMouseTimer.SetTimeout( HIDE_MOUSE_TIMEOUT );
203 maMouseTimer.Start();
206 else
208 // if this is the first mouse move, note current
209 // time and start idle timer to cancel show mouse pointer
210 // again if not enough mouse movement is measured
211 mnFirstMouseMove = ::tools::Time::GetSystemTicks();
212 maMouseTimer.SetTimeout( 2*SHOW_MOUSE_TIMEOUT );
213 maMouseTimer.Start();
216 else
218 // current mousemove restarts the idle timer to hide the mouse
219 maMouseTimer.Start();
223 if( mpViewShell )
224 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(vcl::RenderContext& /*rRenderContext*/, 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 // just blank through background color => nothing to be done here
284 void ShowWindow::GetFocus()
286 // base class
287 Window::GetFocus();
290 void ShowWindow::LoseFocus()
292 Window::LoseFocus();
294 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode)
295 TerminateShow();
298 void ShowWindow::Resize()
300 ::sd::Window::Resize();
303 void ShowWindow::Move()
305 ::sd::Window::Move();
308 bool ShowWindow::SetEndMode()
310 if( ( SHOWWINDOWMODE_NORMAL == meShowWindowMode ) && mpViewShell && mpViewShell->GetView() )
312 DeleteWindowFromPaintView();
313 meShowWindowMode = SHOWWINDOWMODE_END;
314 maShowBackground = Wallpaper( Color( COL_BLACK ) );
316 // hide navigator if it is visible
317 if( mpViewShell->GetViewFrame()->GetChildWindow( SID_NAVIGATOR ) )
319 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, false );
320 mbShowNavigatorAfterSpecialMode = true;
323 Invalidate();
326 return( SHOWWINDOWMODE_END == meShowWindowMode );
329 bool ShowWindow::SetPauseMode( sal_Int32 nPageIndexToRestart, sal_Int32 nTimeout, Graphic* pLogo )
331 rtl::Reference< SlideShow > xSlideShow;
333 if( mpViewShell )
334 xSlideShow = SlideShow::GetSlideShow( mpViewShell->GetViewShellBase() );
336 if( xSlideShow.is() && !nTimeout )
338 xSlideShow->jumpToPageIndex( nPageIndexToRestart );
340 else if( ( SHOWWINDOWMODE_NORMAL == meShowWindowMode ) && mpViewShell && mpViewShell->GetView() )
342 DeleteWindowFromPaintView();
343 mnPauseTimeout = nTimeout;
344 mnRestartPageIndex = nPageIndexToRestart;
345 meShowWindowMode = SHOWWINDOWMODE_PAUSE;
346 maShowBackground = Wallpaper( Color( COL_BLACK ) );
348 // hide navigator if it is visible
349 if( mpViewShell->GetViewFrame()->GetChildWindow( SID_NAVIGATOR ) )
351 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, false );
352 mbShowNavigatorAfterSpecialMode = true;
355 if( pLogo )
356 maLogo = *pLogo;
358 Invalidate();
360 if( SLIDE_NO_TIMEOUT != mnPauseTimeout )
361 maPauseTimer.Start();
364 return( SHOWWINDOWMODE_PAUSE == meShowWindowMode );
367 bool ShowWindow::SetBlankMode( sal_Int32 nPageIndexToRestart, const Color& rBlankColor )
369 if( ( SHOWWINDOWMODE_NORMAL == meShowWindowMode ) && mpViewShell && mpViewShell->GetView() )
371 DeleteWindowFromPaintView();
372 mnRestartPageIndex = nPageIndexToRestart;
373 meShowWindowMode = SHOWWINDOWMODE_BLANK;
374 maShowBackground = Wallpaper( rBlankColor );
376 // hide navigator if it is visible
377 if( mpViewShell->GetViewFrame()->GetChildWindow( SID_NAVIGATOR ) )
379 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, false );
380 mbShowNavigatorAfterSpecialMode = true;
383 Invalidate();
386 return( SHOWWINDOWMODE_BLANK == meShowWindowMode );
389 void ShowWindow::SetPreviewMode()
391 meShowWindowMode = SHOWWINDOWMODE_PREVIEW;
394 void ShowWindow::TerminateShow()
396 maLogo.Clear();
397 maPauseTimer.Stop();
398 maMouseTimer.Stop();
399 Erase();
400 maShowBackground = Wallpaper( Color( COL_BLACK ) );
401 meShowWindowMode = SHOWWINDOWMODE_NORMAL;
402 mnPauseTimeout = SLIDE_NO_TIMEOUT;
404 if( mpViewShell )
406 // show navigator?
407 if( mbShowNavigatorAfterSpecialMode )
409 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, true );
410 mbShowNavigatorAfterSpecialMode = false;
414 if( mxController.is() )
415 mxController->endPresentation();
417 mnRestartPageIndex = PAGE_NO_END;
420 void ShowWindow::RestartShow()
422 RestartShow( mnRestartPageIndex );
425 void ShowWindow::RestartShow( sal_Int32 nPageIndexToRestart )
428 ShowWindowMode eOldShowWindowMode = meShowWindowMode;
430 maLogo.Clear();
431 maPauseTimer.Stop();
432 Erase();
433 maShowBackground = Wallpaper( Color( COL_BLACK ) );
434 meShowWindowMode = SHOWWINDOWMODE_NORMAL;
435 mnPauseTimeout = SLIDE_NO_TIMEOUT;
437 if( mpViewShell )
439 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( mpViewShell->GetViewShellBase() ) );
441 if( xSlideShow.is() )
443 AddWindowToPaintView();
445 if( SHOWWINDOWMODE_BLANK == eOldShowWindowMode )
447 xSlideShow->pause(false);
448 Invalidate();
450 else
452 xSlideShow->jumpToPageIndex( nPageIndexToRestart );
457 mnRestartPageIndex = PAGE_NO_END;
459 // show navigator?
460 if( mbShowNavigatorAfterSpecialMode )
462 if (mpViewShell)
463 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, true );
464 mbShowNavigatorAfterSpecialMode = false;
468 void ShowWindow::DrawPauseScene( bool bTimeoutOnly )
470 const MapMode& rMap = GetMapMode();
471 const Point aOutOrg( PixelToLogic( Point() ) );
472 const Size aOutSize( GetOutputSize() );
473 const Size aTextSize( LogicToLogic( Size( 0, 14 ), MAP_POINT, rMap ) );
474 const Size aOffset( LogicToLogic( Size( 1000, 1000 ), MAP_100TH_MM, rMap ) );
475 OUString aText( SdResId( STR_PRES_PAUSE ) );
476 bool bDrawn = false;
478 vcl::Font aFont( GetSettings().GetStyleSettings().GetMenuFont() );
479 const vcl::Font aOldFont( GetFont() );
481 aFont.SetSize( aTextSize );
482 aFont.SetColor( COL_WHITE );
483 aFont.SetCharSet( aOldFont.GetCharSet() );
484 aFont.SetLanguage( aOldFont.GetLanguage() );
486 if( !bTimeoutOnly && ( maLogo.GetType() != GRAPHIC_NONE ) )
488 Size aGrfSize;
490 if( maLogo.GetPrefMapMode() == MAP_PIXEL )
491 aGrfSize = PixelToLogic( maLogo.GetPrefSize() );
492 else
493 aGrfSize = LogicToLogic( maLogo.GetPrefSize(), maLogo.GetPrefMapMode(), rMap );
495 const Point aGrfPos( std::max( aOutOrg.X() + aOutSize.Width() - aGrfSize.Width() - aOffset.Width(), aOutOrg.X() ),
496 std::max( aOutOrg.Y() + aOutSize.Height() - aGrfSize.Height() - aOffset.Height(), aOutOrg.Y() ) );
498 if( maLogo.IsAnimated() )
499 maLogo.StartAnimation( this, aGrfPos, aGrfSize, reinterpret_cast<sal_IntPtr>(this) );
500 else
501 maLogo.Draw( this, aGrfPos, aGrfSize );
504 if( SLIDE_NO_TIMEOUT != mnPauseTimeout )
506 MapMode aVMap( rMap );
507 ScopedVclPtrInstance< VirtualDevice > pVDev( *this );
509 aVMap.SetOrigin( Point() );
510 pVDev->SetMapMode( aVMap );
511 pVDev->SetBackground( Wallpaper( Color( COL_BLACK ) ) );
513 // set font first, to determine real output height
514 pVDev->SetFont( aFont );
516 const Size aVDevSize( aOutSize.Width(), pVDev->GetTextHeight() );
518 if( pVDev->SetOutputSize( aVDevSize ) )
520 // Note: if performance gets an issue here, we can use NumberFormatter directly
521 SvtSysLocale aSysLocale;
522 const LocaleDataWrapper& aLocaleData = aSysLocale.GetLocaleData();
524 aText += " ( ";
525 aText += aLocaleData.getDuration( ::tools::Time( 0, 0, mnPauseTimeout ) );
526 aText += " )";
527 pVDev->DrawText( Point( aOffset.Width(), 0 ), aText );
528 DrawOutDev( Point( aOutOrg.X(), aOffset.Height() ), aVDevSize, Point(), aVDevSize, *pVDev.get() );
529 bDrawn = true;
533 if( !bDrawn )
535 SetFont( aFont );
536 DrawText( Point( aOutOrg.X() + aOffset.Width(), aOutOrg.Y() + aOffset.Height() ), aText );
537 SetFont( aOldFont );
541 void ShowWindow::DrawEndScene()
543 const vcl::Font aOldFont( GetFont() );
544 vcl::Font aFont( GetSettings().GetStyleSettings().GetMenuFont() );
546 const Point aOutOrg( PixelToLogic( Point() ) );
547 const Size aTextSize( LogicToLogic( Size( 0, 14 ), MAP_POINT, GetMapMode() ) );
548 const OUString aText( SdResId( STR_PRES_SOFTEND ) );
550 aFont.SetSize( aTextSize );
551 aFont.SetColor( COL_WHITE );
552 aFont.SetCharSet( aOldFont.GetCharSet() );
553 aFont.SetLanguage( aOldFont.GetLanguage() );
554 SetFont( aFont );
555 DrawText( Point( aOutOrg.X() + aTextSize.Height(), aOutOrg.Y() + aTextSize.Height() ), aText );
556 SetFont( aOldFont );
559 IMPL_LINK_TYPED( ShowWindow, PauseTimeoutHdl, Timer*, pTimer, void )
561 if( !( --mnPauseTimeout ) )
562 RestartShow();
563 else
565 DrawPauseScene( true );
566 pTimer->Start();
570 IMPL_LINK_NOARG_TYPED(ShowWindow, MouseTimeoutHdl, Timer *, void)
572 if( mbMouseCursorHidden )
574 // not enough mouse movements since first recording so
575 // cancel show mouse pointer for now
576 mnFirstMouseMove = 0;
578 else
580 // mouse has been idle to long, hide pointer
581 ShowPointer( false );
582 mbMouseCursorHidden = true;
586 IMPL_LINK( ShowWindow, EventHdl, VclWindowEvent*, pEvent )
588 if( mbMouseAutoHide )
590 if (pEvent->GetId() == VCLEVENT_WINDOW_SHOW)
592 maMouseTimer.SetTimeout( HIDE_MOUSE_TIMEOUT );
593 maMouseTimer.Start();
596 return 0L;
599 void ShowWindow::SetPresentationArea( const Rectangle& rPresArea )
601 maPresArea = rPresArea;
604 void ShowWindow::DeleteWindowFromPaintView()
606 if( mpViewShell->GetView() )
607 mpViewShell->GetView()->DeleteWindowFromPaintView( this );
609 sal_uInt16 nChild = GetChildCount();
610 while( nChild-- )
611 GetChild( nChild )->Show( false );
614 void ShowWindow::AddWindowToPaintView()
616 if( mpViewShell->GetView() )
617 mpViewShell->GetView()->AddWindowToPaintView( this, 0 );
619 sal_uInt16 nChild = GetChildCount();
620 while( nChild-- )
621 GetChild( nChild )->Show( true );
624 // Override the sd::Window's CreateAccessible to create a different accessible object
625 ::com::sun::star::uno::Reference<
626 ::com::sun::star::accessibility::XAccessible>
627 ShowWindow::CreateAccessible()
629 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAcc = GetAccessible(false);
630 if (xAcc.get())
632 return xAcc;
634 if (mpViewShell != NULL)
636 xAcc = mpViewShell->CreateAccessibleDocumentView (this);
637 SetAccessible(xAcc);
638 return xAcc;
640 else
642 OSL_TRACE ("::sd::Window::CreateAccessible: no view shell");
643 return vcl::Window::CreateAccessible ();
646 } // end of namespace sd
648 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */