sync master with lastest vba changes
[ooovba.git] / toolkit / source / awt / vclxtopwindow.cxx
blob124f250a65bd290353df309f19cc018c78d75bf1
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 #if !defined(UNX) && !defined(OS2)
37 #include <tools/prewin.h>
38 #include <windows.h>
39 #include <tools/postwin.h>
40 #endif
42 #ifdef QUARTZ
43 #include "premac.h"
44 #include <Cocoa/Cocoa.h>
45 #include "postmac.h"
46 #endif
48 #include <vcl/syschild.hxx>
49 #include <vcl/sysdata.hxx>
50 #include <cppuhelper/typeprovider.hxx>
52 #include <toolkit/awt/vclxtopwindow.hxx>
53 #include <toolkit/awt/vclxmenu.hxx>
54 #include <toolkit/helper/macros.hxx>
56 #include <vcl/wrkwin.hxx>
57 #include <vcl/syswin.hxx>
58 #include <vcl/menu.hxx>
60 #include <tools/debug.hxx>
62 VCLXTopWindow_Base::~VCLXTopWindow_Base()
66 ::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)
68 ::vos::OGuard aGuard( GetMutexImpl() );
70 // TODO, check the process id
71 ::com::sun::star::uno::Any aRet;
72 Window* pWindow = GetWindowImpl();
73 if ( pWindow )
75 const SystemEnvData* pSysData = ((SystemWindow *)pWindow)->GetSystemData();
76 if( pSysData )
78 #if (defined WNT)
79 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32 )
81 aRet <<= (sal_Int32)pSysData->hWnd;
83 #elif (defined OS2)
84 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_OS2 )
86 aRet <<= (sal_Int32)pSysData->hWnd;
88 #elif (defined QUARTZ)
89 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_MAC )
91 aRet <<= (sal_IntPtr)pSysData->pView;
93 #elif (defined UNX)
94 if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW )
96 ::com::sun::star::awt::SystemDependentXWindow aSD;
97 aSD.DisplayPointer = sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(pSysData->pDisplay));
98 aSD.WindowHandle = pSysData->aWindow;
99 aRet <<= aSD;
101 #endif
104 return aRet;
107 void VCLXTopWindow_Base::addTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
109 ::vos::OGuard aGuard( GetMutexImpl() );
111 GetTopWindowListenersImpl().addInterface( rxListener );
114 void VCLXTopWindow_Base::removeTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
116 ::vos::OGuard aGuard( GetMutexImpl() );
118 GetTopWindowListenersImpl().removeInterface( rxListener );
121 void VCLXTopWindow_Base::toFront( ) throw(::com::sun::star::uno::RuntimeException)
123 ::vos::OGuard aGuard( GetMutexImpl() );
125 Window* pWindow = GetWindowImpl();
126 if ( pWindow )
127 ((WorkWindow*)pWindow)->ToTop( TOTOP_RESTOREWHENMIN );
130 void VCLXTopWindow_Base::toBack( ) throw(::com::sun::star::uno::RuntimeException)
132 #if 0 // Not possible in VCL...
134 ::vos::OGuard aGuard( GetMutexImpl() );
136 Window* pWindow = GetWindowImpl();
137 if ( pWindow )
139 ((WorkWindow*)pWindow)->ToBack();
141 #endif
144 void VCLXTopWindow_Base::setMenuBar( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuBar >& rxMenu ) throw(::com::sun::star::uno::RuntimeException)
146 ::vos::OGuard aGuard( GetMutexImpl() );
148 SystemWindow* pWindow = (SystemWindow*) GetWindowImpl();
149 if ( pWindow )
151 pWindow->SetMenuBar( NULL );
152 if ( rxMenu.is() )
154 VCLXMenu* pMenu = VCLXMenu::GetImplementation( rxMenu );
155 if ( pMenu && !pMenu->IsPopupMenu() )
156 pWindow->SetMenuBar( (MenuBar*) pMenu->GetMenu() );
159 mxMenuBar = rxMenu;
162 // ----------------------------------------------------
163 // class VCLXTopWindow
164 // ----------------------------------------------------
166 void VCLXTopWindow::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds )
168 VCLXContainer::ImplGetPropertyIds( rIds );
171 VCLXTopWindow::VCLXTopWindow(bool bWHWND)
172 : m_bWHWND(bWHWND)
176 VCLXTopWindow::~VCLXTopWindow()
180 vos::IMutex& VCLXTopWindow::GetMutexImpl()
182 return VCLXContainer::GetMutex();
185 Window* VCLXTopWindow::GetWindowImpl()
187 return VCLXContainer::GetWindow();
190 ::cppu::OInterfaceContainerHelper& VCLXTopWindow::GetTopWindowListenersImpl()
192 return GetTopWindowListeners();
195 // ::com::sun::star::uno::XInterface
196 ::com::sun::star::uno::Any VCLXTopWindow::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
198 ::com::sun::star::uno::Any aRet;
199 if(! m_bWHWND) {
200 aRet = ::cppu::queryInterface( rType,
201 SAL_STATIC_CAST( ::com::sun::star::awt::XTopWindow*, this ) );
203 else {
204 aRet = ::cppu::queryInterface( rType,
205 SAL_STATIC_CAST( ::com::sun::star::awt::XTopWindow*, this ),
206 SAL_STATIC_CAST( ::com::sun::star::awt::XSystemDependentWindowPeer*, this ) );
208 return (aRet.hasValue() ? aRet : VCLXContainer::queryInterface( rType ));
211 ::com::sun::star::uno::Sequence< sal_Int8 > VCLXTopWindow::getImplementationId() throw(::com::sun::star::uno::RuntimeException)
213 static ::cppu::OImplementationId* pId = NULL;
214 static ::cppu::OImplementationId* pIdWithHandle = NULL;
215 if ( m_bWHWND )
217 if( !pIdWithHandle )
219 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
220 if( !pIdWithHandle )
222 static ::cppu::OImplementationId idWithHandle( sal_False );
223 pIdWithHandle = &idWithHandle;
227 return (*pIdWithHandle).getImplementationId();
229 else
231 if( !pId )
233 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
234 if( !pId )
236 static ::cppu::OImplementationId id( sal_False );
237 pId = &id;
241 return (*pId).getImplementationId();
245 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > VCLXTopWindow::getTypes() throw(::com::sun::star::uno::RuntimeException)
247 static ::cppu::OTypeCollection* pCollection = NULL;
248 static ::cppu::OTypeCollection* pCollectionWithHandle = NULL;
250 if ( m_bWHWND )
252 if( !pCollectionWithHandle )
254 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
255 if( !pCollectionWithHandle )
257 static ::cppu::OTypeCollection collectionWithHandle(
258 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider>* ) NULL ),
259 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindow>* ) NULL ),
260 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XSystemDependentWindowPeer>* ) NULL ),
261 VCLXContainer::getTypes() );
262 pCollectionWithHandle = &collectionWithHandle;
266 return (*pCollectionWithHandle).getTypes();
268 else
270 if( !pCollection )
272 ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
273 if( !pCollection )
275 static ::cppu::OTypeCollection collection(
276 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider>* ) NULL ),
277 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindow>* ) NULL ),
278 VCLXContainer::getTypes() );
279 pCollection = &collection;
282 return (*pCollection).getTypes();