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