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