xref: /trunk/main/sd/source/ui/framework/module/ShellStackGuard.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_sd.hxx"
25 
26 #include "ShellStackGuard.hxx"
27 
28 #include "framework/ConfigurationController.hxx"
29 #include "framework/FrameworkHelper.hxx"
30 
31 #include "DrawController.hxx"
32 #include "ViewShellBase.hxx"
33 #include <sfx2/printer.hxx>
34 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
35 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
36 
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::drawing::framework;
40 
41 using ::rtl::OUString;
42 using ::sd::framework::FrameworkHelper;
43 
44 
45 namespace sd { namespace framework {
46 
47 //===== CenterViewFocusModule ====================================================
48 
ShellStackGuard(Reference<frame::XController> & rxController)49 ShellStackGuard::ShellStackGuard (Reference<frame::XController>& rxController)
50     : ShellStackGuardInterfaceBase(m_aMutex),
51       mxConfigurationController(),
52       mpBase(NULL),
53       mpUpdateLock(),
54       maPrinterPollingTimer()
55 {
56     Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
57     if (xControllerManager.is())
58     {
59         mxConfigurationController = xControllerManager->getConfigurationController();
60 
61         // Tunnel through the controller to obtain a ViewShellBase.
62         Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
63         if (xTunnel.is())
64         {
65             ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
66                 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
67             if (pController != NULL)
68                 mpBase = pController->GetViewShellBase();
69         }
70     }
71 
72     if (mxConfigurationController.is())
73     {
74         // Listen for update starts so that the following update can be
75         // prevented in case of a printing printer.
76         mxConfigurationController->addConfigurationChangeListener(
77             this,
78             FrameworkHelper::msConfigurationUpdateStartEvent,
79             Any());
80 
81         // Prepare the printer polling.
82         maPrinterPollingTimer.SetTimeoutHdl(LINK(this,ShellStackGuard,TimeoutHandler));
83         maPrinterPollingTimer.SetTimeout(300);
84     }
85 }
86 
87 
88 
89 
~ShellStackGuard(void)90 ShellStackGuard::~ShellStackGuard (void)
91 {
92 }
93 
94 
95 
96 
disposing(void)97 void SAL_CALL ShellStackGuard::disposing (void)
98 {
99     if (mxConfigurationController.is())
100         mxConfigurationController->removeConfigurationChangeListener(this);
101 
102     mxConfigurationController = NULL;
103     mpBase = NULL;
104 }
105 
106 
107 
108 
notifyConfigurationChange(const ConfigurationChangeEvent & rEvent)109 void SAL_CALL ShellStackGuard::notifyConfigurationChange (
110     const ConfigurationChangeEvent& rEvent)
111 {
112     if (rEvent.Type.equals(FrameworkHelper::msConfigurationUpdateStartEvent))
113     {
114         if (mpUpdateLock.get() == NULL && IsPrinting())
115         {
116             // Prevent configuration updates while the printer is printing.
117             mpUpdateLock.reset(new ConfigurationController::Lock(mxConfigurationController));
118 
119             // Start polling for the printer having finished printing.
120             maPrinterPollingTimer.Start();
121         }
122     }
123 }
124 
125 
126 
127 
disposing(const lang::EventObject & rEvent)128 void SAL_CALL ShellStackGuard::disposing (
129     const lang::EventObject& rEvent)
130 {
131     if (mxConfigurationController.is())
132         if (rEvent.Source == mxConfigurationController)
133         {
134             mxConfigurationController = NULL;
135             mpBase = NULL;
136         }
137 }
138 
139 
140 
141 
IMPL_LINK(ShellStackGuard,TimeoutHandler,Timer *,pTimer)142 IMPL_LINK(ShellStackGuard, TimeoutHandler, Timer*, pTimer)
143 {
144 #ifdef DEBUG
145     OSL_ASSERT(pTimer==&maPrinterPollingTimer);
146 #else
147     (void)pTimer;
148 #endif
149     if (mpUpdateLock.get() != NULL)
150     {
151         if ( ! IsPrinting())
152         {
153             // Printing finished.  Release the update lock.
154             mpUpdateLock.reset();
155         }
156         else
157         {
158             // Wait long for the printing to finish.
159             maPrinterPollingTimer.Start();
160         }
161     }
162 
163     return 0;
164 }
165 
166 
167 
168 
169 
IsPrinting(void) const170 bool ShellStackGuard::IsPrinting (void) const
171 {
172     if (mpBase != NULL)
173     {
174         SfxPrinter* pPrinter = mpBase->GetPrinter();
175         if (pPrinter != NULL
176             && pPrinter->IsPrinting())
177         {
178             return true;
179         }
180     }
181 
182     return false;
183 }
184 
185 
186 } } // end of namespace sd::framework
187