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