?? htmltextbox.cs
字號:
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.UI;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Resources;
using System.Collections;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using ASPNET.StarterKit.Communities.HtmlTextBoxControls;
using ASPNET.StarterKit.Communities.HtmlTextBoxControls.Common;
using ASPNET.StarterKit.Communities.HtmlTextBoxControls.Design;
[assembly:TagPrefix("HtmlTextBoxControls", "FTB")]
namespace ASPNET.StarterKit.Communities
{
/// <summary>
/// An HTML editor using MSHTML written for ASP.NET.
/// </summary>
[ToolboxData("<{0}:HtmlTextBox runat=server></{0}:HtmlTextBox>"),
ValidationPropertyAttribute("Text"),
Designer(typeof(HtmlTextBoxControls.Design.HtmlTextBoxDesigner))]
public class HtmlTextBox : Control, IPostBackDataHandler, INamingContainer, IPostBackEventHandler, IAttributeAccessor //SMR- CSK integration - IAttributeAccessor added for
{
// Events
/// <summary>
/// The event fired when a Save button is pressed.
/// </summary>
public event EventHandler SaveClick;
/// <summary>
/// Event for Save button
/// </summary>
protected virtual void OnSaveClick(EventArgs e)
{
if (SaveClick != null)
{
SaveClick(this, e);
}
}
public virtual void RaisePostBackEvent(string eventArgument)
{
switch (eventArgument)
{
case "Save":
this.OnSaveClick(EventArgs.Empty);
break;
default:
break;
}
}
public void RaisePostDataChangedEvent()
{
// nothing happens for text changed
}
public bool LoadPostData(String postDataKey, NameValueCollection values)
{
string PresentValue = this.ViewStateText;
string PostedValue = values[base.ID];
if (!PresentValue.Equals(PostedValue))
{
this.OldText = PostedValue;//SMR- CSK integration
return true;
}
else
{
return false;
}
}
#region Properties
// Properties
private string ViewStateText
{
get
{
object savedState = this.ViewState["Text"];
return (savedState == null) ? "" : (string) savedState;
}
}
/// <summary>
/// Returns the Text property stripped of HTML, using Regex <(.|\n)+?>
/// </summary>
[
CategoryAttribute("Output"),
BrowsableAttribute(false)
]
public string HtmlStrippedText
{
get
{
return Regex.Replace(this.OldText,"<(.|\n)+?>","");//SMR- CSK integration
}
}
/// <summary>
/// Collection of the toolbars
/// </summary>
public ToolbarList Toolbars = new ToolbarList();
/// <summary>
/// Contains the HTML for the editor.
/// </summary>
[
CategoryAttribute("Output"),
BrowsableAttribute(false)
]
public string OldText
{
get
{
string output = this.ViewStateText;
if (this.RemoveServerNameFromUrls || this.ConvertHtmlSymbolsToHtmlCodes || this.RemoveScriptNameFromBookmarks)
{
try
{
PostProcessor processor = new PostProcessor();
if (this.RemoveScriptNameFromBookmarks)
{
string server = Page.Request.ServerVariables["HTTP_HOST"];
string script = Page.Request.ServerVariables["SCRIPT_NAME"];
string qstring = Page.Request.QueryString.ToString();
output = processor.RemoveScriptNameFromBookmarks(output,server,script,qstring);
output = processor.RemoveScriptNameFromBookmarks(output,server,script,qstring.Replace("&","&"));
}
if (this.RemoveServerNameFromUrls)
output = processor.RemoveServerNameFromUrls(output,Page.Request.ServerVariables["HTTP_HOST"]);
if (this.ConvertHtmlSymbolsToHtmlCodes)
output = processor.HtmlSymbolsToHtmlCodes(output);
}
catch
{
// for designer do nothing...
}
}
return output;
}
set
{
ViewState["Text"] = value;
}
}
[
CategoryAttribute("Output")
]
public string Text
{
get
{
if (_allowHtml == AllowHtml.Limited && this.IsMshtmlEditorCapable == false)
{
return SimpleHtmlEncode(this.RawText);
}
else
{
return this.RawText;
}
}
set {this.OldText = Context.Server.HtmlEncode(value);}//SMR- CSK integration
}
/// <summary>
/// Outputs what is stored in the hidden HMTL field before any post processing
/// </summary>
[
CategoryAttribute("Output"),
BrowsableAttribute(false)
]
public string RawText
{
get
{
object savedState = this.ViewState["Text"];
return (savedState == null) ? "" : (string) savedState;
}
}
/// <summary>
/// Applies Server.HtmlEncode to Text. Please note that Server.HtmlEncode does not recognize all HTML characters.
/// </summary>
[
CategoryAttribute("Output"),
BrowsableAttribute(false)
]
public string HtmlEncodedText
{
get {return Page.Server.HtmlEncode(this.OldText);}//SMR- CSK integration
}
/// <summary>
/// If true, does not allow pasting of text into FreeTextArea.
/// </summary>
[
CategoryAttribute("Behavior")
]
public bool DisablePaste
{
get
{
object savedState = this.ViewState["DisablePaste"];
return (savedState == null) ? false : (bool) savedState;
}
set
{
ViewState["DisablePaste"] = value;
}
}
/*
I'd like to impliment this in a future build
/// <summary>
/// If true, alerts user to possible HTML from MS Word.
/// </summary>
[
CategoryAttribute("Behavior")
]
public bool AlertClientToMsWordPaste {
get {
object savedState = this.ViewState["AlertClientToMsWordPaste"];
return (savedState == null) ? true : (bool) savedState;
}
set {
ViewState["AlertClientToMsWordPaste"] = value;
}
}
*/
/// <summary>
/// If true, strips out the local server name from all A and IMG tags
/// </summary>
[
CategoryAttribute("Behavior")
]
public bool RemoveServerNameFromUrls
{
get
{
object savedState = this.ViewState["RemoveServerNameFromUrls"];
return (savedState == null) ? true : (bool) savedState;
}
set
{
ViewState["RemoveServerNameFromUrls"] = value;
}
}
/// <summary>
/// Removes the scriptname from bookmarks
/// </summary>
[
CategoryAttribute("Behavior")
]
public bool RemoveScriptNameFromBookmarks
{
get
{
object savedState = this.ViewState["RemoveScriptNameFromBookmarks"];
return (savedState == null) ? true : (bool) savedState;
}
set
{
ViewState["RemoveScriptNameFromBookmarks"] = value;
}
}
/// <summary>
/// If true, sets IFRAME source so that SSL will work
/// </summary>
[
CategoryAttribute("Behavior")
]
public bool EnableSsl
{
get
{
object savedState = this.ViewState["EnableSsl"];
return (savedState == null) ? false : (bool) savedState;
}
set
{
ViewState["EnableSsl"] = value;
}
}
/// <summary>
/// If true, strips out all the base
/// </summary>
[
CategoryAttribute("Behavior")
]
public bool ConvertHtmlSymbolsToHtmlCodes
{
get
{
object savedState = this.ViewState["ConvertHtmlSymbolsToHtmlCodes"];
return (savedState == null) ? true : (bool) savedState;
}
set
{
ViewState["ConvertHtmlSymbolsToHtmlCodes"] = value;
}
}
/// <summary>
/// When the user switches from Html to Design mode this will alert the user to possible changes or additions made by MSHTML. Default false.
/// </summary>
[
CategoryAttribute("Behavior")
]
public bool AlertClientToChangesInDesignMode
{
get
{
object savedState = this.ViewState["AlertClientToChangesInDesignMode"];
return (savedState == null) ? false : (bool) savedState;
}
set
{
ViewState["AlertClientToChangesInDesignMode"] = value;
}
}
/// <summary>
/// Will insert curly quotes (using HTML codes “ and ”) in place of normal quotes. Default true.
/// </summary>
[
CategoryAttribute("Behavior")
]
public bool EnableCurlyQuotes
{
get
{
object savedState = this.ViewState["EnableCurlyQuotes"];
return (savedState == null) ? true : (bool) savedState;
}
set
{
ViewState["EnableCurlyQuotes"] = value;
}
}
// Drop Down Data
/// <summary>
/// The title for the font drop down.
/// </summary>
[
CategoryAttribute("Toolbar Items")
]
public string FontFacesMenuTitle
{
get
{
object savedState = this.ViewState["FontFacesMenuTitle"];
return (savedState == null) ? "Font" : (string) savedState;
}
set
{
ViewState["FontFacesMenuTitle"] = value;
}
}
/// <summary>
/// A list of fonts for the font drop down.
/// </summary>
[
CategoryAttribute("Toolbar Items")
]
public string[] FontFacesMenuList
{
get
{
object savedState = this.ViewState["FontFacesMenuList"];
return (savedState == null) ?
new string[] {"Arial","Courier New","Garamond","Georgia","Tahoma","Times New Roman","Verdana"} :
(string[]) savedState;
}
set
{
ViewState["FontFacesMenuList"] = value;
}
}
/// <summary>
/// The title for the font sizes drop down.
/// </summary>
[
CategoryAttribute("Toolbar Items")
]
public string FontSizesMenuTitle
{
get
{
object savedState = this.ViewState["FontSizesMenuTitle"];
return (savedState == null) ? "Size" : (string) savedState;
}
set
{
ViewState["FontSizesMenuTitle"] = value;
}
}
/// <summary>
/// A list of fonts sizes the font sizes drop down.
/// </summary>
[
CategoryAttribute("Toolbar Items")
]
public string[] FontSizesMenuList
{
get
{
object savedState = this.ViewState["FontSizesMenuList"];
return (savedState == null) ?
new string[] {"1","2","3","4","5","6"} :
(string[]) savedState;
}
set
{
ViewState["FontSizesMenuList"] = value;
}
}
/// <summary>
/// The title for the font fore colors drop down.
/// </summary>
[
CategoryAttribute("Toolbar Items")
]
public string FontForeColorsMenuTitle
{
get
{
object savedState = this.ViewState["FontForeColorsMenuTitle"];
return (savedState == null) ? "Color" : (string) savedState;
}
set
{
ViewState["FontForeColorsMenuTitle"] = value;
}
}
/// <summary>
/// A list of colors for the font fore colors drop down.
/// </summary>
[
CategoryAttribute("Toolbar Items")
]
public Color[] FontForeColorsMenuList
{
get
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -