From 7cd946b3725c0c66db8cdcbb56dc0e804ff7e4ef Mon Sep 17 00:00:00 2001 From: Robin Date: Tue, 5 Jan 2016 10:59:44 +0000 Subject: [PATCH] Can now drag content in to empty regions. --- DarkUI/Docking/DockDropArea.cs | 72 +++++++++++++++++++++- DarkUI/Docking/DockDropCollection.cs | 28 +-------- DarkUI/Win32/DockContentDragFilter.cs | 88 +++------------------------ todo.txt | 3 +- 4 files changed, 83 insertions(+), 108 deletions(-) diff --git a/DarkUI/Docking/DockDropArea.cs b/DarkUI/Docking/DockDropArea.cs index fd6f610..dc4a128 100644 --- a/DarkUI/Docking/DockDropArea.cs +++ b/DarkUI/Docking/DockDropArea.cs @@ -22,16 +22,22 @@ namespace DarkUI.Docking #region Constructor Region - internal DockDropArea(DarkDockRegion region, DockInsertType insertType) + internal DockDropArea(DarkDockPanel dockPanel, DarkDockRegion region) { + DockPanel = dockPanel; DockRegion = region; - InsertType = insertType; + InsertType = DockInsertType.None; + + BuildAreas(); } - internal DockDropArea(DarkDockGroup group, DockInsertType insertType) + internal DockDropArea(DarkDockPanel dockPanel, DarkDockGroup group, DockInsertType insertType) { + DockPanel = dockPanel; DockGroup = group; InsertType = insertType; + + BuildAreas(); } #endregion @@ -48,7 +54,67 @@ namespace DarkUI.Docking private void BuildRegionAreas() { + switch (DockRegion.DockArea) + { + case DarkDockArea.Left: + var leftRect = new Rectangle + { + X = DockPanel.PointToScreen(Point.Empty).X, + Y = DockPanel.PointToScreen(Point.Empty).Y, + Width = 50, + Height = DockPanel.Height + }; + + DropArea = leftRect; + HighlightArea = leftRect; + + break; + + case DarkDockArea.Right: + + var rightRect = new Rectangle + { + X = DockPanel.PointToScreen(Point.Empty).X + DockPanel.Width - 50, + Y = DockPanel.PointToScreen(Point.Empty).Y, + Width = 50, + Height = DockPanel.Height + }; + + DropArea = rightRect; + HighlightArea = rightRect; + + break; + + case DarkDockArea.Bottom: + + var x = DockPanel.PointToScreen(Point.Empty).X; + var width = DockPanel.Width; + + if (DockPanel.Regions[DarkDockArea.Left].Visible) + { + x += DockPanel.Regions[DarkDockArea.Left].Width; + width -= DockPanel.Regions[DarkDockArea.Left].Width; + } + + if (DockPanel.Regions[DarkDockArea.Right].Visible) + { + width -= DockPanel.Regions[DarkDockArea.Right].Width; + } + + var bottomRect = new Rectangle + { + X = x, + Y = DockPanel.PointToScreen(Point.Empty).Y + DockPanel.Height - 50, + Width = width, + Height = 50 + }; + + DropArea = bottomRect; + HighlightArea = bottomRect; + + break; + } } private void BuildGroupAreas() diff --git a/DarkUI/Docking/DockDropCollection.cs b/DarkUI/Docking/DockDropCollection.cs index 521e133..31578fe 100644 --- a/DarkUI/Docking/DockDropCollection.cs +++ b/DarkUI/Docking/DockDropCollection.cs @@ -14,33 +14,11 @@ #region Constructor Region - internal DockDropCollection(DarkDockPanel dockPanel, DarkDockRegion region) - { - DropArea = new DockDropArea(region, DockInsertType.None); - InsertBeforeArea = new DockDropArea(region, DockInsertType.Before); - InsertAfterArea = new DockDropArea(region, DockInsertType.After); - - BuildAreas(); - } - internal DockDropCollection(DarkDockPanel dockPanel, DarkDockGroup group) { - DropArea = new DockDropArea(group, DockInsertType.None); - InsertBeforeArea = new DockDropArea(group, DockInsertType.Before); - InsertAfterArea = new DockDropArea(group, DockInsertType.After); - - BuildAreas(); - } - - #endregion - - #region Method Region - - private void BuildAreas() - { - DropArea.BuildAreas(); - InsertBeforeArea.BuildAreas(); - InsertAfterArea.BuildAreas(); + DropArea = new DockDropArea(dockPanel, group, DockInsertType.None); + InsertBeforeArea = new DockDropArea(dockPanel, group, DockInsertType.Before); + InsertAfterArea = new DockDropArea(dockPanel, group, DockInsertType.After); } #endregion diff --git a/DarkUI/Win32/DockContentDragFilter.cs b/DarkUI/Win32/DockContentDragFilter.cs index 814ffa1..daf3a7d 100644 --- a/DarkUI/Win32/DockContentDragFilter.cs +++ b/DarkUI/Win32/DockContentDragFilter.cs @@ -22,7 +22,7 @@ namespace DarkUI.Win32 private DarkDockGroup _targetGroup; private DockInsertType _insertType = DockInsertType.None; - private Dictionary _regionDropAreas = new Dictionary(); + private Dictionary _regionDropAreas = new Dictionary(); private Dictionary _groupDropAreas = new Dictionary(); #endregion @@ -98,7 +98,7 @@ namespace DarkUI.Win32 public void StartDrag(DarkDockContent content) { - _regionDropAreas = new Dictionary(); + _regionDropAreas = new Dictionary(); _groupDropAreas = new Dictionary(); // Add all regions and groups to the drop collections @@ -116,65 +116,11 @@ namespace DarkUI.Win32 _groupDropAreas.Add(group, collection); } } - // If the region is NOT visible then build a drop area for the region itself. + // If the region is NOT visible then build drop areas for the region itself. else { - /*var rect = new Rectangle(); - - switch (region.DockArea) - { - case DarkDockArea.Left: - - rect = new Rectangle - { - X = _dockPanel.PointToScreen(Point.Empty).X, - Y = _dockPanel.PointToScreen(Point.Empty).Y, - Width = 15, - Height = _dockPanel.Height - }; - - break; - - case DarkDockArea.Right: - - rect = new Rectangle - { - X = _dockPanel.PointToScreen(Point.Empty).X + _dockPanel.Width - 15, - Y = _dockPanel.PointToScreen(Point.Empty).Y, - Width = 15, - Height = _dockPanel.Height - }; - - break; - - case DarkDockArea.Bottom: - - var x = _dockPanel.PointToScreen(Point.Empty).X; - var width = _dockPanel.Width; - - if (_dockPanel.Regions[DarkDockArea.Left].Visible) - { - x += _dockPanel.Regions[DarkDockArea.Left].Width; - width -= _dockPanel.Regions[DarkDockArea.Left].Width; - } - - if (_dockPanel.Regions[DarkDockArea.Right].Visible) - { - width -= _dockPanel.Regions[DarkDockArea.Right].Width; - } - - rect = new Rectangle - { - X = x, - Y = _dockPanel.PointToScreen(Point.Empty).Y + _dockPanel.Height - 15, - Width = width, - Height = 15 - }; - - break; - } - - _regionDropAreas.Add(region, rect);*/ + var area = new DockDropArea(_dockPanel, region); + _regionDropAreas.Add(region, area); } } @@ -219,29 +165,13 @@ namespace DarkUI.Win32 _targetGroup = null; // Check all region drop areas - foreach (var collection in _regionDropAreas.Values) + foreach (var area in _regionDropAreas.Values) { - if (collection.InsertBeforeArea.DropArea.Contains(location)) - { - _insertType = DockInsertType.Before; - _targetRegion = collection.InsertBeforeArea.DockRegion; - UpdateHighlightForm(collection.InsertBeforeArea.HighlightArea); - return; - } - - if (collection.InsertAfterArea.DropArea.Contains(location)) - { - _insertType = DockInsertType.After; - _targetRegion = collection.InsertAfterArea.DockRegion; - UpdateHighlightForm(collection.InsertAfterArea.HighlightArea); - return; - } - - if (collection.DropArea.DropArea.Contains(location)) + if (area.DropArea.Contains(location)) { _insertType = DockInsertType.None; - _targetRegion = collection.DropArea.DockRegion; - UpdateHighlightForm(collection.DropArea.HighlightArea); + _targetRegion = area.DockRegion; + UpdateHighlightForm(area.HighlightArea); return; } } diff --git a/todo.txt b/todo.txt index b25fc74..a0df657 100644 --- a/todo.txt +++ b/todo.txt @@ -16,11 +16,12 @@ DarkUI -- ScrollView not taking in to account size WITHOUT scrollbars causing you to have to overshoot when re-sizing to get rid of them -- if the final node in a treeview has been previous expanded, pressing 'down' will cause it to re-open -- create click-through panel +-- dragging treeview nodes doesn't rebuild prev/next references Dock panel -- make it so highlight form doesn't steal focus -- add splitters between region groups --- fix max position of splitters +-- fix max position of splitters - can currently resize a tool window offscreen -- serialise the visible content for groups and the active content -- right click tab menu. close all, close all but this etc. etc. -- stop dragging tabs instantly going to the end of the row