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 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
30 using System.ComponentModel;
31 using System.Collections;
32 using System.Diagnostics;
33 using System.Runtime.InteropServices;
37 namespace System.Windows.Forms {
38 public class XplatUI {
39 #region Local Variables
40 static XplatUIDriver driver;
41 static String default_class_name;
42 #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;
65 static public bool DropTarget {
67 return driver.DropTarget;
71 driver.DropTarget=value;
75 #endregion // Subclasses
77 #region Constructor & Destructor
79 // Don't forget to throw the mac in here somewhere, too
80 default_class_name="SWFClass";
82 if (Environment.OSVersion.Platform == (PlatformID)128) {
83 if (Environment.GetEnvironmentVariable ("MONO_MWF_USE_QUARTZ_BACKEND") != null)
84 driver=XplatUIOSX.GetInstance();
86 driver=XplatUIX11.GetInstance();
88 driver=XplatUIWin32.GetInstance();
91 Console.WriteLine("#region #line XplatUI Constructor called");
95 Console.WriteLine("XplatUI Destructor called");
97 #endregion // Constructor & Destructor
99 #region Public Static Properties
100 internal static string DefaultClassName {
102 return default_class_name;
106 default_class_name=value;
109 #endregion // Public Static Properties
111 internal static event EventHandler Idle {
113 driver.Idle += value;
116 driver.Idle -= value;
120 #region Public Static Methods
121 internal static void Exit() {
125 internal static void GetDisplaySize(out Size size) {
126 driver.GetDisplaySize(out size);
129 internal static void EnableThemes() {
130 driver.EnableThemes();
133 internal static bool Text(IntPtr hWnd, string text) {
134 return driver.Text(hWnd, text);
137 internal static bool GetText(IntPtr hWnd, out string text) {
138 return driver.GetText(hWnd, out text);
141 internal static bool SetVisible(IntPtr hWnd, bool visible) {
142 return driver.SetVisible(hWnd, visible);
145 internal static bool IsVisible(IntPtr hWnd) {
146 return driver.IsVisible(hWnd);
149 internal static IntPtr SetParent(IntPtr hWnd, IntPtr hParent) {
150 return driver.SetParent(hWnd, hParent);
153 internal static IntPtr GetParent(IntPtr hWnd) {
154 return driver.GetParent(hWnd);
157 internal static void Version() {
158 Console.WriteLine("Xplat version $revision: $");
161 internal static IntPtr CreateWindow(CreateParams cp) {
162 return driver.CreateWindow(cp);
165 internal static IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
166 return driver.CreateWindow(Parent, X, Y, Width, Height);
169 internal static void DestroyWindow(IntPtr handle) {
170 driver.DestroyWindow(handle);
173 internal static FormWindowState GetWindowState(IntPtr handle) {
174 return driver.GetWindowState(handle);
177 internal static void SetWindowState(IntPtr handle, FormWindowState state) {
178 driver.SetWindowState(handle, state);
181 internal static void SetWindowStyle(IntPtr handle, CreateParams cp) {
182 driver.SetWindowStyle(handle, cp);
185 internal static void UpdateWindow(IntPtr handle) {
186 driver.UpdateWindow(handle);
189 internal static void SetWindowBackground(IntPtr handle, Color color) {
190 driver.SetWindowBackground(handle, color);
193 internal static PaintEventArgs PaintEventStart(IntPtr handle) {
194 return driver.PaintEventStart(handle);
197 internal static void PaintEventEnd(IntPtr handle) {
198 driver.PaintEventEnd(handle);
201 internal static void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
202 driver.SetWindowPos(handle, x, y, width, height);
205 internal static void GetWindowPos(IntPtr handle, out int x, out int y, out int width, out int height, out int client_width, out int client_height) {
206 driver.GetWindowPos(handle, out x, out y, out width, out height, out client_width, out client_height);
209 internal static void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
210 driver.Invalidate(handle, rc, clear);
213 internal static void Activate(IntPtr handle) {
214 driver.Activate(handle);
217 internal static void EnableWindow(IntPtr handle, bool Enable) {
218 driver.EnableWindow(handle, Enable);
221 internal static void SetModal(IntPtr handle, bool Modal) {
222 driver.SetModal(handle, Modal);
225 internal static IntPtr DefWndProc(ref Message msg) {
226 return driver.DefWndProc(ref msg);
229 internal static void HandleException(Exception e) {
230 driver.HandleException(e);
233 internal static void DoEvents() {
237 internal static bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
238 return driver.PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
241 internal static bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
242 return driver.GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
245 internal static bool TranslateMessage(ref MSG msg) {
246 return driver.TranslateMessage(ref msg);
249 internal static IntPtr DispatchMessage(ref MSG msg) {
250 return driver.DispatchMessage(ref msg);
253 internal static void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
254 driver.GrabWindow(hWnd, ConfineToHwnd);
257 internal static void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
258 driver.GrabInfo(out hWnd, out GrabConfined, out GrabArea);
261 internal static void ReleaseWindow(IntPtr hWnd) {
262 driver.ReleaseWindow(hWnd);
265 internal static bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
266 return driver.SetZOrder(hWnd, AfterhWnd, Top, Bottom);
269 internal static bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
270 return driver.SetTopmost(hWnd, hWndOwner, Enabled);
273 internal static bool CalculateWindowRect(IntPtr hWnd, ref Rectangle ClientRect, int Style, bool HasMenu, out Rectangle WindowRect) {
274 return driver.CalculateWindowRect(hWnd, ref ClientRect, Style, HasMenu, out WindowRect);
277 internal static void SetCursor(IntPtr hwnd, IntPtr cursor) {
278 driver.SetCursor(hwnd, cursor);
281 internal static void ShowCursor(bool show) {
282 driver.ShowCursor(show);
285 internal static void OverrideCursor(IntPtr cursor) {
286 driver.OverrideCursor(cursor);
289 internal static IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
290 return driver.DefineCursor(bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
293 internal static IntPtr DefineStdCursor(StdCursor id) {
294 return driver.DefineStdCursor(id);
297 internal static void DestroyCursor(IntPtr cursor) {
298 driver.DestroyCursor(cursor);
301 internal static void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
302 driver.GetCursorInfo(cursor, out width, out height, out hotspot_x, out hotspot_y);
305 internal static void SetCursorPos(IntPtr handle, int x, int y) {
306 driver.SetCursorPos(handle, x, y);
309 internal static void GetCursorPos(IntPtr handle, out int x, out int y) {
310 driver.GetCursorPos(handle, out x, out y);
313 internal static void ScreenToClient(IntPtr handle, ref int x, ref int y) {
314 driver.ScreenToClient (handle, ref x, ref y);
317 internal static void ClientToScreen(IntPtr handle, ref int x, ref int y) {
318 driver.ClientToScreen(handle, ref x, ref y);
321 internal static void SendAsyncMethod (AsyncMethodData data) {
322 driver.SendAsyncMethod (data);
325 internal static void CreateCaret(IntPtr hwnd, int width, int height) {
326 driver.CreateCaret(hwnd, width, height);
329 internal static void DestroyCaret(IntPtr hwnd) {
330 driver.DestroyCaret(hwnd);
333 internal static void SetCaretPos(IntPtr hwnd, int x, int y) {
334 driver.SetCaretPos(hwnd, x, y);
337 internal static void CaretVisible(IntPtr hwnd, bool visible) {
338 driver.CaretVisible(hwnd, visible);
341 internal static void SetFocus(IntPtr hwnd) {
342 driver.SetFocus(hwnd);
345 internal static IntPtr GetActive() {
346 return driver.GetActive();
349 internal static bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
350 return driver.GetFontMetrics(g, font, out ascent, out descent);
353 internal static void SetTimer (Timer timer)
355 driver.SetTimer (timer);
358 internal static void KillTimer (Timer timer)
360 driver.KillTimer (timer);
363 internal static int KeyboardSpeed {
365 return driver.KeyboardSpeed;
369 internal static int KeyboardDelay {
371 return driver.KeyboardSpeed;
375 internal static void ScrollWindow(IntPtr hwnd, Rectangle rectangle, int XAmount, int YAmount, bool clear) {
376 driver.ScrollWindow(hwnd, rectangle, XAmount, YAmount, clear);
379 internal static void ScrollWindow(IntPtr hwnd, int XAmount, int YAmount, bool clear) {
380 driver.ScrollWindow(hwnd, XAmount, YAmount, clear);
383 internal static bool SystrayAdd(IntPtr hwnd, string tip, Icon icon) {
384 return driver.SystrayAdd(hwnd, tip, icon);
387 internal static void SystrayChange(IntPtr hwnd, string tip, Icon icon) {
388 driver.SystrayChange(hwnd, tip, icon);
391 internal static void SystrayRemove(IntPtr hwnd) {
392 driver.SystrayRemove(hwnd);
396 // Santa's little helper
397 internal static void Where() {
398 Console.WriteLine("Here: {0}", new StackTrace().ToString());
400 #endregion // Public Static Methods