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"
27 KeyDialog::KeyDialog (wxWindow* parent, dcp::Key key)
28 : TableDialog (parent, _("Key"), 3, 1, true)
32 wxClientDC dc (parent);
33 wxSize size = dc.GetTextExtent (wxT ("0123456790ABCDEF0123456790ABCDEF"));
36 wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST);
39 wxString n (wxT ("0123456789abcdefABCDEF"));
40 for (size_t i = 0; i < n.Length(); ++i) {
44 validator.SetIncludes (list);
46 _key = add (new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, size, 0, validator));
47 _key->SetValue (std_to_wx (key.hex ()));
48 _key->SetMaxLength (32);
50 _random = add (new wxButton (this, wxID_ANY, _("Random")));
52 _key->Bind (wxEVT_TEXT, boost::bind (&KeyDialog::key_changed, this));
53 _random->Bind (wxEVT_BUTTON, boost::bind (&KeyDialog::random, this));
59 KeyDialog::key () const
61 return dcp::Key (wx_to_std (_key->GetValue ()));
65 KeyDialog::key_changed ()
67 wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
68 ok->Enable (_key->GetValue().Length() == 32);
74 _key->SetValue (dcp::Key().hex ());