- Implemented SystemInformation class
[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 // NOT COMPLETE
27
28 using System;
29 using System.Drawing;
30 using System.ComponentModel;
31 using System.Collections;
32 using System.Diagnostics;
33 using System.Runtime.InteropServices;
34
35
36 /// X11 Version
37 namespace System.Windows.Forms {
38         internal class XplatUI {
39                 #region Local Variables
40                 static XplatUIDriver            driver;
41                 static String                   default_class_name;
42                 #endregion      // Local Variables
43
44                 #region Subclasses
45
46                 public class State {
47                         static public Keys ModifierKeys {
48                                 get {
49                                         return driver.ModifierKeys;
50                                 }
51                         }
52
53                         static public MouseButtons MouseButtons {
54                                 get {
55                                         return driver.MouseButtons;
56                                 }
57                         }
58
59                         static public Point MousePosition {
60                                 get {
61                                         return driver.MousePosition;
62                                 }
63                         }
64
65                         static public bool DropTarget {
66                                 get {
67                                         return driver.DropTarget;
68                                 }
69
70                                 set {
71                                         driver.DropTarget=value;
72                                 }
73                         }
74
75                 }
76                 #endregion      // Subclasses
77
78                 #region Constructor & Destructor
79                 static XplatUI() {
80                         // Don't forget to throw the mac in here somewhere, too
81                         default_class_name="SWFClass";
82
83                         if (Environment.OSVersion.Platform == (PlatformID)128) {
84                                 if (Environment.GetEnvironmentVariable ("MONO_MWF_USE_QUARTZ_BACKEND") != null)
85                                         driver=XplatUIOSX.GetInstance();
86                                 else
87                                         driver=XplatUIX11.GetInstance();
88                         } else {
89                                 driver=XplatUIWin32.GetInstance();
90                         }
91
92                         Console.WriteLine("#region #line XplatUI Constructor called");
93                 }
94
95                 ~XplatUI() {
96                         Console.WriteLine("XplatUI Destructor called");
97                 }
98                 #endregion      // Constructor & Destructor
99
100                 #region Public Static Properties
101                 internal static string DefaultClassName {
102                         get {
103                                 return default_class_name;
104                         }
105
106                         set {
107                                 default_class_name=value;
108                         }
109                 }
110
111                 static public Size CursorSize {
112                         get {
113                                 return driver.CursorSize;
114                         }
115                 }
116
117                 static public bool DragFullWindows {
118                         get {
119                                 return driver.DragFullWindows;
120                         }
121                 }
122
123                 static public Size DragSize {
124                         get {
125                                 return driver.DragSize;
126                         }
127                 }
128
129                 static public Size IconSize {
130                         get {
131                                 return driver.IconSize;
132                         }
133                 }
134
135                 static public Size MaxWindowTrackSize {
136                         get {
137                                 return driver.MaxWindowTrackSize;
138                         }
139                 }
140
141                 static public Size MinimizedWindowSize {
142                         get {
143                                 return driver.MinimizedWindowSize;
144                         }
145                 }
146
147                 static public Size MinimizedWindowSpacingSize {
148                         get {
149                                 return driver.MinimizedWindowSpacingSize;
150                         }
151                 }
152
153                 static public Size MinimumWindowSize {
154                         get {
155                                 return driver.MinimumWindowSize;
156                         }
157                 }
158
159                 static public Size MinWindowTrackSize {
160                         get {
161                                 return driver.MinWindowTrackSize;
162                         }
163                 }
164
165                 static public Size SmallIconSize {
166                         get {
167                                 return driver.SmallIconSize;
168                         }
169                 }
170
171                 static public int MouseButtonCount {
172                         get {
173                                 return driver.MouseButtonCount;
174                         }
175                 }
176
177                 static public bool MouseButtonsSwapped {
178                         get {
179                                 return driver.MouseButtonsSwapped;
180                         }
181                 }
182
183                 static public bool MouseWheelPresent {
184                         get {
185                                 return driver.MouseWheelPresent;
186                         }
187                 }
188
189                 static public Rectangle VirtualScreen {
190                         get {
191                                 return driver.VirtualScreen;
192                         }
193                 }
194
195                 static public Rectangle WorkingArea {
196                         get {
197                                 return driver.WorkingArea;
198                         }
199                 }
200                 #endregion      // Public Static Properties
201
202                 internal static event EventHandler Idle {
203                         add {
204                                 driver.Idle += value;
205                         }
206                         remove {
207                                 driver.Idle -= value;
208                         }
209                 }
210                 
211                 #region Public Static Methods
212                 internal static void Exit() {
213                         driver.Exit();
214                 }
215
216                 internal static void GetDisplaySize(out Size size) {
217                         driver.GetDisplaySize(out size);
218                 }
219
220                 internal static void EnableThemes() {
221                         driver.EnableThemes();
222                 }
223
224                 internal static bool Text(IntPtr hWnd, string text) {
225                         return driver.Text(hWnd, text);
226                 }
227
228                 internal static bool GetText(IntPtr hWnd, out string text) {
229                         return driver.GetText(hWnd, out text);
230                 }
231
232                 internal static bool SetVisible(IntPtr hWnd, bool visible) {
233                         return driver.SetVisible(hWnd, visible);
234                 }
235
236                 internal static bool IsVisible(IntPtr hWnd) {
237                         return driver.IsVisible(hWnd);
238                 }
239
240                 internal static IntPtr SetParent(IntPtr hWnd, IntPtr hParent) {
241                         return driver.SetParent(hWnd, hParent);
242                 }
243
244                 internal static IntPtr GetParent(IntPtr hWnd) {
245                         return driver.GetParent(hWnd);
246                 }
247
248                 internal static void Version() {
249                         Console.WriteLine("Xplat version $revision: $");
250                 }
251
252                 internal static IntPtr CreateWindow(CreateParams cp) {
253                         return driver.CreateWindow(cp);
254                 }
255
256                 internal static IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
257                         return driver.CreateWindow(Parent, X, Y, Width, Height);
258                 }
259
260                 internal static void DestroyWindow(IntPtr handle) {
261                         driver.DestroyWindow(handle);
262                 }
263
264                 internal static FormWindowState GetWindowState(IntPtr handle) {
265                         return driver.GetWindowState(handle);
266                 }
267
268                 internal static void SetWindowState(IntPtr handle, FormWindowState state) {
269                         driver.SetWindowState(handle, state);
270                 }
271
272                 internal static void SetWindowStyle(IntPtr handle, CreateParams cp) {
273                         driver.SetWindowStyle(handle, cp);
274                 }
275
276                 internal static void UpdateWindow(IntPtr handle) {
277                         driver.UpdateWindow(handle);
278                 }
279
280                 internal static void SetWindowBackground(IntPtr handle, Color color) {
281                         driver.SetWindowBackground(handle, color);
282                 }
283                         
284                 internal static PaintEventArgs PaintEventStart(IntPtr handle) {
285                         return driver.PaintEventStart(handle);
286                 }
287
288                 internal static void PaintEventEnd(IntPtr handle) {
289                         driver.PaintEventEnd(handle);
290                 }
291
292                 internal static void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
293                         driver.SetWindowPos(handle, x, y, width, height);
294                 }
295
296                 internal static void GetWindowPos(IntPtr handle, bool is_toplevel, out int x, out int y, out int width, out int height, out int client_width, out int client_height) {
297                         driver.GetWindowPos(handle, is_toplevel, out x, out y, out width, out height, out client_width, out client_height);
298                 }
299
300                 internal static void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
301                         driver.Invalidate(handle, rc, clear);
302                 }
303
304                 internal static void Activate(IntPtr handle) {
305                         driver.Activate(handle);
306                 }
307
308                 internal static void EnableWindow(IntPtr handle, bool Enable) {
309                         driver.EnableWindow(handle, Enable);
310                 }
311
312                 internal static void SetModal(IntPtr handle, bool Modal) {
313                         driver.SetModal(handle, Modal);
314                 }
315
316                 internal static IntPtr DefWndProc(ref Message msg) {
317                         return driver.DefWndProc(ref msg);
318                 }
319
320                 internal static void HandleException(Exception e) {
321                         driver.HandleException(e);
322                 }
323
324                 internal static void DoEvents() {
325                         driver.DoEvents();
326                 }
327
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);
330                 }
331
332                 internal static bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
333                         return driver.GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
334                 }
335
336                 internal static bool TranslateMessage(ref MSG msg) {
337                         return driver.TranslateMessage(ref msg);
338                 }
339
340                 internal static IntPtr DispatchMessage(ref MSG msg) {
341                         return driver.DispatchMessage(ref msg);
342                 }
343
344                 internal static void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
345                         driver.GrabWindow(hWnd, ConfineToHwnd);
346                 }
347
348                 internal static void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
349                         driver.GrabInfo(out hWnd, out GrabConfined, out GrabArea);
350                 }
351
352                 internal static void ReleaseWindow(IntPtr hWnd) {
353                         driver.ReleaseWindow(hWnd);
354                 }
355
356                 internal static bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
357                         return driver.SetZOrder(hWnd, AfterhWnd, Top, Bottom);
358                 }
359
360                 internal static bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
361                         return driver.SetTopmost(hWnd, hWndOwner, Enabled);
362                 }
363
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);
366                 }
367
368                 internal static void SetCursor(IntPtr hwnd, IntPtr cursor) {
369                         driver.SetCursor(hwnd, cursor);
370                 }
371
372                 internal static void ShowCursor(bool show) {
373                         driver.ShowCursor(show);
374                 }
375
376                 internal static void OverrideCursor(IntPtr cursor) {
377                         driver.OverrideCursor(cursor);
378                 }
379
380                 internal static IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
381                         return driver.DefineCursor(bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
382                 }
383
384                 internal static IntPtr DefineStdCursor(StdCursor id) {
385                         return driver.DefineStdCursor(id);
386                 }
387
388                 internal static void DestroyCursor(IntPtr cursor) {
389                         driver.DestroyCursor(cursor);
390                 }
391
392                 internal static void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
393                         driver.GetCursorInfo(cursor, out width, out height, out hotspot_x, out hotspot_y);
394                 }
395
396                 internal static void SetCursorPos(IntPtr handle, int x, int y) {
397                         driver.SetCursorPos(handle, x, y);
398                 }
399
400                 internal static void GetCursorPos(IntPtr handle, out int x, out int y) {
401                         driver.GetCursorPos(handle, out x, out y);
402                 }
403
404                 internal static void ScreenToClient(IntPtr handle, ref int x, ref int y) {
405                         driver.ScreenToClient (handle, ref x, ref y);
406                 }
407
408                 internal static void ClientToScreen(IntPtr handle, ref int x, ref int y) {
409                         driver.ClientToScreen(handle, ref x, ref y);
410                 }
411
412                 internal static void SendAsyncMethod (AsyncMethodData data) {
413                         driver.SendAsyncMethod (data);
414                 }
415
416                 internal static void CreateCaret(IntPtr hwnd, int width, int height) {
417                         driver.CreateCaret(hwnd, width, height);
418                 }
419
420                 internal static void DestroyCaret(IntPtr hwnd) {
421                         driver.DestroyCaret(hwnd);
422                 }
423
424                 internal static void SetCaretPos(IntPtr hwnd, int x, int y) {
425                         driver.SetCaretPos(hwnd, x, y);
426                 }
427
428                 internal static void CaretVisible(IntPtr hwnd, bool visible) {
429                         driver.CaretVisible(hwnd, visible);
430                 }
431
432                 internal static void SetFocus(IntPtr hwnd) {
433                         driver.SetFocus(hwnd);
434                 }
435
436                 internal static IntPtr GetActive() {
437                         return driver.GetActive();
438                 }
439
440                 internal static bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
441                         return driver.GetFontMetrics(g, font, out ascent, out descent);
442                 }
443                         
444                 internal static void SetTimer (Timer timer)
445                 {
446                         driver.SetTimer (timer);
447                 }
448
449                 internal static void KillTimer (Timer timer)
450                 {
451                         driver.KillTimer (timer);
452                 }
453
454                 internal static int KeyboardSpeed {
455                         get {
456                                 return driver.KeyboardSpeed;
457                         }
458                 }
459
460                 internal static int KeyboardDelay {
461                         get {
462                                 return driver.KeyboardSpeed;
463                         }
464                 }
465
466                 internal static void ScrollWindow(IntPtr hwnd, Rectangle rectangle, int XAmount, int YAmount, bool clear) {
467                         driver.ScrollWindow(hwnd, rectangle, XAmount, YAmount, clear);
468                 }
469
470                 internal static void ScrollWindow(IntPtr hwnd, int XAmount, int YAmount, bool clear) {
471                         driver.ScrollWindow(hwnd, XAmount, YAmount, clear);
472                 }
473
474                 internal static bool SystrayAdd(IntPtr hwnd, string tip, Icon icon, out ToolTip tt) {
475                         return driver.SystrayAdd(hwnd, tip, icon, out tt);
476                 }
477
478                 internal static void SystrayChange(IntPtr hwnd, string tip, Icon icon, ref ToolTip tt) {
479                         driver.SystrayChange(hwnd, tip, icon, ref tt);
480                 }
481
482                 internal static void SystrayRemove(IntPtr hwnd, ref ToolTip tt) {
483                         driver.SystrayRemove(hwnd, ref tt);
484                 }
485
486
487                 // Santa's little helper
488                 internal static void Where() {
489                         Console.WriteLine("Here: {0}", new StackTrace().ToString());
490                 }
491                 #endregion      // Public Static Methods
492
493         }
494 }