1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_sd.hxx"
25 
26 #include "framework/Pane.hxx"
27 
28 #include <rtl/uuid.h>
29 #include <vcl/svapp.hxx>
30 #include <vos/mutex.hxx>
31 #include <toolkit/helper/vclunohelper.hxx>
32 #include <vcl/window.hxx>
33 #include <cppcanvas/vclfactory.hxx>
34 
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::drawing::framework;
38 
39 using ::rtl::OUString;
40 
41 namespace sd { namespace framework {
42 
43 Pane::Pane (
44     const Reference<XResourceId>& rxPaneId,
45     ::Window* pWindow)
46     throw ()
47     : PaneInterfaceBase(MutexOwner::maMutex),
48       mxPaneId(rxPaneId),
49       mpWindow(pWindow),
50       mxWindow(VCLUnoHelper::GetInterface(pWindow))
51 {
52 }
53 
54 
55 
56 
57 Pane::~Pane (void) throw()
58 {
59 }
60 
61 
62 
63 
64 void Pane::disposing (void)
65 {
66     mxWindow = NULL;
67     mpWindow = NULL;
68 }
69 
70 
71 
72 
73 ::Window* Pane::GetWindow (void)
74 {
75     if (mxWindow.is())
76         return mpWindow;
77     else
78         return NULL;
79 }
80 
81 
82 
83 
84 //----- XPane -----------------------------------------------------------------
85 
86 Reference<awt::XWindow> SAL_CALL Pane::getWindow (void)
87     throw (RuntimeException)
88 {
89     ThrowIfDisposed();
90 
91     return mxWindow;
92 }
93 
94 
95 
96 
97 Reference<rendering::XCanvas> SAL_CALL Pane::getCanvas (void)
98     throw (RuntimeException)
99 {
100     ::osl::MutexGuard aGuard (maMutex);
101     ThrowIfDisposed();
102 
103     if ( ! mxCanvas.is())
104         mxCanvas = CreateCanvas();
105 
106     return mxCanvas;
107 }
108 
109 
110 
111 
112 //----- XPane2 ----------------------------------------------------------------
113 
114 sal_Bool SAL_CALL Pane::isVisible (void)
115     throw (RuntimeException)
116 {
117     ThrowIfDisposed();
118 
119     const ::Window* pWindow = GetWindow();
120     if (pWindow != NULL)
121         return pWindow->IsVisible();
122     else
123         return false;
124 }
125 
126 
127 
128 
129 void SAL_CALL Pane::setVisible (sal_Bool bIsVisible)
130     throw (RuntimeException)
131 {
132     ThrowIfDisposed();
133 
134     ::Window* pWindow = GetWindow();
135     if (pWindow != NULL)
136         pWindow->Show(bIsVisible);
137 }
138 
139 
140 
141 
142 Reference<accessibility::XAccessible> SAL_CALL Pane::getAccessible (void)
143     throw (RuntimeException)
144 {
145     ThrowIfDisposed();
146     ::Window* pWindow = GetWindow();
147     if (pWindow != NULL)
148         return pWindow->GetAccessible(sal_False);
149     else
150         return NULL;
151 }
152 
153 
154 
155 
156 void SAL_CALL Pane::setAccessible (
157     const Reference<accessibility::XAccessible>& rxAccessible)
158     throw (RuntimeException)
159 {
160     ThrowIfDisposed();
161     ::Window* pWindow = GetWindow();
162     if (pWindow != NULL)
163         pWindow->SetAccessible(rxAccessible);
164 }
165 
166 
167 
168 
169 //----- XResource -------------------------------------------------------------
170 
171 Reference<XResourceId> SAL_CALL Pane::getResourceId (void)
172     throw (RuntimeException)
173 {
174     ThrowIfDisposed();
175 
176     return mxPaneId;
177 }
178 
179 
180 
181 
182 sal_Bool SAL_CALL Pane::isAnchorOnly (void)
183     throw (RuntimeException)
184 {
185     return true;
186 }
187 
188 
189 
190 
191 //----- XUnoTunnel ------------------------------------------------------------
192 
193 const Sequence<sal_Int8>& Pane::getUnoTunnelId (void)
194 {
195 	static Sequence<sal_Int8>* pSequence = NULL;
196 	if (pSequence == NULL)
197 	{
198         const ::vos::OGuard aSolarGuard (Application::GetSolarMutex());
199 		if (pSequence == NULL)
200 		{
201 			static ::com::sun::star::uno::Sequence<sal_Int8> aSequence (16);
202 			rtl_createUuid((sal_uInt8*)aSequence.getArray(), 0, sal_True);
203 			pSequence = &aSequence;
204 		}
205 	}
206 	return *pSequence;
207 }
208 
209 
210 
211 
212 sal_Int64 SAL_CALL Pane::getSomething (const Sequence<sal_Int8>& rId)
213     throw (RuntimeException)
214 {
215     sal_Int64 nResult = 0;
216 
217     if (rId.getLength() == 16
218         && rtl_compareMemory(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
219 	{
220 		nResult = reinterpret_cast<sal_Int64>(this);
221 	}
222 
223     return nResult;
224 }
225 
226 
227 
228 
229 //-----------------------------------------------------------------------------
230 
231 Reference<rendering::XCanvas> Pane::CreateCanvas (void)
232     throw (RuntimeException)
233 {
234     Reference<rendering::XCanvas> xCanvas;
235 
236     if (mpWindow != NULL)
237     {
238         ::cppcanvas::SpriteCanvasSharedPtr pCanvas (
239             ::cppcanvas::VCLFactory::getInstance().createSpriteCanvas(*mpWindow));
240         if (pCanvas.get() != NULL)
241             xCanvas = Reference<rendering::XCanvas>(pCanvas->getUNOSpriteCanvas(), UNO_QUERY);
242     }
243 
244     return xCanvas;
245 }
246 
247 
248 
249 
250 void Pane::ThrowIfDisposed (void) const
251     throw (lang::DisposedException)
252 {
253 	if (rBHelper.bDisposed || rBHelper.bInDispose)
254 	{
255         throw lang::DisposedException (
256             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
257                 "Pane object has already been disposed")),
258             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
259     }
260 }
261 
262 
263 } } // end of namespace sd::framework
264