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 #include <accessibility/standard/vclxaccessibletoolboxitem.hxx>
27 #include <toolkit/helper/convert.hxx>
28 #include <accessibility/helper/accresmgr.hxx>
29 #include <accessibility/helper/accessiblestrings.hrc>
30 #include <com/sun/star/awt/Point.hpp>
31 #include <com/sun/star/awt/Rectangle.hpp>
32 #include <com/sun/star/awt/Size.hpp>
33
34 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
35 #include <com/sun/star/accessibility/AccessibleRole.hpp>
36 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
37 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
38 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
39 #include <tools/debug.hxx>
40 #include <vcl/svapp.hxx>
41 #include <vcl/toolbox.hxx>
42 #include <vcl/unohelp2.hxx>
43 #include <vcl/help.hxx>
44 #include <toolkit/awt/vclxwindow.hxx>
45 #include <toolkit/helper/externallock.hxx>
46 #include <unotools/accessiblestatesethelper.hxx>
47 #include <unotools/accessiblerelationsethelper.hxx>
48 #include <cppuhelper/typeprovider.hxx>
49 #include <comphelper/sequence.hxx>
50
51 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
52
53 // class VCLXAccessibleToolBoxItem ------------------------------------------
54
55 using namespace ::com::sun::star::accessibility;
56 using namespace ::com::sun::star::uno;
57 using namespace ::com::sun::star::beans;
58 using namespace ::com::sun::star::lang;
59 using namespace ::com::sun::star;
60 using namespace ::comphelper;
61
DBG_NAME(VCLXAccessibleToolBoxItem)62 DBG_NAME(VCLXAccessibleToolBoxItem)
63
64 // -----------------------------------------------------------------------------
65 // Ctor() and Dtor()
66 // -----------------------------------------------------------------------------
67 VCLXAccessibleToolBoxItem::VCLXAccessibleToolBoxItem( ToolBox* _pToolBox, sal_Int32 _nPos ) :
68
69 AccessibleTextHelper_BASE( new VCLExternalSolarLock() ),
70
71 m_pToolBox ( _pToolBox ),
72 m_nIndexInParent( _nPos ),
73 m_nRole ( AccessibleRole::PUSH_BUTTON ),
74 m_nItemId ( 0 ),
75 m_bHasFocus ( sal_False ),
76 m_bIsChecked ( sal_False ),
77 m_bIndeterminate( false )
78
79 {
80 DBG_CTOR( VCLXAccessibleToolBoxItem, NULL );
81
82 m_pExternalLock = static_cast< VCLExternalSolarLock* >( getExternalLock( ) );
83
84 DBG_ASSERT( m_pToolBox, "invalid toolbox" );
85 m_nItemId = m_pToolBox->GetItemId( (sal_uInt16)m_nIndexInParent );
86 m_sOldName = GetText( true );
87 m_bIsChecked = m_pToolBox->IsItemChecked( m_nItemId );
88 m_bIndeterminate = ( m_pToolBox->GetItemState( m_nItemId ) == STATE_DONTKNOW );
89 ToolBoxItemType eType = m_pToolBox->GetItemType( (sal_uInt16)m_nIndexInParent );
90 switch ( eType )
91 {
92 case TOOLBOXITEM_BUTTON :
93 {
94 ToolBoxItemBits nBits = m_pToolBox->GetItemBits( m_nItemId );
95 if (( nBits & TIB_DROPDOWN ) == TIB_DROPDOWN)
96 m_nRole = AccessibleRole::BUTTON_DROPDOWN;
97 else if (( ( nBits & TIB_CHECKABLE ) == TIB_CHECKABLE ) ||
98 ( ( nBits & TIB_AUTOCHECK ) == TIB_AUTOCHECK ) )
99 m_nRole = AccessibleRole::TOGGLE_BUTTON;
100 else if ( (nBits & TIB_DROPDOWN) == TIB_DROPDOWN )
101 {
102 m_nRole = AccessibleRole::BUTTON_DROPDOWN;
103 }
104 else if ( m_pToolBox->GetItemWindow( m_nItemId ) )
105 m_nRole = AccessibleRole::PANEL;
106 break;
107 }
108
109 case TOOLBOXITEM_SPACE :
110 m_nRole = AccessibleRole::FILLER;
111 break;
112
113 case TOOLBOXITEM_SEPARATOR :
114 case TOOLBOXITEM_BREAK :
115 m_nRole = AccessibleRole::SEPARATOR;
116 break;
117
118 default:
119 {
120 DBG_ERRORFILE( "unsupported toolbox itemtype" );
121 }
122 }
123 }
124 // -----------------------------------------------------------------------------
~VCLXAccessibleToolBoxItem()125 VCLXAccessibleToolBoxItem::~VCLXAccessibleToolBoxItem()
126 {
127 DBG_DTOR( VCLXAccessibleToolBoxItem, NULL );
128
129 delete m_pExternalLock;
130 m_pExternalLock = NULL;
131 }
132 // -----------------------------------------------------------------------------
GetText(bool _bAsName)133 ::rtl::OUString VCLXAccessibleToolBoxItem::GetText( bool _bAsName )
134 {
135 ::rtl::OUString sRet;
136 // no text for separators and spaces
137 if ( m_pToolBox && m_nItemId > 0 && ( _bAsName || m_pToolBox->GetButtonType() != BUTTON_SYMBOL ) )
138 {
139 sRet = m_pToolBox->GetItemText( m_nItemId );
140 //OJ #108243# we only read the name of the toolboxitem
141 //
142 // Window* pItemWindow = m_pToolBox->GetItemWindow( m_nItemId );
143 // if ( pItemWindow && pItemWindow->GetAccessible().is() &&
144 // pItemWindow->GetAccessible()->getAccessibleContext().is() )
145 // {
146 // ::rtl::OUString sWinText = pItemWindow->GetAccessible()->getAccessibleContext()->getAccessibleName();
147 // if ( ( sRet.getLength() > 0 ) && ( sWinText.getLength() > 0 ) )
148 // sRet += String( RTL_CONSTASCII_USTRINGPARAM( " " ) );
149 // sRet += sWinText;
150 // }
151 if ( sRet.isEmpty() )
152 {
153 Window* pItemWindow = m_pToolBox->GetItemWindow( m_nItemId );
154 if ( m_nRole == AccessibleRole::PANEL && pItemWindow && pItemWindow->GetAccessible().is() &&
155 pItemWindow->GetAccessible()->getAccessibleContext().is() )
156 {
157 ::rtl::OUString sWinText = pItemWindow->GetAccessible()->getAccessibleContext()->getAccessibleName();
158 if ( !sWinText.isEmpty() )
159 sRet = sWinText;
160 }
161 }
162
163 }
164 return sRet;
165 }
166 // -----------------------------------------------------------------------------
SetFocus(sal_Bool _bFocus)167 void VCLXAccessibleToolBoxItem::SetFocus( sal_Bool _bFocus )
168 {
169 if ( m_bHasFocus != _bFocus )
170 {
171 Any aOldValue;
172 Any aNewValue;
173 if ( m_bHasFocus )
174 aOldValue <<= AccessibleStateType::FOCUSED;
175 else
176 aNewValue <<= AccessibleStateType::FOCUSED;
177 m_bHasFocus = _bFocus;
178 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
179 }
180 }
181 // -----------------------------------------------------------------------------
SetChecked(sal_Bool _bCheck)182 void VCLXAccessibleToolBoxItem::SetChecked( sal_Bool _bCheck )
183 {
184 if( m_nRole == AccessibleRole::PANEL)
185 return;
186 if ( m_bIsChecked != _bCheck )
187 {
188 Any aOldValue;
189 Any aNewValue;
190 if ( m_bIsChecked )
191 aOldValue <<= AccessibleStateType::CHECKED;
192 else
193 aNewValue <<= AccessibleStateType::CHECKED;
194 m_bIsChecked = _bCheck;
195 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
196 }
197 }
198 // -----------------------------------------------------------------------------
SetIndeterminate(bool _bIndeterminate)199 void VCLXAccessibleToolBoxItem::SetIndeterminate( bool _bIndeterminate )
200 {
201 if ( m_bIndeterminate != _bIndeterminate )
202 {
203 Any aOldValue, aNewValue;
204 if ( m_bIndeterminate )
205 aOldValue <<= AccessibleStateType::INDETERMINATE;
206 else
207 aNewValue <<= AccessibleStateType::INDETERMINATE;
208 m_bIndeterminate = _bIndeterminate;
209 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
210 }
211 }
212 // -----------------------------------------------------------------------------
NameChanged()213 void VCLXAccessibleToolBoxItem::NameChanged()
214 {
215 ::rtl::OUString sNewName = implGetText();
216 if ( sNewName != m_sOldName )
217 {
218 Any aOldValue, aNewValue;
219 aOldValue <<= m_sOldName;
220 // save new name as old name for next change
221 m_sOldName = sNewName;
222 aNewValue <<= m_sOldName;
223 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
224 }
225 }
226 // -----------------------------------------------------------------------------
SetChild(const Reference<XAccessible> & _xChild)227 void VCLXAccessibleToolBoxItem::SetChild( const Reference< XAccessible >& _xChild )
228 {
229 m_xChild = _xChild;
230 }
231 // -----------------------------------------------------------------------------
NotifyChildEvent(const Reference<XAccessible> & _xChild,bool _bShow)232 void VCLXAccessibleToolBoxItem::NotifyChildEvent( const Reference< XAccessible >& _xChild, bool _bShow )
233 {
234 Any aOld = _bShow ? Any() : makeAny( _xChild );
235 Any aNew = _bShow ? makeAny( _xChild ) : Any();
236 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOld, aNew );
237 }
238 // -----------------------------------------------------------------------------
ToggleEnableState()239 void VCLXAccessibleToolBoxItem::ToggleEnableState()
240 {
241 Any aOldValue[2], aNewValue[2];
242 if ( m_pToolBox->IsItemEnabled( m_nItemId ) )
243 {
244 aNewValue[0] <<= AccessibleStateType::SENSITIVE;
245 aNewValue[1] <<= AccessibleStateType::ENABLED;
246 }
247 else
248 {
249 aOldValue[0] <<= AccessibleStateType::ENABLED;
250 aOldValue[1] <<= AccessibleStateType::SENSITIVE;
251 }
252
253 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[0], aNewValue[0] );
254 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue[1], aNewValue[1] );
255 }
256 // -----------------------------------------------------------------------------
implGetBounds()257 awt::Rectangle SAL_CALL VCLXAccessibleToolBoxItem::implGetBounds( ) throw (RuntimeException)
258 {
259 awt::Rectangle aRect;
260 if ( m_pToolBox )
261 aRect = AWTRectangle( m_pToolBox->GetItemPosRect( (sal_uInt16)m_nIndexInParent ) );
262
263 return aRect;
264 }
265 // -----------------------------------------------------------------------------
implGetText()266 ::rtl::OUString VCLXAccessibleToolBoxItem::implGetText()
267 {
268 return GetText (true);
269 }
270 // -----------------------------------------------------------------------------
implGetLocale()271 Locale VCLXAccessibleToolBoxItem::implGetLocale()
272 {
273 return Application::GetSettings().GetUILocale();
274 }
275 // -----------------------------------------------------------------------------
implGetSelection(sal_Int32 & nStartIndex,sal_Int32 & nEndIndex)276 void VCLXAccessibleToolBoxItem::implGetSelection( sal_Int32& nStartIndex, sal_Int32& nEndIndex )
277 {
278 nStartIndex = 0;
279 nEndIndex = 0;
280 }
281 // -----------------------------------------------------------------------------
282 // XInterface
283 // -----------------------------------------------------------------------------
IMPLEMENT_FORWARD_REFCOUNT(VCLXAccessibleToolBoxItem,AccessibleTextHelper_BASE)284 IMPLEMENT_FORWARD_REFCOUNT( VCLXAccessibleToolBoxItem, AccessibleTextHelper_BASE )
285 Any SAL_CALL VCLXAccessibleToolBoxItem::queryInterface( const Type& _rType ) throw (RuntimeException)
286 {
287 // --> PB 2004-09-03 #i33611# - toolbox buttons without text don't support XAccessibleText
288 if ( _rType == ::getCppuType( ( const Reference< XAccessibleText >* ) 0 )
289 && ( !m_pToolBox || m_pToolBox->GetButtonType() == BUTTON_SYMBOL ) )
290 return Any();
291 // <--
292
293 ::com::sun::star::uno::Any aReturn = AccessibleTextHelper_BASE::queryInterface( _rType );
294 if ( !aReturn.hasValue() )
295 aReturn = VCLXAccessibleToolBoxItem_BASE::queryInterface( _rType );
296 return aReturn;
297 }
298 // -----------------------------------------------------------------------------
299 // XTypeProvider
300 // -----------------------------------------------------------------------------
IMPLEMENT_FORWARD_XTYPEPROVIDER2(VCLXAccessibleToolBoxItem,AccessibleTextHelper_BASE,VCLXAccessibleToolBoxItem_BASE)301 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleToolBoxItem, AccessibleTextHelper_BASE, VCLXAccessibleToolBoxItem_BASE )
302 // -----------------------------------------------------------------------------
303 // XComponent
304 // -----------------------------------------------------------------------------
305 void SAL_CALL VCLXAccessibleToolBoxItem::disposing()
306 {
307 AccessibleTextHelper_BASE::disposing();
308 m_pToolBox = NULL;
309 }
310 // -----------------------------------------------------------------------------
311 // XServiceInfo
312 // -----------------------------------------------------------------------------
getImplementationName()313 ::rtl::OUString VCLXAccessibleToolBoxItem::getImplementationName() throw (RuntimeException)
314 {
315 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleToolBoxItem" );
316 }
317 // -----------------------------------------------------------------------------
supportsService(const::rtl::OUString & rServiceName)318 sal_Bool VCLXAccessibleToolBoxItem::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
319 {
320 Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
321 const ::rtl::OUString* pNames = aNames.getConstArray();
322 const ::rtl::OUString* pEnd = pNames + aNames.getLength();
323 for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
324 ;
325
326 return pNames != pEnd;
327 }
328 // -----------------------------------------------------------------------------
getSupportedServiceNames()329 Sequence< ::rtl::OUString > VCLXAccessibleToolBoxItem::getSupportedServiceNames() throw (RuntimeException)
330 {
331 Sequence< ::rtl::OUString > aNames(4);
332 aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.accessibility.AccessibleContext" );
333 aNames[1] = ::rtl::OUString::createFromAscii( "com.sun.star.accessibility.AccessibleComponent" );
334 aNames[2] = ::rtl::OUString::createFromAscii( "com.sun.star.accessibility.AccessibleExtendedComponent" );
335 aNames[3] = ::rtl::OUString::createFromAscii( "com.sun.star.accessibility.AccessibleToolBoxItem" );
336 return aNames;
337 }
338 // -----------------------------------------------------------------------------
339 // XAccessible
340 // -----------------------------------------------------------------------------
getAccessibleContext()341 Reference< XAccessibleContext > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleContext( ) throw (RuntimeException)
342 {
343 return this;
344 }
345 // -----------------------------------------------------------------------------
346 // XAccessibleContext
347 // -----------------------------------------------------------------------------
getAccessibleChildCount()348 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleChildCount( ) throw (RuntimeException)
349 {
350 OContextEntryGuard aGuard( this );
351
352 return m_xChild.is() ? 1 : 0;
353 }
354 // -----------------------------------------------------------------------------
getAccessibleChild(sal_Int32 i)355 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleChild( sal_Int32 i ) throw (RuntimeException, com::sun::star::lang::IndexOutOfBoundsException)
356 {
357 OContextEntryGuard aGuard( this );
358
359 // no child -> so index is out of bounds
360 if ( !m_xChild.is() || i != 0 )
361 throw IndexOutOfBoundsException();
362
363 return m_xChild;
364 }
365 // -----------------------------------------------------------------------------
getAccessibleParent()366 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleParent( ) throw (RuntimeException)
367 {
368 OContextEntryGuard aGuard( this );
369
370 return m_pToolBox->GetAccessible();
371 }
372 // -----------------------------------------------------------------------------
getAccessibleIndexInParent()373 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleIndexInParent( ) throw (RuntimeException)
374 {
375 OContextEntryGuard aGuard( this );
376
377 return m_nIndexInParent;
378 }
379 // -----------------------------------------------------------------------------
getAccessibleRole()380 sal_Int16 SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleRole( ) throw (RuntimeException)
381 {
382 OContextEntryGuard aGuard( this );
383
384 return m_nRole;
385 }
386 // -----------------------------------------------------------------------------
getAccessibleDescription()387 ::rtl::OUString SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleDescription( ) throw (RuntimeException)
388 {
389 OExternalLockGuard aGuard( this );
390
391
392 if(m_nRole == AccessibleRole::PANEL && getAccessibleChildCount() > 0 )
393 {
394 return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_PANEL_DESCRIPTION ) );
395 }
396 else
397 {
398 ::rtl::OUString sDescription;
399 if ( m_pToolBox )
400 sDescription = m_pToolBox->GetHelpText( m_nItemId );
401
402 return sDescription;
403 }
404 }
405 // -----------------------------------------------------------------------------
getAccessibleName()406 ::rtl::OUString SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleName( ) throw (RuntimeException)
407 {
408 OExternalLockGuard aGuard( this );
409
410 // entry text == accessible name
411 return GetText( true );
412 }
413 // -----------------------------------------------------------------------------
getAccessibleRelationSet()414 Reference< XAccessibleRelationSet > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleRelationSet( ) throw (RuntimeException)
415 {
416 OContextEntryGuard aGuard( this );
417
418 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
419 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
420 return xSet;
421 }
422 // -----------------------------------------------------------------------------
getAccessibleStateSet()423 Reference< XAccessibleStateSet > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleStateSet( ) throw (RuntimeException)
424 {
425 OExternalLockGuard aGuard( this );
426
427 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
428 Reference< XAccessibleStateSet > xStateSet = pStateSetHelper;
429
430 if ( m_pToolBox && !rBHelper.bDisposed && !rBHelper.bInDispose )
431 {
432 pStateSetHelper->AddState( AccessibleStateType::FOCUSABLE );
433 if ( m_bIsChecked && m_nRole != AccessibleRole::PANEL )
434 pStateSetHelper->AddState( AccessibleStateType::CHECKED );
435 if ( m_bIndeterminate )
436 pStateSetHelper->AddState( AccessibleStateType::INDETERMINATE );
437 if ( m_pToolBox->IsEnabled() && m_pToolBox->IsItemEnabled( m_nItemId ) )
438 {
439 pStateSetHelper->AddState( AccessibleStateType::ENABLED );
440 pStateSetHelper->AddState( AccessibleStateType::SENSITIVE );
441 }
442 if ( m_pToolBox->IsItemVisible( m_nItemId ) )
443 pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
444 if ( m_pToolBox->IsItemReallyVisible( m_nItemId ) )
445 pStateSetHelper->AddState( AccessibleStateType::SHOWING );
446 if ( m_bHasFocus )
447 pStateSetHelper->AddState( AccessibleStateType::FOCUSED );
448 }
449 else
450 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
451
452 return xStateSet;
453 }
454 // -----------------------------------------------------------------------------
455 // XAccessibleText
456 // -----------------------------------------------------------------------------
getCaretPosition()457 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getCaretPosition() throw (RuntimeException)
458 {
459 return -1;
460 }
461 // -----------------------------------------------------------------------------
setCaretPosition(sal_Int32 nIndex)462 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::setCaretPosition( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
463 {
464 OExternalLockGuard aGuard( this );
465
466 if ( !implIsValidRange( nIndex, nIndex, implGetText().getLength() ) )
467 throw IndexOutOfBoundsException();
468
469 return sal_False;
470 }
471 // -----------------------------------------------------------------------------
getCharacterAttributes(sal_Int32 nIndex,const Sequence<::rtl::OUString> &)472 Sequence< PropertyValue > SAL_CALL VCLXAccessibleToolBoxItem::getCharacterAttributes( sal_Int32 nIndex, const Sequence< ::rtl::OUString >& ) throw (IndexOutOfBoundsException, RuntimeException)
473 {
474 OExternalLockGuard aGuard( this );
475
476 ::rtl::OUString sText( implGetText() );
477
478 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
479 throw IndexOutOfBoundsException();
480
481 return Sequence< PropertyValue >();
482 }
483 // -----------------------------------------------------------------------------
getCharacterBounds(sal_Int32 nIndex)484 awt::Rectangle SAL_CALL VCLXAccessibleToolBoxItem::getCharacterBounds( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
485 {
486 OExternalLockGuard aGuard( this );
487
488 ::rtl::OUString sText( implGetText() );
489
490 if ( !implIsValidIndex( nIndex, sText.getLength() ) )
491 throw IndexOutOfBoundsException();
492
493 awt::Rectangle aBounds( 0, 0, 0, 0 );
494 if ( m_pToolBox && m_pToolBox->GetButtonType() != BUTTON_SYMBOL ) // symbol buttons have no character bounds
495 {
496 Rectangle aCharRect = m_pToolBox->GetCharacterBounds( m_nItemId, nIndex );
497 Rectangle aItemRect = m_pToolBox->GetItemRect( m_nItemId );
498 aCharRect.Move( -aItemRect.Left(), -aItemRect.Top() );
499 aBounds = AWTRectangle( aCharRect );
500 }
501
502 return aBounds;
503 }
504 // -----------------------------------------------------------------------------
getIndexAtPoint(const awt::Point & aPoint)505 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getIndexAtPoint( const awt::Point& aPoint ) throw (RuntimeException)
506 {
507 OExternalLockGuard aGuard( this );
508
509 sal_Int32 nIndex = -1;
510 if ( m_pToolBox && m_pToolBox->GetButtonType() != BUTTON_SYMBOL ) // symbol buttons have no character bounds
511 {
512 sal_uInt16 nItemId = 0;
513 Rectangle aItemRect = m_pToolBox->GetItemRect( m_nItemId );
514 Point aPnt( VCLPoint( aPoint ) );
515 aPnt += aItemRect.TopLeft();
516 sal_Int32 nIdx = m_pToolBox->GetIndexForPoint( aPnt, nItemId );
517 if ( nIdx != -1 && nItemId == m_nItemId )
518 nIndex = nIdx;
519 }
520
521 return nIndex;
522 }
523 // -----------------------------------------------------------------------------
setSelection(sal_Int32 nStartIndex,sal_Int32 nEndIndex)524 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::setSelection( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
525 {
526 OExternalLockGuard aGuard( this );
527
528 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
529 throw IndexOutOfBoundsException();
530
531 return sal_False;
532 }
533 // -----------------------------------------------------------------------------
copyText(sal_Int32 nStartIndex,sal_Int32 nEndIndex)534 sal_Bool SAL_CALL VCLXAccessibleToolBoxItem::copyText( sal_Int32 nStartIndex, sal_Int32 nEndIndex ) throw (IndexOutOfBoundsException, RuntimeException)
535 {
536 OExternalLockGuard aGuard( this );
537
538 if ( !implIsValidRange( nStartIndex, nEndIndex, implGetText().getLength() ) )
539 throw IndexOutOfBoundsException();
540
541 sal_Bool bReturn = sal_False;
542
543 if ( m_pToolBox )
544 {
545 Reference< datatransfer::clipboard::XClipboard > xClipboard = m_pToolBox->GetClipboard();
546 if ( xClipboard.is() )
547 {
548 ::rtl::OUString sText( getTextRange( nStartIndex, nEndIndex ) );
549
550 ::vcl::unohelper::TextDataObject* pDataObj = new ::vcl::unohelper::TextDataObject( sText );
551 const sal_uInt32 nRef = Application::ReleaseSolarMutex();
552 xClipboard->setContents( pDataObj, NULL );
553
554 Reference< datatransfer::clipboard::XFlushableClipboard > xFlushableClipboard( xClipboard, uno::UNO_QUERY );
555 if( xFlushableClipboard.is() )
556 xFlushableClipboard->flushClipboard();
557
558 Application::AcquireSolarMutex( nRef );
559
560 bReturn = sal_True;
561 }
562 }
563
564 return bReturn;
565 }
566 // -----------------------------------------------------------------------------
567 // XAccessibleComponent
568 // -----------------------------------------------------------------------------
getAccessibleAtPoint(const awt::Point &)569 Reference< XAccessible > SAL_CALL VCLXAccessibleToolBoxItem::getAccessibleAtPoint( const awt::Point& ) throw (RuntimeException)
570 {
571 return Reference< XAccessible >();
572 }
573 // -----------------------------------------------------------------------------
grabFocus()574 void SAL_CALL VCLXAccessibleToolBoxItem::grabFocus( ) throw (RuntimeException)
575 {
576 Reference< XAccessible > xParent(getAccessibleParent());
577
578 if( xParent.is() )
579 {
580 Reference< XAccessibleSelection > rxAccessibleSelection(xParent->getAccessibleContext(), UNO_QUERY);
581
582 if ( rxAccessibleSelection.is() )
583 {
584 rxAccessibleSelection -> selectAccessibleChild ( getAccessibleIndexInParent() );
585 }
586 }
587 }
588 // -----------------------------------------------------------------------------
getForeground()589 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getForeground( ) throw (RuntimeException)
590 {
591 OExternalLockGuard aGuard( this );
592
593 sal_Int32 nColor = 0;
594 if ( m_pToolBox )
595 nColor = m_pToolBox->GetControlForeground().GetColor();
596
597 return nColor;
598 }
599 // -----------------------------------------------------------------------------
getBackground()600 sal_Int32 SAL_CALL VCLXAccessibleToolBoxItem::getBackground( ) throw (RuntimeException)
601 {
602 OExternalLockGuard aGuard( this );
603
604 sal_Int32 nColor = 0;
605 if ( m_pToolBox )
606 nColor = m_pToolBox->GetControlBackground().GetColor();
607
608 return nColor;
609 }
610 // -----------------------------------------------------------------------------
611 // XAccessibleExtendedComponent
612 // -----------------------------------------------------------------------------
getFont()613 Reference< awt::XFont > SAL_CALL VCLXAccessibleToolBoxItem::getFont( ) throw (RuntimeException)
614 {
615 return uno::Reference< awt::XFont >();
616 }
617 // -----------------------------------------------------------------------------
getFontMetrics(const Reference<awt::XFont> & xFont)618 awt::FontDescriptor SAL_CALL VCLXAccessibleToolBoxItem::getFontMetrics( const Reference< awt::XFont >& xFont ) throw (RuntimeException)
619 {
620 return xFont->getFontDescriptor();
621 }
622 // -----------------------------------------------------------------------------
getTitledBorderText()623 ::rtl::OUString SAL_CALL VCLXAccessibleToolBoxItem::getTitledBorderText( ) throw (RuntimeException)
624 {
625 OExternalLockGuard aGuard( this );
626
627 ::rtl::OUString sRet;
628 if ( m_pToolBox )
629 sRet = m_pToolBox->GetItemText( m_nItemId );
630
631 return sRet;
632 }
633 // -----------------------------------------------------------------------------
getToolTipText()634 ::rtl::OUString SAL_CALL VCLXAccessibleToolBoxItem::getToolTipText( ) throw (RuntimeException)
635 {
636 OExternalLockGuard aGuard( this );
637
638 ::rtl::OUString sRet;
639 if ( m_pToolBox )
640 {
641 if ( Help::IsExtHelpEnabled() )
642 sRet = m_pToolBox->GetHelpText( m_nItemId );
643 else
644 sRet = m_pToolBox->GetQuickHelpText( m_nItemId );
645 if ( sRet.isEmpty() )
646 // no help text set, so use item text
647 sRet = m_pToolBox->GetItemText( m_nItemId );
648 }
649 return sRet;
650 }
651 // -----------------------------------------------------------------------------
652 // XAccessibleAction
653 // -----------------------------------------------------------------------------
getAccessibleActionCount()654 sal_Int32 VCLXAccessibleToolBoxItem::getAccessibleActionCount( ) throw (RuntimeException)
655 {
656 // only one action -> "Click"
657 return 1;
658 }
659 // -----------------------------------------------------------------------------
doAccessibleAction(sal_Int32 nIndex)660 sal_Bool VCLXAccessibleToolBoxItem::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
661 {
662 OExternalLockGuard aGuard( this );
663
664 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
665 throw IndexOutOfBoundsException();
666
667 if ( m_pToolBox )
668 m_pToolBox->TriggerItem( m_nItemId );
669
670 return sal_True;
671 }
672 // -----------------------------------------------------------------------------
getAccessibleActionDescription(sal_Int32 nIndex)673 ::rtl::OUString VCLXAccessibleToolBoxItem::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
674 {
675 OExternalLockGuard aGuard( this );
676
677 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
678 throw IndexOutOfBoundsException();
679
680 return ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_CLICK ) );
681 }
682 // -----------------------------------------------------------------------------
getAccessibleActionKeyBinding(sal_Int32 nIndex)683 Reference< XAccessibleKeyBinding > VCLXAccessibleToolBoxItem::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
684 {
685 OContextEntryGuard aGuard( this );
686
687 if ( nIndex < 0 || nIndex >= getAccessibleActionCount() )
688 throw IndexOutOfBoundsException();
689
690 return Reference< XAccessibleKeyBinding >();
691 }
692 // -----------------------------------------------------------------------------
693 // XAccessibleValue
694 // -----------------------------------------------------------------------------
getCurrentValue()695 Any VCLXAccessibleToolBoxItem::getCurrentValue( ) throw (RuntimeException)
696 {
697 OExternalLockGuard aGuard( this );
698
699 Any aValue;
700 if ( m_pToolBox )
701 aValue <<= (sal_Int32)m_pToolBox->IsItemChecked( m_nItemId );
702
703 if( m_nRole == AccessibleRole::PANEL )
704 aValue <<= (sal_Int32)0;
705 return aValue;
706 }
707 // -----------------------------------------------------------------------------
setCurrentValue(const Any & aNumber)708 sal_Bool VCLXAccessibleToolBoxItem::setCurrentValue( const Any& aNumber ) throw (RuntimeException)
709 {
710 OExternalLockGuard aGuard( this );
711
712 sal_Bool bReturn = sal_False;
713
714 if ( m_pToolBox )
715 {
716 sal_Int32 nValue = 0;
717 OSL_VERIFY( aNumber >>= nValue );
718
719 if ( nValue < 0 )
720 nValue = 0;
721 else if ( nValue > 1 )
722 nValue = 1;
723
724 m_pToolBox->CheckItem( m_nItemId, (sal_Bool) nValue );
725 bReturn = sal_True;
726 }
727
728 return bReturn;
729 }
730 // -----------------------------------------------------------------------------
getMaximumValue()731 Any VCLXAccessibleToolBoxItem::getMaximumValue( ) throw (RuntimeException)
732 {
733 return makeAny((sal_Int32)1);
734 }
735 // -----------------------------------------------------------------------------
getMinimumValue()736 Any VCLXAccessibleToolBoxItem::getMinimumValue( ) throw (RuntimeException)
737 {
738 return makeAny((sal_Int32)0);
739 }
740 // -----------------------------------------------------------------------------
741
742
743