XplatUI.cs 9.9 KB

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