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