--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System;
+using System.Web;
+using System.Web.UI;
+using System.Web.UI.WebControls;
+using System.ComponentModel;
+
+namespace System.Web.UI.WebControls {
+ [DefaultEvent("ServerValidate")]
+ [ToolboxData("<{0}:CustomValidator runat=server ErrorMessage=\"CustomValidator\"></{0}:CustomValidator>")]
+ public class CustomValidator : BaseValidator {
+ #region Public Constructors
+ public CustomValidator() {
+ }
+ #endregion // Public Constructors
+
+ #region Public Instance Properties
+ [DefaultValue("")]
+ public string ClientValidationFunction {
+ get {
+ return ViewState.GetString("ClientValidationFunction", string.Empty);
+ }
+
+ set {
+ ViewState["ClientValidationFunction"] = value;
+ }
+ }
+ #endregion // Public Instance Properties
+
+ #region Public Instance Methods
+ protected override void AddAttributesToRender(HtmlTextWriter writer) {
+ base.AddAttributesToRender (writer);
+
+ if (base.RenderUplevel) {
+ string s;
+
+ writer.AddAttribute("evaluationfunction", "CustomValidatorEvaluateIsValid");
+
+ s = ClientValidationFunction;
+ if (s != string.Empty) {
+ writer.AddAttribute("clientvalidationfunction", s);
+ }
+ }
+ }
+
+ protected override bool ControlPropertiesValid() {
+ return base.ControlPropertiesValid ();
+ }
+
+ protected override bool EvaluateIsValid() {
+ if (ControlToValidate.Length > 0) {
+ return OnServerValidate(GetControlValidationValue(ControlToValidate));
+ }
+ return OnServerValidate(string.Empty);
+ }
+
+ protected virtual bool OnServerValidate(string value) {
+ if (ServerValidate != null) {
+ ServerValidateEventArgs e;
+
+ e = new ServerValidateEventArgs(value, true);
+ ServerValidate(this, e);
+ return e.IsValid;
+ }
+ return true;
+ }
+ #endregion // Public Instance Methods
+
+ #region Events
+ public event ServerValidateEventHandler ServerValidate;
+ #endregion // Events
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System.ComponentModel;
+using System.Web.UI;
+
+namespace System.Web.UI.WebControls {
+ public class DataGridItem : TableRow, INamingContainer {
+ #region Fields
+ private object item;
+ private int dataset_index;
+ private int item_index;
+ private ListItemType item_type;
+ #endregion // Fields
+
+ #region Public Constructors
+ public DataGridItem(int itemIndex, int dataSetIndex, ListItemType itemType) {
+ item_index = itemIndex;
+ dataset_index = dataSetIndex;
+ item_type = itemType;
+ }
+ #endregion // Public Constructors
+
+ #region Public Instance Properties
+ public virtual object DataItem {
+ get {
+ return item;
+ }
+
+ set {
+ item = value;
+ }
+ }
+
+ public virtual int DataSetIndex {
+ get {
+ return dataset_index;
+ }
+ }
+
+ public virtual int ItemIndex {
+ get {
+ return item_index;
+ }
+ }
+
+ public virtual ListItemType ItemType {
+ get {
+ return item_type;
+ }
+ }
+ #endregion // Public Instance Properties
+
+ #region Public Instance Methods
+ protected override bool OnBubbleEvent(object source, EventArgs args) {
+ // Nikhil Kothari, pg 312-313:
+ if (args is CommandEventArgs) {
+ RaiseBubbleEvent(this, new DataGridCommandEventArgs(this, source, (CommandEventArgs)args));
+ return true;
+ }
+
+ return base.OnBubbleEvent (source, args);
+ }
+
+ protected internal virtual void SetItemType(ListItemType itemType) {
+ item_type = itemType;
+
+ }
+ #endregion // Public Instance Methods
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System.Collections;
+
+namespace System.Web.UI.WebControls {
+ public class DataGridItemCollection : ICollection, IEnumerable {
+ #region Fields
+ private ArrayList array;
+ #endregion // Fields
+
+ #region Public Constructors
+ public DataGridItemCollection (ArrayList items) {
+ array = items;
+ }
+ #endregion // Public Constructors
+
+ #region Public Instance Properties
+ public int Count {
+ get {
+ return array.Count;
+ }
+ }
+
+ public bool IsReadOnly {
+ get {
+ return array.IsReadOnly;
+ }
+ }
+
+ public bool IsSynchronized {
+ get {
+ return array.IsSynchronized;
+ }
+ }
+
+ public object SyncRoot {
+ get {
+ return array.SyncRoot;
+ }
+ }
+
+ public DataGridItem this[int index] {
+ get {
+ return (DataGridItem)array[index];
+ }
+ }
+ #endregion // Public Instance Properties
+
+ #region Public Instance Methods
+ public void CopyTo(Array array, int index) {
+ if ( !(array is DataGridItem[])) {
+ throw new InvalidCastException("Target array must be DataGridItem[]");
+ }
+
+ if ((index + this.array.Count) > array.Length) {
+ throw new IndexOutOfRangeException("Target array not large enough to hold copied array.");
+ }
+ this.array.CopyTo(array, index);
+ }
+
+ public IEnumerator GetEnumerator() {
+ return array.GetEnumerator();
+ }
+ #endregion // Public Instance Methods
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System.ComponentModel;
+
+namespace System.Web.UI.WebControls {
+ public sealed class DataGridPagerStyle : TableItemStyle {
+ #region Constructors
+ internal DataGridPagerStyle () {
+ }
+ #endregion // Constructors
+
+ #region Public Instance Properties
+ [Bindable(true)]
+ [DefaultValue(PagerMode.NextPrev)]
+ [NotifyParentProperty(true)]
+ public PagerMode Mode {
+ get {
+ if ((styles & Styles.Mode) == 0) {
+ return PagerMode.NextPrev;
+ }
+
+ return (PagerMode)ViewState["Mode"];
+ }
+
+ set {
+ styles |= Styles.Mode;
+ ViewState["Mode"] = value;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue(">")]
+ [NotifyParentProperty(true)]
+ public string NextPageText {
+ get {
+ if ((styles & Styles.NextPageText) == 0) {
+ return ">";
+ }
+
+ return ViewState.GetString("NextPageText", ">");
+ }
+
+ set {
+ styles |= Styles.NextPageText;
+ ViewState["NextPageText"] = value;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue(10)]
+ [NotifyParentProperty(true)]
+ public int PageButtonCount {
+ get {
+ if ((styles & Styles.PageButtonCount) == 0) {
+ return 10;
+ }
+
+ return ViewState.GetInt("PageButtonCount", 10);
+ }
+
+ set {
+ if (value < 1) {
+ throw new ArgumentOutOfRangeException("value", "PageButtonCount must be greater than 0");
+ }
+
+ styles |= Styles.PageButtonCount;
+ ViewState["PageButtonCount"] = value;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue(PagerPosition.Bottom)]
+ [NotifyParentProperty(true)]
+ public PagerPosition Position {
+ get {
+ if ((styles & Styles.Position) == 0) {
+ return PagerPosition.Bottom;
+ }
+
+ return (PagerPosition)ViewState["Position"];
+ }
+
+ set {
+ styles |= Styles.Position;
+ ViewState["Position"] = value;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue("<")]
+ [NotifyParentProperty(true)]
+ public string PrevPageText {
+ get {
+ if ((styles & Styles.NextPageText) == 0) {
+ return "<";
+ }
+
+ return ViewState.GetString("PrevPageText", "<");
+ }
+
+ set {
+ styles |= Styles.PrevPageText;
+ ViewState["PrevPageText"] = value;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue(true)]
+ [NotifyParentProperty(true)]
+ public bool Visible {
+ get {
+ if ((styles & Styles.Visible) == 0) {
+ return true;
+ }
+
+ return ViewState.GetBool("Visible", true);
+ }
+
+ set {
+ styles |= Styles.Visible;
+ ViewState["Visible"] = value;
+ }
+ }
+ #endregion // Public Instance Properties
+
+ #region Public Instance Methods
+ public override void CopyFrom(Style s) {
+ base.CopyFrom (s);
+
+ if (s == null || s.IsEmpty) {
+ return;
+ }
+
+ if (((s.styles & Styles.Mode) != 0) && (((DataGridPagerStyle)s).Mode != PagerMode.NextPrev)) {
+ this.Mode = ((DataGridPagerStyle)s).Mode;
+ }
+
+ if (((s.styles & Styles.NextPageText) != 0) && (((DataGridPagerStyle)s).NextPageText != ">")) {
+ this.NextPageText = ((DataGridPagerStyle)s).NextPageText;
+ }
+
+ if (((s.styles & Styles.PageButtonCount) != 0) && (((DataGridPagerStyle)s).PageButtonCount != 10)) {
+ this.PageButtonCount = ((DataGridPagerStyle)s).PageButtonCount;
+ }
+
+ if (((s.styles & Styles.Position) != 0) && (((DataGridPagerStyle)s).Position != PagerPosition.Bottom)) {
+ this.Position = ((DataGridPagerStyle)s).Position;
+ }
+
+ if (((s.styles & Styles.PrevPageText) != 0) && (((DataGridPagerStyle)s).PrevPageText != "<")) {
+ this.PrevPageText = ((DataGridPagerStyle)s).PrevPageText;
+ }
+
+ if (((s.styles & Styles.Visible) != 0) && (((DataGridPagerStyle)s).Visible != true)) {
+ this.Visible = ((DataGridPagerStyle)s).Visible;
+ }
+
+ }
+
+ public override void MergeWith(Style s) {
+ base.MergeWith (s);
+
+ if (s == null || s.IsEmpty) {
+ return;
+ }
+
+ if (((styles & Styles.Mode) == 0) && ((s.styles & Styles.Mode) != 0) && (((DataGridPagerStyle)s).Mode != PagerMode.NextPrev)) {
+ this.Mode = ((DataGridPagerStyle)s).Mode;
+ }
+
+ if (((styles & Styles.NextPageText) == 0) && ((s.styles & Styles.NextPageText) != 0) && (((DataGridPagerStyle)s).NextPageText != ">")) {
+ this.NextPageText = ((DataGridPagerStyle)s).NextPageText;
+ }
+
+ if (((styles & Styles.PageButtonCount) == 0) && ((s.styles & Styles.PageButtonCount) != 0) && (((DataGridPagerStyle)s).PageButtonCount != 10)) {
+ this.PageButtonCount = ((DataGridPagerStyle)s).PageButtonCount;
+ }
+
+ if (((styles & Styles.Position) == 0) && ((s.styles & Styles.Position) != 0) && (((DataGridPagerStyle)s).Position != PagerPosition.Bottom)) {
+ this.Position = ((DataGridPagerStyle)s).Position;
+ }
+
+ if (((styles & Styles.PrevPageText) == 0) && ((s.styles & Styles.PrevPageText) != 0) && (((DataGridPagerStyle)s).PrevPageText != "<")) {
+ this.PrevPageText = ((DataGridPagerStyle)s).PrevPageText;
+ }
+
+ if (((styles & Styles.Visible) == 0) && ((s.styles & Styles.Visible) != 0) && (((DataGridPagerStyle)s).Visible != true)) {
+ this.Visible = ((DataGridPagerStyle)s).Visible;
+ }
+ }
+
+ public override void Reset() {
+ // We call base.Reset(), we don't need this
+ //styles &= ~(Styles.Mode | Styles.NextPageText | Styles.PageButtonCount | Styles.Position | Styles.PrevPageText | Styles.Visible);
+
+ ViewState.Remove("Mode");
+ ViewState.Remove("NextPageText");
+ ViewState.Remove("PageButtonCount");
+ ViewState.Remove("Position");
+ ViewState.Remove("PrevPageText");
+ ViewState.Remove("Visible");
+
+ base.Reset ();
+ }
+
+ internal override void LoadViewStateInternal()
+ {
+ if (viewstate["Mode"] != null) {
+ styles |= Styles.Mode;
+ }
+ if (viewstate["NextPageText"] != null) {
+ styles |= Styles.NextPageText;
+ }
+ if (viewstate["PageButtonCount"] != null) {
+ styles |= Styles.PageButtonCount;
+ }
+ if (viewstate["Position"] != null) {
+ styles |= Styles.Position;
+ }
+ if (viewstate["PrevPageText"] != null) {
+ styles |= Styles.PrevPageText;
+ }
+ if (viewstate["Visible"] != null) {
+ styles |= Styles.Visible;
+ }
+
+ base.LoadViewStateInternal();
+ }
+ #endregion // Public Instance Methods
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System;
+using System.Collections.Specialized;
+using System.ComponentModel;
+using System.Drawing;
+using System.Web;
+using System.Web.UI;
+
+namespace System.Web.UI.WebControls {
+ [ValidationProperty("SelectedItem")]
+ public class DropDownList : ListControl, IPostBackDataHandler {
+ #region Public Constructors
+ public DropDownList() {
+ }
+ #endregion // Public Constructors
+
+ #region Public Instance Properties
+ [Browsable(false)]
+ public override Color BorderColor {
+ get {
+ return base.BorderColor;
+ }
+
+ set {
+ base.BorderColor = value;
+ }
+ }
+
+ [Browsable(false)]
+ public override BorderStyle BorderStyle {
+ get {
+ return base.BorderStyle;
+ }
+
+ set {
+ base.BorderStyle = value;
+ }
+ }
+
+ [Browsable(false)]
+ public override Unit BorderWidth {
+ get {
+ return base.BorderWidth;
+ }
+
+ set {
+ base.BorderWidth = value;
+ }
+ }
+
+ [DefaultValue(0)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ public override int SelectedIndex {
+ get {
+ int selected;
+
+ selected = base.SelectedIndex;
+ if ((selected != -1) || (Items.Count == 0)) {
+ return selected;
+ }
+
+ Items[0].Selected = true;
+ return 0;
+ }
+
+ set {
+ base.SelectedIndex = value;
+ }
+ }
+
+#if ONLY_1_1
+ [Bindable(false)]
+ [Browsable(false)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override string ToolTip {
+ get {
+ return string.Empty;
+ }
+
+ set {
+ }
+ }
+#endif
+ #endregion // Public Instance Properties
+
+ #region Protected Instance Methods
+ protected override void AddAttributesToRender(HtmlTextWriter writer) {
+ if (Page != null)
+ Page.VerifyRenderingInServerForm (this);
+
+ writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID, true);
+
+ if (AutoPostBack) {
+ writer.AddAttribute (HtmlTextWriterAttribute.Onchange, Page.GetPostBackClientHyperlink (this, ""));
+ }
+
+ base.AddAttributesToRender(writer);
+ }
+
+ protected override ControlCollection CreateControlCollection() {
+ return base.CreateControlCollection();
+ }
+
+#if NET_2_0
+ protected internal
+#else
+ protected
+#endif
+ override void RenderContents(HtmlTextWriter writer) {
+ int count;
+ ListItem item;
+ bool selected;
+
+ if (writer == null) {
+ return;
+ }
+
+ count = Items.Count;
+ selected = false;
+
+ for (int i = 0; i < count; i++) {
+ item = Items[i];
+
+ writer.WriteBeginTag("option");
+ if (item.Selected) {
+ if (selected) {
+ throw new HttpException("DropDownList only may have a single selected item");
+ }
+ writer.WriteAttribute("selected", "selected", false);
+ selected = true;
+ }
+ writer.WriteAttribute("value", item.Value, true);
+
+ writer.Write(">");
+ writer.Write(item.Text);
+ writer.WriteEndTag("option");
+ writer.WriteLine();
+ }
+
+ base.RenderContents(writer);
+ }
+
+#if NET_2_0
+ [MonoTODO]
+ protected internal override void VerifyMultiSelect ()
+ {
+ throw new NotImplementedException ();
+ }
+#endif
+
+ #endregion // Protected Instance Methods
+
+ #region Interface Methods
+#if NET_2_0
+ [MonoTODO]
+ protected virtual bool LoadPostData (string postDataKey, NameValueCollection postCollection)
+ {
+ throw new NotImplementedException ();
+ }
+
+ [MonoTODO]
+ protected virtual void RaisePostDataChangedEvent ()
+ {
+ throw new NotImplementedException ();
+ }
+#endif
+
+ bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection) {
+ int index;
+
+ index = Items.IndexOf(postCollection[postDataKey]);
+ if (index != this.SelectedIndex) {
+ SelectedIndex = index;
+ return true;
+ }
+
+ return false;
+ }
+
+ void IPostBackDataHandler.RaisePostDataChangedEvent() {
+ OnSelectedIndexChanged(EventArgs.Empty);
+ }
+ #endregion // Interface Methods
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System;
+using System.Web.UI;
+
+namespace System.Web.UI.WebControls {
+ public class EditCommandColumn : DataGridColumn {
+ #region Public Constructors
+ public EditCommandColumn() {
+ }
+ #endregion // Public Constructors
+
+ #region Public Instance Properties
+ public virtual ButtonColumnType ButtonType {
+ get {
+ object obj;
+
+ obj = ViewState["ButtonType"];
+ if (obj != null) {
+ return (ButtonColumnType)obj;
+ }
+ return ButtonColumnType.LinkButton;
+ }
+
+ set {
+ ViewState["ButtonType"] = value;
+ }
+ }
+
+ public virtual string CancelText {
+ get {
+ return ViewState.GetString("CancelText", string.Empty);
+ }
+
+ set {
+ ViewState["CancelText"] = value;
+ }
+ }
+
+ public virtual string EditText {
+ get {
+ return ViewState.GetString("EditText", string.Empty);
+ }
+
+ set {
+ ViewState["EditText"] = value;
+ }
+ }
+
+ public virtual string UpdateText {
+ get {
+ return ViewState.GetString("UpdateText", string.Empty);
+ }
+
+ set {
+ ViewState["UpdateText"] = value;
+ }
+ }
+ #endregion // Public Instance Properties
+
+ #region Public Instance Methods
+
+ // Modeled after Ben's CommandField.InitializeCell. Saved me a lot of figuring-out time :-)
+ public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) {
+ base.InitializeCell (cell, columnIndex, itemType);
+
+ switch(itemType) {
+ case ListItemType.Separator:
+ case ListItemType.Pager:
+ case ListItemType.Footer:
+ case ListItemType.Header: {
+ // Base handles header and footer, dunno about the others
+ return;
+ }
+
+ case ListItemType.Item:
+ case ListItemType.SelectedItem:
+ case ListItemType.AlternatingItem:{
+ cell.Controls.Add(CreateButton(ButtonType, EditText, "Edit"));
+ break;
+ }
+
+ case ListItemType.EditItem: {
+ cell.Controls.Add(CreateButton(ButtonType, UpdateText, "Update"));
+ cell.Controls.Add(new LiteralControl(" "));
+ cell.Controls.Add(CreateButton(ButtonType, CancelText, "Cancel"));
+ break;
+ }
+ }
+ }
+ #endregion // Public Instance Methods
+
+ #region Private Methods
+ private Control CreateButton(ButtonColumnType type, string text, string command) {
+ Button b;
+ LinkButton d;
+
+ if (type == ButtonColumnType.LinkButton) {
+ d = new LinkButton();
+ d.Text = text;
+ d.CommandName = command;
+ return d;
+ }
+
+ b = new Button();
+ b.Text = text;
+ b.CommandName = command;
+ return b;
+ }
+ #endregion // Private Methods
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+namespace System.Web.UI.WebControls {
+ public enum FirstDayOfWeek {
+ Sunday = 0,
+ Monday = 1,
+ Tuesday = 2,
+ Wednesday = 3,
+ Thursday = 4,
+ Friday = 5,
+ Saturday = 6,
+ Default = 7
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Dennis Bartok (pbartok@novell.com)
+//
+//
+
+using System.ComponentModel;
+
+namespace System.Web.UI.WebControls
+{
+ [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
+ public sealed class FontInfo
+ {
+ [Flags]
+ internal enum FontStyles
+ {
+ None = 0,
+ Bold = 0x0001,
+ Italic = 0x0002,
+ Names = 0x0004,
+ Overline = 0x0008,
+ Size = 0x0010,
+ Strikeout = 0x0020,
+ Underline = 0x0040
+ }
+
+ #region Fields
+ private static string[] empty_names = new string[0];
+ private FontStyles fontstyles;
+ private StateBag bag;
+ #endregion // Fields
+
+ #region Constructors
+ private FontInfo()
+ {
+ }
+
+ internal FontInfo(Style owner)
+ {
+ this.bag = owner.ViewState;
+ }
+ #endregion // Constructors
+
+ #region Public Instance Properties
+ [Bindable(true)]
+ [DefaultValue(false)]
+ [NotifyParentProperty(true)]
+ public bool Bold
+ {
+ get
+ {
+ if ((fontstyles & FontStyles.Bold) == 0)
+ {
+ return false;
+ }
+
+ return bag.GetBool("Font_Bold", false);
+ }
+
+ set
+ {
+ fontstyles |= FontStyles.Bold;
+ bag["Font_Bold"] = value;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue(false)]
+ [NotifyParentProperty(true)]
+ public bool Italic
+ {
+ get
+ {
+ if ((fontstyles & FontStyles.Italic) == 0)
+ {
+ return false;
+ }
+
+ return bag.GetBool("Font_Italic", false);
+ }
+
+ set
+ {
+ fontstyles |= FontStyles.Italic;
+ bag["Font_Italic"] = value;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue("")]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ [Editor("System.Drawing.Design.FontNameEditor, " + Consts.AssemblySystem_Drawing_Design, typeof(System.Drawing.Design.UITypeEditor))]
+ [NotifyParentProperty(true)]
+ [TypeConverter (typeof(System.Drawing.FontConverter.FontNameConverter))]
+ public string Name
+ {
+ get
+ {
+ string[] names;
+
+ if ((fontstyles & FontStyles.Names) == 0)
+ {
+ return string.Empty;
+ }
+
+ names = (string[])bag["Font_Names"];
+
+ if (names.Length == 0)
+ {
+ return string.Empty;
+ }
+
+ return names[0];
+ }
+
+ set
+ {
+ // Seems to be a special case in MS, removing the names from the bag when Name is set to empty,
+ // but not when setting Names to an empty array
+ if (value == string.Empty) {
+ bag.Remove("Font_Names");
+ return;
+ }
+
+ if (value == null) {
+ throw new ArgumentNullException("value", "Font name cannot be null");
+ }
+ Names = new string[1] { value };
+ }
+ }
+
+ [Editor("System.Windows.Forms.Design.StringArrayEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
+ [NotifyParentProperty(true)]
+ [TypeConverter(typeof(System.Web.UI.WebControls.FontNamesConverter))]
+ public string[] Names
+ {
+ get
+ {
+ string[] ret;
+
+ if ((fontstyles & FontStyles.Names) == 0)
+ {
+ return FontInfo.empty_names;
+ }
+
+ ret = (string[])bag["Font_Names"];
+
+ if (ret != null) {
+ return ret;
+ }
+ return FontInfo.empty_names;
+ }
+
+ set
+ {
+ fontstyles |= FontStyles.Names;
+ bag["Font_Names"] = value;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue(false)]
+ [NotifyParentProperty(true)]
+ public bool Overline
+ {
+ get
+ {
+ if ((fontstyles & FontStyles.Overline) == 0)
+ {
+ return false;
+ }
+
+ return bag.GetBool("Font_Overline", false);
+ }
+
+ set
+ {
+ fontstyles |= FontStyles.Overline;
+ bag["Font_Overline"] = value;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue("")]
+ [NotifyParentProperty(true)]
+ public FontUnit Size
+ {
+ get
+ {
+ if ((fontstyles & FontStyles.Size) == 0)
+ {
+ return FontUnit.Empty;
+ }
+
+ return (FontUnit)bag["Font_Size"];
+ }
+
+ set
+ {
+ if (value.Unit.Value < 0)
+ {
+ throw new ArgumentOutOfRangeException("Value", value.Unit.Value, "Font size cannot be negative");
+ }
+ fontstyles |= FontStyles.Size;
+ bag["Font_Size"] = value;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue(false)]
+ [NotifyParentProperty(true)]
+ public bool Strikeout
+ {
+ get
+ {
+ if ((fontstyles & FontStyles.Strikeout) == 0)
+ {
+ return false;
+ }
+
+ return bag.GetBool("Font_Strikeout", false);
+ }
+
+ set
+ {
+ fontstyles |= FontStyles.Strikeout;
+ bag["Font_Strikeout"] = value;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue(false)]
+ [NotifyParentProperty(true)]
+ public bool Underline
+ {
+ get
+ {
+ if ((fontstyles & FontStyles.Underline) == 0)
+ {
+ return false;
+ }
+
+ return bag.GetBool("Font_Underline", false);
+ }
+
+ set
+ {
+ fontstyles |= FontStyles.Underline;
+ bag["Font_Underline"] = value;
+ }
+ }
+ #endregion // Public Instance Properties
+
+ #region Public Instance Methods
+ public void CopyFrom(FontInfo f)
+ {
+ this.Reset();
+
+ // MS does not store the property in the bag if it's value is false
+ if (((f.fontstyles & FontStyles.Bold) != 0) && f.Bold)
+ {
+ this.Bold = true;
+ }
+
+ if (((f.fontstyles & FontStyles.Italic) != 0) && f.Italic)
+ {
+ this.Italic = true;
+ }
+
+ // MS seems to have some weird behaviour, even if f's Name has been set to String.Empty we still get an empty array
+ if (((f.fontstyles & FontStyles.Names) != 0))
+ {
+ this.Names = f.Names;
+ }
+
+ if (((f.fontstyles & FontStyles.Overline) != 0) && f.Overline)
+ {
+ this.Overline = true;
+ }
+
+ if (((f.fontstyles & FontStyles.Size) != 0) && (f.Size != FontUnit.Empty))
+ {
+ this.Size = f.Size;
+ }
+
+ if (((f.fontstyles & FontStyles.Strikeout) != 0) && f.Strikeout)
+ {
+ this.Strikeout = true;
+ }
+
+ if (((f.fontstyles & FontStyles.Underline) != 0) && f.Underline)
+ {
+ this.Underline = true;
+ }
+ }
+
+ public void MergeWith(FontInfo f)
+ {
+ if (((fontstyles & FontStyles.Bold) == 0) && ((f.fontstyles & FontStyles.Bold) != 0) && f.Bold)
+ {
+ this.Bold = true;
+ }
+
+ if (((fontstyles & FontStyles.Italic) == 0) && ((f.fontstyles & FontStyles.Italic) != 0) && f.Italic)
+ {
+ this.Italic = true;
+ }
+
+ if (((fontstyles & FontStyles.Names) == 0) && ((f.fontstyles & FontStyles.Names) != 0))
+ {
+ this.Names = f.Names;
+ }
+
+ if (((fontstyles & FontStyles.Overline) == 0) && ((f.fontstyles & FontStyles.Overline) != 0) && f.Overline)
+ {
+ this.Overline = true;
+ }
+
+ if (((fontstyles & FontStyles.Size) == 0) && ((f.fontstyles & FontStyles.Size) != 0) && (f.Size != FontUnit.Empty))
+ {
+ this.Size = f.Size;
+ }
+
+ if (((fontstyles & FontStyles.Strikeout) == 0) && ((f.fontstyles & FontStyles.Strikeout) != 0) && f.Strikeout)
+ {
+ this.Strikeout = true;
+ }
+
+ if (((fontstyles & FontStyles.Underline) == 0) && ((f.fontstyles & FontStyles.Underline) != 0) && f.Underline)
+ {
+ this.Underline = true;
+ }
+ }
+
+ [MonoTODO]
+ public bool ShouldSerializeNames()
+ {
+ throw new NotImplementedException("Microsoft Internal, not sure what to do");
+ }
+
+ public override string ToString()
+ {
+ if (this.Names.Length == 0)
+ {
+ return string.Empty;
+ }
+
+ return this.Name + ", " + this.Size.ToString();
+ }
+ #endregion // Public Instance Methods
+
+ #region Private Methods
+ internal void Reset()
+ {
+ bag.Remove("Font_Bold");
+ bag.Remove("Font_Italic");
+ bag.Remove("Font_Names");
+ bag.Remove("Font_Overline");
+ bag.Remove("Font_Size");
+ bag.Remove("Font_Strikeout");
+ bag.Remove("Font_Underline");
+ fontstyles = FontStyles.None;
+ }
+
+ internal void LoadViewState() {
+ fontstyles = FontStyles.None;
+
+ if (bag["Font_Bold"] != null)
+ {
+ fontstyles |= FontStyles.Bold;
+ }
+ if (bag["Font_Italic"] != null)
+ {
+ fontstyles |= FontStyles.Italic;
+ }
+ if (bag["Font_Names"] != null)
+ {
+ fontstyles |= FontStyles.Names;
+ }
+ if (bag["Font_Overline"] != null)
+ {
+ fontstyles |= FontStyles.Overline;
+ }
+ if (bag["Font_Size"] != null)
+ {
+ fontstyles |= FontStyles.Size;
+ }
+ if (bag["Font_Strikeout"] != null)
+ {
+ fontstyles |= FontStyles.Strikeout;
+ }
+ if (bag["Font_Underline"] != null)
+ {
+ fontstyles |= FontStyles.Underline;
+ }
+ }
+ #endregion // Private Methods
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System;
+using System.ComponentModel;
+using System.Globalization;
+
+namespace System.Web.UI.WebControls
+{
+ public class FontNamesConverter : System.ComponentModel.TypeConverter
+ {
+ #region Public Constructors
+ public FontNamesConverter()
+ {
+ }
+ #endregion // Public Constructors
+
+ #region Public Instance Methods
+ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
+ {
+ if (sourceType == typeof(string))
+ {
+ return true;
+ }
+
+ return base.CanConvertFrom(context, sourceType);
+ }
+
+ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
+ {
+ if (value is string)
+ {
+ string[] names;
+ string namelist;
+ int count;
+
+ namelist = (string)value;
+
+ if (namelist == string.Empty)
+ {
+ return new string[0];
+ }
+
+ names = namelist.Split(new char[] { ',' });
+
+ count = names.Length;
+ for (int i = 0; i < count; i++)
+ {
+ names[i] = names[i].Trim();
+ }
+
+ return names;
+ }
+ return base.ConvertFrom(context, culture, value);
+ }
+
+ public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
+ {
+ if ((destinationType == typeof(string)) && (value is string[]))
+ {
+ return String.Join(",", (string[])value);
+ }
+ return base.ConvertTo(context, culture, value, destinationType);
+ }
+ #endregion // Public Instance Methods
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System;
+using System.Collections;
+using System.ComponentModel;
+using System.Globalization;
+
+namespace System.Web.UI.WebControls
+{
+ public class FontUnitConverter : TypeConverter
+ {
+ #region Public Constructors
+ public FontUnitConverter()
+ {
+ }
+ #endregion // Public Constructors
+
+ #region Public Instance Methods
+ public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
+ {
+ if (sourceType == typeof(string))
+ {
+ return true;
+ }
+ return base.CanConvertFrom (context, sourceType);
+ }
+
+ public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
+ {
+ string s;
+
+ if ((value == null) || !(value is string))
+ {
+ return base.ConvertFrom (context, culture, value);
+ }
+
+
+ s = (string)value;
+
+ if (culture == null)
+ {
+ culture = CultureInfo.CurrentCulture;
+ }
+
+ if (s == "")
+ {
+ return FontUnit.Empty;
+ }
+ return FontUnit.Parse(s, culture);
+ }
+
+ public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
+ {
+ FontUnit fu;
+
+ if ((value == null) || !(value is FontUnit) || (destinationType != typeof(string)))
+ {
+ return base.ConvertTo (context, culture, value, destinationType);
+ }
+
+ if (culture == null)
+ {
+ culture = CultureInfo.CurrentCulture;
+ }
+
+ fu = (FontUnit)value;
+
+ return fu.ToString(culture);
+ }
+
+ public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
+ {
+ PropertyDescriptorCollection props = TypeDescriptor.GetProperties (typeof (FontUnit));
+ ArrayList vals = new ArrayList ();
+
+ for (int i = 0; i < props.Count; i++)
+ vals.Add (props [i].GetValue (null));
+ return new StandardValuesCollection (vals);
+ }
+
+ public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
+ {
+ return false;
+ }
+
+ public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
+ {
+ return true;
+ }
+ #endregion // Public Instance Methods
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System;
+using System.Collections;
+using System.ComponentModel;
+using System.Globalization;
+using System.Reflection;
+
+namespace System.Web.UI.WebControls {
+ [Editor("System.Web.UI.Design.WebControls.ListItemsCollectionEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
+ public sealed class ListItemCollection : IList, ICollection, IEnumerable, IStateManager {
+ #region Fields
+ private ArrayList items;
+ private bool tracking;
+ #endregion // Fields
+
+ #region Public Constructors
+ public ListItemCollection() {
+ items = new ArrayList();
+ }
+ #endregion // Public Constructors
+
+ #region Public Instance Properties
+ public int Capacity {
+ get {
+ return items.Capacity;
+ }
+
+ set {
+ items.Capacity = value;
+ }
+ }
+
+ public int Count {
+ get {
+ return items.Count;
+ }
+ }
+
+ public bool IsReadOnly {
+ get {
+ return items.IsReadOnly;
+ }
+ }
+
+ public bool IsSynchronized {
+ get {
+ return items.IsSynchronized;
+ }
+ }
+
+ public object SyncRoot {
+ get {
+ return items.SyncRoot;
+ }
+ }
+
+ public ListItem this[int index] {
+ get {
+ return (ListItem)items[index];
+ }
+ }
+ #endregion // Public Instance Properties
+
+ #region Public Instance Methods
+ public void Add(ListItem item) {
+ items.Add(item);
+ }
+
+ public void Add(string item) {
+ items.Add(new ListItem(item));
+ }
+
+ public void AddRange(ListItem[] items) {
+ for (int i = 0; i < items.Length; i++) {
+ Add(items[i]);
+ }
+ }
+
+ public void Clear() {
+ items.Clear();
+ }
+
+ public bool Contains(ListItem item) {
+ return items.Contains(item);
+ }
+
+ public void CopyTo(Array array, int index) {
+ items.CopyTo(array, index);
+ }
+
+ public ListItem FindByText (string text)
+ {
+ for (int i = 0; i < items.Count; i++)
+ if (text == this [i].Text)
+ return this [i];
+
+ return null;
+ }
+
+ public ListItem FindByValue (string value)
+ {
+ for (int i = 0; i < items.Count; i++)
+ if (value == this [i].Value)
+ return this [i];
+
+ return null;
+ }
+
+ public IEnumerator GetEnumerator() {
+ return items.GetEnumerator();
+ }
+
+ public int IndexOf(ListItem item) {
+ return items.IndexOf(item);
+ }
+
+ internal int IndexOf(string value) {
+ for (int i = 0; i < items.Count; i++)
+ if (value == this [i].Value)
+ return i;
+ return -1;
+ }
+
+ public void Insert(int index, ListItem item) {
+ items.Insert(index, item);
+ }
+
+ public void Insert(int index, string item) {
+ items.Insert(index, new ListItem(item));
+ }
+
+ public void Remove(ListItem item) {
+ items.Remove(item);
+ }
+
+ public void Remove (string item)
+ {
+ for (int i = 0; i < items.Count; i++)
+ if (item == this [i].Value)
+ items.RemoveAt (i);
+ }
+
+ public void RemoveAt(int index) {
+ items.RemoveAt(index);
+ }
+ #endregion // Public Instance Methods
+
+ #region Interface methods
+ bool IList.IsFixedSize {
+ get {
+ return items.IsFixedSize;
+ }
+ }
+
+ object IList.this[int index] {
+ get {
+ return this[index];
+ }
+
+ set {
+ if ((index >= 0) && (index < items.Count)) {
+ items[index] = (ListItem)value;
+ }
+ }
+ }
+
+ int IList.Add(object value) {
+ return items.Add((ListItem)value);
+ }
+
+ bool IList.Contains(object value) {
+ return Contains((ListItem)value);
+ }
+
+ int IList.IndexOf(object value) {
+ return IndexOf((ListItem)value);
+ }
+
+ void IList.Insert(int index, object value) {
+ Insert(index, (ListItem)value);
+ }
+
+ void IList.Remove(object value) {
+ Remove((ListItem)value);
+ }
+
+ bool IStateManager.IsTrackingViewState {
+ get {
+ return tracking;
+ }
+ }
+
+ void IStateManager.LoadViewState(object state) {
+ Pair pair;
+ int count;
+ string[] text;
+ string[] value;
+
+ if (state == null) {
+ return;
+ }
+
+ pair = (Pair)state;
+
+ text = (string[])pair.First;
+ value = (string[])pair.Second;
+
+ count = text.Length;
+
+ items = new ArrayList(count);
+ for (int i = 0; i < count; i++) {
+ items.Add(new ListItem(text[i], value[i]));
+ }
+ }
+
+ object IStateManager.SaveViewState() {
+ string[] text;
+ string[] value;
+ int count;
+
+ count = items.Count;
+ text = new string[count];
+ value = new string[count];
+
+ for (int i = 0; i < count; i++) {
+ text[i] = ((ListItem)items[i]).Text;
+ value[i] = ((ListItem)items[i]).Value;
+ }
+
+ return new Pair(text, value);
+ }
+
+ void IStateManager.TrackViewState() {
+ tracking = true;
+
+ for (int i = 0; i < items.Count; i++) {
+ ((ListItem)items[i]).TrackViewState();
+ }
+ }
+ #endregion // Interface methods
+
+ #region REMOVE ME
+ [MonoTODO]
+ internal void LoadViewState(object state) {
+ throw new NotImplementedException("Use the IStateManager interface instead of this method. It has been obsoleted due to Project Fresh.");
+ }
+ [MonoTODO]
+ internal object SaveViewState() {
+ throw new NotImplementedException("Use the IStateManager interface instead of this method. It has been obsoleted due to Project Fresh");
+ }
+ [MonoTODO]
+ internal void TrackViewState() {
+ throw new NotImplementedException("Use the IStateManager interface instead of this method. It has been obsoleted due to Project Fresh");
+ }
+ #endregion // REMOVE ME
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System;
+using System.ComponentModel;
+using System.Globalization;
+
+// Modeled after Nikhil Kothari's sample in "ASP Server Controls and Components", pp368
+
+namespace System.Web.UI.WebControls {
+ [ToolboxData("<{0}:RangeValidator runat=server ErrorMessage=\"RangeValidator\"></{0}:RangeValidator>")]
+ public class RangeValidator : BaseCompareValidator {
+ #region Public Constructors
+ public RangeValidator() {
+ }
+ #endregion // Public Constructors
+
+ #region Public Instance Properties
+ [Bindable(true)]
+ [DefaultValue("")]
+ public string MaximumValue {
+ get {
+ return ViewState.GetString("MaximumValue", String.Empty);
+ }
+
+ set {
+ ViewState["MaximumValue"] = value;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue("")]
+ public string MinimumValue {
+ get {
+ return ViewState.GetString("MinimumValue", String.Empty);
+ }
+
+ set {
+ ViewState["MinimumValue"] = value;
+ }
+ }
+ #endregion // Public Instance Properties
+
+ #region Public Instance Methods
+ protected override void AddAttributesToRender(HtmlTextWriter writer) {
+ base.AddAttributesToRender (writer);
+
+ if (RenderUplevel) {
+ writer.AddAttribute("evaluationfunction", "RangeValidatorEvaluateIsValid"); // FIXME - we need to define this in client code
+ writer.AddAttribute("minimumValue", MinimumValue.ToString(CultureInfo.InvariantCulture));
+ writer.AddAttribute("maximumValue", MaximumValue.ToString(CultureInfo.InvariantCulture));
+ }
+ }
+
+ protected override bool ControlPropertiesValid() {
+ if (!CanConvert(MinimumValue, this.Type)) {
+ throw new HttpException("Minimum value cannot be converterd to type " + this.Type.ToString());
+ }
+ if (!CanConvert(MaximumValue, this.Type)) {
+ throw new HttpException("Maximum value cannot be converterd to type " + this.Type.ToString());
+ }
+ if (this.Type != ValidationDataType.String) {
+ if (Compare(MinimumValue, MaximumValue, ValidationCompareOperator.GreaterThan, this.Type)) {
+ throw new HttpException("Maximum value must be equal or bigger than Minimum value");
+ }
+ }
+ return base.ControlPropertiesValid ();
+ }
+
+ protected override bool EvaluateIsValid() {
+ string control_value;
+
+ control_value = GetControlValidationValue(this.ControlToValidate);
+ if (control_value == null) {
+ return true;
+ }
+
+ control_value = control_value.Trim();
+
+ if (Compare(control_value, MinimumValue, ValidationCompareOperator.GreaterThanEqual, this.Type)) {
+ if (Compare(control_value, MaximumValue, ValidationCompareOperator.LessThanEqual, this.Type)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ #endregion // Public Instance Methods
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Dennis Bartok (pbartok@novell.com)
+//
+//
+
+using System;
+using System.ComponentModel;
+using System.Drawing;
+
+namespace System.Web.UI.WebControls
+{
+ [TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
+ [ToolboxItem("")]
+ public class Style : System.ComponentModel.Component, System.Web.UI.IStateManager
+ {
+ [Flags]
+ internal enum Styles
+ {
+ None = 0,
+ BackColor = 0x00000001,
+ BorderColor = 0x00000002,
+ BorderStyle = 0x00000004,
+ BorderWidth = 0x00000008,
+ CssClass = 0x00000010,
+ Font = 0x00000020,
+ ForeColor = 0x00000040,
+ Height = 0x00000080,
+ Width = 0x00000100,
+
+ // from TableStyle (which doesn't override IsEmpty)
+ BackImageUrl = 0x00000200,
+ CellPadding = 0x00000400,
+ CellSpacing = 0x00000800,
+ GridLines = 0x00001000,
+ HorizontalAlign = 0x00002000,
+
+ // from TableItemStyle (which doesn't override IsEmpty neither)
+ VerticalAlign = 0x00004000,
+ Wrap = 0x00008000,
+
+ // from DataGridPagerStyle (and, once again, no IsEmpty override)
+ Mode = 0x00010000,
+ NextPageText = 0x00020000,
+ PageButtonCount = 0x00040000,
+ Position = 0x00080000,
+ PrevPageText = 0x00100000,
+ Visible = 0x00200000
+
+ }
+
+ #region Fields
+ internal Styles styles;
+ internal StateBag viewstate;
+ private FontInfo fontinfo;
+ private bool tracking;
+#if NET_2_0
+ private string registered_class;
+#endif
+ #endregion // Fields
+
+ #region Public Constructors
+ public Style() : this(new StateBag())
+ {
+ }
+
+ public Style(System.Web.UI.StateBag bag)
+ {
+ if (bag != null) {
+ viewstate = bag;
+ } else {
+ viewstate = new StateBag();
+ }
+ tracking = false;
+ }
+ #endregion // Public Constructors
+
+ #region Public Instance Properties
+ [Bindable(true)]
+ [DefaultValue("Color [Empty]")]
+ [NotifyParentProperty(true)]
+ [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
+ public Color BackColor
+ {
+ get
+ {
+ if ((styles & Styles.BackColor) == 0)
+ {
+ return Color.Empty;
+ }
+
+ return (Color)viewstate["BackColor"];
+ }
+
+ set
+ {
+ viewstate["BackColor"] = value;
+ styles |= Styles.BackColor;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue("Color [Empty]")]
+ [NotifyParentProperty(true)]
+ [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
+ public Color BorderColor
+ {
+ get
+ {
+ if ((styles & Styles.BorderColor) == 0)
+ {
+ return Color.Empty;
+ }
+
+ return (Color)viewstate["BorderColor"];
+ }
+
+ set
+ {
+ viewstate["BorderColor"] = value;
+ styles |= Styles.BorderColor;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue(BorderStyle.NotSet)]
+ [NotifyParentProperty(true)]
+ public BorderStyle BorderStyle
+ {
+ get
+ {
+ if ((styles & Styles.BorderStyle) == 0)
+ {
+ return BorderStyle.NotSet;
+ }
+
+ return (BorderStyle)viewstate["BorderStyle"];
+ }
+
+ set
+ {
+ viewstate["BorderStyle"] = value;
+ styles |= Styles.BorderStyle;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue("")]
+ [NotifyParentProperty(true)]
+ public Unit BorderWidth
+ {
+ get
+ {
+ if ((styles & Styles.BorderWidth) == 0)
+ {
+ return Unit.Empty;
+ }
+
+ return (Unit)viewstate["BorderWidth"];
+ }
+
+ set
+ {
+ if (value.Value < 0)
+ {
+ throw new ArgumentOutOfRangeException("Value", value.Value, "BorderWidth must not be negative");
+ }
+
+ viewstate["BorderWidth"] = value;
+ styles |= Styles.BorderWidth;
+ }
+ }
+
+ [DefaultValue("")]
+ [NotifyParentProperty(true)]
+ public string CssClass
+ {
+ get
+ {
+ if ((styles & Styles.CssClass) == 0)
+ {
+ return string.Empty;
+ }
+
+ return (string)viewstate["CssClass"];
+ }
+
+ set
+ {
+ viewstate["CssClass"] = value;
+ styles |= Styles.CssClass;
+ }
+ }
+
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
+ [NotifyParentProperty(true)]
+ public FontInfo Font
+ {
+ get
+ {
+ if (fontinfo == null)
+ {
+ fontinfo = new FontInfo(this);
+ }
+ return fontinfo;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue("Color [Empty]")]
+ [NotifyParentProperty(true)]
+ [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
+ public Color ForeColor
+ {
+ get
+ {
+ if ((styles & Styles.ForeColor) == 0)
+ {
+ return Color.Empty;
+ }
+
+ return (Color)viewstate["ForeColor"];
+ }
+
+ set
+ {
+ viewstate["ForeColor"] = value;
+ styles |= Styles.ForeColor;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue("")]
+ [NotifyParentProperty(true)]
+ public Unit Height
+ {
+ get
+ {
+ if ((styles & Styles.Height) == 0)
+ {
+ return Unit.Empty;
+ }
+
+ return (Unit)viewstate["Height"];
+ }
+
+ set
+ {
+ if (value.Value < 0)
+ {
+ throw new ArgumentOutOfRangeException("Value", value.Value, "Height must not be negative");
+ }
+
+ viewstate["Height"] = value;
+ styles |= Styles.Height;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue("")]
+ [NotifyParentProperty(true)]
+ public Unit Width
+ {
+ get
+ {
+ if ((styles & Styles.Width) == 0)
+ {
+ return Unit.Empty;
+ }
+
+ return (Unit)viewstate["Width"];
+ }
+
+ set
+ {
+ if (value.Value < 0)
+ {
+ throw new ArgumentOutOfRangeException("Value", value.Value, "Width must not be negative");
+ }
+
+ viewstate["Width"] = value;
+ styles |= Styles.Width;
+ }
+ }
+ #endregion // Public Instance Properties
+
+ #region Protected Instance Properties
+ protected internal virtual bool IsEmpty
+ {
+ get
+ {
+ return (styles == 0);
+ }
+ }
+
+ protected bool IsTrackingViewState
+ {
+ get
+ {
+ return tracking;
+ }
+ }
+
+ [Browsable(false)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ protected internal StateBag ViewState
+ {
+ get
+ {
+ return viewstate;
+ }
+ }
+ #endregion // Protected Instance Properties
+
+ #region Public Instance Methods
+ public void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
+ {
+ AddAttributesToRender(writer, null);
+ }
+
+ public virtual void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer, WebControl owner)
+ {
+ if ((styles & Styles.CssClass) != 0)
+ {
+ string s = (string)viewstate["CssClass"];
+ if (s != string.Empty)
+ writer.AddAttribute (HtmlTextWriterAttribute.Class, s);
+ }
+
+ CssStyleCollection attributes = new CssStyleCollection ();
+ FillStyleAttributes (attributes);
+ foreach (string attr in attributes.Keys)
+ writer.AddStyleAttribute (attr, attributes [attr]);
+ }
+
+ void FillStyleAttributes (CssStyleCollection attributes)
+ {
+ string s;
+ Color color;
+ BorderStyle bs;
+ Unit u;
+
+ if ((styles & Styles.BackColor) != 0)
+ {
+ color = (Color)viewstate["BackColor"];
+ if (!color.IsEmpty)
+ attributes.Add (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
+ }
+
+ if ((styles & Styles.BorderColor) != 0)
+ {
+ color = (Color)viewstate["BorderColor"];
+ if (!color.IsEmpty)
+ attributes.Add (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
+ }
+
+ if ((styles & Styles.BorderStyle) != 0)
+ {
+ bs = (BorderStyle)viewstate["BorderStyle"];
+ if (bs != BorderStyle.NotSet)
+ attributes.Add (HtmlTextWriterStyle.BorderStyle, bs.ToString());
+ }
+
+ if ((styles & Styles.BorderWidth) != 0)
+ {
+ u = (Unit)viewstate["BorderWidth"];
+ if (!u.IsEmpty)
+ attributes.Add (HtmlTextWriterStyle.BorderWidth, u.ToString());
+ }
+
+ if ((styles & Styles.ForeColor) != 0)
+ {
+ color = (Color)viewstate["ForeColor"];
+ if (!color.IsEmpty)
+ attributes.Add (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
+ }
+
+ if ((styles & Styles.Height) != 0)
+ {
+ u = (Unit)viewstate["Height"];
+ if (!u.IsEmpty)
+ attributes.Add (HtmlTextWriterStyle.Height, u.ToString());
+ }
+
+ if ((styles & Styles.Width) != 0)
+ {
+ u = (Unit)viewstate["Width"];
+ if (!u.IsEmpty)
+ attributes.Add (HtmlTextWriterStyle.Width, u.ToString());
+ }
+
+ if (fontinfo != null) {
+ // Fonts are a bit weird
+ if (fontinfo.Name != string.Empty)
+ {
+ s = fontinfo.Names[0];
+ for (int i = 1; i < fontinfo.Names.Length; i++)
+ {
+ s += "," + fontinfo.Names[i];
+ }
+ attributes.Add (HtmlTextWriterStyle.FontFamily, s);
+ }
+
+ if (fontinfo.Bold)
+ {
+ attributes.Add (HtmlTextWriterStyle.FontWeight, "bold");
+ }
+
+ if (fontinfo.Italic)
+ {
+ attributes.Add (HtmlTextWriterStyle.FontStyle, "italic");
+ }
+
+ if (!fontinfo.Size.IsEmpty)
+ {
+ attributes.Add (HtmlTextWriterStyle.FontSize, fontinfo.Size.ToString());
+ }
+
+ // These styles are munged into a attribute decoration
+ s = string.Empty;
+
+ if (fontinfo.Overline)
+ {
+ s += "overline ";
+ }
+
+ if (fontinfo.Strikeout)
+ {
+ s += "line-through ";
+ }
+
+ if (fontinfo.Underline)
+ {
+ s += "underline ";
+ }
+
+ if (s != string.Empty)
+ {
+ attributes.Add (HtmlTextWriterStyle.TextDecoration, s);
+ }
+ }
+ }
+
+ public virtual void CopyFrom(Style s)
+ {
+ if ((s == null) || s.IsEmpty)
+ {
+ return;
+ }
+
+ if (s.fontinfo != null)
+ {
+ Font.CopyFrom(s.fontinfo);
+ }
+
+ if (((s.styles & Styles.BackColor) != 0) && (s.BackColor != Color.Empty))
+ {
+ this.BackColor = s.BackColor;
+ }
+ if (((s.styles & Styles.BorderColor) != 0) && (s.BorderColor != Color.Empty))
+ {
+ this.BorderColor = s.BorderColor;
+ }
+ if (((s.styles & Styles.BorderStyle) != 0) && (s.BorderStyle != BorderStyle.NotSet))
+ {
+ this.BorderStyle = s.BorderStyle;
+ }
+ if (((s.styles & Styles.BorderWidth) != 0) && (s.BorderWidth != Unit.Empty))
+ {
+ this.BorderWidth = s.BorderWidth;
+ }
+ if (((s.styles & Styles.CssClass) != 0) && (s.CssClass != string.Empty))
+ {
+ this.CssClass = s.CssClass;
+ }
+ if (((s.styles & Styles.ForeColor) != 0) && (s.ForeColor != Color.Empty))
+ {
+ this.ForeColor = s.ForeColor;
+ }
+ if (((s.styles & Styles.Height) != 0) && (s.Height != Unit.Empty))
+ {
+ this.Height = s.Height;
+ }
+ if (((s.styles & Styles.Width) != 0) && (s.Width != Unit.Empty))
+ {
+ this.Width = s.Width;
+ }
+ }
+
+ public virtual void MergeWith(Style s)
+ {
+ if ((s == null) || (s.IsEmpty))
+ {
+ return;
+ }
+
+ if (s.fontinfo != null)
+ {
+ Font.MergeWith(s.fontinfo);
+ }
+
+ if (((styles & Styles.BackColor) == 0) && ((s.styles & Styles.BackColor) != 0) && (s.BackColor != Color.Empty))
+ {
+ this.BackColor = s.BackColor;
+ }
+ if (((styles & Styles.BorderColor) == 0) && ((s.styles & Styles.BorderColor) != 0) && (s.BorderColor != Color.Empty))
+ {
+ this.BorderColor = s.BorderColor;
+ }
+ if (((styles & Styles.BorderStyle) == 0) && ((s.styles & Styles.BorderStyle) != 0) && (s.BorderStyle != BorderStyle.NotSet))
+ {
+ this.BorderStyle = s.BorderStyle;
+ }
+ if (((styles & Styles.BorderWidth) == 0) && ((s.styles & Styles.BorderWidth) != 0) && (s.BorderWidth != Unit.Empty))
+ {
+ this.BorderWidth = s.BorderWidth;
+ }
+ if (((styles & Styles.CssClass) == 0) && ((s.styles & Styles.CssClass) != 0) && (s.CssClass != string.Empty))
+ {
+ this.CssClass = s.CssClass;
+ }
+ if (((styles & Styles.ForeColor) == 0) && ((s.styles & Styles.ForeColor) != 0) && (s.ForeColor != Color.Empty))
+ {
+ this.ForeColor = s.ForeColor;
+ }
+ if (((styles & Styles.Height) == 0) && ((s.styles & Styles.Height) != 0) && (s.Height != Unit.Empty))
+ {
+ this.Height = s.Height;
+ }
+ if (((styles & Styles.Width) == 0) && ((s.styles & Styles.Width) != 0) && (s.Width != Unit.Empty))
+ {
+ this.Width = s.Width;
+ }
+ }
+
+ public virtual void Reset()
+ {
+ viewstate.Remove("BackColor");
+ viewstate.Remove("BorderColor");
+ viewstate.Remove("BorderStyle");
+ viewstate.Remove("BorderWidth");
+ viewstate.Remove("CssClass");
+ viewstate.Remove("ForeColor");
+ viewstate.Remove("Height");
+ viewstate.Remove("Width");
+ if (fontinfo != null)
+ {
+ fontinfo.Reset();
+ }
+ styles = Styles.None;
+ }
+
+ public override string ToString()
+ {
+ return string.Empty;
+ }
+ #endregion // Public Instance Methods
+
+ #region Protected Instance Methods
+ protected internal void LoadViewState(object state)
+ {
+ viewstate.LoadViewState(state);
+
+ // Update our style
+ this.styles = Styles.None;
+
+ if (viewstate["BackColor"] != null)
+ {
+ styles |= Styles.BackColor;
+ }
+ if (viewstate["BorderColor"] != null)
+ {
+ styles |= Styles.BorderColor;
+ }
+ if (viewstate["BorderStyle"] != null)
+ {
+ styles |= Styles.BorderStyle;
+ }
+ if (viewstate["BorderWidth"] != null)
+ {
+ styles |= Styles.BorderWidth;
+ }
+ if (viewstate["CssClass"] != null)
+ {
+ styles |= Styles.CssClass;
+ }
+ if (viewstate["ForeColor"] != null)
+ {
+ styles |= Styles.ForeColor;
+ }
+ if (viewstate["Height"] != null)
+ {
+ styles |= Styles.Height;
+ }
+ if (viewstate["Width"] != null)
+ {
+ styles |= Styles.Width;
+ }
+ if (fontinfo != null) {
+ fontinfo.LoadViewState();
+ }
+
+ LoadViewStateInternal();
+ }
+
+ internal virtual void LoadViewStateInternal()
+ {
+ // Override me
+ }
+
+ protected internal virtual object SaveViewState ()
+ {
+ if (styles != Styles.None)
+ {
+ return viewstate.SaveViewState();
+ }
+ return null;
+ }
+
+ [MonoTODO]
+ protected internal virtual void SetBit( int bit )
+ {
+ throw new NotImplementedException();
+ }
+
+ protected internal virtual void TrackViewState()
+ {
+ tracking = true;
+ viewstate.TrackViewState();
+ }
+ #endregion // Protected Instance Methods
+
+ #region IStateManager Properties & Methods
+ void IStateManager.LoadViewState(object state)
+ {
+ LoadViewState(state);
+ }
+
+ object IStateManager.SaveViewState()
+ {
+ return SaveViewState();
+ }
+
+ void IStateManager.TrackViewState()
+ {
+ TrackViewState();
+ }
+
+ bool IStateManager.IsTrackingViewState
+ {
+ get
+ {
+ return this.IsTrackingViewState;
+ }
+ }
+ #endregion // IStateManager Properties & Methods
+
+ #region REMOVE ME
+ internal static int BORDERWIDTH = 0xeadbeef;
+ internal static int FORECOLOR = 0xeadbeef;
+
+ [Obsolete ("This method will be removed in Fresh")]
+ internal bool IsSet(int blah)
+ {
+ if (blah == BORDERWIDTH)
+ return ((styles & Styles.BorderWidth) != 0);
+
+ if (blah == FORECOLOR)
+ return ((styles & Styles.ForeColor) != 0);
+
+ return false;
+ }
+
+ [Obsolete ("This method will be removed in Fresh")]
+ internal void Set(int blah)
+ {
+ }
+ #endregion // REMOVE ME
+
+#if NET_2_0
+ protected virtual void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
+ {
+ FillStyleAttributes (attributes);
+ }
+
+ internal void SetRegisteredCssClass (string name)
+ {
+ registered_class = name;
+ }
+
+ public CssStyleCollection GetStyleAttributes (IUrlResolutionService resolver)
+ {
+ CssStyleCollection col = new CssStyleCollection ();
+ FillStyleAttributes (col, resolver);
+ return col;
+ }
+
+ [MonoTODO]
+ public string RegisteredCssClass {
+ get {
+ return registered_class;
+ }
+ }
+
+ internal virtual void CopyTextStylesFrom (Style source)
+ {
+ // Need to ask lluis if we need fonts, too
+ if ((styles & Styles.ForeColor) != 0) {
+ ForeColor = source.ForeColor;
+ }
+ if ((styles & Styles.BackColor) != 0) {
+ BackColor = source.BackColor;
+ }
+ }
+
+ public void SetDirty ()
+ {
+ if (viewstate != null)
+ viewstate.SetDirty ();
+ }
+
+ public static bool IsStyleEmpty (Style s)
+ {
+ if (s == null)
+ return true;
+ return s.IsEmpty;
+ }
+
+#endif
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System.ComponentModel;
+
+namespace System.Web.UI.WebControls {
+ public class TargetConverter : System.ComponentModel.StringConverter {
+ #region Public Constructors
+ public TargetConverter() {
+ }
+ #endregion // Public Constructors
+
+ #region Public Instance Methods
+ public override System.ComponentModel.TypeConverter.StandardValuesCollection GetStandardValues(System.ComponentModel.ITypeDescriptorContext context) {
+ string[] values = new string[] { "_blank", "_parent", "_search", "_self", "_top"};
+ return new TypeConverter.StandardValuesCollection(values);
+ }
+
+ public override bool GetStandardValuesExclusive(System.ComponentModel.ITypeDescriptorContext context) {
+ return false;
+ }
+
+ public override bool GetStandardValuesSupported(System.ComponentModel.ITypeDescriptorContext context) {
+ return true;
+ }
+
+ #endregion // Public Instance Methods
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System;
+using System.Collections;
+using System.ComponentModel;
+using System.Globalization;
+
+namespace System.Web.UI.WebControls {
+ public class ValidatedControlConverter : StringConverter {
+ #region Public Constructors
+ public ValidatedControlConverter() {
+ }
+ #endregion // Public Constructors
+
+ #region Public Instance Methods
+ // We need to return all controls that have a validation property
+ public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
+ if ((context != null) && (context.Container != null) && (context.Container.Components != null)) {
+ ArrayList values;
+ int count;
+ PropertyDescriptor pd;
+ string id;
+ ComponentCollection components;
+
+ values = new ArrayList();
+ components = context.Container.Components;
+ count = components.Count;
+
+ for (int i = 0; i < count; i++) {
+ pd = BaseValidator.GetValidationProperty(components[i]);
+ if (pd != null) { // We have a ValidationProperty
+ id = ((Control)components[i]).ID;
+ if ((id != null) && (id.Length > 0)) {
+ values.Add(id);
+ }
+ }
+ }
+
+ // How do I sort the InvariantCulture way?
+ values.Sort();
+ if (values.Count > 0) {
+ return new StandardValuesCollection(values);
+ }
+ return null;
+ }
+ return base.GetStandardValues (context);
+ }
+
+ public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) {
+ return false;
+ }
+
+ public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
+ return true;
+ }
+ #endregion // Public Instance Methods
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System;
+using System.Collections;
+using System.ComponentModel;
+using System.Drawing;
+using System.Globalization;
+using System.Web;
+using System.Web.UI;
+using System.Web.UI.WebControls;
+
+namespace System.Web.UI.WebControls {
+#if NET_2_0
+ [Designer ("System.Web.UI.Design.WebControls.PreviewControlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
+#endif
+ public class ValidationSummary : WebControl {
+ #region Public Constructors
+ public ValidationSummary() : base(HtmlTextWriterTag.Div) {
+ this.ForeColor = Color.Red;
+ }
+ #endregion // Public Constructors
+
+ #region Public Instance Properties
+#if ONLY_1_1
+ [Bindable(true)]
+#endif
+ [DefaultValue(ValidationSummaryDisplayMode.BulletList)]
+ public ValidationSummaryDisplayMode DisplayMode {
+ get {
+ object obj;
+
+ obj = ViewState["DisplayMode"];
+ if (obj != null) {
+ return (ValidationSummaryDisplayMode)obj;
+ }
+ return ValidationSummaryDisplayMode.BulletList;
+ }
+
+ set {
+ ViewState["DisplayMode"] = value;
+ }
+ }
+
+ [DefaultValue(true)]
+#if NET_2_0
+ [Themeable (false)]
+#endif
+ public bool EnableClientScript {
+ get {
+ return ViewState.GetBool("EnableClientScript", true);
+ }
+
+ set {
+ ViewState["EnableClientScript"] = value;
+ }
+ }
+
+ [DefaultValue("Color [Red]")]
+ public override System.Drawing.Color ForeColor {
+ get {
+ return base.ForeColor;
+ }
+
+ set {
+ base.ForeColor = value;
+ }
+ }
+
+#if ONLY_1_1
+ [Bindable(true)]
+#endif
+ [DefaultValue("")]
+#if NET_2_0
+ [Localizable (true)]
+#endif
+ public string HeaderText {
+ get {
+ return ViewState.GetString("HeaderText", string.Empty);
+ }
+
+ set {
+ ViewState["HeaderText"] = value;
+ }
+ }
+
+#if ONLY_1_1
+ [Bindable(true)]
+#endif
+ [DefaultValue(false)]
+ public bool ShowMessageBox {
+ get {
+ return ViewState.GetBool("ShowMessageBox", false);
+ }
+
+ set {
+ ViewState["ShowMessageBox"] = value;
+ }
+ }
+
+#if ONLY_1_1
+ [Bindable(true)]
+#endif
+ [DefaultValue(true)]
+ public bool ShowSummary {
+ get {
+ return ViewState.GetBool("ShowSummary", true);
+ }
+
+ set {
+ ViewState["ShowSummary"] = value;
+ }
+ }
+
+#if NET_2_0
+ [DefaultValue ("")]
+ [Themeable (false)]
+ public string ValidationGroup
+ {
+ get {
+ return ViewState.GetString("ValidationGroup", string.Empty);
+ }
+ set {
+ ViewState["ValidationGroup"] = value;
+ }
+ }
+#endif
+
+ #endregion // Public Instance Properties
+
+ #region Public Instance Methods
+ protected override void AddAttributesToRender(HtmlTextWriter writer) {
+ base.AddAttributesToRender (writer);
+
+ if (EnableClientScript && pre_render_called) {
+ if (HeaderText != "")
+ writer.AddAttribute ("headertext", HeaderText);
+
+ if (ShowMessageBox)
+ writer.AddAttribute ("showmessagebox", ShowMessageBox.ToString());
+
+ if (ShowSummary == false)
+ writer.AddAttribute ("showsummary", ShowSummary.ToString());
+
+ if (DisplayMode != ValidationSummaryDisplayMode.BulletList)
+ writer.AddAttribute ("displaymode", DisplayMode.ToString());
+
+ writer.AddStyleAttribute ("display", "none");
+ }
+ }
+
+ bool pre_render_called = false;
+
+#if NET_2_0
+ protected internal
+#else
+ protected
+#endif
+ override void OnPreRender(EventArgs e) {
+ base.OnPreRender (e);
+
+ pre_render_called = true;
+ }
+
+#if NET_2_0
+ protected internal
+#else
+ protected
+#endif
+ override void Render(HtmlTextWriter writer) {
+ ValidatorCollection validators;
+ ArrayList errors;
+
+ // First, figure out if there's even data to deal with
+#if NET_2_0
+ validators = Page.GetValidators (ValidationGroup);
+#else
+ validators = Page.Validators;
+#endif
+ if (validators.Count == 0) {
+ return;
+ }
+
+ if (EnableClientScript && pre_render_called) {
+ Page.RegisterArrayDeclaration ("Page_ValidationSummaries",
+ String.Format ("document.getElementById ('{0}')", ID));
+ }
+
+ // We have validators
+ errors = new ArrayList(validators.Count);
+ for (int i = 0; i < validators.Count; i++) {
+ if (!validators[i].IsValid) {
+ errors.Add(validators[i].ErrorMessage);
+ }
+ }
+
+ if ((ShowSummary && errors.Count > 0) || (EnableClientScript && pre_render_called))
+ base.RenderBeginTag(writer);
+
+ if (ShowSummary && errors.Count > 0) {
+ switch(DisplayMode) {
+ case ValidationSummaryDisplayMode.BulletList: {
+ if (HeaderText.Length > 0) {
+ writer.Write(HeaderText);
+ }
+
+ writer.Write("<ul>");
+ for (int i = 0; i < errors.Count; i++) {
+ writer.Write("<li>");
+ writer.Write(errors[i]);
+ writer.Write("</li>");
+ }
+ writer.Write("</ul>");
+ break;
+ }
+
+ case ValidationSummaryDisplayMode.List: {
+ if (HeaderText.Length > 0) {
+ writer.Write(HeaderText);
+#if NET_2_0
+ writer.Write("<br />");
+#else
+ writer.Write("<br>");
+#endif
+ }
+
+ for (int i = 0; i < errors.Count; i++) {
+ writer.Write(errors[i]);
+#if NET_2_0
+ writer.Write("<br />");
+#else
+ writer.Write("<br>");
+#endif
+ }
+ break;
+ }
+
+ case ValidationSummaryDisplayMode.SingleParagraph: {
+ if (HeaderText.Length > 0) {
+ writer.Write(HeaderText);
+ writer.Write(" ");
+ }
+
+ for (int i = 0; i < errors.Count; i++) {
+ writer.Write(errors[i]);
+ writer.Write(" ");
+ }
+#if NET_2_0
+ writer.Write("<br />");
+#else
+ writer.Write("<br>");
+#endif
+
+ break;
+ }
+ }
+ }
+
+ if ((ShowSummary && errors.Count > 0) || (EnableClientScript && pre_render_called))
+ base.RenderEndTag(writer);
+ }
+ #endregion // Public Instance Methods
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System;
+using System.Drawing;
+using System.Globalization;
+using System.ComponentModel;
+
+namespace System.Web.UI.WebControls {
+ public class WebColorConverter : ColorConverter {
+
+ // Converts from string to Color
+ public override object ConvertFrom (ITypeDescriptorContext context, CultureInfo culture, object value)
+ {
+ if (value is string)
+ {
+ string s;
+
+ s = ((string)value).Trim();
+ if (s.Length == 0)
+ {
+ return Color.Empty;
+ }
+
+ if (culture == null) {
+ culture = CultureInfo.InvariantCulture;
+ }
+
+ if (s[0] == '#')
+ {
+ // Hex
+
+ // MS throws a generic exception, wrapping the specific exception, who knows why...
+ try
+ {
+ if (s.Length == 7)
+ {
+ int v;
+ v = Int32.Parse(s.Substring(1), NumberStyles.HexNumber, culture);
+
+ return Color.FromArgb(255, (v >> 16) & 0xff, (v >> 8) & 0xff, v & 0xff);
+ }
+ else
+ {
+ return Color.FromArgb(Int32.Parse(s.Substring(1), NumberStyles.HexNumber, culture));
+ }
+ }
+
+ catch (FormatException e)
+ {
+ throw new Exception(s + "is not a valid color value", e);
+ }
+ catch (System.OverflowException e)
+ {
+ throw new Exception(s + " is not a valid color value", e);
+ }
+ }
+ else
+ {
+ // Name or decimal
+ int n = 0;
+
+ try
+ {
+ n = Int32.Parse(s, NumberStyles.Integer, culture);
+ }
+
+ catch (FormatException e)
+ {
+ Color c;
+
+ c = Color.FromName(s);
+ if ((c.A != 0) || (c.R != 0) || (c.G != 0) || (c.B != 0))
+ {
+ return c;
+ }
+
+ throw new Exception(s + " is not a valid color value", e);
+ }
+
+ catch (System.OverflowException e)
+ {
+ throw new Exception(s + " is not a valid color value", e);
+ }
+
+ catch
+ {
+ throw;
+ }
+
+ return Color.FromArgb(n);
+ }
+ }
+ return base.ConvertFrom (context, culture, value);
+ }
+
+ // Converts from Color to string
+ public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
+ {
+ if (!(value is Color) || destinationType != typeof (string))
+ return base.ConvertTo (context, culture, value, destinationType);
+
+ Color c = (Color) value;
+
+ if (culture == null)
+ culture = CultureInfo.InvariantCulture;
+
+ string s = c.ToKnownColor ().ToString ();
+ if (s != "0")
+ return s;
+
+ return String.Format (culture, "#{0:X2}{1:X2}{2:X2}", c.R, c.G, c.B);
+ }
+ }
+}
--- /dev/null
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
+//
+// Authors:
+// Peter Bartok (pbartok@novell.com)
+//
+//
+
+using System.ComponentModel;
+using System.Drawing;
+
+namespace System.Web.UI.WebControls {
+#if NET_2_0
+ [PersistChildrenAttribute (false, false)]
+ [ParseChildrenAttribute (true, ChildControlType = typeof(Control))]
+ [Themeable (true)]
+#else
+ [PersistChildrenAttribute (false)]
+ [ParseChildrenAttribute (true)]
+#endif
+ public class WebControl : Control, IAttributeAccessor {
+ Style style;
+ HtmlTextWriterTag tag;
+ string tag_name;
+ AttributeCollection attributes;
+ StateBag attribute_state;
+ bool enabled;
+
+ public WebControl (HtmlTextWriterTag tag)
+ {
+ this.tag = tag;
+ this.enabled = true;
+ }
+
+ protected WebControl () : this (HtmlTextWriterTag.Span)
+ {
+ }
+
+ protected WebControl (string tag)
+ {
+ this.tag = HtmlTextWriterTag.Unknown;
+ this.tag_name = tag;
+ this.enabled = true;
+ }
+
+#if ONLY_1_1
+ [Bindable(true)]
+#endif
+ [DefaultValue("")]
+ public virtual string AccessKey {
+ get {
+ return ViewState.GetString ("AccessKey", string.Empty);
+ }
+ set {
+ if (value == null || value.Length < 2)
+ ViewState ["AccessKey"] = value;
+ else
+ throw new ArgumentException ("AccessKey can only be null, empty or a single character", "value");
+ }
+ }
+
+ [Browsable(false)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ public AttributeCollection Attributes {
+ get {
+ if (attributes == null) {
+ attribute_state = new StateBag ();
+ if (IsTrackingViewState)
+ attribute_state.TrackViewState ();
+
+ attributes = new AttributeCollection (attribute_state);
+ }
+ return attributes;
+ }
+ }
+
+#if ONLY_1_1
+ [Bindable(true)]
+#endif
+ [DefaultValue("Color [Empty]")]
+ [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
+ public virtual Color BackColor {
+ get {
+ if (style == null)
+ return Color.Empty;
+
+ return style.BackColor;
+ }
+ set {
+ ControlStyle.BackColor = value;
+ }
+ }
+
+#if ONLY_1_1
+ [Bindable(true)]
+#endif
+ [DefaultValue("Color [Empty]")]
+ [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
+ public virtual Color BorderColor {
+ get {
+ if (style == null)
+ return Color.Empty;
+
+ return style.BorderColor;
+ }
+
+ set {
+ ControlStyle.BorderColor = value;
+ }
+ }
+
+#if ONLY_1_1
+ [Bindable(true)]
+#endif
+ [DefaultValue(BorderStyle.NotSet)]
+ public virtual BorderStyle BorderStyle {
+ get {
+ if (style == null)
+ return BorderStyle.NotSet;
+
+ return style.BorderStyle;
+ }
+ set {
+ if (value < BorderStyle.NotSet || value > BorderStyle.Outset)
+ throw new ArgumentOutOfRangeException ("value");
+
+ ControlStyle.BorderStyle = value;
+ }
+ }
+
+#if ONLY_1_1
+ [Bindable(true)]
+#endif
+ [DefaultValue("")]
+ public virtual Unit BorderWidth {
+ get {
+ if (style == null)
+ return Unit.Empty;
+
+ return style.BorderWidth;
+ }
+ set {
+ ControlStyle.BorderWidth = value;
+ }
+ }
+
+ [Browsable(false)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ public Style ControlStyle {
+ get {
+ if (style == null) {
+ style = this.CreateControlStyle ();
+
+ if (IsTrackingViewState)
+ style.TrackViewState ();
+ }
+
+ return style;
+ }
+ }
+
+ [Browsable(false)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ public bool ControlStyleCreated {
+ get {
+ return style != null;
+ }
+ }
+
+#if ONLY_1_1
+ [Bindable(true)]
+#endif
+ [DefaultValue("")]
+ public virtual string CssClass {
+ get {
+ if (style == null)
+ return string.Empty;
+
+ return style.CssClass;
+ }
+ set {
+ ControlStyle.CssClass = value;
+ }
+ }
+
+ [Bindable(true)]
+ [DefaultValue(true)]
+#if NET_2_0
+ [Themeable (false)]
+#endif
+ public virtual bool Enabled {
+ get {
+ return enabled;
+ }
+
+ set {
+ if (enabled != value) {
+ ViewState ["Enabled"] = value;
+ enabled = value;
+ }
+ }
+ }
+
+#if NET_2_0
+ [Browsable (true)]
+ [MonoTODO]
+ public virtual new bool EnableTheming
+ {
+ get {
+ throw new NotImplementedException ();
+ }
+ set {
+ throw new NotImplementedException ();
+ }
+ }
+#endif
+
+#if ONLY_1_1
+ [DefaultValue(null)]
+#endif
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
+ [NotifyParentProperty(true)]
+ public virtual FontInfo Font {
+ get {
+ // Oddly enough, it looks like we have to let it create the style
+ // since we can't create a FontInfo without a style owner
+ return ControlStyle.Font;
+ }
+ }
+
+#if ONLY_1_1
+ [Bindable(true)]
+#endif
+ [DefaultValue("Color [Empty]")]
+ [TypeConverter(typeof(System.Web.UI.WebControls.WebColorConverter))]
+ public virtual Color ForeColor {
+ get {
+ if (style == null)
+ return Color.Empty;
+
+ return style.ForeColor;
+ }
+ set {
+ ControlStyle.ForeColor = value;
+ }
+ }
+
+#if NET_2_0
+ [Browsable (false)]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ [MonoTODO]
+ public bool HasAttributes
+ {
+ get {
+ throw new NotImplementedException ();
+ }
+ }
+#endif
+
+#if ONLY_1_1
+ [Bindable(true)]
+#endif
+ [DefaultValue("")]
+ public virtual Unit Height {
+ get {
+ if (style == null)
+ return Unit.Empty;
+
+ return style.Height;
+ }
+ set {
+ ControlStyle.Height = value;
+ }
+ }
+
+#if NET_2_0
+ [Browsable (true)]
+ [MonoTODO]
+ public virtual new string SkinID
+ {
+ get {
+ throw new NotImplementedException ();
+ }
+ set {
+ throw new NotImplementedException ();
+ }
+ }
+#endif
+
+ [Browsable(false)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ public CssStyleCollection Style {
+ get {
+ return Attributes.CssStyle;
+ }
+ }
+
+ [DefaultValue(0)]
+ public virtual short TabIndex {
+ get {
+ return ViewState.GetShort ("TabIndex", 0);
+ }
+ set {
+ ViewState ["TabIndex"] = value;
+ }
+ }
+
+#if ONLY_1_1
+ [Bindable(true)]
+#endif
+ [DefaultValue("")]
+#if NET_2_0
+ [Localizable (true)]
+#endif
+ public virtual string ToolTip {
+ get {
+ return ViewState.GetString ("ToolTip", string.Empty);
+ }
+ set {
+ ViewState ["ToolTip"] = value;
+ }
+ }
+
+#if ONLY_1_1
+ [Bindable(true)]
+#endif
+ [DefaultValue("")]
+ public virtual Unit Width {
+ get {
+ if (style == null)
+ return Unit.Empty;
+
+ return style.Width;
+ }
+ set {
+ ControlStyle.Width = value;
+ }
+ }
+
+ [Browsable(false)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ protected virtual HtmlTextWriterTag TagKey {
+ get {
+ return tag;
+ }
+ }
+
+ [Browsable(false)]
+ [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
+ protected virtual string TagName {
+ get {
+ // do this here to avoid potentially costly lookups on every control
+ if (tag_name == null)
+ tag_name = HtmlTextWriter.StaticGetTagName (TagKey);
+
+ return tag_name;
+ }
+ }
+
+#if NET_2_0
+ [MonoTODO]
+ protected internal bool IsEnabled
+ {
+ get {
+ throw new NotImplementedException ();
+ }
+ }
+#endif
+
+
+ public void ApplyStyle (Style s)
+ {
+ if (s != null && !s.IsEmpty)
+ ControlStyle.CopyFrom(s);
+ }
+
+ public void CopyBaseAttributes (WebControl controlSrc)
+ {
+ object o;
+
+ if (controlSrc == null)
+ return;
+
+ o = controlSrc.ViewState ["Enabled"];
+ if (o != null) {
+ enabled = (bool)o;
+ }
+
+ o = controlSrc.ViewState ["AccessKey"];
+ if (o != null)
+ ViewState ["AccessKey"] = o;
+
+ o = controlSrc.ViewState ["TabIndex"];
+ if (o != null)
+ ViewState ["TabIndex"] = o;
+
+ o = controlSrc.ViewState ["ToolTip"];
+ if (o != null)
+ ViewState ["ToolTip"] = o;
+
+ if (controlSrc.attributes != null)
+ foreach (string s in controlSrc.attributes.Keys)
+ Attributes [s] = controlSrc.attributes [s];
+ }
+
+ public void MergeStyle (Style s)
+ {
+ if (s != null && !s.IsEmpty)
+ ControlStyle.MergeWith(s);
+ }
+
+ public virtual void RenderBeginTag (HtmlTextWriter writer)
+ {
+ AddAttributesToRender (writer);
+
+ if (TagKey == HtmlTextWriterTag.Unknown)
+ writer.RenderBeginTag (TagName);
+ else
+ writer.RenderBeginTag (TagKey);
+
+ }
+
+ public virtual void RenderEndTag (HtmlTextWriter writer)
+ {
+ writer.RenderEndTag ();
+ }
+
+ protected virtual void AddAttributesToRender (HtmlTextWriter writer)
+ {
+ if (ID != null)
+ writer.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
+
+ if (AccessKey != string.Empty)
+ writer.AddAttribute (HtmlTextWriterAttribute.Accesskey, AccessKey);
+
+ if (!enabled)
+ writer.AddAttribute (HtmlTextWriterAttribute.Disabled, "disabled");
+
+ if (ToolTip != string.Empty)
+ writer.AddAttribute (HtmlTextWriterAttribute.Title, ToolTip);
+
+ if (TabIndex != 0)
+ writer.AddAttribute (HtmlTextWriterAttribute.Tabindex, TabIndex.ToString ());
+
+ if (style != null && !style.IsEmpty)
+ style.AddAttributesToRender(writer, this);
+
+ if (attributes != null)
+ foreach(string s in attributes.Keys)
+ writer.AddAttribute (s, attributes [s]);
+ }
+
+ protected virtual Style CreateControlStyle()
+ {
+ style = new Style (ViewState);
+ return style;
+ }
+
+ protected override void LoadViewState (object savedState)
+ {
+ if (savedState == null) {
+ base.LoadViewState(null);
+ return;
+ }
+
+ Triplet triplet = (Triplet) savedState;
+
+ base.LoadViewState (triplet.First);
+
+ if (triplet.Second != null) {
+ if (attribute_state == null) {
+ attribute_state = new StateBag ();
+ if (IsTrackingViewState)
+ attribute_state.TrackViewState ();
+ }
+ attribute_state.LoadViewState (triplet.Second);
+ attributes = new AttributeCollection(attribute_state);
+ }
+
+ if (triplet.Third != null) {
+ if (style == null)
+ style = CreateControlStyle ();
+
+ style.LoadViewState (triplet.Third);
+ }
+
+ enabled = ViewState.GetBool("Enabled", true);
+ }
+
+#if NET_2_0
+ protected internal
+#else
+ protected
+#endif
+ override void Render (HtmlTextWriter writer)
+ {
+ RenderBeginTag (writer);
+ RenderContents (writer);
+ RenderEndTag (writer);
+ }
+
+#if NET_2_0
+ protected internal
+#else
+ protected
+#endif
+ virtual void RenderContents (HtmlTextWriter writer)
+ {
+ base.Render (writer);
+ }
+
+ protected override object SaveViewState ()
+ {
+ object view_state;
+ object attr_view_state = null;
+ object style_view_state = null;
+
+ view_state = base.SaveViewState ();
+
+ if (attribute_state != null)
+ attr_view_state = attribute_state.SaveViewState ();
+
+ if (style != null)
+ style_view_state = style.SaveViewState ();
+
+ if (view_state == null && attr_view_state == null && style_view_state == null)
+ return null;
+
+ return new Triplet (view_state, attr_view_state, style_view_state);
+ }
+
+ protected override void TrackViewState()
+ {
+ if (style != null)
+ style.TrackViewState ();
+
+ if (attribute_state != null)
+ attribute_state.TrackViewState ();
+
+ base.TrackViewState ();
+ }
+
+ string IAttributeAccessor.GetAttribute (string key)
+ {
+ if (attributes != null)
+ return attributes [key];
+
+ return null;
+ }
+
+ void IAttributeAccessor.SetAttribute (string key, string value)
+ {
+ Attributes [key] = value;
+ }
+ }
+}