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 Color transparency_key;
\r
76 #endregion // Local Variables
78 #region Private & Internal Methods
79 #endregion // Private & Internal Methods
81 #region Public Classes
82 public new class ControlCollection : Control.ControlCollection {
85 public ControlCollection(Form owner) : base(owner) {
86 this.form_owner = owner;
89 public override void Add(Control value) {
90 for (int i=0; i<list.Count; i++) {
92 // Do we need to do anything here?
97 ((Form)value).owner=(Form)owner;
100 public override void Remove(Control value) {
101 ((Form)value).owner = null;
105 #endregion // Public Classes
107 #region Public Constructor & Destructor
112 dialog_result = DialogResult.None;
113 start_position = FormStartPosition.WindowsDefaultLocation;
114 formBorderStyle = FormBorderStyle.Sizable;
118 minimum_size = new Size(0, 0);
119 maximum_size = new Size(0, 0);
124 show_in_taskbar = true;
125 ime_mode = ImeMode.NoControl;
128 size_grip_style = SizeGripStyle.Auto;
129 maximized_bounds = Rectangle.Empty;
130 default_maximized_bounds = Rectangle.Empty;
131 owned_forms = new Form.ControlCollection(this);
132 transparency_key = Color.Empty;
134 #endregion // Public Constructor & Destructor
136 #region Public Static Properties
138 public static Form ActiveForm {
142 active = FromHandle(XplatUI.GetActive());
144 if (active != null) {
145 if ( !(active is Form)) {
148 parent = active.Parent;
149 while (parent != null) {
150 if (parent is Form) {
153 parent = parent.Parent;
163 #endregion // Public Static Properties
165 #region Public Instance Properties
167 public IButtonControl AcceptButton {
169 return accept_button;
173 accept_button = value;
177 [MonoTODO("Figure out a way for transparency support in windows")]
179 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
180 public bool AllowTransparency {
190 public bool AutoScale {
202 [EditorBrowsable(EditorBrowsableState.Advanced)]
203 public virtual Size AutoScaleBaseSize {
205 return autoscale_base_size;
209 autoscale_base_size=value;
214 public override bool AutoScroll {
216 return base.AutoScroll;
219 base.AutoScroll = value;
223 public override Color BackColor {
225 return base.BackColor;
228 base.BackColor = value;
233 public IButtonControl CancelButton {
235 return cancel_button;
239 cancel_button = value;
243 [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
245 public Size ClientSize {
247 return base.ClientSize;
251 base.ClientSize = value;
256 public bool ControlBox {
262 if (control_box != value) {
270 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
271 public Rectangle DesktopBounds {
273 return new Rectangle(Location, Size);
282 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
283 public Point DesktopLocation {
294 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
295 public DialogResult DialogResult {
297 return dialog_result;
301 dialog_result = value;
303 if (is_modal && (dialog_result != DialogResult.None)) {
309 [DefaultValue(FormBorderStyle.Sizable)]
311 public FormBorderStyle FormBorderStyle {
313 return formBorderStyle;
316 formBorderStyle = value;
321 [DefaultValue(false)]
322 public bool HelpButton {
328 if (help_button != value) {
346 XplatUI.SetIcon(Handle, icon);
352 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
353 public bool IsMdiChild {
355 return mdi_parent != null;
359 [DefaultValue(false)]
360 public bool IsMdiContainer {
362 return mdi_container != null;
366 if (value && mdi_container == null) {
367 mdi_container = new MdiClient();
368 Controls.Add(mdi_container);
369 } else if (!value && mdi_container != null) {
370 Controls.Remove(mdi_container);
371 mdi_container.Dispose();
377 [EditorBrowsable(EditorBrowsableState.Advanced)]
378 public bool IsRestrictedWindow {
384 [DefaultValue(false)]
385 public bool KeyPreview {
396 public bool MaximizeBox {
401 if (maximize_box != value) {
402 maximize_box = value;
408 [DefaultValue(typeof(Size), "{Width=0, Height=0}")]
410 [RefreshProperties(RefreshProperties.Repaint)]
411 public Size MaximumSize {
417 if (maximum_size != value) {
418 maximum_size = value;
419 OnMaximumSizeChanged(EventArgs.Empty);
425 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
426 public Form[] MdiChildren {
428 if (mdi_container != null) {
431 form_list = new Form[mdi_container.Controls.Count];
432 for (int i = 0; i < mdi_container.Controls.Count; i++) {
433 form_list[i] = (Form)mdi_container.Controls[i];
442 [MonoTODO("Finish setter")]
444 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
445 public Form MdiParent {
451 if (mdi_parent != null) {
452 mdi_parent.Controls.Remove(this);
456 if (mdi_parent != null) {
457 mdi_parent.Controls.Add(this);
463 public MainMenu Menu {
473 MenuAPI.SetMenuBarWindow (menu.Handle, this);
475 if (IsHandleCreated && menu != null) {
476 XplatUI.SetMenu(window.Handle, menu.Handle);
479 // FIXME - Do we still need this?
480 this.SetBoundsCore(0, 0, 0, 0, BoundsSpecified.None);
482 ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu.Handle, ClientSize.Width);
488 public bool MinimizeBox {
493 if (minimize_box != value) {
494 minimize_box = value;
500 [DefaultValue(typeof(Size), "{Width=0, Height=0}")]
502 [RefreshProperties(RefreshProperties.Repaint)]
503 public Size MinimumSize {
509 if (minimum_size != value) {
510 minimum_size = value;
511 OnMinimumSizeChanged(EventArgs.Empty);
517 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
525 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
526 public Form[] OwnedForms {
530 form_list = new Form[owned_forms.Count];
532 for (int i=0; i<owned_forms.Count; i++) {
533 form_list[i] = (Form)owned_forms[i];
541 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
548 if (owner != value) {
550 owner.RemoveOwnedForm(this);
553 owner.AddOwnedForm(this);
555 XplatUI.SetTopmost(this.window.Handle, owner.window.Handle, true);
557 XplatUI.SetTopmost(this.window.Handle, IntPtr.Zero, false);
564 public bool ShowInTaskbar {
566 return show_in_taskbar;
569 if (show_in_taskbar != value) {
570 show_in_taskbar = value;
576 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
588 [MonoTODO("Trigger something when GripStyle is set")]
589 [DefaultValue(SizeGripStyle.Auto)]
590 public SizeGripStyle SizeGripStyle {
592 return size_grip_style;
596 size_grip_style = value;
600 [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
602 public FormStartPosition StartPosition {
604 return start_position;
608 if (start_position == FormStartPosition.WindowsDefaultLocation) { // Only do this if it's not set yet
609 start_position = value;
610 if (IsHandleCreated) {
611 switch(start_position) {
612 case FormStartPosition.CenterParent: {
617 case FormStartPosition.CenterScreen: {
632 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
633 [EditorBrowsable(EditorBrowsableState.Never)]
634 public int TabIndex {
636 return base.TabIndex;
640 base.TabIndex = value;
645 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
646 [EditorBrowsable(EditorBrowsableState.Advanced)]
647 public bool TopLevel {
649 return GetTopLevel();
657 [DefaultValue(false)]
658 public bool TopMost {
664 if (topmost != value) {
666 XplatUI.SetTopmost(window.Handle, owner != null ? owner.window.Handle : IntPtr.Zero, value);
671 public Color TransparencyKey {
\r
673 return transparency_key;
\r
677 AllowTransparency = true;
\r
678 transparency_key = value;
\r
679 // TODO: change window attributes; a new driver call
\r
683 [DefaultValue(FormWindowState.Normal)]
684 public FormWindowState WindowState {
686 return XplatUI.GetWindowState(window.Handle);
690 XplatUI.SetWindowState(window.Handle, value);
694 #endregion // Public Instance Properties
696 #region Protected Instance Properties
697 [MonoTODO("Need to add MDI support")]
698 protected override CreateParams CreateParams {
702 cp = new CreateParams();
704 cp.Caption = "FormWindow";
705 cp.ClassName = XplatUI.DefaultClassName;
709 cp.Parent = IntPtr.Zero;
710 // if (start_position == FormStartPosition.WindowsDefaultLocation) {
711 cp.X = unchecked((int)0x80000000);
712 cp.Y = unchecked((int)0x80000000);
720 cp.Style = (int)(WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CLIPCHILDREN);
722 switch (FormBorderStyle) {
723 case FormBorderStyle.Fixed3D: {
724 cp.Style |= (int)WindowStyles.WS_CAPTION;
725 cp.ExStyle |= (int)WindowStyles.WS_EX_OVERLAPPEDWINDOW;
729 case FormBorderStyle.FixedDialog: {
730 cp.Style |= (int)WindowStyles.WS_CAPTION;
731 cp.ExStyle |= (int)(WindowStyles.WS_EX_DLGMODALFRAME | WindowStyles.WS_EX_WINDOWEDGE);
735 case FormBorderStyle.FixedSingle: {
736 cp.Style |= (int)WindowStyles.WS_CAPTION;
737 cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE);
741 case FormBorderStyle.FixedToolWindow: {
742 cp.Style |= (int)WindowStyles.WS_CAPTION;
743 cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE | WindowStyles.WS_EX_TOOLWINDOW);
747 case FormBorderStyle.Sizable: {
748 cp.Style |= (int)WindowStyles.WS_OVERLAPPEDWINDOW;
749 cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE);
753 case FormBorderStyle.SizableToolWindow: {
754 cp.Style |= (int)WindowStyles.WS_OVERLAPPEDWINDOW;
755 cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE | WindowStyles.WS_EX_TOOLWINDOW);
761 cp.ExStyle |= (int)WindowStyles.WS_EX_APPWINDOW;
765 cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
769 cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
773 cp.Style |= (int)WindowStyles.WS_SYSMENU;
777 cp.ExStyle |= (int)WindowStyles.WS_EX_CONTEXTHELP;
783 protected override ImeMode DefaultImeMode {
785 return ImeMode.NoControl;
789 protected override Size DefaultSize {
791 return new Size (250, 250);
795 protected Rectangle MaximizedBounds {
797 if (maximized_bounds != Rectangle.Empty) {
798 return maximized_bounds;
800 return default_maximized_bounds;
804 maximized_bounds = value;
805 OnMaximizedBoundsChanged(EventArgs.Empty);
808 #endregion // Protected Instance Properties
810 #region Public Static Methods
811 [MonoTODO("Figure out the math")]
812 [EditorBrowsable(EditorBrowsableState.Advanced)]
813 public static SizeF GetAutoScaleSize(Font font) {
816 result = new SizeF(250, 250);
817 result.Width *= font.SizeInPoints / 12;
818 result.Height *= font.SizeInPoints / 12;
821 #endregion // Public Static Methods
823 #region Public Instance Methods
824 public void Activate() {
827 // The docs say activate only activates if our app is already active
829 if ((active != null) && (this != active)) {
830 XplatUI.Activate(window.Handle);
834 public void AddOwnedForm(Form ownedForm) {
835 owned_forms.Add(ownedForm);
838 public void Close () {
839 CancelEventArgs args = new CancelEventArgs ();
842 OnClosed (EventArgs.Empty);
848 public void LayoutMdi(MdiLayout value) {
849 if (mdi_container != null) {
850 mdi_container.LayoutMdi(value);
854 public void RemoveOwnedForm(Form ownedForm) {
855 owned_forms.Remove(ownedForm);
858 public void SetDesktopBounds(int x, int y, int width, int height) {
859 DesktopBounds = new Rectangle(x, y, width, height);
862 public void SetDesktopLocation(int x, int y) {
863 DesktopLocation = new Point(x, y);
866 public DialogResult ShowDialog() {
867 return ShowDialog(null);
870 public DialogResult ShowDialog(IWin32Window ownerWin32) {
874 Control owner = null;
876 if (ownerWin32 != null) {
877 owner = Control.FromHandle(ownerWin32.Handle);
882 return DialogResult.None;
886 throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
890 // Can't do this, will screw us in the modal loop
891 form_parent_window.Parent = owner;
894 previous = Form.ActiveForm;
896 if (!IsHandleCreated) {
900 XplatUI.SetModal(window.Handle, true);
906 Application.ModalRun(this);
910 XplatUI.SetModal(window.Handle, false);
912 if (previous != null) {
913 // Cannot use Activate(), it has a check for the current active window...
914 XplatUI.Activate(previous.window.Handle);
920 public override string ToString() {
921 return GetType().FullName.ToString() + ", Text: " + Text;
923 #endregion // Public Instance Methods
925 #region Protected Instance Methods
926 [MonoTODO("Finish when MDI is more complete")]
927 protected void ActivateMdiChild(Form form) {
928 OnMdiChildActivate(EventArgs.Empty);
929 throw new NotImplementedException();
932 [EditorBrowsable(EditorBrowsableState.Advanced)]
933 protected override void AdjustFormScrollbars(bool displayScrollbars) {
934 base.AdjustFormScrollbars (displayScrollbars);
937 [EditorBrowsable(EditorBrowsableState.Advanced)]
938 protected void ApplyAutoScaling() {
939 // Hm, not sure what this does
942 protected void CenterToParent() {
950 w = DefaultSize.Width;
956 h = DefaultSize.Height;
960 if (parent != null) {
962 } else if (owner != null) {
967 this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
971 protected void CenterToScreen() {
979 w = DefaultSize.Width;
985 h = DefaultSize.Height;
988 XplatUI.GetDisplaySize(out DisplaySize);
989 this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
992 [EditorBrowsable(EditorBrowsableState.Advanced)]
993 protected override Control.ControlCollection CreateControlsInstance() {
994 return base.CreateControlsInstance ();
997 [EditorBrowsable(EditorBrowsableState.Advanced)]
998 protected override void CreateHandle() {
999 base.CreateHandle ();
1002 [EditorBrowsable(EditorBrowsableState.Advanced)]
1003 protected override void DefWndProc(ref Message m) {
1004 base.DefWndProc (ref m);
1007 protected override void Dispose(bool disposing) {
1008 base.Dispose (disposing);
1011 [EditorBrowsable(EditorBrowsableState.Advanced)]
1012 protected virtual void OnActivated(EventArgs e) {
1013 if (Activated != null) {
1018 [EditorBrowsable(EditorBrowsableState.Advanced)]
1019 protected virtual void OnClosed(EventArgs e) {
1020 if (Closed != null) {
1025 [EditorBrowsable(EditorBrowsableState.Advanced)]
1026 protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
1027 if (Closing != null) {
1032 [EditorBrowsable(EditorBrowsableState.Advanced)]
1033 protected override void OnCreateControl() {
1034 base.OnCreateControl ();
1035 if (this.ActiveControl == null) {
1038 // This visible hack is to work around CanSelect always being false if one of the parents
1039 // is not visible; and we by default create Form invisible...
1040 visible = this.is_visible;
1041 this.is_visible = true;
1043 if (SelectNextControl(this, true, true, true, true) == false) {
1047 this.is_visible = visible;
1051 XplatUI.SetMenu(window.Handle, menu.Handle);
1054 OnLoad(EventArgs.Empty);
1056 // Send initial location
1057 OnLocationChanged(EventArgs.Empty);
1060 [EditorBrowsable(EditorBrowsableState.Advanced)]
1061 protected virtual void OnDeactivate(EventArgs e) {
1062 if (Deactivate != null) {
1063 Deactivate(this, e);
1067 [EditorBrowsable(EditorBrowsableState.Advanced)]
1068 protected override void OnFontChanged(EventArgs e) {
1069 base.OnFontChanged (e);
1072 [EditorBrowsable(EditorBrowsableState.Advanced)]
1073 protected override void OnHandleCreated(EventArgs e) {
1074 base.OnHandleCreated (e);
1077 [EditorBrowsable(EditorBrowsableState.Advanced)]
1078 protected override void OnHandleDestroyed(EventArgs e) {
1079 base.OnHandleDestroyed (e);
1082 [EditorBrowsable(EditorBrowsableState.Advanced)]
1083 protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
1084 if (InputLanguageChanged!=null) {
1085 InputLanguageChanged(this, e);
1089 [EditorBrowsable(EditorBrowsableState.Advanced)]
1090 protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
1091 if (InputLanguageChanging!=null) {
1092 InputLanguageChanging(this, e);
1096 [EditorBrowsable(EditorBrowsableState.Advanced)]
1097 protected virtual void OnLoad(EventArgs e) {
1103 [EditorBrowsable(EditorBrowsableState.Advanced)]
1104 protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
1105 if (MaximizedBoundsChanged != null) {
1106 MaximizedBoundsChanged(this, e);
1110 [EditorBrowsable(EditorBrowsableState.Advanced)]
1111 protected virtual void OnMaximumSizeChanged(EventArgs e) {
1112 if (MaximumSizeChanged != null) {
1113 MaximumSizeChanged(this, e);
1117 [EditorBrowsable(EditorBrowsableState.Advanced)]
1118 protected virtual void OnMdiChildActivate(EventArgs e) {
1119 if (MdiChildActivate != null) {
1120 MdiChildActivate(this, e);
1124 [EditorBrowsable(EditorBrowsableState.Advanced)]
1125 protected virtual void OnMenuComplete(EventArgs e) {
1126 if (MenuComplete != null) {
1127 MenuComplete(this, e);
1131 [EditorBrowsable(EditorBrowsableState.Advanced)]
1132 protected virtual void OnMenuStart(EventArgs e) {
1133 if (MenuStart != null) {
1138 [EditorBrowsable(EditorBrowsableState.Advanced)]
1139 protected virtual void OnMinimumSizeChanged(EventArgs e) {
1140 if (MinimumSizeChanged != null) {
1141 MinimumSizeChanged(this, e);
1145 [EditorBrowsable(EditorBrowsableState.Advanced)]
1146 protected override void OnPaint (PaintEventArgs pevent) {
1147 base.OnPaint (pevent);
1150 [EditorBrowsable(EditorBrowsableState.Advanced)]
1151 protected override void OnResize(EventArgs e) {
1155 [EditorBrowsable(EditorBrowsableState.Advanced)]
1156 protected override void OnStyleChanged(EventArgs e) {
1157 base.OnStyleChanged (e);
1160 [EditorBrowsable(EditorBrowsableState.Advanced)]
1161 protected override void OnTextChanged(EventArgs e) {
1162 base.OnTextChanged (e);
1165 [EditorBrowsable(EditorBrowsableState.Advanced)]
1166 protected override void OnVisibleChanged(EventArgs e) {
1167 base.OnVisibleChanged (e);
1170 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
1171 if (base.ProcessCmdKey (ref msg, keyData)) {
1175 // Give our menu a shot
1177 return menu.ProcessCmdKey(ref msg, keyData);
1183 // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
1184 [EditorBrowsable (EditorBrowsableState.Advanced)]
1185 protected override bool ProcessDialogChar(char charCode) {
1186 return base.ProcessDialogChar (charCode);
1189 protected override bool ProcessDialogKey(Keys keyData) {
1190 if ((keyData & Keys.Modifiers) == 0) {
1191 if (keyData == Keys.Enter && accept_button != null) {
1192 accept_button.PerformClick();
1194 } else if (keyData == Keys.Escape && cancel_button != null) {
1195 cancel_button.PerformClick();
1199 return base.ProcessDialogKey(keyData);
1202 protected override bool ProcessKeyPreview(ref Message msg) {
1204 if (ProcessKeyEventArgs(ref msg)) {
1208 return base.ProcessKeyPreview (ref msg);
1211 protected override bool ProcessTabKey(bool forward) {
1212 return SelectNextControl(ActiveControl, forward, true, true, true);
1215 [EditorBrowsable(EditorBrowsableState.Advanced)]
1216 protected override void ScaleCore(float dx, float dy) {
1217 base.ScaleCore (dx, dy);
1220 protected override void Select(bool directed, bool forward) {
1224 base.SelectNextControl(null, forward, true, true, true);
1227 parent = this.ParentForm;
1228 if (parent != null) {
1229 parent.ActiveControl = this;
1235 [EditorBrowsable(EditorBrowsableState.Advanced)]
1236 protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
1237 base.SetBoundsCore (x, y, width, height, specified);
1240 [EditorBrowsable(EditorBrowsableState.Advanced)]
1241 protected override void SetClientSizeCore(int x, int y) {
1242 if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
1243 x = minimum_size.Width;
1244 } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
1245 x = maximum_size.Width;
1248 if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
1249 y = minimum_size.Height;
1250 } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
1251 y = maximum_size.Height;
1254 base.SetClientSizeCore (x, y);
1257 [EditorBrowsable(EditorBrowsableState.Advanced)]
1258 protected override void SetVisibleCore(bool value) {
1259 base.SetVisibleCore (value);
1262 protected override void UpdateDefaultButton() {
1263 base.UpdateDefaultButton ();
1266 [EditorBrowsable(EditorBrowsableState.Advanced)]
1267 protected override void WndProc(ref Message m) {
1268 switch((Msg)m.Msg) {
1269 case Msg.WM_CLOSE: {
1270 CancelEventArgs args = new CancelEventArgs();
1275 OnClosed(EventArgs.Empty);
1277 base.WndProc(ref m);
1283 case Msg.WM_ACTIVATE: {
1284 if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
1285 OnActivated(EventArgs.Empty);
1287 OnDeactivate(EventArgs.Empty);
1292 case Msg.WM_KILLFOCUS: {
1293 base.WndProc(ref m);
1297 case Msg.WM_SETFOCUS: {
1299 if (this.ActiveControl != null) {
1300 ActiveControl.Focus();
1303 base.WndProc(ref m);
1308 case Msg.WM_NCLBUTTONDOWN: {
1309 if (this.menu != null) {
1310 int x = LowOrder ((int) m.LParam.ToInt32 ()) ;
1311 int y = HighOrder ((int) m.LParam.ToInt32 ());
1312 menu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, x, y, 0));
1314 base.WndProc(ref m);
1318 case Msg.WM_NCMOUSEMOVE: {
1319 if (this.menu != null) {
1320 menu.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
1321 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0));
1323 base.WndProc(ref m);
1327 case Msg.WM_NCPAINT: {
1328 if (this.menu != null) {
1329 Point pnt = XplatUI.GetMenuOrigin(window.Handle);
1330 MenuAPI.DrawMenuBar (menu.Handle, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
1333 base.WndProc(ref m);
1337 // This message is only received under Win32
1338 case Msg.WM_NCCALCSIZE: {
1339 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
1341 if ((menu != null) && (m.WParam == (IntPtr)1)) {
1342 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
1345 ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu.menu_handle, ClientSize.Width);
1346 Marshal.StructureToPtr(ncp, m.LParam, true);
1352 case Msg.WM_GETMINMAXINFO: {
1353 XplatUIWin32.MINMAXINFO mmi;
1355 if (m.LParam != IntPtr.Zero) {
1356 mmi = (XplatUIWin32.MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.MINMAXINFO));
1357 default_maximized_bounds = new Rectangle(mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
1358 if (maximized_bounds != Rectangle.Empty) {
1359 mmi.ptMaxSize.x = maximized_bounds.Width;
1360 mmi.ptMaxSize.y = maximized_bounds.Height;
1363 Marshal.StructureToPtr(mmi, m.LParam, false);
1369 base.WndProc (ref m);
1374 #endregion // Protected Instance Methods
1377 public event EventHandler Activated;
1378 public event EventHandler Closed;
1379 public event CancelEventHandler Closing;
1380 public event EventHandler Deactivate;
1381 public event InputLanguageChangedEventHandler InputLanguageChanged;
1382 public event InputLanguageChangingEventHandler InputLanguageChanging;
1383 public event EventHandler Load;
1384 public event EventHandler MaximizedBoundsChanged;
1385 public event EventHandler MaximumSizeChanged;
1386 public event EventHandler MdiChildActivate;
1387 public event EventHandler MenuComplete;
1388 public event EventHandler MenuStart;
1389 public event EventHandler MinimumSizeChanged;
1392 [EditorBrowsable(EditorBrowsableState.Never)]
1393 public new event EventHandler TabIndexChanged;
1394 #endregion // Events