2 Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "fonts_dialog.h"
23 #include "system_font_dialog.h"
24 #include "font_files_dialog.h"
26 #include "lib/content.h"
27 #include "lib/subtitle_content.h"
29 #include <boost/foreach.hpp>
35 using boost::shared_ptr;
37 FontsDialog::FontsDialog (wxWindow* parent, shared_ptr<Content> content)
38 : wxDialog (parent, wxID_ANY, _("Fonts"))
41 _fonts = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize (550, 200), wxLC_REPORT | wxLC_SINGLE_SEL);
48 _fonts->InsertColumn (0, ip);
54 ip.SetText (_("Normal file"));
56 _fonts->InsertColumn (1, ip);
62 ip.SetText (_("Italic file"));
64 _fonts->InsertColumn (2, ip);
70 ip.SetText (_("Bold file"));
72 _fonts->InsertColumn (3, ip);
75 wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
76 sizer->Add (_fonts, 1, wxEXPAND | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
78 _edit = new wxButton (this, wxID_ANY, _("Edit..."));
79 sizer->Add (_edit, 0, wxTOP | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
81 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
82 overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
84 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
86 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
89 SetSizerAndFit (overall_sizer);
91 _edit->Bind (wxEVT_BUTTON, boost::bind (&FontsDialog::edit_clicked, this));
92 _fonts->Bind (wxEVT_LIST_ITEM_SELECTED, boost::bind (&FontsDialog::selection_changed, this));
93 _fonts->Bind (wxEVT_LIST_ITEM_DESELECTED, boost::bind (&FontsDialog::selection_changed, this));
101 shared_ptr<Content> content = _content.lock ();
106 _fonts->DeleteAllItems ();
108 BOOST_FOREACH (shared_ptr<Font> i, content->subtitle->fonts ()) {
111 _fonts->InsertItem (item);
112 _fonts->SetItem (n, 0, std_to_wx (i->id ()));
113 for (int j = 0; j < FontFiles::VARIANTS; ++j) {
114 if (i->file(static_cast<FontFiles::Variant>(j))) {
115 _fonts->SetItem (n, j + 1, i->file(static_cast<FontFiles::Variant>(j)).get().leaf().string ());
121 setup_sensitivity ();
125 FontsDialog::selection_changed ()
127 setup_sensitivity ();
131 FontsDialog::setup_sensitivity ()
133 int const item = _fonts->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
134 _edit->Enable (item != -1);
138 FontsDialog::edit_clicked ()
140 shared_ptr<Content> content = _content.lock ();
145 int const item = _fonts->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
146 string const id = wx_to_std (_fonts->GetItemText (item, 0));
147 shared_ptr<Font> font;
148 BOOST_FOREACH (shared_ptr<Font> i, content->subtitle->fonts()) {
158 FontFilesDialog* d = new FontFilesDialog (this, font->files ());
159 if (d->ShowModal () == wxID_OK) {
160 font->set_files (d->get ());