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