]> O.S.I.I.S - jp/crow.git/commitdiff
Derive ListBox from TemplatedGroup
authorjpbruyere <jp.bruyere@hotmail.com>
Sun, 4 Sep 2016 16:41:04 +0000 (18:41 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Sun, 4 Sep 2016 16:41:04 +0000 (18:41 +0200)
Move Data List handling and selection in TemplatedGroup
modifié :         Templates/ComboBox.template
modifié :         Templates/ListBox.template
modifié :         Templates/ScrollingListBox.goml
modifié :         Templates/TreeView.template
modifié :         Templates/treeList.crow
modifié :         Tests/BasicTests.cs
modifié :         Tests/Interfaces/TemplatedContainer/testTreeView.crow
modifié :         Tests/Interfaces/TemplatedControl/testItemTemplateTag.crow
modifié :         src/GraphicObjects/ListBox.cs
modifié :         src/GraphicObjects/MenuItem.cs
modifié :         src/GraphicObjects/TemplatedControl.cs
modifié :         src/GraphicObjects/TemplatedGroup.cs
modifié :         src/GraphicObjects/TreeView.cs
modifié :         src/IMLReader.cs
modifié :         src/ItemTemplate.cs

15 files changed:
Templates/ComboBox.template
Templates/ListBox.template
Templates/ScrollingListBox.goml
Templates/TreeView.template
Templates/treeList.crow
Tests/BasicTests.cs
Tests/Interfaces/TemplatedContainer/testTreeView.crow
Tests/Interfaces/TemplatedControl/testItemTemplateTag.crow
src/GraphicObjects/ListBox.cs
src/GraphicObjects/MenuItem.cs
src/GraphicObjects/TemplatedControl.cs
src/GraphicObjects/TemplatedGroup.cs
src/GraphicObjects/TreeView.cs
src/IMLReader.cs
src/ItemTemplate.cs

index 9688721a794a29021b1f3bc8217f59443833f50d..d28a7b913758b76e6487ec45cc00cf9576ae56cb 100755 (executable)
@@ -22,7 +22,7 @@
                        HorizontalAlignment="Left"
                        ValueChanged="../../../_scroller_ValueChanged">
                        <VerticalStack LayoutChanged="../../../../_list_LayoutChanged"
-                               Height="Fit" Width="{../../WidthPolicy}" Name="List" Margin="0"
+                               Height="Fit" Width="{../../WidthPolicy}" Name="ItemsContainer" Margin="0"
                                HorizontalAlignment="Left"
                                VerticalAlignment="Top"/>
                </Scroller>
index c56ec0d05ae0a3b8894dc72bf0248a3d8e7d6f89..36f2f61e218e626d375f4edd00a2fabbb0db130a 100755 (executable)
@@ -4,6 +4,6 @@
                Height="{./HeightPolicy}" Width="{./WidthPolicy}"
                ValueChanged="./_scroller_ValueChanged">
                <VerticalStack LayoutChanged="./_list_LayoutChanged"
-                       Height="Fit" Width="{./WidthPolicy}" Name="List" Margin="0" VerticalAlignment="Top"/>
+                       Height="Fit" Width="{./WidthPolicy}" Name="ItemsContainer" Margin="0" VerticalAlignment="Top"/>
        </Scroller>
 </Border>
\ No newline at end of file
index a746cb652f4ea114c1062190184388834d40efd4..54e3eb482c27494e71c849b4117b6b80aed0e4c9 100644 (file)
@@ -5,7 +5,7 @@
                                Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}"
                                ValueChanged="./_scroller_ValueChanged">
                        <VerticalStack Width="{./WidthPolicy}" Height="-1" MinimumSize="10,10"
-                               Name="List" Margin="0" VerticalAlignment="Top"
+                               Name="ItemsContainer" Margin="0" VerticalAlignment="Top"
                                LayoutChanged="./_list_LayoutChanged"/>
                </Scroller>
                <ScrollBar Name="scrollbar1" Value="{../scroller1.ScrollY}" 
index bd50e54a178523809cce16fca4affaf53c072b73..377de50cc6da730487f44f87b1914d1741c4c890 100644 (file)
@@ -6,7 +6,7 @@
                ScrollY="{../scrollbar1.Value}"
                ValueChanged="./_scroller_ValueChanged">
                <VerticalStack LayoutChanged="./_list_LayoutChanged"
-                       Height="Fit" Width="{./WidthPolicy}" Name="List" Margin="0" VerticalAlignment="Top"/>
+                       Height="Fit" Width="{./WidthPolicy}" Name="ItemsContainer" Margin="0" VerticalAlignment="Top"/>
        </Scroller>
        <ScrollBar
                Name="scrollbar1"
index 61ee12a44d01d5c15b1bb979017005673b2ed2f9..160f351a7475cce73a98139bbf9d1dccb3f3c89b 100755 (executable)
@@ -1,3 +1,3 @@
 <?xml version="1.0"?>
 <VerticalStack
-       Height="Fit" Width="{../WidthPolicy}" Name="List"/>
\ No newline at end of file
+       Height="Fit" Width="{../WidthPolicy}" Name="ItemsContainer"/>
\ No newline at end of file
index 62ddc567fe3eeb018a6bdf2f3d3a8629d7c1da40..cd9e3ba37175d6b36df4686c814f905060d6383d 100644 (file)
@@ -145,8 +145,12 @@ namespace Tests
                                idx = testFiles.Length - 1;
                        
                        this.Title = testFiles [idx] + ". Press <F3> to cycle examples.";
-                       GraphicObject obj = CrowInterface.LoadInterface(testFiles[idx]);
-                       obj.DataSource = this;
+                       try {
+                               GraphicObject obj = CrowInterface.LoadInterface(testFiles[idx]);
+                               obj.DataSource = this;
+                       } catch (Exception ex) {
+                               Debug.WriteLine (ex.Message + ex.InnerException);
+                       }
                }
                void Tv_SelectedItemChanged (object sender, SelectionChangeEventArgs e)
                {
index 3a44bf34b7e8d85a0671f43bdfb6adc3fb4d75b9..e8e7164516887d041631e4959625dab7ab1762d2 100755 (executable)
@@ -32,7 +32,7 @@
                                <GraphicObject Width="12" Height="10"/>
                                <TreeView Name="List" Height="Fit" Width="{./WidthPolicy}">
                                        <Template>
-                                               <VerticalStack Height="Fit" Width="{../WidthPolicy}" Name="List"/>
+                                               <VerticalStack Height="Fit" Width="{../WidthPolicy}" Name="ItemsContainer"/>
                                        </Template>
                                </TreeView>
                        </HorizontalStack>
index 5f86071903facfb3dee1ef657622503d7f500e31..94625915349917515fe5ac53dda9bb8e9ff9bb72 100755 (executable)
@@ -10,7 +10,7 @@
                                                                Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}"
                                                                ValueChanged="../../../_scroller_ValueChanged">
                                                        <VerticalStack Width="{../../../../WidthPolicy}" Height="Fit" MinimumSize="10,10"
-                                                               Name="List" Margin="0"
+                                                               Name="ItemsContainer" Margin="0"
                                                                VerticalAlignment="Top"
                                                                HorizontalAlignment="Left"
                                                                LayoutChanged="../../../../_list_LayoutChanged"/>
index ffbaf3e8cd2478d9475877866b91c3d59c6895f2..82a4014b14ce87bf9d1f0a65ce46c6f3ce65c410 100644 (file)
@@ -30,210 +30,12 @@ using System.Threading;
 
 namespace Crow
 {
-       public class ListBox : TemplatedControl
+       public class ListBox : TemplatedGroup
        {
                #region CTOR
                public ListBox () : base() {}
                #endregion
 
-               #region events
-               public event EventHandler<SelectionChangeEventArgs> SelectedItemChanged;
-               #endregion
-
-               Group _list;
-               GenericStack _gsList;
-               IList data;
-               int _selectedIndex;
-               int itemPerPage = 50;
-               Thread loadingThread = null;
-               volatile bool cancelLoading = false;
-
-               [XmlAttributeAttribute]public IList Data {
-                       get {
-                               return data;
-                       }
-                       set {
-                               if (value == data)
-                                       return;
-                               
-                               cancelLoadingThread ();
-
-                               data = value;
-
-                               NotifyValueChanged ("Data", data);
-
-                               lock (CurrentInterface.UpdateMutex)
-                                       _list.ClearChildren ();
-                               if (_gsList.Orientation == Orientation.Horizontal)
-                                       _gsList.Width = -1;
-                               else
-                                       _gsList.Height = -1;
-
-                               if (data == null)
-                                       return;
-
-                               loadingThread = new Thread (loading);
-                               loadingThread.IsBackground = true;
-                               loadingThread.Start ();
-                               //loadPage(1);
-
-                               NotifyValueChanged ("SelectedIndex", _selectedIndex);
-                               NotifyValueChanged ("SelectedItem", SelectedItem);
-                               SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem));
-                       }
-               }
-
-               [XmlAttributeAttribute][DefaultValue(-1)]public int SelectedIndex{
-                       get { return _selectedIndex; }
-                       set { 
-                               if (value == _selectedIndex)
-                                       return;
-
-                               _selectedIndex = value; 
-
-                               NotifyValueChanged ("SelectedIndex", _selectedIndex);
-                               NotifyValueChanged ("SelectedItem", SelectedItem);
-                               SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem));
-                       }
-               }
-               [XmlIgnore]public virtual object SelectedItem{
-                       get { return data == null ? null : _selectedIndex < 0 ? null : data[_selectedIndex]; }
-               }
-               protected void raiseSelectedItemChanged(){
-                       SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem));
-               }
-                       
-               #region TemplatedControl override
-               protected override void loadTemplate (GraphicObject template = null)
-               {
-                       base.loadTemplate (template);
-                       _list = this.child.FindByName ("List") as Group;
-                       if (_list == null)
-                               throw new Exception ("ListBox Template MUST contain a Goup widget named 'List'.");
-                       _gsList = _list as GenericStack;
-               }
-               #endregion
-
-               void loading(){
-                       if (ItemTemplates == null)
-                               ItemTemplates = new Dictionary<string, ItemTemplate> ();
-                       if (!ItemTemplates.ContainsKey ("default"))
-                               ItemTemplates ["default"] = Interface.GetItemTemplate (ItemTemplate);
-
-                       for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) {
-                               if (cancelLoading)
-                                       return;
-                               loadPage (i);
-                       }
-               }
-               void cancelLoadingThread(){
-                       if (loadingThread == null)
-                               return;
-                       if (!loadingThread.IsAlive)
-                               return;                 
-                       cancelLoading = true;
-                       loadingThread.Join ();
-                       cancelLoading = false;
-               }
-               void loadPage(int pageNum)
-               {
-                       #if DEBUG_LOAD
-                       Stopwatch loadingTime = new Stopwatch ();
-                       loadingTime.Start ();
-                       #endif
-
-                       Group page = _list.Clone () as Group;
-                       
-                       page.Name = "page" + pageNum;
-
-                       //reset size to fit in the dir of the stacking
-                       //because _list total size is forced to approx size
-                       if (_gsList.Orientation == Orientation.Horizontal) {
-                               page.Width = Measure.Fit;
-                               page.BindMember ("Height", "../HeightPolicy");
-                       } else {
-                               page.Height = Measure.Fit;
-                               page.BindMember ("Width", "../WidthPolicy");
-                       }
-
-                       for (int i = (pageNum - 1) * itemPerPage; i < pageNum * itemPerPage; i++) {
-                               if (i >= data.Count)
-                                       break;
-                               if (cancelLoading)
-                                       return;
-                               
-                               loadItem (i, page);
-
-                               //g.LogicalParent = this;
-                       }
-
-                       lock (CurrentInterface.LayoutMutex)
-                               _list.AddChild (page);
-
-                       #if DEBUG_LOAD
-                       loadingTime.Stop ();
-                       Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms",
-                       loadingTime.ElapsedTicks,
-                       loadingTime.ElapsedMilliseconds, this.ToString());
-                       #endif
-               }
-               protected void loadItem(int i, Group page){
-                       GraphicObject g = null;
-                       ItemTemplate iTemp = null;
-                       Type dataType = data [i].GetType ();
-
-                       if (ItemTemplates.ContainsKey (dataType.FullName))
-                               iTemp = ItemTemplates [dataType.FullName];
-                       else
-                               iTemp = ItemTemplates ["default"];
-
-                       lock (CurrentInterface.LayoutMutex) {
-                               g = iTemp.CreateInstance(CurrentInterface);
-                               page.AddChild (g);
-                               g.DataSource = data [i];
-                       }
-
-                       registerItemClick (g);
-
-                       if (iTemp.Expand != null && g is Expandable) {
-                               (g as Expandable).Expand += iTemp.Expand;
-                       }                       
-               }
-               protected virtual void registerItemClick(GraphicObject g){
-                       g.MouseClick += itemClick;
-               }
-               protected void _list_LayoutChanged (object sender, LayoutingEventArgs e)
-               {
-#if DEBUG_LAYOUTING
-                       Debug.WriteLine("list_LayoutChanged");
-#endif
-                       if (_gsList.Orientation == Orientation.Horizontal) {
-                               if (e.LayoutType == LayoutingType.Width)
-                                       _gsList.Width = approxSize;
-                       } else if (e.LayoutType == LayoutingType.Height)
-                               _gsList.Height = approxSize;
-               }
-               int approxSize
-               {
-                       get {
-                               if (data == null)
-                                       return -1;
-                               GenericStack page1 = _list.FindByName ("page1") as GenericStack;
-                               if (page1 == null)
-                                       return -1;
-                               
-                               return page1.Orientation == Orientation.Horizontal ?
-                                       data.Count < itemPerPage ?
-                                               -1:
-                                       (int)Math.Ceiling ((double)page1.Slot.Width / (double)itemPerPage * (double)(data.Count+1)):
-                                       data.Count < itemPerPage ?
-                                               -1:
-                                       (int)Math.Ceiling ((double)page1.Slot.Height / (double)itemPerPage * (double)(data.Count+1));
-                       }
-               }
-               internal virtual void itemClick(object sender, MouseButtonEventArgs e){
-                       SelectedIndex = data.IndexOf((sender as GraphicObject).DataSource);
-               }
        }
 }
 
index 6023336192fbbc74788b583e464dc8f6809f36d4..78162fbbd567fb8986c119612db4b81b22e18745 100644 (file)
@@ -101,11 +101,11 @@ namespace Crow
                {
                        Execute.Raise (this, null);
                }
-               void onOpen (object sender, EventArgs e){
+               protected virtual void onOpen (object sender, EventArgs e){
                        MenuRoot.IsOpened = true;
                        Open.Raise (this, null);
                }
-               void onClose (object sender, EventArgs e){
+               protected virtual void onClose (object sender, EventArgs e){
                        //MenuRoot.IsOpened = true;
                        Close.Raise (this, null);
                }
index cb14dfd9178c71dab3d28394de143673cd4572a0..7f2e1b87b3bf13f7ef962f97a27c2a920391f7c1 100644 (file)
@@ -46,9 +46,6 @@ namespace Crow
                }
 
                string _template;
-               string _itemTemplate;
-               public Dictionary<string, ItemTemplate> ItemTemplates = new Dictionary<string, Crow.ItemTemplate>();//TODO: dont instantiate if not used
-                                                                                                                                                                                                       //but then i should test if null in msil gen
                [XmlAttributeAttribute][DefaultValue(null)]
                public string Template {
                        get { return _template; }
@@ -63,19 +60,7 @@ namespace Crow
                                        loadTemplate (CurrentInterface.Load (_template));
                        }
                }
-               [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")]
-               public string ItemTemplate {
-                       get { return _itemTemplate; }
-                       set {
-                               if (value == _itemTemplate)
-                                       return;
 
-                               _itemTemplate = value;
-
-                               //TODO:reload list with new template?
-                               NotifyValueChanged("ItemTemplate", _itemTemplate);
-                       }
-               }
                #region GraphicObject overrides
                public override GraphicObject FindByName (string nameToFind)
                {
@@ -86,7 +71,7 @@ namespace Crow
                {
                        //onDraw is overrided to prevent default drawing of background, template top container
                        //may have a binding to root background or a fixed one.
-                       //this allow applying root background to random template component
+                       //this allow applying root background to random template's component
                        gr.Save ();
 
                        if (ClipToClientRect) {
@@ -113,6 +98,7 @@ namespace Crow
                        this.ResolveBindings ();
                }
 
+               //TODO:IXmlSerializable is not used anymore
                #region IXmlSerializable
                public override System.Xml.Schema.XmlSchema GetSchema(){ return null; }
                public override void ReadXml(System.Xml.XmlReader reader)
@@ -151,15 +137,15 @@ namespace Crow
                                                                xr.MoveToElement ();
                                                                itemTmp = xr.ReadInnerXml ();
 
-                                                               if (ItemTemplates == null)
-                                                                       ItemTemplates = new Dictionary<string, ItemTemplate> ();
-
-                                                               using (IMLReader iTmp = new IMLReader (null, itemTmp)) {
-                                                                       ItemTemplates [dataType] =
-                                                                               new ItemTemplate (iTmp.RootType, iTmp.GetLoader (), dataType, datas);
-                                                               }
-                                                               if (!string.IsNullOrEmpty (datas))
-                                                                       ItemTemplates [dataType].CreateExpandDelegate(this);
+//                                                             if (ItemTemplates == null)
+//                                                                     ItemTemplates = new Dictionary<string, ItemTemplate> ();
+//
+//                                                             using (IMLReader iTmp = new IMLReader (null, itemTmp)) {
+//                                                                     ItemTemplates [dataType] =
+//                                                                             new ItemTemplate (iTmp.RootType, iTmp.GetLoader (), dataType, datas);
+//                                                             }
+//                                                             if (!string.IsNullOrEmpty (datas))
+//                                                                     ItemTemplates [dataType].CreateExpandDelegate(this);
 
                                                                continue;
                                                        }
index 0d48b9eb24089d5248efd46293ee4fd6f48774a5..500e5ea658df86782f0cac756098fd8adbb5979b 100644 (file)
@@ -23,6 +23,9 @@ using System.Xml.Serialization;
 using System.Xml;
 using System.Reflection;
 using System.Collections.Generic;
+using System.ComponentModel;
+using System.Collections;
+using System.Threading;
 
 namespace Crow
 {
@@ -33,8 +36,127 @@ namespace Crow
                #endregion
 
                protected Group items;
+               string _itemTemplate;
+
+               #region events
+               public event EventHandler<SelectionChangeEventArgs> SelectedItemChanged;
+               #endregion
+
+               Group _list;
+               IList data;
+               int _selectedIndex;
+               Color selBackground, selForeground;
+
+               int itemPerPage = 50;
+               Thread loadingThread = null;
+               volatile bool cancelLoading = false;
+
+               #region Templating
+               //TODO: dont instantiate ItemTemplates if not used
+               //but then i should test if null in msil gen
+               public Dictionary<string, ItemTemplate> ItemTemplates = new Dictionary<string, Crow.ItemTemplate>();
+
+               [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")]
+               public string ItemTemplate {
+                       get { return _itemTemplate; }
+                       set {
+                               if (value == _itemTemplate)
+                                       return;
+
+                               _itemTemplate = value;
+
+                               //TODO:reload list with new template?
+                               NotifyValueChanged("ItemTemplate", _itemTemplate);
+                       }
+               }
+               protected override void loadTemplate(GraphicObject template = null)
+               {
+                       base.loadTemplate (template);
+
+                       items = this.child.FindByName ("ItemsContainer") as Group;
+                       if (items == null)
+                               throw new Exception ("TemplatedGroup template Must contain a Group named 'ItemsContainer'");
+                       if (items.Children.Count == 0)
+                               NotifyValueChanged ("HasChildren", false);
+                       else
+                               NotifyValueChanged ("HasChildren", true);
+               }
+               #endregion
 
                public virtual List<GraphicObject> Items{ get { return items.Children; }}
+               [XmlAttributeAttribute][DefaultValue(-1)]public int SelectedIndex{
+                       get { return _selectedIndex; }
+                       set { 
+                               if (value == _selectedIndex)
+                                       return;
+
+                               _selectedIndex = value; 
+
+                               NotifyValueChanged ("SelectedIndex", _selectedIndex);
+                               NotifyValueChanged ("SelectedItem", SelectedItem);
+                               SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem));
+                       }
+               }
+               [XmlIgnore]public virtual object SelectedItem{
+                       get { return data == null ? null : _selectedIndex < 0 ? null : data[_selectedIndex]; }
+               }
+
+               [XmlAttributeAttribute]public IList Data {
+                       get { return data; }
+                       set {
+                               if (value == data)
+                                       return;
+
+                               cancelLoadingThread ();
+
+                               data = value;
+
+                               NotifyValueChanged ("Data", data);
+
+                               lock (CurrentInterface.UpdateMutex)
+                                       ClearItems ();
+
+                               if (data == null)
+                                       return;
+
+                               loadingThread = new Thread (loading);
+                               loadingThread.IsBackground = true;
+                               loadingThread.Start ();
+                               //loadPage(1);
+
+                               NotifyValueChanged ("SelectedIndex", _selectedIndex);
+                               NotifyValueChanged ("SelectedItem", SelectedItem);
+                               SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem));
+                       }
+               }
+
+               [XmlAttributeAttribute][DefaultValue("SteelBlue")]//DeepJungleGreen
+               public virtual Color SelectionBackground {
+                       get { return selBackground; }
+                       set {
+                               if (value == selBackground)
+                                       return;
+                               selBackground = value;
+                               NotifyValueChanged ("SelectionBackground", selBackground);
+                               RegisterForRedraw ();
+                       }
+               }
+               [XmlAttributeAttribute][DefaultValue("White")]
+               public virtual Color SelectionForeground {
+                       get { return selForeground; }
+                       set {
+                               if (value == selForeground)
+                                       return;
+                               selForeground = value;
+                               NotifyValueChanged ("SelectionForeground", selForeground);
+                               RegisterForRedraw ();
+                       }
+               }
+
+               protected void raiseSelectedItemChanged(){
+                       SelectedItemChanged.Raise (this, new SelectionChangeEventArgs (SelectedItem));
+               }
+                       
 
                public virtual void AddItem(GraphicObject g){
                        items.AddChild (g);
@@ -53,18 +175,6 @@ namespace Crow
                        NotifyValueChanged ("HasChildren", false);
                }
 
-               protected override void loadTemplate(GraphicObject template = null)
-               {
-                       base.loadTemplate (template);
-
-                       items = this.child.FindByName ("ItemsContainer") as Group;
-                       if (items == null)
-                               throw new Exception ("TemplatedGroup template Must contain a Group named 'ItemsContainer'");
-                       if (items.Children.Count == 0)
-                               NotifyValueChanged ("HasChildren", false);
-                       else
-                               NotifyValueChanged ("HasChildren", true);
-               }
 
                #region GraphicObject overrides
                public override GraphicObject FindByName (string nameToFind)
@@ -160,5 +270,127 @@ namespace Crow
                        throw new NotImplementedException ();
                }
                #endregion
+
+               void loading(){
+                       if (ItemTemplates == null)
+                               ItemTemplates = new Dictionary<string, ItemTemplate> ();
+                       if (!ItemTemplates.ContainsKey ("default"))
+                               ItemTemplates ["default"] = Interface.GetItemTemplate (ItemTemplate);
+
+                       for (int i = 1; i <= (data.Count / itemPerPage) + 1; i++) {
+                               if (cancelLoading)
+                                       return;
+                               loadPage (i);
+                       }
+               }
+               void cancelLoadingThread(){
+                       if (loadingThread == null)
+                               return;
+                       if (!loadingThread.IsAlive)
+                               return;                 
+                       cancelLoading = true;
+                       loadingThread.Join ();
+                       cancelLoading = false;
+               }
+               void loadPage(int pageNum)
+               {
+                       #if DEBUG_LOAD
+                       Stopwatch loadingTime = new Stopwatch ();
+                       loadingTime.Start ();
+                       #endif
+
+                       Group page = items.Clone () as Group;
+
+                       page.Name = "page" + pageNum;
+
+//                     //reset size to fit in the dir of the stacking
+//                     //because items total size is forced to approx size
+//                     if (_gsList.Orientation == Orientation.Horizontal) {
+//                             page.Width = Measure.Fit;
+                               page.BindMember ("Height", "../HeightPolicy");
+                               page.BindMember ("Width", "../WidthPolicy");
+//                     } else {
+//                             page.Height = Measure.Fit;
+//                             page.BindMember ("Width", "../WidthPolicy");
+//                     }
+
+                       for (int i = (pageNum - 1) * itemPerPage; i < pageNum * itemPerPage; i++) {
+                               if (i >= data.Count)
+                                       break;
+                               if (cancelLoading)
+                                       return;
+
+                               loadItem (i, page);
+
+                               //g.LogicalParent = this;
+                       }
+
+                       lock (CurrentInterface.LayoutMutex)
+                               items.AddChild (page);
+
+                       #if DEBUG_LOAD
+                       loadingTime.Stop ();
+                       Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms",
+                       loadingTime.ElapsedTicks,
+                       loadingTime.ElapsedMilliseconds, this.ToString());
+                       #endif
+               }
+               protected void loadItem(int i, Group page){
+                       GraphicObject g = null;
+                       ItemTemplate iTemp = null;
+                       Type dataType = data [i].GetType ();
+
+                       if (ItemTemplates.ContainsKey (dataType.FullName))
+                               iTemp = ItemTemplates [dataType.FullName];
+                       else
+                               iTemp = ItemTemplates ["default"];
+
+                       lock (CurrentInterface.LayoutMutex) {
+                               g = iTemp.CreateInstance(CurrentInterface);
+                               page.AddChild (g);
+                               g.DataSource = data [i];
+                       }
+
+                       registerItemClick (g);
+
+                       if (iTemp.Expand != null && g is Expandable) {
+                               (g as Expandable).Expand += iTemp.Expand;
+                       }                       
+               }
+               protected virtual void registerItemClick(GraphicObject g){
+                       g.MouseClick += itemClick;
+               }
+//             protected void _list_LayoutChanged (object sender, LayoutingEventArgs e)
+//             {
+//                     #if DEBUG_LAYOUTING
+//                     Debug.WriteLine("list_LayoutChanged");
+//                     #endif
+//                     if (_gsList.Orientation == Orientation.Horizontal) {
+//                             if (e.LayoutType == LayoutingType.Width)
+//                                     _gsList.Width = approxSize;
+//                     } else if (e.LayoutType == LayoutingType.Height)
+//                             _gsList.Height = approxSize;
+//             }
+               int approxSize
+               {
+                       get {
+                               if (data == null)
+                                       return -1;
+                               GenericStack page1 = items.FindByName ("page1") as GenericStack;
+                               if (page1 == null)
+                                       return -1;
+
+                               return page1.Orientation == Orientation.Horizontal ?
+                                       data.Count < itemPerPage ?
+                                       -1:
+                                       (int)Math.Ceiling ((double)page1.Slot.Width / (double)itemPerPage * (double)(data.Count+1)):
+                                       data.Count < itemPerPage ?
+                                       -1:
+                                       (int)Math.Ceiling ((double)page1.Slot.Height / (double)itemPerPage * (double)(data.Count+1));
+                       }
+               }
+               internal virtual void itemClick(object sender, MouseButtonEventArgs e){
+                       SelectedIndex = data.IndexOf((sender as GraphicObject).DataSource);
+               }
        }
 }
index ef22826023b72e48d5e2d06380b4dbe366fa0ae0..0cf2ce0110b0a4371d90301a37e35f6607dc8d6f 100644 (file)
@@ -27,7 +27,7 @@ namespace Crow
 {
        //treeview expect expandable child (or not)
        //if their are expandable, some functions and events are added
-       public class TreeView : ListBox
+       public class TreeView : TemplatedGroup
        {
                GraphicObject selectedItemContainer = null;
                Color selBackground;
index 922a48d7d7b1bc485ca071d4b1f607855515ab57..0ff8065299f8e3ea034f4a867b89a9db185b80e6 100644 (file)
@@ -107,7 +107,7 @@ namespace Crow
 
                        il.Emit (OpCodes.Ldloc_0);//save current go onto the stack if child has to be added
 
-                       #region Template and TemplateItems loading
+                       #region Template and ItemTemplates loading
                        if (typeof(TemplatedControl).IsAssignableFrom (crowType)) {
                                //if its a template, first read template elements
                                using (IMLReader reader = new IMLReader (il, tmpXml)) {
@@ -164,7 +164,7 @@ namespace Crow
                                        foreach (string[] iTempId in itemTemplateIds) {
                                                reader.il.Emit (OpCodes.Ldloc_0);//load TempControl ref
                                                reader.il.Emit (OpCodes.Ldfld,//load ItemTemplates dic field
-                                                       typeof(TemplatedControl).GetField("ItemTemplates"));
+                                                       typeof(TemplatedGroup).GetField("ItemTemplates"));
                                                reader.il.Emit (OpCodes.Ldstr, iTempId[0]);//load key
                                                reader.il.Emit (OpCodes.Ldstr, iTempId[1]);//load value
                                                reader.il.Emit (OpCodes.Callvirt,
@@ -177,7 +177,7 @@ namespace Crow
                                                        //expand delegate creation
                                                        reader.il.Emit (OpCodes.Ldloc_0);//load TempControl ref
                                                        reader.il.Emit (OpCodes.Ldfld,//load ItemTemplates dic field
-                                                               typeof(TemplatedControl).GetField ("ItemTemplates"));
+                                                               typeof(TemplatedGroup).GetField ("ItemTemplates"));
                                                        reader.il.Emit (OpCodes.Ldstr, iTempId [0]);//load key
                                                        reader.il.Emit (OpCodes.Callvirt,
                                                                typeof(Dictionary<string, ItemTemplate>).GetMethod ("get_Item",
index cc5d507543409d1e77b5641441b1dedbebc3145f..f760ecee8afa055f36260acc0d3ed7c9ee3fbaa2 100644 (file)
@@ -47,9 +47,9 @@ namespace Crow
                }
                #endregion
 
-               public void CreateExpandDelegate (TemplatedControl host){
+               public void CreateExpandDelegate (TemplatedGroup host){
                        Type dataType = Type.GetType(strDataType);
-                       Type hostType = typeof(TemplatedControl);//not sure is the best place to put the dyn method
+                       Type hostType = typeof(TemplatedGroup);//not sure is the best place to put the dyn method
                        Type evtType = typeof(EventHandler);
                        Type listBoxType = typeof(ListBox);
 
@@ -75,7 +75,7 @@ namespace Crow
                        il.Emit (OpCodes.Callvirt, miFindByName);
                        il.Emit (OpCodes.Stloc_0);
 
-                       FieldInfo fiTemplates = typeof(TemplatedControl).GetField("ItemTemplates");
+                       FieldInfo fiTemplates = typeof(TemplatedGroup).GetField("ItemTemplates");
                        il.Emit (OpCodes.Ldloc_0);
                        il.Emit (OpCodes.Ldarg_0);
                        il.Emit (OpCodes.Ldfld, fiTemplates);