XplatUI.cs 8.0 KB

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