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 <ViewShellBase.hxx>
34 #include <sdresid.hxx>
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
;
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)
58 , mxController( xController
)
60 SetOutDevViewType( OutDevViewType::SlideShow
);
62 // Do never mirror the preview window. This explicitly includes right
63 // to left writing environments.
66 MapMode
aMap(GetMapMode());
67 aMap
.SetMapUnit(MapUnit::Map100thMM
);
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!
81 AddEventListener( LINK( this, ShowWindow
, EventHdl
) );
84 ShowWindow::~ShowWindow()
89 void ShowWindow::dispose()
93 ::sd::Window::dispose();
96 void ShowWindow::KeyInput(const KeyEvent
& rKEvt
)
100 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
105 else if( SHOWWINDOWMODE_END
== meShowWindowMode
)
107 const int nKeyCode
= rKEvt
.GetKeyCode().GetCode();
116 case awt::Key::CONTEXTMENU
:
117 // these keys will be handled by the slide show even
125 else if( SHOWWINDOWMODE_BLANK
== meShowWindowMode
)
130 else if( SHOWWINDOWMODE_PAUSE
== meShowWindowMode
)
132 const int nKeyCode
= rKEvt
.GetKeyCode().GetCode();
145 case awt::Key::CONTEXTMENU
:
146 // these keys will be handled by the slide show even
158 if( mxController
.is() )
159 bReturn
= mxController
->keyInput(rKEvt
);
165 mpViewShell
->KeyInput(rKEvt
,this);
169 Window::KeyInput(rKEvt
);
175 mpViewShell
->SetActiveWindow( this );
178 void ShowWindow::MouseButtonDown(const MouseEvent
& /*rMEvt*/)
180 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
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
)
204 mnFirstMouseMove
= 0;
205 mbMouseCursorHidden
= false;
206 maMouseTimer
.SetTimeout( HIDE_MOUSE_TIMEOUT
);
207 maMouseTimer
.Start();
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();
222 // current mousemove restarts the idle timer to hide the mouse
223 maMouseTimer
.Start();
228 mpViewShell
->SetActiveWindow( this );
231 void ShowWindow::MouseButtonUp(const MouseEvent
& rMEvt
)
233 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
237 else if( (SHOWWINDOWMODE_END
== meShowWindowMode
) && !rMEvt
.IsRight() )
241 else if( (( SHOWWINDOWMODE_BLANK
== meShowWindowMode
) || ( SHOWWINDOWMODE_PAUSE
== meShowWindowMode
))
242 && !rMEvt
.IsRight() )
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);
271 DrawWallpaper( rRect
, maShowBackground
);
273 if( SHOWWINDOWMODE_END
== meShowWindowMode
)
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()
292 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
296 void ShowWindow::SetEndMode()
298 if( !(( SHOWWINDOWMODE_NORMAL
== meShowWindowMode
) && mpViewShell
&& mpViewShell
->GetView()) )
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;
315 bool ShowWindow::SetPauseMode( sal_Int32 nTimeout
, Graphic
const * pLogo
)
317 rtl::Reference
< SlideShow
> xSlideShow
;
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;
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;
372 return( SHOWWINDOWMODE_BLANK
== meShowWindowMode
);
375 void ShowWindow::SetPreviewMode()
377 meShowWindowMode
= SHOWWINDOWMODE_PREVIEW
;
380 void ShowWindow::TerminateShow()
386 maShowBackground
= Wallpaper( COL_BLACK
);
387 meShowWindowMode
= SHOWWINDOWMODE_NORMAL
;
388 mnPauseTimeout
= SLIDE_NO_TIMEOUT
;
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
;
419 maShowBackground
= Wallpaper( COL_BLACK
);
420 meShowWindowMode
= SHOWWINDOWMODE_NORMAL
;
421 mnPauseTimeout
= SLIDE_NO_TIMEOUT
;
425 rtl::Reference
< SlideShow
> xSlideShow( SlideShow::GetSlideShow( mpViewShell
->GetViewShellBase() ) );
427 if( xSlideShow
.is() )
429 AddWindowToPaintView();
431 if( SHOWWINDOWMODE_BLANK
== eOldShowWindowMode
)
433 xSlideShow
->pause(false);
438 xSlideShow
->jumpToPageIndex( nPageIndexToRestart
);
443 mnRestartPageIndex
= PAGE_NO_END
;
446 if( mbShowNavigatorAfterSpecialMode
)
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
) );
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
) )
476 if (maLogo
.GetPrefMapMode().GetMapUnit() == MapUnit::MapPixel
)
477 aGrfSize
= PixelToLogic( maLogo
.GetPrefSize() );
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) );
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();
511 aText
+= aLocaleData
.getDuration( ::tools::Time( 0, 0, mnPauseTimeout
) );
513 pVDev
->DrawText( Point( aOffset
.Width(), 0 ), aText
);
514 DrawOutDev( Point( aOutOrg
.X(), aOffset
.Height() ), aVDevSize
, Point(), aVDevSize
, *pVDev
);
522 DrawText( Point( aOutOrg
.X() + aOffset
.Width(), aOutOrg
.Y() + aOffset
.Height() ), aText
);
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() );
541 DrawText( Point( aOutOrg
.X() + aTextSize
.Height(), aOutOrg
.Y() + aTextSize
.Height() ), aText
);
545 IMPL_LINK( ShowWindow
, PauseTimeoutHdl
, Timer
*, pTimer
, void )
547 if( !( --mnPauseTimeout
) )
551 DrawPauseScene( true );
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;
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();
591 GetChild( nChild
)->Show( false );
594 void ShowWindow::AddWindowToPaintView()
596 if( mpViewShell
->GetView() )
597 mpViewShell
->GetView()->AddWindowToPaintView( this, nullptr );
599 sal_uInt16 nChild
= GetChildCount();
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);
613 if (mpViewShell
!= nullptr)
615 xAcc
= mpViewShell
->CreateAccessibleDocumentView (this);
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: */