Form.cs 7.9 KB

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