Form.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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.9 $
  27. // $Modtime: $
  28. // $Log: Form.cs,v $
  29. // Revision 1.9 2004/09/13 16:51:29 pbartok
  30. // - Added Accept and CancelButton properties
  31. // - Added ProcessDialogKey() method
  32. //
  33. // Revision 1.8 2004/09/01 02:05:18 pbartok
  34. // - Added (partial) implementation of DialogResult; rest needs to be
  35. // implemented when the modal loop code is done
  36. //
  37. // Revision 1.7 2004/08/23 22:10:02 pbartok
  38. // - Fixed handling of WM_CLOSE message
  39. // - Removed debug output
  40. //
  41. // Revision 1.6 2004/08/22 21:10:30 pbartok
  42. // - Removed OverlappedWindow style from Control, instead it's default
  43. // now is child
  44. // - Made form windows OverlappedWindow by default
  45. //
  46. // Revision 1.5 2004/08/19 21:30:37 pbartok
  47. // - Added handling of WM_CLOSE
  48. //
  49. // Revision 1.4 2004/08/11 22:20:59 pbartok
  50. // - Signature fixes
  51. //
  52. // Revision 1.3 2004/08/04 21:13:47 pbartok
  53. // - Added AutoScale properties
  54. //
  55. // Revision 1.2 2004/07/13 15:31:45 jordi
  56. // commit: new properties and fixes form size problems
  57. //
  58. // Revision 1.1 2004/07/09 05:21:25 pbartok
  59. // - Initial check-in
  60. //
  61. //
  62. // NOT COMPLETE
  63. using System;
  64. using System.Drawing;
  65. using System.ComponentModel;
  66. using System.Collections;
  67. using System.Runtime.InteropServices;
  68. using System.Threading;
  69. namespace System.Windows.Forms {
  70. public class Form : ContainerControl {
  71. #region Local Variables
  72. internal bool closing;
  73. private static bool autoscale;
  74. private static Size autoscale_base_size;
  75. private IButtonControl accept_button;
  76. private IButtonControl cancel_button;
  77. private DialogResult dialog_result;
  78. #endregion // Local Variables
  79. #region Public Constructor & Destructor
  80. public Form() {
  81. closing = false;
  82. //XplatUI.Version();
  83. }
  84. #endregion // Public Constructor & Destructor
  85. #region Public Static Properties
  86. #endregion // Public Static Properties
  87. #region Public Instance Properties
  88. protected override Size DefaultSize {
  89. get {
  90. return new Size (250, 250);
  91. }
  92. }
  93. #endregion // Public Instance Properties
  94. #region Protected Instance Properties
  95. public IButtonControl AcceptButton {
  96. get {
  97. return accept_button;
  98. }
  99. set {
  100. accept_button = value;
  101. }
  102. }
  103. public bool AutoScale {
  104. get {
  105. return autoscale;
  106. }
  107. set {
  108. autoscale=value;
  109. }
  110. }
  111. public virtual Size AutoScaleBaseSize {
  112. get {
  113. return autoscale_base_size;
  114. }
  115. set {
  116. autoscale_base_size=value;
  117. }
  118. }
  119. [MonoTODO("Add code to terminate modal application loop")]
  120. public DialogResult DialogResult {
  121. get {
  122. return dialog_result;
  123. }
  124. set {
  125. dialog_result = value;
  126. // Add termination code here
  127. }
  128. }
  129. public IButtonControl CancelButton {
  130. get {
  131. return cancel_button;
  132. }
  133. set {
  134. cancel_button = value;
  135. }
  136. }
  137. #endregion // Public Instance Properties
  138. #region Public Static Methods
  139. #endregion // Public Static Methods
  140. #region Public Instance Methods
  141. [MonoTODO("Need to add MDI support")]
  142. protected override CreateParams CreateParams {
  143. get {
  144. CreateParams create_params = new CreateParams();
  145. create_params.Caption = "";
  146. create_params.ClassName=XplatUI.DefaultClassName;
  147. create_params.ClassStyle = 0;
  148. create_params.ExStyle=0;
  149. create_params.Parent=IntPtr.Zero;
  150. create_params.Param=0;
  151. create_params.X = Left;
  152. create_params.Y = Top;
  153. create_params.Width = Width;
  154. create_params.Height = Height;
  155. create_params.Style = (int)WindowStyles.WS_OVERLAPPEDWINDOW;
  156. create_params.Style |= (int)WindowStyles.WS_VISIBLE;
  157. return create_params;
  158. }
  159. }
  160. #endregion // Public Instance Methods
  161. #region Protected Instance Methods
  162. protected override bool ProcessDialogKey(Keys keyData) {
  163. if (keyData == Keys.Enter && accept_button != null) {
  164. accept_button.PerformClick();
  165. return true;
  166. } else if (keyData == Keys.Enter && cancel_button != null) {
  167. cancel_button.PerformClick();
  168. return true;
  169. }
  170. return base.ProcessDialogKey(keyData);
  171. }
  172. protected override void WndProc(ref Message m) {
  173. switch((Msg)m.Msg) {
  174. case Msg.WM_CLOSE: {
  175. CancelEventArgs args = new CancelEventArgs(true);
  176. OnClosing(args);
  177. if (!args.Cancel) {
  178. OnClosed(EventArgs.Empty);
  179. base.WndProc(ref m);
  180. break;
  181. }
  182. closing = true;
  183. break;
  184. }
  185. default: {
  186. base.WndProc (ref m);
  187. break;
  188. }
  189. }
  190. }
  191. #endregion // Protected Instance Methods
  192. #region Events
  193. protected virtual void OnActivated(EventArgs e) {
  194. if (Activated != null) {
  195. Activated(this, e);
  196. }
  197. }
  198. protected virtual void OnClosed(EventArgs e) {
  199. if (Closed != null) {
  200. Closed(this, e);
  201. }
  202. }
  203. protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
  204. if (Closing != null) {
  205. Closing(this, e);
  206. }
  207. }
  208. protected virtual void OnDeactivate(EventArgs e) {
  209. if (Deactivate != null) {
  210. Deactivate(this, e);
  211. }
  212. }
  213. protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
  214. if (InputLanguageChanged!=null) {
  215. InputLanguageChanged(this, e);
  216. }
  217. }
  218. protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
  219. if (InputLanguageChanging!=null) {
  220. InputLanguageChanging(this, e);
  221. }
  222. }
  223. protected virtual void OnLoad(EventArgs e) {
  224. if (Load != null) {
  225. Load(this, e);
  226. }
  227. }
  228. protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
  229. if (MaximizedBoundsChanged != null) {
  230. MaximizedBoundsChanged(this, e);
  231. }
  232. }
  233. protected virtual void OnMaximumSizeChanged(EventArgs e) {
  234. if (MaximumSizeChanged != null) {
  235. MaximumSizeChanged(this, e);
  236. }
  237. }
  238. protected virtual void OnMdiChildActivate(EventArgs e) {
  239. if (MdiChildActivate != null) {
  240. MdiChildActivate(this, e);
  241. }
  242. }
  243. protected virtual void OnMenuComplete(EventArgs e) {
  244. if (MenuComplete != null) {
  245. MenuComplete(this, e);
  246. }
  247. }
  248. protected virtual void OnMenuStart(EventArgs e) {
  249. if (MenuStart != null) {
  250. MenuStart(this, e);
  251. }
  252. }
  253. protected virtual void OnMinimumSizeChanged(EventArgs e) {
  254. if (MinimumSizeChanged != null) {
  255. MinimumSizeChanged(this, e);
  256. }
  257. }
  258. public event EventHandler Activated;
  259. public event EventHandler Closed;
  260. public event CancelEventHandler Closing;
  261. public event EventHandler Deactivate;
  262. public event InputLanguageChangedEventHandler InputLanguageChanged;
  263. public event InputLanguageChangingEventHandler InputLanguageChanging;
  264. public event EventHandler Load;
  265. public event EventHandler MaximizedBoundsChanged;
  266. public event EventHandler MaximumSizeChanged;
  267. public event EventHandler MdiChildActivate;
  268. public event EventHandler MenuComplete;
  269. public event EventHandler MenuStart;
  270. public event EventHandler MinimumSizeChanged;
  271. #endregion // Events
  272. }
  273. }