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 driver
=XplatUIX11
.GetInstance();
188 driver
=XplatUIWin32
.GetInstance();
191 Console
.WriteLine("#region #line XplatUI Constructor called");
195 Console
.WriteLine("XplatUI Destructor called");
197 #endregion // Constructor & Destructor
199 #region Public Static Properties
200 internal static string DefaultClassName
{
202 return default_class_name
;
206 default_class_name
=value;
209 #endregion // Public Static Properties
211 internal static event EventHandler Idle
{
213 driver
.Idle
+= value;
216 driver
.Idle
-= value;
220 #region Public Static Methods
221 internal static void Exit() {
225 internal static void GetDisplaySize(out Size size
) {
226 driver
.GetDisplaySize(out size
);
229 internal static void EnableThemes() {
230 driver
.EnableThemes();
233 internal static bool Text(IntPtr hWnd
, string text
) {
234 return driver
.Text(hWnd
, text
);
237 internal static bool GetText(IntPtr hWnd
, out string text
) {
238 return driver
.GetText(hWnd
, out text
);
241 internal static bool SetVisible(IntPtr hWnd
, bool visible
) {
242 return driver
.SetVisible(hWnd
, visible
);
245 internal static bool IsVisible(IntPtr hWnd
) {
246 return driver
.IsVisible(hWnd
);
249 internal static IntPtr
SetParent(IntPtr hWnd
, IntPtr hParent
) {
250 return driver
.SetParent(hWnd
, hParent
);
253 internal static IntPtr
GetParent(IntPtr hWnd
) {
254 return driver
.GetParent(hWnd
);
257 internal static void Version() {
258 Console
.WriteLine("Xplat version $revision: $");
261 internal static IntPtr
CreateWindow(CreateParams cp
) {
262 return driver
.CreateWindow(cp
);
265 internal static IntPtr
CreateWindow(IntPtr Parent
, int X
, int Y
, int Width
, int Height
) {
266 return driver
.CreateWindow(Parent
, X
, Y
, Width
, Height
);
269 internal static void DestroyWindow(IntPtr handle
) {
270 driver
.DestroyWindow(handle
);
273 internal static void RefreshWindow(IntPtr handle
) {
274 driver
.RefreshWindow(handle
);
277 internal static void SetWindowBackground(IntPtr handle
, Color color
) {
278 driver
.SetWindowBackground(handle
, color
);
281 internal static PaintEventArgs
PaintEventStart(IntPtr handle
) {
282 return driver
.PaintEventStart(handle
);
285 internal static void PaintEventEnd(IntPtr handle
) {
286 driver
.PaintEventEnd(handle
);
289 internal static void SetWindowPos(IntPtr handle
, int x
, int y
, int width
, int height
) {
290 driver
.SetWindowPos(handle
, x
, y
, width
, height
);
293 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
) {
294 driver
.GetWindowPos(handle
, out x
, out y
, out width
, out height
, out client_width
, out client_height
);
297 internal static void Invalidate(IntPtr handle
, Rectangle rc
, bool clear
) {
298 driver
.Invalidate(handle
, rc
, clear
);
301 internal static void Activate(IntPtr handle
) {
302 driver
.Activate(handle
);
305 internal static void EnableWindow(IntPtr handle
, bool Enable
) {
306 driver
.EnableWindow(handle
, Enable
);
309 internal static void SetModal(IntPtr handle
, bool Modal
) {
310 driver
.SetModal(handle
, Modal
);
313 internal static IntPtr
DefWndProc(ref Message msg
) {
314 return driver
.DefWndProc(ref msg
);
317 internal static void HandleException(Exception e
) {
318 driver
.HandleException(e
);
321 internal static void DoEvents() {
325 internal static bool PeekMessage(ref MSG msg
, IntPtr hWnd
, int wFilterMin
, int wFilterMax
, uint flags
) {
326 return driver
.PeekMessage(ref msg
, hWnd
, wFilterMin
, wFilterMax
, flags
);
329 internal static bool GetMessage(ref MSG msg
, IntPtr hWnd
, int wFilterMin
, int wFilterMax
) {
330 return driver
.GetMessage(ref msg
, hWnd
, wFilterMin
, wFilterMax
);
333 internal static bool TranslateMessage(ref MSG msg
) {
334 return driver
.TranslateMessage(ref msg
);
337 internal static bool DispatchMessage(ref MSG msg
) {
338 return driver
.DispatchMessage(ref msg
);
341 internal static void GrabWindow(IntPtr hWnd
, IntPtr ConfineToHwnd
) {
342 driver
.GrabWindow(hWnd
, ConfineToHwnd
);
345 internal static void GrabInfo(out IntPtr hWnd
, out bool GrabConfined
, out Rectangle GrabArea
) {
346 driver
.GrabInfo(out hWnd
, out GrabConfined
, out GrabArea
);
349 internal static void ReleaseWindow(IntPtr hWnd
) {
350 driver
.ReleaseWindow(hWnd
);
353 internal static bool SetZOrder(IntPtr hWnd
, IntPtr AfterhWnd
, bool Top
, bool Bottom
) {
354 return driver
.SetZOrder(hWnd
, AfterhWnd
, Top
, Bottom
);
357 internal static bool SetTopmost(IntPtr hWnd
, IntPtr hWndOwner
, bool Enabled
) {
358 return driver
.SetTopmost(hWnd
, hWndOwner
, Enabled
);
361 internal static bool CalculateWindowRect(IntPtr hWnd
, ref Rectangle ClientRect
, int Style
, bool HasMenu
, out Rectangle WindowRect
) {
362 return driver
.CalculateWindowRect(hWnd
, ref ClientRect
, Style
, HasMenu
, out WindowRect
);
365 internal static void SetCursorPos(IntPtr handle
, int x
, int y
) {
366 driver
.SetCursorPos(handle
, x
, y
);
369 internal static void GetCursorPos(IntPtr handle
, out int x
, out int y
) {
370 driver
.GetCursorPos(handle
, out x
, out y
);
373 internal static void ScreenToClient(IntPtr handle
, ref int x
, ref int y
) {
374 driver
.ScreenToClient (handle
, ref x
, ref y
);
377 internal static void ClientToScreen(IntPtr handle
, ref int x
, ref int y
) {
378 driver
.ClientToScreen(handle
, ref x
, ref y
);
381 internal static void SendAsyncMethod (AsyncMethodData data
) {
382 driver
.SendAsyncMethod (data
);
385 internal static void SetTimer (Timer timer
)
387 driver
.SetTimer (timer
);
390 internal static void KillTimer (Timer timer
)
392 driver
.KillTimer (timer
);
395 // Santa's little helper
396 internal static void Where() {
397 Console
.WriteLine("Here: {0}", new StackTrace().ToString());
399 #endregion // Public Static Methods