Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Olk <aolk@mono-cvs.ximian.com>2006-02-28 21:00:40 +0300
committerAlexander Olk <aolk@mono-cvs.ximian.com>2006-02-28 21:00:40 +0300
commita4bd10ca7d8eac7dbd0214818b5a7bc73a4eabab (patch)
tree6f303e3c4498f2588e309648660610e24c7566fc
parent03c23396357e305e9835a3d0f90a14f94300c10b (diff)
2006-02-28 Alexander Olk <alex.olk@googlemail.com>
* FontDialog.cs: - Got rid of the panel. All controls are now directly added to the dialog form - It is now possible to set a font with the Font property - MinSize and MaxSize property do now what they should - ShowApply, ShowHelp, ShowColor, ShowEffects likewise - Searching and selecting a font with the font textbox works now, the same applies to the style and size textbox - Draw the correct 3D border in the example panel - Fixed a little mem leak (unused fonts didn't get disposed) - Many other internal updates/rewrites... svn path=/trunk/mcs/; revision=57407
-rw-r--r--mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog14
-rw-r--r--mcs/class/Managed.Windows.Forms/System.Windows.Forms/FontDialog.cs996
2 files changed, 588 insertions, 422 deletions
diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
index 8a3faaaaded..332eb527ad0 100644
--- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
+++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
@@ -1,3 +1,17 @@
+2006-02-28 Alexander Olk <alex.olk@googlemail.com>
+
+ * FontDialog.cs:
+ - Got rid of the panel. All controls are now directly added to
+ the dialog form
+ - It is now possible to set a font with the Font property
+ - MinSize and MaxSize property do now what they should
+ - ShowApply, ShowHelp, ShowColor, ShowEffects likewise
+ - Searching and selecting a font with the font textbox works now,
+ the same applies to the style and size textbox
+ - Draw the correct 3D border in the example panel
+ - Fixed a little mem leak (unused fonts didn't get disposed)
+ - Many other internal updates/rewrites...
+
2006-02-27 Peter Dennis Bartok <pbartok@novell.com>
* TextControl.cs:
diff --git a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FontDialog.cs b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FontDialog.cs
index e31f17a3753..da89b180aca 100644
--- a/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FontDialog.cs
+++ b/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FontDialog.cs
@@ -33,6 +33,8 @@
using System.ComponentModel;
using System.Drawing;
using System.Text.RegularExpressions;
+using System;
+using System.Collections;
namespace System.Windows.Forms
{
@@ -42,8 +44,6 @@ namespace System.Windows.Forms
{
protected static readonly object EventApply = new object ();
- private FontDialogPanel fontDialogPanel;
-
private Font font;
private Color color = Color.Black;
private bool allowSimulations = true;
@@ -61,14 +61,272 @@ namespace System.Windows.Forms
private bool fontMustExist = false;
+ private Panel examplePanel;
+
+ private Button okButton;
+ private Button cancelButton;
+ private Button applyButton;
+ private Button helpButton;
+
+ private TextBox fontTextBox;
+ private TextBox fontstyleTextBox;
+ private TextBox fontsizeTextBox;
+
+ private ListBox fontListBox;
+ private ListBox fontstyleListBox;
+ private ListBox fontsizeListBox;
+
+ private GroupBox effectsGroupBox;
+ private CheckBox strikethroughCheckBox;
+ private CheckBox underlinedCheckBox;
+ private ComboBox scriptComboBox;
+
+ private Label fontLabel;
+ private Label fontstyleLabel;
+ private Label sizeLabel;
+ private Label scriptLabel;
+
+ private GroupBox exampleGroupBox;
+
+ private ColorComboBox colorComboBox;
+
+ private FontFamily[] fontFamilies;
+
+ private string currentFontName;
+
+ private float currentSize;
+
+ private FontFamily currentFamily;
+
+ private FontStyle currentFontStyle;
+
+ private bool underlined = false;
+ private bool strikethrough = false;
+
+ private Hashtable fontHash = new Hashtable();
+
+ private int[] a_sizes = {
+ 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72
+ };
+
+ private bool internal_change = false;
+
#region Public Constructors
public FontDialog( )
{
- form.ClientSize = new Size( 430, 318 );
+ okButton = new Button( );
+ cancelButton = new Button( );
+ applyButton = new Button( );
+ helpButton = new Button( );
+
+ fontTextBox = new TextBox( );
+ fontstyleTextBox = new TextBox( );
+ fontsizeTextBox = new TextBox( );
+
+ fontListBox = new ListBox( );
+ fontsizeListBox = new ListBox( );
+
+ fontLabel = new Label( );
+ fontstyleLabel = new Label( );
+ sizeLabel = new Label( );
+ scriptLabel = new Label( );
+
+ exampleGroupBox = new GroupBox( );
+ fontstyleListBox = new ListBox( );
+
+ effectsGroupBox = new GroupBox( );
+ underlinedCheckBox = new CheckBox( );
+ strikethroughCheckBox = new CheckBox( );
+ scriptComboBox = new ComboBox( );
+
+ examplePanel = new Panel( );
+
+ colorComboBox = new ColorComboBox( this );
+
+ exampleGroupBox.SuspendLayout( );
+ effectsGroupBox.SuspendLayout( );
+ form.SuspendLayout( );
+
+ // fontsizeListBox
+ fontsizeListBox.Location = new Point( 284, 47 );
+ fontsizeListBox.Size = new Size( 52, 95 );
+ fontsizeListBox.TabIndex = 10;
+ fontListBox.Sorted = true;
+ // fontTextBox
+ fontTextBox.Location = new Point( 16, 26 );
+ fontTextBox.Size = new Size( 140, 21 );
+ fontTextBox.TabIndex = 5;
+ fontTextBox.Text = "";
+ // fontstyleLabel
+ fontstyleLabel.Location = new Point( 164, 10 );
+ fontstyleLabel.Size = new Size( 100, 16 );
+ fontstyleLabel.TabIndex = 1;
+ fontstyleLabel.Text = "Font Style:";
+ // typesizeTextBox
+ fontsizeTextBox.Location = new Point( 284, 26 );
+ fontsizeTextBox.Size = new Size( 52, 21 );
+ fontsizeTextBox.TabIndex = 7;
+ fontsizeTextBox.Text = "";
+ // schriftartListBox
+ fontListBox.Location = new Point( 16, 47 );
+ fontListBox.Size = new Size( 140, 95 );
+ fontListBox.TabIndex = 8;
+ fontListBox.Sorted = true;
+ // exampleGroupBox
+ exampleGroupBox.Controls.Add( examplePanel );
+ exampleGroupBox.FlatStyle = FlatStyle.System;
+ exampleGroupBox.Location = new Point( 164, 158 );
+ exampleGroupBox.Size = new Size( 172, 70 );
+ exampleGroupBox.TabIndex = 12;
+ exampleGroupBox.TabStop = false;
+ exampleGroupBox.Text = "Example";
+ // fontstyleListBox
+ fontstyleListBox.Location = new Point( 164, 47 );
+ fontstyleListBox.Size = new Size( 112, 95 );
+ fontstyleListBox.TabIndex = 9;
+ // schriftartLabel
+ fontLabel.Location = new Point( 16, 10 );
+ fontLabel.Size = new Size( 88, 16 );
+ fontLabel.TabIndex = 0;
+ fontLabel.Text = "Font:";
+ // effectsGroupBox
+ effectsGroupBox.Controls.Add( underlinedCheckBox );
+ effectsGroupBox.Controls.Add( strikethroughCheckBox );
+ effectsGroupBox.Controls.Add( colorComboBox );
+ effectsGroupBox.FlatStyle = FlatStyle.System;
+ effectsGroupBox.Location = new Point( 16, 158 );
+ effectsGroupBox.Size = new Size( 140, 116 );
+ effectsGroupBox.TabIndex = 11;
+ effectsGroupBox.TabStop = false;
+ effectsGroupBox.Text = "Effects";
+ // strikethroughCheckBox
+ strikethroughCheckBox.FlatStyle = FlatStyle.System;
+ strikethroughCheckBox.Location = new Point( 8, 16 );
+ strikethroughCheckBox.TabIndex = 0;
+ strikethroughCheckBox.Text = "Strikethrough";
+ // colorComboBox
+ colorComboBox.Location = new Point( 8, 70 );
+ colorComboBox.Size = new Size( 130, 21 );
+ // sizeLabel
+ sizeLabel.Location = new Point( 284, 10 );
+ sizeLabel.Size = new Size( 100, 16 );
+ sizeLabel.TabIndex = 2;
+ sizeLabel.Text = "Size:";
+ // scriptComboBox
+ scriptComboBox.Location = new Point( 164, 253 );
+ scriptComboBox.Size = new Size( 172, 21 );
+ scriptComboBox.TabIndex = 14;
+ scriptComboBox.Text = "-/-";
+ // okButton
+ okButton.FlatStyle = FlatStyle.System;
+ okButton.Location = new Point( 352, 26 );
+ okButton.Size = new Size( 70, 23 );
+ okButton.TabIndex = 3;
+ okButton.Text = "OK";
+ // cancelButton
+ cancelButton.FlatStyle = FlatStyle.System;
+ cancelButton.Location = new Point( 352, 52 );
+ cancelButton.Size = new Size( 70, 23 );
+ cancelButton.TabIndex = 4;
+ cancelButton.Text = "Cancel";
+ // applyButton
+ applyButton.FlatStyle = FlatStyle.System;
+ applyButton.Location = new Point( 352, 78 );
+ applyButton.Size = new Size( 70, 23 );
+ applyButton.TabIndex = 5;
+ applyButton.Text = "Apply";
+ // helpButton
+ helpButton.FlatStyle = FlatStyle.System;
+ helpButton.Location = new Point( 352, 104 );
+ helpButton.Size = new Size( 70, 23 );
+ helpButton.TabIndex = 6;
+ helpButton.Text = "Help";
+ // underlinedCheckBox
+ underlinedCheckBox.FlatStyle = FlatStyle.System;
+ underlinedCheckBox.Location = new Point( 8, 36 );
+ underlinedCheckBox.TabIndex = 1;
+ underlinedCheckBox.Text = "Underlined";
+ // fontstyleTextBox
+ fontstyleTextBox.Location = new Point( 164, 26 );
+ fontstyleTextBox.Size = new Size( 112, 21 );
+ fontstyleTextBox.TabIndex = 6;
+ fontstyleTextBox.Text = "";
+ // scriptLabel
+ scriptLabel.Location = new Point( 164, 236 );
+ scriptLabel.Size = new Size( 100, 16 );
+ scriptLabel.TabIndex = 13;
+ scriptLabel.Text = "Script:";
+ // examplePanel
+ examplePanel.Location = new Point( 8, 20 );
+ examplePanel.TabIndex = 0;
+ examplePanel.Size = new Size( 156, 40 );
+
+ form.AcceptButton = okButton;
+
+ form.Controls.Add( scriptComboBox );
+ form.Controls.Add( scriptLabel );
+ form.Controls.Add( exampleGroupBox );
+ form.Controls.Add( effectsGroupBox );
+ form.Controls.Add( fontsizeListBox );
+ form.Controls.Add( fontstyleListBox );
+ form.Controls.Add( fontListBox );
+ form.Controls.Add( fontsizeTextBox );
+ form.Controls.Add( fontstyleTextBox );
+ form.Controls.Add( fontTextBox );
+ form.Controls.Add( cancelButton );
+ form.Controls.Add( okButton );
+ form.Controls.Add( sizeLabel );
+ form.Controls.Add( fontstyleLabel );
+ form.Controls.Add( fontLabel );
+ form.Controls.Add( applyButton );
+ form.Controls.Add( helpButton );
+
+ exampleGroupBox.ResumeLayout( false );
+ effectsGroupBox.ResumeLayout( false );
form.Size = new Size( 430, 318 );
+ form.MinimumSize = new Size( 430, 318 );
+
+ form.FormBorderStyle = FormBorderStyle.FixedDialog;
+ form.MaximizeBox = false;
form.Text = "Font";
+
+ 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 ();
+
+ applyButton.Hide( );
+ helpButton.Hide( );
+ colorComboBox.Hide( );
+
+ cancelButton.Click += new EventHandler( OnClickCancelButton );
+ okButton.Click += new EventHandler( OnClickOkButton );
+ applyButton.Click += new EventHandler (OnApplyButton);
+ examplePanel.Paint += new PaintEventHandler( OnPaintExamplePanel );
+ fontListBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedFontListBox );
+ fontsizeListBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedSizeListBox );
+ fontstyleListBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedFontStyleListBox );
+ underlinedCheckBox.CheckedChanged += new EventHandler( OnCheckedChangedUnderlinedCheckBox );
+ strikethroughCheckBox.CheckedChanged += new EventHandler( OnCheckedChangedStrikethroughCheckBox );
+
+ fontTextBox.KeyUp += new KeyEventHandler (OnFontTextBoxKeyUp);
+ fontstyleTextBox.KeyUp += new KeyEventHandler (OnFontStyleTextBoxKeyUp);
+ fontsizeTextBox.KeyUp += new KeyEventHandler (OnFontSizeTextBoxKeyUp);
+
+ Font = form.Font;
}
#endregion // Public Constructors
@@ -80,7 +338,23 @@ namespace System.Windows.Forms
}
set {
- font = value;
+ if (value != null) {
+ font = new Font(value, value.Style);
+
+ currentFontStyle = font.Style;
+ currentSize = font.Size;
+ currentFontName = font.Name;
+
+ int index = fontListBox.FindString (currentFontName);
+
+ if (index != -1) {
+ fontListBox.SelectedIndex = index;
+ } else {
+ fontListBox.SelectedIndex = 0;
+ }
+
+ fontListBox.TopIndex = fontListBox.SelectedIndex;
+ }
}
}
@@ -100,6 +374,7 @@ namespace System.Windows.Forms
{
set {
color = value;
+ examplePanel.Invalidate( );
}
get {
@@ -172,6 +447,14 @@ namespace System.Windows.Forms
{
set {
maxSize = value;
+
+ if (maxSize < 0)
+ maxSize = 0;
+
+ if (maxSize < minSize)
+ minSize = maxSize;
+
+ CreateFontSizeListBoxItems ();
}
get {
@@ -184,6 +467,27 @@ namespace System.Windows.Forms
{
set {
minSize = value;
+
+ if (minSize < 0)
+ minSize = 0;
+
+ if (minSize > maxSize)
+ maxSize = minSize;
+
+ CreateFontSizeListBoxItems ();
+
+ if (minSize > currentSize)
+ if (font != null) {
+ font.Dispose();
+
+ currentSize = minSize;
+
+ font = new Font( currentFamily, currentSize, currentFontStyle );
+
+ UpdateExamplePanel ();
+
+ fontsizeTextBox.Text = currentSize.ToString ();
+ }
}
get {
@@ -207,7 +511,17 @@ namespace System.Windows.Forms
public bool ShowApply
{
set {
- showApply = value;
+ if (value != showApply)
+ {
+ showApply = value;
+ if (showApply)
+ applyButton.Show ();
+ else
+ applyButton.Hide ();
+
+ form.Refresh();
+ }
+
}
get {
@@ -219,7 +533,16 @@ namespace System.Windows.Forms
public bool ShowColor
{
set {
- showColor = value;
+ if (value != showColor)
+ {
+ showColor = value;
+ if (showColor)
+ colorComboBox.Show ();
+ else
+ colorComboBox.Hide ();
+
+ form.Refresh();
+ }
}
get {
@@ -231,7 +554,16 @@ namespace System.Windows.Forms
public bool ShowEffects
{
set {
- showEffects = value;
+ if (value != showEffects)
+ {
+ showEffects = value;
+ if (showEffects)
+ effectsGroupBox.Show ();
+ else
+ effectsGroupBox.Hide ();
+
+ form.Refresh();
+ }
}
get {
@@ -243,7 +575,16 @@ namespace System.Windows.Forms
public bool ShowHelp
{
set {
- showHelp = value;
+ if (value != showHelp)
+ {
+ showHelp = value;
+ if (showHelp)
+ helpButton.Show ();
+ else
+ helpButton.Hide ();
+
+ form.Refresh();
+ }
}
get {
@@ -266,13 +607,26 @@ namespace System.Windows.Forms
allowVerticalFonts = true;
allowScriptChange = true;
fixedPitchOnly = false;
+
maxSize = 0;
minSize = 0;
+ CreateFontSizeListBoxItems ();
+
scriptsOnly = false;
+
showApply = false;
+ applyButton.Hide ();
+
showColor = false;
+ colorComboBox.Hide ();
+
showEffects = true;
+ effectsGroupBox.Show ();
+
showHelp = false;
+ helpButton.Hide ();
+
+ form.Refresh ();
}
public override string ToString ()
@@ -287,8 +641,7 @@ namespace System.Windows.Forms
[MonoTODO]
protected override bool RunDialog( IntPtr hwndOwner )
{
- fontDialogPanel = new FontDialogPanel (this);
- form.Controls.Add( fontDialogPanel );
+ form.Refresh();
return true;
}
@@ -305,394 +658,28 @@ namespace System.Windows.Forms
apply (this, e);
}
#endregion // Protected Instance Methods
-
- public event EventHandler Apply {
- add { Events.AddHandler (EventApply, value); }
- remove { Events.RemoveHandler (EventApply, value); }
- }
- }
-
- internal class FontDialogPanel : Panel
- {
- private Panel examplePanel;
-
- private Button okButton;
- private Button cancelButton;
- private Button applyButton;
- private Button helpButton;
-
- private TextBox fontTextBox;
- private TextBox fontstyleTextBox;
- private TextBox sizeTextBox;
-
- private ListBox fontListBox;
- private ListBox fontstyleListBox;
- private ListBox sizeListBox;
-
- private GroupBox effectsGroupBox;
- private CheckBox strikethroughCheckBox;
- private CheckBox underlinedCheckBox;
- private ComboBox scriptComboBox;
-
- private Label fontLabel;
- private Label fontstyleLabel;
- private Label sizeLabel;
- private Label scriptLabel;
-
- private GroupBox exampleGroupBox;
-
- private ColorComboBox colorComboBox;
-
- private FontFamily[] fontFamilies;
-
- private string currentFontName;
-
- private Font currentFont;
-
- private int currentSize;
-
- private FontFamily currentFamily;
-
- private Color currentColor;
-
- private FontStyle currentFontStyle;
-
- private FontDialog fontDialog;
-
- private System.Collections.ArrayList fontStyleArray = new System.Collections.ArrayList();
-
- private System.Collections.Hashtable fontHash = new System.Collections.Hashtable();
-
- public FontDialogPanel( FontDialog fontDialog )
- {
- this.fontDialog = fontDialog;
-
- okButton = new Button( );
- cancelButton = new Button( );
- applyButton = new Button( );
- helpButton = new Button( );
-
- fontTextBox = new TextBox( );
- fontstyleTextBox = new TextBox( );
- sizeTextBox = new TextBox( );
-
- fontListBox = new ListBox( );
- sizeListBox = new ListBox( );
-
- fontLabel = new Label( );
- fontstyleLabel = new Label( );
- sizeLabel = new Label( );
- scriptLabel = new Label( );
-
- exampleGroupBox = new GroupBox( );
- fontstyleListBox = new ListBox( );
-
- effectsGroupBox = new GroupBox( );
- underlinedCheckBox = new CheckBox( );
- strikethroughCheckBox = new CheckBox( );
- scriptComboBox = new ComboBox( );
-
- examplePanel = new Panel( );
-
- colorComboBox = new ColorComboBox( this );
-
- exampleGroupBox.SuspendLayout( );
- effectsGroupBox.SuspendLayout( );
- SuspendLayout( );
-
- // typesizeListBox
- sizeListBox.Location = new Point( 284, 47 );
- sizeListBox.Size = new Size( 52, 95 );
- sizeListBox.TabIndex = 10;
- // fontTextBox
- fontTextBox.Location = new Point( 16, 26 );
- fontTextBox.Size = new Size( 140, 21 );
- fontTextBox.TabIndex = 5;
- fontTextBox.Text = "";
- // fontstyleLabel
- fontstyleLabel.Location = new Point( 164, 10 );
- fontstyleLabel.Size = new Size( 100, 16 );
- fontstyleLabel.TabIndex = 1;
- fontstyleLabel.Text = "Font Style:";
- // typesizeTextBox
- sizeTextBox.Location = new Point( 284, 26 );
- sizeTextBox.Size = new Size( 52, 21 );
- sizeTextBox.TabIndex = 7;
- sizeTextBox.Text = "";
- // schriftartListBox
- fontListBox.Location = new Point( 16, 47 );
- fontListBox.Size = new Size( 140, 95 );
- fontListBox.TabIndex = 8;
- fontListBox.Sorted = true;
- // exampleGroupBox
- exampleGroupBox.Controls.Add( examplePanel );
- exampleGroupBox.FlatStyle = FlatStyle.System;
- exampleGroupBox.Location = new Point( 164, 158 );
- exampleGroupBox.Size = new Size( 172, 70 );
- exampleGroupBox.TabIndex = 12;
- exampleGroupBox.TabStop = false;
- exampleGroupBox.Text = "Example";
- // fontstyleListBox
- fontstyleListBox.Location = new Point( 164, 47 );
- fontstyleListBox.Size = new Size( 112, 95 );
- fontstyleListBox.TabIndex = 9;
- // schriftartLabel
- fontLabel.Location = new Point( 16, 10 );
- fontLabel.Size = new Size( 88, 16 );
- fontLabel.TabIndex = 0;
- fontLabel.Text = "Font:";
- // effectsGroupBox
- effectsGroupBox.Controls.Add( underlinedCheckBox );
- effectsGroupBox.Controls.Add( strikethroughCheckBox );
- effectsGroupBox.Controls.Add( colorComboBox );
- effectsGroupBox.FlatStyle = FlatStyle.System;
- effectsGroupBox.Location = new Point( 16, 158 );
- effectsGroupBox.Size = new Size( 140, 116 );
- effectsGroupBox.TabIndex = 11;
- effectsGroupBox.TabStop = false;
- effectsGroupBox.Text = "Effects";
- // strikethroughCheckBox
- strikethroughCheckBox.FlatStyle = FlatStyle.System;
- strikethroughCheckBox.Location = new Point( 8, 16 );
- strikethroughCheckBox.TabIndex = 0;
- strikethroughCheckBox.Text = "Strikethrough";
- // colorComboBox
- colorComboBox.Location = new Point( 8, 70 );
- colorComboBox.Size = new Size( 130, 21 );
- // sizeLabel
- sizeLabel.Location = new Point( 284, 10 );
- sizeLabel.Size = new Size( 100, 16 );
- sizeLabel.TabIndex = 2;
- sizeLabel.Text = "Size:";
- // scriptComboBox
- scriptComboBox.Location = new Point( 164, 253 );
- scriptComboBox.Size = new Size( 172, 21 );
- scriptComboBox.TabIndex = 14;
- scriptComboBox.Text = "-/-";
- // okButton
- okButton.FlatStyle = FlatStyle.System;
- okButton.Location = new Point( 352, 26 );
- okButton.Size = new Size( 70, 23 );
- okButton.TabIndex = 3;
- okButton.Text = "OK";
- // cancelButton
- cancelButton.FlatStyle = FlatStyle.System;
- cancelButton.Location = new Point( 352, 52 );
- cancelButton.Size = new Size( 70, 23 );
- cancelButton.TabIndex = 4;
- cancelButton.Text = "Cancel";
- // applyButton
- applyButton.FlatStyle = FlatStyle.System;
- applyButton.Location = new Point( 352, 78 );
- applyButton.Size = new Size( 70, 23 );
- applyButton.TabIndex = 5;
- applyButton.Text = "Apply";
- // helpButton
- helpButton.FlatStyle = FlatStyle.System;
- helpButton.Location = new Point( 352, 104 );
- helpButton.Size = new Size( 70, 23 );
- helpButton.TabIndex = 6;
- helpButton.Text = "Help";
- // underlinedCheckBox
- underlinedCheckBox.FlatStyle = FlatStyle.System;
- underlinedCheckBox.Location = new Point( 8, 36 );
- underlinedCheckBox.TabIndex = 1;
- underlinedCheckBox.Text = "Underlined";
- // fontstyleTextBox
- fontstyleTextBox.Location = new Point( 164, 26 );
- fontstyleTextBox.Size = new Size( 112, 21 );
- fontstyleTextBox.TabIndex = 6;
- fontstyleTextBox.Text = "";
- // scriptLabel
- scriptLabel.Location = new Point( 164, 236 );
- scriptLabel.Size = new Size( 100, 16 );
- scriptLabel.TabIndex = 13;
- scriptLabel.Text = "Script:";
- // examplePanel
- examplePanel.Location = new Point( 8, 20 );
- examplePanel.TabIndex = 0;
- examplePanel.BorderStyle = BorderStyle.Fixed3D;
- examplePanel.Size = new Size( 156, 40 );
-
- ClientSize = new Size( 430, 318 );
-
- Controls.Add( scriptComboBox );
- Controls.Add( scriptLabel );
- Controls.Add( exampleGroupBox );
- Controls.Add( effectsGroupBox );
- Controls.Add( sizeListBox );
- Controls.Add( fontstyleListBox );
- Controls.Add( fontListBox );
- Controls.Add( sizeTextBox );
- Controls.Add( fontstyleTextBox );
- Controls.Add( fontTextBox );
- Controls.Add( cancelButton );
- Controls.Add( okButton );
- Controls.Add( sizeLabel );
- Controls.Add( fontstyleLabel );
- Controls.Add( fontLabel );
- Controls.Add( applyButton );
- Controls.Add( helpButton );
-
- exampleGroupBox.ResumeLayout( false );
- effectsGroupBox.ResumeLayout( false );
-
- 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( );
-
- fontListBox.SelectedIndex = 0;
-
- // TODO: If Font is provided via FontDialog.Font property set correct font in FontListBox
- currentFontName = fontListBox.Items[ 0 ].ToString( );
- fontTextBox.Text = currentFontName;
-
- // default 12 ?!?
- currentSize = 12;
-
- currentFamily = FindByName( currentFontName );
-
- currentFontStyle = FontStyle.Regular;
-
- currentFont = new Font( currentFamily, currentSize, currentFontStyle );
-
- currentColor = fontDialog.Color;
-
- UpdateFontStyleListBox( );
-
- fontstyleTextBox.Text = "Regular";
-
- fontstyleListBox.SelectedIndex = 0 ;
-
- sizeTextBox.Text = currentSize.ToString( );
-
- sizeListBox.Items.AddRange( new object[] {
- "8",
- "9",
- "10",
- "11",
- "12",
- "14",
- "16",
- "18",
- "20",
- "22",
- "24",
- "26",
- "28",
- "36",
- "48",
- "72" } );
-
- sizeListBox.SelectedIndex = 4;
-
- if ( !fontDialog.ShowApply )
- applyButton.Hide( );
- if ( !fontDialog.ShowHelp )
- helpButton.Hide( );
- if ( !fontDialog.ShowEffects )
- effectsGroupBox.Hide( );
- if ( !fontDialog.ShowColor )
- colorComboBox.Hide( );
-
- cancelButton.Click += new EventHandler( OnClickCancelButton );
- okButton.Click += new EventHandler( OnClickOkButton );
- applyButton.Click += new EventHandler (fontDialog.OnApplyButton);
- examplePanel.Paint += new PaintEventHandler( OnPaintExamplePanel );
- fontListBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedFontListBox );
- sizeListBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedSizeListBox );
- fontstyleListBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedFontStyleListBox );
- underlinedCheckBox.CheckedChanged += new EventHandler( OnCheckedChangedUnderlinedCheckBox );
- strikethroughCheckBox.CheckedChanged += new EventHandler( OnCheckedChangedStrikethroughCheckBox );
- }
-
- public Color CurrentColor
- {
- set {
- currentColor = value;
- examplePanel.Invalidate( );
- }
-
- get {
- return currentColor;
- }
- }
-
- private void UpdateFontStyleListBox( )
- {
- // don't know if that works, IsStyleAvailable returns true for all styles under X
-
- fontStyleArray.Clear( );
-
- fontstyleListBox.BeginUpdate( );
-
- fontstyleListBox.Items.Clear( );
-
- if ( currentFamily.IsStyleAvailable( FontStyle.Regular ) )
- {
- fontstyleListBox.Items.Add( "Regular" );
- fontStyleArray.Add( 0 );
- }
-
- if ( currentFamily.IsStyleAvailable( FontStyle.Bold ) )
- {
- fontstyleListBox.Items.Add( "Bold" );
- fontStyleArray.Add( 1 );
- }
-
- if ( currentFamily.IsStyleAvailable( FontStyle.Italic ) )
- {
- fontstyleListBox.Items.Add( "Italic" );
- fontStyleArray.Add( 2 );
- }
-
- if ( currentFamily.IsStyleAvailable( FontStyle.Bold ) && currentFamily.IsStyleAvailable( FontStyle.Italic ) )
- {
- fontstyleListBox.Items.Add( "Bold Italic" );
- fontStyleArray.Add( 3 );
- }
-
- fontstyleListBox.EndUpdate( );
- }
-
- private FontFamily FindByName( string name )
- {
- return fontHash[ name ] as FontFamily;
- }
void OnClickCancelButton( object sender, EventArgs e )
{
- fontDialog.form.Controls.Remove( this );
- fontDialog.form.DialogResult = DialogResult.Cancel;
+ form.DialogResult = DialogResult.Cancel;
}
void OnClickOkButton( object sender, EventArgs e )
{
- fontDialog.form.Controls.Remove( this );
- fontDialog.Font = currentFont;
- fontDialog.Color = currentColor;
- fontDialog.form.DialogResult = DialogResult.OK;
+ form.DialogResult = DialogResult.OK;
}
-
+
void OnPaintExamplePanel( object sender, PaintEventArgs e )
{
- SolidBrush brush = ThemeEngine.Current.ResPool.GetSolidBrush( currentColor );
+ SolidBrush brush = ThemeEngine.Current.ResPool.GetSolidBrush( color );
e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( SystemColors.Control ), 0, 0, 156, 40 );
+ ControlPaint.DrawBorder3D(e.Graphics, e.ClipRectangle, Border3DStyle.SunkenInner);
+
string text = "AaBbYyZz";
- SizeF fontSizeF = e.Graphics.MeasureString( text, currentFont );
+ SizeF fontSizeF = e.Graphics.MeasureString( text, font );
int text_width = (int)fontSizeF.Width;
int text_height = (int)fontSizeF.Height;
@@ -702,7 +689,7 @@ namespace System.Windows.Forms
int y = ( examplePanel.Height / 2 ) - ( text_height / 2 );
- e.Graphics.DrawString( text, currentFont, brush, new Point( x, y ) );
+ e.Graphics.DrawString( text, font, brush, new Point( x, y ) );
}
void OnSelectedIndexChangedFontListBox( object sender, EventArgs e )
@@ -713,21 +700,30 @@ namespace System.Windows.Forms
fontTextBox.Text = currentFamily.Name;
+ internal_change = true;
+
UpdateFontStyleListBox( );
- UpdateExamplePanel( );
+ UpdateFontSizeListBox ();
+
+ form.Select(fontTextBox);
+
+ internal_change = false;
}
}
void OnSelectedIndexChangedSizeListBox( object sender, EventArgs e )
{
- if ( sizeListBox.SelectedIndex != -1 )
+ if ( fontsizeListBox.SelectedIndex != -1 )
{
- currentSize = System.Convert.ToInt32( sizeListBox.Items[ sizeListBox.SelectedIndex ] );
+ currentSize = (float)System.Convert.ToDouble( fontsizeListBox.Items[ fontsizeListBox.SelectedIndex ] );
- sizeTextBox.Text = currentSize.ToString( );
+ fontsizeTextBox.Text = currentSize.ToString( );
UpdateExamplePanel( );
+
+ if (!internal_change)
+ form.Select(fontsizeTextBox);
}
}
@@ -735,57 +731,209 @@ namespace System.Windows.Forms
{
if ( fontstyleListBox.SelectedIndex != -1 )
{
- switch ( (int)fontStyleArray[ fontstyleListBox.SelectedIndex ] )
+ switch ( fontstyleListBox.SelectedIndex )
{
- case 0:
- currentFontStyle = FontStyle.Regular;
- break;
- case 1:
- currentFontStyle = FontStyle.Bold;
- break;
- case 2:
- currentFontStyle = FontStyle.Italic;
- break;
- case 3:
- currentFontStyle = FontStyle.Bold | FontStyle.Italic;
- break;
- default:
- currentFontStyle = FontStyle.Regular;
- break;
+ case 0:
+ currentFontStyle = FontStyle.Regular;
+ break;
+ case 1:
+ currentFontStyle = FontStyle.Bold;
+ break;
+ case 2:
+ currentFontStyle = FontStyle.Italic;
+ break;
+ case 3:
+ currentFontStyle = FontStyle.Bold | FontStyle.Italic;
+ break;
+ default:
+ currentFontStyle = FontStyle.Regular;
+ break;
}
+ if (underlined)
+ currentFontStyle = currentFontStyle | FontStyle.Underline;
+
+ if (strikethrough)
+ currentFontStyle = currentFontStyle | FontStyle.Strikeout;
+
fontstyleTextBox.Text = fontstyleListBox.Items[ fontstyleListBox.SelectedIndex ].ToString( );
- UpdateExamplePanel( );
+ if (!internal_change) {
+ UpdateExamplePanel( );
+
+ form.Select(fontstyleTextBox);
+ }
}
}
void OnCheckedChangedUnderlinedCheckBox( object sender, EventArgs e )
{
- if ( underlinedCheckBox.Checked )
+ if ( underlinedCheckBox.Checked ) {
currentFontStyle = currentFontStyle | FontStyle.Underline;
- else
+ underlined = true;
+ }
+ else {
currentFontStyle = currentFontStyle ^ FontStyle.Underline;
+ underlined = false;
+ }
UpdateExamplePanel( );
}
void OnCheckedChangedStrikethroughCheckBox( object sender, EventArgs e )
{
- if ( strikethroughCheckBox.Checked )
+ if ( strikethroughCheckBox.Checked ) {
currentFontStyle = currentFontStyle | FontStyle.Strikeout;
- else
+ strikethrough = true;
+ }
+ else {
currentFontStyle = currentFontStyle ^ FontStyle.Strikeout;
+ strikethrough = false;
+ }
UpdateExamplePanel( );
}
- private void UpdateExamplePanel( )
+ void OnFontTextBoxKeyUp (object sender, EventArgs e)
+ {
+ 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;
+ }
+ }
+ }
+
+ void OnFontStyleTextBoxKeyUp (object sender, KeyEventArgs e)
{
- currentFont = new Font( currentFamily, currentSize, currentFontStyle );
+ 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;
+ else
+ fontstyleListBox.TopIndex = i;
+
+ break;
+ }
+ }
+ }
+
+ void OnFontSizeTextBoxKeyUp (object sender, KeyEventArgs e)
+ {
+ for (int i = 0; i < fontsizeListBox.Items.Count; i++) {
+ string name = fontsizeListBox.Items [i] as string;
+
+ if (name.StartsWith(fontsizeTextBox.Text)) {
+ if (name == fontsizeTextBox.Text)
+ fontsizeListBox.SelectedIndex = i;
+ else
+ fontsizeListBox.TopIndex = i;
+
+ break;
+ }
+ }
+ }
+
+ void UpdateExamplePanel( )
+ {
+ if (font != null)
+ font.Dispose();
+
+ font = new Font( currentFamily, currentSize, currentFontStyle );
examplePanel.Invalidate( );
- examplePanel.Update( );
+ }
+
+ void UpdateFontSizeListBox ()
+ {
+ int index = fontsizeListBox.FindString(currentSize.ToString());
+
+ if (index != -1)
+ fontsizeListBox.SelectedIndex = index;
+ else
+ fontsizeListBox.SelectedIndex = 0;
+ }
+
+ void UpdateFontStyleListBox( )
+ {
+ // don't know if that works, IsStyleAvailable returns true for all styles under X
+
+ fontstyleListBox.BeginUpdate( );
+
+ fontstyleListBox.Items.Clear( );
+
+ int index = -1;
+ int to_select = 0;
+
+ if ( currentFamily.IsStyleAvailable( FontStyle.Regular ) )
+ {
+ index = fontstyleListBox.Items.Add( "Regular" );
+
+ if ((currentFontStyle & FontStyle.Regular) == FontStyle.Regular)
+ to_select = index;
+ }
+
+ if ( currentFamily.IsStyleAvailable( FontStyle.Bold ) )
+ {
+ index = fontstyleListBox.Items.Add( "Bold" );
+
+ if ((currentFontStyle & FontStyle.Bold) == FontStyle.Bold)
+ to_select = index;
+ }
+
+ if ( currentFamily.IsStyleAvailable( FontStyle.Italic ) )
+ {
+ index = fontstyleListBox.Items.Add( "Italic" );
+
+ if ((currentFontStyle & FontStyle.Italic) == FontStyle.Italic)
+ to_select = index;
+ }
+
+ if ( currentFamily.IsStyleAvailable( FontStyle.Bold ) && currentFamily.IsStyleAvailable( FontStyle.Italic ) )
+ {
+ index = fontstyleListBox.Items.Add( "Bold Italic" );
+
+ if ((currentFontStyle & (FontStyle.Bold | FontStyle.Italic)) == (FontStyle.Bold | FontStyle.Italic))
+ to_select = index;
+ }
+
+ if (fontstyleListBox.Items.Count > 0)
+ fontstyleListBox.SelectedIndex = to_select;
+
+ fontstyleListBox.EndUpdate( );
+ }
+
+ FontFamily FindByName( string name )
+ {
+ return fontHash[ name ] as FontFamily;
+ }
+
+ void CreateFontSizeListBoxItems ()
+ {
+ fontsizeListBox.BeginUpdate ();
+
+ fontsizeListBox.Items. Clear();
+
+ if (minSize == 0 && maxSize == 0)
+ {
+ foreach (int i in a_sizes)
+ fontsizeListBox.Items.Add (i.ToString());
+ } else {
+ foreach (int i in a_sizes) {
+ if (i >= minSize && i <= maxSize)
+ fontsizeListBox.Items.Add (i.ToString());
+ }
+ }
+
+ fontsizeListBox.EndUpdate ();
}
internal class ColorComboBox : ComboBox
@@ -826,13 +974,11 @@ namespace System.Windows.Forms
private Color selectedColor;
- private FontDialogPanel fontDialogPanel;
-
- // FIXME: TextBox backcolor shouldn't be the same as the selected item in the ListBox/ListCtrl
+ private FontDialog fontDialog;
- public ColorComboBox( FontDialogPanel fontDialogPanel )
+ public ColorComboBox( FontDialog fontDialog )
{
- this.fontDialogPanel = fontDialogPanel;
+ this.fontDialog = fontDialog;
DropDownStyle = ComboBoxStyle.DropDownList;
DrawMode = DrawMode.OwnerDrawFixed;
@@ -872,15 +1018,15 @@ namespace System.Windows.Forms
if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected )
{
e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( Color.Blue ), e.Bounds ); // bot blue
- e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( ccbi.Color ), e.Bounds.X + 3, e.Bounds.Y + 3, e.Bounds.X + 16, e.Bounds.Y + e.Bounds.Height - 2 );
- e.Graphics.DrawRectangle( ThemeEngine.Current.ResPool.GetPen( Color.Black ), e.Bounds.X + 2, e. Bounds.Y + 2, e.Bounds.X + 17, e.Bounds.Y + e.Bounds.Height - 1 );
+ e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( ccbi.Color ), e.Bounds.X + 3, e.Bounds.Y + 3, e.Bounds.X + 16, e.Bounds.Bottom - 3 );
+ e.Graphics.DrawRectangle( ThemeEngine.Current.ResPool.GetPen( Color.Black ), e.Bounds.X + 2, e. Bounds.Y + 2, e.Bounds.X + 17, e.Bounds.Bottom - 3 );
e.Graphics.DrawString( ccbi.Name, this.Font, ThemeEngine.Current.ResPool.GetSolidBrush( Color.White ), r );
}
else
{
e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( Color.White ), e.Bounds );
- e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( ccbi.Color ), e.Bounds.X + 3, e.Bounds.Y + 3, e.Bounds.X + 16, e.Bounds.Y + e.Bounds.Height - 2 );
- e.Graphics.DrawRectangle( ThemeEngine.Current.ResPool.GetPen( Color.Black ), e.Bounds.X + 2, e. Bounds.Y + 2, e.Bounds.X + 17, e.Bounds.Y + e.Bounds.Height - 1 );
+ e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( ccbi.Color ), e.Bounds.X + 3, e.Bounds.Y + 3, e.Bounds.X + 16, e.Bounds.Bottom - 3 );
+ e.Graphics.DrawRectangle( ThemeEngine.Current.ResPool.GetPen( Color.Black ), e.Bounds.X + 2, e. Bounds.Y + 2, e.Bounds.X + 17, e.Bounds.Bottom - 3 );
e.Graphics.DrawString( ccbi.Name, this.Font, ThemeEngine.Current.ResPool.GetSolidBrush( Color.Black ), r );
}
}
@@ -890,8 +1036,14 @@ namespace System.Windows.Forms
ColorComboBoxItem ccbi = Items[ SelectedIndex ] as ColorComboBoxItem;
selectedColor = ccbi.Color;
- fontDialogPanel.CurrentColor = selectedColor;
+ fontDialog.Color = selectedColor;
}
}
+
+ public event EventHandler Apply {
+ add { Events.AddHandler (EventApply, value); }
+ remove { Events.RemoveHandler (EventApply, value); }
+ }
}
}
+