1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxtopwindow.cxx,v $
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>
37 #include <tools/prewin.h>
39 #include <tools/postwin.h>
40 #elif defined ( QUARTZ )
42 #include <Cocoa/Cocoa.h>
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();
73 const SystemEnvData
* pSysData
= ((SystemWindow
*)pWindow
)->GetSystemData();
77 if( SystemType
== ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32
)
79 aRet
<<= (sal_Int32
)pSysData
->hWnd
;
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
;
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
;
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();
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();
137 ((WorkWindow
*)pWindow
)->ToBack();
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();
149 pWindow
->SetMenuBar( NULL
);
152 VCLXMenu
* pMenu
= VCLXMenu::GetImplementation( rxMenu
);
153 if ( pMenu
&& !pMenu
->IsPopupMenu() )
154 pWindow
->SetMenuBar( (MenuBar
*) pMenu
->GetMenu() );
160 // ----------------------------------------------------
161 // class VCLXTopWindow
162 // ----------------------------------------------------
164 void VCLXTopWindow::ImplGetPropertyIds( std::list
< sal_uInt16
> &rIds
)
166 VCLXContainer::ImplGetPropertyIds( rIds
);
169 VCLXTopWindow::VCLXTopWindow(bool 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
;
198 aRet
= ::cppu::queryInterface( rType
,
199 SAL_STATIC_CAST( ::com::sun::star::awt::XTopWindow
*, this ) );
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
;
217 ::osl::Guard
< ::osl::Mutex
> aGuard( ::osl::Mutex::getGlobalMutex() );
220 static ::cppu::OImplementationId
idWithHandle( sal_False
);
221 pIdWithHandle
= &idWithHandle
;
225 return (*pIdWithHandle
).getImplementationId();
231 ::osl::Guard
< ::osl::Mutex
> aGuard( ::osl::Mutex::getGlobalMutex() );
234 static ::cppu::OImplementationId
id( sal_False
);
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
;
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();
270 ::osl::Guard
< ::osl::Mutex
> aGuard( ::osl::Mutex::getGlobalMutex() );
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();