- Removed Run method, was only required for initial development
[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.6 $
27 // $Modtime: $
28 // $Log: XplatUI.cs,v $
29 // Revision 1.6  2004/08/09 20:55:59  pbartok
30 // - Removed Run method, was only required for initial development
31 //
32 // Revision 1.5  2004/08/09 20:51:25  pbartok
33 // - Implemented GrabWindow/ReleaseWindow methods to allow pointer capture
34 //
35 // Revision 1.4  2004/08/09 17:02:29  jackson
36 // Get default window properties from the theme
37 //
38 // Revision 1.3  2004/08/09 15:56:44  jackson
39 // Remove defaults, these are handled by the theme now.
40 //
41 // Revision 1.2  2004/08/04 20:11:24  pbartok
42 // - Added Invalidate handling
43 //
44 // Revision 1.1  2004/07/09 05:21:25  pbartok
45 // - Initial check-in
46 //
47 //
48
49 // NOT COMPLETE
50
51 using System;
52 using System.Drawing;
53 using System.ComponentModel;
54 using System.Collections;
55 using System.Diagnostics;
56 using System.Runtime.InteropServices;
57
58 //
59 // Random architecture notes
60 // We need
61 // * windows
62 //   - create
63 //   - set location/size
64 //   - define cursor
65 //   - destroy
66 //   - reparent?
67 //   - show/hide
68 // * Keyboard
69 // * Mouse
70 //
71
72 /// X11 Version
73 namespace System.Windows.Forms {
74         public class XplatUI {
75                 #region Local Variables
76                 static XplatUIDriver            driver;
77                 static String                   default_class_name;
78                 #endregion      // Local Variables
79
80                 #region Subclasses
81
82                 public class State {
83                         static public Keys ModifierKeys {
84                                 get {
85                                         return driver.ModifierKeys;
86                                 }
87                         }
88
89                         static public MouseButtons MouseButtons {
90                                 get {
91                                         return driver.MouseButtons;
92                                 }
93                         }
94
95                         static public Point MousePosition {
96                                 get {
97                                         return driver.MousePosition;
98                                 }
99                         }
100
101                         static public bool DropTarget {
102                                 get {
103                                         return driver.DropTarget;
104                                 }
105
106                                 set {
107                                         driver.DropTarget=value;
108                                 }
109                         }
110                 }
111                 #endregion      // Subclasses
112
113                 #region Constructor & Destructor
114                 static XplatUI() {
115                         // Don't forget to throw the mac in here somewhere, too
116                         default_class_name="SWFClass";
117
118                         if (Environment.OSVersion.Platform == (PlatformID)128) {
119                                 driver=XplatUIX11.GetInstance();
120                         } else {
121                                 driver=XplatUIWin32.GetInstance();
122                         }
123
124                         Console.WriteLine("#region #line XplatUI Constructor called");
125                 }
126
127                 ~XplatUI() {
128                         Console.WriteLine("XplatUI Destructor called");
129                 }
130                 #endregion      // Constructor & Destructor
131
132                 #region Public Static Properties
133                 internal static string DefaultClassName {
134                         get {
135                                 return default_class_name;
136                         }
137
138                         set {
139                                 default_class_name=value;
140                         }
141                 }
142                 #endregion      // Public Static Properties
143
144                 #region Public Static Methods
145                 internal static void Exit() {
146                         driver.Exit();
147                 }
148
149                 internal static bool Text(IntPtr hWnd, string text) {
150                         return driver.Text(hWnd, text);
151                 }
152
153                 internal static bool SetVisible(IntPtr hWnd, bool visible) {
154                         return driver.SetVisible(hWnd, visible);
155                 }
156
157                 internal static bool IsVisible(IntPtr hWnd) {
158                         return driver.IsVisible(hWnd);
159                 }
160
161                 internal static IntPtr SetParent(IntPtr hWnd, IntPtr hParent) {
162                         return driver.SetParent(hWnd, hParent);
163                 }
164
165                 internal static IntPtr GetParent(IntPtr hWnd) {
166                         return driver.GetParent(hWnd);
167                 }
168
169                 internal static void Version() {
170                         Console.WriteLine("Xplat version $revision: $");
171                 }
172
173                 internal static IntPtr CreateWindow(CreateParams cp) {
174                         return driver.CreateWindow(cp);
175                 }
176
177                 internal static IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
178                         return driver.CreateWindow(Parent, X, Y, Width, Height);
179                 }
180
181                 internal static void DestroyWindow(IntPtr handle) {
182                         driver.DestroyWindow(handle);
183                 }
184
185                 internal static void RefreshWindow(IntPtr handle) {
186                         driver.RefreshWindow(handle);
187                 }
188
189                 internal static PaintEventArgs PaintEventStart(IntPtr handle) {
190                         return driver.PaintEventStart(handle);
191                 }
192
193                 internal static void PaintEventEnd(IntPtr handle) {
194                         driver.PaintEventEnd(handle);
195                 }
196
197                 internal static void SetWindowPos(IntPtr handle, Rectangle rc) {
198                         driver.SetWindowPos(handle, rc);
199                 }
200
201                 internal static void MoveWindow(IntPtr hWnd, int x, int y, int width, int height) {
202                         driver.MoveWindow(hWnd, x, y, width, height);
203                 }
204
205                 internal static void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
206                         driver.SetWindowPos(handle, x, y, width, 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 IntPtr DefWndProc(ref Message msg) {
218                         return driver.DefWndProc(ref msg);
219                 }
220
221                 internal static void HandleException(Exception e) {
222                         driver.HandleException(e);
223                 }
224
225                 internal static void DoEvents() {
226                         driver.DoEvents();
227                 }
228
229                 internal static bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
230                         return driver.PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
231                 }
232
233                 internal static bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
234                         return driver.GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
235                 }
236
237                 internal static bool TranslateMessage(ref MSG msg) {
238                         return driver.TranslateMessage(ref msg);
239                 }
240
241                 internal static bool DispatchMessage(ref MSG msg) {
242                         return driver.DispatchMessage(ref msg);
243                 }
244
245                 internal static void GrabWindow(IntPtr hWnd) {
246                         driver.GrabWindow(hWnd);
247                 }
248                 internal static void ReleaseWindow(IntPtr hWnd) {
249                         driver.ReleaseWindow(hWnd);
250                 }
251
252                 // Santa's little helper
253                 internal static void Where() {
254                         Console.WriteLine("Here: {0}", new StackTrace().ToString());
255                 }
256                 #endregion      // Public Static Methods
257
258         }
259 }