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:
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
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.
24 * Namespace : System.Web.UI.MobileControls
25 * Class : MobileListItem
26 * Author : Gaurav Vaish
28 * Copyright : 2003 with Gaurav Vaish, and with
33 using System
.Collections
;
35 using System
.Web
.UI
.WebControls
;
37 namespace System
.Web
.UI
.MobileControls
39 public class MobileListItem
: TemplateContainer
, IStateManager
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)
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)
80 this.dataItem
= dataItem
;
83 this.itemType
= MobileListItemType
.ListItem
;
86 internal void SetIndex(int index
)
91 public object DataItem
99 this.dataItem
= value;
111 internal MobileListItemType ItemType
115 return this.itemType
;
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;
164 if(this.text
!= null)
166 if(this.value != null)
173 if(IsTrackingViewState
)
184 if(this.value != null)
186 if(this.text
!= null)
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
);
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()
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
,
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 }
;
269 void IStateManager
.LoadViewState(object state
)
273 string[] data
= (string[]) state
;
275 this.value = data
[1];