1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2006 Novell, Inc.
23 // Peter Dennis Bartok pbartok@novell.com
31 using System
.Globalization
;
32 using System
.Reflection
;
33 using System
.Runtime
.InteropServices
;
35 namespace System
.Windows
.Forms
{
37 public class AccessibleObject
: StandardOleMarshalObject
, IReflect
, IAccessible
{
38 #region Private Variables
40 internal string value;
41 internal Control owner
;
42 internal AccessibleRole role
;
43 internal AccessibleStates state
;
44 internal string default_action
;
45 internal string description
;
47 internal string keyboard_shortcut
;
48 #endregion // Private Variables
50 #region Public Constructors
51 public AccessibleObject() {
55 this.role
= AccessibleRole
.Default
;
56 this.default_action
= null;
57 this.description
= null;
59 this.keyboard_shortcut
= null;
60 this.state
= AccessibleStates
.None
;
62 #endregion // Public Constructors
64 #region Private Constructors
65 internal AccessibleObject(Control owner
) : this () {
68 #endregion // Private Constructors
70 #region Public Instance Properties
71 public virtual Rectangle Bounds
{
77 public virtual string DefaultAction
{
79 return default_action
;
83 public virtual string Description
{
89 public virtual string Help
{
95 public virtual string KeyboardShortcut
{
97 return keyboard_shortcut
;
101 public virtual string Name
{
111 public virtual AccessibleObject Parent
{
113 if ((owner
!=null) && (owner
.Parent
!=null)) {
114 return owner
.Parent
.AccessibilityObject
;
120 public virtual AccessibleRole Role
{
126 public virtual AccessibleStates State
{
130 state
|= AccessibleStates
.Focused
;
132 if (owner
.CanFocus
) {
133 state
|= AccessibleStates
.Focusable
;
135 if (!owner
.Visible
) {
136 state
|= AccessibleStates
.Invisible
;
143 public virtual string Value
{
152 #endregion // Public Instance Properties
154 #region Public Instance Methods
155 public virtual void DoDefaultAction() {
157 owner
.DoDefaultAction();
161 public virtual AccessibleObject
GetChild(int index
) {
163 if (index
<owner
.Controls
.Count
) {
164 return owner
.Controls
[index
].AccessibilityObject
;
170 public virtual int GetChildCount() {
172 return owner
.Controls
.Count
;
177 public virtual AccessibleObject
GetFocused() {
178 if (owner
.has_focus
) {
179 return owner
.AccessibilityObject
;
182 return FindFocusControl(owner
);
185 public virtual int GetHelpTopic (out string fileName
)
191 public virtual AccessibleObject
GetSelected() {
192 if ((state
& AccessibleStates
.Selected
) != 0) {
196 return FindSelectedControl(owner
);
199 public virtual AccessibleObject
HitTest(int x
, int y
) {
202 result
= FindHittestControl(owner
, x
, y
);
204 if (result
!= null) {
205 return result
.AccessibilityObject
;
211 public virtual AccessibleObject
Navigate(AccessibleNavigation navdir
) {
214 // I'm not throwing exceptions if an object doesn't exist in the specified direction
215 // Might not be too helpful to a blind dude trying to navigate. Instead we return
218 if (owner
.Parent
!= null) {
219 index
= owner
.Parent
.Controls
.IndexOf(owner
);
225 // Spatial navigation; limited to siblings
226 case AccessibleNavigation
.Up
: {
227 if (owner
.Parent
!= null) {
228 for (int i
=0; i
<owner
.Parent
.Controls
.Count
; i
++) {
229 if ((owner
!= owner
.Parent
.Controls
[i
]) && (owner
.Parent
.Controls
[i
].Top
<owner
.Top
)) {
230 return owner
.Parent
.Controls
[i
].AccessibilityObject
;
235 return owner
.AccessibilityObject
;
238 case AccessibleNavigation
.Down
: {
239 if (owner
.Parent
!= null) {
240 for (int i
=0; i
<owner
.Parent
.Controls
.Count
; i
++) {
241 if ((owner
!= owner
.Parent
.Controls
[i
]) && (owner
.Parent
.Controls
[i
].Top
>owner
.Bottom
)) {
242 return owner
.Parent
.Controls
[i
].AccessibilityObject
;
247 return owner
.AccessibilityObject
;
250 case AccessibleNavigation
.Left
: {
251 if (owner
.Parent
!= null) {
252 for (int i
=0; i
<owner
.Parent
.Controls
.Count
; i
++) {
253 if ((owner
!= owner
.Parent
.Controls
[i
]) && (owner
.Parent
.Controls
[i
].Left
<owner
.Left
)) {
254 return owner
.Parent
.Controls
[i
].AccessibilityObject
;
259 return owner
.AccessibilityObject
;
262 case AccessibleNavigation
.Right
: {
263 if (owner
.Parent
!= null) {
264 for (int i
=0; i
<owner
.Parent
.Controls
.Count
; i
++) {
265 if ((owner
!= owner
.Parent
.Controls
[i
]) && (owner
.Parent
.Controls
[i
].Left
>owner
.Right
)) {
266 return owner
.Parent
.Controls
[i
].AccessibilityObject
;
271 return owner
.AccessibilityObject
;
274 // Logical navigation
275 case AccessibleNavigation
.Next
: {
276 if (owner
.Parent
!= null) {
277 if ((index
+1)<owner
.Parent
.Controls
.Count
) {
278 return owner
.Parent
.Controls
[index
+1].AccessibilityObject
;
280 return owner
.Parent
.Controls
[0].AccessibilityObject
;
283 return owner
.AccessibilityObject
;
287 case AccessibleNavigation
.Previous
: {
288 if (owner
.Parent
!= null) {
290 return owner
.Parent
.Controls
[index
-1].AccessibilityObject
;
292 return owner
.Parent
.Controls
[owner
.Parent
.Controls
.Count
-1].AccessibilityObject
;
295 return owner
.AccessibilityObject
;
299 case AccessibleNavigation
.FirstChild
: {
300 if (owner
.Controls
.Count
>0) {
301 return owner
.Controls
[0].AccessibilityObject
;
303 return owner
.AccessibilityObject
;
307 case AccessibleNavigation
.LastChild
: {
308 if (owner
.Controls
.Count
>0) {
309 return owner
.Controls
[owner
.Controls
.Count
-1].AccessibilityObject
;
311 return owner
.AccessibilityObject
;
316 return owner
.AccessibilityObject
;
319 public virtual void Select(AccessibleSelection flags
) {
320 if ((flags
& AccessibleSelection
.TakeFocus
) != 0){
325 #endregion // Public Instance Methods
327 #region Protected Instance Methods
328 protected void UseStdAccessibleObjects(IntPtr handle
) {
331 protected void UseStdAccessibleObjects(IntPtr handle
, int objid
) {
332 UseStdAccessibleObjects(handle
, 0);
334 #endregion // Protected Instance Methods
337 #region Internal Methods
338 internal static AccessibleObject
FindFocusControl(Control parent
) {
341 if (parent
!= null) {
342 for (int i
=0; i
< parent
.Controls
.Count
; i
++) {
343 child
= parent
.Controls
[i
];
344 if ((child
.AccessibilityObject
.state
& AccessibleStates
.Focused
) != 0) {
345 return child
.AccessibilityObject
;
348 if (child
.Controls
.Count
>0) {
349 AccessibleObject result
;
351 result
= FindFocusControl(child
);
352 if (result
!= null) {
361 internal static AccessibleObject
FindSelectedControl(Control parent
) {
364 if (parent
!= null) {
365 for (int i
=0; i
< parent
.Controls
.Count
; i
++) {
366 child
= parent
.Controls
[i
];
367 if ((child
.AccessibilityObject
.state
& AccessibleStates
.Selected
) != 0) {
368 return child
.AccessibilityObject
;
370 if (child
.Controls
.Count
>0) {
371 AccessibleObject result
;
373 result
= FindSelectedControl(child
);
374 if (result
!= null) {
383 internal static Control
FindHittestControl(Control parent
, int x
, int y
) {
388 hittest_point
= new Point(x
, y
);
390 child_point
= parent
.PointToClient(hittest_point
);
391 if (parent
.ClientRectangle
.Contains(child_point
)) {
395 for (int i
=0; i
< parent
.Controls
.Count
; i
++) {
396 child
=parent
.Controls
[i
];
397 child_point
= child
.PointToClient(hittest_point
);
398 if (child
.ClientRectangle
.Contains(child_point
)) {
401 if (child
.Controls
.Count
>0) {
404 result
= FindHittestControl(child
, x
, y
);
405 if (result
!= null) {
412 #endregion // Internal Methods
414 #region IReflection Methods and Properties
415 FieldInfo IReflect
.GetField(String name
, BindingFlags bindingAttr
) {
416 throw new NotImplementedException();
419 FieldInfo
[] IReflect
.GetFields(BindingFlags bindingAttr
) {
420 throw new NotImplementedException();
423 MemberInfo
[] IReflect
.GetMember(String name
, BindingFlags bindingAttr
) {
424 throw new NotImplementedException();
427 MemberInfo
[] IReflect
.GetMembers(BindingFlags bindingAttr
) {
428 throw new NotImplementedException();
431 MethodInfo IReflect
.GetMethod(String name
, BindingFlags bindingAttr
) {
432 throw new NotImplementedException();
435 MethodInfo IReflect
.GetMethod(String name
, BindingFlags bindingAttr
, Binder binder
, Type
[] types
, ParameterModifier
[] modifiers
) {
436 throw new NotImplementedException();
439 MethodInfo
[] IReflect
.GetMethods(BindingFlags bindingAttr
) {
440 throw new NotImplementedException();
443 PropertyInfo IReflect
.GetProperty(String name
, BindingFlags bindingAttr
) {
444 throw new NotImplementedException();
447 PropertyInfo IReflect
.GetProperty(String name
, BindingFlags bindingAttr
, Binder binder
, Type returnType
, Type
[] types
, ParameterModifier
[] modifiers
) {
448 throw new NotImplementedException();
451 PropertyInfo
[] IReflect
.GetProperties(BindingFlags bindingAttr
) {
452 throw new NotImplementedException();
455 Object IReflect
.InvokeMember(String name
, BindingFlags invokeAttr
, Binder binder
, Object target
, Object
[] args
, ParameterModifier
[] modifiers
, CultureInfo culture
, String
[] namedParameters
) {
456 throw new NotImplementedException();
459 Type IReflect
.UnderlyingSystemType
{
461 throw new NotImplementedException();
464 #endregion // IReflection Methods and Properties
466 #region IAccessible Methods and Properties
467 void IAccessible
.accDoDefaultAction(object childID
) {
468 throw new NotImplementedException();
471 int IAccessible
.accChildCount
{
473 throw new NotImplementedException();
477 object IAccessible
.accFocus
{
479 throw new NotImplementedException();
483 object IAccessible
.accHitTest(int xLeft
, int yTop
) {
484 throw new NotImplementedException();
487 void IAccessible
.accLocation(out int pxLeft
, out int pyTop
, out int pcxWidth
, out int pcyHeight
, object childID
) {
488 throw new NotImplementedException();
491 object IAccessible
.accNavigate(int navDir
, object childID
) {
492 throw new NotImplementedException();
495 object IAccessible
.accParent
{
497 throw new NotImplementedException();
501 void IAccessible
.accSelect(int flagsSelect
, object childID
) {
502 throw new NotImplementedException();
505 object IAccessible
.accSelection
{
507 throw new NotImplementedException();
511 object IAccessible
.get_accChild(object childID
) {
512 throw new NotImplementedException();
515 string IAccessible
.get_accDefaultAction(object childID
) {
516 throw new NotImplementedException();
519 string IAccessible
.get_accDescription(object childID
) {
520 throw new NotImplementedException();
523 string IAccessible
.get_accHelp(object childID
) {
524 throw new NotImplementedException();
527 int IAccessible
.get_accHelpTopic(out string pszHelpFile
,object childID
) {
528 throw new NotImplementedException();
531 string IAccessible
.get_accKeyboardShortcut(object childID
) {
532 throw new NotImplementedException();
535 string IAccessible
.get_accName(object childID
) {
536 throw new NotImplementedException();
539 object IAccessible
.get_accRole(object childID
) {
540 throw new NotImplementedException();
543 object IAccessible
.get_accState(object childID
) {
544 throw new NotImplementedException();
547 string IAccessible
.get_accValue(object childID
) {
548 throw new NotImplementedException();
551 void IAccessible
.set_accName(object childID
, string newName
) {
552 throw new NotImplementedException();
555 void IAccessible
.set_accValue(object childID
, string newValue
) {
556 throw new NotImplementedException();
558 #endregion // IAccessible Methods and Properties