Expose functionality to send async messages through the driver
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / XplatUI.cs
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:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
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.
19 //
20 // Copyright (c) 2004 Novell, Inc.
21 //
22 // Authors:
23 //      Peter Bartok    pbartok@novell.com
24 //
25 //
26 // $Revision: 1.15 $
27 // $Modtime: $
28 // $Log: XplatUI.cs,v $
29 // Revision 1.15  2004/08/20 19:14:35  jackson
30 // Expose functionality to send async messages through the driver
31 //
32 // Revision 1.14  2004/08/13 21:42:15  pbartok
33 // - Changed signature for GetCursorPos
34 //
35 // Revision 1.13  2004/08/13 19:00:15  jordi
36 // implements PointToClient (ScreenToClient)
37 //
38 // Revision 1.12  2004/08/13 18:53:14  pbartok
39 // - Changed GetWindowPos to also provide client area size
40 //
41 // Revision 1.11  2004/08/12 22:59:03  pbartok
42 // - Implemented method to get current mouse position
43 //
44 // Revision 1.10  2004/08/11 22:20:59  pbartok
45 // - Signature fixes
46 //
47 // Revision 1.9  2004/08/11 19:19:44  pbartok
48 // - We had SetWindowPos and MoveWindow to set window positions and size,
49 //   removed MoveWindow. We have GetWindowPos, so it made sense to keep
50 //   SetWindowPos as matching counterpart
51 // - Added some X11 sanity checking
52 //
53 // Revision 1.8  2004/08/11 18:55:46  pbartok
54 // - Added method to calculate difference between decorated window and raw
55 //   client area
56 //
57 // Revision 1.7  2004/08/10 17:39:22  pbartok
58 // - Added GetWindowPos method
59 //
60 // Revision 1.6  2004/08/09 20:55:59  pbartok
61 // - Removed Run method, was only required for initial development
62 //
63 // Revision 1.5  2004/08/09 20:51:25  pbartok
64 // - Implemented GrabWindow/ReleaseWindow methods to allow pointer capture
65 //
66 // Revision 1.4  2004/08/09 17:02:29  jackson
67 // Get default window properties from the theme
68 //
69 // Revision 1.3  2004/08/09 15:56:44  jackson
70 // Remove defaults, these are handled by the theme now.
71 //
72 // Revision 1.2  2004/08/04 20:11:24  pbartok
73 // - Added Invalidate handling
74 //
75 // Revision 1.1  2004/07/09 05:21:25  pbartok
76 // - Initial check-in
77 //
78 //
79
80 // NOT COMPLETE
81
82 using System;
83 using System.Drawing;
84 using System.ComponentModel;
85 using System.Collections;
86 using System.Diagnostics;
87 using System.Runtime.InteropServices;
88
89 //
90 // Random architecture notes
91 // We need
92 // * windows
93 //   - create
94 //   - set location/size
95 //   - define cursor
96 //   - destroy
97 //   - reparent?
98 //   - show/hide
99 // * Keyboard
100 // * Mouse
101 //
102
103 /// X11 Version
104 namespace System.Windows.Forms {
105         internal class XplatUI {
106                 #region Local Variables
107                 static XplatUIDriver            driver;
108                 static String                   default_class_name;
109                 #endregion      // Local Variables
110
111                 #region Subclasses
112
113                 public class State {
114                         static public Keys ModifierKeys {
115                                 get {
116                                         return driver.ModifierKeys;
117                                 }
118                         }
119
120                         static public MouseButtons MouseButtons {
121                                 get {
122                                         return driver.MouseButtons;
123                                 }
124                         }
125
126                         static public Point MousePosition {
127                                 get {
128                                         return driver.MousePosition;
129                                 }
130                         }
131
132                         static public bool DropTarget {
133                                 get {
134                                         return driver.DropTarget;
135                                 }
136
137                                 set {
138                                         driver.DropTarget=value;
139                                 }
140                         }
141                 }
142                 #endregion      // Subclasses
143
144                 #region Constructor & Destructor
145                 static XplatUI() {
146                         // Don't forget to throw the mac in here somewhere, too
147                         default_class_name="SWFClass";
148
149                         if (Environment.OSVersion.Platform == (PlatformID)128) {
150                                 driver=XplatUIX11.GetInstance();
151                         } else {
152                                 driver=XplatUIWin32.GetInstance();
153                         }
154
155                         Console.WriteLine("#region #line XplatUI Constructor called");
156                 }
157
158                 ~XplatUI() {
159                         Console.WriteLine("XplatUI Destructor called");
160                 }
161                 #endregion      // Constructor & Destructor
162
163                 #region Public Static Properties
164                 internal static string DefaultClassName {
165                         get {
166                                 return default_class_name;
167                         }
168
169                         set {
170                                 default_class_name=value;
171                         }
172                 }
173                 #endregion      // Public Static Properties
174
175                 #region Public Static Methods
176                 internal static void Exit() {
177                         driver.Exit();
178                 }
179
180                 internal static void EnableThemes() {
181                         driver.EnableThemes();
182                 }
183
184                 internal static bool Text(IntPtr hWnd, string text) {
185                         return driver.Text(hWnd, text);
186                 }
187
188                 internal static bool SetVisible(IntPtr hWnd, bool visible) {
189                         return driver.SetVisible(hWnd, visible);
190                 }
191
192                 internal static bool IsVisible(IntPtr hWnd) {
193                         return driver.IsVisible(hWnd);
194                 }
195
196                 internal static IntPtr SetParent(IntPtr hWnd, IntPtr hParent) {
197                         return driver.SetParent(hWnd, hParent);
198                 }
199
200                 internal static IntPtr GetParent(IntPtr hWnd) {
201                         return driver.GetParent(hWnd);
202                 }
203
204                 internal static void Version() {
205                         Console.WriteLine("Xplat version $revision: $");
206                 }
207
208                 internal static IntPtr CreateWindow(CreateParams cp) {
209                         return driver.CreateWindow(cp);
210                 }
211
212                 internal static IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
213                         return driver.CreateWindow(Parent, X, Y, Width, Height);
214                 }
215
216                 internal static void DestroyWindow(IntPtr handle) {
217                         driver.DestroyWindow(handle);
218                 }
219
220                 internal static void RefreshWindow(IntPtr handle) {
221                         driver.RefreshWindow(handle);
222                 }
223
224                 internal static PaintEventArgs PaintEventStart(IntPtr handle) {
225                         return driver.PaintEventStart(handle);
226                 }
227
228                 internal static void PaintEventEnd(IntPtr handle) {
229                         driver.PaintEventEnd(handle);
230                 }
231
232                 internal static void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
233                         driver.SetWindowPos(handle, x, y, width, height);
234                 }
235
236                 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) {
237                         driver.GetWindowPos(handle, out x, out y, out width, out height, out client_width, out client_height);
238                 }
239
240                 internal static void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
241                         driver.Invalidate(handle, rc, clear);
242                 }
243
244                 internal static void Activate(IntPtr handle) {
245                         driver.Activate(handle);
246                 }
247
248                 internal static IntPtr DefWndProc(ref Message msg) {
249                         return driver.DefWndProc(ref msg);
250                 }
251
252                 internal static void HandleException(Exception e) {
253                         driver.HandleException(e);
254                 }
255
256                 internal static void DoEvents() {
257                         driver.DoEvents();
258                 }
259
260                 internal static bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
261                         return driver.PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
262                 }
263
264                 internal static bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
265                         return driver.GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
266                 }
267
268                 internal static bool TranslateMessage(ref MSG msg) {
269                         return driver.TranslateMessage(ref msg);
270                 }
271
272                 internal static bool DispatchMessage(ref MSG msg) {
273                         return driver.DispatchMessage(ref msg);
274                 }
275
276                 internal static void GrabWindow(IntPtr hWnd) {
277                         driver.GrabWindow(hWnd);
278                 }
279
280                 internal static void ReleaseWindow(IntPtr hWnd) {
281                         driver.ReleaseWindow(hWnd);
282                 }
283
284                 internal static bool CalculateWindowRect(IntPtr hWnd, ref Rectangle ClientRect, int Style, bool HasMenu, out Rectangle WindowRect) {
285                         return driver.CalculateWindowRect(hWnd, ref ClientRect, Style, HasMenu, out WindowRect);
286                 }
287
288                 internal static void GetCursorPos(IntPtr handle, out int x, out int y) {
289                         driver.GetCursorPos(handle, out x, out y);
290                 }
291
292                 internal static void ScreenToClient(IntPtr handle, ref int x, ref int y) {
293                         driver.ScreenToClient (handle, ref x, ref y);
294                 }
295
296                 internal static void SendAsyncMethod (AsyncMethodData data) {
297                         driver.SendAsyncMethod (data);
298                 }
299
300                 // Santa's little helper
301                 internal static void Where() {
302                         Console.WriteLine("Here: {0}", new StackTrace().ToString());
303                 }
304                 #endregion      // Public Static Methods
305
306         }
307 }