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 #include "vclxdialog.hxx" 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp> 27cdf0e10cSrcweir #include <com/sun/star/awt/SystemDependentXWindow.hpp> 28cdf0e10cSrcweir #include <com/sun/star/lang/SystemDependent.hpp> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <toolkit/awt/vclxmenu.hxx> 33cdf0e10cSrcweir #include <toolkit/helper/macros.hxx> 34cdf0e10cSrcweir #include <toolkit/helper/property.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #ifdef WNT 37cdf0e10cSrcweir #include <tools/prewin.h> 38cdf0e10cSrcweir #include <windows.h> 39cdf0e10cSrcweir #include <tools/postwin.h> 40*27ead02aSPedro Giffuni #elif defined ( OS2 ) 41*27ead02aSPedro Giffuni #include <svpm.h> 42cdf0e10cSrcweir #elif defined ( QUARTZ ) 43cdf0e10cSrcweir #include "premac.h" 44cdf0e10cSrcweir #include <Cocoa/Cocoa.h> 45cdf0e10cSrcweir #include "postmac.h" 46cdf0e10cSrcweir #endif 47cdf0e10cSrcweir 48cdf0e10cSrcweir #include <vcl/dialog.hxx> 49cdf0e10cSrcweir #include <vcl/msgbox.hxx> 50cdf0e10cSrcweir #include <vcl/svapp.hxx> 51cdf0e10cSrcweir #include <vcl/sysdata.hxx> 52cdf0e10cSrcweir #include <vcl/wrkwin.hxx> 53cdf0e10cSrcweir 54cdf0e10cSrcweir #include "forward.hxx" 55cdf0e10cSrcweir 56cdf0e10cSrcweir namespace layoutimpl 57cdf0e10cSrcweir { 58cdf0e10cSrcweir 59cdf0e10cSrcweir DBG_NAME( VCLXDialog ) 60cdf0e10cSrcweir 61cdf0e10cSrcweir VCLXDialog::VCLXDialog() 62cdf0e10cSrcweir : VCLXWindow() 63cdf0e10cSrcweir , VCLXTopWindow_Base( true ) 64cdf0e10cSrcweir , VCLXDialog_Base() 65cdf0e10cSrcweir , Bin() 66cdf0e10cSrcweir , bRealized( false ) 67cdf0e10cSrcweir , bResizeSafeguard( false ) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir DBG_CTOR( VCLXDialog, NULL ); 70cdf0e10cSrcweir 71cdf0e10cSrcweir /* mxLayoutUnit = uno::Reference< awt::XLayoutUnit >( new LayoutUnit() ); 72cdf0e10cSrcweir assert(mxLayoutUnit.is());*/ 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir VCLXDialog::~VCLXDialog() 76cdf0e10cSrcweir { 77cdf0e10cSrcweir DBG_DTOR( VCLXDialog, NULL ); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir 80cdf0e10cSrcweir vos::IMutex& VCLXDialog::GetMutexImpl() 81cdf0e10cSrcweir { 82cdf0e10cSrcweir return VCLXWindow::GetMutex(); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir Window* VCLXDialog::GetWindowImpl() 86cdf0e10cSrcweir { 87cdf0e10cSrcweir return VCLXWindow::GetWindow(); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper& VCLXDialog::GetTopWindowListenersImpl() 91cdf0e10cSrcweir { 92cdf0e10cSrcweir return GetTopWindowListeners(); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir IMPLEMENT_2_FORWARD_XINTERFACE2( VCLXDialog, VCLXWindow, Bin, VCLXDialog_Base ); 96cdf0e10cSrcweir 97cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXDialog, VCLXWindow, VCLXDialog_Base ); 98cdf0e10cSrcweir 99cdf0e10cSrcweir void SAL_CALL VCLXDialog::dispose() throw(::com::sun::star::uno::RuntimeException) 100cdf0e10cSrcweir { 101cdf0e10cSrcweir { 102cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 103cdf0e10cSrcweir 104cdf0e10cSrcweir ::com::sun::star::lang::EventObject aDisposeEvent; 105cdf0e10cSrcweir aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this); 106cdf0e10cSrcweir // maTabListeners.disposeAndClear( aDisposeEvent ); 107cdf0e10cSrcweir } 108cdf0e10cSrcweir 109cdf0e10cSrcweir VCLXWindow::dispose(); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir void VCLXDialog::resizedCb() 113cdf0e10cSrcweir { 114cdf0e10cSrcweir queueResize(); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir void SAL_CALL VCLXDialog::allocateArea( const css::awt::Rectangle &rArea ) 118cdf0e10cSrcweir throw (css::uno::RuntimeException) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir ::com::sun::star::awt::Size reqSize = Bin::getMinimumSize(); 121cdf0e10cSrcweir reqSize.Height = getHeightForWidth( rArea.Width ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir if ( !bRealized ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir setPosSize( 0, 0, reqSize.Width, reqSize.Height, ::com::sun::star::awt::PosSize::SIZE ); 126cdf0e10cSrcweir bRealized = true; 127cdf0e10cSrcweir setVisible( true ); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir else 130cdf0e10cSrcweir { 131cdf0e10cSrcweir ::com::sun::star::awt::Size curSize = getSize(); 132cdf0e10cSrcweir if ( reqSize.Width > curSize.Width ) 133cdf0e10cSrcweir setPosSize( 0, 0, reqSize.Width, 0, ::com::sun::star::awt::PosSize::WIDTH ); 134cdf0e10cSrcweir if ( reqSize.Height > curSize.Height ) 135cdf0e10cSrcweir setPosSize( 0, 0, 0, reqSize.Height, ::com::sun::star::awt::PosSize::HEIGHT ); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir ::com::sun::star::awt::Size size = getSize(); 139cdf0e10cSrcweir maAllocation.Width = size.Width; 140cdf0e10cSrcweir maAllocation.Height = size.Height; 141cdf0e10cSrcweir 142cdf0e10cSrcweir Bin::allocateArea( maAllocation ); 143cdf0e10cSrcweir } 144cdf0e10cSrcweir 145cdf0e10cSrcweir void VCLXDialog::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir ::vos::OClearableGuard aGuard( GetMutex() ); 148cdf0e10cSrcweir 149cdf0e10cSrcweir switch ( _rVclWindowEvent.GetId() ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir case VCLEVENT_WINDOW_RESIZE: 152cdf0e10cSrcweir resizedCb(); 153cdf0e10cSrcweir default: 154cdf0e10cSrcweir aGuard.clear(); 155cdf0e10cSrcweir VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); 156cdf0e10cSrcweir break; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir void SAL_CALL VCLXDialog::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any &Value ) throw(::com::sun::star::uno::RuntimeException) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 163cdf0e10cSrcweir 164cdf0e10cSrcweir if ( GetWindow() ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir /* sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); 167cdf0e10cSrcweir switch ( nPropertyId ) 168cdf0e10cSrcweir { 169cdf0e10cSrcweir default: 170cdf0e10cSrcweir */ 171cdf0e10cSrcweir VCLXWindow::setProperty( PropertyName, Value ); 172cdf0e10cSrcweir /* } 173cdf0e10cSrcweir */ 174cdf0e10cSrcweir } 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL VCLXDialog::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) 178cdf0e10cSrcweir { 179cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 180cdf0e10cSrcweir 181cdf0e10cSrcweir ::com::sun::star::uno::Any aReturn; 182cdf0e10cSrcweir if ( GetWindow() ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir /* 185cdf0e10cSrcweir sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); 186cdf0e10cSrcweir switch ( nPropertyId ) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir default: 189cdf0e10cSrcweir */ 190cdf0e10cSrcweir aReturn = VCLXWindow::getProperty( PropertyName ); 191cdf0e10cSrcweir /* 192cdf0e10cSrcweir } 193cdf0e10cSrcweir */ 194cdf0e10cSrcweir } 195cdf0e10cSrcweir return aReturn; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir 198cdf0e10cSrcweir void VCLXDialog::setTitle( const ::rtl::OUString& Title ) throw(::com::sun::star::uno::RuntimeException) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 201cdf0e10cSrcweir 202cdf0e10cSrcweir Window* pWindow = GetWindow(); 203cdf0e10cSrcweir if ( pWindow ) 204cdf0e10cSrcweir pWindow->SetText( Title ); 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir void VCLXDialog::setHelpId( const rtl::OUString& rId ) throw(::com::sun::star::uno::RuntimeException) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 210cdf0e10cSrcweir 211cdf0e10cSrcweir Window* pWindow = GetWindow(); 212cdf0e10cSrcweir if ( pWindow ) 213cdf0e10cSrcweir pWindow->SetHelpId( rtl::OUStringToOString( rId, RTL_TEXTENCODING_UTF8 ) ); 214cdf0e10cSrcweir } 215cdf0e10cSrcweir 216cdf0e10cSrcweir ::rtl::OUString VCLXDialog::getTitle() throw(::com::sun::star::uno::RuntimeException) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 219cdf0e10cSrcweir 220cdf0e10cSrcweir ::rtl::OUString aTitle; 221cdf0e10cSrcweir Window* pWindow = GetWindow(); 222cdf0e10cSrcweir if ( pWindow ) 223cdf0e10cSrcweir aTitle = pWindow->GetText(); 224cdf0e10cSrcweir return aTitle; 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227cdf0e10cSrcweir sal_Int16 VCLXDialog::execute() throw(::com::sun::star::uno::RuntimeException) 228cdf0e10cSrcweir { 229cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 230cdf0e10cSrcweir 231cdf0e10cSrcweir sal_Int16 nRet = 0; 232cdf0e10cSrcweir if ( GetWindow() ) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir Dialog* pDlg = (Dialog*) GetWindow(); 235cdf0e10cSrcweir Window* pParent = pDlg->GetWindow( WINDOW_PARENTOVERLAP ); 236cdf0e10cSrcweir Window* pOldParent = NULL; 237cdf0e10cSrcweir if ( pParent && !pParent->IsReallyVisible() ) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir pOldParent = pDlg->GetParent(); 240cdf0e10cSrcweir Window* pFrame = pDlg->GetWindow( WINDOW_FRAME ); 241cdf0e10cSrcweir if ( pFrame != pDlg ) 242cdf0e10cSrcweir pDlg->SetParent( pFrame ); 243cdf0e10cSrcweir } 244cdf0e10cSrcweir nRet = pDlg->Execute(); 245cdf0e10cSrcweir if ( pOldParent ) 246cdf0e10cSrcweir pDlg->SetParent( pOldParent ); 247cdf0e10cSrcweir } 248cdf0e10cSrcweir return nRet; 249cdf0e10cSrcweir } 250cdf0e10cSrcweir 251cdf0e10cSrcweir void VCLXDialog::endDialog( sal_Int32 nResult ) throw(::com::sun::star::uno::RuntimeException) 252cdf0e10cSrcweir { 253cdf0e10cSrcweir ::vos::OGuard aGuard( GetMutex() ); 254cdf0e10cSrcweir 255cdf0e10cSrcweir if ( nResult == BUTTONID_HELP ) 256cdf0e10cSrcweir { 257cdf0e10cSrcweir // UGH: c&p button.cxx 258cdf0e10cSrcweir ::Window* pFocusWin = Application::GetFocusWindow(); 259cdf0e10cSrcweir if ( !pFocusWin ) 260cdf0e10cSrcweir pFocusWin = GetWindow(); 261cdf0e10cSrcweir 262cdf0e10cSrcweir HelpEvent aEvt( pFocusWin->GetPointerPosPixel(), HELPMODE_CONTEXT ); 263cdf0e10cSrcweir pFocusWin->RequestHelp( aEvt ); 264cdf0e10cSrcweir return; 265cdf0e10cSrcweir } 266cdf0e10cSrcweir 267cdf0e10cSrcweir Dialog* pDlg = (Dialog*) GetWindow(); 268cdf0e10cSrcweir if ( pDlg ) 269cdf0e10cSrcweir pDlg->EndDialog( nResult ); 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir void VCLXDialog::endExecute() throw(::com::sun::star::uno::RuntimeException) 273cdf0e10cSrcweir { 274cdf0e10cSrcweir endDialog( 0 ); 275cdf0e10cSrcweir } 276cdf0e10cSrcweir 277cdf0e10cSrcweir } // namespace layoutimpl 278