Accessor for ClosedCaptionsDialog.
[dcpomatic.git] / src / wx / password_entry.cc
1 /*
2     Copyright (C) 2019 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "password_entry.h"
22 #include "check_box.h"
23 #include "wx_util.h"
24
25 using std::string;
26 using boost::bind;
27
28 PasswordEntry::PasswordEntry (wxWindow* parent)
29 {
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);
37
38         _show->Bind (wxEVT_CHECKBOX, bind(&PasswordEntry::show_clicked, this));
39         _text->Bind (wxEVT_TEXT, bind(boost::ref(Changed)));
40 }
41
42 wxPanel *
43 PasswordEntry::get_panel () const
44 {
45         return _panel;
46 }
47
48 void
49 PasswordEntry::show_clicked ()
50 {
51         _panel->Freeze ();
52         wxString const pass = _text->GetValue ();
53         wxSizer* sizer = _text->GetContainingSizer ();
54         long from, to;
55         _text->GetSelection (&from, &to);
56         sizer->Detach (_text);
57         delete _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);
62         sizer->Layout ();
63         _panel->Thaw ();
64 }
65
66 string
67 PasswordEntry::get () const
68 {
69         return wx_to_std (_text->GetValue());
70 }
71
72 void
73 PasswordEntry::set (string s)
74 {
75         _text->SetValue (std_to_wx(s));
76 }