1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        src/generic/fontdlgg.cpp
3 // Purpose:     Generic font dialog
4 // Author:      Julian Smart
5 // Modified by:
6 // Created:     04/01/98
7 // Copyright:   (c) Julian Smart
8 // Licence:     wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10 
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13 
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17 
18 #if wxUSE_FONTDLG && (!defined(__WXGTK__) || defined(__WXGPE__) || defined(__WXUNIVERSAL__))
19 
20 #ifndef WX_PRECOMP
21     #include <stdio.h>
22     #include "wx/crt.h"
23     #include "wx/utils.h"
24     #include "wx/dialog.h"
25     #include "wx/listbox.h"
26     #include "wx/button.h"
27     #include "wx/stattext.h"
28     #include "wx/layout.h"
29     #include "wx/dcclient.h"
30     #include "wx/choice.h"
31     #include "wx/checkbox.h"
32     #include "wx/intl.h"
33     #include "wx/settings.h"
34     #include "wx/sizer.h"
35 #endif
36 
37 #include <string.h>
38 #include <stdlib.h>
39 
40 #include "wx/fontdlg.h"
41 #include "wx/generic/fontdlgg.h"
42 
43 #if USE_SPINCTRL_FOR_POINT_SIZE
44 #include "wx/spinctrl.h"
45 #endif
46 
47 //-----------------------------------------------------------------------------
48 // helper class - wxFontPreviewer
49 //-----------------------------------------------------------------------------
50 
51 class WXDLLEXPORT wxFontPreviewer : public wxWindow
52 {
53 public:
wxFontPreviewer(wxWindow * parent,const wxSize & sz=wxDefaultSize)54     wxFontPreviewer(wxWindow *parent, const wxSize& sz = wxDefaultSize) : wxWindow(parent, wxID_ANY, wxDefaultPosition, sz)
55     {
56     }
57 
58 private:
59     void OnPaint(wxPaintEvent& event);
60     DECLARE_EVENT_TABLE()
61 };
62 
BEGIN_EVENT_TABLE(wxFontPreviewer,wxWindow)63 BEGIN_EVENT_TABLE(wxFontPreviewer, wxWindow)
64     EVT_PAINT(wxFontPreviewer::OnPaint)
65 END_EVENT_TABLE()
66 
67 void wxFontPreviewer::OnPaint(wxPaintEvent& WXUNUSED(event))
68 {
69     wxPaintDC dc(this);
70 
71     wxSize size = GetSize();
72     wxFont font = GetFont();
73 
74     dc.SetPen(*wxBLACK_PEN);
75     dc.SetBrush(*wxWHITE_BRUSH);
76     dc.DrawRectangle(0, 0, size.x, size.y);
77 
78     if ( font.IsOk() )
79     {
80         dc.SetFont(font);
81         dc.SetTextForeground(GetForegroundColour());
82         dc.SetClippingRegion(2, 2, size.x-4, size.y-4);
83         dc.DrawText(_("ABCDEFGabcdefg12345"),
84                      10, (size.y - dc.GetTextExtent(wxT("X")).y)/2);
85         dc.DestroyClippingRegion();
86     }
87 }
88 
89 //-----------------------------------------------------------------------------
90 // helper functions
91 //-----------------------------------------------------------------------------
92 
wxFontWeightIntToString(int weight)93 static const wxChar *wxFontWeightIntToString(int weight)
94 {
95     switch (weight)
96     {
97         case wxLIGHT:
98             return wxT("Light");
99         case wxBOLD:
100             return wxT("Bold");
101         case wxNORMAL:
102         default:
103             return wxT("Normal");
104     }
105 }
106 
wxFontStyleIntToString(int style)107 static const wxChar *wxFontStyleIntToString(int style)
108 {
109     switch (style)
110     {
111         case wxITALIC:
112             return wxT("Italic");
113         case wxSLANT:
114             return wxT("Slant");
115         case wxNORMAL:
116             default:
117             return wxT("Normal");
118     }
119 }
120 
wxFontFamilyIntToString(int family)121 static const wxChar *wxFontFamilyIntToString(int family)
122 {
123     switch (family)
124     {
125         case wxROMAN:
126             return wxT("Roman");
127         case wxDECORATIVE:
128             return wxT("Decorative");
129         case wxMODERN:
130             return wxT("Modern");
131         case wxSCRIPT:
132             return wxT("Script");
133         case wxTELETYPE:
134             return wxT("Teletype");
135         case wxSWISS:
136         default:
137             return wxT("Swiss");
138     }
139 }
140 
wxFontFamilyStringToInt(const wxString & family)141 static int wxFontFamilyStringToInt(const wxString& family)
142 {
143     if (family.empty())
144         return wxSWISS;
145 
146     if (wxStrcmp(family, wxT("Roman")) == 0)
147         return wxROMAN;
148     else if (wxStrcmp(family, wxT("Decorative")) == 0)
149         return wxDECORATIVE;
150     else if (wxStrcmp(family, wxT("Modern")) == 0)
151         return wxMODERN;
152     else if (wxStrcmp(family, wxT("Script")) == 0)
153         return wxSCRIPT;
154     else if (wxStrcmp(family, wxT("Teletype")) == 0)
155         return wxTELETYPE;
156     else return wxSWISS;
157 }
158 
wxFontStyleStringToInt(const wxString & style)159 static int wxFontStyleStringToInt(const wxString& style)
160 {
161     if (style.empty())
162         return wxNORMAL;
163     if (wxStrcmp(style, wxT("Italic")) == 0)
164         return wxITALIC;
165     else if (wxStrcmp(style, wxT("Slant")) == 0)
166         return wxSLANT;
167     else
168         return wxNORMAL;
169 }
170 
wxFontWeightStringToInt(const wxString & weight)171 static int wxFontWeightStringToInt(const wxString& weight)
172 {
173     if (weight.empty())
174         return wxNORMAL;
175     if (wxStrcmp(weight, wxT("Bold")) == 0)
176         return wxBOLD;
177     else if (wxStrcmp(weight, wxT("Light")) == 0)
178         return wxLIGHT;
179     else
180         return wxNORMAL;
181 }
182 
183 //-----------------------------------------------------------------------------
184 // wxGenericFontDialog
185 //-----------------------------------------------------------------------------
186 
187 IMPLEMENT_DYNAMIC_CLASS(wxGenericFontDialog, wxDialog)
188 
189 BEGIN_EVENT_TABLE(wxGenericFontDialog, wxDialog)
190     EVT_CHECKBOX(wxID_FONT_UNDERLINE, wxGenericFontDialog::OnChangeFont)
191     EVT_CHOICE(wxID_FONT_STYLE, wxGenericFontDialog::OnChangeFont)
192     EVT_CHOICE(wxID_FONT_WEIGHT, wxGenericFontDialog::OnChangeFont)
193     EVT_CHOICE(wxID_FONT_FAMILY, wxGenericFontDialog::OnChangeFont)
194     EVT_CHOICE(wxID_FONT_COLOUR, wxGenericFontDialog::OnChangeFont)
195 #if USE_SPINCTRL_FOR_POINT_SIZE
196     EVT_SPINCTRL(wxID_FONT_SIZE, wxGenericFontDialog::OnChangeSize)
197     EVT_TEXT(wxID_FONT_SIZE, wxGenericFontDialog::OnChangeFont)
198 #else
199     EVT_CHOICE(wxID_FONT_SIZE, wxGenericFontDialog::OnChangeFont)
200 #endif
201     EVT_CLOSE(wxGenericFontDialog::OnCloseWindow)
202 END_EVENT_TABLE()
203 
204 
205 #define NUM_COLS 48
206 static wxString wxColourDialogNames[NUM_COLS]={wxT("ORANGE"),
207                     wxT("GOLDENROD"),
208                     wxT("WHEAT"),
209                     wxT("SPRING GREEN"),
210                     wxT("SKY BLUE"),
211                     wxT("SLATE BLUE"),
212                     wxT("MEDIUM VIOLET RED"),
213                     wxT("PURPLE"),
214 
215                     wxT("RED"),
216                     wxT("YELLOW"),
217                     wxT("MEDIUM SPRING GREEN"),
218                     wxT("PALE GREEN"),
219                     wxT("CYAN"),
220                     wxT("LIGHT STEEL BLUE"),
221                     wxT("ORCHID"),
222                     wxT("LIGHT MAGENTA"),
223 
224                     wxT("BROWN"),
225                     wxT("YELLOW"),
226                     wxT("GREEN"),
227                     wxT("CADET BLUE"),
228                     wxT("MEDIUM BLUE"),
229                     wxT("MAGENTA"),
230                     wxT("MAROON"),
231                     wxT("ORANGE RED"),
232 
233                     wxT("FIREBRICK"),
234                     wxT("CORAL"),
235                     wxT("FOREST GREEN"),
236                     wxT("AQUAMARINE"),
237                     wxT("BLUE"),
238                     wxT("NAVY"),
239                     wxT("THISTLE"),
240                     wxT("MEDIUM VIOLET RED"),
241 
242                     wxT("INDIAN RED"),
243                     wxT("GOLD"),
244                     wxT("MEDIUM SEA GREEN"),
245                     wxT("MEDIUM BLUE"),
246                     wxT("MIDNIGHT BLUE"),
247                     wxT("GREY"),
248                     wxT("PURPLE"),
249                     wxT("KHAKI"),
250 
251                     wxT("BLACK"),
252                     wxT("MEDIUM FOREST GREEN"),
253                     wxT("KHAKI"),
254                     wxT("DARK GREY"),
255                     wxT("SEA GREEN"),
256                     wxT("LIGHT GREY"),
257                     wxT("MEDIUM SLATE BLUE"),
258                     wxT("WHITE")
259                     };
260 
261 /*
262  * Generic wxFontDialog
263  */
264 
Init()265 void wxGenericFontDialog::Init()
266 {
267     m_useEvents = false;
268     m_previewer = NULL;
269     Create( m_parent ) ;
270 }
271 
~wxGenericFontDialog()272 wxGenericFontDialog::~wxGenericFontDialog()
273 {
274 }
275 
OnCloseWindow(wxCloseEvent & WXUNUSED (event))276 void wxGenericFontDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
277 {
278     EndModal(wxID_CANCEL);
279 }
280 
DoCreate(wxWindow * parent)281 bool wxGenericFontDialog::DoCreate(wxWindow *parent)
282 {
283     parent = GetParentForModalDialog(parent, 0);
284 
285     if ( !wxDialog::Create( parent , wxID_ANY , wxT("Choose Font") ,
286                             wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
287         wxT("fontdialog") ) )
288     {
289         wxFAIL_MSG( wxT("wxFontDialog creation failed") );
290         return false;
291     }
292 
293     InitializeFont();
294     CreateWidgets();
295 
296     // sets initial font in preview area
297     DoChangeFont();
298 
299     return true;
300 }
301 
ShowModal()302 int wxGenericFontDialog::ShowModal()
303 {
304     int ret = wxDialog::ShowModal();
305 
306     if (ret != wxID_CANCEL)
307     {
308         m_fontData.m_chosenFont = m_dialogFont;
309     }
310 
311     return ret;
312 }
313 
314 // This should be application-settable
ShowToolTips()315 static bool ShowToolTips() { return false; }
316 
CreateWidgets()317 void wxGenericFontDialog::CreateWidgets()
318 {
319     wxString *families = new wxString[6],
320              *styles = new wxString[3],
321              *weights = new wxString[3];
322     families[0] =  _("Roman");
323     families[1] = _("Decorative");
324     families[2] = _("Modern");
325     families[3] = _("Script");
326     families[4] = _("Swiss" );
327     families[5] = _("Teletype" );
328     styles[0] = _("Normal");
329     styles[1] = _("Italic");
330     styles[2] = _("Slant");
331     weights[0] = _("Normal");
332     weights[1] = _("Light");
333     weights[2] = _("Bold");
334 
335 #if !USE_SPINCTRL_FOR_POINT_SIZE
336     wxString *pointSizes = new wxString[40];
337     int i;
338     for ( i = 0; i < 40; i++)
339     {
340         wxChar buf[5];
341         wxSprintf(buf, wxT("%d"), i + 1);
342         pointSizes[i] = buf;
343     }
344 #endif
345 
346     // layout
347 
348     bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
349     int noCols, noRows;
350     if (is_pda)
351     {
352         noCols = 2; noRows = 3;
353     }
354     else
355     {
356         noCols = 3; noRows = 2;
357     }
358 
359     wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
360     this->SetSizer(itemBoxSizer2);
361     this->SetAutoLayout(true);
362 
363     wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
364     itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);
365 
366     wxFlexGridSizer* itemGridSizer4 = new wxFlexGridSizer(noRows, noCols, 0, 0);
367     itemBoxSizer3->Add(itemGridSizer4, 0, wxGROW, 5);
368 
369     wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL);
370     itemGridSizer4->Add(itemBoxSizer5, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5);
371     wxStaticText* itemStaticText6 = new wxStaticText( this, wxID_STATIC, _("&Font family:"), wxDefaultPosition, wxDefaultSize, 0 );
372     itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
373 
374     wxChoice* itemChoice7 = new wxChoice( this, wxID_FONT_FAMILY, wxDefaultPosition, wxDefaultSize, 5, families, 0 );
375     itemChoice7->SetHelpText(_("The font family."));
376     if (ShowToolTips())
377         itemChoice7->SetToolTip(_("The font family."));
378     itemBoxSizer5->Add(itemChoice7, 0, wxALIGN_LEFT|wxALL, 5);
379 
380     wxBoxSizer* itemBoxSizer8 = new wxBoxSizer(wxVERTICAL);
381     itemGridSizer4->Add(itemBoxSizer8, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5);
382     wxStaticText* itemStaticText9 = new wxStaticText( this, wxID_STATIC, _("&Style:"), wxDefaultPosition, wxDefaultSize, 0 );
383     itemBoxSizer8->Add(itemStaticText9, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
384 
385     wxChoice* itemChoice10 = new wxChoice( this, wxID_FONT_STYLE, wxDefaultPosition, wxDefaultSize, 3, styles, 0 );
386     itemChoice10->SetHelpText(_("The font style."));
387     if (ShowToolTips())
388         itemChoice10->SetToolTip(_("The font style."));
389     itemBoxSizer8->Add(itemChoice10, 0, wxALIGN_LEFT|wxALL, 5);
390 
391     wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxVERTICAL);
392     itemGridSizer4->Add(itemBoxSizer11, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5);
393     wxStaticText* itemStaticText12 = new wxStaticText( this, wxID_STATIC, _("&Weight:"), wxDefaultPosition, wxDefaultSize, 0 );
394     itemBoxSizer11->Add(itemStaticText12, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
395 
396     wxChoice* itemChoice13 = new wxChoice( this, wxID_FONT_WEIGHT, wxDefaultPosition, wxDefaultSize, 3, weights, 0 );
397     itemChoice13->SetHelpText(_("The font weight."));
398     if (ShowToolTips())
399         itemChoice13->SetToolTip(_("The font weight."));
400     itemBoxSizer11->Add(itemChoice13, 0, wxALIGN_LEFT|wxALL, 5);
401 
402     wxBoxSizer* itemBoxSizer14 = new wxBoxSizer(wxVERTICAL);
403     itemGridSizer4->Add(itemBoxSizer14, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5);
404     if (m_fontData.GetEnableEffects())
405     {
406         wxStaticText* itemStaticText15 = new wxStaticText( this, wxID_STATIC, _("C&olour:"), wxDefaultPosition, wxDefaultSize, 0 );
407         itemBoxSizer14->Add(itemStaticText15, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
408 
409         wxSize colourSize = wxDefaultSize;
410         if (is_pda)
411             colourSize.x = 100;
412 
413         wxChoice* itemChoice16 = new wxChoice( this, wxID_FONT_COLOUR, wxDefaultPosition, colourSize, NUM_COLS, wxColourDialogNames, 0 );
414         itemChoice16->SetHelpText(_("The font colour."));
415         if (ShowToolTips())
416             itemChoice16->SetToolTip(_("The font colour."));
417         itemBoxSizer14->Add(itemChoice16, 0, wxALIGN_LEFT|wxALL, 5);
418     }
419 
420     wxBoxSizer* itemBoxSizer17 = new wxBoxSizer(wxVERTICAL);
421     itemGridSizer4->Add(itemBoxSizer17, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5);
422     wxStaticText* itemStaticText18 = new wxStaticText( this, wxID_STATIC, _("&Point size:"), wxDefaultPosition, wxDefaultSize, 0 );
423     itemBoxSizer17->Add(itemStaticText18, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
424 
425 #if USE_SPINCTRL_FOR_POINT_SIZE
426     wxSpinCtrl* spinCtrl = new wxSpinCtrl(this, wxID_FONT_SIZE, wxT("12"), wxDefaultPosition, wxSize(80, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 500, 12);
427     spinCtrl->SetHelpText(_("The font point size."));
428     if (ShowToolTips())
429         spinCtrl->SetToolTip(_("The font point size."));
430 
431     itemBoxSizer17->Add(spinCtrl, 0, wxALIGN_LEFT|wxALL, 5);
432 #else
433     wxChoice* itemChoice19 = new wxChoice( this, wxID_FONT_SIZE, wxDefaultPosition, wxDefaultSize, 40, pointSizes, 0 );
434     itemChoice19->SetHelpText(_("The font point size."));
435     if (ShowToolTips())
436         itemChoice19->SetToolTip(_("The font point size."));
437     itemBoxSizer17->Add(itemChoice19, 0, wxALIGN_LEFT|wxALL, 5);
438 #endif
439 
440     if (m_fontData.GetEnableEffects())
441     {
442         wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxVERTICAL);
443         itemGridSizer4->Add(itemBoxSizer20, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
444         wxCheckBox* itemCheckBox21 = new wxCheckBox( this, wxID_FONT_UNDERLINE, _("&Underline"), wxDefaultPosition, wxDefaultSize, 0 );
445         itemCheckBox21->SetValue(false);
446         itemCheckBox21->SetHelpText(_("Whether the font is underlined."));
447         if (ShowToolTips())
448             itemCheckBox21->SetToolTip(_("Whether the font is underlined."));
449         itemBoxSizer20->Add(itemCheckBox21, 0, wxALIGN_LEFT|wxALL, 5);
450     }
451 
452     if (!is_pda)
453         itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
454 
455     wxStaticText* itemStaticText23 = new wxStaticText( this, wxID_STATIC, _("Preview:"), wxDefaultPosition, wxDefaultSize, 0 );
456     itemBoxSizer3->Add(itemStaticText23, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
457 
458     wxFontPreviewer* itemWindow24 = new wxFontPreviewer( this );
459     m_previewer = itemWindow24;
460     itemWindow24->SetHelpText(_("Shows the font preview."));
461     if (ShowToolTips())
462         itemWindow24->SetToolTip(_("Shows the font preview."));
463     itemBoxSizer3->Add(itemWindow24, 1, wxGROW|wxALL, 5);
464 
465     wxBoxSizer* itemBoxSizer25 = new wxBoxSizer(wxHORIZONTAL);
466     itemBoxSizer3->Add(itemBoxSizer25, 0, wxGROW, 5);
467     itemBoxSizer25->Add(5, 5, 1, wxGROW|wxALL, 5);
468 
469 #ifdef __WXMAC__
470     wxButton* itemButton28 = new wxButton( this, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
471     if (ShowToolTips())
472         itemButton28->SetToolTip(_("Click to cancel the font selection."));
473     itemBoxSizer25->Add(itemButton28, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
474 
475     wxButton* itemButton27 = new wxButton( this, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
476     itemButton27->SetDefault();
477     itemButton27->SetHelpText(_("Click to confirm the font selection."));
478     if (ShowToolTips())
479         itemButton27->SetToolTip(_("Click to confirm the font selection."));
480     itemBoxSizer25->Add(itemButton27, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
481 #else
482     wxButton* itemButton27 = new wxButton( this, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
483     itemButton27->SetDefault();
484     itemButton27->SetHelpText(_("Click to confirm the font selection."));
485     if (ShowToolTips())
486         itemButton27->SetToolTip(_("Click to confirm the font selection."));
487     itemBoxSizer25->Add(itemButton27, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
488 
489     wxButton* itemButton28 = new wxButton( this, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
490     if (ShowToolTips())
491         itemButton28->SetToolTip(_("Click to cancel the font selection."));
492     itemBoxSizer25->Add(itemButton28, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
493 #endif
494 
495     m_familyChoice = (wxChoice*) FindWindow(wxID_FONT_FAMILY);
496     m_styleChoice = (wxChoice*) FindWindow(wxID_FONT_STYLE);
497     m_weightChoice = (wxChoice*) FindWindow(wxID_FONT_WEIGHT);
498     m_colourChoice = (wxChoice*) FindWindow(wxID_FONT_COLOUR);
499     m_underLineCheckBox = (wxCheckBox*) FindWindow(wxID_FONT_UNDERLINE);
500 
501     m_familyChoice->SetStringSelection( wxFontFamilyIntToString(m_dialogFont.GetFamily()) );
502     m_styleChoice->SetStringSelection(wxFontStyleIntToString(m_dialogFont.GetStyle()));
503     m_weightChoice->SetStringSelection(wxFontWeightIntToString(m_dialogFont.GetWeight()));
504 
505     if (m_colourChoice)
506     {
507         wxString name(wxTheColourDatabase->FindName(m_fontData.GetColour()));
508         if ( name.empty() )
509             m_colourChoice->SetStringSelection(wxT("BLACK"));
510         else
511             m_colourChoice->SetStringSelection(name);
512     }
513 
514     if (m_underLineCheckBox)
515     {
516         m_underLineCheckBox->SetValue(m_dialogFont.GetUnderlined());
517     }
518 
519 #if USE_SPINCTRL_FOR_POINT_SIZE
520     spinCtrl->SetValue(m_dialogFont.GetPointSize());
521 #else
522     m_pointSizeChoice = (wxChoice*) FindWindow(wxID_FONT_SIZE);
523     m_pointSizeChoice->SetSelection(m_dialogFont.GetPointSize()-1);
524 #endif
525 
526     GetSizer()->SetItemMinSize(m_previewer, is_pda ? 100 : 430, is_pda ? 40 : 100);
527     GetSizer()->SetSizeHints(this);
528     GetSizer()->Fit(this);
529 
530     Centre(wxBOTH);
531 
532     delete[] families;
533     delete[] styles;
534     delete[] weights;
535 #if !USE_SPINCTRL_FOR_POINT_SIZE
536     delete[] pointSizes;
537 #endif
538 
539     // Don't block events any more
540     m_useEvents = true;
541 
542 }
543 
InitializeFont()544 void wxGenericFontDialog::InitializeFont()
545 {
546     int fontFamily = wxSWISS;
547     int fontWeight = wxNORMAL;
548     int fontStyle = wxNORMAL;
549     int fontSize = 12;
550     bool fontUnderline = false;
551 
552     if (m_fontData.m_initialFont.IsOk())
553     {
554         fontFamily = m_fontData.m_initialFont.GetFamily();
555         fontWeight = m_fontData.m_initialFont.GetWeight();
556         fontStyle = m_fontData.m_initialFont.GetStyle();
557         fontSize = m_fontData.m_initialFont.GetPointSize();
558         fontUnderline = m_fontData.m_initialFont.GetUnderlined();
559     }
560 
561     m_dialogFont = wxFont(fontSize, fontFamily, fontStyle,
562                           fontWeight, fontUnderline);
563 
564     if (m_previewer)
565         m_previewer->SetFont(m_dialogFont);
566 }
567 
OnChangeFont(wxCommandEvent & WXUNUSED (event))568 void wxGenericFontDialog::OnChangeFont(wxCommandEvent& WXUNUSED(event))
569 {
570     DoChangeFont();
571 }
572 
DoChangeFont()573 void wxGenericFontDialog::DoChangeFont()
574 {
575     if (!m_useEvents) return;
576 
577     int fontFamily = wxFontFamilyStringToInt(m_familyChoice->GetStringSelection());
578     int fontWeight = wxFontWeightStringToInt(m_weightChoice->GetStringSelection());
579     int fontStyle = wxFontStyleStringToInt(m_styleChoice->GetStringSelection());
580 #if USE_SPINCTRL_FOR_POINT_SIZE
581     wxSpinCtrl* fontSizeCtrl = wxDynamicCast(FindWindow(wxID_FONT_SIZE), wxSpinCtrl);
582     int fontSize = fontSizeCtrl->GetValue();
583 #else
584     int fontSize = wxAtoi(m_pointSizeChoice->GetStringSelection());
585 #endif
586 
587     // Start with previous underline setting, we want to retain it even if we can't edit it
588     // m_dialogFont is always initialized because of the call to InitializeFont
589     int fontUnderline = m_dialogFont.GetUnderlined();
590 
591     if (m_underLineCheckBox)
592     {
593         fontUnderline = m_underLineCheckBox->GetValue();
594     }
595 
596     m_dialogFont = wxFont(fontSize, fontFamily, fontStyle, fontWeight, (fontUnderline != 0));
597     m_previewer->SetFont(m_dialogFont);
598 
599     if ( m_colourChoice )
600     {
601         if ( !m_colourChoice->GetStringSelection().empty() )
602         {
603             wxColour col = wxTheColourDatabase->Find(m_colourChoice->GetStringSelection());
604             if (col.IsOk())
605             {
606                 m_fontData.m_fontColour = col;
607             }
608         }
609     }
610     // Update color here so that we can also use the color originally passed in
611     // (EnableEffects may be false)
612     if (m_fontData.m_fontColour.IsOk())
613         m_previewer->SetForegroundColour(m_fontData.m_fontColour);
614 
615     m_previewer->Refresh();
616 }
617 
618 #if USE_SPINCTRL_FOR_POINT_SIZE
OnChangeSize(wxSpinEvent & WXUNUSED (event))619 void wxGenericFontDialog::OnChangeSize(wxSpinEvent& WXUNUSED(event))
620 {
621     DoChangeFont();
622 }
623 #endif
624 
625 #endif
626     // wxUSE_FONTDLG
627