aboutsummaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-08-05 18:32:18 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2016-08-05 18:32:18 +0200
commitb9e90a3df66f4bd8228c1246af830d7801ea57ba (patch)
tree8de343d8341be621c4b5daa12899155e0bc2f26a /src
parente9963abca14fbad8ff6c215e5c9d6b45652b38dc (diff)
TreeView
template access with './', update all templates binding path begining with '/' starts at current level
Diffstat (limited to 'src')
-rw-r--r--src/CompilerServices/Bindings.cs14
-rw-r--r--src/GraphicObjects/Expandable.cs3
-rw-r--r--src/GraphicObjects/GraphicObject.cs7
-rw-r--r--src/GraphicObjects/Label.cs52
-rw-r--r--src/GraphicObjects/ListBox.cs21
-rw-r--r--src/GraphicObjects/TemplatedControl.cs11
-rw-r--r--src/GraphicObjects/TreeView.cs62
-rw-r--r--src/Interface.cs2
8 files changed, 145 insertions, 27 deletions
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 ();
}
}
@@ -151,6 +152,21 @@ namespace Crow
}
}
[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
{
get { return _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 <http://www.gnu.org/licenses/>.
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;
}