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