- Implemented NotifyIcon and required driver support
[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         public 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                 #endregion      // Subclasses
76
77                 #region Constructor & Destructor
78                 static XplatUI() {
79                         // Don't forget to throw the mac in here somewhere, too
80                         default_class_name="SWFClass";
81
82                         if (Environment.OSVersion.Platform == (PlatformID)128) {
83                                 if (Environment.GetEnvironmentVariable ("MONO_MWF_USE_QUARTZ_BACKEND") != null)
84                                         driver=XplatUIOSX.GetInstance();
85                                 else
86                                         driver=XplatUIX11.GetInstance();
87                         } else {
88                                 driver=XplatUIWin32.GetInstance();
89                         }
90
91                         Console.WriteLine("#region #line XplatUI Constructor called");
92                 }
93
94                 ~XplatUI() {
95                         Console.WriteLine("XplatUI Destructor called");
96                 }
97                 #endregion      // Constructor & Destructor
98
99                 #region Public Static Properties
100                 internal static string DefaultClassName {
101                         get {
102                                 return default_class_name;
103                         }
104
105                         set {
106                                 default_class_name=value;
107                         }
108                 }
109                 #endregion      // Public Static Properties
110
111                 internal static event EventHandler Idle {
112                         add {
113                                 driver.Idle += value;
114                         }
115                         remove {
116                                 driver.Idle -= value;
117                         }
118                 }
119                 
120                 #region Public Static Methods
121                 internal static void Exit() {
122                         driver.Exit();
123                 }
124
125                 internal static void GetDisplaySize(out Size size) {
126                         driver.GetDisplaySize(out size);
127                 }
128
129                 internal static void EnableThemes() {
130                         driver.EnableThemes();
131                 }
132
133                 internal static bool Text(IntPtr hWnd, string text) {
134                         return driver.Text(hWnd, text);
135                 }
136
137                 internal static bool GetText(IntPtr hWnd, out string text) {
138                         return driver.GetText(hWnd, out text);
139                 }
140
141                 internal static bool SetVisible(IntPtr hWnd, bool visible) {
142                         return driver.SetVisible(hWnd, visible);
143                 }
144
145                 internal static bool IsVisible(IntPtr hWnd) {
146                         return driver.IsVisible(hWnd);
147                 }
148
149                 internal static IntPtr SetParent(IntPtr hWnd, IntPtr hParent) {
150                         return driver.SetParent(hWnd, hParent);
151                 }
152
153                 internal static IntPtr GetParent(IntPtr hWnd) {
154                         return driver.GetParent(hWnd);
155                 }
156
157                 internal static void Version() {
158                         Console.WriteLine("Xplat version $revision: $");
159                 }
160
161                 internal static IntPtr CreateWindow(CreateParams cp) {
162                         return driver.CreateWindow(cp);
163                 }
164
165                 internal static IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
166                         return driver.CreateWindow(Parent, X, Y, Width, Height);
167                 }
168
169                 internal static void DestroyWindow(IntPtr handle) {
170                         driver.DestroyWindow(handle);
171                 }
172
173                 internal static FormWindowState GetWindowState(IntPtr handle) {
174                         return driver.GetWindowState(handle);
175                 }
176
177                 internal static void SetWindowState(IntPtr handle, FormWindowState state) {
178                         driver.SetWindowState(handle, state);
179                 }
180
181                 internal static void SetWindowStyle(IntPtr handle, CreateParams cp) {
182                         driver.SetWindowStyle(handle, cp);
183                 }
184
185                 internal static void UpdateWindow(IntPtr handle) {
186                         driver.UpdateWindow(handle);
187                 }
188
189                 internal static void SetWindowBackground(IntPtr handle, Color color) {
190                         driver.SetWindowBackground(handle, color);
191                 }
192                         
193                 internal static PaintEventArgs PaintEventStart(IntPtr handle) {
194                         return driver.PaintEventStart(handle);
195                 }
196
197                 internal static void PaintEventEnd(IntPtr handle) {
198                         driver.PaintEventEnd(handle);
199                 }
200
201                 internal static void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
202                         driver.SetWindowPos(handle, x, y, width, height);
203                 }
204
205                 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) {
206                         driver.GetWindowPos(handle, out x, out y, out width, out height, out client_width, out client_height);
207                 }
208
209                 internal static void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
210                         driver.Invalidate(handle, rc, clear);
211                 }
212
213                 internal static void Activate(IntPtr handle) {
214                         driver.Activate(handle);
215                 }
216
217                 internal static void EnableWindow(IntPtr handle, bool Enable) {
218                         driver.EnableWindow(handle, Enable);
219                 }
220
221                 internal static void SetModal(IntPtr handle, bool Modal) {
222                         driver.SetModal(handle, Modal);
223                 }
224
225                 internal static IntPtr DefWndProc(ref Message msg) {
226                         return driver.DefWndProc(ref msg);
227                 }
228
229                 internal static void HandleException(Exception e) {
230                         driver.HandleException(e);
231                 }
232
233                 internal static void DoEvents() {
234                         driver.DoEvents();
235                 }
236
237                 internal static bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
238                         return driver.PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
239                 }
240
241                 internal static bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
242                         return driver.GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
243                 }
244
245                 internal static bool TranslateMessage(ref MSG msg) {
246                         return driver.TranslateMessage(ref msg);
247                 }
248
249                 internal static IntPtr DispatchMessage(ref MSG msg) {
250                         return driver.DispatchMessage(ref msg);
251                 }
252
253                 internal static void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
254                         driver.GrabWindow(hWnd, ConfineToHwnd);
255                 }
256
257                 internal static void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
258                         driver.GrabInfo(out hWnd, out GrabConfined, out GrabArea);
259                 }
260
261                 internal static void ReleaseWindow(IntPtr hWnd) {
262                         driver.ReleaseWindow(hWnd);
263                 }
264
265                 internal static bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
266                         return driver.SetZOrder(hWnd, AfterhWnd, Top, Bottom);
267                 }
268
269                 internal static bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
270                         return driver.SetTopmost(hWnd, hWndOwner, Enabled);
271                 }
272
273                 internal static bool CalculateWindowRect(IntPtr hWnd, ref Rectangle ClientRect, int Style, bool HasMenu, out Rectangle WindowRect) {
274                         return driver.CalculateWindowRect(hWnd, ref ClientRect, Style, HasMenu, out WindowRect);
275                 }
276
277                 internal static void SetCursor(IntPtr hwnd, IntPtr cursor) {
278                         driver.SetCursor(hwnd, cursor);
279                 }
280
281                 internal static void ShowCursor(bool show) {
282                         driver.ShowCursor(show);
283                 }
284
285                 internal static void OverrideCursor(IntPtr cursor) {
286                         driver.OverrideCursor(cursor);
287                 }
288
289                 internal static IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
290                         return driver.DefineCursor(bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
291                 }
292
293                 internal static IntPtr DefineStdCursor(StdCursor id) {
294                         return driver.DefineStdCursor(id);
295                 }
296
297                 internal static void DestroyCursor(IntPtr cursor) {
298                         driver.DestroyCursor(cursor);
299                 }
300
301                 internal static void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
302                         driver.GetCursorInfo(cursor, out width, out height, out hotspot_x, out hotspot_y);
303                 }
304
305                 internal static void SetCursorPos(IntPtr handle, int x, int y) {
306                         driver.SetCursorPos(handle, x, y);
307                 }
308
309                 internal static void GetCursorPos(IntPtr handle, out int x, out int y) {
310                         driver.GetCursorPos(handle, out x, out y);
311                 }
312
313                 internal static void ScreenToClient(IntPtr handle, ref int x, ref int y) {
314                         driver.ScreenToClient (handle, ref x, ref y);
315                 }
316
317                 internal static void ClientToScreen(IntPtr handle, ref int x, ref int y) {
318                         driver.ClientToScreen(handle, ref x, ref y);
319                 }
320
321                 internal static void SendAsyncMethod (AsyncMethodData data) {
322                         driver.SendAsyncMethod (data);
323                 }
324
325                 internal static void CreateCaret(IntPtr hwnd, int width, int height) {
326                         driver.CreateCaret(hwnd, width, height);
327                 }
328
329                 internal static void DestroyCaret(IntPtr hwnd) {
330                         driver.DestroyCaret(hwnd);
331                 }
332
333                 internal static void SetCaretPos(IntPtr hwnd, int x, int y) {
334                         driver.SetCaretPos(hwnd, x, y);
335                 }
336
337                 internal static void CaretVisible(IntPtr hwnd, bool visible) {
338                         driver.CaretVisible(hwnd, visible);
339                 }
340
341                 internal static void SetFocus(IntPtr hwnd) {
342                         driver.SetFocus(hwnd);
343                 }
344
345                 internal static IntPtr GetActive() {
346                         return driver.GetActive();
347                 }
348
349                 internal static bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
350                         return driver.GetFontMetrics(g, font, out ascent, out descent);
351                 }
352                         
353                 internal static void SetTimer (Timer timer)
354                 {
355                         driver.SetTimer (timer);
356                 }
357
358                 internal static void KillTimer (Timer timer)
359                 {
360                         driver.KillTimer (timer);
361                 }
362
363                 internal static int KeyboardSpeed {
364                         get {
365                                 return driver.KeyboardSpeed;
366                         }
367                 }
368
369                 internal static int KeyboardDelay {
370                         get {
371                                 return driver.KeyboardSpeed;
372                         }
373                 }
374
375                 internal static void ScrollWindow(IntPtr hwnd, Rectangle rectangle, int XAmount, int YAmount, bool clear) {
376                         driver.ScrollWindow(hwnd, rectangle, XAmount, YAmount, clear);
377                 }
378
379                 internal static void ScrollWindow(IntPtr hwnd, int XAmount, int YAmount, bool clear) {
380                         driver.ScrollWindow(hwnd, XAmount, YAmount, clear);
381                 }
382
383                 internal static bool SystrayAdd(IntPtr hwnd, string tip, Icon icon) {
384                         return driver.SystrayAdd(hwnd, tip, icon);
385                 }
386
387                 internal static void SystrayChange(IntPtr hwnd, string tip, Icon icon) {
388                         driver.SystrayChange(hwnd, tip, icon);
389                 }
390
391                 internal static void SystrayRemove(IntPtr hwnd) {
392                         driver.SystrayRemove(hwnd);
393                 }
394
395
396                 // Santa's little helper
397                 internal static void Where() {
398                         Console.WriteLine("Here: {0}", new StackTrace().ToString());
399                 }
400                 #endregion      // Public Static Methods
401
402         }
403 }