No-op; fix GPL address and use the explicit-program-name version.
[dcpomatic.git] / src / wx / fonts_dialog.cc
1 /*
2     Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "fonts_dialog.h"
22 #include "wx_util.h"
23 #include "system_font_dialog.h"
24 #include "font_files_dialog.h"
25 #include "lib/font.h"
26 #include "lib/content.h"
27 #include "lib/subtitle_content.h"
28 #include <wx/wx.h>
29 #include <boost/foreach.hpp>
30 #include <iostream>
31
32 using std::list;
33 using std::string;
34 using std::cout;
35 using boost::shared_ptr;
36
37 FontsDialog::FontsDialog (wxWindow* parent, shared_ptr<Content> content)
38         : wxDialog (parent, wxID_ANY, _("Fonts"))
39         , _content (content)
40 {
41         _fonts = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize (550, 200), wxLC_REPORT | wxLC_SINGLE_SEL);
42
43         {
44                 wxListItem ip;
45                 ip.SetId (0);
46                 ip.SetText (_("ID"));
47                 ip.SetWidth (100);
48                 _fonts->InsertColumn (0, ip);
49         }
50
51         {
52                 wxListItem ip;
53                 ip.SetId (1);
54                 ip.SetText (_("Normal file"));
55                 ip.SetWidth (150);
56                 _fonts->InsertColumn (1, ip);
57         }
58
59         {
60                 wxListItem ip;
61                 ip.SetId (2);
62                 ip.SetText (_("Italic file"));
63                 ip.SetWidth (150);
64                 _fonts->InsertColumn (2, ip);
65         }
66
67         {
68                 wxListItem ip;
69                 ip.SetId (3);
70                 ip.SetText (_("Bold file"));
71                 ip.SetWidth (150);
72                 _fonts->InsertColumn (3, ip);
73         }
74
75         wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
76         sizer->Add (_fonts, 1, wxEXPAND | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
77
78         _edit = new wxButton (this, wxID_ANY, _("Edit..."));
79         sizer->Add (_edit, 0, wxTOP | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
80
81         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
82         overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
83
84         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
85         if (buttons) {
86                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
87         }
88
89         SetSizerAndFit (overall_sizer);
90
91         _edit->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&FontsDialog::edit_clicked, this));
92         _fonts->Bind (wxEVT_COMMAND_LIST_ITEM_SELECTED, boost::bind (&FontsDialog::selection_changed, this));
93         _fonts->Bind (wxEVT_COMMAND_LIST_ITEM_DESELECTED, boost::bind (&FontsDialog::selection_changed, this));
94
95         setup ();
96 }
97
98 void
99 FontsDialog::setup ()
100 {
101         shared_ptr<Content> content = _content.lock ();
102         if (!content) {
103                 return;
104         }
105
106         _fonts->DeleteAllItems ();
107         size_t n = 0;
108         BOOST_FOREACH (shared_ptr<Font> i, content->subtitle->fonts ()) {
109                 wxListItem item;
110                 item.SetId (n);
111                 _fonts->InsertItem (item);
112                 _fonts->SetItem (n, 0, std_to_wx (i->id ()));
113                 if (i->file(FontFiles::NORMAL)) {
114                         _fonts->SetItem (n, 1, i->file(FontFiles::NORMAL).get().leaf().string ());
115                 }
116                 ++n;
117         }
118
119         setup_sensitivity ();
120 }
121
122 void
123 FontsDialog::selection_changed ()
124 {
125         setup_sensitivity ();
126 }
127
128 void
129 FontsDialog::setup_sensitivity ()
130 {
131         int const item = _fonts->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
132         _edit->Enable (item != -1);
133 }
134
135 void
136 FontsDialog::edit_clicked ()
137 {
138         shared_ptr<Content> content = _content.lock ();
139         if (!content) {
140                 return;
141         }
142
143         int const item = _fonts->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
144         string const id = wx_to_std (_fonts->GetItemText (item, 0));
145         shared_ptr<Font> font;
146         BOOST_FOREACH (shared_ptr<Font> i, content->subtitle->fonts()) {
147                 if (i->id() == id) {
148                         font = i;
149                 }
150         }
151
152         if (!font) {
153                 return;
154         }
155
156         FontFilesDialog* d = new FontFilesDialog (this, font->files ());
157         if (d->ShowModal () == wxID_OK) {
158                 font->set_files (d->get ());
159         }
160         d->Destroy ();
161
162         setup ();
163 }