* TextBoxBase.cs: Take HideSelection into account when
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / FontDialog.cs
blob722e62692e4e845a1191837080ec883a792b5641
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) 2004 Novell, Inc. (http://www.novell.com)
22 // Authors:
23 // Alexander Olk xenomorph2@onlinehome.de
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 public Color Color
454 set {
455 color = value;
456 examplePanel.Invalidate( );
459 get {
460 return color;
464 [DefaultValue(true)]
465 public bool AllowSimulations
467 set {
468 allowSimulations = value;
471 get {
472 return allowSimulations;
476 [DefaultValue(true)]
477 public bool AllowVectorFonts
479 set {
480 allowVectorFonts = value;
483 get {
484 return allowVectorFonts;
488 [DefaultValue(true)]
489 public bool AllowVerticalFonts
491 set {
492 allowVerticalFonts = value;
495 get {
496 return allowVerticalFonts;
500 [DefaultValue(true)]
501 public bool AllowScriptChange
503 set {
504 allowScriptChange = value;
507 get {
508 return allowScriptChange;
512 [DefaultValue(false)]
513 public bool FixedPitchOnly
515 set {
516 fixedPitchOnly = value;
519 get {
520 return fixedPitchOnly;
524 [DefaultValue(0)]
525 public int MaxSize
527 set {
528 maxSize = value;
530 if (maxSize < 0)
531 maxSize = 0;
533 if (maxSize < minSize)
534 minSize = maxSize;
536 CreateFontSizeListBoxItems ();
539 get {
540 return maxSize;
544 [DefaultValue(0)]
545 public int MinSize
547 set {
548 minSize = value;
550 if (minSize < 0)
551 minSize = 0;
553 if (minSize > maxSize)
554 maxSize = minSize;
556 CreateFontSizeListBoxItems ();
558 if (minSize > currentSize)
559 if (font != null) {
560 font.Dispose();
562 currentSize = minSize;
564 font = new Font( currentFamily, currentSize, currentFontStyle );
566 UpdateExamplePanel ();
568 fontsizeTextBox.Text = currentSize.ToString ();
572 get {
573 return minSize;
577 [DefaultValue(false)]
578 public bool ScriptsOnly
580 set {
581 scriptsOnly = value;
584 get {
585 return scriptsOnly;
589 [DefaultValue(false)]
590 public bool ShowApply
592 set {
593 if (value != showApply)
595 showApply = value;
596 if (showApply)
597 applyButton.Show ();
598 else
599 applyButton.Hide ();
601 form.Refresh();
606 get {
607 return showApply;
611 [DefaultValue(false)]
612 public bool ShowColor
614 set {
615 if (value != showColor)
617 showColor = value;
618 if (showColor)
619 colorComboBox.Show ();
620 else
621 colorComboBox.Hide ();
623 form.Refresh();
627 get {
628 return showColor;
632 [DefaultValue(true)]
633 public bool ShowEffects
635 set {
636 if (value != showEffects)
638 showEffects = value;
639 if (showEffects)
640 effectsGroupBox.Show ();
641 else
642 effectsGroupBox.Hide ();
644 form.Refresh();
648 get {
649 return showEffects;
653 [DefaultValue(false)]
654 public bool ShowHelp
656 set {
657 if (value != showHelp)
659 showHelp = value;
660 if (showHelp)
661 helpButton.Show ();
662 else
663 helpButton.Hide ();
665 form.Refresh();
669 get {
670 return showHelp;
674 #endregion // Public Instance Properties
676 #region Protected Instance Properties
677 protected int Options {
678 get { return 0; }
680 #endregion // Protected Instance Properties
682 #region Public Instance Methods
683 public override void Reset( )
685 color = Color.Black;
686 allowSimulations = true;
687 allowVectorFonts = true;
688 allowVerticalFonts = true;
689 allowScriptChange = true;
690 fixedPitchOnly = false;
692 maxSize = 0;
693 minSize = 0;
694 CreateFontSizeListBoxItems ();
696 scriptsOnly = false;
698 showApply = false;
699 applyButton.Hide ();
701 showColor = false;
702 colorComboBox.Hide ();
704 showEffects = true;
705 effectsGroupBox.Show ();
707 showHelp = false;
708 helpButton.Hide ();
710 form.Refresh ();
713 public override string ToString ()
715 if (font == null)
716 return base.ToString ();
717 return String.Concat (base.ToString (), ", Font: ", font.ToString ());
719 #endregion // Public Instance Methods
721 #region Protected Instance Methods
722 protected override IntPtr HookProc (IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
724 return base.HookProc (hWnd, msg, wparam, lparam);
727 protected override bool RunDialog( IntPtr hwndOwner )
729 form.Refresh();
731 return true;
734 internal void OnApplyButton (object sender, EventArgs e)
736 OnApply (e);
739 protected virtual void OnApply (EventArgs e)
741 EventHandler apply = (EventHandler) Events [EventApply];
742 if (apply != null)
743 apply (this, e);
745 #endregion // Protected Instance Methods
747 void OnClickCancelButton( object sender, EventArgs e )
749 form.DialogResult = DialogResult.Cancel;
752 void OnClickOkButton( object sender, EventArgs e )
754 form.DialogResult = DialogResult.OK;
757 void OnPaintExamplePanel( object sender, PaintEventArgs e )
759 SolidBrush brush = ThemeEngine.Current.ResPool.GetSolidBrush( color );
761 e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( SystemColors.Control ), 0, 0, 156, 40 );
763 SizeF fontSizeF = e.Graphics.MeasureString( example_panel_text, font );
765 int text_width = (int)fontSizeF.Width;
766 int text_height = (int)fontSizeF.Height;
768 int x = ( examplePanel.Width / 2 ) - ( text_width / 2 );
769 if ( x < 0 ) x = 0;
771 int y = ( examplePanel.Height / 2 ) - ( text_height / 2 );
773 e.Graphics.DrawString( example_panel_text, font, brush, new Point( x, y ) );
776 void OnSelectedIndexChangedFontListBox( object sender, EventArgs e )
778 if ( fontListBox.SelectedIndex != -1 )
780 currentFamily = FindByName( fontListBox.Items[ fontListBox.SelectedIndex ].ToString( ) );
782 fontTextBox.Text = currentFamily.Name;
784 internal_change = true;
786 UpdateFontStyleListBox( );
788 UpdateFontSizeListBox ();
790 UpdateExamplePanel ();
792 form.Select(fontTextBox);
794 internal_change = false;
798 void OnSelectedIndexChangedSizeListBox( object sender, EventArgs e )
800 if ( fontsizeListBox.SelectedIndex != -1 )
802 currentSize = (float)System.Convert.ToDouble( fontsizeListBox.Items[ fontsizeListBox.SelectedIndex ] );
804 fontsizeTextBox.Text = currentSize.ToString( );
806 UpdateExamplePanel( );
808 if (!internal_change)
809 form.Select(fontsizeTextBox);
813 void OnSelectedIndexChangedFontStyleListBox( object sender, EventArgs e )
815 if ( fontstyleListBox.SelectedIndex != -1 )
817 switch ( fontstyleListBox.SelectedIndex )
819 case 0:
820 currentFontStyle = FontStyle.Regular;
821 break;
822 case 1:
823 currentFontStyle = FontStyle.Bold;
824 break;
825 case 2:
826 currentFontStyle = FontStyle.Italic;
827 break;
828 case 3:
829 currentFontStyle = FontStyle.Bold | FontStyle.Italic;
830 break;
831 default:
832 currentFontStyle = FontStyle.Regular;
833 break;
836 if (underlined)
837 currentFontStyle = currentFontStyle | FontStyle.Underline;
839 if (strikethrough)
840 currentFontStyle = currentFontStyle | FontStyle.Strikeout;
842 fontstyleTextBox.Text = fontstyleListBox.Items[ fontstyleListBox.SelectedIndex ].ToString( );
844 if (!internal_change) {
845 UpdateExamplePanel( );
847 form.Select(fontstyleTextBox);
852 void OnCheckedChangedUnderlinedCheckBox( object sender, EventArgs e )
854 if ( underlinedCheckBox.Checked ) {
855 currentFontStyle = currentFontStyle | FontStyle.Underline;
856 underlined = true;
858 else {
859 currentFontStyle = currentFontStyle ^ FontStyle.Underline;
860 underlined = false;
863 UpdateExamplePanel( );
866 void OnCheckedChangedStrikethroughCheckBox( object sender, EventArgs e )
868 if ( strikethroughCheckBox.Checked ) {
869 currentFontStyle = currentFontStyle | FontStyle.Strikeout;
870 strikethrough = true;
872 else {
873 currentFontStyle = currentFontStyle ^ FontStyle.Strikeout;
874 strikethrough = false;
877 UpdateExamplePanel( );
880 bool internal_textbox_change = false;
882 void OnFontTextBoxMouseWheel (object sender, MouseEventArgs e)
884 fontListBox.SendMouseWheelEvent (e);
887 void OnFontStyleTextBoxMouseWheel (object sender, MouseEventArgs e)
889 fontstyleListBox.SendMouseWheelEvent (e);
892 void OnFontSizeTextBoxMouseWheel (object sender, MouseEventArgs e)
894 fontsizeListBox.SendMouseWheelEvent (e);
897 void OnFontTextBoxKeyDown (object sender, KeyEventArgs e)
899 if (e.KeyCode == Keys.Up) {
900 int sel_index = fontListBox.SelectedIndex;
902 sel_index--;
904 if (sel_index < 0)
905 sel_index = 0;
907 fontListBox.SelectedIndex = sel_index;
908 } else if (e.KeyCode == Keys.Down) {
909 int sel_index = fontListBox.SelectedIndex;
911 sel_index++;
913 if (sel_index > fontListBox.Items.Count - 1)
914 sel_index = fontListBox.Items.Count - 1;
916 fontListBox.SelectedIndex = sel_index;
920 void OnFontStyleTextBoxKeyDown (object sender, KeyEventArgs e)
922 if (e.KeyCode == Keys.Up) {
923 int sel_index = fontstyleListBox.SelectedIndex;
925 sel_index--;
927 if (sel_index < 0)
928 sel_index = 0;
930 fontstyleListBox.SelectedIndex = sel_index;
931 } else if (e.KeyCode == Keys.Down) {
932 int sel_index = fontstyleListBox.SelectedIndex;
934 sel_index++;
936 if (sel_index > fontstyleListBox.Items.Count - 1)
937 sel_index = fontstyleListBox.Items.Count - 1;
939 fontstyleListBox.SelectedIndex = sel_index;
943 void OnFontSizeTextBoxKeyDown (object sender, KeyEventArgs e)
945 if (e.KeyCode == Keys.Up) {
946 int sel_index = fontsizeListBox.SelectedIndex;
948 sel_index--;
950 if (sel_index < 0)
951 sel_index = 0;
953 fontsizeListBox.SelectedIndex = sel_index;
954 } else if (e.KeyCode == Keys.Down) {
955 int sel_index = fontsizeListBox.SelectedIndex;
957 sel_index++;
959 if (sel_index > fontsizeListBox.Items.Count - 1)
960 sel_index = fontsizeListBox.Items.Count - 1;
962 fontsizeListBox.SelectedIndex = sel_index;
966 void OnFontTextBoxKeyPress (object sender, KeyPressEventArgs e)
968 internal_textbox_change = true;
970 if (fontListBox.SelectedIndex > -1)
971 fontListBox.SelectedIndex = -1;
974 void OnFontStyleTextBoxKeyPress (object sender, KeyPressEventArgs e)
976 internal_textbox_change = true;
978 if (fontstyleListBox.SelectedIndex > -1)
979 fontstyleListBox.SelectedIndex = -1;
982 void OnFontSizeTextBoxKeyPress (object sender, KeyPressEventArgs e)
984 if (Char.IsLetter (e.KeyChar) || Char.IsWhiteSpace (e.KeyChar) || Char.IsPunctuation (e.KeyChar) || e.KeyChar == ',') {
985 e.Handled = true;
986 return;
989 internal_textbox_change = true;
992 void OnFontTextBoxTextChanged (object sender, EventArgs e)
994 if (!internal_textbox_change)
995 return;
997 internal_textbox_change = false;
999 for (int i = 0; i < fontListBox.Items.Count; i++) {
1000 string name = fontListBox.Items [i] as string;
1002 if (name.StartsWith(fontTextBox.Text)) {
1003 if (name == fontTextBox.Text)
1004 fontListBox.SelectedIndex = i;
1005 else
1006 fontListBox.TopIndex = i;
1008 break;
1013 void OnFontStyleTextTextChanged (object sender, EventArgs e)
1015 if (!internal_textbox_change)
1016 return;
1018 internal_textbox_change = false;
1020 for (int i = 0; i < fontstyleListBox.Items.Count; i++) {
1021 string name = fontstyleListBox.Items [i] as string;
1023 if (name.StartsWith(fontstyleTextBox.Text)) {
1024 if (name == fontstyleTextBox.Text)
1025 fontstyleListBox.SelectedIndex = i;
1027 break;
1032 void OnFontSizeTextBoxTextChanged (object sender, EventArgs e)
1034 if (!internal_textbox_change)
1035 return;
1037 internal_textbox_change = false;
1039 if (fontsizeTextBox.Text.Length == 0)
1040 return;
1042 for (int i = 0; i < fontsizeListBox.Items.Count; i++) {
1043 string name = fontsizeListBox.Items [i] as string;
1045 if (name.StartsWith(fontsizeTextBox.Text)) {
1046 if (name == fontsizeTextBox.Text)
1047 fontsizeListBox.SelectedIndex = i;
1048 else
1049 fontsizeListBox.TopIndex = i;
1051 break;
1056 void OnSelectedIndexChangedScriptComboBox (object sender, EventArgs e)
1058 string tmp_str = char_sets [scriptComboBox.SelectedIndex];
1060 if (tmp_str.Length > 0) {
1061 example_panel_text = tmp_str;
1063 UpdateExamplePanel ();
1067 void UpdateExamplePanel( )
1069 if (font != null)
1070 font.Dispose();
1072 font = new Font( currentFamily, currentSize, currentFontStyle );
1074 examplePanel.Invalidate( );
1077 void UpdateFontSizeListBox ()
1079 int index = fontsizeListBox.FindString(currentSize.ToString());
1081 if (index != -1)
1082 fontsizeListBox.SelectedIndex = index;
1083 else
1084 fontsizeListBox.SelectedIndex = 0;
1087 void UpdateFontStyleListBox( )
1089 // don't know if that works, IsStyleAvailable returns true for all styles under X
1091 fontstyleListBox.BeginUpdate( );
1093 fontstyleListBox.Items.Clear( );
1095 int index = -1;
1096 int to_select = 0;
1098 if ( currentFamily.IsStyleAvailable( FontStyle.Regular ) )
1100 index = fontstyleListBox.Items.Add( "Regular" );
1102 if ((currentFontStyle & FontStyle.Regular) == FontStyle.Regular)
1103 to_select = index;
1106 if ( currentFamily.IsStyleAvailable( FontStyle.Bold ) )
1108 index = fontstyleListBox.Items.Add( "Bold" );
1110 if ((currentFontStyle & FontStyle.Bold) == FontStyle.Bold)
1111 to_select = index;
1114 if ( currentFamily.IsStyleAvailable( FontStyle.Italic ) )
1116 index = fontstyleListBox.Items.Add( "Italic" );
1118 if ((currentFontStyle & FontStyle.Italic) == FontStyle.Italic)
1119 to_select = index;
1122 if ( currentFamily.IsStyleAvailable( FontStyle.Bold ) && currentFamily.IsStyleAvailable( FontStyle.Italic ) )
1124 index = fontstyleListBox.Items.Add( "Bold Italic" );
1126 if ((currentFontStyle & (FontStyle.Bold | FontStyle.Italic)) == (FontStyle.Bold | FontStyle.Italic))
1127 to_select = index;
1130 if (fontstyleListBox.Items.Count > 0)
1131 fontstyleListBox.SelectedIndex = to_select;
1133 fontstyleListBox.EndUpdate( );
1136 FontFamily FindByName( string name )
1138 return fontHash[ name ] as FontFamily;
1141 void CreateFontSizeListBoxItems ()
1143 fontsizeListBox.BeginUpdate ();
1145 fontsizeListBox.Items. Clear();
1147 if (minSize == 0 && maxSize == 0)
1149 foreach (int i in a_sizes)
1150 fontsizeListBox.Items.Add (i.ToString());
1151 } else {
1152 foreach (int i in a_sizes) {
1153 if (i >= minSize && i <= maxSize)
1154 fontsizeListBox.Items.Add (i.ToString());
1158 fontsizeListBox.EndUpdate ();
1161 internal class ColorComboBox : ComboBox
1163 internal class ColorComboBoxItem
1165 private Color color;
1166 private string name;
1168 public ColorComboBoxItem( Color color, string name )
1170 this.color = color;
1171 this.name = name;
1174 public Color Color
1176 set {
1177 color = value;
1180 get {
1181 return color;
1185 public string Name
1187 set {
1188 name = value;
1191 get {
1192 return name;
1197 private Color selectedColor;
1199 private FontDialog fontDialog;
1201 public ColorComboBox( FontDialog fontDialog )
1203 this.fontDialog = fontDialog;
1205 DropDownStyle = ComboBoxStyle.DropDownList;
1206 DrawMode = DrawMode.OwnerDrawFixed;
1208 Items.AddRange( new object[] {
1209 new ColorComboBoxItem( Color.Black, "Black" ),
1210 new ColorComboBoxItem( Color.DarkRed, "Dark-Red" ),
1211 new ColorComboBoxItem( Color.Green, "Green" ),
1212 new ColorComboBoxItem( Color.Olive, "Olive-Green" ), // color not correct
1213 new ColorComboBoxItem( Color.Aquamarine, "Aquamarine" ), // color not correct
1214 new ColorComboBoxItem( Color.Crimson, "Crimson" ),
1215 new ColorComboBoxItem( Color.Cyan, "Cyan" ),
1216 new ColorComboBoxItem( Color.Gray, "Gray" ),
1217 new ColorComboBoxItem( Color.Silver, "Silver" ),
1218 new ColorComboBoxItem( Color.Red, "Red" ),
1219 new ColorComboBoxItem( Color.YellowGreen, "Yellow-Green" ),
1220 new ColorComboBoxItem( Color.Yellow, "Yellow" ),
1221 new ColorComboBoxItem( Color.Blue, "Blue" ),
1222 new ColorComboBoxItem( Color.Purple, "Purple" ),
1223 new ColorComboBoxItem( Color.Aquamarine, "Aquamarine" ),
1224 new ColorComboBoxItem( Color.White, "White" ) }
1227 SelectedIndex = 0;
1230 protected override void OnDrawItem( DrawItemEventArgs e )
1232 if ( e.Index == -1 )
1233 return;
1235 ColorComboBoxItem ccbi = Items[ e.Index ] as ColorComboBoxItem;
1237 Rectangle r = e.Bounds;
1238 r.X = r.X + 24;
1240 if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected )
1242 e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( Color.Blue ), e.Bounds ); // bot blue
1243 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 );
1244 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 );
1245 e.Graphics.DrawString( ccbi.Name, this.Font, ThemeEngine.Current.ResPool.GetSolidBrush( Color.White ), r );
1247 else
1249 e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( Color.White ), e.Bounds );
1250 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 );
1251 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 );
1252 e.Graphics.DrawString( ccbi.Name, this.Font, ThemeEngine.Current.ResPool.GetSolidBrush( Color.Black ), r );
1256 protected override void OnSelectedIndexChanged( EventArgs e )
1258 ColorComboBoxItem ccbi = Items[ SelectedIndex ] as ColorComboBoxItem;
1259 selectedColor = ccbi.Color;
1261 fontDialog.Color = selectedColor;
1265 public event EventHandler Apply {
1266 add { Events.AddHandler (EventApply, value); }
1267 remove { Events.RemoveHandler (EventApply, value); }
1271 internal class MouseWheelListBox : ListBox
1273 public void SendMouseWheelEvent(MouseEventArgs e)
1275 OnMouseWheel (e);