merge the formfield patch from ooo-build
[ooovba.git] / toolkit / source / awt / vclxtopwindow.cxx
blobf490a78ee9960b80e3a6be5b13745e936490310d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxtopwindow.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_toolkit.hxx"
33 #include <com/sun/star/lang/SystemDependent.hpp>
34 #include <com/sun/star/awt/SystemDependentXWindow.hpp>
36 #ifdef WNT
37 #include <tools/prewin.h>
38 #include <windows.h>
39 #include <tools/postwin.h>
40 #elif defined ( QUARTZ )
41 #include "premac.h"
42 #include <Cocoa/Cocoa.h>
43 #include "postmac.h"
44 #endif
46 #include <vcl/syschild.hxx>
47 #include <vcl/sysdata.hxx>
48 #include <cppuhelper/typeprovider.hxx>
50 #include <toolkit/awt/vclxtopwindow.hxx>
51 #include <toolkit/awt/vclxmenu.hxx>
52 #include <toolkit/helper/macros.hxx>
54 #include <vcl/wrkwin.hxx>
55 #include <vcl/syswin.hxx>
56 #include <vcl/menu.hxx>
58 #include <tools/debug.hxx>
60 VCLXTopWindow_Base::~VCLXTopWindow_Base()
64 ::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)
66 ::vos::OGuard aGuard( GetMutexImpl() );
68 // TODO, check the process id
69 ::com::sun::star::uno::Any aRet;
70 Window* pWindow = GetWindowImpl();
71 if ( pWindow )
73 const SystemEnvData* pSysData = ((SystemWindow *)pWindow)->GetSystemData();
74 if( pSysData )
76 #if (defined WNT)
77 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32 )
79 aRet <<= (sal_Int32)pSysData->hWnd;
81 #elif (defined OS2)
82 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_OS2 )
84 aRet <<= (sal_Int32)pSysData->hWnd;
86 #elif (defined QUARTZ)
87 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_MAC )
89 aRet <<= (sal_IntPtr)pSysData->pView;
91 #elif (defined UNX)
92 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW )
94 ::com::sun::star::awt::SystemDependentXWindow aSD;
95 aSD.DisplayPointer = sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(pSysData->pDisplay));
96 aSD.WindowHandle = pSysData->aWindow;
97 aRet <<= aSD;
99 #endif
102 return aRet;
105 void VCLXTopWindow_Base::addTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
107 ::vos::OGuard aGuard( GetMutexImpl() );
109 GetTopWindowListenersImpl().addInterface( rxListener );
112 void VCLXTopWindow_Base::removeTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
114 ::vos::OGuard aGuard( GetMutexImpl() );
116 GetTopWindowListenersImpl().removeInterface( rxListener );
119 void VCLXTopWindow_Base::toFront( ) throw(::com::sun::star::uno::RuntimeException)
121 ::vos::OGuard aGuard( GetMutexImpl() );
123 Window* pWindow = GetWindowImpl();
124 if ( pWindow )
125 ((WorkWindow*)pWindow)->ToTop( TOTOP_RESTOREWHENMIN );
128 void VCLXTopWindow_Base::toBack( ) throw(::com::sun::star::uno::RuntimeException)
130 #if 0 // Not possible in VCL...
132 ::vos::OGuard aGuard( GetMutexImpl() );
134 Window* pWindow = GetWindowImpl();
135 if ( pWindow )
137 ((WorkWindow*)pWindow)->ToBack();
139 #endif
142 void VCLXTopWindow_Base::setMenuBar( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuBar >& rxMenu ) throw(::com::sun::star::uno::RuntimeException)
144 ::vos::OGuard aGuard( GetMutexImpl() );
146 SystemWindow* pWindow = (SystemWindow*) GetWindowImpl();
147 if ( pWindow )
149 pWindow->SetMenuBar( NULL );
150 if ( rxMenu.is() )
152 VCLXMenu* pMenu = VCLXMenu::GetImplementation( rxMenu );
153 if ( pMenu && !pMenu->IsPopupMenu() )
154 pWindow->SetMenuBar( (MenuBar*) pMenu->GetMenu() );
157 mxMenuBar = rxMenu;
160 // ----------------------------------------------------
161 // class VCLXTopWindow
162 // ----------------------------------------------------
164 void VCLXTopWindow::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
166 VCLXContainer::ImplGetPropertyIds( rIds );
169 VCLXTopWindow::VCLXTopWindow(bool bWHWND)
170 : m_bWHWND(bWHWND)
174 VCLXTopWindow::~VCLXTopWindow()
178 vos::IMutex& VCLXTopWindow::GetMutexImpl()
180 return VCLXContainer::GetMutex();
183 Window* VCLXTopWindow::GetWindowImpl()
185 return VCLXContainer::GetWindow();
188 ::cppu::OInterfaceContainerHelper& VCLXTopWindow::GetTopWindowListenersImpl()
190 return GetTopWindowListeners();
193 // ::com::sun::star::uno::XInterface
194 ::com::sun::star::uno::Any VCLXTopWindow::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
196 ::com::sun::star::uno::Any aRet;
197 if(! m_bWHWND) {
198 aRet = ::cppu::queryInterface( rType,
199 SAL_STATIC_CAST( ::com::sun::star::awt::XTopWindow*, this ) );
201 else {
202 aRet = ::cppu::queryInterface( rType,
203 SAL_STATIC_CAST( ::com::sun::star::awt::XTopWindow*, this ),
204 SAL_STATIC_CAST( ::com::sun::star::awt::XSystemDependentWindowPeer*, this ) );
206 return (aRet.hasValue() ? aRet : VCLXContainer::queryInterface( rType ));
209 ::com::sun::star::uno::Sequence< sal_Int8 > VCLXTopWindow::getImplementationId() throw(::com::sun::star::uno::RuntimeException)
211 static ::cppu::OImplementationId* pId = NULL;
212 static ::cppu::OImplementationId* pIdWithHandle = NULL;
213 if ( m_bWHWND )
215 if( !pIdWithHandle )
217 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
218 if( !pIdWithHandle )
220 static ::cppu::OImplementationId idWithHandle( sal_False );
221 pIdWithHandle = &idWithHandle;
225 return (*pIdWithHandle).getImplementationId();
227 else
229 if( !pId )
231 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
232 if( !pId )
234 static ::cppu::OImplementationId id( sal_False );
235 pId = &id;
239 return (*pId).getImplementationId();
243 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > VCLXTopWindow::getTypes() throw(::com::sun::star::uno::RuntimeException)
245 static ::cppu::OTypeCollection* pCollection = NULL;
246 static ::cppu::OTypeCollection* pCollectionWithHandle = NULL;
248 if ( m_bWHWND )
250 if( !pCollectionWithHandle )
252 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
253 if( !pCollectionWithHandle )
255 static ::cppu::OTypeCollection collectionWithHandle(
256 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider>* ) NULL ),
257 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindow>* ) NULL ),
258 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSystemDependentWindowPeer>* ) NULL ),
259 VCLXContainer::getTypes() );
260 pCollectionWithHandle = &collectionWithHandle;
264 return (*pCollectionWithHandle).getTypes();
266 else
268 if( !pCollection )
270 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
271 if( !pCollection )
273 static ::cppu::OTypeCollection collection(
274 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider>* ) NULL ),
275 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindow>* ) NULL ),
276 VCLXContainer::getTypes() );
277 pCollection = &collection;
280 return (*pCollection).getTypes();