* Control.cs : check if control is already in control collection, Created property,
[mono.git] / mcs / class / System.Windows.Forms / System.Windows.Forms / Control.cs
1     //
2     // System.Windows.Forms.Control.cs
3     //
4     // Author:
5     //   stubbed out by Jaak Simm (jaaksimm@firm.ee)
6     //  Dennis Hayes (dennish@rayetk.com)
7     //   WINELib implementation started by John Sohn (jsohn@columbus.rr.com)
8     //   Alexandre Pigolkine (pigolkine@gmx.de)
9     //  Aleksey Ryabchuk (ryabchuk@yahoo.com)
10     //
11     // (C) Ximian, Inc., 2002
12     //
13     
14     using System.ComponentModel;
15     using System.Drawing;
16     using System.Collections;
17         using System.Threading;
18         using System.Text;
19     using System.Runtime.InteropServices;
20     using System.Collections.Specialized;
21
22     namespace System.Windows.Forms {
23     
24         /// <summary>
25         /// Defines the base class for controls, which are components with 
26         /// visual representation.
27         /// </summary>
28         
29         public class Control : Component , ISynchronizeInvoke, IWin32Window {
30     
31
32                 // Helper NativeWindow class to dispatch messages back
33                 // to the Control class
34                 protected class ControlNativeWindow : NativeWindow {
35     
36                         private Control control;
37     
38                         public ControlNativeWindow (Control control) : base() {
39                                 this.control = control;
40                         }
41     
42                         protected override void WndProc (ref Message m) {
43                                         //Console.WriteLine ("Control WndProc Message HWnd {0}, Msg {1}", m.HWnd, m.Msg);
44                                         // Do not call default WndProc here
45                                         // let the control decide what to do
46                                 // base.WndProc (ref m);
47                                 control.WndProc (ref m);
48                         }
49                 }
50                 
51                 // FIXME: not sure if dervied classes should have access
52                 protected ControlNativeWindow window;
53                 private ControlCollection childControls;
54                 private Control parent;
55                 static private Hashtable controlsCollection = new Hashtable ();
56                 static private NativeWindow parkingWindow = null;
57
58                 // private fields
59                 // it seems these are stored in case the window is not created,
60                 // corresponding properties (below) need to check if window
61                 // is created or not and react accordingly
62                 string accessibleDefaultActionDescription;
63                 string accessibleDescription;
64                 string accessibleName;
65                 AccessibleRole accessibleRole;
66                 bool allowDrop;
67                 AnchorStyles anchor;
68                 Color backColor;
69                 Image backgroundImage;
70                 //BindingContext bindingContext;
71                 Rectangle bounds;
72                 Rectangle oldBounds;
73
74                 bool causesValidation;
75                 //ContextMenu contextMenu;
76                 DockStyle dock;
77                 bool enabled;
78                 Font font;
79                 Color foreColor;
80                 ImeMode imeMode;
81                 bool isAccessible;
82                 // Point location;  // using bounds to store location
83                 string name;
84                 Region region;
85                 RightToLeft rightToLeft;
86                 bool tabStop;
87                 string text;
88                 bool visible;
89                 protected ControlStyles controlStyles_;
90
91                 int clientWidth;
92                 int clientHeight;
93
94                 BitVector32 statuses;
95                 private static readonly int LAYOUT_SUSPENDED = BitVector32.CreateMask();
96                 private static readonly int LAYOUT_PENDING   = BitVector32.CreateMask( LAYOUT_SUSPENDED );
97                 private static readonly int DISPOSED         = BitVector32.CreateMask( LAYOUT_PENDING );
98                 private static readonly int RECREATING_HANDLE= BitVector32.CreateMask( DISPOSED );
99                 private static readonly int CREATED          = BitVector32.CreateMask( RECREATING_HANDLE );
100
101                         object tag;
102                         protected bool mouseIsInside_;
103
104                         // BeginInvoke() etc. helpers
105                         static int InvokeMessage = Win32.RegisterWindowMessage("mono_control_invoke_helper");
106
107                         // CHECKME: This variable is used to determine whether current thread
108                         // was used to create Control Handle. It take some space but saves a call
109                         // to unmanaged code in ISynchronizeInvoke.IsInvokeRequired.
110                         private int CreatorThreadId_ = 0; 
111
112                         private Queue InvokeQueue_ = new Queue();
113
114                         internal class ControlInvokeHelper : IAsyncResult {
115                                 private Delegate Method_ = null;
116                                 private object[] MethodArgs_ = null;
117                                 private object MethodResult_ = null;
118                                 private ManualResetEvent AsyncWaitHandle_ = new ManualResetEvent(false);
119                                 private bool CompletedSynchronously_ = false;
120                                 private bool IsCompleted_ = false;
121
122                                 public ControlInvokeHelper( Delegate method, object[] args) {
123                                         Method_ = method;
124                                         MethodArgs_ = args;
125                                 }
126
127                                 // IAsyncResult interface 
128                                 object IAsyncResult.AsyncState { 
129                                         get {
130                                                 if( MethodArgs_ != null && MethodArgs_.Length != 0) {
131                                                         return MethodArgs_[MethodArgs_.Length - 1];
132                                                 }
133                                                 return null;
134                                         }
135                                 }
136
137                                 WaitHandle IAsyncResult.AsyncWaitHandle { 
138                                         get {
139                                                 return AsyncWaitHandle_;
140                                         }
141                                 }
142
143                                 bool IAsyncResult.CompletedSynchronously {
144                                         get {
145                                                 return CompletedSynchronously_;
146                                         }
147                                 }
148
149                                 bool IAsyncResult.IsCompleted { 
150                                         get {
151                                                 return IsCompleted_;
152                                         }
153                                 }
154
155                                 internal bool CompletedSynchronously {
156                                         set {
157                                                 CompletedSynchronously_ = value;
158                                         }
159                                 }
160
161                                 internal object MethodResult {
162                                         get {
163                                                 return MethodResult_;
164                                         }
165                                 }
166
167                                 internal void ExecuteMethod() {
168                                         object result = Method_.DynamicInvoke(MethodArgs_);
169                                         lock(this) {
170                                                 MethodResult_ = result;
171                                                 IsCompleted_ = true;
172                                         }
173                                         AsyncWaitHandle_.Set();
174                                 }
175                         }
176
177                 // --- Constructors ---
178     
179                         //Compact Framework //only Control()
180                 public Control ()
181                 {
182                         childControls = CreateControlsInstance ();
183
184                         statuses = new BitVector32(); 
185                         
186                         accessibleDefaultActionDescription = null;
187                         accessibleDescription = null;
188                         accessibleName = null;
189                         accessibleRole = AccessibleRole.Default;
190                         allowDrop = false;
191                         anchor = AnchorStyles.Top | AnchorStyles.Left;
192                         backColor = Control.DefaultBackColor;
193                         backgroundImage = null;
194                         bounds = new Rectangle();
195                         oldBounds = new Rectangle();
196                         // bindingContext = null;
197                         causesValidation = true;
198                         // contextMenu = null;
199                         dock = DockStyle.None;
200                         enabled = true;
201                         // font = Control.DefaultFont;
202                         foreColor = Control.DefaultForeColor;
203                         imeMode = ImeMode.Inherit;
204                         isAccessible = false;
205                         // location = new Point (0,0); should be from OS
206                         name = "";
207                         region = null;
208                         rightToLeft = RightToLeft.Inherit;
209                         tabStop = false;
210                         text = "";
211                         visible = true;
212                         parent = null;
213
214                         oldBounds.Width  = bounds.Width = DefaultSize.Width;
215                         oldBounds.Height = bounds.Height= DefaultSize.Height;
216                         clientWidth      = DefaultSize.Width;
217                         clientHeight     = DefaultSize.Height;
218
219                         mouseIsInside_ = false;
220                         controlStyles_ = ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick;
221                                 // Do not create Handle here, only in CreateHandle
222                         // CreateHandle();//sets window handle. FIXME: No it does not
223                 }
224                 
225                 // according to docs, the constructors do not create 
226                 // the (HWND) window
227                 public Control (string text) : this() 
228                 {
229                         Text = text;
230                         // SetWindowTextA (Handle, text);
231                 }
232                 
233                 public Control (Control parent, string text) : this (text) 
234                 {
235                         Parent = parent;
236                         // SetParent (Handle, parent.Handle);
237                 }
238                 
239                 public Control (string text, int left, int top, 
240                                 int width, int height) : this(text) 
241                 {
242                         Left = left;
243                         Top = top;
244                         Width = width;
245                         Height = height;
246                         //SetWindowPos (Handle, (IntPtr) 0, left, top,
247                         //          width, height, 0);
248                 }
249                 
250                 public Control (Control parent,string text,int left, int top,
251                                 int width,int height) : this (parent, text)
252                 {
253                         Left = left;
254                         Top = top;
255                         Width = width;
256                         Height = height;
257                         // SetWindowPos (Handle, (IntPtr) 0, left, top,
258                         //                  width, height, 0);
259                 }
260     
261                 // for internal use only, create a control class
262                 // for an existing, created HWND
263                 private Control (IntPtr existingHandle)
264                 {
265                         window = (ControlNativeWindow) NativeWindow.FromHandle (
266                                 existingHandle);
267                 }
268     
269                 // --- Properties ---
270                 // Properties only supporting .NET framework, not stubbed out:
271                 //  - protected bool RenderRightToLeft {get;}
272                 //  - public IWindowTarget WindowTarget {get; set;}
273                 //[MonoTODO]
274                 //public AccessibleObject AccessibilityObject {
275                 //      get {
276                 //              throw new NotImplementedException ();
277                 //      }
278                 //}
279     
280                 public string AccessibleDefaultActionDescription {
281                         get {
282                                 return accessibleDefaultActionDescription;
283                         }
284                         set {
285                                 accessibleDefaultActionDescription = value;
286                         }
287                 }
288                 
289                 public string AccessibleDescription {
290                         get {
291                                 return accessibleDescription;
292                         }
293                         set {
294                                 accessibleDescription=value;
295                         }
296                 }
297                 
298                 public string AccessibleName {
299                         get {
300                                 return accessibleName;
301                         }
302                         set {
303                                 accessibleName=value;
304                         }
305                 }
306                 
307                 public AccessibleRole AccessibleRole {
308                         get {
309                                 return accessibleRole;
310                         }
311                         set {
312                                 accessibleRole=value;
313                         }
314                 }
315                 
316                 public virtual bool AllowDrop {
317                         get {
318                                 return allowDrop;
319                         }
320                         set {
321                                 allowDrop=value;
322                         }
323                 }
324         
325                 public virtual AnchorStyles Anchor {
326                         get {
327                                 return anchor;
328                         }
329                         set {
330                                 if ( anchor != value ) {
331                                         anchor = value;
332                                         if ( anchor != ( AnchorStyles.Left | AnchorStyles.Top ) )
333                                                 Dock = DockStyle.None;
334                                 }
335                         }
336                 }
337                 
338                         //Compact Framework
339                 public virtual Color BackColor {
340                         get {
341                                         return backColor;
342                         }
343                         set {
344                                         if( backColor != value) {
345                                                 backColor = value;
346                                                 OnBackColorChanged(new EventArgs());
347                                         }
348                         }
349                 }
350                 
351                 public virtual Image BackgroundImage {
352                         get {
353                                 return backgroundImage;
354                         }
355                         set {
356                                 backgroundImage = value;
357                                 // FIXME: force redraw
358                                         Invalidate();
359                         }
360                 }
361     
362                 public virtual BindingContext BindingContext {
363                         get {
364                                 //return bindingContext;
365                                 throw new NotImplementedException ();
366                         }
367                         set {
368                                 //bindingContext=value;
369                                 throw new NotImplementedException ();
370                         }
371                 }
372                 
373                         //Compact Framework
374                 public int Bottom {
375                         get {
376                                 return Top + Height;
377                         }
378                 }
379                 
380                         //Compact Framework
381                 public Rectangle Bounds {
382                         get {
383                                 return bounds;
384                         }
385                         set {
386                                 SetBounds(value.Left, value.Top, value.Width, value.Height);
387                         }
388                 }
389                 
390                 public bool CanFocus {
391                         get {
392                                 if (IsHandleCreated && Visible && Enabled)
393                                         return true;
394                                 return false;
395                         }
396                 }
397                 
398                 [MonoTODO]
399                 public bool CanSelect {
400                         get {
401     //                          if (ControlStyles.Selectable &&
402     //                              isContainedInAnotherControl &&
403     //                              parentIsVisiable && isVisialbe &&
404     //                              parentIsEnabled && isEnabled) {
405     //                                  return true;
406     //                          }
407     //                          return false;
408     
409                                 throw new NotImplementedException ();
410                         }
411                 }
412                 
413                         //Compact Framework
414                 public bool Capture {
415                         get {
416                                 if (IsHandleCreated) {
417                                         IntPtr captured = Win32.GetCapture ();
418                                         if (Handle == captured) 
419                                                 return true;
420                                 }
421                                 return false;
422                         }
423                         set {
424                                 if (IsHandleCreated) {
425                                         if (value)
426                                                 Win32.SetCapture (Handle);
427                                         else {
428                                                 IntPtr captured = Win32.GetCapture ();
429     
430                                                 // if this window is in capture state
431                                                 // release it
432                                                 if (Handle == captured)
433                                                         Win32.ReleaseCapture ();
434                                         }
435                                 }
436                         }
437                 }
438                 
439                 public bool CausesValidation {
440                         get {
441                                 return causesValidation;
442                         }
443                         set {
444                                 causesValidation=value;
445                         }
446                 }
447                 
448                         //Compact Framework
449                 public Rectangle ClientRectangle {
450                         get {
451                                 return new Rectangle ( 0, 0, ClientSize.Width, ClientSize.Height );
452  
453                         }
454                 }
455                 
456                         //Compact Framework
457                         [MonoTODO]
458                         public Size ClientSize {
459                                 get {
460                                         return new Size ( clientWidth, clientHeight);
461                                 }
462                                 set {
463                                         SetClientSizeCore ( value.Width, value.Height );
464                                 }
465                         }
466                 
467                 [MonoTODO]
468                 public string CompanyName {
469                         get {
470                                         //Better than throwing an execption
471                                 return "Company Name";
472                         }
473                 }
474
475                         internal void SetClientSize(Size value, int styleIfNoWindow, bool menuIfNoWindow) {
476                                 RECT rc = new RECT();
477                                 rc.left = rc.top = 0;
478                                 rc.right = value.Width;
479                                 rc.bottom = value.Height;
480                                 
481                                 if( IsHandleCreated ){
482                                         int style = Win32.GetWindowLong( Handle, GetWindowLongFlag.GWL_STYLE).ToInt32();
483                                         int menuExists = 0;
484                                         if( (style & (int)WindowStyles.WS_CHILD) == 0 ){
485                                                 menuExists = Win32.GetMenu(Handle) != IntPtr.Zero ? 1 : 0;
486                                         }
487                                         Win32.AdjustWindowRect( ref rc, style, menuExists);
488                                         Win32.SetWindowPos( Handle, SetWindowPosZOrder.HWND_TOP, 0, 0, rc.right - rc.left, rc.bottom - rc.top, 
489                                                 SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOZORDER);
490                                 }
491                                 else {
492                                         Win32.AdjustWindowRect( ref rc, styleIfNoWindow, menuIfNoWindow ? 1 : 0);
493                                 }
494                                 Size = new Size(rc.right - rc.left, rc.bottom - rc.top);
495                         }               
496                 
497                 public bool ContainsFocus {
498                         get {
499                                 if (IsHandleCreated) {
500                                         IntPtr focusedWindow = Win32.GetFocus();
501                                         if (focusedWindow == Handle)
502                                                 return true;
503                                 }
504                                 return false;
505                         }
506                 }
507                 
508                         //Compact Framework
509                 [MonoTODO]
510                 public virtual ContextMenu ContextMenu {
511                         get {
512                                 //return contextMenu;
513                                 throw new NotImplementedException ();
514                         }
515                         set {
516                                 //contextMenu=value;
517                                 throw new NotImplementedException ();
518                         }
519                 }
520                 
521                 public ControlCollection Controls {
522                         get { return childControls; }
523                 }
524                 
525                 public bool Created {
526                         get { return statuses[ CREATED ]; }
527                 }
528                 
529                 protected virtual CreateParams CreateParams {
530                         get {
531                                         CreateParams createParams = new CreateParams ();
532                                         createParams.Caption = Text;
533                                         createParams.X = Left;
534                                         createParams.Y = Top;
535                                         createParams.Width = Width;
536                                         createParams.Height = Height;
537                                         createParams.ClassStyle = 0;
538                                         createParams.ExStyle = 0;
539                                         createParams.Param = 0;
540                                 
541                                         if (parent != null)
542                                                 createParams.Parent = parent.Handle;
543                                         else 
544                                                 createParams.Parent = ParkingWindowHandle;
545           
546                                         createParams.Style = (int) WindowStyles.WS_OVERLAPPEDWINDOW;
547           
548                                 return createParams;
549                         }
550                 }
551                 
552                         internal protected IntPtr ControlRealWndProc = IntPtr.Zero;
553                         internal protected bool SubClassWndProc_ = false;
554
555                         // This function lets Windows or/and default Windows control process message
556                         // Classes have to call it if they do not handle message in WndProc or
557                         // default handling is needed.
558                         protected void CallControlWndProc( ref Message msg) {
559                                 if( ControlRealWndProc != IntPtr.Zero) {
560                                         msg.Result = (IntPtr)Win32.CallWindowProc(ControlRealWndProc, msg.HWnd, (int)msg.Msg, msg.WParam.ToInt32(), msg.LParam.ToInt32());
561                                 }
562                                 else {
563                                         DefWndProc(ref msg);
564                                 }
565                         }
566
567                         // Subclass only native Windows controls. Those classes have to set SubClassWndProc_ to true in contructor
568                         private void SubclassWindow() {
569                                 if( IsHandleCreated && SubClassWndProc_) {
570                                         ControlRealWndProc = Win32.SetWindowLong( Handle, GetWindowLongFlag.GWL_WNDPROC, NativeWindow.GetWindowProc());
571                                 }
572                         }
573
574                         private void UnsubclassWindow() {
575                                 if( IsHandleCreated) {
576                                         Win32.SetWindowLong( Handle, GetWindowLongFlag.GWL_WNDPROC, ControlRealWndProc.ToInt32());
577                                 }
578                         }
579
580                         protected virtual void OnWmCommand (ref Message m) {
581                                 if( m.LParam.ToInt32() != 0) {
582                                         if( m.LParam != Handle) {
583                                                 // Control notification
584                                                 System.Console.WriteLine("Control notification Code {0} Id = Hwnd {1}", m.HiWordWParam, m.LParam.ToInt32());
585                                                 Control.ReflectMessage(m.LParam, ref m);
586                                         }
587                                         else {
588                                                 // Unhandled Control reflection
589                                                 // Derived class didn't handle WM_COMMAND or called base.WndProc in WM_COMMAND handler
590                                                 // CHECKME: Shall we notify user in debug build, throw an exception or just ignore this case ?
591                                         }
592                                 }
593                         }
594
595                 [MonoTODO]
596                 public virtual Cursor Cursor {
597                         get {
598                                 throw new NotImplementedException ();
599                         }
600                         set {
601                                 throw new NotImplementedException ();
602                         }
603                 }
604                 
605                         //Compact Framework
606                 [MonoTODO]
607                 // waiting for BindingContext; should be stubbed now
608                 public ControlBindingsCollection DataBindings {
609                         get {
610                                 throw new NotImplementedException ();
611                         }
612                 }
613                 
614                 public static Color DefaultBackColor {
615                         get {
616                                 // FIXME: use GetSystemMetrics?
617                                 return SystemColors.Control;
618                                 //throw new NotImplementedException ();
619                         }
620                 }
621     
622                 //[MonoTODO]
623                 // FIXME: use GetSystemMetrics?
624                 public static Font DefaultFont {
625                         // FIXME: get current system font from GenericSansSerif
626                         //        call ArgumentException not called
627                         get {
628                 //              throw new NotImplementedException ();
629                 //              return (FontFamily.GenericSansSerif);
630                                         return Font.FromHfont(Win32.GetStockObject(GSO_.DEFAULT_GUI_FONT));
631                         }
632                 }
633                 
634                 public static Color DefaultForeColor {
635                         get {
636                                 return SystemColors.ControlText;
637                         }
638                 }
639                 
640                 protected virtual ImeMode DefaultImeMode {
641                         get {
642                                 return ImeMode.Inherit;
643                         }
644                 }
645                 
646                 protected virtual Size DefaultSize {
647                         get {
648                                         //Default label size, this should be correct.
649                                 return new Size(100,23);
650                         }
651                 }
652                 
653                 public virtual Rectangle DisplayRectangle {
654                         get {
655                                 return ClientRectangle;
656                         }
657                 }
658                 
659                 [MonoTODO]
660                 public bool Disposing {
661                         get {
662                                 throw new NotImplementedException ();
663                         }
664                 }
665                 
666                 public virtual DockStyle Dock {
667                         get {
668                                 return dock;
669                         }
670                         set {
671                                 if ( dock != value ) {
672                                         dock = value;
673                                         if ( dock != DockStyle.None )
674                                                  Anchor = ( AnchorStyles.Left | AnchorStyles.Top );
675                                         OnDockChanged ( EventArgs.Empty );                                      
676                                 }
677                         }
678                 }
679     
680                         //Compact Framework
681                 public virtual bool Enabled {
682                         get {
683                                         return enabled;
684                                 //return Win32.IsWindowEnabled (Handle);
685                         }
686                         set {
687                                         if( enabled != value) {
688                                                 Win32.EnableWindow (Handle, value);
689                                                 enabled = value;
690                                                 // FIXME: Disable/enable all children here
691                                                 Invalidate();
692                                         }
693                         }
694                 }
695                 
696                         //Compact Framework
697                 public virtual bool Focused {
698                         get {
699                                 return ContainsFocus;
700                         }
701                 }
702                 
703                         //Compact Framework
704                 public virtual Font Font {
705                                 get {
706                                         Font result = font;
707                                         if( result == null) {
708                                                 if( Parent != null) {
709                                                         result = Parent.Font;
710                                                 }
711                                                 if( result == null) {
712                                                         result = Control.DefaultFont;
713                                                 }
714                                         }
715                                         return result;
716                                 }
717                         set {
718                                         font = value;
719                                         if( IsHandleCreated) {
720                                                 Win32.SendMessage(Handle, Msg.WM_SETFONT, Font.ToHfont().ToInt32(), 1);
721                                         }
722                                 }
723                 }
724                 
725                 [MonoTODO]
726                 protected int FontHeight {
727                         get {
728                                 throw new NotImplementedException ();
729                         }
730                         set {
731                                 throw new NotImplementedException ();
732                         }
733                 }
734                 
735                         //Compact Framework
736                 public virtual Color ForeColor {
737                         get {
738                                 return foreColor;
739                         }
740                         set {
741                                 foreColor = value;
742                         }
743                 }
744                 
745                 public bool HasChildren {
746                         get {
747                                 if (childControls.Count >0) 
748                                         return true;
749                                 return false;
750                         }
751                 }
752                 
753                         //Compact Framework
754                 public int Height {
755                         get {
756                                 return bounds.Height;
757                         }
758                         set {
759                                 SetBounds(bounds.X, bounds.Y, bounds.Width, value, BoundsSpecified.Height);
760                         }
761                 }
762                 
763                 public ImeMode ImeMode {
764                         // CHECKME:
765                         get {
766                                 return imeMode;
767                         }
768                         set {
769                                 imeMode=value;
770                         }
771                 }
772                 
773                 public bool IsAccessible {
774                         // CHECKME:
775                         get {
776                                 return isAccessible;
777                         } // default is false
778                         set {
779                                 isAccessible=value;
780                         }
781                 }
782                 
783                 public bool IsDisposed {
784                         get {   return statuses [ DISPOSED ]; }
785                 }
786                 
787                 public bool IsHandleCreated {
788                         get {
789                                 return window != null && window.Handle != IntPtr.Zero;
790                                 //if (Handle != (IntPtr) 0)
791                                 //      return true;
792                                 //return false;
793                         }
794                 }
795                 
796                         //Compact Framework
797                         public int Left {
798                                 get {
799                                         return bounds.X;
800                                 }
801                                 set {
802                                         SetBounds(value, bounds.Y, bounds.Width, bounds.Height, BoundsSpecified.X);
803                                 }
804                         }
805                 
806                         //Compact Framework
807                         public Point Location {
808                                 // CHECKME:
809                                 get {
810                                         return new Point (Top, Left);
811                                 }
812                                 set {
813                                         SetBounds(value.X, value.Y, bounds.Width, bounds.Height, BoundsSpecified.Location);
814                                 }
815                         }
816                 
817                 [MonoTODO]
818                 public static Keys ModifierKeys {
819                         get {
820                                 throw new NotImplementedException ();
821                         }
822                 }
823                 
824                         //Compact Framework
825                 [MonoTODO]
826                 public static MouseButtons MouseButtons {
827                         get {
828                                 // FIXME: use GetAsycKeyState?
829                                 throw new NotImplementedException ();
830                         }
831                 }
832                 
833                         //Compact Framework
834                 public static Point MousePosition {
835                         get {
836                                 POINT point = new POINT();
837                                 Win32.GetCursorPos (ref point);
838                                 return new Point ( (int) point.x, (int) point.y);
839                         }
840                 }
841                 
842                 public string Name {
843                         // CHECKME:
844                         get {
845                                 return name;
846                         }
847                         set {
848                                 name = value;
849                         }
850                 }
851                 
852                         //Compact Framework
853                 public Control Parent {
854                         get {
855                                 return parent;
856                                 //IntPtr parent = GetParent (Handle);
857                                 //return FromHandle (parent);
858                         }
859                         set {
860                                         if( parent != value) {
861                                                 Console.WriteLine ("setting parent");
862                                                 parent = value;
863             
864                                                 Console.WriteLine ("add ourself to the parents control");
865                                                 // add ourself to the parents control
866                                                 if ( !parent.Controls.Contains ( this ) )
867                                                         parent.Controls.Add (this);
868
869                                                 // FIXME: Is this logic correct ?
870                                                 if( BackColor == DefaultBackColor) {
871                                                         if( parent.BackColor != BackColor)
872                                                                 OnParentBackColorChanged(new EventArgs());
873                                                 }
874
875                                                 Console.WriteLine ("SetParent");
876                                                 if (IsHandleCreated) {
877                                                         Console.WriteLine ("Handle created");
878                                                         Win32.SetParent (Handle, value.Handle);
879                                                 }
880                                                 /*
881                                                 else if( parent.IsHandleCreated){
882                                                         // CHECKME: Now control is responsible for creating his window
883                                                         // when added to Form, may be things must be reversed.
884                                                         CreateControl();
885                                                 }
886                                                 */                      
887                                         }
888                         }
889                 }
890                 
891                 private static IntPtr ParkingWindowHandle {
892                         get {
893                                 if ( parkingWindow == null )
894                                         parkingWindow = new NativeWindow ( );
895
896                                 if ( parkingWindow.Handle == IntPtr.Zero ) {
897                                         CreateParams pars = new CreateParams ( );
898                                         pars.ClassName = "mono_native_window";
899                                         pars.Style = (int) WindowStyles.WS_OVERLAPPED;
900                                         parkingWindow.CreateHandle ( pars );
901                                 }
902
903                                 return parkingWindow.Handle;
904                         }
905                 }
906
907                 [MonoTODO]
908                 public string ProductName {
909                         get {
910                                         //FIXME:
911                                 return "Product Name";
912                         }
913                 }
914                 
915                 [MonoTODO]
916                 public string ProductVersion {
917                         get {
918                                         //FIXME:
919                                         return "Product Version";
920                         }
921                 }
922                 
923                 [MonoTODO]
924                 public bool RecreatingHandle {
925                         get {
926                                 return statuses [ RECREATING_HANDLE ] ;
927                         }
928                 }
929                 
930                 public Region Region {
931                         // CHECKME:
932                         get {
933                                 return region;
934                         }
935                         set {
936                                 region = value;
937                         }
938                 }
939                 
940                 [MonoTODO]
941                 protected bool ResizeRedraw {
942                         get {
943                                 throw new NotImplementedException ();
944                         }
945                         set {
946                                 throw new NotImplementedException ();
947                         }
948                 }
949                 
950                         //Compact Framework
951                 public int Right {
952                         get {
953                                 return Left + Width;
954                         }
955                 }
956                 
957                 [MonoTODO]
958                 public virtual RightToLeft RightToLeft {
959                         // CHECKME:
960                         get {
961                                 return rightToLeft;
962                         }
963                         set {
964                                 rightToLeft=value;
965                         }
966                 }
967                 
968                 [MonoTODO]
969                 protected virtual bool ShowFocusCues {
970                         get {
971                                 throw new NotImplementedException ();
972                         }
973                 }
974                 
975                 [MonoTODO]
976                 protected bool ShowKeyboardCues {
977                         get {
978                                 throw new NotImplementedException ();
979                         }
980                 }
981                 
982                 [MonoTODO]
983                 public override ISite Site {
984                         get {
985                                 throw new NotImplementedException ();
986                         }
987                         set {
988                                 throw new NotImplementedException ();
989                         }
990                 }
991                 
992                 //Compact Framework
993                 public Size Size {
994                         get {
995                                 return new Size(Width, Height);
996                         }
997                         set {
998                                 SetBounds(bounds.X, bounds.Y, value.Width, value.Height, BoundsSpecified.Size);
999                         }
1000                 }
1001
1002                 internal int tabindex;//for debug/test only. remove
1003                 [MonoTODO]
1004                 public int TabIndex {
1005                         get {
1006                                 return tabindex;
1007                         }
1008                         set {
1009                                 tabindex = value;
1010                         }
1011                 }
1012                 
1013                 public bool TabStop {
1014                         // CHECKME:
1015                         get {
1016                                 return tabStop;
1017                         }
1018                         set {
1019                                 tabStop = value;
1020                         }
1021                 }
1022                 
1023                 [MonoTODO]
1024                 public object Tag {
1025                         get {
1026                                 return tag;
1027                         }
1028                         set {
1029                                 tag = value;
1030                         }
1031                 }
1032                 
1033                         //Compact Framework
1034                 public virtual string Text {
1035                         get {
1036                                         // CHECKME: if we really need to provide back current text of real window
1037                                         // or just our copy in text member.
1038                                 if (IsHandleCreated) {
1039                                                 int len = Win32.GetWindowTextLengthA (Handle);
1040                                                 // FIXME: len is doubled due to some strange behaviour.(of GetWindowText function ?)
1041                                                 // instead of 10 characters we can get only 9, even if sb.Capacity is 10.
1042                                                 StringBuilder sb = new StringBuilder(len * 2 /*Win32.GetWindowTextLengthA (Handle)*/);
1043                                         Win32.GetWindowText (Handle, sb, sb.Capacity);
1044                                         return sb.ToString();
1045                                 } 
1046                                         else{
1047                                                 return text;
1048                                         }
1049                         }
1050                         set {
1051                                 text = value;
1052     
1053                                 if (IsHandleCreated)
1054                                         Win32.SetWindowTextA (Handle, value);
1055                         }
1056                 }
1057                 
1058                         //Compact Framework
1059                 public int Top {
1060                         get {
1061                                 return bounds.Top;
1062                         }
1063                         set {
1064                                 SetBounds(bounds.X, value, bounds.Width, bounds.Height, BoundsSpecified.Y);
1065                         }
1066                 }
1067                 
1068                 [MonoTODO]
1069                 public Control TopLevelControl {
1070                         get {
1071                                 throw new NotImplementedException ();
1072                         }
1073                 }
1074     
1075                         //Compact Framework
1076                 public bool Visible {
1077                         get {
1078                                 return visible;
1079                         }
1080                         set {
1081                                 visible = value;
1082                                 if ( visible ) 
1083                                          Show();
1084                                 else     Hide ();
1085                         }
1086                 }
1087                 
1088                         //Compact Framework
1089                 public int Width {
1090                         get {
1091                                 return bounds.Width;
1092                         }
1093                         set {
1094                                 SetBounds(bounds.X, bounds.Y, value, bounds.Height, BoundsSpecified.Width);
1095                         }
1096                 }
1097                 
1098                 /// --- methods ---
1099                 /// internal .NET framework supporting methods, not stubbed out:
1100                 /// - protected virtual void NotifyInvalidate(Rectangle invalidatedArea)
1101                 /// - protected void RaiseDragEvent(object key,DragEventArgs e);
1102                 /// - protected void RaiseKeyEvent(object key,KeyEventArgs e);
1103                 /// - protected void RaiseMouseEvent(object key,MouseEventArgs e);
1104                 /// - protected void RaisePaintEvent(object key,PaintEventArgs e);
1105                 /// - protected void ResetMouseEventArgs();
1106                 
1107                 [MonoTODO]
1108                 protected void AccessibilityNotifyClients (
1109                         AccessibleEvents accEvent,int childID) 
1110                 {
1111                         throw new NotImplementedException ();
1112                 }
1113                 
1114                         //Compact Framework
1115                 [MonoTODO]
1116                 public void BringToFront () 
1117                 {
1118                         //FIXME:
1119                 }
1120                 
1121                 public bool Contains (Control ctl) 
1122                 {
1123                         return childControls.Contains (ctl);
1124                 }
1125                 
1126                 public void CreateControl () 
1127                 {
1128                         CreateHandle ();
1129                         OnCreateControl();
1130                         statuses [ CREATED ] = true;
1131                 }
1132     
1133                 [MonoTODO]
1134                 protected virtual AccessibleObject CreateAccessibilityInstance() {
1135                         throw new NotImplementedException ();
1136                 }
1137                 
1138                 protected virtual ControlCollection CreateControlsInstance ()
1139                 {
1140                         return new ControlCollection (this);
1141                 }
1142                 
1143                         //Compact Framework
1144                 [MonoTODO]
1145                 public Graphics CreateGraphics () 
1146                 {
1147                                 return Graphics.FromHwnd(Handle);
1148                 }
1149         
1150                 protected virtual void CreateHandle ()
1151                 {
1152                         if( IsDisposed )
1153                                 throw new ObjectDisposedException ( Name );
1154
1155                         if( IsHandleCreated ) 
1156                                 return;
1157
1158                         if( window == null)
1159                                 window = new ControlNativeWindow (this);
1160
1161                         CreateParams createParams = CreateParams;
1162                         if( !Enabled) {
1163                                 createParams.Style |= (int)WindowStyles.WS_DISABLED;
1164                         }
1165                         window.CreateHandle (createParams);
1166
1167                         if( window.Handle != IntPtr.Zero) {
1168                                 if( !controlsCollection.Contains( window.Handle ) )
1169                                         controlsCollection.Add( window.Handle, this );
1170
1171                                 SubclassWindow();
1172
1173                                 CreatorThreadId_ = Win32.GetCurrentThreadId();
1174
1175                                 OnHandleCreated ( EventArgs.Empty );
1176                         }
1177                 }
1178         
1179                 protected virtual void DefWndProc (ref Message m)
1180                 {
1181                         window.DefWndProc(ref m);
1182                 }
1183                 
1184                 protected virtual void DestroyHandle ()
1185                 {
1186                         if ( IsHandleCreated ) {
1187                                 if( Handle != IntPtr.Zero) {
1188                                         controlsCollection.Remove(Handle);
1189                                 }
1190                                 if( window != null) {
1191                                         window.DestroyHandle ();
1192                                 }
1193                         }
1194                 }
1195         
1196                 protected override void Dispose (bool disposing) 
1197                 {
1198                         statuses [ DISPOSED ] = true;
1199                                 //FIXME: 
1200                         base.Dispose(disposing);
1201                 }
1202         
1203                 [MonoTODO]
1204                 public DragDropEffects DoDragDrop (
1205                         object data, DragDropEffects allowedEffects)
1206                 {
1207                         throw new NotImplementedException ();
1208                 }
1209         
1210                 //public object EndInvoke(IAsyncResult asyncResult):
1211                 //look under ISynchronizeInvoke methods
1212         
1213                 [MonoTODO]
1214                 public Form FindForm () 
1215                 {
1216                         throw new NotImplementedException ();
1217                 }
1218         
1219                         //Compact Framework
1220                 public bool Focus () 
1221                 {
1222                         if (Win32.SetFocus (Handle) != (IntPtr) 0)
1223                                 return true;
1224                         return false;
1225                 }
1226         
1227                 [MonoTODO]
1228                 public static Control FromChildHandle (IntPtr handle) 
1229                 {
1230                         Control control  = null;
1231                         IntPtr  controlHwnd = handle;
1232                                 while( controlHwnd != IntPtr.Zero) {
1233                                         control  = controlsCollection[controlHwnd] as Control;
1234                                         if( control != null) break;
1235                                         controlHwnd = Win32.GetParent(controlHwnd);
1236                                 }
1237                                 return control;                         
1238                 }
1239         
1240                 public static Control FromHandle (IntPtr handle) 
1241                 {
1242                                 // FIXME: Here we have to check, whether control already exists
1243                         //Control control = new Control (handle);
1244                                 Control control  = controlsCollection[handle] as Control;
1245                         return control;
1246                 }
1247         
1248                 [MonoTODO]
1249                 public Control GetChildAtPoint (Point pt) 
1250                 {
1251                         throw new NotImplementedException ();
1252                 }
1253         
1254                 // [MonoTODO]
1255                 //public IContainerControl GetContainerControl () 
1256                 //{
1257                 //      throw new NotImplementedException ();
1258                 //}
1259                 
1260                 [MonoTODO]
1261                 public Control GetNextControl (Control ctl, bool forward) 
1262                 {
1263                         throw new NotImplementedException ();
1264                 }
1265         
1266                 [MonoTODO]
1267                 protected bool GetStyle (ControlStyles flag) 
1268                 {
1269                         return (controlStyles_ & flag) != 0;
1270                 }
1271         
1272                 [MonoTODO]
1273                 protected bool GetTopLevel () 
1274                 {
1275                         throw new NotImplementedException ();
1276                 }
1277                 
1278                         //Compact Framework
1279                 public void Hide ()
1280                 {
1281                         if (IsHandleCreated)
1282                                 Win32.ShowWindow (Handle, ShowWindowStyles.SW_HIDE);
1283                 }
1284                 
1285                 [MonoTODO]
1286                 protected virtual void InitLayout () 
1287                 {
1288                                 //FIXME:
1289                 }
1290                 
1291                         //Compact Framework
1292                 public void Invalidate () 
1293                 {
1294                         if (IsHandleCreated) {
1295                                         Win32.InvalidateRect(Handle, IntPtr.Zero, 1);
1296                         }
1297                 }
1298                 
1299                 [MonoTODO]
1300                 public void Invalidate (bool invalidateChildren) 
1301                 {
1302                                 //FIXME:
1303                 }
1304                 
1305                 // tries to find appropriate owner for modal form
1306                 internal static Control getOwnerWindow ( Control skip )
1307                 {
1308                         // temporary solution
1309                         IEnumerator cw = controlsCollection.GetEnumerator ( );
1310
1311                         while ( cw.MoveNext ( ) ) {
1312                                 Control c = ( (DictionaryEntry) cw.Current).Value as Control;
1313                                 if ( c != null && c != skip ) {
1314                                         IntPtr parent = Win32.GetParent ( c.Handle );
1315                                         IntPtr owner  = Win32.GetWindow ( c.Handle, (uint) GetWindowConstants.GW_OWNER );
1316                                         if ( parent == IntPtr.Zero && owner == IntPtr.Zero )
1317                                                 return c;
1318                                 }
1319                         }
1320                         return null;
1321                 }
1322
1323                         //Compact Framework
1324                 public void Invalidate (Rectangle rc) 
1325                 {
1326                         if (IsHandleCreated) {
1327                                 RECT rect = new RECT();
1328                                 rect.left = rc.Left;
1329                                 rect.top = rc.Top;
1330                                 rect.right = rc.Right;
1331                                 rect.bottom = rc.Bottom;
1332                                 Win32.InvalidateRect (Handle, ref rect, true);
1333                         }
1334                 }
1335                 
1336                 [MonoTODO]
1337                 public void Invalidate(Region region) 
1338                 {
1339                                 //FIXME:
1340                         }
1341                 
1342                 [MonoTODO]
1343                 public void Invalidate (Rectangle rc, bool invalidateChildren) 
1344                 {
1345                                 //FIXME:
1346                 }
1347                 
1348                 [MonoTODO]
1349                 public void Invalidate(Region region,bool invalidateChildren) 
1350                 {
1351                                 //FIXME:
1352                         }
1353                 
1354                 [MonoTODO]
1355                 protected void InvokeGotFocus (Control toInvoke, EventArgs e) 
1356                 {
1357                                 //FIXME:
1358                         }
1359                 
1360                 [MonoTODO]
1361                 protected void InvokeLostFocus (Control toInvoke, EventArgs e) 
1362                 {
1363                                 //FIXME:
1364                         }
1365                 
1366                 [MonoTODO]
1367                 protected void InvokeOnClick (Control toInvoke, EventArgs e) 
1368                 {
1369                                 //FIXME:
1370                         }
1371                 
1372                 [MonoTODO]
1373                 protected void InvokePaint (Control c, PaintEventArgs e) 
1374                 {
1375                                 //FIXME:
1376                         }
1377                 
1378                 [MonoTODO]
1379                 protected void InvokePaintBackground (
1380                         Control c,PaintEventArgs e) 
1381                 {
1382                                 //FIXME:
1383                         }
1384                 
1385                 [MonoTODO]
1386                 protected virtual bool IsInputChar (char charCode)
1387                 {
1388                         throw new NotImplementedException ();
1389                 }
1390                 
1391                 [MonoTODO]
1392                 protected virtual bool IsInputKey (Keys keyData) 
1393                 {
1394                         throw new NotImplementedException ();
1395                 }
1396                 
1397                 [MonoTODO]
1398                 public static bool IsMnemonic (char charCode,string text)
1399                 {
1400                         throw new NotImplementedException ();
1401                 }
1402                 
1403                 // methods used with events:
1404                 protected virtual void OnBackColorChanged (EventArgs e)
1405                 {
1406                         if (BackColorChanged != null)
1407                                 BackColorChanged (this, e);
1408
1409                                 foreach( Control ctl in Controls) {
1410                                         ctl.OnParentBackColorChanged(e);
1411                                 }
1412                         }
1413                 
1414                 protected virtual void OnBackgroundImageChanged (EventArgs e)
1415                 {
1416                         if (BackgroundImageChanged != null) 
1417                                 BackgroundImageChanged (this, e);
1418                 }
1419                 
1420                 protected virtual void OnBindingContextChanged (EventArgs e)
1421                 {
1422                         if (BindingContextChanged != null)
1423                                 BindingContextChanged (this, e);
1424                 }
1425                 
1426                 protected virtual void OnCausesValidationChanged (EventArgs e)
1427                 {
1428                         if (CausesValidationChanged != null)
1429                                 CausesValidationChanged (this, e);
1430                 }
1431                 
1432                 protected virtual void OnChangeUICues(UICuesEventArgs e) 
1433                 {
1434                         if (ChangeUICues != null)
1435                                 ChangeUICues (this, e);
1436                 }
1437                 
1438                         //Compact Framework
1439                 protected virtual void OnClick (EventArgs e)
1440                 {
1441                         if (Click != null)
1442                                 Click (this, e);
1443                 }
1444                 
1445     
1446                 protected virtual void OnContextMenuChanged (EventArgs e)
1447                 {
1448                         if (ContextMenuChanged != null)
1449                                 ContextMenuChanged (this, e);
1450                 }
1451                 
1452                 protected virtual void OnControlAdded (ControlEventArgs e)
1453                 {
1454                         if (ControlAdded != null)
1455                                 ControlAdded (this, e);
1456                 }
1457                 
1458                 protected virtual void OnControlRemoved (ControlEventArgs e)
1459                 {
1460                         if (ControlRemoved != null)
1461                                 ControlRemoved (this, e);
1462                 }
1463                 
1464                 protected virtual void OnCreateControl ()
1465                 {
1466                                 //FIXME:
1467                         // create all child windows
1468                         IEnumerator cw = childControls.GetEnumerator();
1469     
1470                         while (cw.MoveNext()) {
1471                                 Console.WriteLine ("Adding Control");
1472                                 Control control = (Control) cw.Current;
1473                                 control.CreateControl ();
1474                                 control.Show ();
1475                         }
1476                         }
1477                 
1478                 protected virtual void OnCursorChanged (EventArgs e)
1479                 {
1480                         if (CursorChanged != null)
1481                                 CursorChanged (this, e);
1482                 }
1483                 
1484                 protected virtual void OnDockChanged (EventArgs e)
1485                 {
1486                         PerformLayout ( this, "Dock" );
1487                         if (DockChanged != null)
1488                                 DockChanged (this, e);
1489                 }
1490                 
1491                 protected virtual void OnDoubleClick (EventArgs e)
1492                 {
1493                         if (DoubleClick != null)
1494                                 DoubleClick (this, e);
1495                 }
1496                 
1497                 protected virtual void OnDragDrop (DragEventArgs e)
1498                 {
1499                         if (DragDrop != null)
1500                                 DragDrop (this, e);
1501                 }
1502                 
1503                 protected virtual void OnDragEnter (DragEventArgs e)
1504                 {
1505                         if (DragEnter != null)
1506                                 DragEnter (this, e);
1507                 }
1508                 
1509                 protected virtual void OnDragLeave (EventArgs e)
1510                 {
1511                         if (DragLeave != null)
1512                                 DragLeave (this, e);
1513                 }
1514                 
1515                 protected virtual void OnDragOver (DragEventArgs e)
1516                 {
1517                         if (DragOver != null)
1518                                 DragOver (this, e);
1519                 }
1520                 
1521                         //Compact Framework
1522                 protected virtual void OnEnabledChanged (EventArgs e)
1523                 {
1524                         if (EnabledChanged != null)
1525                                 EnabledChanged (this, e);
1526                 }
1527                 
1528                 protected virtual void OnEnter (EventArgs e)
1529                 {
1530                         if (Enter != null)
1531                                 Enter (this, e);
1532                 }
1533                 
1534                 protected virtual void OnFontChanged (EventArgs e)
1535                 {
1536                         if (FontChanged != null)
1537                                 FontChanged (this, e);
1538                 }
1539                 
1540                 protected virtual void OnForeColorChanged (EventArgs e) 
1541                 {
1542                         if (ForeColorChanged != null)
1543                                 ForeColorChanged (this, e);
1544                 }
1545                 
1546                 protected virtual void OnGiveFeedback (GiveFeedbackEventArgs e)
1547                 {
1548                         if (GiveFeedback != null)
1549                                 GiveFeedback (this, e);
1550                 }
1551                 
1552                         //Compact Framework
1553                 protected virtual void OnGotFocus (EventArgs e) 
1554                 {
1555                         if (GotFocus != null)
1556                                 GotFocus (this, e);
1557                 }
1558                 
1559                 protected virtual void OnHandleCreated (EventArgs e) 
1560                 {
1561                         Console.WriteLine ("OnHandleCreated");
1562
1563                                 //if( font != null) {
1564                                 //      Win32.SendMessage( Handle, Msg.WM_SETFONT, font.ToHfont().ToInt32(), 0);
1565                                 //}
1566                                 Win32.SendMessage( Handle, Msg.WM_SETFONT, Font.ToHfont().ToInt32(), 0);
1567                                 Win32.SetWindowText( Handle, text);
1568
1569                         if (HandleCreated != null)
1570                                 HandleCreated (this, e);
1571     
1572                 }
1573                 
1574                 protected virtual void OnHandleDestroyed (EventArgs e) 
1575                 {
1576                                 if( Handle != IntPtr.Zero) {
1577                                         controlsCollection.Remove(Handle);
1578                                 }
1579                                 
1580                         if (HandleDestroyed != null) {
1581                                 HandleDestroyed (this, e);
1582                         }
1583                 }
1584                 
1585                 protected virtual void OnHelpRequested (HelpEventArgs e) 
1586                 {
1587                         if (HelpRequested != null)
1588                                 HelpRequested (this, e);
1589                 }
1590                 
1591                 protected virtual void OnImeModeChanged (EventArgs e) 
1592                 {
1593                         if (ImeModeChanged != null)
1594                                 ImeModeChanged (this, e);
1595                 }
1596                 
1597                 protected virtual void OnInvalidated (InvalidateEventArgs e) 
1598                 {
1599                         if (Invalidated != null)
1600                                 Invalidated (this, e);
1601                 }
1602                 
1603                         //Compact Framework
1604                 protected virtual void OnKeyDown (KeyEventArgs e) 
1605                 {
1606                         if (KeyDown != null)
1607                                 KeyDown (this, e);
1608                 }
1609                 
1610                         //Compact Framework
1611                 protected virtual void OnKeyPress (KeyPressEventArgs e) 
1612                 {
1613                         if (KeyPress != null)
1614                                 KeyPress (this, e);
1615                 }
1616                 
1617                         //Compact Framework
1618                 protected virtual void OnKeyUp (KeyEventArgs e) 
1619                 {
1620                         if (KeyUp != null)
1621                                 KeyUp (this, e);
1622     
1623                 }
1624                 
1625                 protected virtual void OnLayout (LayoutEventArgs e) 
1626                 {
1627                         DoDockAndAnchorLayout ( e );
1628                         if (Layout != null)
1629                                 Layout (this, e);
1630                 }
1631                 
1632                 protected virtual void OnLeave (EventArgs e) 
1633                 {
1634                         if (Leave != null)
1635                                 Leave (this, e);
1636                 }
1637                 
1638                 protected virtual void OnLocationChanged (EventArgs e) 
1639                 {
1640                         PerformLayout ( this, "Location" );
1641                         if (LocationChanged != null)
1642                                 LocationChanged (this, e);
1643                 }
1644                 
1645                         //Compact Framework
1646                 protected virtual void OnLostFocus (EventArgs e) 
1647                 {
1648                         if (LostFocus != null)
1649                                 LostFocus (this, e);
1650                 }
1651                 
1652                         //Compact Framework
1653                 protected virtual void OnMouseDown (MouseEventArgs e) 
1654                 {
1655                         if (MouseDown != null)
1656                                 MouseDown (this, e);
1657                 }
1658                 
1659                 protected virtual void OnMouseEnter (EventArgs e) 
1660                 {
1661                                 //System.Console.WriteLine("OnMouseEnter");
1662                         if (MouseEnter != null)
1663                                 MouseEnter (this, e);
1664                 }
1665     
1666                 protected virtual void OnMouseHover (EventArgs e) 
1667                 {
1668                         if (MouseHover != null)
1669                                 MouseHover (this, e);
1670                 }
1671                 
1672                 protected virtual void OnMouseLeave (EventArgs e) 
1673                 {
1674                                 //System.Console.WriteLine("OnMouseLeave");
1675
1676                                 mouseIsInside_ = false;
1677                         if (MouseLeave != null)
1678                                 MouseLeave (this, e);
1679                 }
1680                 
1681                         //Compact Framework
1682                 protected virtual void OnMouseMove (MouseEventArgs e) 
1683                 {
1684                                 // If enter and mouse pressed - do not process
1685                                 if( ((e.Button & MouseButtons.Left) != 0) && !mouseIsInside_) return;
1686
1687                                 if( !mouseIsInside_) {
1688                                         TRACKMOUSEEVENT tme = new TRACKMOUSEEVENT();
1689                                         tme.cbSize = 16;
1690                                         tme.hWnd = Handle;
1691                                         tme.dwFlags = (int)TrackerEventFlags.TME_LEAVE;
1692                                         tme.dwHoverTime = 0;
1693
1694                                         bool result = Win32.TrackMouseEvent(ref tme);
1695                                         if( !result) {
1696                                                 System.Console.WriteLine("{0}",Win32.FormatMessage(Win32.GetLastError()));
1697                                         }
1698                                 }
1699
1700                                 POINT pt = new POINT();
1701                                 pt.x = e.X;
1702                                 pt.y = e.Y;
1703                                 Win32.ClientToScreen(Handle, ref pt);
1704                                 IntPtr wndUnderMouse = Win32.WindowFromPoint(pt);
1705
1706                                 if( wndUnderMouse != Handle) {
1707                                         // we are outside of the window
1708                                         if( mouseIsInside_) {
1709                                                 OnMouseLeave(new EventArgs());
1710                                                 mouseIsInside_ = false;
1711                                         }
1712                                 }
1713                                 else {
1714                                         if( !mouseIsInside_) {
1715                                                 mouseIsInside_ = true;
1716                                                 OnMouseEnter(new EventArgs());
1717                                         }
1718                                 }
1719                         if (MouseMove != null)
1720                                 MouseMove (this, e);
1721                 }
1722                 
1723                         //Compact Framework
1724                 protected virtual void OnMouseUp (MouseEventArgs e) 
1725                 {
1726                         if (MouseUp != null)
1727                                 MouseUp (this, e);
1728                 }
1729                 
1730                 protected virtual void OnMouseWheel (MouseEventArgs e) 
1731                 {
1732                         if (MouseWheel != null)
1733                                 MouseWheel (this, e);
1734                 }
1735                 
1736                 protected virtual void OnMove (EventArgs e) 
1737                 {
1738                         if (Move != null)
1739                                 Move (this, e);
1740                 }
1741                 
1742                 protected virtual void OnNotifyMessage (Message m) 
1743                 {
1744                                 //FIXME:
1745                         }
1746                 
1747                         //Compact Framework
1748                 protected virtual void OnPaint (PaintEventArgs e)
1749                 {
1750                         if (Paint != null)
1751                                 Paint (this, e);
1752                 }
1753                 
1754                         //Compact Framework
1755                 protected virtual void OnPaintBackground (PaintEventArgs e) 
1756                 {
1757                 if( GetStyle(ControlStyles.UserPaint)) {
1758                     Brush br = new SolidBrush(BackColor);
1759                     e.Graphics.FillRectangle(br, e.ClipRectangle);
1760                     br.Dispose();
1761                 }
1762             }
1763                 
1764                 protected virtual void OnParentBackColorChanged (EventArgs e) 
1765                 {
1766                                 BackColor = Parent.BackColor;
1767                                 // FIXME: setting BackColor fires the BackColorChanged event,
1768                                 // so we do not need to call this here
1769                                 /*
1770                         if (BackColorChanged != null)
1771                                 BackColorChanged (this, e);
1772                                 */                                      
1773                 }
1774                 
1775                 protected virtual void OnParentBackgroundImageChanged (
1776                         EventArgs e) 
1777                 {
1778                         if (BackgroundImageChanged != null)
1779                                 BackgroundImageChanged (this, e);
1780                 }
1781                 
1782                 protected virtual void OnParentBindingContextChanged (
1783                         EventArgs e) 
1784                 {
1785                         if (BindingContextChanged != null)
1786                                 BindingContextChanged (this, e);
1787                 }
1788                 
1789                         //Compact Framework
1790                 protected virtual void OnParentChanged (EventArgs e) 
1791                 {
1792                         if (ParentChanged != null)
1793                                 ParentChanged (this, e);
1794                 }
1795                 
1796                 protected virtual void OnParentEnabledChanged (EventArgs e) 
1797                 {
1798                         if (EnabledChanged != null)
1799                                 EnabledChanged (this, e);
1800                 }
1801                 
1802                 protected virtual void OnParentFontChanged (EventArgs e) 
1803                 {
1804                         if (FontChanged != null)
1805                                 FontChanged (this, e);
1806                 }
1807                 
1808                 protected virtual void OnParentForeColorChanged (EventArgs e) 
1809                 {
1810                         if (ForeColorChanged != null)
1811                                 ForeColorChanged (this, e);
1812                 }
1813                 
1814                 protected virtual void OnParentRightToLeftChanged (
1815                         EventArgs e) 
1816                 {
1817                         if (RightToLeftChanged != null)
1818                                 RightToLeftChanged (this, e);
1819                 }
1820                 
1821                 protected virtual void OnParentVisibleChanged (EventArgs e) 
1822                 {
1823                         if (VisibleChanged != null)
1824                                 VisibleChanged (this, e);
1825                 }
1826                 
1827                 protected virtual void OnQueryContinueDrag (
1828                         QueryContinueDragEventArgs e) 
1829                 {
1830                         if (QueryContinueDrag != null)
1831                                 QueryContinueDrag (this, e);
1832                 }
1833                 
1834                         //Compact Framework
1835                 protected virtual void OnResize (EventArgs e) 
1836                 {
1837                         if (Resize != null)
1838                                 Resize (this, e);
1839
1840                         PerformLayout ( );
1841                 }
1842                 
1843                 protected virtual void OnRightToLeftChanged (EventArgs e) 
1844                 {
1845                         if (RightToLeftChanged != null)
1846                                 RightToLeftChanged (this, e);
1847                 }
1848                 
1849                 protected virtual void OnSizeChanged (EventArgs e) 
1850                 {
1851                         PerformLayout ( this, "Size" );
1852                         if (SizeChanged != null)
1853                                 SizeChanged (this, e);
1854                 }
1855                 
1856                 protected virtual void OnStyleChanged (EventArgs e) 
1857                 {
1858                         if (StyleChanged != null)
1859                                 StyleChanged (this, e);
1860                 }
1861                 
1862                 protected virtual void OnSystemColorsChanged (EventArgs e) 
1863                 {
1864                         if (SystemColorsChanged != null)
1865                                 SystemColorsChanged (this, e);
1866                 }
1867                 
1868                 protected virtual void OnTabIndexChanged (EventArgs e) 
1869                 {
1870                         if (TabIndexChanged != null)
1871                                 TabIndexChanged (this, e);
1872                 }
1873                 
1874                 protected virtual void OnTabStopChanged (EventArgs e) 
1875                 {
1876                         if (TabStopChanged != null)
1877                                 TabStopChanged (this, e);
1878                 }
1879                 
1880                         //Compact Framework
1881                 protected virtual void OnTextChanged (EventArgs e) 
1882                 {
1883                         if (TextChanged != null)
1884                                 TextChanged (this, e);
1885                 }
1886     
1887                 //[MonoTODO] // this doesn't seem to be documented
1888     //          protected virtual void OnTextAlignChanged (EventArgs e) {
1889     //                  TextAlignChanged (this, e);
1890     //          }
1891                 
1892                 protected virtual void OnValidated (EventArgs e) 
1893                 {
1894                         if (Validated != null)
1895                                 Validated (this, e);
1896                 }
1897                 
1898                 //[MonoTODO]
1899                 // CancelEventArgs not ready
1900                 //protected virtual void OnValidating(CancelEventArgs e) 
1901                 //{
1902                 //      throw new NotImplementedException ();
1903                 //}
1904                 
1905                 [MonoTODO]
1906                 protected virtual void OnVisibleChanged (EventArgs e) 
1907                 {
1908                         if (VisibleChanged != null)
1909                                 VisibleChanged (this, e);
1910
1911                         PerformLayout ( );
1912                 }
1913                 // --- end of methods for events ---
1914                 
1915                 
1916                 [MonoTODO]
1917                 public void PerformLayout () 
1918                 {
1919                         PerformLayout ( null, null );
1920                 }
1921                 
1922                 [MonoTODO]
1923                 public void PerformLayout (Control affectedControl,
1924                                            string affectedProperty) 
1925                 {
1926                         if ( !statuses [ LAYOUT_SUSPENDED ] )
1927                                 OnLayout ( new LayoutEventArgs ( affectedControl, affectedProperty ) );
1928                         else
1929                                 statuses [ LAYOUT_PENDING ] = true;
1930                 }
1931                 
1932                         //Compact Framework
1933                 [MonoTODO]
1934                 public Point PointToClient (Point p) 
1935                 {
1936                         throw new NotImplementedException ();
1937                 }
1938                 
1939                         //Compact Framework
1940                 [MonoTODO]
1941                 public Point PointToScreen (Point p) 
1942                 {
1943                         throw new NotImplementedException ();
1944                 }
1945                 
1946                 [MonoTODO]
1947                 public virtual bool PreProcessMessage (ref Message msg) 
1948                 {
1949                         throw new NotImplementedException ();
1950                 }
1951                 
1952                 [MonoTODO]
1953                 protected virtual bool ProcessCmdKey (ref Message msg,
1954                                                       Keys keyData) 
1955                 {
1956                         throw new NotImplementedException ();
1957                 }
1958                 
1959                 [MonoTODO]
1960                 protected virtual bool ProcessDialogChar (char charCode) 
1961                 {
1962                         throw new NotImplementedException ();
1963                 }
1964                 
1965                 [MonoTODO]
1966                 protected virtual bool ProcessDialogKey (Keys keyData) 
1967                 {
1968                         throw new NotImplementedException ();
1969                 }
1970                 
1971                 [MonoTODO]
1972                 protected virtual bool ProcessKeyEventArgs (ref Message m) 
1973                 {
1974                         throw new NotImplementedException ();
1975                 }
1976                 
1977                 [MonoTODO]
1978                 protected internal virtual bool ProcessKeyMessage (
1979                         ref Message m) 
1980                 {
1981                         throw new NotImplementedException ();
1982                 }
1983                 
1984                 [MonoTODO]
1985                 protected virtual bool ProcessKeyPreview (ref Message m) 
1986                 {
1987                         throw new NotImplementedException ();
1988                 }
1989                 
1990                 [MonoTODO]
1991                 protected virtual bool ProcessMnemonic (char charCode) 
1992                 {
1993                         throw new NotImplementedException ();
1994                 }
1995                 
1996                 // used when properties/values of Control 
1997                 // are big enough to warrant recreating the HWND
1998                 protected void RecreateHandle() 
1999                 {
2000                         statuses [ RECREATING_HANDLE ] = true;
2001                         if( IsHandleCreated) {
2002                                 DestroyHandle ();
2003                                 CreateHandle ();
2004
2005                                 IEnumerator cw = childControls.GetEnumerator();
2006                                 while ( cw.MoveNext() )
2007                                         (( Control )cw.Current).RecreateHandle ( );
2008
2009                         }
2010                         statuses [ RECREATING_HANDLE ] = false;
2011                 }
2012                 
2013                         //Compact Framework
2014                 [MonoTODO]
2015                 public Rectangle RectangleToClient (Rectangle r) 
2016                 {
2017                                 // FIXME: What to return if Handle is not created yet ?
2018                                 RECT rect = new RECT();
2019                                 rect.left = r.Left;
2020                                 rect.top = r.Top;
2021                                 rect.right = r.Right;
2022                                 rect.bottom = r.Bottom;
2023                                 Win32.ScreenToClient(Handle,ref rect);
2024                                 return new Rectangle( rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
2025                 }
2026                 
2027                         //Compact Framework
2028                 [MonoTODO]
2029                 public Rectangle RectangleToScreen (Rectangle r) 
2030                 {
2031                                 // FIXME: What to return if Handle is not created yet ?
2032                                 RECT rect = new RECT();
2033                                 rect.left = r.Left;
2034                                 rect.top = r.Top;
2035                                 rect.right = r.Right;
2036                                 rect.bottom = r.Bottom;
2037                                 Win32.ClientToScreen(Handle,ref rect);
2038                                 return new Rectangle( rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
2039                         }
2040                 
2041                 [MonoTODO]
2042                 protected static bool ReflectMessage (IntPtr hWnd, ref Message m) {
2043                                 bool result = false;
2044                                 Control cntrl = Control.FromHandle( hWnd);
2045                                 if( cntrl != null) {
2046                                         cntrl.WndProc(ref m);
2047                                         result = true;
2048                                 }
2049                                 return result;
2050                         }
2051                 
2052                         //Compact Framework
2053                 public virtual void Refresh () 
2054                 {
2055                         //RECT rect = (RECT) null;
2056                         //InvalidateRect (Handle, ref rect, true);
2057                         Win32.UpdateWindow (Handle);
2058                 }
2059                 
2060                 [MonoTODO]
2061                 public virtual void ResetBackColor () 
2062                 {
2063                                 //FIXME:
2064                         }
2065                 
2066                 [MonoTODO]
2067                 public void ResetBindings () 
2068                 {
2069                                 //FIXME:
2070                         }
2071                 
2072                 [MonoTODO]
2073                 public virtual void ResetFont () 
2074                 {
2075                                 //FIXME:
2076                         }
2077                 
2078                 [MonoTODO]
2079                 public virtual void ResetForeColor () 
2080                 {
2081                                 //FIXME:
2082                         }
2083                 
2084                 [MonoTODO]
2085                 public void ResetImeMode () 
2086                 {
2087                                 //FIXME:
2088                         }
2089                 
2090                 [MonoTODO]
2091                 public virtual void ResetRightToLeft () 
2092                 {
2093                                 //FIXME:
2094                         }
2095                 
2096                 [MonoTODO]
2097                 public virtual void ResetText () 
2098                 {
2099                                 //FIXME:
2100                         }
2101                 
2102                 [MonoTODO]
2103                 public void ResumeLayout () 
2104                 {
2105                         statuses [ LAYOUT_SUSPENDED ] = false;
2106                         if ( statuses [ LAYOUT_PENDING ] ) {
2107                                 PerformLayout ( );
2108                                 statuses [ LAYOUT_PENDING ] = false;
2109                         }
2110                 }
2111                 
2112                 [MonoTODO]
2113                 public void ResumeLayout (bool performLayout) 
2114                 {
2115                         statuses [ LAYOUT_SUSPENDED ] = false;
2116                         if ( performLayout && statuses [ LAYOUT_PENDING ] ) {
2117                                 PerformLayout ( );
2118                                 statuses [ LAYOUT_PENDING ] = false;
2119                         }
2120                 }
2121                 
2122                 [MonoTODO]
2123                 protected ContentAlignment RtlTranslateAlignment (
2124                         ContentAlignment align) 
2125                 {
2126                         throw new NotImplementedException ();
2127                 }
2128                 
2129                 [MonoTODO]
2130                 protected HorizontalAlignment RtlTranslateAlignment (
2131                         HorizontalAlignment align) 
2132                 {
2133                         throw new NotImplementedException ();
2134                 }
2135                 
2136                 [MonoTODO]
2137                 protected LeftRightAlignment RtlTranslateAlignment (
2138                         LeftRightAlignment align) 
2139                 {
2140                         throw new NotImplementedException ();
2141                 }
2142                 
2143                 [MonoTODO]
2144                 protected ContentAlignment RtlTranslateContent (
2145                         ContentAlignment align) 
2146                 {
2147                         throw new NotImplementedException ();
2148                 }
2149                 
2150                 [MonoTODO]
2151                 protected HorizontalAlignment RtlTranslateHorizontal (
2152                         HorizontalAlignment align) 
2153                 {
2154                         throw new NotImplementedException ();
2155                 }
2156                 
2157                 [MonoTODO]
2158                 protected LeftRightAlignment RtlTranslateLeftRight (
2159                         LeftRightAlignment align) 
2160                 {
2161                         throw new NotImplementedException ();
2162                 }
2163                 
2164                 [MonoTODO]
2165                 public void Scale (float ratio) 
2166                 {
2167                         Scale ( ratio, ratio );
2168                 }
2169                 
2170                 [MonoTODO]
2171                 public void Scale (float dx,float dy) 
2172                 {
2173                         SuspendLayout();
2174                         ScaleCore ( dx, dy );
2175                         IEnumerator cw = childControls.GetEnumerator();
2176                         while ( cw.MoveNext() ) {
2177                                 Control control = (Control) cw.Current;
2178                                 control.Scale ( dx, dy );
2179                         }
2180                         ResumeLayout();
2181                 }
2182                 
2183                 [MonoTODO]
2184                 protected virtual void ScaleCore (float dx, float dy) 
2185                 {
2186                         Location   = new Point ( (int) (Left * dx), (int) (Top * dy) );
2187                         ClientSize = new Size  ((int) ( ClientSize.Width * dx ),
2188                                                 (int) ( ClientSize.Height * dy) );
2189                 }
2190                 
2191                 [MonoTODO]
2192                 public void Select () 
2193                 {
2194                                 //FIXME:
2195                         }
2196                 
2197                 [MonoTODO]
2198                 protected virtual void Select (bool directed,bool forward) 
2199                 {
2200                                 //FIXME:
2201                         }
2202                 
2203                 [MonoTODO]
2204                 public bool SelectNextControl (Control ctl, bool forward, 
2205                                                bool tabStopOnly, 
2206                                                bool nested, bool wrap)
2207                 {
2208                         throw new NotImplementedException ();
2209                 }
2210                 
2211                         //Compact Framework
2212                 [MonoTODO]
2213                 public void SendToBack () 
2214                 {
2215                                 //FIXME:
2216                 }
2217                 
2218                 [MonoTODO]
2219                 public void SetBounds (int x, int y, int width, int height) 
2220                 {
2221                         SetBounds(x, y, width, height, BoundsSpecified.All);
2222                 }
2223                 
2224                 [MonoTODO]
2225                 public void SetBounds (int x, int y, int width, int height, BoundsSpecified specified) 
2226                 {
2227                         SetBoundsCore( x, y, width, height, specified);
2228                 }
2229                 
2230                 [MonoTODO]
2231                 protected virtual void SetBoundsCore ( int x, int y, int width, int height, BoundsSpecified specified) 
2232                 {
2233                         if( (specified & BoundsSpecified.X) == 0)      x = Left;
2234                         if( (specified & BoundsSpecified.Y) == 0)      y = Top;
2235                         if( (specified & BoundsSpecified.Width) == 0)  width = Width;
2236                         if( (specified & BoundsSpecified.Height) == 0) height = Height;
2237
2238                         if( IsHandleCreated ) {
2239                                 SetWindowPosFlags flags = SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_DRAWFRAME;
2240                                 Win32.SetWindowPos( Handle, SetWindowPosZOrder.HWND_NOTOPMOST, x, y, width, height, flags);
2241                         }
2242
2243                         UpdateBounds( x, y, width, height );
2244                 }
2245                 
2246                 protected virtual bool MenuPresent {
2247                         get { return false; }
2248                 }
2249
2250                 [MonoTODO]
2251                 protected virtual void SetClientSizeCore (int x, int y)
2252                 {
2253                         RECT rc   = new RECT();
2254                         rc.right  = x;
2255                         rc.bottom = y;
2256                         
2257                         CreateParams pars = CreateParams;               
2258                         Win32.AdjustWindowRectEx ( ref rc, pars.Style, MenuPresent ? 1 : 0, pars.ExStyle );
2259
2260                         Size = new Size( rc.right - rc.left, rc.bottom - rc.top );
2261                 }
2262                 
2263                 [MonoTODO]
2264                 protected void SetStyle (ControlStyles flag, bool value) 
2265                 {
2266                         if( value) {
2267                                 controlStyles_ |= flag;
2268                         }
2269                         else {
2270                                 controlStyles_ &= ~flag;
2271                         }
2272                         }
2273                 
2274                 protected void SetTopLevel (bool value)
2275                 {
2276                         if (value)
2277                                 // FIXME: verify on whether this is supposed
2278                                 // to activate/deactive the window
2279                                 Win32.SetWindowPos (Handle, 
2280                                                 SetWindowPosZOrder.HWND_NOTOPMOST,
2281                                                 0, 0, 0, 0, 0);
2282                         else
2283                                 // FIXME: this does not make sense but
2284                                 // the docs say the window is hidden
2285                                 Win32.ShowWindow (Handle, ShowWindowStyles.SW_HIDE);
2286                 }
2287                 
2288                 [MonoTODO]
2289                 protected virtual void SetVisibleCore (bool value)
2290                 {
2291                                 //FIXME:
2292                         }
2293                 
2294                         //Compact Framework
2295                 public void Show () 
2296                 {
2297                         if (IsHandleCreated)
2298                                 Win32.ShowWindow (Handle, ShowWindowStyles.SW_SHOW);
2299                 }
2300                 
2301                 public void SuspendLayout () 
2302                 {
2303                         statuses [ LAYOUT_SUSPENDED ] = true;
2304                 }
2305                 
2306                         //Compact Framework
2307                 public void Update () 
2308                 {
2309                         Win32.UpdateWindow (Handle);
2310                 }
2311                 
2312                 [MonoTODO]
2313                 protected void UpdateBounds () 
2314                 {       // update control bounds with current size and position
2315
2316                         // currently, this function is called in responce to
2317                         // window events, so I assume that all window handles
2318                         // are created
2319                         RECT rect = new RECT ( );
2320                         Win32.GetWindowRect ( Handle, ref rect );
2321
2322                         IntPtr parent = Win32.GetParent ( Handle );
2323                         if ( parent != IntPtr.Zero ) {
2324                                 Win32.ScreenToClient( parent, ref rect );
2325                         }
2326
2327                         UpdateBounds ( rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top );
2328                 }
2329                 
2330                 [MonoTODO]
2331                 protected void UpdateBounds (int x, int y, int width, int height) 
2332                 {
2333                         int clWidth = width;
2334                         int clHeight = height;
2335
2336                         CreateParams pars = CreateParams;
2337                         // this check should be removed when all controls will use base
2338                         // implementation of CreateParams
2339                         if ( pars != null ) {
2340                                 RECT rc   = new RECT();
2341                                 rc.right  = width;
2342                                 rc.bottom = height;
2343                                 
2344                                 Win32.AdjustWindowRectEx ( ref rc, pars.Style, MenuPresent ? 1 : 0, pars.ExStyle );
2345
2346                                 clWidth  -= ( ( rc.right - rc.left ) - clWidth );
2347                                 clHeight -= ( ( rc.bottom - rc.top ) - clHeight);
2348                         }
2349                         
2350                         UpdateBounds ( x , y, width, height, clWidth, clHeight );
2351                 }
2352                 
2353                 [MonoTODO]
2354                 protected void UpdateBounds (
2355                         int x, int y, int width, int height, int clientWidth,
2356                         int clientHeight)
2357                 {
2358                         oldBounds.X = bounds.X;
2359                         oldBounds.Y = bounds.Y;
2360                         oldBounds.Width = bounds.Width;
2361                         oldBounds.Height = bounds.Height;
2362
2363                         bool bLocationChanged = ( bounds.X != x ) || ( bounds.Y != y );
2364                         bounds.X = x;
2365                         bounds.Y = y;
2366                         
2367                         bool bSizeChanged = ( bounds.Width  != width ) || ( bounds.Height != height );
2368                         bounds.Width  = width;
2369                         bounds.Height = height;
2370
2371                         this.clientWidth   = clientWidth;
2372                         this.clientHeight  = clientHeight;
2373
2374                         if ( bLocationChanged )
2375                                 OnLocationChanged ( EventArgs.Empty );
2376                         if ( bSizeChanged )
2377                                 OnSizeChanged ( EventArgs.Empty );
2378                 }
2379                 
2380                 [MonoTODO]
2381                 protected void UpdateStyles () 
2382                 {
2383                                 //FIXME:
2384                         }
2385                 
2386                 [MonoTODO]
2387                 protected void UpdateZOrder () 
2388                 {
2389                                 //FIXME:
2390                         }
2391                 
2392
2393                         internal MouseEventArgs Msg2MouseEventArgs( ref Message msg) {
2394                                 MouseButtons mb = MouseButtons.None;
2395                                 KeyStatusFlags keyIndicator = (KeyStatusFlags)msg.WParam.ToInt32();
2396                                 if( (keyIndicator & KeyStatusFlags.MK_LBUTTON) != 0) {
2397                                         mb |= MouseButtons.Left;
2398                                 }
2399                                 if( (keyIndicator & KeyStatusFlags.MK_RBUTTON) != 0) {
2400                                         mb |= MouseButtons.Right;
2401                                 }
2402                                 if( (keyIndicator & KeyStatusFlags.MK_MBUTTON) != 0) {
2403                                         mb |= MouseButtons.Middle;
2404                                 }
2405                                 if( (keyIndicator & KeyStatusFlags.MK_XBUTTON1) != 0) {
2406                                         mb |= MouseButtons.XButton1;
2407                                 }
2408                                 if( (keyIndicator & KeyStatusFlags.MK_XBUTTON2) != 0) {
2409                                         mb |= MouseButtons.XButton2;
2410                                 }
2411
2412                                 return new MouseEventArgs( mb, (mb != MouseButtons.None) ? 1: 0, msg.LoWordLParam, msg.HiWordLParam, 0);
2413                         }
2414
2415                 // WndProc - calls appriate On... function for the give
2416                 // message
2417                 //
2418                 // These On... functions do not appear to be called by
2419                 // WndProc:
2420                 //
2421                 // background color/image handled by WinForms
2422                 // OnBackColorChanged
2423                 // OnBackgroundImageChanged
2424                 // OnForeColorChanged
2425                 // OnPaintBackground
2426                 //
2427                 // controls are added/removed by WinForms
2428                 // OnControlAdded
2429                 // OnControlRemoved
2430                 // OnCreateControl
2431                 //
2432                 // OnBindingContextChanged
2433                 // OnCausesValidationChanged
2434                 // OnChangeUICues
2435                 // OnContextMenuChanged
2436                 // OnRightToLeftChanged
2437                 // OnGiveFeedback
2438                 // OnLayout
2439                 // OnDockChanged
2440                 // OnCursorChanged
2441                 // OnTextAlignChanged
2442                 // OnValidated
2443                 // OnValidating
2444                 // OnTabIndexChanged
2445                 // OnTabStopChanged
2446                 // OnLocationChanged
2447                 //
2448                 // FIXME: may be one of the WM_IME_ messages
2449                 // OnImeModeChanged 
2450                 //
2451                 // InvalidateRect is called by no Invalidate message exists
2452                 // OnInvalidated
2453                 //
2454                 // these messages ARE not called by WNDPROC according to docs
2455                 // OnParentBackColorChanged 
2456                 // OnParentBackgroundImageChanged
2457                 // OnParentBindingContextChanged
2458                 // OnParentChanged
2459                 // OnParentEnabledChanged
2460                 // OnParentFontChanged
2461                 // OnParentForeColorChanged
2462                 // OnParentRightToLeftChanged
2463                 // OnParentVisibleChanged
2464                 //
2465                 protected virtual void WndProc(ref Message m) 
2466                 {
2467                         EventArgs eventArgs = new EventArgs ();
2468                         // FIXME: paintEventArgs is not being created properly
2469                                 // FIXME: Graphics does not have a public constructor, you must get one from .NET
2470                         //PaintEventArgs paintEventArgs = new PaintEventArgs (
2471                         //      new Graphics(), new Rectangle());
2472
2473                                 if( (uint)m.Msg == Control.InvokeMessage) {
2474                                         ControlInvokeHelper helper = null;
2475                                         lock( InvokeQueue_.SyncRoot) {
2476                                                 if( InvokeQueue_.Count > 0) {
2477                                                         helper = (ControlInvokeHelper)InvokeQueue_.Dequeue();
2478                                                 }
2479                                         }
2480                                         if( helper != null) {
2481                                                 helper.ExecuteMethod();
2482                                         }
2483                                         return;
2484                                 }
2485                                 else if( m.Msg == Msg.WM_COMMAND) {
2486                                         // Notification
2487                                         m.Result = (IntPtr)1;
2488                                         OnWmCommand (ref m);
2489                                         if( m.Result != IntPtr.Zero) {
2490                                                 CallControlWndProc (ref m);
2491                                         }
2492                                         return;
2493                                 }
2494
2495                         switch (m.Msg) {
2496                         case Msg.WM_CREATE:
2497                                 Console.WriteLine ("WM_CREATE");
2498                                 OnHandleCreated (eventArgs);
2499                                 break;
2500                         case Msg.WM_LBUTTONDBLCLK:
2501                                 OnDoubleClick (eventArgs);
2502                                         CallControlWndProc(ref m);
2503                                 break;
2504                                 // OnDragDrop
2505                                 // OnDragEnter
2506                                 // OnDragLeave
2507                                 // OnDragOver
2508                                 // OnQueryContinueDrag
2509                         case Msg.WM_ENABLE:
2510                                 OnEnabledChanged (eventArgs);
2511                                         CallControlWndProc(ref m);
2512                                         break;
2513                         case Msg.WM_SETFOCUS:
2514                                 OnEnter (eventArgs);
2515                                 OnGotFocus (eventArgs);
2516                                         CallControlWndProc(ref m);
2517                                         break;
2518                         case Msg.WM_FONTCHANGE:
2519                                 OnFontChanged (eventArgs);
2520                                         CallControlWndProc(ref m);
2521                                         break;
2522                         case Msg.WM_DESTROY:
2523                                 OnHandleDestroyed (eventArgs);
2524                                         CallControlWndProc(ref m);
2525                                         break;
2526                         case Msg.WM_HELP:
2527                                 // FIXME:
2528                                 //OnHelpRequested (eventArgs);
2529                                         CallControlWndProc(ref m);
2530                                         break;
2531                         case Msg.WM_KEYDOWN:
2532                                 // FIXME:
2533                                 // OnKeyDown (eventArgs);
2534                                         CallControlWndProc(ref m);
2535                                         break;
2536                         case Msg.WM_CHAR:
2537                                 // FIXME:
2538                                 // OnKeyPress (eventArgs);
2539                                         CallControlWndProc(ref m);
2540                                         break;
2541                         case Msg.WM_KEYUP:
2542                                 // FIXME:
2543                                 OnKeyUp ( new KeyEventArgs ( (Keys)m.WParam.ToInt32() ) );
2544                                 CallControlWndProc(ref m);
2545                                 break;
2546                         case Msg.WM_KILLFOCUS:
2547                                 OnLeave (eventArgs);
2548                                 OnLostFocus (eventArgs);
2549                                         CallControlWndProc(ref m);
2550                                         break;
2551                         case Msg.WM_MOUSEACTIVATE:
2552                                 //OnMouseEnter (eventArgs);
2553                                         CallControlWndProc(ref m);
2554                                         break;
2555                         case Msg.WM_MOUSEHOVER: // called by TrackMouseEvent
2556                                 OnMouseHover (eventArgs);
2557                                         CallControlWndProc(ref m);
2558                                         break;
2559                         case Msg.WM_MOUSELEAVE: // called by TrackMouseEvent
2560                                 OnMouseLeave (eventArgs);
2561                                         CallControlWndProc(ref m);
2562                                         break;
2563                         case Msg.WM_MOUSEMOVE:
2564                                 // FIXME:
2565                                 OnMouseMove (Msg2MouseEventArgs(ref m));
2566                                         CallControlWndProc(ref m);
2567                                         break;
2568                                 case Msg.WM_LBUTTONDOWN:
2569                                         // FIXME:
2570                                         //OnMouseDown (eventArgs);
2571                                         CallControlWndProc(ref m);
2572                                         break;
2573                                 case Msg.WM_LBUTTONUP:
2574                                 // FIXME:
2575                                 //OnMouseUp (eventArgs);
2576                                         CallControlWndProc(ref m);
2577                                         break;
2578                         case Msg.WM_MOUSEWHEEL:
2579                                 // FIXME:
2580                                 //OnMouseWheel (eventArgs);
2581                                         CallControlWndProc(ref m);
2582                                         break;
2583                         case Msg.WM_MOVE:
2584                                 OnMove (eventArgs);
2585                                 UpdateBounds ( );
2586                                 CallControlWndProc(ref m);
2587                                 break;
2588                                 case Msg.WM_NOTIFY:
2589                                         NMHDR nmhdr = (NMHDR)Marshal.PtrToStructure ( m.LParam,
2590                                                                         typeof ( NMHDR ) );
2591                                         if( !Control.ReflectMessage( nmhdr.hwndFrom, ref m )) 
2592                                                 CallControlWndProc(ref m);
2593                                         
2594                                         // FIXME: get NM_CLICKED msg from pnmh
2595                                         // OnClick (eventArgs);
2596                                         //OnNotifyMessage (eventArgs);
2597                                         break;
2598                         case Msg.WM_ERASEBKGND:
2599                                 if( GetStyle(ControlStyles.UserPaint)){
2600                                         if( !GetStyle(ControlStyles.AllPaintingInWmPaint)) {
2601                                                         PaintEventArgs eraseEventArgs = new PaintEventArgs( Graphics.FromHdc(m.WParam), new Rectangle(new Point(0,0),Size));
2602                                                 OnPaintBackground(eraseEventArgs);
2603                                                         eraseEventArgs.Dispose();
2604                                         }
2605                                         m.Result = (IntPtr)1;
2606                                 }
2607                                 else {
2608                                                 CallControlWndProc(ref m);
2609                                 }
2610                                 break;
2611                                 case Msg.WM_PAINT:
2612                                         if( !GetStyle(ControlStyles.UserPaint)) {
2613                                                 CallControlWndProc(ref m);
2614                                         }
2615                                         else {
2616                                                 PAINTSTRUCT     ps = new PAINTSTRUCT();
2617                                                 IntPtr hdc = Win32.BeginPaint( Handle, ref ps);
2618                                                 Rectangle rc = new Rectangle();
2619                                                 rc.X = ps.rcPaint.left;
2620                                                 rc.Y = ps.rcPaint.top;
2621                                                 rc.Width = ps.rcPaint.right - ps.rcPaint.left;
2622                                                 rc.Height = ps.rcPaint.bottom - ps.rcPaint.top;
2623                                                 PaintEventArgs paintEventArgs = new PaintEventArgs( Graphics.FromHdc(hdc), rc);
2624                                         if( GetStyle(ControlStyles.AllPaintingInWmPaint)) {
2625                                                 OnPaintBackground(paintEventArgs);
2626                                         }
2627                                                 OnPaint (paintEventArgs);
2628                                                 paintEventArgs.Dispose();
2629                                                 Win32.EndPaint(Handle, ref ps);
2630                                         }
2631                                         break;
2632                         case Msg.WM_SIZE:
2633                                 OnResize (eventArgs);
2634                                 UpdateBounds ( );
2635                                 if( GetStyle(ControlStyles.ResizeRedraw)) {
2636                                         Invalidate();           
2637                                 }
2638                                 CallControlWndProc(ref m);
2639                                 break;
2640                         case Msg.WM_WINDOWPOSCHANGED:
2641                                 UpdateBounds ( );
2642                                 CallControlWndProc(ref m);
2643                         break;
2644                         case Msg.WM_STYLECHANGED:
2645                                 OnStyleChanged (eventArgs);
2646                                         CallControlWndProc(ref m);
2647                                         break;
2648                         case Msg.WM_SYSCOLORCHANGE:
2649                                 OnSystemColorsChanged (eventArgs);
2650                                         CallControlWndProc(ref m);
2651                                         break;
2652                         case Msg.WM_SETTEXT:
2653                                 OnTextChanged (eventArgs);
2654                                         CallControlWndProc(ref m);
2655                                         break;
2656                         case Msg.WM_SETFONT:
2657                                 //OnTextChanged (eventArgs);
2658                                         CallControlWndProc(ref m);
2659                                         break;
2660                         case Msg.WM_SHOWWINDOW:
2661                                 OnVisibleChanged (eventArgs);
2662                                         CallControlWndProc(ref m);
2663                                         break;
2664                                 case Msg.WM_CTLCOLORLISTBOX:
2665                                         Win32.SetTextColor( m.WParam, Win32.RGB(ForeColor));
2666                                         //Win32.SetBkColor( m.WParam, 0x00FF00);
2667                                         //m.Result = Win32.GetStockObject(GSO_.LTGRAY_BRUSH);
2668                                         break;
2669                                 case Msg.WM_MEASUREITEM:
2670                                         ReflectMessage( m.WParam, ref m);
2671                                         break;
2672                                 case Msg.WM_DRAWITEM:
2673                                         Control.ReflectMessage( m.WParam, ref m);
2674                                         break;
2675                                 case Msg.WM_HSCROLL:
2676                                 case Msg.WM_VSCROLL:
2677                                         if(!Control.ReflectMessage( m.LParam, ref m )) {
2678                                         CallControlWndProc(ref m);
2679                                         }
2680                                         break;
2681                                 default:
2682                                         CallControlWndProc(ref m);
2683 /*
2684                                         if( ControlRealWndProc != IntPtr.Zero) {
2685                                                 CallControlWndProc(ref m);
2686                                         }
2687                                         else {
2688                                                 DefWndProc (ref m);
2689                                         }
2690 */                                      
2691                                 break;
2692                         }
2693                 }
2694
2695                 private void DoDockAndAnchorLayout ( LayoutEventArgs e ) {
2696                         Rectangle area = DisplayRectangle;
2697                         
2698                         for ( int i = childControls.Count - 1; i >= 0; i-- ) {
2699                                 Control control = childControls[i];
2700                                 
2701                                 switch ( control.Dock ) {
2702                                 case DockStyle.Bottom:
2703                                         control.SetBounds ( area.Left, area.Bottom - control.Height,
2704                                                                 area.Width, control.Height );
2705                                         area.Height -= control.Height;
2706                                 break;
2707                                 case DockStyle.Top:
2708                                         control.SetBounds ( area.Left, area.Y, area.Width, control.Height );
2709                                         area.Y += control.Height;
2710                                         area.Height -= control.Height;
2711                                 break;
2712                                 case DockStyle.Right:
2713                                         control.SetBounds ( area.Right - control.Width, area.Top,
2714                                                                 control.Width, area.Height );
2715                                         area.Width -= control.Width;
2716                                 break;
2717                                 case DockStyle.Left:
2718                                         control.SetBounds ( area.Left, area.Y, control.Width, area.Height );
2719                                         area.X += control.Width;
2720                                         area.Width -= control.Width;
2721                                 break;
2722                                 }
2723                         }
2724
2725                         for ( int i = childControls.Count - 1; i >= 0; i-- ) {
2726                                 Control control = childControls[i];
2727                                 
2728                                 if ( control.Dock == DockStyle.Fill ) {
2729                                         control.SetBounds ( area.X, area.Y, area.Width, area.Height );
2730                                 }       
2731                         }
2732                 }
2733                 
2734                 /// --- Control: events ---
2735                 public event EventHandler BackColorChanged;
2736                 public event EventHandler BackgroundImageChanged;
2737                 public event EventHandler BindingContextChanged;
2738                 public event EventHandler CausesValidationChanged;
2739                 public event UICuesEventHandler ChangeUICues;
2740                 
2741                         //Compact Framework
2742                 public event EventHandler Click;
2743                 
2744                 public event EventHandler ContextMenuChanged;
2745                 public event ControlEventHandler ControlAdded;
2746                 public event ControlEventHandler ControlRemoved;
2747                 public event EventHandler CursorChanged;
2748                 public event EventHandler DockChanged;
2749                 public event EventHandler DoubleClick;
2750                 public event DragEventHandler DragDrop;
2751                 public event DragEventHandler DragEnter;
2752                 public event EventHandler DragLeave;
2753                 public event DragEventHandler DragOver;
2754
2755                         //Compact Framework
2756                 public event EventHandler EnabledChanged;
2757                 
2758                 public event EventHandler Enter;
2759                 public event EventHandler FontChanged;
2760                 public event EventHandler ForeColorChanged;
2761                 public event GiveFeedbackEventHandler GiveFeedback;
2762                 
2763                         //Compact Framework
2764                 public event EventHandler GotFocus;
2765                 
2766                 public event EventHandler HandleCreated;
2767                 public event EventHandler HandleDestroyed;
2768                 public event HelpEventHandler HelpRequested;
2769                 public event EventHandler ImeModeChanged;
2770                 public event InvalidateEventHandler Invalidated;
2771                 
2772                         //Compact Framework
2773                 public event KeyEventHandler KeyDown;
2774                 
2775                         //Compact Framework
2776                 public event KeyPressEventHandler KeyPress;
2777                 
2778                         //Compact Framework
2779                 public event KeyEventHandler KeyUp;
2780                 
2781                 public event LayoutEventHandler Layout;
2782                 public event EventHandler Leave;
2783                 public event EventHandler LocationChanged;
2784                 
2785                         //Compact Framework
2786                 public event EventHandler LostFocus;
2787
2788                         //Compact Framework
2789                 public event MouseEventHandler MouseDown;
2790                 
2791                 public event EventHandler MouseEnter;
2792                 public event EventHandler MouseHover;
2793                 public event EventHandler MouseLeave;
2794                 
2795                         //Compact Framework
2796                 public event MouseEventHandler MouseMove;
2797                 
2798                         //Compact Framework
2799                 public event MouseEventHandler MouseUp;
2800                 
2801                 public event MouseEventHandler MouseWheel;
2802                 public event EventHandler Move;
2803                 
2804                         //Compact Framework
2805                 public event PaintEventHandler Paint;
2806                 
2807                         //Compact Framework
2808                 public event EventHandler ParentChanged;
2809                 
2810                 public event QueryAccessibilityHelpEventHandler QueryAccessibilityHelp;
2811                 public event QueryContinueDragEventHandler QueryContinueDrag;
2812                 
2813                         //Compact Framework
2814                 public event EventHandler Resize;
2815                 
2816                 public event EventHandler RightToLeftChanged;
2817                 public event EventHandler SizeChanged;
2818                 public event EventHandler StyleChanged;
2819                 public event EventHandler SystemColorsChanged;
2820                 public event EventHandler TabIndexChanged;
2821                 public event EventHandler TabStopChanged;
2822                 
2823                         //Compact Framework
2824                 public event EventHandler TextChanged;
2825                 
2826                 public event EventHandler Validated;
2827                 //[MonoTODO]
2828                 // CancelEventHandler not yet defined
2829                 //public event CancelEventHandler Validating {
2830                 
2831                 public event EventHandler VisibleChanged;
2832                 
2833                 /// --- IWin32Window properties
2834                 public IntPtr Handle {
2835                         get { 
2836                                 // If the handle has not yet been created,
2837                                 // referencing this property will force the
2838                                 // handle to be created. ( MSDN )
2839
2840                                 if ( !IsHandleCreated ) 
2841                                         CreateHandle ( );
2842
2843                                 return window.Handle;
2844                         }
2845                 }
2846                 
2847                 /// --- ISynchronizeInvoke properties ---
2848                 [MonoTODO]
2849                 public bool InvokeRequired {
2850                         get { 
2851                                         return CreatorThreadId_ != Win32.GetCurrentThreadId(); 
2852                                 }
2853                 }
2854                 
2855                         private IAsyncResult DoInvoke( Delegate method, object[] args) {
2856                                 IAsyncResult result = null;
2857                                 ControlInvokeHelper helper = new ControlInvokeHelper(method, args);
2858                                 if( InvokeRequired) {
2859                                         lock( this) {
2860                                                 lock( InvokeQueue_.SyncRoot) {
2861                                                         InvokeQueue_.Enqueue(helper);
2862                                                 }
2863                                                 Win32.PostMessage(Handle, Control.InvokeMessage, 0, 0);
2864                                                 result = helper;
2865                                         }
2866                                 }
2867                                 else {
2868                                         helper.CompletedSynchronously = true;
2869                                         helper.ExecuteMethod();
2870                                         result = helper;
2871                                 }
2872                                 return result;
2873                         }
2874
2875                 /// --- ISynchronizeInvoke methods ---
2876                 [MonoTODO]
2877                 public IAsyncResult BeginInvoke (Delegate method) 
2878                 {
2879                                 return DoInvoke( method, null);
2880                 }
2881                 
2882                 [MonoTODO]
2883                 public IAsyncResult BeginInvoke (Delegate method, object[] args) 
2884                 {
2885                                 return DoInvoke( method, args);
2886                         }
2887                 
2888                 [MonoTODO]
2889                 public object EndInvoke (IAsyncResult asyncResult) 
2890                 {
2891                                 object result = null;
2892                                 ControlInvokeHelper helper = asyncResult as ControlInvokeHelper;
2893                                 if( helper != null) {
2894                                         if( !asyncResult.CompletedSynchronously) {
2895                                                 asyncResult.AsyncWaitHandle.WaitOne();
2896                                         }
2897                                         result = helper.MethodResult;
2898                                 }
2899                                 return result;
2900                         }
2901                 
2902                 //Compact Framework
2903                 [MonoTODO]
2904                 public object Invoke (Delegate method) 
2905                 {
2906                                 return Invoke( method, null);
2907                         }
2908                 
2909                 //[MonoTODO]
2910                 public object Invoke (Delegate method, object[] args) 
2911                 {
2912                                 IAsyncResult result = BeginInvoke(method, args);
2913                                 return EndInvoke(result);
2914                         }
2915                 
2916                 /// sub-class: Control.ControlAccessibleObject
2917                 /// <summary>
2918                 /// Provides information about a control that can be used by an accessibility application.
2919                 /// </summary>
2920                 public class ControlAccessibleObject : AccessibleObject {
2921                         // AccessibleObject not ready to be base class
2922                         /// --- ControlAccessibleObject.constructor ---
2923                         [MonoTODO]
2924                         public ControlAccessibleObject (Control ownerControl) 
2925                         {
2926                                 throw new NotImplementedException ();
2927                         }
2928                         
2929                         
2930                         /// --- ControlAccessibleObject Properties ---
2931                         [MonoTODO]
2932                         public override string DefaultAction {
2933                                 get {
2934                                                 //FIXME:
2935                                                 return base.DefaultAction;
2936                                         }
2937                         }
2938                         
2939                         [MonoTODO]
2940                         public override string Description {
2941                                 get {
2942                                                 //FIXME:
2943                                                 return base.Description;
2944                                         }
2945                         }
2946                         
2947                         [MonoTODO]
2948                         public IntPtr Handle {
2949                                 get {
2950                                                 throw new NotImplementedException ();
2951                                         }
2952                                 set {
2953                                                 //FIXME:
2954                                         }
2955                         }
2956                         
2957                         [MonoTODO]
2958                         public override string Help {
2959                                 get {
2960                                                 //FIXME:
2961                                                 return base.Help;
2962                                         }
2963                         }
2964                         
2965                         [MonoTODO]
2966                         public override string KeyboardShortcut {
2967                                 get {
2968                                                 //FIXME:
2969                                                 return base.KeyboardShortcut;
2970                                         }
2971                         }
2972                         
2973                         [MonoTODO]
2974                         public override string Name {
2975                                 get {
2976                                                 //FIXME:
2977                                                 return base.Name;
2978                                         }
2979                                 set {
2980                                                 //FIXME:
2981                                                 base.Name = value;
2982                                         }
2983                         }
2984                         
2985                         [MonoTODO]
2986                         public Control Owner {
2987                                 get { 
2988                                                 throw new NotImplementedException ();
2989                                         }
2990                         }
2991                         
2992                         [MonoTODO]
2993                         public override AccessibleRole Role {
2994                                 get {
2995                                                 //FIXME:
2996                                                 return base.Role;
2997                                         }
2998                         }
2999                         
3000                         /// --- ControlAccessibleObject Methods ---
3001                         [MonoTODO]
3002                         public override int GetHelpTopic(out string fileName) 
3003                         {
3004                                         //FIXME:
3005                                         return base.GetHelpTopic(out fileName);
3006                                 }
3007                         
3008                         [MonoTODO]
3009                         public void NotifyClients (AccessibleEvents accEvent) 
3010                         {
3011                                         //FIXME:
3012                         }
3013                         
3014                         [MonoTODO]
3015                         public void NotifyClients (AccessibleEvents accEvent,
3016                                                    int childID) 
3017                         {
3018                                         //FIXME:
3019                                 }
3020                         
3021                         [MonoTODO]
3022                         public override string ToString ()
3023                         {
3024                                         //FIXME:
3025                                         return base.ToString();
3026                                 }
3027                 }
3028                 
3029                 /// sub-class: Control.ControlCollection
3030                 /// <summary>
3031                 /// Represents a collection of Control objects
3032                 /// </summary>
3033                 public class ControlCollection : IList, ICollection, IEnumerable, ICloneable {
3034     
3035                         private ArrayList collection = new ArrayList ();
3036                         protected Control owner;
3037     
3038                         /// --- ControlCollection.constructor ---
3039                         public ControlCollection (Control owner) 
3040                         {
3041                                 this.owner = owner;
3042                         }
3043                 
3044                         /// --- ControlCollection Properties ---
3045                         public int Count {
3046                                 get {
3047                                                 return collection.Count;
3048                                         }
3049                         }
3050                 
3051                         public bool IsReadOnly {
3052                                 get {
3053                                                 return collection.IsReadOnly;
3054                                         }
3055                         }
3056                         
3057                         public virtual Control this [int index] {
3058                                 get {
3059                                                 return (Control) collection[index];
3060                                         }
3061                         }
3062                 
3063                         public virtual void Add (Control value) 
3064                         {
3065                                         if( !Contains(value)) {
3066                                                 collection.Add (value);
3067                                                 value.Parent = owner;
3068                                         }
3069                                 }
3070                         
3071                         public virtual void AddRange (Control[] controls) 
3072                         {
3073                                         for(int i = 0; i < controls.Length; i++) {
3074                                                 Add(controls[i]);
3075                                         }
3076                         }
3077                         
3078                         public virtual void Clear () 
3079                         {
3080                                 collection.Clear ();
3081                         }
3082                 
3083                         public bool Contains (Control control) 
3084                         {
3085                                 return collection.Contains (control);
3086                         }
3087                         
3088                         public void CopyTo (Array dest,int index) 
3089                         {
3090                                 collection.CopyTo (dest, index);
3091                         }
3092                         
3093                         [MonoTODO]
3094                         public override bool Equals (object obj) 
3095                         {
3096                                         //FIXME:
3097                                         return base.Equals(obj);
3098                         }
3099
3100                         [MonoTODO]
3101                         public int GetChildIndex (Control child)
3102                         {
3103                                 throw new NotImplementedException ();
3104                         }
3105                         
3106                         public IEnumerator GetEnumerator () 
3107                         {
3108                                 return collection.GetEnumerator ();
3109                         }
3110                         
3111                         [MonoTODO]
3112                         public override int GetHashCode () 
3113                         {
3114                                         //FIXME:
3115                                         return base.GetHashCode();
3116                                 }
3117                         
3118                         public int IndexOf (Control control) 
3119                         {
3120                                 return collection.IndexOf (control);
3121                         }
3122                         
3123                         public virtual void Remove (Control value) 
3124                         {
3125                                 collection.Remove (value);
3126                         }
3127                         
3128                         public void RemoveAt (int index) 
3129                         {
3130                                 Remove ( this [ index ] );
3131                                 // have to give a chance to handle this situation in derived class
3132                                 //collection.RemoveAt (index);
3133                         }
3134                         
3135                         [MonoTODO]
3136                         public void SetChildIndex (Control child,int newIndex) 
3137                         {
3138                                         //FIXME:
3139                         }
3140                         
3141                         /// --- ControlCollection.IClonable methods ---
3142                         [MonoTODO]
3143                         object ICloneable.Clone ()
3144                         {
3145                                 throw new NotImplementedException ();
3146                         }
3147                         
3148                         /// --- ControlCollection.IList properties ---
3149                         bool IList.IsFixedSize {
3150                                 get {
3151                                                 return collection.IsFixedSize;
3152                                         }
3153                         }
3154     
3155                         object IList.this [int index] {
3156                                 get {
3157                                                 return collection[index];
3158                                         }
3159                                 set {
3160                                                 collection[index] = value;
3161                                         }
3162                         }
3163     
3164                         object ICollection.SyncRoot {
3165                                 get {
3166                                                 return collection.SyncRoot;
3167                                         }
3168                         }
3169         
3170                         bool ICollection.IsSynchronized {
3171                                 get {
3172                                                 return collection.IsSynchronized;
3173                                         }
3174                         }
3175                         
3176                         /// --- ControlCollection.IList methods ---
3177                         int IList.Add (object control) 
3178                         {
3179                                 return collection.Add (control);
3180                         }
3181                 
3182                         bool IList.Contains (object control) 
3183                         {
3184                                 return collection.Contains (control);
3185                         }
3186                 
3187                         int IList.IndexOf (object control) 
3188                         {
3189                                 return collection.IndexOf (control);
3190                         }
3191                 
3192                         void IList.Insert (int index,object value) 
3193                         {
3194                                 collection.Insert (index, value);
3195                         }
3196                 
3197                         void IList.Remove (object control) 
3198                         {
3199                                 collection.Remove (control);
3200                         }
3201                 }  // --- end of Control.ControlCollection ---
3202         }
3203     }