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 // MARKER(update_precomp.py): autogen include statement, do not remove
24 #include "precompiled_svx.hxx"
25 
26 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEROLE_HPP_
27 #include <com/sun/star/accessibility/AccessibleRole.hpp>
28 #endif
29 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLEEVENTID_HPP_
30 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
31 #endif
32 #ifndef _UTL_ACCESSIBLESTATESETHELPER_HXX_
33 #include <unotools/accessiblestatesethelper.hxx>
34 #endif
35 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLESTATETYPE_HPP_
36 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
37 #endif
38 
39 #ifndef	_COM_SUN_STAR_BEANS_PROPERTYCHANGEEVENT_HPP_
40 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
41 #endif
42 
43 #ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
44 #include <com/sun/star/awt/XWindow.hpp>
45 #endif
46 
47 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
48 #include <cppuhelper/typeprovider.hxx>
49 #endif
50 
51 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
52 #include <toolkit/helper/vclunohelper.hxx>
53 #endif
54 #ifndef _TOOLKIT_HELPER_CONVERT_HXX_
55 #include <toolkit/helper/convert.hxx>
56 #endif
57 
58 #ifndef _SV_SVAPP_HXX
59 #include <vcl/svapp.hxx>
60 #endif
61 
62 #ifndef _OSL_MUTEX_HXX_
63 #include <osl/mutex.hxx>
64 #endif
65 #ifndef _RTL_UUID_H_
66 #include <rtl/uuid.h>
67 #endif
68 #ifndef _TOOLS_DEBUG_HXX
69 #include <tools/debug.hxx>
70 #endif
71 #ifndef _SV_GEN_HXX
72 #include <tools/gen.hxx>
73 #endif
74 
75 #include <svx/dialogs.hrc>
76 #include "accessibility.hrc"
77 #include <svx/dlgctrl.hxx>
78 
79 #ifndef _SVX_DIALMGR_HXX
80 #include <svx/dialmgr.hxx>
81 #endif
82 #ifndef COMPHELPER_ACCESSIBLE_EVENT_NOTIFIER
83 #include <comphelper/accessibleeventnotifier.hxx>
84 #endif
85 
86 #include <unotools/accessiblerelationsethelper.hxx>
87 
88 #ifndef _SVXPIXELACCESSIBLECONTEXT_HXX
89 #include "svxpixelctlaccessiblecontext.hxx"
90 #endif
91 #ifndef _COM_SUN_STAR_ACCESSIBILITY_ACCESSIBLERELATIONTYPE_HPP_
92 #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
93 #endif
94 using namespace ::cppu;
95 using namespace ::osl;
96 using namespace	::rtl;
97 using namespace	::com::sun::star;
98 using namespace	::com::sun::star::uno;
99 using namespace	::com::sun::star::accessibility;
100 
SvxPixelCtlAccessible(SvxPixelCtl & rControl)101 SvxPixelCtlAccessible::SvxPixelCtlAccessible( SvxPixelCtl& rControl) :
102 	SvxPixelCtlAccessible_BASE(m_aMutex),
103     pPixelCtl(&rControl),
104     mnClientId(0)
105 {
106     //FreeResource();
107 }
108 
~SvxPixelCtlAccessible()109 SvxPixelCtlAccessible::~SvxPixelCtlAccessible()
110 {
111 //	DBG_DTOR( SvxPixelCtlAccessible, NULL );
112 
113 	if( IsAlive() )
114 	{
115 		osl_incrementInterlockedCount( &m_refCount );
116 		dispose();		// set mpRepr = NULL & release all childs
117 	}
118 }
119 /*-- 04.02.2002 14:11:55---------------------------------------------------
120 
121   -----------------------------------------------------------------------*/
getAccessibleContext()122 uno::Reference< XAccessibleContext > SvxPixelCtlAccessible::getAccessibleContext(  )
123     throw (uno::RuntimeException)
124 {
125     return this;
126 }
127 
getAccessibleChildCount()128 sal_Int32 SvxPixelCtlAccessible::getAccessibleChildCount(  ) throw (uno::RuntimeException)
129 {
130     ::osl::MutexGuard	aGuard( m_aMutex );
131     IsValid();
132 	if(pPixelCtl)
133 	{
134 	    return pPixelCtl->GetSquares();
135 	}
136 	else
137 		return 0;
138 }
139 /*-- 04.02.2002 14:11:56---------------------------------------------------
140 
141   -----------------------------------------------------------------------*/
getAccessibleChild(sal_Int32 i)142 uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleChild( sal_Int32 i )
143     throw (uno::RuntimeException)
144 {
145     ::osl::MutexGuard	aGuard( m_aMutex );
146     IsValid();
147     if ( i < 0 || i >= getAccessibleChildCount())
148 	throw lang::IndexOutOfBoundsException();
149     uno::Reference <XAccessible> xAcc;
150     if(pPixelCtl)
151 	{
152 		return CreateChild(i, pPixelCtl->IndexToPoint(i));
153 	}
154     else
155 		return xAcc;
156     /*
157     throw lang::IndexOutOfBoundsException (
158         ::rtl::OUString::createFromAscii ("no child with index " + i),
159 		NULL);
160     */
161 }
162 
163 
164 
getAccessibleParent()165 uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleParent(  )
166     throw (uno::RuntimeException)
167 {
168     ::osl::MutexGuard	aGuard( m_aMutex );
169     IsValid();
170     uno::Reference< XAccessible > xRet;
171     if(pPixelCtl)
172 	    xRet = pPixelCtl->GetParent()->GetAccessible( sal_True );
173     return xRet;
174 }
175 
getAccessibleIndexInParent()176 sal_Int32 SvxPixelCtlAccessible::getAccessibleIndexInParent(  )
177     throw (uno::RuntimeException)
178 {
179     ::osl::MutexGuard	aGuard( m_aMutex );
180     IsValid();
181     sal_uInt16 nIdx = 0;
182     if(pPixelCtl)
183     {
184         Window* pTabPage = pPixelCtl->GetParent();
185         sal_uInt16 nChildren = pTabPage->GetChildCount();
186         for(nIdx = 0; nIdx < nChildren; nIdx++)
187             if(pTabPage->GetChild( nIdx ) == pPixelCtl)
188                 break;
189     }
190     return nIdx;
191 }
192 /*-- 04.02.2002 14:11:57---------------------------------------------------
193 
194   -----------------------------------------------------------------------*/
getAccessibleRole()195 sal_Int16 SvxPixelCtlAccessible::getAccessibleRole(  ) throw (uno::RuntimeException)
196 {
197     return AccessibleRole::LIST;
198 }
199 
getAccessibleDescription()200 ::rtl::OUString SvxPixelCtlAccessible::getAccessibleDescription(  )
201     throw (uno::RuntimeException)
202 {
203 
204     ::osl::MutexGuard	aGuard( m_aMutex );
205     IsValid();
206     if(pPixelCtl)
207 	return pPixelCtl->GetAccessibleDescription();
208     else
209 	return String();
210 
211 }
212 
getAccessibleName()213 ::rtl::OUString SvxPixelCtlAccessible::getAccessibleName(  )
214     throw (uno::RuntimeException)
215 {
216 
217     ::osl::MutexGuard	aGuard( m_aMutex );
218     IsValid();
219     if(pPixelCtl)
220 	    return pPixelCtl->GetAccessibleName();
221     else
222 	    return String();
223 
224 }
225 
getAccessibleRelationSet()226 uno::Reference< XAccessibleRelationSet > SvxPixelCtlAccessible::getAccessibleRelationSet(  )
227     throw (uno::RuntimeException)
228 {
229     ::osl::MutexGuard	aGuard( m_aMutex );
230     IsValid();
231 	Window* pWindow = (Window*)pPixelCtl;
232 	utl::AccessibleRelationSetHelper* rRelationSet = new utl::AccessibleRelationSetHelper;
233 	uno::Reference< accessibility::XAccessibleRelationSet > rSet = rRelationSet;
234 	if ( pWindow )
235 	{
236 		Window *pLabeledBy = pWindow->GetAccessibleRelationLabeledBy();
237 		if ( pLabeledBy && pLabeledBy != pWindow )
238 		{
239 			uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
240 			aSequence[0] = pLabeledBy->GetAccessible();
241 			rRelationSet->AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::LABELED_BY, aSequence ) );
242 		}
243 
244 		Window* pMemberOf = pWindow->GetAccessibleRelationMemberOf();
245 		if ( pMemberOf && pMemberOf != pWindow )
246 		{
247 			uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
248 			aSequence[0] = pMemberOf->GetAccessible();
249 			rRelationSet->AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::MEMBER_OF, aSequence ) );
250 		}
251 		return rSet;
252 	}
253 
254     return new utl::AccessibleRelationSetHelper;
255 }
256 
257 
getAccessibleStateSet()258 uno::Reference< XAccessibleStateSet > SvxPixelCtlAccessible::getAccessibleStateSet(  )
259     throw (uno::RuntimeException)
260 {
261     ::osl::MutexGuard	aGuard( m_aMutex );
262     utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
263     uno::Reference< XAccessibleStateSet > xRet = pStateSetHelper;
264 
265     if(!pPixelCtl)
266         pStateSetHelper->AddState(AccessibleStateType::DEFUNC);
267     else
268     {
269         const sal_Int16 aStandardStates[] =
270         {
271             AccessibleStateType::FOCUSABLE,
272 				AccessibleStateType::SELECTABLE,
273 				AccessibleStateType::SHOWING,
274 				AccessibleStateType::VISIBLE,
275 				AccessibleStateType::OPAQUE,
276 				0};
277 
278 			sal_Int16 nState = 0;
279 			while(aStandardStates[nState])
280 			{
281 				pStateSetHelper->AddState(aStandardStates[nState++]);
282 			}
283 			if(pPixelCtl->IsEnabled())
284 				pStateSetHelper->AddState(AccessibleStateType::ENABLED);
285 			if(pPixelCtl->HasFocus())
286 				pStateSetHelper->AddState(AccessibleStateType::FOCUSED);
287 			pStateSetHelper->AddState(AccessibleStateType::MANAGES_DESCENDANTS);
288     }
289     return xRet;
290 }
291 
292 
getLocale()293 com::sun::star::lang::Locale SvxPixelCtlAccessible::getLocale(  )
294     throw (IllegalAccessibleComponentStateException, uno::RuntimeException)
295 {
296 	::osl::MutexGuard	aGuard( m_aMutex );
297 	if( getAccessibleParent().is() )
298     {
299     	uno::Reference< XAccessibleContext >		xParentContext( getAccessibleParent()->getAccessibleContext() );
300         if( xParentContext.is() )
301 	    	return xParentContext->getLocale();
302     }
303 
304     //	No locale and no parent.  Therefore throw exception to indicate this
305     //	cluelessness.
306     throw IllegalAccessibleComponentStateException();
307 }
308 
309 
containsPoint(const awt::Point & aPt)310 sal_Bool SvxPixelCtlAccessible::containsPoint( const awt::Point& aPt )
311     throw (uno::RuntimeException)
312 {
313     ::osl::MutexGuard	aGuard( m_aMutex );
314     IsValid();
315     Point aPoint(aPt.X, aPt.Y);
316     if(pPixelCtl)
317 	    return (aPoint.X() >= 0)
318 	        && (aPoint.X() < pPixelCtl->GetSizePixel().getWidth())
319 	        && (aPoint.Y() >= 0)
320 	        && (aPoint.Y() < pPixelCtl->GetSizePixel().getHeight());
321     else
322 	    return sal_False;
323 }
getAccessibleAtPoint(const awt::Point & aPoint)324 uno::Reference<XAccessible > SAL_CALL SvxPixelCtlAccessible::getAccessibleAtPoint (
325         const awt::Point& aPoint)
326     throw (uno::RuntimeException)
327 {
328 	::osl::MutexGuard	aGuard( m_aMutex );
329 	ensureIsAlive();
330 	uno::Reference <XAccessible> xAcc;
331 
332 	Point childPoint;
333 	childPoint.X() = aPoint.X;
334 	childPoint.Y() = aPoint.Y;
335 
336     if(pPixelCtl)
337    	{
338 		Point pt= pPixelCtl->PixelToLogic(childPoint);
339 		long nIndex = pPixelCtl->PointToIndex(pt);
340 	    return CreateChild(nIndex,pPixelCtl->IndexToPoint(nIndex));
341     }
342     else
343 	   return xAcc;
344 
345 }
346 
getBounds()347 awt::Rectangle SvxPixelCtlAccessible::getBounds(  ) throw (uno::RuntimeException)
348 {
349     ::osl::MutexGuard	aGuard( m_aMutex );
350     IsValid();
351     Size aSz;
352     Point aPos(0,0);
353     awt::Rectangle aRet;
354 	if(pPixelCtl)
355 	{
356 	    aSz = pPixelCtl->GetSizePixel();
357 	    aPos = pPixelCtl->GetPosPixel();
358 	    aRet.X = aPos.X();
359 	    aRet.Y = aPos.Y();
360 	    aRet.Width = aSz.Width();
361 	    aRet.Height = aSz.Height();
362 	}
363     return aRet;
364 }
365 
getLocation()366 awt::Point SvxPixelCtlAccessible::getLocation(  ) throw (uno::RuntimeException)
367 {
368     ::osl::MutexGuard	aGuard( m_aMutex );
369     IsValid();
370     Point aPos;
371     aPos = pPixelCtl->GetPosPixel();
372     awt::Point aRet(aPos.X(), aPos.Y());
373     return aRet;
374 }
375 
getLocationOnScreen()376 awt::Point SvxPixelCtlAccessible::getLocationOnScreen(  ) throw (uno::RuntimeException)
377 {
378     ::osl::MutexGuard	aGuard( m_aMutex );
379     IsValid();
380     Rectangle rect;
381     rect = pPixelCtl->GetWindowExtentsRelative(NULL);
382     awt::Point aRet(rect.Left(),rect.Top() );
383     return aRet;
384 }
385 
getSize()386 awt::Size SvxPixelCtlAccessible::getSize(  ) throw (uno::RuntimeException)
387 {
388     ::osl::MutexGuard	aGuard( m_aMutex );
389     IsValid();
390     Size aSz;
391     aSz = pPixelCtl->GetSizePixel();
392     awt::Size aRet(aSz.Width(),aSz.Height());
393     return aRet;
394 }
grabFocus()395 void SvxPixelCtlAccessible::grabFocus(  ) throw (uno::RuntimeException)
396 {
397     ::osl::MutexGuard	aGuard( m_aMutex );
398     IsValid();
399     if(pPixelCtl)
400 	pPixelCtl->GrabFocus();
401 }
402 
getForeground()403 sal_Int32 SvxPixelCtlAccessible::getForeground(  )
404         throw (::com::sun::star::uno::RuntimeException)
405 {
406     uno::Any aRet;
407     ::osl::MutexGuard	aGuard( m_aMutex );
408     IsValid();
409     return pPixelCtl->GetControlForeground().GetColor();
410 }
411 
getBackground()412 sal_Int32 SvxPixelCtlAccessible::getBackground(  )
413         throw (::com::sun::star::uno::RuntimeException)
414 {
415     uno::Any aRet;
416     ::osl::MutexGuard	aGuard( m_aMutex );
417     IsValid();
418     return pPixelCtl->GetControlBackground().GetColor();
419 }
420 
getImplementationName()421 ::rtl::OUString SvxPixelCtlAccessible::getImplementationName(  ) throw (uno::RuntimeException)
422 {
423     return rtl::OUString::createFromAscii("SvxPixelCtlAccessible");
424 }
425 /*-- 04.02.2002 14:12:05---------------------------------------------------
426 
427   -----------------------------------------------------------------------*/
428 const sal_Char sAccessible[]          = "Accessible";
429 const sal_Char sAccessibleContext[]   = "AccessibleContext";
430 const sal_Char sAccessibleComponent[] = "AccessibleComponent";
431 //const sal_Char sAccessibleTable[] = "AccessibleTable";
432 
supportsService(const::rtl::OUString & rServiceName)433 sal_Bool SvxPixelCtlAccessible::supportsService( const ::rtl::OUString& rServiceName )
434     throw (uno::RuntimeException)
435 {
436     return  rServiceName.equalsAsciiL( sAccessible         , sizeof(sAccessible         )-1 ) ||
437             rServiceName.equalsAsciiL( sAccessibleContext  , sizeof(sAccessibleContext  )-1 ) ||
438             rServiceName.equalsAsciiL( sAccessibleComponent, sizeof(sAccessibleComponent)-1 );// ||
439 //            rServiceName.equalsAsciiL( sAccessibleTable, sizeof(sAccessibleTable)-1 );
440 }
441 /*-- 04.02.2002 14:12:05---------------------------------------------------
442 
443   -----------------------------------------------------------------------*/
getSupportedServiceNames()444 uno::Sequence< ::rtl::OUString > SvxPixelCtlAccessible::getSupportedServiceNames(  )
445     throw (uno::RuntimeException)
446 {
447     uno::Sequence< OUString > aRet(2);
448 	OUString* pArray = aRet.getArray();
449     pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessible         ) );
450     pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleContext  ) );
451     pArray[2] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleComponent) );
452 //    pArray[3] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleTable) );
453     return aRet;
454 }
455 
456 // -----------------------------------------------------------------------------
457 // XAccessibleSelection
458 // -----------------------------------------------------------------------------
selectAccessibleChild(sal_Int32 nChildIndex)459 void SAL_CALL SvxPixelCtlAccessible::selectAccessibleChild( sal_Int32 nChildIndex ) throw (lang::IndexOutOfBoundsException, RuntimeException)
460 {
461     ::osl::MutexGuard	aGuard( m_aMutex );
462     IsValid();
463 
464 	if ( nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
465 		throw lang::IndexOutOfBoundsException();
466 
467 	long nIndex = pPixelCtl->ShowPosition(pPixelCtl->IndexToPoint(nChildIndex));
468 	NotifyChild(nIndex,sal_True,sal_False);
469 }
470 // -----------------------------------------------------------------------------
isAccessibleChildSelected(sal_Int32 nChildIndex)471 sal_Bool SAL_CALL SvxPixelCtlAccessible::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (lang::IndexOutOfBoundsException, RuntimeException)
472 {
473     ::osl::MutexGuard	aGuard( m_aMutex );
474 
475     IsValid();
476 
477 	return pPixelCtl->GetFoucsPosIndex() == nChildIndex;
478 }
479 // -----------------------------------------------------------------------------
clearAccessibleSelection()480 void SAL_CALL SvxPixelCtlAccessible::clearAccessibleSelection(  ) throw (RuntimeException)
481 {
482     ::osl::MutexGuard	aGuard( m_aMutex );
483 
484     IsValid();
485 
486 }
487 // -----------------------------------------------------------------------------
selectAllAccessibleChildren()488 void SAL_CALL SvxPixelCtlAccessible::selectAllAccessibleChildren(  ) throw (RuntimeException)
489 {
490     ::osl::MutexGuard	aGuard( m_aMutex );
491 
492     IsValid();
493 
494 }
495 // -----------------------------------------------------------------------------
getSelectedAccessibleChildCount()496 sal_Int32 SAL_CALL SvxPixelCtlAccessible::getSelectedAccessibleChildCount(  ) throw (RuntimeException)
497 {
498     ::osl::MutexGuard	aGuard( m_aMutex );
499 
500     IsValid();
501 
502 	return 1;
503 }
504 // -----------------------------------------------------------------------------
getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex)505 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessible::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (lang::IndexOutOfBoundsException, RuntimeException)
506 {
507     ::osl::MutexGuard	aGuard( m_aMutex );
508 
509     IsValid();
510 
511 	if ( nSelectedChildIndex >= 1)
512 		throw lang::IndexOutOfBoundsException();
513 
514 	uno::Reference< XAccessible > xChild;
515 	if(pPixelCtl)
516 	{
517 		if(m_xCurChild.is())
518 		{
519 			xChild = m_xCurChild;
520 		}
521 	}
522 	return xChild;
523 }
524 // -----------------------------------------------------------------------------
deselectAccessibleChild(sal_Int32)525 void SAL_CALL SvxPixelCtlAccessible::deselectAccessibleChild( sal_Int32 ) throw (lang::IndexOutOfBoundsException, RuntimeException)
526 {
527     ::osl::MutexGuard	aGuard( m_aMutex );
528 
529     IsValid();
530 
531 
532 }
533 
534 // Added by lq
ensureIsAlive() const535 void SvxPixelCtlAccessible::ensureIsAlive() const
536     throw ( lang::DisposedException )
537 {
538     if( !IsAlive() )
539         throw lang::DisposedException();
540 }
541 
ensureIsValidRow(sal_Int32 nRow)542 void SvxPixelCtlAccessible::ensureIsValidRow( sal_Int32 nRow )
543     throw ( lang::IndexOutOfBoundsException )
544 {
545     if( nRow >= pPixelCtl->GetHeight() || nRow <0)
546         throw lang::IndexOutOfBoundsException(
547             OUString( RTL_CONSTASCII_USTRINGPARAM( "row index is invalid" ) ), *this );
548 }
549 
ensureIsValidColumn(sal_Int32 nColumn)550 void SvxPixelCtlAccessible::ensureIsValidColumn( sal_Int32 nColumn )
551     throw ( lang::IndexOutOfBoundsException )
552 {
553     if( nColumn >= pPixelCtl->GetWidth() || nColumn <0 )
554         throw lang::IndexOutOfBoundsException(
555             OUString( RTL_CONSTASCII_USTRINGPARAM("column index is invalid") ), *this );
556 }
557 
ensureIsValidAddress(sal_Int32 nRow,sal_Int32 nColumn)558 void SvxPixelCtlAccessible::ensureIsValidAddress(
559         sal_Int32 nRow, sal_Int32 nColumn )
560     throw ( lang::IndexOutOfBoundsException )
561 {
562     ensureIsValidRow( nRow );
563     ensureIsValidColumn( nColumn );
564 }
565 
ensureIsValidIndex(sal_Int32 nChildIndex)566 void SvxPixelCtlAccessible::ensureIsValidIndex( sal_Int32 nChildIndex )
567     throw ( lang::IndexOutOfBoundsException )
568 {
569     if( nChildIndex >=  pPixelCtl->GetSquares())
570         throw lang::IndexOutOfBoundsException(
571             OUString( RTL_CONSTASCII_USTRINGPARAM("child index is invalid") ), *this );
572 }
573 
574 // XAccessibleTable -----------------------------------------------------------
575 /*
576 sal_Int32 SAL_CALL SvxPixelCtlAccessible::getAccessibleRowCount()
577     throw ( uno::RuntimeException )
578 {
579    ::osl::MutexGuard	aGuard( m_aMutex );
580    ensureIsAlive();
581     return pPixelCtl->GetLineCount();
582 }
583 
584 sal_Int32 SAL_CALL SvxPixelCtlAccessible::getAccessibleColumnCount()
585     throw ( uno::RuntimeException )
586 {
587     ::osl::MutexGuard	aGuard( m_aMutex );
588     ensureIsAlive();
589     return pPixelCtl->GetLineCount();
590 }
591 
592 sal_Int32 SAL_CALL SvxPixelCtlAccessible::getAccessibleRowExtentAt(
593         sal_Int32 nRow, sal_Int32 nColumn )
594     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
595 {
596     ::osl::MutexGuard	aGuard( m_aMutex );
597     ensureIsAlive();
598     return 1;   // merged cells not supported
599 }
600 
601 sal_Int32 SAL_CALL SvxPixelCtlAccessible::getAccessibleColumnExtentAt(
602         sal_Int32 nRow, sal_Int32 nColumn )
603     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
604 {
605     ::osl::MutexGuard	aGuard( m_aMutex );
606     ensureIsAlive();
607     return 1;   // merged cells not supported
608 }
609 
610 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessible::getAccessibleCaption()
611     throw ( uno::RuntimeException )
612 {
613 	uno::Reference< XAccessible > xAccessble;
614     ensureIsAlive();
615     return xAccessble;    // not supported
616 }
617 
618 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessible::getAccessibleSummary()
619     throw ( uno::RuntimeException )
620 {
621 	uno::Reference< XAccessible > xAccessble;
622     ensureIsAlive();
623     return xAccessble;    // not supported
624 }
625 
626 sal_Int32 SAL_CALL SvxPixelCtlAccessible::getAccessibleIndex(
627         sal_Int32 nRow, sal_Int32 nColumn )
628     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
629 {
630     ::osl::MutexGuard	aGuard( m_aMutex );
631     ensureIsAlive();
632     ensureIsValidAddress(nRow,nColumn);
633     return nRow + nColumn * pPixelCtl->GetLineCount() ;
634 }
635 
636 sal_Int32 SAL_CALL SvxPixelCtlAccessible::getAccessibleRow( sal_Int32 nChildIndex )
637     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
638 {
639     ::osl::MutexGuard	aGuard( m_aMutex );
640     ensureIsAlive();
641     ensureIsValidIndex( nChildIndex );
642     return nChildIndex/pPixelCtl->GetLineCount();
643 }
644 
645 sal_Int32 SAL_CALL SvxPixelCtlAccessible::getAccessibleColumn( sal_Int32 nChildIndex )
646     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
647 {
648     ::osl::MutexGuard	aGuard( m_aMutex );
649     ensureIsAlive();
650     ensureIsValidIndex( nChildIndex );
651     return nChildIndex%pPixelCtl->GetLineCount();
652 }
653 
654 ::rtl::OUString SAL_CALL SvxPixelCtlAccessible::getAccessibleRowDescription( sal_Int32 nRow )
655     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
656 {
657     ::osl::MutexGuard	aGuard( m_aMutex );
658     ensureIsAlive();
659     ensureIsValidRow( nRow );
660     return ::rtl::OUString::createFromAscii ("");
661 }
662 
663 ::rtl::OUString SAL_CALL SvxPixelCtlAccessible::getAccessibleColumnDescription( sal_Int32 nColumn )
664     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
665 {
666     ::osl::MutexGuard	aGuard( m_aMutex );
667     ensureIsAlive();
668     ensureIsValidColumn( nColumn );
669     return ::rtl::OUString::createFromAscii ("");
670 }
671 
672 uno::Reference< XAccessibleTable > SAL_CALL SvxPixelCtlAccessible::getAccessibleRowHeaders()
673     throw ( uno::RuntimeException )
674 {
675     ::osl::MutexGuard	aGuard( m_aMutex );
676     uno::Reference< XAccessibleTable > xAccessble;
677     ensureIsAlive();
678     return xAccessble;
679 }
680 
681 uno::Reference< XAccessibleTable > SAL_CALL SvxPixelCtlAccessible::getAccessibleColumnHeaders()
682     throw ( uno::RuntimeException )
683 {
684     ::osl::MutexGuard	aGuard( m_aMutex );
685     uno::Reference< XAccessibleTable > xAccessble;
686     ensureIsAlive();
687     return xAccessble;
688 }
689 
690 Sequence< sal_Int32 > SAL_CALL SvxPixelCtlAccessible::getSelectedAccessibleRows()
691     throw ( uno::RuntimeException )
692 {
693     ::osl::MutexGuard	aGuard( m_aMutex );
694     Sequence< sal_Int32 > accRows;
695     ensureIsAlive();
696 
697     return accRows;
698 }
699 
700 Sequence< sal_Int32 > SAL_CALL SvxPixelCtlAccessible::getSelectedAccessibleColumns()
701     throw ( uno::RuntimeException )
702 {
703     ::osl::MutexGuard	aGuard( m_aMutex );
704     Sequence< sal_Int32 > accColumns;
705     ensureIsAlive();
706 
707     return accColumns;
708 }
709 
710 sal_Bool SAL_CALL SvxPixelCtlAccessible::isAccessibleRowSelected( sal_Int32 nRow )
711     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
712 {
713     ::osl::MutexGuard	aGuard( m_aMutex );
714     ensureIsAlive();
715     ensureIsValidRow( nRow );
716     return sal_False;
717 }
718 
719 sal_Bool SAL_CALL SvxPixelCtlAccessible::isAccessibleColumnSelected( sal_Int32 nColumn )
720     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
721 {
722     ::osl::MutexGuard	aGuard( m_aMutex );
723     ensureIsAlive();
724     ensureIsValidColumn( nColumn );
725     return sal_False;
726 }
727 
728 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessible::getAccessibleCellAt(
729         sal_Int32 nRow, sal_Int32 nColumn )
730     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
731 {
732     ::osl::MutexGuard	aGuard( m_aMutex );
733     ensureIsAlive();
734     ensureIsValidAddress( nRow, nColumn );
735     return getAccessibleChild(nRow*pPixelCtl->GetLineCount()+nColumn);
736 }
737 
738 sal_Bool SAL_CALL SvxPixelCtlAccessible::isAccessibleSelected(
739         sal_Int32 nRow, sal_Int32 nColumn )
740     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
741 {
742     ::osl::MutexGuard	aGuard( m_aMutex );
743     ensureIsAlive();
744     ensureIsValidAddress( nRow, nColumn );
745     return isAccessibleChildSelected(nRow*pPixelCtl->GetLineCount()+nColumn);
746 }
747 // Added by lq end
748 */
749 
750 //XAccessibleEventBroadcaster
addEventListener(const uno::Reference<XAccessibleEventListener> & xListener)751 void SAL_CALL SvxPixelCtlAccessible::addEventListener( const uno::Reference< XAccessibleEventListener >& xListener )  throw( RuntimeException )
752 {
753 	if (xListener.is())
754     {
755 		::osl::MutexGuard	aGuard( m_aMutex );
756 		if (!mnClientId)
757 	            mnClientId = comphelper::AccessibleEventNotifier::registerClient( );
758 		comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener );
759     }
760 }
761 
removeEventListener(const uno::Reference<XAccessibleEventListener> & xListener)762 void SAL_CALL SvxPixelCtlAccessible::removeEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
763     throw( RuntimeException )
764 {
765 	if (xListener.is())
766 	{
767     	::osl::MutexGuard	aGuard( m_aMutex );
768 
769         sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
770 		if ( !nListenerCount )
771 		{
772 			comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
773 			mnClientId = 0;
774 		}
775 	}
776 }
CommitChange(const AccessibleEventObject & rEvent)777 void SvxPixelCtlAccessible::CommitChange( const AccessibleEventObject& rEvent )
778 {
779 	if (mnClientId)
780 		comphelper::AccessibleEventNotifier::addEvent( mnClientId, rEvent );
781 }
782 
783 //Solution:Add the event handling method
FireAccessibleEvent(short nEventId,const::com::sun::star::uno::Any & rOld,const::com::sun::star::uno::Any & rNew)784 void SvxPixelCtlAccessible::FireAccessibleEvent (short nEventId, const ::com::sun::star::uno::Any& rOld, const ::com::sun::star::uno::Any& rNew)
785 {
786 	const uno::Reference< XInterface >	xSource( *this );
787 	CommitChange( AccessibleEventObject( xSource, nEventId, rNew,rOld ) );
788 }
789 
disposing()790 void SAL_CALL SvxPixelCtlAccessible::disposing()
791 {
792 	if( !rBHelper.bDisposed )
793 	{
794 		{
795 			::osl::MutexGuard	aGuard( m_aMutex );
796 			if ( mnClientId )
797 			{
798 				comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
799 				mnClientId =  0;
800 			}
801 		}
802 	    //mxParent = uno::Reference< XAccessible >();
803 
804 	}
805 }
Invalidate()806 void SvxPixelCtlAccessible::Invalidate()
807 {
808 	pPixelCtl = 0;
809 }
ThrowExceptionIfNotAlive(void)810 void SvxPixelCtlAccessible::ThrowExceptionIfNotAlive( void ) throw( lang::DisposedException )
811 {
812 	if( IsNotAlive() )
813 		throw lang::DisposedException();
814 }
IsValid()815 void SvxPixelCtlAccessible::IsValid() throw (uno::RuntimeException)
816 {
817     if(!pPixelCtl)
818         throw uno::RuntimeException();
819 }
820 
821 
NotifyChild(long nIndex,sal_Bool bSelect,sal_Bool bCheck)822 void SvxPixelCtlAccessible::NotifyChild(long nIndex,sal_Bool bSelect ,sal_Bool bCheck)
823 {
824 	DBG_ASSERT( !(!bSelect && !bCheck),"" );//non is false
825 
826 	SvxPixelCtlAccessibleChild *pChild= NULL;
827 
828 	if (m_xCurChild.is())
829 	{
830 		pChild= static_cast<SvxPixelCtlAccessibleChild*>(m_xCurChild.get());
831 		DBG_ASSERT(pChild,"Child Must be Valid");
832 		if (pChild->getAccessibleIndexInParent() == nIndex )
833 		{
834 			if (bSelect)
835 			{
836 				pChild->SelectChild(sal_True);
837 			}
838 			if (bCheck)
839 			{
840 				pChild->ChangePixelColorOrBG(sal_Bool(pPixelCtl->GetBitmapPixel(sal_uInt16(nIndex))));
841 				pChild->CheckChild();
842 			}
843 			return ;
844 		}
845 	}
846 	uno::Reference <XAccessible> xNewChild =CreateChild(nIndex, pPixelCtl->IndexToPoint(nIndex));
847 	SvxPixelCtlAccessibleChild *pNewChild= static_cast<SvxPixelCtlAccessibleChild*>(xNewChild.get());
848 	DBG_ASSERT(pNewChild,"Child Must be Valid");
849 
850 	Any aNewValue,aOldValue;
851 	aNewValue<<= xNewChild;
852 	FireAccessibleEvent(	AccessibleEventId::ACTIVE_DESCENDANT_CHANGED,
853 							aOldValue,
854 							aNewValue );
855 
856 	if (bSelect)
857 	{
858 		if (pChild)
859 		{
860 			pChild->SelectChild(sal_False);
861 		}
862 		pNewChild->SelectChild(sal_True);
863 	}
864 	if (bCheck)
865 	{
866 		pNewChild->CheckChild();
867 	}
868 	m_xCurChild= xNewChild;
869 
870 
871 }
872 
CreateChild(long nIndex,Point mPoint)873 uno::Reference<XAccessible> SvxPixelCtlAccessible::CreateChild (long nIndex,Point mPoint)
874 {
875 	long nX = mPoint.X();
876 	long nY = mPoint.Y();
877 	if( Application::GetSettings().GetLayoutRTL())
878 	{
879 	    nX = (sal_uInt16) pPixelCtl->GetWidth() - 1 - nX;
880 	}
881 
882 	sal_Bool bPixelColorOrBG= sal_Bool(pPixelCtl->GetBitmapPixel(sal_uInt16(nIndex)));
883 	Size size(pPixelCtl->GetWidth() / pPixelCtl->GetLineCount(),pPixelCtl->GetHeight() / pPixelCtl->GetLineCount());
884 	uno::Reference<XAccessible> xChild;
885 	xChild = new SvxPixelCtlAccessibleChild(pPixelCtl,
886 				bPixelColorOrBG,
887 				Point(nX,nY),
888 				Rectangle(mPoint,size),
889 				this,
890 				nIndex);
891 
892 	return xChild;
893 }
894 
895 
LoseFocus()896 void SvxPixelCtlAccessible::LoseFocus()
897 {
898 	m_xCurChild = uno::Reference< XAccessible >() ;
899 }
900 
CheckChild()901 void SvxPixelCtlAccessibleChild::CheckChild()
902 {
903 	Any aChecked;
904 	aChecked <<= AccessibleStateType::CHECKED;
905 
906 	if (m_bPixelColorOrBG)//Current Child State
907 	{
908 		FireAccessibleEvent(	AccessibleEventId::STATE_CHANGED,
909 								Any(),
910 								aChecked);
911 	}
912 	else
913 	{
914 		FireAccessibleEvent(	AccessibleEventId::STATE_CHANGED,
915 								aChecked,
916 								Any() );
917 	}
918 }
919 
SelectChild(sal_Bool bSelect)920 void SvxPixelCtlAccessibleChild::SelectChild( sal_Bool bSelect)
921 {
922 	Any aSelected;
923 	aSelected <<= AccessibleStateType::SELECTED;
924 
925 	if (bSelect)
926 	{
927 		FireAccessibleEvent(	AccessibleEventId::STATE_CHANGED,
928 								Any(),
929 								aSelected);
930 	}
931 	else
932 	{
933 		FireAccessibleEvent(	AccessibleEventId::STATE_CHANGED,
934 								aSelected,
935 								Any());
936 	}
937 }
FireAccessibleEvent(short nEventId,const::com::sun::star::uno::Any & rOld,const::com::sun::star::uno::Any & rNew)938 void SvxPixelCtlAccessibleChild::FireAccessibleEvent (
939 	short nEventId,
940 	const ::com::sun::star::uno::Any& rOld,
941 	const ::com::sun::star::uno::Any& rNew)
942 {
943 	const uno::Reference< XInterface >	xSource( *this );
944 	CommitChange( AccessibleEventObject( xSource, nEventId, rNew,rOld ) );
945 }
946 
947 
948 
DBG_NAME(SvxPixelCtlAccessibleChild)949 DBG_NAME( SvxPixelCtlAccessibleChild )
950 
951 
952 SvxPixelCtlAccessibleChild::SvxPixelCtlAccessibleChild(
953 	SvxPixelCtl* rWindow,
954 	sal_Bool bPixelColorOrBG,
955 	const Point &aPoint,
956 	const Rectangle& rBoundingBox,
957 	const uno::Reference<XAccessible>&	rxParent,
958 	long nIndexInParent ) :
959 	SvxPixelCtlAccessibleChild_BASE( m_aMutex ),
960 	mrParentWindow( rWindow ),
961 	mxParent(rxParent),
962 	m_bPixelColorOrBG(bPixelColorOrBG),
963 	maPoint(aPoint),
964 	mpBoundingBox( new Rectangle( rBoundingBox ) ),
965 	mnIndexInParent( nIndexInParent ),
966 	mnClientId( 0 )
967 {
968 	DBG_CTOR( SvxPixelCtlAccessibleChild, NULL );
969 }
970 
971 
~SvxPixelCtlAccessibleChild()972 SvxPixelCtlAccessibleChild::~SvxPixelCtlAccessibleChild()
973 {
974 	DBG_DTOR( SvxPixelCtlAccessibleChild, NULL );
975 
976 	if( IsAlive() )
977 	{
978 		osl_incrementInterlockedCount( &m_refCount );
979 		dispose();		// set mpRepr = NULL & release all childs
980 	}
981 }
982 
983 //=====  XAccessible  =========================================================
984 
getAccessibleContext(void)985 uno::Reference< XAccessibleContext> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleContext( void ) throw( RuntimeException )
986 {
987 	return this;
988 }
989 
990 //=====  XAccessibleComponent  ================================================
991 
containsPoint(const awt::Point & rPoint)992 sal_Bool SAL_CALL SvxPixelCtlAccessibleChild::containsPoint( const awt::Point& rPoint ) throw( RuntimeException )
993 {
994 	// no guard -> done in getBounds()
995 //	return GetBoundingBox().IsInside( VCLPoint( rPoint ) );
996 	return Rectangle( Point( 0, 0 ), GetBoundingBox().GetSize() ).IsInside( VCLPoint( rPoint ) );
997 }
998 
getAccessibleAtPoint(const awt::Point &)999 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleAtPoint( const awt::Point& ) throw( RuntimeException )
1000 {
1001 	return uno::Reference< XAccessible >();
1002 }
1003 
getBounds()1004 awt::Rectangle SAL_CALL SvxPixelCtlAccessibleChild::getBounds() throw( RuntimeException )
1005 {
1006 	// no guard -> done in getBoundingBox()
1007 	//Modified by lq, 09/26
1008 	//return AWTRectangle( GetBoundingBox() );
1009 	awt::Rectangle rect = AWTRectangle( GetBoundingBox() );
1010 	rect.X = rect.X + mrParentWindow->GetClientWindowExtentsRelative(NULL).Left()-mrParentWindow->GetWindowExtentsRelative(NULL).Left();
1011 	rect.Y = rect.Y + mrParentWindow->GetClientWindowExtentsRelative(NULL).Top()-mrParentWindow->GetWindowExtentsRelative(NULL).Top();
1012 	return rect;
1013 	// End
1014 }
1015 
getLocation()1016 awt::Point SAL_CALL SvxPixelCtlAccessibleChild::getLocation() throw( RuntimeException )
1017 {
1018 	// no guard -> done in getBoundingBox()
1019 	return AWTPoint( GetBoundingBox().TopLeft() );
1020 }
1021 
getLocationOnScreen()1022 awt::Point SAL_CALL SvxPixelCtlAccessibleChild::getLocationOnScreen() throw( RuntimeException )
1023 {
1024 	// no guard -> done in getBoundingBoxOnScreen()
1025 	return AWTPoint( GetBoundingBoxOnScreen().TopLeft() );
1026 }
1027 
getSize()1028 awt::Size SAL_CALL SvxPixelCtlAccessibleChild::getSize() throw( RuntimeException )
1029 {
1030 	// no guard -> done in getBoundingBox()
1031 	return AWTSize( GetBoundingBox().GetSize() );
1032 }
1033 
grabFocus()1034 void SAL_CALL SvxPixelCtlAccessibleChild::grabFocus() throw( RuntimeException )
1035 {
1036 }
1037 
getForeground()1038 sal_Int32 SvxPixelCtlAccessibleChild::getForeground(  )
1039         throw (::com::sun::star::uno::RuntimeException)
1040 {
1041     //::vos::OGuard       aSolarGuard( Application::GetSolarMutex() );
1042     ::osl::MutexGuard   aGuard( m_aMutex );
1043     ThrowExceptionIfNotAlive();
1044     return mrParentWindow->GetControlForeground().GetColor();
1045 }
getBackground()1046 sal_Int32 SvxPixelCtlAccessibleChild::getBackground(  )
1047         throw (::com::sun::star::uno::RuntimeException)
1048 {
1049     //::vos::OGuard       aSolarGuard( Application::GetSolarMutex() );
1050     ::osl::MutexGuard   aGuard( m_aMutex );
1051 
1052     ThrowExceptionIfNotAlive();
1053     return mrParentWindow->GetControlBackground().GetColor();
1054 }
1055 
1056 //=====  XAccessibleContext  ==================================================
1057 
getAccessibleChildCount(void)1058 sal_Int32 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChildCount( void ) throw( RuntimeException )
1059 {
1060 	return 0;
1061 }
1062 
getAccessibleChild(sal_Int32)1063 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleChild( sal_Int32 ) throw ( RuntimeException )
1064 {
1065 	throw lang::IndexOutOfBoundsException();
1066 }
1067 
getAccessibleParent(void)1068 uno::Reference< XAccessible > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleParent( void ) throw( RuntimeException )
1069 {
1070 	return mxParent;
1071 }
1072 
getAccessibleIndexInParent(void)1073 sal_Int32 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleIndexInParent( void ) throw( RuntimeException )
1074 {
1075    return mnIndexInParent;
1076 }
1077 
getAccessibleRole(void)1078 sal_Int16 SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRole( void ) throw( RuntimeException )
1079 {
1080 	return AccessibleRole::CHECK_BOX;
1081 }
1082 
getAccessibleDescription(void)1083 OUString SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleDescription( void ) throw( RuntimeException )
1084 {
1085 	::osl::MutexGuard	aGuard( m_aMutex );
1086 
1087 	return  GetName();
1088 }
1089 
getAccessibleName(void)1090 OUString SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleName( void ) throw( RuntimeException )
1091 {
1092 	::osl::MutexGuard	aGuard( m_aMutex );
1093 	return  GetName();
1094 }
1095 
1096 /**	Return empty uno::Reference to indicate that the relation set is not
1097 	supported.
1098 */
getAccessibleRelationSet(void)1099 uno::Reference<XAccessibleRelationSet> SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleRelationSet( void ) throw( RuntimeException )
1100 {
1101 	return uno::Reference< XAccessibleRelationSet >();
1102 }
1103 
getAccessibleStateSet(void)1104 uno::Reference< XAccessibleStateSet > SAL_CALL SvxPixelCtlAccessibleChild::getAccessibleStateSet( void ) throw( RuntimeException )
1105 {
1106 	::osl::MutexGuard						aGuard( m_aMutex );
1107 	utl::AccessibleStateSetHelper*			pStateSetHelper = new utl::AccessibleStateSetHelper;
1108 
1109 	if( IsAlive() )
1110 	{
1111 
1112 		pStateSetHelper->AddState( AccessibleStateType::TRANSIENT );
1113 		pStateSetHelper->AddState( AccessibleStateType::ENABLED );
1114 		pStateSetHelper->AddState( AccessibleStateType::OPAQUE );
1115 		pStateSetHelper->AddState( AccessibleStateType::SELECTABLE );
1116 		pStateSetHelper->AddState( AccessibleStateType::SHOWING );
1117 		pStateSetHelper->AddState( AccessibleStateType::VISIBLE );
1118 
1119 		if (mrParentWindow )
1120 		{
1121 			long nIndex = mrParentWindow->GetFoucsPosIndex();
1122 			if ( nIndex == mnIndexInParent)
1123 			{
1124 				pStateSetHelper->AddState( AccessibleStateType::SELECTED );
1125 			}
1126 			if (mrParentWindow->GetBitmapPixel(sal_uInt16(mnIndexInParent)))
1127 			{
1128 				pStateSetHelper->AddState( AccessibleStateType::CHECKED );
1129 			}
1130 		}
1131 	}
1132 	else
1133 		pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
1134 
1135 	return pStateSetHelper;
1136 }
1137 
getLocale(void)1138 lang::Locale SAL_CALL SvxPixelCtlAccessibleChild::getLocale( void ) throw( IllegalAccessibleComponentStateException, RuntimeException )
1139 {
1140 	::osl::MutexGuard						aGuard( m_aMutex );
1141 	if( mxParent.is() )
1142     {
1143     	uno::Reference< XAccessibleContext >		xParentContext( mxParent->getAccessibleContext() );
1144         if( xParentContext.is() )
1145 	    	return xParentContext->getLocale();
1146     }
1147 
1148     //	No locale and no parent.  Therefore throw exception to indicate this
1149     //	cluelessness.
1150     throw IllegalAccessibleComponentStateException();
1151 }
1152 
addEventListener(const uno::Reference<XAccessibleEventListener> & xListener)1153 void SAL_CALL SvxPixelCtlAccessibleChild::addEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
1154     throw( RuntimeException )
1155 {
1156 	if (xListener.is())
1157     {
1158     	::osl::MutexGuard	aGuard( m_aMutex );
1159 		if (!mnClientId)
1160             mnClientId = comphelper::AccessibleEventNotifier::registerClient( );
1161 		comphelper::AccessibleEventNotifier::addEventListener( mnClientId, xListener );
1162     }
1163 }
1164 
1165 
1166 
1167 
removeEventListener(const uno::Reference<XAccessibleEventListener> & xListener)1168 void SAL_CALL SvxPixelCtlAccessibleChild::removeEventListener( const uno::Reference< XAccessibleEventListener >& xListener )
1169     throw( RuntimeException )
1170 {
1171 	if (xListener.is())
1172 	{
1173     	::osl::MutexGuard	aGuard( m_aMutex );
1174 
1175         sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( mnClientId, xListener );
1176 		if ( !nListenerCount )
1177 		{
1178 			// no listeners anymore
1179 			// -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
1180 			// and at least to us not firing any events anymore, in case somebody calls
1181 			// NotifyAccessibleEvent, again
1182 			comphelper::AccessibleEventNotifier::revokeClient( mnClientId );
1183 			mnClientId = 0;
1184 		}
1185 	}
1186 }
1187 
1188 
1189 //=====  XServiceInfo  ========================================================
1190 
getImplementationName(void)1191 OUString SAL_CALL SvxPixelCtlAccessibleChild::getImplementationName( void ) throw( RuntimeException )
1192 {
1193 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "SvxPixelCtlAccessibleChild" ) );
1194 }
1195 
supportsService(const OUString & rServiceName)1196 sal_Bool SAL_CALL SvxPixelCtlAccessibleChild::supportsService( const OUString& rServiceName ) throw( RuntimeException )
1197 {
1198     return  rServiceName.equalsAsciiL( sAccessible         , sizeof(sAccessible         )-1 ) ||
1199             rServiceName.equalsAsciiL( sAccessibleContext  , sizeof(sAccessibleContext  )-1 ) ||
1200             rServiceName.equalsAsciiL( sAccessibleComponent, sizeof(sAccessibleComponent)-1 );
1201 
1202 }
1203 
getSupportedServiceNames(void)1204 Sequence< OUString > SAL_CALL SvxPixelCtlAccessibleChild::getSupportedServiceNames( void ) throw( RuntimeException )
1205 {
1206     uno::Sequence< OUString > aRet(3);
1207 	OUString* pArray = aRet.getArray();
1208     pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessible         ) );
1209     pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleContext  ) );
1210     pArray[2] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleComponent) );
1211     return aRet;
1212 }
1213 
1214 //=====  internal  ============================================================
1215 
CommitChange(const AccessibleEventObject & rEvent)1216 void SvxPixelCtlAccessibleChild::CommitChange( const AccessibleEventObject& rEvent )
1217 {
1218 	if (mnClientId)
1219 		comphelper::AccessibleEventNotifier::addEvent( mnClientId, rEvent );
1220 }
1221 
disposing()1222 void SAL_CALL SvxPixelCtlAccessibleChild::disposing()
1223 {
1224 	if( !rBHelper.bDisposed )
1225 	{
1226 		::osl::MutexGuard	aGuard( m_aMutex );
1227 
1228         // Send a disposing to all listeners.
1229 	    if ( mnClientId )
1230 	    {
1231             comphelper::AccessibleEventNotifier::revokeClientNotifyDisposing( mnClientId, *this );
1232 		    mnClientId =  0;
1233 	    }
1234 
1235 		mxParent = uno::Reference< XAccessible >();
1236 
1237 	    delete mpBoundingBox;
1238 	}
1239 }
1240 
ThrowExceptionIfNotAlive(void)1241 void SvxPixelCtlAccessibleChild::ThrowExceptionIfNotAlive( void ) throw( lang::DisposedException )
1242 {
1243 	if( IsNotAlive() )
1244 		throw lang::DisposedException();
1245 }
1246 
GetBoundingBoxOnScreen(void)1247 Rectangle SvxPixelCtlAccessibleChild::GetBoundingBoxOnScreen( void ) throw( RuntimeException )
1248 {
1249 	::osl::MutexGuard	aGuard( m_aMutex );
1250 
1251 	// no ThrowExceptionIfNotAlive() because its done in GetBoundingBox()
1252 	Rectangle			aRect( GetBoundingBox() );
1253 
1254 	return Rectangle( mrParentWindow->OutputToAbsoluteScreenPixel( aRect.TopLeft() ), aRect.GetSize() );
1255 }
1256 
GetBoundingBox(void)1257 Rectangle SvxPixelCtlAccessibleChild::GetBoundingBox( void ) throw( RuntimeException )
1258 {
1259 	// no guard necessary, because no one changes mpBoundingBox after creating it
1260 	ThrowExceptionIfNotAlive();
1261 
1262 	return *mpBoundingBox;
1263 }
1264 
GetName()1265 ::rtl::OUString SvxPixelCtlAccessibleChild::GetName()
1266 {
1267 	sal_Int32 nXIndex = mnIndexInParent % mrParentWindow->GetLineCount();
1268 	sal_Int32 nYIndex = mnIndexInParent / mrParentWindow->GetLineCount();
1269 
1270 	OUString str;
1271 	str += OUString::createFromAscii("(");
1272 	str += OUString::valueOf(nXIndex);
1273 	str += OUString::createFromAscii(",");
1274 	str += OUString::valueOf(nYIndex);
1275 // 	str += OUString::createFromAscii(",");
1276 // 	str += OUString::valueOf(m_bPixelColorOrBG);
1277 	str += OUString::createFromAscii(")");
1278 	return str;
1279 }
1280