[292622]: EditDlg.cpp Maximize Restore History

Download this file

EditDlg.cpp    262 lines (215 with data), 6.0 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
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/// \file EditDlg.cpp
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "PasswordSafe.h"
#include "ThisMfcApp.h"
#include "DboxMain.h"
#include "EditDlg.h"
#include "PwFont.h"
#include "PwsPlatform.h"
#if defined(POCKET_PC)
#include "pocketpc/PocketPC.h"
#endif
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#if defined(POCKET_PC)
#define SHOW_PASSWORD_TXT _T("S")
#define HIDE_PASSWORD_TXT _T("H")
#else
#define SHOW_PASSWORD_TXT _T("&Show Password")
#define HIDE_PASSWORD_TXT _T("&Hide Password")
#endif
void CEditDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_NOTES, (CString &)m_notes);
DDX_Text(pDX, IDC_PASSWORD, (CString &)m_password);
DDX_Text(pDX, IDC_USERNAME, (CString &)m_username);
DDX_Text(pDX, IDC_TITLE, (CString &)m_title);
}
BEGIN_MESSAGE_MAP(CEditDlg, CDialog)
ON_BN_CLICKED(IDC_SHOWPASSWORD, OnShowpassword)
// ON_BN_CLICKED(IDHELP, OnHelp)
ON_BN_CLICKED(ID_HELP, OnHelp)
ON_BN_CLICKED(IDC_RANDOM, OnRandom)
#if defined(POCKET_PC)
ON_WM_SHOWWINDOW()
ON_EN_SETFOCUS(IDC_PASSWORD, OnPasskeySetfocus)
ON_EN_KILLFOCUS(IDC_PASSWORD, OnPasskeyKillfocus)
#endif
END_MESSAGE_MAP()
void CEditDlg::OnShowpassword()
{
UpdateData(TRUE);
CMyString wndName;
GetDlgItem(IDC_SHOWPASSWORD)->GetWindowText(wndName);
if (wndName == SHOW_PASSWORD_TXT)
{
ShowPassword();
}
else if (wndName == HIDE_PASSWORD_TXT)
{
m_realpassword = m_password;
HidePassword();
}
else
AfxMessageBox(_T("Error in retrieving window text"));
UpdateData(FALSE);
}
void
CEditDlg::OnOK()
{
UpdateData(TRUE);
/*
* If the password is shown it may have been edited,
* so save the current text.
*/
if (! m_isPwHidden)
m_realpassword = m_password;
//Check that data is valid
if (m_title == "")
{
AfxMessageBox(_T("This entry must have a title."));
((CEdit*)GetDlgItem(IDC_TITLE))->SetFocus();
return;
}
if (m_password == "")
{
AfxMessageBox(_T("This entry must have a password."));
((CEdit*)GetDlgItem(IDC_PASSWORD))->SetFocus();
return;
}
//End check
DboxMain* pParent = (DboxMain*) GetParent();
ASSERT(pParent != NULL);
POSITION listindex = pParent->Find(m_title, m_username);
/*
* If there is a matching entry in our list, and that
* entry is not the same one we started editing, tell the
* user to try again.
*/
if ((listindex != NULL) &&
(m_listindex != listindex))
{
CMyString temp =
"An item with Title \""
+ m_title + "\" and User Name \"" + m_username
+ "\" already exists.";
AfxMessageBox(temp);
((CEdit*)GetDlgItem(IDC_TITLE))->SetSel(MAKEWORD(-1, 0));
((CEdit*)GetDlgItem(IDC_TITLE))->SetFocus();
}
else
{
app.m_pMainWnd = NULL;
CDialog::OnOK();
}
}
void CEditDlg::OnCancel()
{
app.m_pMainWnd = NULL;
CDialog::OnCancel();
}
BOOL CEditDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetPasswordFont(GetDlgItem(IDC_PASSWORD));
if (app.GetProfileInt(_T(PWS_REG_OPTIONS), _T("showpwdefault"), FALSE) == TRUE)
{
ShowPassword();
}
else
{
HidePassword();
}
UpdateData(FALSE);
return TRUE;
}
void CEditDlg::ShowPassword(void)
{
m_password = m_realpassword;
m_isPwHidden = false;
GetDlgItem(IDC_SHOWPASSWORD)->SetWindowText(HIDE_PASSWORD_TXT);
GetDlgItem(IDC_PASSWORD)->EnableWindow(TRUE);
}
void CEditDlg::HidePassword(void)
{
m_password = HIDDEN_PASSWORD;
m_isPwHidden = true;
GetDlgItem(IDC_SHOWPASSWORD)->SetWindowText(SHOW_PASSWORD_TXT);
GetDlgItem(IDC_PASSWORD)->EnableWindow(FALSE);
}
void CEditDlg::OnRandom()
{
DboxMain* pParent = (DboxMain*) GetParent();
ASSERT(pParent != NULL);
CMyString temp = pParent->GetPassword();
UpdateData(TRUE);
CMyString msg;
int nResponse;
//Ask if something's there
if (m_password != "")
{
msg =
"The randomly generated password is: \""
+ temp
+ "\" \n(without the quotes). Would you like to use it?";
nResponse = MessageBox(msg,
AfxGetAppName(),
MB_ICONEXCLAMATION|MB_YESNO);
}
else
nResponse = IDYES;
if (nResponse == IDYES)
{
m_realpassword = temp;
CMyString wndName;
GetDlgItem(IDC_SHOWPASSWORD)->GetWindowText(wndName);
if (wndName == SHOW_PASSWORD_TXT)
{
m_password = HIDDEN_PASSWORD;
}
else if (wndName == HIDE_PASSWORD_TXT)
{
m_password = m_realpassword;
}
UpdateData(FALSE);
}
else if (nResponse == IDNO)
{
}
}
void CEditDlg::OnHelp()
{
#if defined(POCKET_PC)
CreateProcess( _T("PegHelp.exe"), _T("pws_ce_help.html#editview"), NULL, NULL, FALSE, 0, NULL, NULL, NULL, NULL );
#else
::HtmlHelp(
NULL,
"pwsafe.chm::/html/pws_edit.htm",
HH_DISPLAY_TOPIC, 0);
#endif
}
#if defined(POCKET_PC)
/************************************************************************/
/* Restore the state of word completion when the password field loses */
/* focus. */
/************************************************************************/
void CEditDlg::OnPasskeyKillfocus()
{
EnableWordCompletion( m_hWnd );
}
/************************************************************************/
/* When the password field is activated, pull up the SIP and disable */
/* word completion. */
/************************************************************************/
void CEditDlg::OnPasskeySetfocus()
{
DisableWordCompletion( m_hWnd );
}
#endif
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------