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 31 #include "accessibility/extended/AccessibleBrowseBoxTableCell.hxx" 32 #include <svtools/accessibletableprovider.hxx> 33 #include "accessibility/extended/AccessibleBrowseBox.hxx" 34 #include <tools/gen.hxx> 35 #include <toolkit/helper/vclunohelper.hxx> 36 #include <com/sun/star/accessibility/AccessibleEventId.hpp> 37 38 namespace accessibility 39 { 40 namespace 41 { 42 void checkIndex_Impl( sal_Int32 _nIndex, const ::rtl::OUString& _sText ) throw (::com::sun::star::lang::IndexOutOfBoundsException) 43 { 44 if ( _nIndex >= _sText.getLength() ) 45 throw ::com::sun::star::lang::IndexOutOfBoundsException(); 46 } 47 48 sal_Int32 getIndex_Impl( sal_Int32 _nRow, sal_uInt16 _nColumn, sal_uInt16 _nColumnCount ) 49 { 50 return _nRow * _nColumnCount + _nColumn; 51 } 52 } 53 using namespace ::com::sun::star::lang; 54 using namespace utl; 55 using namespace comphelper; 56 using ::rtl::OUString; 57 using ::accessibility::AccessibleBrowseBox; 58 using namespace ::com::sun::star::uno; 59 using ::com::sun::star::accessibility::XAccessible; 60 using namespace ::com::sun::star::accessibility; 61 using namespace ::svt; 62 63 64 // implementation of a table cell 65 ::rtl::OUString AccessibleBrowseBoxTableCell::implGetText() 66 { 67 ensureIsAlive(); 68 return mpBrowseBox->GetAccessibleCellText( getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) ); 69 } 70 71 ::com::sun::star::lang::Locale AccessibleBrowseBoxTableCell::implGetLocale() 72 { 73 ensureIsAlive(); 74 return mpBrowseBox->GetAccessible()->getAccessibleContext()->getLocale(); 75 } 76 77 void AccessibleBrowseBoxTableCell::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex ) 78 { 79 nStartIndex = 0; 80 nEndIndex = 0; 81 } 82 83 AccessibleBrowseBoxTableCell::AccessibleBrowseBoxTableCell(const Reference<XAccessible >& _rxParent, 84 IAccessibleTableProvider& _rBrowseBox, 85 const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& _xFocusWindow, 86 sal_Int32 _nRowPos, 87 sal_uInt16 _nColPos, 88 sal_Int32 _nOffset ) 89 :AccessibleBrowseBoxCell( _rxParent, _rBrowseBox, _xFocusWindow, _nRowPos, _nColPos ) 90 { 91 m_nOffset = ( OFFSET_DEFAULT == _nOffset ) ? (sal_Int32)BBINDEX_FIRSTCONTROL : _nOffset; 92 sal_Int32 nIndex = getIndex_Impl( _nRowPos, _nColPos, _rBrowseBox.GetColumnCount() ); 93 setAccessibleName( _rBrowseBox.GetAccessibleObjectName( BBTYPE_TABLECELL, nIndex ) ); 94 setAccessibleDescription( _rBrowseBox.GetAccessibleObjectDescription( BBTYPE_TABLECELL, nIndex ) ); 95 // Need to register as event listener 96 Reference< XComponent > xComponent(_rxParent, UNO_QUERY); 97 if( xComponent.is() ) 98 xComponent->addEventListener(static_cast< XEventListener *> (this)); 99 } 100 101 void AccessibleBrowseBoxTableCell::nameChanged( const ::rtl::OUString& rNewName, const ::rtl::OUString& rOldName ) 102 { 103 implSetName( rNewName ); 104 Any aOldValue, aNewValue; 105 aOldValue <<= rOldName; 106 aNewValue <<= rNewName; 107 commitEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue ); 108 } 109 110 // XInterface ------------------------------------------------------------- 111 112 /** Queries for a new interface. */ 113 ::com::sun::star::uno::Any SAL_CALL AccessibleBrowseBoxTableCell::queryInterface( 114 const ::com::sun::star::uno::Type& rType ) 115 throw ( ::com::sun::star::uno::RuntimeException ) 116 { 117 Any aRet = AccessibleBrowseBoxCell::queryInterface(rType); 118 if ( !aRet.hasValue() ) 119 aRet = AccessibleTextHelper_BASE::queryInterface(rType); 120 return aRet; 121 } 122 123 /** Aquires the object (calls acquire() on base class). */ 124 void SAL_CALL AccessibleBrowseBoxTableCell::acquire() throw () 125 { 126 AccessibleBrowseBoxCell::acquire(); 127 } 128 129 /** Releases the object (calls release() on base class). */ 130 void SAL_CALL AccessibleBrowseBoxTableCell::release() throw () 131 { 132 AccessibleBrowseBoxCell::release(); 133 } 134 135 ::com::sun::star::awt::Rectangle SAL_CALL AccessibleBrowseBoxTableCell::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 136 { 137 BBSolarGuard aSolarGuard; 138 ::osl::MutexGuard aGuard( getOslMutex() ); 139 140 ensureIsAlive(); 141 if ( !implIsValidIndex( nIndex, implGetText().getLength() ) ) 142 throw IndexOutOfBoundsException(); 143 144 ::com::sun::star::awt::Rectangle aRect; 145 146 if ( mpBrowseBox ) 147 { 148 aRect = AWTRectangle( mpBrowseBox->GetFieldCharacterBounds( getRowPos(), getColumnPos(), nIndex ) ); 149 } 150 151 return aRect; 152 } 153 154 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getIndexAtPoint( const ::com::sun::star::awt::Point& _aPoint ) throw (RuntimeException) 155 { 156 //! TODO CTL bidi 157 // DBG_ASSERT(0,"Need to be done by base class!"); 158 BBSolarGuard aSolarGuard; 159 ::osl::MutexGuard aGuard( getOslMutex() ); 160 ensureIsAlive(); 161 162 return mpBrowseBox->GetFieldIndexAtPoint( getRowPos(), getColumnPos(), VCLPoint( _aPoint ) ); 163 } 164 165 /** @return 166 The name of this class. 167 */ 168 ::rtl::OUString SAL_CALL AccessibleBrowseBoxTableCell::getImplementationName() 169 throw ( ::com::sun::star::uno::RuntimeException ) 170 { 171 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.AccessibleBrowseBoxTableCell" ) ); 172 } 173 174 /** @return The count of visible children. */ 175 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleChildCount() 176 throw ( ::com::sun::star::uno::RuntimeException ) 177 { 178 return 0; 179 } 180 181 /** @return The XAccessible interface of the specified child. */ 182 ::com::sun::star::uno::Reference< 183 ::com::sun::star::accessibility::XAccessible > SAL_CALL 184 AccessibleBrowseBoxTableCell::getAccessibleChild( sal_Int32 ) 185 throw ( ::com::sun::star::lang::IndexOutOfBoundsException, 186 ::com::sun::star::uno::RuntimeException ) 187 { 188 throw ::com::sun::star::lang::IndexOutOfBoundsException(); 189 } 190 191 /** Creates a new AccessibleStateSetHelper and fills it with states of the 192 current object. 193 @return 194 A filled AccessibleStateSetHelper. 195 */ 196 ::utl::AccessibleStateSetHelper* AccessibleBrowseBoxTableCell::implCreateStateSetHelper() 197 { 198 BBSolarGuard aSolarGuard; 199 ::osl::MutexGuard aGuard( getOslMutex() ); 200 201 ::utl::AccessibleStateSetHelper* pStateSetHelper = new ::utl::AccessibleStateSetHelper; 202 203 if( isAlive() ) 204 { 205 // SHOWING done with mxParent 206 if( implIsShowing() ) 207 pStateSetHelper->AddState( AccessibleStateType::SHOWING ); 208 209 mpBrowseBox->FillAccessibleStateSetForCell( *pStateSetHelper, getRowPos(), static_cast< sal_uInt16 >( getColumnPos() ) ); 210 } 211 else 212 pStateSetHelper->AddState( AccessibleStateType::DEFUNC ); 213 214 return pStateSetHelper; 215 } 216 217 218 // XAccessible ------------------------------------------------------------ 219 220 /** @return The XAccessibleContext interface of this object. */ 221 Reference< XAccessibleContext > SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleContext() throw ( RuntimeException ) 222 { 223 ensureIsAlive(); 224 return this; 225 } 226 227 // XAccessibleContext ----------------------------------------------------- 228 229 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getAccessibleIndexInParent() 230 throw ( ::com::sun::star::uno::RuntimeException ) 231 { 232 BBSolarGuard aSolarGuard; 233 ::osl::MutexGuard aGuard( getOslMutex() ); 234 ensureIsAlive(); 235 236 return /*BBINDEX_FIRSTCONTROL*/ m_nOffset + ( getRowPos() * mpBrowseBox->GetColumnCount() ) + getColumnPos(); 237 } 238 239 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCaretPosition( ) throw (::com::sun::star::uno::RuntimeException) 240 { 241 return -1; 242 } 243 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setCaretPosition ( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 244 { 245 BBSolarGuard aSolarGuard; 246 ::osl::MutexGuard aGuard( getOslMutex() ); 247 248 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) ) 249 throw IndexOutOfBoundsException(); 250 251 return sal_False; 252 } 253 sal_Unicode SAL_CALL AccessibleBrowseBoxTableCell::getCharacter( sal_Int32 nIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 254 { 255 BBSolarGuard aSolarGuard; 256 ::osl::MutexGuard aGuard( getOslMutex() ); 257 return OCommonAccessibleText::getCharacter( nIndex ); 258 } 259 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL AccessibleBrowseBoxTableCell::getCharacterAttributes( sal_Int32 nIndex, const ::com::sun::star::uno::Sequence< ::rtl::OUString >& ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 260 { 261 BBSolarGuard aSolarGuard; 262 ::osl::MutexGuard aGuard( getOslMutex() ); 263 264 ::rtl::OUString sText( implGetText() ); 265 266 if ( !implIsValidIndex( nIndex, sText.getLength() ) ) 267 throw IndexOutOfBoundsException(); 268 269 return ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >(); 270 } 271 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getCharacterCount( ) throw (::com::sun::star::uno::RuntimeException) 272 { 273 BBSolarGuard aSolarGuard; 274 ::osl::MutexGuard aGuard( getOslMutex() ); 275 return OCommonAccessibleText::getCharacterCount( ); 276 } 277 278 ::rtl::OUString SAL_CALL AccessibleBrowseBoxTableCell::getSelectedText( ) throw (::com::sun::star::uno::RuntimeException) 279 { 280 BBSolarGuard aSolarGuard; 281 ::osl::MutexGuard aGuard( getOslMutex() ); 282 return OCommonAccessibleText::getSelectedText( ); 283 } 284 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionStart( ) throw (::com::sun::star::uno::RuntimeException) 285 { 286 BBSolarGuard aSolarGuard; 287 ::osl::MutexGuard aGuard( getOslMutex() ); 288 return OCommonAccessibleText::getSelectionStart( ); 289 } 290 sal_Int32 SAL_CALL AccessibleBrowseBoxTableCell::getSelectionEnd( ) throw (::com::sun::star::uno::RuntimeException) 291 { 292 BBSolarGuard aSolarGuard; 293 ::osl::MutexGuard aGuard( getOslMutex() ); 294 return OCommonAccessibleText::getSelectionEnd( ); 295 } 296 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 297 { 298 BBSolarGuard aSolarGuard; 299 ::osl::MutexGuard aGuard( getOslMutex() ); 300 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) ) 301 throw IndexOutOfBoundsException(); 302 303 return sal_False; 304 } 305 ::rtl::OUString SAL_CALL AccessibleBrowseBoxTableCell::getText( ) throw (::com::sun::star::uno::RuntimeException) 306 { 307 BBSolarGuard aSolarGuard; 308 ::osl::MutexGuard aGuard( getOslMutex() ); 309 return OCommonAccessibleText::getText( ); 310 } 311 ::rtl::OUString SAL_CALL AccessibleBrowseBoxTableCell::getTextRange( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 312 { 313 BBSolarGuard aSolarGuard; 314 ::osl::MutexGuard aGuard( getOslMutex() ); 315 return OCommonAccessibleText::getTextRange( nStartIndex, nEndIndex ); 316 } 317 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextAtIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 318 { 319 BBSolarGuard aSolarGuard; 320 ::osl::MutexGuard aGuard( getOslMutex() ); 321 return OCommonAccessibleText::getTextAtIndex( nIndex ,aTextType); 322 } 323 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBeforeIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 324 { 325 BBSolarGuard aSolarGuard; 326 ::osl::MutexGuard aGuard( getOslMutex() ); 327 return OCommonAccessibleText::getTextBeforeIndex( nIndex ,aTextType); 328 } 329 ::com::sun::star::accessibility::TextSegment SAL_CALL AccessibleBrowseBoxTableCell::getTextBehindIndex( sal_Int32 nIndex, sal_Int16 aTextType ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 330 { 331 BBSolarGuard aSolarGuard; 332 ::osl::MutexGuard aGuard( getOslMutex() ); 333 return OCommonAccessibleText::getTextBehindIndex( nIndex ,aTextType); 334 } 335 sal_Bool SAL_CALL AccessibleBrowseBoxTableCell::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException) 336 { 337 BBSolarGuard aSolarGuard; 338 ::osl::MutexGuard aGuard( getOslMutex() ); 339 ::rtl::OUString sText = implGetText(); 340 checkIndex_Impl( nStartIndex, sText ); 341 checkIndex_Impl( nEndIndex, sText ); 342 343 //!!! don't know how to put a string into the clipboard 344 return sal_False; 345 } 346 void AccessibleBrowseBoxTableCell::disposing( const EventObject& _rSource ) throw (RuntimeException) 347 { 348 if ( _rSource.Source == mxParent ) 349 { 350 dispose(); 351 } 352 } 353 354 } 355