* TextBoxBase.cs: Use the new SuspendRecalc/ResumeRecalc methods
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / FontDialog.cs
blob0206a0536815a6a0bc286c97fe4d579f28603e5c
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:
8 //
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
22 // Authors:
23 // Alexander Olk alex.olk@googlemail.com
27 // NOT COMPLETE - work in progress
29 using System.ComponentModel;
30 using System.Drawing;
31 using System.Text.RegularExpressions;
32 using System;
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 ();
43 private Font font;
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 = {
110 "Western",
111 "Symbol",
112 "Shift Jis",
113 "Hangul",
114 "GB2312",
115 "BIG5",
116 "Greek",
117 "Turkish",
118 "Hebrew",
119 "Arabic",
120 "Baltic",
121 "Vietname",
122 "Cyrillic",
123 "East European",
124 "Thai",
125 "Johab",
126 "Mac",
127 "OEM",
128 "VISCII",
129 "TCVN",
130 "KOI-8",
131 "ISO-8859-3",
132 "ISO-8859-4",
133 "ISO-8859-10",
134 "Celtic"
137 private string [] char_sets = {
138 "AaBbYyZz",
139 "Symbol",
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,
148 "AaBbYyZz",
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",
154 "AaBbYyZz",
155 "AaBb" + (char)0xf8 + (char)0xf1 + (char)0xfd,
165 private string example_panel_text;
167 private bool internal_change = false;
169 #region Public Constructors
170 public FontDialog( )
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;
210 // fontsizeListBox
211 fontsizeListBox.Location = new Point( 284, 47 );
212 fontsizeListBox.Size = new Size( 52, 95 );
213 fontsizeListBox.TabIndex = 10;
214 fontListBox.Sorted = true;
215 // fontTextBox
216 fontTextBox.Location = new Point( 16, 26 );
217 fontTextBox.Size = new Size( 140, 21 );
218 fontTextBox.TabIndex = 5;
219 fontTextBox.Text = "";
220 // fontstyleLabel
221 fontstyleLabel.Location = new Point( 164, 10 );
222 fontstyleLabel.Size = new Size( 100, 16 );
223 fontstyleLabel.TabIndex = 1;
224 fontstyleLabel.Text = "Font Style:";
225 // typesizeTextBox
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;
231 // schriftartListBox
232 fontListBox.Location = new Point( 16, 47 );
233 fontListBox.Size = new Size( 140, 95 );
234 fontListBox.TabIndex = 8;
235 fontListBox.Sorted = true;
236 // exampleGroupBox
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";
244 // fontstyleListBox
245 fontstyleListBox.Location = new Point( 164, 47 );
246 fontstyleListBox.Size = new Size( 112, 95 );
247 fontstyleListBox.TabIndex = 9;
248 // schriftartLabel
249 fontLabel.Location = new Point( 16, 10 );
250 fontLabel.Size = new Size( 88, 16 );
251 fontLabel.TabIndex = 0;
252 fontLabel.Text = "Font:";
253 // effectsGroupBox
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";
268 // colorComboBox
269 colorComboBox.Location = new Point( 8, 70 );
270 colorComboBox.Size = new Size( 130, 21 );
271 // sizeLabel
272 sizeLabel.Location = new Point( 284, 10 );
273 sizeLabel.Size = new Size( 100, 16 );
274 sizeLabel.TabIndex = 2;
275 sizeLabel.Text = "Size:";
276 // scriptComboBox
277 scriptComboBox.Location = new Point( 164, 253 );
278 scriptComboBox.Size = new Size( 172, 21 );
279 scriptComboBox.TabIndex = 14;
280 scriptComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
281 // okButton
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";
287 // cancelButton
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";
293 // applyButton
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";
299 // helpButton
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";
310 // fontstyleTextBox
311 fontstyleTextBox.Location = new Point( 164, 26 );
312 fontstyleTextBox.Size = new Size( 112, 21 );
313 fontstyleTextBox.TabIndex = 6;
314 fontstyleTextBox.Text = "";
315 // scriptLabel
316 scriptLabel.Location = new Point( 164, 236 );
317 scriptLabel.Size = new Size( 100, 16 );
318 scriptLabel.TabIndex = 13;
319 scriptLabel.Text = "Script:";
320 // examplePanel
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;
354 form.Text = "Font";
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 ();
377 applyButton.Hide( );
378 helpButton.Hide( );
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);
408 Font = form.Font;
410 #endregion // Public Constructors
412 #region Public Instance Properties
413 public Font Font
415 get {
416 return font;
419 set {
420 if (value != null) {
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);
429 if (index != -1) {
430 fontListBox.SelectedIndex = index;
431 } else {
432 fontListBox.SelectedIndex = 0;
435 fontListBox.TopIndex = fontListBox.SelectedIndex;
440 [DefaultValue(false)]
441 public bool FontMustExist
443 get {
444 return fontMustExist;
447 set {
448 fontMustExist = value;
452 #if NET_2_0
453 [DefaultValue ("Color [Black]")]
454 #endif
455 public Color Color
457 set {
458 color = value;
459 examplePanel.Invalidate( );
462 get {
463 return color;
467 [DefaultValue(true)]
468 public bool AllowSimulations
470 set {
471 allowSimulations = value;
474 get {
475 return allowSimulations;
479 [DefaultValue(true)]
480 public bool AllowVectorFonts
482 set {
483 allowVectorFonts = value;
486 get {
487 return allowVectorFonts;
491 [DefaultValue(true)]
492 public bool AllowVerticalFonts
494 set {
495 allowVerticalFonts = value;
498 get {
499 return allowVerticalFonts;
503 [DefaultValue(true)]
504 public bool AllowScriptChange
506 set {
507 allowScriptChange = value;
510 get {
511 return allowScriptChange;
515 [DefaultValue(false)]
516 public bool FixedPitchOnly
518 set {
519 fixedPitchOnly = value;
522 get {
523 return fixedPitchOnly;
527 [DefaultValue(0)]
528 public int MaxSize
530 set {
531 maxSize = value;
533 if (maxSize < 0)
534 maxSize = 0;
536 if (maxSize < minSize)
537 minSize = maxSize;
539 CreateFontSizeListBoxItems ();
542 get {
543 return maxSize;
547 [DefaultValue(0)]
548 public int MinSize
550 set {
551 minSize = value;
553 if (minSize < 0)
554 minSize = 0;
556 if (minSize > maxSize)
557 maxSize = minSize;
559 CreateFontSizeListBoxItems ();
561 if (minSize > currentSize)
562 if (font != null) {
563 font.Dispose();
565 currentSize = minSize;
567 font = new Font( currentFamily, currentSize, currentFontStyle );
569 UpdateExamplePanel ();
571 fontsizeTextBox.Text = currentSize.ToString ();
575 get {
576 return minSize;
580 [DefaultValue(false)]
581 public bool ScriptsOnly
583 set {
584 scriptsOnly = value;
587 get {
588 return scriptsOnly;
592 [DefaultValue(false)]
593 public bool ShowApply
595 set {
596 if (value != showApply)
598 showApply = value;
599 if (showApply)
600 applyButton.Show ();
601 else
602 applyButton.Hide ();
604 form.Refresh();
609 get {
610 return showApply;
614 [DefaultValue(false)]
615 public bool ShowColor
617 set {
618 if (value != showColor)
620 showColor = value;
621 if (showColor)
622 colorComboBox.Show ();
623 else
624 colorComboBox.Hide ();
626 form.Refresh();
630 get {
631 return showColor;
635 [DefaultValue(true)]
636 public bool ShowEffects
638 set {
639 if (value != showEffects)
641 showEffects = value;
642 if (showEffects)
643 effectsGroupBox.Show ();
644 else
645 effectsGroupBox.Hide ();
647 form.Refresh();
651 get {
652 return showEffects;
656 [DefaultValue(false)]
657 public bool ShowHelp
659 set {
660 if (value != showHelp)
662 showHelp = value;
663 if (showHelp)
664 helpButton.Show ();
665 else
666 helpButton.Hide ();
668 form.Refresh();
672 get {
673 return showHelp;
677 #endregion // Public Instance Properties
679 #region Protected Instance Properties
680 protected int Options {
681 get { return 0; }
683 #endregion // Protected Instance Properties
685 #region Public Instance Methods
686 public override void Reset( )
688 color = Color.Black;
689 allowSimulations = true;
690 allowVectorFonts = true;
691 allowVerticalFonts = true;
692 allowScriptChange = true;
693 fixedPitchOnly = false;
695 maxSize = 0;
696 minSize = 0;
697 CreateFontSizeListBoxItems ();
699 scriptsOnly = false;
701 showApply = false;
702 applyButton.Hide ();
704 showColor = false;
705 colorComboBox.Hide ();
707 showEffects = true;
708 effectsGroupBox.Show ();
710 showHelp = false;
711 helpButton.Hide ();
713 form.Refresh ();
716 public override string ToString ()
718 if (font == null)
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 )
732 form.Refresh();
734 return true;
737 internal void OnApplyButton (object sender, EventArgs e)
739 OnApply (e);
742 protected virtual void OnApply (EventArgs e)
744 EventHandler apply = (EventHandler) Events [EventApply];
745 if (apply != null)
746 apply (this, e);
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 );
772 if ( x < 0 ) x = 0;
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 )
822 case 0:
823 currentFontStyle = FontStyle.Regular;
824 break;
825 case 1:
826 currentFontStyle = FontStyle.Bold;
827 break;
828 case 2:
829 currentFontStyle = FontStyle.Italic;
830 break;
831 case 3:
832 currentFontStyle = FontStyle.Bold | FontStyle.Italic;
833 break;
834 default:
835 currentFontStyle = FontStyle.Regular;
836 break;
839 if (underlined)
840 currentFontStyle = currentFontStyle | FontStyle.Underline;
842 if (strikethrough)
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;
859 underlined = true;
861 else {
862 currentFontStyle = currentFontStyle ^ FontStyle.Underline;
863 underlined = false;
866 UpdateExamplePanel( );
869 void OnCheckedChangedStrikethroughCheckBox( object sender, EventArgs e )
871 if ( strikethroughCheckBox.Checked ) {
872 currentFontStyle = currentFontStyle | FontStyle.Strikeout;
873 strikethrough = true;
875 else {
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;
905 sel_index--;
907 if (sel_index < 0)
908 sel_index = 0;
910 fontListBox.SelectedIndex = sel_index;
911 } else if (e.KeyCode == Keys.Down) {
912 int sel_index = fontListBox.SelectedIndex;
914 sel_index++;
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;
928 sel_index--;
930 if (sel_index < 0)
931 sel_index = 0;
933 fontstyleListBox.SelectedIndex = sel_index;
934 } else if (e.KeyCode == Keys.Down) {
935 int sel_index = fontstyleListBox.SelectedIndex;
937 sel_index++;
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;
951 sel_index--;
953 if (sel_index < 0)
954 sel_index = 0;
956 fontsizeListBox.SelectedIndex = sel_index;
957 } else if (e.KeyCode == Keys.Down) {
958 int sel_index = fontsizeListBox.SelectedIndex;
960 sel_index++;
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 == ',') {
988 e.Handled = true;
989 return;
992 internal_textbox_change = true;
995 void OnFontTextBoxTextChanged (object sender, EventArgs e)
997 if (!internal_textbox_change)
998 return;
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;
1008 else
1009 fontListBox.TopIndex = i;
1011 break;
1016 void OnFontStyleTextTextChanged (object sender, EventArgs e)
1018 if (!internal_textbox_change)
1019 return;
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;
1030 break;
1035 void OnFontSizeTextBoxTextChanged (object sender, EventArgs e)
1037 if (!internal_textbox_change)
1038 return;
1040 internal_textbox_change = false;
1042 if (fontsizeTextBox.Text.Length == 0)
1043 return;
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;
1051 else
1052 fontsizeListBox.TopIndex = i;
1054 break;
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( )
1072 if (font != null)
1073 font.Dispose();
1075 font = new Font( currentFamily, currentSize, currentFontStyle );
1077 examplePanel.Invalidate( );
1080 void UpdateFontSizeListBox ()
1082 int index = fontsizeListBox.FindString(currentSize.ToString());
1084 if (index != -1)
1085 fontsizeListBox.SelectedIndex = index;
1086 else
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( );
1098 int index = -1;
1099 int to_select = 0;
1101 if ( currentFamily.IsStyleAvailable( FontStyle.Regular ) )
1103 index = fontstyleListBox.Items.Add( "Regular" );
1105 if ((currentFontStyle & FontStyle.Regular) == FontStyle.Regular)
1106 to_select = index;
1109 if ( currentFamily.IsStyleAvailable( FontStyle.Bold ) )
1111 index = fontstyleListBox.Items.Add( "Bold" );
1113 if ((currentFontStyle & FontStyle.Bold) == FontStyle.Bold)
1114 to_select = index;
1117 if ( currentFamily.IsStyleAvailable( FontStyle.Italic ) )
1119 index = fontstyleListBox.Items.Add( "Italic" );
1121 if ((currentFontStyle & FontStyle.Italic) == FontStyle.Italic)
1122 to_select = index;
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))
1130 to_select = index;
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());
1154 } else {
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 )
1173 this.color = color;
1174 this.name = name;
1177 public Color Color
1179 set {
1180 color = value;
1183 get {
1184 return color;
1188 public string Name
1190 set {
1191 name = value;
1194 get {
1195 return 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" ) }
1230 SelectedIndex = 0;
1233 protected override void OnDrawItem( DrawItemEventArgs e )
1235 if ( e.Index == -1 )
1236 return;
1238 ColorComboBoxItem ccbi = Items[ e.Index ] as ColorComboBoxItem;
1240 Rectangle r = e.Bounds;
1241 r.X = r.X + 24;
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 );
1250 else
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)
1278 OnMouseWheel (e);