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 145 : sal_Int32 IdleDetection::GetIdleState (const vcl::Window* pWindow)
37 : {
38 145 : sal_Int32 nResult (CheckInputPending() | CheckSlideShowRunning());
39 145 : if (pWindow != NULL)
40 145 : nResult |= CheckWindowPainting(*pWindow);
41 145 : return nResult;
42 : }
43 :
44 145 : sal_Int32 IdleDetection::CheckInputPending()
45 : {
46 145 : if (Application::AnyInput(VclInputFlags::MOUSE | VclInputFlags::KEYBOARD | VclInputFlags::PAINT))
47 0 : return IDET_SYSTEM_EVENT_PENDING;
48 : else
49 145 : return IDET_IDLE;
50 : }
51 :
52 145 : sal_Int32 IdleDetection::CheckSlideShowRunning()
53 : {
54 145 : sal_Int32 eResult (IDET_IDLE);
55 :
56 145 : bool bIsSlideShowShowing = false;
57 :
58 : // Iterate over all view frames.
59 291 : for (SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
60 146 : 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 146 : bool bIgnoreFrame (true);
66 146 : uno::Reference<frame::XFrame> xFrame (pViewFrame->GetFrame().GetFrameInterface());
67 : try
68 : {
69 146 : if (xFrame.is() && xFrame->isActive())
70 116 : bIgnoreFrame = false;
71 : }
72 0 : catch (const uno::RuntimeException&)
73 : {
74 : }
75 146 : if (bIgnoreFrame)
76 30 : continue;
77 :
78 : // Get sd::ViewShell from active frame.
79 116 : ViewShellBase* pBase = ViewShellBase::GetViewShellBase(pViewFrame);
80 116 : if (pBase != NULL)
81 : {
82 116 : rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( *pBase ) );
83 116 : 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 116 : }
90 : }
91 116 : }
92 :
93 145 : return eResult;
94 : }
95 :
96 145 : sal_Int32 IdleDetection::CheckWindowPainting (const vcl::Window& rWindow)
97 : {
98 145 : if (rWindow.IsInPaint())
99 0 : return IDET_WINDOW_PAINTING;
100 : else
101 145 : return IDET_IDLE;
102 : }
103 :
104 66 : } } // end of namespace ::sd::tools
105 :
106 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|