/src/libreoffice/sd/source/ui/tools/IdleDetection.cxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <tools/IdleDetection.hxx> |
21 | | |
22 | | #include <slideshow.hxx> |
23 | | #include <ViewShellBase.hxx> |
24 | | |
25 | | #include <vcl/window.hxx> |
26 | | #include <sfx2/viewfrm.hxx> |
27 | | |
28 | | #include <com/sun/star/frame/XFrame.hpp> |
29 | | #include <vcl/svapp.hxx> |
30 | | |
31 | | using namespace ::com::sun::star; |
32 | | |
33 | | namespace sd::tools { |
34 | | |
35 | | IdleState IdleDetection::GetIdleState (const vcl::Window* pWindow) |
36 | 0 | { |
37 | 0 | IdleState nResult (CheckInputPending() | CheckSlideShowRunning()); |
38 | 0 | if (pWindow != nullptr) |
39 | 0 | nResult |= CheckWindowPainting(*pWindow); |
40 | 0 | return nResult; |
41 | 0 | } |
42 | | |
43 | | IdleState IdleDetection::CheckInputPending() |
44 | 0 | { |
45 | 0 | if (Application::AnyInput(VclInputFlags::MOUSE | VclInputFlags::KEYBOARD | VclInputFlags::PAINT)) |
46 | 0 | return IdleState::SystemEventPending; |
47 | 0 | else |
48 | 0 | return IdleState::Idle; |
49 | 0 | } |
50 | | |
51 | | IdleState IdleDetection::CheckSlideShowRunning() |
52 | 0 | { |
53 | 0 | IdleState eResult (IdleState::Idle); |
54 | | |
55 | | // Iterate over all view frames. |
56 | 0 | for (SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst(); |
57 | 0 | pViewFrame!=nullptr; |
58 | 0 | pViewFrame = SfxViewFrame::GetNext(*pViewFrame)) |
59 | 0 | { |
60 | | // Ignore the current frame when it does not exist, is not valid, or |
61 | | // is not active. |
62 | 0 | bool bIgnoreFrame (true); |
63 | 0 | uno::Reference<frame::XFrame> xFrame (pViewFrame->GetFrame().GetFrameInterface()); |
64 | 0 | try |
65 | 0 | { |
66 | 0 | if (xFrame.is() && xFrame->isActive()) |
67 | 0 | bIgnoreFrame = false; |
68 | 0 | } |
69 | 0 | catch (const uno::RuntimeException&) |
70 | 0 | { |
71 | 0 | } |
72 | 0 | if (bIgnoreFrame) |
73 | 0 | continue; |
74 | | |
75 | | // Get sd::ViewShell from active frame. |
76 | 0 | ViewShellBase* pBase = ViewShellBase::GetViewShellBase(pViewFrame); |
77 | 0 | if (pBase != nullptr) |
78 | 0 | { |
79 | 0 | rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( *pBase ) ); |
80 | 0 | if( xSlideShow.is() && xSlideShow->isRunning() && !xSlideShow->IsInteractiveSlideshow()) // IASS |
81 | 0 | { |
82 | 0 | if (xSlideShow->isFullScreen()) |
83 | 0 | eResult |= IdleState::FullScreenShowActive; |
84 | 0 | else |
85 | 0 | eResult |= IdleState::WindowShowActive; |
86 | 0 | } |
87 | 0 | } |
88 | 0 | } |
89 | | |
90 | 0 | return eResult; |
91 | 0 | } |
92 | | |
93 | | IdleState IdleDetection::CheckWindowPainting (const vcl::Window& rWindow) |
94 | 0 | { |
95 | 0 | if (rWindow.IsInPaint()) |
96 | 0 | return IdleState::WindowPainting; |
97 | 0 | else |
98 | 0 | return IdleState::Idle; |
99 | 0 | } |
100 | | |
101 | | } // end of namespace ::sd::tools |
102 | | |
103 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |