bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / presenter / CanvasUpdateRequester.cxx
blobc8ff74cd516600817dba564ba6d3772f21e19a12
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "CanvasUpdateRequester.hxx"
21 #include <vcl/svapp.hxx>
22 #include <com/sun/star/lang/XComponent.hpp>
23 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
24 #include <cppuhelper/weakref.hxx>
25 #include <vector>
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::uno;
30 namespace sd { namespace presenter {
32 //===== CanvasUpdateRequester::Deleter ========================================
34 class CanvasUpdateRequester::Deleter
36 public:
37 void operator() (CanvasUpdateRequester* pObject) { delete pObject; }
40 //===== CanvasUpdateRequester =================================================
42 std::shared_ptr<CanvasUpdateRequester> CanvasUpdateRequester::Instance (
43 const Reference<rendering::XSpriteCanvas>& rxSharedCanvas)
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(); )
51 uno::Reference<rendering::XSpriteCanvas> const xCanvas(it->first);
52 if (!xCanvas.is())
54 it = s_RequesterMap.erase(it); // remove stale entry
56 else if (xCanvas == rxSharedCanvas)
58 std::shared_ptr<CanvasUpdateRequester> pRequester(it->second);
59 if (pRequester)
61 return pRequester;
63 else
65 std::shared_ptr<CanvasUpdateRequester> const pNew(
66 new CanvasUpdateRequester(rxSharedCanvas), Deleter());
67 it->second = pNew;
68 return pNew;
71 else
73 ++it;
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;
85 CanvasUpdateRequester::CanvasUpdateRequester (
86 const Reference<rendering::XSpriteCanvas>& rxCanvas)
87 : mxCanvas(rxCanvas)
88 , m_pUserEventId(nullptr)
89 , mbUpdateFlag(false)
91 Reference<lang::XComponent> xComponent (mxCanvas, UNO_QUERY);
92 if (xComponent.is())
94 //xComponent->addEventListener(this);
98 CanvasUpdateRequester::~CanvasUpdateRequester()
100 assert(m_pUserEventId == nullptr);
103 void CanvasUpdateRequester::RequestUpdate (const bool bUpdateAll)
105 if (m_pUserEventId == nullptr)
107 m_pThis = shared_from_this(); // keep instance alive until dispatch
108 mbUpdateFlag = bUpdateAll;
109 m_pUserEventId = Application::PostUserEvent(LINK(this, CanvasUpdateRequester, Callback));
111 else
113 mbUpdateFlag |= bUpdateAll;
117 IMPL_LINK_NOARG(CanvasUpdateRequester, Callback, void*, void)
119 m_pUserEventId = nullptr;
120 if (mxCanvas.is())
122 mxCanvas->updateScreen(mbUpdateFlag);
123 mbUpdateFlag = false;
125 assert(m_pThis);
126 m_pThis.reset(); // possibly delete "this"
129 } } // end of namespace ::sd::presenter
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */