xref: /AOO41X/main/toolkit/source/awt/vclxaccessiblecomponent.cxx (revision ff7e158db68186b1942121d5f0855a9ab0df726e)
1b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b0724fc6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b0724fc6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b0724fc6SAndrew Rist  * distributed with this work for additional information
6b0724fc6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b0724fc6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b0724fc6SAndrew Rist  * "License"); you may not use this file except in compliance
9b0724fc6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11b0724fc6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13b0724fc6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b0724fc6SAndrew Rist  * software distributed under the License is distributed on an
15b0724fc6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b0724fc6SAndrew Rist  * KIND, either express or implied.  See the License for the
17b0724fc6SAndrew Rist  * specific language governing permissions and limitations
18b0724fc6SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20b0724fc6SAndrew Rist  *************************************************************/
21b0724fc6SAndrew Rist 
22b0724fc6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_toolkit.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
29cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
30cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
31cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleEventListener.hpp>
32cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRelationType.hpp>
33cdf0e10cSrcweir #include <toolkit/awt/vclxaccessiblecomponent.hxx>
34cdf0e10cSrcweir #include <toolkit/helper/externallock.hxx>
35cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
36cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
37cdf0e10cSrcweir #include <toolkit/awt/vclxfont.hxx>
38cdf0e10cSrcweir #include <vcl/dialog.hxx>
39cdf0e10cSrcweir #include <vcl/window.hxx>
40*ff7e158dSSteve Yin //IAccessibility2 Implementation 2009-----
41*ff7e158dSSteve Yin //Solution:Need methods in Edit.
42*ff7e158dSSteve Yin #include <vcl/edit.hxx>
43*ff7e158dSSteve Yin //-----IAccessibility2 Implementation 2009
44cdf0e10cSrcweir #include <tools/debug.hxx>
45cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
46cdf0e10cSrcweir #include <unotools/accessiblerelationsethelper.hxx>
47cdf0e10cSrcweir #include <vcl/svapp.hxx>
48cdf0e10cSrcweir #include <vcl/menu.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #ifndef VCLEVENT_WINDOW_FRAMETITLECHANGED
51cdf0e10cSrcweir #define VCLEVENT_WINDOW_FRAMETITLECHANGED   1018    // pData = XubString* = oldTitle
52cdf0e10cSrcweir #endif
53cdf0e10cSrcweir 
54cdf0e10cSrcweir using namespace ::com::sun::star;
55cdf0e10cSrcweir using namespace ::comphelper;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 
58cdf0e10cSrcweir DBG_NAME(VCLXAccessibleComponent)
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir //	----------------------------------------------------
62cdf0e10cSrcweir //	class VCLXAccessibleComponent
63cdf0e10cSrcweir //	----------------------------------------------------
64cdf0e10cSrcweir VCLXAccessibleComponent::VCLXAccessibleComponent( VCLXWindow* pVCLXindow )
65cdf0e10cSrcweir 	: AccessibleExtendedComponentHelper_BASE( new VCLExternalSolarLock() )
66cdf0e10cSrcweir 	, OAccessibleImplementationAccess( )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir 	DBG_CTOR( VCLXAccessibleComponent, 0 );
69cdf0e10cSrcweir 	mpVCLXindow = pVCLXindow;
70cdf0e10cSrcweir 	mxWindow = pVCLXindow;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	m_pSolarLock = static_cast< VCLExternalSolarLock* >( getExternalLock( ) );
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	DBG_ASSERT( pVCLXindow->GetWindow(), "VCLXAccessibleComponent - no window!" );
75cdf0e10cSrcweir 	if ( pVCLXindow->GetWindow() )
76cdf0e10cSrcweir     {
77cdf0e10cSrcweir 	  pVCLXindow->GetWindow()->AddEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) );
78cdf0e10cSrcweir 	  pVCLXindow->GetWindow()->AddChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) );
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	// announce the XAccessible of our creator to the base class
82cdf0e10cSrcweir 	lateInit( pVCLXindow );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir VCLXAccessibleComponent::~VCLXAccessibleComponent()
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	DBG_DTOR( VCLXAccessibleComponent, 0 );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     ensureDisposed();
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	if ( mpVCLXindow && mpVCLXindow->GetWindow() )
92cdf0e10cSrcweir     {
93cdf0e10cSrcweir 		mpVCLXindow->GetWindow()->RemoveEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) );
94cdf0e10cSrcweir 		mpVCLXindow->GetWindow()->RemoveChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) );
95cdf0e10cSrcweir     }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	delete m_pSolarLock;
98cdf0e10cSrcweir 	m_pSolarLock = NULL;
99cdf0e10cSrcweir 	// This is not completely safe. If we assume that the base class dtor calls some method which
100cdf0e10cSrcweir 	// uses this lock, the we crash. However, as the base class' dtor does not have a chance to call _out_
101cdf0e10cSrcweir 	// virtual methods, this is no problem as long as the base class is safe, i.e. does not use the external
102cdf0e10cSrcweir 	// lock from within it's dtor. At the moment, we _know_ the base class is safe in this respect, so
103cdf0e10cSrcweir 	// let's assume it keeps this way.
104cdf0e10cSrcweir 	// @see OAccessibleContextHelper::OAccessibleContextHelper( IMutex* )
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE3( VCLXAccessibleComponent, AccessibleExtendedComponentHelper_BASE, OAccessibleImplementationAccess, VCLXAccessibleComponent_BASE )
108cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER3( VCLXAccessibleComponent, AccessibleExtendedComponentHelper_BASE, OAccessibleImplementationAccess, VCLXAccessibleComponent_BASE )
109cdf0e10cSrcweir 
110cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleComponent::getImplementationName() throw (uno::RuntimeException)
111cdf0e10cSrcweir {
112cdf0e10cSrcweir 	return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleWindow" );
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir sal_Bool VCLXAccessibleComponent::supportsService( const ::rtl::OUString& rServiceName ) throw (uno::RuntimeException)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
118cdf0e10cSrcweir 	const ::rtl::OUString* pNames = aNames.getConstArray();
119cdf0e10cSrcweir 	const ::rtl::OUString* pEnd = pNames + aNames.getLength();
120cdf0e10cSrcweir 	for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
121cdf0e10cSrcweir 		;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	return pNames != pEnd;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > VCLXAccessibleComponent::getSupportedServiceNames() throw (uno::RuntimeException)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aNames(1);
129cdf0e10cSrcweir 	aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleWindow" );
130cdf0e10cSrcweir 	return aNames;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir IMPL_LINK( VCLXAccessibleComponent, WindowEventListener, VclSimpleEvent*, pEvent )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir 	DBG_CHKTHIS(VCLXAccessibleComponent,0);
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	DBG_ASSERT( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         /* Ignore VCLEVENT_WINDOW_ENDPOPUPMODE, because the UNO accessibility wrapper
140cdf0e10cSrcweir          * might have been destroyed by the previous VCLEventListener (if no AT tool
141cdf0e10cSrcweir          * is running), e.g. sub-toolbars in impress.
142cdf0e10cSrcweir          */
143cdf0e10cSrcweir 	if ( pEvent && pEvent->ISA( VclWindowEvent ) && mxWindow.is() /* #122218# */ && (pEvent->GetId() != VCLEVENT_WINDOW_ENDPOPUPMODE) )
144cdf0e10cSrcweir 	{
145cdf0e10cSrcweir 		DBG_ASSERT( ((VclWindowEvent*)pEvent)->GetWindow(), "Window???" );
146cdf0e10cSrcweir         if( !((VclWindowEvent*)pEvent)->GetWindow()->IsAccessibilityEventsSuppressed() || ( pEvent->GetId() == VCLEVENT_OBJECT_DYING ) )
147cdf0e10cSrcweir 		{
148cdf0e10cSrcweir 		    ProcessWindowEvent( *(VclWindowEvent*)pEvent );
149cdf0e10cSrcweir 		}
150cdf0e10cSrcweir 	}
151cdf0e10cSrcweir 	return 0;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir IMPL_LINK( VCLXAccessibleComponent, WindowChildEventListener, VclSimpleEvent*, pEvent )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir 	DBG_CHKTHIS(VCLXAccessibleComponent,0);
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     DBG_ASSERT( pEvent && pEvent->ISA( VclWindowEvent ), "Unknown WindowEvent!" );
159cdf0e10cSrcweir 	if ( pEvent && pEvent->ISA( VclWindowEvent ) && mxWindow.is() /* #i68079# */ )
160cdf0e10cSrcweir 	{
161cdf0e10cSrcweir 		DBG_ASSERT( ((VclWindowEvent*)pEvent)->GetWindow(), "Window???" );
162cdf0e10cSrcweir         if( !((VclWindowEvent*)pEvent)->GetWindow()->IsAccessibilityEventsSuppressed() )
163cdf0e10cSrcweir 		{
164cdf0e10cSrcweir 			// #103087# to prevent an early release of the component
165cdf0e10cSrcweir 			uno::Reference< accessibility::XAccessibleContext > xTmp = this;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 		    ProcessWindowChildEvent( *(VclWindowEvent*)pEvent );
168cdf0e10cSrcweir 		}
169cdf0e10cSrcweir 	}
170cdf0e10cSrcweir 	return 0;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir 
173cdf0e10cSrcweir uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::GetChildAccessible( const VclWindowEvent& rVclWindowEvent )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir     // checks if the data in the window event is our direct child
176cdf0e10cSrcweir     // and returns its accessible
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     // MT: Change this later, normaly a show/hide event shouldn't have the Window* in pData.
179cdf0e10cSrcweir     Window* pChildWindow = (Window *) rVclWindowEvent.GetData();
180cdf0e10cSrcweir     if( pChildWindow && GetWindow() == pChildWindow->GetAccessibleParentWindow() )
181cdf0e10cSrcweir         return pChildWindow->GetAccessible( rVclWindowEvent.GetId() == VCLEVENT_WINDOW_SHOW );
182cdf0e10cSrcweir     else
183cdf0e10cSrcweir         return uno::Reference< accessibility::XAccessible > ();
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir void VCLXAccessibleComponent::ProcessWindowChildEvent( const VclWindowEvent& rVclWindowEvent )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir 	uno::Any aOldValue, aNewValue;
189cdf0e10cSrcweir     uno::Reference< accessibility::XAccessible > xAcc;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 	switch ( rVclWindowEvent.GetId() )
192cdf0e10cSrcweir 	{
193cdf0e10cSrcweir         case VCLEVENT_WINDOW_SHOW:  // send create on show for direct accessible children
194cdf0e10cSrcweir         {
195cdf0e10cSrcweir             xAcc = GetChildAccessible( rVclWindowEvent );
196cdf0e10cSrcweir             if( xAcc.is() )
197cdf0e10cSrcweir             {
198cdf0e10cSrcweir                 aNewValue <<= xAcc;
199cdf0e10cSrcweir                 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
200cdf0e10cSrcweir             }
201cdf0e10cSrcweir         }
202cdf0e10cSrcweir         break;
203cdf0e10cSrcweir         case VCLEVENT_WINDOW_HIDE:  // send destroy on hide for direct accessible children
204cdf0e10cSrcweir         {
205cdf0e10cSrcweir             xAcc = GetChildAccessible( rVclWindowEvent );
206cdf0e10cSrcweir             if( xAcc.is() )
207cdf0e10cSrcweir             {
208cdf0e10cSrcweir                 aOldValue <<= xAcc;
209cdf0e10cSrcweir                 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
210cdf0e10cSrcweir             }
211cdf0e10cSrcweir         }
212cdf0e10cSrcweir         break;
213cdf0e10cSrcweir 	}
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir void VCLXAccessibleComponent::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir 	uno::Any aOldValue, aNewValue;
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 	Window* pAccWindow = rVclWindowEvent.GetWindow();
221cdf0e10cSrcweir 	DBG_ASSERT( pAccWindow, "VCLXAccessibleComponent::ProcessWindowEvent - Window?" );
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 	switch ( rVclWindowEvent.GetId() )
224cdf0e10cSrcweir 	{
225cdf0e10cSrcweir         case VCLEVENT_OBJECT_DYING:
226cdf0e10cSrcweir         {
227cdf0e10cSrcweir 		    pAccWindow->RemoveEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) );
228cdf0e10cSrcweir 		    pAccWindow->RemoveChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) );
229cdf0e10cSrcweir 	        mxWindow.clear();
230cdf0e10cSrcweir 	        mpVCLXindow = NULL;
231cdf0e10cSrcweir         }
232cdf0e10cSrcweir         break;
233cdf0e10cSrcweir         //
234cdf0e10cSrcweir         // dont handle CHILDCREATED events here
235cdf0e10cSrcweir         // they are handled separately as child events, see ProcessWindowChildEvent above
236cdf0e10cSrcweir         //
237cdf0e10cSrcweir         /*
238cdf0e10cSrcweir         case VCLEVENT_WINDOW_CHILDCREATED:
239cdf0e10cSrcweir         {
240cdf0e10cSrcweir             Window* pWindow = (Window*) rVclWindowEvent.GetData();
241cdf0e10cSrcweir             DBG_ASSERT( pWindow, "VCLEVENT_WINDOW_CHILDCREATED - Window=?" );
242cdf0e10cSrcweir             aNewValue <<= pWindow->GetAccessible();
243cdf0e10cSrcweir             NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
244cdf0e10cSrcweir         }
245cdf0e10cSrcweir         break;
246cdf0e10cSrcweir         */
247cdf0e10cSrcweir         case VCLEVENT_WINDOW_CHILDDESTROYED:
248cdf0e10cSrcweir         {
249cdf0e10cSrcweir             Window* pWindow = (Window*) rVclWindowEvent.GetData();
250cdf0e10cSrcweir             DBG_ASSERT( pWindow, "VCLEVENT_WINDOW_CHILDDESTROYED - Window=?" );
251cdf0e10cSrcweir             if ( pWindow->GetAccessible( sal_False ).is() )
252cdf0e10cSrcweir             {
253cdf0e10cSrcweir                 aOldValue <<= pWindow->GetAccessible( sal_False );
254cdf0e10cSrcweir                 NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
255cdf0e10cSrcweir             }
256cdf0e10cSrcweir         }
257cdf0e10cSrcweir         break;
258cdf0e10cSrcweir 
259cdf0e10cSrcweir         //
260cdf0e10cSrcweir         // show and hide will be handled as child events only and are
261cdf0e10cSrcweir         // responsible for sending create/destroy events, see ProcessWindowChildEvent above
262cdf0e10cSrcweir         //
263cdf0e10cSrcweir         /*
264cdf0e10cSrcweir 		case VCLEVENT_WINDOW_SHOW:
265cdf0e10cSrcweir 		{
266cdf0e10cSrcweir 			aNewValue <<= accessibility::AccessibleStateType::VISIBLE;
267cdf0e10cSrcweir 			NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 			aNewValue <<= accessibility::AccessibleStateType::SHOWING;
270cdf0e10cSrcweir 			NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 			aNewValue.clear();
273cdf0e10cSrcweir 			aOldValue <<= accessibility::AccessibleStateType::INVALID;
274cdf0e10cSrcweir 			NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
275cdf0e10cSrcweir 		}
276cdf0e10cSrcweir 		break;
277cdf0e10cSrcweir 		case VCLEVENT_WINDOW_HIDE:
278cdf0e10cSrcweir 		{
279cdf0e10cSrcweir 			aOldValue <<= accessibility::AccessibleStateType::VISIBLE;
280cdf0e10cSrcweir 			NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 			aOldValue <<= accessibility::AccessibleStateType::SHOWING;
283cdf0e10cSrcweir 			NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
284cdf0e10cSrcweir 
285cdf0e10cSrcweir 			aOldValue.clear();
286cdf0e10cSrcweir 			aNewValue <<= accessibility::AccessibleStateType::INVALID;
287cdf0e10cSrcweir 			NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
288cdf0e10cSrcweir 		}
289cdf0e10cSrcweir 		break;
290cdf0e10cSrcweir         */
291cdf0e10cSrcweir 		case VCLEVENT_WINDOW_ACTIVATE:
292cdf0e10cSrcweir 		{
293cdf0e10cSrcweir             // avoid notification if a child frame is already active
294cdf0e10cSrcweir             // only one frame may be active at a given time
295cdf0e10cSrcweir             if ( !pAccWindow->HasActiveChildFrame() &&
296cdf0e10cSrcweir                  ( getAccessibleRole() == accessibility::AccessibleRole::FRAME ||
297cdf0e10cSrcweir                    getAccessibleRole() == accessibility::AccessibleRole::ALERT ||
298cdf0e10cSrcweir                    getAccessibleRole() == accessibility::AccessibleRole::DIALOG ) )  // #i18891#
299cdf0e10cSrcweir             {
300cdf0e10cSrcweir 			    aNewValue <<= accessibility::AccessibleStateType::ACTIVE;
301cdf0e10cSrcweir 			    NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
302cdf0e10cSrcweir             }
303cdf0e10cSrcweir 		}
304cdf0e10cSrcweir 		break;
305cdf0e10cSrcweir 		case VCLEVENT_WINDOW_DEACTIVATE:
306cdf0e10cSrcweir 		{
307cdf0e10cSrcweir             if ( getAccessibleRole() == accessibility::AccessibleRole::FRAME ||
308cdf0e10cSrcweir                  getAccessibleRole() == accessibility::AccessibleRole::ALERT ||
309cdf0e10cSrcweir                  getAccessibleRole() == accessibility::AccessibleRole::DIALOG )  // #i18891#
310cdf0e10cSrcweir             {
311cdf0e10cSrcweir                 aOldValue <<= accessibility::AccessibleStateType::ACTIVE;
312cdf0e10cSrcweir                 NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
313cdf0e10cSrcweir             }
314cdf0e10cSrcweir 		}
315cdf0e10cSrcweir 		break;
316cdf0e10cSrcweir 		case VCLEVENT_WINDOW_GETFOCUS:
317cdf0e10cSrcweir 		case VCLEVENT_CONTROL_GETFOCUS:
318cdf0e10cSrcweir 		{
319cdf0e10cSrcweir             if( (pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_CONTROL_GETFOCUS) ||
320cdf0e10cSrcweir                 (!pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_WINDOW_GETFOCUS) )
321cdf0e10cSrcweir             {
322cdf0e10cSrcweir                 // if multiple listeners were registered it is possible that the
323cdf0e10cSrcweir                 // focus was changed during event processing (eg SfxTopWindow )
324cdf0e10cSrcweir                 // #106082# allow ChildPathFocus only for CompoundControls, for windows the focus must be in the window itself
325cdf0e10cSrcweir                 if( (pAccWindow->IsCompoundControl() && pAccWindow->HasChildPathFocus()) ||
326cdf0e10cSrcweir                     (!pAccWindow->IsCompoundControl() && pAccWindow->HasFocus()) )
327cdf0e10cSrcweir                 {
328cdf0e10cSrcweir 			        aNewValue <<= accessibility::AccessibleStateType::FOCUSED;
329cdf0e10cSrcweir 			        NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
330cdf0e10cSrcweir                 }
331cdf0e10cSrcweir             }
332cdf0e10cSrcweir 		}
333cdf0e10cSrcweir 		break;
334cdf0e10cSrcweir 		case VCLEVENT_WINDOW_LOSEFOCUS:
335cdf0e10cSrcweir 		case VCLEVENT_CONTROL_LOSEFOCUS:
336cdf0e10cSrcweir 		{
337cdf0e10cSrcweir             if( (pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_CONTROL_LOSEFOCUS) ||
338cdf0e10cSrcweir                 (!pAccWindow->IsCompoundControl() && rVclWindowEvent.GetId() == VCLEVENT_WINDOW_LOSEFOCUS) )
339cdf0e10cSrcweir             {
340cdf0e10cSrcweir 			    aOldValue <<= accessibility::AccessibleStateType::FOCUSED;
341cdf0e10cSrcweir 			    NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
342cdf0e10cSrcweir             }
343cdf0e10cSrcweir 		}
344cdf0e10cSrcweir 		break;
345cdf0e10cSrcweir         case VCLEVENT_WINDOW_FRAMETITLECHANGED:
346cdf0e10cSrcweir         {
347cdf0e10cSrcweir             ::rtl::OUString aOldName( *((::rtl::OUString*) rVclWindowEvent.GetData()) );
348cdf0e10cSrcweir             ::rtl::OUString aNewName( getAccessibleName() );
349cdf0e10cSrcweir 			aOldValue <<= aOldName;
350cdf0e10cSrcweir             aNewValue <<= aNewName;
351cdf0e10cSrcweir 			NotifyAccessibleEvent( accessibility::AccessibleEventId::NAME_CHANGED, aOldValue, aNewValue );
352cdf0e10cSrcweir         }
353cdf0e10cSrcweir         break;
354cdf0e10cSrcweir 		case VCLEVENT_WINDOW_ENABLED:
355cdf0e10cSrcweir 		{
356cdf0e10cSrcweir 			aNewValue <<= accessibility::AccessibleStateType::ENABLED;
357cdf0e10cSrcweir 			NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
358cdf0e10cSrcweir             aNewValue <<= accessibility::AccessibleStateType::SENSITIVE;
359cdf0e10cSrcweir             NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
360cdf0e10cSrcweir 		}
361cdf0e10cSrcweir 		break;
362cdf0e10cSrcweir 		case VCLEVENT_WINDOW_DISABLED:
363cdf0e10cSrcweir 		{
364cdf0e10cSrcweir             aOldValue <<= accessibility::AccessibleStateType::SENSITIVE;
365cdf0e10cSrcweir 			NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
366cdf0e10cSrcweir 
367cdf0e10cSrcweir             aOldValue <<= accessibility::AccessibleStateType::ENABLED;
368cdf0e10cSrcweir             NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
369cdf0e10cSrcweir 		}
370cdf0e10cSrcweir 		break;
371cdf0e10cSrcweir 		case VCLEVENT_WINDOW_MOVE:
372cdf0e10cSrcweir 		case VCLEVENT_WINDOW_RESIZE:
373cdf0e10cSrcweir 		{
374cdf0e10cSrcweir 			NotifyAccessibleEvent( accessibility::AccessibleEventId::BOUNDRECT_CHANGED, aOldValue, aNewValue );
375cdf0e10cSrcweir 		}
376cdf0e10cSrcweir 		break;
377cdf0e10cSrcweir 		case VCLEVENT_WINDOW_MENUBARADDED:
378cdf0e10cSrcweir 		{
379cdf0e10cSrcweir             MenuBar* pMenuBar = (MenuBar*) rVclWindowEvent.GetData();
380cdf0e10cSrcweir 			if ( pMenuBar )
381cdf0e10cSrcweir 			{
382cdf0e10cSrcweir 				uno::Reference< accessibility::XAccessible > xChild( pMenuBar->GetAccessible() );
383cdf0e10cSrcweir 				if ( xChild.is() )
384cdf0e10cSrcweir 				{
385cdf0e10cSrcweir 					aNewValue <<= xChild;
386cdf0e10cSrcweir 					NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
387cdf0e10cSrcweir 				}
388cdf0e10cSrcweir 			}
389cdf0e10cSrcweir 		}
390cdf0e10cSrcweir 		break;
391cdf0e10cSrcweir 		case VCLEVENT_WINDOW_MENUBARREMOVED:
392cdf0e10cSrcweir 		{
393cdf0e10cSrcweir             MenuBar* pMenuBar = (MenuBar*) rVclWindowEvent.GetData();
394cdf0e10cSrcweir 			if ( pMenuBar )
395cdf0e10cSrcweir 			{
396cdf0e10cSrcweir 				uno::Reference< accessibility::XAccessible > xChild( pMenuBar->GetAccessible() );
397cdf0e10cSrcweir 				if ( xChild.is() )
398cdf0e10cSrcweir 				{
399cdf0e10cSrcweir 					aOldValue <<= xChild;
400cdf0e10cSrcweir 					NotifyAccessibleEvent( accessibility::AccessibleEventId::CHILD, aOldValue, aNewValue );
401cdf0e10cSrcweir 				}
402cdf0e10cSrcweir 			}
403cdf0e10cSrcweir 		}
404cdf0e10cSrcweir 		break;
405cdf0e10cSrcweir 		case VCLEVENT_WINDOW_MINIMIZE:
406cdf0e10cSrcweir 		{
407cdf0e10cSrcweir 			aNewValue <<= accessibility::AccessibleStateType::ICONIFIED;
408cdf0e10cSrcweir 			NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
409cdf0e10cSrcweir 		}
410cdf0e10cSrcweir 		break;
411cdf0e10cSrcweir 		case VCLEVENT_WINDOW_NORMALIZE:
412cdf0e10cSrcweir 		{
413cdf0e10cSrcweir 			aOldValue <<= accessibility::AccessibleStateType::ICONIFIED;
414cdf0e10cSrcweir 			NotifyAccessibleEvent( accessibility::AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
415cdf0e10cSrcweir 		}
416cdf0e10cSrcweir 		break;
417cdf0e10cSrcweir 		default:
418cdf0e10cSrcweir 		{
419cdf0e10cSrcweir 		}
420cdf0e10cSrcweir 		break;
421cdf0e10cSrcweir 	}
422cdf0e10cSrcweir }
423cdf0e10cSrcweir 
424cdf0e10cSrcweir void VCLXAccessibleComponent::disposing()
425cdf0e10cSrcweir {
426cdf0e10cSrcweir 	if ( mpVCLXindow && mpVCLXindow->GetWindow() )
427cdf0e10cSrcweir     {
428cdf0e10cSrcweir 		mpVCLXindow->GetWindow()->RemoveEventListener( LINK( this, VCLXAccessibleComponent, WindowEventListener ) );
429cdf0e10cSrcweir 		mpVCLXindow->GetWindow()->RemoveChildEventListener( LINK( this, VCLXAccessibleComponent, WindowChildEventListener ) );
430cdf0e10cSrcweir     }
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 	AccessibleExtendedComponentHelper_BASE::disposing();
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 	mxWindow.clear();
435cdf0e10cSrcweir 	mpVCLXindow = NULL;
436cdf0e10cSrcweir }
437cdf0e10cSrcweir 
438cdf0e10cSrcweir Window* VCLXAccessibleComponent::GetWindow() const
439cdf0e10cSrcweir {
440cdf0e10cSrcweir 	return GetVCLXWindow() ? GetVCLXWindow()->GetWindow() : NULL;
441cdf0e10cSrcweir }
442cdf0e10cSrcweir 
443cdf0e10cSrcweir void VCLXAccessibleComponent::FillAccessibleRelationSet( utl::AccessibleRelationSetHelper& rRelationSet )
444cdf0e10cSrcweir {
445cdf0e10cSrcweir 	Window* pWindow = GetWindow();
446cdf0e10cSrcweir 	if ( pWindow )
447cdf0e10cSrcweir 	{
448*ff7e158dSSteve Yin //IAccessibility2 Implementation 2009-----
449cdf0e10cSrcweir 		Window *pLabeledBy = pWindow->GetAccessibleRelationLabeledBy();
450*ff7e158dSSteve Yin //-----IAccessibility2 Implementation 2009
451cdf0e10cSrcweir 		if ( pLabeledBy && pLabeledBy != pWindow )
452cdf0e10cSrcweir 		{
453cdf0e10cSrcweir 			uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
454cdf0e10cSrcweir 			aSequence[0] = pLabeledBy->GetAccessible();
455cdf0e10cSrcweir 			rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::LABELED_BY, aSequence ) );
456cdf0e10cSrcweir 		}
457cdf0e10cSrcweir 
458cdf0e10cSrcweir 		Window* pLabelFor = pWindow->GetAccessibleRelationLabelFor();
459cdf0e10cSrcweir 		if ( pLabelFor && pLabelFor != pWindow )
460cdf0e10cSrcweir 		{
461cdf0e10cSrcweir 			uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
462cdf0e10cSrcweir 			aSequence[0] = pLabelFor->GetAccessible();
463cdf0e10cSrcweir 			rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::LABEL_FOR, aSequence ) );
464cdf0e10cSrcweir 		}
465*ff7e158dSSteve Yin //IAccessibility2 Implementation 2009-----
466*ff7e158dSSteve Yin 		Window* pMemberOf = pWindow->GetAccessibleRelationMemberOf();
467*ff7e158dSSteve Yin 		if ( pMemberOf && pMemberOf != pWindow )
468*ff7e158dSSteve Yin 		{
469*ff7e158dSSteve Yin 			uno::Sequence< uno::Reference< uno::XInterface > > aSequence(1);
470*ff7e158dSSteve Yin 			aSequence[0] = pMemberOf->GetAccessible();
471*ff7e158dSSteve Yin 			rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::MEMBER_OF, aSequence ) );
472*ff7e158dSSteve Yin 		}
473*ff7e158dSSteve Yin 		uno::Sequence< uno::Reference< uno::XInterface > > aFlowToSequence = pWindow->GetAccFlowToSequence();
474*ff7e158dSSteve Yin 		if( aFlowToSequence.getLength() > 0 )
475*ff7e158dSSteve Yin 		{
476*ff7e158dSSteve Yin 			rRelationSet.AddRelation( accessibility::AccessibleRelation( accessibility::AccessibleRelationType::CONTENT_FLOWS_TO, aFlowToSequence ) );
477*ff7e158dSSteve Yin 		}
478*ff7e158dSSteve Yin //-----IAccessibility2 Implementation 2009
479cdf0e10cSrcweir 	}
480cdf0e10cSrcweir }
481cdf0e10cSrcweir 
482cdf0e10cSrcweir void VCLXAccessibleComponent::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
483cdf0e10cSrcweir {
484cdf0e10cSrcweir 	Window* pWindow = GetWindow();
485cdf0e10cSrcweir 	if ( pWindow )
486cdf0e10cSrcweir 	{
487cdf0e10cSrcweir 		if ( pWindow->IsVisible() )
488cdf0e10cSrcweir 		{
489cdf0e10cSrcweir 			rStateSet.AddState( accessibility::AccessibleStateType::VISIBLE );
490cdf0e10cSrcweir 			rStateSet.AddState( accessibility::AccessibleStateType::SHOWING );
491cdf0e10cSrcweir 		}
492cdf0e10cSrcweir 		else
493cdf0e10cSrcweir 		{
494cdf0e10cSrcweir 			rStateSet.AddState( accessibility::AccessibleStateType::INVALID );
495cdf0e10cSrcweir 		}
496cdf0e10cSrcweir 
497cdf0e10cSrcweir 		if ( pWindow->IsEnabled() )
498cdf0e10cSrcweir         {
499cdf0e10cSrcweir 			rStateSet.AddState( accessibility::AccessibleStateType::ENABLED );
500cdf0e10cSrcweir             rStateSet.AddState( accessibility::AccessibleStateType::SENSITIVE );
501cdf0e10cSrcweir         }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir         if ( pWindow->HasChildPathFocus() &&
504cdf0e10cSrcweir              ( getAccessibleRole() == accessibility::AccessibleRole::FRAME ||
505cdf0e10cSrcweir                getAccessibleRole() == accessibility::AccessibleRole::ALERT ||
506cdf0e10cSrcweir                getAccessibleRole() == accessibility::AccessibleRole::DIALOG ) )  // #i18891#
507cdf0e10cSrcweir 			rStateSet.AddState( accessibility::AccessibleStateType::ACTIVE );
508cdf0e10cSrcweir 
509cdf0e10cSrcweir         // #104290# MT: This way, a ComboBox doesn't get state FOCUSED.
510cdf0e10cSrcweir         // I also don't understand
511cdf0e10cSrcweir         // a) why WINDOW_FIRSTCHILD is used here (which btw is a border window in the case of a combo box)
512cdf0e10cSrcweir         // b) why HasFocus() is nout "enough" for a compound control
513cdf0e10cSrcweir         /*
514cdf0e10cSrcweir 		Window* pChild = pWindow->GetWindow( WINDOW_FIRSTCHILD );
515cdf0e10cSrcweir 		if ( ( !pWindow->IsCompoundControl() && pWindow->HasFocus() ) ||
516cdf0e10cSrcweir 		     ( pWindow->IsCompoundControl() && pChild && pChild->HasFocus() ) )
517cdf0e10cSrcweir 			rStateSet.AddState( accessibility::AccessibleStateType::FOCUSED );
518cdf0e10cSrcweir 	    */
519cdf0e10cSrcweir 		if ( pWindow->HasFocus() || ( pWindow->IsCompoundControl() && pWindow->HasChildPathFocus() ) )
520cdf0e10cSrcweir 			rStateSet.AddState( accessibility::AccessibleStateType::FOCUSED );
521cdf0e10cSrcweir 
522cdf0e10cSrcweir 		if ( pWindow->IsWait() )
523cdf0e10cSrcweir 			rStateSet.AddState( accessibility::AccessibleStateType::BUSY );
524cdf0e10cSrcweir 
525cdf0e10cSrcweir 		if ( pWindow->GetStyle() & WB_SIZEABLE )
526cdf0e10cSrcweir 			rStateSet.AddState( accessibility::AccessibleStateType::RESIZABLE );
527*ff7e158dSSteve Yin //IAccessibility2 Implementation 2009-----
528*ff7e158dSSteve Yin 		// 6. frame doesn't have MOVABLE state
529*ff7e158dSSteve Yin 		// 10. for password text, where is the sensitive state?
530*ff7e158dSSteve Yin 		if( ( getAccessibleRole() == accessibility::AccessibleRole::FRAME ||getAccessibleRole() == accessibility::AccessibleRole::DIALOG )&& pWindow->GetStyle() & WB_MOVEABLE )
531*ff7e158dSSteve Yin 			rStateSet.AddState( accessibility::AccessibleStateType::MOVEABLE );
532*ff7e158dSSteve Yin //-----IAccessibility2 Implementation 2009
533cdf0e10cSrcweir         if( pWindow->IsDialog() )
534cdf0e10cSrcweir         {
535cdf0e10cSrcweir             Dialog *pDlg = static_cast< Dialog* >( pWindow );
536cdf0e10cSrcweir             if( pDlg->IsInExecute() )
537cdf0e10cSrcweir 			    rStateSet.AddState( accessibility::AccessibleStateType::MODAL );
538cdf0e10cSrcweir         }
539*ff7e158dSSteve Yin //IAccessibility2 Implementation 2009-----
540*ff7e158dSSteve Yin         //Solution:If a combobox or list's edit child isn't read-only,EDITABLE state
541*ff7e158dSSteve Yin         //         should be set.
542*ff7e158dSSteve Yin 		if( pWindow && pWindow->GetType() == WINDOW_COMBOBOX )
543*ff7e158dSSteve Yin 		{
544*ff7e158dSSteve Yin 			if( !( pWindow->GetStyle() & WB_READONLY) ||
545*ff7e158dSSteve Yin 			    !((Edit*)pWindow)->IsReadOnly() )
546*ff7e158dSSteve Yin 					rStateSet.AddState( accessibility::AccessibleStateType::EDITABLE );
547*ff7e158dSSteve Yin 		}
548*ff7e158dSSteve Yin 
549*ff7e158dSSteve Yin 		Window* pChild = pWindow->GetWindow( WINDOW_FIRSTCHILD );
550*ff7e158dSSteve Yin 
551*ff7e158dSSteve Yin 		while( pWindow && pChild )
552*ff7e158dSSteve Yin 		{
553*ff7e158dSSteve Yin 			Window* pWinTemp = pChild->GetWindow( WINDOW_FIRSTCHILD );
554*ff7e158dSSteve Yin 			if( pWinTemp && pWinTemp->GetType() == WINDOW_EDIT )
555*ff7e158dSSteve Yin 			{
556*ff7e158dSSteve Yin 				if( !( pWinTemp->GetStyle() & WB_READONLY) ||
557*ff7e158dSSteve Yin 					!((Edit*)pWinTemp)->IsReadOnly() )
558*ff7e158dSSteve Yin 					rStateSet.AddState( accessibility::AccessibleStateType::EDITABLE );
559*ff7e158dSSteve Yin 				break;
560*ff7e158dSSteve Yin 			}
561*ff7e158dSSteve Yin 			if( pChild->GetType() == WINDOW_EDIT )
562*ff7e158dSSteve Yin 			{
563*ff7e158dSSteve Yin 				if( !( pChild->GetStyle() & WB_READONLY) ||
564*ff7e158dSSteve Yin 					!((Edit*)pChild)->IsReadOnly())
565*ff7e158dSSteve Yin 					rStateSet.AddState( accessibility::AccessibleStateType::EDITABLE );
566*ff7e158dSSteve Yin 				break;
567*ff7e158dSSteve Yin 			}
568*ff7e158dSSteve Yin 			pChild = pChild->GetWindow( WINDOW_NEXT );
569*ff7e158dSSteve Yin 		}
570*ff7e158dSSteve Yin //-----IAccessibility2 Implementation 2009
571cdf0e10cSrcweir 	}
572cdf0e10cSrcweir 	else
573cdf0e10cSrcweir 	{
574cdf0e10cSrcweir 		rStateSet.AddState( accessibility::AccessibleStateType::DEFUNC );
575cdf0e10cSrcweir 	}
576cdf0e10cSrcweir 
577cdf0e10cSrcweir /*
578cdf0e10cSrcweir 
579cdf0e10cSrcweir MUST BE SET FROM DERIVED CLASSES:
580cdf0e10cSrcweir 
581cdf0e10cSrcweir CHECKED
582cdf0e10cSrcweir COLLAPSED
583cdf0e10cSrcweir EXPANDED
584cdf0e10cSrcweir EXPANDABLE
585cdf0e10cSrcweir EDITABLE
586cdf0e10cSrcweir FOCUSABLE
587cdf0e10cSrcweir HORIZONTAL
588cdf0e10cSrcweir VERTICAL
589cdf0e10cSrcweir ICONIFIED
590cdf0e10cSrcweir MULTILINE
591cdf0e10cSrcweir MULTI_SELECTABLE
592cdf0e10cSrcweir PRESSED
593cdf0e10cSrcweir SELECTABLE
594cdf0e10cSrcweir SELECTED
595cdf0e10cSrcweir SINGLE_LINE
596cdf0e10cSrcweir TRANSIENT
597cdf0e10cSrcweir 
598cdf0e10cSrcweir 	*/
599cdf0e10cSrcweir }
600cdf0e10cSrcweir 
601cdf0e10cSrcweir 
602cdf0e10cSrcweir // accessibility::XAccessibleContext
603cdf0e10cSrcweir sal_Int32 VCLXAccessibleComponent::getAccessibleChildCount() throw (uno::RuntimeException)
604cdf0e10cSrcweir {
605cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
606cdf0e10cSrcweir 
607cdf0e10cSrcweir 	sal_Int32 nChildren = 0;
608cdf0e10cSrcweir 	if ( GetWindow() )
609cdf0e10cSrcweir 		nChildren = GetWindow()->GetAccessibleChildWindowCount();
610cdf0e10cSrcweir 
611cdf0e10cSrcweir 	return nChildren;
612cdf0e10cSrcweir }
613cdf0e10cSrcweir 
614cdf0e10cSrcweir uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleChild( sal_Int32 i ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
615cdf0e10cSrcweir {
616cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
617cdf0e10cSrcweir 
618cdf0e10cSrcweir 	if ( i >= getAccessibleChildCount() )
619cdf0e10cSrcweir 		throw lang::IndexOutOfBoundsException();
620cdf0e10cSrcweir 
621cdf0e10cSrcweir 	uno::Reference< accessibility::XAccessible > xAcc;
622cdf0e10cSrcweir 	if ( GetWindow() )
623cdf0e10cSrcweir 	{
624cdf0e10cSrcweir 		Window* pChild = GetWindow()->GetAccessibleChildWindow( (sal_uInt16)i );
625cdf0e10cSrcweir 		if ( pChild )
626cdf0e10cSrcweir 			xAcc = pChild->GetAccessible();
627cdf0e10cSrcweir 	}
628cdf0e10cSrcweir 
629cdf0e10cSrcweir 	return xAcc;
630cdf0e10cSrcweir }
631cdf0e10cSrcweir 
632cdf0e10cSrcweir uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getVclParent() const
633cdf0e10cSrcweir {
634cdf0e10cSrcweir 	uno::Reference< accessibility::XAccessible > xAcc;
635cdf0e10cSrcweir 	if ( GetWindow() )
636cdf0e10cSrcweir 	{
637cdf0e10cSrcweir 		Window* pParent = GetWindow()->GetAccessibleParentWindow();
638cdf0e10cSrcweir 		if ( pParent )
639cdf0e10cSrcweir 			xAcc = pParent->GetAccessible();
640cdf0e10cSrcweir 	}
641cdf0e10cSrcweir 	return xAcc;
642cdf0e10cSrcweir }
643cdf0e10cSrcweir 
644cdf0e10cSrcweir uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleParent(	) throw (uno::RuntimeException)
645cdf0e10cSrcweir {
646cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
647cdf0e10cSrcweir 
648cdf0e10cSrcweir 	uno::Reference< accessibility::XAccessible > xAcc( implGetForeignControlledParent() );
649cdf0e10cSrcweir 	if ( !xAcc.is() )
650cdf0e10cSrcweir 		// we do _not_ have a foreign-controlled parent -> default to our VCL parent
651cdf0e10cSrcweir 		xAcc = getVclParent();
652cdf0e10cSrcweir 
653cdf0e10cSrcweir 	return xAcc;
654cdf0e10cSrcweir }
655cdf0e10cSrcweir 
656cdf0e10cSrcweir sal_Int32 VCLXAccessibleComponent::getAccessibleIndexInParent(	) throw (uno::RuntimeException)
657cdf0e10cSrcweir {
658cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
659cdf0e10cSrcweir 
660cdf0e10cSrcweir 	sal_Int32 nIndex = -1;
661cdf0e10cSrcweir 
662cdf0e10cSrcweir 	uno::Reference< accessibility::XAccessible > xAcc( implGetForeignControlledParent() );
663cdf0e10cSrcweir 	if ( xAcc.is() )
664cdf0e10cSrcweir 	{	// we _do_ have a foreign-controlled parent -> use the base class' implementation,
665cdf0e10cSrcweir 		// which goes the UNO way
666cdf0e10cSrcweir 		nIndex = AccessibleExtendedComponentHelper_BASE::getAccessibleIndexInParent( );
667cdf0e10cSrcweir 	}
668cdf0e10cSrcweir 	else
669cdf0e10cSrcweir 	{
670cdf0e10cSrcweir 		if ( GetWindow() )
671cdf0e10cSrcweir 		{
672cdf0e10cSrcweir 			Window* pParent = GetWindow()->GetAccessibleParentWindow();
673cdf0e10cSrcweir 			if ( pParent )
674cdf0e10cSrcweir 			{
675cdf0e10cSrcweir                 /*
676cdf0e10cSrcweir 				for ( sal_uInt16 n = pParent->GetAccessibleChildWindowCount(); n; )
677cdf0e10cSrcweir 				{
678cdf0e10cSrcweir 					Window* pChild = pParent->GetAccessibleChildWindow( --n );
679cdf0e10cSrcweir 					if ( pChild == GetWindow() )
680cdf0e10cSrcweir 					{
681cdf0e10cSrcweir 						nIndex = n;
682cdf0e10cSrcweir 						break;
683cdf0e10cSrcweir 					}
684cdf0e10cSrcweir 				}
685cdf0e10cSrcweir                 */
686cdf0e10cSrcweir                 //	Iterate over all the parent's children and search for this object.
687cdf0e10cSrcweir                 // this should be compatible with the code in SVX
688cdf0e10cSrcweir                 uno::Reference< accessibility::XAccessible > xParentAcc( pParent->GetAccessible() );
689cdf0e10cSrcweir                 if ( xParentAcc.is() )
690cdf0e10cSrcweir                 {
691cdf0e10cSrcweir                     uno::Reference< accessibility::XAccessibleContext > xParentContext ( xParentAcc->getAccessibleContext() );
692cdf0e10cSrcweir                     if ( xParentContext.is() )
693cdf0e10cSrcweir                     {
694cdf0e10cSrcweir                         sal_Int32 nChildCount = xParentContext->getAccessibleChildCount();
695cdf0e10cSrcweir                         for ( sal_Int32 i=0; i<nChildCount; i++ )
696cdf0e10cSrcweir                         {
697cdf0e10cSrcweir                             uno::Reference< accessibility::XAccessible > xChild( xParentContext->getAccessibleChild(i) );
698cdf0e10cSrcweir                             if ( xChild.is() )
699cdf0e10cSrcweir                             {
700cdf0e10cSrcweir                                 uno::Reference< accessibility::XAccessibleContext > xChildContext = xChild->getAccessibleContext();
701cdf0e10cSrcweir 	                            if ( xChildContext == (accessibility::XAccessibleContext*) this )
702cdf0e10cSrcweir                                 {
703cdf0e10cSrcweir                                     nIndex = i;
704cdf0e10cSrcweir                                     break;
705cdf0e10cSrcweir                                 }
706cdf0e10cSrcweir                             }
707cdf0e10cSrcweir                         }
708cdf0e10cSrcweir                     }
709cdf0e10cSrcweir                 }
710cdf0e10cSrcweir 			}
711cdf0e10cSrcweir 		}
712cdf0e10cSrcweir 	}
713cdf0e10cSrcweir 	return nIndex;
714cdf0e10cSrcweir }
715cdf0e10cSrcweir 
716cdf0e10cSrcweir sal_Int16 VCLXAccessibleComponent::getAccessibleRole(  ) throw (uno::RuntimeException)
717cdf0e10cSrcweir {
718cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
719cdf0e10cSrcweir 
720cdf0e10cSrcweir 	sal_Int16 nRole = 0;
721cdf0e10cSrcweir 
722cdf0e10cSrcweir 	if ( GetWindow() )
723cdf0e10cSrcweir 		nRole = GetWindow()->GetAccessibleRole();
724cdf0e10cSrcweir 
725cdf0e10cSrcweir 	return nRole;
726cdf0e10cSrcweir }
727cdf0e10cSrcweir 
728cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleComponent::getAccessibleDescription(	) throw (uno::RuntimeException)
729cdf0e10cSrcweir {
730cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
731cdf0e10cSrcweir 
732cdf0e10cSrcweir 	::rtl::OUString aDescription;
733cdf0e10cSrcweir 
734cdf0e10cSrcweir 	if ( GetWindow() )
735cdf0e10cSrcweir 		aDescription = GetWindow()->GetAccessibleDescription();
736cdf0e10cSrcweir 
737cdf0e10cSrcweir 	return aDescription;
738cdf0e10cSrcweir }
739cdf0e10cSrcweir 
740cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleComponent::getAccessibleName(  ) throw (uno::RuntimeException)
741cdf0e10cSrcweir {
742cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
743cdf0e10cSrcweir 
744cdf0e10cSrcweir 	::rtl::OUString aName;
745cdf0e10cSrcweir 	if ( GetWindow() )
746cdf0e10cSrcweir 	{
747cdf0e10cSrcweir 		aName = GetWindow()->GetAccessibleName();
748cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
749cdf0e10cSrcweir 		aName += String( RTL_CONSTASCII_USTRINGPARAM( " (Type = " ) );
750cdf0e10cSrcweir 		aName += String::CreateFromInt32( GetWindow()->GetType() );
751cdf0e10cSrcweir 		aName += String( RTL_CONSTASCII_USTRINGPARAM( ")" ) );
752cdf0e10cSrcweir #endif
753cdf0e10cSrcweir 	}
754cdf0e10cSrcweir 	return aName;
755cdf0e10cSrcweir }
756cdf0e10cSrcweir 
757cdf0e10cSrcweir uno::Reference< accessibility::XAccessibleRelationSet > VCLXAccessibleComponent::getAccessibleRelationSet(	) throw (uno::RuntimeException)
758cdf0e10cSrcweir {
759cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
760cdf0e10cSrcweir 
761cdf0e10cSrcweir     utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
762cdf0e10cSrcweir 	uno::Reference< accessibility::XAccessibleRelationSet > xSet = pRelationSetHelper;
763cdf0e10cSrcweir 	FillAccessibleRelationSet( *pRelationSetHelper );
764cdf0e10cSrcweir     return xSet;
765cdf0e10cSrcweir }
766cdf0e10cSrcweir 
767cdf0e10cSrcweir uno::Reference< accessibility::XAccessibleStateSet > VCLXAccessibleComponent::getAccessibleStateSet(  ) throw (uno::RuntimeException)
768cdf0e10cSrcweir {
769cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
770cdf0e10cSrcweir 
771cdf0e10cSrcweir 	utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
772cdf0e10cSrcweir 	uno::Reference< accessibility::XAccessibleStateSet > xSet = pStateSetHelper;
773cdf0e10cSrcweir 	FillAccessibleStateSet( *pStateSetHelper );
774cdf0e10cSrcweir 	return xSet;
775cdf0e10cSrcweir }
776cdf0e10cSrcweir 
777cdf0e10cSrcweir lang::Locale VCLXAccessibleComponent::getLocale() throw (accessibility::IllegalAccessibleComponentStateException, uno::RuntimeException)
778cdf0e10cSrcweir {
779cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
780cdf0e10cSrcweir 
781cdf0e10cSrcweir 	return Application::GetSettings().GetLocale();
782cdf0e10cSrcweir }
783cdf0e10cSrcweir 
784cdf0e10cSrcweir uno::Reference< accessibility::XAccessible > VCLXAccessibleComponent::getAccessibleAtPoint( const awt::Point& rPoint ) throw (uno::RuntimeException)
785cdf0e10cSrcweir {
786cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
787cdf0e10cSrcweir 
788cdf0e10cSrcweir     uno::Reference< accessibility::XAccessible > xChild;
789cdf0e10cSrcweir 	for ( sal_uInt32 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
790cdf0e10cSrcweir 	{
791cdf0e10cSrcweir 		uno::Reference< accessibility::XAccessible > xAcc = getAccessibleChild( i );
792cdf0e10cSrcweir 		if ( xAcc.is() )
793cdf0e10cSrcweir 		{
794cdf0e10cSrcweir 			uno::Reference< accessibility::XAccessibleComponent > xComp( xAcc->getAccessibleContext(), uno::UNO_QUERY );
795cdf0e10cSrcweir 			if ( xComp.is() )
796cdf0e10cSrcweir 			{
797cdf0e10cSrcweir 				Rectangle aRect = VCLRectangle( xComp->getBounds() );
798cdf0e10cSrcweir 				Point aPos = VCLPoint( rPoint );
799cdf0e10cSrcweir 				if ( aRect.IsInside( aPos ) )
800cdf0e10cSrcweir 				{
801cdf0e10cSrcweir 					xChild = xAcc;
802cdf0e10cSrcweir 					break;
803cdf0e10cSrcweir 				}
804cdf0e10cSrcweir 			}
805cdf0e10cSrcweir 		}
806cdf0e10cSrcweir 	}
807cdf0e10cSrcweir 
808cdf0e10cSrcweir 	return xChild;
809cdf0e10cSrcweir }
810cdf0e10cSrcweir 
811cdf0e10cSrcweir // accessibility::XAccessibleComponent
812cdf0e10cSrcweir awt::Rectangle VCLXAccessibleComponent::implGetBounds() throw (uno::RuntimeException)
813cdf0e10cSrcweir {
814cdf0e10cSrcweir 	awt::Rectangle aBounds ( 0, 0, 0, 0 );
815cdf0e10cSrcweir 
816cdf0e10cSrcweir 	Window* pWindow = GetWindow();
817cdf0e10cSrcweir 	if ( pWindow )
818cdf0e10cSrcweir 	{
819cdf0e10cSrcweir 		Rectangle aRect = pWindow->GetWindowExtentsRelative( NULL );
820cdf0e10cSrcweir 		aBounds = AWTRectangle( aRect );
821cdf0e10cSrcweir 		Window* pParent = pWindow->GetAccessibleParentWindow();
822cdf0e10cSrcweir 		if ( pParent )
823cdf0e10cSrcweir 		{
824cdf0e10cSrcweir 			Rectangle aParentRect = pParent->GetWindowExtentsRelative( NULL );
825cdf0e10cSrcweir 			awt::Point aParentScreenLoc = AWTPoint( aParentRect.TopLeft() );
826cdf0e10cSrcweir 			aBounds.X -= aParentScreenLoc.X;
827cdf0e10cSrcweir 			aBounds.Y -= aParentScreenLoc.Y;
828cdf0e10cSrcweir 		}
829cdf0e10cSrcweir 	}
830cdf0e10cSrcweir 
831cdf0e10cSrcweir 	uno::Reference< accessibility::XAccessible > xParent( implGetForeignControlledParent() );
832cdf0e10cSrcweir 	if ( xParent.is() )
833cdf0e10cSrcweir 	{	// hmm, we can't rely on our VCL coordinates, as in the Accessibility Hierarchy, somebody gave
834cdf0e10cSrcweir 		// us a parent which is different from our VCL parent
835cdf0e10cSrcweir 		// (actually, we did not check if it's really different ...)
836cdf0e10cSrcweir 
837cdf0e10cSrcweir 		// the screen location of the foreign parent
838cdf0e10cSrcweir 		uno::Reference< accessibility::XAccessibleComponent > xParentComponent( xParent->getAccessibleContext(), uno::UNO_QUERY );
839cdf0e10cSrcweir 		DBG_ASSERT( xParentComponent.is(), "VCLXAccessibleComponent::implGetBounds: invalid (foreign) parent component!" );
840cdf0e10cSrcweir 
841cdf0e10cSrcweir 		awt::Point aScreenLocForeign( 0, 0 );
842cdf0e10cSrcweir 		if ( xParentComponent.is() )
843cdf0e10cSrcweir 			aScreenLocForeign = xParentComponent->getLocationOnScreen();
844cdf0e10cSrcweir 
845cdf0e10cSrcweir 		// the screen location of the VCL parent
846cdf0e10cSrcweir 		xParent = getVclParent();
847cdf0e10cSrcweir 		if ( xParent.is() )
848cdf0e10cSrcweir 			xParentComponent = xParentComponent.query( xParent->getAccessibleContext() );
849cdf0e10cSrcweir 
850cdf0e10cSrcweir 		awt::Point aScreenLocVCL( 0, 0 );
851cdf0e10cSrcweir 		if ( xParentComponent.is() )
852cdf0e10cSrcweir 			aScreenLocVCL = xParentComponent->getLocationOnScreen();
853cdf0e10cSrcweir 
854cdf0e10cSrcweir 		// the difference between them
855cdf0e10cSrcweir 		awt::Size aOffset( aScreenLocVCL.X - aScreenLocForeign.X, aScreenLocVCL.Y - aScreenLocForeign.Y );
856cdf0e10cSrcweir 		// move the bounds
857cdf0e10cSrcweir 		aBounds.X += aOffset.Width;
858cdf0e10cSrcweir 		aBounds.Y += aOffset.Height;
859cdf0e10cSrcweir 	}
860cdf0e10cSrcweir 
861cdf0e10cSrcweir 	return aBounds;
862cdf0e10cSrcweir }
863cdf0e10cSrcweir 
864cdf0e10cSrcweir awt::Point VCLXAccessibleComponent::getLocationOnScreen(  ) throw (uno::RuntimeException)
865cdf0e10cSrcweir {
866cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
867cdf0e10cSrcweir 
868cdf0e10cSrcweir 	awt::Point aPos;
869cdf0e10cSrcweir 	if ( GetWindow() )
870cdf0e10cSrcweir 	{
871cdf0e10cSrcweir 		Rectangle aRect = GetWindow()->GetWindowExtentsRelative( NULL );
872cdf0e10cSrcweir 		aPos.X = aRect.Left();
873cdf0e10cSrcweir 		aPos.Y = aRect.Top();
874cdf0e10cSrcweir 	}
875cdf0e10cSrcweir 
876cdf0e10cSrcweir 	return aPos;
877cdf0e10cSrcweir }
878cdf0e10cSrcweir 
879cdf0e10cSrcweir void VCLXAccessibleComponent::grabFocus(  ) throw (uno::RuntimeException)
880cdf0e10cSrcweir {
881cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
882cdf0e10cSrcweir 
883cdf0e10cSrcweir 	uno::Reference< accessibility::XAccessibleStateSet > xStates = getAccessibleStateSet();
884cdf0e10cSrcweir 	if ( mxWindow.is() && xStates.is() && xStates->contains( accessibility::AccessibleStateType::FOCUSABLE ) )
885cdf0e10cSrcweir 		mxWindow->setFocus();
886cdf0e10cSrcweir }
887cdf0e10cSrcweir 
888cdf0e10cSrcweir sal_Int32 SAL_CALL VCLXAccessibleComponent::getForeground(	) throw (uno::RuntimeException)
889cdf0e10cSrcweir {
890cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
891cdf0e10cSrcweir 
892cdf0e10cSrcweir 	sal_Int32 nColor = 0;
893cdf0e10cSrcweir 	Window* pWindow = GetWindow();
894cdf0e10cSrcweir 	if ( pWindow )
895cdf0e10cSrcweir 	{
896cdf0e10cSrcweir 		if ( pWindow->IsControlForeground() )
897cdf0e10cSrcweir 			nColor = pWindow->GetControlForeground().GetColor();
898cdf0e10cSrcweir 		else
899cdf0e10cSrcweir 		{
900cdf0e10cSrcweir 			Font aFont;
901cdf0e10cSrcweir 			if ( pWindow->IsControlFont() )
902cdf0e10cSrcweir 				aFont = pWindow->GetControlFont();
903cdf0e10cSrcweir 			else
904cdf0e10cSrcweir 				aFont = pWindow->GetFont();
905cdf0e10cSrcweir 			nColor = aFont.GetColor().GetColor();
906*ff7e158dSSteve Yin //IAccessibility2 Implementation 2009-----
907*ff7e158dSSteve Yin 			if ( nColor == COL_AUTO)
908*ff7e158dSSteve Yin 				nColor = pWindow->GetTextColor().GetColor();
909*ff7e158dSSteve Yin //-----IAccessibility2 Implementation 2009
910cdf0e10cSrcweir 		}
911cdf0e10cSrcweir 	}
912cdf0e10cSrcweir 
913cdf0e10cSrcweir 	return nColor;
914cdf0e10cSrcweir }
915cdf0e10cSrcweir 
916cdf0e10cSrcweir sal_Int32 SAL_CALL VCLXAccessibleComponent::getBackground(	) throw (uno::RuntimeException)
917cdf0e10cSrcweir {
918cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
919cdf0e10cSrcweir 
920cdf0e10cSrcweir 	sal_Int32 nColor = 0;
921cdf0e10cSrcweir 	Window* pWindow = GetWindow();
922cdf0e10cSrcweir 	if ( pWindow )
923cdf0e10cSrcweir 	{
924cdf0e10cSrcweir 		if ( pWindow->IsControlBackground() )
925cdf0e10cSrcweir 			nColor = pWindow->GetControlBackground().GetColor();
926cdf0e10cSrcweir 		else
927cdf0e10cSrcweir 			nColor = pWindow->GetBackground().GetColor().GetColor();
928cdf0e10cSrcweir 	}
929cdf0e10cSrcweir 
930cdf0e10cSrcweir 	return nColor;
931cdf0e10cSrcweir }
932cdf0e10cSrcweir 
933cdf0e10cSrcweir // XAccessibleExtendedComponent
934cdf0e10cSrcweir 
935cdf0e10cSrcweir uno::Reference< awt::XFont > SAL_CALL VCLXAccessibleComponent::getFont(  ) throw (uno::RuntimeException)
936cdf0e10cSrcweir {
937cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
938cdf0e10cSrcweir 
939cdf0e10cSrcweir 	uno::Reference< awt::XFont > xFont;
940cdf0e10cSrcweir 	Window* pWindow = GetWindow();
941cdf0e10cSrcweir 	if ( pWindow )
942cdf0e10cSrcweir 	{
943cdf0e10cSrcweir 		uno::Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), uno::UNO_QUERY );
944cdf0e10cSrcweir 		if ( xDev.is() )
945cdf0e10cSrcweir 		{
946cdf0e10cSrcweir 			Font aFont;
947cdf0e10cSrcweir 			if ( pWindow->IsControlFont() )
948cdf0e10cSrcweir 				aFont = pWindow->GetControlFont();
949cdf0e10cSrcweir 			else
950cdf0e10cSrcweir 				aFont = pWindow->GetFont();
951cdf0e10cSrcweir 			VCLXFont* pVCLXFont = new VCLXFont;
952cdf0e10cSrcweir 			pVCLXFont->Init( *xDev.get(), aFont );
953cdf0e10cSrcweir 			xFont = pVCLXFont;
954cdf0e10cSrcweir 		}
955cdf0e10cSrcweir 	}
956cdf0e10cSrcweir 
957cdf0e10cSrcweir 	return xFont;
958cdf0e10cSrcweir }
959cdf0e10cSrcweir 
960cdf0e10cSrcweir ::rtl::OUString SAL_CALL VCLXAccessibleComponent::getTitledBorderText(	) throw (uno::RuntimeException)
961cdf0e10cSrcweir {
962cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
963cdf0e10cSrcweir 
964cdf0e10cSrcweir 	::rtl::OUString sRet;
965cdf0e10cSrcweir 	if ( GetWindow() )
966cdf0e10cSrcweir 		sRet = GetWindow()->GetText();
967cdf0e10cSrcweir 
968cdf0e10cSrcweir 	return sRet;
969cdf0e10cSrcweir }
970cdf0e10cSrcweir 
971cdf0e10cSrcweir ::rtl::OUString SAL_CALL VCLXAccessibleComponent::getToolTipText(  ) throw (uno::RuntimeException)
972cdf0e10cSrcweir {
973cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
974cdf0e10cSrcweir 
975cdf0e10cSrcweir 	::rtl::OUString sRet;
976cdf0e10cSrcweir 	if ( GetWindow() )
977cdf0e10cSrcweir 		sRet = GetWindow()->GetQuickHelpText();
978cdf0e10cSrcweir 
979cdf0e10cSrcweir 	return sRet;
980cdf0e10cSrcweir }
981cdf0e10cSrcweir 
982