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