(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Web.Mobile / System.Web.UI.MobileControls / MobileListItem.cs
blob7f9d6761ac8f4cb7f81b9f047bfe95c2c69adc7f
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 /**
23 * Project : Mono
24 * Namespace : System.Web.UI.MobileControls
25 * Class : MobileListItem
26 * Author : Gaurav Vaish
28 * Copyright : 2003 with Gaurav Vaish, and with
29 * Ximian Inc
32 using System;
33 using System.Collections;
34 using System.Web.UI;
35 using System.Web.UI.WebControls;
37 namespace System.Web.UI.MobileControls
39 public class MobileListItem : TemplateContainer, IStateManager
41 private int index;
42 private string text;
43 private string value;
45 private object dataItem;
46 private MobileListItemType itemType;
48 private const int SELECTED = 0x00;
49 private const int MARKED = 0x01; // Tracking?
50 private const int SELECTD = 0x02; // Selection dirty flag
51 private const int TEXTD = 0x03; // Text dirty flag
52 private const int VALUED = 0x04; // Value dirty flag
54 private BitArray flags = new BitArray(5);
56 public MobileListItem()
57 : this(null, null, null)
61 public MobileListItem(MobileListItemType type)
62 : this(null, null, null)
64 this.itemType = type;
67 public MobileListItem(string text)
68 : this(null, text, null)
72 public MobileListItem(string text, string value)
73 : this(null, text, value)
77 public MobileListItem(object dataItem, string text, string value)
78 : base()
80 this.dataItem = dataItem;
81 this.text = text;
82 this.value = value;
83 this.itemType = MobileListItemType.ListItem;
86 internal void SetIndex(int index)
88 this.index = index;
91 public object DataItem
93 get
95 return this.dataItem;
97 set
99 this.dataItem = value;
103 public int Index
107 return this.index;
111 internal MobileListItemType ItemType
115 return this.itemType;
119 public bool Selected
123 return flags[SELECTED];
127 flags[SELECTED] = value;
128 if(IsTrackingViewState)
130 flags[SELECTD] = true;
135 internal bool IsSelectionDirty
139 return flags[SELECTD];
143 flags[SELECTD] = value;
147 internal bool IsDirty
151 return (flags[TEXTD] || flags[VALUED]);
155 flags[TEXTD] = value;
156 flags[VALUED] = value;
160 public string Text
164 if(this.text != null)
165 return this.text;
166 if(this.value != null)
167 return this.value;
168 return String.Empty;
172 this.text = value;
173 if(IsTrackingViewState)
175 flags[TEXTD] = true;
180 public string Value
184 if(this.value != null)
185 return this.value;
186 if(this.text != null)
187 return this.text;
188 return String.Empty;
192 this.value = value;
193 if(IsTrackingViewState)
195 flags[VALUED] = true;
200 public static implicit operator MobileListItem(string text)
202 return new MobileListItem(text);
205 bool IStateManager.IsTrackingViewState
209 return flags[MARKED];
213 public override bool Equals(object obj)
215 if(obj is MobileListItem)
217 MobileListItem other = (MobileListItem) obj;
218 return (this.Text == other.Text &&
219 this.Value == other.Value);
221 return false;
224 public override int GetHashCode()
226 return (Text.GetHashCode() + Value.GetHashCode());
229 public static MobileListItem FromString(string text)
231 return new MobileListItem(text);
234 public override string ToString()
236 return this.Text;
239 protected override bool OnBubbleEvent(object sender, EventArgs e)
241 if(e is CommandEventArgs)
243 CommandEventArgs cmdArgs = (CommandEventArgs)e;
244 RaiseBubbleEvent(this,
245 new ListCommandEventArgs(this, sender,
246 cmdArgs));
247 return true;
249 return false;
252 void IStateManager.TrackViewState()
254 flags[MARKED] = true;
257 object IStateManager.SaveViewState()
259 object retVal = null;
260 string text = (flags[TEXTD] ? this.text : null);
261 string value = (flags[VALUED] ? this.value : null);
262 if(text != null || value != null)
264 retVal = new string[] { text, value };
266 return retVal;
269 void IStateManager.LoadViewState(object state)
271 if(state != null)
273 string[] data = (string[]) state;
274 this.text = data[0];
275 this.value = data[1];