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