2 Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
21 #include "key_dialog.h"
23 #include "dcpomatic_button.h"
28 KeyDialog::KeyDialog (wxWindow* parent, dcp::Key key)
29 : TableDialog (parent, _("Key"), 3, 1, true)
33 wxClientDC dc (parent);
34 wxSize size = dc.GetTextExtent (wxT ("0123456790ABCDEF0123456790ABCDEF"));
37 wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST);
40 wxString n (wxT ("0123456789abcdefABCDEF"));
41 for (size_t i = 0; i < n.Length(); ++i) {
45 validator.SetIncludes (list);
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);
51 _random = add (new Button(this, _("Random")));
53 _key->Bind (wxEVT_TEXT, boost::bind (&KeyDialog::key_changed, this));
54 _random->Bind (wxEVT_BUTTON, boost::bind (&KeyDialog::random, this));
60 KeyDialog::key () const
62 return dcp::Key (wx_to_std (_key->GetValue ()));
66 KeyDialog::key_changed ()
68 wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
69 ok->Enable (_key->GetValue().Length() == 32);
75 _key->SetValue (dcp::Key().hex ());