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: 49925; built: 2005/9/11 14:27: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();
92 Console.WriteLine("XplatUI Destructor called");
94 #endregion // Constructor & Destructor
96 #region Public Static Properties
97 internal static string DefaultClassName {
99 return default_class_name;
103 default_class_name=value;
107 static public int CaptionHeight {
109 return driver.Caption;
113 static public Size CursorSize {
115 return driver.CursorSize;
119 static public bool DragFullWindows {
121 return driver.DragFullWindows;
125 static public Size DragSize {
127 return driver.DragSize;
131 public static Size FrameBorderSize {
133 return driver.FrameBorderSize;
137 static public Size IconSize {
139 return driver.IconSize;
143 static public int KeyboardSpeed {
145 return driver.KeyboardSpeed;
149 static public int KeyboardDelay {
151 return driver.KeyboardSpeed;
155 static public Size MaxWindowTrackSize {
157 return driver.MaxWindowTrackSize;
161 static public Size MinimizedWindowSize {
163 return driver.MinimizedWindowSize;
167 static public Size MinimizedWindowSpacingSize {
169 return driver.MinimizedWindowSpacingSize;
173 static public Size MinimumWindowSize {
175 return driver.MinimumWindowSize;
179 static public Size MinWindowTrackSize {
181 return driver.MinWindowTrackSize;
185 static public Size SmallIconSize {
187 return driver.SmallIconSize;
191 static public int MouseButtonCount {
193 return driver.MouseButtonCount;
197 static public bool MouseButtonsSwapped {
199 return driver.MouseButtonsSwapped;
203 static public bool MouseWheelPresent {
205 return driver.MouseWheelPresent;
209 static public Rectangle VirtualScreen {
211 return driver.VirtualScreen;
215 static public Rectangle WorkingArea {
217 return driver.WorkingArea;
220 #endregion // Public Static Properties
223 internal static event EventHandler Idle {
225 driver.Idle += value;
228 driver.Idle -= value;
234 #region Public Static Methods
235 internal static void Activate(IntPtr handle) {
237 Console.WriteLine("Activate({0:X}): Called", handle.ToInt32());
239 driver.Activate(handle);
242 internal static bool CalculateWindowRect(IntPtr handle, ref Rectangle ClientRect, int Style, int ExStyle, IntPtr MenuHandle, out Rectangle WindowRect) {
244 Console.WriteLine("CalculateWindowRect({0:X}): Called", handle.ToInt32());
246 return driver.CalculateWindowRect(handle, ref ClientRect, Style, ExStyle, MenuHandle, out WindowRect);
249 internal static void CaretVisible(IntPtr handle, bool visible) {
251 Console.WriteLine("CaretVisible({0:X}, {1}): Called", handle.ToInt32(), visible);
253 driver.CaretVisible(handle, visible);
256 internal static void CreateCaret(IntPtr handle, int width, int height) {
258 Console.WriteLine("CreateCaret({0:X}), {1}, {2}: Called", handle.ToInt32(), width, height);
260 driver.CreateCaret(handle, width, height);
263 internal static IntPtr CreateWindow(CreateParams cp) {
265 Console.WriteLine("CreateWindow(): Called");
267 return driver.CreateWindow(cp);
270 internal static IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
272 Console.WriteLine("CreateWindow(): Called");
274 return driver.CreateWindow(Parent, X, Y, Width, Height);
277 internal static void ClientToScreen(IntPtr handle, ref int x, ref int y) {
279 Console.WriteLine("ClientToScreen({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
281 driver.ClientToScreen(handle, ref x, ref y);
284 internal static int[] ClipboardAvailableFormats(IntPtr handle) {
286 Console.WriteLine("ClipboardAvailableTypes({0:X}): Called", handle.ToInt32());
288 return driver.ClipboardAvailableFormats(handle);
291 internal static void ClipboardClose(IntPtr handle) {
293 Console.WriteLine("ClipboardClose({0:X}): Called", handle.ToInt32());
295 driver.ClipboardClose(handle);
298 internal static int ClipboardGetID(IntPtr handle, string format) {
300 Console.WriteLine("ClipboardGetID({0:X}, {1}): Called", handle.ToInt32(), format);
302 return driver.ClipboardGetID(handle, format);
305 internal static IntPtr ClipboardOpen() {
307 Console.WriteLine("ClipboardOpen(): Called");
309 return driver.ClipboardOpen();
312 internal static void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
314 Console.WriteLine("ClipboardStore({0:X}, {1}, {2}): Called", handle.ToInt32(), obj, (ClipboardFormat)type, converter);
316 driver.ClipboardStore(handle, obj, type, converter);
319 internal static object ClipboardRetrieve(IntPtr handle, int type, XplatUI.ClipboardToObject converter) {
321 Console.WriteLine("ClipboardRetrieve({0:X}, type, {1}): Called", handle.ToInt32(), converter);
323 return driver.ClipboardRetrieve(handle, type, converter);
326 internal static IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
328 Console.WriteLine("DefineCursor(...): Called");
330 return driver.DefineCursor(bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
333 internal static IntPtr DefineStdCursor(StdCursor id) {
334 return driver.DefineStdCursor(id);
337 internal static IntPtr DefWndProc(ref Message msg) {
338 return driver.DefWndProc(ref msg);
341 internal static void DestroyCaret(IntPtr handle) {
343 Console.WriteLine("DestroyCaret({0:X}): Called", handle.ToInt32());
345 driver.DestroyCaret(handle);
348 internal static void DestroyCursor(IntPtr cursor) {
350 Console.WriteLine("DestroyCursor({0:X}): Called", cursor.ToInt32());
352 driver.DestroyCursor(cursor);
355 internal static void DestroyWindow(IntPtr handle) {
357 Console.WriteLine("DestroyWindow({0:X}): Called", handle.ToInt32());
359 driver.DestroyWindow(handle);
362 internal static IntPtr DispatchMessage(ref MSG msg) {
363 return driver.DispatchMessage(ref msg);
366 internal static void DoEvents() {
370 internal static void DrawReversibleRectangle(IntPtr handle, Rectangle rect) {
372 Console.WriteLine("DrawReversibleRectangle({0:X}, {1}): Called", handle.ToInt32(), rect);
374 driver.DrawReversibleRectangle(handle, rect);
377 internal static void EnableThemes() {
378 driver.EnableThemes();
381 internal static void EnableWindow(IntPtr handle, bool Enable) {
383 Console.WriteLine("EnableWindow({0:X}, {1}): Called", handle.ToInt32(), Enable);
385 driver.EnableWindow(handle, Enable);
388 internal static void Exit() {
392 internal static void EraseWindowBackground(IntPtr handle, IntPtr wParam) {
393 driver.EraseWindowBackground(handle, wParam);
396 internal static IntPtr GetActive() {
398 Console.WriteLine("GetActive(): Called");
400 return driver.GetActive();
403 internal static void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
405 Console.WriteLine("GetCursorInfo({0:X}): Called", cursor.ToInt32());
407 driver.GetCursorInfo(cursor, out width, out height, out hotspot_x, out hotspot_y);
410 internal static void GetCursorPos(IntPtr handle, out int x, out int y) {
412 Console.WriteLine("GetCursorPos({0:X}): Called", handle.ToInt32());
414 driver.GetCursorPos(handle, out x, out y);
417 internal static void GetDisplaySize(out Size size) {
419 Console.WriteLine("GetDisplaySize(): Called");
421 driver.GetDisplaySize(out size);
424 internal static bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
426 Console.WriteLine("GetFontMetrics(): Called");
428 return driver.GetFontMetrics(g, font, out ascent, out descent);
431 internal static Graphics GetMenuDC(IntPtr handle, IntPtr ncpaint_region) {
433 Console.WriteLine("GetMenuDC({0:X}): Called", handle.ToInt32());
435 return driver.GetMenuDC(handle, ncpaint_region);
438 internal static Point GetMenuOrigin(IntPtr handle) {
440 Console.WriteLine("GetMenuOrigin({0:X}): Called", handle.ToInt32());
442 return driver.GetMenuOrigin(handle);
445 internal static bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
446 return driver.GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
449 internal static IntPtr GetParent(IntPtr hWnd) {
451 Console.WriteLine("GetParent({0:X}): Called", hWnd.ToInt32());
453 return driver.GetParent(hWnd);
456 internal static bool GetText(IntPtr hWnd, out string text) {
458 Console.WriteLine("GetText(): Called");
460 return driver.GetText(hWnd, out text);
463 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) {
465 Console.WriteLine("GetWindowPos({0:X}): Called", handle.ToInt32());
467 driver.GetWindowPos(handle, is_toplevel, out x, out y, out width, out height, out client_width, out client_height);
470 internal static FormWindowState GetWindowState(IntPtr handle) {
472 Console.WriteLine("GetWindowState({0:X}): Called", handle.ToInt32());
474 return driver.GetWindowState(handle);
477 internal static void GrabInfo(out IntPtr handle, out bool GrabConfined, out Rectangle GrabArea) {
479 Console.WriteLine("GrabInfo(): Called");
481 driver.GrabInfo(out handle, out GrabConfined, out GrabArea);
484 internal static void GrabWindow(IntPtr handle, IntPtr ConfineToHwnd) {
486 Console.WriteLine("GrabWindow({0:X}): Called", handle.ToInt32());
488 driver.GrabWindow(handle, ConfineToHwnd);
491 internal static void HandleException(Exception e) {
492 driver.HandleException(e);
495 internal static void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
497 Console.WriteLine("Invalidate({0:X}, {1}, {2}): Called", handle.ToInt32(), rc, clear);
499 driver.Invalidate(handle, rc, clear);
502 internal static bool IsVisible(IntPtr hWnd) {
504 Console.WriteLine("IsVisible({0:X}): Called", hWnd.ToInt32());
506 return driver.IsVisible(hWnd);
509 internal static void KillTimer (Timer timer)
512 Console.WriteLine("KillTimer({0}): Called", timer);
514 driver.KillTimer (timer);
517 internal static void MenuToScreen(IntPtr handle, ref int x, ref int y) {
519 Console.WriteLine("MenuToScreen({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
521 driver.MenuToScreen(handle, ref x, ref y);
524 internal static void OverrideCursor(IntPtr cursor) {
526 Console.WriteLine("OverrideCursor({0:X}): Called", cursor.ToInt32());
528 driver.OverrideCursor(cursor);
531 internal static void PaintEventEnd(IntPtr handle, bool client) {
533 Console.WriteLine("PaintEventEnd({0:X}, {1}): Called", handle.ToInt32(), client);
535 driver.PaintEventEnd(handle, client);
538 internal static PaintEventArgs PaintEventStart(IntPtr handle, bool client) {
540 Console.WriteLine("PaintEventStart({0:X}, {1}): Called", handle.ToInt32(), client);
542 return driver.PaintEventStart(handle, client);
545 internal static bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
546 return driver.PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
549 internal static void ReleaseMenuDC(IntPtr handle, Graphics dc) {
551 Console.WriteLine("ReleaseMenuDC({0:X}): Called", handle.ToInt32());
553 driver.ReleaseMenuDC(handle, dc);
556 internal static void ScreenToClient(IntPtr handle, ref int x, ref int y) {
558 Console.WriteLine("ScreenToClient({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
560 driver.ScreenToClient (handle, ref x, ref y);
563 internal static void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
565 Console.WriteLine("ScreenToMenu({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
567 driver.ScreenToMenu(handle, ref x, ref y);
570 internal static void ScrollWindow(IntPtr handle, Rectangle rectangle, int XAmount, int YAmount, bool with_children) {
572 Console.WriteLine("ScrollWindow({0:X}, {1}, {2}, {3}, {4}): Called", handle.ToInt32(), rectangle, XAmount, YAmount, with_children);
574 driver.ScrollWindow(handle, rectangle, XAmount, YAmount, with_children);
577 internal static void ScrollWindow(IntPtr handle, int XAmount, int YAmount, bool with_children) {
579 Console.WriteLine("ScrollWindow({0:X}, {2}, {3}, {4}): Called", handle.ToInt32(), XAmount, YAmount, with_children);
581 driver.ScrollWindow(handle, XAmount, YAmount, with_children);
584 internal static void SendAsyncMethod (AsyncMethodData data) {
586 Console.WriteLine("SendAsyncMethod({0}): Called", data);
588 driver.SendAsyncMethod (data);
591 internal static void SetAllowDrop (IntPtr handle, bool value)
594 Console.WriteLine ("SetAllowDrop({0}, {1}): Called", handle, value);
596 driver.SetAllowDrop (handle, value);
599 internal static void SetBorderStyle(IntPtr handle, BorderStyle border_style) {
601 Console.WriteLine("SetBorderStyle({0:X}, {1}): Called", handle.ToInt32(), border_style);
603 driver.SetBorderStyle(handle, border_style);
606 internal static void SetCaretPos(IntPtr handle, int x, int y) {
608 Console.WriteLine("SetCaretPos({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
610 driver.SetCaretPos(handle, x, y);
613 internal static void SetCursor(IntPtr handle, IntPtr cursor) {
615 Console.WriteLine("SetCursor({0:X}, {1:X}): Called", handle.ToInt32(), cursor.ToInt32());
617 driver.SetCursor(handle, cursor);
620 internal static void SetCursorPos(IntPtr handle, int x, int y) {
622 Console.WriteLine("SetCursorPos({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
624 driver.SetCursorPos(handle, x, y);
627 internal static void SetFocus(IntPtr handle) {
629 Console.WriteLine("SetFocus({0:X}): Called", handle.ToInt32());
631 driver.SetFocus(handle);
634 internal static void SetIcon(IntPtr handle, Icon icon) {
636 Console.WriteLine("SetIcon({0:X}, {1}): Called", handle.ToInt32(), icon);
638 driver.SetIcon(handle, icon);
641 internal static void SetMenu(IntPtr handle, IntPtr menu_handle) {
643 Console.WriteLine("SetMenu({0:X}, {1:X}): Called", handle.ToInt32(), menu_handle.ToInt32());
645 driver.SetMenu(handle, menu_handle);
648 internal static void SetModal(IntPtr handle, bool Modal) {
650 Console.WriteLine("SetModal({0:X}, {1}): Called", handle.ToInt32(), Modal);
652 driver.SetModal(handle, Modal);
655 internal static IntPtr SetParent(IntPtr hWnd, IntPtr hParent) {
657 Console.WriteLine("SetParent({0:X}, {1:X}): Called", hWnd.ToInt32(), hParent.ToInt32());
659 return driver.SetParent(hWnd, hParent);
662 internal static void SetTimer (Timer timer)
665 Console.WriteLine("SetTimer({0}): Called", timer);
667 driver.SetTimer (timer);
670 internal static bool SetTopmost(IntPtr handle, IntPtr hWndOwner, bool Enabled) {
672 Console.WriteLine("SetTopMost({0:X}, {1:X}, {2}): Called", handle.ToInt32(), hWndOwner.ToInt32(), Enabled);
674 return driver.SetTopmost(handle, hWndOwner, Enabled);
677 internal static bool SetVisible(IntPtr hWnd, bool visible) {
679 Console.WriteLine("SetVisible({0:X}, {1}): Called", hWnd.ToInt32(), visible);
681 return driver.SetVisible(hWnd, visible);
684 internal static void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
686 Console.WriteLine("SetWindowPos({0:X}, {1}, {2}, {3}, {4}): Called", handle.ToInt32(), x, y, width, height);
688 driver.SetWindowPos(handle, x, y, width, height);
691 internal static void SetWindowState(IntPtr handle, FormWindowState state) {
693 Console.WriteLine("SetWindowState({0:X} {1}): Called", handle.ToInt32(), state);
695 driver.SetWindowState(handle, state);
698 internal static void SetWindowStyle(IntPtr handle, CreateParams cp) {
700 Console.WriteLine("SetWindowStyle({0:X}): Called", handle.ToInt32());
702 driver.SetWindowStyle(handle, cp);
705 internal static void SetWindowBackground(IntPtr handle, Color color) {
707 Console.WriteLine("SetWindowBackground({0:X}, {1}): Called", handle.ToInt32(), color);
709 driver.SetWindowBackground(handle, color);
712 internal static bool SetZOrder(IntPtr handle, IntPtr AfterhWnd, bool Top, bool Bottom) {
714 Console.WriteLine("SetZOrder({0:X}, {1:X}, {2}, {3}): Called", handle.ToInt32(), AfterhWnd.ToInt32(), Top, Bottom);
716 return driver.SetZOrder(handle, AfterhWnd, Top, Bottom);
719 internal static void ShowCursor(bool show) {
721 Console.WriteLine("ShowCursor({0}): Called", show);
723 driver.ShowCursor(show);
726 internal static DragDropEffects StartDrag(IntPtr handle, object data, DragDropEffects allowedEffects) {
728 Console.WriteLine ("StartDrag({0}, {1}, {2}): Called", handle, data, allowedEffects);
730 return driver.StartDrag (handle, data, allowedEffects);
733 internal static bool SystrayAdd(IntPtr handle, string tip, Icon icon, out ToolTip tt) {
735 Console.WriteLine("SystrayAdd({0:X}, {1}): Called", handle.ToInt32(), tip);
737 return driver.SystrayAdd(handle, tip, icon, out tt);
740 internal static void SystrayChange(IntPtr handle, string tip, Icon icon, ref ToolTip tt) {
742 Console.WriteLine("SystrayChange({0:X}, {1}): Called", handle.ToInt32(), tip);
744 driver.SystrayChange(handle, tip, icon, ref tt);
747 internal static void SystrayRemove(IntPtr handle, ref ToolTip tt) {
749 Console.WriteLine("SystrayRemove({0:X}): Called", handle.ToInt32());
751 driver.SystrayRemove(handle, ref tt);
754 internal static bool Text(IntPtr hWnd, string text) {
756 Console.WriteLine("Text({0:X}, {1}): Called", hWnd.ToInt32(), text);
758 return driver.Text(hWnd, text);
761 internal static bool TranslateMessage(ref MSG msg) {
762 return driver.TranslateMessage(ref msg);
765 internal static void UngrabWindow(IntPtr handle) {
767 Console.WriteLine("UngrabWindow({0:X}): Called", handle.ToInt32());
769 driver.UngrabWindow(handle);
772 internal static void UpdateWindow(IntPtr handle) {
774 Console.WriteLine("UpdateWindow({0:X}): Called", handle.ToInt32());
776 driver.UpdateWindow(handle);
779 // Santa's little helper
780 internal static void Version() {
781 Console.WriteLine("Xplat version $Revision: $");
784 internal static void Where() {
787 #endregion // Public Static Methods
790 public delegate bool ClipboardToObject(int type, IntPtr data, out object obj);
791 public delegate bool ObjectToClipboard(ref int type, object obj, out byte[] data);
792 #endregion // Delegates