]> git.saurik.com Git - wxWidgets.git/blame - src/generic/fontdlgg.cpp
no real changes, just some reformatting
[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 22 #include <stdio.h>
3a3dde0d 23 #include "wx/crt.h"
53cf79fa
VS
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"
9eddec69 34 #include "wx/settings.h"
ce5d92e1 35 #include "wx/cmndata.h"
ed2fbeb8 36 #include "wx/sizer.h"
c801d85f
KB
37#endif
38
39#include <string.h>
40#include <stdlib.h>
41
c2c59b22 42#include "wx/fontdlg.h"
23c47bc1 43#include "wx/generic/fontdlgg.h"
c801d85f 44
6b775e66
JS
45#if USE_SPINCTRL_FOR_POINT_SIZE
46#include "wx/spinctrl.h"
47#endif
48
53cf79fa
VS
49//-----------------------------------------------------------------------------
50// helper class - wxFontPreviewer
51//-----------------------------------------------------------------------------
52
53class WXDLLEXPORT wxFontPreviewer : public wxWindow
54{
55public:
94f53923
JS
56 wxFontPreviewer(wxWindow *parent, const wxSize& sz = wxDefaultSize) : wxWindow(parent, wxID_ANY, wxDefaultPosition, sz)
57 {
58 }
53cf79fa
VS
59
60private:
61 void OnPaint(wxPaintEvent& event);
62 DECLARE_EVENT_TABLE()
63};
64
65BEGIN_EVENT_TABLE(wxFontPreviewer, wxWindow)
66 EVT_PAINT(wxFontPreviewer::OnPaint)
67END_EVENT_TABLE()
68
69void 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 {
2b5f62a0 82 dc.SetFont(font);
53cf79fa
VS
83 dc.SetTextForeground(GetForegroundColour());
84 dc.SetClippingRegion(2, 2, size.x-4, size.y-4);
dabbc6a5 85 dc.DrawText(_("ABCDEFGabcdefg12345"),
8f3447c2 86 10, (size.y - dc.GetTextExtent(wxT("X")).y)/2);
53cf79fa
VS
87 dc.DestroyClippingRegion();
88 }
89}
90
994f04a3
VS
91//-----------------------------------------------------------------------------
92// helper functions
93//-----------------------------------------------------------------------------
94
95static 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
109static 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
123static 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
143static 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
161static 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
173static 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
53cf79fa
VS
185//-----------------------------------------------------------------------------
186// wxGenericFontDialog
187//-----------------------------------------------------------------------------
188
c801d85f
KB
189IMPLEMENT_DYNAMIC_CLASS(wxGenericFontDialog, wxDialog)
190
191BEGIN_EVENT_TABLE(wxGenericFontDialog, wxDialog)
c35414db
VZ
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)
6b775e66
JS
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
c35414db 201 EVT_CHOICE(wxID_FONT_SIZE, wxGenericFontDialog::OnChangeFont)
6b775e66 202#endif
c35414db 203 EVT_CLOSE(wxGenericFontDialog::OnCloseWindow)
c801d85f
KB
204END_EVENT_TABLE()
205
c801d85f
KB
206
207#define NUM_COLS 48
223d09f6
KB
208static 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")
c35414db 261 };
c801d85f
KB
262
263/*
264 * Generic wxFontDialog
265 */
266
c2c59b22 267void wxGenericFontDialog::Init()
c801d85f 268{
cececf4d
WS
269 m_useEvents = false;
270 m_previewer = NULL;
271 Create( m_parent ) ;
c801d85f
KB
272}
273
c2c59b22 274wxGenericFontDialog::~wxGenericFontDialog()
c801d85f
KB
275{
276}
277
74e3313b 278void wxGenericFontDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
c801d85f 279{
47e118ba 280 EndModal(wxID_CANCEL);
c801d85f 281}
c35414db 282
c2c59b22 283bool wxGenericFontDialog::DoCreate(wxWindow *parent)
c801d85f 284{
2229243b
VZ
285 parent = GetParentForModalDialog(parent);
286
287 if ( !wxDialog::Create( parent , wxID_ANY , _T("Choose Font") ,
288 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
1bab9242
SC
289 _T("fontdialog") ) )
290 {
291 wxFAIL_MSG( wxT("wxFontDialog creation failed") );
dabbc6a5 292 return false;
1bab9242 293 }
fc8eba27 294
47e118ba
RR
295 InitializeFont();
296 CreateWidgets();
dabbc6a5 297
47e118ba 298 // sets initial font in preview area
cececf4d 299 DoChangeFont();
dabbc6a5
DS
300
301 return true;
c801d85f
KB
302}
303
c2c59b22 304int wxGenericFontDialog::ShowModal()
c801d85f 305{
1bab9242 306 int ret = wxDialog::ShowModal();
c801d85f
KB
307
308 if (ret != wxID_CANCEL)
309 {
cececf4d 310 m_fontData.m_chosenFont = m_dialogFont;
c801d85f
KB
311 }
312
c35414db 313 return ret;
c801d85f
KB
314}
315
4566d7db
JS
316// This should be application-settable
317static bool ShowToolTips() { return false; }
318
c2c59b22 319void wxGenericFontDialog::CreateWidgets()
c801d85f 320{
cececf4d
WS
321 wxString *families = new wxString[6],
322 *styles = new wxString[3],
323 *weights = new wxString[3];
47e118ba
RR
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
6b775e66 337#if !USE_SPINCTRL_FOR_POINT_SIZE
47e118ba
RR
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 }
6b775e66 346#endif
c801d85f 347
4566d7db 348 // layout
c801d85f 349
4566d7db
JS
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 }
c801d85f 360
4566d7db
JS
361 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
362 this->SetSizer(itemBoxSizer2);
cececf4d
WS
363 this->SetAutoLayout(true);
364
4566d7db
JS
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 );
69ce77e2 374 itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
4566d7db
JS
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 );
69ce77e2 385 itemBoxSizer8->Add(itemStaticText9, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
4566d7db
JS
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 );
69ce77e2 396 itemBoxSizer11->Add(itemStaticText12, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
4566d7db
JS
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);
8ae6cfb6
KH
406 if (m_fontData.GetEnableEffects())
407 {
408 wxStaticText* itemStaticText15 = new wxStaticText( this, wxID_STATIC, _("C&olour:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 409 itemBoxSizer14->Add(itemStaticText15, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
cececf4d 410
94f53923
JS
411 wxSize colourSize = wxDefaultSize;
412 if (is_pda)
413 colourSize.x = 100;
8ae6cfb6 414
d6b30150 415 wxChoice* itemChoice16 = new wxChoice( this, wxID_FONT_COLOUR, wxDefaultPosition, colourSize, NUM_COLS, wxColourDialogNames, 0 );
8ae6cfb6
KH
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 }
4566d7db
JS
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 );
69ce77e2 425 itemBoxSizer17->Add(itemStaticText18, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
4566d7db 426
6b775e66 427#if USE_SPINCTRL_FOR_POINT_SIZE
cececf4d 428 wxSpinCtrl* spinCtrl = new wxSpinCtrl(this, wxID_FONT_SIZE, wxT("12"), wxDefaultPosition, wxSize(80, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 500, 12);
6b775e66
JS
429 spinCtrl->SetHelpText(_("The font point size."));
430 if (ShowToolTips())
431 spinCtrl->SetToolTip(_("The font point size."));
cececf4d 432
6b775e66
JS
433 itemBoxSizer17->Add(spinCtrl, 0, wxALIGN_LEFT|wxALL, 5);
434#else
4566d7db
JS
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);
6b775e66 440#endif
4566d7db 441
8ae6cfb6
KH
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 );
cececf4d 447 itemCheckBox21->SetValue(false);
8ae6cfb6
KH
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 }
4566d7db 453
94f53923
JS
454 if (!is_pda)
455 itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
4566d7db
JS
456
457 wxStaticText* itemStaticText23 = new wxStaticText( this, wxID_STATIC, _("Preview:"), wxDefaultPosition, wxDefaultSize, 0 );
69ce77e2 458 itemBoxSizer3->Add(itemStaticText23, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
cececf4d 459
4566d7db
JS
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."));
6b775e66 465 itemBoxSizer3->Add(itemWindow24, 1, wxGROW|wxALL, 5);
4566d7db
JS
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
c801d85f 496
cececf4d
WS
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)
8ae6cfb6
KH
508 {
509 wxString name(wxTheColourDatabase->FindName(m_fontData.GetColour()));
510 if (name.length())
cececf4d 511 m_colourChoice->SetStringSelection(name);
8ae6cfb6 512 else
cececf4d 513 m_colourChoice->SetStringSelection(wxT("BLACK"));
8ae6cfb6 514 }
cececf4d
WS
515
516 if (m_underLineCheckBox)
8ae6cfb6 517 {
cececf4d 518 m_underLineCheckBox->SetValue(m_dialogFont.GetUnderlined());
8ae6cfb6
KH
519 }
520
6b775e66 521#if USE_SPINCTRL_FOR_POINT_SIZE
cececf4d 522 spinCtrl->SetValue(m_dialogFont.GetPointSize());
6b775e66 523#else
cececf4d
WS
524 m_pointSizeChoice = (wxChoice*) FindWindow(wxID_FONT_SIZE);
525 m_pointSizeChoice->SetSelection(m_dialogFont.GetPointSize()-1);
6b775e66 526#endif
c801d85f 527
94f53923 528 GetSizer()->SetItemMinSize(m_previewer, is_pda ? 100 : 430, is_pda ? 40 : 100);
4566d7db 529 GetSizer()->SetSizeHints(this);
cececf4d 530 GetSizer()->Fit(this);
47e118ba
RR
531
532 Centre(wxBOTH);
533
534 delete[] families;
535 delete[] styles;
536 delete[] weights;
6b775e66 537#if !USE_SPINCTRL_FOR_POINT_SIZE
47e118ba 538 delete[] pointSizes;
6b775e66 539#endif
dabbc6a5 540
47e118ba 541 // Don't block events any more
dabbc6a5 542 m_useEvents = true;
4566d7db 543
c801d85f
KB
544}
545
c2c59b22 546void wxGenericFontDialog::InitializeFont()
c801d85f 547{
47e118ba
RR
548 int fontFamily = wxSWISS;
549 int fontWeight = wxNORMAL;
550 int fontStyle = wxNORMAL;
551 int fontSize = 12;
dabbc6a5 552 bool fontUnderline = false;
53cf79fa 553
47e118ba
RR
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 }
c801d85f 562
cececf4d
WS
563 m_dialogFont = wxFont(fontSize, fontFamily, fontStyle,
564 fontWeight, fontUnderline);
c801d85f 565
47e118ba 566 if (m_previewer)
cececf4d 567 m_previewer->SetFont(m_dialogFont);
c801d85f
KB
568}
569
570void wxGenericFontDialog::OnChangeFont(wxCommandEvent& WXUNUSED(event))
cececf4d
WS
571{
572 DoChangeFont();
573}
574
575void wxGenericFontDialog::DoChangeFont()
c801d85f 576{
47e118ba 577 if (!m_useEvents) return;
c35414db 578
994f04a3
VS
579 int fontFamily = wxFontFamilyStringToInt(m_familyChoice->GetStringSelection());
580 int fontWeight = wxFontWeightStringToInt(m_weightChoice->GetStringSelection());
581 int fontStyle = wxFontStyleStringToInt(m_styleChoice->GetStringSelection());
6b775e66
JS
582#if USE_SPINCTRL_FOR_POINT_SIZE
583 wxSpinCtrl* fontSizeCtrl = wxDynamicCast(FindWindow(wxID_FONT_SIZE), wxSpinCtrl);
584 int fontSize = fontSizeCtrl->GetValue();
585#else
cececf4d 586 int fontSize = wxAtoi(m_pointSizeChoice->GetStringSelection());
6b775e66
JS
587#endif
588
8ae6cfb6 589 // Start with previous underline setting, we want to retain it even if we can't edit it
cececf4d
WS
590 // m_dialogFont is always initialized because of the call to InitializeFont
591 int fontUnderline = m_dialogFont.GetUnderlined();
8ae6cfb6 592
cececf4d 593 if (m_underLineCheckBox)
8ae6cfb6 594 {
cececf4d 595 fontUnderline = m_underLineCheckBox->GetValue();
8ae6cfb6 596 }
c801d85f 597
cececf4d
WS
598 m_dialogFont = wxFont(fontSize, fontFamily, fontStyle, fontWeight, (fontUnderline != 0));
599 m_previewer->SetFont(m_dialogFont);
8ae6cfb6 600
cececf4d 601 if ( m_colourChoice )
c801d85f 602 {
cececf4d 603 if ( !m_colourChoice->GetStringSelection().empty() )
47e118ba 604 {
cececf4d 605 wxColour col = wxTheColourDatabase->Find(m_colourChoice->GetStringSelection());
8ae6cfb6
KH
606 if (col.Ok())
607 {
608 m_fontData.m_fontColour = col;
609 }
47e118ba 610 }
c801d85f 611 }
8ae6cfb6
KH
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);
cececf4d 616
47e118ba 617 m_previewer->Refresh();
c801d85f
KB
618}
619
6b775e66
JS
620#if USE_SPINCTRL_FOR_POINT_SIZE
621void wxGenericFontDialog::OnChangeSize(wxSpinEvent& WXUNUSED(event))
622{
cececf4d 623 DoChangeFont();
6b775e66
JS
624}
625#endif
626
3808e191
JS
627#endif
628 // wxUSE_FONTDLG