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 :
21 : #include "ShellStackGuard.hxx"
22 :
23 : #include "framework/ConfigurationController.hxx"
24 : #include "framework/FrameworkHelper.hxx"
25 :
26 : #include "DrawController.hxx"
27 : #include "ViewShellBase.hxx"
28 : #include <sfx2/printer.hxx>
29 : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
30 : #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
31 :
32 : using namespace ::com::sun::star;
33 : using namespace ::com::sun::star::uno;
34 : using namespace ::com::sun::star::drawing::framework;
35 :
36 : using ::sd::framework::FrameworkHelper;
37 :
38 :
39 : namespace sd { namespace framework {
40 :
41 : //===== CenterViewFocusModule ====================================================
42 :
43 0 : ShellStackGuard::ShellStackGuard (Reference<frame::XController>& rxController)
44 : : ShellStackGuardInterfaceBase(m_aMutex),
45 : mxConfigurationController(),
46 : mpBase(NULL),
47 : mpUpdateLock(),
48 0 : maPrinterPollingTimer()
49 : {
50 0 : Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
51 0 : if (xControllerManager.is())
52 : {
53 0 : mxConfigurationController = xControllerManager->getConfigurationController();
54 :
55 : // Tunnel through the controller to obtain a ViewShellBase.
56 0 : Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
57 0 : if (xTunnel.is())
58 : {
59 : ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
60 0 : xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
61 0 : if (pController != NULL)
62 0 : mpBase = pController->GetViewShellBase();
63 0 : }
64 : }
65 :
66 0 : if (mxConfigurationController.is())
67 : {
68 : // Listen for update starts so that the following update can be
69 : // prevented in case of a printing printer.
70 0 : mxConfigurationController->addConfigurationChangeListener(
71 : this,
72 : FrameworkHelper::msConfigurationUpdateStartEvent,
73 0 : Any());
74 :
75 : // Prepare the printer polling.
76 0 : maPrinterPollingTimer.SetTimeoutHdl(LINK(this,ShellStackGuard,TimeoutHandler));
77 0 : maPrinterPollingTimer.SetTimeout(300);
78 0 : }
79 0 : }
80 :
81 :
82 :
83 :
84 0 : ShellStackGuard::~ShellStackGuard (void)
85 : {
86 0 : }
87 :
88 :
89 :
90 :
91 0 : void SAL_CALL ShellStackGuard::disposing (void)
92 : {
93 0 : if (mxConfigurationController.is())
94 0 : mxConfigurationController->removeConfigurationChangeListener(this);
95 :
96 0 : mxConfigurationController = NULL;
97 0 : mpBase = NULL;
98 0 : }
99 :
100 :
101 :
102 :
103 0 : void SAL_CALL ShellStackGuard::notifyConfigurationChange (
104 : const ConfigurationChangeEvent& rEvent)
105 : throw (RuntimeException, std::exception)
106 : {
107 0 : if (rEvent.Type.equals(FrameworkHelper::msConfigurationUpdateStartEvent))
108 : {
109 0 : if (mpUpdateLock.get() == NULL && IsPrinting())
110 : {
111 : // Prevent configuration updates while the printer is printing.
112 0 : mpUpdateLock.reset(new ConfigurationController::Lock(mxConfigurationController));
113 :
114 : // Start polling for the printer having finished printing.
115 0 : maPrinterPollingTimer.Start();
116 : }
117 : }
118 0 : }
119 :
120 :
121 :
122 :
123 0 : void SAL_CALL ShellStackGuard::disposing (
124 : const lang::EventObject& rEvent)
125 : throw (RuntimeException, std::exception)
126 : {
127 0 : if (mxConfigurationController.is())
128 0 : if (rEvent.Source == mxConfigurationController)
129 : {
130 0 : mxConfigurationController = NULL;
131 0 : mpBase = NULL;
132 : }
133 0 : }
134 :
135 :
136 :
137 :
138 0 : IMPL_LINK(ShellStackGuard, TimeoutHandler, Timer*, pTimer)
139 : {
140 : #ifdef DEBUG
141 : OSL_ASSERT(pTimer==&maPrinterPollingTimer);
142 : #else
143 : (void)pTimer;
144 : #endif
145 0 : if (mpUpdateLock.get() != NULL)
146 : {
147 0 : if ( ! IsPrinting())
148 : {
149 : // Printing finished. Release the update lock.
150 0 : mpUpdateLock.reset();
151 : }
152 : else
153 : {
154 : // Wait long for the printing to finish.
155 0 : maPrinterPollingTimer.Start();
156 : }
157 : }
158 :
159 0 : return 0;
160 : }
161 :
162 :
163 :
164 :
165 :
166 0 : bool ShellStackGuard::IsPrinting (void) const
167 : {
168 0 : if (mpBase != NULL)
169 : {
170 0 : SfxPrinter* pPrinter = mpBase->GetPrinter();
171 0 : if (pPrinter != NULL
172 0 : && pPrinter->IsPrinting())
173 : {
174 0 : return true;
175 : }
176 : }
177 :
178 0 : return false;
179 : }
180 :
181 :
182 : } } // end of namespace sd::framework
183 :
184 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|