1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2006, Alexander Olk
23 // Alexander Olk alex.olk@googlemail.com
27 // NOT COMPLETE - work in progress
29 using System.ComponentModel;
31 using System.Text.RegularExpressions;
33 using System.Collections;
35 namespace System.Windows.Forms
37 [DefaultProperty( "Font" )]
38 [DefaultEvent("Apply")]
39 public class FontDialog : CommonDialog
41 protected static readonly object EventApply = new object ();
44 private Color color = Color.Black;
45 private bool allowSimulations = true;
46 private bool allowVectorFonts = true;
47 private bool allowVerticalFonts = true;
48 private bool allowScriptChange = true;
49 private bool fixedPitchOnly = false;
50 private int maxSize = 0;
51 private int minSize = 0;
52 private bool scriptsOnly = false;
53 private bool showApply = false;
54 private bool showColor = false;
55 private bool showEffects = true;
56 private bool showHelp = false;
58 private bool fontMustExist = false;
60 private Panel examplePanel;
62 private Button okButton;
63 private Button cancelButton;
64 private Button applyButton;
65 private Button helpButton;
67 private TextBox fontTextBox;
68 private TextBox fontstyleTextBox;
69 private TextBox fontsizeTextBox;
71 private MouseWheelListBox fontListBox;
72 private MouseWheelListBox fontstyleListBox;
73 private MouseWheelListBox fontsizeListBox;
75 private GroupBox effectsGroupBox;
76 private CheckBox strikethroughCheckBox;
77 private CheckBox underlinedCheckBox;
78 private ComboBox scriptComboBox;
80 private Label fontLabel;
81 private Label fontstyleLabel;
82 private Label sizeLabel;
83 private Label scriptLabel;
85 private GroupBox exampleGroupBox;
87 private ColorComboBox colorComboBox;
89 private FontFamily[] fontFamilies;
91 private string currentFontName;
93 private float currentSize;
95 private FontFamily currentFamily;
97 private FontStyle currentFontStyle;
99 private bool underlined = false;
100 private bool strikethrough = false;
102 private Hashtable fontHash = new Hashtable();
104 private int[] a_sizes = {
105 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72
108 // char set stuff is only here to make me happy :-)
109 private string [] char_sets_names = {
137 private string [] char_sets = {
140 "Aa" + (char)0x3042 + (char)0x3041 + (char)0x30a2 + (char)0x30a1 + (char)0x4e9c + (char)0x5b87,
141 (char)0xac00 + (char)0xb098 + (char)0xb2e4 + "AaBYyZz",
142 new String(new Char [] {(char)0x5fae, (char)0x8f6f, (char)0x4e2d, (char)0x6587, (char)0x8f6f, (char)0x4ef6}),
143 new String(new Char [] {(char)0x4e2d, (char)0x6587, (char)0x5b57, (char)0x578b, (char)0x7bc4, (char)0x4f8b}),
144 "AaBb" + (char)0x0391 + (char)0x03b1 + (char)0x0392 + (char)0x03b2,
145 "AaBb" + (char)0x011e + (char)0x011f + (char)0x015e + (char)0x015f,
146 "AaBb" + (char)0x05e0 + (char)0x05e1 + (char)0x05e9 + (char)0x05ea,
147 "AaBb" + (char)0x0627 + (char)0x0628 + (char)0x062c + (char)0x062f + (char)0x0647 + (char)0x0648 + (char)0x0632,
149 "AaBb" + (char)0x01a0 + (char)0x01a1 + (char)0x01af + (char)0x01b0,
150 "AaBb" + (char)0x0411 + (char)0x0431 + (char)0x0424 + (char)0x0444,
151 "AaBb" + (char)0xc1 + (char)0xe1 + (char)0xd4 + (char)0xf4,
152 "AaBb" + (char)0x0e2d + (char)0x0e31 + (char)0x0e01 + (char)0x0e29 + (char)0x0e23 + (char)0x0e44 + (char)0x0e17 +(char)0x0e22,
153 (char)0xac00 + (char)0xb098 + (char)0xb2e4 + "AaBYyZz",
155 "AaBb" + (char)0xf8 + (char)0xf1 + (char)0xfd,
165 private string example_panel_text;
167 private bool internal_change = false;
169 #region Public Constructors
172 example_panel_text = char_sets [0];
174 okButton = new Button( );
175 cancelButton = new Button( );
176 applyButton = new Button( );
177 helpButton = new Button( );
179 fontTextBox = new TextBox( );
180 fontstyleTextBox = new TextBox( );
181 fontsizeTextBox = new TextBox( );
183 fontListBox = new MouseWheelListBox ();
184 fontsizeListBox = new MouseWheelListBox ();
185 fontstyleListBox = new MouseWheelListBox ();
187 fontLabel = new Label( );
188 fontstyleLabel = new Label( );
189 sizeLabel = new Label( );
190 scriptLabel = new Label( );
192 exampleGroupBox = new GroupBox( );
194 effectsGroupBox = new GroupBox( );
195 underlinedCheckBox = new CheckBox( );
196 strikethroughCheckBox = new CheckBox( );
197 scriptComboBox = new ComboBox( );
199 examplePanel = new Panel( );
201 colorComboBox = new ColorComboBox( this );
203 exampleGroupBox.SuspendLayout( );
204 effectsGroupBox.SuspendLayout( );
205 form.SuspendLayout( );
207 form.FormBorderStyle = FormBorderStyle.FixedDialog;
208 form.MaximizeBox = false;
211 fontsizeListBox.Location = new Point( 284, 47 );
212 fontsizeListBox.Size = new Size( 52, 95 );
213 fontsizeListBox.TabIndex = 10;
214 fontListBox.Sorted = true;
216 fontTextBox.Location = new Point( 16, 26 );
217 fontTextBox.Size = new Size( 140, 21 );
218 fontTextBox.TabIndex = 5;
219 fontTextBox.Text = "";
221 fontstyleLabel.Location = new Point( 164, 10 );
222 fontstyleLabel.Size = new Size( 100, 16 );
223 fontstyleLabel.TabIndex = 1;
224 fontstyleLabel.Text = "Font Style:";
226 fontsizeTextBox.Location = new Point( 284, 26 );
227 fontsizeTextBox.Size = new Size( 52, 21 );
228 fontsizeTextBox.TabIndex = 7;
229 fontsizeTextBox.Text = "";
230 fontsizeTextBox.MaxLength = 2;
232 fontListBox.Location = new Point( 16, 47 );
233 fontListBox.Size = new Size( 140, 95 );
234 fontListBox.TabIndex = 8;
235 fontListBox.Sorted = true;
237 exampleGroupBox.Controls.Add( examplePanel );
238 exampleGroupBox.FlatStyle = FlatStyle.System;
239 exampleGroupBox.Location = new Point( 164, 158 );
240 exampleGroupBox.Size = new Size( 172, 70 );
241 exampleGroupBox.TabIndex = 12;
242 exampleGroupBox.TabStop = false;
243 exampleGroupBox.Text = "Example";
245 fontstyleListBox.Location = new Point( 164, 47 );
246 fontstyleListBox.Size = new Size( 112, 95 );
247 fontstyleListBox.TabIndex = 9;
249 fontLabel.Location = new Point( 16, 10 );
250 fontLabel.Size = new Size( 88, 16 );
251 fontLabel.TabIndex = 0;
252 fontLabel.Text = "Font:";
254 effectsGroupBox.Controls.Add( underlinedCheckBox );
255 effectsGroupBox.Controls.Add( strikethroughCheckBox );
256 effectsGroupBox.Controls.Add( colorComboBox );
257 effectsGroupBox.FlatStyle = FlatStyle.System;
258 effectsGroupBox.Location = new Point( 16, 158 );
259 effectsGroupBox.Size = new Size( 140, 116 );
260 effectsGroupBox.TabIndex = 11;
261 effectsGroupBox.TabStop = false;
262 effectsGroupBox.Text = "Effects";
263 // strikethroughCheckBox
264 strikethroughCheckBox.FlatStyle = FlatStyle.System;
265 strikethroughCheckBox.Location = new Point( 8, 16 );
266 strikethroughCheckBox.TabIndex = 0;
267 strikethroughCheckBox.Text = "Strikethrough";
269 colorComboBox.Location = new Point( 8, 70 );
270 colorComboBox.Size = new Size( 130, 21 );
272 sizeLabel.Location = new Point( 284, 10 );
273 sizeLabel.Size = new Size( 100, 16 );
274 sizeLabel.TabIndex = 2;
275 sizeLabel.Text = "Size:";
277 scriptComboBox.Location = new Point( 164, 253 );
278 scriptComboBox.Size = new Size( 172, 21 );
279 scriptComboBox.TabIndex = 14;
280 scriptComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
282 okButton.FlatStyle = FlatStyle.System;
283 okButton.Location = new Point( 352, 26 );
284 okButton.Size = new Size( 70, 23 );
285 okButton.TabIndex = 3;
286 okButton.Text = "OK";
288 cancelButton.FlatStyle = FlatStyle.System;
289 cancelButton.Location = new Point( 352, 52 );
290 cancelButton.Size = new Size( 70, 23 );
291 cancelButton.TabIndex = 4;
292 cancelButton.Text = "Cancel";
294 applyButton.FlatStyle = FlatStyle.System;
295 applyButton.Location = new Point( 352, 78 );
296 applyButton.Size = new Size( 70, 23 );
297 applyButton.TabIndex = 5;
298 applyButton.Text = "Apply";
300 helpButton.FlatStyle = FlatStyle.System;
301 helpButton.Location = new Point( 352, 104 );
302 helpButton.Size = new Size( 70, 23 );
303 helpButton.TabIndex = 6;
304 helpButton.Text = "Help";
305 // underlinedCheckBox
306 underlinedCheckBox.FlatStyle = FlatStyle.System;
307 underlinedCheckBox.Location = new Point( 8, 36 );
308 underlinedCheckBox.TabIndex = 1;
309 underlinedCheckBox.Text = "Underlined";
311 fontstyleTextBox.Location = new Point( 164, 26 );
312 fontstyleTextBox.Size = new Size( 112, 21 );
313 fontstyleTextBox.TabIndex = 6;
314 fontstyleTextBox.Text = "";
316 scriptLabel.Location = new Point( 164, 236 );
317 scriptLabel.Size = new Size( 100, 16 );
318 scriptLabel.TabIndex = 13;
319 scriptLabel.Text = "Script:";
321 examplePanel.Location = new Point( 8, 20 );
322 examplePanel.TabIndex = 0;
323 examplePanel.Size = new Size( 156, 40 );
324 examplePanel.BorderStyle = BorderStyle.Fixed3D;
326 form.AcceptButton = okButton;
328 form.Controls.Add( scriptComboBox );
329 form.Controls.Add( scriptLabel );
330 form.Controls.Add( exampleGroupBox );
331 form.Controls.Add( effectsGroupBox );
332 form.Controls.Add( fontsizeListBox );
333 form.Controls.Add( fontstyleListBox );
334 form.Controls.Add( fontListBox );
335 form.Controls.Add( fontsizeTextBox );
336 form.Controls.Add( fontstyleTextBox );
337 form.Controls.Add( fontTextBox );
338 form.Controls.Add( cancelButton );
339 form.Controls.Add( okButton );
340 form.Controls.Add( sizeLabel );
341 form.Controls.Add( fontstyleLabel );
342 form.Controls.Add( fontLabel );
343 form.Controls.Add( applyButton );
344 form.Controls.Add( helpButton );
346 exampleGroupBox.ResumeLayout( false );
347 effectsGroupBox.ResumeLayout( false );
349 form.Size = new Size( 430, 318 );
351 form.FormBorderStyle = FormBorderStyle.FixedDialog;
352 form.MaximizeBox = false;
356 form.ResumeLayout( false );
358 fontFamilies = FontFamily.Families;
360 fontListBox.BeginUpdate( );
361 foreach ( FontFamily ff in fontFamilies )
363 if ( !fontHash.ContainsKey (ff.Name) ) {
364 fontListBox.Items.Add( ff.Name );
365 fontHash.Add( ff.Name, ff );
368 fontListBox.EndUpdate( );
370 CreateFontSizeListBoxItems ();
372 scriptComboBox.BeginUpdate ();
373 scriptComboBox.Items.AddRange (char_sets_names);
374 scriptComboBox.SelectedIndex = 0;
375 scriptComboBox.EndUpdate ();
379 colorComboBox.Hide( );
381 cancelButton.Click += new EventHandler( OnClickCancelButton );
382 okButton.Click += new EventHandler( OnClickOkButton );
383 applyButton.Click += new EventHandler (OnApplyButton);
384 examplePanel.Paint += new PaintEventHandler( OnPaintExamplePanel );
385 fontListBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedFontListBox );
386 fontsizeListBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedSizeListBox );
387 fontstyleListBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedFontStyleListBox );
388 underlinedCheckBox.CheckedChanged += new EventHandler( OnCheckedChangedUnderlinedCheckBox );
389 strikethroughCheckBox.CheckedChanged += new EventHandler( OnCheckedChangedStrikethroughCheckBox );
390 scriptComboBox.SelectedIndexChanged += new EventHandler (OnSelectedIndexChangedScriptComboBox);
392 fontTextBox.KeyPress += new KeyPressEventHandler (OnFontTextBoxKeyPress);
393 fontstyleTextBox.KeyPress += new KeyPressEventHandler (OnFontStyleTextBoxKeyPress);
394 fontsizeTextBox.KeyPress += new KeyPressEventHandler (OnFontSizeTextBoxKeyPress);
396 fontTextBox.TextChanged += new EventHandler (OnFontTextBoxTextChanged);
397 fontstyleTextBox.TextChanged += new EventHandler (OnFontStyleTextTextChanged);
398 fontsizeTextBox.TextChanged += new EventHandler (OnFontSizeTextBoxTextChanged);
400 fontTextBox.KeyDown += new KeyEventHandler (OnFontTextBoxKeyDown);
401 fontstyleTextBox.KeyDown += new KeyEventHandler (OnFontStyleTextBoxKeyDown);
402 fontsizeTextBox.KeyDown += new KeyEventHandler (OnFontSizeTextBoxKeyDown);
404 fontTextBox.MouseWheel += new MouseEventHandler (OnFontTextBoxMouseWheel);
405 fontstyleTextBox.MouseWheel += new MouseEventHandler (OnFontStyleTextBoxMouseWheel);
406 fontsizeTextBox.MouseWheel += new MouseEventHandler (OnFontSizeTextBoxMouseWheel);
410 #endregion // Public Constructors
412 #region Public Instance Properties
421 font = new Font(value, value.Style);
423 currentFontStyle = font.Style;
424 currentSize = font.Size;
425 currentFontName = font.Name;
427 int index = fontListBox.FindString (currentFontName);
430 fontListBox.SelectedIndex = index;
432 fontListBox.SelectedIndex = 0;
435 fontListBox.TopIndex = fontListBox.SelectedIndex;
440 [DefaultValue(false)]
441 public bool FontMustExist
444 return fontMustExist;
448 fontMustExist = value;
453 [DefaultValue ("Color [Black]")]
459 examplePanel.Invalidate( );
468 public bool AllowSimulations
471 allowSimulations = value;
475 return allowSimulations;
480 public bool AllowVectorFonts
483 allowVectorFonts = value;
487 return allowVectorFonts;
492 public bool AllowVerticalFonts
495 allowVerticalFonts = value;
499 return allowVerticalFonts;
504 public bool AllowScriptChange
507 allowScriptChange = value;
511 return allowScriptChange;
515 [DefaultValue(false)]
516 public bool FixedPitchOnly
519 fixedPitchOnly = value;
523 return fixedPitchOnly;
536 if (maxSize < minSize)
539 CreateFontSizeListBoxItems ();
556 if (minSize > maxSize)
559 CreateFontSizeListBoxItems ();
561 if (minSize > currentSize)
565 currentSize = minSize;
567 font = new Font( currentFamily, currentSize, currentFontStyle );
569 UpdateExamplePanel ();
571 fontsizeTextBox.Text = currentSize.ToString ();
580 [DefaultValue(false)]
581 public bool ScriptsOnly
592 [DefaultValue(false)]
593 public bool ShowApply
596 if (value != showApply)
614 [DefaultValue(false)]
615 public bool ShowColor
618 if (value != showColor)
622 colorComboBox.Show ();
624 colorComboBox.Hide ();
636 public bool ShowEffects
639 if (value != showEffects)
643 effectsGroupBox.Show ();
645 effectsGroupBox.Hide ();
656 [DefaultValue(false)]
660 if (value != showHelp)
677 #endregion // Public Instance Properties
679 #region Protected Instance Properties
680 protected int Options {
683 #endregion // Protected Instance Properties
685 #region Public Instance Methods
686 public override void Reset( )
689 allowSimulations = true;
690 allowVectorFonts = true;
691 allowVerticalFonts = true;
692 allowScriptChange = true;
693 fixedPitchOnly = false;
697 CreateFontSizeListBoxItems ();
705 colorComboBox.Hide ();
708 effectsGroupBox.Show ();
716 public override string ToString ()
719 return base.ToString ();
720 return String.Concat (base.ToString (), ", Font: ", font.ToString ());
722 #endregion // Public Instance Methods
724 #region Protected Instance Methods
725 protected override IntPtr HookProc (IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
727 return base.HookProc (hWnd, msg, wparam, lparam);
730 protected override bool RunDialog( IntPtr hwndOwner )
737 internal void OnApplyButton (object sender, EventArgs e)
742 protected virtual void OnApply (EventArgs e)
744 EventHandler apply = (EventHandler) Events [EventApply];
748 #endregion // Protected Instance Methods
750 void OnClickCancelButton( object sender, EventArgs e )
752 form.DialogResult = DialogResult.Cancel;
755 void OnClickOkButton( object sender, EventArgs e )
757 form.DialogResult = DialogResult.OK;
760 void OnPaintExamplePanel( object sender, PaintEventArgs e )
762 SolidBrush brush = ThemeEngine.Current.ResPool.GetSolidBrush( color );
764 e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( SystemColors.Control ), 0, 0, 156, 40 );
766 SizeF fontSizeF = e.Graphics.MeasureString( example_panel_text, font );
768 int text_width = (int)fontSizeF.Width;
769 int text_height = (int)fontSizeF.Height;
771 int x = ( examplePanel.Width / 2 ) - ( text_width / 2 );
774 int y = ( examplePanel.Height / 2 ) - ( text_height / 2 );
776 e.Graphics.DrawString( example_panel_text, font, brush, new Point( x, y ) );
779 void OnSelectedIndexChangedFontListBox( object sender, EventArgs e )
781 if ( fontListBox.SelectedIndex != -1 )
783 currentFamily = FindByName( fontListBox.Items[ fontListBox.SelectedIndex ].ToString( ) );
785 fontTextBox.Text = currentFamily.Name;
787 internal_change = true;
789 UpdateFontStyleListBox( );
791 UpdateFontSizeListBox ();
793 UpdateExamplePanel ();
795 form.Select(fontTextBox);
797 internal_change = false;
801 void OnSelectedIndexChangedSizeListBox( object sender, EventArgs e )
803 if ( fontsizeListBox.SelectedIndex != -1 )
805 currentSize = (float)System.Convert.ToDouble( fontsizeListBox.Items[ fontsizeListBox.SelectedIndex ] );
807 fontsizeTextBox.Text = currentSize.ToString( );
809 UpdateExamplePanel( );
811 if (!internal_change)
812 form.Select(fontsizeTextBox);
816 void OnSelectedIndexChangedFontStyleListBox( object sender, EventArgs e )
818 if ( fontstyleListBox.SelectedIndex != -1 )
820 switch ( fontstyleListBox.SelectedIndex )
823 currentFontStyle = FontStyle.Regular;
826 currentFontStyle = FontStyle.Bold;
829 currentFontStyle = FontStyle.Italic;
832 currentFontStyle = FontStyle.Bold | FontStyle.Italic;
835 currentFontStyle = FontStyle.Regular;
840 currentFontStyle = currentFontStyle | FontStyle.Underline;
843 currentFontStyle = currentFontStyle | FontStyle.Strikeout;
845 fontstyleTextBox.Text = fontstyleListBox.Items[ fontstyleListBox.SelectedIndex ].ToString( );
847 if (!internal_change) {
848 UpdateExamplePanel( );
850 form.Select(fontstyleTextBox);
855 void OnCheckedChangedUnderlinedCheckBox( object sender, EventArgs e )
857 if ( underlinedCheckBox.Checked ) {
858 currentFontStyle = currentFontStyle | FontStyle.Underline;
862 currentFontStyle = currentFontStyle ^ FontStyle.Underline;
866 UpdateExamplePanel( );
869 void OnCheckedChangedStrikethroughCheckBox( object sender, EventArgs e )
871 if ( strikethroughCheckBox.Checked ) {
872 currentFontStyle = currentFontStyle | FontStyle.Strikeout;
873 strikethrough = true;
876 currentFontStyle = currentFontStyle ^ FontStyle.Strikeout;
877 strikethrough = false;
880 UpdateExamplePanel( );
883 bool internal_textbox_change = false;
885 void OnFontTextBoxMouseWheel (object sender, MouseEventArgs e)
887 fontListBox.SendMouseWheelEvent (e);
890 void OnFontStyleTextBoxMouseWheel (object sender, MouseEventArgs e)
892 fontstyleListBox.SendMouseWheelEvent (e);
895 void OnFontSizeTextBoxMouseWheel (object sender, MouseEventArgs e)
897 fontsizeListBox.SendMouseWheelEvent (e);
900 void OnFontTextBoxKeyDown (object sender, KeyEventArgs e)
902 if (e.KeyCode == Keys.Up) {
903 int sel_index = fontListBox.SelectedIndex;
910 fontListBox.SelectedIndex = sel_index;
911 } else if (e.KeyCode == Keys.Down) {
912 int sel_index = fontListBox.SelectedIndex;
916 if (sel_index > fontListBox.Items.Count - 1)
917 sel_index = fontListBox.Items.Count - 1;
919 fontListBox.SelectedIndex = sel_index;
923 void OnFontStyleTextBoxKeyDown (object sender, KeyEventArgs e)
925 if (e.KeyCode == Keys.Up) {
926 int sel_index = fontstyleListBox.SelectedIndex;
933 fontstyleListBox.SelectedIndex = sel_index;
934 } else if (e.KeyCode == Keys.Down) {
935 int sel_index = fontstyleListBox.SelectedIndex;
939 if (sel_index > fontstyleListBox.Items.Count - 1)
940 sel_index = fontstyleListBox.Items.Count - 1;
942 fontstyleListBox.SelectedIndex = sel_index;
946 void OnFontSizeTextBoxKeyDown (object sender, KeyEventArgs e)
948 if (e.KeyCode == Keys.Up) {
949 int sel_index = fontsizeListBox.SelectedIndex;
956 fontsizeListBox.SelectedIndex = sel_index;
957 } else if (e.KeyCode == Keys.Down) {
958 int sel_index = fontsizeListBox.SelectedIndex;
962 if (sel_index > fontsizeListBox.Items.Count - 1)
963 sel_index = fontsizeListBox.Items.Count - 1;
965 fontsizeListBox.SelectedIndex = sel_index;
969 void OnFontTextBoxKeyPress (object sender, KeyPressEventArgs e)
971 internal_textbox_change = true;
973 if (fontListBox.SelectedIndex > -1)
974 fontListBox.SelectedIndex = -1;
977 void OnFontStyleTextBoxKeyPress (object sender, KeyPressEventArgs e)
979 internal_textbox_change = true;
981 if (fontstyleListBox.SelectedIndex > -1)
982 fontstyleListBox.SelectedIndex = -1;
985 void OnFontSizeTextBoxKeyPress (object sender, KeyPressEventArgs e)
987 if (Char.IsLetter (e.KeyChar) || Char.IsWhiteSpace (e.KeyChar) || Char.IsPunctuation (e.KeyChar) || e.KeyChar == ',') {
992 internal_textbox_change = true;
995 void OnFontTextBoxTextChanged (object sender, EventArgs e)
997 if (!internal_textbox_change)
1000 internal_textbox_change = false;
1002 for (int i = 0; i < fontListBox.Items.Count; i++) {
1003 string name = fontListBox.Items [i] as string;
1005 if (name.StartsWith(fontTextBox.Text)) {
1006 if (name == fontTextBox.Text)
1007 fontListBox.SelectedIndex = i;
1009 fontListBox.TopIndex = i;
1016 void OnFontStyleTextTextChanged (object sender, EventArgs e)
1018 if (!internal_textbox_change)
1021 internal_textbox_change = false;
1023 for (int i = 0; i < fontstyleListBox.Items.Count; i++) {
1024 string name = fontstyleListBox.Items [i] as string;
1026 if (name.StartsWith(fontstyleTextBox.Text)) {
1027 if (name == fontstyleTextBox.Text)
1028 fontstyleListBox.SelectedIndex = i;
1035 void OnFontSizeTextBoxTextChanged (object sender, EventArgs e)
1037 if (!internal_textbox_change)
1040 internal_textbox_change = false;
1042 if (fontsizeTextBox.Text.Length == 0)
1045 for (int i = 0; i < fontsizeListBox.Items.Count; i++) {
1046 string name = fontsizeListBox.Items [i] as string;
1048 if (name.StartsWith(fontsizeTextBox.Text)) {
1049 if (name == fontsizeTextBox.Text)
1050 fontsizeListBox.SelectedIndex = i;
1052 fontsizeListBox.TopIndex = i;
1059 void OnSelectedIndexChangedScriptComboBox (object sender, EventArgs e)
1061 string tmp_str = char_sets [scriptComboBox.SelectedIndex];
1063 if (tmp_str.Length > 0) {
1064 example_panel_text = tmp_str;
1066 UpdateExamplePanel ();
1070 void UpdateExamplePanel( )
1075 font = new Font( currentFamily, currentSize, currentFontStyle );
1077 examplePanel.Invalidate( );
1080 void UpdateFontSizeListBox ()
1082 int index = fontsizeListBox.FindString(currentSize.ToString());
1085 fontsizeListBox.SelectedIndex = index;
1087 fontsizeListBox.SelectedIndex = 0;
1090 void UpdateFontStyleListBox( )
1092 // don't know if that works, IsStyleAvailable returns true for all styles under X
1094 fontstyleListBox.BeginUpdate( );
1096 fontstyleListBox.Items.Clear( );
1101 if ( currentFamily.IsStyleAvailable( FontStyle.Regular ) )
1103 index = fontstyleListBox.Items.Add( "Regular" );
1105 if ((currentFontStyle & FontStyle.Regular) == FontStyle.Regular)
1109 if ( currentFamily.IsStyleAvailable( FontStyle.Bold ) )
1111 index = fontstyleListBox.Items.Add( "Bold" );
1113 if ((currentFontStyle & FontStyle.Bold) == FontStyle.Bold)
1117 if ( currentFamily.IsStyleAvailable( FontStyle.Italic ) )
1119 index = fontstyleListBox.Items.Add( "Italic" );
1121 if ((currentFontStyle & FontStyle.Italic) == FontStyle.Italic)
1125 if ( currentFamily.IsStyleAvailable( FontStyle.Bold ) && currentFamily.IsStyleAvailable( FontStyle.Italic ) )
1127 index = fontstyleListBox.Items.Add( "Bold Italic" );
1129 if ((currentFontStyle & (FontStyle.Bold | FontStyle.Italic)) == (FontStyle.Bold | FontStyle.Italic))
1133 if (fontstyleListBox.Items.Count > 0)
1134 fontstyleListBox.SelectedIndex = to_select;
1136 fontstyleListBox.EndUpdate( );
1139 FontFamily FindByName( string name )
1141 return fontHash[ name ] as FontFamily;
1144 void CreateFontSizeListBoxItems ()
1146 fontsizeListBox.BeginUpdate ();
1148 fontsizeListBox.Items. Clear();
1150 if (minSize == 0 && maxSize == 0)
1152 foreach (int i in a_sizes)
1153 fontsizeListBox.Items.Add (i.ToString());
1155 foreach (int i in a_sizes) {
1156 if (i >= minSize && i <= maxSize)
1157 fontsizeListBox.Items.Add (i.ToString());
1161 fontsizeListBox.EndUpdate ();
1164 internal class ColorComboBox : ComboBox
1166 internal class ColorComboBoxItem
1168 private Color color;
1169 private string name;
1171 public ColorComboBoxItem( Color color, string name )
1200 private Color selectedColor;
1202 private FontDialog fontDialog;
1204 public ColorComboBox( FontDialog fontDialog )
1206 this.fontDialog = fontDialog;
1208 DropDownStyle = ComboBoxStyle.DropDownList;
1209 DrawMode = DrawMode.OwnerDrawFixed;
1211 Items.AddRange( new object[] {
1212 new ColorComboBoxItem( Color.Black, "Black" ),
1213 new ColorComboBoxItem( Color.DarkRed, "Dark-Red" ),
1214 new ColorComboBoxItem( Color.Green, "Green" ),
1215 new ColorComboBoxItem( Color.Olive, "Olive-Green" ), // color not correct
1216 new ColorComboBoxItem( Color.Aquamarine, "Aquamarine" ), // color not correct
1217 new ColorComboBoxItem( Color.Crimson, "Crimson" ),
1218 new ColorComboBoxItem( Color.Cyan, "Cyan" ),
1219 new ColorComboBoxItem( Color.Gray, "Gray" ),
1220 new ColorComboBoxItem( Color.Silver, "Silver" ),
1221 new ColorComboBoxItem( Color.Red, "Red" ),
1222 new ColorComboBoxItem( Color.YellowGreen, "Yellow-Green" ),
1223 new ColorComboBoxItem( Color.Yellow, "Yellow" ),
1224 new ColorComboBoxItem( Color.Blue, "Blue" ),
1225 new ColorComboBoxItem( Color.Purple, "Purple" ),
1226 new ColorComboBoxItem( Color.Aquamarine, "Aquamarine" ),
1227 new ColorComboBoxItem( Color.White, "White" ) }
1233 protected override void OnDrawItem( DrawItemEventArgs e )
1235 if ( e.Index == -1 )
1238 ColorComboBoxItem ccbi = Items[ e.Index ] as ColorComboBoxItem;
1240 Rectangle r = e.Bounds;
1243 if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected )
1245 e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( Color.Blue ), e.Bounds ); // bot blue
1246 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 );
1247 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 );
1248 e.Graphics.DrawString( ccbi.Name, this.Font, ThemeEngine.Current.ResPool.GetSolidBrush( Color.White ), r );
1252 e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( Color.White ), e.Bounds );
1253 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 );
1254 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 );
1255 e.Graphics.DrawString( ccbi.Name, this.Font, ThemeEngine.Current.ResPool.GetSolidBrush( Color.Black ), r );
1259 protected override void OnSelectedIndexChanged( EventArgs e )
1261 ColorComboBoxItem ccbi = Items[ SelectedIndex ] as ColorComboBoxItem;
1262 selectedColor = ccbi.Color;
1264 fontDialog.Color = selectedColor;
1268 public event EventHandler Apply {
1269 add { Events.AddHandler (EventApply, value); }
1270 remove { Events.RemoveHandler (EventApply, value); }
1274 internal class MouseWheelListBox : ListBox
1276 public void SendMouseWheelEvent(MouseEventArgs e)