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