1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "precompiled_sd.hxx"
29 
30 #include "framework/Pane.hxx"
31 
32 #include <rtl/uuid.h>
33 #include <vcl/svapp.hxx>
34 #include <vos/mutex.hxx>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <vcl/window.hxx>
37 #include <cppcanvas/vclfactory.hxx>
38 
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::drawing::framework;
42 
43 using ::rtl::OUString;
44 
45 namespace sd { namespace framework {
46 
47 Pane::Pane (
48     const Reference<XResourceId>& rxPaneId,
49     ::Window* pWindow)
50     throw ()
51     : PaneInterfaceBase(MutexOwner::maMutex),
52       mxPaneId(rxPaneId),
53       mpWindow(pWindow),
54       mxWindow(VCLUnoHelper::GetInterface(pWindow))
55 {
56 }
57 
58 
59 
60 
61 Pane::~Pane (void) throw()
62 {
63 }
64 
65 
66 
67 
68 void Pane::disposing (void)
69 {
70     mxWindow = NULL;
71     mpWindow = NULL;
72 }
73 
74 
75 
76 
77 ::Window* Pane::GetWindow (void)
78 {
79     if (mxWindow.is())
80         return mpWindow;
81     else
82         return NULL;
83 }
84 
85 
86 
87 
88 //----- XPane -----------------------------------------------------------------
89 
90 Reference<awt::XWindow> SAL_CALL Pane::getWindow (void)
91     throw (RuntimeException)
92 {
93     ThrowIfDisposed();
94 
95     return mxWindow;
96 }
97 
98 
99 
100 
101 Reference<rendering::XCanvas> SAL_CALL Pane::getCanvas (void)
102     throw (RuntimeException)
103 {
104     ::osl::MutexGuard aGuard (maMutex);
105     ThrowIfDisposed();
106 
107     if ( ! mxCanvas.is())
108         mxCanvas = CreateCanvas();
109 
110     return mxCanvas;
111 }
112 
113 
114 
115 
116 //----- XPane2 ----------------------------------------------------------------
117 
118 sal_Bool SAL_CALL Pane::isVisible (void)
119     throw (RuntimeException)
120 {
121     ThrowIfDisposed();
122 
123     const ::Window* pWindow = GetWindow();
124     if (pWindow != NULL)
125         return pWindow->IsVisible();
126     else
127         return false;
128 }
129 
130 
131 
132 
133 void SAL_CALL Pane::setVisible (sal_Bool bIsVisible)
134     throw (RuntimeException)
135 {
136     ThrowIfDisposed();
137 
138     ::Window* pWindow = GetWindow();
139     if (pWindow != NULL)
140         pWindow->Show(bIsVisible);
141 }
142 
143 
144 
145 
146 Reference<accessibility::XAccessible> SAL_CALL Pane::getAccessible (void)
147     throw (RuntimeException)
148 {
149     ThrowIfDisposed();
150     ::Window* pWindow = GetWindow();
151     if (pWindow != NULL)
152         return pWindow->GetAccessible(sal_False);
153     else
154         return NULL;
155 }
156 
157 
158 
159 
160 void SAL_CALL Pane::setAccessible (
161     const Reference<accessibility::XAccessible>& rxAccessible)
162     throw (RuntimeException)
163 {
164     ThrowIfDisposed();
165     ::Window* pWindow = GetWindow();
166     if (pWindow != NULL)
167         pWindow->SetAccessible(rxAccessible);
168 }
169 
170 
171 
172 
173 //----- XResource -------------------------------------------------------------
174 
175 Reference<XResourceId> SAL_CALL Pane::getResourceId (void)
176     throw (RuntimeException)
177 {
178     ThrowIfDisposed();
179 
180     return mxPaneId;
181 }
182 
183 
184 
185 
186 sal_Bool SAL_CALL Pane::isAnchorOnly (void)
187     throw (RuntimeException)
188 {
189     return true;
190 }
191 
192 
193 
194 
195 //----- XUnoTunnel ------------------------------------------------------------
196 
197 const Sequence<sal_Int8>& Pane::getUnoTunnelId (void)
198 {
199 	static Sequence<sal_Int8>* pSequence = NULL;
200 	if (pSequence == NULL)
201 	{
202         const ::vos::OGuard aSolarGuard (Application::GetSolarMutex());
203 		if (pSequence == NULL)
204 		{
205 			static ::com::sun::star::uno::Sequence<sal_Int8> aSequence (16);
206 			rtl_createUuid((sal_uInt8*)aSequence.getArray(), 0, sal_True);
207 			pSequence = &aSequence;
208 		}
209 	}
210 	return *pSequence;
211 }
212 
213 
214 
215 
216 sal_Int64 SAL_CALL Pane::getSomething (const Sequence<sal_Int8>& rId)
217     throw (RuntimeException)
218 {
219     sal_Int64 nResult = 0;
220 
221     if (rId.getLength() == 16
222         && rtl_compareMemory(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
223 	{
224 		nResult = reinterpret_cast<sal_Int64>(this);
225 	}
226 
227     return nResult;
228 }
229 
230 
231 
232 
233 //-----------------------------------------------------------------------------
234 
235 Reference<rendering::XCanvas> Pane::CreateCanvas (void)
236     throw (RuntimeException)
237 {
238     Reference<rendering::XCanvas> xCanvas;
239 
240     if (mpWindow != NULL)
241     {
242         ::cppcanvas::SpriteCanvasSharedPtr pCanvas (
243             ::cppcanvas::VCLFactory::getInstance().createSpriteCanvas(*mpWindow));
244         if (pCanvas.get() != NULL)
245             xCanvas = Reference<rendering::XCanvas>(pCanvas->getUNOSpriteCanvas(), UNO_QUERY);
246     }
247 
248     return xCanvas;
249 }
250 
251 
252 
253 
254 void Pane::ThrowIfDisposed (void) const
255     throw (lang::DisposedException)
256 {
257 	if (rBHelper.bDisposed || rBHelper.bInDispose)
258 	{
259         throw lang::DisposedException (
260             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
261                 "Pane object has already been disposed")),
262             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
263     }
264 }
265 
266 
267 } } // end of namespace sd::framework
268