Fix "find" feature in file viewer

The 1.0 edit control only searched down, so the fact that CP was
misconfiguring the search request didn't matter.  This change fixes
the search parameters and enables bi-directional searches.
This commit is contained in:
Andy McFadden 2015-02-17 10:41:22 -08:00
parent 4d85f31f0f
commit e22eb99212
2 changed files with 38 additions and 40 deletions

View File

@ -1171,14 +1171,7 @@ void ViewFilesDialog::OnFviewFind(void)
if (fFindMatchWholeWord)
flags |= FR_WHOLEWORD;
/*
* I can't get this to work with FindText(). There's a lot of questions
* about this on web sites. Probably safest to just disable it.
*/
flags |= FR_HIDEUPDOWN;
fpFindDialog = new CFindReplaceDialog;
fpFindDialog->Create(TRUE, // "find" only
fFindLastStr, // default string to search for
NULL, // default string to replace
@ -1225,35 +1218,44 @@ void ViewFilesDialog::FindNext(const WCHAR* str, bool down, bool matchCase,
DWORD flags = 0;
long start, result;
if (down)
flags |= FR_DOWN;
if (matchCase)
flags |= FR_MATCHCASE;
if (wholeWord)
flags |= FR_WHOLEWORD;
fEditCtrl.GetSel(selChrg);
LOGD(" selection is %ld,%ld",
selChrg.cpMin, selChrg.cpMax);
if (selChrg.cpMin == selChrg.cpMax)
start = selChrg.cpMin; // start at caret
else
start = selChrg.cpMin +1; // start past selection
LOGD(" selection is %ld,%ld; start=%ld",
selChrg.cpMin, selChrg.cpMax, start);
findTextEx.chrg.cpMin = start;
findTextEx.chrg.cpMax = -1;
findTextEx.lpstrText = str;
/* MSVC++6 claims FindText doesn't exist, even though it's in the header */
//result = fEditCtrl.FindText(flags, &findTextEx);
result = fEditCtrl.SendMessage(EM_FINDTEXTEX, (WPARAM) flags,
(LPARAM) &findTextEx);
if (result == -1) {
/* didn't find it, wrap around to start */
findTextEx.chrg.cpMin = 0;
findTextEx.chrg.cpMin = start;
if (down) {
findTextEx.chrg.cpMax = -1;
} else {
findTextEx.chrg.cpMax = 0;
}
LOGV(" using cpMin=%ld cpMax=%ld",
findTextEx.chrg.cpMin, findTextEx.chrg.cpMax);
result = fEditCtrl.FindText(flags, &findTextEx);
if (result == -1) {
LOGD(" not found, wrapping and retrying");
/* didn't find it, wrap around to start/end and retry */
if (down) {
findTextEx.chrg.cpMin = 0;
findTextEx.chrg.cpMax = -1;
} else {
findTextEx.chrg.cpMin = fEditCtrl.GetTextLength();
findTextEx.chrg.cpMax = 0;
}
findTextEx.lpstrText = str;
result = fEditCtrl.SendMessage(EM_FINDTEXTEX, (WPARAM) flags,
(LPARAM) &findTextEx);
result = fEditCtrl.FindText(flags, &findTextEx);
}
LOGD(" result=%ld min=%ld max=%ld", result,

View File

@ -23,24 +23,20 @@ class MainWindow;
class ViewFilesDialog : public CDialog {
public:
ViewFilesDialog(CWnd* pParentWnd = NULL) :
CDialog(IDD_FILE_VIEWER, pParentWnd)
{
//fpMainWindow = NULL;
fpSelSet = NULL;
fpHolder = NULL;
fpOutput = NULL;
fTypeFace = "";
fPointSize = 0;
fNoWrapText = false;
fBusy = false;
fpRichEditOle = NULL;
fFirstResize = false;
fpFindDialog = NULL;
fFindDown = false;
fFindMatchCase = false;
fFindMatchWholeWord = false;
}
CDialog(IDD_FILE_VIEWER, pParentWnd),
fpSelSet(NULL),
fpHolder(NULL),
fpOutput(NULL),
fPointSize(0),
fNoWrapText(false),
fBusy(false),
fFirstResize(false),
fpRichEditOle(NULL),
fpFindDialog(NULL),
fFindDown(true),
fFindMatchCase(false),
fFindMatchWholeWord(false)
{}
virtual ~ViewFilesDialog(void) {
delete fpHolder;
delete fpOutput;