Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / toolkit / source / awt / vclxtopwindow.cxx
blob462a5682184d0a1f2fa526add6baff0fafb39ace
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 <com/sun/star/lang/SystemDependent.hpp>
21 #include <com/sun/star/awt/SystemDependentXWindow.hpp>
23 #if defined ( QUARTZ )
24 #include "premac.h"
25 #include <Cocoa/Cocoa.h>
26 #include "postmac.h"
27 #endif
29 #if defined ( IOS )
30 #include "premac.h"
31 #include <UIKit/UIKit.h>
32 #include "postmac.h"
33 #endif
35 #include <vcl/syschild.hxx>
36 #include <vcl/sysdata.hxx>
37 #include <cppuhelper/typeprovider.hxx>
38 #include <comphelper/sequence.hxx>
40 #include <toolkit/awt/vclxtopwindow.hxx>
41 #include <toolkit/awt/vclxmenu.hxx>
42 #include <toolkit/helper/macros.hxx>
44 #include <vcl/wrkwin.hxx>
45 #include <vcl/syswin.hxx>
46 #include <vcl/menu.hxx>
47 #include <vcl/svapp.hxx>
49 using ::com::sun::star::uno::RuntimeException;
50 using ::com::sun::star::uno::Sequence;
51 using ::com::sun::star::uno::Type;
52 using ::com::sun::star::uno::Any;
53 using ::com::sun::star::lang::IndexOutOfBoundsException;
55 VCLXTopWindow_Base::VCLXTopWindow_Base( const bool _bSupportSystemWindowPeer )
56 :m_bWHWND( _bSupportSystemWindowPeer )
60 VCLXTopWindow_Base::~VCLXTopWindow_Base()
64 Any VCLXTopWindow_Base::queryInterface( const Type & rType ) throw(RuntimeException)
66 ::com::sun::star::uno::Any aRet( VCLXTopWindow_XBase::queryInterface( rType ) );
68 // do not expose XSystemDependentWindowPeer if we do not have a system window handle
69 if ( !aRet.hasValue() && m_bWHWND )
70 aRet = VCLXTopWindow_SBase::queryInterface( rType );
72 return aRet;
75 Sequence< Type > VCLXTopWindow_Base::getTypes() throw(RuntimeException)
77 Sequence< Type > aTypes( VCLXTopWindow_XBase::getTypes() );
78 if ( m_bWHWND )
79 aTypes = ::comphelper::concatSequences( aTypes, VCLXTopWindow_SBase::getTypes() );
80 return aTypes;
83 ::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)
85 SolarMutexGuard aGuard;
87 // TODO, check the process id
88 ::com::sun::star::uno::Any aRet;
89 Window* pWindow = GetWindowImpl();
90 if ( pWindow )
92 const SystemEnvData* pSysData = ((SystemWindow *)pWindow)->GetSystemData();
93 if( pSysData )
95 #if (defined WNT)
96 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32 )
98 aRet <<= (sal_Int32)pSysData->hWnd;
100 #elif (defined QUARTZ)
101 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_MAC )
103 aRet <<= (sal_IntPtr)pSysData->pView;
105 #elif (defined IOS)
106 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_IOS )
108 aRet <<= (sal_IntPtr)pSysData->pView;
110 #elif (defined UNX)
111 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW )
113 ::com::sun::star::awt::SystemDependentXWindow aSD;
114 aSD.DisplayPointer = sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(pSysData->pDisplay));
115 aSD.WindowHandle = pSysData->aWindow;
116 aRet <<= aSD;
118 #endif
121 return aRet;
124 void VCLXTopWindow_Base::addTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
126 SolarMutexGuard aGuard;
128 GetTopWindowListenersImpl().addInterface( rxListener );
131 void VCLXTopWindow_Base::removeTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
133 SolarMutexGuard aGuard;
135 GetTopWindowListenersImpl().removeInterface( rxListener );
138 void VCLXTopWindow_Base::toFront( ) throw(::com::sun::star::uno::RuntimeException)
140 SolarMutexGuard aGuard;
142 Window* pWindow = GetWindowImpl();
143 if ( pWindow )
144 ((WorkWindow*)pWindow)->ToTop( TOTOP_RESTOREWHENMIN );
147 void VCLXTopWindow_Base::toBack( ) throw(::com::sun::star::uno::RuntimeException)
151 void VCLXTopWindow_Base::setMenuBar( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuBar >& rxMenu ) throw(::com::sun::star::uno::RuntimeException)
153 SolarMutexGuard aGuard;
155 SystemWindow* pWindow = (SystemWindow*) GetWindowImpl();
156 if ( pWindow )
158 pWindow->SetMenuBar( NULL );
159 if ( rxMenu.is() )
161 VCLXMenu* pMenu = VCLXMenu::GetImplementation( rxMenu );
162 if ( pMenu && !pMenu->IsPopupMenu() )
163 pWindow->SetMenuBar( (MenuBar*) pMenu->GetMenu() );
166 mxMenuBar = rxMenu;
169 //--------------------------------------------------------------------
170 ::sal_Bool SAL_CALL VCLXTopWindow_Base::getIsMaximized() throw (RuntimeException)
172 SolarMutexGuard aGuard;
174 const WorkWindow* pWindow = dynamic_cast< const WorkWindow* >( GetWindowImpl() );
175 if ( !pWindow )
176 return sal_False;
178 return pWindow->IsMaximized();
181 //--------------------------------------------------------------------
182 void SAL_CALL VCLXTopWindow_Base::setIsMaximized( ::sal_Bool _ismaximized ) throw (RuntimeException)
184 SolarMutexGuard aGuard;
186 WorkWindow* pWindow = dynamic_cast< WorkWindow* >( GetWindowImpl() );
187 if ( !pWindow )
188 return;
190 pWindow->Maximize( _ismaximized );
193 //--------------------------------------------------------------------
194 ::sal_Bool SAL_CALL VCLXTopWindow_Base::getIsMinimized() throw (RuntimeException)
196 SolarMutexGuard aGuard;
198 const WorkWindow* pWindow = dynamic_cast< const WorkWindow* >( GetWindowImpl() );
199 if ( !pWindow )
200 return sal_False;
202 return pWindow->IsMinimized();
205 //--------------------------------------------------------------------
206 void SAL_CALL VCLXTopWindow_Base::setIsMinimized( ::sal_Bool _isMinimized ) throw (RuntimeException)
208 SolarMutexGuard aGuard;
210 WorkWindow* pWindow = dynamic_cast< WorkWindow* >( GetWindowImpl() );
211 if ( !pWindow )
212 return;
214 _isMinimized ? pWindow->Minimize() : pWindow->Restore();
217 //--------------------------------------------------------------------
218 ::sal_Int32 SAL_CALL VCLXTopWindow_Base::getDisplay() throw (RuntimeException)
220 SolarMutexGuard aGuard;
222 const SystemWindow* pWindow = dynamic_cast< const SystemWindow* >( GetWindowImpl() );
223 if ( !pWindow )
224 return 0;
226 return pWindow->GetScreenNumber();
229 //--------------------------------------------------------------------
230 void SAL_CALL VCLXTopWindow_Base::setDisplay( ::sal_Int32 _display ) throw (RuntimeException, IndexOutOfBoundsException)
232 SolarMutexGuard aGuard;
234 if ( ( _display < 0 ) || ( _display >= (sal_Int32)Application::GetScreenCount() ) )
235 throw IndexOutOfBoundsException();
237 SystemWindow* pWindow = dynamic_cast< SystemWindow* >( GetWindowImpl() );
238 if ( !pWindow )
239 return;
241 pWindow->SetScreenNumber( _display );
244 // ----------------------------------------------------
245 // class VCLXTopWindow
246 // ----------------------------------------------------
248 void VCLXTopWindow::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
250 VCLXContainer::ImplGetPropertyIds( rIds );
253 VCLXTopWindow::VCLXTopWindow(bool bWHWND)
254 : VCLXTopWindow_Base( bWHWND )
258 VCLXTopWindow::~VCLXTopWindow()
262 Window* VCLXTopWindow::GetWindowImpl()
264 return VCLXContainer::GetWindow();
267 ::cppu::OInterfaceContainerHelper& VCLXTopWindow::GetTopWindowListenersImpl()
269 return GetTopWindowListeners();
272 // ::com::sun::star::uno::XInterface
273 ::com::sun::star::uno::Any VCLXTopWindow::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
275 ::com::sun::star::uno::Any aRet( VCLXTopWindow_Base::queryInterface( rType ) );
277 if ( !aRet.hasValue() )
278 aRet = VCLXContainer::queryInterface( rType );
280 return aRet;
283 ::com::sun::star::uno::Sequence< sal_Int8 > VCLXTopWindow::getImplementationId() throw(::com::sun::star::uno::RuntimeException)
285 static ::cppu::OImplementationId* pId = NULL;
286 static ::cppu::OImplementationId* pIdWithHandle = NULL;
287 if ( isSystemDependentWindowPeer() )
289 if( !pIdWithHandle )
291 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
292 if( !pIdWithHandle )
294 static ::cppu::OImplementationId idWithHandle( sal_False );
295 pIdWithHandle = &idWithHandle;
299 return (*pIdWithHandle).getImplementationId();
301 else
303 if( !pId )
305 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
306 if( !pId )
308 static ::cppu::OImplementationId id( sal_False );
309 pId = &id;
313 return (*pId).getImplementationId();
317 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > VCLXTopWindow::getTypes() throw(::com::sun::star::uno::RuntimeException)
319 return ::comphelper::concatSequences( VCLXTopWindow_Base::getTypes(), VCLXContainer::getTypes() );
322 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */