1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_toolkit.hxx" 30*cdf0e10cSrcweir #include <com/sun/star/lang/SystemDependent.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/awt/SystemDependentXWindow.hpp> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #ifdef WNT 34*cdf0e10cSrcweir #include <tools/prewin.h> 35*cdf0e10cSrcweir #include <windows.h> 36*cdf0e10cSrcweir #include <tools/postwin.h> 37*cdf0e10cSrcweir #elif defined ( QUARTZ ) 38*cdf0e10cSrcweir #include "premac.h" 39*cdf0e10cSrcweir #include <Cocoa/Cocoa.h> 40*cdf0e10cSrcweir #include "postmac.h" 41*cdf0e10cSrcweir #endif 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #include <vcl/syschild.hxx> 44*cdf0e10cSrcweir #include <vcl/sysdata.hxx> 45*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 46*cdf0e10cSrcweir #include <comphelper/sequence.hxx> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #include <toolkit/awt/vclxtopwindow.hxx> 49*cdf0e10cSrcweir #include <toolkit/awt/vclxmenu.hxx> 50*cdf0e10cSrcweir #include <toolkit/helper/macros.hxx> 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #include <vcl/wrkwin.hxx> 53*cdf0e10cSrcweir #include <vcl/syswin.hxx> 54*cdf0e10cSrcweir #include <vcl/menu.hxx> 55*cdf0e10cSrcweir #include <vcl/svapp.hxx> 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir #include <tools/debug.hxx> 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 60*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 61*cdf0e10cSrcweir using ::com::sun::star::uno::Type; 62*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 63*cdf0e10cSrcweir using ::com::sun::star::lang::IndexOutOfBoundsException; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir VCLXTopWindow_Base::VCLXTopWindow_Base( const bool _bSupportSystemWindowPeer ) 66*cdf0e10cSrcweir :m_bWHWND( _bSupportSystemWindowPeer ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir VCLXTopWindow_Base::~VCLXTopWindow_Base() 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir Any VCLXTopWindow_Base::queryInterface( const Type & rType ) throw(RuntimeException) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir ::com::sun::star::uno::Any aRet( VCLXTopWindow_XBase::queryInterface( rType ) ); 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir // do not expose XSystemDependentWindowPeer if we do not have a system window handle 79*cdf0e10cSrcweir if ( !aRet.hasValue() && m_bWHWND ) 80*cdf0e10cSrcweir aRet = VCLXTopWindow_SBase::queryInterface( rType ); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir return aRet; 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir Sequence< Type > VCLXTopWindow_Base::getTypes() throw(RuntimeException) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir Sequence< Type > aTypes( VCLXTopWindow_XBase::getTypes() ); 88*cdf0e10cSrcweir if ( m_bWHWND ) 89*cdf0e10cSrcweir aTypes = ::comphelper::concatSequences( aTypes, VCLXTopWindow_SBase::getTypes() ); 90*cdf0e10cSrcweir return aTypes; 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir ::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) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutexImpl() ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // TODO, check the process id 98*cdf0e10cSrcweir ::com::sun::star::uno::Any aRet; 99*cdf0e10cSrcweir Window* pWindow = GetWindowImpl(); 100*cdf0e10cSrcweir if ( pWindow ) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir const SystemEnvData* pSysData = ((SystemWindow *)pWindow)->GetSystemData(); 103*cdf0e10cSrcweir if( pSysData ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir #if (defined WNT) 106*cdf0e10cSrcweir if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_WIN32 ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir aRet <<= (sal_Int32)pSysData->hWnd; 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir #elif (defined OS2) 111*cdf0e10cSrcweir if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_OS2 ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir aRet <<= (sal_Int32)pSysData->hWnd; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir #elif (defined QUARTZ) 116*cdf0e10cSrcweir if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_MAC ) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir aRet <<= (sal_IntPtr)pSysData->pView; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir #elif (defined UNX) 121*cdf0e10cSrcweir if( SystemType == ::com::sun::star::lang::SystemDependent::SYSTEM_XWINDOW ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir ::com::sun::star::awt::SystemDependentXWindow aSD; 124*cdf0e10cSrcweir aSD.DisplayPointer = sal::static_int_cast< sal_Int64 >(reinterpret_cast< sal_IntPtr >(pSysData->pDisplay)); 125*cdf0e10cSrcweir aSD.WindowHandle = pSysData->aWindow; 126*cdf0e10cSrcweir aRet <<= aSD; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir #endif 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir return aRet; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir void VCLXTopWindow_Base::addTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutexImpl() ); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir GetTopWindowListenersImpl().addInterface( rxListener ); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir void VCLXTopWindow_Base::removeTopWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTopWindowListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutexImpl() ); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir GetTopWindowListenersImpl().removeInterface( rxListener ); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir void VCLXTopWindow_Base::toFront( ) throw(::com::sun::star::uno::RuntimeException) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutexImpl() ); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir Window* pWindow = GetWindowImpl(); 153*cdf0e10cSrcweir if ( pWindow ) 154*cdf0e10cSrcweir ((WorkWindow*)pWindow)->ToTop( TOTOP_RESTOREWHENMIN ); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir void VCLXTopWindow_Base::toBack( ) throw(::com::sun::star::uno::RuntimeException) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir #if 0 // Not possible in VCL... 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutexImpl() ); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir Window* pWindow = GetWindowImpl(); 164*cdf0e10cSrcweir if ( pWindow ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir ((WorkWindow*)pWindow)->ToBack(); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir #endif 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir void VCLXTopWindow_Base::setMenuBar( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuBar >& rxMenu ) throw(::com::sun::star::uno::RuntimeException) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutexImpl() ); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir SystemWindow* pWindow = (SystemWindow*) GetWindowImpl(); 176*cdf0e10cSrcweir if ( pWindow ) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir pWindow->SetMenuBar( NULL ); 179*cdf0e10cSrcweir if ( rxMenu.is() ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir VCLXMenu* pMenu = VCLXMenu::GetImplementation( rxMenu ); 182*cdf0e10cSrcweir if ( pMenu && !pMenu->IsPopupMenu() ) 183*cdf0e10cSrcweir pWindow->SetMenuBar( (MenuBar*) pMenu->GetMenu() ); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir mxMenuBar = rxMenu; 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir //-------------------------------------------------------------------- 190*cdf0e10cSrcweir ::sal_Bool SAL_CALL VCLXTopWindow_Base::getIsMaximized() throw (RuntimeException) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutexImpl() ); 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir const WorkWindow* pWindow = dynamic_cast< const WorkWindow* >( GetWindowImpl() ); 195*cdf0e10cSrcweir if ( !pWindow ) 196*cdf0e10cSrcweir return sal_False; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir return pWindow->IsMaximized(); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir //-------------------------------------------------------------------- 202*cdf0e10cSrcweir void SAL_CALL VCLXTopWindow_Base::setIsMaximized( ::sal_Bool _ismaximized ) throw (RuntimeException) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutexImpl() ); 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir WorkWindow* pWindow = dynamic_cast< WorkWindow* >( GetWindowImpl() ); 207*cdf0e10cSrcweir if ( !pWindow ) 208*cdf0e10cSrcweir return; 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir pWindow->Maximize( _ismaximized ); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir //-------------------------------------------------------------------- 214*cdf0e10cSrcweir ::sal_Bool SAL_CALL VCLXTopWindow_Base::getIsMinimized() throw (RuntimeException) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutexImpl() ); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir const WorkWindow* pWindow = dynamic_cast< const WorkWindow* >( GetWindowImpl() ); 219*cdf0e10cSrcweir if ( !pWindow ) 220*cdf0e10cSrcweir return sal_False; 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir return pWindow->IsMinimized(); 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir //-------------------------------------------------------------------- 226*cdf0e10cSrcweir void SAL_CALL VCLXTopWindow_Base::setIsMinimized( ::sal_Bool _isMinimized ) throw (RuntimeException) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutexImpl() ); 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir WorkWindow* pWindow = dynamic_cast< WorkWindow* >( GetWindowImpl() ); 231*cdf0e10cSrcweir if ( !pWindow ) 232*cdf0e10cSrcweir return; 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir _isMinimized ? pWindow->Minimize() : pWindow->Restore(); 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir //-------------------------------------------------------------------- 238*cdf0e10cSrcweir ::sal_Int32 SAL_CALL VCLXTopWindow_Base::getDisplay() throw (RuntimeException) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutexImpl() ); 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir const SystemWindow* pWindow = dynamic_cast< const SystemWindow* >( GetWindowImpl() ); 243*cdf0e10cSrcweir if ( !pWindow ) 244*cdf0e10cSrcweir return 0; 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir return pWindow->GetScreenNumber(); 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir //-------------------------------------------------------------------- 250*cdf0e10cSrcweir void SAL_CALL VCLXTopWindow_Base::setDisplay( ::sal_Int32 _display ) throw (RuntimeException, IndexOutOfBoundsException) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutexImpl() ); 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir if ( ( _display < 0 ) || ( _display >= (sal_Int32)Application::GetScreenCount() ) ) 255*cdf0e10cSrcweir throw IndexOutOfBoundsException(); 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir SystemWindow* pWindow = dynamic_cast< SystemWindow* >( GetWindowImpl() ); 258*cdf0e10cSrcweir if ( !pWindow ) 259*cdf0e10cSrcweir return; 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir pWindow->SetScreenNumber( _display ); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir // ---------------------------------------------------- 265*cdf0e10cSrcweir // class VCLXTopWindow 266*cdf0e10cSrcweir // ---------------------------------------------------- 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir void VCLXTopWindow::ImplGetPropertyIds( std::list< sal_uInt16 > &rIds ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir VCLXContainer::ImplGetPropertyIds( rIds ); 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir VCLXTopWindow::VCLXTopWindow(bool bWHWND) 274*cdf0e10cSrcweir : VCLXTopWindow_Base( bWHWND ) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir VCLXTopWindow::~VCLXTopWindow() 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir vos::IMutex& VCLXTopWindow::GetMutexImpl() 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir return VCLXContainer::GetMutex(); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir Window* VCLXTopWindow::GetWindowImpl() 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir return VCLXContainer::GetWindow(); 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper& VCLXTopWindow::GetTopWindowListenersImpl() 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir return GetTopWindowListeners(); 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir // ::com::sun::star::uno::XInterface 298*cdf0e10cSrcweir ::com::sun::star::uno::Any VCLXTopWindow::queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException) 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir ::com::sun::star::uno::Any aRet( VCLXTopWindow_Base::queryInterface( rType ) ); 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir if ( !aRet.hasValue() ) 303*cdf0e10cSrcweir aRet = VCLXContainer::queryInterface( rType ); 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir return aRet; 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< sal_Int8 > VCLXTopWindow::getImplementationId() throw(::com::sun::star::uno::RuntimeException) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir static ::cppu::OImplementationId* pId = NULL; 311*cdf0e10cSrcweir static ::cppu::OImplementationId* pIdWithHandle = NULL; 312*cdf0e10cSrcweir if ( isSystemDependentWindowPeer() ) 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir if( !pIdWithHandle ) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); 317*cdf0e10cSrcweir if( !pIdWithHandle ) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir static ::cppu::OImplementationId idWithHandle( sal_False ); 320*cdf0e10cSrcweir pIdWithHandle = &idWithHandle; 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir return (*pIdWithHandle).getImplementationId(); 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir else 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir if( !pId ) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir ::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() ); 331*cdf0e10cSrcweir if( !pId ) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir static ::cppu::OImplementationId id( sal_False ); 334*cdf0e10cSrcweir pId = &id; 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir return (*pId).getImplementationId(); 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > VCLXTopWindow::getTypes() throw(::com::sun::star::uno::RuntimeException) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir return ::comphelper::concatSequences( VCLXTopWindow_Base::getTypes(), VCLXContainer::getTypes() ); 345*cdf0e10cSrcweir } 346