| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- /**
- * Project : Mono
- * Namespace : System.Web.UI.MobileControls
- * Class : MobileListItem
- * Author : Gaurav Vaish
- *
- * Copyright : 2003 with Gaurav Vaish, and with
- * Ximian Inc
- */
- using System;
- using System.Collections;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace System.Web.UI.MobileControls
- {
- public class MobileListItem : TemplateContainer, IStateManager
- {
- private int index;
- private string text;
- private string value;
- private object dataItem;
- private MobileListItemType itemType;
- private const int SELECTED = 0x00;
- private const int MARKED = 0x01; // Tracking?
- private const int SELECTD = 0x02; // Selection dirty flag
- private const int TEXTD = 0x03; // Text dirty flag
- private const int VALUED = 0x04; // Value dirty flag
- private BitArray flags = new BitArray(5);
- public MobileListItem()
- : this(null, null, null)
- {
- }
- public MobileListItem(MobileListItemType type)
- : this(null, null, null)
- {
- this.itemType = type;
- }
- public MobileListItem(string text)
- : this(null, text, null)
- {
- }
- public MobileListItem(string text, string value)
- : this(null, text, value)
- {
- }
- public MobileListItem(object dataItem, string text, string value)
- : base()
- {
- this.dataItem = dataItem;
- this.text = text;
- this.value = value;
- this.itemType = MobileListItemType.ListItem;
- }
- internal void SetIndex(int index)
- {
- this.index = index;
- }
- public object DataItem
- {
- get
- {
- return this.dataItem;
- }
- set
- {
- this.dataItem = value;
- }
- }
- public int Index
- {
- get
- {
- return this.index;
- }
- }
- internal MobileListItemType ItemType
- {
- get
- {
- return this.itemType;
- }
- }
- public bool Selected
- {
- get
- {
- return flags[SELECTED];
- }
- set
- {
- flags[SELECTED] = value;
- if(IsTrackingViewState)
- {
- flags[SELECTD] = true;
- }
- }
- }
- internal bool IsSelectionDirty
- {
- get
- {
- return flags[SELECTD];
- }
- set
- {
- flags[SELECTD] = value;
- }
- }
- internal bool IsDirty
- {
- get
- {
- return (flags[TEXTD] || flags[VALUED]);
- }
- set
- {
- flags[TEXTD] = value;
- flags[VALUED] = value;
- }
- }
- public string Text
- {
- get
- {
- if(this.text != null)
- return this.text;
- if(this.value != null)
- return this.value;
- return String.Empty;
- }
- set
- {
- this.text = value;
- if(IsTrackingViewState)
- {
- flags[TEXTD] = true;
- }
- }
- }
- public string Value
- {
- get
- {
- if(this.value != null)
- return this.value;
- if(this.text != null)
- return this.text;
- return String.Empty;
- }
- set
- {
- this.value = value;
- if(IsTrackingViewState)
- {
- flags[VALUED] = true;
- }
- }
- }
- public static implicit operator MobileListItem(string text)
- {
- return new MobileListItem(text);
- }
- bool IStateManager.IsTrackingViewState
- {
- get
- {
- return flags[MARKED];
- }
- }
- public override bool Equals(object obj)
- {
- if(obj is MobileListItem)
- {
- MobileListItem other = (MobileListItem) obj;
- return (this.Text == other.Text &&
- this.Value == other.Value);
- }
- return false;
- }
- public override int GetHashCode()
- {
- return (Text.GetHashCode() + Value.GetHashCode());
- }
- public static MobileListItem FromString(string text)
- {
- return new MobileListItem(text);
- }
- public override string ToString()
- {
- return this.Text;
- }
- protected override bool OnBubbleEvent(object sender, EventArgs e)
- {
- if(e is CommandEventArgs)
- {
- CommandEventArgs cmdArgs = (CommandEventArgs)e;
- RaiseBubbleEvent(this,
- new ListCommandEventArgs(this, sender,
- cmdArgs));
- return true;
- }
- return false;
- }
- void IStateManager.TrackViewState()
- {
- flags[MARKED] = true;
- }
- object IStateManager.SaveViewState()
- {
- object retVal = null;
- string text = (flags[TEXTD] ? this.text : null);
- string value = (flags[VALUED] ? this.value : null);
- if(text != null || value != null)
- {
- retVal = new string[] { text, value };
- }
- return retVal;
- }
- void IStateManager.LoadViewState(object state)
- {
- if(state != null)
- {
- string[] data = (string[]) state;
- this.text = data[0];
- this.value = data[1];
- }
- }
- }
- }
|