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