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