Merge pull request #1275 from ranma42/fix-lib64
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / AccessibleObject.cs
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:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
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.
19 //
20 // Copyright (c) 2004-2006 Novell, Inc.
21 //
22 // Authors:
23 //      Peter Dennis Bartok     pbartok@novell.com
24 //
25
26
27 // NOT COMPLETE
28
29 using Accessibility;
30 using System.Drawing;
31 using System.Globalization;
32 using System.Reflection;
33 using System.Runtime.InteropServices;
34
35 namespace System.Windows.Forms {
36         [ComVisible(true)]
37         public class AccessibleObject : StandardOleMarshalObject, IReflect, IAccessible {
38                 #region Private Variables
39                 internal string         name;
40                 internal string         value;
41                 internal Control owner;
42                 internal AccessibleRole role;
43                 internal AccessibleStates       state;
44                 internal string         default_action;
45                 internal string         description;
46                 internal string         help;
47                 internal string         keyboard_shortcut;
48                 #endregion      // Private Variables
49
50                 #region Public Constructors
51                 public AccessibleObject() {
52                         this.owner = null;
53                         this.value = null;
54                         this.name = null;
55                         this.role = AccessibleRole.Default;
56                         this.default_action = null;
57                         this.description = null;
58                         this.help = null;
59                         this.keyboard_shortcut = null;
60                         this.state = AccessibleStates.None;
61                 }
62                 #endregion      // Public Constructors
63
64                 #region Private Constructors
65                 internal AccessibleObject(Control owner) : this () {
66                         this.owner=owner;
67                 }
68                 #endregion      // Private Constructors
69
70                 #region Public Instance Properties
71                 public virtual Rectangle Bounds {
72                         get {
73                                 return owner.Bounds;
74                         }
75                 }
76
77                 public virtual string DefaultAction {
78                         get {
79                                 return default_action;
80                         }
81                 }
82
83                 public virtual string Description {
84                         get {
85                                 return description;
86                         }
87                 }
88
89                 public virtual string Help {
90                         get {
91                                 return help;
92                         }
93                 }
94
95                 public virtual string KeyboardShortcut {
96                         get {
97                                 return keyboard_shortcut;
98                         }
99                 }
100
101                 public virtual string Name {
102                         get {
103                                 return name;
104                         }
105
106                         set {
107                                 name=value;
108                         }
109                 }
110
111                 public virtual AccessibleObject Parent {
112                         get {
113                                 if ((owner!=null) && (owner.Parent!=null)) {
114                                         return owner.Parent.AccessibilityObject;
115                                 }
116                                 return null;
117                         }
118                 }
119
120                 public virtual AccessibleRole Role {
121                         get {
122                                 return role;
123                         }
124                 }
125
126                 public virtual AccessibleStates State {
127                         get {
128 #if not
129                                 if (owner!=null) {
130                                         if (owner.Focused) {
131                                                 state |= AccessibleStates.Focused;
132                                         }
133
134                                         if (!owner.Visible) {
135                                                 state |= AccessibleStates.Invisible;
136                                         }
137                                 }
138 #endif
139                                 return state;
140                         }
141                 }
142
143                 public virtual string Value {
144                         get {
145                                 return this.value;
146                         }
147
148                         set {
149                                 this.value=value;
150                         }
151                 }
152                 #endregion      // Public Instance Properties
153
154                 #region Public Instance Methods
155                 public virtual void DoDefaultAction() {
156                         if (owner!=null) {
157                                 owner.DoDefaultAction();
158                         }
159                 }
160
161                 public virtual AccessibleObject GetChild(int index) {
162                         if (owner!=null) {
163                                 if (index<owner.Controls.Count) {
164                                         return owner.Controls[index].AccessibilityObject;
165                                 }
166                         }
167                         return null;
168                 }
169
170                 public virtual int GetChildCount() {
171                         if (owner!=null) {
172                                 return owner.Controls.Count;
173                         }
174                         return -1;
175                 }
176
177                 public virtual AccessibleObject GetFocused() {
178                         if (owner.has_focus) {
179                                 return owner.AccessibilityObject;
180                         }
181
182                         return FindFocusControl(owner);
183                 }
184
185                 public virtual int GetHelpTopic (out string fileName)
186                 {
187                         fileName = null;
188                         return -1;
189                 }
190
191                 public virtual AccessibleObject GetSelected() {
192                         if ((state & AccessibleStates.Selected) != 0) {
193                                 return this;
194                         }
195
196                         return FindSelectedControl(owner);
197                 }
198
199                 public virtual AccessibleObject HitTest(int x, int y) {
200                         Control result;
201
202                         result = FindHittestControl(owner, x, y);
203
204                         if (result != null) {
205                                 return result.AccessibilityObject;
206                         }
207
208                         return null;
209                 }
210
211                 public virtual AccessibleObject Navigate(AccessibleNavigation navdir) {
212                         int     index;
213
214                         // I'm not throwing exceptions if an object doesn't exist in the specified direction
215                         // Might not be too helpful to a blind dude trying to navigate. Instead we return
216                         // our own object
217
218                         if (owner.Parent != null) {
219                                 index = owner.Parent.Controls.IndexOf(owner);
220                         } else {
221                                 index = -1;
222                         }
223
224                         switch (navdir) {
225                                 // Spatial navigation; limited to siblings
226                                 case AccessibleNavigation.Up: {
227                                         if (owner.Parent != null) {
228                                                 for (int i=0; i<owner.Parent.Controls.Count; i++) {
229                                                         if ((owner != owner.Parent.Controls[i]) && (owner.Parent.Controls[i].Top<owner.Top)) {
230                                                                 return owner.Parent.Controls[i].AccessibilityObject;
231                                                         }
232                                                 }
233                                                 
234                                         }
235                                         return owner.AccessibilityObject;
236                                 }
237
238                                 case AccessibleNavigation.Down: {
239                                         if (owner.Parent != null) {
240                                                 for (int i=0; i<owner.Parent.Controls.Count; i++) {
241                                                         if ((owner != owner.Parent.Controls[i]) && (owner.Parent.Controls[i].Top>owner.Bottom)) {
242                                                                 return owner.Parent.Controls[i].AccessibilityObject;
243                                                         }
244                                                 }
245                                                 
246                                         }
247                                         return owner.AccessibilityObject;
248                                 }
249
250                                 case AccessibleNavigation.Left: {
251                                         if (owner.Parent != null) {
252                                                 for (int i=0; i<owner.Parent.Controls.Count; i++) {
253                                                         if ((owner != owner.Parent.Controls[i]) && (owner.Parent.Controls[i].Left<owner.Left)) {
254                                                                 return owner.Parent.Controls[i].AccessibilityObject;
255                                                         }
256                                                 }
257                                                 
258                                         }
259                                         return owner.AccessibilityObject;
260                                 }
261
262                                 case AccessibleNavigation.Right: {
263                                         if (owner.Parent != null) {
264                                                 for (int i=0; i<owner.Parent.Controls.Count; i++) {
265                                                         if ((owner != owner.Parent.Controls[i]) && (owner.Parent.Controls[i].Left>owner.Right)) {
266                                                                 return owner.Parent.Controls[i].AccessibilityObject;
267                                                         }
268                                                 }
269                                                 
270                                         }
271                                         return owner.AccessibilityObject;
272                                 }
273
274                                 // Logical navigation
275                                 case AccessibleNavigation.Next: {
276                                         if (owner.Parent != null) {
277                                                 if ((index+1)<owner.Parent.Controls.Count) {
278                                                         return owner.Parent.Controls[index+1].AccessibilityObject;
279                                                 } else {
280                                                         return owner.Parent.Controls[0].AccessibilityObject;
281                                                 }
282                                         } else {
283                                                 return owner.AccessibilityObject;
284                                         }
285                                 }
286
287                                 case AccessibleNavigation.Previous: {
288                                         if (owner.Parent != null) {
289                                                 if (index>0) {
290                                                         return owner.Parent.Controls[index-1].AccessibilityObject;
291                                                 } else {
292                                                         return owner.Parent.Controls[owner.Parent.Controls.Count-1].AccessibilityObject;
293                                                 }
294                                         } else {
295                                                 return owner.AccessibilityObject;
296                                         }
297                                 }
298
299                                 case AccessibleNavigation.FirstChild: {
300                                         if (owner.Controls.Count>0) {
301                                                 return owner.Controls[0].AccessibilityObject;
302                                         } else {
303                                                 return owner.AccessibilityObject;
304                                         }
305                                 }
306
307                                 case AccessibleNavigation.LastChild: {
308                                         if (owner.Controls.Count>0) {
309                                                 return owner.Controls[owner.Controls.Count-1].AccessibilityObject;
310                                         } else {
311                                                 return owner.AccessibilityObject;
312                                         }
313                                 }
314                         }
315
316                         return owner.AccessibilityObject;
317                 }
318
319                 public virtual void Select(AccessibleSelection flags) {
320                         if ((flags & AccessibleSelection.TakeFocus) != 0){
321                                 owner.Focus();
322                         }
323                         return;
324                 }
325                 #endregion      // Public Instance Methods
326
327                 #region Protected Instance Methods
328                 protected void UseStdAccessibleObjects(IntPtr handle) {
329                 }
330
331                 protected void UseStdAccessibleObjects(IntPtr handle, int objid) {
332                         UseStdAccessibleObjects(handle, 0);
333                 }
334                 #endregion      // Protected Instance Methods
335
336
337                 #region Internal Methods
338                 internal static AccessibleObject FindFocusControl(Control parent) {
339                         Control child;
340
341                         if (parent != null) {
342                                 for (int i=0; i < parent.Controls.Count; i++) {
343                                         child = parent.Controls[i];
344                                         if ((child.AccessibilityObject.state & AccessibleStates.Focused) != 0) {
345                                                 return child.AccessibilityObject;
346                                         }
347
348                                         if (child.Controls.Count>0) {
349                                                 AccessibleObject result;
350
351                                                 result = FindFocusControl(child);
352                                                 if (result != null) {
353                                                         return result;
354                                                 }
355                                         }
356                                 }
357                         }
358                         return null;
359                 }
360
361                 internal static AccessibleObject FindSelectedControl(Control parent) {
362                         Control child;
363
364                         if (parent != null) {
365                                 for (int i=0; i < parent.Controls.Count; i++) {
366                                         child = parent.Controls[i];
367                                         if ((child.AccessibilityObject.state & AccessibleStates.Selected) != 0) {
368                                                 return child.AccessibilityObject;
369                                         }
370                                         if (child.Controls.Count>0) {
371                                                 AccessibleObject result;
372
373                                                 result = FindSelectedControl(child);
374                                                 if (result != null) {
375                                                         return result;
376                                                 }
377                                         }
378                                 }
379                         }
380                         return null;
381                 }
382
383                 internal static Control FindHittestControl(Control parent, int x, int y) {
384                         Control child;
385                         Point   child_point;
386                         Point   hittest_point;
387
388                         hittest_point = new Point(x, y);
389
390                         child_point = parent.PointToClient(hittest_point);
391                         if (parent.ClientRectangle.Contains(child_point)) {
392                                 return parent;
393                         }
394
395                         for (int i=0; i < parent.Controls.Count; i++) {
396                                 child=parent.Controls[i];
397                                 child_point = child.PointToClient(hittest_point);
398                                 if (child.ClientRectangle.Contains(child_point)) {
399                                         return child;
400                                 }
401                                 if (child.Controls.Count>0) {
402                                         Control result;
403
404                                         result = FindHittestControl(child, x, y);
405                                         if (result != null) {
406                                                 return result;
407                                         }
408                                 }
409                         }
410                         return null;
411                 }
412                 #endregion      // Internal Methods
413
414                 #region IReflection Methods and Properties
415                 FieldInfo IReflect.GetField(String name, BindingFlags bindingAttr) {
416                         throw new NotImplementedException();
417                 }       
418
419                 FieldInfo[] IReflect.GetFields(BindingFlags bindingAttr) {
420                         throw new NotImplementedException();
421                 }    
422
423                 MemberInfo[] IReflect.GetMember(String name, BindingFlags bindingAttr) {
424                         throw new NotImplementedException();
425                 }
426
427                 MemberInfo[] IReflect.GetMembers(BindingFlags bindingAttr) {
428                         throw new NotImplementedException();
429                 }
430
431                 MethodInfo IReflect.GetMethod(String name, BindingFlags bindingAttr) {
432                         throw new NotImplementedException();
433                 }
434
435                 MethodInfo IReflect.GetMethod(String name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers) {
436                         throw new NotImplementedException();
437                 }
438
439                 MethodInfo[] IReflect.GetMethods(BindingFlags bindingAttr) {
440                         throw new NotImplementedException();
441                 }
442
443                 PropertyInfo IReflect.GetProperty(String name, BindingFlags bindingAttr) {
444                         throw new NotImplementedException();
445                 }
446
447                 PropertyInfo IReflect.GetProperty(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) {
448                         throw new NotImplementedException();
449                 }
450
451                 PropertyInfo[] IReflect.GetProperties(BindingFlags bindingAttr) {
452                         throw new NotImplementedException();
453                 }
454
455                 Object IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) {
456                         throw new NotImplementedException();
457                 }
458
459                 Type IReflect.UnderlyingSystemType {
460                         get {
461                                 throw new NotImplementedException();
462                         }
463                 }
464                 #endregion      // IReflection Methods and Properties
465
466                 #region IAccessible Methods and Properties
467                 void IAccessible.accDoDefaultAction(object childID) {
468                         throw new NotImplementedException();
469                 }
470
471                 int IAccessible.accChildCount {
472                         get {
473                                 throw new NotImplementedException();
474                         }
475                 }
476
477                 object IAccessible.accFocus {
478                         get {
479                                 throw new NotImplementedException();
480                         }
481                 }
482
483                 object IAccessible.accHitTest(int xLeft, int yTop) {
484                         throw new NotImplementedException();
485                 }
486
487                 void IAccessible.accLocation(out int pxLeft, out int pyTop, out int pcxWidth, out int pcyHeight, object childID) {
488                         throw new NotImplementedException();
489                 }
490
491                 object IAccessible.accNavigate(int navDir, object childID) {
492                         throw new NotImplementedException();
493                 }
494
495                 object IAccessible.accParent {
496                         get {
497                                 throw new NotImplementedException();
498                         }
499                 }
500
501                 void IAccessible.accSelect(int flagsSelect, object childID) {
502                         throw new NotImplementedException();
503                 }
504
505                 object IAccessible.accSelection {
506                         get {
507                                 throw new NotImplementedException();
508                         }
509                 }
510
511                 object IAccessible.get_accChild(object childID) {
512                         throw new NotImplementedException();
513                 }
514
515                 string IAccessible.get_accDefaultAction(object childID) {
516                         throw new NotImplementedException();
517                 }
518
519                 string IAccessible.get_accDescription(object childID) {
520                         throw new NotImplementedException();
521                 }
522
523                 string IAccessible.get_accHelp(object childID) {
524                         throw new NotImplementedException();
525                 }
526
527                 int IAccessible.get_accHelpTopic(out string pszHelpFile,object childID) {
528                         throw new NotImplementedException();
529                 }
530
531                 string IAccessible.get_accKeyboardShortcut(object childID) {
532                         throw new NotImplementedException();
533                 }
534
535                 string IAccessible.get_accName(object childID) {
536                         throw new NotImplementedException();
537                 }
538
539                 object IAccessible.get_accRole(object childID) {
540                         throw new NotImplementedException();
541                 }
542
543                 object IAccessible.get_accState(object childID) {
544                         throw new NotImplementedException();
545                 }
546
547                 string IAccessible.get_accValue(object childID) {
548                         throw new NotImplementedException();
549                 }
550
551                 void IAccessible.set_accName(object childID, string newName) {
552                         throw new NotImplementedException();
553                 }
554
555                 void IAccessible.set_accValue(object childID, string newValue) {
556                         throw new NotImplementedException();
557                 }
558                 #endregion      // IAccessible Methods and Properties
559         }
560 }