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