1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: IdleDetection.cxx,v $
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());
55 nResult
|= CheckWindowPainting(*pWindow
);
62 sal_Int32
IdleDetection::CheckInputPending (void)
64 if (GetpApp()->AnyInput(INPUT_MOUSE
| INPUT_KEYBOARD
| INPUT_PAINT
))
65 return IDET_SYSTEM_EVENT_PENDING
;
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
87 bool bIgnoreFrame (true);
88 if (pViewFrame
->GetFrame() != NULL
)
90 uno::Reference
<frame::XFrame
> xFrame (pViewFrame
->GetFrame()->GetFrameInterface());
93 if (xFrame
.is() && xFrame
->isActive())
96 catch (uno::RuntimeException e
)
104 // Get sd::ViewShell from active frame.
105 ViewShellBase
* pBase
= ViewShellBase::GetViewShellBase(pViewFrame
);
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
;
114 eResult
|= IDET_WINDOW_SHOW_ACTIVE
;
125 sal_Int32
IdleDetection::CheckWindowPainting (const ::Window
& rWindow
)
127 if (rWindow
.IsInPaint())
128 return IDET_WINDOW_PAINTING
;
133 } } // end of namespace ::sd::tools