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 bool DropTarget {
49 return driver.DropTarget;
53 driver.DropTarget=value;
57 static public Keys ModifierKeys {
59 return driver.ModifierKeys;
63 static public MouseButtons MouseButtons {
65 return driver.MouseButtons;
69 static public Point MousePosition {
71 return driver.MousePosition;
76 #endregion // Subclasses
78 #region Constructor & Destructor
80 Console.WriteLine("Mono System.Windows.Forms Assembly [Revision: 44278; built: 2005/4/9 9:44:53]");
82 // Don't forget to throw the mac in here somewhere, too
83 default_class_name="SWFClass";
85 // check for Unix platforms - see FAQ for more details
86 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
87 int platform = (int) Environment.OSVersion.Platform;
88 if ((platform == 4) || (platform == 128)) {
89 if (Environment.GetEnvironmentVariable ("MONO_MWF_USE_QUARTZ_BACKEND") != null)
90 driver=XplatUIOSX.GetInstance();
92 driver=XplatUIX11.GetInstance();
94 driver=XplatUIWin32.GetInstance();
100 Console.WriteLine("XplatUI Destructor called");
102 #endregion // Constructor & Destructor
104 #region Public Static Properties
105 internal static string DefaultClassName {
107 return default_class_name;
111 default_class_name=value;
115 static public Size CursorSize {
117 return driver.CursorSize;
121 static public bool DragFullWindows {
123 return driver.DragFullWindows;
127 static public Size DragSize {
129 return driver.DragSize;
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 void ClipboardClose(IntPtr handle) {
282 Console.WriteLine("ClipboardClose({0:X}): Called", handle.ToInt32());
284 driver.ClipboardOpen();
287 internal static int ClipboardGetID(IntPtr handle, string format) {
289 Console.WriteLine("ClipboardGetID({0:X}, {1}): Called", handle.ToInt32(), format);
291 return driver.ClipboardGetID(handle, format);
294 internal static IntPtr ClipboardOpen() {
296 Console.WriteLine("ClipboardOpen(): Called");
298 return driver.ClipboardOpen();
301 internal static void ClipboardStore(IntPtr handle, object obj, int type) {
303 Console.WriteLine("ClipboardStore({0:X}, {1}, {2}): Called", handle.ToInt32(), obj, type);
305 driver.ClipboardStore(handle, obj, type);
308 internal static bool ClipboardRetrieve(IntPtr handle, out object obj, out int type) {
310 Console.WriteLine("ClipboardRetrieve({0:X}, obj, type): Called", handle.ToInt32());
312 return driver.ClipboardRetrieve(handle, out obj, out type);
315 internal static IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
317 Console.WriteLine("DefineCursor(...): Called");
319 return driver.DefineCursor(bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
322 internal static IntPtr DefineStdCursor(StdCursor id) {
323 return driver.DefineStdCursor(id);
326 internal static IntPtr DefWndProc(ref Message msg) {
327 return driver.DefWndProc(ref msg);
330 internal static void DestroyCaret(IntPtr handle) {
332 Console.WriteLine("DestroyCaret({0:X}): Called", handle.ToInt32());
334 driver.DestroyCaret(handle);
337 internal static void DestroyCursor(IntPtr cursor) {
339 Console.WriteLine("DestroyCursor({0:X}): Called", cursor.ToInt32());
341 driver.DestroyCursor(cursor);
344 internal static void DestroyWindow(IntPtr handle) {
346 Console.WriteLine("DestroyWindow({0:X}): Called", handle.ToInt32());
348 driver.DestroyWindow(handle);
351 internal static IntPtr DispatchMessage(ref MSG msg) {
352 return driver.DispatchMessage(ref msg);
355 internal static void DoEvents() {
359 internal static void EnableThemes() {
360 driver.EnableThemes();
363 internal static void EnableWindow(IntPtr handle, bool Enable) {
365 Console.WriteLine("EnableWindow({0:X}, {1}): Called", handle.ToInt32(), Enable);
367 driver.EnableWindow(handle, Enable);
370 internal static void Exit() {
374 internal static void EraseWindowBackground(IntPtr handle, IntPtr wParam) {
375 driver.EraseWindowBackground(handle, wParam);
378 internal static IntPtr GetActive() {
380 Console.WriteLine("GetActive(): Called");
382 return driver.GetActive();
385 internal static void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
387 Console.WriteLine("GetCursorInfo({0:X}): Called", cursor.ToInt32());
389 driver.GetCursorInfo(cursor, out width, out height, out hotspot_x, out hotspot_y);
392 internal static void GetCursorPos(IntPtr handle, out int x, out int y) {
394 Console.WriteLine("GetCursorPos({0:X}): Called", handle.ToInt32());
396 driver.GetCursorPos(handle, out x, out y);
399 internal static void GetDisplaySize(out Size size) {
401 Console.WriteLine("GetDisplaySize(): Called");
403 driver.GetDisplaySize(out size);
406 internal static bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
408 Console.WriteLine("GetFontMetrics(): Called");
410 return driver.GetFontMetrics(g, font, out ascent, out descent);
413 internal static Graphics GetMenuDC(IntPtr handle, IntPtr ncpaint_region) {
415 Console.WriteLine("GetMenuDC({0:X}): Called", handle.ToInt32());
417 return driver.GetMenuDC(handle, ncpaint_region);
420 internal static Point GetMenuOrigin(IntPtr handle) {
422 Console.WriteLine("GetMenuOrigin({0:X}): Called", handle.ToInt32());
424 return driver.GetMenuOrigin(handle);
427 internal static bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
428 return driver.GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
431 internal static IntPtr GetParent(IntPtr hWnd) {
433 Console.WriteLine("GetParent({0:X}): Called", hWnd.ToInt32());
435 return driver.GetParent(hWnd);
438 internal static bool GetText(IntPtr hWnd, out string text) {
440 Console.WriteLine("GetText(): Called");
442 return driver.GetText(hWnd, out text);
445 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) {
447 Console.WriteLine("GetWindowPos({0:X}): Called", handle.ToInt32());
449 driver.GetWindowPos(handle, is_toplevel, out x, out y, out width, out height, out client_width, out client_height);
452 internal static FormWindowState GetWindowState(IntPtr handle) {
454 Console.WriteLine("GetWindowState({0:X}): Called", handle.ToInt32());
456 return driver.GetWindowState(handle);
459 internal static void GrabInfo(out IntPtr handle, out bool GrabConfined, out Rectangle GrabArea) {
461 Console.WriteLine("GrabInfo(): Called");
463 driver.GrabInfo(out handle, out GrabConfined, out GrabArea);
466 internal static void GrabWindow(IntPtr handle, IntPtr ConfineToHwnd) {
468 Console.WriteLine("GrabWindow({0:X}): Called", handle.ToInt32());
470 driver.GrabWindow(handle, ConfineToHwnd);
473 internal static void HandleException(Exception e) {
474 driver.HandleException(e);
477 internal static void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
479 Console.WriteLine("Invalidate({0:X}, {1}, {2}): Called", handle.ToInt32(), rc, clear);
481 driver.Invalidate(handle, rc, clear);
484 internal static bool IsVisible(IntPtr hWnd) {
486 Console.WriteLine("IsVisible({0:X}): Called", hWnd.ToInt32());
488 return driver.IsVisible(hWnd);
491 internal static void KillTimer (Timer timer)
494 Console.WriteLine("KillTimer({0}): Called", timer);
496 driver.KillTimer (timer);
499 internal static void MenuToScreen(IntPtr handle, ref int x, ref int y) {
501 Console.WriteLine("MenuToScreen({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
503 driver.MenuToScreen(handle, ref x, ref y);
506 internal static void OverrideCursor(IntPtr cursor) {
508 Console.WriteLine("OverrideCursor({0:X}): Called", cursor.ToInt32());
510 driver.OverrideCursor(cursor);
513 internal static void PaintEventEnd(IntPtr handle) {
515 Console.WriteLine("PaintEventEnd({0:X}): Called", handle.ToInt32());
517 driver.PaintEventEnd(handle);
520 internal static PaintEventArgs PaintEventStart(IntPtr handle) {
522 Console.WriteLine("PaintEventStart({0:X}): Called", handle.ToInt32());
524 return driver.PaintEventStart(handle);
527 internal static bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
528 return driver.PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
531 internal static void ReleaseMenuDC(IntPtr handle, Graphics dc) {
533 Console.WriteLine("ReleaseMenuDC({0:X}): Called", handle.ToInt32());
535 driver.ReleaseMenuDC(handle, dc);
538 internal static void ScreenToClient(IntPtr handle, ref int x, ref int y) {
540 Console.WriteLine("ScreenToClient({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
542 driver.ScreenToClient (handle, ref x, ref y);
545 internal static void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
547 Console.WriteLine("ScreenToMenu({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
549 driver.ScreenToMenu(handle, ref x, ref y);
552 internal static void ScrollWindow(IntPtr handle, Rectangle rectangle, int XAmount, int YAmount, bool with_children) {
554 Console.WriteLine("ScrollWindow({0:X}, {1}, {2}, {3}, {4}): Called", handle.ToInt32(), rectangle, XAmount, YAmount, with_children);
556 driver.ScrollWindow(handle, rectangle, XAmount, YAmount, with_children);
559 internal static void ScrollWindow(IntPtr handle, int XAmount, int YAmount, bool with_children) {
561 Console.WriteLine("ScrollWindow({0:X}, {2}, {3}, {4}): Called", handle.ToInt32(), XAmount, YAmount, with_children);
563 driver.ScrollWindow(handle, XAmount, YAmount, with_children);
566 internal static void SendAsyncMethod (AsyncMethodData data) {
568 Console.WriteLine("SendAsyncMethod({0}): Called", data);
570 driver.SendAsyncMethod (data);
573 internal static void SetBorderStyle(IntPtr handle, BorderStyle border_style) {
575 Console.WriteLine("SetBorderStyle({0:X}, {1}): Called", handle.ToInt32(), border_style);
577 driver.SetBorderStyle(handle, border_style);
580 internal static void SetCaretPos(IntPtr handle, int x, int y) {
582 Console.WriteLine("SetCaretPos({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
584 driver.SetCaretPos(handle, x, y);
587 internal static void SetCursor(IntPtr handle, IntPtr cursor) {
589 Console.WriteLine("SetCursor({0:X}, {1:X}): Called", handle.ToInt32(), cursor.ToInt32());
591 driver.SetCursor(handle, cursor);
594 internal static void SetCursorPos(IntPtr handle, int x, int y) {
596 Console.WriteLine("SetCursorPos({0:X}, {1}, {2}): Called", handle.ToInt32(), x, y);
598 driver.SetCursorPos(handle, x, y);
601 internal static void SetFocus(IntPtr handle) {
603 Console.WriteLine("SetFocus({0:X}): Called", handle.ToInt32());
605 driver.SetFocus(handle);
608 internal static void SetIcon(IntPtr handle, Icon icon) {
610 Console.WriteLine("SetIcon({0:X}, {1}): Called", handle.ToInt32(), icon);
612 driver.SetIcon(handle, icon);
615 internal static void SetMenu(IntPtr handle, IntPtr menu_handle) {
617 Console.WriteLine("SetMenu({0:X}, {1:X}): Called", handle.ToInt32(), menu_handle.ToInt32());
619 driver.SetMenu(handle, menu_handle);
622 internal static void SetModal(IntPtr handle, bool Modal) {
624 Console.WriteLine("SetModal({0:X}, {1}): Called", handle.ToInt32(), Modal);
626 driver.SetModal(handle, Modal);
629 internal static IntPtr SetParent(IntPtr hWnd, IntPtr hParent) {
631 Console.WriteLine("SetParent({0:X}, {1:X}): Called", hWnd.ToInt32(), hParent.ToInt32());
633 return driver.SetParent(hWnd, hParent);
636 internal static void SetTimer (Timer timer)
639 Console.WriteLine("SetTimer({0}): Called", timer);
641 driver.SetTimer (timer);
644 internal static bool SetTopmost(IntPtr handle, IntPtr hWndOwner, bool Enabled) {
646 Console.WriteLine("SetTopMost({0:X}, {1:X}, {2}): Called", handle.ToInt32(), hWndOwner.ToInt32(), Enabled);
648 return driver.SetTopmost(handle, hWndOwner, Enabled);
651 internal static bool SetVisible(IntPtr hWnd, bool visible) {
653 Console.WriteLine("SetVisible({0:X}, {1}): Called", hWnd.ToInt32(), visible);
655 return driver.SetVisible(hWnd, visible);
658 internal static void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
660 Console.WriteLine("SetWindowPos({0:X}, {1}, {2}, {3}, {4}): Called", handle.ToInt32(), x, y, width, height);
662 driver.SetWindowPos(handle, x, y, width, height);
665 internal static void SetWindowState(IntPtr handle, FormWindowState state) {
667 Console.WriteLine("SetWindowState({0:X} {1}): Called", handle.ToInt32(), state);
669 driver.SetWindowState(handle, state);
672 internal static void SetWindowStyle(IntPtr handle, CreateParams cp) {
674 Console.WriteLine("SetWindowStyle({0:X}): Called", handle.ToInt32());
676 driver.SetWindowStyle(handle, cp);
679 internal static void SetWindowBackground(IntPtr handle, Color color) {
681 Console.WriteLine("SetWindowBackground({0:X}, {1}): Called", handle.ToInt32(), color);
683 driver.SetWindowBackground(handle, color);
686 internal static bool SetZOrder(IntPtr handle, IntPtr AfterhWnd, bool Top, bool Bottom) {
688 Console.WriteLine("SetZOrder({0:X}, {1:X}, {2}, {3}): Called", handle.ToInt32(), AfterhWnd.ToInt32(), Top, Bottom);
690 return driver.SetZOrder(handle, AfterhWnd, Top, Bottom);
693 internal static void ShowCursor(bool show) {
695 Console.WriteLine("ShowCursor({0}): Called", show);
697 driver.ShowCursor(show);
700 internal static bool SystrayAdd(IntPtr handle, string tip, Icon icon, out ToolTip tt) {
702 Console.WriteLine("SystrayAdd({0:X}, {1}): Called", handle.ToInt32(), tip);
704 return driver.SystrayAdd(handle, tip, icon, out tt);
707 internal static void SystrayChange(IntPtr handle, string tip, Icon icon, ref ToolTip tt) {
709 Console.WriteLine("SystrayChange({0:X}, {1}): Called", handle.ToInt32(), tip);
711 driver.SystrayChange(handle, tip, icon, ref tt);
714 internal static void SystrayRemove(IntPtr handle, ref ToolTip tt) {
716 Console.WriteLine("SystrayRemove({0:X}): Called", handle.ToInt32());
718 driver.SystrayRemove(handle, ref tt);
721 internal static bool Text(IntPtr hWnd, string text) {
723 Console.WriteLine("Text({0:X}, {1}): Called", hWnd.ToInt32(), text);
725 return driver.Text(hWnd, text);
728 internal static bool TranslateMessage(ref MSG msg) {
729 return driver.TranslateMessage(ref msg);
732 internal static void UngrabWindow(IntPtr handle) {
734 Console.WriteLine("UngrabWindow({0:X}): Called", handle.ToInt32());
736 driver.UngrabWindow(handle);
739 internal static void UpdateWindow(IntPtr handle) {
741 Console.WriteLine("UpdateWindow({0:X}): Called", handle.ToInt32());
743 driver.UpdateWindow(handle);
746 // Santa's little helper
747 internal static void Version() {
748 Console.WriteLine("Xplat version $Revision: $");
751 internal static void Where() {
754 #endregion // Public Static Methods