Tweak label as suggested by Carsten.
[dcpomatic.git] / src / wx / subtitle_view.cc
1 /*
2     Copyright (C) 2014-2016 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 "lib/text_subtitle_decoder.h"
22 #include "lib/content_subtitle.h"
23 #include "lib/video_decoder.h"
24 #include "lib/audio_decoder.h"
25 #include "lib/film.h"
26 #include "lib/text_subtitle_content.h"
27 #include "subtitle_view.h"
28 #include "wx_util.h"
29
30 using std::list;
31 using boost::shared_ptr;
32 using boost::bind;
33 using boost::dynamic_pointer_cast;
34
35 SubtitleView::SubtitleView (wxWindow* parent, shared_ptr<Film> film, shared_ptr<Decoder> decoder, DCPTime position)
36         : wxDialog (parent, wxID_ANY, _("Subtitles"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
37 {
38         _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL);
39
40         {
41                 wxListItem ip;
42                 ip.SetId (0);
43                 ip.SetText (_("Start"));
44                 ip.SetWidth (100);
45                 _list->InsertColumn (0, ip);
46         }
47
48         {
49                 wxListItem ip;
50                 ip.SetId (1);
51                 ip.SetText (_("End"));
52                 ip.SetWidth (100);
53                 _list->InsertColumn (1, ip);
54         }
55
56         {
57                 wxListItem ip;
58                 ip.SetId (2);
59                 ip.SetText (_("Subtitle"));
60                 ip.SetWidth (640);
61                 _list->InsertColumn (2, ip);
62         }
63
64         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
65         sizer->Add (_list, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
66
67         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
68         if (buttons) {
69                 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
70         }
71
72         if (decoder->video) {
73                 decoder->video->set_ignore ();
74         }
75         if (decoder->audio) {
76                 decoder->audio->set_ignore ();
77         }
78
79         _subs = 0;
80         _frc = film->active_frame_rate_change (position);
81         decoder->subtitle->TextStart.connect (bind (&SubtitleView::data_start, this, _1));
82         decoder->subtitle->Stop.connect (bind (&SubtitleView::data_stop, this, _1));
83         while (!decoder->pass ()) {}
84         SetSizerAndFit (sizer);
85 }
86
87 void
88 SubtitleView::data_start (ContentTextSubtitle cts)
89 {
90         BOOST_FOREACH (dcp::SubtitleString const & i, cts.subs) {
91                 wxListItem list_item;
92                 list_item.SetId (_subs);
93                 _list->InsertItem (list_item);
94                 _list->SetItem (_subs, 0, std_to_wx (cts.from().timecode (_frc->source)));
95                 _list->SetItem (_subs, 2, std_to_wx (i.text ()));
96                 ++_subs;
97         }
98
99         _last_count = cts.subs.size ();
100 }
101
102 void
103 SubtitleView::data_stop (ContentTime time)
104 {
105         if (!_last_count) {
106                 return;
107         }
108
109         for (int i = _subs - *_last_count; i < _subs; ++i) {
110                 _list->SetItem (i, 1, std_to_wx (time.timecode (_frc->source)));
111         }
112 }