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 <sal/config.h>
22 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23 #include <com/sun/star/lang/SystemDependent.hpp>
24 #include <com/sun/star/awt/SystemDependentXWindow.hpp>
26 #if defined ( MACOSX )
28 #include <Cocoa/Cocoa.h>
32 #include <vcl/syschild.hxx>
33 #include <vcl/sysdata.hxx>
34 #include <cppuhelper/typeprovider.hxx>
35 #include <comphelper/sequence.hxx>
37 #include <toolkit/awt/vclxtopwindow.hxx>
38 #include <toolkit/awt/vclxmenu.hxx>
39 #include <toolkit/helper/macros.hxx>
41 #include <vcl/wrkwin.hxx>
42 #include <vcl/syswin.hxx>
43 #include <vcl/menu.hxx>
44 #include <vcl/svapp.hxx>
46 using ::com::sun::star::uno::RuntimeException
;
47 using ::com::sun::star::uno::Sequence
;
48 using ::com::sun::star::uno::Type
;
49 using ::com::sun::star::uno::Any
;
50 using ::com::sun::star::lang::IndexOutOfBoundsException
;
52 VCLXTopWindow_Base::VCLXTopWindow_Base()
56 VCLXTopWindow_Base::~VCLXTopWindow_Base()
60 Any
VCLXTopWindow_Base::queryInterface( const Type
& rType
)
62 css::uno::Any
aRet( VCLXTopWindow_XBase::queryInterface( rType
) );
65 aRet
= VCLXTopWindow_SBase::queryInterface( rType
);
70 Sequence
< Type
> VCLXTopWindow_Base::getTypes()
72 Sequence
< Type
> aTypes( VCLXTopWindow_XBase::getTypes() );
73 aTypes
= ::comphelper::concatSequences( aTypes
, VCLXTopWindow_SBase::getTypes() );
77 css::uno::Any
VCLXTopWindow_Base::getWindowHandle( const css::uno::Sequence
< sal_Int8
>& /*ProcessId*/, sal_Int16 SystemType
)
79 SolarMutexGuard aGuard
;
81 // TODO, check the process id
83 vcl::Window
* pWindow
= GetWindowImpl();
86 const SystemEnvData
* pSysData
= static_cast<SystemWindow
*>(pWindow
)->GetSystemData();
90 if( SystemType
== css::lang::SystemDependent::SYSTEM_WIN32
)
92 aRet
<<= reinterpret_cast<sal_IntPtr
>(pSysData
->hWnd
);
95 if( SystemType
== css::lang::SystemDependent::SYSTEM_MAC
)
97 aRet
<<= reinterpret_cast<sal_IntPtr
>(pSysData
->mpNSView
);
99 #elif defined(ANDROID)
106 if( SystemType
== css::lang::SystemDependent::SYSTEM_XWINDOW
)
108 css::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 css::uno::Reference
< css::awt::XTopWindowListener
>& rxListener
)
121 SolarMutexGuard aGuard
;
123 GetTopWindowListenersImpl().addInterface( rxListener
);
126 void VCLXTopWindow_Base::removeTopWindowListener( const css::uno::Reference
< css::awt::XTopWindowListener
>& rxListener
)
128 SolarMutexGuard aGuard
;
130 GetTopWindowListenersImpl().removeInterface( rxListener
);
133 void VCLXTopWindow_Base::toFront( )
135 SolarMutexGuard aGuard
;
137 vcl::Window
* pWindow
= GetWindowImpl();
139 static_cast<WorkWindow
*>(pWindow
)->ToTop( ToTopFlags::RestoreWhenMin
);
142 void VCLXTopWindow_Base::toBack( )
146 void VCLXTopWindow_Base::setMenuBar( const css::uno::Reference
< css::awt::XMenuBar
>& rxMenu
)
148 SolarMutexGuard aGuard
;
150 vcl::Window
* pWindow
= GetWindowImpl();
153 SystemWindow
* pSystemWindow
= static_cast<SystemWindow
*>( pWindow
);
154 pSystemWindow
->SetMenuBar( nullptr );
157 VCLXMenu
* pMenu
= VCLXMenu::GetImplementation( rxMenu
);
158 if ( pMenu
&& !pMenu
->IsPopupMenu() )
159 pSystemWindow
->SetMenuBar( static_cast<MenuBar
*>( pMenu
->GetMenu() ));
165 sal_Bool SAL_CALL
VCLXTopWindow_Base::getIsMaximized()
167 SolarMutexGuard aGuard
;
169 const WorkWindow
* pWindow
= dynamic_cast< const WorkWindow
* >( GetWindowImpl() );
173 return pWindow
->IsMaximized();
177 void SAL_CALL
VCLXTopWindow_Base::setIsMaximized( sal_Bool _ismaximized
)
179 SolarMutexGuard aGuard
;
181 WorkWindow
* pWindow
= dynamic_cast< WorkWindow
* >( GetWindowImpl() );
185 pWindow
->Maximize( _ismaximized
);
189 sal_Bool SAL_CALL
VCLXTopWindow_Base::getIsMinimized()
191 SolarMutexGuard aGuard
;
193 const WorkWindow
* pWindow
= dynamic_cast< const WorkWindow
* >( GetWindowImpl() );
197 return pWindow
->IsMinimized();
201 void SAL_CALL
VCLXTopWindow_Base::setIsMinimized( sal_Bool _isMinimized
)
203 SolarMutexGuard aGuard
;
205 WorkWindow
* pWindow
= dynamic_cast< WorkWindow
* >( GetWindowImpl() );
209 _isMinimized
? pWindow
->Minimize() : pWindow
->Restore();
213 ::sal_Int32 SAL_CALL
VCLXTopWindow_Base::getDisplay()
215 SolarMutexGuard aGuard
;
217 const SystemWindow
* pWindow
= dynamic_cast< const SystemWindow
* >( GetWindowImpl() );
221 return pWindow
->GetScreenNumber();
225 void SAL_CALL
VCLXTopWindow_Base::setDisplay( ::sal_Int32 _display
)
227 SolarMutexGuard aGuard
;
229 if ( ( _display
< 0 ) || ( _display
>= static_cast<sal_Int32
>(Application::GetScreenCount()) ) )
230 throw IndexOutOfBoundsException();
232 SystemWindow
* pWindow
= dynamic_cast< SystemWindow
* >( GetWindowImpl() );
236 pWindow
->SetScreenNumber( _display
);
240 // class VCLXTopWindow
243 void VCLXTopWindow::ImplGetPropertyIds( std::vector
< sal_uInt16
> &rIds
)
245 VCLXContainer::ImplGetPropertyIds( rIds
);
248 VCLXTopWindow::VCLXTopWindow()
252 VCLXTopWindow::~VCLXTopWindow()
256 vcl::Window
* VCLXTopWindow::GetWindowImpl()
258 return VCLXContainer::GetWindow();
261 ::comphelper::OInterfaceContainerHelper2
& VCLXTopWindow::GetTopWindowListenersImpl()
263 return GetTopWindowListeners();
266 // css::uno::XInterface
267 css::uno::Any
VCLXTopWindow::queryInterface( const css::uno::Type
& rType
)
269 css::uno::Any
aRet( VCLXTopWindow_Base::queryInterface( rType
) );
271 if ( !aRet
.hasValue() )
272 aRet
= VCLXContainer::queryInterface( rType
);
277 css::uno::Sequence
< sal_Int8
> VCLXTopWindow::getImplementationId()
279 return css::uno::Sequence
<sal_Int8
>();
282 css::uno::Sequence
< css::uno::Type
> VCLXTopWindow::getTypes()
284 return ::comphelper::concatSequences( VCLXTopWindow_Base::getTypes(), VCLXContainer::getTypes() );
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */