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