Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <com/sun/star/lang/SystemDependent.hpp>
21 : #include <com/sun/star/awt/SystemDependentXWindow.hpp>
22 :
23 : #if defined ( MACOSX )
24 : #include "premac.h"
25 : #include <Cocoa/Cocoa.h>
26 : #include "postmac.h"
27 : #endif
28 :
29 : #include <vcl/syschild.hxx>
30 : #include <vcl/sysdata.hxx>
31 : #include <cppuhelper/typeprovider.hxx>
32 : #include <comphelper/sequence.hxx>
33 :
34 : #include <toolkit/awt/vclxtopwindow.hxx>
35 : #include <toolkit/awt/vclxmenu.hxx>
36 : #include <toolkit/helper/macros.hxx>
37 :
38 : #include <vcl/wrkwin.hxx>
39 : #include <vcl/syswin.hxx>
40 : #include <vcl/menu.hxx>
41 : #include <vcl/svapp.hxx>
42 :
43 : using ::com::sun::star::uno::RuntimeException;
44 : using ::com::sun::star::uno::Sequence;
45 : using ::com::sun::star::uno::Type;
46 : using ::com::sun::star::uno::Any;
47 : using ::com::sun::star::lang::IndexOutOfBoundsException;
48 :
49 3293 : VCLXTopWindow_Base::VCLXTopWindow_Base( const bool _bSupportSystemWindowPeer )
50 3293 : :m_bWHWND( _bSupportSystemWindowPeer )
51 : {
52 3293 : }
53 :
54 3138 : VCLXTopWindow_Base::~VCLXTopWindow_Base()
55 : {
56 3138 : }
57 :
58 209888 : Any VCLXTopWindow_Base::queryInterface( const Type & rType ) throw(RuntimeException)
59 : {
60 209888 : ::com::sun::star::uno::Any aRet( VCLXTopWindow_XBase::queryInterface( rType ) );
61 :
62 : // do not expose XSystemDependentWindowPeer if we do not have a system window handle
63 209888 : if ( !aRet.hasValue() && m_bWHWND )
64 176107 : aRet = VCLXTopWindow_SBase::queryInterface( rType );
65 :
66 209888 : return aRet;
67 : }
68 :
69 0 : Sequence< Type > VCLXTopWindow_Base::getTypes() throw(RuntimeException)
70 : {
71 0 : Sequence< Type > aTypes( VCLXTopWindow_XBase::getTypes() );
72 0 : if ( m_bWHWND )
73 0 : aTypes = ::comphelper::concatSequences( aTypes, VCLXTopWindow_SBase::getTypes() );
74 0 : return aTypes;
75 : }
76 :
77 0 : ::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)
78 : {
79 0 : SolarMutexGuard aGuard;
80 :
81 : // TODO, check the process id
82 0 : ::com::sun::star::uno::Any aRet;
83 0 : Window* pWindow = GetWindowImpl();
84 0 : if ( pWindow )
85 : {
86 0 : const SystemEnvData* pSysData = ((SystemWindow *)pWindow)->GetSystemData();
87 0 : if( pSysData )
88 : {
89 : #if (defined WNT)
90 : if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32 )
91 : {
92 : aRet <<= (sal_IntPtr)pSysData->hWnd;
93 : }
94 : #elif (defined MACOSX)
95 : if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_MAC )
96 : {
97 : aRet <<= (sal_IntPtr)pSysData->pView;
98 : }
99 : #elif (defined ANDROID)
100 : // Nothing
101 : (void) SystemType;
102 : #elif (defined IOS)
103 : // Nothing
104 : (void) SystemType;
105 : #elif (defined UNX)
106 0 : if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW )
107 : {
108 0 : ::com::sun::star::awt::SystemDependentXWindow aSD;
109 0 : aSD.DisplayPointer = sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(pSysData->pDisplay));
110 0 : aSD.WindowHandle = pSysData->aWindow;
111 0 : aRet <<= aSD;
112 : }
113 : #endif
114 : }
115 : }
116 0 : return aRet;
117 : }
118 :
119 3344 : void VCLXTopWindow_Base::addTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
120 : {
121 3344 : SolarMutexGuard aGuard;
122 :
123 3344 : GetTopWindowListenersImpl().addInterface( rxListener );
124 3344 : }
125 :
126 3337 : void VCLXTopWindow_Base::removeTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
127 : {
128 3337 : SolarMutexGuard aGuard;
129 :
130 3337 : GetTopWindowListenersImpl().removeInterface( rxListener );
131 3337 : }
132 :
133 664 : void VCLXTopWindow_Base::toFront( ) throw(::com::sun::star::uno::RuntimeException)
134 : {
135 664 : SolarMutexGuard aGuard;
136 :
137 664 : Window* pWindow = GetWindowImpl();
138 664 : if ( pWindow )
139 664 : ((WorkWindow*)pWindow)->ToTop( TOTOP_RESTOREWHENMIN );
140 664 : }
141 :
142 0 : void VCLXTopWindow_Base::toBack( ) throw(::com::sun::star::uno::RuntimeException)
143 : {
144 0 : }
145 :
146 4 : void VCLXTopWindow_Base::setMenuBar( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuBar >& rxMenu ) throw(::com::sun::star::uno::RuntimeException)
147 : {
148 4 : SolarMutexGuard aGuard;
149 :
150 4 : SystemWindow* pWindow = (SystemWindow*) GetWindowImpl();
151 4 : if ( pWindow )
152 : {
153 4 : pWindow->SetMenuBar( NULL );
154 4 : if ( rxMenu.is() )
155 : {
156 0 : VCLXMenu* pMenu = VCLXMenu::GetImplementation( rxMenu );
157 0 : if ( pMenu && !pMenu->IsPopupMenu() )
158 0 : pWindow->SetMenuBar( (MenuBar*) pMenu->GetMenu() );
159 : }
160 : }
161 4 : mxMenuBar = rxMenu;
162 4 : }
163 :
164 : //--------------------------------------------------------------------
165 0 : ::sal_Bool SAL_CALL VCLXTopWindow_Base::getIsMaximized() throw (RuntimeException)
166 : {
167 0 : SolarMutexGuard aGuard;
168 :
169 0 : const WorkWindow* pWindow = dynamic_cast< const WorkWindow* >( GetWindowImpl() );
170 0 : if ( !pWindow )
171 0 : return sal_False;
172 :
173 0 : return pWindow->IsMaximized();
174 : }
175 :
176 : //--------------------------------------------------------------------
177 0 : void SAL_CALL VCLXTopWindow_Base::setIsMaximized( ::sal_Bool _ismaximized ) throw (RuntimeException)
178 : {
179 0 : SolarMutexGuard aGuard;
180 :
181 0 : WorkWindow* pWindow = dynamic_cast< WorkWindow* >( GetWindowImpl() );
182 0 : if ( !pWindow )
183 0 : return;
184 :
185 0 : pWindow->Maximize( _ismaximized );
186 : }
187 :
188 : //--------------------------------------------------------------------
189 0 : ::sal_Bool SAL_CALL VCLXTopWindow_Base::getIsMinimized() throw (RuntimeException)
190 : {
191 0 : SolarMutexGuard aGuard;
192 :
193 0 : const WorkWindow* pWindow = dynamic_cast< const WorkWindow* >( GetWindowImpl() );
194 0 : if ( !pWindow )
195 0 : return sal_False;
196 :
197 0 : return pWindow->IsMinimized();
198 : }
199 :
200 : //--------------------------------------------------------------------
201 0 : void SAL_CALL VCLXTopWindow_Base::setIsMinimized( ::sal_Bool _isMinimized ) throw (RuntimeException)
202 : {
203 0 : SolarMutexGuard aGuard;
204 :
205 0 : WorkWindow* pWindow = dynamic_cast< WorkWindow* >( GetWindowImpl() );
206 0 : if ( !pWindow )
207 0 : return;
208 :
209 0 : _isMinimized ? pWindow->Minimize() : pWindow->Restore();
210 : }
211 :
212 : //--------------------------------------------------------------------
213 0 : ::sal_Int32 SAL_CALL VCLXTopWindow_Base::getDisplay() throw (RuntimeException)
214 : {
215 0 : SolarMutexGuard aGuard;
216 :
217 0 : const SystemWindow* pWindow = dynamic_cast< const SystemWindow* >( GetWindowImpl() );
218 0 : if ( !pWindow )
219 0 : return 0;
220 :
221 0 : return pWindow->GetScreenNumber();
222 : }
223 :
224 : //--------------------------------------------------------------------
225 0 : void SAL_CALL VCLXTopWindow_Base::setDisplay( ::sal_Int32 _display ) throw (RuntimeException, IndexOutOfBoundsException)
226 : {
227 0 : SolarMutexGuard aGuard;
228 :
229 0 : if ( ( _display < 0 ) || ( _display >= (sal_Int32)Application::GetScreenCount() ) )
230 0 : throw IndexOutOfBoundsException();
231 :
232 0 : SystemWindow* pWindow = dynamic_cast< SystemWindow* >( GetWindowImpl() );
233 0 : if ( !pWindow )
234 0 : return;
235 :
236 0 : pWindow->SetScreenNumber( _display );
237 : }
238 :
239 : // ----------------------------------------------------
240 : // class VCLXTopWindow
241 : // ----------------------------------------------------
242 :
243 0 : void VCLXTopWindow::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
244 : {
245 0 : VCLXContainer::ImplGetPropertyIds( rIds );
246 0 : }
247 :
248 3293 : VCLXTopWindow::VCLXTopWindow(bool bWHWND)
249 3293 : : VCLXTopWindow_Base( bWHWND )
250 : {
251 3293 : }
252 :
253 6271 : VCLXTopWindow::~VCLXTopWindow()
254 : {
255 6271 : }
256 :
257 668 : Window* VCLXTopWindow::GetWindowImpl()
258 : {
259 668 : return VCLXContainer::GetWindow();
260 : }
261 :
262 6681 : ::cppu::OInterfaceContainerHelper& VCLXTopWindow::GetTopWindowListenersImpl()
263 : {
264 6681 : return GetTopWindowListeners();
265 : }
266 :
267 : // ::com::sun::star::uno::XInterface
268 209888 : ::com::sun::star::uno::Any VCLXTopWindow::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
269 : {
270 209888 : ::com::sun::star::uno::Any aRet( VCLXTopWindow_Base::queryInterface( rType ) );
271 :
272 209888 : if ( !aRet.hasValue() )
273 181084 : aRet = VCLXContainer::queryInterface( rType );
274 :
275 209888 : return aRet;
276 : }
277 :
278 0 : ::com::sun::star::uno::Sequence< sal_Int8 > VCLXTopWindow::getImplementationId() throw(::com::sun::star::uno::RuntimeException)
279 : {
280 : static ::cppu::OImplementationId* pId = NULL;
281 : static ::cppu::OImplementationId* pIdWithHandle = NULL;
282 0 : if ( isSystemDependentWindowPeer() )
283 : {
284 0 : if( !pIdWithHandle )
285 : {
286 0 : ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
287 0 : if( !pIdWithHandle )
288 : {
289 0 : static ::cppu::OImplementationId idWithHandle( sal_False );
290 0 : pIdWithHandle = &idWithHandle;
291 0 : }
292 : }
293 :
294 0 : return (*pIdWithHandle).getImplementationId();
295 : }
296 : else
297 : {
298 0 : if( !pId )
299 : {
300 0 : ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
301 0 : if( !pId )
302 : {
303 0 : static ::cppu::OImplementationId id( sal_False );
304 0 : pId = &id;
305 0 : }
306 : }
307 :
308 0 : return (*pId).getImplementationId();
309 : }
310 : }
311 :
312 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > VCLXTopWindow::getTypes() throw(::com::sun::star::uno::RuntimeException)
313 : {
314 0 : return ::comphelper::concatSequences( VCLXTopWindow_Base::getTypes(), VCLXContainer::getTypes() );
315 465 : }
316 :
317 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|