xref: /aoo41x/main/sd/source/ui/tools/IdleDetection.cxx (revision 79aad27f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include "tools/IdleDetection.hxx"
28 
29 #include "ViewShell.hxx"
30 #include "slideshow.hxx"
31 #include "ViewShellBase.hxx"
32 
33 #include <vcl/window.hxx>
34 #include <sfx2/viewfrm.hxx>
35 
36 #include <com/sun/star/frame/XFrame.hdl>
37 #include <vcl/svapp.hxx>
38 
39 using namespace ::com::sun::star;
40 
41 namespace sd { namespace tools {
42 
43 
GetIdleState(const::Window * pWindow)44 sal_Int32 IdleDetection::GetIdleState (const ::Window* pWindow)
45 {
46     sal_Int32 nResult (CheckInputPending() | CheckSlideShowRunning());
47     if (pWindow != NULL)
48         nResult |= CheckWindowPainting(*pWindow);
49     return nResult;
50 }
51 
52 
53 
54 
CheckInputPending(void)55 sal_Int32 IdleDetection::CheckInputPending (void)
56 {
57     if (GetpApp()->AnyInput(INPUT_MOUSE | INPUT_KEYBOARD | INPUT_PAINT))
58         return IDET_SYSTEM_EVENT_PENDING;
59     else
60         return IDET_IDLE;
61 }
62 
63 
64 
65 
CheckSlideShowRunning(void)66 sal_Int32 IdleDetection::CheckSlideShowRunning (void)
67 {
68     sal_Int32 eResult (IDET_IDLE);
69 
70 	bool bIsSlideShowShowing = false;
71 
72 	// Iterate over all view frames.
73 	SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
74 	for (pViewFrame = SfxViewFrame::GetFirst();
75          pViewFrame!=NULL && !bIsSlideShowShowing;
76          pViewFrame = SfxViewFrame::GetNext(*pViewFrame))
77     {
78         // Ignore the current frame when it does not exist, is not valid, or
79         // is not active.
80         bool bIgnoreFrame (true);
81         uno::Reference<frame::XFrame> xFrame (pViewFrame->GetFrame().GetFrameInterface());
82         try
83         {
84             if (xFrame.is() && xFrame->isActive())
85                 bIgnoreFrame = false;
86         }
87         catch (uno::RuntimeException e)
88         {
89             (void) e;
90         }
91         if (bIgnoreFrame)
92             continue;
93 
94 		// Get sd::ViewShell from active frame.
95 		ViewShellBase* pBase = ViewShellBase::GetViewShellBase(pViewFrame);
96 		if (pBase != NULL)
97 		{
98 			rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( *pBase ) );
99 			if( xSlideShow.is() && xSlideShow->isRunning() )
100 			{
101 				if (xSlideShow->isFullScreen())
102 					eResult |= IDET_FULL_SCREEN_SHOW_ACTIVE;
103 				else
104 					eResult |= IDET_WINDOW_SHOW_ACTIVE;
105 			}
106 		}
107 	}
108 
109 	return eResult;
110 }
111 
112 
113 
114 
CheckWindowPainting(const::Window & rWindow)115 sal_Int32 IdleDetection::CheckWindowPainting (const ::Window& rWindow)
116 {
117     if (rWindow.IsInPaint())
118         return IDET_WINDOW_PAINTING;
119     else
120         return IDET_IDLE;
121 }
122 
123 } } // end of namespace ::sd::tools
124