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