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"
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"
32 #include "strings.hrc"
34 #include <vcl/settings.hxx>
35 #include <vcl/virdev.hxx>
37 using namespace ::com::sun::star
;
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)
53 , mxController( xController
)
55 SetOutDevViewType( OUTDEV_VIEWTYPE_SLIDESHOW
);
57 // Do never mirror the preview window. This explicitly includes right
58 // to left writing environments.
61 MapMode
aMap(GetMapMode());
62 aMap
.SetMapUnit(MAP_100TH_MM
);
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!
77 AddEventListener( LINK( this, ShowWindow
, EventHdl
) );
80 ShowWindow::~ShowWindow()
85 void ShowWindow::dispose()
89 ::sd::Window::dispose();
92 void ShowWindow::KeyInput(const KeyEvent
& rKEvt
)
96 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
101 else if( SHOWWINDOWMODE_END
== meShowWindowMode
)
103 const int nKeyCode
= rKEvt
.GetKeyCode().GetCode();
112 case awt::Key::CONTEXTMENU
:
113 // these keys will be handled by the slide show even
121 else if( SHOWWINDOWMODE_BLANK
== meShowWindowMode
)
126 else if( SHOWWINDOWMODE_PAUSE
== meShowWindowMode
)
128 const int nKeyCode
= rKEvt
.GetKeyCode().GetCode();
141 case awt::Key::CONTEXTMENU
:
142 // these keys will be handled by the slide show even
154 if( mxController
.is() )
155 bReturn
= mxController
->keyInput(rKEvt
);
161 mpViewShell
->KeyInput(rKEvt
,this);
165 Window::KeyInput(rKEvt
);
171 mpViewShell
->SetActiveWindow( this );
174 void ShowWindow::MouseButtonDown(const MouseEvent
& /*rMEvt*/)
176 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
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
)
200 mnFirstMouseMove
= 0;
201 mbMouseCursorHidden
= false;
202 maMouseTimer
.SetTimeout( HIDE_MOUSE_TIMEOUT
);
203 maMouseTimer
.Start();
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();
218 // current mousemove restarts the idle timer to hide the mouse
219 maMouseTimer
.Start();
224 mpViewShell
->SetActiveWindow( this );
227 void ShowWindow::MouseButtonUp(const MouseEvent
& rMEvt
)
229 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
233 else if( (SHOWWINDOWMODE_END
== meShowWindowMode
) && !rMEvt
.IsRight() )
237 else if( (( SHOWWINDOWMODE_BLANK
== meShowWindowMode
) || ( SHOWWINDOWMODE_PAUSE
== meShowWindowMode
))
238 && !rMEvt
.IsRight() )
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);
267 DrawWallpaper( rRect
, maShowBackground
);
269 if( SHOWWINDOWMODE_END
== meShowWindowMode
)
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()
290 void ShowWindow::LoseFocus()
294 if( SHOWWINDOWMODE_PREVIEW
== meShowWindowMode
)
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;
326 return( SHOWWINDOWMODE_END
== meShowWindowMode
);
329 bool ShowWindow::SetPauseMode( sal_Int32 nPageIndexToRestart
, sal_Int32 nTimeout
, Graphic
* pLogo
)
331 rtl::Reference
< SlideShow
> xSlideShow
;
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;
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;
386 return( SHOWWINDOWMODE_BLANK
== meShowWindowMode
);
389 void ShowWindow::SetPreviewMode()
391 meShowWindowMode
= SHOWWINDOWMODE_PREVIEW
;
394 void ShowWindow::TerminateShow()
400 maShowBackground
= Wallpaper( Color( COL_BLACK
) );
401 meShowWindowMode
= SHOWWINDOWMODE_NORMAL
;
402 mnPauseTimeout
= SLIDE_NO_TIMEOUT
;
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
;
433 maShowBackground
= Wallpaper( Color( COL_BLACK
) );
434 meShowWindowMode
= SHOWWINDOWMODE_NORMAL
;
435 mnPauseTimeout
= SLIDE_NO_TIMEOUT
;
439 rtl::Reference
< SlideShow
> xSlideShow( SlideShow::GetSlideShow( mpViewShell
->GetViewShellBase() ) );
441 if( xSlideShow
.is() )
443 AddWindowToPaintView();
445 if( SHOWWINDOWMODE_BLANK
== eOldShowWindowMode
)
447 xSlideShow
->pause(false);
452 xSlideShow
->jumpToPageIndex( nPageIndexToRestart
);
457 mnRestartPageIndex
= PAGE_NO_END
;
460 if( mbShowNavigatorAfterSpecialMode
)
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
) );
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
) )
490 if( maLogo
.GetPrefMapMode() == MAP_PIXEL
)
491 aGrfSize
= PixelToLogic( maLogo
.GetPrefSize() );
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) );
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();
525 aText
+= aLocaleData
.getDuration( ::tools::Time( 0, 0, mnPauseTimeout
) );
527 pVDev
->DrawText( Point( aOffset
.Width(), 0 ), aText
);
528 DrawOutDev( Point( aOutOrg
.X(), aOffset
.Height() ), aVDevSize
, Point(), aVDevSize
, *pVDev
.get() );
536 DrawText( Point( aOutOrg
.X() + aOffset
.Width(), aOutOrg
.Y() + aOffset
.Height() ), aText
);
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() );
555 DrawText( Point( aOutOrg
.X() + aTextSize
.Height(), aOutOrg
.Y() + aTextSize
.Height() ), aText
);
559 IMPL_LINK_TYPED( ShowWindow
, PauseTimeoutHdl
, Timer
*, pTimer
, void )
561 if( !( --mnPauseTimeout
) )
565 DrawPauseScene( true );
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;
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();
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();
611 GetChild( nChild
)->Show( false );
614 void ShowWindow::AddWindowToPaintView()
616 if( mpViewShell
->GetView() )
617 mpViewShell
->GetView()->AddWindowToPaintView( this, 0 );
619 sal_uInt16 nChild
= GetChildCount();
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);
634 if (mpViewShell
!= NULL
)
636 xAcc
= mpViewShell
->CreateAccessibleDocumentView (this);
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: */