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: 52467; built: 2005/11/3 12:50:32]");
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 bool CalculateWindowRect(IntPtr handle, ref Rectangle ClientRect, int Style, int ExStyle, IntPtr MenuHandle, out Rectangle WindowRect) {
242 Console.WriteLine("CalculateWindowRect({0:X}): Called", handle.ToInt32());
244 return driver.CalculateWindowRect(handle, ref ClientRect, Style, ExStyle, MenuHandle, out WindowRect);
247 internal static void CaretVisible(IntPtr handle, bool visible) {
249 Console.WriteLine("CaretVisible({0:X}, {1}): Called", handle.ToInt32(), visible);
251 driver.CaretVisible(handle, visible);
254 internal static void CreateCaret(IntPtr handle, int width, int height) {
256 Console.WriteLine("CreateCaret({0:X}), {1}, {2}: Called", handle.ToInt32(), width, height);
258 driver.CreateCaret(handle, width, height);
261 internal static IntPtr CreateWindow(CreateParams cp) {
263 Console.WriteLine("CreateWindow(): Called");
265 return driver.CreateWindow(cp);
268 internal static IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
270 Console.WriteLine("CreateWindow(): Called");
272 return driver.CreateWindow(Parent, X, Y, Width, Height);
275 internal static void ClientToScreen(IntPtr handle, ref int x, ref int y) {
277 Console.WriteLine("ClientToScreen({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
279 driver.ClientToScreen(handle, ref x, ref y);
282 internal static int[] ClipboardAvailableFormats(IntPtr handle) {
284 Console.WriteLine("ClipboardAvailableTypes({0:X}): Called", handle.ToInt32());
286 return driver.ClipboardAvailableFormats(handle);
289 internal static void ClipboardClose(IntPtr handle) {
291 Console.WriteLine("ClipboardClose({0:X}): Called", handle.ToInt32());
293 driver.ClipboardClose(handle);
296 internal static int ClipboardGetID(IntPtr handle, string format) {
298 Console.WriteLine("ClipboardGetID({0:X}, {1}): Called", handle.ToInt32(), format);
300 return driver.ClipboardGetID(handle, format);
303 internal static IntPtr ClipboardOpen() {
305 Console.WriteLine("ClipboardOpen(): Called");
307 return driver.ClipboardOpen();
310 internal static void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
312 Console.WriteLine("ClipboardStore({0:X}, {1}, {2}): Called", handle.ToInt32(), obj, (ClipboardFormat)type, converter);
314 driver.ClipboardStore(handle, obj, type, converter);
317 internal static object ClipboardRetrieve(IntPtr handle, int type, XplatUI.ClipboardToObject converter) {
319 Console.WriteLine("ClipboardRetrieve({0:X}, type, {1}): Called", handle.ToInt32(), converter);
321 return driver.ClipboardRetrieve(handle, type, converter);
324 internal static IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
326 Console.WriteLine("DefineCursor(...): Called");
328 return driver.DefineCursor(bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
331 internal static IntPtr DefineStdCursor(StdCursor id) {
332 return driver.DefineStdCursor(id);
335 internal static IntPtr DefWndProc(ref Message msg) {
336 return driver.DefWndProc(ref msg);
339 internal static void DestroyCaret(IntPtr handle) {
341 Console.WriteLine("DestroyCaret({0:X}): Called", handle.ToInt32());
343 driver.DestroyCaret(handle);
346 internal static void DestroyCursor(IntPtr cursor) {
348 Console.WriteLine("DestroyCursor({0:X}): Called", cursor.ToInt32());
350 driver.DestroyCursor(cursor);
353 internal static void DestroyWindow(IntPtr handle) {
355 Console.WriteLine("DestroyWindow({0:X}): Called", handle.ToInt32());
357 driver.DestroyWindow(handle);
360 internal static IntPtr DispatchMessage(ref MSG msg) {
361 return driver.DispatchMessage(ref msg);
364 internal static void DoEvents() {
368 internal static void DrawReversibleRectangle(IntPtr handle, Rectangle rect, int line_width) {
370 Console.WriteLine("DrawReversibleRectangle({0:X}, {1}, {2}): Called", handle.ToInt32(), rect, line_width);
372 driver.DrawReversibleRectangle(handle, rect, line_width);
375 internal static void EnableThemes() {
376 driver.EnableThemes();
379 internal static void EnableWindow(IntPtr handle, bool Enable) {
381 Console.WriteLine("EnableWindow({0:X}, {1}): Called", handle.ToInt32(), Enable);
383 driver.EnableWindow(handle, Enable);
386 internal static void Exit() {
390 internal static IntPtr GetActive() {
392 Console.WriteLine("GetActive(): Called");
394 return driver.GetActive();
397 internal static SizeF GetAutoScaleSize(Font font) {
399 Console.WriteLine("GetAutoScaleSize({0}): Called", font);
401 return driver.GetAutoScaleSize(font);
404 internal static void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
406 Console.WriteLine("GetCursorInfo({0:X}): Called", cursor.ToInt32());
408 driver.GetCursorInfo(cursor, out width, out height, out hotspot_x, out hotspot_y);
411 internal static void GetCursorPos(IntPtr handle, out int x, out int y) {
413 Console.WriteLine("GetCursorPos({0:X}): Called", handle.ToInt32());
415 driver.GetCursorPos(handle, out x, out y);
418 internal static void GetDisplaySize(out Size size) {
420 Console.WriteLine("GetDisplaySize(): Called");
422 driver.GetDisplaySize(out size);
425 internal static bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
427 Console.WriteLine("GetFontMetrics(): Called");
429 return driver.GetFontMetrics(g, font, out ascent, out descent);
432 internal static Graphics GetMenuDC(IntPtr handle, IntPtr ncpaint_region) {
434 Console.WriteLine("GetMenuDC({0:X}): Called", handle.ToInt32());
436 return driver.GetMenuDC(handle, ncpaint_region);
439 internal static Point GetMenuOrigin(IntPtr handle) {
441 Console.WriteLine("GetMenuOrigin({0:X}): Called", handle.ToInt32());
443 return driver.GetMenuOrigin(handle);
446 internal static bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
447 return driver.GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
450 internal static IntPtr GetParent(IntPtr hWnd) {
452 Console.WriteLine("GetParent({0:X}): Called", hWnd.ToInt32());
454 return driver.GetParent(hWnd);
457 internal static bool GetText(IntPtr hWnd, out string text) {
459 Console.WriteLine("GetText(): Called");
461 return driver.GetText(hWnd, out text);
464 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) {
466 Console.WriteLine("GetWindowPos({0:X}): Called", handle.ToInt32());
468 driver.GetWindowPos(handle, is_toplevel, out x, out y, out width, out height, out client_width, out client_height);
471 internal static FormWindowState GetWindowState(IntPtr handle) {
473 Console.WriteLine("GetWindowState({0:X}): Called", handle.ToInt32());
475 return driver.GetWindowState(handle);
478 internal static void GrabInfo(out IntPtr handle, out bool GrabConfined, out Rectangle GrabArea) {
480 Console.WriteLine("GrabInfo(): Called");
482 driver.GrabInfo(out handle, out GrabConfined, out GrabArea);
485 internal static void GrabWindow(IntPtr handle, IntPtr ConfineToHwnd) {
487 Console.WriteLine("GrabWindow({0:X}): Called", handle.ToInt32());
489 driver.GrabWindow(handle, ConfineToHwnd);
492 internal static void HandleException(Exception e) {
493 driver.HandleException(e);
496 internal static void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
498 Console.WriteLine("Invalidate({0:X}, {1}, {2}): Called", handle.ToInt32(), rc, clear);
500 driver.Invalidate(handle, rc, clear);
503 internal static bool IsVisible(IntPtr hWnd) {
505 Console.WriteLine("IsVisible({0:X}): Called", hWnd.ToInt32());
507 return driver.IsVisible(hWnd);
510 internal static void KillTimer (Timer timer)
513 Console.WriteLine("KillTimer({0}): Called", timer);
515 driver.KillTimer (timer);
518 internal static void MenuToScreen(IntPtr handle, ref int x, ref int y) {
520 Console.WriteLine("MenuToScreen({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
522 driver.MenuToScreen(handle, ref x, ref y);
525 internal static void OverrideCursor(IntPtr cursor) {
527 Console.WriteLine("OverrideCursor({0:X}): Called", cursor.ToInt32());
529 driver.OverrideCursor(cursor);
532 internal static void PaintEventEnd(IntPtr handle, bool client) {
534 Console.WriteLine("PaintEventEnd({0:X}, {1}): Called", handle.ToInt32(), client);
536 driver.PaintEventEnd(handle, client);
539 internal static PaintEventArgs PaintEventStart(IntPtr handle, bool client) {
541 Console.WriteLine("PaintEventStart({0:X}, {1}): Called", handle.ToInt32(), client);
543 return driver.PaintEventStart(handle, client);
546 internal static bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
547 return driver.PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
550 internal static void ReleaseMenuDC(IntPtr handle, Graphics dc) {
552 Console.WriteLine("ReleaseMenuDC({0:X}): Called", handle.ToInt32());
554 driver.ReleaseMenuDC(handle, dc);
557 internal static void ScreenToClient(IntPtr handle, ref int x, ref int y) {
559 Console.WriteLine("ScreenToClient({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
561 driver.ScreenToClient (handle, ref x, ref y);
564 internal static void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
566 Console.WriteLine("ScreenToMenu({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
568 driver.ScreenToMenu(handle, ref x, ref y);
571 internal static void ScrollWindow(IntPtr handle, Rectangle rectangle, int XAmount, int YAmount, bool with_children) {
573 Console.WriteLine("ScrollWindow({0:X}, {1}, {2}, {3}, {4}): Called", handle.ToInt32(), rectangle, XAmount, YAmount, with_children);
575 driver.ScrollWindow(handle, rectangle, XAmount, YAmount, with_children);
578 internal static void ScrollWindow(IntPtr handle, int XAmount, int YAmount, bool with_children) {
580 Console.WriteLine("ScrollWindow({0:X}, {2}, {3}, {4}): Called", handle.ToInt32(), XAmount, YAmount, with_children);
582 driver.ScrollWindow(handle, XAmount, YAmount, with_children);
585 internal static void SendAsyncMethod (AsyncMethodData data) {
587 Console.WriteLine("SendAsyncMethod({0}): Called", data);
589 driver.SendAsyncMethod (data);
592 internal static void SetAllowDrop (IntPtr handle, bool value)
595 Console.WriteLine ("SetAllowDrop({0}, {1}): Called", handle, value);
597 driver.SetAllowDrop (handle, value);
600 internal static void SetBorderStyle(IntPtr handle, FormBorderStyle border_style) {
602 Console.WriteLine("SetBorderStyle({0:X}, {1}): Called", handle.ToInt32(), border_style);
604 driver.SetBorderStyle(handle, border_style);
607 internal static void SetCaretPos(IntPtr handle, int x, int y) {
609 Console.WriteLine("SetCaretPos({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
611 driver.SetCaretPos(handle, x, y);
614 internal static void SetCursor(IntPtr handle, IntPtr cursor) {
616 Console.WriteLine("SetCursor({0:X}, {1:X}): Called", handle.ToInt32(), cursor.ToInt32());
618 driver.SetCursor(handle, cursor);
621 internal static void SetCursorPos(IntPtr handle, int x, int y) {
623 Console.WriteLine("SetCursorPos({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
625 driver.SetCursorPos(handle, x, y);
628 internal static void SetFocus(IntPtr handle) {
630 Console.WriteLine("SetFocus({0:X}): Called", handle.ToInt32());
632 driver.SetFocus(handle);
635 internal static void SetIcon(IntPtr handle, Icon icon) {
637 Console.WriteLine("SetIcon({0:X}, {1}): Called", handle.ToInt32(), icon);
639 driver.SetIcon(handle, icon);
642 internal static void SetMenu(IntPtr handle, IntPtr menu_handle) {
644 Console.WriteLine("SetMenu({0:X}, {1:X}): Called", handle.ToInt32(), menu_handle.ToInt32());
646 driver.SetMenu(handle, menu_handle);
649 internal static void SetModal(IntPtr handle, bool Modal) {
651 Console.WriteLine("SetModal({0:X}, {1}): Called", handle.ToInt32(), Modal);
653 driver.SetModal(handle, Modal);
656 internal static IntPtr SetParent(IntPtr hWnd, IntPtr hParent) {
658 Console.WriteLine("SetParent({0:X}, {1:X}): Called", hWnd.ToInt32(), hParent.ToInt32());
660 return driver.SetParent(hWnd, hParent);
663 internal static void SetTimer (Timer timer)
666 Console.WriteLine("SetTimer({0}): Called", timer);
668 driver.SetTimer (timer);
671 internal static bool SetTopmost(IntPtr handle, IntPtr hWndOwner, bool Enabled) {
673 Console.WriteLine("SetTopMost({0:X}, {1:X}, {2}): Called", handle.ToInt32(), hWndOwner.ToInt32(), Enabled);
675 return driver.SetTopmost(handle, hWndOwner, Enabled);
678 internal static bool SetVisible(IntPtr hWnd, bool visible) {
680 Console.WriteLine("SetVisible({0:X}, {1}): Called", hWnd.ToInt32(), visible);
682 return driver.SetVisible(hWnd, visible);
685 internal static void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
687 Console.WriteLine("SetWindowPos({0:X}, {1}, {2}, {3}, {4}): Called", handle.ToInt32(), x, y, width, height);
689 driver.SetWindowPos(handle, x, y, width, height);
692 internal static void SetWindowState(IntPtr handle, FormWindowState state) {
694 Console.WriteLine("SetWindowState({0:X} {1}): Called", handle.ToInt32(), state);
696 driver.SetWindowState(handle, state);
699 internal static void SetWindowStyle(IntPtr handle, CreateParams cp) {
701 Console.WriteLine("SetWindowStyle({0:X}): Called", handle.ToInt32());
703 driver.SetWindowStyle(handle, cp);
706 internal static bool SetZOrder(IntPtr handle, IntPtr AfterhWnd, bool Top, bool Bottom) {
708 Console.WriteLine("SetZOrder({0:X}, {1:X}, {2}, {3}): Called", handle.ToInt32(), AfterhWnd.ToInt32(), Top, Bottom);
710 return driver.SetZOrder(handle, AfterhWnd, Top, Bottom);
713 internal static void ShowCursor(bool show) {
715 Console.WriteLine("ShowCursor({0}): Called", show);
717 driver.ShowCursor(show);
720 internal static DragDropEffects StartDrag(IntPtr handle, object data, DragDropEffects allowedEffects) {
722 Console.WriteLine ("StartDrag({0}, {1}, {2}): Called", handle, data, allowedEffects);
724 return driver.StartDrag (handle, data, allowedEffects);
727 internal static bool SystrayAdd(IntPtr handle, string tip, Icon icon, out ToolTip tt) {
729 Console.WriteLine("SystrayAdd({0:X}, {1}): Called", handle.ToInt32(), tip);
731 return driver.SystrayAdd(handle, tip, icon, out tt);
734 internal static void SystrayChange(IntPtr handle, string tip, Icon icon, ref ToolTip tt) {
736 Console.WriteLine("SystrayChange({0:X}, {1}): Called", handle.ToInt32(), tip);
738 driver.SystrayChange(handle, tip, icon, ref tt);
741 internal static void SystrayRemove(IntPtr handle, ref ToolTip tt) {
743 Console.WriteLine("SystrayRemove({0:X}): Called", handle.ToInt32());
745 driver.SystrayRemove(handle, ref tt);
748 internal static bool Text(IntPtr hWnd, string text) {
750 Console.WriteLine("Text({0:X}, {1}): Called", hWnd.ToInt32(), text);
752 return driver.Text(hWnd, text);
755 internal static bool TranslateMessage(ref MSG msg) {
756 return driver.TranslateMessage(ref msg);
759 internal static void UngrabWindow(IntPtr handle) {
761 Console.WriteLine("UngrabWindow({0:X}): Called", handle.ToInt32());
763 driver.UngrabWindow(handle);
766 internal static void UpdateWindow(IntPtr handle) {
768 Console.WriteLine("UpdateWindow({0:X}): Called", handle.ToInt32());
770 driver.UpdateWindow(handle);
773 // Santa's little helper
774 internal static void Version() {
775 Console.WriteLine("Xplat version $Revision: $");
778 internal static void Where() {
781 #endregion // Public Static Methods
784 public delegate bool ClipboardToObject(int type, IntPtr data, out object obj);
785 public delegate bool ObjectToClipboard(ref int type, object obj, out byte[] data);
786 #endregion // Delegates