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