- Implemented ClientSize property
[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 // Random architecture notes
37 // We need
38 // * windows
39 //   - create
40 //   - set location/size
41 //   - define cursor
42 //   - destroy
43 //   - reparent?
44 //   - show/hide
45 // * Keyboard
46 // * Mouse
47 //
48
49 /// X11 Version
50 namespace System.Windows.Forms {
51         internal class XplatUI {
52                 #region Local Variables
53                 static XplatUIDriver            driver;
54                 static String                   default_class_name;
55                 #endregion      // Local Variables
56
57                 #region Subclasses
58
59                 public class State {
60                         static public Keys ModifierKeys {
61                                 get {
62                                         return driver.ModifierKeys;
63                                 }
64                         }
65
66                         static public MouseButtons MouseButtons {
67                                 get {
68                                         return driver.MouseButtons;
69                                 }
70                         }
71
72                         static public Point MousePosition {
73                                 get {
74                                         return driver.MousePosition;
75                                 }
76                         }
77
78                         static public bool DropTarget {
79                                 get {
80                                         return driver.DropTarget;
81                                 }
82
83                                 set {
84                                         driver.DropTarget=value;
85                                 }
86                         }
87                 }
88                 #endregion      // Subclasses
89
90                 #region Constructor & Destructor
91                 static XplatUI() {
92                         // Don't forget to throw the mac in here somewhere, too
93                         default_class_name="SWFClass";
94
95                         if (Environment.OSVersion.Platform == (PlatformID)128) {
96                                 if (Environment.GetEnvironmentVariable ("MONO_MWF_USE_QUARTZ_BACKEND") != null)
97                                         driver=XplatUIOSX.GetInstance();
98                                 else
99                                         driver=XplatUIX11.GetInstance();
100                         } else {
101                                 driver=XplatUIWin32.GetInstance();
102                         }
103
104                         Console.WriteLine("#region #line XplatUI Constructor called");
105                 }
106
107                 ~XplatUI() {
108                         Console.WriteLine("XplatUI Destructor called");
109                 }
110                 #endregion      // Constructor & Destructor
111
112                 #region Public Static Properties
113                 internal static string DefaultClassName {
114                         get {
115                                 return default_class_name;
116                         }
117
118                         set {
119                                 default_class_name=value;
120                         }
121                 }
122                 #endregion      // Public Static Properties
123
124                 internal static event EventHandler Idle {
125                         add {
126                                 driver.Idle += value;
127                         }
128                         remove {
129                                 driver.Idle -= value;
130                         }
131                 }
132                 
133                 #region Public Static Methods
134                 internal static void Exit() {
135                         driver.Exit();
136                 }
137
138                 internal static void GetDisplaySize(out Size size) {
139                         driver.GetDisplaySize(out size);
140                 }
141
142                 internal static void EnableThemes() {
143                         driver.EnableThemes();
144                 }
145
146                 internal static bool Text(IntPtr hWnd, string text) {
147                         return driver.Text(hWnd, text);
148                 }
149
150                 internal static bool GetText(IntPtr hWnd, out string text) {
151                         return driver.GetText(hWnd, out text);
152                 }
153
154                 internal static bool SetVisible(IntPtr hWnd, bool visible) {
155                         return driver.SetVisible(hWnd, visible);
156                 }
157
158                 internal static bool IsVisible(IntPtr hWnd) {
159                         return driver.IsVisible(hWnd);
160                 }
161
162                 internal static IntPtr SetParent(IntPtr hWnd, IntPtr hParent) {
163                         return driver.SetParent(hWnd, hParent);
164                 }
165
166                 internal static IntPtr GetParent(IntPtr hWnd) {
167                         return driver.GetParent(hWnd);
168                 }
169
170                 internal static void Version() {
171                         Console.WriteLine("Xplat version $revision: $");
172                 }
173
174                 internal static IntPtr CreateWindow(CreateParams cp) {
175                         return driver.CreateWindow(cp);
176                 }
177
178                 internal static IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
179                         return driver.CreateWindow(Parent, X, Y, Width, Height);
180                 }
181
182                 internal static void DestroyWindow(IntPtr handle) {
183                         driver.DestroyWindow(handle);
184                 }
185
186                 internal static FormWindowState GetWindowState(IntPtr handle) {
187                         return driver.GetWindowState(handle);
188                 }
189
190                 internal static void SetWindowState(IntPtr handle, FormWindowState state) {
191                         driver.SetWindowState(handle, state);
192                 }
193
194                 internal static void RefreshWindow(IntPtr handle) {
195                         driver.RefreshWindow(handle);
196                 }
197
198                 internal static void SetWindowBackground(IntPtr handle, Color color) {
199                         driver.SetWindowBackground(handle, color);
200                 }
201                         
202                 internal static PaintEventArgs PaintEventStart(IntPtr handle) {
203                         return driver.PaintEventStart(handle);
204                 }
205
206                 internal static void PaintEventEnd(IntPtr handle) {
207                         driver.PaintEventEnd(handle);
208                 }
209
210                 internal static void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
211                         driver.SetWindowPos(handle, x, y, width, height);
212                 }
213
214                 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) {
215                         driver.GetWindowPos(handle, out x, out y, out width, out height, out client_width, out client_height);
216                 }
217
218                 internal static void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
219                         driver.Invalidate(handle, rc, clear);
220                 }
221
222                 internal static void Activate(IntPtr handle) {
223                         driver.Activate(handle);
224                 }
225
226                 internal static void EnableWindow(IntPtr handle, bool Enable) {
227                         driver.EnableWindow(handle, Enable);
228                 }
229
230                 internal static void SetModal(IntPtr handle, bool Modal) {
231                         driver.SetModal(handle, Modal);
232                 }
233
234                 internal static IntPtr DefWndProc(ref Message msg) {
235                         return driver.DefWndProc(ref msg);
236                 }
237
238                 internal static void HandleException(Exception e) {
239                         driver.HandleException(e);
240                 }
241
242                 internal static void DoEvents() {
243                         driver.DoEvents();
244                 }
245
246                 internal static bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
247                         return driver.PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
248                 }
249
250                 internal static bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
251                         return driver.GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
252                 }
253
254                 internal static bool TranslateMessage(ref MSG msg) {
255                         return driver.TranslateMessage(ref msg);
256                 }
257
258                 internal static IntPtr DispatchMessage(ref MSG msg) {
259                         return driver.DispatchMessage(ref msg);
260                 }
261
262                 internal static void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
263                         driver.GrabWindow(hWnd, ConfineToHwnd);
264                 }
265
266                 internal static void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
267                         driver.GrabInfo(out hWnd, out GrabConfined, out GrabArea);
268                 }
269
270                 internal static void ReleaseWindow(IntPtr hWnd) {
271                         driver.ReleaseWindow(hWnd);
272                 }
273
274                 internal static bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
275                         return driver.SetZOrder(hWnd, AfterhWnd, Top, Bottom);
276                 }
277
278                 internal static bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
279                         return driver.SetTopmost(hWnd, hWndOwner, Enabled);
280                 }
281
282                 internal static bool CalculateWindowRect(IntPtr hWnd, ref Rectangle ClientRect, int Style, bool HasMenu, out Rectangle WindowRect) {
283                         return driver.CalculateWindowRect(hWnd, ref ClientRect, Style, HasMenu, out WindowRect);
284                 }
285
286                 internal static void SetCursorPos(IntPtr handle, int x, int y) {
287                         driver.SetCursorPos(handle, x, y);
288                 }
289
290                 internal static void GetCursorPos(IntPtr handle, out int x, out int y) {
291                         driver.GetCursorPos(handle, out x, out y);
292                 }
293
294                 internal static void ScreenToClient(IntPtr handle, ref int x, ref int y) {
295                         driver.ScreenToClient (handle, ref x, ref y);
296                 }
297
298                 internal static void ClientToScreen(IntPtr handle, ref int x, ref int y) {
299                         driver.ClientToScreen(handle, ref x, ref y);
300                 }
301
302                 internal static void SendAsyncMethod (AsyncMethodData data) {
303                         driver.SendAsyncMethod (data);
304                 }
305
306                 internal static void CreateCaret(IntPtr hwnd, int width, int height) {
307                         driver.CreateCaret(hwnd, width, height);
308                 }
309
310                 internal static void DestroyCaret(IntPtr hwnd) {
311                         driver.DestroyCaret(hwnd);
312                 }
313
314                 internal static void SetCaretPos(IntPtr hwnd, int x, int y) {
315                         driver.SetCaretPos(hwnd, x, y);
316                 }
317
318                 internal static void CaretVisible(IntPtr hwnd, bool visible) {
319                         driver.CaretVisible(hwnd, visible);
320                 }
321
322                 internal static void SetFocus(IntPtr hwnd) {
323                         driver.SetFocus(hwnd);
324                 }
325
326                 internal static IntPtr GetActive() {
327                         return driver.GetActive();
328                 }
329
330                 internal static bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
331                         return driver.GetFontMetrics(g, font, out ascent, out descent);
332                 }
333                         
334                 internal static void SetTimer (Timer timer)
335                 {
336                         driver.SetTimer (timer);
337                 }
338
339                 internal static void KillTimer (Timer timer)
340                 {
341                         driver.KillTimer (timer);
342                 }
343
344                 internal static int KeyboardSpeed {
345                         get {
346                                 return driver.KeyboardSpeed;
347                         }
348                 }
349
350                 internal static int KeyboardDelay {
351                         get {
352                                 return driver.KeyboardSpeed;
353                         }
354                 }
355
356                 internal static void ScrollWindow(IntPtr hwnd, int XAmount, int YAmount) {
357                         driver.ScrollWindow(hwnd, XAmount, YAmount);
358                 }
359                 
360                 // Santa's little helper
361                 internal static void Where() {
362                         Console.WriteLine("Here: {0}", new StackTrace().ToString());
363                 }
364                 #endregion      // Public Static Methods
365
366         }
367 }