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-2005 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
40 internal string value;
41 internal 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 {
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 public virtual int GetHelpTopic(out string FileName) {
198 public virtual AccessibleObject GetSelected() {
201 if (owner.is_selected) {
202 return owner.AccessibilityObject;
205 result = FindSelectedControl(owner);
207 if (result != null) {
208 return result.AccessibilityObject;
214 public virtual AccessibleObject HitTest(int x, int y) {
217 result = FindHittestControl(owner, x, y);
219 if (result != null) {
220 return result.AccessibilityObject;
226 public virtual AccessibleObject Navigate(AccessibleNavigation navdir) {
229 // I'm not throwing exceptions if an object doesn't exist in the specified direction
230 // Might not be too helpful to a blind dude trying to navigate. Instead we return
233 if (owner.parent != null) {
234 index = owner.parent.child_controls.IndexOf(owner);
240 // Spatial navigation; limited to siblings
241 case AccessibleNavigation.Up: {
242 if (owner.parent != null) {
243 for (int i=0; i<owner.parent.child_controls.Count; i++) {
244 if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Top<owner.Top)) {
245 return owner.parent.child_controls[i].AccessibilityObject;
250 return owner.AccessibilityObject;
253 case AccessibleNavigation.Down: {
254 if (owner.parent != null) {
255 for (int i=0; i<owner.parent.child_controls.Count; i++) {
256 if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Top>owner.Bottom)) {
257 return owner.parent.child_controls[i].AccessibilityObject;
262 return owner.AccessibilityObject;
265 case AccessibleNavigation.Left: {
266 if (owner.parent != null) {
267 for (int i=0; i<owner.parent.child_controls.Count; i++) {
268 if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Left<owner.Left)) {
269 return owner.parent.child_controls[i].AccessibilityObject;
274 return owner.AccessibilityObject;
277 case AccessibleNavigation.Right: {
278 if (owner.parent != null) {
279 for (int i=0; i<owner.parent.child_controls.Count; i++) {
280 if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Left>owner.Right)) {
281 return owner.parent.child_controls[i].AccessibilityObject;
286 return owner.AccessibilityObject;
289 // Logical navigation
290 case AccessibleNavigation.Next: {
291 if (owner.parent != null) {
292 if ((index+1)<owner.parent.child_controls.Count) {
293 return owner.parent.child_controls[index+1].AccessibilityObject;
295 return owner.parent.child_controls[0].AccessibilityObject;
298 return owner.AccessibilityObject;
302 case AccessibleNavigation.Previous: {
303 if (owner.parent != null) {
305 return owner.parent.child_controls[index-1].AccessibilityObject;
307 return owner.parent.child_controls[owner.parent.child_controls.Count-1].AccessibilityObject;
310 return owner.AccessibilityObject;
314 case AccessibleNavigation.FirstChild: {
315 if (owner.child_controls.Count>0) {
316 return owner.child_controls[0].AccessibilityObject;
318 return owner.AccessibilityObject;
322 case AccessibleNavigation.LastChild: {
323 if (owner.child_controls.Count>0) {
324 return owner.child_controls[owner.child_controls.Count-1].AccessibilityObject;
326 return owner.AccessibilityObject;
331 return owner.AccessibilityObject;
334 public virtual void Select(AccessibleSelection flags) {
335 if ((flags & AccessibleSelection.TakeFocus) != 0){
340 #endregion // Public Instance Methods
342 #region Protected Instance Methods
343 protected void UseStdAccessibleObjects(IntPtr handle) {
346 protected void UseStdAccessibleObjects(IntPtr handle, int objid) {
347 UseStdAccessibleObjects(handle, 0);
349 #endregion // Protected Instance Methods
352 #region Internal Methods
353 internal static Control FindFocusControl(Control parent) {
356 for (int i=0; i < parent.child_controls.Count; i++) {
357 child=parent.child_controls[i];
358 if (child.has_focus) {
361 if (child.child_controls.Count>0) {
364 result = FindFocusControl(child);
365 if (result != null) {
373 internal static Control FindSelectedControl(Control parent) {
376 for (int i=0; i < parent.child_controls.Count; i++) {
377 child=parent.child_controls[i];
378 if (child.has_focus) {
381 if (child.child_controls.Count>0) {
384 result = FindSelectedControl(child);
385 if (result != null) {
393 internal static Control FindHittestControl(Control parent, int x, int y) {
398 hittest_point = new Point(x, y);
400 child_point = parent.PointToClient(hittest_point);
401 if (parent.ClientRectangle.Contains(child_point)) {
405 for (int i=0; i < parent.child_controls.Count; i++) {
406 child=parent.child_controls[i];
407 child_point = child.PointToClient(hittest_point);
408 if (child.ClientRectangle.Contains(child_point)) {
411 if (child.child_controls.Count>0) {
414 result = FindHittestControl(child, x, y);
415 if (result != null) {
422 #endregion // Internal Methods
424 #region IReflection Methods and Properties
425 FieldInfo IReflect.GetField(String name, BindingFlags bindingAttr) {
426 throw new NotImplementedException();
429 FieldInfo[] IReflect.GetFields(BindingFlags bindingAttr) {
430 throw new NotImplementedException();
433 MemberInfo[] IReflect.GetMember(String name, BindingFlags bindingAttr) {
434 throw new NotImplementedException();
437 MemberInfo[] IReflect.GetMembers(BindingFlags bindingAttr) {
438 throw new NotImplementedException();
441 MethodInfo IReflect.GetMethod(String name, BindingFlags bindingAttr) {
442 throw new NotImplementedException();
445 MethodInfo IReflect.GetMethod(String name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers) {
446 throw new NotImplementedException();
449 MethodInfo[] IReflect.GetMethods(BindingFlags bindingAttr) {
450 throw new NotImplementedException();
453 PropertyInfo IReflect.GetProperty(String name, BindingFlags bindingAttr) {
454 throw new NotImplementedException();
457 PropertyInfo IReflect.GetProperty(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) {
458 throw new NotImplementedException();
461 PropertyInfo[] IReflect.GetProperties(BindingFlags bindingAttr) {
462 throw new NotImplementedException();
465 Object IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) {
466 throw new NotImplementedException();
469 Type IReflect.UnderlyingSystemType {
471 throw new NotImplementedException();
474 #endregion // IReflection Methods and Properties
476 #region IAccessible Methods and Properties
477 void IAccessible.accDoDefaultAction(object childID) {
478 throw new NotImplementedException();
481 int IAccessible.accChildCount {
483 throw new NotImplementedException();
487 object IAccessible.accFocus {
489 throw new NotImplementedException();
493 object IAccessible.accHitTest(int xLeft, int yTop) {
494 throw new NotImplementedException();
497 void IAccessible.accLocation(out int pxLeft, out int pyTop, out int pcxWidth, out int pcyHeight, object childID) {
498 throw new NotImplementedException();
501 object IAccessible.accNavigate(int navDir, object childID) {
502 throw new NotImplementedException();
505 object IAccessible.accParent {
507 throw new NotImplementedException();
511 void IAccessible.accSelect(int flagsSelect, object childID) {
512 throw new NotImplementedException();
515 object IAccessible.accSelection {
517 throw new NotImplementedException();
521 object IAccessible.get_accChild(object childID) {
522 throw new NotImplementedException();
525 string IAccessible.get_accDefaultAction(object childID) {
526 throw new NotImplementedException();
529 string IAccessible.get_accDescription(object childID) {
530 throw new NotImplementedException();
533 string IAccessible.get_accHelp(object childID) {
534 throw new NotImplementedException();
537 int IAccessible.get_accHelpTopic(out string pszHelpFile,object childID) {
538 throw new NotImplementedException();
541 string IAccessible.get_accKeyboardShortcut(object childID) {
542 throw new NotImplementedException();
545 string IAccessible.get_accName(object childID) {
546 throw new NotImplementedException();
549 object IAccessible.get_accRole(object childID) {
550 throw new NotImplementedException();
553 object IAccessible.get_accState(object childID) {
554 throw new NotImplementedException();
557 string IAccessible.get_accValue(object childID) {
558 throw new NotImplementedException();
561 void IAccessible.set_accName(object childID, string newName) {
562 throw new NotImplementedException();
565 void IAccessible.set_accValue(object childID, string newValue) {
566 throw new NotImplementedException();
568 #endregion // IAccessible Methods and Properties