update dev300-m58
[ooovba.git] / sd / source / ui / tools / IdleDetection.cxx
blob32a15f07752e7ab68fbf65d4983144eac8f71a4b
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: IdleDetection.cxx,v $
10 * $Revision: 1.12 $
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 "tools/IdleDetection.hxx"
36 #include "ViewShell.hxx"
37 #include "slideshow.hxx"
38 #include "ViewShellBase.hxx"
40 #include <vcl/window.hxx>
41 #include <sfx2/viewfrm.hxx>
43 #include <com/sun/star/frame/XFrame.hdl>
44 #include <vcl/svapp.hxx>
46 using namespace ::com::sun::star;
48 namespace sd { namespace tools {
51 sal_Int32 IdleDetection::GetIdleState (const ::Window* pWindow)
53 sal_Int32 nResult (CheckInputPending() | CheckSlideShowRunning());
54 if (pWindow != NULL)
55 nResult |= CheckWindowPainting(*pWindow);
56 return nResult;
62 sal_Int32 IdleDetection::CheckInputPending (void)
64 if (GetpApp()->AnyInput(INPUT_MOUSE | INPUT_KEYBOARD | INPUT_PAINT))
65 return IDET_SYSTEM_EVENT_PENDING;
66 else
67 return IDET_IDLE;
73 sal_Int32 IdleDetection::CheckSlideShowRunning (void)
75 sal_Int32 eResult (IDET_IDLE);
77 bool bIsSlideShowShowing = false;
79 // Iterate over all view frames.
80 SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
81 for (pViewFrame = SfxViewFrame::GetFirst();
82 pViewFrame!=NULL && !bIsSlideShowShowing;
83 pViewFrame = SfxViewFrame::GetNext(*pViewFrame))
85 // Ignore the current frame when it does not exist, is not valid, or
86 // is not active.
87 bool bIgnoreFrame (true);
88 if (pViewFrame->GetFrame() != NULL)
90 uno::Reference<frame::XFrame> xFrame (pViewFrame->GetFrame()->GetFrameInterface());
91 try
93 if (xFrame.is() && xFrame->isActive())
94 bIgnoreFrame = false;
96 catch (uno::RuntimeException e)
98 (void) e;
101 if (bIgnoreFrame)
102 continue;
104 // Get sd::ViewShell from active frame.
105 ViewShellBase* pBase = ViewShellBase::GetViewShellBase(pViewFrame);
106 if (pBase != NULL)
108 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( *pBase ) );
109 if( xSlideShow.is() && xSlideShow->isRunning() )
111 if (xSlideShow->isFullScreen())
112 eResult |= IDET_FULL_SCREEN_SHOW_ACTIVE;
113 else
114 eResult |= IDET_WINDOW_SHOW_ACTIVE;
119 return eResult;
125 sal_Int32 IdleDetection::CheckWindowPainting (const ::Window& rWindow)
127 if (rWindow.IsInPaint())
128 return IDET_WINDOW_PAINTING;
129 else
130 return IDET_IDLE;
133 } } // end of namespace ::sd::tools