Hack to avoid empty tracks appearing in the DCP Track control.
[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         ContentList sel = _parent->selected_text ();
444         BOOST_FOREACH (shared_ptr<Content> i, sel) {
445                 /* These are the content types that could include subtitles */
446                 shared_ptr<const FFmpegContent> fc = boost::dynamic_pointer_cast<const FFmpegContent> (i);
447                 shared_ptr<const StringTextFileContent> sc = boost::dynamic_pointer_cast<const StringTextFileContent> (i);
448                 shared_ptr<const DCPContent> dc = boost::dynamic_pointer_cast<const DCPContent> (i);
449                 shared_ptr<const DCPSubtitleContent> dsc = boost::dynamic_pointer_cast<const DCPSubtitleContent> (i);
450                 if (fc) {
451                         if (!fc->text.empty()) {
452                                 ++ffmpeg_subs;
453                                 ++any_subs;
454                         }
455                 } else if (sc || dc || dsc) {
456                         /* XXX: in the future there could be bitmap subs from DCPs */
457                         ++any_subs;
458                 }
459         }
460
461         /* Decide whether we can reference these subs */
462
463         shared_ptr<DCPContent> dcp;
464         if (sel.size() == 1) {
465                 dcp = dynamic_pointer_cast<DCPContent> (sel.front ());
466         }
467
468         string why_not;
469         bool const can_reference = dcp && dcp->can_reference_text (_parent->film(), _original_type, why_not);
470         setup_refer_button (_reference, _reference_note, dcp, can_reference, why_not);
471
472         bool const reference = _reference->GetValue ();
473
474         TextType const type = current_type ();
475
476         /* Set up _type */
477         _type->Clear ();
478         _type->Append (_("open subtitles"));
479         if (ffmpeg_subs == 0) {
480                 _type->Append (_("closed captions"));
481         }
482
483         switch (type) {
484         case TEXT_OPEN_SUBTITLE:
485                 _type->SetSelection (0);
486                 break;
487         case TEXT_CLOSED_CAPTION:
488                 if (_type->GetCount() > 1) {
489                         _type->SetSelection (1);
490                 }
491                 break;
492         default:
493                 break;
494         }
495
496         /* Set up sensitivity */
497         _use->Enable (!reference && any_subs > 0);
498         bool const use = _use->GetValue ();
499         _type->Enable (!reference && any_subs > 0 && use);
500         _burn->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
501         _x_offset->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
502         _y_offset->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
503         _x_scale->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
504         _y_scale->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
505         _line_spacing->Enable (!reference && use && type == TEXT_OPEN_SUBTITLE);
506         _dcp_track->Enable (!reference && any_subs > 0 && use && type == TEXT_CLOSED_CAPTION);
507         _language->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
508         _stream->Enable (!reference && ffmpeg_subs == 1);
509         /* Ideally we would check here to see if the FFmpeg content has "string" subs (i.e. not bitmaps) */
510         _text_view_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0);
511         _fonts_dialog_button->Enable (!reference && any_subs > 0 && ffmpeg_subs == 0 && type == TEXT_OPEN_SUBTITLE);
512         _appearance_dialog_button->Enable (!reference && any_subs > 0 && use && type == TEXT_OPEN_SUBTITLE);
513 }
514
515 void
516 TextPanel::stream_changed ()
517 {
518         FFmpegContentList fc = _parent->selected_ffmpeg ();
519         if (fc.size() != 1) {
520                 return;
521         }
522
523         shared_ptr<FFmpegContent> fcs = fc.front ();
524
525         vector<shared_ptr<FFmpegSubtitleStream> > a = fcs->subtitle_streams ();
526         vector<shared_ptr<FFmpegSubtitleStream> >::iterator i = a.begin ();
527         string const s = string_client_data (_stream->GetClientObject (_stream->GetSelection ()));
528         while (i != a.end() && (*i)->identifier () != s) {
529                 ++i;
530         }
531
532         if (i != a.end ()) {
533                 fcs->set_subtitle_stream (*i);
534         }
535 }
536
537 void
538 TextPanel::x_offset_changed ()
539 {
540         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
541                 i->text_of_original_type(_original_type)->set_x_offset (_x_offset->GetValue() / 100.0);
542         }
543 }
544
545 void
546 TextPanel::y_offset_changed ()
547 {
548         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
549                 i->text_of_original_type(_original_type)->set_y_offset (_y_offset->GetValue() / 100.0);
550         }
551 }
552
553 void
554 TextPanel::x_scale_changed ()
555 {
556         ContentList c = _parent->selected_text ();
557         if (c.size() == 1) {
558                 c.front()->text_of_original_type(_original_type)->set_x_scale (_x_scale->GetValue() / 100.0);
559         }
560 }
561
562 void
563 TextPanel::y_scale_changed ()
564 {
565         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
566                 i->text_of_original_type(_original_type)->set_y_scale (_y_scale->GetValue() / 100.0);
567         }
568 }
569
570 void
571 TextPanel::line_spacing_changed ()
572 {
573         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
574                 i->text_of_original_type(_original_type)->set_line_spacing (_line_spacing->GetValue() / 100.0);
575         }
576 }
577
578 void
579 TextPanel::language_changed ()
580 {
581         BOOST_FOREACH (shared_ptr<Content> i, _parent->selected_text ()) {
582                 i->text_of_original_type(_original_type)->set_language (wx_to_std (_language->GetValue()));
583         }
584 }
585
586 void
587 TextPanel::content_selection_changed ()
588 {
589         film_content_changed (FFmpegContentProperty::SUBTITLE_STREAMS);
590         film_content_changed (TextContentProperty::USE);
591         film_content_changed (TextContentProperty::BURN);
592         film_content_changed (TextContentProperty::X_OFFSET);
593         film_content_changed (TextContentProperty::Y_OFFSET);
594         film_content_changed (TextContentProperty::X_SCALE);
595         film_content_changed (TextContentProperty::Y_SCALE);
596         film_content_changed (TextContentProperty::LINE_SPACING);
597         film_content_changed (TextContentProperty::LANGUAGE);
598         film_content_changed (TextContentProperty::FONTS);
599         film_content_changed (TextContentProperty::TYPE);
600         film_content_changed (TextContentProperty::DCP_TRACK);
601         film_content_changed (DCPContentProperty::REFERENCE_TEXT);
602 }
603
604 void
605 TextPanel::text_view_clicked ()
606 {
607         if (_text_view) {
608                 _text_view->Destroy ();
609                 _text_view = 0;
610         }
611
612         ContentList c = _parent->selected_text ();
613         DCPOMATIC_ASSERT (c.size() == 1);
614
615         shared_ptr<Decoder> decoder = decoder_factory (_parent->film(), c.front(), false);
616
617         if (decoder) {
618                 _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());
619                 _text_view->Show ();
620         }
621 }
622
623 void
624 TextPanel::fonts_dialog_clicked ()
625 {
626         if (_fonts_dialog) {
627                 _fonts_dialog->Destroy ();
628                 _fonts_dialog = 0;
629         }
630
631         ContentList c = _parent->selected_text ();
632         DCPOMATIC_ASSERT (c.size() == 1);
633
634         _fonts_dialog = new FontsDialog (this, c.front(), c.front()->text_of_original_type(_original_type));
635         _fonts_dialog->Show ();
636 }
637
638 void
639 TextPanel::reference_clicked ()
640 {
641         ContentList c = _parent->selected ();
642         if (c.size() != 1) {
643                 return;
644         }
645
646         shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent> (c.front ());
647         if (!d) {
648                 return;
649         }
650
651         d->set_reference_text (_original_type, _reference->GetValue ());
652 }
653
654 void
655 TextPanel::appearance_dialog_clicked ()
656 {
657         ContentList c = _parent->selected_text ();
658         DCPOMATIC_ASSERT (c.size() == 1);
659
660         SubtitleAppearanceDialog* d = new SubtitleAppearanceDialog (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
661         if (d->ShowModal () == wxID_OK) {
662                 d->apply ();
663         }
664         d->Destroy ();
665 }