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 Novell, Inc.
23 // Peter 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 : MarshalByRefObject, IReflect, IAccessible {
38 #region Private Variables
41 private Control owner;
42 internal AccessibleRole role;
43 internal string default_action;
44 internal string description;
46 internal string keyboard_shortcut;
47 #endregion // Private Variables
49 #region Public Constructors
50 public AccessibleObject() {
54 this.role=AccessibleRole.Default;
55 this.default_action=null;
56 this.description=null;
58 this.keyboard_shortcut=null;
60 #endregion // Public Constructors
62 #region Private Constructors
63 internal AccessibleObject(Control owner) : this () {
66 #endregion // Private Constructors
68 #region Public Instance Properties
69 public virtual Rectangle Bounds {
71 return Rectangle.Empty;
75 public virtual string DefaultAction {
77 return default_action;
81 public virtual string Description {
87 public virtual string Help {
93 public virtual string KeyboardShortcut {
95 return keyboard_shortcut;
99 public virtual string Name {
109 public virtual AccessibleObject Parent {
111 if ((owner!=null) && (owner.Parent!=null)) {
112 return owner.Parent.AccessibilityObject;
118 public virtual AccessibleRole Role {
124 public virtual AccessibleStates State {
126 AccessibleStates state=AccessibleStates.None;
130 state |= AccessibleStates.Focused;
133 if (!owner.Visible) {
134 state |= AccessibleStates.Invisible;
141 public virtual string Value {
150 #endregion // Public Instance Properties
152 #region Public Instance Methods
153 public virtual void DoDefaultAction() {
155 owner.DoDefaultAction();
159 public virtual AccessibleObject GetChild(int index) {
161 if (index<owner.child_controls.Count) {
162 return owner.child_controls[index].AccessibilityObject;
168 public virtual int GetChildCount() {
170 return owner.child_controls.Count;
175 public virtual AccessibleObject GetFocused() {
178 if (owner.has_focus) {
179 return owner.AccessibilityObject;
182 result = FindFocusControl(owner);
184 if (result != null) {
185 return result.AccessibilityObject;
191 [MonoTODO("Integrate help into accessibility system")]
192 public virtual int GetHelpTopic(out string FileName) {
199 public virtual AccessibleObject GetSelected() {
202 if (owner.is_selected) {
203 return owner.AccessibilityObject;
206 result = FindSelectedControl(owner);
208 if (result != null) {
209 return result.AccessibilityObject;
215 public virtual AccessibleObject HitTest(int x, int y) {
218 result = FindHittestControl(owner, x, y);
220 if (result != null) {
221 return result.AccessibilityObject;
227 public virtual AccessibleObject Navigate(AccessibleNavigation navdir) {
230 // I'm not throwing exceptions if an object doesn't exist in the specified direction
231 // Might not be too helpful to a blind dude trying to navigate. Instead we return
234 if (owner.parent != null) {
235 index = owner.parent.child_controls.IndexOf(owner);
241 // Spatial navigation; limited to siblings
242 case AccessibleNavigation.Up: {
243 if (owner.parent != null) {
244 for (int i=0; i<owner.parent.child_controls.Count; i++) {
245 if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Top<owner.Top)) {
246 return owner.parent.child_controls[i].AccessibilityObject;
251 return owner.AccessibilityObject;
254 case AccessibleNavigation.Down: {
255 if (owner.parent != null) {
256 for (int i=0; i<owner.parent.child_controls.Count; i++) {
257 if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Top>owner.Bottom)) {
258 return owner.parent.child_controls[i].AccessibilityObject;
263 return owner.AccessibilityObject;
266 case AccessibleNavigation.Left: {
267 if (owner.parent != null) {
268 for (int i=0; i<owner.parent.child_controls.Count; i++) {
269 if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Left<owner.Left)) {
270 return owner.parent.child_controls[i].AccessibilityObject;
275 return owner.AccessibilityObject;
278 case AccessibleNavigation.Right: {
279 if (owner.parent != null) {
280 for (int i=0; i<owner.parent.child_controls.Count; i++) {
281 if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Left>owner.Right)) {
282 return owner.parent.child_controls[i].AccessibilityObject;
287 return owner.AccessibilityObject;
290 // Logical navigation
291 case AccessibleNavigation.Next: {
292 if (owner.parent != null) {
293 if ((index+1)<owner.parent.child_controls.Count) {
294 return owner.parent.child_controls[index+1].AccessibilityObject;
296 return owner.parent.child_controls[0].AccessibilityObject;
299 return owner.AccessibilityObject;
303 case AccessibleNavigation.Previous: {
304 if (owner.parent != null) {
306 return owner.parent.child_controls[index-1].AccessibilityObject;
308 return owner.parent.child_controls[owner.parent.child_controls.Count-1].AccessibilityObject;
311 return owner.AccessibilityObject;
315 case AccessibleNavigation.FirstChild: {
316 if (owner.child_controls.Count>0) {
317 return owner.child_controls[0].AccessibilityObject;
319 return owner.AccessibilityObject;
323 case AccessibleNavigation.LastChild: {
324 if (owner.child_controls.Count>0) {
325 return owner.child_controls[owner.child_controls.Count-1].AccessibilityObject;
327 return owner.AccessibilityObject;
332 return owner.AccessibilityObject;
335 public virtual void Select(AccessibleSelection flags) {
336 if ((flags & AccessibleSelection.TakeFocus) != 0){
341 #endregion // Public Instance Methods
343 #region Protected Instance Methods
344 protected void UseStdAccessibleObjects(IntPtr handle) {
347 protected void UseStdAccessibleObjects(IntPtr handle, int objid) {
348 UseStdAccessibleObjects(handle, 0);
350 #endregion // Protected Instance Methods
353 #region Internal Methods
354 internal static Control FindFocusControl(Control parent) {
357 for (int i=0; i < parent.child_controls.Count; i++) {
358 child=parent.child_controls[i];
359 if (child.has_focus) {
362 if (child.child_controls.Count>0) {
365 result = FindFocusControl(child);
366 if (result != null) {
374 internal static Control FindSelectedControl(Control parent) {
377 for (int i=0; i < parent.child_controls.Count; i++) {
378 child=parent.child_controls[i];
379 if (child.has_focus) {
382 if (child.child_controls.Count>0) {
385 result = FindSelectedControl(child);
386 if (result != null) {
394 internal static Control FindHittestControl(Control parent, int x, int y) {
399 hittest_point = new Point(x, y);
401 child_point = parent.PointToClient(hittest_point);
402 if (parent.ClientRectangle.Contains(child_point)) {
406 for (int i=0; i < parent.child_controls.Count; i++) {
407 child=parent.child_controls[i];
408 child_point = child.PointToClient(hittest_point);
409 if (child.ClientRectangle.Contains(child_point)) {
412 if (child.child_controls.Count>0) {
415 result = FindHittestControl(child, x, y);
416 if (result != null) {
423 #endregion // Internal Methods
425 #region IReflection Methods and Properties
426 FieldInfo IReflect.GetField(String name, BindingFlags bindingAttr) {
427 throw new NotImplementedException();
430 FieldInfo[] IReflect.GetFields(BindingFlags bindingAttr) {
431 throw new NotImplementedException();
434 MemberInfo[] IReflect.GetMember(String name, BindingFlags bindingAttr) {
435 throw new NotImplementedException();
438 MemberInfo[] IReflect.GetMembers(BindingFlags bindingAttr) {
439 throw new NotImplementedException();
442 MethodInfo IReflect.GetMethod(String name, BindingFlags bindingAttr) {
443 throw new NotImplementedException();
446 MethodInfo IReflect.GetMethod(String name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers) {
447 throw new NotImplementedException();
450 MethodInfo[] IReflect.GetMethods(BindingFlags bindingAttr) {
451 throw new NotImplementedException();
454 PropertyInfo IReflect.GetProperty(String name, BindingFlags bindingAttr) {
455 throw new NotImplementedException();
458 PropertyInfo IReflect.GetProperty(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) {
459 throw new NotImplementedException();
462 PropertyInfo[] IReflect.GetProperties(BindingFlags bindingAttr) {
463 throw new NotImplementedException();
466 Object IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) {
467 throw new NotImplementedException();
470 Type IReflect.UnderlyingSystemType {
472 throw new NotImplementedException();
475 #endregion // IReflection Methods and Properties
477 #region IAccessible Methods and Properties
478 void IAccessible.accDoDefaultAction(object childID) {
479 throw new NotImplementedException();
482 int IAccessible.accChildCount {
484 throw new NotImplementedException();
488 object IAccessible.accFocus {
490 throw new NotImplementedException();
494 object IAccessible.accHitTest(int xLeft, int yTop) {
495 throw new NotImplementedException();
498 void IAccessible.accLocation(out int pxLeft, out int pyTop, out int pcxWidth, out int pcyHeight, object childID) {
499 throw new NotImplementedException();
502 object IAccessible.accNavigate(int navDir, object childID) {
503 throw new NotImplementedException();
506 object IAccessible.accParent {
508 throw new NotImplementedException();
512 void IAccessible.accSelect(int flagsSelect, object childID) {
513 throw new NotImplementedException();
516 object IAccessible.accSelection {
518 throw new NotImplementedException();
522 object IAccessible.get_accChild(object childID) {
523 throw new NotImplementedException();
526 string IAccessible.get_accDefaultAction(object childID) {
527 throw new NotImplementedException();
530 string IAccessible.get_accDescription(object childID) {
531 throw new NotImplementedException();
534 string IAccessible.get_accHelp(object childID) {
535 throw new NotImplementedException();
538 int IAccessible.get_accHelpTopic(out string pszHelpFile,object childID) {
539 throw new NotImplementedException();
542 string IAccessible.get_accKeyboardShortcut(object childID) {
543 throw new NotImplementedException();
546 string IAccessible.get_accName(object childID) {
547 throw new NotImplementedException();
550 object IAccessible.get_accRole(object childID) {
551 throw new NotImplementedException();
554 object IAccessible.get_accState(object childID) {
555 throw new NotImplementedException();
558 string IAccessible.get_accValue(object childID) {
559 throw new NotImplementedException();
562 void IAccessible.set_accName(object childID, string newName) {
563 throw new NotImplementedException();
566 void IAccessible.set_accValue(object childID, string newValue) {
567 throw new NotImplementedException();
569 #endregion // IAccessible Methods and Properties