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