tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / toolkit / source / awt / vclxtopwindow.cxx
blob55dbb8070b9150d22fadec996aa3fdf0567589d6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 )
27 #include <premac.h>
28 #include <Cocoa/Cocoa.h>
29 #include <postmac.h>
30 #endif
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
53 css::uno::Any aRet;
54 vcl::Window* pWindow = VCLXContainer::GetWindow();
55 if ( pWindow )
57 const SystemEnvData* pSysData = static_cast<SystemWindow *>(pWindow)->GetSystemData();
58 if( pSysData )
60 #if defined (_WIN32)
61 if( SystemType == css::lang::SystemDependent::SYSTEM_WIN32 )
63 aRet <<= reinterpret_cast<sal_IntPtr>(pSysData->hWnd);
65 #elif defined(MACOSX)
66 if( SystemType == css::lang::SystemDependent::SYSTEM_MAC )
68 aRet <<= reinterpret_cast<sal_IntPtr>(pSysData->mpNSView);
70 #elif defined(ANDROID)
71 // Nothing
72 (void) SystemType;
73 #elif defined(IOS)
74 // Nothing
75 (void) SystemType;
76 #elif defined(UNX)
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());
82 aRet <<= aSD;
84 #endif
87 return aRet;
90 void VCLXTopWindow::addTopWindowListener( const css::uno::Reference< css::awt::XTopWindowListener >& rxListener )
92 SolarMutexGuard aGuard;
94 if (!IsDisposed())
95 GetTopWindowListeners().addInterface( rxListener );
98 void VCLXTopWindow::removeTopWindowListener( const css::uno::Reference< css::awt::XTopWindowListener >& rxListener )
100 SolarMutexGuard aGuard;
102 if (!IsDisposed())
103 GetTopWindowListeners().removeInterface( rxListener );
106 void VCLXTopWindow::toFront( )
108 SolarMutexGuard aGuard;
110 vcl::Window* pWindow = VCLXContainer::GetWindow();
111 if (pWindow)
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();
124 if ( pWindow )
126 SystemWindow* pSystemWindow = static_cast<SystemWindow*>( pWindow );
127 pSystemWindow->SetMenuBar( nullptr );
128 if ( rxMenu.is() )
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>();
143 if ( !pWindow )
144 return false;
146 return pWindow->IsMaximized();
150 void SAL_CALL VCLXTopWindow::setIsMaximized( sal_Bool _ismaximized )
152 SolarMutexGuard aGuard;
154 WorkWindow* pWindow = VCLXContainer::GetAsDynamic<WorkWindow>();
155 if ( !pWindow )
156 return;
158 pWindow->Maximize( _ismaximized );
162 sal_Bool SAL_CALL VCLXTopWindow::getIsMinimized()
164 SolarMutexGuard aGuard;
166 const WorkWindow* pWindow = VCLXContainer::GetAsDynamic<WorkWindow>();
167 if ( !pWindow )
168 return false;
170 return pWindow->IsMinimized();
174 void SAL_CALL VCLXTopWindow::setIsMinimized( sal_Bool _isMinimized )
176 SolarMutexGuard aGuard;
178 WorkWindow* pWindow = VCLXContainer::GetAsDynamic<WorkWindow>();
179 if ( !pWindow )
180 return;
182 _isMinimized ? pWindow->Minimize() : pWindow->Restore();
186 ::sal_Int32 SAL_CALL VCLXTopWindow::getDisplay()
188 SolarMutexGuard aGuard;
190 const SystemWindow* pWindow = VCLXContainer::GetAsDynamic<SystemWindow>();
191 if ( !pWindow )
192 return 0;
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>();
206 if ( !pWindow )
207 return;
209 pWindow->SetScreenNumber( _display );
212 sal_Bool VCLXTopWindow::getFullScreen() {
213 SolarMutexGuard g;
214 if (auto const win = VCLXContainer::GetAsDynamic<WorkWindow>()) {
215 return win->IsFullScreenMode();
217 return false;
220 void VCLXTopWindow::setFullScreen(sal_Bool value) {
221 SolarMutexGuard g;
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: */