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