using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web.UI;
using CMS.CMSHelper;
using CMS.GlobalHelper;
using CMS.PortalControls;
using CMS.PortalEngine;
using CMS.SettingsProvider;
using CMS.SiteProvider;
using CMS.DocumentEngine;
using CMS.URLRewritingEngine;
public partial class CMSWebParts_Localization_languageselectiondropdown : CMSAbstractLanguageWebPart
{
#region "Public properties"
///
/// Gets or sets the value than indicates whether culture names are displayed.
///
public bool ShowCultureNames
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowCultureNames"), true);
}
set
{
SetValue("ShowCultureNames", value);
}
}
///
/// Gets or sets the value than indicates whether the control is shown.
///
public bool HideIfOneCulture
{
get
{
return ValidationHelper.GetBoolean(GetValue("HideIfOneCulture"), true);
}
set
{
SetValue("HideIfOneCulture", value);
}
}
#endregion
#region "Methods"
///
/// OnPreRender event handler.
///
/// Event argument
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
SetupControl();
}
///
/// Initializes the control properties.
///
protected void SetupControl()
{
if (StopProcessing)
{
// Do nothing
}
else
{
// If there is only one culture on site and hiding is enabled hide webpart
if (HideIfOneCulture && !CultureInfoProvider.IsSiteMultilignual(CMSContext.CurrentSiteName))
{
Visible = false;
return;
}
// Get list of cultures
List cultures = GetCultures();
// Check whether exists more than one culture
if ((cultures != null) && ((cultures.Count > 1) || (HideCurrentCulture && (cultures.Count > 0))))
{
// Add CSS Stylesheet
CSSHelper.RegisterCSSLink(Page, URLHelper.ResolveUrl("~/CMSWebparts/Localization/languageselectiondropdown_files/langselector.css"));
string imgFlagIcon = String.Empty;
StringBuilder result = new StringBuilder();
result.Append("");
// Set first item to the current language
CultureInfo ci = CultureInfoProvider.GetCultureInfo(CultureHelper.GetPreferredCulture());
if (ci != null)
{
// Drop down imitating icon
string dropIcon = ResolveUrl("~/CMSWebparts/Localization/languageselectiondropdown_files/dd_arrow.gif");
// Current language
imgFlagIcon = GetImageUrl("Flags/16x16/" + HTMLHelper.HTMLEncode(ci.CultureCode) + ".png");
string currentCultureShortName = String.Empty;
if (ShowCultureNames)
{
currentCultureShortName = HTMLHelper.HTMLEncode(ci.CultureShortName);
}
result.AppendFormat("- {3}",
dropIcon, imgFlagIcon, "#", currentCultureShortName);
}
result.Append("
");
// Loop thru all cultures
foreach (string[] data in cultures)
{
string url = data[0];
string code = data[1];
string name = HTMLHelper.HTMLEncode(data[2]);
// Language icon
imgFlagIcon = GetImageUrl("Flags/16x16/" + HTMLHelper.HTMLEncode(code) + ".png");
if (!ShowCultureNames)
{
name = string.Empty;
}
result.AppendFormat("- {2}
\r\n",
imgFlagIcon, HTMLHelper.HTMLEncode(URLHelper.ResolveUrl(url)), name);
}
result.Append("
");
ltlLanguages.Text = result.ToString();
}
else if (HideIfOneCulture)
{
Visible = false;
}
}
}
///
/// Reloads data for partial caching.
///
public override void ReloadData()
{
base.ReloadData();
SetupControl();
}
#endregion
}