1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "vclxdialog.hxx" 29 30 #include <com/sun/star/awt/PosSize.hpp> 31 #include <com/sun/star/awt/SystemDependentXWindow.hpp> 32 #include <com/sun/star/lang/SystemDependent.hpp> 33 34 #include <cppuhelper/typeprovider.hxx> 35 36 #include <toolkit/awt/vclxmenu.hxx> 37 #include <toolkit/helper/macros.hxx> 38 #include <toolkit/helper/property.hxx> 39 40 #ifdef WNT 41 #include <tools/prewin.h> 42 #include <windows.h> 43 #include <tools/postwin.h> 44 #elif defined ( QUARTZ ) 45 #include "premac.h" 46 #include <Cocoa/Cocoa.h> 47 #include "postmac.h" 48 #endif 49 50 #include <vcl/dialog.hxx> 51 #include <vcl/msgbox.hxx> 52 #include <vcl/svapp.hxx> 53 #include <vcl/sysdata.hxx> 54 #include <vcl/wrkwin.hxx> 55 56 #include "forward.hxx" 57 58 namespace layoutimpl 59 { 60 61 DBG_NAME( VCLXDialog ) 62 63 VCLXDialog::VCLXDialog() 64 : VCLXWindow() 65 , VCLXTopWindow_Base( true ) 66 , VCLXDialog_Base() 67 , Bin() 68 , bRealized( false ) 69 , bResizeSafeguard( false ) 70 { 71 DBG_CTOR( VCLXDialog, NULL ); 72 73 /* mxLayoutUnit = uno::Reference< awt::XLayoutUnit >( new LayoutUnit() ); 74 assert(mxLayoutUnit.is());*/ 75 } 76 77 VCLXDialog::~VCLXDialog() 78 { 79 DBG_DTOR( VCLXDialog, NULL ); 80 } 81 82 vos::IMutex& VCLXDialog::GetMutexImpl() 83 { 84 return VCLXWindow::GetMutex(); 85 } 86 87 Window* VCLXDialog::GetWindowImpl() 88 { 89 return VCLXWindow::GetWindow(); 90 } 91 92 ::cppu::OInterfaceContainerHelper& VCLXDialog::GetTopWindowListenersImpl() 93 { 94 return GetTopWindowListeners(); 95 } 96 97 IMPLEMENT_2_FORWARD_XINTERFACE2( VCLXDialog, VCLXWindow, Bin, VCLXDialog_Base ); 98 99 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXDialog, VCLXWindow, VCLXDialog_Base ); 100 101 void SAL_CALL VCLXDialog::dispose() throw(::com::sun::star::uno::RuntimeException) 102 { 103 { 104 ::vos::OGuard aGuard( GetMutex() ); 105 106 ::com::sun::star::lang::EventObject aDisposeEvent; 107 aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this); 108 // maTabListeners.disposeAndClear( aDisposeEvent ); 109 } 110 111 VCLXWindow::dispose(); 112 } 113 114 void VCLXDialog::resizedCb() 115 { 116 queueResize(); 117 } 118 119 void SAL_CALL VCLXDialog::allocateArea( const css::awt::Rectangle &rArea ) 120 throw (css::uno::RuntimeException) 121 { 122 ::com::sun::star::awt::Size reqSize = Bin::getMinimumSize(); 123 reqSize.Height = getHeightForWidth( rArea.Width ); 124 125 if ( !bRealized ) 126 { 127 setPosSize( 0, 0, reqSize.Width, reqSize.Height, ::com::sun::star::awt::PosSize::SIZE ); 128 bRealized = true; 129 setVisible( true ); 130 } 131 else 132 { 133 ::com::sun::star::awt::Size curSize = getSize(); 134 if ( reqSize.Width > curSize.Width ) 135 setPosSize( 0, 0, reqSize.Width, 0, ::com::sun::star::awt::PosSize::WIDTH ); 136 if ( reqSize.Height > curSize.Height ) 137 setPosSize( 0, 0, 0, reqSize.Height, ::com::sun::star::awt::PosSize::HEIGHT ); 138 } 139 140 ::com::sun::star::awt::Size size = getSize(); 141 maAllocation.Width = size.Width; 142 maAllocation.Height = size.Height; 143 144 Bin::allocateArea( maAllocation ); 145 } 146 147 void VCLXDialog::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent ) 148 { 149 ::vos::OClearableGuard aGuard( GetMutex() ); 150 151 switch ( _rVclWindowEvent.GetId() ) 152 { 153 case VCLEVENT_WINDOW_RESIZE: 154 resizedCb(); 155 default: 156 aGuard.clear(); 157 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent ); 158 break; 159 } 160 } 161 162 void SAL_CALL VCLXDialog::setProperty( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Any &Value ) throw(::com::sun::star::uno::RuntimeException) 163 { 164 ::vos::OGuard aGuard( GetMutex() ); 165 166 if ( GetWindow() ) 167 { 168 /* sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); 169 switch ( nPropertyId ) 170 { 171 default: 172 */ 173 VCLXWindow::setProperty( PropertyName, Value ); 174 /* } 175 */ 176 } 177 } 178 179 ::com::sun::star::uno::Any SAL_CALL VCLXDialog::getProperty( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::uno::RuntimeException) 180 { 181 ::vos::OGuard aGuard( GetMutex() ); 182 183 ::com::sun::star::uno::Any aReturn; 184 if ( GetWindow() ) 185 { 186 /* 187 sal_uInt16 nPropertyId = GetPropertyId( PropertyName ); 188 switch ( nPropertyId ) 189 { 190 default: 191 */ 192 aReturn = VCLXWindow::getProperty( PropertyName ); 193 /* 194 } 195 */ 196 } 197 return aReturn; 198 } 199 200 void VCLXDialog::setTitle( const ::rtl::OUString& Title ) throw(::com::sun::star::uno::RuntimeException) 201 { 202 ::vos::OGuard aGuard( GetMutex() ); 203 204 Window* pWindow = GetWindow(); 205 if ( pWindow ) 206 pWindow->SetText( Title ); 207 } 208 209 void VCLXDialog::setHelpId( const rtl::OUString& rId ) throw(::com::sun::star::uno::RuntimeException) 210 { 211 ::vos::OGuard aGuard( GetMutex() ); 212 213 Window* pWindow = GetWindow(); 214 if ( pWindow ) 215 pWindow->SetHelpId( rtl::OUStringToOString( rId, RTL_TEXTENCODING_UTF8 ) ); 216 } 217 218 ::rtl::OUString VCLXDialog::getTitle() throw(::com::sun::star::uno::RuntimeException) 219 { 220 ::vos::OGuard aGuard( GetMutex() ); 221 222 ::rtl::OUString aTitle; 223 Window* pWindow = GetWindow(); 224 if ( pWindow ) 225 aTitle = pWindow->GetText(); 226 return aTitle; 227 } 228 229 sal_Int16 VCLXDialog::execute() throw(::com::sun::star::uno::RuntimeException) 230 { 231 ::vos::OGuard aGuard( GetMutex() ); 232 233 sal_Int16 nRet = 0; 234 if ( GetWindow() ) 235 { 236 Dialog* pDlg = (Dialog*) GetWindow(); 237 Window* pParent = pDlg->GetWindow( WINDOW_PARENTOVERLAP ); 238 Window* pOldParent = NULL; 239 if ( pParent && !pParent->IsReallyVisible() ) 240 { 241 pOldParent = pDlg->GetParent(); 242 Window* pFrame = pDlg->GetWindow( WINDOW_FRAME ); 243 if ( pFrame != pDlg ) 244 pDlg->SetParent( pFrame ); 245 } 246 nRet = pDlg->Execute(); 247 if ( pOldParent ) 248 pDlg->SetParent( pOldParent ); 249 } 250 return nRet; 251 } 252 253 void VCLXDialog::endDialog( sal_Int32 nResult ) throw(::com::sun::star::uno::RuntimeException) 254 { 255 ::vos::OGuard aGuard( GetMutex() ); 256 257 if ( nResult == BUTTONID_HELP ) 258 { 259 // UGH: c&p button.cxx 260 ::Window* pFocusWin = Application::GetFocusWindow(); 261 if ( !pFocusWin ) 262 pFocusWin = GetWindow(); 263 264 HelpEvent aEvt( pFocusWin->GetPointerPosPixel(), HELPMODE_CONTEXT ); 265 pFocusWin->RequestHelp( aEvt ); 266 return; 267 } 268 269 Dialog* pDlg = (Dialog*) GetWindow(); 270 if ( pDlg ) 271 pDlg->EndDialog( nResult ); 272 } 273 274 void VCLXDialog::endExecute() throw(::com::sun::star::uno::RuntimeException) 275 { 276 endDialog( 0 ); 277 } 278 279 } // namespace layoutimpl 280