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