LibreOffice Module sd (master) 1
ShellStackGuard.cxx
Go to the documentation of this file.
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
24
25#include <DrawController.hxx>
26#include <ViewShellBase.hxx>
27#include <sfx2/printer.hxx>
28#include <com/sun/star/drawing/framework/XControllerManager.hpp>
30
31using namespace ::com::sun::star;
32using namespace ::com::sun::star::uno;
34
35using ::sd::framework::FrameworkHelper;
36
37namespace sd::framework {
38
39//===== CenterViewFocusModule ====================================================
40
42 : mpBase(nullptr),
43 maPrinterPollingIdle("sd ShellStackGuard PrinterPollingIdle")
44{
45 if (rxController.is())
46 {
47 mxConfigurationController = rxController->getConfigurationController();
48
49 // Tunnel through the controller to obtain a ViewShellBase.
50 mpBase = rxController->GetViewShellBase();
51 }
52
54 {
55 // Listen for update starts so that the following update can be
56 // prevented in case of a printing printer.
57 mxConfigurationController->addConfigurationChangeListener(
58 this,
60 Any());
61
62 // Prepare the printer polling.
64 }
65}
66
68{
69}
70
71void ShellStackGuard::disposing(std::unique_lock<std::mutex>&)
72{
74 {
75 mxConfigurationController->removeConfigurationChangeListener(this);
77 }
78 mpBase = nullptr;
79}
80
82 const ConfigurationChangeEvent& rEvent)
83{
85 {
86 if (mpUpdateLock == nullptr && IsPrinting())
87 {
88 // Prevent configuration updates while the printer is printing.
90
91 // Start polling for the printer having finished printing.
93 }
94 }
95}
96
97void SAL_CALL ShellStackGuard::disposing (
98 const lang::EventObject& rEvent)
99{
101 if (rEvent.Source == mxConfigurationController)
102 {
104 mpBase = nullptr;
105 }
106}
107
108IMPL_LINK(ShellStackGuard, TimeoutHandler, Timer*, pIdle, void)
109{
110#ifdef DEBUG
111 OSL_ASSERT(pIdle==&maPrinterPollingIdle);
112#else
113 (void)pIdle;
114#endif
115 if (mpUpdateLock == nullptr)
116 return;
117
118 if ( ! IsPrinting())
119 {
120 // Printing finished. Release the update lock.
121 mpUpdateLock.reset();
122 }
123 else
124 {
125 // Wait long for the printing to finish.
126 maPrinterPollingIdle.Start();
127 }
128}
129
131{
132 if (mpBase != nullptr)
133 {
134 SfxPrinter* pPrinter = mpBase->GetPrinter();
135 if (pPrinter != nullptr
136 && pPrinter->IsPrinting())
137 {
138 return true;
139 }
140 }
141
142 return false;
143}
144
145} // end of namespace sd::framework
146
147/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void Start(bool bStartTimer=true) override
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual SfxPrinter * GetPrinter(bool bCreate=false) override
Forwarded to the print manager.
Use this class instead of calling lock() and unlock() directly in order to be exception safe.
static constexpr OUStringLiteral msConfigurationUpdateStartEvent
This module locks updates of the current configuration in situations when the shell stack must not be...
ShellStackGuard(rtl::Reference< sd::DrawController > const &rxController)
std::unique_ptr< ConfigurationController::Lock > mpUpdateLock
css::uno::Reference< css::drawing::framework::XConfigurationController > mxConfigurationController
virtual void SAL_CALL notifyConfigurationChange(const css::drawing::framework::ConfigurationChangeEvent &rEvent) override
virtual void disposing(std::unique_lock< std::mutex > &) override
bool IsPrinting() const
Return <TRUE> when the printer is printing.
virtual ~ShellStackGuard() override
IMPL_LINK(FullScreenPane, WindowEventHandler, VclWindowEvent &, rEvent, void)