merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / framework / module / ShellStackGuard.cxx
blob4a197a42d7ecf3e11f55aa16e923154eb5ffcdb5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ShellStackGuard.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
33 #include "ShellStackGuard.hxx"
35 #include "framework/ConfigurationController.hxx"
36 #include "framework/FrameworkHelper.hxx"
38 #include "DrawController.hxx"
39 #include "ViewShellBase.hxx"
40 #include <sfx2/printer.hxx>
41 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
42 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::drawing::framework;
48 using ::rtl::OUString;
49 using ::sd::framework::FrameworkHelper;
52 namespace sd { namespace framework {
54 //===== CenterViewFocusModule ====================================================
56 ShellStackGuard::ShellStackGuard (Reference<frame::XController>& rxController)
57 : ShellStackGuardInterfaceBase(m_aMutex),
58 mxConfigurationController(),
59 mpBase(NULL),
60 mpUpdateLock(),
61 maPrinterPollingTimer()
63 Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
64 if (xControllerManager.is())
66 mxConfigurationController = xControllerManager->getConfigurationController();
68 // Tunnel through the controller to obtain a ViewShellBase.
69 Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
70 if (xTunnel.is())
72 ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
73 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
74 if (pController != NULL)
75 mpBase = pController->GetViewShellBase();
79 if (mxConfigurationController.is())
81 // Listen for update starts so that the following update can be
82 // prevented in case of a printing printer.
83 mxConfigurationController->addConfigurationChangeListener(
84 this,
85 FrameworkHelper::msConfigurationUpdateStartEvent,
86 Any());
88 // Prepare the printer polling.
89 maPrinterPollingTimer.SetTimeoutHdl(LINK(this,ShellStackGuard,TimeoutHandler));
90 maPrinterPollingTimer.SetTimeout(300);
97 ShellStackGuard::~ShellStackGuard (void)
104 void SAL_CALL ShellStackGuard::disposing (void)
106 if (mxConfigurationController.is())
107 mxConfigurationController->removeConfigurationChangeListener(this);
109 mxConfigurationController = NULL;
110 mpBase = NULL;
116 void SAL_CALL ShellStackGuard::notifyConfigurationChange (
117 const ConfigurationChangeEvent& rEvent)
118 throw (RuntimeException)
120 if (rEvent.Type.equals(FrameworkHelper::msConfigurationUpdateStartEvent))
122 if (mpUpdateLock.get() == NULL && IsPrinting())
124 // Prevent configuration updates while the printer is printing.
125 mpUpdateLock.reset(new ConfigurationController::Lock(mxConfigurationController));
127 // Start polling for the printer having finished printing.
128 maPrinterPollingTimer.Start();
136 void SAL_CALL ShellStackGuard::disposing (
137 const lang::EventObject& rEvent)
138 throw (RuntimeException)
140 if (mxConfigurationController.is())
141 if (rEvent.Source == mxConfigurationController)
143 mxConfigurationController = NULL;
144 mpBase = NULL;
151 IMPL_LINK(ShellStackGuard, TimeoutHandler, Timer*, pTimer)
153 #ifdef DEBUG
154 OSL_ASSERT(pTimer==&maPrinterPollingTimer);
155 #else
156 (void)pTimer;
157 #endif
158 if (mpUpdateLock.get() != NULL)
160 if ( ! IsPrinting())
162 // Printing finished. Release the update lock.
163 mpUpdateLock.reset();
165 else
167 // Wait long for the printing to finish.
168 maPrinterPollingTimer.Start();
172 return 0;
179 bool ShellStackGuard::IsPrinting (void) const
181 if (mpBase != NULL)
183 SfxPrinter* pPrinter = mpBase->GetPrinter();
184 if (pPrinter != NULL
185 && pPrinter->IsPrinting())
187 return true;
191 return false;
195 } } // end of namespace sd::framework