| 1 |
#include "FontPickerDlg.h" |
| 2 |
#include "wxgui_helpers.h" |
| 3 |
#include <windowattrmanager.h> |
| 4 |
|
| 5 |
FontPickerDlg::FontPickerDlg(wxWindow* parent, const wxString& font) |
| 6 |
: FontPickerDlgBaseClass(parent) |
| 7 |
, m_fontname(font) |
| 8 |
{ |
| 9 |
wxFont f = wxCrafter::StringToFont(m_fontname); |
| 10 |
if(wxCrafter::IsSystemFont(m_fontname)) { |
| 11 |
wxString name = m_fontname.BeforeFirst(wxT(',')); |
| 12 |
int where = m_choiceSystemFonts->FindString(name); |
| 13 |
if(where != wxNOT_FOUND) { m_choiceSystemFonts->SetSelection(where); } |
| 14 |
|
| 15 |
m_checkBoxBold->SetValue(f.GetWeight() == wxFONTWEIGHT_BOLD); |
| 16 |
m_checkBoxItalic->SetValue(f.GetStyle() == wxFONTSTYLE_ITALIC); |
| 17 |
m_checkBoxUnderlined->SetValue(f.GetUnderlined()); |
| 18 |
m_checkBoxPreDefinedFont->SetValue(true); |
| 19 |
DoUpdateSelectionToPreDefinedFont(); |
| 20 |
|
| 21 |
} else if(f.IsOk()) { |
| 22 |
m_fontPicker->SetSelectedFont(f); |
| 23 |
m_checkBoxCustomFont->SetValue(true); |
| 24 |
DoUpdateSelectionToCustomFont(); |
| 25 |
} |
| 26 |
|
| 27 |
if(f.IsOk()) { |
| 28 |
m_staticTextSample->SetFont(f); |
| 29 |
m_staticTextSample->SetLabel(_("Sample Text")); |
| 30 |
} |
| 31 |
SetName("FontPickerDlg"); |
| 32 |
WindowAttrManager::Load(this); |
| 33 |
} |
| 34 |
|
| 35 |
FontPickerDlg::~FontPickerDlg() {} |
| 36 |
|
| 37 |
void FontPickerDlg::OnUseCustomFont(wxCommandEvent& event) |
| 38 |
{ |
| 39 |
m_checkBoxPreDefinedFont->SetValue(false); |
| 40 |
wxFont font = m_fontPicker->GetSelectedFont(); |
| 41 |
m_fontname = wxCrafter::FontToString(font); |
| 42 |
DoUpdateSelectionToCustomFont(); |
| 43 |
} |
| 44 |
|
| 45 |
void FontPickerDlg::OnUseCustomFontUI(wxUpdateUIEvent& event) { event.Enable(m_checkBoxCustomFont->IsChecked()); } |
| 46 |
|
| 47 |
void FontPickerDlg::OnUsePreDefinedFontUI(wxUpdateUIEvent& event) |
| 48 |
{ |
| 49 |
event.Enable(m_checkBoxPreDefinedFont->IsChecked()); |
| 50 |
} |
| 51 |
|
| 52 |
void FontPickerDlg::OnSystemFontSelected(wxCommandEvent& event) { DoUpdateSelectionToPreDefinedFont(); } |
| 53 |
|
| 54 |
void FontPickerDlg::OnFontSelected(wxFontPickerEvent& event) { DoUpdateSelectionToCustomFont(); } |
| 55 |
|
| 56 |
void FontPickerDlg::OnUsePreDefinedFont(wxCommandEvent& event) |
| 57 |
{ |
| 58 |
m_checkBoxCustomFont->SetValue(false); |
| 59 |
DoUpdateSelectionToPreDefinedFont(); |
| 60 |
} |
| 61 |
|
| 62 |
void FontPickerDlg::DoUpdateSelectionToPreDefinedFont() |
| 63 |
{ |
| 64 |
// Update the preview |
| 65 |
wxFont font = wxCrafter::StringToFont(m_choiceSystemFonts->GetStringSelection()); |
| 66 |
if(font.IsOk()) { |
| 67 |
|
| 68 |
if(wxCrafter::IsSystemFont(m_choiceSystemFonts->GetStringSelection())) { |
| 69 |
m_fontname = m_choiceSystemFonts->GetStringSelection(); |
| 70 |
if(m_checkBoxItalic->IsChecked()) { |
| 71 |
m_fontname << wxT(",italic"); |
| 72 |
font.SetStyle(wxFONTSTYLE_ITALIC); |
| 73 |
} else |
| 74 |
m_fontname << wxT(",normal"); |
| 75 |
|
| 76 |
if(m_checkBoxBold->IsChecked()) { |
| 77 |
m_fontname << wxT(",bold"); |
| 78 |
font.SetWeight(wxFONTWEIGHT_BOLD); |
| 79 |
} else |
| 80 |
m_fontname << wxT(",normal"); |
| 81 |
|
| 82 |
if(m_checkBoxUnderlined->IsChecked()) { |
| 83 |
m_fontname << wxT(",underlined"); |
| 84 |
font.SetUnderlined(true); |
| 85 |
} else |
| 86 |
m_fontname << wxT(",normal"); |
| 87 |
|
| 88 |
m_staticTextSample->SetFont(font); |
| 89 |
m_staticTextSample->SetLabel(_("Sample Text")); |
| 90 |
|
| 91 |
} else { |
| 92 |
m_fontname = wxCrafter::FontToString(font); |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
void FontPickerDlg::DoUpdateSelectionToCustomFont() |
| 97 |
{ |
| 98 |
wxFont font = m_fontPicker->GetSelectedFont(); |
| 99 |
m_fontname = wxCrafter::FontToString(font); |
| 100 |
|
| 101 |
m_staticTextSample->SetFont(font); |
| 102 |
m_staticTextSample->SetLabel(_("Sample Text")); |
| 103 |
} |