FreeTextBoxAdapter.cs :  » Bloggers » dasBlog » newtelligence » DasBlog » Web » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » dasBlog 
dasBlog » newtelligence » DasBlog » Web » FreeTextBoxAdapter.cs
using System;
using System.Collections.Specialized;
using System.Globalization;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using newtelligence.DasBlog.Web;
using newtelligence.DasBlog.Web.Core;
using FreeTextBoxControls;

namespace newtelligence.DasBlog.Web{
  /// <summary>
  /// Converts the FreeTextBox control to the interface needed by dasBlog
  /// </summary>
  /// <remarks>
  /// Based on v3.0.5 of FreeTextBox http://www.freetextbox.com/
  /// </remarks>
  public class FreeTextBoxAdapter : EditControlAdapter
  {
    FreeTextBox freeTextBox;

    public FreeTextBoxAdapter()
    {
      freeTextBox = new FreeTextBox();
      freeTextBox.ID = "freeTextBox";
      freeTextBox.DesignModeCss = "ftb/designmode.css";
      freeTextBox.SupportFolder = "ftb/";
      freeTextBox.ToolbarLayout = "ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu|Bold,Italic,Underline,Strikethrough;Superscript,Subscript,RemoveFormat|JustifyLeft,JustifyRight,JustifyCenter,JustifyFull;BulletedList,NumberedList,Indent,Outdent;IeSpellCheck,CreateLink,Unlink,InsertImage,InsertImageFromGallery,InsertRule|Cut,Copy,Paste;Undo,Redo,Print";
      freeTextBox.ImageGalleryUrl = "ftb/ftb.imagegallery.aspx?rif={0}&amp;cif={0}";
      freeTextBox.RemoveServerNameFromUrls = false;
      freeTextBox.TextDirection = FreeTextBoxControls.TextDirection.LeftToRight;
      freeTextBox.ImageGalleryPath = SiteConfig.GetSiteConfig().BinariesDir;
    }

    public override Control Control { get { return freeTextBox; } }

    public override void Initialize()
    {
      base.Initialize ();
      if (this.freeTextBox.Visible && this.freeTextBox.EnableHtmlMode)
      {
        Toolbar myToolbar = new Toolbar();

        ToolbarButton myButton = new ToolbarButton("Insert Code", "insertCode", "csharp");

        string insertCodeCallback = @"<script type=""text/javascript"">
var ftbReference;
function setFtbReference(ftbRef){
  this.ftbReference = ftbRef;
}

function addTextToPost(html){
  ftbReference.InsertHtml(html);
}
</script>";
        this.Control.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"insertCodeCallback", insertCodeCallback);

        string scriptBlock = "var codescript = '" + this.freeTextBox.SupportFolder + @"ftb.insertcode.aspx';
if (FTB_Browser.isIE){
  code = showModalDialog(codescript,window,'dialogWidth:400px; dialogHeight:500px;help:0;status:0;resizeable:1;');
  if (code != null) {
    this.ftb.InsertHtml(code);
  }
} else {
  setFtbReference(this.ftb);
  window.open(codescript, 'insertcode', 'width=550,height=500,resizable=yes,scrollbars=yes,status=no,modal=yes,dependent=yes,dialog=yes');
}
";
        myButton.ScriptBlock = scriptBlock;
        myToolbar.Items.Add(myButton);
        this.freeTextBox.Toolbars.Add(myToolbar);
      }
    }


    public override string Text
    {
      get  { return freeTextBox.Text; }
      set { freeTextBox.Text = value; }
    }

    public override bool HasText()
    {
      return (freeTextBox.Text.Trim().Length > 0 && freeTextBox.Text.Trim() != "<p>\r\n\t\t</p>");
    }

    public override Unit Width
    {
      get { return freeTextBox.Width; }
      set { freeTextBox.Width = value; }
    }

    public override Unit Height
    {
      get { return freeTextBox.Height; }
      set { freeTextBox.Height = value; }
    }


    public override void SetLanguage(string language)
    {
      freeTextBox.Language = ConvertToSupportedLanguage(language);
    }

    public override void SetTextDirection(SharedBasePage.TextDirection textDirection)
    {
      if (textDirection == SharedBasePage.TextDirection.RightToLeft) 
      {
        freeTextBox.TextDirection = FreeTextBoxControls.TextDirection.RightToLeft;
      }
      else // default to LTR
      {
        freeTextBox.TextDirection = FreeTextBoxControls.TextDirection.LeftToRight;
      }
    }


    // could be a performance issue, but the editor is only used during editing 
    // so we should be ok, in the 90% case.
    // If it becomes an issue we should cache the supported cultures.
    private static string ConvertToSupportedLanguage(string language ){

      if( language == null ){
        return "en-US";
      }

      FreeTextBoxControls.Support.ResourceManager rm = new FreeTextBoxControls.Support.ResourceManager();
      NameValueCollection coll = rm.GetSupportedLanguages();

      string[]  cultures = new string[coll.Count];

      coll.CopyTo(cultures,0);

      int index = Array.IndexOf( cultures, language );

      if( index > -1){
        return language;
      }

      // convert to a CultureInfo object, so we can find the fall back culture
      CultureInfo reqCulture;
      try{
        reqCulture = new CultureInfo( language ); 
      }catch(Exception){
        return "en-US";
      }

      CultureInfo parent = (!reqCulture.IsNeutralCulture? reqCulture.Parent: reqCulture);
      
      foreach( string s in cultures ){
        CultureInfo current = new CultureInfo(s).Parent;

        // same parent should be good enough
        if( parent.Equals(current) ){
          return s;
        }
      }
      
      // if we don't support your language, we return en-us
      return "en-US";
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.