mirror of
https://github.com/colhountech/DarkUI.Net5.git
synced 2025-07-03 07:39:28 +03:00
148 lines
4.4 KiB
C#
148 lines
4.4 KiB
C#
using DarkUI.Config;
|
|
using DarkUI.Win32;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Windows.Forms;
|
|
|
|
namespace DarkUI.Docking
|
|
{
|
|
public class DarkDockPanel : UserControl
|
|
{
|
|
#region Field Region
|
|
|
|
private List<DarkDockContent> _contents;
|
|
private Dictionary<DarkDockArea, DarkDockRegion> _regions;
|
|
|
|
private DarkDockContent _activeContent;
|
|
|
|
#endregion
|
|
|
|
#region Property Region
|
|
|
|
public DarkDockContent ActiveContent
|
|
{
|
|
get { return _activeContent; }
|
|
internal set
|
|
{
|
|
_activeContent = value;
|
|
|
|
ActiveGroup = _activeContent.DockGroup;
|
|
ActiveRegion = ActiveGroup.DockRegion;
|
|
|
|
foreach (var content in _contents)
|
|
content.Invalidate();
|
|
}
|
|
}
|
|
|
|
[Browsable(false)]
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
public DarkDockRegion ActiveRegion { get; internal set; }
|
|
|
|
[Browsable(false)]
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
public DarkDockGroup ActiveGroup { get; internal set; }
|
|
|
|
[Browsable(false)]
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
public IMessageFilter MessageFilter { get; private set; }
|
|
|
|
[Browsable(false)]
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
public List<DarkDockSplitter> Splitters { get; private set; }
|
|
|
|
[Browsable(false)]
|
|
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
|
|
public MouseButtons MouseButtonState
|
|
{
|
|
get
|
|
{
|
|
var buttonState = MouseButtons;
|
|
return buttonState;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Constructor Region
|
|
|
|
public DarkDockPanel()
|
|
{
|
|
Splitters = new List<DarkDockSplitter>();
|
|
MessageFilter = new DarkDockResizeFilter(this);
|
|
|
|
_regions = new Dictionary<DarkDockArea, DarkDockRegion>();
|
|
_contents = new List<DarkDockContent>();
|
|
|
|
BackColor = Colors.GreyBackground;
|
|
|
|
CreateRegions();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Method Region
|
|
|
|
public void AddContent(DarkDockContent dockContent)
|
|
{
|
|
AddContent(dockContent, null);
|
|
}
|
|
|
|
public void AddContent(DarkDockContent dockContent, DarkDockGroup dockGroup)
|
|
{
|
|
if (_contents.Contains(dockContent))
|
|
return;
|
|
|
|
if (dockContent.DockArea == DarkDockArea.None)
|
|
return;
|
|
|
|
dockContent.DockPanel = this;
|
|
_contents.Add(dockContent);
|
|
|
|
var region = _regions[dockContent.DockArea];
|
|
region.AddContent(dockContent, dockGroup);
|
|
}
|
|
|
|
public void RemoveContent(DarkDockContent dockContent)
|
|
{
|
|
if (!_contents.Contains(dockContent))
|
|
return;
|
|
|
|
dockContent.DockPanel = null;
|
|
_contents.Remove(dockContent);
|
|
|
|
var region = _regions[dockContent.DockArea];
|
|
region.RemoveContent(dockContent);
|
|
}
|
|
|
|
private void CreateRegions()
|
|
{
|
|
var documentRegion = new DarkDockRegion(this, DarkDockArea.Document);
|
|
_regions.Add(DarkDockArea.Document, documentRegion);
|
|
|
|
var leftRegion = new DarkDockRegion(this, DarkDockArea.Left);
|
|
_regions.Add(DarkDockArea.Left, leftRegion);
|
|
|
|
var rightRegion = new DarkDockRegion(this, DarkDockArea.Right);
|
|
_regions.Add(DarkDockArea.Right, rightRegion);
|
|
|
|
var bottomRegion = new DarkDockRegion(this, DarkDockArea.Bottom);
|
|
_regions.Add(DarkDockArea.Bottom, bottomRegion);
|
|
|
|
// Add the regions in this order to force the bottom region to be positioned
|
|
// between the left and right regions properly.
|
|
Controls.Add(documentRegion);
|
|
Controls.Add(bottomRegion);
|
|
Controls.Add(leftRegion);
|
|
Controls.Add(rightRegion);
|
|
|
|
// Create tab index for intuitive tabbing order
|
|
documentRegion.TabIndex = 0;
|
|
rightRegion.TabIndex = 1;
|
|
bottomRegion.TabIndex = 2;
|
|
leftRegion.TabIndex = 3;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|