[58676d]: FindDlg.cpp Maximize Restore History

Download this file

FindDlg.cpp    253 lines (220 with data), 6.9 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
// FindDlg.cpp : implementation file
//
#include "stdafx.h"
#include "passwordsafe.h"
#if defined(POCKET_PC)
#include "pocketpc/resource.h"
#else
#include "resource.h"
#endif
#include "FindDlg.h"
#include "DboxMain.h"
#include "ThisMfcApp.h" // for disable/enable accel.
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFindDlg dialog
CFindDlg *CFindDlg::self = NULL; // for Singleton pattern
void CFindDlg::Doit(CWnd *pParent, BOOL *isCS, CMyString *lastFind, bool *continuefindateodb)
{
if (self == NULL) {
self = new CFindDlg(pParent, isCS, lastFind);
if (self != NULL)
if (self->Create(CFindDlg::IDD)) {
RECT myRect, parentRect;
// move find dialog so that it doesn't overlap its parent
pParent->GetWindowRect(&parentRect);
self->GetWindowRect(&myRect);
// Move the dialog to the right if parent is on left side
// of screen,and vice versa,
// UNLESS parent is close to screen's width!
const int screenWidth = GetSystemMetrics(SM_CXSCREEN);
const int screenCenter = screenWidth/2;
const int parentWidth = (parentRect.right - parentRect.left);
const int parentCenter = (parentRect.right + parentRect.left)/2;
if (parentWidth < (screenWidth * 9) / 10) {
if (parentCenter < screenCenter) {
// move right
myRect.right = parentRect.right + myRect.right - myRect.left;
myRect.left = parentRect.right;
} else { // move left
myRect.left = parentRect.left - (myRect.right - myRect.left);
myRect.right = parentRect.left;
}
self->MoveWindow(&myRect);
} // parent not too wide
}
} else {
self->BringWindowToTop();
}
self->ShowWindow(SW_SHOW);
self->m_bcontinuefindateodb = *continuefindateodb;
((DboxMain*)pParent)->SetFindActive(); // Prevent switch tree/list display modes
app.DisableAccelerator(); // don't accel Del when this dlg is shown
}
CFindDlg::CFindDlg(CWnd* pParent, BOOL *isCS, CMyString *lastFind)
: super(CFindDlg::IDD, pParent), m_indices(NULL),
m_lastshown(-1), m_numFound(0),
m_last_search_text(_T("")), m_last_cs_search(FALSE),
m_lastCSPtr(isCS), m_lastTextPtr(lastFind)
{
ASSERT(isCS !=NULL);
ASSERT(lastFind != NULL);
//{{AFX_DATA_INIT(CFindDlg)
m_cs_search = *isCS;
m_search_text = *lastFind;
m_status = _T("");
//}}AFX_DATA_INIT
}
void CFindDlg::EndIt()
{
if (self != NULL)
delete self;
}
CFindDlg::~CFindDlg()
{
delete[] m_indices;
self = NULL;
}
void CFindDlg::DoDataExchange(CDataExchange* pDX)
{
super::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFindDlg)
DDX_Check(pDX, IDC_FIND_CS, m_cs_search);
DDX_Text(pDX, IDC_FIND_TEXT, m_search_text);
#if !defined(POCKET_PC)
DDX_Text(pDX, IDC_STATUS, m_status);
#endif
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFindDlg, super)
//{{AFX_MSG_MAP(CFindDlg)
ON_BN_CLICKED(IDOK, OnFind)
#if defined(POCKET_PC)
ON_BN_CLICKED(IDCANCEL, OnCancel)
#else
ON_BN_CLICKED(IDCANCEL, OnClose)
#endif
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFindDlg message handlers
void CFindDlg::OnFind()
{
DboxMain* pParent = (DboxMain*) GetParent();
ASSERT(pParent != NULL);
const int numEntries = pParent->GetNumEntries();
if (numEntries == 0) {
// Right Thing would be to disable find menu item if list is empty
m_status = _T("Password list is empty.");
UpdateData(FALSE);
return;
}
UpdateData(TRUE);
if (m_search_text.IsEmpty()) {
m_status = _T("Please enter a search string");
UpdateData(FALSE);
return;
}
// If the user changes the search text or cs, then this is a new search:
if (m_search_text != m_last_search_text ||
m_cs_search != m_last_cs_search) {
m_last_search_text = m_search_text;
m_last_cs_search = m_cs_search;
m_lastshown = -1;
}
if (m_bLastView != pParent->GetCurrentView()) {
m_bLastView = pParent->GetCurrentView();
m_lastshown = -1; // Indices will be in different order even if search the same
}
if (m_lastshown == -1) {
if (m_indices != NULL) {
// take care of the pathological case where someone added or deleted
// an entry while this dialog box is open
delete[] m_indices;
}
m_indices = new int[numEntries];
m_numFound = pParent->FindAll(m_search_text, m_cs_search, m_indices);
switch (m_numFound) {
case 0:
m_status = _T("No matches found.");
break;
case 1:
m_status = _T("Found 1 match.");
break;
default:
// {kjp} this kludge is needed because the declaration of CString in <afx.h> defines
// {kjp} FormatMessage as implemented, but if you take a look at the source for
// {kjp} CString in strex.cpp you'll see that it's only actully implemented if the
// {kjp} platform is not WinCE. Methinks this is a bug in afx.h
#if defined(POCKET_PC)
m_status.Format( _T("Found %d matches."), m_numFound );
#else
m_status.FormatMessage(_T("Found %1!d! matches."), m_numFound);
#endif
break;
}
UpdateData(FALSE);
} // m_lastshown == -1
// OK, so now we have a (possibly empty) list of items to select.
if (m_numFound > 0) {
if (m_numFound == 1) {
pParent->SelectEntry(m_indices[0], TRUE);
} else {
m_lastshown++;
if(m_lastshown >= m_numFound) {
int rc = IDYES;
if (!m_bcontinuefindateodb) { // Ask
rc = MessageBox(_T("Continue search from the beginning?"),
_T("Search string not found"), MB_ICONQUESTION | MB_YESNOCANCEL | MB_DEFBUTTON2);
}
switch (rc) {
case IDYES:
m_lastshown = 0;
pParent->SelectEntry(m_indices[m_lastshown], TRUE);
break;
case IDNO:
#if defined(POCKET_PC)
OnCancel();
#else
OnClose();
#endif
break;
case IDCANCEL:
break;
default:
ASSERT(FALSE);
}
} else {
pParent->SelectEntry(m_indices[m_lastshown], TRUE);
}
SetDlgItemText(IDOK, _T("Find Next"));
}
}
// don't call super::OnOK - user will Cancel() to close dbox
}
#if defined(POCKET_PC)
void CFindDlg::OnCancel()
{
UpdateData(TRUE);
*m_lastTextPtr = m_search_text;
*m_lastCSPtr = m_cs_search;
app.EnableAccelerator(); // restore accel table
super::DestroyWindow();
}
#else
void CFindDlg::OnClose()
{
UpdateData(TRUE);
*m_lastTextPtr = m_search_text;
*m_lastCSPtr = m_cs_search;
DboxMain* pParent = (DboxMain*)GetParent();
pParent->SetFindInActive(); // Allow switch tree/list display modes again
m_bLastView = pParent->GetCurrentView();
app.EnableAccelerator(); // restore accel table
super::OnCancel();
}
#endif