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