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