diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2017-01-05 15:47:33 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2017-01-05 15:47:33 +0100 |
| commit | 49346012274739fd39745f9e035ee8853149bc73 (patch) | |
| tree | b8757165c6b31a6d08b7caad2118ed76f463c287 /src/GraphicObjects | |
| parent | 9c0f77e860a1852ee7de381a82118e6d8c7fb819 (diff) | |
| parent | 40b16003066ad42604fd82dc0eec9cfa0a4abeca (diff) | |
Merge branch 'master' into CrowIDE
Diffstat (limited to 'src/GraphicObjects')
22 files changed, 382 insertions, 429 deletions
diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs index 59762182..1cfbe85c 100644 --- a/src/GraphicObjects/Button.cs +++ b/src/GraphicObjects/Button.cs @@ -47,12 +47,6 @@ namespace Crow #endregion #region GraphicObject Overrides - public override void ResolveBindings () - { - base.ResolveBindings (); - if (Content != null) - Content.ResolveBindings (); - } public override void onMouseDown (object sender, MouseButtonEventArgs e) { IsPressed = true; diff --git a/src/GraphicObjects/ColorPicker.cs b/src/GraphicObjects/ColorPicker.cs index cc8dfac3..57f9610d 100644 --- a/src/GraphicObjects/ColorPicker.cs +++ b/src/GraphicObjects/ColorPicker.cs @@ -131,9 +131,21 @@ namespace Crow hsvFromRGB (); } } - + [XmlAttributeAttribute] + public virtual Color SelectedRawColor { + get { return curColor; } + set { + if (curColor == value) + return; + curColor = value; + notifyCurColorHasChanged (); + notifyRGBAHasChanged (); + hsvFromRGB (); + } + } void notifyCurColorHasChanged(){ NotifyValueChanged ("SelectedColor", SelectedColor); + NotifyValueChanged ("SelectedRawColor", curColor); string n = curColor.ToString (); if (char.IsLetter(n[0])) NotifyValueChanged ("SelectedColorName", n); @@ -154,6 +166,7 @@ namespace Crow } void hsvFromRGB(){ Color c = curColor; + c.ResetName (); double min = Math.Min (c.R, Math.Min (c.G, c.B)); //Min. value of RGB double max = Math.Max (c.R, Math.Max (c.G, c.B)); //Max. value of RGB double diff = max - min; //Delta RGB value @@ -188,7 +201,7 @@ namespace Crow } void rgbFromHSV(){ Color c = Color.Black; - + c.ResetName (); if (s == 0) {//HSV from 0 to 1 c.R = v; c.G = v; diff --git a/src/GraphicObjects/IBindable.cs b/src/GraphicObjects/DataSourceChangeEventArgs.cs index 45ff5864..56d44428 100644 --- a/src/GraphicObjects/IBindable.cs +++ b/src/GraphicObjects/DataSourceChangeEventArgs.cs @@ -1,10 +1,10 @@ // -// IValueChange.cs +// DataSourceChangeEventArg.cs // // Author: // Jean-Philippe Bruyère <jp.bruyere@hotmail.com> // -// Copyright (c) 2015 jp +// Copyright (c) 2016 jp // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -19,14 +19,23 @@ // 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.Collections.Generic; namespace Crow { - public interface IBindable + public class DataSourceChangeEventArgs : EventArgs { - List<Binding> Bindings { get; } - object DataSource { get; set; } + public object OldDataSource; + public object NewDataSource; + + public DataSourceChangeEventArgs (object oldDataSource, object newDataSource) : base() + { + OldDataSource = oldDataSource; + NewDataSource = newDataSource; + } + public override string ToString () + { + return string.Format ("DSChangeEA: {0} => {1}", OldDataSource, NewDataSource); + } } } diff --git a/src/GraphicObjects/DirectoryView.cs b/src/GraphicObjects/DirectoryView.cs index 4e29621e..5ed46f3e 100644 --- a/src/GraphicObjects/DirectoryView.cs +++ b/src/GraphicObjects/DirectoryView.cs @@ -52,7 +52,7 @@ namespace Crow NotifyValueChanged ("SelectedItem", _selectedItem); } } - [XmlAttributeAttribute()][DefaultValue(false)] + [XmlAttributeAttribute()][DefaultValue(true)] public virtual bool ShowFiles { get { return showFiles; } set { @@ -76,8 +76,10 @@ namespace Crow } [XmlIgnore]public FileSystemInfo[] FileSystemEntries { get { - return showFiles ? new DirectoryInfo (CurrentDirectory).GetFileSystemInfos (): - new DirectoryInfo(currentDirectory).GetDirectories(); + return string.IsNullOrEmpty(CurrentDirectory) ? null : + showFiles ? + new DirectoryInfo (CurrentDirectory).GetFileSystemInfos () : + new DirectoryInfo(CurrentDirectory).GetDirectories(); } } public void onSelectedItemChanged (object sender, SelectionChangeEventArgs e){ diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs index 70451f41..38506de8 100644 --- a/src/GraphicObjects/Expandable.cs +++ b/src/GraphicObjects/Expandable.cs @@ -45,14 +45,12 @@ namespace Crow public event EventHandler Collapse; #endregion - #region GraphicObject overrides - public override void onMouseClick (object sender, MouseButtonEventArgs e) + public BooleanTestOnInstance GetIsExpandable; + + public void onClickForExpand (object sender, MouseButtonEventArgs e) { - if (this.HasFocus) - IsExpanded = !IsExpanded; - base.onMouseClick (sender, e); + IsExpanded = !IsExpanded; } - #endregion public override GraphicObject Content { get { @@ -70,15 +68,9 @@ namespace Crow _contentContainer = this.child.FindByName ("Content") as Container; } - public override void ResolveBindings () - { - base.ResolveBindings (); - if (Content != null) - Content.ResolveBindings (); - } #region Public properties - [XmlAttributeAttribute()][DefaultValue("Expandable")] + [XmlAttributeAttribute][DefaultValue("Expandable")] public string Caption { get { return caption; } set { @@ -88,7 +80,7 @@ namespace Crow NotifyValueChanged ("Caption", caption); } } - [XmlAttributeAttribute()][DefaultValue("#Crow.Images.Icons.expandable.svg")] + [XmlAttributeAttribute][DefaultValue("#Crow.Images.Icons.expandable.svg")] public string Image { get { return image; } set { @@ -98,7 +90,7 @@ namespace Crow NotifyValueChanged ("Image", image); } } - [XmlAttributeAttribute()][DefaultValue(false)] + [XmlAttributeAttribute][DefaultValue(false)] public bool IsExpanded { get { return _isExpanded; } @@ -109,7 +101,9 @@ namespace Crow _isExpanded = value; - if (!HasContent) + bool isExp = IsExpandable; + NotifyValueChanged ("IsExpandable", isExp); + if (!(HasContent & isExp)) _isExpanded = false; NotifyValueChanged ("IsExpanded", _isExpanded); @@ -123,7 +117,16 @@ namespace Crow [XmlIgnore]public bool HasContent { get { return _contentContainer == null ? false : _contentContainer.Child != null; } } - + [XmlIgnore]public bool IsExpandable { + get { + try { + return GetIsExpandable == null ? true : GetIsExpandable (this); + } catch (Exception ex) { + System.Diagnostics.Debug.WriteLine ("Not Expandable error: " + ex.ToString ()); + return false; + } + } + } #endregion public virtual void onExpand(object sender, EventArgs e) diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 840e883f..a2d78d88 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -84,7 +84,7 @@ namespace Crow d += c.Slot.Height + Spacing; } } - bmp = null; + IsDirty = true; } GraphicObject stretchedGO = null; public override bool UpdateLayout (LayoutingType layoutType) @@ -99,7 +99,7 @@ namespace Crow ComputeChildrenPositions (); //if no layouting remains in queue for item, registre for redraw - if (RegisteredLayoutings == LayoutingType.None && bmp == null) + if (RegisteredLayoutings == LayoutingType.None && IsDirty) CurrentInterface.EnqueueForRepaint (this); return true; @@ -134,7 +134,7 @@ namespace Crow newW = Math.Min (newW, stretchedGO.MaximumSize.Width); if (newW != stretchedGO.Slot.Width) { stretchedGO.Slot.Width = newW; - stretchedGO.bmp = null; + stretchedGO.IsDirty = true; #if DEBUG_LAYOUTING Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString()); #endif @@ -173,7 +173,7 @@ namespace Crow newH = Math.Min (newH, stretchedGO.MaximumSize.Height); if (newH != stretchedGO.Slot.Height) { stretchedGO.Slot.Height = newH; - stretchedGO.bmp = null; + stretchedGO.IsDirty = true; #if DEBUG_LAYOUTING Debug.WriteLine ("\tAdjusting Height of " + stretchedGO.ToString()); #endif diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 277e3d48..25332832 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -12,16 +12,8 @@ using System.IO; namespace Crow { - public class GraphicObject : IXmlSerializable, ILayoutable, IValueChange, ICloneable, IBindable + public class GraphicObject : IXmlSerializable, ILayoutable, IValueChange, ICloneable { - #region IBindable implementation - List<Binding> bindings = new List<Binding> (); - public List<Binding> Bindings { - get { return bindings; } - } - - #endregion - internal static ulong currentUid = 0; internal ulong uid = 0; @@ -88,7 +80,7 @@ namespace Crow Size minimumSize = "0,0"; bool cacheEnabled = false; bool clipToClientRect = true; - object dataSource; + protected object dataSource; string style; #endregion @@ -115,6 +107,7 @@ namespace Crow public object Tag; /// <summary>drawing Cache, if null, a redraw is done, cached or not</summary> public byte[] bmp; + public bool IsDirty = true; /// <summary> /// This size is computed on each child' layout changes. /// In stacking widget, it is used to compute the remaining space for the stretched @@ -133,11 +126,29 @@ namespace Crow /// </summary> [XmlIgnore]public virtual ILayoutable Parent { get { return parent; } - set { parent = value; } + set { + if (parent == value) + return; + DataSourceChangeEventArgs e = new DataSourceChangeEventArgs (parent, value); + parent = value; + + onParentChanged (this, e); + } } [XmlIgnore]public ILayoutable LogicalParent { get { return logicalParent == null ? Parent : logicalParent; } - set { logicalParent = value; } + set { + if (logicalParent == value) + return; + if (logicalParent != null) + (logicalParent as GraphicObject).DataSourceChanged -= onLogicalParentDataSourceChanged; + DataSourceChangeEventArgs dsce = new DataSourceChangeEventArgs (LogicalParent, null); + logicalParent = value; + dsce.NewDataSource = LogicalParent; + if (logicalParent != null) + (logicalParent as GraphicObject).DataSourceChanged += onLogicalParentDataSourceChanged; + onLogicalParentChanged (this, dsce); + } } [XmlIgnore]public virtual Rectangle ClientRectangle { get { @@ -178,6 +189,9 @@ namespace Crow public event EventHandler Enabled; public event EventHandler Disabled; public event EventHandler<LayoutingEventArgs> LayoutChanged; + public event EventHandler<DataSourceChangeEventArgs> DataSourceChanged; + public event EventHandler<DataSourceChangeEventArgs> ParentChanged; + public event EventHandler<DataSourceChangeEventArgs> LogicalParentChanged; #endregion #region public properties @@ -376,6 +390,10 @@ namespace Crow return; hasFocus = value; + if (hasFocus) + onFocused (this, null); + else + onUnfocused (this, null); NotifyValueChanged ("HasFocus", hasFocus); } } @@ -399,17 +417,23 @@ namespace Crow NotifyValueChanged ("MouseRepeat", mouseRepeat); } } + bool clearBackground = false; [XmlAttributeAttribute()][DefaultValue("Transparent")] public virtual Fill Background { get { return background; } set { if (background == value) return; + clearBackground = false; if (value == null) return; background = value; NotifyValueChanged ("Background", background); RegisterForRedraw (); + if (background is SolidColor) { + if ((Background as SolidColor).Equals (Color.Clear)) + clearBackground = true; + } } } [XmlAttributeAttribute()][DefaultValue("White")] @@ -528,32 +552,45 @@ namespace Crow RegisterForLayouting (LayoutingType.Sizing); } } + /// <summary> + /// Seek first logical tree upward if logicalParent is set, or seek graphic tree for + /// a not null dataSource that will be active for all descendants having dataSource=null + /// </summary> [XmlAttributeAttribute][DefaultValue(null)] public virtual object DataSource { set { - if (dataSource == value) + if (DataSource == value) return; - #if DEBUG_BINDING - Debug.WriteLine("******************************"); - Debug.WriteLine("New DataSource for => " + this.ToString()); - Debug.WriteLine("\t- " + DataSource); - Debug.WriteLine("\t+ " + value); - #endif - - this.ClearBinding (); + DataSourceChangeEventArgs dse = new DataSourceChangeEventArgs (DataSource, null); dataSource = value; + dse.NewDataSource = DataSource; - this.ResolveBindings(); + OnDataSourceChanged (this, dse); - NotifyValueChanged ("DataSource", dataSource); + NotifyValueChanged ("DataSource", DataSource); } get { - return dataSource == null ? LogicalParent == null ? null : - LogicalParent is GraphicObject ? - (LogicalParent as GraphicObject).DataSource : null : dataSource; + return dataSource == null ? + LogicalParent == null ? null : + LogicalParent is GraphicObject ? (LogicalParent as GraphicObject).DataSource : null : + dataSource; } } + protected virtual void onLogicalParentDataSourceChanged(object sender, DataSourceChangeEventArgs e){ + if (localDataSourceIsNull) + OnDataSourceChanged (this, e); + } + internal bool localDataSourceIsNull { get { return dataSource == null; } } + internal bool localLogicalParentIsNull { get { return logicalParent == null; } } + + public virtual void OnDataSourceChanged(object sender, DataSourceChangeEventArgs e){ + DataSourceChanged.Raise (this, e); + #if DEBUG_BINDING + Debug.WriteLine("New DataSource for => {0} \n\t{1}=>{2}", this.ToString(),e.OldDataSource,e.NewDataSource); + #endif + } + [XmlAttributeAttribute] public virtual string Style { get { return style; } @@ -635,10 +672,10 @@ namespace Crow dm = new DynamicMethod("dyn_loadDefValues", MethodAttributes.Family | MethodAttributes.FamANDAssem | MethodAttributes.NewSlot, CallingConventions.Standard, - typeof(void),new Type[] {typeof(object)},thisType,true); + typeof(void),new Type[] {CompilerServices.TObject},thisType,true); il = dm.GetILGenerator(256); - il.DeclareLocal(typeof(GraphicObject)); + il.DeclareLocal(CompilerServices.TObject); il.Emit(OpCodes.Nop); //set local GraphicObject to root object passed as 1st argument il.Emit (OpCodes.Ldarg_0); @@ -648,7 +685,26 @@ namespace Crow string expression; if (!getDefaultEvent(ei, styling, out expression)) continue; - CompilerServices.emitBindingCreation (il, ei.Name, expression); + //TODO:dynEventHandler could be cached somewhere, maybe a style instanciato class holding the styling delegate and bound to it. + foreach (string exp in CompilerServices.splitOnSemiColumnOutsideAccolades(expression)) { + string trimed = exp.Trim(); + if (trimed.StartsWith ("{", StringComparison.OrdinalIgnoreCase)){ + il.Emit (OpCodes.Ldloc_0);//load this as 1st arg of event Add + + //push eventInfo as 1st arg of compile + il.Emit (OpCodes.Ldloc_0); + il.Emit (OpCodes.Call, CompilerServices.miGetType); + il.Emit (OpCodes.Ldstr, ei.Name);//push event name + il.Emit (OpCodes.Call, CompilerServices.miGetEvent); + //push expression as 2nd arg of compile + il.Emit (OpCodes.Ldstr, trimed.Substring (1, trimed.Length - 2)); + il.Emit (OpCodes.Ldnull); + il.Emit (OpCodes.Callvirt, CompilerServices.miCompileDynEventHandler); + il.Emit (OpCodes.Castclass, ei.EventHandlerType); + il.Emit (OpCodes.Callvirt, ei.AddMethod); + }else + Debug.WriteLine("error in styling, event not handled : " + trimed); + } } foreach (PropertyInfo pi in thisType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { @@ -732,7 +788,7 @@ namespace Crow #region Queuing public virtual void RegisterClip(Rectangle clip){ - if (CacheEnabled && bmp != null) + if (CacheEnabled && !IsDirty) Clipping.AddRectangle (clip + ClientRectangle.Position); if (Parent != null) Parent.RegisterClip (clip + Slot.Position + ClientRectangle.Position); @@ -741,7 +797,7 @@ namespace Crow [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RegisterForGraphicUpdate () { - bmp = null; + IsDirty = true; if (Width.IsFit || Height.IsFit) RegisterForLayouting (LayoutingType.Sizing); else if (RegisteredLayoutings == LayoutingType.None) @@ -751,7 +807,7 @@ namespace Crow [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RegisterForRedraw () { - bmp = null; + IsDirty = true; if (RegisteredLayoutings == LayoutingType.None) CurrentInterface.EnqueueForRepaint (this); } @@ -864,7 +920,7 @@ namespace Crow if (LastSlots.X == Slot.X) break; - bmp = null; + IsDirty = true; OnLayoutChanges (layoutType); @@ -894,7 +950,7 @@ namespace Crow if (LastSlots.Y == Slot.Y) break; - bmp = null; + IsDirty = true; OnLayoutChanges (layoutType); @@ -930,7 +986,7 @@ namespace Crow if (LastSlots.Width == Slot.Width) break; - bmp = null; + IsDirty = true; OnLayoutChanges (layoutType); @@ -966,7 +1022,7 @@ namespace Crow if (LastSlots.Height == Slot.Height) break; - bmp = null; + IsDirty = true; OnLayoutChanges (layoutType); @@ -975,7 +1031,7 @@ namespace Crow } //if no layouting remains in queue for item, registre for redraw - if (this.registeredLayoutings == LayoutingType.None && bmp == null) + if (this.registeredLayoutings == LayoutingType.None && IsDirty) CurrentInterface.EnqueueForRepaint (this); return true; @@ -1002,7 +1058,7 @@ namespace Crow int bmpSize = Math.Abs (stride) * Slot.Height; bmp = new byte[bmpSize]; - + IsDirty = false; using (ImageSurface draw = new ImageSurface(bmp, Format.Argb32, Slot.Width, Slot.Height, stride)) { using (Context gr = new Context (draw)) { @@ -1014,16 +1070,13 @@ namespace Crow } protected virtual void UpdateCache(Context ctx){ Rectangle rb = Slot + Parent.ClientRectangle.Position; - using (ImageSurface cache = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) { - //TODO:improve equality test for basic color and Fill - if (this.Background is SolidColor) { - if ((this.Background as SolidColor).Equals (Color.Clear)) { + using (ImageSurface cache = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) { + if (clearBackground) { ctx.Save (); ctx.Operator = Operator.Clear; ctx.Rectangle (rb); ctx.Fill (); ctx.Restore (); - } } ctx.SetSourceSurface (cache, rb.X, rb.Y); ctx.Paint (); @@ -1035,9 +1088,6 @@ namespace Crow /// of the widget </summary> public virtual void Paint (ref Context ctx) { - if (!Visible) - return; - //TODO:this test should not be necessary if (Slot.Height < 0 || Slot.Width < 0) return; @@ -1050,7 +1100,7 @@ namespace Crow } if (cacheEnabled) { - if (bmp == null) + if (IsDirty) RecreateCache (); UpdateCache (ctx); @@ -1113,7 +1163,7 @@ namespace Crow onMouseEnter (this, e); } - this.onMouseMove (this, e); + this.onMouseMove (this, e);//without this, window border doesn't work, should be removed } public virtual void onMouseMove(object sender, MouseMoveEventArgs e) { @@ -1125,6 +1175,12 @@ namespace Crow MouseMove.Raise (sender, e); } public virtual void onMouseDown(object sender, MouseButtonEventArgs e){ + if (CurrentInterface.eligibleForDoubleClick == this && CurrentInterface.clickTimer.ElapsedMilliseconds < Interface.DoubleClick) + onMouseDoubleClick (this, e); + else + currentInterface.clickTimer.Restart(); + CurrentInterface.eligibleForDoubleClick = null; + if (CurrentInterface.activeWidget == null) CurrentInterface.activeWidget = this; if (this.Focusable && !Interface.FocusOnHover) { @@ -1149,19 +1205,13 @@ namespace Crow MouseUp.Raise (this, e); - if (MouseIsIn (e.Position) && IsActive) + if (MouseIsIn (e.Position) && IsActive) { + if (CurrentInterface.clickTimer.ElapsedMilliseconds < Interface.DoubleClick) + CurrentInterface.eligibleForDoubleClick = this; onMouseClick (this, e); + } } public virtual void onMouseClick(object sender, MouseButtonEventArgs e){ - - if (Interface.clickTimer.ElapsedMilliseconds > 0 && - Interface.clickTimer.ElapsedMilliseconds < Interface.DoubleClick) { - Interface.clickTimer.Reset (); - onMouseDoubleClick (this, e); - return; - } else - Interface.clickTimer.Restart (); - GraphicObject p = Parent as GraphicObject; if (p != null) p.onMouseClick(sender,e); @@ -1196,20 +1246,17 @@ namespace Crow } #endregion - public virtual void onFocused(object sender, EventArgs e){ + protected virtual void onFocused(object sender, EventArgs e){ #if DEBUG_FOCUS Debug.WriteLine("Focused => " + this.ToString()); #endif Focused.Raise (this, e); - this.HasFocus = true; } - public virtual void onUnfocused(object sender, EventArgs e){ + protected virtual void onUnfocused(object sender, EventArgs e){ #if DEBUG_FOCUS Debug.WriteLine("UnFocused => " + this.ToString()); #endif - Unfocused.Raise (this, e); - this.HasFocus = false; } public virtual void onEnable(object sender, EventArgs e){ Enabled.Raise (this, e); @@ -1217,147 +1264,73 @@ namespace Crow public virtual void onDisable(object sender, EventArgs e){ Disabled.Raise (this, e); } - - #region Binding - public void BindMember(string _member, string _expression){ - Bindings.Add(new Binding (this, _member, _expression)); + protected virtual void onParentChanged(object sender, DataSourceChangeEventArgs e) { + ParentChanged.Raise (this, e); + if (logicalParent == null) + LogicalParentChanged.Raise (this, e); } - public virtual void ResolveBindings() - { - if (Bindings.Count == 0) - return; - #if DEBUG_BINDING - Debug.WriteLine ("Resolve Bindings => " + this.ToString ()); - #endif - - CompilerServices.ResolveBindings (Bindings); + protected virtual void onLogicalParentChanged(object sender, DataSourceChangeEventArgs e) { + LogicalParentChanged.Raise (this, e); } - - /// <summary> - /// Remove dynamic delegates by ids from dataSource - /// and delete ref of this in Shared interface refs - /// </summary> - public virtual void ClearBinding(){ - //dont clear binding if dataSource is not null, - foreach (Binding b in Bindings) { - try { - if (!b.Resolved) - continue; - //cancel compiled events - if (b.Target == null){ - continue; - #if DEBUG_BINDING - Debug.WriteLine("Clear binding canceled for => " + b.ToString()); - #endif - } - if (b.Target.Instance != DataSource){ - #if DEBUG_BINDING - Debug.WriteLine("Clear binding canceled for => " + b.ToString()); - #endif - continue; - } - #if DEBUG_BINDING - Debug.WriteLine("ClearBinding => " + b.ToString()); - #endif - if (string.IsNullOrEmpty (b.DynMethodId)) { - b.Resolved = false; - if (b.Source.Member.MemberType == MemberTypes.Event) - removeEventHandler (b); - //TODO:check if full reset is necessary - continue; - } - MemberReference mr = null; - if (b.Target == null) - mr = b.Source; - else - mr = b.Target; - Type dataSourceType = mr.Instance.GetType(); - EventInfo evtInfo = dataSourceType.GetEvent ("ValueChanged"); - FieldInfo evtFi = CompilerServices.GetEventHandlerField (dataSourceType, "ValueChanged"); - MulticastDelegate multicastDelegate = evtFi.GetValue (mr.Instance) as MulticastDelegate; - if (multicastDelegate != null) { - foreach (Delegate d in multicastDelegate.GetInvocationList()) { - if (d.Method.Name == b.DynMethodId) - evtInfo.RemoveEventHandler (mr.Instance, d); - } - } - b.Reset (); - } catch (Exception ex) { - Debug.WriteLine("\t Error: " + ex.ToString()); - } - } - } - void removeEventHandler(Binding b){ - FieldInfo fiEvt = CompilerServices.GetEventHandlerField (b.Source.Instance.GetType(), b.Source.Member.Name); - MulticastDelegate multiDel = fiEvt.GetValue (b.Source.Instance) as MulticastDelegate; - if (multiDel != null) { - foreach (Delegate d in multiDel.GetInvocationList()) { - if (d.Method.Name == b.Target.Member.Name) - b.Source.Event.RemoveEventHandler (b.Source.Instance, d); - } - } - } - #endregion - #region IXmlSerializable public virtual System.Xml.Schema.XmlSchema GetSchema () { return null; } - void affectMember(string name, string value){ - Type thisType = this.GetType (); - - if (string.IsNullOrEmpty (value)) - return; - - MemberInfo mi = thisType.GetMember (name).FirstOrDefault(); - if (mi == null) { - Debug.WriteLine ("XML: Unknown attribute in " + thisType.ToString() + " : " + name); - return; - } - if (mi.MemberType == MemberTypes.Event) { - this.Bindings.Add (new Binding (new MemberReference(this, mi), value)); - return; - } - if (mi.MemberType == MemberTypes.Property) { - PropertyInfo pi = mi as PropertyInfo; - - if (pi.GetSetMethod () == null) { - Debug.WriteLine ("XML: Read only property in " + thisType.ToString() + " : " + name); - return; - } - - XmlAttributeAttribute xaa = (XmlAttributeAttribute)pi.GetCustomAttribute (typeof(XmlAttributeAttribute)); - if (xaa != null) { - if (!string.IsNullOrEmpty (xaa.AttributeName)) - name = xaa.AttributeName; - } - if (value.StartsWith("{",StringComparison.Ordinal)) { - //binding - if (!value.EndsWith("}", StringComparison.Ordinal)) - throw new Exception (string.Format("XML:Malformed binding: {0}", value)); - - this.Bindings.Add (new Binding (new MemberReference(this, pi), value.Substring (1, value.Length - 2))); - return; - } - if (pi.GetCustomAttribute (typeof(XmlIgnoreAttribute)) != null) - return; - if (xaa == null)//not define as xmlAttribute - return; - - if (pi.PropertyType == typeof(string)) { - pi.SetValue (this, value, null); - return; - } - - if (pi.PropertyType.IsEnum) { - pi.SetValue (this, Enum.Parse (pi.PropertyType, value), null); - } else { - MethodInfo me = pi.PropertyType.GetMethod ("Parse", new Type[] { typeof(string) }); - pi.SetValue (this, me.Invoke (null, new string[] { value }), null); - } - } - } +// void affectMember(string name, string value){ +// Type thisType = this.GetType (); +// +// if (string.IsNullOrEmpty (value)) +// return; +// +// MemberInfo mi = thisType.GetMember (name).FirstOrDefault(); +// if (mi == null) { +// Debug.WriteLine ("XML: Unknown attribute in " + thisType.ToString() + " : " + name); +// return; +// } +// if (mi.MemberType == MemberTypes.Event) { +// this.Bindings.Add (new Binding (new MemberReference(this, mi), value)); +// return; +// } +// if (mi.MemberType == MemberTypes.Property) { +// PropertyInfo pi = mi as PropertyInfo; +// +// if (pi.GetSetMethod () == null) { +// Debug.WriteLine ("XML: Read only property in " + thisType.ToString() + " : " + name); +// return; +// } +// +// XmlAttributeAttribute xaa = (XmlAttributeAttribute)pi.GetCustomAttribute (typeof(XmlAttributeAttribute)); +// if (xaa != null) { +// if (!string.IsNullOrEmpty (xaa.AttributeName)) +// name = xaa.AttributeName; +// } +// if (value.StartsWith("{",StringComparison.Ordinal)) { +// //binding +// if (!value.EndsWith("}", StringComparison.Ordinal)) +// throw new Exception (string.Format("XML:Malformed binding: {0}", value)); +// +// this.Bindings.Add (new Binding (new MemberReference(this, pi), value.Substring (1, value.Length - 2))); +// return; +// } +// if (pi.GetCustomAttribute (typeof(XmlIgnoreAttribute)) != null) +// return; +// if (xaa == null)//not define as xmlAttribute +// return; +// +// if (pi.PropertyType == typeof(string)) { +// pi.SetValue (this, value, null); +// return; +// } +// +// if (pi.PropertyType.IsEnum) { +// pi.SetValue (this, Enum.Parse (pi.PropertyType, value), null); +// } else { +// MethodInfo me = pi.PropertyType.GetMethod ("Parse", new Type[] { typeof(string) }); +// pi.SetValue (this, me.Invoke (null, new string[] { value }), null); +// } +// } +// } public virtual void ReadXml (System.Xml.XmlReader reader) { if (reader.HasAttributes) { @@ -1370,7 +1343,7 @@ namespace Crow if (reader.Name == "Style") continue; - affectMember (reader.Name, reader.Value); + //affectMember (reader.Name, reader.Value); } reader.MoveToElement (); }else @@ -1488,12 +1461,6 @@ namespace Crow /// <summary> /// full GraphicTree clone with binding definition /// </summary> - public virtual GraphicObject DeepClone(){ - GraphicObject tmp = Clone () as GraphicObject; - foreach (Binding b in this.bindings) - tmp.Bindings.Add (new Binding (new MemberReference (tmp, b.Source.Member), b.Expression)); - return tmp; - } public override string ToString () { diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs index a0f0cb69..57ceda5e 100644 --- a/src/GraphicObjects/Grid.cs +++ b/src/GraphicObjects/Grid.cs @@ -134,7 +134,7 @@ namespace Crow ComputeChildrenPositions (); //if no layouting remains in queue for item, registre for redraw - if (RegisteredLayoutings == LayoutingType.None && bmp == null) + if (RegisteredLayoutings == LayoutingType.None && IsDirty) CurrentInterface.EnqueueForRepaint (this); return true; diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index efe02d95..a285e282 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -40,7 +40,6 @@ namespace Crow lock (children) Children.Add(g); g.Parent = this; - g.ResolveBindings (); g.RegisteredLayoutings = LayoutingType.None; g.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren); g.LayoutChanged += OnChildLayoutChanges; @@ -48,7 +47,6 @@ namespace Crow public virtual void RemoveChild(GraphicObject child) { child.LayoutChanged -= OnChildLayoutChanges; - child.ClearBinding (); //child.Parent = null; lock (children) Children.Remove(child); @@ -65,7 +63,6 @@ namespace Crow while(Children.Count > 0){ GraphicObject g = Children[Children.Count-1]; g.LayoutChanged -= OnChildLayoutChanges; - g.ClearBinding (); g.Parent = null; Children.RemoveAt(Children.Count-1); } @@ -94,11 +91,12 @@ namespace Crow } #region GraphicObject overrides - public override void ResolveBindings () + public override void OnDataSourceChanged (object sender, DataSourceChangeEventArgs e) { - base.ResolveBindings (); - foreach (GraphicObject w in Children) - w.ResolveBindings (); + base.OnDataSourceChanged (this, e); + foreach (GraphicObject g in children) + if (g.localDataSourceIsNull & g.localLogicalParentIsNull) + g.OnDataSourceChanged (sender, e); } public override GraphicObject FindByName (string nameToFind) { @@ -365,17 +363,5 @@ namespace Crow #endregion - public override void ClearBinding(){ - foreach (GraphicObject c in Children) - c.ClearBinding (); - base.ClearBinding (); - } - public override GraphicObject DeepClone () - { - Group tmp = base.DeepClone () as Group; - foreach (GraphicObject c in Children) - tmp.AddChild (c.DeepClone ()); - return tmp; - } } } diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs index 61b6e059..fa036b97 100644 --- a/src/GraphicObjects/Image.cs +++ b/src/GraphicObjects/Image.cs @@ -50,9 +50,11 @@ namespace Crow _pic = null; return; } - LoadImage (value); - _pic.Scaled = scaled; - _pic.KeepProportions = keepProps; + lock(CurrentInterface.LayoutMutex){ + LoadImage (value); + _pic.Scaled = scaled; + _pic.KeepProportions = keepProps; + } } catch (Exception ex) { Debug.WriteLine (ex.Message); _pic = null; @@ -86,7 +88,6 @@ namespace Crow _pic.LoadImage (path); RegisterForGraphicUpdate (); - RegisterForLayouting (LayoutingType.Sizing); } #endregion diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index 666f00a2..2f35c223 100644 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -670,7 +670,7 @@ namespace Crow base.onMouseLeave (sender, e); CurrentInterface.MouseCursor = XCursor.Default; } - public override void onFocused (object sender, EventArgs e) + protected override void onFocused (object sender, EventArgs e) { base.onFocused (sender, e); @@ -680,7 +680,7 @@ namespace Crow SelRelease = new Point (lines.LastOrDefault ().Length, lines.Count-1); RegisterForRedraw (); } - public override void onUnfocused (object sender, EventArgs e) + protected override void onUnfocused (object sender, EventArgs e) { base.onUnfocused (sender, e); diff --git a/src/GraphicObjects/Menu.cs b/src/GraphicObjects/Menu.cs index 765925e9..1a7a3f95 100644 --- a/src/GraphicObjects/Menu.cs +++ b/src/GraphicObjects/Menu.cs @@ -26,10 +26,14 @@ namespace Crow { public class Menu : TemplatedGroup { + #region CTOR + public Menu () : base() {} + #endregion + Orientation orientation; [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)] - public virtual Orientation Orientation { + public Orientation Orientation { get { return orientation; } set { if (orientation == value) @@ -38,23 +42,15 @@ namespace Crow NotifyValueChanged ("Orientation", orientation); } } - bool isOpened = false; - public bool IsOpened - { - get { return isOpened; } - set - { - isOpened = value; - System.Diagnostics.Debug.WriteLine ("is opened = " + isOpened); - } - } - - public Menu () : base() + bool autoOpen = false; + [XmlIgnore]public bool AutomaticOpenning { + get { return autoOpen; } + set { autoOpen = value; } } public override void AddItem (GraphicObject g) - { + { base.AddItem (g); if (orientation == Orientation.Horizontal) @@ -65,7 +61,7 @@ namespace Crow public override void onMouseLeave (object sender, MouseMoveEventArgs e) { base.onMouseLeave (sender, e); - IsOpened = false; + AutomaticOpenning = false; } } } diff --git a/src/GraphicObjects/MenuItem.cs b/src/GraphicObjects/MenuItem.cs index 78162fbb..80b5759d 100644 --- a/src/GraphicObjects/MenuItem.cs +++ b/src/GraphicObjects/MenuItem.cs @@ -24,7 +24,7 @@ using System.ComponentModel; namespace Crow { - public class MenuItem : TemplatedGroup + public class MenuItem : Menu { #region CTOR public MenuItem () : base() {} @@ -40,7 +40,6 @@ namespace Crow [XmlAttributeAttribute][DefaultValue(false)] public bool IsOpened { - //get { return MenuRoot == null ? false : MenuRoot.IsOpened; } get { return isOpened; } set { if (isOpened == value) @@ -50,8 +49,7 @@ namespace Crow if (isOpened) { onOpen (this, null); - if (MenuRoot != null) - MenuRoot.IsOpened = true; + (LogicalParent as Menu).AutomaticOpenning = true; }else onClose (this, null); } @@ -78,19 +76,7 @@ namespace Crow NotifyValueChanged ("Caption", caption); } } - - [XmlIgnore]Menu MenuRoot { - get { - ILayoutable tmp = LogicalParent; - while (tmp != null) { - if (tmp is Menu) - return tmp as Menu; - tmp = tmp.LogicalParent; - } - return null; - } - } - + public override void AddItem (GraphicObject g) { base.AddItem (g); @@ -100,21 +86,30 @@ namespace Crow void onMI_Click (object sender, MouseButtonEventArgs e) { Execute.Raise (this, null); + if(!IsOpened) + (LogicalParent as Menu).AutomaticOpenning = false; } protected virtual void onOpen (object sender, EventArgs e){ - MenuRoot.IsOpened = true; Open.Raise (this, null); } protected virtual void onClose (object sender, EventArgs e){ - //MenuRoot.IsOpened = true; Close.Raise (this, null); } + public override bool MouseIsIn (Point m) + { + return base.MouseIsIn (m) || child.MouseIsIn (m); + } public override void onMouseEnter (object sender, MouseMoveEventArgs e) { base.onMouseEnter (sender, e); - if (MenuRoot == null || Items.Count == 0) - return; - IsOpened = MenuRoot.IsOpened; + if ((LogicalParent as Menu).AutomaticOpenning && items.Children.Count>0) + IsOpened = true; + } + public override void onMouseLeave (object sender, MouseMoveEventArgs e) + { + if (IsOpened) + IsOpened = false; + base.onMouseLeave (this, e); } } } diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index 669b8d7f..38621337 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -175,42 +175,42 @@ namespace Crow _content.MinimumSize = new Size (this.Slot.Width, _content.MinimumSize.Height); } - public override void ClearBinding () - { - //ensure popped window is cleared - if (Content != null) { - if (Content.Parent != null) - CurrentInterface.DeleteWidget (Content); - } - base.ClearBinding (); - } - public override void ResolveBindings () - { - base.ResolveBindings (); - if (Content != null) - Content.ResolveBindings (); - } public override void onMouseClick (object sender, MouseButtonEventArgs e) { if (_canPop) IsPopped = !IsPopped; - base.onMouseClick (sender, e); + base.onMouseClick (this, e); } public override void onMouseLeave (object sender, MouseMoveEventArgs e) { - if (!_isPopped || _content == null) { - base.onMouseLeave (sender, e); - System.Diagnostics.Debug.WriteLine ("NotPopped***popper mouse leave:"+ this.ToString()); - return; + base.onMouseLeave (this, e); + IsPopped = false; + } + public override bool MouseIsIn (Point m) + { + bool isInContent = false; + if (Content != null) { + if (Content.Parent != null) + isInContent = Content.MouseIsIn (m); } - - if (!_content.MouseIsIn (e.Position)) { - base.onMouseLeave (sender, e); - System.Diagnostics.Debug.WriteLine ("***popper mouse leave:"+ this.ToString()); - IsPopped = false; - return; + return base.MouseIsIn (m) || isInContent; + } + public override void checkHoverWidget (MouseMoveEventArgs e) + { + if (CurrentInterface.HoverWidget != this) { + CurrentInterface.HoverWidget = this; + onMouseEnter (this, e); + } + if (Content != null){ + if (Content.Parent != null) { + if (Content.MouseIsIn (e.Position)) { + Content.checkHoverWidget (e); + return; + } + } } + base.checkHoverWidget (e); } #endregion diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index 2a5deeaa..9c65e935 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -47,7 +47,6 @@ namespace Crow { if (child != null) { - child.ClearBinding (); contentSize = new Size (0, 0); child.LayoutChanged -= OnChildLayoutChanges; child.Parent = null; @@ -66,16 +65,7 @@ namespace Crow } #region GraphicObject Overrides - public override void ResolveBindings () - { - base.ResolveBindings (); - if (child != null) - child.ResolveBindings (); - } - protected void ResolveBindingsWithNoRecurse () - { - base.ResolveBindings (); - } + public override GraphicObject FindByName (string nameToFind) { if (Name == nameToFind) @@ -88,6 +78,13 @@ namespace Crow return child == goToFind ? true : child == null ? false : child.Contains(goToFind); } + public override void OnDataSourceChanged (object sender, DataSourceChangeEventArgs e) + { + base.OnDataSourceChanged (this, e); + if (child != null) + if (child.localDataSourceIsNull & child.localLogicalParentIsNull) + child.OnDataSourceChanged (sender, e); + } public override bool UpdateLayout (LayoutingType layoutType) { if (child != null) { @@ -161,8 +158,10 @@ namespace Crow gr.Clip (); } - if (child != null) - child.Paint (ref gr); + if (child != null) { + if (child.Visible) + child.Paint (ref gr); + } gr.Restore (); } protected override void UpdateCache (Context ctx) @@ -197,19 +196,6 @@ namespace Crow } #endregion - public override void ClearBinding () - { - if (child != null) - child.ClearBinding (); - base.ClearBinding (); - } - public override GraphicObject DeepClone () - { - PrivateContainer tmp = base.DeepClone () as PrivateContainer; - if (child != null) - tmp.SetChild (child.DeepClone ()); - return tmp; - } } } diff --git a/src/GraphicObjects/TabItem.cs b/src/GraphicObjects/TabItem.cs index e14a7815..aca033d9 100644 --- a/src/GraphicObjects/TabItem.cs +++ b/src/GraphicObjects/TabItem.cs @@ -27,17 +27,17 @@ namespace Crow { public class TabItem : TemplatedContainer { + #region CTOR + public TabItem () : base() {} + #endregion + #region Private fields string caption; Container _contentContainer; GraphicObject _tabTitle; int tabOffset; - #endregion - - #region CTOR - public TabItem () : base() - { - } + bool isSelected; + Measure tabThickness; #endregion #region TemplatedControl overrides @@ -46,15 +46,15 @@ namespace Crow return _contentContainer == null ? null : _contentContainer.Child; } set { + if (Content != null) { + Content.LogicalParent = null; + _contentContainer.SetChild (null); + } _contentContainer.SetChild(value); + if (value != null) + value.LogicalParent = this; } } - public override void ResolveBindings () - { - base.ResolveBindings (); - if (_contentContainer != null) - _contentContainer.ResolveBindings (); - } protected override void loadTemplate(GraphicObject template = null) { base.loadTemplate (template); @@ -65,6 +65,17 @@ namespace Crow internal GraphicObject TabTitle { get { return _tabTitle; }} #endregion + [XmlAttributeAttribute][DefaultValue("18")] + public virtual Measure TabThickness { + get { return tabThickness; } + set { + if (tabThickness == value) + return; + tabThickness = value; + NotifyValueChanged ("TabThickness", tabThickness); + RegisterForGraphicUpdate (); + } + } [XmlAttributeAttribute][DefaultValue(0)] public virtual int TabOffset { get { return tabOffset; } @@ -88,7 +99,6 @@ namespace Crow NotifyValueChanged ("Caption", caption); } } - bool isSelected; [XmlAttributeAttribute][DefaultValue(false)] public virtual bool IsSelected { get { return isSelected; } @@ -101,9 +111,11 @@ namespace Crow } protected override void onDraw (Cairo.Context gr) { + gr.Save (); + int spacing = (Parent as TabView).Spacing; - gr.MoveTo (0, TabTitle.Slot.Bottom-0.5); + gr.MoveTo (0.5, TabTitle.Slot.Bottom-0.5); gr.LineTo (TabTitle.Slot.Left - spacing, TabTitle.Slot.Bottom-0.5); gr.CurveTo ( TabTitle.Slot.Left - spacing / 2, TabTitle.Slot.Bottom-0.5, @@ -114,16 +126,16 @@ namespace Crow TabTitle.Slot.Right + spacing / 2, 0.5, TabTitle.Slot.Right + spacing / 2, TabTitle.Slot.Bottom-0.5, TabTitle.Slot.Right + spacing, TabTitle.Slot.Bottom-0.5); - gr.LineTo (Slot.Width, TabTitle.Slot.Bottom-0.5); + gr.LineTo (Slot.Width-0.5, TabTitle.Slot.Bottom-0.5); + - gr.LineWidth = 1; + gr.LineTo (Slot.Width-0.5, Slot.Height-0.5); + gr.LineTo (0.5, Slot.Height-0.5); + gr.ClosePath (); + gr.LineWidth = 2; Foreground.SetAsSource (gr); gr.StrokePreserve (); - gr.LineTo (Slot.Width, Slot.Height); - gr.LineTo (0, Slot.Height); - gr.ClosePath (); - gr.Save (); gr.Clip (); base.onDraw (gr); gr.Restore (); diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs index 42bb39c0..1debfedc 100644 --- a/src/GraphicObjects/TabView.cs +++ b/src/GraphicObjects/TabView.cs @@ -25,10 +25,13 @@ using Cairo; using System.Diagnostics; namespace Crow -{ - //TODO:use TemplatedGroup +{ public class TabView : Group { + #region CTOR + public TabView () : base() {} + #endregion + #region Private fields int _spacing; Measure tabThickness; @@ -36,9 +39,6 @@ namespace Crow int selectedTab = 0; #endregion - public TabView () : base() - { - } #region public properties [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)] @@ -56,7 +56,7 @@ namespace Crow NotifyValueChanged ("TabOrientation", Orientation.Horizontal); } } - [XmlAttributeAttribute()][DefaultValue(20)] + [XmlAttributeAttribute()][DefaultValue(16)] public int Spacing { get { return _spacing; } @@ -83,17 +83,6 @@ namespace Crow RegisterForRedraw (); } } - [XmlAttributeAttribute()][DefaultValue("18")] - public virtual Measure TabThickness { - get { return tabThickness; } - set { - if (tabThickness == value) - return; - tabThickness = value; - NotifyValueChanged ("TabThickness", tabThickness); - RegisterForGraphicUpdate (); - } - } #endregion public override void AddChild (GraphicObject child) @@ -143,7 +132,7 @@ namespace Crow } //if no layouting remains in queue for item, registre for redraw - if (RegisteredLayoutings == LayoutingType.None && bmp == null) + if (RegisteredLayoutings == LayoutingType.None && IsDirty) CurrentInterface.EnqueueForRepaint (this); return true; diff --git a/src/GraphicObjects/TemplatedContainer.cs b/src/GraphicObjects/TemplatedContainer.cs index 7a4649a4..44c2ad08 100644 --- a/src/GraphicObjects/TemplatedContainer.cs +++ b/src/GraphicObjects/TemplatedContainer.cs @@ -34,19 +34,6 @@ namespace Crow [XmlIgnore]public abstract GraphicObject Content{ get; set;} #region GraphicObject overrides - public override void ClearBinding () - { - if (Content != null) - Content.ClearBinding (); - - base.ClearBinding (); - } -// public override void ResolveBindings () -// { -// base.ResolveBindings (); -// if (Content != null) -// Content.ResolveBindings (); -// } public override GraphicObject FindByName (string nameToFind) { if (Name == nameToFind) diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index 7f2e1b87..ba49f44f 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -94,8 +94,6 @@ namespace Crow this.SetChild (CurrentInterface.Load (Interface.DefaultTemplates[this.GetType ().FullName])); }else this.SetChild (template); - - this.ResolveBindings (); } //TODO:IXmlSerializable is not used anymore diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs index 7fb3ceff..f636786d 100644 --- a/src/GraphicObjects/TemplatedGroup.cs +++ b/src/GraphicObjects/TemplatedGroup.cs @@ -42,7 +42,6 @@ namespace Crow public event EventHandler<SelectionChangeEventArgs> SelectedItemChanged; #endregion - Group _list; IList data; int _selectedIndex; Color selBackground, selForeground; @@ -121,7 +120,9 @@ namespace Crow [XmlIgnore]public virtual object SelectedItem{ get { return data == null ? null : _selectedIndex < 0 ? null : data[_selectedIndex]; } } - + [XmlIgnore]public bool HasItems { + get { return Items.Count > 0; } + } [XmlAttributeAttribute]public IList Data { get { return data; } set { @@ -148,6 +149,7 @@ namespace Crow NotifyValueChanged ("SelectedIndex", _selectedIndex); NotifyValueChanged ("SelectedItem", SelectedItem); SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem)); + NotifyValueChanged ("HasItems", HasItems); } } @@ -181,10 +183,12 @@ namespace Crow public virtual void AddItem(GraphicObject g){ items.AddChild (g); + g.LogicalParent = this; NotifyValueChanged ("HasChildren", true); } public virtual void RemoveItem(GraphicObject g) { + g.LogicalParent = null; items.RemoveChild (g); if (items.Children.Count == 0) NotifyValueChanged ("HasChildren", false); @@ -302,6 +306,7 @@ namespace Crow if (cancelLoading) return; loadPage (i); + Thread.Sleep (1); } } void cancelLoadingThread(){ @@ -320,7 +325,23 @@ namespace Crow loadingTime.Start (); #endif - Group page = items.Clone () as Group; + Group page; + if (typeof(Wrapper).IsAssignableFrom (items.GetType ())){ + page = items; + itemPerPage = int.MaxValue; + }else if (typeof(GenericStack).IsAssignableFrom (items.GetType ())) { + GenericStack gs = new GenericStack (); + gs.CurrentInterface = items.CurrentInterface; + gs.initialize (); + gs.Orientation = (items as GenericStack).Orientation; + gs.Width = items.Width; + gs.Height = items.Height; + gs.VerticalAlignment = items.VerticalAlignment; + gs.HorizontalAlignment = items.HorizontalAlignment; + page = gs; + + }else + page = Activator.CreateInstance (items.GetType ()) as Group; page.Name = "page" + pageNum; @@ -331,10 +352,10 @@ namespace Crow return; loadItem (i, page); - - //g.LogicalParent = this; } + if (page == items) + return; lock (CurrentInterface.LayoutMutex) items.AddChild (page); @@ -369,16 +390,16 @@ namespace Crow lock (CurrentInterface.LayoutMutex) { g = iTemp.CreateInstance(CurrentInterface); page.AddChild (g); - g.DataSource = data [i]; - if (typeof(IBindable).IsAssignableFrom (dataType)) - CompilerServices.ResolveBindings ((data [i] as IBindable).Bindings); + //g.LogicalParent = this; + registerItemClick (g); } - registerItemClick (g); - if (iTemp.Expand != null && g is Expandable) { (g as Expandable).Expand += iTemp.Expand; - } + (g as Expandable).GetIsExpandable = iTemp.HasSubItems; + } + + g.DataSource = data [i]; } protected virtual void registerItemClick(GraphicObject g){ g.MouseClick += itemClick; diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs index 9ef9e642..86f05d86 100644 --- a/src/GraphicObjects/Window.cs +++ b/src/GraphicObjects/Window.cs @@ -134,12 +134,6 @@ namespace Crow #endregion #region GraphicObject Overrides - public override void ResolveBindings () - { - base.ResolveBindings (); - if (Content != null) - Content.ResolveBindings (); - } public override void onMouseMove (object sender, MouseMoveEventArgs e) { base.onMouseMove (sender, e); diff --git a/src/GraphicObjects/Wrapper.cs b/src/GraphicObjects/Wrapper.cs index 1bfcd92a..fcf88583 100644 --- a/src/GraphicObjects/Wrapper.cs +++ b/src/GraphicObjects/Wrapper.cs @@ -76,7 +76,7 @@ namespace Crow dy += c.Slot.Height + Spacing; } } - bmp = null; + IsDirty = true; } public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg) { @@ -180,7 +180,7 @@ namespace Crow ComputeChildrenPositions (); //if no layouting remains in queue for item, registre for redraw - if (RegisteredLayoutings == LayoutingType.None && bmp == null) + if (RegisteredLayoutings == LayoutingType.None && IsDirty) CurrentInterface.EnqueueForRepaint (this); return true; |