// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-// Copyright (c) 2004 Novell, Inc. (http://www.novell.com)
+// Copyright (c) 2006, Alexander Olk
//
// Authors:
-// Alexander Olk xenomorph2@onlinehome.de
+// Alexander Olk alex.olk@googlemail.com
//
//
private ColorComboBox colorComboBox;
- private FontFamily[] fontFamilies;
-
private string currentFontName;
private float currentSize;
#region Public Constructors
public FontDialog( )
{
+ form = new DialogForm (this);
example_panel_text = char_sets [0];
okButton = new Button( );
examplePanel.BorderStyle = BorderStyle.Fixed3D;
form.AcceptButton = okButton;
+ form.CancelButton = cancelButton;
form.Controls.Add( scriptComboBox );
form.Controls.Add( scriptLabel );
form.ResumeLayout( false );
- fontFamilies = FontFamily.Families;
-
- fontListBox.BeginUpdate( );
- foreach ( FontFamily ff in fontFamilies )
- {
- if ( !fontHash.ContainsKey (ff.Name) ) {
- fontListBox.Items.Add( ff.Name );
- fontHash.Add( ff.Name, ff );
- }
- }
- fontListBox.EndUpdate( );
-
- CreateFontSizeListBoxItems ();
-
scriptComboBox.BeginUpdate ();
scriptComboBox.Items.AddRange (char_sets_names);
scriptComboBox.SelectedIndex = 0;
fontstyleTextBox.MouseWheel += new MouseEventHandler (OnFontStyleTextBoxMouseWheel);
fontsizeTextBox.MouseWheel += new MouseEventHandler (OnFontSizeTextBoxMouseWheel);
- Font = form.Font;
+ PopulateFontList ();
}
#endregion // Public Constructors
font = new Font(value, value.Style);
currentFontStyle = font.Style;
- currentSize = font.Size;
+ currentSize = font.SizeInPoints;
currentFontName = font.Name;
+ strikethroughCheckBox.Checked = font.Strikeout;
+ underlinedCheckBox.Checked = font.Underline;
+
int index = fontListBox.FindString (currentFontName);
if (index != -1) {
fontListBox.SelectedIndex = 0;
}
+ UpdateFontSizeListBox ();
+ UpdateFontStyleListBox ();
+
fontListBox.TopIndex = fontListBox.SelectedIndex;
}
}
fontMustExist = value;
}
}
-
+
+ [DefaultValue ("Color [Black]")]
public Color Color
{
set {
public bool FixedPitchOnly
{
set {
- fixedPitchOnly = value;
+ if (fixedPitchOnly != value) {
+ fixedPitchOnly = value;
+ PopulateFontList ();
+ }
}
get {
return base.HookProc (hWnd, msg, wparam, lparam);
}
- protected override bool RunDialog( IntPtr hwndOwner )
+ protected override bool RunDialog( IntPtr hWndOwner )
{
form.Refresh();
void OnFontTextBoxKeyDown (object sender, KeyEventArgs e)
{
- if (e.KeyCode == Keys.Up) {
- int sel_index = fontListBox.SelectedIndex;
-
- sel_index--;
-
- if (sel_index < 0)
- sel_index = 0;
-
- fontListBox.SelectedIndex = sel_index;
- } else if (e.KeyCode == Keys.Down) {
- int sel_index = fontListBox.SelectedIndex;
-
- sel_index++;
-
- if (sel_index > fontListBox.Items.Count - 1)
- sel_index = fontListBox.Items.Count - 1;
-
- fontListBox.SelectedIndex = sel_index;
+ // Forward these keys on to the font style listbox
+ switch (e.KeyCode) {
+ case Keys.Up:
+ case Keys.Down:
+ case Keys.PageDown:
+ case Keys.PageUp:
+ fontListBox.HandleKeyDown (e.KeyCode);
+ break;
}
}
void OnFontStyleTextBoxKeyDown (object sender, KeyEventArgs e)
{
- if (e.KeyCode == Keys.Up) {
- int sel_index = fontstyleListBox.SelectedIndex;
-
- sel_index--;
-
- if (sel_index < 0)
- sel_index = 0;
-
- fontstyleListBox.SelectedIndex = sel_index;
- } else if (e.KeyCode == Keys.Down) {
- int sel_index = fontstyleListBox.SelectedIndex;
-
- sel_index++;
-
- if (sel_index > fontstyleListBox.Items.Count - 1)
- sel_index = fontstyleListBox.Items.Count - 1;
-
- fontstyleListBox.SelectedIndex = sel_index;
+ // Forward these keys on to the font style listbox
+ switch (e.KeyCode) {
+ case Keys.Up:
+ case Keys.Down:
+ case Keys.PageDown:
+ case Keys.PageUp:
+ fontstyleListBox.HandleKeyDown (e.KeyCode);
+ break;
}
}
void OnFontSizeTextBoxKeyDown (object sender, KeyEventArgs e)
{
- if (e.KeyCode == Keys.Up) {
- int sel_index = fontsizeListBox.SelectedIndex;
-
- sel_index--;
-
- if (sel_index < 0)
- sel_index = 0;
-
- fontsizeListBox.SelectedIndex = sel_index;
- } else if (e.KeyCode == Keys.Down) {
- int sel_index = fontsizeListBox.SelectedIndex;
-
- sel_index++;
-
- if (sel_index > fontsizeListBox.Items.Count - 1)
- sel_index = fontsizeListBox.Items.Count - 1;
-
- fontsizeListBox.SelectedIndex = sel_index;
+ // Forward these keys on to the font size listbox
+ switch (e.KeyCode) {
+ case Keys.Up:
+ case Keys.Down:
+ case Keys.PageDown:
+ case Keys.PageUp:
+ fontsizeListBox.HandleKeyDown (e.KeyCode);
+ break;
}
}
internal_textbox_change = false;
- for (int i = 0; i < fontListBox.Items.Count; i++) {
- string name = fontListBox.Items [i] as string;
-
- if (name.StartsWith(fontTextBox.Text)) {
- if (name == fontTextBox.Text)
- fontListBox.SelectedIndex = i;
- else
- fontListBox.TopIndex = i;
-
- break;
- }
+ string search = fontTextBox.Text;
+
+ // Look for an exact match
+ int found = fontListBox.FindStringExact (search);
+
+ if (found != ListBox.NoMatches) {
+ fontListBox.SelectedIndex = found;
+ return;
+ }
+
+ // Look for a partial match
+ found = fontListBox.FindString (search);
+
+ if (found != ListBox.NoMatches) {
+ fontListBox.TopIndex = found;
+ return;
}
+
+ // No match, scroll to the top
+ if (fontListBox.Items.Count > 0)
+ fontListBox.TopIndex = 0;
}
void OnFontStyleTextTextChanged (object sender, EventArgs e)
return;
internal_textbox_change = false;
-
- for (int i = 0; i < fontstyleListBox.Items.Count; i++) {
- string name = fontstyleListBox.Items [i] as string;
-
- if (name.StartsWith(fontstyleTextBox.Text)) {
- if (name == fontstyleTextBox.Text)
- fontstyleListBox.SelectedIndex = i;
-
- break;
- }
- }
+
+ // Look for an exact match
+ int found = fontstyleListBox.FindStringExact (fontstyleTextBox.Text);
+
+ if (found != ListBox.NoMatches)
+ fontstyleListBox.SelectedIndex = found;
}
void OnFontSizeTextBoxTextChanged (object sender, EventArgs e)
void UpdateFontSizeListBox ()
{
- int index = fontsizeListBox.FindString(currentSize.ToString());
+ int index = fontsizeListBox.FindString(((int)Math.Round ((currentSize))).ToString());
if (index != -1)
fontsizeListBox.SelectedIndex = index;
to_select = index;
}
- if (fontstyleListBox.Items.Count > 0)
+ if (fontstyleListBox.Items.Count > 0) {
fontstyleListBox.SelectedIndex = to_select;
+
+ switch ((string)fontstyleListBox.SelectedItem) {
+ case "Regular":
+ currentFontStyle = FontStyle.Regular;
+ break;
+ case "Bold":
+ currentFontStyle = FontStyle.Bold;
+ break;
+ case "Italic":
+ currentFontStyle = FontStyle.Italic;
+ break;
+ case "Bold Italic":
+ currentFontStyle = FontStyle.Bold | FontStyle.Italic;
+ break;
+ }
+
+ if (strikethroughCheckBox.Checked)
+ currentFontStyle |= FontStyle.Strikeout;
+ if (underlinedCheckBox.Checked)
+ currentFontStyle |= FontStyle.Underline;
+ }
fontstyleListBox.EndUpdate( );
}
{
fontsizeListBox.BeginUpdate ();
- fontsizeListBox.Items. Clear();
+ fontsizeListBox.Items.Clear();
if (minSize == 0 && maxSize == 0)
{
fontsizeListBox.EndUpdate ();
}
+
+ #region Private Methods
+ private void PopulateFontList ()
+ {
+ fontListBox.Items.Clear ();
+ fontHash.Clear ();
+
+ fontListBox.BeginUpdate ();
+
+ foreach (FontFamily ff in FontFamily.Families) {
+ if (!fontHash.ContainsKey (ff.Name)) {
+ if (!fixedPitchOnly || (IsFontFamilyFixedPitch (ff))) {
+ fontListBox.Items.Add (ff.Name);
+ fontHash.Add (ff.Name, ff);
+ }
+ }
+ }
+
+ fontListBox.EndUpdate ();
+ CreateFontSizeListBoxItems ();
+
+ if (fixedPitchOnly)
+ this.Font = new Font (FontFamily.GenericMonospace, 8.25f);
+ else
+ this.Font = form.Font;
+ }
+
+ private bool IsFontFamilyFixedPitch (FontFamily family)
+ {
+ FontStyle fs;
+
+ if (family.IsStyleAvailable (FontStyle.Regular))
+ fs = FontStyle.Regular;
+ else if (family.IsStyleAvailable (FontStyle.Bold))
+ fs = FontStyle.Bold;
+ else if (family.IsStyleAvailable (FontStyle.Italic))
+ fs = FontStyle.Italic;
+ else if (family.IsStyleAvailable (FontStyle.Strikeout))
+ fs = FontStyle.Strikeout;
+ else if (family.IsStyleAvailable (FontStyle.Underline))
+ fs = FontStyle.Underline;
+ else
+ return false;
+
+ Font f = new Font (family.Name, 10, fs);
+
+ if (TextRenderer.MeasureString ("i", f).Width == TextRenderer.MeasureString ("w", f).Width)
+ return true;
+
+ return false;
+ }
+ #endregion
internal class ColorComboBox : ComboBox
{
return name;
}
}
+
+ public override string ToString()
+ {
+ return this.Name;
+ }
}
private Color selectedColor;
DropDownStyle = ComboBoxStyle.DropDownList;
DrawMode = DrawMode.OwnerDrawFixed;
- Items.AddRange( new object[] {
- new ColorComboBoxItem( Color.Black, "Black" ),
- new ColorComboBoxItem( Color.DarkRed, "Dark-Red" ),
- new ColorComboBoxItem( Color.Green, "Green" ),
- new ColorComboBoxItem( Color.Olive, "Olive-Green" ), // color not correct
- new ColorComboBoxItem( Color.Aquamarine, "Aquamarine" ), // color not correct
- new ColorComboBoxItem( Color.Crimson, "Crimson" ),
- new ColorComboBoxItem( Color.Cyan, "Cyan" ),
- new ColorComboBoxItem( Color.Gray, "Gray" ),
- new ColorComboBoxItem( Color.Silver, "Silver" ),
- new ColorComboBoxItem( Color.Red, "Red" ),
- new ColorComboBoxItem( Color.YellowGreen, "Yellow-Green" ),
- new ColorComboBoxItem( Color.Yellow, "Yellow" ),
- new ColorComboBoxItem( Color.Blue, "Blue" ),
- new ColorComboBoxItem( Color.Purple, "Purple" ),
- new ColorComboBoxItem( Color.Aquamarine, "Aquamarine" ),
- new ColorComboBoxItem( Color.White, "White" ) }
- );
+ Items.AddRange (new object[] {
+ new ColorComboBoxItem (Color.Black, "Black"),
+ new ColorComboBoxItem (Color.Maroon, "Maroon"),
+ new ColorComboBoxItem (Color.Green, "Green"),
+ new ColorComboBoxItem (Color.Olive, "Olive"),
+ new ColorComboBoxItem (Color.Navy, "Navy"),
+ new ColorComboBoxItem (Color.Purple, "Purple"),
+ new ColorComboBoxItem (Color.Teal, "Teal"),
+ new ColorComboBoxItem (Color.Gray, "Gray"),
+ new ColorComboBoxItem (Color.Silver, "Silver"),
+ new ColorComboBoxItem (Color.Red, "Red"),
+ new ColorComboBoxItem (Color.Lime, "Lime"),
+ new ColorComboBoxItem (Color.Yellow, "Yellow"),
+ new ColorComboBoxItem (Color.Blue, "Blue"),
+ new ColorComboBoxItem (Color.Fuchsia, "Fuchsia"),
+ new ColorComboBoxItem (Color.Aqua, "Aqua"),
+ new ColorComboBoxItem (Color.White, "White") }
+ );
SelectedIndex = 0;
+ MaxDropDownItems = 16;
}
protected override void OnDrawItem( DrawItemEventArgs e )