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