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