示例#1
0
        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();
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
            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);
            }
示例#4
0
        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;
        }
示例#5
0
        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);
        }
示例#6
0
        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();
                }
            }
        }
示例#7
0
        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 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 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 NET_2_0
			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);
			}
#endif

			return maximize_this;
		}