12 #include "wx/wxprec.h"
20 #include "wx/dialog.h"
21 #include "wx/listbox.h"
22 #include "wx/button.h"
23 #include "wx/stattext.h"
24 #include "wx/layout.h"
25 #include "wx/dcclient.h"
26 #include "wx/choice.h"
27 #include "wx/checkbox.h"
29 #include "wx/settings.h"
36 #include "wx/fontdlg.h"
37 #include "ocpn_fontdlg.h"
39 #if USE_SPINCTRL_FOR_POINT_SIZE
40 #include "wx/spinctrl.h"
50 OCPNFontPreviewer(wxWindow *parent,
const wxSize& sz = wxDefaultSize) : wxWindow(parent, wxID_ANY, wxDefaultPosition, sz)
55 void OnPaint(wxPaintEvent& event);
56 wxDECLARE_EVENT_TABLE();
60 EVT_PAINT(OCPNFontPreviewer::OnPaint)
67 wxSize size = GetSize();
68 wxFont font = GetFont();
70 dc.SetPen(*wxBLACK_PEN);
71 dc.SetBrush(*wxWHITE_BRUSH);
72 dc.DrawRectangle(0, 0, size.x, size.y);
77 dc.SetTextForeground(GetForegroundColour());
78 dc.SetClippingRegion(2, 2, size.x-4, size.y-4);
79 dc.DrawText(_(
"ABCDEFGabcdefg12345"),
80 10, (size.y - dc.GetTextExtent(wxT(
"X")).y)/2);
81 dc.DestroyClippingRegion();
89 static const wxChar *ocpnFontWeightIntToString(
int weight)
93 case wxFONTWEIGHT_LIGHT:
95 case wxFONTWEIGHT_BOLD:
97 case wxFONTWEIGHT_NORMAL:
103 static const wxChar *ocpnFontStyleIntToString(
int style)
107 case wxFONTSTYLE_ITALIC:
108 return wxT(
"Italic");
109 case wxFONTSTYLE_SLANT:
111 case wxFONTSTYLE_NORMAL:
113 return wxT(
"Normal");
117 static const wxChar *ocpnFontFamilyIntToString(
int family)
121 case wxFONTFAMILY_ROMAN:
123 case wxFONTFAMILY_DECORATIVE:
124 return wxT(
"Decorative");
125 case wxFONTFAMILY_MODERN:
126 return wxT(
"Modern");
127 case wxFONTFAMILY_SCRIPT:
128 return wxT(
"Script");
129 case wxFONTFAMILY_TELETYPE:
130 return wxT(
"Teletype");
131 case wxFONTFAMILY_SWISS:
137 static wxFontFamily ocpnFontFamilyStringToInt(
const wxString& family)
140 return wxFONTFAMILY_SWISS;
142 if (wxStrcmp(family, wxT(
"Roman")) == 0)
143 return wxFONTFAMILY_ROMAN;
144 else if (wxStrcmp(family, wxT(
"Decorative")) == 0)
145 return wxFONTFAMILY_DECORATIVE;
146 else if (wxStrcmp(family, wxT(
"Modern")) == 0)
147 return wxFONTFAMILY_MODERN;
148 else if (wxStrcmp(family, wxT(
"Script")) == 0)
149 return wxFONTFAMILY_SCRIPT;
150 else if (wxStrcmp(family, wxT(
"Teletype")) == 0)
151 return wxFONTFAMILY_TELETYPE;
152 else return wxFONTFAMILY_SWISS;
155 static wxFontStyle ocpnFontStyleStringToInt(
const wxString& style)
158 return wxFONTSTYLE_NORMAL;
159 if (wxStrcmp(style, wxT(
"Italic")) == 0)
160 return wxFONTSTYLE_ITALIC;
161 else if (wxStrcmp(style, wxT(
"Slant")) == 0)
162 return wxFONTSTYLE_SLANT;
164 return wxFONTSTYLE_NORMAL;
167 static wxFontWeight ocpnFontWeightStringToInt(
const wxString& weight)
170 return wxFONTWEIGHT_NORMAL;
171 if (wxStrcmp(weight, wxT(
"Bold")) == 0)
172 return wxFONTWEIGHT_BOLD;
173 else if (wxStrcmp(weight, wxT(
"Light")) == 0)
174 return wxFONTWEIGHT_LIGHT;
176 return wxFONTWEIGHT_NORMAL;
186 EVT_CHECKBOX(wxID_FONT_UNDERLINE, ocpnGenericFontDialog::OnChangeFont)
187 EVT_CHOICE(wxID_FONT_STYLE, ocpnGenericFontDialog::OnChangeFont)
188 EVT_CHOICE(wxID_FONT_WEIGHT, ocpnGenericFontDialog::OnChangeFont)
189 EVT_CHOICE(wxID_FONT_FAMILY, ocpnGenericFontDialog::OnChangeFont)
190 EVT_CHOICE(wxID_FONT_COLOUR, ocpnGenericFontDialog::OnChangeFont)
191 #if USE_SPINCTRL_FOR_POINT_SIZE
192 EVT_SPINCTRL(wxID_FONT_SIZE, ocpnGenericFontDialog::OnChangeSize)
193 EVT_TEXT(wxID_FONT_SIZE, ocpnGenericFontDialog::OnChangeFont)
195 EVT_CHOICE(wxID_FONT_SIZE, ocpnGenericFontDialog::OnChangeFont)
197 EVT_CLOSE(ocpnGenericFontDialog::OnCloseWindow)
202 static wxString ocpnColourDialogNames[NUM_COLS]={wxT(
"ORANGE"),
208 wxT(
"MEDIUM VIOLET RED"),
213 wxT(
"MEDIUM SPRING GREEN"),
216 wxT(
"LIGHT STEEL BLUE"),
218 wxT(
"LIGHT MAGENTA"),
236 wxT(
"MEDIUM VIOLET RED"),
240 wxT(
"MEDIUM SEA GREEN"),
242 wxT(
"MIDNIGHT BLUE"),
248 wxT(
"MEDIUM FOREST GREEN"),
253 wxT(
"MEDIUM SLATE BLUE"),
261 void ocpnGenericFontDialog::Init()
268 ocpnGenericFontDialog::~ocpnGenericFontDialog()
272 void ocpnGenericFontDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
274 EndModal(wxID_CANCEL);
277 bool ocpnGenericFontDialog::DoCreate(wxWindow *parent)
279 parent = GetParentForModalDialog(parent, 0);
281 if ( !wxDialog::Create( parent , wxID_ANY , wxT(
"Choose Font") ,
282 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
283 wxT(
"fontdialog") ) )
285 wxFAIL_MSG( wxT(
"wxFontDialog creation failed") );
298 int ocpnGenericFontDialog::ShowModal()
300 int ret = wxDialog::ShowModal();
302 if (ret != wxID_CANCEL)
304 m_fontData.m_chosenFont = m_dialogFont;
311 static bool ShowToolTips() {
return false; }
313 void ocpnGenericFontDialog::CreateWidgets()
315 wxString *families =
new wxString[6],
316 *styles =
new wxString[3],
317 *weights =
new wxString[3];
318 families[0] = _(
"Roman");
319 families[1] = _(
"Decorative");
320 families[2] = _(
"Modern");
321 families[3] = _(
"Script");
322 families[4] = _(
"Swiss" );
323 families[5] = _(
"Teletype" );
324 styles[0] = _(
"Normal");
325 styles[1] = _(
"Italic");
326 styles[2] = _(
"Slant");
327 weights[0] = _(
"Normal");
328 weights[1] = _(
"Light");
329 weights[2] = _(
"Bold");
332 wxString *pointSizes =
new wxString[40];
334 for ( i = 0; i < 40; i++)
337 wxSprintf(buf, wxT(
"%d"), i + 1);
344 bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
348 noCols = 2; noRows = 3;
352 noCols = 3; noRows = 2;
355 wxBoxSizer* itemBoxSizer2 =
new wxBoxSizer(wxVERTICAL);
356 this->SetSizer(itemBoxSizer2);
358 wxBoxSizer* itemBoxSizer3 =
new wxBoxSizer(wxVERTICAL);
359 itemBoxSizer2->Add(itemBoxSizer3, 1, wxGROW|wxALL, 5);
361 wxFlexGridSizer* itemGridSizer4 =
new wxFlexGridSizer(noRows, noCols, 0, 0);
362 itemBoxSizer3->Add(itemGridSizer4, 0, wxGROW, 5);
364 wxBoxSizer* itemBoxSizer5 =
new wxBoxSizer(wxVERTICAL);
365 itemGridSizer4->Add(itemBoxSizer5, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5);
366 wxStaticText* itemStaticText6 =
new wxStaticText(
this, wxID_STATIC, _(
"&Font family:"), wxDefaultPosition, wxDefaultSize, 0 );
367 itemBoxSizer5->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
369 m_familyChoice =
new wxChoice(
this, wxID_FONT_FAMILY, wxDefaultPosition, wxDefaultSize, 5, families, 0 );
370 m_familyChoice->SetHelpText(_(
"The font family."));
372 m_familyChoice->SetToolTip(_(
"The font family."));
373 itemBoxSizer5->Add(m_familyChoice, 0, wxALIGN_LEFT|wxALL, 5);
375 wxBoxSizer* itemBoxSizer8 =
new wxBoxSizer(wxVERTICAL);
376 itemGridSizer4->Add(itemBoxSizer8, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5);
377 wxStaticText* itemStaticText9 =
new wxStaticText(
this, wxID_STATIC, _(
"&Style:"), wxDefaultPosition, wxDefaultSize, 0 );
378 itemBoxSizer8->Add(itemStaticText9, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
380 m_styleChoice =
new wxChoice(
this, wxID_FONT_STYLE, wxDefaultPosition, wxDefaultSize, 3, styles, 0 );
381 m_styleChoice->SetHelpText(_(
"The font style."));
383 m_styleChoice->SetToolTip(_(
"The font style."));
384 itemBoxSizer8->Add(m_styleChoice, 0, wxALIGN_LEFT|wxALL, 5);
386 wxBoxSizer* itemBoxSizer11 =
new wxBoxSizer(wxVERTICAL);
387 itemGridSizer4->Add(itemBoxSizer11, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5);
388 wxStaticText* itemStaticText12 =
new wxStaticText(
this, wxID_STATIC, _(
"&Weight:"), wxDefaultPosition, wxDefaultSize, 0 );
389 itemBoxSizer11->Add(itemStaticText12, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
391 m_weightChoice =
new wxChoice(
this, wxID_FONT_WEIGHT, wxDefaultPosition, wxDefaultSize, 3, weights, 0 );
392 m_weightChoice->SetHelpText(_(
"The font weight."));
394 m_weightChoice->SetToolTip(_(
"The font weight."));
395 itemBoxSizer11->Add(m_weightChoice, 0, wxALIGN_LEFT|wxALL, 5);
397 wxBoxSizer* itemBoxSizer14 =
new wxBoxSizer(wxVERTICAL);
398 itemGridSizer4->Add(itemBoxSizer14, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5);
399 m_colourChoice = NULL;
400 if (m_fontData.GetEnableEffects())
402 wxStaticText* itemStaticText15 =
new wxStaticText(
this, wxID_STATIC, _(
"C&olour:"), wxDefaultPosition, wxDefaultSize, 0 );
403 itemBoxSizer14->Add(itemStaticText15, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
405 wxSize colourSize = wxDefaultSize;
409 m_colourChoice =
new wxChoice(
this, wxID_FONT_COLOUR, wxDefaultPosition, colourSize, NUM_COLS, ocpnColourDialogNames, 0 );
410 m_colourChoice->SetHelpText(_(
"The font colour."));
412 m_colourChoice->SetToolTip(_(
"The font colour."));
413 itemBoxSizer14->Add(m_colourChoice, 0, wxALIGN_LEFT|wxALL, 5);
416 wxBoxSizer* itemBoxSizer17 =
new wxBoxSizer(wxVERTICAL);
417 itemGridSizer4->Add(itemBoxSizer17, 0, wxALIGN_CENTER_HORIZONTAL|wxGROW, 5);
418 wxStaticText* itemStaticText18 =
new wxStaticText(
this, wxID_STATIC, _(
"&Point size:"), wxDefaultPosition, wxDefaultSize, 0 );
419 itemBoxSizer17->Add(itemStaticText18, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
421 #if USE_SPINCTRL_FOR_POINT_SIZE
422 m_pointSizeSpin =
new wxSpinCtrl(
this, wxID_FONT_SIZE, wxT(
"12"), wxDefaultPosition, wxSize(80, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 500, 12);
423 m_pointSizeSpin->SetHelpText(_(
"The font point size."));
425 m_pointSizeSpin->SetToolTip(_(
"The font point size."));
426 itemBoxSizer17->Add(m_pointSizeSpin, 0, wxALIGN_LEFT|wxALL, 5);
428 m_pointSizeChoice =
new wxChoice(
this, wxID_FONT_SIZE, wxDefaultPosition, wxDefaultSize, 40, pointSizes, 0 );
429 m_pointSizeChoice->SetHelpText(_(
"The font point size."));
431 m_pointSizeChoice->SetToolTip(_(
"The font point size."));
432 itemBoxSizer17->Add(m_pointSizeChoice, 0, wxALIGN_LEFT|wxALL, 5);
435 m_underLineCheckBox = NULL;
436 if (m_fontData.GetEnableEffects())
438 wxBoxSizer* itemBoxSizer20 =
new wxBoxSizer(wxVERTICAL);
439 itemGridSizer4->Add(itemBoxSizer20, 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL, 5);
440 m_underLineCheckBox =
new wxCheckBox(
this, wxID_FONT_UNDERLINE, _(
"&Underline"), wxDefaultPosition, wxDefaultSize, 0 );
441 m_underLineCheckBox->SetValue(
false);
442 m_underLineCheckBox->SetHelpText(_(
"Whether the font is underlined."));
444 m_underLineCheckBox->SetToolTip(_(
"Whether the font is underlined."));
445 itemBoxSizer20->Add(m_underLineCheckBox, 0, wxALIGN_LEFT|wxALL, 5);
449 itemBoxSizer3->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
451 wxStaticText* itemStaticText23 =
new wxStaticText(
this, wxID_STATIC, _(
"Preview:"), wxDefaultPosition, wxDefaultSize, 0 );
452 itemBoxSizer3->Add(itemStaticText23, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
455 m_previewer->SetHelpText(_(
"Shows the font preview."));
457 m_previewer->SetToolTip(_(
"Shows the font preview."));
458 itemBoxSizer3->Add(m_previewer, 1, wxGROW|wxALL, 5);
460 wxBoxSizer* itemBoxSizer25 =
new wxBoxSizer(wxHORIZONTAL);
461 itemBoxSizer3->Add(itemBoxSizer25, 0, wxGROW, 5);
462 itemBoxSizer25->Add(5, 5, 1, wxGROW|wxALL, 5);
465 wxButton* itemButton28 =
new wxButton(
this, wxID_CANCEL, _(
"&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
467 itemButton28->SetToolTip(_(
"Click to cancel the font selection."));
468 itemBoxSizer25->Add(itemButton28, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
470 wxButton* itemButton27 =
new wxButton(
this, wxID_OK, _(
"&OK"), 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* itemButton27 =
new wxButton(
this, wxID_OK, _(
"&OK"), wxDefaultPosition, wxDefaultSize, 0 );
478 itemButton27->SetDefault();
479 itemButton27->SetHelpText(_(
"Click to confirm the font selection."));
481 itemButton27->SetToolTip(_(
"Click to confirm the font selection."));
482 itemBoxSizer25->Add(itemButton27, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
484 wxButton* itemButton28 =
new wxButton(
this, wxID_CANCEL, _(
"&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
486 itemButton28->SetToolTip(_(
"Click to cancel the font selection."));
487 itemBoxSizer25->Add(itemButton28, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
490 m_familyChoice->SetStringSelection( ocpnFontFamilyIntToString(m_dialogFont.GetFamily()) );
491 m_styleChoice->SetStringSelection(ocpnFontStyleIntToString(m_dialogFont.GetStyle()));
492 m_weightChoice->SetStringSelection(ocpnFontWeightIntToString(m_dialogFont.GetWeight()));
496 wxString name(wxTheColourDatabase->FindName(m_fontData.GetColour()));
498 m_colourChoice->SetStringSelection(wxT(
"BLACK"));
500 m_colourChoice->SetStringSelection(name);
503 if (m_underLineCheckBox)
505 m_underLineCheckBox->SetValue(m_dialogFont.GetUnderlined());
508 #if USE_SPINCTRL_FOR_POINT_SIZE
509 m_pointSizeSpin->SetValue(m_dialogFont.GetPointSize());
511 m_pointSizeChoice->SetSelection(m_dialogFont.GetPointSize()-1);
514 GetSizer()->SetItemMinSize(m_previewer, is_pda ? 100 : 430, is_pda ? 40 : 100);
515 GetSizer()->SetSizeHints(
this);
522 #if !USE_SPINCTRL_FOR_POINT_SIZE
531 void ocpnGenericFontDialog::InitializeFont()
533 wxFontFamily fontFamily = wxFONTFAMILY_SWISS;
534 wxFontWeight fontWeight = wxFONTWEIGHT_NORMAL;
535 wxFontStyle fontStyle = wxFONTSTYLE_NORMAL;
537 bool fontUnderline =
false;
539 if (m_fontData.m_initialFont.IsOk())
541 fontFamily = m_fontData.m_initialFont.GetFamily();
542 fontWeight = m_fontData.m_initialFont.GetWeight();
543 fontStyle = m_fontData.m_initialFont.GetStyle();
544 fontSize = m_fontData.m_initialFont.GetPointSize();
545 fontUnderline = m_fontData.m_initialFont.GetUnderlined();
548 m_dialogFont = wxFont(fontSize, fontFamily, fontStyle,
549 fontWeight, fontUnderline);
552 m_previewer->SetFont(m_dialogFont);
555 void ocpnGenericFontDialog::OnChangeFont(wxCommandEvent& WXUNUSED(event))
560 void ocpnGenericFontDialog::DoChangeFont()
562 if (!m_useEvents)
return;
564 wxFontFamily fontFamily = ocpnFontFamilyStringToInt(m_familyChoice->GetStringSelection());
565 wxFontWeight fontWeight = ocpnFontWeightStringToInt(m_weightChoice->GetStringSelection());
566 wxFontStyle fontStyle = ocpnFontStyleStringToInt(m_styleChoice->GetStringSelection());
567 #if USE_SPINCTRL_FOR_POINT_SIZE
568 int fontSize = m_pointSizeSpin->GetValue();
570 int fontSize = wxAtoi(m_pointSizeChoice->GetStringSelection());
575 int fontUnderline = m_dialogFont.GetUnderlined();
577 if (m_underLineCheckBox)
579 fontUnderline = m_underLineCheckBox->GetValue();
582 m_dialogFont = wxFont(fontSize, fontFamily, fontStyle, fontWeight, (fontUnderline != 0));
583 m_previewer->SetFont(m_dialogFont);
585 if ( m_colourChoice )
587 if ( !m_colourChoice->GetStringSelection().empty() )
589 wxColour col = wxTheColourDatabase->Find(m_colourChoice->GetStringSelection());
592 m_fontData.m_fontColour = col;
598 if (m_fontData.m_fontColour.IsOk())
599 m_previewer->SetForegroundColour(m_fontData.m_fontColour);
601 m_previewer->Refresh();
604 #if USE_SPINCTRL_FOR_POINT_SIZE
605 void ocpnGenericFontDialog::OnChangeSize(wxSpinEvent& WXUNUSED(event))