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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_accessibility.hxx" 30 #include <accessibility/extended/accessibleeditbrowseboxcell.hxx> 31 #include <svtools/editbrowsebox.hxx> 32 #include <comphelper/processfactory.hxx> 33 #include <com/sun/star/accessibility/XAccessibleText.hpp> 34 #include <com/sun/star/accessibility/AccessibleEventId.hpp> 35 36 37 // ................................................................................. 38 namespace accessibility 39 { 40 // ................................................................................. 41 42 using namespace com::sun::star::accessibility; 43 using namespace ::com::sun::star::uno; 44 using namespace ::com::sun::star::lang; 45 using namespace ::com::sun::star::awt; 46 using namespace ::comphelper; 47 using namespace ::svt; 48 49 DBG_NAME( acc_EditBrowseBoxTableCell ) 50 // ----------------------------------------------------------------------------- 51 EditBrowseBoxTableCell::EditBrowseBoxTableCell( 52 const com::sun::star::uno::Reference< XAccessible >& _rxParent, 53 const com::sun::star::uno::Reference< XAccessible >& _rxOwningAccessible, 54 const com::sun::star::uno::Reference< XAccessibleContext >& _xControlChild, 55 IAccessibleTableProvider& _rBrowseBox, 56 const Reference< XWindow >& _xFocusWindow, 57 sal_Int32 _nRowPos, 58 sal_uInt16 _nColPos) 59 :AccessibleBrowseBoxCell( _rxParent, _rBrowseBox, _xFocusWindow, _nRowPos, _nColPos ) 60 ,OAccessibleContextWrapperHelper( ::comphelper::getProcessServiceFactory(), rBHelper, _xControlChild, _rxOwningAccessible, _rxParent ) 61 { 62 DBG_CTOR( acc_EditBrowseBoxTableCell, NULL ); 63 64 aggregateProxy( m_refCount, *this ); 65 } 66 67 // ----------------------------------------------------------------------------- 68 EditBrowseBoxTableCell::~EditBrowseBoxTableCell() 69 { 70 if ( !rBHelper.bDisposed ) 71 { 72 acquire(); // to prevent duplicate dtor calls 73 dispose(); 74 } 75 76 DBG_DTOR( acc_EditBrowseBoxTableCell, NULL ); 77 } 78 79 // ----------------------------------------------------------------------------- 80 ::rtl::OUString SAL_CALL EditBrowseBoxTableCell::getImplementationName() throw ( ::com::sun::star::uno::RuntimeException ) 81 { 82 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.TableCellProxy" ) ); 83 } 84 85 // ----------------------------------------------------------------------------- 86 IMPLEMENT_FORWARD_XINTERFACE2( EditBrowseBoxTableCell, AccessibleBrowseBoxCell, OAccessibleContextWrapperHelper ) 87 88 // ----------------------------------------------------------------------------- 89 IMPLEMENT_FORWARD_XTYPEPROVIDER2( EditBrowseBoxTableCell, AccessibleBrowseBoxCell, OAccessibleContextWrapperHelper ) 90 91 // ----------------------------------------------------------------------------- 92 void EditBrowseBoxTableCell::notifyTranslatedEvent( const AccessibleEventObject& _rEvent ) throw (RuntimeException) 93 { 94 commitEvent( _rEvent.EventId, _rEvent.NewValue, _rEvent.OldValue ); 95 } 96 97 // XAccessibleComponent 98 // ----------------------------------------------------------------------------- 99 sal_Int32 SAL_CALL EditBrowseBoxTableCell::getForeground( ) throw (RuntimeException) 100 { 101 SolarMethodGuard aGuard( *this ); 102 Reference< XAccessibleComponent > xAccComp( m_xInnerContext, UNO_QUERY ); 103 if ( xAccComp.is() ) 104 return xAccComp->getForeground(); 105 return 0; 106 } 107 108 // ----------------------------------------------------------------------------- 109 sal_Int32 SAL_CALL EditBrowseBoxTableCell::getBackground( ) throw (RuntimeException) 110 { 111 SolarMethodGuard aGuard( *this ); 112 Reference< XAccessibleComponent > xAccComp( m_xInnerContext, UNO_QUERY ); 113 if ( xAccComp.is() ) 114 return xAccComp->getBackground(); 115 return 0; 116 } 117 118 // ----------------------------------------------------------------------------- 119 Reference< XAccessible > SAL_CALL EditBrowseBoxTableCell::getAccessibleParent( ) throw (RuntimeException) 120 { 121 return m_xParentAccessible; 122 } 123 124 // ----------------------------------------------------------------------------- 125 ::rtl::OUString SAL_CALL EditBrowseBoxTableCell::getAccessibleDescription() throw ( RuntimeException ) 126 { 127 SolarMethodGuard aGuard( *this ); 128 return m_xInnerContext->getAccessibleDescription(); 129 } 130 131 // ----------------------------------------------------------------------------- 132 ::rtl::OUString SAL_CALL EditBrowseBoxTableCell::getAccessibleName() throw ( RuntimeException ) 133 { 134 SolarMethodGuard aGuard( *this ); 135 136 // TODO: localize this! 137 String sName = mpBrowseBox->GetColumnDescription( ::sal::static_int_cast< sal_uInt16 >( getColumnPos() ) ); 138 if ( 0 == sName.Len() ) 139 { 140 sName = String::CreateFromAscii( "Column " ); 141 sName += String::CreateFromInt32( getColumnPos( ) ); 142 } 143 144 sName += String::CreateFromAscii( ", Row " ); 145 sName += String::CreateFromInt32( getRowPos( ) ); 146 147 return ::rtl::OUString( sName ); 148 } 149 150 // ----------------------------------------------------------------------------- 151 Reference< XAccessibleRelationSet > SAL_CALL EditBrowseBoxTableCell::getAccessibleRelationSet() throw ( RuntimeException ) 152 { 153 SolarMethodGuard aGuard( *this ); 154 return OAccessibleContextWrapperHelper::getAccessibleRelationSet( ); 155 } 156 157 // ----------------------------------------------------------------------------- 158 Reference<XAccessibleStateSet > SAL_CALL EditBrowseBoxTableCell::getAccessibleStateSet() throw ( RuntimeException ) 159 { 160 SolarMethodGuard aGuard( *this ); 161 return m_xInnerContext->getAccessibleStateSet(); 162 // TODO: shouldn't we add an ACTIVE here? Isn't the EditBrowseBoxTableCell always ACTIVE? 163 } 164 165 // ----------------------------------------------------------------------------- 166 sal_Int32 SAL_CALL EditBrowseBoxTableCell::getAccessibleChildCount( ) throw (RuntimeException) 167 { 168 SolarMethodGuard aGuard( *this ); 169 return OAccessibleContextWrapperHelper::getAccessibleChildCount(); 170 } 171 172 // ----------------------------------------------------------------------------- 173 Reference< XAccessible > SAL_CALL EditBrowseBoxTableCell::getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException) 174 { 175 SolarMethodGuard aGuard( *this ); 176 return OAccessibleContextWrapperHelper::getAccessibleChild( i ); 177 } 178 179 // ----------------------------------------------------------------------------- 180 sal_Int16 SAL_CALL EditBrowseBoxTableCell::getAccessibleRole() throw ( RuntimeException ) 181 { 182 SolarMethodGuard aGuard( *this ); 183 return m_xInnerContext->getAccessibleRole( ); 184 } 185 // ----------------------------------------------------------------------------- 186 void SAL_CALL EditBrowseBoxTableCell::dispose() throw( RuntimeException ) 187 { 188 // simply disambiguate. Note that the OComponentHelper base in AccessibleBrowseBoxCell 189 // will call our "disposing()", which will call "dispose()" on the OAccessibleContextWrapperHelper 190 // so there is no need to do this here. 191 AccessibleBrowseBoxCell::dispose(); 192 } 193 // ----------------------------------------------------------------------------- 194 void SAL_CALL EditBrowseBoxTableCell::disposing( const EventObject& _rSource ) throw (RuntimeException) 195 { 196 AccessibleBrowseBoxCell::disposing( _rSource ); 197 OAccessibleContextWrapperHelper::disposing( _rSource ); 198 } 199 // ----------------------------------------------------------------------------- 200 void SAL_CALL EditBrowseBoxTableCell::disposing() 201 { 202 SolarMethodGuard aGuard( *this, false ); 203 OAccessibleContextWrapperHelper::dispose(); 204 // TODO: do we need to dispose our inner object? The base class does this, but is it a good idea? 205 AccessibleBrowseBoxCell::disposing(); 206 } 207 // ============================================================================= 208 // = EditBrowseBoxTableCell 209 // ============================================================================= 210 DBG_NAME( EditBrowseBoxTableCellAccess ) 211 // ----------------------------------------------------------------------------- 212 EditBrowseBoxTableCellAccess::EditBrowseBoxTableCellAccess( 213 const Reference< XAccessible >& _rxParent, const Reference< XAccessible > _rxControlAccessible, 214 const Reference< XWindow >& _rxFocusWindow, 215 IAccessibleTableProvider& _rBrowseBox, sal_Int32 _nRowPos, sal_uInt16 _nColPos ) 216 :EditBrowseBoxTableCellAccess_Base( m_aMutex ) 217 ,m_xParent( _rxParent ) 218 ,m_xControlAccessible( _rxControlAccessible ) 219 ,m_xFocusWindow( _rxFocusWindow ) 220 ,m_pBrowseBox( &_rBrowseBox ) 221 ,m_nRowPos( _nRowPos ) 222 ,m_nColPos( _nColPos ) 223 { 224 DBG_CTOR( EditBrowseBoxTableCellAccess, NULL ); 225 } 226 // ----------------------------------------------------------------------------- 227 EditBrowseBoxTableCellAccess::~EditBrowseBoxTableCellAccess( ) 228 { 229 DBG_DTOR( EditBrowseBoxTableCellAccess, NULL ); 230 } 231 //-------------------------------------------------------------------- 232 Reference< XAccessibleContext > SAL_CALL EditBrowseBoxTableCellAccess::getAccessibleContext( ) throw (RuntimeException) 233 { 234 if ( !m_pBrowseBox || !m_xControlAccessible.is() ) 235 throw DisposedException(); 236 Reference< XAccessibleContext > xMyContext( m_aContext ); 237 if ( !xMyContext.is() ) 238 { 239 Reference< XAccessibleContext > xInnerContext = m_xControlAccessible->getAccessibleContext(); 240 Reference< XAccessible > xMe( this ); 241 242 xMyContext = new EditBrowseBoxTableCell( m_xParent, xMe, xInnerContext, *m_pBrowseBox, m_xFocusWindow, m_nRowPos, m_nColPos ); 243 m_aContext = xMyContext; 244 } 245 return xMyContext; 246 } 247 //-------------------------------------------------------------------- 248 void SAL_CALL EditBrowseBoxTableCellAccess::disposing() 249 { 250 // dispose our context, if it still alive 251 Reference< XComponent > xMyContext( (Reference< XAccessibleContext >)m_aContext, UNO_QUERY ); 252 if ( xMyContext.is() ) 253 { 254 try 255 { 256 xMyContext->dispose(); 257 } 258 catch( const Exception& e ) 259 { 260 (void)e; 261 OSL_ENSURE( false, "EditBrowseBoxTableCellAccess::disposing: caught an exception while disposing the context!" ); 262 } 263 } 264 265 m_pBrowseBox = NULL; 266 m_xControlAccessible.clear(); 267 m_aContext = Reference< XAccessibleContext >( ); 268 // NO dispose of the inner object there: it is the XAccessible of an window, and disposing 269 // it would delete the respective VCL window 270 } 271 // ................................................................................. 272 } // namespace accessibility 273 // ................................................................................. 274