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