LibreOffice Module sd (master) 1
CanvasUpdateRequester.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
21#include <vcl/svapp.hxx>
22#include <com/sun/star/lang/XComponent.hpp>
23#include <com/sun/star/rendering/XSpriteCanvas.hpp>
25#include <vector>
26
27using namespace ::com::sun::star;
28using namespace ::com::sun::star::uno;
29
30namespace sd::presenter {
31
32//===== CanvasUpdateRequester::Deleter ========================================
33
35{
36public:
37 void operator() (CanvasUpdateRequester* pObject) { delete pObject; }
38};
39
40//===== CanvasUpdateRequester =================================================
41
42std::shared_ptr<CanvasUpdateRequester> CanvasUpdateRequester::Instance (
43 const Reference<rendering::XSpriteCanvas>& rxSharedCanvas)
44{
45 // this global must not own anything or we crash on shutdown
46 static std::vector<std::pair<
47 uno::WeakReference<rendering::XSpriteCanvas>,
48 std::weak_ptr<CanvasUpdateRequester>>> s_RequesterMap;
49 for (auto it = s_RequesterMap.begin(); it != s_RequesterMap.end(); )
50 {
51 uno::Reference<rendering::XSpriteCanvas> const xCanvas(it->first);
52 if (!xCanvas.is())
53 {
54 it = s_RequesterMap.erase(it); // remove stale entry
55 }
56 else if (xCanvas == rxSharedCanvas)
57 {
58 std::shared_ptr<CanvasUpdateRequester> pRequester(it->second);
59 if (pRequester)
60 {
61 return pRequester;
62 }
63 else
64 {
65 std::shared_ptr<CanvasUpdateRequester> const pNew(
66 new CanvasUpdateRequester(rxSharedCanvas), Deleter());
67 it->second = pNew;
68 return pNew;
69 }
70 }
71 else
72 {
73 ++it;
74 }
75 }
76
77 // No requester for the given canvas found. Create a new one.
78 std::shared_ptr<CanvasUpdateRequester> pRequester (
79 new CanvasUpdateRequester(rxSharedCanvas), Deleter());
80 s_RequesterMap.emplace_back(rxSharedCanvas, pRequester);
81 return pRequester;
82}
83
84
86 const Reference<rendering::XSpriteCanvas>& rxCanvas)
87 : mxCanvas(rxCanvas)
88 , m_pUserEventId(nullptr)
89 , mbUpdateFlag(false)
90{
91 Reference<lang::XComponent> xComponent (mxCanvas, UNO_QUERY);
92 if (xComponent.is())
93 {
94 //xComponent->addEventListener(this);
95 }
96}
97
99{
100 assert(m_pUserEventId == nullptr);
101}
102
103void CanvasUpdateRequester::RequestUpdate (const bool bUpdateAll)
104{
105 if (m_pUserEventId == nullptr)
106 {
107 m_pThis = shared_from_this(); // keep instance alive until dispatch
108 mbUpdateFlag = bUpdateAll;
110 }
111 else
112 {
113 mbUpdateFlag |= bUpdateAll;
114 }
115}
116
118{
119 m_pUserEventId = nullptr;
120 if (mxCanvas.is())
121 {
122 mxCanvas->updateScreen(mbUpdateFlag);
123 mbUpdateFlag = false;
124 }
125 assert(m_pThis);
126 m_pThis.reset(); // possibly delete "this"
127}
128
129} // end of namespace ::sd::presenter
130
131/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< rendering::XCanvas > mxCanvas
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
void operator()(CanvasUpdateRequester *pObject)
Each UpdateRequester handles update requests (calls to XCanvas::updateScreen()) for one shared canvas...
static std::shared_ptr< CanvasUpdateRequester > Instance(const css::uno::Reference< css::rendering::XSpriteCanvas > &rxCanvas)
std::shared_ptr< CanvasUpdateRequester > m_pThis
keep instance alive waiting for event dispatch
CanvasUpdateRequester(const CanvasUpdateRequester &)=delete
css::uno::Reference< css::rendering::XSpriteCanvas > mxCanvas
EmbeddedObjectRef * pObject
IMPL_LINK_NOARG(CanvasUpdateRequester, Callback, void *, void)