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-2005 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 form_border_style;
48 private bool autoscale;
49 private Size autoscale_base_size;
50 private static Icon default_icon;
51 internal bool is_modal;
52 internal bool end_modal; // This var is being monitored by the application modal loop
53 private bool control_box;
54 private bool minimize_box;
55 private bool maximize_box;
56 private bool help_button;
57 private bool show_in_taskbar;
59 private IButtonControl accept_button;
60 private IButtonControl cancel_button;
61 private DialogResult dialog_result;
62 private FormStartPosition start_position;
64 private Form.ControlCollection owned_forms;
65 private MdiClient mdi_container;
66 private MdiChildContext mdi_child_context;
67 private Form mdi_parent;
68 private bool key_preview;
69 private MainMenu menu;
71 private Size maximum_size;
72 private Size minimum_size;
73 private SizeGripStyle size_grip_style;
74 private Rectangle maximized_bounds;
75 private Rectangle default_maximized_bounds;
76 private double opacity;
77 Color transparency_key;
79 #endregion // Local Variables
81 #region Private & Internal Methods
84 default_icon = (Icon)Locale.GetResource("mono.ico");
86 #endregion // Private & Internal Methods
88 #region Public Classes
89 public new class ControlCollection : Control.ControlCollection {
92 public ControlCollection(Form owner) : base(owner) {
93 this.form_owner = owner;
96 public override void Add(Control value) {
100 ((Form)value).owner=(Form)owner;
103 public override void Remove(Control value) {
104 ((Form)value).owner = null;
108 #endregion // Public Classes
110 #region Public Constructor & Destructor
113 SizeF current_scale = GetAutoScaleSize (DeviceContext, Font);
116 autoscale_base_size = new Size ((int)current_scale.Width, (int) current_scale.Height);
120 dialog_result = DialogResult.None;
121 start_position = FormStartPosition.WindowsDefaultLocation;
122 form_border_style = FormBorderStyle.Sizable;
127 minimum_size = new Size(0, 0);
128 maximum_size = new Size(0, 0);
133 show_in_taskbar = true;
134 ime_mode = ImeMode.NoControl;
137 size_grip_style = SizeGripStyle.Auto;
138 maximized_bounds = Rectangle.Empty;
139 default_maximized_bounds = Rectangle.Empty;
140 owned_forms = new Form.ControlCollection(this);
141 transparency_key = Color.Empty;
143 #endregion // Public Constructor & Destructor
145 #region Public Static Properties
147 public static Form ActiveForm {
151 active = FromHandle(XplatUI.GetActive());
153 if (active != null) {
154 if ( !(active is Form)) {
157 parent = active.Parent;
158 while (parent != null) {
159 if (parent is Form) {
162 parent = parent.Parent;
172 #endregion // Public Static Properties
174 #region Public Instance Properties
176 public IButtonControl AcceptButton {
178 return accept_button;
182 accept_button = value;
186 [MonoTODO("Figure out a way for transparency support in windows")]
188 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
189 public bool AllowTransparency {
199 public bool AutoScale {
211 [EditorBrowsable(EditorBrowsableState.Advanced)]
212 public virtual Size AutoScaleBaseSize {
214 return autoscale_base_size;
218 autoscale_base_size = value;
223 public override bool AutoScroll {
225 return base.AutoScroll;
228 base.AutoScroll = value;
232 public override Color BackColor {
234 return base.BackColor;
237 base.BackColor = value;
242 public IButtonControl CancelButton {
244 return cancel_button;
248 cancel_button = value;
252 [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
254 public Size ClientSize {
256 return base.ClientSize;
260 base.ClientSize = value;
265 public bool ControlBox {
271 if (control_box != value) {
279 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
280 public Rectangle DesktopBounds {
282 return new Rectangle(Location, Size);
291 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
292 public Point DesktopLocation {
303 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
304 public DialogResult DialogResult {
306 return dialog_result;
310 dialog_result = value;
312 if (is_modal && (dialog_result != DialogResult.None)) {
318 [DefaultValue(FormBorderStyle.Sizable)]
320 public FormBorderStyle FormBorderStyle {
322 return form_border_style;
325 form_border_style = value;
326 if (IsHandleCreated) {
327 XplatUI.SetBorderStyle(window.Handle, form_border_style);
333 [DefaultValue(false)]
334 public bool HelpButton {
340 if (help_button != value) {
358 if (IsHandleCreated) {
359 XplatUI.SetIcon(Handle, icon);
366 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
367 public bool IsMdiChild {
369 return mdi_parent != null;
373 [DefaultValue(false)]
374 public bool IsMdiContainer {
376 return mdi_container != null;
380 if (value && mdi_container == null) {
381 mdi_container = new MdiClient();
382 Controls.Add(mdi_container);
383 } else if (!value && mdi_container != null) {
384 Controls.Remove(mdi_container);
385 mdi_container.Dispose();
390 public Form ActiveMdiChild {
394 return (Form) mdi_container.ActiveMdiChild;
399 [EditorBrowsable(EditorBrowsableState.Advanced)]
400 public bool IsRestrictedWindow {
406 [DefaultValue(false)]
407 public bool KeyPreview {
418 public bool MaximizeBox {
423 if (maximize_box != value) {
424 maximize_box = value;
430 [DefaultValue("{Width=0, Height=0}")]
432 [RefreshProperties(RefreshProperties.Repaint)]
433 public Size MaximumSize {
439 if (maximum_size != value) {
440 maximum_size = value;
441 OnMaximumSizeChanged(EventArgs.Empty);
447 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
448 public Form[] MdiChildren {
450 if (mdi_container != null) {
453 form_list = new Form[mdi_container.Controls.Count];
454 for (int i = 0; i < mdi_container.Controls.Count; i++) {
455 form_list[i] = (Form)mdi_container.Controls[i];
464 [MonoTODO("Finish setter")]
466 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
467 public Form MdiParent {
477 if (!value.IsMdiContainer)
478 throw new ArgumentException ();
480 if (mdi_parent != null) {
481 mdi_parent.MdiContainer.Controls.Remove (this);
485 if (mdi_parent != null) {
486 mdi_child_context = new MdiChildContext (this,
487 mdi_parent.MdiContainer);
488 mdi_parent.MdiContainer.Controls.Add (this);
495 internal MdiClient MdiContainer {
496 get { return mdi_container; }
500 public MainMenu Menu {
511 MenuAPI.SetMenuBarWindow (menu.Handle, this);
513 if (IsHandleCreated) {
514 XplatUI.SetMenu (window.Handle, menu.Handle);
517 UpdateBounds (bounds.X, bounds.Y, bounds.Width, bounds.Height, ClientSize.Width, ClientSize.Height -
518 ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu.Handle, ClientSize.Width));
526 public bool MinimizeBox {
531 if (minimize_box != value) {
532 minimize_box = value;
538 [DefaultValue("{Width=0, Height=0}")]
540 [RefreshProperties(RefreshProperties.Repaint)]
541 public Size MinimumSize {
547 if (minimum_size != value) {
548 minimum_size = value;
549 OnMinimumSizeChanged(EventArgs.Empty);
555 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
562 [MonoTODO("Investigate ways to implement opacity")]
564 [TypeConverter(typeof(OpacityConverter))]
565 public double Opacity {
577 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
578 public Form[] OwnedForms {
582 form_list = new Form[owned_forms.Count];
584 for (int i=0; i<owned_forms.Count; i++) {
585 form_list[i] = (Form)owned_forms[i];
593 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
600 if (owner != value) {
602 owner.RemoveOwnedForm(this);
605 owner.AddOwnedForm(this);
607 XplatUI.SetTopmost(this.window.Handle, owner.window.Handle, true);
609 XplatUI.SetTopmost(this.window.Handle, IntPtr.Zero, false);
616 public bool ShowInTaskbar {
618 return show_in_taskbar;
621 if (show_in_taskbar != value) {
622 show_in_taskbar = value;
628 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
640 [MonoTODO("Trigger something when GripStyle is set")]
641 [DefaultValue(SizeGripStyle.Auto)]
642 public SizeGripStyle SizeGripStyle {
644 return size_grip_style;
648 size_grip_style = value;
652 [DefaultValue(FormStartPosition.WindowsDefaultLocation)]
654 public FormStartPosition StartPosition {
656 return start_position;
660 if (start_position == FormStartPosition.WindowsDefaultLocation) { // Only do this if it's not set yet
661 start_position = value;
662 if (IsHandleCreated) {
663 switch(start_position) {
664 case FormStartPosition.CenterParent: {
669 case FormStartPosition.CenterScreen: {
684 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
685 [EditorBrowsable(EditorBrowsableState.Never)]
686 public int TabIndex {
688 return base.TabIndex;
692 base.TabIndex = value;
697 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
698 [EditorBrowsable(EditorBrowsableState.Advanced)]
699 public bool TopLevel {
701 return GetTopLevel();
705 if (!value && IsMdiContainer)
706 throw new ArgumentException ("MDI Container forms must be top level.");
711 [DefaultValue(false)]
712 public bool TopMost {
718 if (topmost != value) {
720 XplatUI.SetTopmost(window.Handle, owner != null ? owner.window.Handle : IntPtr.Zero, value);
725 public Color TransparencyKey {
727 return transparency_key;
731 AllowTransparency = true;
732 transparency_key = value;
733 // TODO: change window attributes; a new driver call
737 [DefaultValue(FormWindowState.Normal)]
738 public FormWindowState WindowState {
740 return XplatUI.GetWindowState(Handle);
744 XplatUI.SetWindowState(Handle, value);
748 #endregion // Public Instance Properties
750 #region Protected Instance Properties
751 [MonoTODO("Need to set start position properly")]
752 protected override CreateParams CreateParams {
754 CreateParams cp = new CreateParams ();
757 cp.ClassName = XplatUI.DefaultClassName;
761 cp.Parent = IntPtr.Zero;
763 // if (start_position == FormStartPosition.WindowsDefaultLocation) {
764 cp.X = unchecked((int)0x80000000);
765 cp.Y = unchecked((int)0x80000000);
773 cp.Style |= (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
776 cp.Style |= (int)WindowStyles.WS_CHILD;
777 cp.Parent = Parent.Handle;
781 switch (FormBorderStyle) {
783 case FormBorderStyle.Fixed3D: {
784 cp.Style |= (int)WindowStyles.WS_CAPTION;
785 cp.ExStyle |= (int)WindowStyles.WS_EX_OVERLAPPEDWINDOW;
789 case FormBorderStyle.FixedDialog: {
790 cp.Style |= (int)WindowStyles.WS_CAPTION;
791 cp.ExStyle |= (int)(WindowStyles.WS_EX_DLGMODALFRAME | WindowStyles.WS_EX_WINDOWEDGE);
795 case FormBorderStyle.FixedSingle: {
796 cp.Style |= (int)WindowStyles.WS_CAPTION;
797 cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE);
801 case FormBorderStyle.FixedToolWindow: {
802 cp.Style |= (int)WindowStyles.WS_CAPTION;
803 cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE | WindowStyles.WS_EX_TOOLWINDOW);
807 case FormBorderStyle.Sizable: {
808 cp.Style |= (int)WindowStyles.WS_OVERLAPPEDWINDOW;
809 cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE);
813 case FormBorderStyle.SizableToolWindow: {
814 cp.Style |= (int)WindowStyles.WS_OVERLAPPEDWINDOW;
815 cp.ExStyle |= (int)(WindowStyles.WS_EX_WINDOWEDGE | WindowStyles.WS_EX_TOOLWINDOW);
822 cp.ExStyle |= (int)WindowStyles.WS_EX_APPWINDOW;
826 cp.Style |= (int)WindowStyles.WS_MAXIMIZEBOX;
830 cp.Style |= (int)WindowStyles.WS_MINIMIZEBOX;
834 cp.Style |= (int)WindowStyles.WS_SYSMENU;
838 cp.ExStyle |= (int)WindowStyles.WS_EX_CONTEXTHELP;
845 protected override ImeMode DefaultImeMode {
847 return ImeMode.NoControl;
851 protected override Size DefaultSize {
853 return new Size (250, 250);
857 protected Rectangle MaximizedBounds {
859 if (maximized_bounds != Rectangle.Empty) {
860 return maximized_bounds;
862 return default_maximized_bounds;
866 maximized_bounds = value;
867 OnMaximizedBoundsChanged(EventArgs.Empty);
870 #endregion // Protected Instance Properties
872 #region Public Static Methods
873 [EditorBrowsable(EditorBrowsableState.Advanced)]
874 public static SizeF GetAutoScaleSize (Font font)
876 return XplatUI.GetAutoScaleSize(font);
879 #endregion // Public Static Methods
881 #region Public Instance Methods
882 internal SizeF GetAutoScaleSize (Graphics g, Font font)
885 // The following constants come from the dotnet mailing list
886 // discussion: http://discuss.develop.com/archives/wa.exe?A2=ind0203A&L=DOTNET&P=R3655
888 // The magic number is "Its almost the length
889 // of the string with a smattering added in
890 // for compat with earlier code".
893 string magic_string = "The quick brown fox jumped over the lazy dog.";
894 double magic_number = 44.549996948242189;
895 float width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
897 return new SizeF (width, font.Height);
900 public void Activate() {
903 // The docs say activate only activates if our app is already active
905 if ((active != null) && (this != active)) {
906 XplatUI.Activate(window.Handle);
910 public void AddOwnedForm(Form ownedForm) {
911 owned_forms.Add(ownedForm);
914 public void Close () {
915 CancelEventArgs args = new CancelEventArgs ();
918 OnClosed (EventArgs.Empty);
924 public void LayoutMdi(MdiLayout value) {
925 if (mdi_container != null) {
926 mdi_container.LayoutMdi(value);
930 public void RemoveOwnedForm(Form ownedForm) {
931 owned_forms.Remove(ownedForm);
934 public void SetDesktopBounds(int x, int y, int width, int height) {
935 DesktopBounds = new Rectangle(x, y, width, height);
938 public void SetDesktopLocation(int x, int y) {
939 DesktopLocation = new Point(x, y);
942 public DialogResult ShowDialog() {
943 return ShowDialog(null);
946 public DialogResult ShowDialog(IWin32Window ownerWin32) {
949 if (ownerWin32 != null) {
950 this.owner = (Form)Control.FromHandle(ownerWin32.Handle);
954 return DialogResult.None;
958 throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
962 // Can't do this, will screw us in the modal loop
963 form_parent_window.Parent = this.owner;
966 previous = Form.ActiveForm;
968 if (!IsHandleCreated) {
972 XplatUI.SetModal(window.Handle, true);
978 Application.ModalRun(this);
982 XplatUI.SetModal(window.Handle, false);
984 if (previous != null) {
985 // Cannot use Activate(), it has a check for the current active window...
986 XplatUI.Activate(previous.window.Handle);
992 public override string ToString() {
993 return GetType().FullName.ToString() + ", Text: " + Text;
995 #endregion // Public Instance Methods
997 #region Protected Instance Methods
998 [MonoTODO("Finish when MDI is more complete")]
999 protected void ActivateMdiChild(Form form) {
1000 OnMdiChildActivate(EventArgs.Empty);
1001 throw new NotImplementedException();
1004 [EditorBrowsable(EditorBrowsableState.Advanced)]
1005 protected override void AdjustFormScrollbars(bool displayScrollbars) {
1006 base.AdjustFormScrollbars (displayScrollbars);
1009 [EditorBrowsable(EditorBrowsableState.Advanced)]
1010 protected void ApplyAutoScaling()
1012 SizeF current_size_f = GetAutoScaleSize (DeviceContext, Font);
1013 Size current_size = new Size ((int) current_size_f.Width, (int) current_size_f.Height);
1015 if (current_size == autoscale_base_size)
1019 // I tried applying the Fudge height factor from:
1020 // http://blogs.msdn.com/mharsh/archive/2004/01/25/62621.aspx
1021 // but it makes things larger without looking better.
1023 Scale (current_size_f.Width / AutoScaleBaseSize.Width,
1024 current_size_f.Height / AutoScaleBaseSize.Height);
1026 AutoScaleBaseSize = current_size;
1029 protected void CenterToParent() {
1037 w = DefaultSize.Width;
1043 h = DefaultSize.Height;
1047 if (parent != null) {
1049 } else if (owner != null) {
1053 if (owner != null) {
1054 this.Location = new Point(ctl.Left + ctl.Width / 2 - w /2, ctl.Top + ctl.Height / 2 - h / 2);
1058 protected void CenterToScreen() {
1066 w = DefaultSize.Width;
1072 h = DefaultSize.Height;
1075 XplatUI.GetDisplaySize(out DisplaySize);
1076 this.Location = new Point(DisplaySize.Width / 2 - w / 2, DisplaySize.Height / 2 - h / 2);
1079 [EditorBrowsable(EditorBrowsableState.Advanced)]
1080 protected override Control.ControlCollection CreateControlsInstance() {
1081 return base.CreateControlsInstance ();
1084 [EditorBrowsable(EditorBrowsableState.Advanced)]
1085 protected override void CreateHandle() {
1086 base.CreateHandle ();
1088 XplatUI.SetIcon(window.Handle, icon);
1092 [EditorBrowsable(EditorBrowsableState.Advanced)]
1093 protected override void DefWndProc(ref Message m) {
1094 base.DefWndProc (ref m);
1097 protected override void Dispose(bool disposing) {
1098 base.Dispose (disposing);
1101 [EditorBrowsable(EditorBrowsableState.Advanced)]
1102 protected virtual void OnActivated(EventArgs e) {
1103 if (Activated != null) {
1108 [EditorBrowsable(EditorBrowsableState.Advanced)]
1109 protected virtual void OnClosed(EventArgs e) {
1110 if (Closed != null) {
1115 [EditorBrowsable(EditorBrowsableState.Advanced)]
1116 protected virtual void OnClosing(System.ComponentModel.CancelEventArgs e) {
1117 if (Closing != null) {
1122 [EditorBrowsable(EditorBrowsableState.Advanced)]
1123 protected override void OnCreateControl() {
1124 base.OnCreateControl ();
1125 if (this.ActiveControl == null) {
1128 // This visible hack is to work around CanSelect always being false if one of the parents
1129 // is not visible; and we by default create Form invisible...
1130 visible = this.is_visible;
1131 this.is_visible = true;
1133 if (SelectNextControl(this, true, true, true, true) == false) {
1137 this.is_visible = visible;
1141 switch (StartPosition) {
1142 case FormStartPosition.CenterScreen:
1143 this.CenterToScreen();
1145 case FormStartPosition.CenterParent:
1146 this.CenterToParent ();
1150 Left = 25 * MdiParent.MdiContainer.ChildrenCreated + 1;
1151 Top = 25 * MdiParent.MdiContainer.ChildrenCreated + 1;
1152 MdiParent.MdiContainer.ChildrenCreated++;
1156 XplatUI.SetMenu(window.Handle, menu.Handle);
1159 OnLoad(EventArgs.Empty);
1161 // Send initial location
1162 OnLocationChanged(EventArgs.Empty);
1165 [EditorBrowsable(EditorBrowsableState.Advanced)]
1166 protected virtual void OnDeactivate(EventArgs e) {
1167 if (Deactivate != null) {
1168 Deactivate(this, e);
1172 [EditorBrowsable(EditorBrowsableState.Advanced)]
1173 protected override void OnFontChanged(EventArgs e) {
1174 base.OnFontChanged (e);
1177 [EditorBrowsable(EditorBrowsableState.Advanced)]
1178 protected override void OnHandleCreated(EventArgs e) {
1179 XplatUI.SetBorderStyle(window.Handle, form_border_style);
1180 base.OnHandleCreated (e);
1183 [EditorBrowsable(EditorBrowsableState.Advanced)]
1184 protected override void OnHandleDestroyed(EventArgs e) {
1185 base.OnHandleDestroyed (e);
1188 [EditorBrowsable(EditorBrowsableState.Advanced)]
1189 protected virtual void OnInputLanguageChanged(InputLanguageChangedEventArgs e) {
1190 if (InputLanguageChanged!=null) {
1191 InputLanguageChanged(this, e);
1195 [EditorBrowsable(EditorBrowsableState.Advanced)]
1196 protected virtual void OnInputLanguageChanging(InputLanguageChangingEventArgs e) {
1197 if (InputLanguageChanging!=null) {
1198 InputLanguageChanging(this, e);
1202 [EditorBrowsable(EditorBrowsableState.Advanced)]
1203 protected virtual void OnLoad(EventArgs e) {
1208 ApplyAutoScaling ();
1213 [EditorBrowsable(EditorBrowsableState.Advanced)]
1214 protected virtual void OnMaximizedBoundsChanged(EventArgs e) {
1215 if (MaximizedBoundsChanged != null) {
1216 MaximizedBoundsChanged(this, e);
1220 [EditorBrowsable(EditorBrowsableState.Advanced)]
1221 protected virtual void OnMaximumSizeChanged(EventArgs e) {
1222 if (MaximumSizeChanged != null) {
1223 MaximumSizeChanged(this, e);
1227 [EditorBrowsable(EditorBrowsableState.Advanced)]
1228 protected virtual void OnMdiChildActivate(EventArgs e) {
1229 if (MdiChildActivate != null) {
1230 MdiChildActivate(this, e);
1234 [EditorBrowsable(EditorBrowsableState.Advanced)]
1235 protected virtual void OnMenuComplete(EventArgs e) {
1236 if (MenuComplete != null) {
1237 MenuComplete(this, e);
1241 [EditorBrowsable(EditorBrowsableState.Advanced)]
1242 protected virtual void OnMenuStart(EventArgs e) {
1243 if (MenuStart != null) {
1248 [EditorBrowsable(EditorBrowsableState.Advanced)]
1249 protected virtual void OnMinimumSizeChanged(EventArgs e) {
1250 if (MinimumSizeChanged != null) {
1251 MinimumSizeChanged(this, e);
1255 [EditorBrowsable(EditorBrowsableState.Advanced)]
1256 protected override void OnPaint (PaintEventArgs pevent) {
1257 base.OnPaint (pevent);
1260 [EditorBrowsable(EditorBrowsableState.Advanced)]
1261 protected override void OnResize(EventArgs e) {
1265 [EditorBrowsable(EditorBrowsableState.Advanced)]
1266 protected override void OnStyleChanged(EventArgs e) {
1267 base.OnStyleChanged (e);
1270 [EditorBrowsable(EditorBrowsableState.Advanced)]
1271 protected override void OnTextChanged(EventArgs e) {
1272 base.OnTextChanged (e);
1275 [EditorBrowsable(EditorBrowsableState.Advanced)]
1276 protected override void OnVisibleChanged(EventArgs e) {
1277 base.OnVisibleChanged (e);
1280 protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
1281 if (base.ProcessCmdKey (ref msg, keyData)) {
1285 // Give our menu a shot
1287 return menu.ProcessCmdKey(ref msg, keyData);
1293 // LAMESPEC - Not documented that Form overrides ProcessDialogChar; class-status showed
1294 [EditorBrowsable (EditorBrowsableState.Advanced)]
1295 protected override bool ProcessDialogChar(char charCode) {
1296 return base.ProcessDialogChar (charCode);
1299 protected override bool ProcessDialogKey(Keys keyData) {
1300 if ((keyData & Keys.Modifiers) == 0) {
1301 if (keyData == Keys.Enter && accept_button != null) {
1302 accept_button.PerformClick();
1304 } else if (keyData == Keys.Escape && cancel_button != null) {
1305 cancel_button.PerformClick();
1309 return base.ProcessDialogKey(keyData);
1312 protected override bool ProcessKeyPreview(ref Message msg) {
1314 if (ProcessKeyEventArgs(ref msg)) {
1318 return base.ProcessKeyPreview (ref msg);
1321 protected override bool ProcessTabKey(bool forward) {
1322 return SelectNextControl(ActiveControl, forward, true, true, true);
1325 [EditorBrowsable(EditorBrowsableState.Advanced)]
1326 protected override void ScaleCore(float dx, float dy) {
1327 base.ScaleCore (dx, dy);
1330 protected override void Select(bool directed, bool forward) {
1334 base.SelectNextControl(null, forward, true, true, true);
1337 parent = this.ParentForm;
1338 if (parent != null) {
1339 parent.ActiveControl = this;
1345 [EditorBrowsable(EditorBrowsableState.Advanced)]
1346 protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) {
1347 base.SetBoundsCore (x, y, width, height, specified);
1350 [EditorBrowsable(EditorBrowsableState.Advanced)]
1351 protected override void SetClientSizeCore(int x, int y) {
1352 if ((minimum_size.Width != 0) && (x < minimum_size.Width)) {
1353 x = minimum_size.Width;
1354 } else if ((maximum_size.Width != 0) && (x > maximum_size.Width)) {
1355 x = maximum_size.Width;
1358 if ((minimum_size.Height != 0) && (y < minimum_size.Height)) {
1359 y = minimum_size.Height;
1360 } else if ((maximum_size.Height != 0) && (y > maximum_size.Height)) {
1361 y = maximum_size.Height;
1364 Rectangle ClientRect = new Rectangle(0, 0, x, y);
1365 Rectangle WindowRect;
1366 CreateParams cp = this.CreateParams;
1368 IntPtr menu_handle = (menu == null)?IntPtr.Zero:menu.Handle;
1370 if (XplatUI.CalculateWindowRect(Handle, ref ClientRect, cp.Style, cp.ExStyle, menu_handle, out WindowRect) )
1371 SetBoundsCore(bounds.X, bounds.Y, WindowRect.Width, WindowRect.Height, BoundsSpecified.Size);
1374 [EditorBrowsable(EditorBrowsableState.Advanced)]
1375 protected override void SetVisibleCore(bool value) {
1376 base.SetVisibleCore (value);
1379 protected override void UpdateDefaultButton() {
1380 base.UpdateDefaultButton ();
1383 [EditorBrowsable(EditorBrowsableState.Advanced)]
1384 protected override void WndProc(ref Message m) {
1386 if (IsMdiChild && mdi_child_context != null &&
1387 mdi_child_context.HandleMessage (ref m)) {
1391 switch((Msg)m.Msg) {
1392 case Msg.WM_CLOSE: {
1393 CancelEventArgs args = new CancelEventArgs();
1398 OnClosed(EventArgs.Empty);
1400 base.WndProc(ref m);
1406 case Msg.WM_ACTIVATE: {
1407 if (m.WParam != (IntPtr)WindowActiveFlags.WA_INACTIVE) {
1408 OnActivated(EventArgs.Empty);
1410 OnDeactivate(EventArgs.Empty);
1415 case Msg.WM_KILLFOCUS: {
1416 base.WndProc(ref m);
1420 case Msg.WM_SETFOCUS: {
1421 if (ActiveControl != null && ActiveControl != this) {
1422 ActiveControl.Focus();
1423 return; // FIXME - do we need to run base.WndProc, even though we just changed focus?
1425 base.WndProc(ref m);
1430 case Msg.WM_NCLBUTTONDOWN: {
1431 if (this.menu != null) {
1432 int x = LowOrder ((int) m.LParam.ToInt32 ()) ;
1433 int y = HighOrder ((int) m.LParam.ToInt32 ());
1434 menu.OnMouseDown(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), mouse_clicks, x, y, 0));
1436 base.WndProc(ref m);
1440 case Msg.WM_NCMOUSEMOVE: {
1441 if (this.menu != null) {
1442 menu.OnMouseMove(this, new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),
1443 mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 0));
1445 base.WndProc(ref m);
1449 case Msg.WM_NCPAINT: {
1450 if (this.menu != null) {
1451 Point pnt = XplatUI.GetMenuOrigin(window.Handle);
1452 MenuAPI.DrawMenuBar (menu.Handle, new Rectangle (pnt.X, pnt.Y, ClientSize.Width, 0));
1455 base.WndProc(ref m);
1459 // This message is only received under Win32
1460 case Msg.WM_NCCALCSIZE: {
1461 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
1463 if ((menu != null) && (m.WParam == (IntPtr)1)) {
1464 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
1467 ncp.rgrc1.top += ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu.menu_handle, ClientSize.Width);
1468 Marshal.StructureToPtr(ncp, m.LParam, true);
1474 case Msg.WM_GETMINMAXINFO: {
1475 XplatUIWin32.MINMAXINFO mmi;
1477 if (m.LParam != IntPtr.Zero) {
1478 mmi = (XplatUIWin32.MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(XplatUIWin32.MINMAXINFO));
1479 default_maximized_bounds = new Rectangle(mmi.ptMaxPosition.x, mmi.ptMaxPosition.y, mmi.ptMaxSize.x, mmi.ptMaxSize.y);
1480 if (maximized_bounds != Rectangle.Empty) {
1481 mmi.ptMaxSize.x = maximized_bounds.Width;
1482 mmi.ptMaxSize.y = maximized_bounds.Height;
1485 Marshal.StructureToPtr(mmi, m.LParam, false);
1491 base.WndProc (ref m);
1496 #endregion // Protected Instance Methods
1499 public event EventHandler Activated;
1500 public event EventHandler Closed;
1501 public event CancelEventHandler Closing;
1502 public event EventHandler Deactivate;
1503 public event InputLanguageChangedEventHandler InputLanguageChanged;
1504 public event InputLanguageChangingEventHandler InputLanguageChanging;
1505 public event EventHandler Load;
1506 public event EventHandler MaximizedBoundsChanged;
1507 public event EventHandler MaximumSizeChanged;
1508 public event EventHandler MdiChildActivate;
1509 public event EventHandler MenuComplete;
1510 public event EventHandler MenuStart;
1511 public event EventHandler MinimumSizeChanged;
1514 [EditorBrowsable(EditorBrowsableState.Never)]
1515 public new event EventHandler TabIndexChanged;
1516 #endregion // Events