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"
26 KeyDialog::KeyDialog (wxWindow* parent, dcp::Key key)
27 : TableDialog (parent, _("Key"), 3, 1, true)
31 wxClientDC dc (parent);
32 wxSize size = dc.GetTextExtent (wxT ("0123456790ABCDEF0123456790ABCDEF"));
35 wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST);
38 wxString n (wxT ("0123456789abcdefABCDEF"));
39 for (size_t i = 0; i < n.Length(); ++i) {
43 validator.SetIncludes (list);
45 _key = add (new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, size, 0, validator));
46 _key->SetValue (std_to_wx (key.hex ()));
47 _key->SetMaxLength (32);
49 _random = add (new wxButton (this, wxID_ANY, _("Random")));
51 _key->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&KeyDialog::key_changed, this));
52 _random->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KeyDialog::random, this));
58 KeyDialog::key () const
60 return dcp::Key (wx_to_std (_key->GetValue ()));
64 KeyDialog::key_changed ()
66 wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
67 ok->Enable (_key->GetValue().Length() == 32);
73 _key->SetValue (dcp::Key().hex ());