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 {
38 public class AccessibleObject : StandardOleMarshalObject, IReflect, IAccessible {
40 public class AccessibleObject : MarshalByRefObject, IReflect, IAccessible {
42 #region Private Variables
44 internal string value;
45 internal Control owner;
46 internal AccessibleRole role;
47 internal AccessibleStates state;
48 internal string default_action;
49 internal string description;
51 internal string keyboard_shortcut;
52 #endregion // Private Variables
54 #region Public Constructors
55 public AccessibleObject() {
59 this.role = AccessibleRole.Default;
60 this.default_action = null;
61 this.description = null;
63 this.keyboard_shortcut = null;
64 this.state = AccessibleStates.None;
66 #endregion // Public Constructors
68 #region Private Constructors
69 internal AccessibleObject(Control owner) : this () {
72 #endregion // Private Constructors
74 #region Public Instance Properties
75 public virtual Rectangle Bounds {
81 public virtual string DefaultAction {
83 return default_action;
87 public virtual string Description {
93 public virtual string Help {
99 public virtual string KeyboardShortcut {
101 return keyboard_shortcut;
105 public virtual string Name {
115 public virtual AccessibleObject Parent {
117 if ((owner!=null) && (owner.Parent!=null)) {
118 return owner.Parent.AccessibilityObject;
124 public virtual AccessibleRole Role {
130 public virtual AccessibleStates State {
135 state |= AccessibleStates.Focused;
138 if (!owner.Visible) {
139 state |= AccessibleStates.Invisible;
147 public virtual string Value {
156 #endregion // Public Instance Properties
158 #region Public Instance Methods
159 public virtual void DoDefaultAction() {
161 owner.DoDefaultAction();
165 public virtual AccessibleObject GetChild(int index) {
167 if (index<owner.Controls.Count) {
168 return owner.Controls[index].AccessibilityObject;
174 public virtual int GetChildCount() {
176 return owner.Controls.Count;
181 public virtual AccessibleObject GetFocused() {
182 if (owner.has_focus) {
183 return owner.AccessibilityObject;
186 return FindFocusControl(owner);
189 public virtual int GetHelpTopic (out string fileName)
195 public virtual AccessibleObject GetSelected() {
196 if ((state & AccessibleStates.Selected) != 0) {
200 return FindSelectedControl(owner);
203 public virtual AccessibleObject HitTest(int x, int y) {
206 result = FindHittestControl(owner, x, y);
208 if (result != null) {
209 return result.AccessibilityObject;
215 public virtual AccessibleObject Navigate(AccessibleNavigation navdir) {
218 // I'm not throwing exceptions if an object doesn't exist in the specified direction
219 // Might not be too helpful to a blind dude trying to navigate. Instead we return
222 if (owner.Parent != null) {
223 index = owner.Parent.Controls.IndexOf(owner);
229 // Spatial navigation; limited to siblings
230 case AccessibleNavigation.Up: {
231 if (owner.Parent != null) {
232 for (int i=0; i<owner.Parent.Controls.Count; i++) {
233 if ((owner != owner.Parent.Controls[i]) && (owner.Parent.Controls[i].Top<owner.Top)) {
234 return owner.Parent.Controls[i].AccessibilityObject;
239 return owner.AccessibilityObject;
242 case AccessibleNavigation.Down: {
243 if (owner.Parent != null) {
244 for (int i=0; i<owner.Parent.Controls.Count; i++) {
245 if ((owner != owner.Parent.Controls[i]) && (owner.Parent.Controls[i].Top>owner.Bottom)) {
246 return owner.Parent.Controls[i].AccessibilityObject;
251 return owner.AccessibilityObject;
254 case AccessibleNavigation.Left: {
255 if (owner.Parent != null) {
256 for (int i=0; i<owner.Parent.Controls.Count; i++) {
257 if ((owner != owner.Parent.Controls[i]) && (owner.Parent.Controls[i].Left<owner.Left)) {
258 return owner.Parent.Controls[i].AccessibilityObject;
263 return owner.AccessibilityObject;
266 case AccessibleNavigation.Right: {
267 if (owner.Parent != null) {
268 for (int i=0; i<owner.Parent.Controls.Count; i++) {
269 if ((owner != owner.Parent.Controls[i]) && (owner.Parent.Controls[i].Left>owner.Right)) {
270 return owner.Parent.Controls[i].AccessibilityObject;
275 return owner.AccessibilityObject;
278 // Logical navigation
279 case AccessibleNavigation.Next: {
280 if (owner.Parent != null) {
281 if ((index+1)<owner.Parent.Controls.Count) {
282 return owner.Parent.Controls[index+1].AccessibilityObject;
284 return owner.Parent.Controls[0].AccessibilityObject;
287 return owner.AccessibilityObject;
291 case AccessibleNavigation.Previous: {
292 if (owner.Parent != null) {
294 return owner.Parent.Controls[index-1].AccessibilityObject;
296 return owner.Parent.Controls[owner.Parent.Controls.Count-1].AccessibilityObject;
299 return owner.AccessibilityObject;
303 case AccessibleNavigation.FirstChild: {
304 if (owner.Controls.Count>0) {
305 return owner.Controls[0].AccessibilityObject;
307 return owner.AccessibilityObject;
311 case AccessibleNavigation.LastChild: {
312 if (owner.Controls.Count>0) {
313 return owner.Controls[owner.Controls.Count-1].AccessibilityObject;
315 return owner.AccessibilityObject;
320 return owner.AccessibilityObject;
323 public virtual void Select(AccessibleSelection flags) {
324 if ((flags & AccessibleSelection.TakeFocus) != 0){
329 #endregion // Public Instance Methods
331 #region Protected Instance Methods
332 protected void UseStdAccessibleObjects(IntPtr handle) {
335 protected void UseStdAccessibleObjects(IntPtr handle, int objid) {
336 UseStdAccessibleObjects(handle, 0);
338 #endregion // Protected Instance Methods
341 #region Internal Methods
342 internal static AccessibleObject FindFocusControl(Control parent) {
345 if (parent != null) {
346 for (int i=0; i < parent.Controls.Count; i++) {
347 child = parent.Controls[i];
348 if ((child.AccessibilityObject.state & AccessibleStates.Focused) != 0) {
349 return child.AccessibilityObject;
352 if (child.Controls.Count>0) {
353 AccessibleObject result;
355 result = FindFocusControl(child);
356 if (result != null) {
365 internal static AccessibleObject FindSelectedControl(Control parent) {
368 if (parent != null) {
369 for (int i=0; i < parent.Controls.Count; i++) {
370 child = parent.Controls[i];
371 if ((child.AccessibilityObject.state & AccessibleStates.Selected) != 0) {
372 return child.AccessibilityObject;
374 if (child.Controls.Count>0) {
375 AccessibleObject result;
377 result = FindSelectedControl(child);
378 if (result != null) {
387 internal static Control FindHittestControl(Control parent, int x, int y) {
392 hittest_point = new Point(x, y);
394 child_point = parent.PointToClient(hittest_point);
395 if (parent.ClientRectangle.Contains(child_point)) {
399 for (int i=0; i < parent.Controls.Count; i++) {
400 child=parent.Controls[i];
401 child_point = child.PointToClient(hittest_point);
402 if (child.ClientRectangle.Contains(child_point)) {
405 if (child.Controls.Count>0) {
408 result = FindHittestControl(child, x, y);
409 if (result != null) {
416 #endregion // Internal Methods
418 #region IReflection Methods and Properties
419 FieldInfo IReflect.GetField(String name, BindingFlags bindingAttr) {
420 throw new NotImplementedException();
423 FieldInfo[] IReflect.GetFields(BindingFlags bindingAttr) {
424 throw new NotImplementedException();
427 MemberInfo[] IReflect.GetMember(String name, BindingFlags bindingAttr) {
428 throw new NotImplementedException();
431 MemberInfo[] IReflect.GetMembers(BindingFlags bindingAttr) {
432 throw new NotImplementedException();
435 MethodInfo IReflect.GetMethod(String name, BindingFlags bindingAttr) {
436 throw new NotImplementedException();
439 MethodInfo IReflect.GetMethod(String name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers) {
440 throw new NotImplementedException();
443 MethodInfo[] IReflect.GetMethods(BindingFlags bindingAttr) {
444 throw new NotImplementedException();
447 PropertyInfo IReflect.GetProperty(String name, BindingFlags bindingAttr) {
448 throw new NotImplementedException();
451 PropertyInfo IReflect.GetProperty(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) {
452 throw new NotImplementedException();
455 PropertyInfo[] IReflect.GetProperties(BindingFlags bindingAttr) {
456 throw new NotImplementedException();
459 Object IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) {
460 throw new NotImplementedException();
463 Type IReflect.UnderlyingSystemType {
465 throw new NotImplementedException();
468 #endregion // IReflection Methods and Properties
470 #region IAccessible Methods and Properties
471 void IAccessible.accDoDefaultAction(object childID) {
472 throw new NotImplementedException();
475 int IAccessible.accChildCount {
477 throw new NotImplementedException();
481 object IAccessible.accFocus {
483 throw new NotImplementedException();
487 object IAccessible.accHitTest(int xLeft, int yTop) {
488 throw new NotImplementedException();
491 void IAccessible.accLocation(out int pxLeft, out int pyTop, out int pcxWidth, out int pcyHeight, object childID) {
492 throw new NotImplementedException();
495 object IAccessible.accNavigate(int navDir, object childID) {
496 throw new NotImplementedException();
499 object IAccessible.accParent {
501 throw new NotImplementedException();
505 void IAccessible.accSelect(int flagsSelect, object childID) {
506 throw new NotImplementedException();
509 object IAccessible.accSelection {
511 throw new NotImplementedException();
515 object IAccessible.get_accChild(object childID) {
516 throw new NotImplementedException();
519 string IAccessible.get_accDefaultAction(object childID) {
520 throw new NotImplementedException();
523 string IAccessible.get_accDescription(object childID) {
524 throw new NotImplementedException();
527 string IAccessible.get_accHelp(object childID) {
528 throw new NotImplementedException();
531 int IAccessible.get_accHelpTopic(out string pszHelpFile,object childID) {
532 throw new NotImplementedException();
535 string IAccessible.get_accKeyboardShortcut(object childID) {
536 throw new NotImplementedException();
539 string IAccessible.get_accName(object childID) {
540 throw new NotImplementedException();
543 object IAccessible.get_accRole(object childID) {
544 throw new NotImplementedException();
547 object IAccessible.get_accState(object childID) {
548 throw new NotImplementedException();
551 string IAccessible.get_accValue(object childID) {
552 throw new NotImplementedException();
555 void IAccessible.set_accName(object childID, string newName) {
556 throw new NotImplementedException();
559 void IAccessible.set_accValue(object childID, string newValue) {
560 throw new NotImplementedException();
562 #endregion // IAccessible Methods and Properties