1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "ShellStackGuard.hxx"
22 #include "framework/ConfigurationController.hxx"
23 #include "framework/FrameworkHelper.hxx"
25 #include "DrawController.hxx"
26 #include "ViewShellBase.hxx"
27 #include <sfx2/printer.hxx>
28 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
29 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
31 using namespace ::com::sun::star
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::drawing::framework
;
35 using ::sd::framework::FrameworkHelper
;
37 namespace sd
{ namespace framework
{
39 //===== CenterViewFocusModule ====================================================
41 ShellStackGuard::ShellStackGuard (Reference
<frame::XController
>& rxController
)
42 : ShellStackGuardInterfaceBase(m_aMutex
),
43 mxConfigurationController(),
46 maPrinterPollingIdle()
48 Reference
<XControllerManager
> xControllerManager (rxController
, UNO_QUERY
);
49 if (xControllerManager
.is())
51 mxConfigurationController
= xControllerManager
->getConfigurationController();
53 // Tunnel through the controller to obtain a ViewShellBase.
54 Reference
<lang::XUnoTunnel
> xTunnel (rxController
, UNO_QUERY
);
57 ::sd::DrawController
* pController
= reinterpret_cast<sd::DrawController
*>(
58 xTunnel
->getSomething(sd::DrawController::getUnoTunnelId()));
59 if (pController
!= NULL
)
60 mpBase
= pController
->GetViewShellBase();
64 if (mxConfigurationController
.is())
66 // Listen for update starts so that the following update can be
67 // prevented in case of a printing printer.
68 mxConfigurationController
->addConfigurationChangeListener(
70 FrameworkHelper::msConfigurationUpdateStartEvent
,
73 // Prepare the printer polling.
74 maPrinterPollingIdle
.SetIdleHdl(LINK(this,ShellStackGuard
,TimeoutHandler
));
75 maPrinterPollingIdle
.SetPriority(SchedulerPriority::LOWER
);
79 ShellStackGuard::~ShellStackGuard()
83 void SAL_CALL
ShellStackGuard::disposing()
85 if (mxConfigurationController
.is())
86 mxConfigurationController
->removeConfigurationChangeListener(this);
88 mxConfigurationController
= NULL
;
92 void SAL_CALL
ShellStackGuard::notifyConfigurationChange (
93 const ConfigurationChangeEvent
& rEvent
)
94 throw (RuntimeException
, std::exception
)
96 if (rEvent
.Type
.equals(FrameworkHelper::msConfigurationUpdateStartEvent
))
98 if (mpUpdateLock
.get() == NULL
&& IsPrinting())
100 // Prevent configuration updates while the printer is printing.
101 mpUpdateLock
.reset(new ConfigurationController::Lock(mxConfigurationController
));
103 // Start polling for the printer having finished printing.
104 maPrinterPollingIdle
.Start();
109 void SAL_CALL
ShellStackGuard::disposing (
110 const lang::EventObject
& rEvent
)
111 throw (RuntimeException
, std::exception
)
113 if (mxConfigurationController
.is())
114 if (rEvent
.Source
== mxConfigurationController
)
116 mxConfigurationController
= NULL
;
121 IMPL_LINK_TYPED(ShellStackGuard
, TimeoutHandler
, Idle
*, pIdle
, void)
124 OSL_ASSERT(pIdle
==&maPrinterPollingIdle
);
128 if (mpUpdateLock
.get() != NULL
)
132 // Printing finished. Release the update lock.
133 mpUpdateLock
.reset();
137 // Wait long for the printing to finish.
138 maPrinterPollingIdle
.Start();
143 bool ShellStackGuard::IsPrinting() const
147 SfxPrinter
* pPrinter
= mpBase
->GetPrinter();
149 && pPrinter
->IsPrinting())
158 } } // end of namespace sd::framework
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */