using System;

using System.Web;

using System.Text;

using System.Web.UI;

using System.Web.UI.Design;

using System.Drawing;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Collections.Specialized;

using System.ComponentModel;

 

namespace eSynapsEditor

{

/// <summary>

/// This is a WYSWYG Text box editor.

/// </summary>

///

[Designer(typeof(eSynapsEditor.Design.eSynapsTextBoxDesigner))]

[ToolboxData("<{0}:eSynapsTextBox runat='server' Height='100' Width='100' ></{0}:eSynapsTextBox>")]

public class eSynapsTextBox : System.Web.UI.Control, INamingContainer, IPostBackDataHandler

{

private PlaceHolder ph = new PlaceHolder();

private string _text2html ="";

public string Text2Html

{

get

{

return _text2html;

}

}

 

//This is to set the display HTML

public string Html2Display

{

get

{

string _text = (string) ViewState["_Html2Display"];

if(_text == null)

_text = "";

return _text;

}

set

{

ViewState["_Html2Display"] = value;

}

}

 

 

//Decide the width of the control

public Unit Width

{

get

{

if(ViewState["_Width"] == null)

{

return 100;

}

else

{

return (Unit) ViewState["_Width"];

}

}

set

{

ViewState["_Width"] = value;

}

}

//Decide the width of the control

public Unit Height

{

get

{

if(ViewState["_Height"] == null)

{

return 100;

}

else

{

return (Unit) ViewState["_Height"];

}

}

set

{

ViewState["_Height"] = value;

}

}

 

//End of properties

public eSynapsTextBox()

{

}

#region CreateChildControls

protected override void CreateChildControls()

{

Table t = new Table();

TableRow tr = new TableRow();

TableCell tc = new TableCell();

//Create a table

t.Width= this.Width;

t.Height = this.Height;

t.CellPadding = 2;

t.CellSpacing = 2;

t.BorderWidth = 2;

t.BorderColor = Color.Transparent;

t.Attributes.Add("Align", "left");

t.Attributes.Add("Valign", "top");

tr.Width = Unit.Percentage(100);

tr.Height = Unit.Pixel(5);

tr.HorizontalAlign = HorizontalAlign.Center;

//Add a table entry with Bold link

tc.Attributes.Add("align", "center");

tc.Width = Unit.Pixel(10);

tc.Attributes.Add("align", "center");

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(PrepareLinkControl("images/circle_b.gif", "Bold", "Bold"));

tr.Cells.Add(tc);

//Add the Italic link

tc = new TableCell();

tc.Width = Unit.Pixel(10);

tc.Attributes.Add("align", "center");

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(PrepareLinkControl("images/circle_i.gif", "Italic", "Italic"));

tr.Cells.Add(tc);

//Add the Underline link

tc = new TableCell();

tc.Width = Unit.Pixel(10);

tc.Attributes.Add("align", "center");

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(PrepareLinkControl("images/circle_ul.gif", "underline", "Underline"));

tr.Cells.Add(tc);

 

//Add the createlink Link

tc = new TableCell();

tc.Width = Unit.Pixel(10);

tc.Attributes.Add("align", "center");

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(PrepareLinkControl("images/circle_u.gif", "createlink", "URL"));

tr.Cells.Add(tc);

//Add the Numbered List Link

tc = new TableCell();

tc.Width = Unit.Pixel(10);

tc.Attributes.Add("align", "center");

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(PrepareLinkControl("images/circle_1.gif", "insertorderedlist", "Number"));

tr.Cells.Add(tc);

//Add the Bullet List Link

tc = new TableCell();

tc.Width = Unit.Pixel(10);

tc.Attributes.Add("align", "center");

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(PrepareLinkControl("images/circle_bu.gif", "insertunorderedlist", "Bullet"));

tr.Cells.Add(tc);

 

//Add the Size

tc = new TableCell();

tc.Attributes.Add("align", "center");

tc.Controls.Add(PrepareDropDownList("Font Name", "FontName", "Arial, Tahoma, Verdana, Courier New,Times New Roman".Split(new Char[] {','})));

tr.Cells.Add(tc);

 

//Add the Font

tc = new TableCell();

tc.Attributes.Add("align", "center");

tc.Controls.Add(PrepareDropDownList("", "FontSize", "1, 2, 3, 4, 5, 6".Split(new Char[] {','})));

tr.Cells.Add(tc);

//Add the Font Color

tc = new TableCell();

tc.Attributes.Add("align", "center");

tc.Controls.Add(PrepareDropDownList("Font Color", "ForeColor", new string[]{"Black", "Blue", "Green", "Orange", "Red"}));

tr.Cells.Add(tc);

//Add the row to the table

tr.BackColor = System.Drawing.Color.LightGray;

t.Rows.Add(tr);

//Add the HTML Generic Control to the table

tr = new TableRow();

tc = new TableCell();

tr.Height = Unit.Percentage(98);

tr.Width = Unit.Percentage(100);

tc.Attributes.Add("Colspan", "9");

HtmlGenericControl hg = new HtmlGenericControl();

hg.TagName = "iframe";

hg.ID = base.ClientID + "_eSynaps_TB";

hg.Attributes.Add("width", "100%");

hg.Attributes.Add("Height", "100%");

tc.Controls.Add(hg);

tc.Width = Unit.Percentage(100);

tr.Cells.Add(tc);

t.Rows.Add(tr);

//Add Input Hidden Field

tr = new TableRow();

tc = new TableCell();

tc.Attributes.Add("Colspan", "9");

hg = new HtmlGenericControl();

hg.TagName = "input";

hg.ID = base.ClientID;

hg.Attributes.Add("name", base.ClientID);

hg.Attributes.Add("type", "hidden");

hg.Attributes.Add("EnableViewState", EnableViewState.ToString());

if (Html2Display.Length > 0)

hg.Attributes.Add("value", Html2Display);

tc.Controls.Add(hg);

tc.Width = Unit.Percentage(100);

tr.Cells.Add(tc);

t.Rows.Add(tr);

ph.Controls.Add(t);

}

#endregion

public virtual void RaisePostDataChangedEvent()

{

}

protected override void Render(HtmlTextWriter output)

{

Table t = new Table();

TableRow tr = new TableRow();

TableCell tc = new TableCell();

t.Width = this.Width;

t.Height = this.Height;

tr.Width = Unit.Percentage(100);

tc.Controls.Add(ph);

tr.Controls.Add(tc);

t.Controls.Add(tr);

t.RenderControl(output);

}

 

#region Prepare Inline Controls

private System.Web.UI.Control PrepareLinkControl(string ImgName, string Command, string ToolTip)

{

System.Web.UI.WebControls.Image ib = new System.Web.UI.WebControls.Image();

StringBuilder sb = new StringBuilder();

sb.Append("ExecThisCmd");

sb.Append(base.ClientID);

sb.Append("(\'" + Command + "\',null)");

ib.ToolTip = ToolTip;

ib.Attributes.Add("unselectable", "on");

ib.Attributes.Add("OnClick", sb.ToString());

ib.BorderWidth =0;

ib.ImageUrl =ImgName;

return ib;

}

private System.Web.UI.Control PrepareDropDownList(string Name, string Command, string[] ItemArray)

{

DropDownList dl = new DropDownList();

dl.Attributes.Add("onchange", String.Concat(new string[]{"ExecThisCmd", base.ClientID, "(\'", Command, "\',this[this.selectedIndex].value);"}));

dl.Items.Add(new ListItem("- " + Name + " -", ""));

for (int i = 0; i < (int)ItemArray.Length; i++)

{

string str3;

string str2 = ItemArray[i];

if (i < (int)ItemArray.Length)

{

str3 = ItemArray[i];

}

else

{

str3 = str2;

}

ListItem listItem2 = new ListItem(str3, str2);

dl.Items.Add(listItem2);

}

return dl;

}

#endregion

 

public virtual bool LoadPostData(string postDataKey, NameValueCollection values)

{

string tempString = values[base.ClientID];

if (tempString == null)

{

this._text2html = "";

}

else

{

this._text2html = tempString;

if (this.EnableViewState)

this.Html2Display = tempString;

}

return false;

}

#region Pre Render Stuff

protected override void OnPreRender(EventArgs e)

{

StringBuilder sb = new StringBuilder();

if (!base.Visible)

{

return;

}

base.Page.RegisterRequiresPostBack(this);

base.Page.RegisterOnSubmitStatement(String.Concat("PostIt", base.ClientID), String.Concat("PostIt", base.ClientID, "();"));

sb.Append("<script language=\"JavaScript\" type=\"text/javascript\">\n");

sb.Append(PrepareBrowserMsgJs());

sb.Append("</script>\n");

base.Page.RegisterStartupScript("eSynapsTextBoxOnLoad", sb.ToString());

}

private string PreparePostItJs()

{

StringBuilder stringBuilder = new StringBuilder();

stringBuilder.Append("\nfunction PostIt" + base.ClientID + "()\n");

stringBuilder.Append("{\n");

stringBuilder.Append("document.getElementById('" + base.ClientID + "').value = ");

stringBuilder.Append( base.ClientID + "_eSynaps_TB.document.body.innerHTML;\n");

stringBuilder.Append("}");

return stringBuilder.ToString();

}

private string PrepareCmdExecJs()

{

StringBuilder stringBuilder = new StringBuilder();

stringBuilder.Append("\nfunction ExecThisCmd" + base.ClientID + "(command, arg)\n");

stringBuilder.Append("{\n");

stringBuilder.Append("if (arg == null)\n");

stringBuilder.Append("{");

stringBuilder.Append(base.ClientID + "_eSynaps_TB.document.execCommand(command);\n");

stringBuilder.Append("}");

stringBuilder.Append("else");

stringBuilder.Append("{");

stringBuilder.Append(base.ClientID + "_eSynaps_TB.document.execCommand(command, \'\', arg);\n");

stringBuilder.Append("}");

stringBuilder.Append(base.ClientID + "_eSynaps_TB.focus();\n}\n");

stringBuilder.Append("\n");

return stringBuilder.ToString();

}

 

private string PrepareBrowserMsgJs()

{

HttpBrowserCapabilities hbc = HttpContext.Current.Request.Browser;

StringBuilder sb = new StringBuilder();

if ((hbc.MajorVersion < 5) || (hbc.Browser != "IE") || ((hbc.Platform != "Win95" && hbc.Platform != "Win98" && hbc.Platform != "WinNT")))

{

sb.Append("\n");

sb.Append("alert('You cannot use this HTML Editor due to one of the following reasons: \\n 1. Your browser is not Microsoft Internet Explorer \\n 2. Your operating system is not windows based (such as Windows 98) \\n 3. You do not have Windows 98 or later version on your system \\n 4. You have Internet Explorer with version earlier than 5.X \\n Sorry for the inconvenience!')");

sb.Append("\n");

ph.Visible = false;

}

else

{

sb.Append(base.ClientID + "_eSynaps_TB.document.designMode = \"On\";\n");

sb.Append("if (document.getElementById('" + base.ClientID + "').value.length > 0)\n");

sb.Append("{\n" + base.ClientID + "_eSynaps_TB.document.open()\n");

sb.Append("\n" + base.ClientID + "_eSynaps_TB.document.write(document.getElementById('" + base.ClientID + "').value)\n");

sb.Append("\n" + base.ClientID + "_eSynaps_TB.document.close()\n");

sb.Append("}\n");

sb.Append(base.ClientID + "_eSynaps_TB.document.focus();\n");

sb.Append(PrepareCmdExecJs());

sb.Append(PreparePostItJs());

}

return sb.ToString();

}

#endregion

 

}

}

namespace eSynapsEditor.Design

{

public class eSynapsTextBoxDesigner : ControlDesigner

{

public eSynapsTextBoxDesigner()

{

}

protected override string GetEmptyDesignTimeHtml()

{

return this.GetEmptyDesignTimeHtml();

}

}

}

using System;

using System.Web;

using System.Text;

using System.Web.UI;

using System.Web.UI.Design;

using System.Drawing;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

using System.Collections.Specialized;

using System.ComponentModel;

 

namespace eSynapsEditor

{

/// <summary>

/// This is a WYSWYG Text box editor.

/// </summary>

///

[Designer(typeof(eSynapsEditor.Design.eSynapsTextBoxDesigner))]

[ToolboxData("<{0}:eSynapsTextBox runat='server' Height='100' Width='100' ></{0}:eSynapsTextBox>")]

public class eSynapsTextBox : System.Web.UI.Control, INamingContainer, IPostBackDataHandler

{

private PlaceHolder ph = new PlaceHolder();

private string _text2html ="";

public string Text2Html

{

get

{

return _text2html;

}

}

 

//This is to set the display HTML

public string Html2Display

{

get

{

string _text = (string) ViewState["_Html2Display"];

if(_text == null)

_text = "";

return _text;

}

set

{

ViewState["_Html2Display"] = value;

}

}

 

 

//Decide the width of the control

public Unit Width

{

get

{

if(ViewState["_Width"] == null)

{

return 100;

}

else

{

return (Unit) ViewState["_Width"];

}

}

set

{

ViewState["_Width"] = value;

}

}

//Decide the width of the control

public Unit Height

{

get

{

if(ViewState["_Height"] == null)

{

return 100;

}

else

{

return (Unit) ViewState["_Height"];

}

}

set

{

ViewState["_Height"] = value;

}

}

 

//End of properties

public eSynapsTextBox()

{

}

#region CreateChildControls

protected override void CreateChildControls()

{

Table t = new Table();

TableRow tr = new TableRow();

TableCell tc = new TableCell();

//Create a table

t.Width= this.Width;

t.Height = this.Height;

t.CellPadding = 2;

t.CellSpacing = 2;

t.BorderWidth = 2;

t.BorderColor = Color.Transparent;

t.Attributes.Add("Align", "left");

t.Attributes.Add("Valign", "top");

tr.Width = Unit.Percentage(100);

tr.Height = Unit.Pixel(5);

tr.HorizontalAlign = HorizontalAlign.Center;

//Add a table entry with Bold link

tc.Attributes.Add("align", "center");

tc.Width = Unit.Pixel(10);

tc.Attributes.Add("align", "center");

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(PrepareLinkControl("images/circle_b.gif", "Bold", "Bold"));

tr.Cells.Add(tc);

//Add the Italic link

tc = new TableCell();

tc.Width = Unit.Pixel(10);

tc.Attributes.Add("align", "center");

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(PrepareLinkControl("images/circle_i.gif", "Italic", "Italic"));

tr.Cells.Add(tc);

//Add the Underline link

tc = new TableCell();

tc.Width = Unit.Pixel(10);

tc.Attributes.Add("align", "center");

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(PrepareLinkControl("images/circle_ul.gif", "underline", "Underline"));

tr.Cells.Add(tc);

 

//Add the createlink Link

tc = new TableCell();

tc.Width = Unit.Pixel(10);

tc.Attributes.Add("align", "center");

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(PrepareLinkControl("images/circle_u.gif", "createlink", "URL"));

tr.Cells.Add(tc);

//Add the Numbered List Link

tc = new TableCell();

tc.Width = Unit.Pixel(10);

tc.Attributes.Add("align", "center");

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(PrepareLinkControl("images/circle_1.gif", "insertorderedlist", "Number"));

tr.Cells.Add(tc);

//Add the Bullet List Link

tc = new TableCell();

tc.Width = Unit.Pixel(10);

tc.Attributes.Add("align", "center");

tc.HorizontalAlign = HorizontalAlign.Center;

tc.Controls.Add(PrepareLinkControl("images/circle_bu.gif", "insertunorderedlist", "Bullet"));

tr.Cells.Add(tc);

 

//Add the Size

tc = new TableCell();

tc.Attributes.Add("align", "center");

tc.Controls.Add(PrepareDropDownList("Font Name", "FontName", "Arial, Tahoma, Verdana, Courier New,Times New Roman".Split(new Char[] {','})));

tr.Cells.Add(tc);

 

//Add the Font

tc = new TableCell();

tc.Attributes.Add("align", "center");

tc.Controls.Add(PrepareDropDownList("", "FontSize", "1, 2, 3, 4, 5, 6".Split(new Char[] {','})));

tr.Cells.Add(tc);

//Add the Font Color

tc = new TableCell();

tc.Attributes.Add("align", "center");

tc.Controls.Add(PrepareDropDownList("Font Color", "ForeColor", new string[]{"Black", "Blue", "Green", "Orange", "Red"}));

tr.Cells.Add(tc);

//Add the row to the table

tr.BackColor = System.Drawing.Color.LightGray;

t.Rows.Add(tr);

//Add the HTML Generic Control to the table

tr = new TableRow();

tc = new TableCell();

tr.Height = Unit.Percentage(98);

tr.Width = Unit.Percentage(100);

tc.Attributes.Add("Colspan", "9");

HtmlGenericControl hg = new HtmlGenericControl();

hg.TagName = "iframe";

hg.ID = base.ClientID + "_eSynaps_TB";

hg.Attributes.Add("width", "100%");

hg.Attributes.Add("Height", "100%");

tc.Controls.Add(hg);

tc.Width = Unit.Percentage(100);

tr.Cells.Add(tc);

t.Rows.Add(tr);

//Add Input Hidden Field

tr = new TableRow();

tc = new TableCell();

tc.Attributes.Add("Colspan", "9");

hg = new HtmlGenericControl();

hg.TagName = "input";

hg.ID = base.ClientID;

hg.Attributes.Add("name", base.ClientID);

hg.Attributes.Add("type", "hidden");

hg.Attributes.Add("EnableViewState", EnableViewState.ToString());

if (Html2Display.Length > 0)

hg.Attributes.Add("value", Html2Display);

tc.Controls.Add(hg);

tc.Width = Unit.Percentage(100);

tr.Cells.Add(tc);

t.Rows.Add(tr);

ph.Controls.Add(t);

}

#endregion

public virtual void RaisePostDataChangedEvent()

{

}

protected override void Render(HtmlTextWriter output)

{

Table t = new Table();

TableRow tr = new TableRow();

TableCell tc = new TableCell();

t.Width = this.Width;

t.Height = this.Height;

tr.Width = Unit.Percentage(100);

tc.Controls.Add(ph);

tr.Controls.Add(tc);

t.Controls.Add(tr);

t.RenderControl(output);

}

 

#region Prepare Inline Controls

private System.Web.UI.Control PrepareLinkControl(string ImgName, string Command, string ToolTip)

{

System.Web.UI.WebControls.Image ib = new System.Web.UI.WebControls.Image();

StringBuilder sb = new StringBuilder();

sb.Append("ExecThisCmd");

sb.Append(base.ClientID);

sb.Append("(\'" + Command + "\',null)");

ib.ToolTip = ToolTip;

ib.Attributes.Add("unselectable", "on");

ib.Attributes.Add("OnClick", sb.ToString());

ib.BorderWidth =0;

ib.ImageUrl =ImgName;

return ib;

}

private System.Web.UI.Control PrepareDropDownList(string Name, string Command, string[] ItemArray)

{

DropDownList dl = new DropDownList();

dl.Attributes.Add("onchange", String.Concat(new string[]{"ExecThisCmd", base.ClientID, "(\'", Command, "\',this[this.selectedIndex].value);"}));

dl.Items.Add(new ListItem("- " + Name + " -", ""));

for (int i = 0; i < (int)ItemArray.Length; i++)

{

string str3;

string str2 = ItemArray[i];

if (i < (int)ItemArray.Length)

{

str3 = ItemArray[i];

}

else

{

str3 = str2;

}

ListItem listItem2 = new ListItem(str3, str2);

dl.Items.Add(listItem2);

}

return dl;

}

#endregion

 

public virtual bool LoadPostData(string postDataKey, NameValueCollection values)

{

string tempString = values[base.ClientID];

if (tempString == null)

{

this._text2html = "";

}

else

{

this._text2html = tempString;

if (this.EnableViewState)

this.Html2Display = tempString;

}

return false;

}

#region Pre Render Stuff

protected override void OnPreRender(EventArgs e)

{

StringBuilder sb = new StringBuilder();

if (!base.Visible)

{

return;

}

base.Page.RegisterRequiresPostBack(this);

base.Page.RegisterOnSubmitStatement(String.Concat("PostIt", base.ClientID), String.Concat("PostIt", base.ClientID, "();"));

sb.Append("<script language=\"JavaScript\" type=\"text/javascript\">\n");

sb.Append(PrepareBrowserMsgJs());

sb.Append("</script>\n");

base.Page.RegisterStartupScript("eSynapsTextBoxOnLoad", sb.ToString());

}

private string PreparePostItJs()

{

StringBuilder stringBuilder = new StringBuilder();

stringBuilder.Append("\nfunction PostIt" + base.ClientID + "()\n");

stringBuilder.Append("{\n");

stringBuilder.Append("document.getElementById('" + base.ClientID + "').value = ");

stringBuilder.Append( base.ClientID + "_eSynaps_TB.document.body.innerHTML;\n");

stringBuilder.Append("}");

return stringBuilder.ToString();

}

private string PrepareCmdExecJs()

{

StringBuilder stringBuilder = new StringBuilder();

stringBuilder.Append("\nfunction ExecThisCmd" + base.ClientID + "(command, arg)\n");

stringBuilder.Append("{\n");

stringBuilder.Append("if (arg == null)\n");

stringBuilder.Append("{");

stringBuilder.Append(base.ClientID + "_eSynaps_TB.document.execCommand(command);\n");

stringBuilder.Append("}");

stringBuilder.Append("else");

stringBuilder.Append("{");

stringBuilder.Append(base.ClientID + "_eSynaps_TB.document.execCommand(command, \'\', arg);\n");

stringBuilder.Append("}");

stringBuilder.Append(base.ClientID + "_eSynaps_TB.focus();\n}\n");

stringBuilder.Append("\n");

return stringBuilder.ToString();

}

 

private string PrepareBrowserMsgJs()

{

HttpBrowserCapabilities hbc = HttpContext.Current.Request.Browser;

StringBuilder sb = new StringBuilder();

if ((hbc.MajorVersion < 5) || (hbc.Browser != "IE") || ((hbc.Platform != "Win95" && hbc.Platform != "Win98" && hbc.Platform != "WinNT")))

{

sb.Append("\n");

sb.Append("alert('You cannot use this HTML Editor due to one of the following reasons: \\n 1. Your browser is not Microsoft Internet Explorer \\n 2. Your operating system is not windows based (such as Windows 98) \\n 3. You do not have Windows 98 or later version on your system \\n 4. You have Internet Explorer with version earlier than 5.X \\n Sorry for the inconvenience!')");

sb.Append("\n");

ph.Visible = false;

}

else

{

sb.Append(base.ClientID + "_eSynaps_TB.document.designMode = \"On\";\n");

sb.Append("if (document.getElementById('" + base.ClientID + "').value.length > 0)\n");

sb.Append("{\n" + base.ClientID + "_eSynaps_TB.document.open()\n");

sb.Append("\n" + base.ClientID + "_eSynaps_TB.document.write(document.getElementById('" + base.ClientID + "').value)\n");

sb.Append("\n" + base.ClientID + "_eSynaps_TB.document.close()\n");

sb.Append("}\n");

sb.Append(base.ClientID + "_eSynaps_TB.document.focus();\n");

sb.Append(PrepareCmdExecJs());

sb.Append(PreparePostItJs());

}

return sb.ToString();

}

#endregion

 

}

}

namespace eSynapsEditor.Design

{

public class eSynapsTextBoxDesigner : ControlDesigner

{

public eSynapsTextBoxDesigner()

{

}

protected override string GetEmptyDesignTimeHtml()

{

return this.GetEmptyDesignTimeHtml();

}

}

}