1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/IdleDetection.hxx>
22 #include <ViewShell.hxx>
23 #include <slideshow.hxx>
24 #include <ViewShellBase.hxx>
26 #include <vcl/window.hxx>
27 #include <sfx2/viewfrm.hxx>
29 #include <com/sun/star/frame/XFrame.hpp>
30 #include <vcl/svapp.hxx>
32 using namespace ::com::sun::star
;
34 namespace sd
{ namespace tools
{
36 IdleState
IdleDetection::GetIdleState (const vcl::Window
* pWindow
)
38 IdleState
nResult (CheckInputPending() | CheckSlideShowRunning());
39 if (pWindow
!= nullptr)
40 nResult
|= CheckWindowPainting(*pWindow
);
44 IdleState
IdleDetection::CheckInputPending()
46 if (Application::AnyInput(VclInputFlags::MOUSE
| VclInputFlags::KEYBOARD
| VclInputFlags::PAINT
))
47 return IdleState::SystemEventPending
;
49 return IdleState::Idle
;
52 IdleState
IdleDetection::CheckSlideShowRunning()
54 IdleState
eResult (IdleState::Idle
);
56 // Iterate over all view frames.
57 for (SfxViewFrame
* pViewFrame
= SfxViewFrame::GetFirst();
59 pViewFrame
= SfxViewFrame::GetNext(*pViewFrame
))
61 // Ignore the current frame when it does not exist, is not valid, or
63 bool bIgnoreFrame (true);
64 uno::Reference
<frame::XFrame
> xFrame (pViewFrame
->GetFrame().GetFrameInterface());
67 if (xFrame
.is() && xFrame
->isActive())
70 catch (const uno::RuntimeException
&)
76 // Get sd::ViewShell from active frame.
77 ViewShellBase
* pBase
= ViewShellBase::GetViewShellBase(pViewFrame
);
80 rtl::Reference
< SlideShow
> xSlideShow( SlideShow::GetSlideShow( *pBase
) );
81 if( xSlideShow
.is() && xSlideShow
->isRunning() )
83 if (xSlideShow
->isFullScreen())
84 eResult
|= IdleState::FullScreenShowActive
;
86 eResult
|= IdleState::WindowShowActive
;
94 IdleState
IdleDetection::CheckWindowPainting (const vcl::Window
& rWindow
)
96 if (rWindow
.IsInPaint())
97 return IdleState::WindowPainting
;
99 return IdleState::Idle
;
102 } } // end of namespace ::sd::tools
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */