Form.cs 6.6 KB

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