]> O.S.I.I.S - jp/crow.git/commitdiff
Simpler Combo, derived from ListBox with a popper as template root
authorjpbruyere <jp.bruyere@hotmail.com>
Tue, 9 Feb 2016 17:35:33 +0000 (18:35 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Tue, 9 Feb 2016 17:49:44 +0000 (18:49 +0100)
Crow.csproj
Templates/ComboBox.goml
Templates/ComboBoxOverlay.goml [deleted file]
Tests/Interfaces/testCombobox.goml
src/GraphicObjects/ComboBox.cs
src/GraphicObjects/ListBox.cs
src/GraphicObjects/Popper.cs

index 5d2ad868ff5a988f2aad71fa7ea057c56b75c5a2..31d5cd1b2106bdae2a2c64893aa64de7a6a30f02 100644 (file)
     <EmbeddedResource Include="Images\Icons\Cursors\move" />
     <EmbeddedResource Include="Templates\CheckBox.goml" />
     <EmbeddedResource Include="Templates\ComboBox.goml" />
-    <EmbeddedResource Include="Templates\ComboBoxOverlay.goml" />
     <EmbeddedResource Include="Templates\GroupBox.goml" />
     <EmbeddedResource Include="Templates\ListBox.goml" />
     <EmbeddedResource Include="Templates\ScrollBar.goml" />
index a4272d617acbe0d9a12cf377d2c87f4a71b3780e..5938117290378311df23e9daab048df42e94cb0b 100755 (executable)
@@ -1,10 +1,24 @@
 <?xml version="1.0"?>
-<Border CornerRadius="0" Foreground="LightGray" Height="{../TemplatedHeight}" Width="{../TemplatedWidth}">
-       <HorizontalStack Margin="1" Spacing="1" Height="{../../TemplatedHeight}" Width="{../../TemplatedWidth}">
-               <Label Margin="1" Foreground="Black" Background="White" Text="{../../../Caption}" 
-                       Height="{../../../TemplatedHeight}" Width="{../../../TemplatedWidth}"/>
-               <Button Width="14" Height="14" >
-                       <Image Margin="0"  Path="#Crow.Images.Icons.updown.svg" SvgSub="down"/>
-               </Button>
-       </HorizontalStack>
-</Border>
\ No newline at end of file
+<Popper PopDirection="Bottom" Height="{../TemplatedHeight}" Width="{../TemplatedWidth}">
+       <Template>
+               <Border CornerRadius="0" Foreground="LightGray" Height="{../TemplatedHeight}" Width="{../TemplatedWidth}">
+                       <HorizontalStack Margin="1" Spacing="1" Height="{../../TemplatedHeight}" Width="{../../TemplatedWidth}">
+                               <TextBox MinimumSize="80;10" Margin="1" Foreground="Black" Background="White"
+                                       Text="{../../../../SelectedItem}" Focusable="true"
+                                       Height="{../../../../TemplatedHeight}" Width="{../../../../TemplatedWidth}"/>
+                               <Button Width="14" Height="14" MouseClick="../../../onMouseClick"
+                                       Template="#Crow.Templates.ArrowButTemplate.crow">
+                                       <Image Margin="0"  Path="#Crow.Images.Icons.updown.svg" SvgSub="down"/>
+                               </Button>
+                       </HorizontalStack>
+               </Border>
+       </Template>
+       <Border Background="DimGray" BorderWidth="1" Margin="1" MinimumSize="100;100" MaximumSize="200;300" Height="-1" Width="-1">
+               <Scroller  Name="scroller1" Margin="1" VerticalScrolling="true"
+                       Height="200" Width="-1"
+                       ValueChanged="../../../_scroller_ValueChanged">
+                       <VerticalStack LayoutChanged="../../../../_list_LayoutChanged"
+                               Height="-1" Width="-1" Name="List" Margin="0" VerticalAlignment="Top"/>
+               </Scroller>
+       </Border>
+</Popper>
diff --git a/Templates/ComboBoxOverlay.goml b/Templates/ComboBoxOverlay.goml
deleted file mode 100755 (executable)
index 53782ac..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0"?>
-<Border BorderWidth="1" Margin="1" MinimumSize="20;20" Height="{../TemplatedHeight}" Width="{../TemplatedWidth}" >
-<!--   <Scroller  Name="scroller1" Margin="1" VerticalScrolling="true"
-               Height="{../../TemplatedHeight}" Width="{../../TemplatedWidth}">-->
-               <VerticalStack Height="-1" Width="{../../../TemplatedWidth}" Name="List" Margin="0" VerticalAlignment="Top"/>
-<!--   </Scroller>-->
-</Border>
\ No newline at end of file
index 2f5e69e570d38da9f2fc706273169b6430a8636a..7fe9118cc09d4c23b70d2fc8d814aa6b46918e58 100755 (executable)
@@ -1,2 +1,4 @@
 <?xml version="1.0"?>
-<ComboBox Height="-1" Data="{TestList}" SelectedIndex="0"/>
\ No newline at end of file
+<VerticalStack>
+       <ComboBox Width="200" Data="{TestList}" SelectedItem="Blue"/>
+</VerticalStack>
\ No newline at end of file
index c071cb5e8853c5915eef8634cac1eaafbe5bde9c..f337a2f408721d3668613916ff03c50a84b85043 100644 (file)
@@ -21,341 +21,10 @@ using System.Threading;
 namespace Crow
 {
        [DefaultTemplate("#Crow.Templates.ComboBox.goml")]
-       [DefaultOverlayTemplate("#Crow.Templates.ComboBoxOverlay.goml")]
-       public class ComboBox : TemplatedContainer
+       public class ComboBox : ListBox
     {          
                #region CTOR
                public ComboBox() : base(){     }       
                #endregion
-
-               bool _isPopped;
-               string caption;
-               GraphicObject _overlay;
-               Group _list;
-               IList data;
-               int _selectedIndex;
-               object _selectedItem;
-               string _itemTemplate;
-               string _overlayTemplate;
-
-               public event EventHandler Pop;
-               public event EventHandler Unpop;
-               public event EventHandler<SelectionChangeEventArgs> SelectedItemChanged;
-
-               #region implemented abstract members of TemplatedControl
-               protected override void loadTemplate (GraphicObject template)
-               {
-                       base.loadTemplate (template);
-                       loadOverlayTemplate (null);
-               }
-               public override GraphicObject Content {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
-               }
-               #endregion
-
-               protected virtual void loadOverlayTemplate(GraphicObject overlayTemplate)
-               {
-                       if (overlayTemplate == null) {
-                               DefaultOverlayTemplate dt = (DefaultOverlayTemplate)this.GetType ().GetCustomAttributes (typeof(DefaultOverlayTemplate), true).FirstOrDefault ();
-                               Overlay = Interface.Load (dt.Path);
-                               Overlay.ResolveBindings ();
-                       } else
-                               Overlay = overlayTemplate;
-                       _list = Overlay.FindByName ("List") as Group;
-               }
-
-               [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")]
-               public string ItemTemplate {
-                       get { return _itemTemplate; }
-                       set { 
-                               //TODO:reload list with new template?
-                               _itemTemplate = value; 
-                       }
-               }
-               [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ComboBoxOverlay.goml")]
-               public string OverlayTemplate {
-                       get { return _overlayTemplate; }
-                       set { 
-                               //TODO:reload list with new template?
-                               _overlayTemplate = value; 
-
-                               Overlay = Interface.Load (_overlayTemplate);
-                               Overlay.ResolveBindings ();
-                               _list = Overlay.FindByName ("List") as Group;
-                       }
-               }
-               [XmlAttributeAttribute][DefaultValue(-1)]
-               public int SelectedIndex{
-                       get { return _selectedIndex; }
-                       set { 
-                               //store value event if data is null, because in xml parsing selindex is always
-                               //before data, so it's impossible without that trick to set a default index in goml
-                               _selectedIndex = value; 
-       
-                               if (data == null)                                       
-                                       return;
-       
-                               if (_selectedIndex > data.Count - 1 || _selectedIndex < 0)
-                                       throw new Exception ("Combobox SelectedIndex out of range");
-
-
-                               _selectedItem = data [_selectedIndex];
-                               NotifyValueChanged ("SelectedIndex", SelectedIndex);
-                               SelectedItemChanged.Raise (this, new SelectionChangeEventArgs(_selectedItem));
-
-                               if (SelectedItem == null)
-                                       Caption = "";
-                               else
-                                       Caption = _selectedItem.ToString ();
-                               }
-               }
-               public object SelectedItem{
-                       set {
-                               if (_selectedItem == value)
-                                       return;
-
-                               _selectedItem = value;
-                               _selectedIndex = data.IndexOf (_selectedItem);
-                               NotifyValueChanged ("SelectedIndex", _selectedIndex);
-                               SelectedItemChanged.Raise (this, new SelectionChangeEventArgs(_selectedItem));
-
-                               if (SelectedItem == null)
-                                       Caption = "";
-                               else
-                                       Caption = _selectedItem.ToString ();
-                       }
-
-                       get { return _selectedItem; }
-               }
-               [XmlAttributeAttribute][DefaultValue(null)]
-               public IList Data {
-                       get {
-                               return data;
-                       }
-                       set {                           
-                               data = value;
-                               if (_list == null)
-                                       return;
-
-                               foreach (GraphicObject c in _list.Children) {
-                                       c.ClearBinding ();
-                               }
-                               _list.Children.Clear ();
-                               _list.registerForGraphicUpdate ();
-                               if (data == null)
-                                       return;
-                               if (SelectedIndex < 0)
-                                       return;
-
-                               //force raise of changes
-                               SelectedIndex = SelectedIndex;
-
-                               pendingChildrenAddition = new Queue<GraphicObject> ();
-                               threadedLoadingFinished = false;
-
-                               Thread t = new Thread (loadingThread);
-                               t.Start ();
-                               t.Join ();
-
-                       }
-               }
-
-               internal void CheckPendingChildrenAddition()
-               {
-                       if (pendingChildrenAddition == null)
-                               return;
-                       lock (pendingChildrenAddition) {
-                               if (!threadedLoadingFinished && pendingChildrenAddition.Count < 50)
-                                       return;
-                               while (pendingChildrenAddition.Count > 0) {
-                                       _list.AddChild (pendingChildrenAddition.Dequeue ());
-                               }
-                       }
-               }
-
-               volatile Queue<GraphicObject> pendingChildrenAddition;
-               volatile bool threadedLoadingFinished = false;
-
-               void loadingThread()
-               {
-                       #if DEBUG_LOAD_TIME
-                       Stopwatch loadingTime = new Stopwatch ();
-                       loadingTime.Start ();
-                       #endif
-
-                       MemoryStream ms = new MemoryStream ();
-                       lock (ItemTemplate) {
-                               using (Stream stream = Interface.GetStreamFromPath (ItemTemplate))
-                                       stream.CopyTo (ms);
-                       }
-
-                       Type t = Interface.GetTopContainerOfGOMLStream (ms);
-
-                       foreach (var item in data) {
-                               ms.Seek(0,SeekOrigin.Begin);
-                               GraphicObject g = Interface.Load (ms, t);
-                               g.DataSource = item;
-                               g.MouseClick += itemClick;
-
-                               lock (pendingChildrenAddition) {
-                                       pendingChildrenAddition.Enqueue (g);
-                               }
-                       }
-
-                       ms.Dispose ();                  
-
-                       threadedLoadingFinished = true;
-
-                       #if DEBUG_LOAD_TIME
-                       loadingTime.Stop ();
-                       Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms",
-                       loadingTime.ElapsedTicks,
-                       loadingTime.ElapsedMilliseconds, this.ToString());
-                       #endif
-               }
-               public GraphicObject Overlay {
-                       get { return _overlay; }
-                       set { 
-                               if (_overlay != null) {
-                                       _overlay.LayoutChanged -= _overlay_LayoutChanged;
-                                       _overlay.MouseLeave -= _overlay_MouseLeave;
-                                       _overlay.LogicalParent = null;
-                               }
-
-                               _overlay = value; 
-
-                               if (_overlay == null)
-                                       return;
-
-                               _overlay.LogicalParent = this;
-                               _overlay.Focusable = true;
-                               _overlay.LayoutChanged += _overlay_LayoutChanged;
-                               _overlay.MouseLeave += _overlay_MouseLeave;
-                       }
-               }
-               [XmlAttributeAttribute()][DefaultValue("Combobox")]
-               public string Caption {
-                       get { return caption; } 
-                       set {
-                               if (caption == value)
-                                       return;
-                               caption = value; 
-                               NotifyValueChanged ("Caption", caption);
-                       }
-               }        
-               [XmlAttributeAttribute()][DefaultValue(false)]
-               public bool IsPopped
-               {
-                       get { return _isPopped; }
-                       set
-                       {
-                               _isPopped = value;
-
-                               if (_isPopped) {
-                                       onPop (this, null);
-                                       NotifyValueChanged ("SvgSub", "expanded");
-                                       return;
-                               }
-
-                               onUnpop (this, null);
-                               NotifyValueChanged ("SvgSub", "collapsed");
-                       }
-               }
-
-               void itemClick(object sender, OpenTK.Input.MouseButtonEventArgs e){
-                       object datasource = (sender as GraphicObject).DataSource;
-                       SelectedItem = datasource;
-                       IsPopped = false;
-                       //Debug.WriteLine ((sender as GraphicObject).DataSource);
-               }
-               void _overlay_MouseLeave (object sender, MouseMoveEventArgs e)
-               {
-                       IsPopped = false;
-               }
-               void _overlay_LayoutChanged (object sender, LayoutingEventArgs e)
-               {
-                       ILayoutable tc = Overlay.Parent as ILayoutable;
-                       if (tc == null)
-                               return;
-                       Rectangle r = this.ScreenCoordinates (this.Slot);
-                       if (e.LayoutType == LayoutingType.Width) {
-                               if (Overlay.Slot.Width < tc.ClientRectangle.Width) {
-                                       if (r.Left + Overlay.Slot.Width > tc.ClientRectangle.Right)
-                                               Overlay.Left = tc.ClientRectangle.Right - Overlay.Slot.Width;
-                                       else
-                                               Overlay.Left = r.Left;
-                               }else
-                                       Overlay.Left = 0;
-                       }else if (e.LayoutType == LayoutingType.Height) {
-                               if (Overlay.Slot.Height < tc.ClientRectangle.Height) {
-                                       if (r.Bottom + Overlay.Slot.Height > tc.ClientRectangle.Bottom)
-                                               Overlay.Top = r.Top - Overlay.Slot.Height;
-                                       else
-                                               Overlay.Top = r.Bottom;
-                               }else
-                                       Overlay.Top = 0;
-                       }
-               }
-
-               [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true
-               public override bool Focusable
-               {
-                       get { return base.Focusable; }
-                       set { base.Focusable = value; }
-               }
-
-                       
-               public virtual void onPop(object sender, EventArgs e)
-               {
-                       IGOLibHost tc = HostContainer;
-                       if (tc == null)
-                               return;
-                       if (Overlay != null) {
-                               Overlay.Visible = true;
-                               if (Overlay.Parent == null)
-                                       tc.AddWidget (Overlay);
-                               (tc as OpenTKGameWindow).PutOnTop (Overlay);
-                       }
-                       Pop.Raise (this, e);
-               }
-               public virtual void onUnpop(object sender, EventArgs e)
-               {
-                       IGOLibHost tc = HostContainer;
-                       if (tc == null)
-                               return;
-                       Overlay.Visible = false;
-                       Unpop.Raise (this, e);
-               }
-                       
-               public override void onMouseClick (object sender, MouseButtonEventArgs e)
-               {
-                       IsPopped = !IsPopped;
-                       base.onMouseClick (sender, e);
-               }
-
-               public override void ClearBinding ()
-               {
-                       //ensure popped window is cleared
-                       if (Overlay != null) {
-                               if (Overlay.Parent != null) {
-                                       IGOLibHost tc = Overlay.Parent as IGOLibHost;
-                                       if (tc != null)
-                                               tc.DeleteWidget (Overlay);
-                               }
-                       }
-                       base.ClearBinding ();
-
-               }
-               public override void ResolveBindings ()
-               {
-                       base.ResolveBindings ();
-                       if (Overlay != null)
-                               Overlay.ResolveBindings ();
-               }
        }
 }
index c90593cb32c467a3e73e53efda156c7a061a8bea..8cfffe493d35fb48810c7df9734685d8016850c3 100644 (file)
@@ -90,7 +90,7 @@ namespace Crow
                        }
                }
                public object SelectedItem{
-                       get { return data == null ? null : data[_selectedIndex]; }
+                       get { return data == null ? "none" : data[_selectedIndex]; }
                }
                [XmlAttributeAttribute]//[DefaultValue(null)]
                public IList Data {
@@ -157,7 +157,7 @@ namespace Crow
                        loadingTime.ElapsedMilliseconds, this.ToString());
                        #endif
                }
-               void _scroller_ValueChanged (object sender, ValueChangeEventArgs e)
+               protected void _scroller_ValueChanged (object sender, ValueChangeEventArgs e)
                {
                        if (_gsList == null)
                                return;
@@ -177,7 +177,7 @@ namespace Crow
                                }
                        }
                }
-               void _list_LayoutChanged (object sender, LayoutingEventArgs e)
+               protected void _list_LayoutChanged (object sender, LayoutingEventArgs e)
                {
                        if (_gsList == null)
                                return;
@@ -211,6 +211,7 @@ namespace Crow
                        SelectedItemChanged.Raise (sender, new SelectionChangeEventArgs((sender as GraphicObject).DataSource));
                        NotifyValueChanged ("SelectedItem", (sender as GraphicObject).DataSource);
                        //Debug.WriteLine ((sender as GraphicObject).DataSource);
+
                }
 
                #region IXmlSerializable
index e0b821a8d453aeb6fe908b506be8e372273c9503..171e54e40d44055bfa73d5a71c403b7ebc180ee3 100644 (file)
@@ -26,6 +26,7 @@ namespace Crow
                {
                }       
                #endregion
+
                bool _isPopped;
                string caption;
                string image;
@@ -52,7 +53,7 @@ namespace Crow
                        }
                }
 
-               void _content_LayoutChanged (object sender, LayoutingEventArgs e)
+               protected void _content_LayoutChanged (object sender, LayoutingEventArgs e)
                {
                        ILayoutable tc = Content.Parent as ILayoutable;
                        if (tc == null)