/// <summary> /// Constructor /// </summary> /// <param name="form">form</param> /// <param name="allowedDock">allowed dock mode</param> /// <param name="identifier">identifier of the form info</param> internal DockableFormInfo(Form form, zAllowedDock allowedDock, Guid identifier) { if (identifier == Guid.Empty) { throw new ArgumentException("Err"); } _identifier = identifier; _dockableForm = form; _allowedDock = allowedDock; _button = new TabButton(form); _button.ExplicitDisposing += OnButtonDisposing; form.GotFocus += OnFormGotFocus; }
/// <summary> /// End mouse action /// </summary> /// <param name="cancel">cancel</param> private void EndMouseAction(bool cancel) { _isMouseDownInTabButton = false; if (_isMovingTabButton) { if (_isDraggingTabButton) { EndButtonDrag(cancel); } _isMovingTabButton = false; _buttonDisplaced = null; } IsMouseDownInScrollBackButton = false; IsMouseDownInScrollNextButton = false; }
/// <summary> /// Remove button /// </summary> /// <param name="button">button</param> /// <returns>true if button was removed</returns> protected bool RemoveButton(TabButton button) { if (_buttons.Contains(button) == false) { return(false); } // If the selected index is the last button index, must decrement the selected index // to prevent index out of range exception after the count of buttons is updated. if (SelectedIndex > 0 && SelectedIndex == ButtonsCount - 1) { SelectedIndex--; } _buttons.Remove(button); OnButtonRemoved(button); button.TextChanged -= OnButtonTextChanged; button.ExplicitDisposing -= OnButtonDisposing; if (_buttons.Count == 0) { if (Disposing == false && IsDisposed == false) { using (Graphics graphics = CreateGraphics()) { UpdatePositions(graphics, false); } } } else { _updatePositionsOnDraw = true; } if (Disposing == false && IsDisposed == false) { UpdateSize(); Invalidate(); } return(true); }
/// <summary> /// Occurs when the mouse id down /// </summary> /// <param name="e">event argument</param> protected override void OnMouseDown(MouseEventArgs e) { _isMouseDownInTabButton = false; _isMovingTabButton = false; if (IsMouseOverScrollBackButton) { IsMouseDownInScrollBackButton = true; ScrollBack(); } else if (IsMouseOverScrollNextButton) { IsMouseDownInScrollNextButton = true; ScrollNext(); } else if (_captionButtonsBounds.Contains(e.Location)) { int captionIndex = ButtonsRenderer.GetCaptionButtonIndex(_captionButtonsBounds, e.Location); OnMouseDownInCaptionButton(captionIndex, e); } else { int index = 0; TabButton button = GetButtonFromPoint(e.Location, out index); if (button != null) { SelectedIndex = index; Invalidate(); _isMouseDownInTabButton = e.Button == MouseButtons.Left; OnMouseDownInTabButton(button); } } base.OnMouseDown(e); }
/// <summary> /// Occurs when tab button is added /// </summary> /// <param name="button">button added</param> protected override void OnButtonAdded(TabButton button) { EventHandler<FormEventArgs> handler = FormAdded; if (handler != null) { FormEventArgs args = new FormEventArgs((Form)button.Page); handler(this, args); } }
/// <summary> /// Occurs when tab button is added /// </summary> /// <param name="button">button added</param> protected override void OnButtonAdded(TabButton button) { EventHandler<FormEventArgs> handler = FormAdded; if (handler != null) { DockableFormInfo info = GetPageInfo((Form)button.Page); FormEventArgs args = new FormEventArgs(info.DockableForm, info.Id); handler(this, args); } }
/// <summary> /// Checks if can scroll next /// </summary> /// <param name="lastButton">last button</param> /// <param name="scrollNextBounds">scroll-next bounds</param> /// <returns>true if can scroll next</returns> internal override bool CanScrollNext(TabButton lastButton, Rectangle scrollNextBounds) { return(lastButton.Left + lastButton.Width > scrollNextBounds.Left); }
/// <summary> /// Can undo the displacement of the next button (the next button was displaced before) /// </summary> /// <param name="displacedButton">displaced button</param> /// <param name="selectedButton">selected button</param> /// <param name="mouseLocation">current mouse location</param> /// <returns>true if can undo</returns> internal override bool CanUndoDisplaceNext(TabButton displacedButton, TabButton selectedButton, Point mouseLocation) { return(true); }
/// <summary> /// Begin button drag /// </summary> /// <param name="selected">selected button</param> /// <param name="mousePosition">mouse position</param> /// <param name="cursor">cursor</param> /// <returns>true if button drag is started</returns> protected virtual bool BeginButtonDrag(TabButton selected, Point mousePosition, ref Cursor cursor) { return false; }
/// <summary> /// Insert a button /// </summary> /// <param name="button">button to insert</param> /// <param name="insertIndex">zero based insert index</param> protected void InsertButton(TabButton button, int insertIndex) { if (button != null && insertIndex >= 0 && insertIndex <= _buttons.Count) { _buttons.Insert(insertIndex, button); OnButtonAdded(button); button.TextChanged += OnButtonTextChanged; button.ExplicitDisposing += OnButtonDisposing; SelectedIndex = insertIndex; if (_buttons.Count == 1) { using (Graphics graphics = CreateGraphics()) { UpdatePositions(graphics, true); } } else { _updatePositionsOnDraw = true; } UpdateSize(); Invalidate(); } }
/// <summary> /// Occurs when mouse cursor is moved over the panel /// </summary> /// <param name="e">event argument</param> protected override void OnMouseMove(MouseEventArgs e) { Cursor cursor = Cursors.Default; if (_isMouseDownInTabButton && e.Button == MouseButtons.Left) { cursor = Cursors.Hand; if (_isMovingTabButton) { TabButton selected = _buttons[SelectedIndex]; if (selected.Contains(e.Location) == false) { if (_isDraggingTabButton) { ContinueButtonDrag(e.Location, ref cursor); } else { int index = -1; TabButton underMouse = GetButtonFromPoint(e.Location, true, out index); if (underMouse != null) { bool displace = false; if (underMouse == _buttonDisplaced) { if (index < SelectedIndex) { displace = ButtonsRenderer.CanUndoDisplaceBack(underMouse, selected, e.Location); } else if (index > SelectedIndex) { displace = ButtonsRenderer.CanUndoDisplaceNext(underMouse, selected, e.Location); } } _buttonDisplaced = underMouse; if (displace) { _buttons[index] = selected; _buttons[SelectedIndex] = underMouse; _updatePositionsOnDraw = true; SelectedIndex = index; } } else { _isDraggingTabButton = BeginButtonDrag(selected, e.Location, ref cursor); } } } } else { _isMovingTabButton = _buttons[SelectedIndex].Contains(e.Location); _isDraggingTabButton = false; } } else if (GetButtonFromPoint(e.Location) != null) { cursor = Cursors.Hand; } CheckIfIsMouseOverScrollButtons(e.Location); if (IsMouseOverScrollBackButton && _firstShownButtonIndex > 0) { cursor = Cursors.Hand; } else if (IsMouseOverScrollNextButton && _canScrollNext) { cursor = Cursors.Hand; } int captionIndex = ButtonsRenderer.GetCaptionButtonIndex(_captionButtonsBounds, e.Location); if (captionIndex < 0 || captionIndex >= ButtonsCount) { captionIndex = -1; } else { cursor = Cursors.Hand; } if (_captionButtonIndexUnderMouse != captionIndex) { _captionButtonIndexUnderMouse = captionIndex; OnMouseMoveOverCaptionButton(captionIndex, e); Invalidate(); } int buttonIndex = -1; TabButton buttonUnderMouse = GetButtonFromPoint(e.Location, false, out buttonIndex); if (buttonUnderMouse != null) { OnMouseMoveOverTabButton(buttonUnderMouse); } Cursor = cursor; base.OnMouseMove(e); }
/// <summary> /// Occurs when mouse button was moved over a tab button /// </summary> /// <param name="buttonUnderMouse">button under mouse</param> protected override void OnMouseMoveOverTabButton(TabButton buttonUnderMouse) { EventHandler<PreviewEventArgs> handler = ShowPreview; if (handler != null) { PreviewEventArgs args = new PreviewEventArgs(new Point(buttonUnderMouse.Left, buttonUnderMouse.Top), (Form)buttonUnderMouse.Page); handler(this, args); } }
/// <summary> /// Add button /// </summary> /// <param name="button">button</param> protected void AddButton(TabButton button) { InsertButton(button, _buttons.Count); }
/// <summary> /// Occurs when tab button is added /// </summary> /// <param name="button">button added</param> protected virtual void OnButtonAdded(TabButton button) { }
/// <summary> /// Occurs when tab button is removed /// </summary> /// <param name="button">button removed</param> protected virtual void OnButtonRemoved(TabButton button) { }
/// <summary> /// Occurs when mouse button was pressed while the cursor was over a tab button /// </summary> /// <param name="buttonUnderMouse">button under mouse</param> protected virtual void OnMouseDownInTabButton(TabButton buttonUnderMouse) { }
/// <summary> /// Occurs when mouse button was moved over a tab button /// </summary> /// <param name="buttonUnderMouse">button under mouse</param> protected virtual void OnMouseMoveOverTabButton(TabButton buttonUnderMouse) { }
/// <summary> /// Checks if can scroll next /// </summary> /// <param name="lastButton">last button</param> /// <param name="scrollNextBounds">scroll-next bounds</param> /// <returns>true if can scroll next</returns> internal override bool CanScrollNext(TabButton lastButton, Rectangle scrollNextBounds) { return lastButton.Top + lastButton.Height > scrollNextBounds.Top; }
/// <summary> /// Can undo the displacement of the next button (the next button was displaced before) /// </summary> /// <param name="displacedButton">displaced button</param> /// <param name="selectedButton">selected button</param> /// <param name="mouseLocation">current mouse location</param> /// <returns>true if can undo</returns> internal override bool CanUndoDisplaceNext(TabButton displacedButton, TabButton selectedButton, Point mouseLocation) { return true; }
/// <summary> /// Checks if can scroll next /// </summary> /// <param name="lastButton">last button</param> /// <param name="scrollNextBounds">scroll-next bounds</param> /// <returns>true if can scroll next</returns> internal abstract bool CanScrollNext(TabButton lastButton, Rectangle scrollNextBounds);
/// <summary> /// Checks if can scroll next /// </summary> /// <param name="lastButton">last button</param> /// <param name="scrollNextBounds">scroll-next bounds</param> /// <returns>true if can scroll next</returns> internal abstract bool CanScrollNext(TabButton lastButton, Rectangle scrollNextBounds);
/// <summary> /// Begin button drag /// </summary> /// <param name="selected">selected button</param> /// <param name="mousePosition">mouse position</param> /// <param name="cursor">cursor</param> /// <returns>true if button drag is started</returns> protected virtual bool BeginButtonDrag(TabButton selected, Point mousePosition, ref Cursor cursor) { return(false); }
/// <summary> /// Remove button /// </summary> /// <param name="button">button</param> /// <returns>true if button was removed</returns> protected bool RemoveButton(TabButton button) { if (_buttons.Contains(button) == false) { return false; } if (SelectedIndex >= 0 && SelectedIndex < ButtonsCount) { if (_buttons[SelectedIndex] == button && (SelectedIndex == ButtonsCount - 1 && SelectedIndex > 0)) { SelectedIndex--; } } _buttons.Remove(button); OnButtonRemoved(button); button.TextChanged -= OnButtonTextChanged; if (_buttons.Count == 0) { using (Graphics graphics = CreateGraphics()) { UpdatePositions(graphics, false); } } else { _updatePositionsOnDraw = true; } UpdateSize(); Invalidate(); return true; }
/// <summary> /// Default constructor /// </summary> public TabPageView() { InitializeComponent(); _button = new TabButton(this); }
/// <summary> /// Remove button /// </summary> /// <param name="button">button</param> /// <returns>true if button was removed</returns> protected bool RemoveButton(TabButton button) { if (_buttons.Contains(button) == false) { return false; } // If the selected index is the last button index, must decrement the selected index // to prevent index out of range exception after the count of buttons is updated. if (SelectedIndex > 0 && SelectedIndex == ButtonsCount - 1) { SelectedIndex--; } _buttons.Remove(button); OnButtonRemoved(button); button.TextChanged -= OnButtonTextChanged; button.ExplicitDisposing -= OnButtonDisposing; if (_buttons.Count == 0) { if (Disposing == false && IsDisposed == false) { using (Graphics graphics = CreateGraphics()) { UpdatePositions(graphics, false); } } } else { _updatePositionsOnDraw = true; } if (Disposing == false && IsDisposed == false) { UpdateSize(); Invalidate(); } return true; }
/// <summary> /// Checks if can scroll next /// </summary> /// <param name="lastButton">last button</param> /// <param name="scrollNextBounds">scroll-next bounds</param> /// <returns>true if can scroll next</returns> internal override bool CanScrollNext(TabButton lastButton, Rectangle scrollNextBounds) { return lastButton.Left + lastButton.Width > scrollNextBounds.Left; }
/// <summary> /// Default constructor /// </summary> public TabPageView() { InitializeComponent(); _button = new TabButton(this); }
/// <summary> /// Can undo the displacement of the previous button (the previous button was displaced before) /// </summary> /// <param name="displacedButton">displaced button</param> /// <param name="selectedButton">selected button</param> /// <param name="mouseLocation">current mouse location</param> /// <returns>true if can undo</returns> internal override bool CanUndoDisplaceBack(TabButton displacedButton, TabButton selectedButton, Point mouseLocation) { return mouseLocation.X < displacedButton.Left + selectedButton.Width; }
/// <summary> /// Can undo the displacement of the previous button (the previous button was displaced before) /// </summary> /// <param name="displacedButton">displaced button</param> /// <param name="selectedButton">selected button</param> /// <param name="mouseLocation">current mouse location</param> /// <returns>true if can undo</returns> internal override bool CanUndoDisplaceBack(TabButton displacedButton, TabButton selectedButton, Point mouseLocation) { return(mouseLocation.X < displacedButton.Left + selectedButton.Width); }
/// <summary> /// Can undo the displacement of the previous button (the previous button was displaced before) /// </summary> /// <param name="displacedButton">displaced button</param> /// <param name="selectedButton">selected button</param> /// <param name="mouseLocation">current mouse location</param> /// <returns>true if can undo</returns> internal override bool CanUndoDisplaceBack(TabButton displacedButton, TabButton selectedButton, Point mouseLocation) { return(mouseLocation.Y < displacedButton.Top + selectedButton.Height); }
/// <summary> /// Occurs when tab button is removed /// </summary> /// <param name="button">button removed</param> protected override void OnButtonRemoved(TabButton button) { Form page = (Form)button.Page; page.FormClosing -= OnPageClosing; page.FormClosed -= OnPageClosed; page.ParentChanged -= OnPageParentChanged; PagesPanel.Remove(page); DockableFormInfo info = null; for (int index = _cachedInfos.Count - 1; index >= 0; index--) { if (_cachedInfos[index].Button == button) { info = _cachedInfos[index]; _cachedInfos.RemoveAt(index); info.ExplicitDisposing -= OnInfoDisposing; info.SelectedChanged -= OnInfoSelectedChanged; break; } } EventHandler<FormEventArgs> handler = FormRemoved; if (handler != null) { FormEventArgs args = new FormEventArgs(page, info.Id); handler(this, args); } }
/// <summary> /// Checks if can scroll next /// </summary> /// <param name="lastButton">last button</param> /// <param name="scrollNextBounds">scroll-next bounds</param> /// <returns>true if can scroll next</returns> internal override bool CanScrollNext(TabButton lastButton, Rectangle scrollNextBounds) { return(lastButton.Top + lastButton.Height > scrollNextBounds.Top); }
/// <summary> /// Begin button drag /// </summary> /// <param name="selected">selected button</param> /// <param name="mousePosition">mouse position</param> /// <param name="cursor">cursor</param> /// <returns>true if button drag is started</returns> protected override bool BeginButtonDrag(TabButton selected, Point mousePosition, ref Cursor cursor) { EventHandler<FormEventArgs> handler = UndockForm; if (handler != null) { _movedButton = selected; _movedForm = (Form)_movedButton.Page; _movedIndex = SelectedIndex; Point mouseScreenPosition = Control.MousePosition; FormEventArgs args = new FormEventArgs(_movedForm); handler(this, args); RemoveButton(_movedButton); _movedDecorator = HierarchyUtility.GetFormsDecorator(_movedForm); _movedDecorator.BeginMovementByMouse(mouseScreenPosition); cursor = Cursors.SizeAll; } return true; }
/// <summary> /// End mouse action /// </summary> /// <param name="cancel">cancel</param> private void EndMouseAction(bool cancel) { _isMouseDownInTabButton = false; if (_isMovingTabButton) { if (_isDraggingTabButton) { EndButtonDrag(cancel); } _isMovingTabButton = false; _buttonDisplaced = null; } IsMouseDownInScrollBackButton = false; IsMouseDownInScrollNextButton = false; }
/// <summary> /// Occurs when tab button is removed /// </summary> /// <param name="button">button removed</param> protected override void OnButtonRemoved(TabButton button) { PagesPanel.Remove((Form)button.Page); for (int index = _cachedInfos.Count - 1; index >= 0; index--) { if (_cachedInfos[index].Button == button) { _cachedInfos.RemoveAt(index); break; } } EventHandler<FormEventArgs> handler = FormRemoved; if (handler != null) { FormEventArgs args = new FormEventArgs((Form)button.Page); handler(this, args); } }
/// <summary> /// Occurs when mouse cursor is moved over the panel /// </summary> /// <param name="e">event argument</param> protected override void OnMouseMove(MouseEventArgs e) { Cursor cursor = Cursors.Default; if (_isMouseDownInTabButton && e.Button == MouseButtons.Left) { cursor = Cursors.Hand; if (_isMovingTabButton) { TabButton selected = _buttons[SelectedIndex]; if (selected.Contains(e.Location) == false) { if (_isDraggingTabButton) { ContinueButtonDrag(e.Location, ref cursor); } else { int index = -1; TabButton underMouse = GetButtonFromPoint(e.Location, true, out index); if (underMouse != null) { bool displace = false; if (underMouse == _buttonDisplaced) { if (index < SelectedIndex) { displace = ButtonsRenderer.CanUndoDisplaceBack(underMouse, selected, e.Location); } else if (index > SelectedIndex) { displace = ButtonsRenderer.CanUndoDisplaceNext(underMouse, selected, e.Location); } } _buttonDisplaced = underMouse; if (displace) { _buttons[index] = selected; _buttons[SelectedIndex] = underMouse; _updatePositionsOnDraw = true; SelectedIndex = index; } } else { _isDraggingTabButton = BeginButtonDrag(selected, e.Location, ref cursor); } } } } else { _isMovingTabButton = _buttons[SelectedIndex].Contains(e.Location); _isDraggingTabButton = false; } } else if (GetButtonFromPoint(e.Location) != null) { cursor = Cursors.Hand; } CheckIfIsMouseOverScrollButtons(e.Location); if (IsMouseOverScrollBackButton && _firstShownButtonIndex > 0) { cursor = Cursors.Hand; } else if (IsMouseOverScrollNextButton && _canScrollNext) { cursor = Cursors.Hand; } int captionIndex = ButtonsRenderer.GetCaptionButtonIndex(_captionButtonsBounds, e.Location); if (captionIndex < 0 || captionIndex >= ButtonsCount) { captionIndex = -1; } else { cursor = Cursors.Hand; } if (_captionButtonIndexUnderMouse != captionIndex) { _captionButtonIndexUnderMouse = captionIndex; OnMouseMoveOverCaptionButton(captionIndex, e); Invalidate(); } int buttonIndex = -1; TabButton buttonUnderMouse = GetButtonFromPoint(e.Location, false, out buttonIndex); if (buttonUnderMouse != null) { OnMouseMoveOverTabButton(buttonUnderMouse); } Cursor = cursor; base.OnMouseMove(e); }
/// <summary> /// Can undo the displacement of the previous button (the previous button was displaced before) /// </summary> /// <param name="displacedButton">displaced button</param> /// <param name="selectedButton">selected button</param> /// <param name="mouseLocation">current mouse location</param> /// <returns>true if can undo</returns> internal override bool CanUndoDisplaceBack(TabButton displacedButton, TabButton selectedButton, Point mouseLocation) { return mouseLocation.Y < displacedButton.Top + selectedButton.Height; }
/// <summary> /// Occurs when mouse button was moved over a tab button /// </summary> /// <param name="buttonUnderMouse">button under mouse</param> protected virtual void OnMouseMoveOverTabButton(TabButton buttonUnderMouse) { }
/// <summary> /// Occurs when mouse button was pressed while the cursor was over a tab button /// </summary> /// <param name="buttonUnderMouse">button under mouse</param> protected override void OnMouseDownInTabButton(TabButton buttonUnderMouse) { EventHandler<ControlEventArgs> handler = SelectButton; if (handler != null) { ControlEventArgs args = new ControlEventArgs(buttonUnderMouse.Page); handler(this, args); } }
/// <summary> /// Occurs when mouse button was pressed while the cursor was over a tab button /// </summary> /// <param name="buttonUnderMouse">button under mouse</param> protected virtual void OnMouseDownInTabButton(TabButton buttonUnderMouse) { }
/// <summary> /// Can undo the displacement of the previous button (the previous button was displaced before) /// </summary> /// <param name="displacedButton">displaced button</param> /// <param name="selectedButton">selected button</param> /// <param name="mouseLocation">current mouse location</param> /// <returns>true if can undo</returns> internal abstract bool CanUndoDisplaceBack(TabButton displacedButton, TabButton selectedButton, Point mouseLocation);
/// <summary> /// Occurs when tab button is removed /// </summary> /// <param name="button">button removed</param> protected virtual void OnButtonRemoved(TabButton button) { }
/// <summary> /// Can undo the displacement of the previous button (the previous button was displaced before) /// </summary> /// <param name="displacedButton">displaced button</param> /// <param name="selectedButton">selected button</param> /// <param name="mouseLocation">current mouse location</param> /// <returns>true if can undo</returns> internal abstract bool CanUndoDisplaceBack(TabButton displacedButton, TabButton selectedButton, Point mouseLocation);
/// <summary> /// Occurs when tab button is added /// </summary> /// <param name="button">button added</param> protected virtual void OnButtonAdded(TabButton button) { }
/// <summary> /// Add button /// </summary> /// <param name="button">button</param> protected void AddButton(TabButton button) { InsertButton(button, _buttons.Count); }
/// <summary> /// Get the page at given index /// </summary> /// <param name="pageIndex">zero based page index</param> /// <returns>page at given index</returns> public TabPageView GetPageAt(int pageIndex) { TabButton buton = GetButtonAt(pageIndex); return((TabPageView)buton.Page); }