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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2004 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
30 using System.ComponentModel;
31 using System.ComponentModel.Design;
32 using System.ComponentModel.Design.Serialization;
33 using System.Collections;
34 using System.Runtime.InteropServices;
35 using System.Threading;
37 namespace System.Windows.Forms {
38 [DesignerCategory("Form")]
39 [DesignTimeVisible(false)]
40 [Designer("System.Windows.Forms.Design.FormDocumentDesigner, " + Consts.AssemblySystem_Design, typeof(IRootDesigner))]
41 [DefaultEvent("Load")]
43 public class Form : ContainerControl {
44 #region Local Variables
45 internal static Form active_form;
46 internal bool closing;
47 FormBorderStyle formBorderStyle;
48 private static bool autoscale;
49 private static Size autoscale_base_size;
50 internal bool is_modal;
51 internal bool end_modal; // This var is being monitored by the application modal loop
52 private bool control_box;
53 private bool minimize_box;
54 private bool maximize_box;
55 private bool help_button;
56 private bool show_in_taskbar;
58 private IButtonControl accept_button;
59 private IButtonControl cancel_button;
60 private DialogResult dialog_result;
61 private FormStartPosition start_position;
63 private Form.ControlCollection owned_forms;
64 private MdiClient mdi_container;
65 private Form mdi_parent;
66 private bool key_preview;
67 private MainMenu menu;
69 private Size maximum_size;
70 private Size minimum_size;
71 private SizeGripStyle size_grip_style;
72 private Rectangle maximized_bounds;
73 private Rectangle default_maximized_bounds;
74 #endregion // Local Variables
76 #region Private & Internal Methods
77 #endregion // Private & Internal Methods
79 #region Public Classes
80 public new class ControlCollection : Control.ControlCollection {
83 public ControlCollection(Form owner) : base(owner) {
84 this.form_owner = owner;
87 public override void Add(Control value) {
88 for (int i=0; i<list.Count; i++) {
90 // Do we need to do anything here?
95 ((Form)value).owner=(Form)owner;
98 public override void Remove(Control value) {
99 ((Form)value).owner = null;
103 #endregion // Public Classes
105 #region Public Constructor & Destructor
110 dialog_result = DialogResult.None;
111 start_position = FormStartPosition.WindowsDefaultLocation;
112 formBorderStyle = FormBorderStyle.Sizable;
116 minimum_size = new Size(0, 0);
117 maximum_size = new Size(0, 0);
122 show_in_taskbar = true;
123 ime_mode = ImeMode.NoControl;
126 size_grip_style = SizeGripStyle.Auto;
127 maximized_bounds = Rectangle.Empty;
128 default_maximized_bounds = Rectangle.Empty;
129 owned_forms = new Form.ControlCollection(this);
131 #endregion // Public Constructor & Destructor
133 #region Public Static Properties
135 public static Form ActiveForm {
139 active = FromHandle(XplatUI.GetActive());
141 if (active != null) {
142 if ( !(active is Form)) {
145 parent = active.Parent;
146 while (parent != null) {
147 if (parent is Form) {
150 parent = parent.Parent;
160 #endregion // Public Static Properties
162 #region Public Instance Properties
164 public IButtonControl AcceptButton {
166 return accept_button;
170 accept_button = value;
174 [MonoTODO("Figure out a way for transparency support in windows")]
176 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
177 public bool AllowTransparency {
187 public bool AutoScale {
199 [EditorBrowsable(EditorBrowsableState.Advanced)]
200 public virtual Size AutoScaleBaseSize {
202 return autoscale_base_size;
206 autoscale_base_size=value;
211 public override bool AutoScroll {
213 return base.AutoScroll;
216 base.AutoScroll = value;
220 public override Color BackColor {
222 return base.BackColor;
225 base.BackColor = value;
230 public IButtonControl CancelButton {
232 return cancel_button;
236 cancel_button = value;
240 [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
242 public Size ClientSize {
244 return base.ClientSize;
248 base.ClientSize = value;
253 public bool ControlBox {
259 if (control_box != value) {
267 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
268 public Rectangle DesktopBounds {
270 return new Rectangle(Location, Size);
279 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
280 public Point DesktopLocation {
291 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
292 public DialogResult DialogResult {
294 return dialog_result;
298 dialog_result = value;
300 if (is_modal && (dialog_result != DialogResult.None)) {
306 [DefaultValue(FormBorderStyle.Sizable)]
308 public FormBorderStyle FormBorderStyle {
310 return formBorderStyle;
313 formBorderStyle = value;
318 [DefaultValue(false)]
319 public bool HelpButton {
325 if (help_button != value) {
343 XplatUI.SetIcon(Handle, icon);
349 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
350 public bool IsMdiChild {
352 return mdi_parent != null;
356 [DefaultValue(false)]
357 public bool IsMdiContainer {
359 return mdi_container != null;
363 if (value && mdi_container == null) {
364 mdi_container = new MdiClient();
365 Controls.Add(mdi_container);
366 } else if (!value && mdi_container != null) {
367 Controls.Remove(mdi_container);
368 mdi_container.Dispose();
374 [EditorBrowsable(EditorBrowsableState.Advanced)]
375 public bool IsRestrictedWindow {
381 [DefaultValue(false)]
382 public bool KeyPreview {
393 public bool MaximizeBox {
398 if (maximize_box != value) {
399 maximize_box = value;
405 [DefaultValue(typeof(Size), "{Width=0, Height=0}")]
407 [RefreshProperties(RefreshProperties.Repaint)]
408 public Size MaximumSize {
414 if (maximum_size != value) {
415 maximum_size = value;
416 OnMaximumSizeChanged(EventArgs.Empty);
422 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
423 public Form[] MdiChildren {
425 if (mdi_container != null) {
428 form_list = new Form[mdi_container.Controls.Count];
429 for (int i = 0; i < mdi_container.Controls.Count; i++) {
430 form_list[i] = (Form)mdi_container.Controls[i];
439 [MonoTODO("Finish setter")]
441 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
442 public Form MdiParent {
448 if (mdi_parent != null) {
449 mdi_parent.Controls.Remove(this);
453 if (mdi_parent != null) {
454 mdi_parent.Controls.Add(this);
460 public MainMenu Menu {
470 MenuAPI.SetMenuBarWindow (menu.Handle, this);
472 XplatUI.SetMenu(window.Handle, menu.Handle);
474 // FIXME - Do we still need this?
475 this.SetBoundsCore(0, 0, 0, 0, BoundsSpecified.None);
477 ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu.Handle, ClientSize.Width);
483 public bool MinimizeBox {
488 if (minimize_box != value) {
489 minimize_box = value;
495 [DefaultValue(typeof(Size), "{Width=0, Height=0}")]
497 [RefreshProperties(RefreshProperties.Repaint)]
498 public Size MinimumSize {
504 if (minimum_size != value) {
505 minimum_size = value;
506 OnMinimumSizeChanged(EventArgs.Empty);
512 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
520 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
521 public Form[] OwnedForms {
525 form_list = new Form[owned_forms.Count];
527 for (int i=0; i<owned_forms.Count; i++) {
528 form_list[i] = (Form)owned_forms[i];
536 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
543 if (owner != value) {
545 owner.RemoveOwnedForm(this);
548 owner.AddOwnedForm(this);
550 XplatUI.SetTopmost(this.window.Handle, owner.window.Handle, true);
552 XplatUI.SetTopmost(this.window.Handle, IntPtr.Zero, false);
559 public bool ShowInTaskbar {
561 return show_in_taskbar;
564 if (show_in_taskbar != value) {
565 show_in_taskbar = value;
571 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
583 [MonoTODO("Trigger something when GripStyle is set")]
584 [DefaultValue(SizeGripStyle.Auto)]
585 public SizeGripStyle SizeGripStyle {
587 return size_grip_style;
591 size_grip_style = value;
595 [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
597 public FormStartPosition StartPosition {
599 return start_position;
603 if (start_position == FormStartPosition.WindowsDefaultLocation) { // Only do this if it's not set yet
604 start_position = value;
605 if (IsHandleCreated) {
606 switch(start_position) {
607 case FormStartPosition.CenterParent: {
612 case FormStartPosition.CenterScreen: {
627 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
628 [EditorBrowsable(EditorBrowsableState.Never)]
629 public int TabIndex {
631 return base.TabIndex;
635 base.TabIndex = value;
640 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
641 [EditorBrowsable(EditorBrowsableState.Advanced)]
642 public bool TopLevel {
644 return GetTopLevel();
652 [DefaultValue(false)]
653 public bool TopMost {
659 if (topmost != value) {
661 XplatUI.SetTopmost(window.Handle, owner != null ? owner.window.Handle : IntPtr.Zero, value);
666 [DefaultValue(FormWindowState.Normal)]
667 public FormWindowState WindowState {
669 return XplatUI.GetWindowState(window.Handle);
673 XplatUI.SetWindowState(window.Handle, value);
677 #endregion // Public Instance Properties
679 #region Protected Instance Properties
680 [MonoTODO("Need to add MDI support")]
681 protected override CreateParams CreateParams {
685 cp = new CreateParams();
687 cp.Caption = "FormWindow";
688 cp.ClassName = XplatUI.DefaultClassName;
692 cp.Parent = IntPtr.Zero;
693 // if (start_position == FormStartPosition.WindowsDefaultLocation) {
694 cp.X = unchecked((int)0x80000000);
695 cp.Y = unchecked((int)0x80000000);
703 cp.Style = (int)(WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CLIPCHILDREN);
705 switch (FormBorderStyle) {
706 case FormBorderStyle.Fixed3D: {
707 cp.Style |= (int)WindowStyles.WS_CAPTION;
708 cp.ExStyle |= (int)WindowStyles.WS_EX_OVERLAPPEDWINDOW;
712 case FormBorderStyle.FixedDialog: {
713 cp.Style |= (int)WindowStyles.WS_CAPTION;
714 cp.ExStyle |= (int)(WindowStyles.WS_EX_DLGMODALFRAME | WindowStyles.WS_EX_WINDOWEDGE);
718 case FormBorderStyle.FixedSingle: {
719 cp.Style |= (int)WindowStyles.WS_CAPTION;
720 cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE);
724 case FormBorderStyle.FixedToolWindow: {
725 cp.Style |= (int)WindowStyles.WS_CAPTION;
726 cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE | WindowStyles.WS_EX_TOOLWINDOW);
730 case FormBorderStyle.Sizable: {
731 cp.Style |= (int)WindowStyles.WS_OVERLAPPEDWINDOW;
732 cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE);
736 case FormBorderStyle.SizableToolWindow: {
737 cp.Style |= (int)WindowStyles.WS_OVERLAPPEDWINDOW;
738 cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE | WindowStyles.WS_EX_TOOLWINDOW);
744 cp.ExStyle |= (int)WindowStyles.WS_EX_APPWINDOW;
748 cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
752 cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
756 cp.Style |= (int)WindowStyles.WS_SYSMENU;
760 cp.ExStyle |= (int)WindowStyles.WS_EX_CONTEXTHELP;
766 protected override ImeMode DefaultImeMode {
768 return ImeMode.NoControl;
772 protected override Size DefaultSize {
774 return new Size (250, 250);
778 protected Rectangle MaximizedBounds {
780 if (maximized_bounds != Rectangle.Empty) {
781 return maximized_bounds;
783 return default_maximized_bounds;
787 maximized_bounds = value;
788 OnMaximizedBoundsChanged(EventArgs.Empty);
791 #endregion // Protected Instance Properties
793 #region Public Static Methods
794 [MonoTODO("Figure out the math")]
795 [EditorBrowsable(EditorBrowsableState.Advanced)]
796 public static SizeF GetAutoScaleSize(Font font) {
799 result = new SizeF(250, 250);
800 result.Width *= font.SizeInPoints / 12;
801 result.Height *= font.SizeInPoints / 12;
804 #endregion // Public Static Methods
806 #region Public Instance Methods
807 public void Activate() {
810 // The docs say activate only activates if our app is already active
812 if ((active != null) && (this != active)) {
813 XplatUI.Activate(window.Handle);
817 public void AddOwnedForm(Form ownedForm) {
818 owned_forms.Add(ownedForm);
821 public void Close () {
822 CancelEventArgs args = new CancelEventArgs ();
825 OnClosed (EventArgs.Empty);
831 public void LayoutMdi(MdiLayout value) {
832 if (mdi_container != null) {
833 mdi_container.LayoutMdi(value);
837 public void RemoveOwnedForm(Form ownedForm) {
838 owned_forms.Remove(ownedForm);
841 public void SetDesktopBounds(int x, int y, int width, int height) {
842 DesktopBounds = new Rectangle(x, y, width, height);
845 public void SetDesktopLocation(int x, int y) {
846 DesktopLocation = new Point(x, y);
849 public DialogResult ShowDialog() {
850 return ShowDialog(null);
853 public DialogResult ShowDialog(IWin32Window ownerWin32) {
857 Control owner = null;
859 if (ownerWin32 != null) {
860 owner = Control.FromHandle(ownerWin32.Handle);
865 return DialogResult.None;
869 throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
873 // Can't do this, will screw us in the modal loop
874 form_parent_window.Parent = owner;
877 previous = Form.ActiveForm;
879 if (!IsHandleCreated) {
883 XplatUI.SetModal(window.Handle, true);
889 Application.ModalRun(this);
893 XplatUI.SetModal(window.Handle, false);
895 if (previous != null) {
896 // Cannot use Activate(), it has a check for the current active window...
897 XplatUI.Activate(previous.window.Handle);
903 public override string ToString() {
904 return GetType().FullName.ToString() + ", Text: " + Text;
906 #endregion // Public Instance Methods
908 #region Protected Instance Methods
909 [MonoTODO("Finish when MDI is more complete")]
910 protected void ActivateMdiChild(Form form) {
911 OnMdiChildActivate(EventArgs.Empty);
912 throw new NotImplementedException();
915 [EditorBrowsable(EditorBrowsableState.Advanced)]
916 protected override void AdjustFormScrollbars(bool displayScrollbars) {
917 base.AdjustFormScrollbars (displayScrollbars);
920 [EditorBrowsable(EditorBrowsableState.Advanced)]
921 protected void ApplyAutoScaling() {
922 // Hm, not sure what this does
925 protected void CenterToParent() {
933 w = DefaultSize.Width;
939 h = DefaultSize.Height;
943 if (parent != null) {
945 } else if (owner != null) {
950 this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
954 protected void CenterToScreen() {
962 w = DefaultSize.Width;
968 h = DefaultSize.Height;
971 XplatUI.GetDisplaySize(out DisplaySize);
972 this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
975 [EditorBrowsable(EditorBrowsableState.Advanced)]
976 protected override Control.ControlCollection CreateControlsInstance() {
977 return base.CreateControlsInstance ();
980 [EditorBrowsable(EditorBrowsableState.Advanced)]
981 protected override void CreateHandle() {
982 base.CreateHandle ();
985 [EditorBrowsable(EditorBrowsableState.Advanced)]
986 protected override void DefWndProc(ref Message m) {
987 base.DefWndProc (ref m);
990 protected override void Dispose(bool disposing) {
991 base.Dispose (disposing);
994 [EditorBrowsable(EditorBrowsableState.Advanced)]
995 protected virtual void OnActivated(EventArgs e) {
996 if (Activated != null) {
1001 [EditorBrowsable(EditorBrowsableState.Advanced)]
1002 protected virtual void OnClosed(EventArgs e) {
1003 if (Closed != null) {
1008 [EditorBrowsable(EditorBrowsableState.Advanced)]
1009 protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
1010 if (Closing != null) {
1015 [EditorBrowsable(EditorBrowsableState.Advanced)]
1016 protected override void OnCreateControl() {
1017 base.OnCreateControl ();
1018 if (this.ActiveControl == null) {
1021 // This visible hack is to work around CanSelect always being false if one of the parents
1022 // is not visible; and we by default create Form invisible...
1023 visible = this.is_visible;
1024 this.is_visible = true;
1026 if (SelectNextControl(this, true, true, true, true) == false) {
1030 this.is_visible = visible;
1032 OnLoad(EventArgs.Empty);
1034 // Send initial location
1035 OnLocationChanged(EventArgs.Empty);
1038 [EditorBrowsable(EditorBrowsableState.Advanced)]
1039 protected virtual void OnDeactivate(EventArgs e) {
1040 if (Deactivate != null) {
1041 Deactivate(this, e);
1045 [EditorBrowsable(EditorBrowsableState.Advanced)]
1046 protected override void OnFontChanged(EventArgs e) {
1047 base.OnFontChanged (e);
1050 [EditorBrowsable(EditorBrowsableState.Advanced)]
1051 protected override void OnHandleCreated(EventArgs e) {
1052 base.OnHandleCreated (e);
1055 [EditorBrowsable(EditorBrowsableState.Advanced)]
1056 protected override void OnHandleDestroyed(EventArgs e) {
1057 base.OnHandleDestroyed (e);
1060 [EditorBrowsable(EditorBrowsableState.Advanced)]
1061 protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
1062 if (InputLanguageChanged!=null) {
1063 InputLanguageChanged(this, e);
1067 [EditorBrowsable(EditorBrowsableState.Advanced)]
1068 protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
1069 if (InputLanguageChanging!=null) {
1070 InputLanguageChanging(this, e);
1074 [EditorBrowsable(EditorBrowsableState.Advanced)]
1075 protected virtual void OnLoad(EventArgs e) {
1081 [EditorBrowsable(EditorBrowsableState.Advanced)]
1082 protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
1083 if (MaximizedBoundsChanged != null) {
1084 MaximizedBoundsChanged(this, e);
1088 [EditorBrowsable(EditorBrowsableState.Advanced)]
1089 protected virtual void OnMaximumSizeChanged(EventArgs e) {
1090 if (MaximumSizeChanged != null) {
1091 MaximumSizeChanged(this, e);
1095 [EditorBrowsable(EditorBrowsableState.Advanced)]
1096 protected virtual void OnMdiChildActivate(EventArgs e) {
1097 if (MdiChildActivate != null) {
1098 MdiChildActivate(this, e);
1102 [EditorBrowsable(EditorBrowsableState.Advanced)]
1103 protected virtual void OnMenuComplete(EventArgs e) {
1104 if (MenuComplete != null) {
1105 MenuComplete(this, e);
1109 [EditorBrowsable(EditorBrowsableState.Advanced)]
1110 protected virtual void OnMenuStart(EventArgs e) {
1111 if (MenuStart != null) {
1116 [EditorBrowsable(EditorBrowsableState.Advanced)]
1117 protected virtual void OnMinimumSizeChanged(EventArgs e) {
1118 if (MinimumSizeChanged != null) {
1119 MinimumSizeChanged(this, e);
1123 [EditorBrowsable(EditorBrowsableState.Advanced)]
1124 protected override void OnPaint (PaintEventArgs pevent) {
1125 base.OnPaint (pevent);
1128 [EditorBrowsable(EditorBrowsableState.Advanced)]
1129 protected override void OnResize(EventArgs e) {
1133 [EditorBrowsable(EditorBrowsableState.Advanced)]
1134 protected override void OnStyleChanged(EventArgs e) {
1135 base.OnStyleChanged (e);
1138 [EditorBrowsable(EditorBrowsableState.Advanced)]
1139 protected override void OnTextChanged(EventArgs e) {
1140 base.OnTextChanged (e);
1143 [EditorBrowsable(EditorBrowsableState.Advanced)]
1144 protected override void OnVisibleChanged(EventArgs e) {
1145 base.OnVisibleChanged (e);
1148 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
1149 if (base.ProcessCmdKey (ref msg, keyData)) {
1153 // Give our menu a shot
1155 return menu.ProcessCmdKey(ref msg, keyData);
1161 // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
1162 [EditorBrowsable (EditorBrowsableState.Advanced)]
1163 protected override bool ProcessDialogChar(char charCode) {
1164 return base.ProcessDialogChar (charCode);
1167 protected override bool ProcessDialogKey(Keys keyData) {
1168 if ((keyData & Keys.Modifiers) == 0) {
1169 if (keyData == Keys.Enter && accept_button != null) {
1170 accept_button.PerformClick();
1172 } else if (keyData == Keys.Escape && cancel_button != null) {
1173 cancel_button.PerformClick();
1177 return base.ProcessDialogKey(keyData);
1180 protected override bool ProcessKeyPreview(ref Message msg) {
1182 if (ProcessKeyEventArgs(ref msg)) {
1186 return base.ProcessKeyPreview (ref msg);
1189 protected override bool ProcessTabKey(bool forward) {
1190 return SelectNextControl(ActiveControl, forward, true, true, true);
1193 [EditorBrowsable(EditorBrowsableState.Advanced)]
1194 protected override void ScaleCore(float dx, float dy) {
1195 base.ScaleCore (dx, dy);
1198 protected override void Select(bool directed, bool forward) {
1202 base.SelectNextControl(null, forward, true, true, true);
1205 parent = this.ParentForm;
1206 if (parent != null) {
1207 parent.ActiveControl = this;
1213 [EditorBrowsable(EditorBrowsableState.Advanced)]
1214 protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
1215 base.SetBoundsCore (x, y, width, height, specified);
1218 [EditorBrowsable(EditorBrowsableState.Advanced)]
1219 protected override void SetClientSizeCore(int x, int y) {
1220 if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
1221 x = minimum_size.Width;
1222 } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
1223 x = maximum_size.Width;
1226 if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
1227 y = minimum_size.Height;
1228 } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
1229 y = maximum_size.Height;
1232 base.SetClientSizeCore (x, y);
1235 [EditorBrowsable(EditorBrowsableState.Advanced)]
1236 protected override void SetVisibleCore(bool value) {
1237 base.SetVisibleCore (value);
1240 protected override void UpdateDefaultButton() {
1241 base.UpdateDefaultButton ();
1244 [EditorBrowsable(EditorBrowsableState.Advanced)]
1245 protected override void WndProc(ref Message m) {
1246 switch((Msg)m.Msg) {
1247 case Msg.WM_CLOSE: {
1248 CancelEventArgs args = new CancelEventArgs();
1253 OnClosed(EventArgs.Empty);
1255 base.WndProc(ref m);
1261 case Msg.WM_ACTIVATE: {
1262 if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
1263 OnActivated(EventArgs.Empty);
1265 OnDeactivate(EventArgs.Empty);
1270 case Msg.WM_KILLFOCUS: {
1271 base.WndProc(ref m);
1275 case Msg.WM_SETFOCUS: {
1277 if (this.ActiveControl != null) {
1278 ActiveControl.Focus();
1281 base.WndProc(ref m);
1286 case Msg.WM_NCLBUTTONDOWN: {
1287 if (this.menu != null) {
1288 int x = LowOrder ((int) m.LParam.ToInt32 ()) ;
1289 int y = HighOrder ((int) m.LParam.ToInt32 ());
1290 menu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, x, y, 0));
1292 base.WndProc(ref m);
1296 case Msg.WM_NCMOUSEMOVE: {
1297 if (this.menu != null) {
1298 menu.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
1299 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0));
1301 base.WndProc(ref m);
1305 case Msg.WM_NCPAINT: {
1306 if (this.menu != null) {
1307 Point pnt = XplatUI.GetMenuOrigin(window.Handle);
1308 MenuAPI.DrawMenuBar (menu.Handle, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
1311 base.WndProc(ref m);
1315 // This message is only received under Win32
1316 case Msg.WM_NCCALCSIZE: {
1317 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
1319 if ((menu != null) && (m.WParam == (IntPtr)1)) {
1320 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
1323 ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu.menu_handle, ClientSize.Width);
1324 Marshal.StructureToPtr(ncp, m.LParam, true);
1330 case Msg.WM_GETMINMAXINFO: {
1331 XplatUIWin32.MINMAXINFO mmi;
1333 if (m.LParam != IntPtr.Zero) {
1334 mmi = (XplatUIWin32.MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.MINMAXINFO));
1335 default_maximized_bounds = new Rectangle(mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
1336 if (maximized_bounds != Rectangle.Empty) {
1337 mmi.ptMaxSize.x = maximized_bounds.Width;
1338 mmi.ptMaxSize.y = maximized_bounds.Height;
1341 Marshal.StructureToPtr(mmi, m.LParam, false);
1347 base.WndProc (ref m);
1352 #endregion // Protected Instance Methods
1355 public event EventHandler Activated;
1356 public event EventHandler Closed;
1357 public event CancelEventHandler Closing;
1358 public event EventHandler Deactivate;
1359 public event InputLanguageChangedEventHandler InputLanguageChanged;
1360 public event InputLanguageChangingEventHandler InputLanguageChanging;
1361 public event EventHandler Load;
1362 public event EventHandler MaximizedBoundsChanged;
1363 public event EventHandler MaximumSizeChanged;
1364 public event EventHandler MdiChildActivate;
1365 public event EventHandler MenuComplete;
1366 public event EventHandler MenuStart;
1367 public event EventHandler MinimumSizeChanged;
1370 [EditorBrowsable(EditorBrowsableState.Never)]
1371 public new event EventHandler TabIndexChanged;
1372 #endregion // Events