XplatUI.cs 10 KB

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