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 .
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>
35 #include <strings.hrc>
37 #include <sal/log.hxx>
39 #include <vcl/settings.hxx>
40 #include <vcl/virdev.hxx>
42 using namespace ::com::sun::star
;
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)
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.
68 MapMode
aMap(GetMapMode());
69 aMap
.SetMapUnit(MapUnit::Map100thMM
);
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!
83 AddEventListener( LINK( this, ShowWindow
, EventHdl
) );
86 ShowWindow::~ShowWindow()
91 void ShowWindow::dispose()
95 ::sd::Window::dispose();
98 void ShowWindow::KeyInput(const KeyEvent
& rKEvt
)
100 bool bReturn
= false;
102 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
107 else if( SHOWWINDOWMODE_END
== meShowWindowMode
)
109 const int nKeyCode
= rKEvt
.GetKeyCode().GetCode();
118 case awt::Key::CONTEXTMENU
:
119 // these keys will be handled by the slide show even
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)
136 else if( SHOWWINDOWMODE_PAUSE
== meShowWindowMode
)
138 const int nKeyCode
= rKEvt
.GetKeyCode().GetCode();
151 case awt::Key::CONTEXTMENU
:
152 // these keys will be handled by the slide show even
164 if( mxController
.is() )
165 bReturn
= mxController
->keyInput(rKEvt
);
171 mpViewShell
->KeyInput(rKEvt
,this);
175 Window::KeyInput(rKEvt
);
181 mpViewShell
->SetActiveWindow( this );
184 void ShowWindow::MouseButtonDown(const MouseEvent
& /*rMEvt*/)
186 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
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
)
210 mnFirstMouseMove
= 0;
211 mbMouseCursorHidden
= false;
212 maMouseTimer
.SetTimeout( HIDE_MOUSE_TIMEOUT
);
213 maMouseTimer
.Start();
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();
228 // current mousemove restarts the idle timer to hide the mouse
229 maMouseTimer
.Start();
234 mpViewShell
->SetActiveWindow( this );
237 void ShowWindow::MouseButtonUp(const MouseEvent
& rMEvt
)
239 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
243 else if( (SHOWWINDOWMODE_END
== meShowWindowMode
) && !rMEvt
.IsRight() )
247 else if( (( SHOWWINDOWMODE_BLANK
== meShowWindowMode
) || ( SHOWWINDOWMODE_PAUSE
== meShowWindowMode
))
248 && !rMEvt
.IsRight() )
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);
277 GetOutDev()->DrawWallpaper( rRect
, maShowBackground
);
279 if( SHOWWINDOWMODE_END
== meShowWindowMode
)
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()
298 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
302 void ShowWindow::SetEndMode()
304 if( !(( SHOWWINDOWMODE_NORMAL
== meShowWindowMode
) && mpViewShell
&& mpViewShell
->GetView()) )
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;
321 bool ShowWindow::SetPauseMode( sal_Int32 nTimeout
, Graphic
const * pLogo
)
323 rtl::Reference
< SlideShow
> xSlideShow
;
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;
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;
378 return( SHOWWINDOWMODE_BLANK
== meShowWindowMode
);
381 void ShowWindow::SetPreviewMode()
383 meShowWindowMode
= SHOWWINDOWMODE_PREVIEW
;
386 void ShowWindow::TerminateShow()
391 GetOutDev()->Erase();
392 maShowBackground
= Wallpaper( COL_BLACK
);
393 meShowWindowMode
= SHOWWINDOWMODE_NORMAL
;
394 mnPauseTimeout
= SLIDE_NO_TIMEOUT
;
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
;
423 GetOutDev()->Erase();
424 maShowBackground
= Wallpaper( COL_BLACK
);
425 meShowWindowMode
= SHOWWINDOWMODE_NORMAL
;
426 mnPauseTimeout
= SLIDE_NO_TIMEOUT
;
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);
443 xSlideShow
->jumpToPageIndex( nPageIndexToRestart
);
448 mnRestartPageIndex
= PAGE_NO_END
;
451 if( mbShowNavigatorAfterSpecialMode
)
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
) );
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
) )
481 if (maLogo
.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel
)
482 aGrfSize
= PixelToLogic( maLogo
.GetPrefSize() );
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));
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
);
525 GetOutDev()->DrawText( Point( aOutOrg
.X() + aOffset
.Width(), aOutOrg
.Y() + aOffset
.Height() ), aText
);
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() );
544 GetOutDev()->DrawText( Point( aOutOrg
.X() + aTextSize
.Height(), aOutOrg
.Y() + aTextSize
.Height() ), aText
);
548 IMPL_LINK( ShowWindow
, PauseTimeoutHdl
, Timer
*, pTimer
, void )
550 if( !( --mnPauseTimeout
) )
554 DrawPauseScene( true );
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;
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();
594 GetChild( nChild
)->Show( false );
597 void ShowWindow::AddWindowToPaintView()
599 if( mpViewShell
->GetView() )
600 mpViewShell
->GetView()->AddDeviceToPaintView( *GetOutDev(), nullptr );
602 sal_uInt16 nChild
= GetChildCount();
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);
616 if (mpViewShell
!= nullptr)
618 xAcc
= mpViewShell
->CreateAccessibleDocumentView (this);
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: */