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 1001 1002
|
// 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) 2005 Novell, Inc. (http://www.novell.com)
//
// Authors:
// Peter Bartok pbartok@novell.com
//
//
// NOT COMPLETE
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
namespace System.Windows.Forms {
[ComVisible (true)]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
[DesignTimeVisible(false)]
[ToolboxItem(false)]
public sealed class MdiClient : Control {
#region Local Variables
private int mdi_created;
private ImplicitHScrollBar hbar;
private ImplicitVScrollBar vbar;
private SizeGrip sizegrip;
private int hbar_value;
private int vbar_value;
private bool lock_sizing;
private bool initializing_scrollbars;
private int prev_bottom;
private bool setting_windowstates = false;
internal ArrayList mdi_child_list;
private string form_text;
private bool setting_form_text;
private Form active_child;
#endregion // Local Variables
#region Public Classes
[ComVisible (false)]
public new class ControlCollection : Control.ControlCollection {
private MdiClient owner;
public ControlCollection(MdiClient owner) : base(owner) {
this.owner = owner;
}
public override void Add(Control value) {
if ((value is Form) == false || !(((Form)value).IsMdiChild)) {
throw new ArgumentException("Form must be MdiChild");
}
owner.mdi_child_list.Add (value);
base.Add (value);
// newest member is the active one
Form form = (Form) value;
owner.ActiveMdiChild = form;
}
public override void Remove(Control value)
{
Form form = value as Form;
if (form != null) {
MdiWindowManager wm = form.WindowManager as MdiWindowManager;
if (wm != null) {
form.Closed -= wm.form_closed_handler;
}
}
owner.mdi_child_list.Remove (value);
base.Remove (value);
}
}
#endregion // Public Classes
#region Public Constructors
public MdiClient()
{
mdi_child_list = new ArrayList ();
BackColor = SystemColors.AppWorkspace;
Dock = DockStyle.Fill;
SetStyle (ControlStyles.Selectable, false);
}
#endregion // Public Constructors
internal void SendFocusToActiveChild ()
{
Form active = this.ActiveMdiChild;
if (active == null) {
ParentForm.SendControlFocus (this);
} else {
active.SendControlFocus (active);
ParentForm.ActiveControl = active;
}
}
internal bool HorizontalScrollbarVisible {
get { return hbar != null && hbar.Visible; }
}
internal bool VerticalScrollbarVisible {
get { return vbar != null && vbar.Visible; }
}
internal void SetParentText(bool text_changed)
{
if (setting_form_text)
return;
setting_form_text = true;
if (text_changed)
form_text = ParentForm.Text;
if (ParentForm.ActiveMaximizedMdiChild == null) {
ParentForm.Text = form_text;
} else {
string childText = ParentForm.ActiveMaximizedMdiChild.form.Text;
if (childText.Length > 0) {
ParentForm.Text = form_text + " - [" + ParentForm.ActiveMaximizedMdiChild.form.Text + "]";
} else {
ParentForm.Text = form_text;
}
}
setting_form_text = false;
}
internal override void OnPaintBackgroundInternal (PaintEventArgs pe)
{
if (BackgroundImage != null)
return;
if (Parent == null || Parent.BackgroundImage == null)
return;
Parent.PaintControlBackground (pe);
}
internal Form ParentForm {
get { return (Form) Parent; }
}
protected override Control.ControlCollection CreateControlsInstance ()
{
return new MdiClient.ControlCollection (this);
}
protected override void WndProc(ref Message m) {
switch ((Msg)m.Msg) {
case Msg.WM_NCPAINT:
PaintEventArgs pe = XplatUI.PaintEventStart (ref m, Handle, false);
Rectangle clip;
clip = new Rectangle (0, 0, Width, Height);
ControlPaint.DrawBorder3D (pe.Graphics, clip, Border3DStyle.Sunken);
XplatUI.PaintEventEnd (ref m, Handle, false);
m.Result = IntPtr.Zero;
return ;
}
base.WndProc (ref m);
}
protected override void OnResize (EventArgs e)
{
base.OnResize (e);
if (Parent != null && Parent.IsHandleCreated)
XplatUI.InvalidateNC (Parent.Handle);
// Should probably make this into one loop
SizeScrollBars ();
ArrangeWindows ();
}
protected override void ScaleControl (SizeF factor, BoundsSpecified specified)
{
// Never change the MdiClient's location
specified &= ~BoundsSpecified.Location;
base.ScaleControl (factor, specified);
}
[System.ComponentModel.EditorBrowsable (EditorBrowsableState.Never)]
protected override void ScaleCore (float dx, float dy)
{
base.ScaleCore (dx, dy);
}
protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
{
base.SetBoundsCore (x, y, width, height, specified);
}
#region Public Instance Properties
[Localizable(true)]
public override System.Drawing.Image BackgroundImage {
get {
return base.BackgroundImage;
}
set {
base.BackgroundImage = value;
}
}
[EditorBrowsable (EditorBrowsableState.Never)]
[Browsable (false)]
public override ImageLayout BackgroundImageLayout {
get {
return base.BackgroundImageLayout;
}
set {
base.BackgroundImageLayout = value;
}
}
public Form [] MdiChildren {
get {
if (mdi_child_list == null)
return new Form [0];
return (Form []) mdi_child_list.ToArray (typeof (Form));
}
}
#endregion // Public Instance Properties
#region Protected Instance Properties
protected override CreateParams CreateParams {
get {
CreateParams result = base.CreateParams;
result.ExStyle |= (int) WindowExStyles.WS_EX_CLIENTEDGE;
return result;
}
}
#endregion // Protected Instance Properties
#region Public Instance Methods
public void LayoutMdi (MdiLayout value) {
// Don't forget to always call ArrangeIconicWindows
ArrangeIconicWindows (true);
switch (value) {
case MdiLayout.Cascade: {
int i = 0;
for (int c = Controls.Count - 1; c >= 0; c--) {
Form form = (Form) Controls [c];
if (form.WindowState == FormWindowState.Minimized)
continue;
if (form.WindowState == FormWindowState.Maximized)
form.WindowState = FormWindowState.Normal;
form.Width = System.Convert.ToInt32 (ClientSize.Width * 0.8);
form.Height = Math.Max (
System.Convert.ToInt32 (ClientSize.Height * 0.8),
SystemInformation.MinimumWindowSize.Height + 2);
int l = 22 * i;
int t = 22 * i;
if (i != 0 && (l + form.Width > ClientSize.Width || t + form.Height > ClientSize.Height)) {
i = 0;
l = 22 * i;
t = 22 * i;
}
form.Left = l;
form.Top = t;
i++;
}
break;
}
case MdiLayout.TileHorizontal:
case MdiLayout.TileVertical: {
// First count number of windows to tile
int total = 0;
// And space used by iconic windows
int clientHeight = ClientSize.Height;
for (int i = 0; i < Controls.Count; i++) {
Form form = Controls [i] as Form;
if (form == null)
continue;
if (!form.Visible)
continue;
if (form.WindowState == FormWindowState.Maximized)
form.WindowState = FormWindowState.Normal;
else if (form.WindowState == FormWindowState.Minimized) {
if (form.Bounds.Top < clientHeight)
clientHeight = form.Bounds.Top;
continue;
}
total++;
}
if (total <= 0)
return;
// Calculate desired height and width
Size newSize;
Size offset;
if (value == MdiLayout.TileHorizontal) {
newSize = new Size(ClientSize.Width, clientHeight / total);
offset = new Size (0, newSize.Height);
} else {
newSize = new Size(ClientSize.Width / total, clientHeight);
offset = new Size (newSize.Width, 0);
}
// Loop again and set the size and location.
Point nextLocation = Point.Empty;
for (int i = 0; i < Controls.Count; i++) {
Form form = Controls [i] as Form;
if (form == null)
continue;
if (!form.Visible)
continue;
if (form.WindowState == FormWindowState.Minimized)
continue;
form.Size = newSize;
form.Location = nextLocation;
nextLocation += offset;
}
break;
}
}
}
#endregion // Public Instance Methods
#region Protected Instance Methods
#endregion // Protected Instance Methods
internal void SizeScrollBars ()
{
if (lock_sizing)
return;
if (!IsHandleCreated)
return;
if (Controls.Count == 0 || ((Form) Controls [0]).WindowState == FormWindowState.Maximized) {
if (hbar != null)
hbar.Visible = false;
if (vbar != null)
vbar.Visible = false;
if (sizegrip != null)
sizegrip.Visible = false;
return;
}
int right = 0;
int left = 0;
int top = 0;
int bottom = 0;
foreach (Form child in Controls) {
if (!child.Visible)
continue;
if (child.Right > right)
right = child.Right;
if (child.Left < left) {
left = child.Left;
}
if (child.Bottom > bottom)
bottom = child.Bottom;
if (child.Top < 0) {
top = child.Top;
}
}
int available_width = ClientSize.Width;
int available_height = ClientSize.Height;
bool need_hbar = false;
bool need_vbar = false;
if (right - left > available_width || left < 0) {
need_hbar = true;
available_height -= SystemInformation.HorizontalScrollBarHeight;
}
if (bottom - top > available_height || top < 0) {
need_vbar = true;
available_width -= SystemInformation.VerticalScrollBarWidth;
if (!need_hbar && (right - left > available_width || left < 0)) {
need_hbar = true;
available_height -= SystemInformation.HorizontalScrollBarHeight;
}
}
if (need_hbar) {
if (hbar == null) {
hbar = new ImplicitHScrollBar ();
Controls.AddImplicit (hbar);
}
hbar.Visible = true;
CalcHBar (left, right, need_vbar);
} else if (hbar != null)
hbar.Visible = false;
if (need_vbar) {
if (vbar == null) {
vbar = new ImplicitVScrollBar ();
Controls.AddImplicit (vbar);
}
vbar.Visible = true;
CalcVBar (top, bottom, need_hbar);
} else if (vbar != null)
vbar.Visible = false;
if (need_hbar && need_vbar) {
if (sizegrip == null) {
sizegrip = new SizeGrip (this.ParentForm);
Controls.AddImplicit (sizegrip);
}
sizegrip.Location = new Point (hbar.Right, vbar.Bottom);
sizegrip.Visible = true;
XplatUI.SetZOrder (sizegrip.Handle, vbar.Handle, false, false);
} else if (sizegrip != null) {
sizegrip.Visible = false;
}
XplatUI.InvalidateNC (Handle);
}
private void CalcHBar (int left, int right, bool vert_vis)
{
initializing_scrollbars = true;
hbar.Left = 0;
hbar.Top = ClientRectangle.Bottom - hbar.Height;
hbar.Width = ClientRectangle.Width - (vert_vis ? SystemInformation.VerticalScrollBarWidth : 0);
hbar.LargeChange = 50;
hbar.Minimum = Math.Min (left, 0);
hbar.Maximum = Math.Max (right - ClientSize.Width + 51 + (vert_vis ? SystemInformation.VerticalScrollBarWidth : 0), 0);
hbar.Value = 0;
hbar_value = 0;
hbar.ValueChanged += new EventHandler (HBarValueChanged);
XplatUI.SetZOrder (hbar.Handle, IntPtr.Zero, true, false);
initializing_scrollbars = false;
}
private void CalcVBar (int top, int bottom, bool horz_vis)
{
initializing_scrollbars = true;
vbar.Top = 0;
vbar.Left = ClientRectangle.Right - vbar.Width;
vbar.Height = ClientRectangle.Height - (horz_vis ? SystemInformation.HorizontalScrollBarHeight : 0);
vbar.LargeChange = 50;
vbar.Minimum = Math.Min (top, 0);
vbar.Maximum = Math.Max (bottom - ClientSize.Height + 51 + (horz_vis ? SystemInformation.HorizontalScrollBarHeight : 0), 0);
vbar.Value = 0;
vbar_value = 0;
vbar.ValueChanged += new EventHandler (VBarValueChanged);
XplatUI.SetZOrder (vbar.Handle, IntPtr.Zero, true, false);
initializing_scrollbars = false;
}
private void HBarValueChanged (object sender, EventArgs e)
{
if (initializing_scrollbars)
return;
if (hbar.Value == hbar_value)
return;
lock_sizing = true;
try {
int diff = hbar_value - hbar.Value;
foreach (Form child in Controls) {
child.Left += diff;
}
} finally {
lock_sizing = false;
}
hbar_value = hbar.Value;
}
private void VBarValueChanged (object sender, EventArgs e)
{
if (initializing_scrollbars)
return;
if (vbar.Value == vbar_value)
return;
lock_sizing = true;
try {
int diff = vbar_value - vbar.Value;
foreach (Form child in Controls) {
child.Top += diff;
}
} finally {
lock_sizing = false;
}
vbar_value = vbar.Value;
}
private void ArrangeWindows ()
{
if (!IsHandleCreated)
return;
int change = 0;
if (prev_bottom != -1)
change = Bottom - prev_bottom;
foreach (Control c in Controls) {
Form child = c as Form;
if (c == null || !child.Visible)
continue;
MdiWindowManager wm = child.WindowManager as MdiWindowManager;
if (wm.GetWindowState () == FormWindowState.Maximized)
child.Bounds = wm.MaximizedBounds;
if (wm.GetWindowState () == FormWindowState.Minimized) {
child.Top += change;
}
}
prev_bottom = Bottom;
}
internal void ArrangeIconicWindows (bool rearrange_all)
{
Rectangle rect = Rectangle.Empty;
lock_sizing = true;
foreach (Form form in Controls) {
if (form.WindowState != FormWindowState.Minimized)
continue;
MdiWindowManager wm = (MdiWindowManager) form.WindowManager;
if (wm.IconicBounds != Rectangle.Empty && !rearrange_all) {
if (form.Bounds != wm.IconicBounds)
form.Bounds = wm.IconicBounds;
continue;
}
bool success = true;
int startx, starty, currentx, currenty;
rect.Size = wm.IconicSize;
startx = 0;
starty = ClientSize.Height - rect.Height;
currentx = startx;
currenty = starty;
do {
rect.X = currentx;
rect.Y = currenty;
success = true;
foreach (Form form2 in Controls) {
if (form2 == form || form2.window_state != FormWindowState.Minimized)
continue;
if (form2.Bounds.IntersectsWith(rect)) {
success = false;
break;
}
}
if (!success) {
currentx += rect.Width;
if (currentx + rect.Width > Right) {
currentx = startx;
currenty -= rect.Height;
}
}
} while (!success);
wm.IconicBounds = rect;
form.Bounds = wm.IconicBounds;
}
lock_sizing = false;
}
internal void ChildFormClosed (Form form)
{
FormWindowState closed_form_windowstate = form.WindowState;
form.Visible = false;
Controls.Remove (form);
if (Controls.Count == 0) {
((MdiWindowManager) form.window_manager).RaiseDeactivate ();
} else if (closed_form_windowstate == FormWindowState.Maximized) {
Form current = (Form) Controls [0];
current.WindowState = FormWindowState.Maximized;
ActivateChild(current);
}
if (Controls.Count == 0) {
XplatUI.RequestNCRecalc (Parent.Handle);
ParentForm.PerformLayout ();
// If we closed the last child, unmerge the menus.
// If it's not the last child, the menu will be unmerged
// when another child takes focus.
MenuStrip parent_menu = form.MdiParent.MainMenuStrip;
if (parent_menu != null)
if (parent_menu.IsCurrentlyMerged)
ToolStripManager.RevertMerge (parent_menu);
}
SizeScrollBars ();
SetParentText (false);
form.Dispose();
}
internal void ActivateNextChild ()
{
if (Controls.Count < 1)
return;
if (Controls.Count == 1 && Controls[0] == ActiveMdiChild)
return;
Form front = (Form) Controls [0];
Form form = (Form) Controls [1];
ActivateChild (form);
front.SendToBack ();
}
internal void ActivatePreviousChild ()
{
if (Controls.Count <= 1)
return;
Form back = (Form) Controls [Controls.Count - 1];
ActivateChild (back);
}
internal void ActivateChild (Form form)
{
if (Controls.Count < 1)
return;
if (ParentForm.is_changing_visible_state > 0)
return;
Form current = (Form) Controls [0];
bool raise_deactivate = ParentForm.ActiveControl == current;
// We want to resize the new active form before it is
// made active to avoid flickering. Can't do it in the
// normal way (form.WindowState = Maximized) since it's not
// active yet and everything would just return to before.
// We also won't suspend layout, this way the layout will
// happen before the form is made active (and in many cases
// before it is visible, which avoids flickering as well).
MdiWindowManager wm = (MdiWindowManager)form.WindowManager;
if (current.WindowState == FormWindowState.Maximized && form.WindowState != FormWindowState.Maximized && form.Visible) {
FormWindowState old_state = form.window_state;
SetWindowState (form, old_state, FormWindowState.Maximized, true);
wm.was_minimized = form.window_state == FormWindowState.Minimized;
form.window_state = FormWindowState.Maximized;
SetParentText (false);
}
form.BringToFront ();
form.SendControlFocus (form);
SetWindowStates (wm);
if (current != form) {
form.has_focus = false;
if (current.IsHandleCreated)
XplatUI.InvalidateNC (current.Handle);
if (form.IsHandleCreated)
XplatUI.InvalidateNC (form.Handle);
if (raise_deactivate) {
MdiWindowManager current_wm = (MdiWindowManager) current.window_manager;
current_wm.RaiseDeactivate ();
}
}
active_child = (Form) Controls [0];
if (active_child.Visible) {
bool raise_activated = ParentForm.ActiveControl != active_child;
ParentForm.ActiveControl = active_child;
if (raise_activated) {
MdiWindowManager active_wm = (MdiWindowManager) active_child.window_manager;
active_wm.RaiseActivated ();
}
}
}
internal override IntPtr AfterTopMostControl ()
{
// order of scrollbars:
// top = vertical
// sizegrid
// bottom = horizontal
if (hbar != null && hbar.Visible)
return hbar.Handle;
// no need to check for sizegrip since it will only
// be visible if hbar is visible.
if (vbar != null && vbar.Visible)
return vbar.Handle;
return base.AfterTopMostControl ();
}
internal bool SetWindowStates (MdiWindowManager wm)
{
/*
MDI WindowState behaviour:
- If the active window is maximized, all other maximized windows are normalized.
- If a normal window gets focus and the original active window was maximized,
the normal window gets maximized and the original window gets normalized.
- If a minimized window gets focus and the original window was maximized,
the minimzed window gets maximized and the original window gets normalized.
If the ex-minimized window gets deactivated, it will be normalized.
*/
Form form = wm.form;
if (setting_windowstates) {
return false;
}
if (!form.Visible)
return false;
bool is_active = wm.IsActive;
bool maximize_this = false;
if (!is_active){
return false;
}
ArrayList minimize_these = new ArrayList ();
ArrayList normalize_these = new ArrayList ();
setting_windowstates = true;
foreach (Form frm in mdi_child_list) {
if (frm == form) {
continue;
} else if (!frm.Visible){
continue;
}
if (frm.WindowState == FormWindowState.Maximized && is_active) {
maximize_this = true;
if (((MdiWindowManager) frm.window_manager).was_minimized) {
minimize_these.Add (frm);
} else {
normalize_these.Add (frm);
}
}
}
if (maximize_this && form.WindowState != FormWindowState.Maximized) {
wm.was_minimized = form.window_state == FormWindowState.Minimized;
form.WindowState = FormWindowState.Maximized;
}
foreach (Form frm in minimize_these)
frm.WindowState = FormWindowState.Minimized;
foreach (Form frm in normalize_these)
frm.WindowState = FormWindowState.Normal;
SetParentText (false);
XplatUI.RequestNCRecalc (ParentForm.Handle);
XplatUI.RequestNCRecalc (Handle);
SizeScrollBars ();
setting_windowstates = false;
if (form.MdiParent.MainMenuStrip != null)
form.MdiParent.MainMenuStrip.RefreshMdiItems ();
// Implicit menu strip merging
// - When child is activated
// - Parent form must have a MainMenuStrip
// - Find the first menustrip on the child
// - Merge
MenuStrip parent_menu = form.MdiParent.MainMenuStrip;
if (parent_menu != null) {
if (parent_menu.IsCurrentlyMerged)
ToolStripManager.RevertMerge (parent_menu);
MenuStrip child_menu = LookForChildMenu (form);
if (form.WindowState != FormWindowState.Maximized)
RemoveControlMenuItems (wm);
if (form.WindowState == FormWindowState.Maximized) {
bool found = false;
foreach (ToolStripItem tsi in parent_menu.Items) {
if (tsi is MdiControlStrip.SystemMenuItem) {
(tsi as MdiControlStrip.SystemMenuItem).MdiForm = form;
found = true;
} else if (tsi is MdiControlStrip.ControlBoxMenuItem) {
(tsi as MdiControlStrip.ControlBoxMenuItem).MdiForm = form;
found = true;
}
}
if (!found) {
parent_menu.SuspendLayout ();
parent_menu.Items.Insert (0, new MdiControlStrip.SystemMenuItem (form));
parent_menu.Items.Add (new MdiControlStrip.ControlBoxMenuItem (form, MdiControlStrip.ControlBoxType.Close));
parent_menu.Items.Add (new MdiControlStrip.ControlBoxMenuItem (form, MdiControlStrip.ControlBoxType.Max));
parent_menu.Items.Add (new MdiControlStrip.ControlBoxMenuItem (form, MdiControlStrip.ControlBoxType.Min));
parent_menu.ResumeLayout ();
}
}
if (child_menu != null)
ToolStripManager.Merge (child_menu, parent_menu);
}
return maximize_this;
}
private MenuStrip LookForChildMenu (Control parent)
{
foreach (Control c in parent.Controls) {
if (c is MenuStrip)
return (MenuStrip)c;
if (c is ToolStripContainer || c is ToolStripPanel) {
MenuStrip ms = LookForChildMenu (c);
if (ms != null)
return ms;
}
}
return null;
}
internal void RemoveControlMenuItems (MdiWindowManager wm)
{
Form form = wm.form;
MenuStrip parent_menu = form.MdiParent.MainMenuStrip;
// Only remove the items if the form requesting still owns the menu items
if (parent_menu != null) {
parent_menu.SuspendLayout ();
for (int i = parent_menu.Items.Count - 1; i >= 0; i--) {
if (parent_menu.Items[i] is MdiControlStrip.SystemMenuItem) {
if ((parent_menu.Items[i] as MdiControlStrip.SystemMenuItem).MdiForm == form)
parent_menu.Items.RemoveAt (i);
} else if (parent_menu.Items[i] is MdiControlStrip.ControlBoxMenuItem) {
if ((parent_menu.Items[i] as MdiControlStrip.ControlBoxMenuItem).MdiForm == form)
parent_menu.Items.RemoveAt (i);
}
}
parent_menu.ResumeLayout ();
}
}
internal void SetWindowState (Form form, FormWindowState old_window_state, FormWindowState new_window_state, bool is_activating_child)
{
bool mdiclient_layout;
MdiWindowManager wm = (MdiWindowManager) form.window_manager;
if (!is_activating_child && new_window_state == FormWindowState.Maximized && !wm.IsActive) {
ActivateChild (form);
return;
}
if (old_window_state == FormWindowState.Normal)
wm.NormalBounds = form.Bounds;
if (SetWindowStates (wm))
return;
if (old_window_state == new_window_state)
return;
mdiclient_layout = old_window_state == FormWindowState.Maximized || new_window_state == FormWindowState.Maximized;
switch (new_window_state) {
case FormWindowState.Minimized:
ArrangeIconicWindows (false);
break;
case FormWindowState.Maximized:
form.Bounds = wm.MaximizedBounds;
break;
case FormWindowState.Normal:
form.Bounds = wm.NormalBounds;
break;
}
wm.UpdateWindowDecorations (new_window_state);
form.ResetCursor ();
if (mdiclient_layout)
Parent.PerformLayout ();
XplatUI.RequestNCRecalc (Parent.Handle);
XplatUI.RequestNCRecalc (form.Handle);
if (!setting_windowstates)
SizeScrollBars ();
}
internal int ChildrenCreated {
get { return mdi_created; }
set { mdi_created = value; }
}
internal Form ActiveMdiChild {
get {
if (ParentForm != null && !ParentForm.Visible)
return null;
if (Controls.Count < 1)
return null;
if (!ParentForm.IsHandleCreated)
return null;
if (!ParentForm.has_been_visible)
return null;
if (!ParentForm.Visible)
return active_child;
active_child = null;
for (int i = 0; i < Controls.Count; i++) {
if (Controls [i].Visible) {
active_child = (Form) Controls [i];
break;
}
}
return active_child;
}
set {
ActivateChild (value);
}
}
internal void ActivateActiveMdiChild ()
{
if (ParentForm.is_changing_visible_state > 0)
return;
for (int i = 0; i < Controls.Count; i++) {
if (Controls [i].Visible) {
ActivateChild ((Form) Controls [i]);
return;
}
}
}
}
}
|