1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/lang/SystemDependent.hpp>
21 #include <com/sun/star/awt/SystemDependentXWindow.hpp>
23 #if defined ( MACOSX )
25 #include <Cocoa/Cocoa.h>
29 #include <vcl/syschild.hxx>
30 #include <vcl/sysdata.hxx>
31 #include <cppuhelper/typeprovider.hxx>
32 #include <comphelper/sequence.hxx>
34 #include <toolkit/awt/vclxtopwindow.hxx>
35 #include <toolkit/awt/vclxmenu.hxx>
36 #include <toolkit/helper/macros.hxx>
38 #include <vcl/wrkwin.hxx>
39 #include <vcl/syswin.hxx>
40 #include <vcl/menu.hxx>
41 #include <vcl/svapp.hxx>
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
;
49 VCLXTopWindow_Base::VCLXTopWindow_Base( const bool _bSupportSystemWindowPeer
)
50 :m_bWHWND( _bSupportSystemWindowPeer
)
54 VCLXTopWindow_Base::~VCLXTopWindow_Base()
58 Any
VCLXTopWindow_Base::queryInterface( const Type
& rType
) throw(RuntimeException
)
60 ::com::sun::star::uno::Any
aRet( VCLXTopWindow_XBase::queryInterface( rType
) );
62 // do not expose XSystemDependentWindowPeer if we do not have a system window handle
63 if ( !aRet
.hasValue() && m_bWHWND
)
64 aRet
= VCLXTopWindow_SBase::queryInterface( rType
);
69 Sequence
< Type
> VCLXTopWindow_Base::getTypes() throw(RuntimeException
)
71 Sequence
< Type
> aTypes( VCLXTopWindow_XBase::getTypes() );
73 aTypes
= ::comphelper::concatSequences( aTypes
, VCLXTopWindow_SBase::getTypes() );
77 ::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
)
79 SolarMutexGuard aGuard
;
81 // TODO, check the process id
82 ::com::sun::star::uno::Any aRet
;
83 Window
* pWindow
= GetWindowImpl();
86 const SystemEnvData
* pSysData
= ((SystemWindow
*)pWindow
)->GetSystemData();
90 if( SystemType
== ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32
)
92 aRet
<<= (sal_Int32
)pSysData
->hWnd
;
94 #elif (defined MACOSX)
95 if( SystemType
== ::com::sun::star::lang::SystemDependent::SYSTEM_MAC
)
97 aRet
<<= (sal_IntPtr
)pSysData
->pView
;
99 #elif (defined ANDROID)
106 if( SystemType
== ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW
)
108 ::com::sun::star::awt::SystemDependentXWindow aSD
;
109 aSD
.DisplayPointer
= sal::static_int_cast
< sal_Int64
>(reinterpret_cast< sal_IntPtr
>(pSysData
->pDisplay
));
110 aSD
.WindowHandle
= pSysData
->aWindow
;
119 void VCLXTopWindow_Base::addTopWindowListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XTopWindowListener
>& rxListener
) throw(::com::sun::star::uno::RuntimeException
)
121 SolarMutexGuard aGuard
;
123 GetTopWindowListenersImpl().addInterface( rxListener
);
126 void VCLXTopWindow_Base::removeTopWindowListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XTopWindowListener
>& rxListener
) throw(::com::sun::star::uno::RuntimeException
)
128 SolarMutexGuard aGuard
;
130 GetTopWindowListenersImpl().removeInterface( rxListener
);
133 void VCLXTopWindow_Base::toFront( ) throw(::com::sun::star::uno::RuntimeException
)
135 SolarMutexGuard aGuard
;
137 Window
* pWindow
= GetWindowImpl();
139 ((WorkWindow
*)pWindow
)->ToTop( TOTOP_RESTOREWHENMIN
);
142 void VCLXTopWindow_Base::toBack( ) throw(::com::sun::star::uno::RuntimeException
)
146 void VCLXTopWindow_Base::setMenuBar( const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMenuBar
>& rxMenu
) throw(::com::sun::star::uno::RuntimeException
)
148 SolarMutexGuard aGuard
;
150 SystemWindow
* pWindow
= (SystemWindow
*) GetWindowImpl();
153 pWindow
->SetMenuBar( NULL
);
156 VCLXMenu
* pMenu
= VCLXMenu::GetImplementation( rxMenu
);
157 if ( pMenu
&& !pMenu
->IsPopupMenu() )
158 pWindow
->SetMenuBar( (MenuBar
*) pMenu
->GetMenu() );
164 //--------------------------------------------------------------------
165 ::sal_Bool SAL_CALL
VCLXTopWindow_Base::getIsMaximized() throw (RuntimeException
)
167 SolarMutexGuard aGuard
;
169 const WorkWindow
* pWindow
= dynamic_cast< const WorkWindow
* >( GetWindowImpl() );
173 return pWindow
->IsMaximized();
176 //--------------------------------------------------------------------
177 void SAL_CALL
VCLXTopWindow_Base::setIsMaximized( ::sal_Bool _ismaximized
) throw (RuntimeException
)
179 SolarMutexGuard aGuard
;
181 WorkWindow
* pWindow
= dynamic_cast< WorkWindow
* >( GetWindowImpl() );
185 pWindow
->Maximize( _ismaximized
);
188 //--------------------------------------------------------------------
189 ::sal_Bool SAL_CALL
VCLXTopWindow_Base::getIsMinimized() throw (RuntimeException
)
191 SolarMutexGuard aGuard
;
193 const WorkWindow
* pWindow
= dynamic_cast< const WorkWindow
* >( GetWindowImpl() );
197 return pWindow
->IsMinimized();
200 //--------------------------------------------------------------------
201 void SAL_CALL
VCLXTopWindow_Base::setIsMinimized( ::sal_Bool _isMinimized
) throw (RuntimeException
)
203 SolarMutexGuard aGuard
;
205 WorkWindow
* pWindow
= dynamic_cast< WorkWindow
* >( GetWindowImpl() );
209 _isMinimized
? pWindow
->Minimize() : pWindow
->Restore();
212 //--------------------------------------------------------------------
213 ::sal_Int32 SAL_CALL
VCLXTopWindow_Base::getDisplay() throw (RuntimeException
)
215 SolarMutexGuard aGuard
;
217 const SystemWindow
* pWindow
= dynamic_cast< const SystemWindow
* >( GetWindowImpl() );
221 return pWindow
->GetScreenNumber();
224 //--------------------------------------------------------------------
225 void SAL_CALL
VCLXTopWindow_Base::setDisplay( ::sal_Int32 _display
) throw (RuntimeException
, IndexOutOfBoundsException
)
227 SolarMutexGuard aGuard
;
229 if ( ( _display
< 0 ) || ( _display
>= (sal_Int32
)Application::GetScreenCount() ) )
230 throw IndexOutOfBoundsException();
232 SystemWindow
* pWindow
= dynamic_cast< SystemWindow
* >( GetWindowImpl() );
236 pWindow
->SetScreenNumber( _display
);
239 // ----------------------------------------------------
240 // class VCLXTopWindow
241 // ----------------------------------------------------
243 void VCLXTopWindow::ImplGetPropertyIds( std::list
< sal_uInt16
> &rIds
)
245 VCLXContainer::ImplGetPropertyIds( rIds
);
248 VCLXTopWindow::VCLXTopWindow(bool bWHWND
)
249 : VCLXTopWindow_Base( bWHWND
)
253 VCLXTopWindow::~VCLXTopWindow()
257 Window
* VCLXTopWindow::GetWindowImpl()
259 return VCLXContainer::GetWindow();
262 ::cppu::OInterfaceContainerHelper
& VCLXTopWindow::GetTopWindowListenersImpl()
264 return GetTopWindowListeners();
267 // ::com::sun::star::uno::XInterface
268 ::com::sun::star::uno::Any
VCLXTopWindow::queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
)
270 ::com::sun::star::uno::Any
aRet( VCLXTopWindow_Base::queryInterface( rType
) );
272 if ( !aRet
.hasValue() )
273 aRet
= VCLXContainer::queryInterface( rType
);
278 ::com::sun::star::uno::Sequence
< sal_Int8
> VCLXTopWindow::getImplementationId() throw(::com::sun::star::uno::RuntimeException
)
280 static ::cppu::OImplementationId
* pId
= NULL
;
281 static ::cppu::OImplementationId
* pIdWithHandle
= NULL
;
282 if ( isSystemDependentWindowPeer() )
286 ::osl::Guard
< ::osl::Mutex
> aGuard( ::osl::Mutex::getGlobalMutex() );
289 static ::cppu::OImplementationId
idWithHandle( sal_False
);
290 pIdWithHandle
= &idWithHandle
;
294 return (*pIdWithHandle
).getImplementationId();
300 ::osl::Guard
< ::osl::Mutex
> aGuard( ::osl::Mutex::getGlobalMutex() );
303 static ::cppu::OImplementationId
id( sal_False
);
308 return (*pId
).getImplementationId();
312 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> VCLXTopWindow::getTypes() throw(::com::sun::star::uno::RuntimeException
)
314 return ::comphelper::concatSequences( VCLXTopWindow_Base::getTypes(), VCLXContainer::getTypes() );
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */