bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / slideshow / showwin.cxx
blob564e23f1e8449fd3104db0980683aef49eea5caf
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"
23 #include "slideshowimpl.hxx"
25 #include <unotools/localedatawrapper.hxx>
26 #include <unotools/syslocale.hxx>
27 #include <sfx2/viewfrm.hxx>
28 #include <sfx2/sfxsids.hrc>
31 #include <slideshow.hxx>
32 #include <ViewShell.hxx>
33 #include <ViewShellBase.hxx>
34 #include <sdresid.hxx>
35 #include <helpids.h>
36 #include <strings.hrc>
38 #include <sal/log.hxx>
39 #include <vcl/settings.hxx>
40 #include <vcl/virdev.hxx>
42 using namespace ::com::sun::star;
44 namespace sd {
46 static const sal_uInt64 HIDE_MOUSE_TIMEOUT = 10000;
47 static const sal_uInt64 SHOW_MOUSE_TIMEOUT = 1000;
49 ShowWindow::ShowWindow( const ::rtl::Reference< SlideshowImpl >& xController, vcl::Window* pParent )
50 : ::sd::Window( pParent )
51 , mnPauseTimeout( SLIDE_NO_TIMEOUT )
52 , mnRestartPageIndex( PAGE_NO_END )
53 , meShowWindowMode(SHOWWINDOWMODE_NORMAL)
54 , mbShowNavigatorAfterSpecialMode( false )
55 , mbMouseAutoHide(true)
56 , mbMouseCursorHidden(false)
57 , mnFirstMouseMove(0)
58 , mxController( xController )
60 SetOutDevViewType( OutDevViewType::SlideShow );
62 // Do never mirror the preview window. This explicitly includes right
63 // to left writing environments.
64 EnableRTL (false);
66 MapMode aMap(GetMapMode());
67 aMap.SetMapUnit(MapUnit::Map100thMM);
68 SetMapMode(aMap);
70 // set HelpId
71 SetHelpId( HID_SD_WIN_PRESENTATION );
73 maPauseTimer.SetInvokeHandler( LINK( this, ShowWindow, PauseTimeoutHdl ) );
74 maPauseTimer.SetTimeout( 1000 );
75 maMouseTimer.SetInvokeHandler( LINK( this, ShowWindow, MouseTimeoutHdl ) );
76 maMouseTimer.SetTimeout( HIDE_MOUSE_TIMEOUT );
78 maShowBackground = Wallpaper( COL_BLACK );
79 SetBackground(); // avoids that VCL paints any background!
80 GetParent()->Show();
81 AddEventListener( LINK( this, ShowWindow, EventHdl ) );
84 ShowWindow::~ShowWindow()
86 disposeOnce();
89 void ShowWindow::dispose()
91 maPauseTimer.Stop();
92 maMouseTimer.Stop();
93 ::sd::Window::dispose();
96 void ShowWindow::KeyInput(const KeyEvent& rKEvt)
98 bool bReturn = false;
100 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode )
102 TerminateShow();
103 bReturn = true;
105 else if( SHOWWINDOWMODE_END == meShowWindowMode )
107 const int nKeyCode = rKEvt.GetKeyCode().GetCode();
108 switch( nKeyCode )
110 case KEY_PAGEUP:
111 case KEY_LEFT:
112 case KEY_UP:
113 case KEY_P:
114 case KEY_HOME:
115 case KEY_END:
116 case awt::Key::CONTEXTMENU:
117 // these keys will be handled by the slide show even
118 // while in end mode
119 break;
120 default:
121 TerminateShow();
122 bReturn = true;
125 else if( SHOWWINDOWMODE_BLANK == meShowWindowMode )
127 RestartShow();
128 bReturn = true;
130 else if( SHOWWINDOWMODE_PAUSE == meShowWindowMode )
132 const int nKeyCode = rKEvt.GetKeyCode().GetCode();
133 switch( nKeyCode )
135 case KEY_ESCAPE:
136 TerminateShow();
137 bReturn = true;
138 break;
139 case KEY_PAGEUP:
140 case KEY_RIGHT:
141 case KEY_UP:
142 case KEY_P:
143 case KEY_HOME:
144 case KEY_END:
145 case awt::Key::CONTEXTMENU:
146 // these keys will be handled by the slide show even
147 // while in end mode
148 break;
149 default:
150 RestartShow();
151 bReturn = true;
152 break;
156 if( !bReturn )
158 if( mxController.is() )
159 bReturn = mxController->keyInput(rKEvt);
161 if( !bReturn )
163 if( mpViewShell )
165 mpViewShell->KeyInput(rKEvt,this);
167 else
169 Window::KeyInput(rKEvt);
174 if( mpViewShell )
175 mpViewShell->SetActiveWindow( this );
178 void ShowWindow::MouseButtonDown(const MouseEvent& /*rMEvt*/)
180 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode )
182 TerminateShow();
184 else if( mpViewShell )
186 mpViewShell->SetActiveWindow( this );
190 void ShowWindow::MouseMove(const MouseEvent& /*rMEvt*/)
192 if( mbMouseAutoHide )
194 if( mbMouseCursorHidden )
196 if( mnFirstMouseMove )
198 // if this is not the first mouse move while hidden, see if
199 // enough time has pasted to show mouse pointer again
200 sal_uInt64 nTime = ::tools::Time::GetSystemTicks();
201 if( (nTime - mnFirstMouseMove) >= SHOW_MOUSE_TIMEOUT )
203 ShowPointer( true );
204 mnFirstMouseMove = 0;
205 mbMouseCursorHidden = false;
206 maMouseTimer.SetTimeout( HIDE_MOUSE_TIMEOUT );
207 maMouseTimer.Start();
210 else
212 // if this is the first mouse move, note current
213 // time and start idle timer to cancel show mouse pointer
214 // again if not enough mouse movement is measured
215 mnFirstMouseMove = ::tools::Time::GetSystemTicks();
216 maMouseTimer.SetTimeout( 2*SHOW_MOUSE_TIMEOUT );
217 maMouseTimer.Start();
220 else
222 // current mousemove restarts the idle timer to hide the mouse
223 maMouseTimer.Start();
227 if( mpViewShell )
228 mpViewShell->SetActiveWindow( this );
231 void ShowWindow::MouseButtonUp(const MouseEvent& rMEvt)
233 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode )
235 TerminateShow();
237 else if( (SHOWWINDOWMODE_END == meShowWindowMode) && !rMEvt.IsRight() )
239 TerminateShow();
241 else if( (( SHOWWINDOWMODE_BLANK == meShowWindowMode ) || ( SHOWWINDOWMODE_PAUSE == meShowWindowMode ))
242 && !rMEvt.IsRight() )
244 RestartShow();
246 else
248 if( mxController.is() )
249 mxController->mouseButtonUp( rMEvt );
254 * if FuSlideShow is still available, forward it
256 void ShowWindow::Paint(vcl::RenderContext& /*rRenderContext*/, const ::tools::Rectangle& rRect)
258 if( (meShowWindowMode == SHOWWINDOWMODE_NORMAL) || (meShowWindowMode == SHOWWINDOWMODE_PREVIEW) )
260 if( mxController.is() )
262 mxController->paint();
264 else if(mpViewShell )
266 mpViewShell->Paint(rRect, this);
269 else
271 DrawWallpaper( rRect, maShowBackground );
273 if( SHOWWINDOWMODE_END == meShowWindowMode )
275 DrawEndScene();
277 else if( SHOWWINDOWMODE_PAUSE == meShowWindowMode )
279 DrawPauseScene( false );
281 else if( SHOWWINDOWMODE_BLANK == meShowWindowMode )
283 // just blank through background color => nothing to be done here
288 void ShowWindow::LoseFocus()
290 Window::LoseFocus();
292 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode)
293 TerminateShow();
296 void ShowWindow::SetEndMode()
298 if( !(( SHOWWINDOWMODE_NORMAL == meShowWindowMode ) && mpViewShell && mpViewShell->GetView()) )
299 return;
301 DeleteWindowFromPaintView();
302 meShowWindowMode = SHOWWINDOWMODE_END;
303 maShowBackground = Wallpaper( COL_BLACK );
305 // hide navigator if it is visible
306 if( mpViewShell->GetViewFrame()->GetChildWindow( SID_NAVIGATOR ) )
308 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, false );
309 mbShowNavigatorAfterSpecialMode = true;
312 Invalidate();
315 bool ShowWindow::SetPauseMode( sal_Int32 nTimeout, Graphic const * pLogo )
317 rtl::Reference< SlideShow > xSlideShow;
319 if( mpViewShell )
320 xSlideShow = SlideShow::GetSlideShow( mpViewShell->GetViewShellBase() );
322 if( xSlideShow.is() && !nTimeout )
324 xSlideShow->jumpToPageIndex( 0 );
326 else if( ( SHOWWINDOWMODE_NORMAL == meShowWindowMode ) && mpViewShell && mpViewShell->GetView() )
328 DeleteWindowFromPaintView();
329 mnPauseTimeout = nTimeout;
330 mnRestartPageIndex = 0;
331 meShowWindowMode = SHOWWINDOWMODE_PAUSE;
332 maShowBackground = Wallpaper( COL_BLACK );
334 // hide navigator if it is visible
335 if( mpViewShell->GetViewFrame()->GetChildWindow( SID_NAVIGATOR ) )
337 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, false );
338 mbShowNavigatorAfterSpecialMode = true;
341 if( pLogo )
342 maLogo = *pLogo;
344 Invalidate();
346 if( SLIDE_NO_TIMEOUT != mnPauseTimeout )
347 maPauseTimer.Start();
350 return( SHOWWINDOWMODE_PAUSE == meShowWindowMode );
353 bool ShowWindow::SetBlankMode( sal_Int32 nPageIndexToRestart, const Color& rBlankColor )
355 if( ( SHOWWINDOWMODE_NORMAL == meShowWindowMode ) && mpViewShell && mpViewShell->GetView() )
357 DeleteWindowFromPaintView();
358 mnRestartPageIndex = nPageIndexToRestart;
359 meShowWindowMode = SHOWWINDOWMODE_BLANK;
360 maShowBackground = Wallpaper( rBlankColor );
362 // hide navigator if it is visible
363 if( mpViewShell->GetViewFrame()->GetChildWindow( SID_NAVIGATOR ) )
365 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, false );
366 mbShowNavigatorAfterSpecialMode = true;
369 Invalidate();
372 return( SHOWWINDOWMODE_BLANK == meShowWindowMode );
375 void ShowWindow::SetPreviewMode()
377 meShowWindowMode = SHOWWINDOWMODE_PREVIEW;
380 void ShowWindow::TerminateShow()
382 maLogo.Clear();
383 maPauseTimer.Stop();
384 maMouseTimer.Stop();
385 Erase();
386 maShowBackground = Wallpaper( COL_BLACK );
387 meShowWindowMode = SHOWWINDOWMODE_NORMAL;
388 mnPauseTimeout = SLIDE_NO_TIMEOUT;
390 if( mpViewShell )
392 // show navigator?
393 if( mbShowNavigatorAfterSpecialMode )
395 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR );
396 mbShowNavigatorAfterSpecialMode = false;
400 if( mxController.is() )
401 mxController->endPresentation();
403 mnRestartPageIndex = PAGE_NO_END;
406 void ShowWindow::RestartShow()
408 RestartShow( mnRestartPageIndex );
411 void ShowWindow::RestartShow( sal_Int32 nPageIndexToRestart )
414 ShowWindowMode eOldShowWindowMode = meShowWindowMode;
416 maLogo.Clear();
417 maPauseTimer.Stop();
418 Erase();
419 maShowBackground = Wallpaper( COL_BLACK );
420 meShowWindowMode = SHOWWINDOWMODE_NORMAL;
421 mnPauseTimeout = SLIDE_NO_TIMEOUT;
423 if( mpViewShell )
425 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( mpViewShell->GetViewShellBase() ) );
427 if( xSlideShow.is() )
429 AddWindowToPaintView();
431 if( SHOWWINDOWMODE_BLANK == eOldShowWindowMode )
433 xSlideShow->pause(false);
434 Invalidate();
436 else
438 xSlideShow->jumpToPageIndex( nPageIndexToRestart );
443 mnRestartPageIndex = PAGE_NO_END;
445 // show navigator?
446 if( mbShowNavigatorAfterSpecialMode )
448 if (mpViewShell)
449 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR );
450 mbShowNavigatorAfterSpecialMode = false;
454 void ShowWindow::DrawPauseScene( bool bTimeoutOnly )
456 const MapMode& rMap = GetMapMode();
457 const Point aOutOrg( PixelToLogic( Point() ) );
458 const Size aOutSize( GetOutputSize() );
459 const Size aTextSize(LogicToLogic(Size(0, 14), MapMode(MapUnit::MapPoint), rMap));
460 const Size aOffset(LogicToLogic(Size(1000, 1000), MapMode(MapUnit::Map100thMM), rMap));
461 OUString aText( SdResId( STR_PRES_PAUSE ) );
462 bool bDrawn = false;
464 vcl::Font aFont( GetSettings().GetStyleSettings().GetMenuFont() );
465 const vcl::Font aOldFont( GetFont() );
467 aFont.SetFontSize( aTextSize );
468 aFont.SetColor( COL_WHITE );
469 aFont.SetCharSet( aOldFont.GetCharSet() );
470 aFont.SetLanguage( aOldFont.GetLanguage() );
472 if( !bTimeoutOnly && ( maLogo.GetType() != GraphicType::NONE ) )
474 Size aGrfSize;
476 if (maLogo.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel)
477 aGrfSize = PixelToLogic( maLogo.GetPrefSize() );
478 else
479 aGrfSize = LogicToLogic( maLogo.GetPrefSize(), maLogo.GetPrefMapMode(), rMap );
481 const Point aGrfPos( std::max( aOutOrg.X() + aOutSize.Width() - aGrfSize.Width() - aOffset.Width(), aOutOrg.X() ),
482 std::max( aOutOrg.Y() + aOutSize.Height() - aGrfSize.Height() - aOffset.Height(), aOutOrg.Y() ) );
484 if( maLogo.IsAnimated() )
485 maLogo.StartAnimation( this, aGrfPos, aGrfSize, reinterpret_cast<sal_IntPtr>(this) );
486 else
487 maLogo.Draw( this, aGrfPos, aGrfSize );
490 if( SLIDE_NO_TIMEOUT != mnPauseTimeout )
492 MapMode aVMap( rMap );
493 ScopedVclPtrInstance< VirtualDevice > pVDev( *this );
495 aVMap.SetOrigin( Point() );
496 pVDev->SetMapMode( aVMap );
497 pVDev->SetBackground( Wallpaper( COL_BLACK ) );
499 // set font first, to determine real output height
500 pVDev->SetFont( aFont );
502 const Size aVDevSize( aOutSize.Width(), pVDev->GetTextHeight() );
504 if( pVDev->SetOutputSize( aVDevSize ) )
506 // Note: if performance gets an issue here, we can use NumberFormatter directly
507 SvtSysLocale aSysLocale;
508 const LocaleDataWrapper& aLocaleData = aSysLocale.GetLocaleData();
510 aText += " ( ";
511 aText += aLocaleData.getDuration( ::tools::Time( 0, 0, mnPauseTimeout ) );
512 aText += " )";
513 pVDev->DrawText( Point( aOffset.Width(), 0 ), aText );
514 DrawOutDev( Point( aOutOrg.X(), aOffset.Height() ), aVDevSize, Point(), aVDevSize, *pVDev );
515 bDrawn = true;
519 if( !bDrawn )
521 SetFont( aFont );
522 DrawText( Point( aOutOrg.X() + aOffset.Width(), aOutOrg.Y() + aOffset.Height() ), aText );
523 SetFont( aOldFont );
527 void ShowWindow::DrawEndScene()
529 const vcl::Font aOldFont( GetFont() );
530 vcl::Font aFont( GetSettings().GetStyleSettings().GetMenuFont() );
532 const Point aOutOrg( PixelToLogic( Point() ) );
533 const Size aTextSize(LogicToLogic(Size(0, 14), MapMode(MapUnit::MapPoint), GetMapMode()));
534 const OUString aText( SdResId( STR_PRES_SOFTEND ) );
536 aFont.SetFontSize( aTextSize );
537 aFont.SetColor( COL_WHITE );
538 aFont.SetCharSet( aOldFont.GetCharSet() );
539 aFont.SetLanguage( aOldFont.GetLanguage() );
540 SetFont( aFont );
541 DrawText( Point( aOutOrg.X() + aTextSize.Height(), aOutOrg.Y() + aTextSize.Height() ), aText );
542 SetFont( aOldFont );
545 IMPL_LINK( ShowWindow, PauseTimeoutHdl, Timer*, pTimer, void )
547 if( !( --mnPauseTimeout ) )
548 RestartShow();
549 else
551 DrawPauseScene( true );
552 pTimer->Start();
556 IMPL_LINK_NOARG(ShowWindow, MouseTimeoutHdl, Timer *, void)
558 if( mbMouseCursorHidden )
560 // not enough mouse movements since first recording so
561 // cancel show mouse pointer for now
562 mnFirstMouseMove = 0;
564 else
566 // mouse has been idle to long, hide pointer
567 ShowPointer( false );
568 mbMouseCursorHidden = true;
572 IMPL_LINK( ShowWindow, EventHdl, VclWindowEvent&, rEvent, void )
574 if( mbMouseAutoHide )
576 if (rEvent.GetId() == VclEventId::WindowShow)
578 maMouseTimer.SetTimeout( HIDE_MOUSE_TIMEOUT );
579 maMouseTimer.Start();
584 void ShowWindow::DeleteWindowFromPaintView()
586 if( mpViewShell->GetView() )
587 mpViewShell->GetView()->DeleteWindowFromPaintView( this );
589 sal_uInt16 nChild = GetChildCount();
590 while( nChild-- )
591 GetChild( nChild )->Show( false );
594 void ShowWindow::AddWindowToPaintView()
596 if( mpViewShell->GetView() )
597 mpViewShell->GetView()->AddWindowToPaintView( this, nullptr );
599 sal_uInt16 nChild = GetChildCount();
600 while( nChild-- )
601 GetChild( nChild )->Show();
604 // Override the sd::Window's CreateAccessible to create a different accessible object
605 css::uno::Reference<css::accessibility::XAccessible>
606 ShowWindow::CreateAccessible()
608 css::uno::Reference< css::accessibility::XAccessible > xAcc = GetAccessible(false);
609 if (xAcc.get())
611 return xAcc;
613 if (mpViewShell != nullptr)
615 xAcc = mpViewShell->CreateAccessibleDocumentView (this);
616 SetAccessible(xAcc);
617 return xAcc;
619 else
621 SAL_WARN("sd", "::sd::Window::CreateAccessible: no view shell");
622 return vcl::Window::CreateAccessible ();
625 } // end of namespace sd
627 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */