OpenCPN Partial API docs
Loading...
Searching...
No Matches
ocpn_fontdlg.cpp
Go to the documentation of this file.
1
2// Author: Julian Smart
3// Modified by: David S Register
4// Created: 04/01/98
5// Copyright: (c) Julian Smart, David S Register
6// Licence: wxWindows licence
8
15#include <stdio.h>
16#include <string.h>
17#include <stdlib.h>
18
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#if 1 // wxUSE_FONTDLG && (defined(__WXGTK__) || defined(__WXGPE__) ||
23 // defined(__WXUNIVERSAL__))
24
25#ifndef WX_PRECOMP
26#include <wx/button.h>
27#include <wx/checkbox.h>
28#include <wx/choice.h>
29#include <wx/crt.h>
30#include <wx/dcclient.h>
31#include <wx/dialog.h>
32#include <wx/fontdlg.h>
33#include <wx/intl.h>
34#include <wx/layout.h>
35#include <wx/listbox.h>
36#include <wx/settings.h>
37#include <wx/sizer.h>
38#include "wx/spinctrl.h"
39#include <wx/stattext.h>
40#include <wx/utils.h>
41#endif
42
43#include "ocpn_fontdlg.h"
44
45//-----------------------------------------------------------------------------
46// helper class - wxFontPreviewer
47//-----------------------------------------------------------------------------
48
49class WXDLLEXPORT OCPNFontPreviewer : public wxWindow {
50public:
51 OCPNFontPreviewer(wxWindow* parent, const wxSize& sz = wxDefaultSize)
52 : wxWindow(parent, wxID_ANY, wxDefaultPosition, sz) {}
53
54private:
55 void OnPaint(wxPaintEvent& event);
56 wxDECLARE_EVENT_TABLE();
57};
58
59wxBEGIN_EVENT_TABLE(OCPNFontPreviewer, wxWindow)
60 EVT_PAINT(OCPNFontPreviewer::OnPaint) wxEND_EVENT_TABLE()
61
62 void OCPNFontPreviewer::OnPaint(wxPaintEvent& WXUNUSED(event)) {
63 wxPaintDC dc(this);
64
65 wxSize size = GetSize();
66 wxFont font = GetFont();
67
68 dc.SetPen(*wxBLACK_PEN);
69 dc.SetBrush(*wxWHITE_BRUSH);
70 dc.DrawRectangle(0, 0, size.x, size.y);
71
72 if (font.IsOk()) {
73 dc.SetFont(font);
74 dc.SetTextForeground(GetForegroundColour());
75 dc.SetClippingRegion(2, 2, size.x - 4, size.y - 4);
76 dc.DrawText(_("ABCDEFGabcdefg12345"), 10,
77 (size.y - dc.GetTextExtent("X").y) / 2);
78 dc.DestroyClippingRegion();
79 }
80}
81
82//-----------------------------------------------------------------------------
83// helper functions
84//-----------------------------------------------------------------------------
85
86static const wxChar* ocpnFontWeightIntToString(int weight) {
87 switch (weight) {
88 case wxFONTWEIGHT_LIGHT:
89 return wxString("Light");
90 case wxFONTWEIGHT_BOLD:
91 return wxString("Bold");
92 case wxFONTWEIGHT_NORMAL:
93 default:
94 return wxString("Normal");
95 }
96}
97
98static const wxChar* ocpnFontStyleIntToString(int style) {
99 switch (style) {
100 case wxFONTSTYLE_ITALIC:
101 return wxString("Italic");
102 case wxFONTSTYLE_SLANT:
103 return wxString("Slant");
104 case wxFONTSTYLE_NORMAL:
105 default:
106 return wxString("Normal");
107 }
108}
109
110static const wxChar* ocpnFontFamilyIntToString(int family) {
111 switch (family) {
112 case wxFONTFAMILY_ROMAN:
113 return wxString("Roman");
114 case wxFONTFAMILY_DECORATIVE:
115 return wxString("Decorative");
116 case wxFONTFAMILY_MODERN:
117 return wxString("Modern");
118 case wxFONTFAMILY_SCRIPT:
119 return wxString("Script");
120 case wxFONTFAMILY_TELETYPE:
121 return wxString("Teletype");
122 case wxFONTFAMILY_SWISS:
123 default:
124 return wxString("Swiss");
125 }
126}
127
128static wxFontFamily ocpnFontFamilyStringToInt(const wxString& family) {
129 if (family.empty()) return wxFONTFAMILY_SWISS;
130
131 if (wxStrcmp(family, "Roman") == 0)
132 return wxFONTFAMILY_ROMAN;
133 else if (wxStrcmp(family, "Decorative") == 0)
134 return wxFONTFAMILY_DECORATIVE;
135 else if (wxStrcmp(family, "Modern") == 0)
136 return wxFONTFAMILY_MODERN;
137 else if (wxStrcmp(family, "Script") == 0)
138 return wxFONTFAMILY_SCRIPT;
139 else if (wxStrcmp(family, "Teletype") == 0)
140 return wxFONTFAMILY_TELETYPE;
141 else
142 return wxFONTFAMILY_SWISS;
143}
144
145static wxFontStyle ocpnFontStyleStringToInt(const wxString& style) {
146 if (style.empty()) return wxFONTSTYLE_NORMAL;
147 if (wxStrcmp(style, "Italic") == 0)
148 return wxFONTSTYLE_ITALIC;
149 else if (wxStrcmp(style, "Slant") == 0)
150 return wxFONTSTYLE_SLANT;
151 else
152 return wxFONTSTYLE_NORMAL;
153}
154
155static wxFontWeight ocpnFontWeightStringToInt(const wxString& weight) {
156 if (weight.empty()) return wxFONTWEIGHT_NORMAL;
157 if (wxStrcmp(weight, "Bold") == 0)
158 return wxFONTWEIGHT_BOLD;
159 else if (wxStrcmp(weight, "Light") == 0)
160 return wxFONTWEIGHT_LIGHT;
161 else
162 return wxFONTWEIGHT_NORMAL;
163}
164
165//-----------------------------------------------------------------------------
166// ocpnGenericFontDialog
167//-----------------------------------------------------------------------------
168
169wxBEGIN_EVENT_TABLE(ocpnGenericFontDialog, wxDialog)
170 EVT_CHECKBOX(wxID_FONT_UNDERLINE, ocpnGenericFontDialog::OnChangeFont)
171 EVT_CHOICE(wxID_FONT_STYLE, ocpnGenericFontDialog::OnChangeFont)
172 EVT_CHOICE(wxID_FONT_WEIGHT, ocpnGenericFontDialog::OnChangeFont)
173 EVT_CHOICE(wxID_FONT_FAMILY,
174 ocpnGenericFontDialog::OnChangeFont)
175 EVT_CHOICE(wxID_FONT_COLOUR,
176 ocpnGenericFontDialog::OnChangeFont)
177#if USE_SPINCTRL_FOR_POINT_SIZE
178 EVT_SPINCTRL(wxID_FONT_SIZE,
179 ocpnGenericFontDialog::OnChangeSize)
180 EVT_TEXT(wxID_FONT_SIZE,
181 ocpnGenericFontDialog::OnChangeFont)
182#else
183 EVT_CHOICE(wxID_FONT_SIZE,
184 ocpnGenericFontDialog::OnChangeFont)
185#endif
186 EVT_CLOSE(ocpnGenericFontDialog::OnCloseWindow)
187 wxEND_EVENT_TABLE()
188
189#define NUM_COLS 48
190 static wxString
191 ocpnColourDialogNames[NUM_COLS] = {"ORANGE",
192 "GOLDENROD",
193 "WHEAT",
194 "SPRING GREEN",
195 "SKY BLUE",
196 "SLATE BLUE",
197 "MEDIUM VIOLET RED",
198 "PURPLE",
199
200 "RED",
201 "YELLOW",
202 "MEDIUM SPRING GREEN",
203 "PALE GREEN",
204 "CYAN",
205 "LIGHT STEEL BLUE",
206 "ORCHID",
207 "LIGHT MAGENTA",
208
209 "BROWN",
210 "YELLOW",
211 "GREEN",
212 "CADET BLUE",
213 "MEDIUM BLUE",
214 "MAGENTA",
215 "MAROON",
216 "ORANGE RED",
217
218 "FIREBRICK",
219 "CORAL",
220 "FOREST GREEN",
221 "AQUAMARINE",
222 "BLUE",
223 "NAVY",
224 "THISTLE",
225 "MEDIUM VIOLET RED",
226
227 "INDIAN RED",
228 "GOLD",
229 "MEDIUM SEA GREEN",
230 "MEDIUM BLUE",
231 "MIDNIGHT BLUE",
232 "GREY",
233 "PURPLE",
234 "KHAKI",
235
236 "BLACK",
237 "MEDIUM FOREST GREEN",
238 "KHAKI",
239 "DARK GREY",
240 "SEA GREEN",
241 "LIGHT GREY",
242 "MEDIUM SLATE BLUE",
243 "WHITE"};
244
245/*
246 * Generic wxFontDialog
247 */
248
249void ocpnGenericFontDialog::Init() {
250 m_useEvents = false;
251 m_previewer = NULL;
252 Create(m_parent);
253}
254
255ocpnGenericFontDialog::~ocpnGenericFontDialog() {}
256
257void ocpnGenericFontDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) {
258 EndModal(wxID_CANCEL);
259}
260
261bool ocpnGenericFontDialog::DoCreate(wxWindow* parent) {
262 parent = GetParentForModalDialog(parent, 0);
263
264 if (!wxDialog::Create(parent, wxID_ANY, "Choose Font", wxDefaultPosition,
265 wxDefaultSize, wxDEFAULT_DIALOG_STYLE, "fontdialog")) {
266 wxFAIL_MSG("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, "%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, "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("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
Generic font dialog for OpenCPN.