xref: /aoo41x/main/sd/source/ui/tools/IdleDetection.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "tools/IdleDetection.hxx"
32 
33 #include "ViewShell.hxx"
34 #include "slideshow.hxx"
35 #include "ViewShellBase.hxx"
36 
37 #include <vcl/window.hxx>
38 #include <sfx2/viewfrm.hxx>
39 
40 #include <com/sun/star/frame/XFrame.hdl>
41 #include <vcl/svapp.hxx>
42 
43 using namespace ::com::sun::star;
44 
45 namespace sd { namespace tools {
46 
47 
48 sal_Int32 IdleDetection::GetIdleState (const ::Window* pWindow)
49 {
50     sal_Int32 nResult (CheckInputPending() | CheckSlideShowRunning());
51     if (pWindow != NULL)
52         nResult |= CheckWindowPainting(*pWindow);
53     return nResult;
54 }
55 
56 
57 
58 
59 sal_Int32 IdleDetection::CheckInputPending (void)
60 {
61     if (GetpApp()->AnyInput(INPUT_MOUSE | INPUT_KEYBOARD | INPUT_PAINT))
62         return IDET_SYSTEM_EVENT_PENDING;
63     else
64         return IDET_IDLE;
65 }
66 
67 
68 
69 
70 sal_Int32 IdleDetection::CheckSlideShowRunning (void)
71 {
72     sal_Int32 eResult (IDET_IDLE);
73 
74 	bool bIsSlideShowShowing = false;
75 
76 	// Iterate over all view frames.
77 	SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
78 	for (pViewFrame = SfxViewFrame::GetFirst();
79          pViewFrame!=NULL && !bIsSlideShowShowing;
80          pViewFrame = SfxViewFrame::GetNext(*pViewFrame))
81     {
82         // Ignore the current frame when it does not exist, is not valid, or
83         // is not active.
84         bool bIgnoreFrame (true);
85         uno::Reference<frame::XFrame> xFrame (pViewFrame->GetFrame().GetFrameInterface());
86         try
87         {
88             if (xFrame.is() && xFrame->isActive())
89                 bIgnoreFrame = false;
90         }
91         catch (uno::RuntimeException e)
92         {
93             (void) e;
94         }
95         if (bIgnoreFrame)
96             continue;
97 
98 		// Get sd::ViewShell from active frame.
99 		ViewShellBase* pBase = ViewShellBase::GetViewShellBase(pViewFrame);
100 		if (pBase != NULL)
101 		{
102 			rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( *pBase ) );
103 			if( xSlideShow.is() && xSlideShow->isRunning() )
104 			{
105 				if (xSlideShow->isFullScreen())
106 					eResult |= IDET_FULL_SCREEN_SHOW_ACTIVE;
107 				else
108 					eResult |= IDET_WINDOW_SHOW_ACTIVE;
109 			}
110 		}
111 	}
112 
113 	return eResult;
114 }
115 
116 
117 
118 
119 sal_Int32 IdleDetection::CheckWindowPainting (const ::Window& rWindow)
120 {
121     if (rWindow.IsInPaint())
122         return IDET_WINDOW_PAINTING;
123     else
124         return IDET_IDLE;
125 }
126 
127 } } // end of namespace ::sd::tools
128