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
28 // $Log: XplatUI.cs,v $
29 // Revision 1.26 2004/11/08 20:53:03 pbartok
30 // - Added argument to SetTopmost
32 // Revision 1.25 2004/10/18 04:50:54 pbartok
33 // - Added method for enabling/disabling windows
34 // - Added method for setting window modality
35 // - Added method for setting topmost window
37 // Revision 1.24 2004/10/02 19:07:36 pbartok
38 // - Added ClientToScreen coordinate translation method
40 // Revision 1.23 2004/09/21 00:54:15 jackson
41 // New message loop that uses poll so we don't get a busy loop
43 // Revision 1.22 2004/09/13 21:18:32 pbartok
44 // - Added Z-Ordering methods
46 // Revision 1.21 2004/09/11 00:57:35 pbartok
47 // - Added method to retrieve text from window
49 // Revision 1.20 2004/08/24 11:29:44 jackson
50 // Move timers to the driver level. On X they are queued by the driver and checked on idle.
52 // Revision 1.19 2004/08/23 19:39:30 pbartok
53 // - Added method to move mouse cursor
55 // Revision 1.18 2004/08/21 20:51:27 pbartok
56 // - Added method to get default display size
58 // Revision 1.17 2004/08/21 20:23:56 pbartok
59 // - Added method to query current grab state
60 // - Added argument to allow confining a grab to a window
62 // Revision 1.16 2004/08/20 20:03:20 pbartok
63 // - Added method for setting the window background
65 // Revision 1.15 2004/08/20 19:14:35 jackson
66 // Expose functionality to send async messages through the driver
68 // Revision 1.14 2004/08/13 21:42:15 pbartok
69 // - Changed signature for GetCursorPos
71 // Revision 1.13 2004/08/13 19:00:15 jordi
72 // implements PointToClient (ScreenToClient)
74 // Revision 1.12 2004/08/13 18:53:14 pbartok
75 // - Changed GetWindowPos to also provide client area size
77 // Revision 1.11 2004/08/12 22:59:03 pbartok
78 // - Implemented method to get current mouse position
80 // Revision 1.10 2004/08/11 22:20:59 pbartok
83 // Revision 1.9 2004/08/11 19:19:44 pbartok
84 // - We had SetWindowPos and MoveWindow to set window positions and size,
85 // removed MoveWindow. We have GetWindowPos, so it made sense to keep
86 // SetWindowPos as matching counterpart
87 // - Added some X11 sanity checking
89 // Revision 1.8 2004/08/11 18:55:46 pbartok
90 // - Added method to calculate difference between decorated window and raw
93 // Revision 1.7 2004/08/10 17:39:22 pbartok
94 // - Added GetWindowPos method
96 // Revision 1.6 2004/08/09 20:55:59 pbartok
97 // - Removed Run method, was only required for initial development
99 // Revision 1.5 2004/08/09 20:51:25 pbartok
100 // - Implemented GrabWindow/ReleaseWindow methods to allow pointer capture
102 // Revision 1.4 2004/08/09 17:02:29 jackson
103 // Get default window properties from the theme
105 // Revision 1.3 2004/08/09 15:56:44 jackson
106 // Remove defaults, these are handled by the theme now.
108 // Revision 1.2 2004/08/04 20:11:24 pbartok
109 // - Added Invalidate handling
111 // Revision 1.1 2004/07/09 05:21:25 pbartok
112 // - Initial check-in
119 using System.Drawing;
120 using System.ComponentModel;
121 using System.Collections;
122 using System.Diagnostics;
123 using System.Runtime.InteropServices;
126 // Random architecture notes
130 // - set location/size
140 namespace System.Windows.Forms {
141 internal class XplatUI {
142 #region Local Variables
143 static XplatUIDriver driver;
144 static String default_class_name;
145 #endregion // Local Variables
150 static public Keys ModifierKeys {
152 return driver.ModifierKeys;
156 static public MouseButtons MouseButtons {
158 return driver.MouseButtons;
162 static public Point MousePosition {
164 return driver.MousePosition;
168 static public bool DropTarget {
170 return driver.DropTarget;
174 driver.DropTarget=value;
178 #endregion // Subclasses
180 #region Constructor & Destructor
182 // Don't forget to throw the mac in here somewhere, too
183 default_class_name="SWFClass";
185 if (Environment.OSVersion.Platform == (PlatformID)128) {
186 if (Environment.GetEnvironmentVariable ("MONO_MWF_USE_QUARTZ_BACKEND") != null)
187 driver=XplatUIOSX.GetInstance();
189 driver=XplatUIX11.GetInstance();
191 driver=XplatUIWin32.GetInstance();
194 Console.WriteLine("#region #line XplatUI Constructor called");
198 Console.WriteLine("XplatUI Destructor called");
200 #endregion // Constructor & Destructor
202 #region Public Static Properties
203 internal static string DefaultClassName {
205 return default_class_name;
209 default_class_name=value;
212 #endregion // Public Static Properties
214 internal static event EventHandler Idle {
216 driver.Idle += value;
219 driver.Idle -= value;
223 #region Public Static Methods
224 internal static void Exit() {
228 internal static void GetDisplaySize(out Size size) {
229 driver.GetDisplaySize(out size);
232 internal static void EnableThemes() {
233 driver.EnableThemes();
236 internal static bool Text(IntPtr hWnd, string text) {
237 return driver.Text(hWnd, text);
240 internal static bool GetText(IntPtr hWnd, out string text) {
241 return driver.GetText(hWnd, out text);
244 internal static bool SetVisible(IntPtr hWnd, bool visible) {
245 return driver.SetVisible(hWnd, visible);
248 internal static bool IsVisible(IntPtr hWnd) {
249 return driver.IsVisible(hWnd);
252 internal static IntPtr SetParent(IntPtr hWnd, IntPtr hParent) {
253 return driver.SetParent(hWnd, hParent);
256 internal static IntPtr GetParent(IntPtr hWnd) {
257 return driver.GetParent(hWnd);
260 internal static void Version() {
261 Console.WriteLine("Xplat version $revision: $");
264 internal static IntPtr CreateWindow(CreateParams cp) {
265 return driver.CreateWindow(cp);
268 internal static IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
269 return driver.CreateWindow(Parent, X, Y, Width, Height);
272 internal static void DestroyWindow(IntPtr handle) {
273 driver.DestroyWindow(handle);
276 internal static void RefreshWindow(IntPtr handle) {
277 driver.RefreshWindow(handle);
280 internal static void SetWindowBackground(IntPtr handle, Color color) {
281 driver.SetWindowBackground(handle, color);
284 internal static PaintEventArgs PaintEventStart(IntPtr handle) {
285 return driver.PaintEventStart(handle);
288 internal static void PaintEventEnd(IntPtr handle) {
289 driver.PaintEventEnd(handle);
292 internal static void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
293 driver.SetWindowPos(handle, x, y, width, height);
296 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) {
297 driver.GetWindowPos(handle, out x, out y, out width, out height, out client_width, out client_height);
300 internal static void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
301 driver.Invalidate(handle, rc, clear);
304 internal static void Activate(IntPtr handle) {
305 driver.Activate(handle);
308 internal static void EnableWindow(IntPtr handle, bool Enable) {
309 driver.EnableWindow(handle, Enable);
312 internal static void SetModal(IntPtr handle, bool Modal) {
313 driver.SetModal(handle, Modal);
316 internal static IntPtr DefWndProc(ref Message msg) {
317 return driver.DefWndProc(ref msg);
320 internal static void HandleException(Exception e) {
321 driver.HandleException(e);
324 internal static void DoEvents() {
328 internal static bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
329 return driver.PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
332 internal static bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
333 return driver.GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
336 internal static bool TranslateMessage(ref MSG msg) {
337 return driver.TranslateMessage(ref msg);
340 internal static IntPtr DispatchMessage(ref MSG msg) {
341 return driver.DispatchMessage(ref msg);
344 internal static void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
345 driver.GrabWindow(hWnd, ConfineToHwnd);
348 internal static void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
349 driver.GrabInfo(out hWnd, out GrabConfined, out GrabArea);
352 internal static void ReleaseWindow(IntPtr hWnd) {
353 driver.ReleaseWindow(hWnd);
356 internal static bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
357 return driver.SetZOrder(hWnd, AfterhWnd, Top, Bottom);
360 internal static bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
361 return driver.SetTopmost(hWnd, hWndOwner, Enabled);
364 internal static bool CalculateWindowRect(IntPtr hWnd, ref Rectangle ClientRect, int Style, bool HasMenu, out Rectangle WindowRect) {
365 return driver.CalculateWindowRect(hWnd, ref ClientRect, Style, HasMenu, out WindowRect);
368 internal static void SetCursorPos(IntPtr handle, int x, int y) {
369 driver.SetCursorPos(handle, x, y);
372 internal static void GetCursorPos(IntPtr handle, out int x, out int y) {
373 driver.GetCursorPos(handle, out x, out y);
376 internal static void ScreenToClient(IntPtr handle, ref int x, ref int y) {
377 driver.ScreenToClient (handle, ref x, ref y);
380 internal static void ClientToScreen(IntPtr handle, ref int x, ref int y) {
381 driver.ClientToScreen(handle, ref x, ref y);
384 internal static void SendAsyncMethod (AsyncMethodData data) {
385 driver.SendAsyncMethod (data);
388 internal static void CreateCaret(IntPtr hwnd, int width, int height) {
389 driver.CreateCaret(hwnd, width, height);
392 internal static void DestroyCaret(IntPtr hwnd) {
393 driver.DestroyCaret(hwnd);
396 internal static void SetCaretPos(IntPtr hwnd, int x, int y) {
397 driver.SetCaretPos(hwnd, x, y);
400 internal static void CaretVisible(IntPtr hwnd, bool visible) {
401 driver.CaretVisible(hwnd, visible);
404 internal static void SetTimer (Timer timer)
406 driver.SetTimer (timer);
409 internal static void KillTimer (Timer timer)
411 driver.KillTimer (timer);
414 internal static int KeyboardSpeed {
416 return driver.KeyboardSpeed;
420 internal static int KeyboardDelay {
422 return driver.KeyboardSpeed;
426 // Santa's little helper
427 internal static void Where() {
428 Console.WriteLine("Here: {0}", new StackTrace().ToString());
430 #endregion // Public Static Methods