1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ShellStackGuard.cxx,v $
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(),
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
);
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(
85 FrameworkHelper::msConfigurationUpdateStartEvent
,
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
;
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
;
151 IMPL_LINK(ShellStackGuard
, TimeoutHandler
, Timer
*, pTimer
)
154 OSL_ASSERT(pTimer
==&maPrinterPollingTimer
);
158 if (mpUpdateLock
.get() != NULL
)
162 // Printing finished. Release the update lock.
163 mpUpdateLock
.reset();
167 // Wait long for the printing to finish.
168 maPrinterPollingTimer
.Start();
179 bool ShellStackGuard::IsPrinting (void) const
183 SfxPrinter
* pPrinter
= mpBase
->GetPrinter();
185 && pPrinter
->IsPrinting())
195 } } // end of namespace sd::framework