Basics of in-place i18n with support for wxStaticText and wxCheckBox.
[dcpomatic.git] / src / wx / text_panel.cc
1 /*
2     Copyright (C) 2012-2018 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 "text_panel.h"
22 #include "film_editor.h"
23 #include "wx_util.h"
24 #include "text_view.h"
25 #include "content_panel.h"
26 #include "fonts_dialog.h"
27 #include "dcp_text_track_dialog.h"
28 #include "subtitle_appearance_dialog.h"
29 #include "static_text.h"
30 #include "check_box.h"
31 #include "lib/ffmpeg_content.h"
32 #include "lib/string_text_file_content.h"
33 #include "lib/ffmpeg_subtitle_stream.h"
34 #include "lib/dcp_subtitle_content.h"
35 #include "lib/string_text_file_decoder.h"
36 #include "lib/dcp_subtitle_decoder.h"
37 #include "lib/dcp_content.h"
38 #include "lib/text_content.h"
39 #include "lib/decoder_factory.h"
40 #include <wx/spinctrl.h>
41 #include <boost/foreach.hpp>
42
43 using std::vector;
44 using std::string;
45 using std::list;
46 using std::cout;
47 using boost::shared_ptr;
48 using boost::optional;
49 using boost::dynamic_pointer_cast;
50
51 /** @param t Original text type of the content, if known */
52 TextPanel::TextPanel (ContentPanel* p, TextType t)
53         : ContentSubPanel (p, std_to_wx(text_type_to_name(t)))
54         , _text_view (0)
55         , _fonts_dialog (0)
56         , _original_type (t)
57 {
58         wxString refer = _("Use this DCP's subtitle as OV and make VF");
59         if (t == TEXT_CLOSED_CAPTION) {
60                 refer = _("Use this DCP's closed caption as OV and make VF");
61         }
62
63         _reference = new CheckBox (this, refer);
64         _reference_note = new StaticText (this, wxT(""));
65         _reference_note->Wrap (200);
66         wxFont font = _reference_note->GetFont();
67         font.SetStyle(wxFONTSTYLE_ITALIC);
68         font.SetPointSize(font.GetPointSize() - 1);
69         _reference_note->SetFont(font);
70
71         _use = new CheckBox (this, _("Use as"));
72         _type = new wxChoice (this, wxID_ANY);
73         _type->Append (_("open subtitles"));
74         _type->Append (_("closed captions"));
75
76         _burn = new CheckBox (this, _("Burn subtitles into image"));
77
78         _offset_label = create_label (this, _("Offset"), true);
79         _x_offset_label = create_label (this, _("X"), true);
80         _x_offset = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(64, -1));
81         _x_offset_pc_label = new StaticText (this, _("%"));
82         _y_offset_label = create_label (this, _("Y"), true);
83         _y_offset = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(64, -1));
84         _y_offset_pc_label = new StaticText (this, _("%"));
85
86         _scale_label = create_label (this, _("Scale"), true);
87         _x_scale_label = create_label (this, _("X"), true);
88         _x_scale = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(64, -1));
89         _x_scale_pc_label = new StaticText (this, _("%"));
90         _y_scale_label = create_label (this, _("Y"), true);
91         _y_scale = new wxSpinCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(64, -1));
92         _y_scale_pc_label = new StaticText (this, _("%"));
93
94         _line_spacing_label = create_label (this, _("Line spacing"), true);
95         _line_spacing = new wxSpinCtrl (this);
96         _line_spacing_pc_label = new StaticText (this, _("%"));
97
98         _dcp_track_label = create_label (this, _("DCP track"), true);
99         _dcp_track = new wxChoice (this, wxID_ANY);
100
101         _language_label = create_label (this, _("Language"), true);
102         _language = new wxTextCtrl (this, wxID_ANY);
103
104         _stream_label = create_label (this, _("Stream"), true);
105         _stream = new wxChoice (this, wxID_ANY);
106
107         _text_view_button = new wxButton (this, wxID_ANY, _("View..."));
108         _fonts_dialog_button = new wxButton (this, wxID_ANY, _("Fonts..."));
109         _appearance_dialog_button = new wxButton (this, wxID_ANY, _("Appearance..."));
110
111         _x_offset->SetRange (-100, 100);
112         _y_offset->SetRange (-100, 100);
113         _x_scale->SetRange (10, 1000);
114         _y_scale->SetRange (10, 1000);
115         _line_spacing->SetRange (10, 1000);
116
117         update_dcp_tracks ();
118
119         content_selection_changed ();
120
121         _reference->Bind                (wxEVT_CHECKBOX, boost::bind (&TextPanel::reference_clicked, this));
122         _use->Bind                      (wxEVT_CHECKBOX, boost::bind (&TextPanel::use_toggled, this));
123         _type->Bind                     (wxEVT_CHOICE,   boost::bind (&TextPanel::type_changed, this));
124         _burn->Bind                     (wxEVT_CHECKBOX, boost::bind (&TextPanel::burn_toggled, this));
125         _x_offset->Bind                 (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_offset_changed, this));
126         _y_offset->Bind                 (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_offset_changed, this));
127         _x_scale->Bind                  (wxEVT_SPINCTRL, boost::bind (&TextPanel::x_scale_changed, this));
128         _y_scale->Bind                  (wxEVT_SPINCTRL, boost::bind (&TextPanel::y_scale_changed, this));
129         _line_spacing->Bind             (wxEVT_SPINCTRL, boost::bind (&TextPanel::line_spacing_changed, this));
130         _dcp_track->Bind                (wxEVT_CHOICE,   boost::bind (&TextPanel::dcp_track_changed, this));
131         _language->Bind                 (wxEVT_TEXT,     boost::bind (&TextPanel::language_changed, this));
132         _stream->Bind                   (wxEVT_CHOICE,   boost::bind (&TextPanel::stream_changed, this));
133         _text_view_button->Bind         (wxEVT_BUTTON,   boost::bind (&TextPanel::text_view_clicked, this));
134         _fonts_dialog_button->Bind      (wxEVT_BUTTON,   boost::bind (&TextPanel::fonts_dialog_clicked, this));
135         _appearance_dialog_button->Bind (wxEVT_BUTTON,   boost::bind (&TextPanel::appearance_dialog_clicked, this));
136
137         add_to_grid();
138 }
139
140 void
141 TextPanel::add_to_grid ()
142 {
143         Config::Interface const interface = Config::instance()->interface_complexity();
144
145         int r = 0;
146
147         _reference->Show (interface == Config::INTERFACE_FULL);
148         _reference_note->Show (interface == Config::INTERFACE_FULL);
149
150         if (interface == Config::INTERFACE_FULL) {
151                 wxBoxSizer* reference_sizer = new wxBoxSizer (wxVERTICAL);
152                 reference_sizer->Add (_reference, 0);
153                 reference_sizer->Add (_reference_note, 0);
154                 _grid->Add (reference_sizer, wxGBPosition(r, 0), wxGBSpan(1, 4));
155                 ++r;
156         }
157
158         wxBoxSizer* use = new wxBoxSizer (wxHORIZONTAL);
159         use->Add (_use, 0, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_GAP);
160         use->Add (_type, 1, wxEXPAND, 0);
161         _grid->Add (use, wxGBPosition (r, 0), wxGBSpan (1, 2));
162         ++r;
163
164         _grid->Add (_burn, wxGBPosition (r, 0), wxGBSpan (1, 2));
165         ++r;
166
167         add_label_to_sizer (_grid, _offset_label, true, wxGBPosition (r, 0));
168         wxBoxSizer* offset = new wxBoxSizer (wxHORIZONTAL);
169         add_label_to_sizer (offset, _x_offset_label, true);
170         offset->Add (_x_offset, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
171         offset->Add (_x_offset_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
172         add_label_to_sizer (offset, _y_offset_label, true);
173         offset->Add (_y_offset, 0);
174         add_label_to_sizer (offset, _y_offset_pc_label, false);
175         _grid->Add (offset, wxGBPosition (r, 1));
176         ++r;
177
178         add_label_to_sizer (_grid, _scale_label, true, wxGBPosition (r, 0));
179         wxBoxSizer* scale = new wxBoxSizer (wxHORIZONTAL);
180         add_label_to_sizer (scale, _x_scale_label, true);
181         scale->Add (_x_scale, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP);
182         scale->Add (_x_scale_pc_label, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_X_GAP * 2);
183         add_label_to_sizer (scale, _y_scale_label, true);
184         scale->Add (_y_scale, 0);
185         add_label_to_sizer (scale, _y_scale_pc_label, false);
186         _grid->Add (scale, wxGBPosition (r, 1));
187         ++r;
188
189         {
190                 add_label_to_sizer (_grid, _line_spacing_label, true, wxGBPosition (r, 0));
191                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
192                 s->Add (_line_spacing);
193                 add_label_to_sizer (s, _line_spacing_pc_label, false);
194                 _grid->Add (s, wxGBPosition (r, 1));
195                 ++r;
196         }
197
198         add_label_to_sizer (_grid, _dcp_track_label, true, wxGBPosition(r, 0));
199         _grid->Add (_dcp_track, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND);
200         ++r;
201
202         add_label_to_sizer (_grid, _language_label, true, wxGBPosition (r, 0));
203         _grid->Add (_language, wxGBPosition (r, 1));
204         ++r;
205
206         add_label_to_sizer (_grid, _stream_label, true, wxGBPosition (r, 0));
207         _grid->Add (_stream, wxGBPosition (r, 1));
208         ++r;
209
210         {
211                 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
212
213                 s->Add (_text_view_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
214                 s->Add (_fonts_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
215                 s->Add (_appearance_dialog_button, 1, wxALL, DCPOMATIC_SIZER_GAP);
216
217                 _grid->Add (s, wxGBPosition (r, 0), wxGBSpan (1, 2));
218                 ++r;
219         }
220 }
221
222 void
223 TextPanel::update_dcp_track_selection ()
224 {
225         optional<DCPTextTrack> selected;
226         bool many = false;
227         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
228                 shared_ptr<TextContent> t = i->text_of_original_type(_original_type);
229                 if (t) {
230                         optional<DCPTextTrack> dt = t->dcp_track();
231                         if (dt && selected && *dt != *selected) {
232                                 many = true;
233                         } else if (!selected) {
234                                 selected = dt;
235                         }
236                 }
237         }
238
239         int n = 0;
240         BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
241                 if (!many && selected && *selected == i) {
242                         _dcp_track->SetSelection (n);
243                 }
244                 ++n;
245         }
246
247         if (!selected || many) {
248                 _dcp_track->SetSelection (wxNOT_FOUND);
249         }
250 }
251
252 void
253 TextPanel::update_dcp_tracks ()
254 {
255         _dcp_track->Clear ();
256         BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
257                 _dcp_track->Append (std_to_wx(i.summary()));
258         }
259
260         if (_parent->film()->closed_caption_tracks().size() < 6) {
261                 _dcp_track->Append (_("Add new..."));
262         }
263
264         update_dcp_track_selection ();
265 }
266
267 void
268 TextPanel::dcp_track_changed ()
269 {
270         optional<DCPTextTrack> track;
271
272         if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
273                 DCPTextTrackDialog* d = new DCPTextTrackDialog (this);
274                 if (d->ShowModal() == wxID_OK) {
275                         track = d->get();
276                 }
277                 d->Destroy ();
278         } else {
279                 /* Find the DCPTextTrack that was selected */
280                 BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
281                         if (i.summary() == wx_to_std(_dcp_track->GetStringSelection())) {
282                                 track = i;
283                         }
284                 }
285         }
286
287         if (track) {
288                 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
289                         shared_ptr<TextContent> t = i->text_of_original_type(_original_type);
290                         if (t && t->type() == TEXT_CLOSED_CAPTION) {
291                                 t->set_dcp_track(*track);
292                         }
293                 }
294         }
295
296         update_dcp_tracks ();
297 }
298
299 void
300 TextPanel::film_changed (Film::Property property)
301 {
302         if (property == Film::CONTENT || property == Film::REEL_TYPE) {
303                 setup_sensitivity ();
304         }
305 }
306
307 void
308 TextPanel::film_content_changed (int property)
309 {
310         FFmpegContentList fc = _parent->selected_ffmpeg ();
311         ContentList sc = _parent->selected_text ();
312
313         shared_ptr<FFmpegContent> fcs;
314         if (fc.size() == 1) {
315                 fcs = fc.front ();
316         }
317
318         shared_ptr<Content> scs;
319         if (sc.size() == 1) {
320                 scs = sc.front ();
321         }
322
323         shared_ptr<TextContent> text;
324         if (scs) {
325                 text = scs->text_of_original_type(_original_type);
326         }
327
328         if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
329                 _stream->Clear ();
330                 if (fcs) {
331                         vector<shared_ptr<FFmpegSubtitleStream> > s = fcs->subtitle_streams ();
332                         for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
333                                 _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx ((*i)->identifier ())));
334                         }
335
336                         if (fcs->subtitle_stream()) {
337                                 checked_set (_stream, fcs->subtitle_stream()->identifier ());
338                         } else {
339                                 _stream->SetSelection (wxNOT_FOUND);
340                         }
341                 }
342                 setup_sensitivity ();
343         } else if (property == TextContentProperty::USE) {
344                 checked_set (_use, text ? text->use() : false);
345                 setup_sensitivity ();
346         } else if (property == TextContentProperty::TYPE) {
347                 if (text) {
348                         switch (text->type()) {
349                         case TEXT_OPEN_SUBTITLE:
350                                 _type->SetSelection (0);
351                                 break;
352                         case TEXT_CLOSED_CAPTION:
353                                 _type->SetSelection (1);
354                                 break;
355                         default:
356                                 DCPOMATIC_ASSERT (false);
357                         }
358                 } else {
359                         _type->SetSelection (0);
360                 }
361                 setup_sensitivity ();
362                 update_dcp_track_selection ();
363         } else if (property == TextContentProperty::BURN) {
364                 checked_set (_burn, text ? text->burn() : false);
365         } else if (property == TextContentProperty::X_OFFSET) {
366                 checked_set (_x_offset, text ? lrint (text->x_offset() * 100) : 0);
367         } else if (property == TextContentProperty::Y_OFFSET) {
368                 checked_set (_y_offset, text ? lrint (text->y_offset() * 100) : 0);
369         } else if (property == TextContentProperty::X_SCALE) {
370                 checked_set (_x_scale, text ? lrint (text->x_scale() * 100) : 100);
371         } else if (property == TextContentProperty::Y_SCALE) {
372                 checked_set (_y_scale, text ? lrint (text->y_scale() * 100) : 100);
373         } else if (property == TextContentProperty::LINE_SPACING) {
374                 checked_set (_line_spacing, text ? lrint (text->line_spacing() * 100) : 100);
375         } else if (property == TextContentProperty::LANGUAGE) {
376                 checked_set (_language, text ? text->language() : "");
377         } else if (property == TextContentProperty::DCP_TRACK) {
378                 update_dcp_track_selection ();
379         } else if (property == DCPContentProperty::REFERENCE_TEXT) {
380                 if (scs) {
381                         shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (scs);
382                         checked_set (_reference, dcp ? dcp->reference_text(_original_type) : false);
383                 } else {
384                         checked_set (_reference, false);
385                 }
386
387                 setup_sensitivity ();
388         } else if (property == DCPContentProperty::TEXTS) {
389                 setup_sensitivity ();
390         }
391 }
392
393 void
394 TextPanel::use_toggled ()
395 {
396         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
397                 i->text_of_original_type(_original_type)->set_use (_use->GetValue());
398         }
399 }
400
401 /** @return the text type that is currently selected in the drop-down */
402 TextType
403 TextPanel::current_type () const
404 {
405         switch (_type->GetSelection()) {
406         case 0:
407                 return TEXT_OPEN_SUBTITLE;
408         case 1:
409                 return TEXT_CLOSED_CAPTION;
410         }
411
412         return TEXT_UNKNOWN;
413 }
414
415 void
416 TextPanel::type_changed ()
417 {
418         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
419                 i->text_of_original_type(_original_type)->set_type (current_type ());
420         }
421 }
422
423 void
424 TextPanel::burn_toggled ()
425 {
426         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
427                 i->text_of_original_type(_original_type)->set_burn (_burn->GetValue());
428         }
429 }
430
431 void
432 TextPanel::setup_sensitivity ()
433 {
434         int any_subs = 0;
435         int ffmpeg_subs = 0;
436         ContentList sel = _parent->selected_text ();
437         BOOST_FOREACH (shared_ptr<Content> i, sel) {
438                 /* These are the content types that could include subtitles */
439                 shared_ptr<const FFmpegContent> fc = boost::dynamic_pointer_cast<const FFmpegContent> (i);
440                 shared_ptr<const StringTextFileContent> sc = boost::dynamic_pointer_cast<const StringTextFileContent> (i);
441                 shared_ptr<const DCPContent> dc = boost::dynamic_pointer_cast<const DCPContent> (i);
442                 shared_ptr<const DCPSubtitleContent> dsc = boost::dynamic_pointer_cast<const DCPSubtitleContent> (i);
443                 if (fc) {
444                         if (!fc->text.empty()) {
445                                 ++ffmpeg_subs;
446                                 ++any_subs;
447                         }
448                 } else if (sc || dc || dsc) {
449                         /* XXX: in the future there could be bitmap subs from DCPs */
450                         ++any_subs;
451                 }
452         }
453
454         /* Decide whether we can reference these subs */
455
456         shared_ptr<DCPContent> dcp;
457         if (sel.size() == 1) {
458                 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
459         }
460
461         string why_not;
462         bool const can_reference = dcp && dcp->can_reference_text (_parent->film(), _original_type, why_not);
463         setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
464
465         bool const reference = _reference->GetValue ();
466
467         TextType const type = current_type ();
468
469         /* Set up sensitivity */
470         _use->Enable (!reference && any_subs > 0);
471         bool const use = _use->GetValue ();
472         _type->Enable (!reference && any_subs > 0 && use);
473         _burn->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
474         _x_offset->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
475         _y_offset->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
476         _x_scale->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
477         _y_scale->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
478         _line_spacing->Enable (!reference && use && type == TEXT_OPEN_SUBTITLE);
479         _dcp_track->Enable (!reference && any_subs > 0 && use && type == TEXT_CLOSED_CAPTION);
480         _language->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
481         _stream->Enable (!reference && ffmpeg_subs == 1);
482         _text_view_button->Enable (!reference);
483         _fonts_dialog_button->Enable (!reference && type == TEXT_OPEN_SUBTITLE);
484         _appearance_dialog_button->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
485 }
486
487 void
488 TextPanel::stream_changed ()
489 {
490         FFmpegContentList fc = _parent->selected_ffmpeg ();
491         if (fc.size() != 1) {
492                 return;
493         }
494
495         shared_ptr<FFmpegContent> fcs = fc.front ();
496
497         vector<shared_ptr<FFmpegSubtitleStream> > a = fcs->subtitle_streams ();
498         vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
499         string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
500         while (i != a.end() && (*i)->identifier () != s) {
501                 ++i;
502         }
503
504         if (i != a.end ()) {
505                 fcs->set_subtitle_stream (*i);
506         }
507 }
508
509 void
510 TextPanel::x_offset_changed ()
511 {
512         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
513                 i->text_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
514         }
515 }
516
517 void
518 TextPanel::y_offset_changed ()
519 {
520         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
521                 i->text_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
522         }
523 }
524
525 void
526 TextPanel::x_scale_changed ()
527 {
528         ContentList c = _parent->selected_text ();
529         if (c.size() == 1) {
530                 c.front()->text_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
531         }
532 }
533
534 void
535 TextPanel::y_scale_changed ()
536 {
537         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
538                 i->text_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
539         }
540 }
541
542 void
543 TextPanel::line_spacing_changed ()
544 {
545         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
546                 i->text_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
547         }
548 }
549
550 void
551 TextPanel::language_changed ()
552 {
553         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
554                 i->text_of_original_type(_original_type)->set_language (wx_to_std (_language->GetValue()));
555         }
556 }
557
558 void
559 TextPanel::content_selection_changed ()
560 {
561         film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
562         film_content_changed (TextContentProperty::USE);
563         film_content_changed (TextContentProperty::BURN);
564         film_content_changed (TextContentProperty::X_OFFSET);
565         film_content_changed (TextContentProperty::Y_OFFSET);
566         film_content_changed (TextContentProperty::X_SCALE);
567         film_content_changed (TextContentProperty::Y_SCALE);
568         film_content_changed (TextContentProperty::LINE_SPACING);
569         film_content_changed (TextContentProperty::LANGUAGE);
570         film_content_changed (TextContentProperty::FONTS);
571         film_content_changed (TextContentProperty::TYPE);
572         film_content_changed (TextContentProperty::DCP_TRACK);
573         film_content_changed (DCPContentProperty::REFERENCE_TEXT);
574 }
575
576 void
577 TextPanel::text_view_clicked ()
578 {
579         if (_text_view) {
580                 _text_view->Destroy ();
581                 _text_view = 0;
582         }
583
584         ContentList c = _parent->selected_text ();
585         DCPOMATIC_ASSERT (c.size() == 1);
586
587         shared_ptr<Decoder> decoder = decoder_factory (_parent->film(), c.front(), false);
588
589         if (decoder) {
590                 _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
591                 _text_view->Show ();
592         }
593 }
594
595 void
596 TextPanel::fonts_dialog_clicked ()
597 {
598         if (_fonts_dialog) {
599                 _fonts_dialog->Destroy ();
600                 _fonts_dialog = 0;
601         }
602
603         ContentList c = _parent->selected_text ();
604         DCPOMATIC_ASSERT (c.size() == 1);
605
606         _fonts_dialog = new FontsDialog (this, c.front(), c.front()->text_of_original_type(_original_type));
607         _fonts_dialog->Show ();
608 }
609
610 void
611 TextPanel::reference_clicked ()
612 {
613         ContentList c = _parent->selected ();
614         if (c.size() != 1) {
615                 return;
616         }
617
618         shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
619         if (!d) {
620                 return;
621         }
622
623         d->set_reference_text (_original_type, _reference->GetValue ());
624 }
625
626 void
627 TextPanel::appearance_dialog_clicked ()
628 {
629         ContentList c = _parent->selected_text ();
630         DCPOMATIC_ASSERT (c.size() == 1);
631
632         SubtitleAppearanceDialog* d = new SubtitleAppearanceDialog (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
633         if (d->ShowModal () == wxID_OK) {
634                 d->apply ();
635         }
636         d->Destroy ();
637 }