XplatUI.cs 9.2 KB

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