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 <slideshow.hxx>
23 #include <ViewShellBase.hxx>
25 #include <vcl/window.hxx>
26 #include <sfx2/viewfrm.hxx>
28 #include <com/sun/star/frame/XFrame.hpp>
29 #include <vcl/svapp.hxx>
31 using namespace ::com::sun::star
;
35 IdleState
IdleDetection::GetIdleState (const vcl::Window
* pWindow
)
37 IdleState
nResult (CheckInputPending() | CheckSlideShowRunning());
38 if (pWindow
!= nullptr)
39 nResult
|= CheckWindowPainting(*pWindow
);
43 IdleState
IdleDetection::CheckInputPending()
45 if (Application::AnyInput(VclInputFlags::MOUSE
| VclInputFlags::KEYBOARD
| VclInputFlags::PAINT
))
46 return IdleState::SystemEventPending
;
48 return IdleState::Idle
;
51 IdleState
IdleDetection::CheckSlideShowRunning()
53 IdleState
eResult (IdleState::Idle
);
55 // Iterate over all view frames.
56 for (SfxViewFrame
* pViewFrame
= SfxViewFrame::GetFirst();
58 pViewFrame
= SfxViewFrame::GetNext(*pViewFrame
))
60 // Ignore the current frame when it does not exist, is not valid, or
62 bool bIgnoreFrame (true);
63 uno::Reference
<frame::XFrame
> xFrame (pViewFrame
->GetFrame().GetFrameInterface());
66 if (xFrame
.is() && xFrame
->isActive())
69 catch (const uno::RuntimeException
&)
75 // Get sd::ViewShell from active frame.
76 ViewShellBase
* pBase
= ViewShellBase::GetViewShellBase(pViewFrame
);
79 rtl::Reference
< SlideShow
> xSlideShow( SlideShow::GetSlideShow( *pBase
) );
80 if( xSlideShow
.is() && xSlideShow
->isRunning() && !xSlideShow
->IsInteractiveSlideshow()) // IASS
82 if (xSlideShow
->isFullScreen())
83 eResult
|= IdleState::FullScreenShowActive
;
85 eResult
|= IdleState::WindowShowActive
;
93 IdleState
IdleDetection::CheckWindowPainting (const vcl::Window
& rWindow
)
95 if (rWindow
.IsInPaint())
96 return IdleState::WindowPainting
;
98 return IdleState::Idle
;
101 } // end of namespace ::sd::tools
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */