bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / tools / IdleDetection.cxx
blobddecd6959b81c3813336444afdfed054dbc2fa79
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 .
21 #include "tools/IdleDetection.hxx"
23 #include "ViewShell.hxx"
24 #include "slideshow.hxx"
25 #include "ViewShellBase.hxx"
27 #include <vcl/window.hxx>
28 #include <sfx2/viewfrm.hxx>
30 #include <com/sun/star/frame/XFrame.hpp>
31 #include <vcl/svapp.hxx>
33 using namespace ::com::sun::star;
35 namespace sd { namespace tools {
38 sal_Int32 IdleDetection::GetIdleState (const ::Window* pWindow)
40 sal_Int32 nResult (CheckInputPending() | CheckSlideShowRunning());
41 if (pWindow != NULL)
42 nResult |= CheckWindowPainting(*pWindow);
43 return nResult;
49 sal_Int32 IdleDetection::CheckInputPending (void)
51 if (GetpApp()->AnyInput(VCL_INPUT_MOUSE | VCL_INPUT_KEYBOARD | VCL_INPUT_PAINT))
52 return IDET_SYSTEM_EVENT_PENDING;
53 else
54 return IDET_IDLE;
60 sal_Int32 IdleDetection::CheckSlideShowRunning (void)
62 sal_Int32 eResult (IDET_IDLE);
64 bool bIsSlideShowShowing = false;
66 // Iterate over all view frames.
67 SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst();
68 for (pViewFrame = SfxViewFrame::GetFirst();
69 pViewFrame!=NULL && !bIsSlideShowShowing;
70 pViewFrame = SfxViewFrame::GetNext(*pViewFrame))
72 // Ignore the current frame when it does not exist, is not valid, or
73 // is not active.
74 bool bIgnoreFrame (true);
75 uno::Reference<frame::XFrame> xFrame (pViewFrame->GetFrame().GetFrameInterface());
76 try
78 if (xFrame.is() && xFrame->isActive())
79 bIgnoreFrame = false;
81 catch (const uno::RuntimeException&)
84 if (bIgnoreFrame)
85 continue;
87 // Get sd::ViewShell from active frame.
88 ViewShellBase* pBase = ViewShellBase::GetViewShellBase(pViewFrame);
89 if (pBase != NULL)
91 rtl::Reference< SlideShow > xSlideShow( SlideShow::GetSlideShow( *pBase ) );
92 if( xSlideShow.is() && xSlideShow->isRunning() )
94 if (xSlideShow->isFullScreen())
95 eResult |= IDET_FULL_SCREEN_SHOW_ACTIVE;
96 else
97 eResult |= IDET_WINDOW_SHOW_ACTIVE;
102 return eResult;
108 sal_Int32 IdleDetection::CheckWindowPainting (const ::Window& rWindow)
110 if (rWindow.IsInPaint())
111 return IDET_WINDOW_PAINTING;
112 else
113 return IDET_IDLE;
116 } } // end of namespace ::sd::tools
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */