No-op; fix GPL address and use the explicit-program-name version.
[dcpomatic.git] / src / wx / font_files_dialog.cc
1 /*
2     Copyright (C) 2015 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 "font_files_dialog.h"
22 #include "system_font_dialog.h"
23
24 using boost::bind;
25
26 FontFilesDialog::FontFilesDialog (wxWindow* parent, FontFiles files)
27 #ifdef DCPOMATIC_WINDOWS
28         : TableDialog (parent, _("Fonts"), 4, 1, true)
29 #else
30         : TableDialog (parent, _("Fonts"), 3, 1, true)
31 #endif
32         , _files (files)
33 {
34         wxString labels[] = {
35                 _("Normal font"),
36                 _("Italic font"),
37                 _("Bold font")
38         };
39
40         DCPOMATIC_ASSERT (FontFiles::VARIANTS == 3);
41
42         for (int i = 0; i < FontFiles::VARIANTS; ++i) {
43                 add (labels[i], true);
44                 _name[i] = new wxStaticText (
45                         this, wxID_ANY,
46                         std_to_wx(_files.get(static_cast<FontFiles::Variant>(i)).get_value_or("").string()),
47                         wxDefaultPosition,
48                         wxSize (200, -1)
49                         );
50                 _table->Add (_name[i], 1, wxEXPAND | wxALIGN_CENTER_VERTICAL | wxALL, 6);
51                 add (_set_file[i] = new wxButton (this, wxID_ANY, _("Set from file...")));
52                 _set_file[i]->Bind (wxEVT_COMMAND_BUTTON_CLICKED, bind (&FontFilesDialog::set_from_file_clicked, this, static_cast<FontFiles::Variant>(i)));
53 #ifdef DCPOMATIC_WINDOWS
54                 add (_set_system[i] = new wxButton (this, wxID_ANY, _("Set from system font...")));
55                 _set_system[i]->Bind (wxEVT_COMMAND_BUTTON_CLICKED, bind (&FontFilesDialog::set_from_system_clicked, this, static_cast<FontFiles::Variant>(i)));
56 #endif
57         }
58
59         layout ();
60 }
61
62 void
63 FontFilesDialog::set_from_file_clicked (FontFiles::Variant variant)
64 {
65         /* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using
66            non-Latin filenames or paths.
67         */
68         wxString default_dir = "";
69 #ifdef DCPOMATIC_LINUX
70         if (boost::filesystem::exists ("/usr/share/fonts/truetype")) {
71                 default_dir = "/usr/share/fonts/truetype";
72         } else {
73                 default_dir = "/usr/share/fonts";
74         }
75 #endif
76 #ifdef DCPOMATIC_OSX
77         default_dir = "/System/Library/Fonts";
78 #endif
79
80         wxFileDialog* d = new wxFileDialog (this, _("Choose a font file"), default_dir, wxT (""), wxT ("*.ttf"), wxFD_CHANGE_DIR);
81         int const r = d->ShowModal ();
82
83         if (r != wxID_OK) {
84                 d->Destroy ();
85                 return;
86         }
87
88         set (variant, wx_to_std (d->GetPath ()));
89         d->Destroy ();
90 }
91
92 #ifdef DCPOMATIC_WINDOWS
93 void
94 FontFilesDialog::set_from_system_clicked (FontFiles::Variant variant)
95 {
96         SystemFontDialog* d = new SystemFontDialog (this);
97         int const r = d->ShowModal ();
98
99         if (r != wxID_OK) {
100                 d->Destroy ();
101                 return;
102         }
103
104         set (variant, d->get_font().get());
105         d->Destroy ();
106 }
107 #endif
108
109 void
110 FontFilesDialog::set (FontFiles::Variant variant, boost::filesystem::path path)
111 {
112         _files.set (variant, path);
113         _name[variant]->SetLabel (std_to_wx (path.leaf().string()));
114 }