cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / framework / factories / Pane.cxx
blob0aaea2cfcb109e01c92b8b526b6b394d3d081778
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 <framework/Pane.hxx>
22 #include <osl/mutex.hxx>
23 #include <toolkit/helper/vclunohelper.hxx>
24 #include <vcl/window.hxx>
25 #include <cppcanvas/vclfactory.hxx>
26 #include <com/sun/star/rendering/XSpriteCanvas.hpp>
27 #include <comphelper/servicehelper.hxx>
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::drawing::framework;
33 namespace sd::framework {
35 Pane::Pane (
36 const Reference<XResourceId>& rxPaneId,
37 vcl::Window* pWindow)
38 noexcept
39 : PaneInterfaceBase(m_aMutex),
40 mxPaneId(rxPaneId),
41 mpWindow(pWindow),
42 mxWindow(VCLUnoHelper::GetInterface(pWindow))
46 Pane::~Pane()
50 void Pane::disposing()
52 mxWindow = nullptr;
53 mpWindow = nullptr;
56 vcl::Window* Pane::GetWindow()
58 if (mxWindow.is())
59 return mpWindow;
60 else
61 return nullptr;
64 //----- XPane -----------------------------------------------------------------
66 Reference<awt::XWindow> SAL_CALL Pane::getWindow()
68 ThrowIfDisposed();
70 return mxWindow;
73 Reference<rendering::XCanvas> SAL_CALL Pane::getCanvas()
75 ::osl::MutexGuard aGuard (m_aMutex);
76 ThrowIfDisposed();
78 if ( ! mxCanvas.is())
79 mxCanvas = CreateCanvas();
81 return mxCanvas;
84 //----- XPane2 ----------------------------------------------------------------
86 sal_Bool SAL_CALL Pane::isVisible()
88 ThrowIfDisposed();
90 const vcl::Window* pWindow = GetWindow();
91 if (pWindow != nullptr)
92 return pWindow->IsVisible();
93 else
94 return false;
97 void SAL_CALL Pane::setVisible (sal_Bool bIsVisible)
99 ThrowIfDisposed();
101 vcl::Window* pWindow = GetWindow();
102 if (pWindow != nullptr)
103 pWindow->Show(bIsVisible);
106 Reference<css::accessibility::XAccessible> SAL_CALL Pane::getAccessible()
108 ThrowIfDisposed();
109 vcl::Window* pWindow = GetWindow();
110 if (pWindow != nullptr)
111 return pWindow->GetAccessible(false);
112 else
113 return nullptr;
116 void SAL_CALL Pane::setAccessible (
117 const Reference<css::accessibility::XAccessible>& rxAccessible)
119 ThrowIfDisposed();
120 vcl::Window* pWindow = GetWindow();
121 if (pWindow != nullptr)
122 pWindow->SetAccessible(rxAccessible);
125 //----- XResource -------------------------------------------------------------
127 Reference<XResourceId> SAL_CALL Pane::getResourceId()
129 ThrowIfDisposed();
131 return mxPaneId;
134 sal_Bool SAL_CALL Pane::isAnchorOnly()
136 return true;
139 Reference<rendering::XCanvas> Pane::CreateCanvas()
141 Reference<rendering::XCanvas> xCanvas;
143 if (mpWindow != nullptr)
145 ::cppcanvas::SpriteCanvasSharedPtr pCanvas (
146 cppcanvas::VCLFactory::createSpriteCanvas(*mpWindow));
147 if (pCanvas)
148 xCanvas.set(pCanvas->getUNOSpriteCanvas());
151 return xCanvas;
154 void Pane::ThrowIfDisposed() const
156 if (rBHelper.bDisposed || rBHelper.bInDispose)
158 throw lang::DisposedException (u"Pane object has already been disposed"_ustr,
159 const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
163 } // end of namespace sd::framework
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */