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 
Pane(const Reference<XResourceId> & rxPaneId,::Window * pWindow)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 
~Pane(void)57 Pane::~Pane (void) throw()
58 {
59 }
60 
61 
62 
63 
disposing(void)64 void Pane::disposing (void)
65 {
66     mxWindow = NULL;
67     mpWindow = NULL;
68 }
69 
70 
71 
72 
GetWindow(void)73 ::Window* Pane::GetWindow (void)
74 {
75     if (mxWindow.is())
76         return mpWindow;
77     else
78         return NULL;
79 }
80 
81 
82 
83 
SetWindow(::Window * pWindow)84 void Pane::SetWindow (::Window* pWindow)
85 {
86     OSL_TRACE("setting Pane::mpWindow to %x", pWindow);
87     mpWindow = pWindow;
88     mxWindow = VCLUnoHelper::GetInterface(mpWindow);
89 }
90 
91 
92 
93 
94 //----- XPane -----------------------------------------------------------------
95 
getWindow(void)96 Reference<awt::XWindow> SAL_CALL Pane::getWindow (void)
97     throw (RuntimeException)
98 {
99     ThrowIfDisposed();
100 
101     return mxWindow;
102 }
103 
104 
105 
106 
getCanvas(void)107 Reference<rendering::XCanvas> SAL_CALL Pane::getCanvas (void)
108     throw (RuntimeException)
109 {
110     ::osl::MutexGuard aGuard (maMutex);
111     ThrowIfDisposed();
112 
113     if ( ! mxCanvas.is())
114         mxCanvas = CreateCanvas();
115 
116     return mxCanvas;
117 }
118 
119 
120 
121 
122 //----- XPane2 ----------------------------------------------------------------
123 
isVisible(void)124 sal_Bool SAL_CALL Pane::isVisible (void)
125     throw (RuntimeException)
126 {
127     ThrowIfDisposed();
128 
129     const ::Window* pWindow = GetWindow();
130     if (pWindow != NULL)
131         return pWindow->IsVisible();
132     else
133         return false;
134 }
135 
136 
137 
138 
setVisible(sal_Bool bIsVisible)139 void SAL_CALL Pane::setVisible (sal_Bool bIsVisible)
140     throw (RuntimeException)
141 {
142     ThrowIfDisposed();
143 
144     ::Window* pWindow = GetWindow();
145     if (pWindow != NULL)
146         pWindow->Show(bIsVisible);
147 }
148 
149 
150 
151 
getAccessible(void)152 Reference<accessibility::XAccessible> SAL_CALL Pane::getAccessible (void)
153     throw (RuntimeException)
154 {
155     ThrowIfDisposed();
156     ::Window* pWindow = GetWindow();
157     if (pWindow != NULL)
158         return pWindow->GetAccessible(sal_False);
159     else
160         return NULL;
161 }
162 
163 
164 
165 
setAccessible(const Reference<accessibility::XAccessible> & rxAccessible)166 void SAL_CALL Pane::setAccessible (
167     const Reference<accessibility::XAccessible>& rxAccessible)
168     throw (RuntimeException)
169 {
170     ThrowIfDisposed();
171     ::Window* pWindow = GetWindow();
172     if (pWindow != NULL)
173         pWindow->SetAccessible(rxAccessible);
174 }
175 
176 
177 
178 
179 //----- XResource -------------------------------------------------------------
180 
getResourceId(void)181 Reference<XResourceId> SAL_CALL Pane::getResourceId (void)
182     throw (RuntimeException)
183 {
184     ThrowIfDisposed();
185 
186     return mxPaneId;
187 }
188 
189 
190 
191 
isAnchorOnly(void)192 sal_Bool SAL_CALL Pane::isAnchorOnly (void)
193     throw (RuntimeException)
194 {
195     return true;
196 }
197 
198 
199 
200 
201 //----- XUnoTunnel ------------------------------------------------------------
202 
getUnoTunnelId(void)203 const Sequence<sal_Int8>& Pane::getUnoTunnelId (void)
204 {
205 	static Sequence<sal_Int8>* pSequence = NULL;
206 	if (pSequence == NULL)
207 	{
208         const ::vos::OGuard aSolarGuard (Application::GetSolarMutex());
209 		if (pSequence == NULL)
210 		{
211 			static ::com::sun::star::uno::Sequence<sal_Int8> aSequence (16);
212 			rtl_createUuid((sal_uInt8*)aSequence.getArray(), 0, sal_True);
213 			pSequence = &aSequence;
214 		}
215 	}
216 	return *pSequence;
217 }
218 
219 
220 
221 
getSomething(const Sequence<sal_Int8> & rId)222 sal_Int64 SAL_CALL Pane::getSomething (const Sequence<sal_Int8>& rId)
223     throw (RuntimeException)
224 {
225     sal_Int64 nResult = 0;
226 
227     if (rId.getLength() == 16
228         && rtl_compareMemory(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
229 	{
230 		nResult = reinterpret_cast<sal_Int64>(this);
231 	}
232 
233     return nResult;
234 }
235 
236 
237 
238 
239 //-----------------------------------------------------------------------------
240 
CreateCanvas(void)241 Reference<rendering::XCanvas> Pane::CreateCanvas (void)
242     throw (RuntimeException)
243 {
244     Reference<rendering::XCanvas> xCanvas;
245 
246     if (mpWindow != NULL)
247     {
248         ::cppcanvas::SpriteCanvasSharedPtr pCanvas (
249             ::cppcanvas::VCLFactory::getInstance().createSpriteCanvas(*mpWindow));
250         if (pCanvas.get() != NULL)
251             xCanvas = Reference<rendering::XCanvas>(pCanvas->getUNOSpriteCanvas(), UNO_QUERY);
252     }
253 
254     return xCanvas;
255 }
256 
257 
258 
259 
ThrowIfDisposed(void) const260 void Pane::ThrowIfDisposed (void) const
261     throw (lang::DisposedException)
262 {
263 	if (rBHelper.bDisposed || rBHelper.bInDispose)
264 	{
265         throw lang::DisposedException (
266             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
267                 "Pane object has already been disposed")),
268             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
269     }
270 }
271 
272 
273 } } // end of namespace sd::framework
274