Fix shared_ptr for Film.
[dcpomatic.git] / src / wx / dcp_range_dialog.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "lib/film.h"
21 #include "dcp_range_dialog.h"
22 #include "wx_util.h"
23
24 using boost::shared_ptr;
25
26 DCPRangeDialog::DCPRangeDialog (wxWindow* p, shared_ptr<Film> f)
27         : wxDialog (p, wxID_ANY, wxString (_("DCP Range")))
28         , _film (f)
29 {
30         wxFlexGridSizer* table = new wxFlexGridSizer (2, 6, 6);
31
32         _whole = new wxRadioButton (this, wxID_ANY, _("Whole film"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
33         table->Add (_whole, 1);
34         table->AddSpacer (0);
35         
36         _first = new wxRadioButton (this, wxID_ANY, _("First"));
37         table->Add (_first);
38         {
39                 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
40                 _n_frames = new wxSpinCtrl (this, wxID_ANY);
41                 s->Add (_n_frames);
42                 add_label_to_sizer (s, this, "frames");
43                 table->Add (s);
44         }
45
46         table->AddSpacer (0);
47         _cut = new wxRadioButton (this, wxID_ANY, _("Cut remainder"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
48         table->Add (_cut);
49
50         table->AddSpacer (0);
51         _black_out = new wxRadioButton (this, wxID_ANY, _("Black-out remainder"));
52         table->Add (_black_out);
53
54         _n_frames->SetRange (1, INT_MAX - 1);
55         if (_film->dcp_frames()) {
56                 _whole->SetValue (false);
57                 _first->SetValue (true);
58                 _n_frames->SetValue (_film->dcp_frames().get());
59         } else {
60                 _whole->SetValue (true);
61                 _first->SetValue (false);
62                 _n_frames->SetValue (24);
63         }
64
65         _black_out->Enable (_film->dcp_trim_action() == BLACK_OUT);
66         _cut->Enable (_film->dcp_trim_action() == CUT);
67
68         _whole->Connect (wxID_ANY, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler (DCPRangeDialog::whole_toggled), 0, this);
69         _first->Connect (wxID_ANY, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler (DCPRangeDialog::first_toggled), 0, this);
70         _cut->Connect (wxID_ANY, wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler (DCPRangeDialog::cut_toggled), 0, this);
71         _n_frames->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (DCPRangeDialog::n_frames_changed), 0, this);
72
73         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
74         overall_sizer->Add (table, 0, wxALL, 6);
75         
76         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
77         if (buttons) {
78                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
79         }
80
81         SetSizer (overall_sizer);
82         overall_sizer->SetSizeHints (this);
83
84         set_sensitivity ();
85 }
86
87 void
88 DCPRangeDialog::whole_toggled (wxCommandEvent &)
89 {
90         set_sensitivity ();
91         emit_changed ();
92 }
93
94 void
95 DCPRangeDialog::first_toggled (wxCommandEvent &)
96 {
97         set_sensitivity ();
98         emit_changed ();
99 }
100
101 void
102 DCPRangeDialog::set_sensitivity ()
103 {
104         _n_frames->Enable (_first->GetValue ());
105         _black_out->Enable (_first->GetValue ());
106         _cut->Enable (_first->GetValue ());
107 }
108
109 void
110 DCPRangeDialog::cut_toggled (wxCommandEvent &)
111 {
112         set_sensitivity ();
113         emit_changed ();
114 }
115
116 void
117 DCPRangeDialog::n_frames_changed (wxCommandEvent &)
118 {
119         emit_changed ();
120 }
121
122 void
123 DCPRangeDialog::emit_changed ()
124 {
125         int frames = 0;
126         if (!_whole->GetValue ()) {
127                 frames = _n_frames->GetValue ();
128         }
129
130         TrimAction action = CUT;
131         if (_black_out->GetValue ()) {
132                 action = BLACK_OUT;
133         }
134
135         Changed (frames, action);
136 }