-
Notifications
You must be signed in to change notification settings - Fork 12
/
Form.cs
3131 lines (2635 loc) · 83.4 KB
/
Form.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2004-2006 Novell, Inc.
//
// Authors:
// Peter Bartok pbartok@novell.com
//
// NOT COMPLETE
using System;
using System.Drawing;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Collections;
using System.Runtime.InteropServices;
using System.Threading;
namespace System.Windows.Forms {
[DesignerCategory("Form")]
[DesignTimeVisible(false)]
[Designer("System.Windows.Forms.Design.FormDocumentDesigner, " + Consts.AssemblySystem_Design, typeof(IRootDesigner))]
[DefaultEvent("Load")]
[ClassInterface (ClassInterfaceType.AutoDispatch)]
[InitializationEvent ("Load")]
[ComVisible (true)]
[ToolboxItemFilter ("System.Windows.Forms.Control.TopLevel")]
[ToolboxItem(false)]
public partial class Form : ContainerControl {
#region Local Variables
internal bool closing;
private bool closed;
FormBorderStyle form_border_style;
private bool is_active;
private bool autoscale;
private Size clientsize_set;
private Size autoscale_base_size;
private bool allow_transparency;
private static Icon default_icon;
internal bool is_modal;
internal FormWindowState window_state;
private bool control_box;
private bool minimize_box;
private bool maximize_box;
private bool help_button;
private bool show_in_taskbar;
private bool topmost;
private IButtonControl accept_button;
private IButtonControl cancel_button;
private DialogResult dialog_result;
private FormStartPosition start_position;
private Form owner;
private Form.ControlCollection owned_forms;
private MdiClient mdi_container;
internal InternalWindowManager window_manager;
private Form mdi_parent;
private bool key_preview;
private MainMenu menu;
private Icon icon;
private Size maximum_size;
private Size minimum_size;
private Rectangle maximized_bounds;
private Rectangle default_maximized_bounds;
private double opacity;
internal ApplicationContext context;
Color transparency_key;
private bool is_loaded;
internal int is_changing_visible_state;
internal bool has_been_visible;
private bool shown_raised;
private bool close_raised;
private bool is_clientsize_set;
internal bool suppress_closing_events;
internal bool waiting_showwindow; // for XplatUIX11
private bool is_minimizing;
private bool show_icon = true;
private MenuStrip main_menu_strip;
private bool right_to_left_layout;
private Rectangle restore_bounds;
private bool autoscale_base_size_set;
internal ArrayList disabled_by_showdialog = new ArrayList();
internal static ArrayList modal_dialogs = new ArrayList();
#endregion // Local Variables
#region Private & Internal Methods
static Form ()
{
default_icon = ResourceImageLoader.GetIcon ("mono.ico");
}
internal bool IsLoaded {
get { return is_loaded; }
}
internal bool IsActive {
get {
return is_active;
}
set {
if (is_active == value || IsRecreating) {
return;
}
is_active = value;
if (is_active) {
Application.AddForm (this);
OnActivated (EventArgs.Empty);
} else {
OnDeactivate (EventArgs.Empty);
}
}
}
// warning: this is only hooked up when an mdi container is created.
private void ControlAddedHandler (object sender, ControlEventArgs e)
{
if (mdi_container != null) {
mdi_container.SendToBack ();
}
}
// Convenience method for fire BOTH OnClosing and OnFormClosing events
// Returns the value of Cancel, so true means the Close was cancelled,
// and you shouldn't close the form.
internal bool FireClosingEvents (CloseReason reason, bool cancel)
{
CancelEventArgs cea = new CancelEventArgs (cancel);
this.OnClosing (cea);
FormClosingEventArgs fcea = new FormClosingEventArgs (reason, cea.Cancel);
this.OnFormClosing (fcea);
return fcea.Cancel;
}
// Convenience method for fire BOTH OnClosed and OnFormClosed events
private void FireClosedEvents (CloseReason reason)
{
this.OnClosed (EventArgs.Empty);
this.OnFormClosed (new FormClosedEventArgs (reason));
}
internal override Size GetPreferredSizeCore (Size proposedSize)
{
Size retsize = Size.Empty;
foreach (Control child in Controls) {
Size child_preferred_size;
if (child.AutoSize)
child_preferred_size = child.PreferredSize;
else
child_preferred_size = child.ExplicitBounds.Size;
int child_right = child.Bounds.X + child_preferred_size.Width;
int child_bottom = child.Bounds.Y + child_preferred_size.Height;
if (child.Dock == DockStyle.Fill) {
if (child_right > retsize.Width)
retsize.Width = child_right;
}
else if (child.Dock != DockStyle.Top && child.Dock != DockStyle.Bottom && child_right > retsize.Width)
retsize.Width = child_right + child.Margin.Right;
if (child.Dock == DockStyle.Fill) {
if (child_bottom > retsize.Height)
retsize.Height = child_bottom;
}
else if (child.Dock != DockStyle.Left && child.Dock != DockStyle.Right && child_bottom > retsize.Height)
retsize.Height = child_bottom + child.Margin.Bottom;
}
if (retsize == Size.Empty) { // no child controls
retsize.Height += this.Padding.Top;
retsize.Width += this.Padding.Left;
}
retsize.Height += this.Padding.Bottom;
retsize.Width += this.Padding.Right;
return SizeFromClientSize (retsize);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected override Rectangle GetScaledBounds (Rectangle bounds, SizeF factor, BoundsSpecified specified)
{
if ((specified & BoundsSpecified.Width) == BoundsSpecified.Width) {
int border = Size.Width - ClientSize.Width;
bounds.Width = (int)Math.Round ((bounds.Width - border) * factor.Width) + border;
}
if ((specified & BoundsSpecified.Height) == BoundsSpecified.Height) {
int border = Size.Height - ClientSize.Height;
bounds.Height = (int)Math.Round ((bounds.Height - border) * factor.Height) + border;
}
return bounds;
}
protected override bool ProcessMnemonic (char charCode)
{
return base.ProcessMnemonic (charCode);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected override void ScaleControl (SizeF factor, BoundsSpecified specified)
{
base.ScaleControl (factor, specified);
}
internal void OnActivatedInternal ()
{
OnActivated (EventArgs.Empty);
}
internal void OnDeactivateInternal ()
{
OnDeactivate (EventArgs.Empty);
}
internal override void UpdateWindowText ()
{
if (!IsHandleCreated) {
return;
}
if (shown_raised) {
/* we need to call .SetWindowStyle here instead of just .Text
because the presence/absence of Text (== "" or not) can cause
other window style things to appear/disappear */
XplatUI.SetWindowStyle (window.Handle, CreateParams);
}
XplatUI.Text (Handle, Text.Replace (Environment.NewLine, string.Empty));
}
internal void SelectActiveControl ()
{
if (this.IsMdiContainer) {
mdi_container.SendFocusToActiveChild ();
return;
}
if (this.ActiveControl == null) {
bool visible;
// This visible hack is to work around CanSelect always being false if one of the parents
// is not visible; and we by default create Form invisible...
visible = this.is_visible;
this.is_visible = true;
if (SelectNextControl (this, true, true, true, true) == false) {
Select (this);
}
this.is_visible = visible;
} else {
Select (ActiveControl);
}
}
private new void UpdateSizeGripVisible ()
{
// Following link explains when to show size grip:
// http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=138687&SiteID=1
// if SizeGripStyle.Auto, only shown if form is shown using ShowDialog and is sizable
// if SizeGripStyle.Show, only shown if form is sizable
bool show = false;
switch (size_grip_style) {
case SizeGripStyle.Auto:
show = is_modal && (form_border_style == FormBorderStyle.Sizable || form_border_style == FormBorderStyle.SizableToolWindow);
break;
case SizeGripStyle.Hide:
show = false;
break;
case SizeGripStyle.Show:
show = (form_border_style == FormBorderStyle.Sizable || form_border_style == FormBorderStyle.SizableToolWindow);
break;
}
if (!show) {
if (size_grip != null && size_grip.Visible)
size_grip.Visible = false;
} else {
if (size_grip == null) {
size_grip = new SizeGrip (this);
size_grip.Virtual = true;
size_grip.FillBackground = false;
}
size_grip.Visible = true;
}
}
internal void ChangingParent (Control new_parent)
{
if (IsMdiChild) {
return;
}
bool recreate_necessary = false;
if (new_parent == null) {
window_manager = null;
} else if (new_parent is MdiClient) {
window_manager = new MdiWindowManager (this, (MdiClient) new_parent);
} else {
window_manager = new FormWindowManager (this);
recreate_necessary = true;
}
if (recreate_necessary) {
if (IsHandleCreated) {
if (new_parent != null && new_parent.IsHandleCreated) {
RecreateHandle ();
} else {
DestroyHandle ();
}
}
} else {
if (IsHandleCreated) {
IntPtr new_handle = IntPtr.Zero;
if (new_parent != null && new_parent.IsHandleCreated) {
new_handle = new_parent.Handle;
}
XplatUI.SetParent (Handle, new_handle);
}
}
if (window_manager != null) {
window_manager.UpdateWindowState (window_state, window_state, true);
}
}
internal override bool FocusInternal (bool skip_check)
{
if (IsMdiChild) {
// MS always creates handles when Focus () is called for mdi clients.
if (!IsHandleCreated)
CreateHandle ();
}
return base.FocusInternal (skip_check);
}
#endregion // Private & Internal Methods
#region Public Classes
[ComVisible (false)]
public new class ControlCollection : Control.ControlCollection {
Form form_owner;
public ControlCollection(Form owner) : base(owner) {
this.form_owner = owner;
}
public override void Add(Control value) {
if (Contains (value))
return;
AddToList (value);
((Form)value).owner=form_owner;
}
public override void Remove(Control value) {
((Form)value).owner = null;
base.Remove (value);
}
}
#endregion // Public Classes
#region Public Constructor & Destructor
public Form ()
{
SizeF current_scale = GetAutoScaleSize (Font);
autoscale = true;
autoscale_base_size = new Size ((int)Math.Round (current_scale.Width), (int)Math.Round(current_scale.Height));
allow_transparency = false;
closing = false;
is_modal = false;
dialog_result = DialogResult.None;
start_position = FormStartPosition.WindowsDefaultLocation;
form_border_style = FormBorderStyle.Sizable;
window_state = FormWindowState.Normal;
key_preview = false;
opacity = 1D;
menu = null;
icon = default_icon;
minimum_size = Size.Empty;
maximum_size = Size.Empty;
clientsize_set = Size.Empty;
control_box = true;
minimize_box = true;
maximize_box = true;
help_button = false;
show_in_taskbar = true;
is_visible = false;
is_toplevel = true;
size_grip_style = SizeGripStyle.Auto;
maximized_bounds = Rectangle.Empty;
default_maximized_bounds = Rectangle.Empty;
owned_forms = new Form.ControlCollection(this);
transparency_key = Color.Empty;
CreateDockPadding ();
InternalClientSize = new Size (this.Width - (SystemInformation.FrameBorderSize.Width * 2), this.Height - (SystemInformation.FrameBorderSize.Height * 2) - SystemInformation.CaptionHeight);
restore_bounds = Bounds;
}
#endregion // Public Constructor & Destructor
#region Public Static Properties
public static Form ActiveForm {
get {
Control active;
active = FromHandle(XplatUI.GetActive());
if (active != null) {
if ( !(active is Form)) {
Control parent;
parent = active.Parent;
while (parent != null) {
if (parent is Form) {
return (Form)parent;
}
parent = parent.Parent;
}
} else {
return (Form)active;
}
}
return null;
}
}
#endregion // Public Static Properties
#region Public Instance Properties
[DefaultValue(null)]
public IButtonControl AcceptButton {
get {
return accept_button;
}
set {
if (accept_button != null)
accept_button.NotifyDefault (false);
accept_button = value;
if (accept_button != null)
accept_button.NotifyDefault (true);
CheckAcceptButton ();
}
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool AllowTransparency {
get {
return allow_transparency;
}
set {
if (value == allow_transparency) {
return;
}
allow_transparency = value;
if (value) {
if (IsHandleCreated) {
if ((XplatUI.SupportsTransparency() & TransparencySupport.Set) != 0) {
XplatUI.SetWindowTransparency(Handle, Opacity, TransparencyKey);
}
} else {
UpdateStyles(); // Remove the WS_EX_LAYERED style
}
}
}
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[Obsolete ("This property has been deprecated in favor of AutoScaleMode.")]
[MWFCategory("Layout")]
public bool AutoScale {
get {
return autoscale;
}
set {
if (value)
AutoScaleMode = AutoScaleMode.None;
autoscale = value;
}
}
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Localizable(true)]
[Browsable(false)]
public virtual Size AutoScaleBaseSize {
get {
return autoscale_base_size;
}
[MonoTODO ("Setting this is probably unintentional and can cause Forms to be improperly sized. See http://www.mono-project.com/FAQ:_Winforms#My_forms_are_sized_improperly for details.")]
set {
autoscale_base_size = value;
autoscale_base_size_set = true;
}
}
[Localizable(true)]
public override bool AutoScroll {
get {
return base.AutoScroll;
}
set {
base.AutoScroll = value;
}
}
internal bool ShouldSerializeAutoScroll ()
{
return this.AutoScroll != false;
}
[Browsable (true)]
[EditorBrowsable (EditorBrowsableState.Always)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
public override bool AutoSize {
get { return base.AutoSize; }
set {
if (base.AutoSize != value) {
base.AutoSize = value;
PerformLayout (this, "AutoSize");
}
}
}
internal bool ShouldSerializeAutoSize ()
{
return this.AutoSize != false;
}
[Browsable (true)]
[Localizable (true)]
[DefaultValue (AutoSizeMode.GrowOnly)]
public AutoSizeMode AutoSizeMode {
get { return base.GetAutoSizeMode (); }
set {
if (base.GetAutoSizeMode () != value) {
if (!Enum.IsDefined (typeof (AutoSizeMode), value))
throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for AutoSizeMode", value));
base.SetAutoSizeMode (value);
PerformLayout (this, "AutoSizeMode");
}
}
}
[Browsable (true)]
[EditorBrowsable (EditorBrowsableState.Always)]
public override AutoValidate AutoValidate {
get { return base.AutoValidate; }
set { base.AutoValidate = value; }
}
public override Color BackColor {
get {
/* we don't let parents override our
default background color for forms.
this fixes the default color for mdi
children. */
if (background_color.IsEmpty)
return DefaultBackColor;
else
return background_color;
}
set {
base.BackColor = value;
}
}
[DefaultValue(null)]
public IButtonControl CancelButton {
get {
return cancel_button;
}
set {
cancel_button = value;
if (cancel_button != null && cancel_button.DialogResult == DialogResult.None)
cancel_button.DialogResult = DialogResult.Cancel;
}
}
// new property so we can change the DesignerSerializationVisibility
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Localizable(true)]
public new Size ClientSize {
get { return base.ClientSize; }
set {
is_clientsize_set = true;
base.ClientSize = value;
}
}
[DefaultValue(true)]
[MWFCategory("Window Style")]
public bool ControlBox {
get {
return control_box;
}
set {
if (control_box != value) {
control_box = value;
UpdateStyles();
}
}
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Rectangle DesktopBounds {
get {
return new Rectangle(Location, Size);
}
set {
Bounds = value;
}
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Point DesktopLocation {
get {
return Location;
}
set {
Location = value;
}
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public DialogResult DialogResult {
get {
return dialog_result;
}
set {
if (value < DialogResult.None || value > DialogResult.No)
throw new InvalidEnumArgumentException ("value", (int) value,
typeof (DialogResult));
dialog_result = value;
if (dialog_result != DialogResult.None && is_modal)
RaiseCloseEvents (false, false); // .Net doesn't send WM_CLOSE here.
}
}
[DefaultValue(FormBorderStyle.Sizable)]
[DispId(-504)]
[MWFCategory("Appearance")]
public FormBorderStyle FormBorderStyle {
get {
return form_border_style;
}
set {
form_border_style = value;
if (window_manager == null) {
if (IsHandleCreated) {
XplatUI.SetBorderStyle(window.Handle, form_border_style);
}
} else {
window_manager.UpdateBorderStyle (value);
}
Size current_client_size = ClientSize;
UpdateStyles();
if (this.IsHandleCreated) {
this.Size = InternalSizeFromClientSize (current_client_size);
XplatUI.InvalidateNC (this.Handle);
} else if (is_clientsize_set) {
this.Size = InternalSizeFromClientSize (current_client_size);
}
}
}
[DefaultValue(false)]
[MWFCategory("Window Style")]
public bool HelpButton {
get {
return help_button;
}
set {
if (help_button != value) {
help_button = value;
UpdateStyles();
}
}
}
[Localizable(true)]
[AmbientValue(null)]
[MWFCategory("Window Style")]
public Icon Icon {
get {
return icon;
}
set {
if (value == null)
value = default_icon;
if (icon == value)
return;
icon = value;
if (IsHandleCreated)
XplatUI.SetIcon (Handle, icon);
}
}
internal bool ShouldSerializeIcon ()
{
return this.Icon != default_icon;
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsMdiChild {
get {
return mdi_parent != null;
}
}
[DefaultValue(false)]
[MWFCategory("Window Style")]
public bool IsMdiContainer {
get {
return mdi_container != null;
}
set {
if (value && mdi_container == null) {
mdi_container = new MdiClient ();
Controls.Add(mdi_container);
ControlAdded += new ControlEventHandler (ControlAddedHandler);
mdi_container.SendToBack ();
mdi_container.SetParentText (true);
} else if (!value && mdi_container != null) {
Controls.Remove(mdi_container);
mdi_container = null;
}
}
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Form ActiveMdiChild {
get {
if (!IsMdiContainer)
return null;
return (Form) mdi_container.ActiveMdiChild;
}
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public bool IsRestrictedWindow {
get {
return false;
}
}
[DefaultValue(false)]
public bool KeyPreview {
get {
return key_preview;
}
set {
key_preview = value;
}
}
[DefaultValue (null)]
[TypeConverter (typeof (ReferenceConverter))]
public MenuStrip MainMenuStrip {
get { return this.main_menu_strip; }
set {
if (this.main_menu_strip != value) {
this.main_menu_strip = value;
this.main_menu_strip.RefreshMdiItems ();
}
}
}
[EditorBrowsable (EditorBrowsableState.Never)]
[Browsable (false)]
public new Padding Margin {
get { return base.Margin; }
set { base.Margin = value; }
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Form[] MdiChildren {
get {
if (mdi_container != null)
return mdi_container.MdiChildren;
else
return new Form[0];
}
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Form MdiParent {
get {
return mdi_parent;
}
set {
if (value == mdi_parent)
return;
if (value != null && !value.IsMdiContainer)
throw new ArgumentException ("Form that was specified to be "
+ "the MdiParent for this form is not an MdiContainer.");
if (mdi_parent != null) {
mdi_parent.MdiContainer.Controls.Remove (this);
}
if (value != null) {
mdi_parent = value;
if (window_manager == null) {
window_manager = new MdiWindowManager (this, mdi_parent.MdiContainer);
}
mdi_parent.MdiContainer.Controls.Add (this);
mdi_parent.MdiContainer.Controls.SetChildIndex (this, 0);
if (IsHandleCreated)
RecreateHandle ();
} else if (mdi_parent != null) {
mdi_parent = null;
// Create a new window manager
window_manager = null;
FormBorderStyle = form_border_style;
if (IsHandleCreated)
RecreateHandle ();
}
is_toplevel = mdi_parent == null;
}
}
internal MdiClient MdiContainer {
get { return mdi_container; }
}
internal InternalWindowManager WindowManager {
get { return window_manager; }
}
[Browsable (false)]
[TypeConverter (typeof (ReferenceConverter))]
[DefaultValue(null)]
[MWFCategory("Window Style")]
public MainMenu Menu {
get {
return menu;
}
set {
if (menu != value) {
menu = value;
if (menu != null && !IsMdiChild) {
menu.SetForm (this);
if (IsHandleCreated) {
XplatUI.SetMenu (window.Handle, menu);
}
if (clientsize_set != Size.Empty) {
SetClientSizeCore(clientsize_set.Width, clientsize_set.Height);
} else {
UpdateBounds (bounds.X, bounds.Y, bounds.Width, bounds.Height, ClientSize.Width, ClientSize.Height -
ThemeEngine.Current.CalcMenuBarSize (DeviceContext, menu, ClientSize.Width));
}
} else
UpdateBounds ();
// UIA Framework Event: Menu Changed
OnUIAMenuChanged (EventArgs.Empty);
}
}
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public MainMenu MergedMenu {
get {
if (!IsMdiChild || window_manager == null)
return null;
return ((MdiWindowManager) window_manager).MergedMenu;
}
}
// This is the menu in display and being used because of merging this can
// be different then the menu that is actually assosciated with the form
internal MainMenu ActiveMenu {
get {
if (IsMdiChild)
return null;
if (IsMdiContainer && mdi_container.Controls.Count > 0 &&
((Form) mdi_container.Controls [0]).WindowState == FormWindowState.Maximized) {
MdiWindowManager wm = (MdiWindowManager) ((Form) mdi_container.Controls [0]).WindowManager;
return wm.MaximizedMenu;
}
Form amc = ActiveMdiChild;
if (amc == null || amc.Menu == null)
return menu;
return amc.MergedMenu;
}
}
internal MdiWindowManager ActiveMaximizedMdiChild {
get {
Form child = ActiveMdiChild;
if (child == null)
return null;
if (child.WindowManager == null || child.window_state != FormWindowState.Maximized)
return null;
return (MdiWindowManager) child.WindowManager;
}
}
[Localizable(true)]
[RefreshProperties(RefreshProperties.Repaint)]
[MWFCategory("Layout")]
public override Size MinimumSize {
get {
return minimum_size;
}
set {
if (minimum_size != value) {
minimum_size = value;
// If this is bigger than the max, adjust the max
if (!maximum_size.IsEmpty) {
if (minimum_size.Width >= maximum_size.Width)
maximum_size.Width = minimum_size.Width;
if (minimum_size.Height >= maximum_size.Height)
maximum_size.Height = minimum_size.Height;
}
if ((Size.Width < value.Width) || (Size.Height < value.Height)) {
Size = new Size(Math.Max(Size.Width, value.Width), Math.Max(Size.Height, value.Height));
}
OnMinimumSizeChanged(EventArgs.Empty);
if (IsHandleCreated) {
XplatUI.SetWindowMinMax(Handle, maximized_bounds, minimum_size, maximum_size);
}
}
}
}