89f91da939c0baf542260b71880a5ca72601da80
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / XplatUI.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2004-2006 Novell, Inc.
21 //
22 // Authors:
23 //      Peter Bartok    pbartok@novell.com
24
25 // NOT COMPLETE
26
27 // define to log API calls to stdout
28 #undef DriverDebug
29 #undef DriverDebugPaint
30 #undef DriverDebugCreate
31 #undef DriverDebugDestroy
32 #undef DriverDebugState
33
34 using System;
35 using System.Drawing;
36 using System.ComponentModel;
37 using System.Collections;
38 using System.Diagnostics;
39 using System.Runtime.InteropServices;
40 using System.Threading;
41
42 namespace System.Windows.Forms {
43         internal class XplatUI {
44                 #region Local Variables
45                 static XplatUIDriver            driver;
46 //              static String                   default_class_name;
47                 internal static ArrayList key_filters = new ArrayList ();
48                 #endregion      // Local Variables
49
50                 #region Private Methods
51                 internal static string Window (IntPtr handle)
52                 {
53                         return String.Format ("'{0}' ({1:X})", Control.FromHandle (handle), handle.ToInt32 ());
54                 }
55
56                 [Conditional ("DriverDebug")]
57                 static void DriverDebug (string format, params object [] args)
58                 {
59                         Console.WriteLine (String.Format (format, args));
60                 }
61                 
62                 #endregion      // Private Methods
63
64                 #region Subclasses
65                 public class State {
66                         static public Keys ModifierKeys {
67                                 get {
68                                         return driver.ModifierKeys;
69                                 }
70                         }
71
72                         static public MouseButtons MouseButtons {
73                                 get {
74                                         return driver.MouseButtons;
75                                 }
76                         }
77
78                         static public Point MousePosition {
79                                 get {
80                                         return driver.MousePosition;
81                                 }
82                         }
83
84                 }
85                 #endregion      // Subclasses
86
87                 #region Constructor & Destructor
88                 static XplatUI ()
89                 {
90                         // Compose name with current domain id because on Win32 we register class name
91                         // and name must be unique to process. If we load MWF into multiple appdomains
92                         // and try to register same class name we fail.
93 //                      default_class_name = "SWFClass" + System.Threading.Thread.GetDomainID ().ToString ();
94
95                         if (RunningOnUnix) {
96                                 //if (Environment.GetEnvironmentVariable ("not_supported_MONO_MWF_USE_NEW_X11_BACKEND") != null) {
97                                 //        driver=XplatUIX11_new.GetInstance ();
98                                 //} else 
99                                 if (Environment.GetEnvironmentVariable ("MONO_MWF_MAC_FORCE_X11") != null) {
100                                         driver = XplatUIX11.GetInstance ();
101                                 } else {
102                                         IntPtr buf = Marshal.AllocHGlobal (8192);
103                                         // This is a hacktastic way of getting sysname from uname ()
104                                         if (uname (buf) != 0) {
105                                                 // WTF: We cannot run uname
106                                                 driver=XplatUIX11.GetInstance ();
107                                         } else {
108                                                 string os = Marshal.PtrToStringAnsi (buf);
109                                                 if (os == "Darwin")
110                                                         driver=XplatUICarbon.GetInstance ();
111                                                 else
112                                                         driver=XplatUIX11.GetInstance ();
113                                         }
114                                         Marshal.FreeHGlobal (buf);
115                                 }
116                         } else {
117                                 driver=XplatUIWin32.GetInstance ();
118                         }
119
120                         driver.InitializeDriver ();
121
122                         // Initialize things that need to be done after the driver is ready
123                         DataFormats.GetFormat (0);
124
125                         // Signal that the Application loop can be run.
126                         // This allows UIA to initialize a11y support for MWF
127                         // before the main loop begins.
128                         Application.FirePreRun ();
129                 }
130                 #endregion      // Constructor & Destructor
131
132                 #region Public Static Properties
133
134                 public static bool RunningOnUnix {
135                         get {
136                                 int p = (int) Environment.OSVersion.Platform;
137                                 
138                                 return (p == 4 || p == 6 || p == 128);
139                         }
140                 }
141
142                 public static int ActiveWindowTrackingDelay {
143                         get { return driver.ActiveWindowTrackingDelay; }
144                 }
145
146                 // Compose name with current domain id because on Win32 we register class name
147                 // and name must be unique to process. If we load MWF into multiple appdomains
148                 // and try to register same class name we fail.
149                 internal static string GetDefaultClassName (Type type)
150                 {
151                         return "SWFClass" + Thread.GetDomainID ().ToString () + "." + type.ToString ();
152                 }
153
154                 static public Size Border3DSize {
155                         get {
156                                 return driver.Border3DSize;
157                         }
158                 }
159
160                 static public Size BorderSize {
161                         get {
162                                 return driver.BorderSize;
163                         }
164                 }
165
166                 static public Size CaptionButtonSize {
167                         get {
168                                 return driver.CaptionButtonSize;
169                         }
170                 }
171
172                 static public int CaptionHeight {
173                         get {
174                                 return driver.CaptionHeight;
175                         }
176                 }
177
178                 public static int CaretBlinkTime { get { return driver.CaretBlinkTime; } }
179                 public static int CaretWidth { get { return driver.CaretWidth; } }
180                 
181                 static public Size CursorSize {
182                         get {
183                                 return driver.CursorSize;
184                         }
185                 }
186
187                 static public Size DoubleClickSize {
188                         get {
189                                 return driver.DoubleClickSize;
190                         }
191                 }
192
193                 static public int DoubleClickTime {
194                         get {
195                                 return driver.DoubleClickTime;
196                         }
197                 }
198
199                 static public bool DragFullWindows {
200                         get {
201                                 return driver.DragFullWindows;
202                         }
203                 }
204
205                 static public Size DragSize {
206                         get {
207                                 return driver.DragSize;
208                         }
209                 }
210
211                 static public Size FixedFrameBorderSize {
212                         get {
213                                 return driver.FixedFrameBorderSize;
214                         }
215                 }
216
217                 public static int FontSmoothingContrast { get { return driver.FontSmoothingContrast; } }
218                 public static int FontSmoothingType { get { return driver.FontSmoothingType; } }
219
220                 public static Size FrameBorderSize {
221                         get {
222                                 return driver.FrameBorderSize;
223                         }
224                 }
225
226                 public static int HorizontalResizeBorderThickness { get { return driver.HorizontalResizeBorderThickness; } }
227                 
228                 static public int HorizontalScrollBarHeight {
229                         get {
230                                 return driver.HorizontalScrollBarHeight;
231                         }
232                 }
233
234                 static public Size IconSize {
235                         get {
236                                 return driver.IconSize;
237                         }
238                 }
239
240                 public static bool IsActiveWindowTrackingEnabled { get { return driver.IsActiveWindowTrackingEnabled; } }
241                 public static bool IsComboBoxAnimationEnabled { get { return driver.IsComboBoxAnimationEnabled; } }
242                 public static bool IsDropShadowEnabled { get { return driver.IsDropShadowEnabled; } }
243                 public static bool IsFontSmoothingEnabled { get { return driver.IsFontSmoothingEnabled; } }
244                 public static bool IsHotTrackingEnabled { get { return driver.IsHotTrackingEnabled; } }
245                 public static bool IsIconTitleWrappingEnabled { get { return driver.IsIconTitleWrappingEnabled; } }
246                 public static bool IsKeyboardPreferred { get { return driver.IsKeyboardPreferred; } }
247                 public static bool IsListBoxSmoothScrollingEnabled { get { return driver.IsListBoxSmoothScrollingEnabled; } }
248                 public static bool IsMenuAnimationEnabled { get { return driver.IsMenuAnimationEnabled; } }
249                 public static bool IsMenuFadeEnabled { get { return driver.IsMenuFadeEnabled; } }
250                 public static bool IsMinimizeRestoreAnimationEnabled { get { return driver.IsMinimizeRestoreAnimationEnabled; } }
251                 public static bool IsSelectionFadeEnabled { get { return driver.IsSelectionFadeEnabled; } }
252                 public static bool IsSnapToDefaultEnabled { get { return driver.IsSnapToDefaultEnabled; } }
253                 public static bool IsTitleBarGradientEnabled { get { return driver.IsTitleBarGradientEnabled; } }
254                 public static bool IsToolTipAnimationEnabled { get { return driver.IsToolTipAnimationEnabled; } }
255                 
256                 static public int KeyboardSpeed {
257                         get {
258                                 return driver.KeyboardSpeed;
259                         }
260                 }
261
262                 static public int KeyboardDelay {
263                         get {
264                                 return driver.KeyboardDelay;
265                         }
266                 }
267
268                 static public Size MaxWindowTrackSize {
269                         get {
270                                 return driver.MaxWindowTrackSize;
271                         }
272                 }
273
274                 static public bool MenuAccessKeysUnderlined {
275                         get {
276                                 return driver.MenuAccessKeysUnderlined;
277                         }
278                 }
279
280                 static public Size MenuBarButtonSize { get { return driver.MenuBarButtonSize; } }
281
282                 public static Size MenuButtonSize {
283                         get {
284                                 return driver.MenuButtonSize;
285                         }
286                 }
287
288                 static public int MenuShowDelay { get { return driver.MenuShowDelay; } }
289                 
290                 static public Size MinimizedWindowSize {
291                         get {
292                                 return driver.MinimizedWindowSize;
293                         }
294                 }
295
296                 static public Size MinimizedWindowSpacingSize {
297                         get {
298                                 return driver.MinimizedWindowSpacingSize;
299                         }
300                 }
301
302                 static public Size MinimumWindowSize {
303                         get {
304                                 return driver.MinimumWindowSize;
305                         }
306                 }
307
308                 static public Size MinimumFixedToolWindowSize {
309                         get { return driver.MinimumFixedToolWindowSize; }
310                 }
311
312                 static public Size MinimumSizeableToolWindowSize {
313                         get { return driver.MinimumSizeableToolWindowSize; }
314                 }
315
316                 static public Size MinimumNoBorderWindowSize {
317                         get { return driver.MinimumNoBorderWindowSize; }
318                 }
319
320                 static public Size MinWindowTrackSize {
321                         get {
322                                 return driver.MinWindowTrackSize;
323                         }
324                 }
325
326                 public static int MouseSpeed {
327                         get { return driver.MouseSpeed; }
328                 }
329                 
330                 static public Size SmallIconSize {
331                         get {
332                                 return driver.SmallIconSize;
333                         }
334                 }
335
336                 static public int MenuHeight {
337                         get {
338                                 return driver.MenuHeight;
339                         }
340                 }
341
342                 static public int MouseButtonCount {
343                         get {
344                                 return driver.MouseButtonCount;
345                         }
346                 }
347
348                 static public bool MouseButtonsSwapped {
349                         get {
350                                 return driver.MouseButtonsSwapped;
351                         }
352                 }
353
354                 static public Size MouseHoverSize {
355                         get {
356                                 return driver.MouseHoverSize;
357                         }
358                 }
359
360                 static public int MouseHoverTime {
361                         get {
362                                 return driver.MouseHoverTime;
363                         }
364                 }
365
366                 static public int MouseWheelScrollDelta {
367                         get {
368                                 return driver.MouseWheelScrollDelta;
369                         }
370                 }
371                 
372                 static public bool MouseWheelPresent {
373                         get {
374                                 return driver.MouseWheelPresent;
375                         }
376                 }
377
378                 public static LeftRightAlignment PopupMenuAlignment {
379                         get { return driver.PopupMenuAlignment; }
380                 }
381                 
382                 public static PowerStatus PowerStatus {
383                         get { return driver.PowerStatus; }
384                 }
385
386                 public static bool RequiresPositiveClientAreaSize {
387                         get {
388                                 return driver.RequiresPositiveClientAreaSize;
389                         }
390                 }
391
392                 public static int SizingBorderWidth {
393                         get { return driver.SizingBorderWidth; }
394                 }
395                 
396                 public static Size SmallCaptionButtonSize {
397                         get { return driver.SmallCaptionButtonSize; }
398                 }
399                 
400                 public static bool UIEffectsEnabled {
401                         get { return driver.UIEffectsEnabled; }
402                 }
403                 
404                 static public bool UserClipWontExposeParent {
405                         get {
406                                 return driver.UserClipWontExposeParent;
407                         }
408                 }
409
410                 public static int VerticalResizeBorderThickness { get { return driver.VerticalResizeBorderThickness; } }
411
412                 static public int VerticalScrollBarWidth {
413                         get {
414                                 return driver.VerticalScrollBarWidth;
415                         }
416                 }
417
418                 static public Rectangle VirtualScreen {
419                         get {
420                                 return driver.VirtualScreen;
421                         }
422                 }
423
424                 static public Rectangle WorkingArea {
425                         get {
426                                 return driver.WorkingArea;
427                         }
428                 }
429
430                 public static bool ThemesEnabled {
431                         get {
432                                 return XplatUI.driver.ThemesEnabled;
433                         }
434                 }
435
436                 public static int ToolWindowCaptionHeight {
437                         get {
438                                 return driver.ToolWindowCaptionHeight;
439                         }
440                 }
441
442                 public static Size ToolWindowCaptionButtonSize {
443                         get {
444                                 return driver.ToolWindowCaptionButtonSize;
445                         }
446                 }
447                 #endregion      // Public Static Properties
448
449                 #region Events
450
451                 internal static event EventHandler Idle {
452                         add {
453                                 driver.Idle += value;
454                         }
455                         remove {
456                                 driver.Idle -= value;
457                         }
458                 }
459
460                 #endregion      // Events
461
462                 #region Public Static Methods
463                 internal static void Activate (IntPtr handle)
464                 {
465                         DriverDebug ("Activate ({0}): Called", Window (handle));
466                         driver.Activate (handle);
467                 }
468
469                 internal static void AudibleAlert (AlertType alert)
470                 {
471                         DriverDebug ("AudibleAlert (): Called");
472                         driver.AudibleAlert (alert);
473                 }
474
475                 internal static void BeginMoveResize (IntPtr handle)
476                 {
477                         driver.BeginMoveResize (handle);
478                 }
479
480                 internal static bool CalculateWindowRect (ref Rectangle ClientRect, CreateParams cp, Menu menu, out Rectangle WindowRect)
481                 {
482                         DriverDebug ("CalculateWindowRect ({0}, {1}, {2}): Called", ClientRect, cp, menu);
483                         return driver.CalculateWindowRect (ref ClientRect, cp, menu, out WindowRect);
484                 }
485
486                 internal static void CaretVisible (IntPtr handle, bool visible)
487                 {
488                         DriverDebug ("CaretVisible ({0:X}, {1}): Called", handle.ToInt32 (), visible);
489                         driver.CaretVisible (handle, visible);
490                 }
491
492                 internal static void CreateCaret (IntPtr handle, int width, int height)
493                 {
494                         DriverDebug ("CreateCaret ({0:X}), {1}, {2}: Called", handle.ToInt32 (), width, height);
495                         driver.CreateCaret (handle, width, height);
496                 }
497
498                 internal static IntPtr CreateWindow (CreateParams cp)
499                 {
500                         #if DriverDebug || DriverDebugCreate
501                                 IntPtr handle;
502
503                                 handle = driver.CreateWindow (cp);
504
505                                 Console.WriteLine ("CreateWindow (): Called, returning {0:X}", handle.ToInt32 ());
506                                 return handle;
507                         #else
508                                 return driver.CreateWindow (cp);
509                         #endif
510                 }
511
512                 internal static IntPtr CreateWindow (IntPtr Parent, int X, int Y, int Width, int Height)
513                 {
514                         #if DriverDebug || DriverDebugCreate
515                                 Console.WriteLine ("CreateWindow (): Called");
516                         #endif
517                         return driver.CreateWindow (Parent, X, Y, Width, Height);
518                 }
519
520                 internal static void ClientToScreen (IntPtr handle, ref int x, ref int y)
521                 {
522                         #if DriverDebug
523                                 Console.WriteLine ("ClientToScreen ({0}, {1}, {2}): Called", Window (handle), x, y);
524                         #endif
525                         driver.ClientToScreen (handle, ref x, ref y);
526                 }
527
528                 internal static int[] ClipboardAvailableFormats (IntPtr handle)
529                 {
530                         DriverDebug ("ClipboardAvailableTypes ({0:X}): Called", handle.ToInt32 ());
531                         return driver.ClipboardAvailableFormats (handle);
532                 }
533
534                 internal static void ClipboardClose (IntPtr handle)
535                 {
536                         DriverDebug ("ClipboardClose ({0:X}): Called", handle.ToInt32 ());
537                         driver.ClipboardClose (handle);
538                 }
539
540                 internal static int ClipboardGetID (IntPtr handle, string format)
541                 {
542                         DriverDebug ("ClipboardGetID ({0:X}, {1}): Called", handle.ToInt32 (), format);
543                         return driver.ClipboardGetID (handle, format);
544                 }
545
546                 internal static IntPtr ClipboardOpen (bool primary_selection)
547                 {
548                         DriverDebug ("ClipboardOpen (): Called");
549                         return driver.ClipboardOpen (primary_selection);
550                 }
551
552                 internal static void ClipboardStore (IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter, bool copy)
553                 {
554                         DriverDebug ("ClipboardStore ({0:X}, {1}, {2}, {3}, {4}): Called", handle.ToInt32 (), obj, type, converter, copy);
555                         driver.ClipboardStore (handle, obj, type, converter, copy);
556                 }
557
558                 internal static object ClipboardRetrieve (IntPtr handle, int type, XplatUI.ClipboardToObject converter)
559                 {
560                         DriverDebug ("ClipboardRetrieve ({0:X}, type, {1}): Called", handle.ToInt32 (), converter);
561                         return driver.ClipboardRetrieve (handle, type, converter);
562                 }
563
564                 internal static IntPtr DefineCursor (Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot)
565                 {
566                         DriverDebug ("DefineCursor (...): Called");
567                         return driver.DefineCursor (bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
568                 }
569
570                 internal static IntPtr DefineStdCursor (StdCursor id)
571                 {
572                         return driver.DefineStdCursor (id);
573                 }
574                 
575                 internal static Bitmap DefineStdCursorBitmap (StdCursor id)
576                 {
577                         return driver.DefineStdCursorBitmap (id);
578                 }
579
580                 internal static IntPtr DefWndProc (ref Message msg)
581                 {
582                         return driver.DefWndProc (ref msg);
583                 }
584
585                 internal static void DestroyCaret (IntPtr handle)
586                 {
587                         DriverDebug ("DestroyCaret ({0:X}): Called", handle.ToInt32 ());
588                         driver.DestroyCaret (handle);
589                 }
590
591                 internal static void DestroyCursor (IntPtr cursor)
592                 {
593                         DriverDebug ("DestroyCursor ({0:X}): Called", cursor.ToInt32 ());
594                         driver.DestroyCursor (cursor);
595                 }
596
597                 internal static void DestroyWindow (IntPtr handle)
598                 {
599                         DriverDebug ("DestroyWindow ({0}): Called", Window (handle));
600                         driver.DestroyWindow (handle);
601                 }
602
603                 internal static IntPtr DispatchMessage (ref MSG msg)
604                 {
605                         return driver.DispatchMessage (ref msg);
606                 }
607
608                 internal static void DoEvents ()
609                 {
610                         driver.DoEvents ();
611                 }
612
613                 internal static void DrawReversibleRectangle (IntPtr handle, Rectangle rect, int line_width)
614                 {
615                         DriverDebug ("DrawReversibleRectangle ({0}, {1}, {2}): Called", Window (handle), rect, line_width);
616                         driver.DrawReversibleRectangle (handle, rect, line_width);
617                 }
618
619                 internal static void FillReversibleRectangle (Rectangle rectangle, Color backColor)
620                 {
621                         DriverDebug ("FillReversibleRectangle ({0}, {1}): Called", rectangle, backColor);
622                         driver.FillReversibleRectangle (rectangle, backColor);
623                 }
624
625                 internal static void DrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style)
626                 {
627                         DriverDebug ("DrawReversibleFrame ({0}, {1}, {2}): Called", rectangle, backColor, style);
628                         driver.DrawReversibleFrame (rectangle, backColor, style);
629                 }
630
631                 internal static void DrawReversibleLine (Point start, Point end, Color backColor)
632                 {
633                         DriverDebug ("DrawReversibleLine ({0}, {1}, {2}): Called", start, end, backColor);
634                         driver.DrawReversibleLine (start, end, backColor);
635                 }
636
637                 internal static void EnableThemes ()
638                 {
639                         driver.EnableThemes ();
640                 }
641
642                 internal static void EnableWindow (IntPtr handle, bool Enable)
643                 {
644                         DriverDebug ("EnableWindow ({0}, {1}): Called", Window (handle), Enable);
645                         driver.EnableWindow (handle, Enable);
646                 }
647
648                 internal static void EndLoop (Thread thread)
649                 {
650                         DriverDebug ("EndLoop ({0:X}): Called", thread.GetHashCode ());
651                         driver.EndLoop (thread);
652                 }
653
654                 internal static IntPtr GetActive ()
655                 {
656                         DriverDebug ("GetActive (): Called");
657                         return driver.GetActive ();
658                 }
659
660                 internal static SizeF GetAutoScaleSize (Font font)
661                 {
662                         DriverDebug ("GetAutoScaleSize ({0}): Called", font);
663                         return driver.GetAutoScaleSize (font);
664                 }
665
666                 internal static Region GetClipRegion (IntPtr handle)
667                 {
668                         DriverDebug ("GetClipRegion ({0}): Called", Window (handle));
669                         return driver.GetClipRegion (handle);
670                 }
671
672                 internal static void GetCursorInfo (IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y)
673                 {
674                         DriverDebug ("GetCursorInfo ({0}): Called", cursor.ToInt32 ());
675                         driver.GetCursorInfo (cursor, out width, out height, out hotspot_x, out hotspot_y);
676                 }
677
678                 internal static void GetCursorPos (IntPtr handle, out int x, out int y)
679                 {
680                         DriverDebug ("GetCursorPos ({0}): Called", Window (handle));
681                         driver.GetCursorPos (handle, out x, out y);
682                 }
683
684                 internal static void GetDisplaySize (out Size size) 
685                 {
686                         DriverDebug ("GetDisplaySize (): Called");
687                         driver.GetDisplaySize (out size);
688                 }
689
690                 internal static IntPtr GetFocus ()
691                 {
692                         DriverDebug ("GetFocus (): Called, Result:{0}", Window (driver.GetFocus ()));
693                         return driver.GetFocus ();
694                 }
695
696                 internal static bool GetFontMetrics (Graphics g, Font font, out int ascent, out int descent)
697                 {
698                         DriverDebug ("GetFontMetrics (): Called");
699                         return driver.GetFontMetrics (g, font, out ascent, out descent);
700                 }
701                         
702                 internal static Point GetMenuOrigin (IntPtr handle)
703                 {
704                         DriverDebug ("GetMenuOrigin ({0}): Called", Window (handle));
705                         return driver.GetMenuOrigin (handle);
706                 }
707
708                 internal static bool GetMessage (object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax)
709                 {
710                         return driver.GetMessage (queue_id, ref msg, hWnd, wFilterMin, wFilterMax);
711                 }
712
713                 internal static IntPtr GetParent (IntPtr handle)
714                 {
715                         DriverDebug ("GetParent ({0}): Called", Window (handle));
716                         return driver.GetParent (handle);
717                 }
718
719                 internal static IntPtr GetPreviousWindow (IntPtr handle)
720                 {
721                         return driver.GetPreviousWindow (handle);
722                 }
723
724                 internal static bool GetText (IntPtr handle, out string text)
725                 {
726                         DriverDebug ("GetText ({0}): Called", Window (handle));
727                         return driver.GetText (handle, out text);
728                 }
729
730                 internal static void GetWindowPos (IntPtr handle, bool is_toplevel, out int x, out int y, out int width, out int height, out int client_width, out int client_height)
731                 {
732                         DriverDebug ("GetWindowPos ({0}): Called", Window (handle));
733                         driver.GetWindowPos (handle, is_toplevel, out x, out y, out width, out height, out client_width, out client_height);
734                 }
735
736                 /* this method can (and does, on X11) return
737                  * (FormWindowState) (-1), when the state of the window
738                  * cannot be determined (in the X11 case, when the
739                  * window isn't mapped.)  Checking for the additional
740                  * return value is less expensive than
741                  * throwing/catching an exception. */
742                 internal static FormWindowState GetWindowState (IntPtr handle)
743                 {
744                         DriverDebug ("GetWindowState ({0}): Called", Window (handle));
745                         return driver.GetWindowState (handle);
746                 }
747
748                 internal static void GrabInfo (out IntPtr handle, out bool GrabConfined, out Rectangle GrabArea)
749                 {
750                         DriverDebug ("GrabInfo (): Called");
751                         driver.GrabInfo (out handle, out GrabConfined, out GrabArea);
752                 }
753
754                 internal static void GrabWindow (IntPtr handle, IntPtr ConfineToHwnd)
755                 {
756                         DriverDebug ("GrabWindow ({0}, {1}): Called", Window (handle), Window (ConfineToHwnd));
757                         driver.GrabWindow (handle, ConfineToHwnd);
758                 }
759
760                 internal static void HandleException (Exception e)
761                 {
762                         driver.HandleException (e);
763                 }
764
765                 internal static void Invalidate (IntPtr handle, Rectangle rc, bool clear)
766                 {
767                         DriverDebug ("Invalidate ({0}, {1}, {2}): Called", Window (handle), rc, clear);
768                         driver.Invalidate (handle, rc, clear);
769                 }
770
771                 internal static void InvalidateNC (IntPtr handle)
772                 {
773                         DriverDebug ("InvalidateNC ({0}): Called", Window (handle));
774                         driver.InvalidateNC (handle);
775                 }
776
777
778                 internal static bool IsEnabled (IntPtr handle)
779                 {
780                         #if DriverDebug || DriverDebugState
781                                 Console.WriteLine ("IsEnabled ({0}): Called, Result={1}", Window (handle), driver.IsEnabled (handle));
782                         #endif
783                         return driver.IsEnabled (handle);
784                 }
785
786                 internal static bool IsKeyLocked (VirtualKeys key)
787                 {
788                         #if DriverDebug || DriverDebugState
789                                 Console.WriteLine ("IsKeyLocked ({0}): Called, Result={1}", key, driver.IsKeyLocked (key));
790                         #endif
791                         return driver.IsKeyLocked (key);
792                 }
793
794                 internal static bool IsVisible (IntPtr handle)
795                 {
796                         #if DriverDebug || DriverDebugState
797                                 Console.WriteLine ("IsVisible ({0}): Called, Result={1}", Window (handle), driver.IsVisible (handle));
798                         #endif
799                         return driver.IsVisible (handle);
800                 }
801
802                 internal static void KillTimer (Timer timer)
803                 {
804                         DriverDebug ("KillTimer ({0}): Called", timer);
805                         driver.KillTimer (timer);
806                 }
807
808                 internal static void MenuToScreen (IntPtr handle, ref int x, ref int y)
809                 {
810                         DriverDebug ("MenuToScreen ({0}, {1}, {2}): Called", Window (handle), x, y);
811                         driver.MenuToScreen (handle, ref x, ref y);
812                 }
813
814                 internal static void OverrideCursor (IntPtr cursor)
815                 {
816                         DriverDebug ("OverrideCursor ({0:X}): Called", cursor.ToInt32 ());
817                         driver.OverrideCursor (cursor);
818                 }
819
820                 internal static void PaintEventEnd (ref Message msg, IntPtr handle, bool client)
821                 {
822                         #if DriverDebug || DriverDebugPaint
823                                 Console.WriteLine ("PaintEventEnd ({0}, {1}, {2}): Called from thread {3}", msg, Window (handle), client, Thread.CurrentThread.GetHashCode ());
824                         #endif
825                         driver.PaintEventEnd (ref msg, handle, client);
826                 }
827
828                 internal static PaintEventArgs PaintEventStart (ref Message msg, IntPtr handle, bool client)
829                 {
830                         #if DriverDebug || DriverDebugPaint
831                                 Console.WriteLine ("PaintEventStart ({0}, {1}, {2}): Called from thread {3}", msg, Window (handle), client, Thread.CurrentThread.GetHashCode ());
832                         #endif
833                         return driver.PaintEventStart (ref msg, handle, client);
834                 }
835
836                 internal static bool PeekMessage (Object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags)
837                 {
838                         return driver.PeekMessage (queue_id, ref msg, hWnd, wFilterMin, wFilterMax, flags);
839                 }
840
841                 internal static bool PostMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam)
842                 {
843                         DriverDebug ("PostMessage ({0}, {1}, {2:X}, {3:X}): Called", Window (hwnd), message, wParam.ToInt32 (), lParam.ToInt32 ());
844                         return driver.PostMessage (hwnd, message, wParam, lParam);
845                 }
846
847                 internal static bool PostMessage (ref MSG msg)
848                 {
849                         DriverDebug ("PostMessage ({0}): Called", msg);
850                         return driver.PostMessage (msg.hwnd, msg.message, msg.wParam, msg.lParam);
851                 }
852
853                 internal static void PostQuitMessage (int exitCode)
854                 {
855                         DriverDebug ("PostQuitMessage ({0}): Called", exitCode);
856                         driver.PostQuitMessage (exitCode);
857                 }
858
859                 internal static void RaiseIdle (EventArgs e)
860                 {
861                         DriverDebug ("RaiseIdle ({0}): Called", e.ToString ());
862                         
863                         driver.RaiseIdle (e);
864                 }
865                 
866                 internal static void RequestAdditionalWM_NCMessages (IntPtr handle, bool hover, bool leave)
867                 {
868                         DriverDebug ("RequestAdditionalWM_NCMessages ({0}, {1}, {2}): Called", Window (handle), hover, leave);
869                         driver.RequestAdditionalWM_NCMessages (handle, hover, leave);
870                 }
871
872                 internal static void RequestNCRecalc (IntPtr handle)
873                 {
874                         DriverDebug ("RequestNCRecalc ({0}): Called", Window (handle));
875                         driver.RequestNCRecalc (handle);
876                 }
877
878                 internal static void ResetMouseHover (IntPtr handle)
879                 {
880                         DriverDebug ("ResetMouseHover ({0}): Called", Window (handle));
881                         driver.ResetMouseHover (handle);
882                 }
883
884                 internal static void ScreenToClient (IntPtr handle, ref int x, ref int y)
885                 {
886                         DriverDebug ("ScreenToClient ({0}, {1}, {2}): Called", Window (handle), x, y);
887                         driver.ScreenToClient (handle, ref x, ref y);
888                 }
889
890                 internal static void ScreenToMenu (IntPtr handle, ref int x, ref int y)
891                 {
892                         DriverDebug ("ScreenToMenu ({0}, {1}, {2}): Called", Window (handle), x, y);
893                         driver.ScreenToMenu (handle, ref x, ref y);
894                 }
895
896                 internal static void ScrollWindow (IntPtr handle, Rectangle rectangle, int XAmount, int YAmount, bool with_children)
897                 {
898                         DriverDebug ("ScrollWindow ({0}, {1}, {2}, {3}, {4}): Called", Window (handle), rectangle, XAmount, YAmount, with_children);
899                         driver.ScrollWindow (handle, rectangle, XAmount, YAmount, with_children);
900                 }
901
902                 internal static void ScrollWindow (IntPtr handle, int XAmount, int YAmount, bool with_children)
903                 {
904                         DriverDebug ("ScrollWindow ({0}, {1}, {2}, {3}): Called", Window (handle), XAmount, YAmount, with_children);
905                         driver.ScrollWindow (handle, XAmount, YAmount, with_children);
906                 }
907
908                 internal static void SendAsyncMethod (AsyncMethodData data)
909                 {
910                         DriverDebug ("SendAsyncMethod ({0}): Called", data);
911                         driver.SendAsyncMethod (data);
912                 }
913
914                 internal static int SendInput (IntPtr hwnd, Queue keys)
915                 {
916                         DriverDebug ("SendInput ({0}, {1}): Called", hwnd, keys);
917                         return driver.SendInput (hwnd, keys);
918                 }
919
920                 internal static IntPtr SendMessage (IntPtr handle, Msg message, IntPtr wParam, IntPtr lParam)
921                 {
922                         DriverDebug ("SendMessage ({0}, {1}, {2:X}, {3:X}): Called", Window (handle), message, wParam.ToInt32 (), lParam.ToInt32 ());
923                         return driver.SendMessage (handle, message, wParam, lParam);
924                 }
925
926                 internal static void SendMessage (ref Message m)
927                 {
928                         DriverDebug ("SendMessage ({0}): Called", m);
929                         m.Result = driver.SendMessage (m.HWnd, (Msg)m.Msg, m.WParam, m.LParam);
930                 }
931
932                 internal static void SetAllowDrop (IntPtr handle, bool value)
933                 {
934                         DriverDebug  ("SetAllowDrop ({0}, {1}): Called", handle, value);
935                         driver.SetAllowDrop (handle, value);
936                 }
937
938                 internal static void SetBorderStyle (IntPtr handle, FormBorderStyle border_style)
939                 {
940                         DriverDebug ("SetBorderStyle ({0}, {1}): Called", Window (handle), border_style);
941                         driver.SetBorderStyle (handle, border_style);
942                 }
943
944                 internal static void SetCaretPos (IntPtr handle, int x, int y)
945                 {
946                         DriverDebug ("SetCaretPos ({0}, {1}, {2}): Called", Window (handle), x, y);
947                         driver.SetCaretPos (handle, x, y);
948                 }
949
950                 internal static void SetClipRegion (IntPtr handle, Region region)
951                 {
952                         DriverDebug ("SetClipRegion ({0}, {1}): Called", Window (handle), region);
953                         driver.SetClipRegion (handle, region);
954                 }
955
956                 internal static void SetCursor (IntPtr handle, IntPtr cursor)
957                 {
958                         DriverDebug ("SetCursor ({0}, {1:X}): Called", Window (handle), cursor.ToInt32 ());
959                         driver.SetCursor (handle, cursor);
960                 }
961
962                 internal static void SetCursorPos (IntPtr handle, int x, int y)
963                 {
964                         DriverDebug ("SetCursorPos ({0}, {1}, {2}): Called", Window (handle), x, y);
965                         driver.SetCursorPos (handle, x, y);
966                 }
967
968                 internal static void SetFocus (IntPtr handle)
969                 {
970                         DriverDebug ("SetFocus ({0}): Called", Window (handle));
971                         driver.SetFocus (handle);
972                 }
973
974                 internal static void SetForegroundWindow (IntPtr handle)
975                 {
976                         DriverDebug ("SetForegroundWindow ({0}): Called", Window (handle));
977                         driver.SetForegroundWindow (handle);
978                 }
979
980                 internal static void SetIcon (IntPtr handle, Icon icon)
981                 {
982                         DriverDebug ("SetIcon ({0}, {1}): Called", Window (handle), icon);
983                         driver.SetIcon (handle, icon);
984                 }
985
986                 internal static void SetMenu (IntPtr handle, Menu menu)
987                 {
988                         DriverDebug ("SetMenu ({0}, {1}): Called", Window (handle), menu);
989                         driver.SetMenu (handle, menu);
990                 }
991
992                 internal static void SetModal (IntPtr handle, bool Modal)
993                 {
994                         DriverDebug ("SetModal ({0}, {1}): Called", Window (handle), Modal);
995                         driver.SetModal (handle, Modal);
996                 }
997
998                 internal static IntPtr SetParent (IntPtr handle, IntPtr hParent)
999                 {
1000                         DriverDebug ("SetParent ({0}, {1:X}): Called", Window (handle), Window (hParent));
1001                         return driver.SetParent (handle, hParent);
1002                 }
1003
1004                 internal static void SetTimer (Timer timer)
1005                 {
1006                         DriverDebug ("SetTimer ({0}): Called", timer);
1007                         driver.SetTimer (timer);
1008                 }
1009
1010                 internal static bool SetTopmost (IntPtr handle, bool Enabled)
1011                 {
1012                         DriverDebug ("SetTopMost ({0}, {1}): Called", Window (handle), Enabled);
1013                         return driver.SetTopmost (handle, Enabled);
1014                 }
1015
1016                 internal static bool SetOwner (IntPtr handle, IntPtr hWndOwner)
1017                 {
1018                         DriverDebug ("SetOwner ({0}, {1}): Called", Window (handle), Window (hWndOwner));
1019                         return driver.SetOwner (handle, hWndOwner);
1020                 }
1021
1022                 internal static bool SetVisible (IntPtr handle, bool visible, bool activate)
1023                 {
1024                         #if DriverDebug || DriverDebugState
1025                                 Console.WriteLine ("SetVisible ({0}, {1}, {2}): Called", Window (handle), visible, activate);
1026                         #endif
1027                         return driver.SetVisible (handle, visible, activate);
1028                 }
1029
1030                 internal static void SetWindowMinMax (IntPtr handle, Rectangle maximized, Size min, Size max)
1031                 {
1032                         #if DriverDebug || DriverDebugState
1033                                 Console.WriteLine ("SetWindowMinMax ({0}, {1}, {2}, {3}): Called", Window (handle), maximized, min, max);
1034                         #endif
1035                         driver.SetWindowMinMax (handle, maximized, min, max);
1036                 }
1037
1038                 internal static void SetWindowPos (IntPtr handle, int x, int y, int width, int height)
1039                 {
1040                         DriverDebug ("SetWindowPos ({0}, {1}, {2}, {3}, {4}): Called", Window (handle), x, y, width, height);
1041                         driver.SetWindowPos (handle, x, y, width, height);
1042                 }
1043
1044                 internal static void SetWindowState (IntPtr handle, FormWindowState state)
1045                 {
1046                         #if DriverDebug || DriverDebugState
1047                                 Console.WriteLine ("SetWindowState ({0} {1}): Called", Window (handle), state);
1048                         #endif
1049                         driver.SetWindowState (handle, state);
1050                 }
1051
1052                 internal static void SetWindowStyle (IntPtr handle, CreateParams cp)
1053                 {
1054                         DriverDebug ("SetWindowStyle ({0}): Called", Window (handle));
1055                         driver.SetWindowStyle (handle, cp);
1056                 }
1057
1058                 internal static double GetWindowTransparency (IntPtr handle)
1059                 {
1060                         DriverDebug ("SetWindowTransparency ({0}): Called", Window (handle));
1061                         return driver.GetWindowTransparency (handle);
1062                 }
1063
1064                 internal static void SetWindowTransparency (IntPtr handle, double transparency, Color key) 
1065                 {
1066                         DriverDebug ("SetWindowTransparency ({0}): Called", Window (handle));
1067                         driver.SetWindowTransparency (handle, transparency, key);
1068                 }
1069
1070                 internal static bool SetZOrder (IntPtr handle, IntPtr AfterhWnd, bool Top, bool Bottom)
1071                 {
1072                         DriverDebug ("SetZOrder ({0}, {1:X}, {2}, {3}): Called", Window (handle), Window (AfterhWnd), Top, Bottom);
1073                         return driver.SetZOrder (handle, AfterhWnd, Top, Bottom);
1074                 }
1075
1076                 internal static void ShowCursor (bool show)
1077                 {
1078                         DriverDebug ("ShowCursor ({0}): Called", show);
1079                         driver.ShowCursor (show);
1080                 }
1081
1082                 internal static DragDropEffects StartDrag (IntPtr handle, object data, DragDropEffects allowedEffects)
1083                 {
1084                         DriverDebug  ("StartDrag ({0}, {1}, {2}): Called", Window (handle), data, allowedEffects);
1085                         return driver.StartDrag (handle, data, allowedEffects);
1086                 }
1087
1088                 internal static object StartLoop (Thread thread)
1089                 {
1090                         DriverDebug ("StartLoop ({0:X}): Called", thread.GetHashCode ());
1091                         return driver.StartLoop (thread);
1092                 }
1093
1094                 internal static TransparencySupport SupportsTransparency ()
1095                 {
1096                         DriverDebug ("SupportsTransparency (): Called, result={0}", driver.SupportsTransparency ());
1097                         return driver.SupportsTransparency ();
1098                 }
1099
1100                 internal static bool SystrayAdd (IntPtr handle, string tip, Icon icon, out ToolTip tt)
1101                 {
1102                         DriverDebug ("SystrayAdd ({0}, {1}): Called", Window (handle), tip);
1103                         return driver.SystrayAdd (handle, tip, icon, out tt);
1104                 }
1105
1106                 internal static void SystrayChange (IntPtr handle, string tip, Icon icon, ref ToolTip tt)
1107                 {
1108                         DriverDebug ("SystrayChange ({0}, {1}): Called", Window (handle), tip);
1109                         driver.SystrayChange (handle, tip, icon, ref tt);
1110                 }
1111
1112                 internal static void SystrayRemove (IntPtr handle, ref ToolTip tt)
1113                 {
1114                         DriverDebug ("SystrayRemove ({0}): Called", Window (handle));
1115                         driver.SystrayRemove (handle, ref tt);
1116                 }
1117
1118                 internal static void SystrayBalloon (IntPtr handle, int timeout, string title, string text, ToolTipIcon icon)
1119                 {
1120                         DriverDebug ("SystrayBalloon ({0}, {1}, {2}, {3}, {4}): Called", Window (handle), timeout, title, text, icon);
1121                         driver.SystrayBalloon (handle, timeout, title, text, icon);
1122                 }
1123
1124                 internal static bool Text (IntPtr handle, string text)
1125                 {
1126                         DriverDebug ("Text ({0}, {1}): Called", Window (handle), text);
1127                         return driver.Text (handle, text);
1128                 }
1129
1130                 internal static bool TranslateMessage (ref MSG msg)
1131                 {
1132                         return driver.TranslateMessage (ref msg);
1133                 }
1134
1135                 internal static void UngrabWindow (IntPtr handle)
1136                 {
1137                         DriverDebug ("UngrabWindow ({0}): Called", Window (handle));
1138                         driver.UngrabWindow (handle);
1139                 }
1140
1141                 internal static void UpdateWindow (IntPtr handle)
1142                 {
1143                         DriverDebug ("UpdateWindow ({0}): Called", Window (handle));
1144                         driver.UpdateWindow (handle);
1145                 }
1146
1147                 // double buffering
1148                 internal static void CreateOffscreenDrawable (IntPtr handle,
1149                                                             int width, int height,
1150                                                             out object offscreen_drawable)
1151                 {
1152                         DriverDebug ("CreateOffscreenDrawable ({2}, {0},{1}): Called", width, height, Window (handle));
1153                         driver.CreateOffscreenDrawable (handle, width, height,
1154                                                         out offscreen_drawable);
1155                 }
1156
1157                 internal static void DestroyOffscreenDrawable (object offscreen_drawable)
1158                 {
1159                         DriverDebug ("DestroyOffscreenDrawable (): Called");
1160                         driver.DestroyOffscreenDrawable (offscreen_drawable);
1161                 }
1162
1163                 internal static Graphics GetOffscreenGraphics (object offscreen_drawable)
1164                 {
1165                         DriverDebug ("GetOffscreenGraphics (): Called");
1166                         return driver.GetOffscreenGraphics (offscreen_drawable);
1167                 }
1168
1169                 internal static void BlitFromOffscreen (IntPtr dest_handle,
1170                                                       Graphics dest_dc,
1171                                                       object offscreen_drawable,
1172                                                       Graphics offscreen_dc,
1173                                                       Rectangle r)
1174                 {
1175                         DriverDebug ("BlitFromOffscreen ({0}): Called", Window (dest_handle));
1176                         driver.BlitFromOffscreen (dest_handle, dest_dc, offscreen_drawable, offscreen_dc, r);
1177                 }
1178
1179
1180                 // Santa's little helper
1181                 internal static void Version ()
1182                 {
1183                         Console.WriteLine ("Xplat version $Revision: $");
1184                 }
1185
1186                 internal static void AddKeyFilter (IKeyFilter value)
1187                 {
1188                         lock (key_filters) {
1189                                 key_filters.Add (value);
1190                         }
1191                 }
1192
1193                 internal static bool FilterKey (KeyFilterData key)
1194                 {
1195                         lock (key_filters) {
1196                                 for (int i = 0; i < key_filters.Count; i++) {
1197                                         IKeyFilter filter = (IKeyFilter) key_filters[i];
1198                                         if (filter.PreFilterKey (key))
1199                                                 return true;
1200                                 }
1201                         }
1202                         return false;
1203                 }
1204                 #endregion      // Public Static Methods
1205
1206                 #region Delegates
1207                 public delegate bool ClipboardToObject (int type, IntPtr data, out object obj);
1208                 public delegate bool ObjectToClipboard (ref int type, object obj, out byte[] data);
1209                 #endregion      // Delegates
1210
1211                 [DllImport ("libc")]
1212                 static extern int uname (IntPtr buf);
1213         }
1214 }