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: 51965; built: 2005/10/20 3:34:45]");
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();
90 #endregion // Constructor & Destructor
92 #region Public Static Properties
93 internal static string DefaultClassName {
95 return default_class_name;
99 default_class_name=value;
103 static public int CaptionHeight {
105 return driver.Caption;
109 static public Size CursorSize {
111 return driver.CursorSize;
115 static public bool DragFullWindows {
117 return driver.DragFullWindows;
121 static public Size DragSize {
123 return driver.DragSize;
127 public static Size FrameBorderSize {
129 return driver.FrameBorderSize;
133 static public Size IconSize {
135 return driver.IconSize;
139 static public int KeyboardSpeed {
141 return driver.KeyboardSpeed;
145 static public int KeyboardDelay {
147 return driver.KeyboardSpeed;
151 static public Size MaxWindowTrackSize {
153 return driver.MaxWindowTrackSize;
157 static public Size MinimizedWindowSize {
159 return driver.MinimizedWindowSize;
163 static public Size MinimizedWindowSpacingSize {
165 return driver.MinimizedWindowSpacingSize;
169 static public Size MinimumWindowSize {
171 return driver.MinimumWindowSize;
175 static public Size MinWindowTrackSize {
177 return driver.MinWindowTrackSize;
181 static public Size SmallIconSize {
183 return driver.SmallIconSize;
187 static public int MouseButtonCount {
189 return driver.MouseButtonCount;
193 static public bool MouseButtonsSwapped {
195 return driver.MouseButtonsSwapped;
199 static public bool MouseWheelPresent {
201 return driver.MouseWheelPresent;
205 static public Rectangle VirtualScreen {
207 return driver.VirtualScreen;
211 static public Rectangle WorkingArea {
213 return driver.WorkingArea;
216 #endregion // Public Static Properties
219 internal static event EventHandler Idle {
221 driver.Idle += value;
224 driver.Idle -= value;
230 #region Public Static Methods
231 internal static void Activate(IntPtr handle) {
233 Console.WriteLine("Activate({0:X}): Called", handle.ToInt32());
235 driver.Activate(handle);
238 internal static bool CalculateWindowRect(IntPtr handle, ref Rectangle ClientRect, int Style, int ExStyle, IntPtr MenuHandle, out Rectangle WindowRect) {
240 Console.WriteLine("CalculateWindowRect({0:X}): Called", handle.ToInt32());
242 return driver.CalculateWindowRect(handle, ref ClientRect, Style, ExStyle, MenuHandle, out WindowRect);
245 internal static void CaretVisible(IntPtr handle, bool visible) {
247 Console.WriteLine("CaretVisible({0:X}, {1}): Called", handle.ToInt32(), visible);
249 driver.CaretVisible(handle, visible);
252 internal static void CreateCaret(IntPtr handle, int width, int height) {
254 Console.WriteLine("CreateCaret({0:X}), {1}, {2}: Called", handle.ToInt32(), width, height);
256 driver.CreateCaret(handle, width, height);
259 internal static IntPtr CreateWindow(CreateParams cp) {
261 Console.WriteLine("CreateWindow(): Called");
263 return driver.CreateWindow(cp);
266 internal static IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
268 Console.WriteLine("CreateWindow(): Called");
270 return driver.CreateWindow(Parent, X, Y, Width, Height);
273 internal static void ClientToScreen(IntPtr handle, ref int x, ref int y) {
275 Console.WriteLine("ClientToScreen({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
277 driver.ClientToScreen(handle, ref x, ref y);
280 internal static int[] ClipboardAvailableFormats(IntPtr handle) {
282 Console.WriteLine("ClipboardAvailableTypes({0:X}): Called", handle.ToInt32());
284 return driver.ClipboardAvailableFormats(handle);
287 internal static void ClipboardClose(IntPtr handle) {
289 Console.WriteLine("ClipboardClose({0:X}): Called", handle.ToInt32());
291 driver.ClipboardClose(handle);
294 internal static int ClipboardGetID(IntPtr handle, string format) {
296 Console.WriteLine("ClipboardGetID({0:X}, {1}): Called", handle.ToInt32(), format);
298 return driver.ClipboardGetID(handle, format);
301 internal static IntPtr ClipboardOpen() {
303 Console.WriteLine("ClipboardOpen(): Called");
305 return driver.ClipboardOpen();
308 internal static void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
310 Console.WriteLine("ClipboardStore({0:X}, {1}, {2}): Called", handle.ToInt32(), obj, (ClipboardFormat)type, converter);
312 driver.ClipboardStore(handle, obj, type, converter);
315 internal static object ClipboardRetrieve(IntPtr handle, int type, XplatUI.ClipboardToObject converter) {
317 Console.WriteLine("ClipboardRetrieve({0:X}, type, {1}): Called", handle.ToInt32(), converter);
319 return driver.ClipboardRetrieve(handle, type, converter);
322 internal static IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
324 Console.WriteLine("DefineCursor(...): Called");
326 return driver.DefineCursor(bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
329 internal static IntPtr DefineStdCursor(StdCursor id) {
330 return driver.DefineStdCursor(id);
333 internal static IntPtr DefWndProc(ref Message msg) {
334 return driver.DefWndProc(ref msg);
337 internal static void DestroyCaret(IntPtr handle) {
339 Console.WriteLine("DestroyCaret({0:X}): Called", handle.ToInt32());
341 driver.DestroyCaret(handle);
344 internal static void DestroyCursor(IntPtr cursor) {
346 Console.WriteLine("DestroyCursor({0:X}): Called", cursor.ToInt32());
348 driver.DestroyCursor(cursor);
351 internal static void DestroyWindow(IntPtr handle) {
353 Console.WriteLine("DestroyWindow({0:X}): Called", handle.ToInt32());
355 driver.DestroyWindow(handle);
358 internal static IntPtr DispatchMessage(ref MSG msg) {
359 return driver.DispatchMessage(ref msg);
362 internal static void DoEvents() {
366 internal static void DrawReversibleRectangle(IntPtr handle, Rectangle rect, int line_width) {
368 Console.WriteLine("DrawReversibleRectangle({0:X}, {1}, {2}): Called", handle.ToInt32(), rect, line_width);
370 driver.DrawReversibleRectangle(handle, rect, line_width);
373 internal static void EnableThemes() {
374 driver.EnableThemes();
377 internal static void EnableWindow(IntPtr handle, bool Enable) {
379 Console.WriteLine("EnableWindow({0:X}, {1}): Called", handle.ToInt32(), Enable);
381 driver.EnableWindow(handle, Enable);
384 internal static void Exit() {
388 internal static IntPtr GetActive() {
390 Console.WriteLine("GetActive(): Called");
392 return driver.GetActive();
395 internal static SizeF GetAutoScaleSize(Font font) {
397 Console.WriteLine("GetAutoScaleSize({0}): Called", font);
399 return driver.GetAutoScaleSize(font);
402 internal static void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
404 Console.WriteLine("GetCursorInfo({0:X}): Called", cursor.ToInt32());
406 driver.GetCursorInfo(cursor, out width, out height, out hotspot_x, out hotspot_y);
409 internal static void GetCursorPos(IntPtr handle, out int x, out int y) {
411 Console.WriteLine("GetCursorPos({0:X}): Called", handle.ToInt32());
413 driver.GetCursorPos(handle, out x, out y);
416 internal static void GetDisplaySize(out Size size) {
418 Console.WriteLine("GetDisplaySize(): Called");
420 driver.GetDisplaySize(out size);
423 internal static bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
425 Console.WriteLine("GetFontMetrics(): Called");
427 return driver.GetFontMetrics(g, font, out ascent, out descent);
430 internal static Graphics GetMenuDC(IntPtr handle, IntPtr ncpaint_region) {
432 Console.WriteLine("GetMenuDC({0:X}): Called", handle.ToInt32());
434 return driver.GetMenuDC(handle, ncpaint_region);
437 internal static Point GetMenuOrigin(IntPtr handle) {
439 Console.WriteLine("GetMenuOrigin({0:X}): Called", handle.ToInt32());
441 return driver.GetMenuOrigin(handle);
444 internal static bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
445 return driver.GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
448 internal static IntPtr GetParent(IntPtr hWnd) {
450 Console.WriteLine("GetParent({0:X}): Called", hWnd.ToInt32());
452 return driver.GetParent(hWnd);
455 internal static bool GetText(IntPtr hWnd, out string text) {
457 Console.WriteLine("GetText(): Called");
459 return driver.GetText(hWnd, out text);
462 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) {
464 Console.WriteLine("GetWindowPos({0:X}): Called", handle.ToInt32());
466 driver.GetWindowPos(handle, is_toplevel, out x, out y, out width, out height, out client_width, out client_height);
469 internal static FormWindowState GetWindowState(IntPtr handle) {
471 Console.WriteLine("GetWindowState({0:X}): Called", handle.ToInt32());
473 return driver.GetWindowState(handle);
476 internal static void GrabInfo(out IntPtr handle, out bool GrabConfined, out Rectangle GrabArea) {
478 Console.WriteLine("GrabInfo(): Called");
480 driver.GrabInfo(out handle, out GrabConfined, out GrabArea);
483 internal static void GrabWindow(IntPtr handle, IntPtr ConfineToHwnd) {
485 Console.WriteLine("GrabWindow({0:X}): Called", handle.ToInt32());
487 driver.GrabWindow(handle, ConfineToHwnd);
490 internal static void HandleException(Exception e) {
491 driver.HandleException(e);
494 internal static void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
496 Console.WriteLine("Invalidate({0:X}, {1}, {2}): Called", handle.ToInt32(), rc, clear);
498 driver.Invalidate(handle, rc, clear);
501 internal static bool IsVisible(IntPtr hWnd) {
503 Console.WriteLine("IsVisible({0:X}): Called", hWnd.ToInt32());
505 return driver.IsVisible(hWnd);
508 internal static void KillTimer (Timer timer)
511 Console.WriteLine("KillTimer({0}): Called", timer);
513 driver.KillTimer (timer);
516 internal static void MenuToScreen(IntPtr handle, ref int x, ref int y) {
518 Console.WriteLine("MenuToScreen({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
520 driver.MenuToScreen(handle, ref x, ref y);
523 internal static void OverrideCursor(IntPtr cursor) {
525 Console.WriteLine("OverrideCursor({0:X}): Called", cursor.ToInt32());
527 driver.OverrideCursor(cursor);
530 internal static void PaintEventEnd(IntPtr handle, bool client) {
532 Console.WriteLine("PaintEventEnd({0:X}, {1}): Called", handle.ToInt32(), client);
534 driver.PaintEventEnd(handle, client);
537 internal static PaintEventArgs PaintEventStart(IntPtr handle, bool client) {
539 Console.WriteLine("PaintEventStart({0:X}, {1}): Called", handle.ToInt32(), client);
541 return driver.PaintEventStart(handle, client);
544 internal static bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
545 return driver.PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
548 internal static void ReleaseMenuDC(IntPtr handle, Graphics dc) {
550 Console.WriteLine("ReleaseMenuDC({0:X}): Called", handle.ToInt32());
552 driver.ReleaseMenuDC(handle, dc);
555 internal static void ScreenToClient(IntPtr handle, ref int x, ref int y) {
557 Console.WriteLine("ScreenToClient({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
559 driver.ScreenToClient (handle, ref x, ref y);
562 internal static void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
564 Console.WriteLine("ScreenToMenu({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
566 driver.ScreenToMenu(handle, ref x, ref y);
569 internal static void ScrollWindow(IntPtr handle, Rectangle rectangle, int XAmount, int YAmount, bool with_children) {
571 Console.WriteLine("ScrollWindow({0:X}, {1}, {2}, {3}, {4}): Called", handle.ToInt32(), rectangle, XAmount, YAmount, with_children);
573 driver.ScrollWindow(handle, rectangle, XAmount, YAmount, with_children);
576 internal static void ScrollWindow(IntPtr handle, int XAmount, int YAmount, bool with_children) {
578 Console.WriteLine("ScrollWindow({0:X}, {2}, {3}, {4}): Called", handle.ToInt32(), XAmount, YAmount, with_children);
580 driver.ScrollWindow(handle, XAmount, YAmount, with_children);
583 internal static void SendAsyncMethod (AsyncMethodData data) {
585 Console.WriteLine("SendAsyncMethod({0}): Called", data);
587 driver.SendAsyncMethod (data);
590 internal static void SetAllowDrop (IntPtr handle, bool value)
593 Console.WriteLine ("SetAllowDrop({0}, {1}): Called", handle, value);
595 driver.SetAllowDrop (handle, value);
598 internal static void SetBorderStyle(IntPtr handle, FormBorderStyle border_style) {
600 Console.WriteLine("SetBorderStyle({0:X}, {1}): Called", handle.ToInt32(), border_style);
602 driver.SetBorderStyle(handle, border_style);
605 internal static void SetCaretPos(IntPtr handle, int x, int y) {
607 Console.WriteLine("SetCaretPos({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
609 driver.SetCaretPos(handle, x, y);
612 internal static void SetCursor(IntPtr handle, IntPtr cursor) {
614 Console.WriteLine("SetCursor({0:X}, {1:X}): Called", handle.ToInt32(), cursor.ToInt32());
616 driver.SetCursor(handle, cursor);
619 internal static void SetCursorPos(IntPtr handle, int x, int y) {
621 Console.WriteLine("SetCursorPos({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
623 driver.SetCursorPos(handle, x, y);
626 internal static void SetFocus(IntPtr handle) {
628 Console.WriteLine("SetFocus({0:X}): Called", handle.ToInt32());
630 driver.SetFocus(handle);
633 internal static void SetIcon(IntPtr handle, Icon icon) {
635 Console.WriteLine("SetIcon({0:X}, {1}): Called", handle.ToInt32(), icon);
637 driver.SetIcon(handle, icon);
640 internal static void SetMenu(IntPtr handle, IntPtr menu_handle) {
642 Console.WriteLine("SetMenu({0:X}, {1:X}): Called", handle.ToInt32(), menu_handle.ToInt32());
644 driver.SetMenu(handle, menu_handle);
647 internal static void SetModal(IntPtr handle, bool Modal) {
649 Console.WriteLine("SetModal({0:X}, {1}): Called", handle.ToInt32(), Modal);
651 driver.SetModal(handle, Modal);
654 internal static IntPtr SetParent(IntPtr hWnd, IntPtr hParent) {
656 Console.WriteLine("SetParent({0:X}, {1:X}): Called", hWnd.ToInt32(), hParent.ToInt32());
658 return driver.SetParent(hWnd, hParent);
661 internal static void SetTimer (Timer timer)
664 Console.WriteLine("SetTimer({0}): Called", timer);
666 driver.SetTimer (timer);
669 internal static bool SetTopmost(IntPtr handle, IntPtr hWndOwner, bool Enabled) {
671 Console.WriteLine("SetTopMost({0:X}, {1:X}, {2}): Called", handle.ToInt32(), hWndOwner.ToInt32(), Enabled);
673 return driver.SetTopmost(handle, hWndOwner, Enabled);
676 internal static bool SetVisible(IntPtr hWnd, bool visible) {
678 Console.WriteLine("SetVisible({0:X}, {1}): Called", hWnd.ToInt32(), visible);
680 return driver.SetVisible(hWnd, visible);
683 internal static void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
685 Console.WriteLine("SetWindowPos({0:X}, {1}, {2}, {3}, {4}): Called", handle.ToInt32(), x, y, width, height);
687 driver.SetWindowPos(handle, x, y, width, height);
690 internal static void SetWindowState(IntPtr handle, FormWindowState state) {
692 Console.WriteLine("SetWindowState({0:X} {1}): Called", handle.ToInt32(), state);
694 driver.SetWindowState(handle, state);
697 internal static void SetWindowStyle(IntPtr handle, CreateParams cp) {
699 Console.WriteLine("SetWindowStyle({0:X}): Called", handle.ToInt32());
701 driver.SetWindowStyle(handle, cp);
704 internal static bool SetZOrder(IntPtr handle, IntPtr AfterhWnd, bool Top, bool Bottom) {
706 Console.WriteLine("SetZOrder({0:X}, {1:X}, {2}, {3}): Called", handle.ToInt32(), AfterhWnd.ToInt32(), Top, Bottom);
708 return driver.SetZOrder(handle, AfterhWnd, Top, Bottom);
711 internal static void ShowCursor(bool show) {
713 Console.WriteLine("ShowCursor({0}): Called", show);
715 driver.ShowCursor(show);
718 internal static DragDropEffects StartDrag(IntPtr handle, object data, DragDropEffects allowedEffects) {
720 Console.WriteLine ("StartDrag({0}, {1}, {2}): Called", handle, data, allowedEffects);
722 return driver.StartDrag (handle, data, allowedEffects);
725 internal static bool SystrayAdd(IntPtr handle, string tip, Icon icon, out ToolTip tt) {
727 Console.WriteLine("SystrayAdd({0:X}, {1}): Called", handle.ToInt32(), tip);
729 return driver.SystrayAdd(handle, tip, icon, out tt);
732 internal static void SystrayChange(IntPtr handle, string tip, Icon icon, ref ToolTip tt) {
734 Console.WriteLine("SystrayChange({0:X}, {1}): Called", handle.ToInt32(), tip);
736 driver.SystrayChange(handle, tip, icon, ref tt);
739 internal static void SystrayRemove(IntPtr handle, ref ToolTip tt) {
741 Console.WriteLine("SystrayRemove({0:X}): Called", handle.ToInt32());
743 driver.SystrayRemove(handle, ref tt);
746 internal static bool Text(IntPtr hWnd, string text) {
748 Console.WriteLine("Text({0:X}, {1}): Called", hWnd.ToInt32(), text);
750 return driver.Text(hWnd, text);
753 internal static bool TranslateMessage(ref MSG msg) {
754 return driver.TranslateMessage(ref msg);
757 internal static void UngrabWindow(IntPtr handle) {
759 Console.WriteLine("UngrabWindow({0:X}): Called", handle.ToInt32());
761 driver.UngrabWindow(handle);
764 internal static void UpdateWindow(IntPtr handle) {
766 Console.WriteLine("UpdateWindow({0:X}): Called", handle.ToInt32());
768 driver.UpdateWindow(handle);
771 // Santa's little helper
772 internal static void Version() {
773 Console.WriteLine("Xplat version $Revision: $");
776 internal static void Where() {
779 #endregion // Public Static Methods
782 public delegate bool ClipboardToObject(int type, IntPtr data, out object obj);
783 public delegate bool ObjectToClipboard(ref int type, object obj, out byte[] data);
784 #endregion // Delegates