2 Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "lib/subtitle_content.h"
22 #include "fonts_dialog.h"
29 using boost::shared_ptr;
31 FontsDialog::FontsDialog (wxWindow* parent, shared_ptr<SubtitleContent> content)
32 : wxDialog (parent, wxID_ANY, _("Fonts"))
35 _fonts = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize (400, 200), wxLC_REPORT | wxLC_SINGLE_SEL);
42 _fonts->InsertColumn (0, ip);
48 ip.SetText (_("Font file"));
50 _fonts->InsertColumn (1, ip);
53 wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
54 sizer->Add (_fonts, 1, wxEXPAND);
57 wxSizer* s = new wxBoxSizer (wxVERTICAL);
58 _set_file = new wxButton (this, wxID_ANY, _("Set file..."));
59 s->Add (_set_file, 0, wxTOP | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
60 sizer->Add (s, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP);
63 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
64 overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
66 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
68 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
71 SetSizerAndFit (overall_sizer);
73 _set_file->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&FontsDialog::set_file_clicked, this));
74 _fonts->Bind (wxEVT_COMMAND_LIST_ITEM_SELECTED, boost::bind (&FontsDialog::selection_changed, this));
75 _fonts->Bind (wxEVT_COMMAND_LIST_ITEM_DESELECTED, boost::bind (&FontsDialog::selection_changed, this));
78 update_sensitivity ();
84 shared_ptr<SubtitleContent> content = _content.lock ();
89 _fonts->DeleteAllItems ();
90 list<shared_ptr<Font> > fonts = content->fonts ();
92 for (list<shared_ptr<Font> >::const_iterator i = fonts.begin(); i != fonts.end(); ++i) {
95 _fonts->InsertItem (item);
96 _fonts->SetItem (n, 0, std_to_wx ((*i)->id ()));
98 _fonts->SetItem (n, 1, (*i)->file().get().leaf().string ());
105 FontsDialog::set_file_clicked ()
107 shared_ptr<SubtitleContent> content = _content.lock ();
112 int item = _fonts->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
117 /* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using
118 non-Latin filenames or paths.
120 wxFileDialog* d = new wxFileDialog (this, _("Choose a font file"), wxT (""), wxT (""), wxT ("*.ttf"), wxFD_CHANGE_DIR);
121 int const r = d->ShowModal ();
128 string id = wx_to_std (_fonts->GetItemText (item, 0));
130 list<shared_ptr<Font> > fonts = content->fonts ();
131 for (list<shared_ptr<Font> >::iterator i = fonts.begin(); i != fonts.end(); ++i) {
132 if ((*i)->id() == id) {
133 (*i)->set_file (wx_to_std (d->GetPath ()));
143 FontsDialog::selection_changed ()
145 update_sensitivity ();
149 FontsDialog::update_sensitivity ()
151 int const item = _fonts->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
152 _set_file->Enable (item != -1);