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