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 : MarshalByRefObject, IReflect, IAccessible {
38 #region Private Variables
40 internal string value;
41 private 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 {
131 state |= AccessibleStates.Focused;
134 if (!owner.Visible) {
135 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) {
192 public virtual AccessibleObject GetSelected() {
193 if ((state & AccessibleStates.Selected) != 0) {
197 return FindSelectedControl(owner);
200 public virtual AccessibleObject HitTest(int x, int y) {
203 result = FindHittestControl(owner, x, y);
205 if (result != null) {
206 return result.AccessibilityObject;
212 public virtual AccessibleObject Navigate(AccessibleNavigation navdir) {
215 // I'm not throwing exceptions if an object doesn't exist in the specified direction
216 // Might not be too helpful to a blind dude trying to navigate. Instead we return
219 if (owner.Parent != null) {
220 index = owner.Parent.Controls.IndexOf(owner);
226 // Spatial navigation; limited to siblings
227 case AccessibleNavigation.Up: {
228 if (owner.Parent != null) {
229 for (int i=0; i<owner.Parent.Controls.Count; i++) {
230 if ((owner != owner.Parent.Controls[i]) && (owner.Parent.Controls[i].Top<owner.Top)) {
231 return owner.Parent.Controls[i].AccessibilityObject;
236 return owner.AccessibilityObject;
239 case AccessibleNavigation.Down: {
240 if (owner.Parent != null) {
241 for (int i=0; i<owner.Parent.Controls.Count; i++) {
242 if ((owner != owner.Parent.Controls[i]) && (owner.Parent.Controls[i].Top>owner.Bottom)) {
243 return owner.Parent.Controls[i].AccessibilityObject;
248 return owner.AccessibilityObject;
251 case AccessibleNavigation.Left: {
252 if (owner.Parent != null) {
253 for (int i=0; i<owner.Parent.Controls.Count; i++) {
254 if ((owner != owner.Parent.Controls[i]) && (owner.Parent.Controls[i].Left<owner.Left)) {
255 return owner.Parent.Controls[i].AccessibilityObject;
260 return owner.AccessibilityObject;
263 case AccessibleNavigation.Right: {
264 if (owner.Parent != null) {
265 for (int i=0; i<owner.Parent.Controls.Count; i++) {
266 if ((owner != owner.Parent.Controls[i]) && (owner.Parent.Controls[i].Left>owner.Right)) {
267 return owner.Parent.Controls[i].AccessibilityObject;
272 return owner.AccessibilityObject;
275 // Logical navigation
276 case AccessibleNavigation.Next: {
277 if (owner.Parent != null) {
278 if ((index+1)<owner.Parent.Controls.Count) {
279 return owner.Parent.Controls[index+1].AccessibilityObject;
281 return owner.Parent.Controls[0].AccessibilityObject;
284 return owner.AccessibilityObject;
288 case AccessibleNavigation.Previous: {
289 if (owner.Parent != null) {
291 return owner.Parent.Controls[index-1].AccessibilityObject;
293 return owner.Parent.Controls[owner.Parent.Controls.Count-1].AccessibilityObject;
296 return owner.AccessibilityObject;
300 case AccessibleNavigation.FirstChild: {
301 if (owner.Controls.Count>0) {
302 return owner.Controls[0].AccessibilityObject;
304 return owner.AccessibilityObject;
308 case AccessibleNavigation.LastChild: {
309 if (owner.Controls.Count>0) {
310 return owner.Controls[owner.Controls.Count-1].AccessibilityObject;
312 return owner.AccessibilityObject;
317 return owner.AccessibilityObject;
320 public virtual void Select(AccessibleSelection flags) {
321 if ((flags & AccessibleSelection.TakeFocus) != 0){
326 #endregion // Public Instance Methods
328 #region Protected Instance Methods
329 protected void UseStdAccessibleObjects(IntPtr handle) {
332 protected void UseStdAccessibleObjects(IntPtr handle, int objid) {
333 UseStdAccessibleObjects(handle, 0);
335 #endregion // Protected Instance Methods
338 #region Internal Methods
339 internal static AccessibleObject FindFocusControl(Control parent) {
342 if (parent != null) {
343 for (int i=0; i < parent.Controls.Count; i++) {
344 child = parent.Controls[i];
345 if ((child.AccessibilityObject.state & AccessibleStates.Focused) != 0) {
346 return child.AccessibilityObject;
349 if (child.Controls.Count>0) {
350 AccessibleObject result;
352 result = FindFocusControl(child);
353 if (result != null) {
362 internal static AccessibleObject FindSelectedControl(Control parent) {
365 if (parent != null) {
366 for (int i=0; i < parent.Controls.Count; i++) {
367 child = parent.Controls[i];
368 if ((child.AccessibilityObject.state & AccessibleStates.Selected) != 0) {
369 return child.AccessibilityObject;
371 if (child.Controls.Count>0) {
372 AccessibleObject result;
374 result = FindSelectedControl(child);
375 if (result != null) {
384 internal static Control FindHittestControl(Control parent, int x, int y) {
389 hittest_point = new Point(x, y);
391 child_point = parent.PointToClient(hittest_point);
392 if (parent.ClientRectangle.Contains(child_point)) {
396 for (int i=0; i < parent.Controls.Count; i++) {
397 child=parent.Controls[i];
398 child_point = child.PointToClient(hittest_point);
399 if (child.ClientRectangle.Contains(child_point)) {
402 if (child.Controls.Count>0) {
405 result = FindHittestControl(child, x, y);
406 if (result != null) {
413 #endregion // Internal Methods
415 #region IReflection Methods and Properties
416 FieldInfo IReflect.GetField(String name, BindingFlags bindingAttr) {
417 throw new NotImplementedException();
420 FieldInfo[] IReflect.GetFields(BindingFlags bindingAttr) {
421 throw new NotImplementedException();
424 MemberInfo[] IReflect.GetMember(String name, BindingFlags bindingAttr) {
425 throw new NotImplementedException();
428 MemberInfo[] IReflect.GetMembers(BindingFlags bindingAttr) {
429 throw new NotImplementedException();
432 MethodInfo IReflect.GetMethod(String name, BindingFlags bindingAttr) {
433 throw new NotImplementedException();
436 MethodInfo IReflect.GetMethod(String name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers) {
437 throw new NotImplementedException();
440 MethodInfo[] IReflect.GetMethods(BindingFlags bindingAttr) {
441 throw new NotImplementedException();
444 PropertyInfo IReflect.GetProperty(String name, BindingFlags bindingAttr) {
445 throw new NotImplementedException();
448 PropertyInfo IReflect.GetProperty(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) {
449 throw new NotImplementedException();
452 PropertyInfo[] IReflect.GetProperties(BindingFlags bindingAttr) {
453 throw new NotImplementedException();
456 Object IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) {
457 throw new NotImplementedException();
460 Type IReflect.UnderlyingSystemType {
462 throw new NotImplementedException();
465 #endregion // IReflection Methods and Properties
467 #region IAccessible Methods and Properties
468 void IAccessible.accDoDefaultAction(object childID) {
469 throw new NotImplementedException();
472 int IAccessible.accChildCount {
474 throw new NotImplementedException();
478 object IAccessible.accFocus {
480 throw new NotImplementedException();
484 object IAccessible.accHitTest(int xLeft, int yTop) {
485 throw new NotImplementedException();
488 void IAccessible.accLocation(out int pxLeft, out int pyTop, out int pcxWidth, out int pcyHeight, object childID) {
489 throw new NotImplementedException();
492 object IAccessible.accNavigate(int navDir, object childID) {
493 throw new NotImplementedException();
496 object IAccessible.accParent {
498 throw new NotImplementedException();
502 void IAccessible.accSelect(int flagsSelect, object childID) {
503 throw new NotImplementedException();
506 object IAccessible.accSelection {
508 throw new NotImplementedException();
512 object IAccessible.get_accChild(object childID) {
513 throw new NotImplementedException();
516 string IAccessible.get_accDefaultAction(object childID) {
517 throw new NotImplementedException();
520 string IAccessible.get_accDescription(object childID) {
521 throw new NotImplementedException();
524 string IAccessible.get_accHelp(object childID) {
525 throw new NotImplementedException();
528 int IAccessible.get_accHelpTopic(out string pszHelpFile,object childID) {
529 throw new NotImplementedException();
532 string IAccessible.get_accKeyboardShortcut(object childID) {
533 throw new NotImplementedException();
536 string IAccessible.get_accName(object childID) {
537 throw new NotImplementedException();
540 object IAccessible.get_accRole(object childID) {
541 throw new NotImplementedException();
544 object IAccessible.get_accState(object childID) {
545 throw new NotImplementedException();
548 string IAccessible.get_accValue(object childID) {
549 throw new NotImplementedException();
552 void IAccessible.set_accName(object childID, string newName) {
553 throw new NotImplementedException();
556 void IAccessible.set_accValue(object childID, string newValue) {
557 throw new NotImplementedException();
559 #endregion // IAccessible Methods and Properties