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/sysdata.hxx>
33 #include <o3tl/safeint.hxx>
35 #include <awt/vclxtopwindow.hxx>
36 #include <toolkit/awt/vclxmenu.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::Sequence
;
44 using ::com::sun::star::uno::Any
;
45 using ::com::sun::star::lang::IndexOutOfBoundsException
;
48 css::uno::Any
VCLXTopWindow::getWindowHandle( const css::uno::Sequence
< sal_Int8
>& /*ProcessId*/, sal_Int16 SystemType
)
50 SolarMutexGuard aGuard
;
52 // TODO, check the process id
54 vcl::Window
* pWindow
= VCLXContainer::GetWindow();
57 const SystemEnvData
* pSysData
= static_cast<SystemWindow
*>(pWindow
)->GetSystemData();
61 if( SystemType
== css::lang::SystemDependent::SYSTEM_WIN32
)
63 aRet
<<= reinterpret_cast<sal_IntPtr
>(pSysData
->hWnd
);
66 if( SystemType
== css::lang::SystemDependent::SYSTEM_MAC
)
68 aRet
<<= reinterpret_cast<sal_IntPtr
>(pSysData
->mpNSView
);
70 #elif defined(ANDROID)
77 if( SystemType
== css::lang::SystemDependent::SYSTEM_XWINDOW
)
79 css::awt::SystemDependentXWindow aSD
;
80 aSD
.DisplayPointer
= sal::static_int_cast
< sal_Int64
>(reinterpret_cast< sal_IntPtr
>(pSysData
->pDisplay
));
81 aSD
.WindowHandle
= pSysData
->GetWindowHandle(pWindow
->ImplGetFrame());
90 void VCLXTopWindow::addTopWindowListener( const css::uno::Reference
< css::awt::XTopWindowListener
>& rxListener
)
92 SolarMutexGuard aGuard
;
95 GetTopWindowListeners().addInterface( rxListener
);
98 void VCLXTopWindow::removeTopWindowListener( const css::uno::Reference
< css::awt::XTopWindowListener
>& rxListener
)
100 SolarMutexGuard aGuard
;
103 GetTopWindowListeners().removeInterface( rxListener
);
106 void VCLXTopWindow::toFront( )
108 SolarMutexGuard aGuard
;
110 vcl::Window
* pWindow
= VCLXContainer::GetWindow();
112 pWindow
->ToTop( ToTopFlags::RestoreWhenMin
);
115 void VCLXTopWindow::toBack( )
119 void VCLXTopWindow::setMenuBar( const css::uno::Reference
< css::awt::XMenuBar
>& rxMenu
)
121 SolarMutexGuard aGuard
;
123 vcl::Window
* pWindow
= VCLXContainer::GetWindow();
126 SystemWindow
* pSystemWindow
= static_cast<SystemWindow
*>( pWindow
);
127 pSystemWindow
->SetMenuBar( nullptr );
130 VCLXMenu
* pMenu
= dynamic_cast<VCLXMenu
*>( rxMenu
.get() );
131 if ( pMenu
&& !pMenu
->IsPopupMenu() )
132 pSystemWindow
->SetMenuBar( static_cast<MenuBar
*>( pMenu
->GetMenu() ));
138 sal_Bool SAL_CALL
VCLXTopWindow::getIsMaximized()
140 SolarMutexGuard aGuard
;
142 const WorkWindow
* pWindow
= VCLXContainer::GetAsDynamic
<WorkWindow
>();
146 return pWindow
->IsMaximized();
150 void SAL_CALL
VCLXTopWindow::setIsMaximized( sal_Bool _ismaximized
)
152 SolarMutexGuard aGuard
;
154 WorkWindow
* pWindow
= VCLXContainer::GetAsDynamic
<WorkWindow
>();
158 pWindow
->Maximize( _ismaximized
);
162 sal_Bool SAL_CALL
VCLXTopWindow::getIsMinimized()
164 SolarMutexGuard aGuard
;
166 const WorkWindow
* pWindow
= VCLXContainer::GetAsDynamic
<WorkWindow
>();
170 return pWindow
->IsMinimized();
174 void SAL_CALL
VCLXTopWindow::setIsMinimized( sal_Bool _isMinimized
)
176 SolarMutexGuard aGuard
;
178 WorkWindow
* pWindow
= VCLXContainer::GetAsDynamic
<WorkWindow
>();
182 _isMinimized
? pWindow
->Minimize() : pWindow
->Restore();
186 ::sal_Int32 SAL_CALL
VCLXTopWindow::getDisplay()
188 SolarMutexGuard aGuard
;
190 const SystemWindow
* pWindow
= VCLXContainer::GetAsDynamic
<SystemWindow
>();
194 return pWindow
->GetScreenNumber();
198 void SAL_CALL
VCLXTopWindow::setDisplay( ::sal_Int32 _display
)
200 SolarMutexGuard aGuard
;
202 if ( ( _display
< 0 ) || ( o3tl::make_unsigned(_display
) >= Application::GetScreenCount() ) )
203 throw IndexOutOfBoundsException();
205 SystemWindow
* pWindow
= VCLXContainer::GetAsDynamic
<SystemWindow
>();
209 pWindow
->SetScreenNumber( _display
);
212 sal_Bool
VCLXTopWindow::getFullScreen() {
214 if (auto const win
= VCLXContainer::GetAsDynamic
<WorkWindow
>()) {
215 return win
->IsFullScreenMode();
220 void VCLXTopWindow::setFullScreen(sal_Bool value
) {
222 if (auto const win
= VCLXContainer::GetAsDynamic
<WorkWindow
>()) {
223 return win
->ShowFullScreenMode(value
);
229 void VCLXTopWindow::ImplGetPropertyIds( std::vector
< sal_uInt16
> &rIds
)
231 VCLXContainer::ImplGetPropertyIds( rIds
);
234 VCLXTopWindow::VCLXTopWindow()
238 VCLXTopWindow::~VCLXTopWindow()
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */