aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/TabView.cs
diff options
context:
space:
mode:
authorj-p <jp.bruyere@live.be>2018-04-14 12:15:08 +0200
committerGitHub <noreply@github.com>2018-04-14 12:15:08 +0200
commit907358fed63b4a89e8dee5184cc9901a7107ab9f (patch)
tree18c473a86b553dbe9f08cfe345b6278c71e9594e /src/GraphicObjects/TabView.cs
parent7c735fa149bf23223eda734f19d5547797ca8ac2 (diff)
parent5a06966fd4be89263988d0838556b78a7988b5a9 (diff)
Merge pull request #40 from jpbruyere/devel
Devel
Diffstat (limited to 'src/GraphicObjects/TabView.cs')
-rw-r--r--src/GraphicObjects/TabView.cs240
1 files changed, 174 insertions, 66 deletions
diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs
index abaa6ac0..304e820d 100644
--- a/src/GraphicObjects/TabView.cs
+++ b/src/GraphicObjects/TabView.cs
@@ -41,14 +41,16 @@ namespace Crow
#endregion
#region Private fields
- int _spacing;
- Measure tabThickness;
+ int adjustedTab = -1;
+ int leftSlope;
+ int rightSlope;
+ Measure tabHeight, tabWidth;
Orientation _orientation;
- int selectedTab = 0;
+ int selectedTab;
#endregion
#region public properties
- [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)]
+ [DefaultValue(Orientation.Horizontal)]
public virtual Orientation Orientation
{
get { return _orientation; }
@@ -60,30 +62,83 @@ namespace Crow
if (_orientation == Orientation.Horizontal)
NotifyValueChanged ("TabOrientation", Orientation.Vertical);
else
- NotifyValueChanged ("TabOrientation", Orientation.Horizontal);
+ NotifyValueChanged ("TabOrientation", Orientation.Horizontal);
+ this.RegisterForLayouting (LayoutingType.ArrangeChildren);
+ }
+ }
+ [DefaultValue(16)]
+ public int LeftSlope
+ {
+ get { return leftSlope; }
+ set {
+ if (leftSlope == value)
+ return;
+ leftSlope = value;
+ NotifyValueChanged ("leftSlope", leftSlope);
+ tabSizeHasChanged = true;
+ //RegisterForLayouting (LayoutingType.ArrangeChildren);
}
}
- [XmlAttributeAttribute()][DefaultValue(16)]
- public int Spacing
+ bool tabSizeHasChanged = false;
+ [DefaultValue(16)]
+ public int RightSlope
{
- get { return _spacing; }
+ get { return rightSlope; }
+ set {
+ if (rightSlope == value)
+ return;
+ rightSlope = value;
+ NotifyValueChanged ("RightSlope", rightSlope);
+ tabSizeHasChanged = true;
+ //RegisterForLayouting (LayoutingType.ArrangeChildren);
+ }
+ }
+ [DefaultValue("18")]
+ public Measure TabHeight {
+ get { return tabHeight; }
set {
- if (_spacing == value)
+ if (tabHeight == value)
return;
- _spacing = value;
- NotifyValueChanged ("Spacing", Spacing);
+ tabHeight = value;
+ NotifyValueChanged ("TabHeight", tabHeight);
+// childrenRWLock.EnterReadLock ();
+// foreach (GraphicObject ti in Children) {
+// ti.NotifyValueChanged ("TabHeight", tabHeight);
+// }
+// childrenRWLock.ExitReadLock ();
+ RegisterForLayouting (LayoutingType.ArrangeChildren);
}
}
- [XmlAttributeAttribute()][DefaultValue(0)]
+ [DefaultValue("120")]
+ public Measure TabWidth {
+ get { return adjustedTab > 0 ? (Measure)adjustedTab : tabWidth; }
+ set {
+ if (tabWidth == value)
+ return;
+ tabWidth = value;
+ NotifyValueChanged ("TabWidth", TabWidth);
+//
+// childrenRWLock.EnterReadLock ();
+// foreach (GraphicObject ti in Children) {
+// ti.NotifyValueChanged ("TabWidth", tabWidth);
+// }
+// childrenRWLock.ExitReadLock ();
+ RegisterForLayouting (LayoutingType.ArrangeChildren);
+ }
+ }
+
public virtual int SelectedTab {
get { return selectedTab; }
set {
- if (selectedTab < Children.Count && SelectedTab >= 0)
+ if (value == selectedTab)
+ return;
+
+ if (selectedTab < Children.Count && selectedTab >= 0)
(Children [selectedTab] as TabItem).IsSelected = false;
selectedTab = value;
- if (selectedTab < Children.Count && SelectedTab >= 0)
+ if (selectedTab < Children.Count && selectedTab >= 0)
(Children [selectedTab] as TabItem).IsSelected = true;
NotifyValueChanged ("SelectedTab", selectedTab);
@@ -92,12 +147,6 @@ namespace Crow
}
#endregion
- void Ti_TabTitle_LayoutChanged (object sender, LayoutingEventArgs e)
- {
- if (e.LayoutType == LayoutingType.Width)
- this.RegisterForLayouting (LayoutingType.ArrangeChildren);
- }
-
public override void AddChild (GraphicObject child)
{
TabItem ti = child as TabItem;
@@ -106,13 +155,14 @@ namespace Crow
ti.MouseDown += Ti_MouseDown;
ti.TabTitle.LayoutChanged += Ti_TabTitle_LayoutChanged;
+ ti.tview = this;
base.AddChild (child);
SelectedTab = ti.ViewIndex = Children.Count - 1;
+ this.RegisterForLayouting (LayoutingType.ArrangeChildren);
}
-
- public override void DeleteChild (GraphicObject child)
+ public override void RemoveChild (GraphicObject child)
{
TabItem ti = child as TabItem;
if (ti == null)
@@ -120,11 +170,30 @@ namespace Crow
ti.MouseDown -= Ti_MouseDown;
ti.TabTitle.LayoutChanged -= Ti_TabTitle_LayoutChanged;
+ ti.tview = null;
- if (selectedTab > Children.Count - 2)
- SelectedTab--;
-
- base.DeleteChild (child);
+ childrenRWLock.EnterReadLock ();
+
+ TabItem[] tabItms = Children.Cast<TabItem>().OrderBy (t=>t.ViewIndex).ToArray();
+ int selTabViewIdx = -1;
+
+ if (SelectedTab < tabItms.Length && SelectedTab >= 0)
+ selTabViewIdx = (Children [SelectedTab] as TabItem).ViewIndex;
+
+ for (int i = selTabViewIdx+1; i < tabItms.Length; i++)
+ tabItms [i].ViewIndex--;
+
+ if (selTabViewIdx > tabItms.Length - 2)
+ selTabViewIdx = tabItms.Length - 2;
+
+ if (selTabViewIdx < 0)
+ SelectedTab = -1;
+ else
+ SelectedTab = Children.IndexOf (tabItms [selTabViewIdx]);
+
+ childrenRWLock.ExitReadLock ();
+
+ base.RemoveChild (child);
}
public override bool ArrangeChildren { get { return true; } }
@@ -132,34 +201,62 @@ namespace Crow
{
RegisteredLayoutings &= (~layoutType);
- if (layoutType == LayoutingType.ArrangeChildren) {
- int curOffset = Spacing;
+ if (layoutType == LayoutingType.ArrangeChildren && Children.Count > 0) {
+ Rectangle cb = ClientRectangle;
+
+ int tabSpace = tabWidth + leftSlope;
+ int tc = Children.Count (c => c.Visible == true);
+
+ if (tc > 0)
+ tabSpace = Math.Min(tabSpace, (cb.Width-rightSlope) / tc);
+
+ if (tabSpace < tabWidth + leftSlope)
+ adjustedTab = tabSpace - leftSlope;
+ else
+ adjustedTab = -1;
+
+ //Console.WriteLine ("tabspace: {0} tw:{1}", tabSpace, tabWidth);
+
+ childrenRWLock.EnterReadLock();
TabItem[] tabItms = Children.Cast<TabItem>().OrderBy (t=>t.ViewIndex).ToArray();
+ childrenRWLock.ExitReadLock();
+ int curOffset = leftSlope;
+
for (int i = 0; i < tabItms.Length; i++) {
if (!tabItms [i].Visible)
continue;
- if (!tabItms [i].HoldCursor)
+ tabItms [i].NotifyValueChanged ("TabHeight", tabHeight);
+ tabItms [i].NotifyValueChanged ("TabWidth", TabWidth);
+ if (!tabItms [i].IsDragged) {
tabItms [i].TabOffset = curOffset;
- if (Orientation == Orientation.Horizontal) {
- if (tabItms [i].TabTitle.RegisteredLayoutings.HasFlag (LayoutingType.Width))
- return false;
- curOffset += tabItms [i].TabTitle.Slot.Width + Spacing;
- } else {
- if (tabItms [i].TabTitle.RegisteredLayoutings.HasFlag (LayoutingType.Height))
- return false;
- curOffset += tabItms [i].TabTitle.Slot.Height + Spacing;
+ //Console.WriteLine ("offset: {0}=>{1}", tabItms [i].Name, tabItms [i].TabOffset);
}
+ if (Orientation == Orientation.Horizontal) {
+ curOffset += tabSpace;
+ } else
+ curOffset += tabSpace;
}
//if no layouting remains in queue for item, registre for redraw
if (RegisteredLayoutings == LayoutingType.None && IsDirty)
- CurrentInterface.EnqueueForRepaint (this);
+ IFace.EnqueueForRepaint (this);
return true;
}
return base.UpdateLayout(layoutType);
}
+ public override void OnLayoutChanges (LayoutingType layoutType)
+ {
+ if (_orientation == Orientation.Horizontal) {
+ if (layoutType == LayoutingType.Width)
+ RegisterForLayouting (LayoutingType.ArrangeChildren);
+ } else if (layoutType == LayoutingType.Height)
+ RegisterForLayouting (LayoutingType.ArrangeChildren);
+
+ base.OnLayoutChanges (layoutType);
+ }
+
protected override void onDraw (Context gr)
{
Rectangle rBack = new Rectangle (Slot.Size);
@@ -178,48 +275,59 @@ namespace Crow
childrenRWLock.EnterReadLock ();
- TabItem[] tabItms = Children.Cast<TabItem> ().OrderBy (t => t.ViewIndex).ToArray ();
- for (int i = 0; i < tabItms.Length; i++) {
- if (tabItms [i] == Children [SelectedTab])
- continue;
- tabItms [i].Paint (ref gr);
- }
+ TabItem[] tabItms = Children.Where(tt=>tt.Visible).Cast<TabItem> ().
+ OrderBy (t => t.ViewIndex).ToArray ();
+ int selTabViewIdx = -1;
if (SelectedTab < tabItms.Length && SelectedTab >= 0)
- Children [SelectedTab].Paint (ref gr);
+ selTabViewIdx = (Children [SelectedTab] as TabItem).ViewIndex;
childrenRWLock.ExitReadLock ();
+
+ int i = 0;
+ while (i < selTabViewIdx) {
+ tabItms [i].Paint (ref gr);
+ i++;
+ }
+ i = tabItms.Length - 1;
+ while (i > selTabViewIdx) {
+ tabItms [i].Paint (ref gr);
+ i--;
+ }
+
+ if (selTabViewIdx >= 0)
+ tabItms [selTabViewIdx].Paint (ref gr);
gr.Restore ();
}
- #region Mouse handling
- public override void checkHoverWidget (MouseMoveEventArgs e)
+ protected override void onDragEnter (object sender, DragDropEventArgs e)
{
- if (CurrentInterface.HoverWidget != this) {
- CurrentInterface.HoverWidget = this;
- onMouseEnter (this, e);
- }
+ base.onDragEnter (sender, e);
- if (SelectedTab > Children.Count - 1)
+ TabItem ti = e.DragSource as TabItem;
+ if (ti == null)
return;
-
- if (((Children[SelectedTab] as TabItem).Content.Parent as GraphicObject).MouseIsIn(e.Position))
- {
- Children[SelectedTab].checkHoverWidget (e);
+ if (ti.Parent != null || ti.savedParent == this)
return;
- }
- TabItem[] tabItms = Children.Cast<TabItem>().OrderBy (t=>t.ViewIndex).ToArray();
- for (int i = tabItms.Length - 1; i >= 0; i--) {
- if (tabItms [i].TabTitle.MouseIsIn(e.Position))
- {
- tabItms [i].checkHoverWidget (e);
- return;
- }
- }
+
+ this.AddChild (ti);
+
+ Point p = ScreenPointToLocal (IFace.Mouse.Position) - Margin;
+
+ p.X = Math.Max (leftSlope, p.X);
+ p.X = Math.Min (ClientRectangle.Width - rightSlope - TabWidth, p.X);
+ ti.TabOffset = p.X;
+
+ IFace.ClearDragImage ();
+
}
- #endregion
+ void Ti_TabTitle_LayoutChanged (object sender, LayoutingEventArgs e)
+ {
+ if (e.LayoutType == LayoutingType.X)
+ RegisterForLayouting (LayoutingType.ArrangeChildren);
+ }
void Ti_MouseDown (object sender, MouseButtonEventArgs e)
{
SelectedTab = Children.IndexOf (sender as GraphicObject);