mirror of
https://github.com/colhountech/DarkUI.Net5.git
synced 2025-07-17 10:06:13 +03:00
Added input to dock tabs
This commit is contained in:
parent
6e39da04da
commit
3466c3a241
@ -272,6 +272,29 @@ namespace DarkUI.Docking
|
|||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void EnsureVisible()
|
||||||
|
{
|
||||||
|
if (DockArea != DarkDockArea.Document)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (DockPanel.ActiveContent == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var width = ClientRectangle.Width - Padding.Horizontal - _tabArea.DropdownRectangle.Width;
|
||||||
|
var offsetArea = new Rectangle(Padding.Left, 0, width, 0);
|
||||||
|
var tab = _tabs[DockPanel.ActiveContent];
|
||||||
|
|
||||||
|
if (tab.ClientRectangle.IsEmpty)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (RectangleToTabArea(tab.ClientRectangle).Left < offsetArea.Left)
|
||||||
|
_tabArea.Offset = tab.ClientRectangle.Left;
|
||||||
|
else if (RectangleToTabArea(tab.ClientRectangle).Right > offsetArea.Right)
|
||||||
|
_tabArea.Offset = tab.ClientRectangle.Right - width;
|
||||||
|
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
private Point PointToTabArea(Point point)
|
private Point PointToTabArea(Point point)
|
||||||
{
|
{
|
||||||
return new Point(point.X - _tabArea.Offset, point.Y);
|
return new Point(point.X - _tabArea.Offset, point.Y);
|
||||||
@ -293,6 +316,115 @@ namespace DarkUI.Docking
|
|||||||
UpdateTabArea();
|
UpdateTabArea();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseMove(e);
|
||||||
|
|
||||||
|
if (_tabArea.DropdownRectangle.Contains(e.Location))
|
||||||
|
{
|
||||||
|
_tabArea.DropdownHot = true;
|
||||||
|
|
||||||
|
foreach (var tab in _tabs.Values)
|
||||||
|
tab.Hot = false;
|
||||||
|
|
||||||
|
Invalidate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_tabArea.DropdownHot = false;
|
||||||
|
|
||||||
|
foreach (var tab in _tabs.Values)
|
||||||
|
{
|
||||||
|
var rect = RectangleToTabArea(tab.ClientRectangle);
|
||||||
|
var hot = rect.Contains(e.Location);
|
||||||
|
|
||||||
|
if (tab.Hot != hot)
|
||||||
|
{
|
||||||
|
tab.Hot = hot;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
var closeRect = RectangleToTabArea(tab.CloseButtonRectangle);
|
||||||
|
var closeHot = closeRect.Contains(e.Location);
|
||||||
|
|
||||||
|
if (tab.CloseButtonHot != closeHot)
|
||||||
|
{
|
||||||
|
tab.CloseButtonHot = closeHot;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseDown(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseDown(e);
|
||||||
|
|
||||||
|
if (_tabArea.DropdownRectangle.Contains(e.Location))
|
||||||
|
{
|
||||||
|
_tabArea.DropdownHot = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var tab in _tabs.Values)
|
||||||
|
{
|
||||||
|
var rect = RectangleToTabArea(tab.ClientRectangle);
|
||||||
|
if (rect.Contains(e.Location))
|
||||||
|
{
|
||||||
|
if (e.Button == MouseButtons.Middle)
|
||||||
|
{
|
||||||
|
tab.DockContent.Close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var closeRect = RectangleToTabArea(tab.CloseButtonRectangle);
|
||||||
|
if (closeRect.Contains(e.Location))
|
||||||
|
{
|
||||||
|
_tabArea.ClickedCloseButton = tab;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DockPanel.ActiveContent = tab.DockContent;
|
||||||
|
EnsureVisible();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VisibleContent != null)
|
||||||
|
DockPanel.ActiveContent = VisibleContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseUp(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseUp(e);
|
||||||
|
|
||||||
|
if (_tabArea.DropdownRectangle.Contains(e.Location))
|
||||||
|
{
|
||||||
|
if (_tabArea.DropdownHot)
|
||||||
|
_tabArea.TabMenu.Show(this, new Point(_tabArea.DropdownRectangle.Left, _tabArea.DropdownRectangle.Bottom - 2));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_tabArea.ClickedCloseButton == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var closeRect = RectangleToTabArea(_tabArea.ClickedCloseButton.CloseButtonRectangle);
|
||||||
|
if (closeRect.Contains(e.Location))
|
||||||
|
_tabArea.ClickedCloseButton.DockContent.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseLeave(EventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseLeave(e);
|
||||||
|
|
||||||
|
foreach (var tab in _tabs.Values)
|
||||||
|
tab.Hot = false;
|
||||||
|
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
private void TabMenuItem_Select(object sender, EventArgs e)
|
private void TabMenuItem_Select(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var menuItem = sender as ToolStripMenuItem;
|
var menuItem = sender as ToolStripMenuItem;
|
||||||
|
@ -14,8 +14,6 @@ namespace DarkUI.Docking
|
|||||||
|
|
||||||
public bool Hot { get; set; }
|
public bool Hot { get; set; }
|
||||||
|
|
||||||
public bool Pressed { get; set; }
|
|
||||||
|
|
||||||
public bool CloseButtonHot { get; set; }
|
public bool CloseButtonHot { get; set; }
|
||||||
|
|
||||||
public bool ShowSeparator { get; set; }
|
public bool ShowSeparator { get; set; }
|
||||||
|
@ -5,7 +5,7 @@ using System.Drawing;
|
|||||||
|
|
||||||
namespace DarkUI.Docking
|
namespace DarkUI.Docking
|
||||||
{
|
{
|
||||||
public class DarkDockTabArea
|
internal class DarkDockTabArea
|
||||||
{
|
{
|
||||||
#region Field Region
|
#region Field Region
|
||||||
|
|
||||||
@ -23,12 +23,16 @@ namespace DarkUI.Docking
|
|||||||
|
|
||||||
public Rectangle DropdownRectangle { get; set; }
|
public Rectangle DropdownRectangle { get; set; }
|
||||||
|
|
||||||
|
public bool DropdownHot { get; set; }
|
||||||
|
|
||||||
public int Offset { get; set; }
|
public int Offset { get; set; }
|
||||||
|
|
||||||
public bool Visible { get; set; }
|
public bool Visible { get; set; }
|
||||||
|
|
||||||
public DarkContextMenu TabMenu { get { return _tabMenu; } }
|
public DarkContextMenu TabMenu { get { return _tabMenu; } }
|
||||||
|
|
||||||
|
public DarkDockTab ClickedCloseButton { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructor Region
|
#region Constructor Region
|
||||||
|
@ -9,10 +9,12 @@ namespace Example
|
|||||||
{
|
{
|
||||||
#region Constructor Region
|
#region Constructor Region
|
||||||
|
|
||||||
public DockDocument()
|
public DockDocument(string text)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
DockText = text;
|
||||||
|
|
||||||
// Workaround to stop the textbox from highlight all text.
|
// Workaround to stop the textbox from highlight all text.
|
||||||
txtDocument.SelectionStart = txtDocument.Text.Length;
|
txtDocument.SelectionStart = txtDocument.Text.Length;
|
||||||
}
|
}
|
||||||
|
@ -46,9 +46,9 @@ namespace Example
|
|||||||
DockPanel.AddContent(_dockHistory, _dockLayers.DockGroup);
|
DockPanel.AddContent(_dockHistory, _dockLayers.DockGroup);
|
||||||
|
|
||||||
// Add dummy documents to the main document area of the dock panel
|
// Add dummy documents to the main document area of the dock panel
|
||||||
DockPanel.AddContent(new DockDocument { DockText = "Document 1" });
|
DockPanel.AddContent(new DockDocument("Document 1"));
|
||||||
DockPanel.AddContent(new DockDocument { DockText = "Document 2" });
|
DockPanel.AddContent(new DockDocument("Document 2"));
|
||||||
DockPanel.AddContent(new DockDocument { DockText = "Document 3" });
|
DockPanel.AddContent(new DockDocument("Document 3"));
|
||||||
|
|
||||||
// Show the tool windows as visible in the 'Window' menu
|
// Show the tool windows as visible in the 'Window' menu
|
||||||
mnuProject.Checked = true;
|
mnuProject.Checked = true;
|
||||||
@ -103,7 +103,7 @@ namespace Example
|
|||||||
|
|
||||||
private void NewFile_Click(object sender, EventArgs e)
|
private void NewFile_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var newFile = new DockDocument();
|
var newFile = new DockDocument("New document");
|
||||||
DockPanel.AddContent(newFile);
|
DockPanel.AddContent(newFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user