merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / slideshow / showwin.cxx
blob1310e049785bf81e0b4b10f51d9256b75c90561f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: showwin.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include <com/sun/star/awt/Key.hpp>
36 #include "showwindow.hxx"
38 #include <svtools/syslocale.hxx>
39 #include <sfx2/viewfrm.hxx>
42 #include "res_bmp.hrc"
43 #include "slideshow.hxx"
44 #include "ViewShellBase.hxx"
45 #include "slideshow.hxx"
46 #include "sdresid.hxx"
47 #include "helpids.h"
48 #include "strings.hrc"
49 #include <vcl/virdev.hxx>
51 using namespace ::com::sun::star;
53 namespace sd {
55 static const ULONG HIDE_MOUSE_TIMEOUT = 10000;
56 static const ULONG SHOW_MOUSE_TIMEOUT = 1000;
58 // =============================================================================
60 ShowWindow::ShowWindow( const ::rtl::Reference< SlideshowImpl >& xController, ::Window* pParent )
61 : ::sd::Window( pParent )
62 , mnPauseTimeout( SLIDE_NO_TIMEOUT )
63 , mnRestartPageIndex( PAGE_NO_END )
64 , meShowWindowMode(SHOWWINDOWMODE_NORMAL)
65 , mbShowNavigatorAfterSpecialMode( FALSE )
66 , mbMouseAutoHide(true)
67 , mbMouseCursorHidden(false)
68 , mnFirstMouseMove(0)
69 , mxController( xController )
71 SetOutDevViewType( OUTDEV_VIEWTYPE_SLIDESHOW );
73 // Do never mirror the preview window. This explicitly includes right
74 // to left writing environments.
75 EnableRTL (FALSE);
77 MapMode aMap(GetMapMode());
78 aMap.SetMapUnit(MAP_100TH_MM);
79 SetMapMode(aMap);
81 // HelpId setzen
82 SetHelpId( HID_SD_WIN_PRESENTATION );
83 SetUniqueId( HID_SD_WIN_PRESENTATION );
85 maPauseTimer.SetTimeoutHdl( LINK( this, ShowWindow, PauseTimeoutHdl ) );
86 maPauseTimer.SetTimeout( 1000 );
87 maMouseTimer.SetTimeoutHdl( LINK( this, ShowWindow, MouseTimeoutHdl ) );
88 maMouseTimer.SetTimeout( HIDE_MOUSE_TIMEOUT );
90 maShowBackground = Wallpaper( Color( COL_BLACK ) );
91 // SetBackground( Wallpaper( Color( COL_BLACK ) ) );
92 SetBackground(); // avoids that VCL paints any background!
93 GetParent()->Show();
94 AddEventListener( LINK( this, ShowWindow, EventHdl ) );
97 ShowWindow::~ShowWindow(void)
99 maPauseTimer.Stop();
100 maMouseTimer.Stop();
103 /*************************************************************************
105 |* Keyboard event
107 \************************************************************************/
109 void ShowWindow::KeyInput(const KeyEvent& rKEvt)
111 BOOL bReturn = FALSE;
113 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode )
115 TerminateShow();
116 bReturn = true;
118 else if( SHOWWINDOWMODE_END == meShowWindowMode )
120 const int nKeyCode = rKEvt.GetKeyCode().GetCode();
121 switch( nKeyCode )
123 case KEY_PAGEUP:
124 case KEY_LEFT:
125 case KEY_UP:
126 case KEY_P:
127 case KEY_HOME:
128 case KEY_END:
129 case awt::Key::CONTEXTMENU:
130 // these keys will be handled by the slide show even
131 // while in end mode
132 break;
133 default:
134 TerminateShow();
135 bReturn = true;
138 else if( SHOWWINDOWMODE_BLANK == meShowWindowMode )
140 RestartShow();
141 bReturn = true;
143 else if( SHOWWINDOWMODE_PAUSE == meShowWindowMode )
145 const int nKeyCode = rKEvt.GetKeyCode().GetCode();
146 switch( nKeyCode )
148 case KEY_ESCAPE:
149 TerminateShow();
150 bReturn = true;
151 break;
152 case KEY_PAGEUP:
153 case KEY_RIGHT:
154 case KEY_UP:
155 case KEY_P:
156 case KEY_HOME:
157 case KEY_END:
158 case awt::Key::CONTEXTMENU:
159 // these keys will be handled by the slide show even
160 // while in end mode
161 break;
162 default:
163 RestartShow();
164 bReturn = true;
165 break;
169 if( !bReturn )
171 if( mxController.is() )
172 bReturn = mxController->keyInput(rKEvt);
174 if( !bReturn )
176 if( mpViewShell )
178 mpViewShell->KeyInput(rKEvt,this);
180 else
182 Window::KeyInput(rKEvt);
187 if( mpViewShell )
188 mpViewShell->SetActiveWindow( this );
191 /*************************************************************************
193 |* MouseButtonDown event
195 \************************************************************************/
197 void ShowWindow::MouseButtonDown(const MouseEvent& /*rMEvt*/)
199 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode )
201 TerminateShow();
203 else if( mpViewShell )
205 mpViewShell->SetActiveWindow( this );
209 /*************************************************************************
211 |* MouseMove event
213 \************************************************************************/
215 void ShowWindow::MouseMove(const MouseEvent& /*rMEvt*/)
217 if( mbMouseAutoHide )
219 if( mbMouseCursorHidden )
221 if( mnFirstMouseMove )
223 // if this is not the first mouse move while hidden, see if
224 // enough time has pasted to show mouse pointer again
225 ULONG nTime = Time::GetSystemTicks();
226 if( (nTime - mnFirstMouseMove) >= SHOW_MOUSE_TIMEOUT )
228 ShowPointer( TRUE );
229 mnFirstMouseMove = 0;
230 mbMouseCursorHidden = false;
231 maMouseTimer.SetTimeout( HIDE_MOUSE_TIMEOUT );
232 maMouseTimer.Start();
235 else
237 // if this is the first mouse move, note current
238 // time and start idle timer to cancel show mouse pointer
239 // again if not enough mouse movement is measured
240 mnFirstMouseMove = Time::GetSystemTicks();
241 maMouseTimer.SetTimeout( 2*SHOW_MOUSE_TIMEOUT );
242 maMouseTimer.Start();
245 else
247 // current mousemove restarts the idle timer to hide the mouse
248 maMouseTimer.Start();
252 if( mpViewShell )
253 mpViewShell->SetActiveWindow( this );
256 /*************************************************************************
258 |* MouseButtonUp event
260 \************************************************************************/
262 void ShowWindow::MouseButtonUp(const MouseEvent& rMEvt)
264 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode )
266 TerminateShow();
268 else if( (SHOWWINDOWMODE_END == meShowWindowMode) && !rMEvt.IsRight() )
270 TerminateShow();
272 else if( (( SHOWWINDOWMODE_BLANK == meShowWindowMode ) || ( SHOWWINDOWMODE_PAUSE == meShowWindowMode ))
273 && !rMEvt.IsRight() )
275 RestartShow();
277 else
279 if( mxController.is() )
280 mxController->mouseButtonUp( rMEvt );
284 /*************************************************************************
286 |* Paint-Event: wenn FuSlideShow noch erreichbar ist, weiterleiten
288 \************************************************************************/
290 void ShowWindow::Paint(const Rectangle& rRect)
292 if( (meShowWindowMode == SHOWWINDOWMODE_NORMAL) || (meShowWindowMode == SHOWWINDOWMODE_PREVIEW) )
295 Region aOldClipRegion( GetClipRegion() );
297 Region aClipRegion( rRect );
298 aClipRegion.Exclude( maPresArea );
299 SetClipRegion( aClipRegion );
301 DrawWallpaper( rRect, maShowBackground );
303 SetClipRegion( aOldClipRegion );
305 if( mxController.is() )
307 mxController->paint(rRect);
309 else if(mpViewShell )
311 mpViewShell->Paint(rRect, this);
314 else
316 DrawWallpaper( rRect, maShowBackground );
318 if( SHOWWINDOWMODE_END == meShowWindowMode )
320 DrawEndScene();
322 else if( SHOWWINDOWMODE_PAUSE == meShowWindowMode )
324 DrawPauseScene( FALSE );
326 else if( SHOWWINDOWMODE_BLANK == meShowWindowMode )
328 DrawBlankScene();
333 /*************************************************************************
335 |* Notify
337 \************************************************************************/
339 long ShowWindow::Notify(NotifyEvent& rNEvt)
341 long nOK = FALSE;
343 if( mpViewShell && rNEvt.GetType() == EVENT_GETFOCUS )
345 NotifyEvent aNEvt(EVENT_GETFOCUS, this);
346 nOK = mpViewShell->GetViewFrame()->GetWindow().Notify(aNEvt);
349 if (!nOK)
350 nOK = Window::Notify(rNEvt);
352 return nOK;
356 // -----------------------------------------------------------------------------
358 void ShowWindow::GetFocus()
360 // Basisklasse
361 Window::GetFocus();
363 if( mpViewShell )
365 NotifyEvent aNEvt(EVENT_GETFOCUS, this);
366 mpViewShell->GetViewFrame()->GetWindow().Notify(aNEvt);
371 // -----------------------------------------------------------------------------
373 void ShowWindow::LoseFocus()
375 Window::LoseFocus();
377 if( SHOWWINDOWMODE_PREVIEW == meShowWindowMode)
378 TerminateShow();
381 // -----------------------------------------------------------------------------
383 void ShowWindow::Resize()
385 ::sd::Window::Resize();
388 // -----------------------------------------------------------------------------
390 void ShowWindow::Move()
392 ::sd::Window::Move();
395 // -----------------------------------------------------------------------------
397 BOOL ShowWindow::SetEndMode()
399 if( ( SHOWWINDOWMODE_NORMAL == meShowWindowMode ) && mpViewShell && mpViewShell->GetView() )
401 DeleteWindowFromPaintView();
402 meShowWindowMode = SHOWWINDOWMODE_END;
403 // maShowBackground = GetBackground();
404 // SetBackground( Wallpaper( Color( COL_BLACK ) ) );
405 maShowBackground = Wallpaper( Color( COL_BLACK ) );
407 // hide navigator if it is visible
408 if( mpViewShell->GetViewFrame()->GetChildWindow( SID_NAVIGATOR ) )
410 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, FALSE );
411 mbShowNavigatorAfterSpecialMode = TRUE;
414 Invalidate();
417 return( SHOWWINDOWMODE_END == meShowWindowMode );
420 // -----------------------------------------------------------------------------
422 BOOL ShowWindow::SetPauseMode( sal_Int32 nPageIndexToRestart, sal_Int32 nTimeout, Graphic* pLogo )
424 rtl::Reference< SlideShow > xSlideShow;
426 if( mpViewShell )
427 xSlideShow = SlideShow::GetSlideShow( mpViewShell->GetViewShellBase() );
429 if( xSlideShow.is() && !nTimeout )
431 xSlideShow->jumpToPageIndex( nPageIndexToRestart );
433 else if( ( SHOWWINDOWMODE_NORMAL == meShowWindowMode ) && mpViewShell && mpViewShell->GetView() )
435 DeleteWindowFromPaintView();
436 mnPauseTimeout = nTimeout;
437 mnRestartPageIndex = nPageIndexToRestart;
438 meShowWindowMode = SHOWWINDOWMODE_PAUSE;
439 // maShowBackground = GetBackground();
440 // SetBackground( Wallpaper( Color( COL_BLACK ) ) );
441 maShowBackground = Wallpaper( Color( COL_BLACK ) );
443 // hide navigator if it is visible
444 if( mpViewShell->GetViewFrame()->GetChildWindow( SID_NAVIGATOR ) )
446 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, FALSE );
447 mbShowNavigatorAfterSpecialMode = TRUE;
450 if( pLogo )
451 maLogo = *pLogo;
453 Invalidate();
455 if( SLIDE_NO_TIMEOUT != mnPauseTimeout )
456 maPauseTimer.Start();
459 return( SHOWWINDOWMODE_PAUSE == meShowWindowMode );
462 // -----------------------------------------------------------------------------
464 BOOL ShowWindow::SetBlankMode( sal_Int32 nPageIndexToRestart, const Color& rBlankColor )
466 if( ( SHOWWINDOWMODE_NORMAL == meShowWindowMode ) && mpViewShell && mpViewShell->GetView() )
468 DeleteWindowFromPaintView();
469 mnRestartPageIndex = nPageIndexToRestart;
470 meShowWindowMode = SHOWWINDOWMODE_BLANK;
471 // maShowBackground = GetBackground();
472 // SetBackground( Wallpaper( rBlankColor ) );
473 maShowBackground = Wallpaper( rBlankColor );
475 // hide navigator if it is visible
476 if( mpViewShell->GetViewFrame()->GetChildWindow( SID_NAVIGATOR ) )
478 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, FALSE );
479 mbShowNavigatorAfterSpecialMode = TRUE;
482 Invalidate();
485 return( SHOWWINDOWMODE_BLANK == meShowWindowMode );
488 // -----------------------------------------------------------------------------
490 void ShowWindow::SetPreviewMode()
492 meShowWindowMode = SHOWWINDOWMODE_PREVIEW;
495 // -----------------------------------------------------------------------------
497 void ShowWindow::TerminateShow()
499 maLogo.Clear();
500 maPauseTimer.Stop();
501 maMouseTimer.Stop();
502 Erase();
503 // SetBackground( maShowBackground );
504 maShowBackground = Wallpaper( Color( COL_BLACK ) );
505 meShowWindowMode = SHOWWINDOWMODE_NORMAL;
506 mnPauseTimeout = SLIDE_NO_TIMEOUT;
508 if( mpViewShell )
510 // show navigator?
511 if( mbShowNavigatorAfterSpecialMode )
513 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, TRUE );
514 mbShowNavigatorAfterSpecialMode = FALSE;
518 if( mxController.is() )
519 mxController->endPresentation();
521 mnRestartPageIndex = PAGE_NO_END;
524 // -----------------------------------------------------------------------------
526 void ShowWindow::RestartShow()
528 RestartShow( mnRestartPageIndex );
531 // -----------------------------------------------------------------------------
533 void ShowWindow::RestartShow( sal_Int32 nPageIndexToRestart )
536 ShowWindowMode eOldShowWindowMode = meShowWindowMode;
538 maLogo.Clear();
539 maPauseTimer.Stop();
540 Erase();
541 // SetBackground( maShowBackground );
542 maShowBackground = Wallpaper( Color( COL_BLACK ) );
543 meShowWindowMode = SHOWWINDOWMODE_NORMAL;
544 mnPauseTimeout = SLIDE_NO_TIMEOUT;
546 if( mpViewShell )
548 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( mpViewShell->GetViewShellBase() ) );
550 if( xSlideShow.is() )
552 AddWindowToPaintView();
554 if( SHOWWINDOWMODE_BLANK == eOldShowWindowMode )
556 xSlideShow->pause(false);
557 Invalidate();
559 else
561 xSlideShow->jumpToPageIndex( nPageIndexToRestart );
566 mnRestartPageIndex = PAGE_NO_END;
568 // show navigator?
569 if( mbShowNavigatorAfterSpecialMode )
571 mpViewShell->GetViewFrame()->ShowChildWindow( SID_NAVIGATOR, TRUE );
572 mbShowNavigatorAfterSpecialMode = FALSE;
576 // -----------------------------------------------------------------------------
578 void ShowWindow::DrawPauseScene( BOOL bTimeoutOnly )
580 const MapMode& rMap = GetMapMode();
581 const Point aOutOrg( PixelToLogic( Point() ) );
582 const Size aOutSize( GetOutputSize() );
583 const Size aTextSize( LogicToLogic( Size( 0, 14 ), MAP_POINT, rMap ) );
584 const Size aOffset( LogicToLogic( Size( 1000, 1000 ), MAP_100TH_MM, rMap ) );
585 String aText( SdResId( STR_PRES_PAUSE ) );
586 BOOL bDrawn = FALSE;
588 Font aFont( GetSettings().GetStyleSettings().GetMenuFont() );
589 const Font aOldFont( GetFont() );
591 aFont.SetSize( aTextSize );
592 aFont.SetColor( COL_WHITE );
593 aFont.SetCharSet( aOldFont.GetCharSet() );
594 aFont.SetLanguage( aOldFont.GetLanguage() );
596 if( !bTimeoutOnly && ( maLogo.GetType() != GRAPHIC_NONE ) )
598 Size aGrfSize;
600 if( maLogo.GetPrefMapMode() == MAP_PIXEL )
601 aGrfSize = PixelToLogic( maLogo.GetPrefSize() );
602 else
603 aGrfSize = LogicToLogic( maLogo.GetPrefSize(), maLogo.GetPrefMapMode(), rMap );
605 const Point aGrfPos( Max( aOutOrg.X() + aOutSize.Width() - aGrfSize.Width() - aOffset.Width(), aOutOrg.X() ),
606 Max( aOutOrg.Y() + aOutSize.Height() - aGrfSize.Height() - aOffset.Height(), aOutOrg.Y() ) );
608 if( maLogo.IsAnimated() )
609 maLogo.StartAnimation( this, aGrfPos, aGrfSize, (long) this );
610 else
611 maLogo.Draw( this, aGrfPos, aGrfSize );
614 if( SLIDE_NO_TIMEOUT != mnPauseTimeout )
616 MapMode aVMap( rMap );
617 VirtualDevice aVDev( *this );
619 aVMap.SetOrigin( Point() );
620 aVDev.SetMapMode( aVMap );
621 aVDev.SetBackground( Wallpaper( Color( COL_BLACK ) ) );
623 // set font first, to determine real output height
624 aVDev.SetFont( aFont );
626 const Size aVDevSize( aOutSize.Width(), aVDev.GetTextHeight() );
628 if( aVDev.SetOutputSize( aVDevSize ) )
630 // Note: if performance gets an issue here, we can use NumberFormatter directly
631 SvtSysLocale aSysLocale;
632 const LocaleDataWrapper& aLocaleData = aSysLocale.GetLocaleData();
634 aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " ( " ));
635 aText += aLocaleData.getDuration( Time( 0, 0, mnPauseTimeout ) );
636 aText.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " )" ));
637 aVDev.DrawText( Point( aOffset.Width(), 0 ), aText );
638 DrawOutDev( Point( aOutOrg.X(), aOffset.Height() ), aVDevSize, Point(), aVDevSize, aVDev );
639 bDrawn = TRUE;
643 if( !bDrawn )
645 SetFont( aFont );
646 DrawText( Point( aOutOrg.X() + aOffset.Width(), aOutOrg.Y() + aOffset.Height() ), aText );
647 SetFont( aOldFont );
651 // -----------------------------------------------------------------------------
653 void ShowWindow::DrawEndScene()
655 const Font aOldFont( GetFont() );
656 Font aFont( GetSettings().GetStyleSettings().GetMenuFont() );
658 const Point aOutOrg( PixelToLogic( Point() ) );
659 const Size aTextSize( LogicToLogic( Size( 0, 14 ), MAP_POINT, GetMapMode() ) );
660 const String aText( SdResId( STR_PRES_SOFTEND ) );
662 aFont.SetSize( aTextSize );
663 aFont.SetColor( COL_WHITE );
664 aFont.SetCharSet( aOldFont.GetCharSet() );
665 aFont.SetLanguage( aOldFont.GetLanguage() );
666 SetFont( aFont );
667 DrawText( Point( aOutOrg.X() + aTextSize.Height(), aOutOrg.Y() + aTextSize.Height() ), aText );
668 SetFont( aOldFont );
671 // -----------------------------------------------------------------------------
673 void ShowWindow::DrawBlankScene()
675 // just blank through background color => nothing to be done here
678 // -----------------------------------------------------------------------------
680 IMPL_LINK( ShowWindow, PauseTimeoutHdl, Timer*, pTimer )
682 if( !( --mnPauseTimeout ) )
683 RestartShow();
684 else
686 DrawPauseScene( TRUE );
687 pTimer->Start();
690 return 0L;
693 IMPL_LINK( ShowWindow, MouseTimeoutHdl, Timer*, EMPTYARG )
695 if( mbMouseCursorHidden )
697 // not enough mouse movements since first recording so
698 // cancle show mouse pointer for now
699 mnFirstMouseMove = 0;
701 else
703 // mouse has been idle to long, hide pointer
704 ShowPointer( FALSE );
705 mbMouseCursorHidden = true;
707 return 0L;
710 IMPL_LINK( ShowWindow, EventHdl, VclWindowEvent*, pEvent )
712 if( mbMouseAutoHide )
714 if (pEvent->GetId() == VCLEVENT_WINDOW_SHOW)
716 maMouseTimer.SetTimeout( HIDE_MOUSE_TIMEOUT );
717 maMouseTimer.Start();
720 return 0L;
723 void ShowWindow::SetPresentationArea( const Rectangle& rPresArea )
725 maPresArea = rPresArea;
728 void ShowWindow::DeleteWindowFromPaintView()
730 if( mpViewShell->GetView() )
731 mpViewShell->GetView()->DeleteWindowFromPaintView( this );
733 USHORT nChild = GetChildCount();
734 while( nChild-- )
735 GetChild( nChild )->Show( FALSE );
738 void ShowWindow::AddWindowToPaintView()
740 if( mpViewShell->GetView() )
741 mpViewShell->GetView()->AddWindowToPaintView( this );
743 USHORT nChild = GetChildCount();
744 while( nChild-- )
745 GetChild( nChild )->Show( TRUE );
748 } // end of namespace sd