/* * Box Social™ * http://boxsocial.net/ * Copyright © 2007, David Lachlan Smith * * $Id:$ * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Web; namespace BoxSocial.Forms { public class TextBox : FormField { private string value; private bool disabled; protected bool visible; private int maxLength; private bool isFormatted; private int lines; private StyleLength width; private ScriptProperty script; public string Value { get { return value; } set { this.value = value; } } public bool IsDisabled { get { return disabled; } set { disabled = value; } } public bool IsVisible { get { return visible; } set { visible = false; } } /// /// True if formatted for BBcode /// public bool IsFormatted { get { return isFormatted; } set { isFormatted = value; if (isFormatted) { MaxLength = -1; lines = 15; } else { lines = 1; } } } public int MaxLength { get { return maxLength; } set { maxLength = value; // Update the value if (maxLength > -1) { if (!string.IsNullOrEmpty(this.value)) { if (this.value.Length > maxLength) { this.value = this.value.Substring(0, maxLength); } } } } } public int Lines { get { return lines; } set { lines = value; } } public StyleLength Width { get { return width; } set { width = value; } } public ScriptProperty Script { get { return script; } } public TextBox(string name) { this.name = name; disabled = false; visible = true; maxLength = -1; lines = 1; width = new StyleLength(100F, LengthUnits.Percentage); script = new ScriptProperty(); } public override string ToString() { if (isFormatted) { return string.Format("
", HttpUtility.HtmlEncode(name), HttpUtility.HtmlEncode(Value), lines, 17 * lines, (IsDisabled) ? " disabled=\"disabled\"" : string.Empty, (!IsVisible) ? " display: none;" : string.Empty, width, Script.ToString()); } else { return string.Format("", HttpUtility.HtmlEncode(name), HttpUtility.HtmlEncode(Value), (IsDisabled) ? " disabled=\"disabled\"" : string.Empty, (MaxLength > -1) ? " maxlength=\"" + MaxLength + "\"" : string.Empty, (!IsVisible) ? " display: none;" : string.Empty, width, Script.ToString()); } } } }