* TreeView.cs: Don't draw the selected node when we lose
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / FontDialog.cs
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.
11 //
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.
19 //
20 // Copyright (c) 2004 Novell, Inc. (http://www.novell.com)
21 //
22 // Authors:
23 //      Alexander Olk   xenomorph2@onlinehome.de
24 //
25 //
26
27 // NOT COMPLETE - work in progress
28
29 // TODO:
30 // - select values for font/style/size via the TextBoxes
31 // - etc
32
33 using System.ComponentModel;
34 using System.Drawing;
35 using System.Text.RegularExpressions;
36
37 namespace System.Windows.Forms
38 {
39         [DefaultProperty( "Font" )]
40         [DefaultEvent("Apply")]
41         public class FontDialog : CommonDialog
42         {
43                 private FontDialogPanel fontDialogPanel;
44                 
45                 private Font font;
46                 private Color color = Color.Black;
47                 private bool allowSimulations = true;
48                 private bool allowVectorFonts = true;
49                 private bool allowVerticalFonts = true;
50                 private bool allowScriptChange = true;
51                 private bool fixedPitchOnly = false;
52                 private int maxSize = 0;
53                 private int minSize = 0;
54                 private bool scriptsOnly = false;
55                 private bool showApply = false;
56                 private bool showColor = false;
57                 private bool showEffects = true;
58                 private bool showHelp = false;
59                 
60                 private bool fontMustExist = false;
61                 
62                 #region Public Constructors
63                 public FontDialog( )
64                 {
65                         form.ClientSize = new Size( 430, 318 );
66                         
67                         form.Size = new Size( 430, 318 );
68                         
69                         form.Text = "Font";
70                         
71                         fontDialogPanel = new FontDialogPanel( this );
72                 }
73                 #endregion      // Public Constructors
74                 
75                 #region Public Instance Properties
76                 public Font Font
77                 {
78                         get {
79                                 return font;
80                         }
81                         
82                         set {
83                                 font = value;
84                         }
85                 }
86                 
87                 [DefaultValue(false)]
88                 public bool FontMustExist
89                 {
90                         get {
91                                 return fontMustExist;
92                         }
93                         
94                         set {
95                                 fontMustExist = value;
96                         }
97                 }
98                 
99                 public Color Color
100                 {
101                         set {
102                                 color = value;
103                         }
104                         
105                         get {
106                                 return color;
107                         }
108                 }
109                 
110                 [DefaultValue(true)]
111                 public bool AllowSimulations
112                 {
113                         set {
114                                 allowSimulations = value;
115                         }
116                         
117                         get {
118                                 return allowSimulations;
119                         }
120                 }
121                 
122                 [DefaultValue(true)]
123                 public bool AllowVectorFonts
124                 {
125                         set {
126                                 allowVectorFonts = value;
127                         }
128                         
129                         get {
130                                 return allowVectorFonts;
131                         }
132                 }
133                 
134                 [DefaultValue(true)]
135                 public bool AllowVerticalFonts
136                 {
137                         set {
138                                 allowVerticalFonts = value;
139                         }
140                         
141                         get {
142                                 return allowVerticalFonts;
143                         }
144                 }
145                 
146                 [DefaultValue(true)]
147                 public bool AllowScriptChange
148                 {
149                         set {
150                                 allowScriptChange = value;
151                         }
152                         
153                         get {
154                                 return allowScriptChange;
155                         }
156                 }
157                 
158                 [DefaultValue(false)]
159                 public bool FixedPitchOnly
160                 {
161                         set {
162                                 fixedPitchOnly = value;
163                         }
164                         
165                         get {
166                                 return fixedPitchOnly;
167                         }
168                 }
169                 
170                 [DefaultValue(0)]
171                 public int MaxSize
172                 {
173                         set {
174                                 maxSize = value;
175                         }
176                         
177                         get {
178                                 return maxSize;
179                         }
180                 }
181                 
182                 [DefaultValue(0)]
183                 public int MinSize
184                 {
185                         set {
186                                 minSize = value;
187                         }
188                         
189                         get {
190                                 return minSize;
191                         }
192                 }
193                 
194                 [DefaultValue(false)]
195                 public bool ScriptsOnly
196                 {
197                         set {
198                                 scriptsOnly = value;
199                         }
200                         
201                         get {
202                                 return scriptsOnly;
203                         }
204                 }
205                 
206                 [DefaultValue(false)]
207                 public bool ShowApply
208                 {
209                         set {
210                                 showApply = value;
211                         }
212                         
213                         get {
214                                 return showApply;
215                         }
216                 }
217                 
218                 [DefaultValue(false)]
219                 public bool ShowColor
220                 {
221                         set {
222                                 showColor = value;
223                         }
224                         
225                         get {
226                                 return showColor;
227                         }
228                 }
229                 
230                 [DefaultValue(true)]
231                 public bool ShowEffects
232                 {
233                         set {
234                                 showEffects = value;
235                         }
236                         
237                         get {
238                                 return showEffects;
239                         }
240                 }
241                 
242                 [DefaultValue(false)]
243                 public bool ShowHelp
244                 {
245                         set {
246                                 showHelp = value;
247                         }
248                         
249                         get {
250                                 return showHelp;
251                         }
252                 }
253                 
254                 #endregion      // Public Instance Properties
255                 
256                 #region Protected Instance Properties
257                 #endregion      // Protected Instance Properties
258                 
259                 #region Public Instance Methods
260                 [MonoTODO]
261                 public override void Reset( )
262                 {
263                         color = Color.Black;
264                         allowSimulations = true;
265                         allowVectorFonts = true;
266                         allowVerticalFonts = true;
267                         allowScriptChange = true;
268                         fixedPitchOnly = false;
269                         maxSize = 0;
270                         minSize = 0;
271                         scriptsOnly = false;
272                         showApply = false;
273                         showColor = false;
274                         showEffects = true;
275                         showHelp = false;
276                 }
277                 #endregion      // Public Instance Methods
278                 
279                 #region Protected Instance Methods
280                 [MonoTODO]
281                 protected override bool RunDialog( IntPtr hwndOwner )
282                 {
283                         form.Controls.Add( fontDialogPanel );
284                         
285                         return true;
286                 }
287                 #endregion      // Protected Instance Methods
288         }
289         
290         internal class FontDialogPanel : Panel
291         {
292                 private Panel examplePanel;
293                 
294                 private Button okButton;
295                 private Button cancelButton;
296                 private Button applyButton;
297                 private Button helpButton;
298                 
299                 private TextBox fontTextBox;
300                 private TextBox fontstyleTextBox;
301                 private TextBox sizeTextBox;
302                 
303                 private ListBox fontListBox;
304                 private ListBox fontstyleListBox;
305                 private ListBox sizeListBox;
306                 
307                 private GroupBox effectsGroupBox;
308                 private CheckBox strikethroughCheckBox;
309                 private CheckBox underlinedCheckBox;
310                 private ComboBox scriptComboBox;
311                 
312                 private Label fontLabel;
313                 private Label fontstyleLabel;
314                 private Label sizeLabel;
315                 private Label scriptLabel;
316                 
317                 private GroupBox exampleGroupBox;
318                 
319                 private ColorComboBox colorComboBox;
320                 
321                 private FontFamily[] fontFamilies;
322                 
323                 private string currentFontName;
324                 
325                 private Font currentFont;
326                 
327                 private int currentSize;
328                 
329                 private FontFamily currentFamily;
330                 
331                 private Color currentColor;
332                 
333                 private FontStyle currentFontStyle;
334                 
335                 private FontDialog fontDialog;
336                 
337                 private System.Collections.ArrayList fontStyleArray = new System.Collections.ArrayList();
338                 
339                 private System.Collections.Hashtable fontHash = new System.Collections.Hashtable();
340                 
341                 public FontDialogPanel( FontDialog fontDialog )
342                 {
343                         this.fontDialog = fontDialog;
344                         
345                         okButton = new Button( );
346                         cancelButton = new Button( );
347                         applyButton = new Button( );
348                         helpButton = new Button( );
349                         
350                         fontTextBox = new TextBox( );
351                         fontstyleTextBox = new TextBox( );
352                         sizeTextBox = new TextBox( );
353                         
354                         fontListBox = new ListBox( );
355                         sizeListBox = new ListBox( );
356                         
357                         fontLabel = new Label( );
358                         fontstyleLabel = new Label( );
359                         sizeLabel = new Label( );
360                         scriptLabel = new Label( );
361                         
362                         exampleGroupBox = new GroupBox( );
363                         fontstyleListBox = new ListBox( );
364                         
365                         effectsGroupBox = new GroupBox( );
366                         underlinedCheckBox = new CheckBox( );
367                         strikethroughCheckBox = new CheckBox( );
368                         scriptComboBox = new ComboBox( );
369                         
370                         examplePanel = new Panel( );
371                         
372                         colorComboBox = new ColorComboBox( this );
373                         
374                         exampleGroupBox.SuspendLayout( );
375                         effectsGroupBox.SuspendLayout( );
376                         SuspendLayout( );
377                         
378                         // typesizeListBox
379                         sizeListBox.Location = new Point( 284, 47 );
380                         sizeListBox.Size = new Size( 52, 95 );
381                         sizeListBox.TabIndex = 10;
382                         // fontTextBox
383                         fontTextBox.Location = new Point( 16, 26 );
384                         fontTextBox.Size = new Size( 140, 21 );
385                         fontTextBox.TabIndex = 5;
386                         fontTextBox.Text = "";
387                         // fontstyleLabel
388                         fontstyleLabel.Location = new Point( 164, 10 );
389                         fontstyleLabel.Size = new Size( 100, 16 );
390                         fontstyleLabel.TabIndex = 1;
391                         fontstyleLabel.Text = "Font Style:";
392                         // typesizeTextBox
393                         sizeTextBox.Location = new Point( 284, 26 );
394                         sizeTextBox.Size = new Size( 52, 21 );
395                         sizeTextBox.TabIndex = 7;
396                         sizeTextBox.Text = "";
397                         // schriftartListBox
398                         fontListBox.Location = new Point( 16, 47 );
399                         fontListBox.Size = new Size( 140, 95 );
400                         fontListBox.TabIndex = 8;
401                         fontListBox.Sorted = true;
402                         // exampleGroupBox
403                         exampleGroupBox.Controls.Add( examplePanel );
404                         exampleGroupBox.FlatStyle = FlatStyle.System;
405                         exampleGroupBox.Location = new Point( 164, 158 );
406                         exampleGroupBox.Size = new Size( 172, 70 );
407                         exampleGroupBox.TabIndex = 12;
408                         exampleGroupBox.TabStop = false;
409                         exampleGroupBox.Text = "Example";
410                         // fontstyleListBox
411                         fontstyleListBox.Location = new Point( 164, 47 );
412                         fontstyleListBox.Size = new Size( 112, 95 );
413                         fontstyleListBox.TabIndex = 9;
414                         // schriftartLabel
415                         fontLabel.Location = new Point( 16, 10 );
416                         fontLabel.Size = new Size( 88, 16 );
417                         fontLabel.TabIndex = 0;
418                         fontLabel.Text = "Font:";
419                         // effectsGroupBox
420                         effectsGroupBox.Controls.Add( underlinedCheckBox );
421                         effectsGroupBox.Controls.Add( strikethroughCheckBox );
422                         effectsGroupBox.Controls.Add( colorComboBox );
423                         effectsGroupBox.FlatStyle = FlatStyle.System;
424                         effectsGroupBox.Location = new Point( 16, 158 );
425                         effectsGroupBox.Size = new Size( 140, 116 );
426                         effectsGroupBox.TabIndex = 11;
427                         effectsGroupBox.TabStop = false;
428                         effectsGroupBox.Text = "Effects";
429                         // strikethroughCheckBox
430                         strikethroughCheckBox.FlatStyle = FlatStyle.System;
431                         strikethroughCheckBox.Location = new Point( 8, 16 );
432                         strikethroughCheckBox.TabIndex = 0;
433                         strikethroughCheckBox.Text = "Strikethrough";
434                         // colorComboBox
435                         colorComboBox.Location = new Point( 8, 70 );
436                         colorComboBox.Size = new Size( 130, 21 );
437                         // sizeLabel
438                         sizeLabel.Location = new Point( 284, 10 );
439                         sizeLabel.Size = new Size( 100, 16 );
440                         sizeLabel.TabIndex = 2;
441                         sizeLabel.Text = "Size:";
442                         // scriptComboBox
443                         scriptComboBox.Location = new Point( 164, 253 );
444                         scriptComboBox.Size = new Size( 172, 21 );
445                         scriptComboBox.TabIndex = 14;
446                         scriptComboBox.Text = "-/-";
447                         // okButton
448                         okButton.FlatStyle = FlatStyle.System;
449                         okButton.Location = new Point( 352, 26 );
450                         okButton.Size = new Size( 70, 23 );
451                         okButton.TabIndex = 3;
452                         okButton.Text = "OK";
453                         // cancelButton
454                         cancelButton.FlatStyle = FlatStyle.System;
455                         cancelButton.Location = new Point( 352, 52 );
456                         cancelButton.Size = new Size( 70, 23 );
457                         cancelButton.TabIndex = 4;
458                         cancelButton.Text = "Cancel";
459                         // applyButton
460                         applyButton.FlatStyle = FlatStyle.System;
461                         applyButton.Location = new Point( 352, 78 );
462                         applyButton.Size = new Size( 70, 23 );
463                         applyButton.TabIndex = 5;
464                         applyButton.Text = "Apply";
465                         // helpButton
466                         helpButton.FlatStyle = FlatStyle.System;
467                         helpButton.Location = new Point( 352, 104 );
468                         helpButton.Size = new Size( 70, 23 );
469                         helpButton.TabIndex = 6;
470                         helpButton.Text = "Help";
471                         // underlinedCheckBox
472                         underlinedCheckBox.FlatStyle = FlatStyle.System;
473                         underlinedCheckBox.Location = new Point( 8, 36 );
474                         underlinedCheckBox.TabIndex = 1;
475                         underlinedCheckBox.Text = "Underlined";
476                         // fontstyleTextBox
477                         fontstyleTextBox.Location = new Point( 164, 26 );
478                         fontstyleTextBox.Size = new Size( 112, 21 );
479                         fontstyleTextBox.TabIndex = 6;
480                         fontstyleTextBox.Text = "";
481                         // scriptLabel
482                         scriptLabel.Location = new Point( 164, 236 );
483                         scriptLabel.Size = new Size( 100, 16 );
484                         scriptLabel.TabIndex = 13;
485                         scriptLabel.Text = "Script:";
486                         // examplePanel
487                         examplePanel.Location = new Point( 8, 20 );
488                         examplePanel.TabIndex = 0;
489                         examplePanel.BorderStyle = BorderStyle.Fixed3D;
490                         examplePanel.Size = new Size( 156, 40 );
491                         
492                         ClientSize = new Size( 430, 318 );
493                         
494                         Controls.Add( scriptComboBox );
495                         Controls.Add( scriptLabel );
496                         Controls.Add( exampleGroupBox );
497                         Controls.Add( effectsGroupBox );
498                         Controls.Add( sizeListBox );
499                         Controls.Add( fontstyleListBox );
500                         Controls.Add( fontListBox );
501                         Controls.Add( sizeTextBox );
502                         Controls.Add( fontstyleTextBox );
503                         Controls.Add( fontTextBox );
504                         Controls.Add( cancelButton );
505                         Controls.Add( okButton );
506                         Controls.Add( sizeLabel );
507                         Controls.Add( fontstyleLabel );
508                         Controls.Add( fontLabel );
509                         Controls.Add( applyButton );
510                         Controls.Add( helpButton );
511                         
512                         exampleGroupBox.ResumeLayout( false );
513                         effectsGroupBox.ResumeLayout( false );
514                         
515                         ResumeLayout( false );
516                         
517                         fontFamilies = FontFamily.Families;
518                         
519                         fontListBox.BeginUpdate( );
520                         foreach ( FontFamily ff in fontFamilies )
521                         {
522                                 fontListBox.Items.Add( ff.Name );
523                                 fontHash.Add( ff.Name, ff );
524                         }
525                         fontListBox.EndUpdate( );
526                         
527                         fontListBox.SelectedIndex = 0;
528                         
529                         // TODO: If Font is provided via FontDialog.Font property set correct font in FontListBox
530                         currentFontName = fontListBox.Items[ 0 ].ToString( );
531                         fontTextBox.Text = currentFontName;
532                         
533                         // default 12 ?!?
534                         currentSize = 12;
535                         
536                         currentFamily = FindByName( currentFontName );
537                         
538                         currentFontStyle = FontStyle.Regular;
539                         
540                         currentFont = new Font( currentFamily, currentSize, currentFontStyle );
541                         
542                         currentColor = fontDialog.Color;
543                         
544                         UpdateFontStyleListBox( );
545                         
546                         fontstyleTextBox.Text = "Regular";
547                         
548                         fontstyleListBox.SelectedIndex = 0 ;
549                         
550                         sizeTextBox.Text = currentSize.ToString( );
551                         
552                         sizeListBox.Items.AddRange( new object[] {
553                                                            "8",
554                                                            "9",
555                                                            "10",
556                                                            "11",
557                                                            "12",
558                                                            "14",
559                                                            "16",
560                                                            "18",
561                                                            "20",
562                                                            "22",
563                                                            "24",
564                                                            "26",
565                                                            "28",
566                                                            "36",
567                                                            "48",
568                                                            "72" } );
569                         
570                         sizeListBox.SelectedIndex = 4;
571                         
572                         if ( !fontDialog.ShowApply )
573                                 applyButton.Hide( );
574                         if ( !fontDialog.ShowHelp )
575                                 helpButton.Hide( );
576                         if ( !fontDialog.ShowEffects )
577                                 effectsGroupBox.Hide( );
578                         if ( !fontDialog.ShowColor )
579                                 colorComboBox.Hide( );
580                         
581                         cancelButton.Click += new EventHandler( OnClickCancelButton );
582                         okButton.Click += new EventHandler( OnClickOkButton );
583                         examplePanel.Paint += new PaintEventHandler( OnPaintExamplePanel );
584                         fontListBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedFontListBox );
585                         sizeListBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedSizeListBox );
586                         fontstyleListBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedFontStyleListBox );
587                         underlinedCheckBox.CheckedChanged += new EventHandler( OnCheckedChangedUnderlinedCheckBox );
588                         strikethroughCheckBox.CheckedChanged += new EventHandler( OnCheckedChangedStrikethroughCheckBox );
589                 }
590                 
591                 public Color CurrentColor
592                 {
593                         set {
594                                 currentColor = value;
595                                 examplePanel.Invalidate( );
596                         }
597                         
598                         get {
599                                 return currentColor;
600                         }
601                 }
602                 
603                 private void UpdateFontStyleListBox( )
604                 {
605                         // don't know if that works, IsStyleAvailable returns true for all styles under X
606                         
607                         fontStyleArray.Clear( );
608                         
609                         fontstyleListBox.BeginUpdate( );
610                         
611                         fontstyleListBox.Items.Clear( );
612                         
613                         if ( currentFamily.IsStyleAvailable( FontStyle.Regular ) )
614                         {
615                                 fontstyleListBox.Items.Add( "Regular" );
616                                 fontStyleArray.Add( 0 );
617                         }
618                         
619                         if ( currentFamily.IsStyleAvailable( FontStyle.Bold ) )
620                         {
621                                 fontstyleListBox.Items.Add( "Bold" );
622                                 fontStyleArray.Add( 1 );
623                         }
624                         
625                         if ( currentFamily.IsStyleAvailable( FontStyle.Italic ) )
626                         {
627                                 fontstyleListBox.Items.Add( "Italic" );
628                                 fontStyleArray.Add( 2 );
629                         }
630                         
631                         if ( currentFamily.IsStyleAvailable( FontStyle.Bold ) && currentFamily.IsStyleAvailable( FontStyle.Italic ) )
632                         {
633                                 fontstyleListBox.Items.Add( "Bold Italic" );
634                                 fontStyleArray.Add( 3 );
635                         }
636                         
637                         fontstyleListBox.EndUpdate( );
638                 }
639                 
640                 private FontFamily FindByName( string name )
641                 {
642                         return fontHash[ name ] as FontFamily;
643                 }
644                 
645                 void OnClickCancelButton( object sender, EventArgs e )
646                 {
647                         fontDialog.form.Controls.Remove( this );
648                         fontDialog.form.DialogResult = DialogResult.Cancel;
649                 }
650                 
651                 void OnClickOkButton( object sender, EventArgs e )
652                 {
653                         fontDialog.form.Controls.Remove( this );
654                         fontDialog.Font = currentFont;
655                         fontDialog.Color = currentColor;
656                         fontDialog.form.DialogResult = DialogResult.OK;
657                 }
658                 
659                 void OnPaintExamplePanel( object sender, PaintEventArgs e )
660                 {
661                         SolidBrush brush = ThemeEngine.Current.ResPool.GetSolidBrush( currentColor );
662                         
663                         e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( SystemColors.Control ), 0, 0, 156, 40 );
664                         
665                         string text = "AaBbYyZz";
666                         
667                         SizeF fontSizeF = e.Graphics.MeasureString( text, currentFont );
668                         
669                         int text_width = (int)fontSizeF.Width;
670                         int text_height = (int)fontSizeF.Height;
671                         
672                         int x = ( examplePanel.Width / 2 ) - ( text_width / 2 );
673                         if ( x < 0 ) x = 0;
674                         
675                         int y = ( examplePanel.Height / 2 ) - ( text_height / 2 );
676                         
677                         e.Graphics.DrawString( text, currentFont, brush, new Point( x, y ) );
678                 }
679                 
680                 void OnSelectedIndexChangedFontListBox( object sender, EventArgs e )
681                 {
682                         if ( fontListBox.SelectedIndex != -1 )
683                         {
684                                 currentFamily = FindByName( fontListBox.Items[ fontListBox.SelectedIndex ].ToString( ) );
685                                 
686                                 fontTextBox.Text = currentFamily.Name;
687                                 
688                                 UpdateFontStyleListBox( );
689                                 
690                                 UpdateExamplePanel( );
691                         }
692                 }
693                 
694                 void OnSelectedIndexChangedSizeListBox( object sender, EventArgs e )
695                 {
696                         if ( sizeListBox.SelectedIndex != -1 )
697                         {
698                                 currentSize = System.Convert.ToInt32( sizeListBox.Items[ sizeListBox.SelectedIndex ] );
699                                 
700                                 sizeTextBox.Text = currentSize.ToString( );
701                                 
702                                 UpdateExamplePanel( );
703                         }
704                 }
705                 
706                 void OnSelectedIndexChangedFontStyleListBox( object sender, EventArgs e )
707                 {
708                         if ( fontstyleListBox.SelectedIndex != -1 )
709                         {
710                                 switch ( (int)fontStyleArray[ fontstyleListBox.SelectedIndex ] )
711                                 {
712                                         case 0:
713                                                 currentFontStyle = FontStyle.Regular;
714                                                 break;
715                                         case 1:
716                                                 currentFontStyle = FontStyle.Bold;
717                                                 break;
718                                         case 2:
719                                                 currentFontStyle = FontStyle.Italic;
720                                                 break;
721                                         case 3:
722                                                 currentFontStyle = FontStyle.Bold | FontStyle.Italic;
723                                                 break;
724                                         default:
725                                                 currentFontStyle = FontStyle.Regular;
726                                                 break;
727                                 }
728                                 
729                                 fontstyleTextBox.Text = fontstyleListBox.Items[ fontstyleListBox.SelectedIndex ].ToString( );
730                                 
731                                 UpdateExamplePanel( );
732                         }
733                 }
734                 
735                 void OnCheckedChangedUnderlinedCheckBox( object sender, EventArgs e )
736                 {
737                         if ( underlinedCheckBox.Checked )
738                                 currentFontStyle = currentFontStyle | FontStyle.Underline;
739                         else
740                                 currentFontStyle = currentFontStyle ^ FontStyle.Underline;
741                         
742                         UpdateExamplePanel( );
743                 }
744                 
745                 void OnCheckedChangedStrikethroughCheckBox( object sender, EventArgs e )
746                 {
747                         if ( strikethroughCheckBox.Checked )
748                                 currentFontStyle = currentFontStyle | FontStyle.Strikeout;
749                         else
750                                 currentFontStyle = currentFontStyle ^ FontStyle.Strikeout;
751                         
752                         UpdateExamplePanel( );
753                 }
754                 
755                 private void UpdateExamplePanel( )
756                 {
757                         currentFont = new Font( currentFamily, currentSize, currentFontStyle );
758                         
759                         examplePanel.Invalidate( );
760                         examplePanel.Update( );
761                 }
762                 
763                 internal class ColorComboBox : ComboBox
764                 {
765                         internal class ColorComboBoxItem
766                         {
767                                 private Color color;
768                                 private string name;
769                                 
770                                 public ColorComboBoxItem( Color color, string name )
771                                 {
772                                         this.color = color;
773                                         this.name = name;
774                                 }
775                                 
776                                 public Color Color
777                                 {
778                                         set {
779                                                 color = value;
780                                         }
781                                         
782                                         get {
783                                                 return color;
784                                         }
785                                 }
786                                 
787                                 public string Name
788                                 {
789                                         set {
790                                                 name = value;
791                                         }
792                                         
793                                         get {
794                                                 return name;
795                                         }
796                                 }
797                         }
798                         
799                         private Color selectedColor;
800                         
801                         private FontDialogPanel fontDialogPanel;
802                         
803                         // FIXME: TextBox backcolor shouldn't be the same as the selected item in the ListBox/ListCtrl
804                         
805                         public ColorComboBox( FontDialogPanel fontDialogPanel )
806                         {
807                                 this.fontDialogPanel = fontDialogPanel;
808                                 
809                                 DropDownStyle = ComboBoxStyle.DropDownList;
810                                 DrawMode = DrawMode.OwnerDrawFixed;
811                                 
812                                 Items.AddRange( new object[] {
813                                                        new ColorComboBoxItem( Color.Black, "Black" ),
814                                                        new ColorComboBoxItem( Color.DarkRed, "Dark-Red" ),
815                                                        new ColorComboBoxItem( Color.Green, "Green" ),
816                                                        new ColorComboBoxItem( Color.Olive, "Olive-Green" ), // color not correct
817                                                        new ColorComboBoxItem( Color.Aquamarine, "Aquamarine" ), // color not correct
818                                                        new ColorComboBoxItem( Color.Crimson, "Crimson" ),
819                                                        new ColorComboBoxItem( Color.Cyan, "Cyan" ),
820                                                        new ColorComboBoxItem( Color.Gray, "Gray" ),
821                                                        new ColorComboBoxItem( Color.Silver, "Silver" ),
822                                                        new ColorComboBoxItem( Color.Red, "Red" ),
823                                                        new ColorComboBoxItem( Color.YellowGreen, "Yellow-Green" ),
824                                                        new ColorComboBoxItem( Color.Yellow, "Yellow" ),
825                                                        new ColorComboBoxItem( Color.Blue, "Blue" ),
826                                                        new ColorComboBoxItem( Color.Purple, "Purple" ),
827                                                        new ColorComboBoxItem( Color.Aquamarine, "Aquamarine" ),
828                                                        new ColorComboBoxItem( Color.White, "White" ) }
829                                                );
830                                 
831                                 SelectedIndex = 0;
832                         }
833                         
834                         protected override void OnDrawItem( DrawItemEventArgs e )
835                         {
836                                 if ( e.Index == -1 )
837                                         return;
838                                 
839                                 ColorComboBoxItem ccbi = Items[ e.Index ] as ColorComboBoxItem;
840                                 
841                                 Rectangle r = e.Bounds;
842                                 r.X = r.X + 24;
843                                 
844                                 if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected )
845                                 {
846                                         e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( Color.Blue ), e.Bounds ); // bot blue
847                                         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 );
848                                         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 );
849                                         e.Graphics.DrawString( ccbi.Name, this.Font, ThemeEngine.Current.ResPool.GetSolidBrush( Color.White ), r );
850                                 }
851                                 else
852                                 {
853                                         e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( Color.White ), e.Bounds );
854                                         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 );
855                                         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 );
856                                         e.Graphics.DrawString( ccbi.Name, this.Font, ThemeEngine.Current.ResPool.GetSolidBrush( Color.Black ), r );
857                                 }
858                         }
859                         
860                         protected override void OnSelectedIndexChanged( EventArgs e )
861                         {
862                                 ColorComboBoxItem ccbi = Items[ SelectedIndex ] as ColorComboBoxItem;
863                                 selectedColor = ccbi.Color;
864                                 
865                                 fontDialogPanel.CurrentColor = selectedColor;
866                         }
867                 }
868         }
869 }