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