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;
36 // Random architecture notes
40 // - set location/size
50 namespace System.Windows.Forms {
51 internal class XplatUI {
52 #region Local Variables
53 static XplatUIDriver driver;
54 static String default_class_name;
55 #endregion // Local Variables
60 static public Keys ModifierKeys {
62 return driver.ModifierKeys;
66 static public MouseButtons MouseButtons {
68 return driver.MouseButtons;
72 static public Point MousePosition {
74 return driver.MousePosition;
78 static public bool DropTarget {
80 return driver.DropTarget;
84 driver.DropTarget=value;
88 #endregion // Subclasses
90 #region Constructor & Destructor
92 // Don't forget to throw the mac in here somewhere, too
93 default_class_name="SWFClass";
95 if (Environment.OSVersion.Platform == (PlatformID)128) {
96 if (Environment.GetEnvironmentVariable ("MONO_MWF_USE_QUARTZ_BACKEND") != null)
97 driver=XplatUIOSX.GetInstance();
99 driver=XplatUIX11.GetInstance();
101 driver=XplatUIWin32.GetInstance();
104 Console.WriteLine("#region #line XplatUI Constructor called");
108 Console.WriteLine("XplatUI Destructor called");
110 #endregion // Constructor & Destructor
112 #region Public Static Properties
113 internal static string DefaultClassName {
115 return default_class_name;
119 default_class_name=value;
122 #endregion // Public Static Properties
124 internal static event EventHandler Idle {
126 driver.Idle += value;
129 driver.Idle -= value;
133 #region Public Static Methods
134 internal static void Exit() {
138 internal static void GetDisplaySize(out Size size) {
139 driver.GetDisplaySize(out size);
142 internal static void EnableThemes() {
143 driver.EnableThemes();
146 internal static bool Text(IntPtr hWnd, string text) {
147 return driver.Text(hWnd, text);
150 internal static bool GetText(IntPtr hWnd, out string text) {
151 return driver.GetText(hWnd, out text);
154 internal static bool SetVisible(IntPtr hWnd, bool visible) {
155 return driver.SetVisible(hWnd, visible);
158 internal static bool IsVisible(IntPtr hWnd) {
159 return driver.IsVisible(hWnd);
162 internal static IntPtr SetParent(IntPtr hWnd, IntPtr hParent) {
163 return driver.SetParent(hWnd, hParent);
166 internal static IntPtr GetParent(IntPtr hWnd) {
167 return driver.GetParent(hWnd);
170 internal static void Version() {
171 Console.WriteLine("Xplat version $revision: $");
174 internal static IntPtr CreateWindow(CreateParams cp) {
175 return driver.CreateWindow(cp);
178 internal static IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
179 return driver.CreateWindow(Parent, X, Y, Width, Height);
182 internal static void DestroyWindow(IntPtr handle) {
183 driver.DestroyWindow(handle);
186 internal static FormWindowState GetWindowState(IntPtr handle) {
187 return driver.GetWindowState(handle);
190 internal static void SetWindowState(IntPtr handle, FormWindowState state) {
191 driver.SetWindowState(handle, state);
194 internal static void RefreshWindow(IntPtr handle) {
195 driver.RefreshWindow(handle);
198 internal static void SetWindowBackground(IntPtr handle, Color color) {
199 driver.SetWindowBackground(handle, color);
202 internal static PaintEventArgs PaintEventStart(IntPtr handle) {
203 return driver.PaintEventStart(handle);
206 internal static void PaintEventEnd(IntPtr handle) {
207 driver.PaintEventEnd(handle);
210 internal static void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
211 driver.SetWindowPos(handle, x, y, width, height);
214 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) {
215 driver.GetWindowPos(handle, out x, out y, out width, out height, out client_width, out client_height);
218 internal static void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
219 driver.Invalidate(handle, rc, clear);
222 internal static void Activate(IntPtr handle) {
223 driver.Activate(handle);
226 internal static void EnableWindow(IntPtr handle, bool Enable) {
227 driver.EnableWindow(handle, Enable);
230 internal static void SetModal(IntPtr handle, bool Modal) {
231 driver.SetModal(handle, Modal);
234 internal static IntPtr DefWndProc(ref Message msg) {
235 return driver.DefWndProc(ref msg);
238 internal static void HandleException(Exception e) {
239 driver.HandleException(e);
242 internal static void DoEvents() {
246 internal static bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
247 return driver.PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
250 internal static bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
251 return driver.GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
254 internal static bool TranslateMessage(ref MSG msg) {
255 return driver.TranslateMessage(ref msg);
258 internal static IntPtr DispatchMessage(ref MSG msg) {
259 return driver.DispatchMessage(ref msg);
262 internal static void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
263 driver.GrabWindow(hWnd, ConfineToHwnd);
266 internal static void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
267 driver.GrabInfo(out hWnd, out GrabConfined, out GrabArea);
270 internal static void ReleaseWindow(IntPtr hWnd) {
271 driver.ReleaseWindow(hWnd);
274 internal static bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
275 return driver.SetZOrder(hWnd, AfterhWnd, Top, Bottom);
278 internal static bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
279 return driver.SetTopmost(hWnd, hWndOwner, Enabled);
282 internal static bool CalculateWindowRect(IntPtr hWnd, ref Rectangle ClientRect, int Style, bool HasMenu, out Rectangle WindowRect) {
283 return driver.CalculateWindowRect(hWnd, ref ClientRect, Style, HasMenu, out WindowRect);
286 internal static void SetCursorPos(IntPtr handle, int x, int y) {
287 driver.SetCursorPos(handle, x, y);
290 internal static void GetCursorPos(IntPtr handle, out int x, out int y) {
291 driver.GetCursorPos(handle, out x, out y);
294 internal static void ScreenToClient(IntPtr handle, ref int x, ref int y) {
295 driver.ScreenToClient (handle, ref x, ref y);
298 internal static void ClientToScreen(IntPtr handle, ref int x, ref int y) {
299 driver.ClientToScreen(handle, ref x, ref y);
302 internal static void SendAsyncMethod (AsyncMethodData data) {
303 driver.SendAsyncMethod (data);
306 internal static void CreateCaret(IntPtr hwnd, int width, int height) {
307 driver.CreateCaret(hwnd, width, height);
310 internal static void DestroyCaret(IntPtr hwnd) {
311 driver.DestroyCaret(hwnd);
314 internal static void SetCaretPos(IntPtr hwnd, int x, int y) {
315 driver.SetCaretPos(hwnd, x, y);
318 internal static void CaretVisible(IntPtr hwnd, bool visible) {
319 driver.CaretVisible(hwnd, visible);
322 internal static void SetFocus(IntPtr hwnd) {
323 driver.SetFocus(hwnd);
326 internal static IntPtr GetActive() {
327 return driver.GetActive();
330 internal static bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
331 return driver.GetFontMetrics(g, font, out ascent, out descent);
334 internal static void SetTimer (Timer timer)
336 driver.SetTimer (timer);
339 internal static void KillTimer (Timer timer)
341 driver.KillTimer (timer);
344 internal static int KeyboardSpeed {
346 return driver.KeyboardSpeed;
350 internal static int KeyboardDelay {
352 return driver.KeyboardSpeed;
356 internal static void ScrollWindow(IntPtr hwnd, int XAmount, int YAmount) {
357 driver.ScrollWindow(hwnd, XAmount, YAmount);
360 // Santa's little helper
361 internal static void Where() {
362 Console.WriteLine("Here: {0}", new StackTrace().ToString());
364 #endregion // Public Static Methods