1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SD_FRAMEWORK_SHELL_STACK_GUARD_HXX
29 #define SD_FRAMEWORK_SHELL_STACK_GUARD_HXX
30 
31 #include <cppuhelper/basemutex.hxx>
32 
33 #include "framework/ConfigurationController.hxx"
34 
35 #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>
36 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
37 #include <com/sun/star/frame/XController.hpp>
38 
39 #include <vcl/timer.hxx>
40 #include <cppuhelper/compbase1.hxx>
41 #include <boost/scoped_ptr.hpp>
42 
43 
44 namespace css = ::com::sun::star;
45 
46 
47 namespace {
48 
49 typedef ::cppu::WeakComponentImplHelper1 <
50     css::drawing::framework::XConfigurationChangeListener
51     > ShellStackGuardInterfaceBase;
52 
53 } // end of anonymous namespace.
54 
55 namespace sd {
56 
57 class ViewShellBase;
58 
59 }
60 
61 
62 
63 
64 namespace sd { namespace framework {
65 
66 /** This module locks updates of the current configuration in situations
67     when the shell stack must not be modified.
68 
69     On every start of a configuration update the ShellStackGuard checks the
70     printer.  If it is printing the configuration update is locked.  It then
71     polls the printer and unlocks updates when printing finishes.
72 
73     When in the future there are no resources left that use shells then this
74     module can be removed.
75 */
76 class ShellStackGuard
77     : private ::cppu::BaseMutex,
78       public ShellStackGuardInterfaceBase
79 {
80 public:
81     ShellStackGuard (css::uno::Reference<css::frame::XController>& rxController);
82     virtual ~ShellStackGuard (void);
83 
84     virtual void SAL_CALL disposing (void);
85 
86 
87     // XConfigurationChangeListener
88 
89     virtual void SAL_CALL notifyConfigurationChange (
90         const css::drawing::framework::ConfigurationChangeEvent& rEvent)
91         throw (css::uno::RuntimeException);
92 
93     // XEventListener
94 
95     virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent)
96         throw (css::uno::RuntimeException);
97 
98 private:
99     css::uno::Reference<css::drawing::framework::XConfigurationController>
100         mxConfigurationController;
101     ViewShellBase* mpBase;
102     ::boost::scoped_ptr<ConfigurationController::Lock> mpUpdateLock;
103     Timer maPrinterPollingTimer;
104 
105     DECL_LINK(TimeoutHandler, Timer*);
106 
107     /** Return <TRUE/> when the printer is printing.  Return <FALSE/> when
108         the printer is not printing, or there is no printer, or someting
109         else went wrong.
110     */
111     bool IsPrinting (void) const;
112 };
113 
114 } } // end of namespace sd::framework
115 
116 #endif
117