XplatUI.cs 7.3 KB

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