3 * Namespace : System.Web.UI.MobileControls
4 * Class : MobileListItem
5 * Author : Gaurav Vaish
7 * Copyright : 2003 with Gaurav Vaish, and with
12 using System.Collections;
14 using System.Web.UI.WebControls;
16 namespace System.Web.UI.MobileControls
18 public class MobileListItem : TemplateContainer, IStateManager
24 private object dataItem;
25 private MobileListItemType itemType;
27 private const int SELECTED = 0x00;
28 private const int MARKED = 0x01; // Tracking?
29 private const int SELECTD = 0x02; // Selection dirty flag
30 private const int TEXTD = 0x03; // Text dirty flag
31 private const int VALUED = 0x04; // Value dirty flag
33 private BitArray flags = new BitArray(5);
35 public MobileListItem()
36 : this(null, null, null)
40 public MobileListItem(MobileListItemType type)
41 : this(null, null, null)
46 public MobileListItem(string text)
47 : this(null, text, null)
51 public MobileListItem(string text, string value)
52 : this(null, text, value)
56 public MobileListItem(object dataItem, string text, string value)
59 this.dataItem = dataItem;
62 this.itemType = MobileListItemType.ListItem;
65 internal void SetIndex(int index)
70 public object DataItem
78 this.dataItem = value;
90 internal MobileListItemType ItemType
102 return flags[SELECTED];
106 flags[SELECTED] = value;
107 if(IsTrackingViewState)
109 flags[SELECTD] = true;
114 internal bool IsSelectionDirty
118 return flags[SELECTD];
122 flags[SELECTD] = value;
126 internal bool IsDirty
130 return (flags[TEXTD] || flags[VALUED]);
134 flags[TEXTD] = value;
135 flags[VALUED] = value;
143 if(this.text != null)
145 if(this.value != null)
152 if(IsTrackingViewState)
163 if(this.value != null)
165 if(this.text != null)
172 if(IsTrackingViewState)
174 flags[VALUED] = true;
179 public static implicit operator MobileListItem(string text)
181 return new MobileListItem(text);
184 bool IStateManager.IsTrackingViewState
188 return flags[MARKED];
192 public override bool Equals(object obj)
194 if(obj is MobileListItem)
196 MobileListItem other = (MobileListItem) obj;
197 return (this.Text == other.Text &&
198 this.Value == other.Value);
203 public override int GetHashCode()
205 return (Text.GetHashCode() + Value.GetHashCode());
208 public static MobileListItem FromString(string text)
210 return new MobileListItem(text);
213 public override string ToString()
218 protected override bool OnBubbleEvent(object sender, EventArgs e)
220 if(e is CommandEventArgs)
222 CommandEventArgs cmdArgs = (CommandEventArgs)e;
223 RaiseBubbleEvent(this,
224 new ListCommandEventArgs(this, sender,
231 void IStateManager.TrackViewState()
233 flags[MARKED] = true;
236 object IStateManager.SaveViewState()
238 object retVal = null;
239 string text = (flags[TEXTD] ? this.text : null);
240 string value = (flags[VALUED] ? this.value : null);
241 if(text != null || value != null)
243 retVal = new string[] { text, value };
248 void IStateManager.LoadViewState(object state)
252 string[] data = (string[]) state;
254 this.value = data[1];