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