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