Form.cs 7.0 KB

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