bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / framework / factories / Pane.cxx
blob3d02f3411df8f7f1afb4919b055cd2e198ec51fb
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 <vcl/svapp.hxx>
23 #include <osl/mutex.hxx>
24 #include <toolkit/helper/vclunohelper.hxx>
25 #include <vcl/window.hxx>
26 #include <cppcanvas/vclfactory.hxx>
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 { namespace framework {
35 Pane::Pane (
36 const Reference<XResourceId>& rxPaneId,
37 vcl::Window* pWindow)
38 throw ()
39 : PaneInterfaceBase(MutexOwner::maMutex),
40 mxPaneId(rxPaneId),
41 mpWindow(pWindow),
42 mxWindow(VCLUnoHelper::GetInterface(pWindow))
46 Pane::~Pane()
50 void Pane::disposing()
52 mxWindow = NULL;
53 mpWindow = NULL;
56 vcl::Window* Pane::GetWindow()
58 if (mxWindow.is())
59 return mpWindow;
60 else
61 return NULL;
64 //----- XPane -----------------------------------------------------------------
66 Reference<awt::XWindow> SAL_CALL Pane::getWindow()
67 throw (RuntimeException, std::exception)
69 ThrowIfDisposed();
71 return mxWindow;
74 Reference<rendering::XCanvas> SAL_CALL Pane::getCanvas()
75 throw (RuntimeException, std::exception)
77 ::osl::MutexGuard aGuard (maMutex);
78 ThrowIfDisposed();
80 if ( ! mxCanvas.is())
81 mxCanvas = CreateCanvas();
83 return mxCanvas;
86 //----- XPane2 ----------------------------------------------------------------
88 sal_Bool SAL_CALL Pane::isVisible()
89 throw (RuntimeException, std::exception)
91 ThrowIfDisposed();
93 const vcl::Window* pWindow = GetWindow();
94 if (pWindow != NULL)
95 return pWindow->IsVisible();
96 else
97 return false;
100 void SAL_CALL Pane::setVisible (sal_Bool bIsVisible)
101 throw (RuntimeException, std::exception)
103 ThrowIfDisposed();
105 vcl::Window* pWindow = GetWindow();
106 if (pWindow != NULL)
107 pWindow->Show(bIsVisible);
110 Reference<css::accessibility::XAccessible> SAL_CALL Pane::getAccessible()
111 throw (RuntimeException, std::exception)
113 ThrowIfDisposed();
114 vcl::Window* pWindow = GetWindow();
115 if (pWindow != NULL)
116 return pWindow->GetAccessible(false);
117 else
118 return NULL;
121 void SAL_CALL Pane::setAccessible (
122 const Reference<css::accessibility::XAccessible>& rxAccessible)
123 throw (RuntimeException, std::exception)
125 ThrowIfDisposed();
126 vcl::Window* pWindow = GetWindow();
127 if (pWindow != NULL)
128 pWindow->SetAccessible(rxAccessible);
131 //----- XResource -------------------------------------------------------------
133 Reference<XResourceId> SAL_CALL Pane::getResourceId()
134 throw (RuntimeException, std::exception)
136 ThrowIfDisposed();
138 return mxPaneId;
141 sal_Bool SAL_CALL Pane::isAnchorOnly()
142 throw (RuntimeException, std::exception)
144 return true;
147 //----- XUnoTunnel ------------------------------------------------------------
149 namespace
151 class thePaneUnoTunnelId : public rtl::Static< UnoTunnelIdInit, thePaneUnoTunnelId > {};
154 const Sequence<sal_Int8>& Pane::getUnoTunnelId()
156 return thePaneUnoTunnelId::get().getSeq();
159 sal_Int64 SAL_CALL Pane::getSomething (const Sequence<sal_Int8>& rId)
160 throw (RuntimeException, std::exception)
162 sal_Int64 nResult = 0;
164 if (rId.getLength() == 16
165 && memcmp(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
167 nResult = reinterpret_cast<sal_Int64>(this);
170 return nResult;
173 Reference<rendering::XCanvas> Pane::CreateCanvas()
174 throw (RuntimeException)
176 Reference<rendering::XCanvas> xCanvas;
178 if (mpWindow != nullptr)
180 ::cppcanvas::SpriteCanvasSharedPtr pCanvas (
181 cppcanvas::VCLFactory::createSpriteCanvas(*mpWindow));
182 if (pCanvas.get() != NULL)
183 xCanvas = Reference<rendering::XCanvas>(pCanvas->getUNOSpriteCanvas(), UNO_QUERY);
186 return xCanvas;
189 void Pane::ThrowIfDisposed() const
190 throw (lang::DisposedException)
192 if (rBHelper.bDisposed || rBHelper.bInDispose)
194 throw lang::DisposedException ("Pane object has already been disposed",
195 const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
199 } } // end of namespace sd::framework
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */