Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / tools / IdleDetection.cxx
blob902b4eb960fc6dccc1dd7651a096ea0ed9c4500e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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);
41 return nResult;
44 IdleState IdleDetection::CheckInputPending()
46 if (Application::AnyInput(VclInputFlags::MOUSE | VclInputFlags::KEYBOARD | VclInputFlags::PAINT))
47 return IdleState::SystemEventPending;
48 else
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();
58 pViewFrame!=nullptr;
59 pViewFrame = SfxViewFrame::GetNext(*pViewFrame))
61 // Ignore the current frame when it does not exist, is not valid, or
62 // is not active.
63 bool bIgnoreFrame (true);
64 uno::Reference<frame::XFrame> xFrame (pViewFrame->GetFrame().GetFrameInterface());
65 try
67 if (xFrame.is() && xFrame->isActive())
68 bIgnoreFrame = false;
70 catch (const uno::RuntimeException&)
73 if (bIgnoreFrame)
74 continue;
76 // Get sd::ViewShell from active frame.
77 ViewShellBase* pBase = ViewShellBase::GetViewShellBase(pViewFrame);
78 if (pBase != nullptr)
80 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( *pBase ) );
81 if( xSlideShow.is() && xSlideShow->isRunning() )
83 if (xSlideShow->isFullScreen())
84 eResult |= IdleState::FullScreenShowActive;
85 else
86 eResult |= IdleState::WindowShowActive;
91 return eResult;
94 IdleState IdleDetection::CheckWindowPainting (const vcl::Window& rWindow)
96 if (rWindow.IsInPaint())
97 return IdleState::WindowPainting;
98 else
99 return IdleState::Idle;
102 } } // end of namespace ::sd::tools
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */