Start of Fonts dialog for setting up subtitle fonts.
[dcpomatic.git] / src / wx / fonts_dialog.cc
1 /*
2     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include "lib/font.h"
21 #include "lib/subtitle_content.h"
22 #include "fonts_dialog.h"
23 #include "wx_util.h"
24 #include <wx/wx.h>
25
26 using std::list;
27 using boost::shared_ptr;
28
29 FontsDialog::FontsDialog (wxWindow* parent, shared_ptr<SubtitleContent> content)
30         : wxDialog (parent, wxID_ANY, _("Fonts"))
31 {
32         _fonts = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize (400, 200), wxLC_REPORT | wxLC_SINGLE_SEL);
33
34         {
35                 wxListItem ip;
36                 ip.SetId (0);
37                 ip.SetText (_("ID"));
38                 ip.SetWidth (100);
39                 _fonts->InsertColumn (0, ip);
40         }
41         
42         {
43                 wxListItem ip;
44                 ip.SetId (1);
45                 ip.SetText (_("Font file"));
46                 ip.SetWidth (300);
47                 _fonts->InsertColumn (1, ip);
48         }
49
50         wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
51         sizer->Add (_fonts, 1, wxEXPAND);
52
53         {
54                 wxSizer* s = new wxBoxSizer (wxVERTICAL);
55                 _edit = new wxButton (this, wxID_ANY, _("Edit..."));
56                 s->Add (_edit, 0, wxTOP | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
57                 sizer->Add (s, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP);
58         }
59
60         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
61         overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
62
63         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
64         if (buttons) {
65                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
66         }
67
68         SetSizerAndFit (overall_sizer);
69
70         list<shared_ptr<Font> > fonts = content->fonts ();
71         size_t n = 0;
72         for (list<shared_ptr<Font> >::const_iterator i = fonts.begin(); i != fonts.end(); ++i) {
73                 wxListItem item;
74                 item.SetId (n);
75                 _fonts->InsertItem (item);
76                 _fonts->SetItem (n, 0, (*i)->id.get_value_or (wx_to_std (_("[Default]"))));
77                 if ((*i)->file) {
78                         _fonts->SetItem (n, 1, (*i)->file.get().leaf().string ());
79                 }
80                 ++n;
81         }
82 }
83