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