android: Update app-specific/MIME type icons
[LibreOffice.git] / sd / source / ui / slideshow / showwin.cxx
blob8e1f8a6d49cdc4aa81096c57013f51d77f278788
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 <sdresid.hxx>
34 #include <helpids.h>
35 #include <strings.hrc>
37 #include <sal/log.hxx>
38 #include <utility>
39 #include <vcl/settings.hxx>
40 #include <vcl/virdev.hxx>
42 using namespace ::com::sun::star;
44 namespace sd {
46 const sal_uInt64 HIDE_MOUSE_TIMEOUT = 10000;
47 const sal_uInt64 SHOW_MOUSE_TIMEOUT = 1000;
49 ShowWindow::ShowWindow( ::rtl::Reference< SlideshowImpl > xController, vcl::Window* pParent )
50 : ::sd::Window( pParent )
51 , maPauseTimer("sd ShowWindow maPauseTimer")
52 , maMouseTimer("sd ShowWindow maMouseTimer")
53 , mnPauseTimeout( SLIDE_NO_TIMEOUT )
54 , mnRestartPageIndex( PAGE_NO_END )
55 , meShowWindowMode(SHOWWINDOWMODE_NORMAL)
56 , mbShowNavigatorAfterSpecialMode( false )
57 , mbMouseAutoHide(true)
58 , mbMouseCursorHidden(false)
59 , mnFirstMouseMove(0)
60 , mxController(std::move( xController ))
62 GetOutDev()->SetOutDevViewType( OutDevViewType::SlideShow );
64 // Do never mirror the preview window. This explicitly includes right
65 // to left writing environments.
66 EnableRTL (false);
68 MapMode aMap(GetMapMode());
69 aMap.SetMapUnit(MapUnit::Map100thMM);
70 SetMapMode(aMap);
72 // set HelpId
73 SetHelpId( HID_SD_WIN_PRESENTATION );
75 maPauseTimer.SetInvokeHandler( LINK( this, ShowWindow, PauseTimeoutHdl ) );
76 maPauseTimer.SetTimeout( 1000 );
77 maMouseTimer.SetInvokeHandler( LINK( this, ShowWindow, MouseTimeoutHdl ) );
78 maMouseTimer.SetTimeout( HIDE_MOUSE_TIMEOUT );
80 maShowBackground = Wallpaper( COL_BLACK );
81 SetBackground(); // avoids that VCL paints any background!
82 GetParent()->Show();
83 AddEventListener( LINK( this, ShowWindow, EventHdl ) );
86 ShowWindow::~ShowWindow()
88 disposeOnce();
91 void ShowWindow::dispose()
93 maPauseTimer.Stop();
94 maMouseTimer.Stop();
95 ::sd::Window::dispose();
98 void ShowWindow::KeyInput(const KeyEvent& rKEvt)
100 bool bReturn = false;
102 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode )
104 TerminateShow();
105 bReturn = true;
107 else if( SHOWWINDOWMODE_END == meShowWindowMode )
109 const int nKeyCode = rKEvt.GetKeyCode().GetCode();
110 switch( nKeyCode )
112 case KEY_PAGEUP:
113 case KEY_LEFT:
114 case KEY_UP:
115 case KEY_P:
116 case KEY_HOME:
117 case KEY_END:
118 case awt::Key::CONTEXTMENU:
119 // these keys will be handled by the slide show even
120 // while in end mode
121 break;
122 default:
123 TerminateShow();
124 bReturn = true;
127 else if( SHOWWINDOWMODE_BLANK == meShowWindowMode )
129 bool bFakeKeyPress = rKEvt.GetKeyCode().GetFullCode() == 0;
130 // Ignore workaround of https://gitlab.gnome.org/GNOME/gtk/issues/1785
131 // See calls to GtkSalFrame::makeFakeKeyPress (Fixed in GTK 2.34)
132 if (!bFakeKeyPress)
133 RestartShow();
134 bReturn = true;
136 else if( SHOWWINDOWMODE_PAUSE == meShowWindowMode )
138 const int nKeyCode = rKEvt.GetKeyCode().GetCode();
139 switch( nKeyCode )
141 case KEY_ESCAPE:
142 TerminateShow();
143 bReturn = true;
144 break;
145 case KEY_PAGEUP:
146 case KEY_RIGHT:
147 case KEY_UP:
148 case KEY_P:
149 case KEY_HOME:
150 case KEY_END:
151 case awt::Key::CONTEXTMENU:
152 // these keys will be handled by the slide show even
153 // while in end mode
154 break;
155 default:
156 RestartShow();
157 bReturn = true;
158 break;
162 if( !bReturn )
164 if( mxController.is() )
165 bReturn = mxController->keyInput(rKEvt);
167 if( !bReturn )
169 if( mpViewShell )
171 mpViewShell->KeyInput(rKEvt,this);
173 else
175 Window::KeyInput(rKEvt);
180 if( mpViewShell )
181 mpViewShell->SetActiveWindow( this );
184 void ShowWindow::MouseButtonDown(const MouseEvent& /*rMEvt*/)
186 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode )
188 TerminateShow();
190 else if( mpViewShell )
192 mpViewShell->SetActiveWindow( this );
196 void ShowWindow::MouseMove(const MouseEvent& /*rMEvt*/)
198 if( mbMouseAutoHide )
200 if( mbMouseCursorHidden )
202 if( mnFirstMouseMove )
204 // if this is not the first mouse move while hidden, see if
205 // enough time has pasted to show mouse pointer again
206 sal_uInt64 nTime = ::tools::Time::GetSystemTicks();
207 if( (nTime - mnFirstMouseMove) >= SHOW_MOUSE_TIMEOUT )
209 ShowPointer( true );
210 mnFirstMouseMove = 0;
211 mbMouseCursorHidden = false;
212 maMouseTimer.SetTimeout( HIDE_MOUSE_TIMEOUT );
213 maMouseTimer.Start();
216 else
218 // if this is the first mouse move, note current
219 // time and start idle timer to cancel show mouse pointer
220 // again if not enough mouse movement is measured
221 mnFirstMouseMove = ::tools::Time::GetSystemTicks();
222 maMouseTimer.SetTimeout( 2*SHOW_MOUSE_TIMEOUT );
223 maMouseTimer.Start();
226 else
228 // current mousemove restarts the idle timer to hide the mouse
229 maMouseTimer.Start();
233 if( mpViewShell )
234 mpViewShell->SetActiveWindow( this );
237 void ShowWindow::MouseButtonUp(const MouseEvent& rMEvt)
239 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode )
241 TerminateShow();
243 else if( (SHOWWINDOWMODE_END == meShowWindowMode) && !rMEvt.IsRight() )
245 TerminateShow();
247 else if( (( SHOWWINDOWMODE_BLANK == meShowWindowMode ) || ( SHOWWINDOWMODE_PAUSE == meShowWindowMode ))
248 && !rMEvt.IsRight() )
250 RestartShow();
252 else
254 if( mxController.is() )
255 mxController->mouseButtonUp( rMEvt );
260 * if FuSlideShow is still available, forward it
262 void ShowWindow::Paint(vcl::RenderContext& /*rRenderContext*/, const ::tools::Rectangle& rRect)
264 if( (meShowWindowMode == SHOWWINDOWMODE_NORMAL) || (meShowWindowMode == SHOWWINDOWMODE_PREVIEW) )
266 if( mxController.is() )
268 mxController->paint();
270 else if(mpViewShell )
272 mpViewShell->Paint(rRect, this);
275 else
277 GetOutDev()->DrawWallpaper( rRect, maShowBackground );
279 if( SHOWWINDOWMODE_END == meShowWindowMode )
281 DrawEndScene();
283 else if( SHOWWINDOWMODE_PAUSE == meShowWindowMode )
285 DrawPauseScene( false );
287 else if( SHOWWINDOWMODE_BLANK == meShowWindowMode )
289 // just blank through background color => nothing to be done here
294 void ShowWindow::LoseFocus()
296 Window::LoseFocus();
298 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode)
299 TerminateShow();
302 void ShowWindow::SetEndMode()
304 if( !(( SHOWWINDOWMODE_NORMAL == meShowWindowMode ) && mpViewShell && mpViewShell->GetView()) )
305 return;
307 DeleteWindowFromPaintView();
308 meShowWindowMode = SHOWWINDOWMODE_END;
309 maShowBackground = Wallpaper( COL_BLACK );
311 // hide navigator if it is visible
312 if( mpViewShell->GetViewFrame()->GetChildWindow( SID_NAVIGATOR ) )
314 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, false );
315 mbShowNavigatorAfterSpecialMode = true;
318 Invalidate();
321 bool ShowWindow::SetPauseMode( sal_Int32 nTimeout, Graphic const * pLogo )
323 rtl::Reference< SlideShow > xSlideShow;
325 if( mpViewShell )
326 xSlideShow = SlideShow::GetSlideShow( mpViewShell->GetViewShellBase() );
328 if( xSlideShow.is() && !nTimeout )
330 xSlideShow->jumpToPageIndex( 0 );
332 else if( ( SHOWWINDOWMODE_NORMAL == meShowWindowMode ) && mpViewShell && mpViewShell->GetView() )
334 DeleteWindowFromPaintView();
335 mnPauseTimeout = nTimeout;
336 mnRestartPageIndex = 0;
337 meShowWindowMode = SHOWWINDOWMODE_PAUSE;
338 maShowBackground = Wallpaper( COL_BLACK );
340 // hide navigator if it is visible
341 if( mpViewShell->GetViewFrame()->GetChildWindow( SID_NAVIGATOR ) )
343 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, false );
344 mbShowNavigatorAfterSpecialMode = true;
347 if( pLogo )
348 maLogo = *pLogo;
350 Invalidate();
352 if( SLIDE_NO_TIMEOUT != mnPauseTimeout )
353 maPauseTimer.Start();
356 return( SHOWWINDOWMODE_PAUSE == meShowWindowMode );
359 bool ShowWindow::SetBlankMode( sal_Int32 nPageIndexToRestart, const Color& rBlankColor )
361 if( ( SHOWWINDOWMODE_NORMAL == meShowWindowMode ) && mpViewShell && mpViewShell->GetView() )
363 DeleteWindowFromPaintView();
364 mnRestartPageIndex = nPageIndexToRestart;
365 meShowWindowMode = SHOWWINDOWMODE_BLANK;
366 maShowBackground = Wallpaper( rBlankColor );
368 // hide navigator if it is visible
369 if( mpViewShell->GetViewFrame()->GetChildWindow( SID_NAVIGATOR ) )
371 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, false );
372 mbShowNavigatorAfterSpecialMode = true;
375 Invalidate();
378 return( SHOWWINDOWMODE_BLANK == meShowWindowMode );
381 void ShowWindow::SetPreviewMode()
383 meShowWindowMode = SHOWWINDOWMODE_PREVIEW;
386 void ShowWindow::TerminateShow()
388 maLogo.Clear();
389 maPauseTimer.Stop();
390 maMouseTimer.Stop();
391 GetOutDev()->Erase();
392 maShowBackground = Wallpaper( COL_BLACK );
393 meShowWindowMode = SHOWWINDOWMODE_NORMAL;
394 mnPauseTimeout = SLIDE_NO_TIMEOUT;
396 if( mpViewShell )
398 // show navigator?
399 if( mbShowNavigatorAfterSpecialMode )
401 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR );
402 mbShowNavigatorAfterSpecialMode = false;
406 if( mxController.is() )
407 mxController->endPresentation();
409 mnRestartPageIndex = PAGE_NO_END;
412 void ShowWindow::RestartShow()
414 RestartShow( mnRestartPageIndex );
417 void ShowWindow::RestartShow( sal_Int32 nPageIndexToRestart )
419 ShowWindowMode eOldShowWindowMode = meShowWindowMode;
421 maLogo.Clear();
422 maPauseTimer.Stop();
423 GetOutDev()->Erase();
424 maShowBackground = Wallpaper( COL_BLACK );
425 meShowWindowMode = SHOWWINDOWMODE_NORMAL;
426 mnPauseTimeout = SLIDE_NO_TIMEOUT;
428 if( mpViewShell )
430 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( mpViewShell->GetViewShellBase() ) );
432 if( xSlideShow.is() )
434 AddWindowToPaintView();
436 if( SHOWWINDOWMODE_BLANK == eOldShowWindowMode || SHOWWINDOWMODE_END == eOldShowWindowMode )
438 xSlideShow->pause(false);
439 Invalidate();
441 else
443 xSlideShow->jumpToPageIndex( nPageIndexToRestart );
448 mnRestartPageIndex = PAGE_NO_END;
450 // show navigator?
451 if( mbShowNavigatorAfterSpecialMode )
453 if (mpViewShell)
454 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR );
455 mbShowNavigatorAfterSpecialMode = false;
459 void ShowWindow::DrawPauseScene( bool bTimeoutOnly )
461 const MapMode& rMap = GetMapMode();
462 const Point aOutOrg( PixelToLogic( Point() ) );
463 const Size aOutSize( GetOutDev()->GetOutputSize() );
464 const Size aTextSize(OutputDevice::LogicToLogic(Size(0, 14), MapMode(MapUnit::MapPoint), rMap));
465 const Size aOffset(OutputDevice::LogicToLogic(Size(1000, 1000), MapMode(MapUnit::Map100thMM), rMap));
466 OUString aText( SdResId( STR_PRES_PAUSE ) );
467 bool bDrawn = false;
469 vcl::Font aFont( GetSettings().GetStyleSettings().GetMenuFont() );
470 const vcl::Font aOldFont( GetFont() );
472 aFont.SetFontSize( aTextSize );
473 aFont.SetColor( COL_WHITE );
474 aFont.SetCharSet( aOldFont.GetCharSet() );
475 aFont.SetLanguage( aOldFont.GetLanguage() );
477 if( !bTimeoutOnly && ( maLogo.GetType() != GraphicType::NONE ) )
479 Size aGrfSize;
481 if (maLogo.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel)
482 aGrfSize = PixelToLogic( maLogo.GetPrefSize() );
483 else
484 aGrfSize = OutputDevice::LogicToLogic( maLogo.GetPrefSize(), maLogo.GetPrefMapMode(), rMap );
486 const Point aGrfPos( std::max( aOutOrg.X() + aOutSize.Width() - aGrfSize.Width() - aOffset.Width(), aOutOrg.X() ),
487 std::max( aOutOrg.Y() + aOutSize.Height() - aGrfSize.Height() - aOffset.Height(), aOutOrg.Y() ) );
489 if( maLogo.IsAnimated() )
490 maLogo.StartAnimation(*GetOutDev(), aGrfPos, aGrfSize, reinterpret_cast<sal_IntPtr>(this));
491 else
492 maLogo.Draw(*GetOutDev(), aGrfPos, aGrfSize);
495 if( SLIDE_NO_TIMEOUT != mnPauseTimeout )
497 MapMode aVMap( rMap );
498 ScopedVclPtrInstance< VirtualDevice > pVDev( *GetOutDev() );
500 aVMap.SetOrigin( Point() );
501 pVDev->SetMapMode( aVMap );
502 pVDev->SetBackground( Wallpaper( COL_BLACK ) );
504 // set font first, to determine real output height
505 pVDev->SetFont( aFont );
507 const Size aVDevSize( aOutSize.Width(), pVDev->GetTextHeight() );
509 if( pVDev->SetOutputSize( aVDevSize ) )
511 // Note: if performance gets an issue here, we can use NumberFormatter directly
512 SvtSysLocale aSysLocale;
513 const LocaleDataWrapper& aLocaleData = aSysLocale.GetLocaleData();
515 aText += " ( " + aLocaleData.getDuration( ::tools::Time( 0, 0, mnPauseTimeout ) ) + " )";
516 pVDev->DrawText( Point( aOffset.Width(), 0 ), aText );
517 GetOutDev()->DrawOutDev( Point( aOutOrg.X(), aOffset.Height() ), aVDevSize, Point(), aVDevSize, *pVDev );
518 bDrawn = true;
522 if( !bDrawn )
524 SetFont( aFont );
525 GetOutDev()->DrawText( Point( aOutOrg.X() + aOffset.Width(), aOutOrg.Y() + aOffset.Height() ), aText );
526 SetFont( aOldFont );
530 void ShowWindow::DrawEndScene()
532 const vcl::Font aOldFont( GetFont() );
533 vcl::Font aFont( GetSettings().GetStyleSettings().GetMenuFont() );
535 const Point aOutOrg( PixelToLogic( Point() ) );
536 const Size aTextSize(OutputDevice::LogicToLogic(Size(0, 14), MapMode(MapUnit::MapPoint), GetMapMode()));
537 const OUString aText( SdResId( STR_PRES_SOFTEND ) );
539 aFont.SetFontSize( aTextSize );
540 aFont.SetColor( COL_WHITE );
541 aFont.SetCharSet( aOldFont.GetCharSet() );
542 aFont.SetLanguage( aOldFont.GetLanguage() );
543 SetFont( aFont );
544 GetOutDev()->DrawText( Point( aOutOrg.X() + aTextSize.Height(), aOutOrg.Y() + aTextSize.Height() ), aText );
545 SetFont( aOldFont );
548 IMPL_LINK( ShowWindow, PauseTimeoutHdl, Timer*, pTimer, void )
550 if( !( --mnPauseTimeout ) )
551 RestartShow();
552 else
554 DrawPauseScene( true );
555 pTimer->Start();
559 IMPL_LINK_NOARG(ShowWindow, MouseTimeoutHdl, Timer *, void)
561 if( mbMouseCursorHidden )
563 // not enough mouse movements since first recording so
564 // cancel show mouse pointer for now
565 mnFirstMouseMove = 0;
567 else
569 // mouse has been idle too long, hide pointer
570 ShowPointer( false );
571 mbMouseCursorHidden = true;
575 IMPL_LINK( ShowWindow, EventHdl, VclWindowEvent&, rEvent, void )
577 if( mbMouseAutoHide )
579 if (rEvent.GetId() == VclEventId::WindowShow)
581 maMouseTimer.SetTimeout( HIDE_MOUSE_TIMEOUT );
582 maMouseTimer.Start();
587 void ShowWindow::DeleteWindowFromPaintView()
589 if( mpViewShell->GetView() )
590 mpViewShell->GetView()->DeleteDeviceFromPaintView( *GetOutDev() );
592 sal_uInt16 nChild = GetChildCount();
593 while( nChild-- )
594 GetChild( nChild )->Show( false );
597 void ShowWindow::AddWindowToPaintView()
599 if( mpViewShell->GetView() )
600 mpViewShell->GetView()->AddDeviceToPaintView( *GetOutDev(), nullptr );
602 sal_uInt16 nChild = GetChildCount();
603 while( nChild-- )
604 GetChild( nChild )->Show();
607 // Override the sd::Window's CreateAccessible to create a different accessible object
608 css::uno::Reference<css::accessibility::XAccessible>
609 ShowWindow::CreateAccessible()
611 css::uno::Reference< css::accessibility::XAccessible > xAcc = GetAccessible(false);
612 if (xAcc)
614 return xAcc;
616 if (mpViewShell != nullptr)
618 xAcc = mpViewShell->CreateAccessibleDocumentView (this);
619 SetAccessible(xAcc);
620 return xAcc;
622 else
624 SAL_WARN("sd", "::sd::Window::CreateAccessible: no view shell");
625 return vcl::Window::CreateAccessible ();
628 } // end of namespace sd
630 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */