2 Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
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.
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.
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.
20 #include "key_dialog.h"
25 KeyDialog::KeyDialog (wxWindow* parent, dcp::Key key)
26 : TableDialog (parent, _("Key"), 3, true)
30 wxClientDC dc (parent);
31 wxSize size = dc.GetTextExtent (wxT ("0123456790ABCDEF0123456790ABCDEF"));
34 wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST);
37 wxString n (wxT ("0123456789abcdefABCDEF"));
38 for (size_t i = 0; i < n.Length(); ++i) {
42 validator.SetIncludes (list);
44 _key = add (new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, size, 0, validator));
45 _key->SetValue (std_to_wx (key.hex ()));
46 _key->SetMaxLength (32);
48 _random = add (new wxButton (this, wxID_ANY, _("Random")));
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));
57 KeyDialog::key () const
59 return dcp::Key (wx_to_std (_key->GetValue ()));
63 KeyDialog::key_changed ()
65 wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
66 ok->Enable (_key->GetValue().Length() == 32);
72 _key->SetValue (dcp::Key().hex ());