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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_toolkit.hxx"
26 #include <com/sun/star/lang/SystemDependent.hpp>
27 #include <com/sun/star/awt/SystemDependentXWindow.hpp>
28
29 #ifdef WNT
30 #include <tools/prewin.h>
31 #include <windows.h>
32 #include <tools/postwin.h>
33 #elif defined ( OS2 )
34 #include <svpm.h>
35 #elif defined ( QUARTZ )
36 #include "premac.h"
37 #include <Cocoa/Cocoa.h>
38 #include "postmac.h"
39 #endif
40
41 #include <vcl/syschild.hxx>
42 #include <vcl/sysdata.hxx>
43 #include <cppuhelper/typeprovider.hxx>
44 #include <comphelper/sequence.hxx>
45
46 #include <toolkit/awt/vclxtopwindow.hxx>
47 #include <toolkit/awt/vclxmenu.hxx>
48 #include <toolkit/helper/macros.hxx>
49
50 #include <vcl/wrkwin.hxx>
51 #include <vcl/syswin.hxx>
52 #include <vcl/menu.hxx>
53 #include <vcl/svapp.hxx>
54
55 #include <tools/debug.hxx>
56
57 using ::com::sun::star::uno::RuntimeException;
58 using ::com::sun::star::uno::Sequence;
59 using ::com::sun::star::uno::Type;
60 using ::com::sun::star::uno::Any;
61 using ::com::sun::star::lang::IndexOutOfBoundsException;
62
VCLXTopWindow_Base(const bool _bSupportSystemWindowPeer)63 VCLXTopWindow_Base::VCLXTopWindow_Base( const bool _bSupportSystemWindowPeer )
64 :m_bWHWND( _bSupportSystemWindowPeer )
65 {
66 }
67
~VCLXTopWindow_Base()68 VCLXTopWindow_Base::~VCLXTopWindow_Base()
69 {
70 }
71
queryInterface(const Type & rType)72 Any VCLXTopWindow_Base::queryInterface( const Type & rType ) throw(RuntimeException)
73 {
74 ::com::sun::star::uno::Any aRet( VCLXTopWindow_XBase::queryInterface( rType ) );
75
76 // do not expose XSystemDependentWindowPeer if we do not have a system window handle
77 if ( !aRet.hasValue() && m_bWHWND )
78 aRet = VCLXTopWindow_SBase::queryInterface( rType );
79
80 return aRet;
81 }
82
getTypes()83 Sequence< Type > VCLXTopWindow_Base::getTypes() throw(RuntimeException)
84 {
85 Sequence< Type > aTypes( VCLXTopWindow_XBase::getTypes() );
86 if ( m_bWHWND )
87 aTypes = ::comphelper::concatSequences( aTypes, VCLXTopWindow_SBase::getTypes() );
88 return aTypes;
89 }
90
getWindowHandle(const::com::sun::star::uno::Sequence<sal_Int8> &,sal_Int16 SystemType)91 ::com::sun::star::uno::Any VCLXTopWindow_Base::getWindowHandle( const ::com::sun::star::uno::Sequence< sal_Int8 >& /*ProcessId*/, sal_Int16 SystemType ) throw(::com::sun::star::uno::RuntimeException)
92 {
93 ::vos::OGuard aGuard( GetMutexImpl() );
94
95 // TODO, check the process id
96 ::com::sun::star::uno::Any aRet;
97 Window* pWindow = GetWindowImpl();
98 if ( pWindow )
99 {
100 const SystemEnvData* pSysData = ((SystemWindow *)pWindow)->GetSystemData();
101 if( pSysData )
102 {
103 #if (defined WNT)
104 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32 )
105 {
106 aRet <<= (sal_Int32)pSysData->hWnd;
107 }
108 #elif (defined OS2)
109 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_OS2 )
110 {
111 aRet <<= (sal_Int32)pSysData->hWnd;
112 }
113 #elif (defined QUARTZ)
114 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_MAC )
115 {
116 aRet <<= (sal_IntPtr)pSysData->mpNSView;
117 }
118 #elif (defined UNX)
119 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW )
120 {
121 ::com::sun::star::awt::SystemDependentXWindow aSD;
122 aSD.DisplayPointer = sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(pSysData->pDisplay));
123 aSD.WindowHandle = pSysData->aWindow;
124 aRet <<= aSD;
125 }
126 #endif
127 }
128 }
129 return aRet;
130 }
131
addTopWindowListener(const::com::sun::star::uno::Reference<::com::sun::star::awt::XTopWindowListener> & rxListener)132 void VCLXTopWindow_Base::addTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
133 {
134 ::vos::OGuard aGuard( GetMutexImpl() );
135
136 GetTopWindowListenersImpl().addInterface( rxListener );
137 }
138
removeTopWindowListener(const::com::sun::star::uno::Reference<::com::sun::star::awt::XTopWindowListener> & rxListener)139 void VCLXTopWindow_Base::removeTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
140 {
141 ::vos::OGuard aGuard( GetMutexImpl() );
142
143 GetTopWindowListenersImpl().removeInterface( rxListener );
144 }
145
toFront()146 void VCLXTopWindow_Base::toFront( ) throw(::com::sun::star::uno::RuntimeException)
147 {
148 ::vos::OGuard aGuard( GetMutexImpl() );
149
150 Window* pWindow = GetWindowImpl();
151 if ( pWindow )
152 ((WorkWindow*)pWindow)->ToTop( TOTOP_RESTOREWHENMIN );
153 }
154
toBack()155 void VCLXTopWindow_Base::toBack( ) throw(::com::sun::star::uno::RuntimeException)
156 {
157 #if 0 // Not possible in VCL...
158
159 ::vos::OGuard aGuard( GetMutexImpl() );
160
161 Window* pWindow = GetWindowImpl();
162 if ( pWindow )
163 {
164 ((WorkWindow*)pWindow)->ToBack();
165 }
166 #endif
167 }
168
setMenuBar(const::com::sun::star::uno::Reference<::com::sun::star::awt::XMenuBar> & rxMenu)169 void VCLXTopWindow_Base::setMenuBar( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuBar >& rxMenu ) throw(::com::sun::star::uno::RuntimeException)
170 {
171 ::vos::OGuard aGuard( GetMutexImpl() );
172
173 SystemWindow* pWindow = (SystemWindow*) GetWindowImpl();
174 if ( pWindow )
175 {
176 pWindow->SetMenuBar( NULL );
177 if ( rxMenu.is() )
178 {
179 VCLXMenu* pMenu = VCLXMenu::GetImplementation( rxMenu );
180 if ( pMenu && !pMenu->IsPopupMenu() )
181 pWindow->SetMenuBar( (MenuBar*) pMenu->GetMenu() );
182 }
183 }
184 mxMenuBar = rxMenu;
185 }
186
187 //--------------------------------------------------------------------
getIsMaximized()188 ::sal_Bool SAL_CALL VCLXTopWindow_Base::getIsMaximized() throw (RuntimeException)
189 {
190 ::vos::OGuard aGuard( GetMutexImpl() );
191
192 const WorkWindow* pWindow = dynamic_cast< const WorkWindow* >( GetWindowImpl() );
193 if ( !pWindow )
194 return sal_False;
195
196 return pWindow->IsMaximized();
197 }
198
199 //--------------------------------------------------------------------
setIsMaximized(::sal_Bool _ismaximized)200 void SAL_CALL VCLXTopWindow_Base::setIsMaximized( ::sal_Bool _ismaximized ) throw (RuntimeException)
201 {
202 ::vos::OGuard aGuard( GetMutexImpl() );
203
204 WorkWindow* pWindow = dynamic_cast< WorkWindow* >( GetWindowImpl() );
205 if ( !pWindow )
206 return;
207
208 pWindow->Maximize( _ismaximized );
209 }
210
211 //--------------------------------------------------------------------
getIsMinimized()212 ::sal_Bool SAL_CALL VCLXTopWindow_Base::getIsMinimized() throw (RuntimeException)
213 {
214 ::vos::OGuard aGuard( GetMutexImpl() );
215
216 const WorkWindow* pWindow = dynamic_cast< const WorkWindow* >( GetWindowImpl() );
217 if ( !pWindow )
218 return sal_False;
219
220 return pWindow->IsMinimized();
221 }
222
223 //--------------------------------------------------------------------
setIsMinimized(::sal_Bool _isMinimized)224 void SAL_CALL VCLXTopWindow_Base::setIsMinimized( ::sal_Bool _isMinimized ) throw (RuntimeException)
225 {
226 ::vos::OGuard aGuard( GetMutexImpl() );
227
228 WorkWindow* pWindow = dynamic_cast< WorkWindow* >( GetWindowImpl() );
229 if ( !pWindow )
230 return;
231
232 _isMinimized ? pWindow->Minimize() : pWindow->Restore();
233 }
234
235 //--------------------------------------------------------------------
getDisplay()236 ::sal_Int32 SAL_CALL VCLXTopWindow_Base::getDisplay() throw (RuntimeException)
237 {
238 ::vos::OGuard aGuard( GetMutexImpl() );
239
240 const SystemWindow* pWindow = dynamic_cast< const SystemWindow* >( GetWindowImpl() );
241 if ( !pWindow )
242 return 0;
243
244 return pWindow->GetScreenNumber();
245 }
246
247 //--------------------------------------------------------------------
setDisplay(::sal_Int32 _display)248 void SAL_CALL VCLXTopWindow_Base::setDisplay( ::sal_Int32 _display ) throw (RuntimeException, IndexOutOfBoundsException)
249 {
250 ::vos::OGuard aGuard( GetMutexImpl() );
251
252 if ( ( _display < 0 ) || ( _display >= (sal_Int32)Application::GetScreenCount() ) )
253 throw IndexOutOfBoundsException();
254
255 SystemWindow* pWindow = dynamic_cast< SystemWindow* >( GetWindowImpl() );
256 if ( !pWindow )
257 return;
258
259 pWindow->SetScreenNumber( _display );
260 }
261
262 // ----------------------------------------------------
263 // class VCLXTopWindow
264 // ----------------------------------------------------
265
ImplGetPropertyIds(std::list<sal_uInt16> & rIds)266 void VCLXTopWindow::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
267 {
268 VCLXContainer::ImplGetPropertyIds( rIds );
269 }
270
VCLXTopWindow(bool bWHWND)271 VCLXTopWindow::VCLXTopWindow(bool bWHWND)
272 : VCLXTopWindow_Base( bWHWND )
273 {
274 }
275
~VCLXTopWindow()276 VCLXTopWindow::~VCLXTopWindow()
277 {
278 }
279
GetMutexImpl()280 vos::IMutex& VCLXTopWindow::GetMutexImpl()
281 {
282 return VCLXContainer::GetMutex();
283 }
284
GetWindowImpl()285 Window* VCLXTopWindow::GetWindowImpl()
286 {
287 return VCLXContainer::GetWindow();
288 }
289
GetTopWindowListenersImpl()290 ::cppu::OInterfaceContainerHelper& VCLXTopWindow::GetTopWindowListenersImpl()
291 {
292 return GetTopWindowListeners();
293 }
294
295 // ::com::sun::star::uno::XInterface
queryInterface(const::com::sun::star::uno::Type & rType)296 ::com::sun::star::uno::Any VCLXTopWindow::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
297 {
298 ::com::sun::star::uno::Any aRet( VCLXTopWindow_Base::queryInterface( rType ) );
299
300 if ( !aRet.hasValue() )
301 aRet = VCLXContainer::queryInterface( rType );
302
303 return aRet;
304 }
305
getImplementationId()306 ::com::sun::star::uno::Sequence< sal_Int8 > VCLXTopWindow::getImplementationId() throw(::com::sun::star::uno::RuntimeException)
307 {
308 static ::cppu::OImplementationId* pId = NULL;
309 static ::cppu::OImplementationId* pIdWithHandle = NULL;
310 if ( isSystemDependentWindowPeer() )
311 {
312 if( !pIdWithHandle )
313 {
314 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
315 if( !pIdWithHandle )
316 {
317 static ::cppu::OImplementationId idWithHandle( sal_False );
318 pIdWithHandle = &idWithHandle;
319 }
320 }
321
322 return (*pIdWithHandle).getImplementationId();
323 }
324 else
325 {
326 if( !pId )
327 {
328 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
329 if( !pId )
330 {
331 static ::cppu::OImplementationId id( sal_False );
332 pId = &id;
333 }
334 }
335
336 return (*pId).getImplementationId();
337 }
338 }
339
getTypes()340 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > VCLXTopWindow::getTypes() throw(::com::sun::star::uno::RuntimeException)
341 {
342 return ::comphelper::concatSequences( VCLXTopWindow_Base::getTypes(), VCLXContainer::getTypes() );
343 }
344