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