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(wxT("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 wxT("Light");
89 case wxFONTWEIGHT_BOLD:
90 return wxT("Bold");
91 case wxFONTWEIGHT_NORMAL:
92 default:
93 return wxT("Normal");
94 }
95}
96
97static const wxChar* ocpnFontStyleIntToString(int style) {
98 switch (style) {
99 case wxFONTSTYLE_ITALIC:
100 return wxT("Italic");
101 case wxFONTSTYLE_SLANT:
102 return wxT("Slant");
103 case wxFONTSTYLE_NORMAL:
104 default:
105 return wxT("Normal");
106 }
107}
108
109static const wxChar* ocpnFontFamilyIntToString(int family) {
110 switch (family) {
111 case wxFONTFAMILY_ROMAN:
112 return wxT("Roman");
113 case wxFONTFAMILY_DECORATIVE:
114 return wxT("Decorative");
115 case wxFONTFAMILY_MODERN:
116 return wxT("Modern");
117 case wxFONTFAMILY_SCRIPT:
118 return wxT("Script");
119 case wxFONTFAMILY_TELETYPE:
120 return wxT("Teletype");
121 case wxFONTFAMILY_SWISS:
122 default:
123 return wxT("Swiss");
124 }
125}
126
127static wxFontFamily ocpnFontFamilyStringToInt(const wxString& family) {
128 if (family.empty()) return wxFONTFAMILY_SWISS;
129
130 if (wxStrcmp(family, wxT("Roman")) == 0)
131 return wxFONTFAMILY_ROMAN;
132 else if (wxStrcmp(family, wxT("Decorative")) == 0)
133 return wxFONTFAMILY_DECORATIVE;
134 else if (wxStrcmp(family, wxT("Modern")) == 0)
135 return wxFONTFAMILY_MODERN;
136 else if (wxStrcmp(family, wxT("Script")) == 0)
137 return wxFONTFAMILY_SCRIPT;
138 else if (wxStrcmp(family, wxT("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, wxT("Italic")) == 0)
147 return wxFONTSTYLE_ITALIC;
148 else if (wxStrcmp(style, wxT("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, wxT("Bold")) == 0)
157 return wxFONTWEIGHT_BOLD;
158 else if (wxStrcmp(weight, wxT("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] = {wxT("ORANGE"),
191 wxT("GOLDENROD"),
192 wxT("WHEAT"),
193 wxT("SPRING GREEN"),
194 wxT("SKY BLUE"),
195 wxT("SLATE BLUE"),
196 wxT("MEDIUM VIOLET RED"),
197 wxT("PURPLE"),
198
199 wxT("RED"),
200 wxT("YELLOW"),
201 wxT("MEDIUM SPRING GREEN"),
202 wxT("PALE GREEN"),
203 wxT("CYAN"),
204 wxT("LIGHT STEEL BLUE"),
205 wxT("ORCHID"),
206 wxT("LIGHT MAGENTA"),
207
208 wxT("BROWN"),
209 wxT("YELLOW"),
210 wxT("GREEN"),
211 wxT("CADET BLUE"),
212 wxT("MEDIUM BLUE"),
213 wxT("MAGENTA"),
214 wxT("MAROON"),
215 wxT("ORANGE RED"),
216
217 wxT("FIREBRICK"),
218 wxT("CORAL"),
219 wxT("FOREST GREEN"),
220 wxT("AQUAMARINE"),
221 wxT("BLUE"),
222 wxT("NAVY"),
223 wxT("THISTLE"),
224 wxT("MEDIUM VIOLET RED"),
225
226 wxT("INDIAN RED"),
227 wxT("GOLD"),
228 wxT("MEDIUM SEA GREEN"),
229 wxT("MEDIUM BLUE"),
230 wxT("MIDNIGHT BLUE"),
231 wxT("GREY"),
232 wxT("PURPLE"),
233 wxT("KHAKI"),
234
235 wxT("BLACK"),
236 wxT("MEDIUM FOREST GREEN"),
237 wxT("KHAKI"),
238 wxT("DARK GREY"),
239 wxT("SEA GREEN"),
240 wxT("LIGHT GREY"),
241 wxT("MEDIUM SLATE BLUE"),
242 wxT("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, wxT("Choose Font"), wxDefaultPosition,
264 wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
265 wxT("fontdialog"))) {
266 wxFAIL_MSG(wxT("wxFontDialog creation failed"));
267 return false;
268 }
269
270 InitializeFont();
271 CreateWidgets();
272
273 // sets initial font in preview area
274 DoChangeFont();
275
276 return true;
277}
278
279int ocpnGenericFontDialog::ShowModal() {
280 int ret = wxDialog::ShowModal();
281
282 if (ret != wxID_CANCEL) {
283 m_fontData.m_chosenFont = m_dialogFont;
284 }
285
286 return ret;
287}
288
289// This should be application-settable
290static bool ShowToolTips() { return false; }
291
292void ocpnGenericFontDialog::CreateWidgets() {
293 wxString *families = new wxString[6], *styles = new wxString[3],
294 *weights = new wxString[3];
295 families[0] = _("Roman");
296 families[1] = _("Decorative");
297 families[2] = _("Modern");
298 families[3] = _("Script");
299 families[4] = _("Swiss");
300 families[5] = _("Teletype");
301 styles[0] = _("Normal");
302 styles[1] = _("Italic");
303 styles[2] = _("Slant");
304 weights[0] = _("Normal");
305 weights[1] = _("Light");
306 weights[2] = _("Bold");
307
308 // #if !USE_SPINCTRL_FOR_POINT_SIZE
309 wxString* pointSizes = new wxString[40];
310 int i;
311 for (i = 0; i < 40; i++) {
312 wxChar buf[5];
313 wxSprintf(buf, wxT("%d"), i + 1);
314 pointSizes[i] = buf;
315 }
316 // #endif
317
318 // layout
319
320 bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
321 int noCols, noRows;
322 if (is_pda) {
323 noCols = 2;
324 noRows = 3;
325 } else {
326 noCols = 3;
327 noRows = 2;
328 }
329
330 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
331 this->SetSizer(itemBoxSizer2);
332
333 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxVERTICAL);
334 itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW | wxALL, 5);
335
336 wxFlexGridSizer* itemGridSizer4 = new wxFlexGridSizer(noRows, noCols, 0, 0);
337 itemBoxSizer3->Add(itemGridSizer4, 0, wxGROW, 5);
338
339 wxBoxSizer* itemBoxSizer5 = new wxBoxSizer(wxVERTICAL);
340 itemGridSizer4->Add(itemBoxSizer5, 0, wxALIGN_CENTER_HORIZONTAL | wxGROW, 5);
341 wxStaticText* itemStaticText6 =
342 new wxStaticText(this, wxID_STATIC, _("&Font family:"), wxDefaultPosition,
343 wxDefaultSize, 0);
344 itemBoxSizer5->Add(itemStaticText6, 0,
345 wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5);
346
347 m_familyChoice = new wxChoice(this, wxID_FONT_FAMILY, wxDefaultPosition,
348 wxDefaultSize, 5, families, 0);
349 m_familyChoice->SetHelpText(_("The font family."));
350 if (ShowToolTips()) m_familyChoice->SetToolTip(_("The font family."));
351 itemBoxSizer5->Add(m_familyChoice, 0, wxALIGN_LEFT | wxALL, 5);
352
353 wxBoxSizer* itemBoxSizer8 = new wxBoxSizer(wxVERTICAL);
354 itemGridSizer4->Add(itemBoxSizer8, 0, wxALIGN_CENTER_HORIZONTAL | wxGROW, 5);
355 wxStaticText* itemStaticText9 = new wxStaticText(
356 this, wxID_STATIC, _("&Style:"), wxDefaultPosition, wxDefaultSize, 0);
357 itemBoxSizer8->Add(itemStaticText9, 0,
358 wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5);
359
360 m_styleChoice = new wxChoice(this, wxID_FONT_STYLE, wxDefaultPosition,
361 wxDefaultSize, 3, styles, 0);
362 m_styleChoice->SetHelpText(_("The font style."));
363 if (ShowToolTips()) m_styleChoice->SetToolTip(_("The font style."));
364 itemBoxSizer8->Add(m_styleChoice, 0, wxALIGN_LEFT | wxALL, 5);
365
366 wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxVERTICAL);
367 itemGridSizer4->Add(itemBoxSizer11, 0, wxALIGN_CENTER_HORIZONTAL | wxGROW, 5);
368 wxStaticText* itemStaticText12 = new wxStaticText(
369 this, wxID_STATIC, _("&Weight:"), wxDefaultPosition, wxDefaultSize, 0);
370 itemBoxSizer11->Add(itemStaticText12, 0,
371 wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5);
372
373 m_weightChoice = new wxChoice(this, wxID_FONT_WEIGHT, wxDefaultPosition,
374 wxDefaultSize, 3, weights, 0);
375 m_weightChoice->SetHelpText(_("The font weight."));
376 if (ShowToolTips()) m_weightChoice->SetToolTip(_("The font weight."));
377 itemBoxSizer11->Add(m_weightChoice, 0, wxALIGN_LEFT | wxALL, 5);
378
379 wxBoxSizer* itemBoxSizer14 = new wxBoxSizer(wxVERTICAL);
380 itemGridSizer4->Add(itemBoxSizer14, 0, wxALIGN_CENTER_HORIZONTAL | wxGROW, 5);
381 m_colourChoice = NULL;
382 if (m_fontData.GetEnableEffects()) {
383 wxStaticText* itemStaticText15 = new wxStaticText(
384 this, wxID_STATIC, _("C&olour:"), wxDefaultPosition, wxDefaultSize, 0);
385 itemBoxSizer14->Add(itemStaticText15, 0,
386 wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5);
387
388 wxSize colourSize = wxDefaultSize;
389 if (is_pda) colourSize.x = 100;
390
391 m_colourChoice =
392 new wxChoice(this, wxID_FONT_COLOUR, wxDefaultPosition, colourSize,
393 NUM_COLS, ocpnColourDialogNames, 0);
394 m_colourChoice->SetHelpText(_("The font colour."));
395 if (ShowToolTips()) m_colourChoice->SetToolTip(_("The font colour."));
396 itemBoxSizer14->Add(m_colourChoice, 0, wxALIGN_LEFT | wxALL, 5);
397 }
398
399 wxBoxSizer* itemBoxSizer17 = new wxBoxSizer(wxVERTICAL);
400 itemGridSizer4->Add(itemBoxSizer17, 0, wxALIGN_CENTER_HORIZONTAL | wxGROW, 5);
401 wxStaticText* itemStaticText18 =
402 new wxStaticText(this, wxID_STATIC, _("&Point size:"), wxDefaultPosition,
403 wxDefaultSize, 0);
404 itemBoxSizer17->Add(itemStaticText18, 0,
405 wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5);
406
407#if USE_SPINCTRL_FOR_POINT_SIZE
408 m_pointSizeSpin =
409 new wxSpinCtrl(this, wxID_FONT_SIZE, wxT("12"), wxDefaultPosition,
410 wxSize(80, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 500, 12);
411 m_pointSizeSpin->SetHelpText(_("The font point size."));
412 if (ShowToolTips()) m_pointSizeSpin->SetToolTip(_("The font point size."));
413 itemBoxSizer17->Add(m_pointSizeSpin, 0, wxALIGN_LEFT | wxALL, 5);
414#else
415 m_pointSizeChoice = new wxChoice(this, wxID_FONT_SIZE, wxDefaultPosition,
416 wxDefaultSize, 40, pointSizes, 0);
417 m_pointSizeChoice->SetHelpText(_("The font point size."));
418 if (ShowToolTips()) m_pointSizeChoice->SetToolTip(_("The font point size."));
419 itemBoxSizer17->Add(m_pointSizeChoice, 0, wxALIGN_LEFT | wxALL, 5);
420#endif
421
422 m_underLineCheckBox = NULL;
423 if (m_fontData.GetEnableEffects()) {
424 wxBoxSizer* itemBoxSizer20 = new wxBoxSizer(wxVERTICAL);
425 itemGridSizer4->Add(itemBoxSizer20, 0,
426 wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 5);
427 m_underLineCheckBox =
428 new wxCheckBox(this, wxID_FONT_UNDERLINE, _("&Underline"),
429 wxDefaultPosition, wxDefaultSize, 0);
430 m_underLineCheckBox->SetValue(false);
431 m_underLineCheckBox->SetHelpText(_("Whether the font is underlined."));
432 if (ShowToolTips())
433 m_underLineCheckBox->SetToolTip(_("Whether the font is underlined."));
434 itemBoxSizer20->Add(m_underLineCheckBox, 0, wxALIGN_LEFT | wxALL, 5);
435 }
436
437 if (!is_pda)
438 itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
439
440 wxStaticText* itemStaticText23 = new wxStaticText(
441 this, wxID_STATIC, _("Preview:"), wxDefaultPosition, wxDefaultSize, 0);
442 itemBoxSizer3->Add(itemStaticText23, 0,
443 wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5);
444
445 m_previewer = new OCPNFontPreviewer(this);
446 m_previewer->SetHelpText(_("Shows the font preview."));
447 if (ShowToolTips()) m_previewer->SetToolTip(_("Shows the font preview."));
448 itemBoxSizer3->Add(m_previewer, 1, wxGROW | wxALL, 5);
449
450 wxBoxSizer* itemBoxSizer25 = new wxBoxSizer(wxHORIZONTAL);
451 itemBoxSizer3->Add(itemBoxSizer25, 0, wxGROW, 5);
452 itemBoxSizer25->Add(5, 5, 1, wxGROW | wxALL, 5);
453
454#ifdef __WXMAC__
455 wxButton* itemButton28 = new wxButton(this, wxID_CANCEL, _("&Cancel"),
456 wxDefaultPosition, wxDefaultSize, 0);
457 if (ShowToolTips())
458 itemButton28->SetToolTip(_("Click to cancel the font selection."));
459 itemBoxSizer25->Add(itemButton28, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
460
461 wxButton* itemButton27 = new wxButton(this, wxID_OK, _("&OK"),
462 wxDefaultPosition, wxDefaultSize, 0);
463 itemButton27->SetDefault();
464 itemButton27->SetHelpText(_("Click to confirm the font selection."));
465 if (ShowToolTips())
466 itemButton27->SetToolTip(_("Click to confirm the font selection."));
467 itemBoxSizer25->Add(itemButton27, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
468#else
469 wxButton* itemButton27 = new wxButton(this, wxID_OK, _("&OK"),
470 wxDefaultPosition, wxDefaultSize, 0);
471 itemButton27->SetDefault();
472 itemButton27->SetHelpText(_("Click to confirm the font selection."));
473 if (ShowToolTips())
474 itemButton27->SetToolTip(_("Click to confirm the font selection."));
475 itemBoxSizer25->Add(itemButton27, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
476
477 wxButton* itemButton28 = new wxButton(this, wxID_CANCEL, _("&Cancel"),
478 wxDefaultPosition, wxDefaultSize, 0);
479 if (ShowToolTips())
480 itemButton28->SetToolTip(_("Click to cancel the font selection."));
481 itemBoxSizer25->Add(itemButton28, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
482#endif
483
484 m_familyChoice->SetStringSelection(
485 ocpnFontFamilyIntToString(m_dialogFont.GetFamily()));
486 m_styleChoice->SetStringSelection(
487 ocpnFontStyleIntToString(m_dialogFont.GetStyle()));
488 m_weightChoice->SetStringSelection(
489 ocpnFontWeightIntToString(m_dialogFont.GetWeight()));
490
491 if (m_colourChoice) {
492 wxString name(wxTheColourDatabase->FindName(m_fontData.GetColour()));
493 if (name.empty())
494 m_colourChoice->SetStringSelection(wxT("BLACK"));
495 else
496 m_colourChoice->SetStringSelection(name);
497 }
498
499 if (m_underLineCheckBox) {
500 m_underLineCheckBox->SetValue(m_dialogFont.GetUnderlined());
501 }
502
503#if USE_SPINCTRL_FOR_POINT_SIZE
504 m_pointSizeSpin->SetValue(m_dialogFont.GetPointSize());
505#else
506 m_pointSizeChoice->SetSelection(m_dialogFont.GetPointSize() - 1);
507#endif
508
509 GetSizer()->SetItemMinSize(m_previewer, is_pda ? 100 : 430,
510 is_pda ? 40 : 100);
511 GetSizer()->SetSizeHints(this);
512
513 Centre(wxBOTH);
514
515 delete[] families;
516 delete[] styles;
517 delete[] weights;
518#if !USE_SPINCTRL_FOR_POINT_SIZE
519 delete[] pointSizes;
520#endif
521
522 // Don't block events any more
523 m_useEvents = true;
524}
525
526void ocpnGenericFontDialog::InitializeFont() {
527 wxFontFamily fontFamily = wxFONTFAMILY_SWISS;
528 wxFontWeight fontWeight = wxFONTWEIGHT_NORMAL;
529 wxFontStyle fontStyle = wxFONTSTYLE_NORMAL;
530 int fontSize = 12;
531 bool fontUnderline = false;
532
533 if (m_fontData.m_initialFont.IsOk()) {
534 fontFamily = m_fontData.m_initialFont.GetFamily();
535 fontWeight = m_fontData.m_initialFont.GetWeight();
536 fontStyle = m_fontData.m_initialFont.GetStyle();
537 fontSize = m_fontData.m_initialFont.GetPointSize();
538 fontUnderline = m_fontData.m_initialFont.GetUnderlined();
539 }
540
541 m_dialogFont =
542 wxFont(fontSize, fontFamily, fontStyle, fontWeight, fontUnderline);
543
544 if (m_previewer) m_previewer->SetFont(m_dialogFont);
545}
546
547void ocpnGenericFontDialog::OnChangeFont(wxCommandEvent& WXUNUSED(event)) {
548 DoChangeFont();
549}
550
551void ocpnGenericFontDialog::DoChangeFont() {
552 if (!m_useEvents) return;
553
554 wxFontFamily fontFamily =
555 ocpnFontFamilyStringToInt(m_familyChoice->GetStringSelection());
556 wxFontWeight fontWeight =
557 ocpnFontWeightStringToInt(m_weightChoice->GetStringSelection());
558 wxFontStyle fontStyle =
559 ocpnFontStyleStringToInt(m_styleChoice->GetStringSelection());
560#if USE_SPINCTRL_FOR_POINT_SIZE
561 int fontSize = m_pointSizeSpin->GetValue();
562#else
563 int fontSize = wxAtoi(m_pointSizeChoice->GetStringSelection());
564#endif
565
566 // Start with previous underline setting, we want to retain it even if we
567 // can't edit it m_dialogFont is always initialized because of the call to
568 // InitializeFont
569 int fontUnderline = m_dialogFont.GetUnderlined();
570
571 if (m_underLineCheckBox) {
572 fontUnderline = m_underLineCheckBox->GetValue();
573 }
574
575 m_dialogFont =
576 wxFont(fontSize, fontFamily, fontStyle, fontWeight, (fontUnderline != 0));
577 m_previewer->SetFont(m_dialogFont);
578
579 if (m_colourChoice) {
580 if (!m_colourChoice->GetStringSelection().empty()) {
581 wxColour col =
582 wxTheColourDatabase->Find(m_colourChoice->GetStringSelection());
583 if (col.IsOk()) {
584 m_fontData.m_fontColour = col;
585 }
586 }
587 }
588 // Update color here so that we can also use the color originally passed in
589 // (EnableEffects may be false)
590 if (m_fontData.m_fontColour.IsOk())
591 m_previewer->SetForegroundColour(m_fontData.m_fontColour);
592
593 m_previewer->Refresh();
594}
595
596#if USE_SPINCTRL_FOR_POINT_SIZE
597void ocpnGenericFontDialog::OnChangeSize(wxSpinEvent& WXUNUSED(event)) {
598 DoChangeFont();
599}
600#endif
601
602#endif