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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2004-2005 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
27 // define to log API calls to stdout
32 using System.ComponentModel;
33 using System.Collections;
34 using System.Diagnostics;
35 using System.Runtime.InteropServices;
38 namespace System.Windows.Forms {
39 internal class XplatUI {
40 #region Local Variables
41 static XplatUIDriver driver;
42 static String default_class_name;
43 #endregion // Local Variables
47 static public Keys ModifierKeys {
49 return driver.ModifierKeys;
53 static public MouseButtons MouseButtons {
55 return driver.MouseButtons;
59 static public Point MousePosition {
61 return driver.MousePosition;
66 #endregion // Subclasses
68 #region Constructor & Destructor
70 Console.WriteLine("Mono System.Windows.Forms Assembly [Revision: 54007; built: 2005/12/6 14:35:24]");
72 // Don't forget to throw the mac in here somewhere, too
73 default_class_name="SWFClass";
75 // check for Unix platforms - see FAQ for more details
76 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
77 int platform = (int) Environment.OSVersion.Platform;
78 if ((platform == 4) || (platform == 128)) {
79 if (Environment.GetEnvironmentVariable ("MONO_MWF_USE_QUARTZ_BACKEND") != null)
80 driver=XplatUIOSX.GetInstance();
82 driver=XplatUIX11.GetInstance();
84 driver=XplatUIWin32.GetInstance();
87 driver.InitializeDriver();
89 // Initialize things that need to be done after the driver is ready
90 DataFormats.GetFormat(0);
92 #endregion // Constructor & Destructor
94 #region Public Static Properties
95 internal static string DefaultClassName {
97 return default_class_name;
101 default_class_name=value;
105 static public int CaptionHeight {
107 return driver.Caption;
111 static public Size CursorSize {
113 return driver.CursorSize;
117 static public bool DragFullWindows {
119 return driver.DragFullWindows;
123 static public Size DragSize {
125 return driver.DragSize;
129 public static Size FrameBorderSize {
131 return driver.FrameBorderSize;
135 static public Size IconSize {
137 return driver.IconSize;
141 static public int KeyboardSpeed {
143 return driver.KeyboardSpeed;
147 static public int KeyboardDelay {
149 return driver.KeyboardSpeed;
153 static public Size MaxWindowTrackSize {
155 return driver.MaxWindowTrackSize;
159 static public Size MinimizedWindowSize {
161 return driver.MinimizedWindowSize;
165 static public Size MinimizedWindowSpacingSize {
167 return driver.MinimizedWindowSpacingSize;
171 static public Size MinimumWindowSize {
173 return driver.MinimumWindowSize;
177 static public Size MinWindowTrackSize {
179 return driver.MinWindowTrackSize;
183 static public Size SmallIconSize {
185 return driver.SmallIconSize;
189 static public int MouseButtonCount {
191 return driver.MouseButtonCount;
195 static public bool MouseButtonsSwapped {
197 return driver.MouseButtonsSwapped;
201 static public bool MouseWheelPresent {
203 return driver.MouseWheelPresent;
207 static public Rectangle VirtualScreen {
209 return driver.VirtualScreen;
213 static public Rectangle WorkingArea {
215 return driver.WorkingArea;
218 #endregion // Public Static Properties
221 internal static event EventHandler Idle {
223 driver.Idle += value;
226 driver.Idle -= value;
232 #region Public Static Methods
233 internal static void Activate(IntPtr handle) {
235 Console.WriteLine("Activate({0:X}): Called", handle.ToInt32());
237 driver.Activate(handle);
240 internal static void AudibleAlert() {
242 Console.WriteLine("AudibleAlert(): Called");
244 driver.AudibleAlert();
247 internal static bool CalculateWindowRect(IntPtr handle, ref Rectangle ClientRect, int Style, int ExStyle, Menu menu, out Rectangle WindowRect) {
249 Console.WriteLine("CalculateWindowRect({0:X}): Called", handle.ToInt32());
251 return driver.CalculateWindowRect(handle, ref ClientRect, Style, ExStyle, menu, out WindowRect);
254 internal static void CaretVisible(IntPtr handle, bool visible) {
256 Console.WriteLine("CaretVisible({0:X}, {1}): Called", handle.ToInt32(), visible);
258 driver.CaretVisible(handle, visible);
261 internal static void CreateCaret(IntPtr handle, int width, int height) {
263 Console.WriteLine("CreateCaret({0:X}), {1}, {2}: Called", handle.ToInt32(), width, height);
265 driver.CreateCaret(handle, width, height);
268 internal static IntPtr CreateWindow(CreateParams cp) {
270 Console.WriteLine("CreateWindow(): Called");
272 return driver.CreateWindow(cp);
275 internal static IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
277 Console.WriteLine("CreateWindow(): Called");
279 return driver.CreateWindow(Parent, X, Y, Width, Height);
282 internal static void ClientToScreen(IntPtr handle, ref int x, ref int y) {
284 Console.WriteLine("ClientToScreen({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
286 driver.ClientToScreen(handle, ref x, ref y);
289 internal static int[] ClipboardAvailableFormats(IntPtr handle) {
291 Console.WriteLine("ClipboardAvailableTypes({0:X}): Called", handle.ToInt32());
293 return driver.ClipboardAvailableFormats(handle);
296 internal static void ClipboardClose(IntPtr handle) {
298 Console.WriteLine("ClipboardClose({0:X}): Called", handle.ToInt32());
300 driver.ClipboardClose(handle);
303 internal static int ClipboardGetID(IntPtr handle, string format) {
305 Console.WriteLine("ClipboardGetID({0:X}, {1}): Called", handle.ToInt32(), format);
307 return driver.ClipboardGetID(handle, format);
310 internal static IntPtr ClipboardOpen() {
312 Console.WriteLine("ClipboardOpen(): Called");
314 return driver.ClipboardOpen();
317 internal static void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
319 Console.WriteLine("ClipboardStore({0:X}, {1}, {2}): Called", handle.ToInt32(), obj, (ClipboardFormat)type, converter);
321 driver.ClipboardStore(handle, obj, type, converter);
324 internal static object ClipboardRetrieve(IntPtr handle, int type, XplatUI.ClipboardToObject converter) {
326 Console.WriteLine("ClipboardRetrieve({0:X}, type, {1}): Called", handle.ToInt32(), converter);
328 return driver.ClipboardRetrieve(handle, type, converter);
331 internal static IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
333 Console.WriteLine("DefineCursor(...): Called");
335 return driver.DefineCursor(bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
338 internal static IntPtr DefineStdCursor(StdCursor id) {
339 return driver.DefineStdCursor(id);
342 internal static IntPtr DefWndProc(ref Message msg) {
343 return driver.DefWndProc(ref msg);
346 internal static void DestroyCaret(IntPtr handle) {
348 Console.WriteLine("DestroyCaret({0:X}): Called", handle.ToInt32());
350 driver.DestroyCaret(handle);
353 internal static void DestroyCursor(IntPtr cursor) {
355 Console.WriteLine("DestroyCursor({0:X}): Called", cursor.ToInt32());
357 driver.DestroyCursor(cursor);
360 internal static void DestroyWindow(IntPtr handle) {
362 Console.WriteLine("DestroyWindow({0:X}): Called", handle.ToInt32());
364 driver.DestroyWindow(handle);
367 internal static IntPtr DispatchMessage(ref MSG msg) {
368 return driver.DispatchMessage(ref msg);
371 internal static void DoEvents() {
375 internal static void DrawReversibleRectangle(IntPtr handle, Rectangle rect, int line_width) {
377 Console.WriteLine("DrawReversibleRectangle({0:X}, {1}, {2}): Called", handle.ToInt32(), rect, line_width);
379 driver.DrawReversibleRectangle(handle, rect, line_width);
382 internal static void EnableThemes() {
383 driver.EnableThemes();
386 internal static void EnableWindow(IntPtr handle, bool Enable) {
388 Console.WriteLine("EnableWindow({0:X}, {1}): Called", handle.ToInt32(), Enable);
390 driver.EnableWindow(handle, Enable);
393 internal static IntPtr GetActive() {
395 Console.WriteLine("GetActive(): Called");
397 return driver.GetActive();
400 internal static SizeF GetAutoScaleSize(Font font) {
402 Console.WriteLine("GetAutoScaleSize({0}): Called", font);
404 return driver.GetAutoScaleSize(font);
407 internal static void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
409 Console.WriteLine("GetCursorInfo({0:X}): Called", cursor.ToInt32());
411 driver.GetCursorInfo(cursor, out width, out height, out hotspot_x, out hotspot_y);
414 internal static void GetCursorPos(IntPtr handle, out int x, out int y) {
416 Console.WriteLine("GetCursorPos({0:X}): Called", handle.ToInt32());
418 driver.GetCursorPos(handle, out x, out y);
421 internal static void GetDisplaySize(out Size size) {
423 Console.WriteLine("GetDisplaySize(): Called");
425 driver.GetDisplaySize(out size);
428 internal static bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
430 Console.WriteLine("GetFontMetrics(): Called");
432 return driver.GetFontMetrics(g, font, out ascent, out descent);
435 internal static Graphics GetMenuDC(IntPtr handle, IntPtr ncpaint_region) {
437 Console.WriteLine("GetMenuDC({0:X}): Called", handle.ToInt32());
439 return driver.GetMenuDC(handle, ncpaint_region);
442 internal static Point GetMenuOrigin(IntPtr handle) {
444 Console.WriteLine("GetMenuOrigin({0:X}): Called", handle.ToInt32());
446 return driver.GetMenuOrigin(handle);
449 internal static bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
450 return driver.GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
453 internal static IntPtr GetParent(IntPtr hWnd) {
455 Console.WriteLine("GetParent({0:X}): Called", hWnd.ToInt32());
457 return driver.GetParent(hWnd);
460 internal static bool GetText(IntPtr hWnd, out string text) {
462 Console.WriteLine("GetText(): Called");
464 return driver.GetText(hWnd, out text);
467 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) {
469 Console.WriteLine("GetWindowPos({0:X}): Called", handle.ToInt32());
471 driver.GetWindowPos(handle, is_toplevel, out x, out y, out width, out height, out client_width, out client_height);
474 internal static FormWindowState GetWindowState(IntPtr handle) {
476 Console.WriteLine("GetWindowState({0:X}): Called", handle.ToInt32());
478 return driver.GetWindowState(handle);
481 internal static void GrabInfo(out IntPtr handle, out bool GrabConfined, out Rectangle GrabArea) {
483 Console.WriteLine("GrabInfo(): Called");
485 driver.GrabInfo(out handle, out GrabConfined, out GrabArea);
488 internal static void GrabWindow(IntPtr handle, IntPtr ConfineToHwnd) {
490 Console.WriteLine("GrabWindow({0:X}): Called", handle.ToInt32());
492 driver.GrabWindow(handle, ConfineToHwnd);
495 internal static void HandleException(Exception e) {
496 driver.HandleException(e);
499 internal static void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
501 Console.WriteLine("Invalidate({0:X}, {1}, {2}): Called", handle.ToInt32(), rc, clear);
503 driver.Invalidate(handle, rc, clear);
506 internal static bool IsVisible(IntPtr hWnd) {
508 Console.WriteLine("IsVisible({0:X}): Called", hWnd.ToInt32());
510 return driver.IsVisible(hWnd);
513 internal static void KillTimer (Timer timer)
516 Console.WriteLine("KillTimer({0}): Called", timer);
518 driver.KillTimer (timer);
521 internal static void MenuToScreen(IntPtr handle, ref int x, ref int y) {
523 Console.WriteLine("MenuToScreen({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
525 driver.MenuToScreen(handle, ref x, ref y);
528 internal static void OverrideCursor(IntPtr cursor) {
530 Console.WriteLine("OverrideCursor({0:X}): Called", cursor.ToInt32());
532 driver.OverrideCursor(cursor);
535 internal static void PaintEventEnd(IntPtr handle, bool client) {
537 Console.WriteLine("PaintEventEnd({0:X}, {1}): Called", handle.ToInt32(), client);
539 driver.PaintEventEnd(handle, client);
542 internal static PaintEventArgs PaintEventStart(IntPtr handle, bool client) {
544 Console.WriteLine("PaintEventStart({0:X}, {1}): Called", handle.ToInt32(), client);
546 return driver.PaintEventStart(handle, client);
549 internal static bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
550 return driver.PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
553 internal static void PostQuitMessage(int exitCode) {
554 driver.PostQuitMessage(exitCode);
557 internal static void ReleaseMenuDC(IntPtr handle, Graphics dc) {
559 Console.WriteLine("ReleaseMenuDC({0:X}): Called", handle.ToInt32());
561 driver.ReleaseMenuDC(handle, dc);
564 internal static void ScreenToClient(IntPtr handle, ref int x, ref int y) {
566 Console.WriteLine("ScreenToClient({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
568 driver.ScreenToClient (handle, ref x, ref y);
571 internal static void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
573 Console.WriteLine("ScreenToMenu({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
575 driver.ScreenToMenu(handle, ref x, ref y);
578 internal static void ScrollWindow(IntPtr handle, Rectangle rectangle, int XAmount, int YAmount, bool with_children) {
580 Console.WriteLine("ScrollWindow({0:X}, {1}, {2}, {3}, {4}): Called", handle.ToInt32(), rectangle, XAmount, YAmount, with_children);
582 driver.ScrollWindow(handle, rectangle, XAmount, YAmount, with_children);
585 internal static void ScrollWindow(IntPtr handle, int XAmount, int YAmount, bool with_children) {
587 Console.WriteLine("ScrollWindow({0:X}, {2}, {3}, {4}): Called", handle.ToInt32(), XAmount, YAmount, with_children);
589 driver.ScrollWindow(handle, XAmount, YAmount, with_children);
592 internal static void SendAsyncMethod (AsyncMethodData data) {
594 Console.WriteLine("SendAsyncMethod({0}): Called", data);
596 driver.SendAsyncMethod (data);
599 internal static void SetAllowDrop (IntPtr handle, bool value)
602 Console.WriteLine ("SetAllowDrop({0}, {1}): Called", handle, value);
604 driver.SetAllowDrop (handle, value);
607 internal static void SetBorderStyle(IntPtr handle, FormBorderStyle border_style) {
609 Console.WriteLine("SetBorderStyle({0:X}, {1}): Called", handle.ToInt32(), border_style);
611 driver.SetBorderStyle(handle, border_style);
614 internal static void SetCaretPos(IntPtr handle, int x, int y) {
616 Console.WriteLine("SetCaretPos({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
618 driver.SetCaretPos(handle, x, y);
621 internal static void SetCursor(IntPtr handle, IntPtr cursor) {
623 Console.WriteLine("SetCursor({0:X}, {1:X}): Called", handle.ToInt32(), cursor.ToInt32());
625 driver.SetCursor(handle, cursor);
628 internal static void SetCursorPos(IntPtr handle, int x, int y) {
630 Console.WriteLine("SetCursorPos({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
632 driver.SetCursorPos(handle, x, y);
635 internal static void SetFocus(IntPtr handle) {
637 Console.WriteLine("SetFocus({0:X}): Called", handle.ToInt32());
639 driver.SetFocus(handle);
642 internal static void SetIcon(IntPtr handle, Icon icon) {
644 Console.WriteLine("SetIcon({0:X}, {1}): Called", handle.ToInt32(), icon);
646 driver.SetIcon(handle, icon);
649 internal static void SetMenu(IntPtr handle, Menu menu) {
651 Console.WriteLine("SetMenu({0:X}, {1}): Called", handle.ToInt32(), menu);
653 driver.SetMenu(handle, menu);
656 internal static void SetModal(IntPtr handle, bool Modal) {
658 Console.WriteLine("SetModal({0:X}, {1}): Called", handle.ToInt32(), Modal);
660 driver.SetModal(handle, Modal);
663 internal static IntPtr SetParent(IntPtr hWnd, IntPtr hParent) {
665 Console.WriteLine("SetParent({0:X}, {1:X}): Called", hWnd.ToInt32(), hParent.ToInt32());
667 return driver.SetParent(hWnd, hParent);
670 internal static void SetTimer (Timer timer)
673 Console.WriteLine("SetTimer({0}): Called", timer);
675 driver.SetTimer (timer);
678 internal static bool SetTopmost(IntPtr handle, IntPtr hWndOwner, bool Enabled) {
680 Console.WriteLine("SetTopMost({0:X}, {1:X}, {2}): Called", handle.ToInt32(), hWndOwner.ToInt32(), Enabled);
682 return driver.SetTopmost(handle, hWndOwner, Enabled);
685 internal static bool SetVisible(IntPtr hWnd, bool visible) {
687 Console.WriteLine("SetVisible({0:X}, {1}): Called", hWnd.ToInt32(), visible);
689 return driver.SetVisible(hWnd, visible);
692 internal static void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
694 Console.WriteLine("SetWindowPos({0:X}, {1}, {2}, {3}, {4}): Called", handle.ToInt32(), x, y, width, height);
696 driver.SetWindowPos(handle, x, y, width, height);
699 internal static void SetWindowState(IntPtr handle, FormWindowState state) {
701 Console.WriteLine("SetWindowState({0:X} {1}): Called", handle.ToInt32(), state);
703 driver.SetWindowState(handle, state);
706 internal static void SetWindowStyle(IntPtr handle, CreateParams cp) {
708 Console.WriteLine("SetWindowStyle({0:X}): Called", handle.ToInt32());
710 driver.SetWindowStyle(handle, cp);
713 internal static bool SetZOrder(IntPtr handle, IntPtr AfterhWnd, bool Top, bool Bottom) {
715 Console.WriteLine("SetZOrder({0:X}, {1:X}, {2}, {3}): Called", handle.ToInt32(), AfterhWnd.ToInt32(), Top, Bottom);
717 return driver.SetZOrder(handle, AfterhWnd, Top, Bottom);
720 internal static void ShowCursor(bool show) {
722 Console.WriteLine("ShowCursor({0}): Called", show);
724 driver.ShowCursor(show);
727 internal static DragDropEffects StartDrag(IntPtr handle, object data, DragDropEffects allowedEffects) {
729 Console.WriteLine ("StartDrag({0}, {1}, {2}): Called", handle, data, allowedEffects);
731 return driver.StartDrag (handle, data, allowedEffects);
734 internal static bool SystrayAdd(IntPtr handle, string tip, Icon icon, out ToolTip tt) {
736 Console.WriteLine("SystrayAdd({0:X}, {1}): Called", handle.ToInt32(), tip);
738 return driver.SystrayAdd(handle, tip, icon, out tt);
741 internal static void SystrayChange(IntPtr handle, string tip, Icon icon, ref ToolTip tt) {
743 Console.WriteLine("SystrayChange({0:X}, {1}): Called", handle.ToInt32(), tip);
745 driver.SystrayChange(handle, tip, icon, ref tt);
748 internal static void SystrayRemove(IntPtr handle, ref ToolTip tt) {
750 Console.WriteLine("SystrayRemove({0:X}): Called", handle.ToInt32());
752 driver.SystrayRemove(handle, ref tt);
755 internal static bool Text(IntPtr hWnd, string text) {
757 Console.WriteLine("Text({0:X}, {1}): Called", hWnd.ToInt32(), text);
759 return driver.Text(hWnd, text);
762 internal static bool TranslateMessage(ref MSG msg) {
763 return driver.TranslateMessage(ref msg);
766 internal static void UngrabWindow(IntPtr handle) {
768 Console.WriteLine("UngrabWindow({0:X}): Called", handle.ToInt32());
770 driver.UngrabWindow(handle);
773 internal static void UpdateWindow(IntPtr handle) {
775 Console.WriteLine("UpdateWindow({0:X}): Called", handle.ToInt32());
777 driver.UpdateWindow(handle);
780 // Santa's little helper
781 internal static void Version() {
782 Console.WriteLine("Xplat version $Revision: $");
785 internal static void Where() {
788 #endregion // Public Static Methods
791 public delegate bool ClipboardToObject(int type, IntPtr data, out object obj);
792 public delegate bool ObjectToClipboard(ref int type, object obj, out byte[] data);
793 #endregion // Delegates