Accessor for ClosedCaptionsDialog.
[dcpomatic.git] / src / wx / key_dialog.cc
1 /*
2     Copyright (C) 2015 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 "key_dialog.h"
22 #include "wx_util.h"
23 #include "dcpomatic_button.h"
24 #include <iostream>
25
26 using std::cout;
27
28 KeyDialog::KeyDialog (wxWindow* parent, dcp::Key key)
29         : TableDialog (parent, _("Key"), 3, 1, true)
30 {
31         add (_("Key"), true);
32
33         wxClientDC dc (parent);
34         wxSize size = dc.GetTextExtent (wxT ("0123456790ABCDEF0123456790ABCDEF"));
35         size.SetHeight (-1);
36
37         wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST);
38         wxArrayString list;
39
40         wxString n (wxT ("0123456789abcdefABCDEF"));
41         for (size_t i = 0; i < n.Length(); ++i) {
42                 list.Add (n[i]);
43         }
44
45         validator.SetIncludes (list);
46
47         _key = add (new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, size, 0, validator));
48         _key->SetValue (std_to_wx (key.hex ()));
49         _key->SetMaxLength (32);
50
51         _random = add (new Button(this, _("Random")));
52
53         _key->Bind (wxEVT_TEXT, boost::bind (&KeyDialog::key_changed, this));
54         _random->Bind (wxEVT_BUTTON, boost::bind (&KeyDialog::random, this));
55
56         layout ();
57 }
58
59 dcp::Key
60 KeyDialog::key () const
61 {
62         return dcp::Key (wx_to_std (_key->GetValue ()));
63 }
64
65 void
66 KeyDialog::key_changed ()
67 {
68         wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
69         ok->Enable (_key->GetValue().Length() == 32);
70 }
71
72 void
73 KeyDialog::random ()
74 {
75         _key->SetValue (dcp::Key().hex ());
76 }