From b9e90a3df66f4bd8228c1246af830d7801ea57ba Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Fri, 5 Aug 2016 18:32:18 +0200 Subject: [PATCH] TreeView template access with './', update all templates binding path begining with '/' starts at current level --- Crow.csproj | 3 +- Images/Icons/file.svg | 103 ++++++++++++++++++++ Images/Icons/folder.svg | 88 +++++++++++++++++ Templates/ArrowButTemplate.crow | 2 +- Templates/Button.crow | 6 +- Templates/CheckBox.goml | 6 +- Templates/Expandable.goml | 18 ++-- Templates/GroupBox.goml | 20 ++-- Templates/ListBox.goml | 10 +- Templates/MessageBox.goml | 28 +++--- Templates/Popper.goml | 8 +- Templates/RadioButton.goml | 6 +- Templates/ScrollBar.goml | 24 ++--- Templates/ScrollingListBox.goml | 14 +-- Templates/Spinner.goml | 13 +-- Templates/TreeItem.crow | 31 ------ Templates/TreeView.crow | 11 ++- Templates/Window.goml | 21 ++-- Tests/Interfaces/Unsorted/testTreeView.crow | 67 ++++++++----- src/CompilerServices/Bindings.cs | 14 ++- src/GraphicObjects/Expandable.cs | 3 +- src/GraphicObjects/GraphicObject.cs | 7 +- src/GraphicObjects/Label.cs | 52 ++++++---- src/GraphicObjects/ListBox.cs | 21 +++- src/GraphicObjects/TemplatedControl.cs | 11 +++ src/GraphicObjects/TreeView.cs | 62 ++++++++++++ src/Interface.cs | 2 +- 27 files changed, 474 insertions(+), 177 deletions(-) create mode 100644 Images/Icons/file.svg create mode 100644 Images/Icons/folder.svg delete mode 100644 Templates/TreeItem.crow diff --git a/Crow.csproj b/Crow.csproj index 611ad918..3f6f6b2d 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -221,11 +221,12 @@ - + + diff --git a/Images/Icons/file.svg b/Images/Icons/file.svg new file mode 100644 index 00000000..a31c367e --- /dev/null +++ b/Images/Icons/file.svg @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Images/Icons/folder.svg b/Images/Icons/folder.svg new file mode 100644 index 00000000..beac8a1b --- /dev/null +++ b/Images/Icons/folder.svg @@ -0,0 +1,88 @@ + + + +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Templates/ArrowButTemplate.crow b/Templates/ArrowButTemplate.crow index fe0e122c..817c00d1 100755 --- a/Templates/ArrowButTemplate.crow +++ b/Templates/ArrowButTemplate.crow @@ -1,7 +1,7 @@ - - - \ No newline at end of file diff --git a/Templates/CheckBox.goml b/Templates/CheckBox.goml index ea566d0e..818e10c1 100755 --- a/Templates/CheckBox.goml +++ b/Templates/CheckBox.goml @@ -1,6 +1,6 @@  - + - \ No newline at end of file diff --git a/Templates/Expandable.goml b/Templates/Expandable.goml index 0174aa6d..b544fd07 100755 --- a/Templates/Expandable.goml +++ b/Templates/Expandable.goml @@ -1,15 +1,15 @@  - - - + + + - + Height="{./HeightPolicy}" Width="{./WidthPolicy}"/> \ No newline at end of file diff --git a/Templates/GroupBox.goml b/Templates/GroupBox.goml index d3a16613..a373a29c 100755 --- a/Templates/GroupBox.goml +++ b/Templates/GroupBox.goml @@ -1,10 +1,12 @@ - - - - - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/Templates/ListBox.goml b/Templates/ListBox.goml index 7ea306a9..c56ec0d0 100755 --- a/Templates/ListBox.goml +++ b/Templates/ListBox.goml @@ -1,9 +1,9 @@ - + - + Height="{./HeightPolicy}" Width="{./WidthPolicy}" + ValueChanged="./_scroller_ValueChanged"> + \ No newline at end of file diff --git a/Templates/MessageBox.goml b/Templates/MessageBox.goml index dd63a10b..4489ee6b 100644 --- a/Templates/MessageBox.goml +++ b/Templates/MessageBox.goml @@ -1,33 +1,33 @@ - - - + + - + - - - + - - + - - diff --git a/Templates/ScrollingListBox.goml b/Templates/ScrollingListBox.goml index 5d9a572d..0822da7c 100644 --- a/Templates/ScrollingListBox.goml +++ b/Templates/ScrollingListBox.goml @@ -1,15 +1,15 @@ - - - + + - + + LayoutChanged="./_list_LayoutChanged"/> + Width="14" Height="{./HeightPolicy}" /> \ No newline at end of file diff --git a/Templates/Spinner.goml b/Templates/Spinner.goml index 0669b228..b63a7d26 100755 --- a/Templates/Spinner.goml +++ b/Templates/Spinner.goml @@ -1,16 +1,17 @@ - - + - - - diff --git a/Templates/TreeItem.crow b/Templates/TreeItem.crow deleted file mode 100644 index 97620096..00000000 --- a/Templates/TreeItem.crow +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - diff --git a/Templates/TreeView.crow b/Templates/TreeView.crow index 5bad322d..db6533e3 100644 --- a/Templates/TreeView.crow +++ b/Templates/TreeView.crow @@ -1,9 +1,10 @@ - + - + Height="{./HeightPolicy}" Width="{./WidthPolicy}" + ValueChanged="./_scroller_ValueChanged"> + diff --git a/Templates/Window.goml b/Templates/Window.goml index 42bc2976..3a252cab 100755 --- a/Templates/Window.goml +++ b/Templates/Window.goml @@ -1,23 +1,22 @@ - - - + + - + - - - + \ No newline at end of file diff --git a/Tests/Interfaces/Unsorted/testTreeView.crow b/Tests/Interfaces/Unsorted/testTreeView.crow index ca5ae138..5873e619 100755 --- a/Tests/Interfaces/Unsorted/testTreeView.crow +++ b/Tests/Interfaces/Unsorted/testTreeView.crow @@ -1,28 +1,43 @@  - - - - - - - - - + + + + + + - - - \ No newline at end of file + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/CompilerServices/Bindings.cs b/src/CompilerServices/Bindings.cs index 397ec39d..40ade60d 100644 --- a/src/CompilerServices/Bindings.cs +++ b/src/CompilerServices/Bindings.cs @@ -125,9 +125,17 @@ namespace Crow } else { int ptr = 0; ILayoutable tmp = Source.Instance as ILayoutable; - if (string.IsNullOrEmpty (bindingExp [0])) { - //if exp start with '/' => Graphic tree parsing start at top container - tmp = Interface.CurrentInterface as ILayoutable; + //if exp start with '/' => Graphic tree parsing start at source + if (string.IsNullOrEmpty (bindingExp [0])) + ptr++; + else if (bindingExp[0] == "."){ //search template root + do { + tmp = tmp.Parent; + if (tmp == null) + return false; + if (tmp is Interface) + throw new Exception ("Not in Templated Control"); + } while (!(tmp is TemplatedControl)); ptr++; } while (ptr < bindingExp.Length - 1) { diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs index d21936e8..819987eb 100644 --- a/src/GraphicObjects/Expandable.cs +++ b/src/GraphicObjects/Expandable.cs @@ -49,7 +49,8 @@ namespace Crow #region GraphicObject overrides public override void onMouseClick (object sender, MouseButtonEventArgs e) { - IsExpanded = !IsExpanded; + if (this.HasFocus) + IsExpanded = !IsExpanded; base.onMouseClick (sender, e); } #endregion diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index f2f2564f..39556976 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -1136,10 +1136,13 @@ namespace Crow MouseUp.Raise (this, e); - if (MouseIsIn (e.Position)&&HasFocus) - onMouseClick(sender,e); + if (MouseIsIn (e.Position) && IsActive) + onMouseClick (this, e); } public virtual void onMouseClick(object sender, MouseButtonEventArgs e){ + GraphicObject p = Parent as GraphicObject; + if (p != null) + p.onMouseClick(sender,e); MouseClick.Raise (this, e); } public virtual void onMouseWheel(object sender, MouseWheelEventArgs e){ diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index 2f5798ee..d09542b5 100644 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -48,12 +48,13 @@ namespace Crow #region private and protected fields string _text = "label"; - Alignment _textAlignment = Alignment.Left; - bool horizontalStretch = false; - bool verticalStretch = false; - bool _multiline = false; - Color selColor; - Color selFontColor; + Alignment _textAlignment; + bool horizontalStretch; + bool verticalStretch; + bool _selectable; + bool _multiline; + Color selBackground; + Color selForeground; Point mouseLocalPos = -1;//mouse coord in widget space, filled only when clicked int _currentCol; //0 based cursor position in string int _currentLine; @@ -73,23 +74,23 @@ namespace Crow [XmlAttributeAttribute][DefaultValue("SteelBlue")] public virtual Color SelectionBackground { - get { return selColor; } + get { return selBackground; } set { - if (value == selColor) + if (value == selBackground) return; - selColor = value; - NotifyValueChanged ("SelectionBackground", selColor); + selBackground = value; + NotifyValueChanged ("SelectionBackground", selBackground); RegisterForRedraw (); } } [XmlAttributeAttribute][DefaultValue("White")] public virtual Color SelectionForeground { - get { return selFontColor; } + get { return selForeground; } set { - if (value == selFontColor) + if (value == selForeground) return; - selFontColor = value; - NotifyValueChanged ("SelectionForeground", selFontColor); + selForeground = value; + NotifyValueChanged ("SelectionForeground", selForeground); RegisterForRedraw (); } } @@ -150,6 +151,21 @@ namespace Crow RegisterForGraphicUpdate (); } } + [XmlAttributeAttribute][DefaultValue(false)] + public bool Selectable + { + get { return _selectable; } + set + { + if (value == _selectable) + return; + _selectable = value; + NotifyValueChanged ("Selectable", _selectable); + SelBegin = -1; + SelRelease = -1; + RegisterForRedraw (); + } + } [XmlAttributeAttribute][DefaultValue(false)] public bool Multiline { @@ -548,7 +564,7 @@ namespace Crow // lineRect.X += (rText.Width - lineLength); if (SelRelease >= 0 && i >= selectionStart.Y && i <= selectionEnd.Y) { - gr.SetSourceColor(selColor); + gr.SetSourceColor(selBackground); Rectangle selRect = lineRect ; @@ -594,6 +610,8 @@ namespace Crow { base.onFocused (sender, e); + if (!_selectable) + return; SelBegin = new Point(0,0); SelRelease = new Point (lines.LastOrDefault ().Length, lines.Count-1); RegisterForRedraw (); @@ -610,7 +628,7 @@ namespace Crow { base.onMouseMove (sender, e); - if (!(SelectionInProgress && HasFocus)) + if (!(SelectionInProgress && HasFocus && _selectable)) return; updatemouseLocalPos (e.Position); @@ -619,7 +637,7 @@ namespace Crow } public override void onMouseDown (object sender, MouseButtonEventArgs e) { - if (this.HasFocus){ + if (this.HasFocus && _selectable){ updatemouseLocalPos (e.Position); SelBegin = -1; SelRelease = -1; diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index 24ceb618..6cef4fd9 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -97,9 +97,12 @@ namespace Crow SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); } } - [XmlIgnore]public object SelectedItem{ + [XmlIgnore]public virtual object SelectedItem{ get { return data == null ? null : _selectedIndex < 0 ? null : data[_selectedIndex]; } } + protected void raiseSelectedItemChanged(){ + SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); + } #region implemented abstract members of TemplatedControl protected override void loadTemplate (GraphicObject template = null) @@ -173,7 +176,19 @@ namespace Crow page.AddChild (g); g.DataSource = data [i]; } - g.MouseClick += itemClick; + if (this is TreeView) { + TreeView tv = this as TreeView; + while (!tv.IsRoot) { + ILayoutable tmp = tv.Parent; + while (!(tmp is TreeView)) { + tmp = tmp.Parent; + } + tv = tmp as TreeView; + } + g.MouseClick += tv.itemClick; + }else + g.MouseClick += itemClick; + if (itemStream.Expand != null && g is Expandable) { (g as Expandable).Expand += itemStream.Expand; } @@ -219,7 +234,7 @@ namespace Crow (int)Math.Ceiling ((double)page1.Slot.Height / (double)itemPerPage * (double)(data.Count+1)); } } - void itemClick(object sender, MouseButtonEventArgs e){ + internal virtual void itemClick(object sender, MouseButtonEventArgs e){ SelectedIndex = data.IndexOf((sender as GraphicObject).DataSource); } } diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index 744cd329..f1c719f6 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -99,6 +99,17 @@ namespace Crow //prevent name searching in template return nameToFind == this.Name ? this : null; } + protected override void onDraw (Cairo.Context gr) + { + gr.Save (); + //clip to client zone + CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius); + gr.Clip (); + + if (child != null) + child.Paint (ref gr); + gr.Restore (); + } #endregion protected virtual void loadTemplate(GraphicObject template = null) diff --git a/src/GraphicObjects/TreeView.cs b/src/GraphicObjects/TreeView.cs index 64d4afcb..51080281 100644 --- a/src/GraphicObjects/TreeView.cs +++ b/src/GraphicObjects/TreeView.cs @@ -19,6 +19,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . using System; +using System.Xml.Serialization; +using System.Diagnostics; +using System.ComponentModel; namespace Crow { @@ -27,9 +30,68 @@ namespace Crow [DefaultTemplate("#Crow.Templates.TreeView.crow")] public class TreeView : ListBox { + GraphicObject selectedItemContainer = null; + Color selBackground; + Color selForeground; + bool isRoot; + + public TreeView () : base() { } + [XmlAttributeAttribute()][DefaultValue(false)] + public virtual bool IsRoot { + get { return isRoot; } + set { + if (isRoot == value) + return; + isRoot = value; + NotifyValueChanged ("IsRoot", isRoot); + } + } + + [XmlAttributeAttribute][DefaultValue("SteelBlue")]//DeepJungleGreen + public virtual Color SelectionBackground { + get { return selBackground; } + set { + if (value == selBackground) + return; + selBackground = value; + NotifyValueChanged ("SelectionBackground", selBackground); + RegisterForRedraw (); + } + } + [XmlAttributeAttribute][DefaultValue("White")] + public virtual Color SelectionForeground { + get { return selForeground; } + set { + if (value == selForeground) + return; + selForeground = value; + NotifyValueChanged ("SelectionForeground", selForeground); + RegisterForRedraw (); + } + } + + [XmlIgnore]public override object SelectedItem { + get { + return selectedItemContainer == null ? + "" : selectedItemContainer.DataSource; + } + } + internal override void itemClick (object sender, MouseButtonEventArgs e) + { + GraphicObject tmp = sender as GraphicObject; + if (selectedItemContainer != null) { + selectedItemContainer.Foreground = Color.Transparent; + selectedItemContainer.Background = Color.Transparent; + } + selectedItemContainer = tmp; + selectedItemContainer.Foreground = SelectionForeground; + selectedItemContainer.Background = SelectionBackground; + NotifyValueChanged ("SelectedItem", SelectedItem); + raiseSelectedItemChanged (); + } } } diff --git a/src/Interface.cs b/src/Interface.cs index 350ef075..99ea974b 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -665,7 +665,7 @@ namespace Crow mouseRepeatThread.Join (); } - _activeWidget.onMouseUp (this, e); + _activeWidget.onMouseUp (_activeWidget, e); activeWidget = null; return true; } -- 2.47.3