Working language selection box in options side panel.

Added custom combo box with image support.
This commit is contained in:
Lorenz Cuno Klopfenstein 2011-03-24 02:31:22 +01:00
parent 6a71f22cc7
commit 3ad9a6eb11
9 changed files with 157 additions and 45 deletions

View file

@ -5,6 +5,9 @@ using System.Drawing;
using System.Windows.Forms;
namespace OnTopReplica {
/// <summary>
/// EventArgs structure for clicks on a cloned window.
/// </summary>
public class CloneClickEventArgs : EventArgs {
public Point ClientClickLocation { get; set; }

View file

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace OnTopReplica {
class ImageComboBox : ComboBox {
public ImageComboBox() {
DrawMode = DrawMode.OwnerDrawFixed;
}
protected override void OnDrawItem(DrawItemEventArgs ea) {
ea.DrawBackground();
ea.DrawFocusRectangle();
if (ea.Index == -1)
return;
Rectangle bounds = ea.Bounds;
var foreBrush = new SolidBrush(ea.ForeColor);
int textLeftBound = (IconList == null) ? bounds.Left : bounds.Left + IconList.ImageSize.Width;
var drawObject = Items[ea.Index];
if (drawObject is ImageComboBoxItem) {
var drawItem = (ImageComboBoxItem)drawObject;
if (drawItem.ImageListIndex != -1 && IconList != null) {
//ea.Graphics.FillRectangle(Brushes.Gray, bounds.Left, bounds.Top, IconList.ImageSize.Width, IconList.ImageSize.Height);
ea.Graphics.DrawImage(IconList.Images[drawItem.ImageListIndex], bounds.Left, bounds.Top);
}
ea.Graphics.DrawString(drawItem.Text, ea.Font, foreBrush, textLeftBound, bounds.Top);
}
else {
ea.Graphics.DrawString(drawObject.ToString(), ea.Font, foreBrush, textLeftBound, bounds.Top);
}
base.OnDrawItem(ea);
}
public ImageList IconList { get; set; }
}
class ImageComboBoxItem {
public ImageComboBoxItem() {
Text = "";
ImageListIndex = -1;
}
public ImageComboBoxItem(string text) {
if (text == null)
throw new ArgumentNullException();
Text = text;
ImageListIndex = -1;
}
public ImageComboBoxItem(string text, int imageListIndex) {
if (text == null)
throw new ArgumentNullException();
Text = text;
ImageListIndex = imageListIndex;
}
public string Text { get; private set; }
public int ImageListIndex { get; private set; }
public object Tag { get; set; }
}
}

View file

@ -69,7 +69,6 @@
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuContextClose = new System.Windows.Forms.ToolStripMenuItem();
this.fullSelectWindowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.danskToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuFullscreenContext = new System.Windows.Forms.ContextMenuStrip(this.components);
this.enableClickthroughToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.fullExitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -458,15 +457,6 @@
this.fullSelectWindowToolStripMenuItem.Text = global::OnTopReplica.Strings.MenuWindows;
this.fullSelectWindowToolStripMenuItem.ToolTipText = global::OnTopReplica.Strings.MenuWindowsTT;
//
// danskToolStripMenuItem
//
this.danskToolStripMenuItem.Image = global::OnTopReplica.Properties.Resources.flag_danish;
this.danskToolStripMenuItem.Name = "danskToolStripMenuItem";
this.danskToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.danskToolStripMenuItem.Tag = "da-DA";
this.danskToolStripMenuItem.Text = "Dansk";
this.danskToolStripMenuItem.Click += new System.EventHandler(this.Menu_Language_click);
//
// menuFullscreenContext
//
this.menuFullscreenContext.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -549,7 +539,6 @@
private System.Windows.Forms.ToolStripMenuItem quarterToolStripMenuItem1;
private System.Windows.Forms.ToolStripMenuItem fullscreenToolStripMenuItem1;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
private System.Windows.Forms.ToolStripMenuItem danskToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem chromeToolStripMenuItem;
private System.Windows.Forms.ContextMenuStrip menuFullscreenContext;
private System.Windows.Forms.ToolStripMenuItem fullSelectWindowToolStripMenuItem;

View file

@ -91,7 +91,7 @@ namespace OnTopReplica {
ClickThroughEnabled = false;
Opacity = 1.0;
//Restore main form in platform with dependent method
//Restore main form in a platform-dependent method
Program.Platform.RestoreForm(this);
}

View file

@ -188,21 +188,6 @@ namespace OnTopReplica {
IsChromeVisible = !IsChromeVisible;
}
private void Menu_Language_click(object sender, EventArgs e) {
//TODO: strip this stuff
ToolStripItem tsi = (ToolStripItem)sender;
string langCode = tsi.Tag as string;
MessageBox.Show("Should change to {0}", langCode);
//TODO
/*if (Program.ForceGlobalLanguageChange(langCode))
this.Close();
else
MessageBox.Show("Error");*/
}
private void Menu_Settings_click(object sender, EventArgs e) {
this.SetSidePanel(new OnTopReplica.SidePanels.OptionsPanel());
}

View file

@ -115,6 +115,9 @@
<Compile Include="EnumerableExtensions.cs" />
<Compile Include="ExtensionAttribute.cs" />
<Compile Include="GeometryExtensions.cs" />
<Compile Include="ImageComboBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="MainForm_Features.cs">
<SubType>Form</SubType>
</Compile>

View file

@ -10,6 +10,11 @@ namespace OnTopReplica {
struct Pair<T1, T2> {
public T1 Item1;
public T2 Item2;
public Pair(T1 value1, T2 value2) {
Item1 = value1;
Item2 = value2;
}
}
}

View file

@ -26,8 +26,8 @@
this.btnClose = new System.Windows.Forms.Button();
this.panelMain = new System.Windows.Forms.Panel();
this.groupLanguage = new System.Windows.Forms.GroupBox();
this.comboLanguage = new OnTopReplica.ImageComboBox();
this.lblLanguage = new System.Windows.Forms.Label();
this.comboLanguage = new System.Windows.Forms.ComboBox();
this.panelMain.SuspendLayout();
this.groupLanguage.SuspendLayout();
this.SuspendLayout();
@ -59,8 +59,8 @@
//
this.groupLanguage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupLanguage.Controls.Add(this.lblLanguage);
this.groupLanguage.Controls.Add(this.comboLanguage);
this.groupLanguage.Controls.Add(this.lblLanguage);
this.groupLanguage.Location = new System.Drawing.Point(3, 3);
this.groupLanguage.Name = "groupLanguage";
this.groupLanguage.Size = new System.Drawing.Size(254, 68);
@ -68,6 +68,18 @@
this.groupLanguage.TabStop = false;
this.groupLanguage.Text = "Language:";
//
// comboLanguage
//
this.comboLanguage.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.comboLanguage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboLanguage.FormattingEnabled = true;
this.comboLanguage.IconList = null;
this.comboLanguage.Location = new System.Drawing.Point(9, 19);
this.comboLanguage.Name = "comboLanguage";
this.comboLanguage.Size = new System.Drawing.Size(239, 21);
this.comboLanguage.TabIndex = 2;
this.comboLanguage.SelectedIndexChanged += new System.EventHandler(this.LanguageBox_IndexChange);
//
// lblLanguage
//
this.lblLanguage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
@ -78,21 +90,6 @@
this.lblLanguage.TabIndex = 1;
this.lblLanguage.Text = "Requires a restart.";
//
// comboLanguage
//
this.comboLanguage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.comboLanguage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboLanguage.FormattingEnabled = true;
this.comboLanguage.Items.AddRange(new object[] {
"English",
"Dansk",
"Italiano"});
this.comboLanguage.Location = new System.Drawing.Point(6, 19);
this.comboLanguage.Name = "comboLanguage";
this.comboLanguage.Size = new System.Drawing.Size(242, 21);
this.comboLanguage.TabIndex = 0;
//
// OptionsPanel
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -114,7 +111,7 @@
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Panel panelMain;
private System.Windows.Forms.GroupBox groupLanguage;
private System.Windows.Forms.ComboBox comboLanguage;
private System.Windows.Forms.Label lblLanguage;
private ImageComboBox comboLanguage;
}
}

View file

@ -5,11 +5,16 @@ using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using OnTopReplica.Properties;
using System.Globalization;
namespace OnTopReplica.SidePanels {
partial class OptionsPanel : SidePanel {
public OptionsPanel() {
InitializeComponent();
PopulateLanguageComboBox();
}
private void Close_click(object sender, EventArgs e) {
@ -21,5 +26,53 @@ namespace OnTopReplica.SidePanels {
return Strings.MenuSettings;
}
}
#region Language
Pair<CultureInfo, Image>[] _languageList = {
new Pair<CultureInfo, Image>(new CultureInfo("en-US"), Resources.flag_usa),
new Pair<CultureInfo, Image>(new CultureInfo("it-IT"), Resources.flag_ita),
new Pair<CultureInfo, Image>(new CultureInfo("cs-CZ"), Resources.flag_czech),
new Pair<CultureInfo, Image>(new CultureInfo("da-DK"), Resources.flag_danish),
new Pair<CultureInfo, Image>(new CultureInfo("es-ES"), Resources.flag_spanish),
};
private void PopulateLanguageComboBox() {
comboLanguage.Items.Clear();
var imageList = new ImageList() {
ImageSize = new Size(16, 16),
ColorDepth = ColorDepth.Depth32Bit
};
comboLanguage.IconList = imageList;
int selectedIndex = -1;
foreach (var langPair in _languageList) {
var item = new ImageComboBoxItem(langPair.Item1.NativeName, imageList.Images.Count) {
Tag = langPair.Item1
};
imageList.Images.Add(langPair.Item2);
comboLanguage.Items.Add(item);
if (langPair.Item1.Equals(CultureInfo.CurrentUICulture) ||
(CultureInfo.CurrentUICulture.Equals(CultureInfo.InvariantCulture) && langPair.Item1.TwoLetterISOLanguageName.Equals("en"))) {
selectedIndex = comboLanguage.Items.Count - 1;
}
}
comboLanguage.SelectedIndex = selectedIndex;
}
private void LanguageBox_IndexChange(object sender, EventArgs e) {
var item = comboLanguage.SelectedItem as ImageComboBoxItem;
if (item == null)
return;
Settings.Default.Language = item.Tag as CultureInfo;
}
#endregion
}
}