27#include <wx/checkbox.h>
30#include <wx/dcclient.h>
32#include <wx/fontdlg.h>
35#include <wx/listbox.h>
36#include <wx/settings.h>
38#include "wx/spinctrl.h"
39#include <wx/stattext.h>
52 : wxWindow(parent, wxID_ANY, wxDefaultPosition, sz) {}
55 void OnPaint(wxPaintEvent& event);
56 wxDECLARE_EVENT_TABLE();
60 EVT_PAINT(OCPNFontPreviewer::OnPaint) wxEND_EVENT_TABLE()
65 wxSize size = GetSize();
66 wxFont font = GetFont();
68 dc.SetPen(*wxBLACK_PEN);
69 dc.SetBrush(*wxWHITE_BRUSH);
70 dc.DrawRectangle(0, 0, size.x, size.y);
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();
86static const wxChar* ocpnFontWeightIntToString(
int weight) {
88 case wxFONTWEIGHT_LIGHT:
89 return wxString(
"Light");
90 case wxFONTWEIGHT_BOLD:
91 return wxString(
"Bold");
92 case wxFONTWEIGHT_NORMAL:
94 return wxString(
"Normal");
98static const wxChar* ocpnFontStyleIntToString(
int style) {
100 case wxFONTSTYLE_ITALIC:
101 return wxString(
"Italic");
102 case wxFONTSTYLE_SLANT:
103 return wxString(
"Slant");
104 case wxFONTSTYLE_NORMAL:
106 return wxString(
"Normal");
110static const wxChar* ocpnFontFamilyIntToString(
int 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:
124 return wxString(
"Swiss");
128static wxFontFamily ocpnFontFamilyStringToInt(
const wxString& family) {
129 if (family.empty())
return wxFONTFAMILY_SWISS;
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;
142 return wxFONTFAMILY_SWISS;
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;
152 return wxFONTSTYLE_NORMAL;
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;
162 return wxFONTWEIGHT_NORMAL;
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)
183 EVT_CHOICE(wxID_FONT_SIZE,
184 ocpnGenericFontDialog::OnChangeFont)
186 EVT_CLOSE(ocpnGenericFontDialog::OnCloseWindow)
191 ocpnColourDialogNames[NUM_COLS] = {
"ORANGE",
202 "MEDIUM SPRING GREEN",
237 "MEDIUM FOREST GREEN",
249void ocpnGenericFontDialog::Init() {
255ocpnGenericFontDialog::~ocpnGenericFontDialog() {}
257void ocpnGenericFontDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) {
258 EndModal(wxID_CANCEL);
261bool ocpnGenericFontDialog::DoCreate(wxWindow* parent) {
262 parent = GetParentForModalDialog(parent, 0);
264 if (!wxDialog::Create(parent, wxID_ANY,
"Choose Font", wxDefaultPosition,
265 wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
"fontdialog")) {
266 wxFAIL_MSG(
"wxFontDialog creation failed");
279int ocpnGenericFontDialog::ShowModal() {
280 int ret = wxDialog::ShowModal();
282 if (ret != wxID_CANCEL) {
283 m_fontData.m_chosenFont = m_dialogFont;
290static bool ShowToolTips() {
return false; }
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");
309 wxString* pointSizes =
new wxString[40];
311 for (i = 0; i < 40; i++) {
313 wxSprintf(buf,
"%d", i + 1);
320 bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
330 wxBoxSizer* itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
331 this->SetSizer(itemBoxSizer2);
333 wxBoxSizer* itemBoxSizer3 =
new wxBoxSizer(wxVERTICAL);
334 itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW | wxALL, 5);
336 wxFlexGridSizer* itemGridSizer4 =
new wxFlexGridSizer(noRows, noCols, 0, 0);
337 itemBoxSizer3->Add(itemGridSizer4, 0, wxGROW, 5);
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,
344 itemBoxSizer5->Add(itemStaticText6, 0,
345 wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5);
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);
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);
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);
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);
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);
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);
388 wxSize colourSize = wxDefaultSize;
389 if (is_pda) colourSize.x = 100;
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);
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,
404 itemBoxSizer17->Add(itemStaticText18, 0,
405 wxALIGN_LEFT | wxLEFT | wxRIGHT | wxTOP, 5);
407#if USE_SPINCTRL_FOR_POINT_SIZE
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);
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);
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."));
433 m_underLineCheckBox->SetToolTip(_(
"Whether the font is underlined."));
434 itemBoxSizer20->Add(m_underLineCheckBox, 0, wxALIGN_LEFT | wxALL, 5);
438 itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL | wxALL, 5);
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);
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);
450 wxBoxSizer* itemBoxSizer25 =
new wxBoxSizer(wxHORIZONTAL);
451 itemBoxSizer3->Add(itemBoxSizer25, 0, wxGROW, 5);
452 itemBoxSizer25->Add(5, 5, 1, wxGROW | wxALL, 5);
455 wxButton* itemButton28 =
new wxButton(
this, wxID_CANCEL, _(
"&Cancel"),
456 wxDefaultPosition, wxDefaultSize, 0);
458 itemButton28->SetToolTip(_(
"Click to cancel the font selection."));
459 itemBoxSizer25->Add(itemButton28, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
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."));
466 itemButton27->SetToolTip(_(
"Click to confirm the font selection."));
467 itemBoxSizer25->Add(itemButton27, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
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."));
474 itemButton27->SetToolTip(_(
"Click to confirm the font selection."));
475 itemBoxSizer25->Add(itemButton27, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
477 wxButton* itemButton28 =
new wxButton(
this, wxID_CANCEL, _(
"&Cancel"),
478 wxDefaultPosition, wxDefaultSize, 0);
480 itemButton28->SetToolTip(_(
"Click to cancel the font selection."));
481 itemBoxSizer25->Add(itemButton28, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
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()));
491 if (m_colourChoice) {
492 wxString name(wxTheColourDatabase->FindName(m_fontData.GetColour()));
494 m_colourChoice->SetStringSelection(
"BLACK");
496 m_colourChoice->SetStringSelection(name);
499 if (m_underLineCheckBox) {
500 m_underLineCheckBox->SetValue(m_dialogFont.GetUnderlined());
503#if USE_SPINCTRL_FOR_POINT_SIZE
504 m_pointSizeSpin->SetValue(m_dialogFont.GetPointSize());
506 m_pointSizeChoice->SetSelection(m_dialogFont.GetPointSize() - 1);
509 GetSizer()->SetItemMinSize(m_previewer, is_pda ? 100 : 430,
511 GetSizer()->SetSizeHints(
this);
518#if !USE_SPINCTRL_FOR_POINT_SIZE
526void ocpnGenericFontDialog::InitializeFont() {
527 wxFontFamily fontFamily = wxFONTFAMILY_SWISS;
528 wxFontWeight fontWeight = wxFONTWEIGHT_NORMAL;
529 wxFontStyle fontStyle = wxFONTSTYLE_NORMAL;
531 bool fontUnderline =
false;
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();
542 wxFont(fontSize, fontFamily, fontStyle, fontWeight, fontUnderline);
544 if (m_previewer) m_previewer->SetFont(m_dialogFont);
547void ocpnGenericFontDialog::OnChangeFont(wxCommandEvent& WXUNUSED(event)) {
551void ocpnGenericFontDialog::DoChangeFont() {
552 if (!m_useEvents)
return;
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();
563 int fontSize = wxAtoi(m_pointSizeChoice->GetStringSelection());
569 int fontUnderline = m_dialogFont.GetUnderlined();
571 if (m_underLineCheckBox) {
572 fontUnderline = m_underLineCheckBox->GetValue();
576 wxFont(fontSize, fontFamily, fontStyle, fontWeight, (fontUnderline != 0));
577 m_previewer->SetFont(m_dialogFont);
579 if (m_colourChoice) {
580 if (!m_colourChoice->GetStringSelection().empty()) {
582 wxTheColourDatabase->Find(m_colourChoice->GetStringSelection());
584 m_fontData.m_fontColour = col;
590 if (m_fontData.m_fontColour.IsOk())
591 m_previewer->SetForegroundColour(m_fontData.m_fontColour);
593 m_previewer->Refresh();
596#if USE_SPINCTRL_FOR_POINT_SIZE
597void ocpnGenericFontDialog::OnChangeSize(wxSpinEvent& WXUNUSED(event)) {
Generic font dialog for OpenCPN.