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