]> O.S.I.I.S - jp/crow.git/commitdiff
removed interface ILayoutable and derive Interfrace class from GraphicObject which... RemovedILayoutable
authorjpbruyere <jp.bruyere@hotmail.com>
Thu, 5 Jan 2017 00:34:39 +0000 (01:34 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Thu, 5 Jan 2017 00:34:39 +0000 (01:34 +0100)
Crow.csproj
Templates/Popper.template
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/ILayoutable.cs [deleted file]
src/GraphicObjects/Popper.cs
src/GraphicObjects/Splitter.cs
src/GraphicObjects/TabView.cs
src/GraphicObjects/TreeView.cs
src/Interface.cs
src/LayoutingQueueItem.cs

index b541152c14e9b51ab86461903379d2a274986c27..f3e91b213d32e65447ec558666a4b87afc82902c 100644 (file)
@@ -61,7 +61,6 @@
     <Compile Include="src\GraphicObjects\Slider.cs" />
     <Compile Include="src\GraphicObjects\NumericControl.cs" />
     <Compile Include="src\GraphicObjects\Scroller.cs" />
-    <Compile Include="src\GraphicObjects\ILayoutable.cs" />
     <Compile Include="src\Enums.cs" />
     <Compile Include="src\GraphicObjects\GenericStack.cs" />
     <Compile Include="src\CompilerServices\CompilerServices.cs" />
index c473cecb291dab267410ba5fdf37ddce0af1a9e3..cebf1ab07161cda8c76ff0a9eff3484a80e73552 100755 (executable)
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <Border Background="{./Background}" BorderWidth="1" Foreground="{./Foreground}" Height="Fit">
-       <HorizontalStack Spacing="1" Height="Fit">
+       <HorizontalStack Spacing="1">
                <Image Style="Icon" Margin="2"
                                Path="#Crow.Images.Icons.expandable.svg" SvgSub="{./IsPopped}"/>
                <Label Text="{./Caption}" />
index 253328327c0c830be7c7666a330583dc9c3daf77..3c9cb061acf076685f8aa2381804d4c4f85b8dc4 100644 (file)
@@ -12,7 +12,7 @@ using System.IO;
 
 namespace Crow
 {
-       public class GraphicObject : IXmlSerializable, ILayoutable, IValueChange, ICloneable
+       public class GraphicObject : IXmlSerializable, IValueChange, ICloneable
        {
                internal static ulong currentUid = 0;
                internal ulong uid = 0;
@@ -58,8 +58,8 @@ namespace Crow
                }
                #region private fields
                LayoutingType registeredLayoutings = LayoutingType.All;
-               ILayoutable logicalParent;
-               ILayoutable parent;
+               GraphicObject logicalParent;
+               GraphicObject parent;
                string name;
                Fill background = Color.Transparent;
                Fill foreground = Color.White;
@@ -118,13 +118,13 @@ namespace Crow
                #endregion
 
                #region ILayoutable
-               [XmlIgnore]public LayoutingType RegisteredLayoutings { get { return registeredLayoutings; } set { registeredLayoutings = value; } }
+               [XmlIgnore]public virtual LayoutingType RegisteredLayoutings { get { return registeredLayoutings; } set { registeredLayoutings = value; } }
                //TODO: it would save the recurent cost of a cast in event bubbling if parent type was GraphicObject
                //              or we could add to the interface the mouse events
                /// <summary>
                /// Parent in the graphic tree, used for rendering and layouting
                /// </summary>
-               [XmlIgnore]public virtual ILayoutable Parent {
+               [XmlIgnore]public virtual GraphicObject Parent {
                        get { return parent; }
                        set {
                                if (parent == value)
@@ -135,18 +135,18 @@ namespace Crow
                                onParentChanged (this, e);
                        }
                }
-               [XmlIgnore]public ILayoutable LogicalParent {
+               [XmlIgnore]public GraphicObject LogicalParent {
                        get { return logicalParent == null ? Parent : logicalParent; }
                        set {
                                if (logicalParent == value)
                                        return;
                                if (logicalParent != null)
-                                       (logicalParent as GraphicObject).DataSourceChanged -= onLogicalParentDataSourceChanged;
+                                       logicalParent.DataSourceChanged -= onLogicalParentDataSourceChanged;
                                DataSourceChangeEventArgs dsce = new DataSourceChangeEventArgs (LogicalParent, null);
                                logicalParent = value;
                                dsce.NewDataSource = LogicalParent;
                                if (logicalParent != null)
-                                       (logicalParent as GraphicObject).DataSourceChanged += onLogicalParentDataSourceChanged;
+                                       logicalParent.DataSourceChanged += onLogicalParentDataSourceChanged;
                                onLogicalParentChanged (this, dsce);
                        }
                }
@@ -158,10 +158,9 @@ namespace Crow
                        }
                }
                public virtual Rectangle ContextCoordinates(Rectangle r){
-                       GraphicObject go = Parent as GraphicObject;
-                       if (go == null)
+                       if (Parent is Interface)
                                return r + Parent.ClientRectangle.Position;
-                       return go.CacheEnabled ?
+                       return Parent.CacheEnabled ?
                                r + Parent.ClientRectangle.Position :
                                Parent.ContextCoordinates (r);
                }
@@ -296,9 +295,7 @@ namespace Crow
                [XmlAttributeAttribute()][DefaultValue("Inherit")]
                public virtual Measure Width {
                        get {
-                               return width.Units == Unit.Inherit ?
-                                       Parent is GraphicObject ? (Parent as GraphicObject).WidthPolicy :
-                                       Measure.Stretched : width;
+                               return width.Units == Unit.Inherit ? Parent == null ? Measure.Stretched : Parent.WidthPolicy : width;
                        }
                        set {
                                if (width == value)
@@ -332,9 +329,7 @@ namespace Crow
                [XmlAttributeAttribute()][DefaultValue("Inherit")]
                public virtual Measure Height {
                        get {
-                               return height.Units == Unit.Inherit ?
-                                       Parent is GraphicObject ? (Parent as GraphicObject).HeightPolicy :
-                                       Measure.Stretched : height;
+                               return height.Units == Unit.Inherit ? Parent == null ? Measure.Stretched :Parent.HeightPolicy : height;
                        }
                        set {
                                if (height == value)
@@ -573,8 +568,7 @@ namespace Crow
                        get {
                                return dataSource == null ? 
                                        LogicalParent == null ? null :
-                                       LogicalParent is GraphicObject ? (LogicalParent as GraphicObject).DataSource : null :
-                                       dataSource;
+                                       LogicalParent.DataSource : dataSource;
                        }
                }
                protected virtual void onLogicalParentDataSourceChanged(object sender, DataSourceChangeEventArgs e){
@@ -843,8 +837,7 @@ namespace Crow
                                        layoutType &= (~LayoutingType.ArrangeChildren);
 
                                //apply constraints depending on parent type
-                               if (Parent is GraphicObject)
-                                       (Parent as GraphicObject).ChildrenLayoutingConstraints (ref layoutType);
+                               Parent.ChildrenLayoutingConstraints (ref layoutType);
 
 //                             //prevent queueing same LayoutingType for this
 //                             layoutType &= (~RegisteredLayoutings);
@@ -872,6 +865,7 @@ namespace Crow
                        #if DEBUG_LAYOUTING
                        CurrentInterface.currentLQI.Slot = LastSlots;
                        CurrentInterface.currentLQI.NewSlot = Slot;
+                       Debug.WriteLine ("\t{0} => {1}",LastSlots,Slot);
                        #endif
 
                        switch (layoutType) {
@@ -1147,11 +1141,8 @@ namespace Crow
                                return false;
                        if (ScreenCoordinates (Slot).ContainsOrIsEqual (m)) {
                                Scroller scr = Parent as Scroller;
-                               if (scr == null) {
-                                       if (Parent is GraphicObject)
-                                               return (Parent as GraphicObject).MouseIsIn (m);
-                                       else return true;
-                               }
+                               if (scr == null) 
+                                       return Parent.MouseIsIn (m);
                                return scr.MouseIsIn (scr.savedMousePos);
                        }
                        return false;
@@ -1167,10 +1158,8 @@ namespace Crow
                }
                public virtual void onMouseMove(object sender, MouseMoveEventArgs e)
                {
-                       //bubble event to the top
-                       GraphicObject p = Parent as GraphicObject;
-                       if (p != null)
-                               p.onMouseMove(sender,e);
+                       if (Parent != null)
+                               Parent.onMouseMove(sender,e);
 
                        MouseMove.Raise (sender, e);
                }
@@ -1191,17 +1180,15 @@ namespace Crow
                                }
                        }
                        //bubble event to the top
-                       GraphicObject p = Parent as GraphicObject;
-                       if (p != null)
-                               p.onMouseDown(sender,e);
+                       if (Parent != null)
+                               Parent.onMouseDown(sender,e);
 
                        MouseDown.Raise (this, e);
                }
                public virtual void onMouseUp(object sender, MouseButtonEventArgs e){
                        //bubble event to the top
-                       GraphicObject p = Parent as GraphicObject;
-                       if (p != null)
-                               p.onMouseUp(sender,e);
+                       if (Parent != null)
+                               Parent.onMouseUp(sender,e);
 
                        MouseUp.Raise (this, e);
 
@@ -1212,21 +1199,18 @@ namespace Crow
                        }
                }
                public virtual void onMouseClick(object sender, MouseButtonEventArgs e){
-                       GraphicObject p = Parent as GraphicObject;
-                       if (p != null)
-                               p.onMouseClick(sender,e);
+                       if (Parent != null)
+                               Parent.onMouseClick(sender,e);
                        MouseClick.Raise (this, e);
                }
                public virtual void onMouseDoubleClick(object sender, MouseButtonEventArgs e){
-                       GraphicObject p = Parent as GraphicObject;
-                       if (p != null)
-                               p.onMouseDoubleClick(sender,e);
+                       if (Parent != null)
+                               Parent.onMouseDoubleClick(sender,e);
                        MouseDoubleClick.Raise (this, e);
                }
                public virtual void onMouseWheel(object sender, MouseWheelEventArgs e){
-                       GraphicObject p = Parent as GraphicObject;
-                       if (p != null)
-                               p.onMouseWheel(sender,e);
+                       if (Parent != null)
+                               Parent.onMouseWheel(sender,e);
 
                        MouseWheelChanged.Raise (this, e);
                }
diff --git a/src/GraphicObjects/ILayoutable.cs b/src/GraphicObjects/ILayoutable.cs
deleted file mode 100644 (file)
index 3315393..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Crow
-{
-       public interface ILayoutable
-       {
-               /// <summary> Parent in the graphic tree </summary>
-               ILayoutable Parent { get; set; }
-               /// <summary> The logical parent (used mainly for bindings) as opposed
-               ///  to the parent in the graphic tree </summary>
-               ILayoutable LogicalParent { get; set; }
-
-               Rectangle ClientRectangle { get; }
-               Rectangle getSlot();
-
-               bool ArrangeChildren { get; }
-               LayoutingType RegisteredLayoutings { get; set; }
-               void RegisterForLayouting(LayoutingType layoutType);
-               void RegisterClip(Rectangle clip);
-               bool UpdateLayout(LayoutingType layoutType);
-
-
-               Rectangle ContextCoordinates(Rectangle r);
-               Rectangle ScreenCoordinates (Rectangle r);
-
-       }
-}
-
index 3862133710b95208d0994a21ab1eb050ee1b7b42..e9887d9463c8d10e0719b775ffbc269f597b49e5 100644 (file)
@@ -119,7 +119,7 @@ namespace Crow
 
                protected void _content_LayoutChanged (object sender, LayoutingEventArgs e)
                {
-                       ILayoutable tc = Content.Parent;
+                       GraphicObject tc = Content.Parent;
                        if (tc == null)
                                return;
                        Rectangle r = this.ScreenCoordinates (this.Slot);
index 220fc4768ecd24f8089c6cfab2d432ea9877fba4..6d4f494ec7937f17e79f60ebc1904cd36a6a9b71 100644 (file)
@@ -64,7 +64,7 @@ namespace Crow
                }
 
                #region GraphicObject override
-               public override ILayoutable Parent {
+               public override GraphicObject Parent {
                        get { return base.Parent; }
                        set {
                                if (value != null) {                    
index 1debfedc65994ee6a0ce82badcab3f7048721aba..b79f41ebb7ab681dc6ab955223c06aa53e260660 100644 (file)
@@ -179,7 +179,7 @@ namespace Crow
                        if (SelectedTab > Children.Count - 1)
                                return;
 
-                       if (((Children[SelectedTab] as TabItem).Content.Parent as GraphicObject).MouseIsIn(e.Position))
+                       if ((Children[SelectedTab] as TabItem).Content.Parent.MouseIsIn(e.Position))
                        {
                                Children[SelectedTab].checkHoverWidget (e);
                                return;
index 4fa881b4e0e3c08bc73308f6e724e919776e5faa..ee73ed198319b70773e156e747f988e755aedf42 100644 (file)
@@ -61,7 +61,7 @@ namespace Crow
                        //register ItemClick on the Root node
                        TreeView tv = this as TreeView;
                        while (!tv.IsRoot) {
-                               ILayoutable tmp = tv.Parent;
+                               GraphicObject tmp = tv.Parent;
                                while (!(tmp is TreeView)) {
                                        tmp = tmp.Parent;
                                }
index 542cf2dd7af090acdc113ac5a6c7aa49f2fd6508..d06870efc19ee861a0f5b985bf510bc44c5420a5 100644 (file)
@@ -41,7 +41,7 @@ namespace Crow
        ///     - helpers to load XML interfaces files
        ///     - global constants and variables of CROW
        /// </summary>
-       public class Interface : ILayoutable
+       public class Interface : GraphicObject
        {
                #region CTOR
                static Interface(){
@@ -580,9 +580,9 @@ namespace Crow
                                //check topmost graphicobject first
                                GraphicObject tmp = HoverWidget;
                                GraphicObject topc = null;
-                               while (tmp is GraphicObject) {
+                               while (!(tmp is Interface)) {
                                        topc = tmp;
-                                       tmp = tmp.LogicalParent as GraphicObject;
+                                       tmp = tmp.LogicalParent;
                                }
                                int idxhw = GraphicTree.IndexOf (topc);
                                if (idxhw != 0) {
@@ -592,7 +592,7 @@ namespace Crow
                                                        if (GraphicTree [i].MouseIsIn (e.Position)) {
                                                                while (HoverWidget != null) {
                                                                        HoverWidget.onMouseLeave (HoverWidget, e);
-                                                                       HoverWidget = HoverWidget.LogicalParent as GraphicObject;
+                                                                       HoverWidget = HoverWidget.LogicalParent;
                                                                }
 
                                                                GraphicTree [i].checkHoverWidget (e);
@@ -610,8 +610,8 @@ namespace Crow
                                } else {
                                        HoverWidget.onMouseLeave (HoverWidget, e);
                                        //seek upward from last focused graph obj's
-                                       while (HoverWidget.LogicalParent as GraphicObject != null) {
-                                               HoverWidget = HoverWidget.LogicalParent as GraphicObject;
+                                       while (!(HoverWidget.LogicalParent is Interface)) {
+                                               HoverWidget = HoverWidget.LogicalParent;
                                                if (HoverWidget.MouseIsIn (e.Position)) {
                                                        HoverWidget.checkHoverWidget (e);
                                                        return true;
@@ -683,6 +683,26 @@ namespace Crow
                        HoverWidget.onMouseWheel (this, e);
                        return true;
                }
+
+
+               public override void onMouseMove (object sender, MouseMoveEventArgs e)
+               {                       
+               }
+               public override void onMouseUp (object sender, MouseButtonEventArgs e)
+               {                       
+               }
+               public override void onMouseDown (object sender, MouseButtonEventArgs e)
+               {
+               }
+               public override void onMouseClick (object sender, MouseButtonEventArgs e)
+               {                       
+               }
+               public override void onMouseDoubleClick (object sender, MouseButtonEventArgs e)
+               {                       
+               }
+               public override void onMouseWheel (object sender, MouseWheelEventArgs e)
+               {                       
+               }
                #endregion
 
                #region Keyboard
@@ -752,39 +772,31 @@ namespace Crow
                #endregion
 
                #region ILayoutable implementation
-               public void RegisterClip(Rectangle r){
-                       clipping.AddRectangle (r);
-               }
-               public bool ArrangeChildren { get { return false; }}
-               public int LayoutingTries {
-                       get { throw new NotImplementedException (); }
-                       set { throw new NotImplementedException (); }
-               }
-               public LayoutingType RegisteredLayoutings {
+               public override void RegisterClip(Rectangle r){ clipping.AddRectangle (r); }
+               public override LayoutingType RegisteredLayoutings {
                        get { return LayoutingType.None; }
                        set { throw new NotImplementedException (); }
                }
-               public void RegisterForLayouting (LayoutingType layoutType) { throw new NotImplementedException (); }
-               public bool UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); }
-               public Rectangle ContextCoordinates (Rectangle r) { return r;}
-               public Rectangle ScreenCoordinates (Rectangle r) { return r; }
-
-               public ILayoutable Parent {
-                       get { return null; }
-                       set { throw new NotImplementedException (); }
-               }
-               public ILayoutable LogicalParent {
-                       get { return null; }
-                       set { throw new NotImplementedException (); }
-               }
-
-               public Rectangle ClientRectangle {
-                       get { return clientRectangle; }
-               }
-               public Interface HostContainer {
-                       get { return this; }
+               public override Rectangle ContextCoordinates (Rectangle r) { return r;}
+               public override Rectangle ScreenCoordinates (Rectangle r) { return r; }
+               public override Rectangle ClientRectangle { get { return clientRectangle; }}
+               public override Rectangle getSlot () { return ClientRectangle; }
+               public override Measure WidthPolicy { get { return Measure.Stretched; }}
+               public override Measure HeightPolicy { get { return Measure.Stretched; }}
+               public override Measure Width {
+                       get { return clientRectangle.Width;     }
+                       set {}
+               }
+               public override Measure Height {
+                       get { return clientRectangle.Height;    }
+                       set {}
+               }
+               public override bool MouseIsIn (Point m){ return true; }
+               public override void RegisterForLayouting (LayoutingType layoutType)
+               {
+                       //base.RegisterForLayouting (layoutType);
+                       return;
                }
-               public Rectangle getSlot () { return ClientRectangle; }
                #endregion
        }
 }
index 95bc6bb725a29ea5d9d1598b74050f708a43fbf7..3c5ceb3e6c78b7abe6641f7990448aca24070971 100644 (file)
@@ -45,7 +45,7 @@ namespace Crow
        public struct LayoutingQueueItem
        {
                /// <summary> Instance of widget to be layouted</summary>
-               public ILayoutable Layoutable;
+               public GraphicObject Layoutable;
                /// <summary> Bitfield containing the element of the layout to performs (x|y|width|height)</summary>
                public LayoutingType LayoutType;
                /// <summary> Unsuccessfull UpdateLayout and requeueing count </summary>
@@ -72,7 +72,7 @@ namespace Crow
                #endif
 
                #region CTOR
-               public LayoutingQueueItem (LayoutingType _layoutType, ILayoutable _graphicObject)
+               public LayoutingQueueItem (LayoutingType _layoutType, GraphicObject _graphicObject)
                {                       
                        LayoutType = _layoutType;
                        Layoutable = _graphicObject;
@@ -100,17 +100,18 @@ namespace Crow
                        }
                        #if DEBUG_LAYOUTING
                        LQITime.Start();
+                       Debug.WriteLine ("LAYOUTING: " + this.ToString ());
                        #endif
                        LayoutingTries++;
                        if (!Layoutable.UpdateLayout (LayoutType)) {
                                if (LayoutingTries < Interface.MaxLayoutingTries) {
                                        Layoutable.RegisteredLayoutings |= LayoutType;
-                                       (Layoutable as GraphicObject).CurrentInterface.LayoutingQueue.Enqueue (this);
+                                       Layoutable.CurrentInterface.LayoutingQueue.Enqueue (this);
                                } else if (DiscardCount < Interface.MaxDiscardCount) {
                                        LayoutingTries = 0;
                                        DiscardCount++;
                                        Layoutable.RegisteredLayoutings |= LayoutType;
-                                       (Layoutable as GraphicObject).CurrentInterface.DiscardQueue.Enqueue (this);
+                                       Layoutable.CurrentInterface.DiscardQueue.Enqueue (this);
                                }
                                #if DEBUG_LAYOUTING
                                else