Don't offer setting for line spacing with DCP subs (#1527).
[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, S_("Coord|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                 /* XXX: don't display the "magic" track which has empty name and language;
259                    this is a nasty hack (see also Film::closed_caption_tracks)
260                 */
261                 if (!i.name.empty() || !i.language.empty()) {
262                         _dcp_track->Append (std_to_wx(i.summary()));
263                 }
264         }
265
266         if (_parent->film()->closed_caption_tracks().size() < 6) {
267                 _dcp_track->Append (_("Add new..."));
268         }
269
270         update_dcp_track_selection ();
271 }
272
273 void
274 TextPanel::dcp_track_changed ()
275 {
276         optional<DCPTextTrack> track;
277
278         if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
279                 DCPTextTrackDialog* d = new DCPTextTrackDialog (this);
280                 if (d->ShowModal() == wxID_OK) {
281                         track = d->get();
282                 }
283                 d->Destroy ();
284         } else {
285                 /* Find the DCPTextTrack that was selected */
286                 BOOST_FOREACH (DCPTextTrack i, _parent->film()->closed_caption_tracks()) {
287                         if (i.summary() == wx_to_std(_dcp_track->GetStringSelection())) {
288                                 track = i;
289                         }
290                 }
291         }
292
293         if (track) {
294                 BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
295                         shared_ptr<TextContent> t = i->text_of_original_type(_original_type);
296                         if (t && t->type() == TEXT_CLOSED_CAPTION) {
297                                 t->set_dcp_track(*track);
298                         }
299                 }
300         }
301
302         update_dcp_tracks ();
303 }
304
305 void
306 TextPanel::film_changed (Film::Property property)
307 {
308         if (property == Film::CONTENT || property == Film::REEL_TYPE) {
309                 setup_sensitivity ();
310         }
311 }
312
313 void
314 TextPanel::film_content_changed (int property)
315 {
316         FFmpegContentList fc = _parent->selected_ffmpeg ();
317         ContentList sc = _parent->selected_text ();
318
319         shared_ptr<FFmpegContent> fcs;
320         if (fc.size() == 1) {
321                 fcs = fc.front ();
322         }
323
324         shared_ptr<Content> scs;
325         if (sc.size() == 1) {
326                 scs = sc.front ();
327         }
328
329         shared_ptr<TextContent> text;
330         if (scs) {
331                 text = scs->text_of_original_type(_original_type);
332         }
333
334         if (property == FFmpegContentProperty::SUBTITLE_STREAMS) {
335                 _stream->Clear ();
336                 if (fcs) {
337                         vector<shared_ptr<FFmpegSubtitleStream> > s = fcs->subtitle_streams ();
338                         for (vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = s.begin(); i != s.end(); ++i) {
339                                 _stream->Append (std_to_wx ((*i)->name), new wxStringClientData (std_to_wx ((*i)->identifier ())));
340                         }
341
342                         if (fcs->subtitle_stream()) {
343                                 checked_set (_stream, fcs->subtitle_stream()->identifier ());
344                         } else {
345                                 _stream->SetSelection (wxNOT_FOUND);
346                         }
347                 }
348                 setup_sensitivity ();
349         } else if (property == TextContentProperty::USE) {
350                 checked_set (_use, text ? text->use() : false);
351                 setup_sensitivity ();
352         } else if (property == TextContentProperty::TYPE) {
353                 if (text) {
354                         switch (text->type()) {
355                         case TEXT_OPEN_SUBTITLE:
356                                 _type->SetSelection (0);
357                                 break;
358                         case TEXT_CLOSED_CAPTION:
359                                 _type->SetSelection (1);
360                                 break;
361                         default:
362                                 DCPOMATIC_ASSERT (false);
363                         }
364                 } else {
365                         _type->SetSelection (0);
366                 }
367                 setup_sensitivity ();
368                 update_dcp_track_selection ();
369         } else if (property == TextContentProperty::BURN) {
370                 checked_set (_burn, text ? text->burn() : false);
371         } else if (property == TextContentProperty::X_OFFSET) {
372                 checked_set (_x_offset, text ? lrint (text->x_offset() * 100) : 0);
373         } else if (property == TextContentProperty::Y_OFFSET) {
374                 checked_set (_y_offset, text ? lrint (text->y_offset() * 100) : 0);
375         } else if (property == TextContentProperty::X_SCALE) {
376                 checked_set (_x_scale, text ? lrint (text->x_scale() * 100) : 100);
377         } else if (property == TextContentProperty::Y_SCALE) {
378                 checked_set (_y_scale, text ? lrint (text->y_scale() * 100) : 100);
379         } else if (property == TextContentProperty::LINE_SPACING) {
380                 checked_set (_line_spacing, text ? lrint (text->line_spacing() * 100) : 100);
381         } else if (property == TextContentProperty::LANGUAGE) {
382                 checked_set (_language, text ? text->language() : "");
383         } else if (property == TextContentProperty::DCP_TRACK) {
384                 update_dcp_track_selection ();
385         } else if (property == DCPContentProperty::REFERENCE_TEXT) {
386                 if (scs) {
387                         shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (scs);
388                         checked_set (_reference, dcp ? dcp->reference_text(_original_type) : false);
389                 } else {
390                         checked_set (_reference, false);
391                 }
392
393                 setup_sensitivity ();
394         } else if (property == DCPContentProperty::TEXTS) {
395                 setup_sensitivity ();
396         }
397 }
398
399 void
400 TextPanel::use_toggled ()
401 {
402         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
403                 i->text_of_original_type(_original_type)->set_use (_use->GetValue());
404         }
405 }
406
407 /** @return the text type that is currently selected in the drop-down */
408 TextType
409 TextPanel::current_type () const
410 {
411         switch (_type->GetSelection()) {
412         case 0:
413                 return TEXT_OPEN_SUBTITLE;
414         case 1:
415                 return TEXT_CLOSED_CAPTION;
416         }
417
418         return TEXT_UNKNOWN;
419 }
420
421 void
422 TextPanel::type_changed ()
423 {
424         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text()) {
425                 i->text_of_original_type(_original_type)->set_type (current_type ());
426         }
427 }
428
429 void
430 TextPanel::burn_toggled ()
431 {
432         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
433                 i->text_of_original_type(_original_type)->set_burn (_burn->GetValue());
434         }
435 }
436
437 void
438 TextPanel::setup_sensitivity ()
439 {
440         int any_subs = 0;
441         /* We currently assume that FFmpeg subtitles are bitmapped */
442         int ffmpeg_subs = 0;
443         /* DCP subs can't have their line spacing changed */
444         int dcp_subs = 0;
445         ContentList sel = _parent->selected_text ();
446         BOOST_FOREACH (shared_ptr<Content> i, sel) {
447                 /* These are the content types that could include subtitles */
448                 shared_ptr<const FFmpegContent> fc = boost::dynamic_pointer_cast<const FFmpegContent> (i);
449                 shared_ptr<const StringTextFileContent> sc = boost::dynamic_pointer_cast<const StringTextFileContent> (i);
450                 shared_ptr<const DCPContent> dc = boost::dynamic_pointer_cast<const DCPContent> (i);
451                 shared_ptr<const DCPSubtitleContent> dsc = boost::dynamic_pointer_cast<const DCPSubtitleContent> (i);
452                 if (fc) {
453                         if (!fc->text.empty()) {
454                                 ++ffmpeg_subs;
455                                 ++any_subs;
456                         }
457                 } else if (dc || dsc) {
458                         ++dcp_subs;
459                         ++any_subs;
460                 } else if (sc) {
461                         /* XXX: in the future there could be bitmap subs from DCPs */
462                         ++any_subs;
463                 }
464         }
465
466         /* Decide whether we can reference these subs */
467
468         shared_ptr<DCPContent> dcp;
469         if (sel.size() == 1) {
470                 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
471         }
472
473         string why_not;
474         bool const can_reference = dcp && dcp->can_reference_text (_parent->film(), _original_type, why_not);
475         setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
476
477         bool const reference = _reference->GetValue ();
478
479         TextType const type = current_type ();
480
481         /* Set up _type */
482         _type->Clear ();
483         _type->Append (_("open subtitles"));
484         if (ffmpeg_subs == 0) {
485                 _type->Append (_("closed captions"));
486         }
487
488         switch (type) {
489         case TEXT_OPEN_SUBTITLE:
490                 _type->SetSelection (0);
491                 break;
492         case TEXT_CLOSED_CAPTION:
493                 if (_type->GetCount() > 1) {
494                         _type->SetSelection (1);
495                 }
496                 break;
497         default:
498                 break;
499         }
500
501         /* Set up sensitivity */
502         _use->Enable (!reference && any_subs > 0);
503         bool const use = _use->GetValue ();
504         _type->Enable (!reference && any_subs > 0 && use);
505         _burn->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
506         _x_offset->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
507         _y_offset->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
508         _x_scale->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
509         _y_scale->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
510         /* DCP subs ignore the line spacing setting */
511         _line_spacing->Enable (!reference && use && type == TEXT_OPEN_SUBTITLE && dcp_subs < any_subs);
512         _dcp_track->Enable (!reference && any_subs > 0 && use && type == TEXT_CLOSED_CAPTION);
513         _language->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
514         _stream->Enable (!reference && ffmpeg_subs == 1);
515         /* Ideally we would check here to see if the FFmpeg content has "string" subs (i.e. not bitmaps) */
516         _text_view_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0);
517         _fonts_dialog_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0 && type == TEXT_OPEN_SUBTITLE);
518         _appearance_dialog_button->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
519 }
520
521 void
522 TextPanel::stream_changed ()
523 {
524         FFmpegContentList fc = _parent->selected_ffmpeg ();
525         if (fc.size() != 1) {
526                 return;
527         }
528
529         shared_ptr<FFmpegContent> fcs = fc.front ();
530
531         vector<shared_ptr<FFmpegSubtitleStream> > a = fcs->subtitle_streams ();
532         vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
533         string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
534         while (i != a.end() && (*i)->identifier () != s) {
535                 ++i;
536         }
537
538         if (i != a.end ()) {
539                 fcs->set_subtitle_stream (*i);
540         }
541 }
542
543 void
544 TextPanel::x_offset_changed ()
545 {
546         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
547                 i->text_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
548         }
549 }
550
551 void
552 TextPanel::y_offset_changed ()
553 {
554         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
555                 i->text_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
556         }
557 }
558
559 void
560 TextPanel::x_scale_changed ()
561 {
562         ContentList c = _parent->selected_text ();
563         if (c.size() == 1) {
564                 c.front()->text_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
565         }
566 }
567
568 void
569 TextPanel::y_scale_changed ()
570 {
571         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
572                 i->text_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
573         }
574 }
575
576 void
577 TextPanel::line_spacing_changed ()
578 {
579         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
580                 i->text_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
581         }
582 }
583
584 void
585 TextPanel::language_changed ()
586 {
587         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
588                 i->text_of_original_type(_original_type)->set_language (wx_to_std (_language->GetValue()));
589         }
590 }
591
592 void
593 TextPanel::content_selection_changed ()
594 {
595         film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
596         film_content_changed (TextContentProperty::USE);
597         film_content_changed (TextContentProperty::BURN);
598         film_content_changed (TextContentProperty::X_OFFSET);
599         film_content_changed (TextContentProperty::Y_OFFSET);
600         film_content_changed (TextContentProperty::X_SCALE);
601         film_content_changed (TextContentProperty::Y_SCALE);
602         film_content_changed (TextContentProperty::LINE_SPACING);
603         film_content_changed (TextContentProperty::LANGUAGE);
604         film_content_changed (TextContentProperty::FONTS);
605         film_content_changed (TextContentProperty::TYPE);
606         film_content_changed (TextContentProperty::DCP_TRACK);
607         film_content_changed (DCPContentProperty::REFERENCE_TEXT);
608 }
609
610 void
611 TextPanel::text_view_clicked ()
612 {
613         if (_text_view) {
614                 _text_view->Destroy ();
615                 _text_view = 0;
616         }
617
618         ContentList c = _parent->selected_text ();
619         DCPOMATIC_ASSERT (c.size() == 1);
620
621         shared_ptr<Decoder> decoder = decoder_factory (_parent->film(), c.front(), false);
622
623         if (decoder) {
624                 _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
625                 _text_view->Show ();
626         }
627 }
628
629 void
630 TextPanel::fonts_dialog_clicked ()
631 {
632         if (_fonts_dialog) {
633                 _fonts_dialog->Destroy ();
634                 _fonts_dialog = 0;
635         }
636
637         ContentList c = _parent->selected_text ();
638         DCPOMATIC_ASSERT (c.size() == 1);
639
640         _fonts_dialog = new FontsDialog (this, c.front(), c.front()->text_of_original_type(_original_type));
641         _fonts_dialog->Show ();
642 }
643
644 void
645 TextPanel::reference_clicked ()
646 {
647         ContentList c = _parent->selected ();
648         if (c.size() != 1) {
649                 return;
650         }
651
652         shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
653         if (!d) {
654                 return;
655         }
656
657         d->set_reference_text (_original_type, _reference->GetValue ());
658 }
659
660 void
661 TextPanel::appearance_dialog_clicked ()
662 {
663         ContentList c = _parent->selected_text ();
664         DCPOMATIC_ASSERT (c.size() == 1);
665
666         SubtitleAppearanceDialog* d = new SubtitleAppearanceDialog (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
667         if (d->ShowModal () == wxID_OK) {
668                 d->apply ();
669         }
670         d->Destroy ();
671 }