Line data Source code
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 "ViewShell.hxx"
23 : #include "slideshow.hxx"
24 : #include "ViewShellBase.hxx"
25 :
26 : #include <vcl/window.hxx>
27 : #include <sfx2/viewfrm.hxx>
28 :
29 : #include <com/sun/star/frame/XFrame.hpp>
30 : #include <vcl/svapp.hxx>
31 :
32 : using namespace ::com::sun::star;
33 :
34 : namespace sd { namespace tools {
35 :
36 181 : sal_Int32 IdleDetection::GetIdleState (const vcl::Window* pWindow)
37 : {
38 181 : sal_Int32 nResult (CheckInputPending() | CheckSlideShowRunning());
39 181 : if (pWindow != NULL)
40 181 : nResult |= CheckWindowPainting(*pWindow);
41 181 : return nResult;
42 : }
43 :
44 181 : sal_Int32 IdleDetection::CheckInputPending (void)
45 : {
46 181 : if (Application::AnyInput(VCL_INPUT_MOUSE | VCL_INPUT_KEYBOARD | VCL_INPUT_PAINT))
47 0 : return IDET_SYSTEM_EVENT_PENDING;
48 : else
49 181 : return IDET_IDLE;
50 : }
51 :
52 181 : sal_Int32 IdleDetection::CheckSlideShowRunning (void)
53 : {
54 181 : sal_Int32 eResult (IDET_IDLE);
55 :
56 181 : bool bIsSlideShowShowing = false;
57 :
58 : // Iterate over all view frames.
59 370 : for (SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
60 189 : pViewFrame!=NULL && !bIsSlideShowShowing;
61 : pViewFrame = SfxViewFrame::GetNext(*pViewFrame))
62 : {
63 : // Ignore the current frame when it does not exist, is not valid, or
64 : // is not active.
65 189 : bool bIgnoreFrame (true);
66 189 : uno::Reference<frame::XFrame> xFrame (pViewFrame->GetFrame().GetFrameInterface());
67 : try
68 : {
69 189 : if (xFrame.is() && xFrame->isActive())
70 167 : bIgnoreFrame = false;
71 : }
72 0 : catch (const uno::RuntimeException&)
73 : {
74 : }
75 189 : if (bIgnoreFrame)
76 22 : continue;
77 :
78 : // Get sd::ViewShell from active frame.
79 167 : ViewShellBase* pBase = ViewShellBase::GetViewShellBase(pViewFrame);
80 167 : if (pBase != NULL)
81 : {
82 167 : rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( *pBase ) );
83 167 : if( xSlideShow.is() && xSlideShow->isRunning() )
84 : {
85 0 : if (xSlideShow->isFullScreen())
86 0 : eResult |= IDET_FULL_SCREEN_SHOW_ACTIVE;
87 : else
88 0 : eResult |= IDET_WINDOW_SHOW_ACTIVE;
89 167 : }
90 : }
91 167 : }
92 :
93 181 : return eResult;
94 : }
95 :
96 181 : sal_Int32 IdleDetection::CheckWindowPainting (const vcl::Window& rWindow)
97 : {
98 181 : if (rWindow.IsInPaint())
99 0 : return IDET_WINDOW_PAINTING;
100 : else
101 181 : return IDET_IDLE;
102 : }
103 :
104 114 : } } // end of namespace ::sd::tools
105 :
106 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|