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
26 // $Log: AccessibleObject.cs,v $
27 // Revision 1.3 2004/09/02 20:25:21 pbartok
28 // - Added missing methods
30 // Revision 1.2 2004/08/11 13:44:33 pbartok
31 // - Fixed to match ControlCollection rewrite
33 // Revision 1.1 2004/07/09 05:21:25 pbartok
42 using System.Globalization;
43 using System.Reflection;
44 using System.Runtime.InteropServices;
46 namespace System.Windows.Forms {
47 public class AccessibleObject : MarshalByRefObject, IReflect, IAccessible {
48 #region Private Variables
51 private Control owner;
52 internal AccessibleRole role;
53 internal string default_action;
54 internal string description;
56 internal string keyboard_shortcut;
57 #endregion // Private Variables
59 #region Public Constructors
60 public AccessibleObject() {
64 this.role=AccessibleRole.Default;
65 this.default_action=null;
66 this.description=null;
68 this.keyboard_shortcut=null;
70 #endregion // Public Constructors
72 #region Private Constructors
73 internal AccessibleObject(Control owner) : this () {
76 #endregion // Private Constructors
78 #region Public Instance Properties
79 public virtual Rectangle Bounds {
81 return Rectangle.Empty;
85 public virtual string DefaultAction {
87 return default_action;
91 public virtual string Description {
97 public virtual string Help {
103 public virtual string KeyboardShortcut {
105 return keyboard_shortcut;
109 public virtual string Name {
119 public virtual AccessibleObject Parent {
121 if ((owner!=null) && (owner.Parent!=null)) {
122 return owner.Parent.AccessibilityObject;
128 public virtual AccessibleRole Role {
134 public virtual AccessibleStates State {
136 AccessibleStates state=AccessibleStates.None;
140 state |= AccessibleStates.Focused;
143 if (!owner.Visible) {
144 state |= AccessibleStates.Invisible;
151 public virtual string Value {
160 #endregion // Public Instance Properties
162 #region Public Instance Methods
163 public virtual void DoDefaultAction() {
165 owner.DoDefaultAction();
169 public virtual AccessibleObject GetChild(int index) {
171 if (index<owner.child_controls.Count) {
172 return owner.child_controls[index].AccessibilityObject;
178 public virtual int GetChildCount() {
180 return owner.child_controls.Count;
185 public virtual AccessibleObject GetFocused() {
188 if (owner.has_focus) {
189 return owner.AccessibilityObject;
192 result = FindFocusControl(owner);
194 if (result != null) {
195 return result.AccessibilityObject;
201 [MonoTODO("Integrate help into accessibility system")]
202 public virtual int GetHelpTopic(out string FileName) {
209 public virtual AccessibleObject GetSelected() {
212 if (owner.is_selected) {
213 return owner.AccessibilityObject;
216 result = FindSelectedControl(owner);
218 if (result != null) {
219 return result.AccessibilityObject;
225 public virtual AccessibleObject HitTest(int x, int y) {
228 result = FindHittestControl(owner, x, y);
230 if (result != null) {
231 return result.AccessibilityObject;
237 public virtual AccessibleObject Navigate(AccessibleNavigation navdir) {
240 // I'm not throwing exceptions if an object doesn't exist in the specified direction
241 // Might not be too helpful to a blind dude trying to navigate. Instead we return
244 if (owner.parent != null) {
245 index = owner.parent.child_controls.IndexOf(owner);
251 // Spatial navigation; limited to siblings
252 case AccessibleNavigation.Up: {
253 if (owner.parent != null) {
254 for (int i=0; i<owner.parent.child_controls.Count; i++) {
255 if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Top<owner.Top)) {
256 return owner.parent.child_controls[i].AccessibilityObject;
261 return owner.AccessibilityObject;
264 case AccessibleNavigation.Down: {
265 if (owner.parent != null) {
266 for (int i=0; i<owner.parent.child_controls.Count; i++) {
267 if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Top>owner.Bottom)) {
268 return owner.parent.child_controls[i].AccessibilityObject;
273 return owner.AccessibilityObject;
276 case AccessibleNavigation.Left: {
277 if (owner.parent != null) {
278 for (int i=0; i<owner.parent.child_controls.Count; i++) {
279 if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Left<owner.Left)) {
280 return owner.parent.child_controls[i].AccessibilityObject;
285 return owner.AccessibilityObject;
288 case AccessibleNavigation.Right: {
289 if (owner.parent != null) {
290 for (int i=0; i<owner.parent.child_controls.Count; i++) {
291 if ((owner != owner.parent.child_controls[i]) && (owner.parent.child_controls[i].Left>owner.Right)) {
292 return owner.parent.child_controls[i].AccessibilityObject;
297 return owner.AccessibilityObject;
300 // Logical navigation
301 case AccessibleNavigation.Next: {
302 if (owner.parent != null) {
303 if ((index+1)<owner.parent.child_controls.Count) {
304 return owner.parent.child_controls[index+1].AccessibilityObject;
306 return owner.parent.child_controls[0].AccessibilityObject;
309 return owner.AccessibilityObject;
313 case AccessibleNavigation.Previous: {
314 if (owner.parent != null) {
316 return owner.parent.child_controls[index-1].AccessibilityObject;
318 return owner.parent.child_controls[owner.parent.child_controls.Count-1].AccessibilityObject;
321 return owner.AccessibilityObject;
325 case AccessibleNavigation.FirstChild: {
326 if (owner.child_controls.Count>0) {
327 return owner.child_controls[0].AccessibilityObject;
329 return owner.AccessibilityObject;
333 case AccessibleNavigation.LastChild: {
334 if (owner.child_controls.Count>0) {
335 return owner.child_controls[owner.child_controls.Count-1].AccessibilityObject;
337 return owner.AccessibilityObject;
342 return owner.AccessibilityObject;
345 [MonoTODO("Finish Select when Control.Select is complete")]
346 public virtual void Select(AccessibleSelection flags) {
347 if ((flags & AccessibleSelection.TakeFocus) != 0){
348 owner.has_focus = true;
353 #endregion // Public Instance Methods
355 #region Protected Instance Methods
356 protected void UseStdAccessibleObjects(IntPtr handle) {
359 protected void UseStdAccessibleObjects(IntPtr handle, int objid) {
360 UseStdAccessibleObjects(handle, 0);
362 #endregion // Protected Instance Methods
365 #region Internal Methods
366 internal static Control FindFocusControl(Control parent) {
369 for (int i=0; i < parent.child_controls.Count; i++) {
370 child=parent.child_controls[i];
371 if (child.has_focus) {
374 if (child.child_controls.Count>0) {
377 result = FindFocusControl(child);
378 if (result != null) {
386 internal static Control FindSelectedControl(Control parent) {
389 for (int i=0; i < parent.child_controls.Count; i++) {
390 child=parent.child_controls[i];
391 if (child.has_focus) {
394 if (child.child_controls.Count>0) {
397 result = FindSelectedControl(child);
398 if (result != null) {
406 internal static Control FindHittestControl(Control parent, int x, int y) {
411 hittest_point = new Point(x, y);
413 child_point = parent.PointToClient(hittest_point);
414 if (parent.ClientRectangle.Contains(child_point)) {
418 for (int i=0; i < parent.child_controls.Count; i++) {
419 child=parent.child_controls[i];
420 child_point = child.PointToClient(hittest_point);
421 if (child.ClientRectangle.Contains(child_point)) {
424 if (child.child_controls.Count>0) {
427 result = FindHittestControl(child, x, y);
428 if (result != null) {
435 #endregion // Internal Methods
437 #region IReflection Methods and Properties
438 FieldInfo IReflect.GetField(String name, BindingFlags bindingAttr) {
439 throw new NotImplementedException();
442 FieldInfo[] IReflect.GetFields(BindingFlags bindingAttr) {
443 throw new NotImplementedException();
446 MemberInfo[] IReflect.GetMember(String name, BindingFlags bindingAttr) {
447 throw new NotImplementedException();
450 MemberInfo[] IReflect.GetMembers(BindingFlags bindingAttr) {
451 throw new NotImplementedException();
454 MethodInfo IReflect.GetMethod(String name, BindingFlags bindingAttr) {
455 throw new NotImplementedException();
458 MethodInfo IReflect.GetMethod(String name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers) {
459 throw new NotImplementedException();
462 MethodInfo[] IReflect.GetMethods(BindingFlags bindingAttr) {
463 throw new NotImplementedException();
466 PropertyInfo IReflect.GetProperty(String name, BindingFlags bindingAttr) {
467 throw new NotImplementedException();
470 PropertyInfo IReflect.GetProperty(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) {
471 throw new NotImplementedException();
474 PropertyInfo[] IReflect.GetProperties(BindingFlags bindingAttr) {
475 throw new NotImplementedException();
478 Object IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) {
479 throw new NotImplementedException();
482 Type IReflect.UnderlyingSystemType {
484 throw new NotImplementedException();
487 #endregion // IReflection Methods and Properties
489 #region IAccessible Methods and Properties
490 void IAccessible.accDoDefaultAction(object childID) {
491 throw new NotImplementedException();
494 int IAccessible.accChildCount {
496 throw new NotImplementedException();
500 object IAccessible.accFocus {
502 throw new NotImplementedException();
506 object IAccessible.accHitTest(int xLeft, int yTop) {
507 throw new NotImplementedException();
510 void IAccessible.accLocation(out int pxLeft, out int pyTop, out int pcxWidth, out int pcyHeight, object childID) {
511 throw new NotImplementedException();
514 object IAccessible.accNavigate(int navDir, object childID) {
515 throw new NotImplementedException();
518 object IAccessible.accParent {
520 throw new NotImplementedException();
524 void IAccessible.accSelect(int flagsSelect, object childID) {
525 throw new NotImplementedException();
528 object IAccessible.accSelection {
530 throw new NotImplementedException();
534 object IAccessible.get_accChild(object childID) {
535 throw new NotImplementedException();
538 string IAccessible.get_accDefaultAction(object childID) {
539 throw new NotImplementedException();
542 string IAccessible.get_accDescription(object childID) {
543 throw new NotImplementedException();
546 string IAccessible.get_accHelp(object childID) {
547 throw new NotImplementedException();
550 int IAccessible.get_accHelpTopic(out string pszHelpFile,object childID) {
551 throw new NotImplementedException();
554 string IAccessible.get_accKeyboardShortcut(object childID) {
555 throw new NotImplementedException();
558 string IAccessible.get_accName(object childID) {
559 throw new NotImplementedException();
562 object IAccessible.get_accRole(object childID) {
563 throw new NotImplementedException();
566 object IAccessible.get_accState(object childID) {
567 throw new NotImplementedException();
570 string IAccessible.get_accValue(object childID) {
571 throw new NotImplementedException();
574 void IAccessible.set_accName(object childID, string newName) {
575 throw new NotImplementedException();
578 void IAccessible.set_accValue(object childID, string newValue) {
579 throw new NotImplementedException();
581 #endregion // IAccessible Methods and Properties