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