2 Copyright (C) 2019 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 "password_entry.h"
22 #include "check_box.h"
28 PasswordEntry::PasswordEntry (wxWindow* parent)
30 _panel = new wxPanel (parent, wxID_ANY);
31 wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
32 _text = new wxTextCtrl (_panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD);
33 sizer->Add (_text, 1, wxRIGHT, DCPOMATIC_SIZER_GAP);
34 _show = new CheckBox (_panel, _("Show"));
35 sizer->Add (_show, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_GAP);
36 _panel->SetSizerAndFit (sizer);
38 _show->Bind (wxEVT_CHECKBOX, bind(&PasswordEntry::show_clicked, this));
39 _text->Bind (wxEVT_TEXT, bind(boost::ref(Changed)));
43 PasswordEntry::get_panel () const
49 PasswordEntry::show_clicked ()
52 wxString const pass = _text->GetValue ();
53 wxSizer* sizer = _text->GetContainingSizer ();
55 _text->GetSelection (&from, &to);
56 sizer->Detach (_text);
58 _text = new wxTextCtrl (_panel, wxID_ANY, pass, wxDefaultPosition, wxDefaultSize, _show->GetValue() ? 0 : wxTE_PASSWORD);
59 _text->SetSelection (from, to);
60 _text->Bind (wxEVT_TEXT, bind(boost::ref(Changed)));
61 sizer->Prepend (_text, 1, wxRIGHT, DCPOMATIC_SIZER_GAP);
67 PasswordEntry::get () const
69 return wx_to_std (_text->GetValue());
73 PasswordEntry::set (string s)
75 _text->SetValue (std_to_wx(s));