* Mono.Posix.dll.sources: Rename Mono.Posix to Mono.Unix.
[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.26 $
27 // $Modtime: $
28 // $Log: XplatUI.cs,v $
29 // Revision 1.26  2004/11/08 20:53:03  pbartok
30 // - Added argument to SetTopmost
31 //
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
36 //
37 // Revision 1.24  2004/10/02 19:07:36  pbartok
38 // - Added ClientToScreen coordinate translation method
39 //
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
42 //
43 // Revision 1.22  2004/09/13 21:18:32  pbartok
44 // - Added Z-Ordering methods
45 //
46 // Revision 1.21  2004/09/11 00:57:35  pbartok
47 // - Added method to retrieve text from window
48 //
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.
51 //
52 // Revision 1.19  2004/08/23 19:39:30  pbartok
53 // - Added method to move mouse cursor
54 //
55 // Revision 1.18  2004/08/21 20:51:27  pbartok
56 // - Added method to get default display size
57 //
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
61 //
62 // Revision 1.16  2004/08/20 20:03:20  pbartok
63 // - Added method for setting the window background
64 //
65 // Revision 1.15  2004/08/20 19:14:35  jackson
66 // Expose functionality to send async messages through the driver
67 //
68 // Revision 1.14  2004/08/13 21:42:15  pbartok
69 // - Changed signature for GetCursorPos
70 //
71 // Revision 1.13  2004/08/13 19:00:15  jordi
72 // implements PointToClient (ScreenToClient)
73 //
74 // Revision 1.12  2004/08/13 18:53:14  pbartok
75 // - Changed GetWindowPos to also provide client area size
76 //
77 // Revision 1.11  2004/08/12 22:59:03  pbartok
78 // - Implemented method to get current mouse position
79 //
80 // Revision 1.10  2004/08/11 22:20:59  pbartok
81 // - Signature fixes
82 //
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
88 //
89 // Revision 1.8  2004/08/11 18:55:46  pbartok
90 // - Added method to calculate difference between decorated window and raw
91 //   client area
92 //
93 // Revision 1.7  2004/08/10 17:39:22  pbartok
94 // - Added GetWindowPos method
95 //
96 // Revision 1.6  2004/08/09 20:55:59  pbartok
97 // - Removed Run method, was only required for initial development
98 //
99 // Revision 1.5  2004/08/09 20:51:25  pbartok
100 // - Implemented GrabWindow/ReleaseWindow methods to allow pointer capture
101 //
102 // Revision 1.4  2004/08/09 17:02:29  jackson
103 // Get default window properties from the theme
104 //
105 // Revision 1.3  2004/08/09 15:56:44  jackson
106 // Remove defaults, these are handled by the theme now.
107 //
108 // Revision 1.2  2004/08/04 20:11:24  pbartok
109 // - Added Invalidate handling
110 //
111 // Revision 1.1  2004/07/09 05:21:25  pbartok
112 // - Initial check-in
113 //
114 //
115
116 // NOT COMPLETE
117
118 using System;
119 using System.Drawing;
120 using System.ComponentModel;
121 using System.Collections;
122 using System.Diagnostics;
123 using System.Runtime.InteropServices;
124
125 //
126 // Random architecture notes
127 // We need
128 // * windows
129 //   - create
130 //   - set location/size
131 //   - define cursor
132 //   - destroy
133 //   - reparent?
134 //   - show/hide
135 // * Keyboard
136 // * Mouse
137 //
138
139 /// X11 Version
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
146
147                 #region Subclasses
148
149                 public class State {
150                         static public Keys ModifierKeys {
151                                 get {
152                                         return driver.ModifierKeys;
153                                 }
154                         }
155
156                         static public MouseButtons MouseButtons {
157                                 get {
158                                         return driver.MouseButtons;
159                                 }
160                         }
161
162                         static public Point MousePosition {
163                                 get {
164                                         return driver.MousePosition;
165                                 }
166                         }
167
168                         static public bool DropTarget {
169                                 get {
170                                         return driver.DropTarget;
171                                 }
172
173                                 set {
174                                         driver.DropTarget=value;
175                                 }
176                         }
177                 }
178                 #endregion      // Subclasses
179
180                 #region Constructor & Destructor
181                 static XplatUI() {
182                         // Don't forget to throw the mac in here somewhere, too
183                         default_class_name="SWFClass";
184
185                         if (Environment.OSVersion.Platform == (PlatformID)128) {
186                                 driver=XplatUIX11.GetInstance();
187                         } else {
188                                 driver=XplatUIWin32.GetInstance();
189                         }
190
191                         Console.WriteLine("#region #line XplatUI Constructor called");
192                 }
193
194                 ~XplatUI() {
195                         Console.WriteLine("XplatUI Destructor called");
196                 }
197                 #endregion      // Constructor & Destructor
198
199                 #region Public Static Properties
200                 internal static string DefaultClassName {
201                         get {
202                                 return default_class_name;
203                         }
204
205                         set {
206                                 default_class_name=value;
207                         }
208                 }
209                 #endregion      // Public Static Properties
210
211                 internal static event EventHandler Idle {
212                         add {
213                                 driver.Idle += value;
214                         }
215                         remove {
216                                 driver.Idle -= value;
217                         }
218                 }
219                 
220                 #region Public Static Methods
221                 internal static void Exit() {
222                         driver.Exit();
223                 }
224
225                 internal static void GetDisplaySize(out Size size) {
226                         driver.GetDisplaySize(out size);
227                 }
228
229                 internal static void EnableThemes() {
230                         driver.EnableThemes();
231                 }
232
233                 internal static bool Text(IntPtr hWnd, string text) {
234                         return driver.Text(hWnd, text);
235                 }
236
237                 internal static bool GetText(IntPtr hWnd, out string text) {
238                         return driver.GetText(hWnd, out text);
239                 }
240
241                 internal static bool SetVisible(IntPtr hWnd, bool visible) {
242                         return driver.SetVisible(hWnd, visible);
243                 }
244
245                 internal static bool IsVisible(IntPtr hWnd) {
246                         return driver.IsVisible(hWnd);
247                 }
248
249                 internal static IntPtr SetParent(IntPtr hWnd, IntPtr hParent) {
250                         return driver.SetParent(hWnd, hParent);
251                 }
252
253                 internal static IntPtr GetParent(IntPtr hWnd) {
254                         return driver.GetParent(hWnd);
255                 }
256
257                 internal static void Version() {
258                         Console.WriteLine("Xplat version $revision: $");
259                 }
260
261                 internal static IntPtr CreateWindow(CreateParams cp) {
262                         return driver.CreateWindow(cp);
263                 }
264
265                 internal static IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
266                         return driver.CreateWindow(Parent, X, Y, Width, Height);
267                 }
268
269                 internal static void DestroyWindow(IntPtr handle) {
270                         driver.DestroyWindow(handle);
271                 }
272
273                 internal static void RefreshWindow(IntPtr handle) {
274                         driver.RefreshWindow(handle);
275                 }
276
277                 internal static void SetWindowBackground(IntPtr handle, Color color) {
278                         driver.SetWindowBackground(handle, color);
279                 }
280                         
281                 internal static PaintEventArgs PaintEventStart(IntPtr handle) {
282                         return driver.PaintEventStart(handle);
283                 }
284
285                 internal static void PaintEventEnd(IntPtr handle) {
286                         driver.PaintEventEnd(handle);
287                 }
288
289                 internal static void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
290                         driver.SetWindowPos(handle, x, y, width, height);
291                 }
292
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);
295                 }
296
297                 internal static void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
298                         driver.Invalidate(handle, rc, clear);
299                 }
300
301                 internal static void Activate(IntPtr handle) {
302                         driver.Activate(handle);
303                 }
304
305                 internal static void EnableWindow(IntPtr handle, bool Enable) {
306                         driver.EnableWindow(handle, Enable);
307                 }
308
309                 internal static void SetModal(IntPtr handle, bool Modal) {
310                         driver.SetModal(handle, Modal);
311                 }
312
313                 internal static IntPtr DefWndProc(ref Message msg) {
314                         return driver.DefWndProc(ref msg);
315                 }
316
317                 internal static void HandleException(Exception e) {
318                         driver.HandleException(e);
319                 }
320
321                 internal static void DoEvents() {
322                         driver.DoEvents();
323                 }
324
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);
327                 }
328
329                 internal static bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
330                         return driver.GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
331                 }
332
333                 internal static bool TranslateMessage(ref MSG msg) {
334                         return driver.TranslateMessage(ref msg);
335                 }
336
337                 internal static bool DispatchMessage(ref MSG msg) {
338                         return driver.DispatchMessage(ref msg);
339                 }
340
341                 internal static void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
342                         driver.GrabWindow(hWnd, ConfineToHwnd);
343                 }
344
345                 internal static void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
346                         driver.GrabInfo(out hWnd, out GrabConfined, out GrabArea);
347                 }
348
349                 internal static void ReleaseWindow(IntPtr hWnd) {
350                         driver.ReleaseWindow(hWnd);
351                 }
352
353                 internal static bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
354                         return driver.SetZOrder(hWnd, AfterhWnd, Top, Bottom);
355                 }
356
357                 internal static bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
358                         return driver.SetTopmost(hWnd, hWndOwner, Enabled);
359                 }
360
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);
363                 }
364
365                 internal static void SetCursorPos(IntPtr handle, int x, int y) {
366                         driver.SetCursorPos(handle, x, y);
367                 }
368
369                 internal static void GetCursorPos(IntPtr handle, out int x, out int y) {
370                         driver.GetCursorPos(handle, out x, out y);
371                 }
372
373                 internal static void ScreenToClient(IntPtr handle, ref int x, ref int y) {
374                         driver.ScreenToClient (handle, ref x, ref y);
375                 }
376
377                 internal static void ClientToScreen(IntPtr handle, ref int x, ref int y) {
378                         driver.ClientToScreen(handle, ref x, ref y);
379                 }
380
381                 internal static void SendAsyncMethod (AsyncMethodData data) {
382                         driver.SendAsyncMethod (data);
383                 }
384
385                 internal static void SetTimer (Timer timer)
386                 {
387                         driver.SetTimer (timer);
388                 }
389
390                 internal static void KillTimer (Timer timer)
391                 {
392                         driver.KillTimer (timer);
393                 }
394
395                 // Santa's little helper
396                 internal static void Where() {
397                         Console.WriteLine("Here: {0}", new StackTrace().ToString());
398                 }
399                 #endregion      // Public Static Methods
400
401         }
402 }