-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountDialog.cpp
More file actions
77 lines (59 loc) · 2.95 KB
/
AccountDialog.cpp
File metadata and controls
77 lines (59 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "AccountDialog.h"
#include "LanguageManager.h"
#include <wx/artprov.h>
AccountDialog::AccountDialog(wxWindow* parent, const wxString& title, const Account& acc)
: wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize) {
auto* mainSizer = new wxBoxSizer(wxVERTICAL);
auto* panel = new wxPanel(this);
auto* panelSizer = new wxBoxSizer(wxVERTICAL);
auto gridSizer = new wxFlexGridSizer(2, 5, 5);
gridSizer->AddGrowableCol(1, 1);
gridSizer->Add(new wxStaticText(panel, wxID_ANY, L("ACCOUNT_ID_LABEL")), 0, wxALIGN_CENTER_VERTICAL);
m_idCtrl = new wxTextCtrl(panel, wxID_ANY, acc.id);
gridSizer->Add(m_idCtrl, 1, wxEXPAND);
gridSizer->Add(new wxStaticText(panel, wxID_ANY, L("PASSWORD_LABEL")), 0, wxALIGN_CENTER_VERTICAL);
auto* passSizer = new wxBoxSizer(wxHORIZONTAL);
m_passCtrl = new wxTextCtrl(panel, wxID_ANY, acc.password, wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD);
m_revealBtn = new wxButton(panel, wxID_ANY, "View", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
#ifdef __WXMSW__
m_revealBtn->SetBitmap(wxArtProvider::GetBitmap(wxART_FIND, wxART_BUTTON));
#endif
passSizer->Add(m_passCtrl, 1, wxEXPAND);
passSizer->Add(m_revealBtn, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 5);
gridSizer->Add(passSizer, 1, wxEXPAND);
gridSizer->Add(new wxStaticText(panel, wxID_ANY, L("DESCRIPTION_LABEL")), 0, wxALIGN_CENTER_VERTICAL);
m_descCtrl = new wxTextCtrl(panel, wxID_ANY, acc.description);
gridSizer->Add(m_descCtrl, 1, wxEXPAND);
panelSizer->Add(gridSizer, 1, wxEXPAND | wxALL, 10);
panel->SetSizer(panelSizer);
mainSizer->Add(panel, 1, wxEXPAND);
mainSizer->Add(CreateButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_RIGHT | wxALL, 10);
SetSizerAndFit(mainSizer);
m_revealBtn->Bind(wxEVT_BUTTON, &AccountDialog::OnToggleReveal, this);
}
void AccountDialog::OnToggleReveal(wxCommandEvent&) {
m_revealed = !m_revealed;
m_revealBtn->SetLabel(m_revealed ? "Hide" : "View");
wxString val = m_passCtrl->GetValue();
long style = m_passCtrl->GetWindowStyleFlag();
auto* sizer = m_passCtrl->GetContainingSizer();
// Find the item in the sizer to get its flags and proportion
wxSizerItem* item = nullptr;
for (size_t i = 0; i < sizer->GetItemCount(); ++i) {
if (sizer->GetItem(i)->GetWindow() == m_passCtrl) {
item = sizer->GetItem(i);
break;
}
}
int flags = item ? item->GetFlag() : wxEXPAND;
int proportion = item ? item->GetProportion() : 1;
wxWindowID id = m_passCtrl->GetId();
m_passCtrl->Destroy();
long newStyle = m_revealed ? 0 : wxTE_PASSWORD;
m_passCtrl = new wxTextCtrl(m_revealBtn->GetParent(), id, val, wxDefaultPosition, wxDefaultSize, newStyle);
sizer->Prepend(m_passCtrl, proportion, flags);
sizer->Layout();
}
Account AccountDialog::GetAccount() const {
return {m_idCtrl->GetValue(), m_passCtrl->GetValue(), m_descCtrl->GetValue()};
}