📄 editor.c
字号:
//-------------------------------------------------------------------------
void PopFindString(HWND hwnd)
{
char buf[256];
HWND hwndedit;
charinfo a;
if (IsWindow(hwndFind))
{
SetFocus(hwndFind);
return ;
}
if (GetWordFromPos(GetDlgItem(hwnd, ID_EDITCHILD), buf, - 1, 0, 0, 0) &&
buf[0])
strcpy(findbuffer, buf);
find.lStructSize = sizeof(find);
find.hwndOwner = hwndFrame;
find.hInstance = hInstance;
find.Flags = FR_ENABLETEMPLATE | FR_ENABLEHOOK;
if (findflags &1)
find.Flags |= FR_WHOLEWORD;
if (findflags &2)
find.Flags |= FR_MATCHCASE;
if (findflags &8)
find.Flags |= FR_DOWN;
find.lpstrFindWhat = findbuffer;
find.lpstrReplaceWith = 0;
find .wFindWhatLen = 256;
find .wReplaceWithLen = 0;
find.lpTemplateName = "FINDDLG";
find.lpfnHook = findHook;
finding = TRUE;
hwndFind = FindText(&find);
hwndedit = GetDlgItem(hwndFind, 1152);
SubClassHistoryCombo(hwndedit);
SendMessage(hwndedit, WM_SETHISTORY, 0, (LPARAM)findhist1);
// EnumChildWindows(hwndFind, (WNDENUMPROC)enumfunc,0) ;
lastfound = - 1;
// SendMessage(GetDlgItem(hwnd,ID_EDITCHILD),EM_GETSEL, (WPARAM)&findpos,0) ;
SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_EXGETSEL, 0, (LPARAM) &a);
findpos = a.min;
}
//-------------------------------------------------------------------------
void PopReplaceString(HWND hwnd)
{
DWINFO *p = (DWINFO*)GetWindowLong(hwnd, 0);
char buf[256];
HWND hwndedit;
charinfo a;
if (IsWindow(hwndFind))
{
SetFocus(hwndFind);
return ;
}
// if (GetWordFromPos(GetDlgItem(hwnd,ID_EDITCHILD),buf,-1,0,0,0) && buf[0])
// strcpy(findbuffer2,buf) ;
replace.lStructSize = sizeof(replace);
replace.hwndOwner = hwndFrame;
replace.hInstance = hInstance;
replace.Flags = FR_ENABLETEMPLATE | FR_ENABLEHOOK | FR_DOWN;
if (replaceflags &1)
find.Flags |= FR_WHOLEWORD;
if (replaceflags &2)
find.Flags |= FR_MATCHCASE;
replace.lpstrFindWhat = findbuffer2;
replace.lpstrReplaceWith = replacebuffer;
replace .wFindWhatLen = 256;
replace .wReplaceWithLen = 256;
replace.lpTemplateName = "REPLACEDLG";
replace.lpfnHook = findHook;
finding = FALSE;
hwndFind = ReplaceText(&replace);
hwndedit = GetDlgItem(hwndFind, 1152);
SubClassHistoryCombo(hwndedit);
SendMessage(hwndedit, WM_SETHISTORY, 0, (LPARAM)findhist2);
hwndedit = GetDlgItem(hwndFind, 1153);
SubClassHistoryCombo(hwndedit);
SendMessage(hwndedit, WM_SETHISTORY, 0, (LPARAM)replacehist);
lastfound = - 1;
SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_EXGETSEL, 0, (LPARAM) &a);
findpos = a.min;
if (a.min != a.max)
CheckRadioButton(hwndFind, IDC_RADIO_ALL_TEXT, IDC_RADIO_SELECTED_TEXT,
IDC_RADIO_SELECTED_TEXT);
else
CheckRadioButton(hwndFind, IDC_RADIO_ALL_TEXT, IDC_RADIO_SELECTED_TEXT,
IDC_RADIO_ALL_TEXT);
}
//-------------------------------------------------------------------------
int xfind(FINDREPLACE *find, char *buf, int pos, int *len, struct re_registers
**r, int *n)
{
int flags = find->Flags;
int i;
if (!find->lpstrFindWhat)
return - 1;
if (pos < 0)
pos = 0;
*len = strlen(find->lpstrFindWhat);
while (TRUE)
{
if (IsWindow(GetDlgItem(hwndFind, 990)) && IsDlgButtonChecked(hwndFind,
990))
{
#ifdef XREGEX_POSIX
regex_t preg;
regmatch_t match[1];
int err = regcomp(&preg, find->lpstrFindWhat, REG_EXTENDED | (
(flags &FR_MATCHCASE) ? 0 : REG_ICASE) | REG_NEWLINE);
if (err)
{
char ebuf[256];
regerror(err, &preg, ebuf, 256);
ExtendedMessageBox("Regular Expression Error",
MB_SETFOREGROUND | MB_SYSTEMMODAL, ebuf);
return - 1;
} if (!regexec(&preg, buf + pos, 1, &match, 0))
{
regfree(&preg);
*len = match->rm_eo - match->rm_so;
pos = match->rm_so + pos + buf;
}
else
{
regfree(&preg);
return - 1;
}
#else
// This isn't a full emacs version
char *err;
static struct re_pattern_buffer patbuf;
static struct re_registers registers;
static unsigned char trans[256], fastmap[256];
re_set_syntax(RE_SYNTAX_EMACS | RE_NEWLINE_ALT |
RE_CHAR_CLASSES | RE_INTERVALS);
patbuf.translate = &trans;
for (i = 0; i < 256; i++)
trans[i] = i;
if (!(flags &FR_MATCHCASE))
for (i = 'a'; i <= 'z'; i++)
trans[i] = i - 'a' + 'A';
patbuf.fastmap = &fastmap;
patbuf.fastmap_accurate = FALSE;
err = re_compile_pattern(find->lpstrFindWhat, strlen(find
->lpstrFindWhat), &patbuf);
if (err)
{
ExtendedMessageBox("Regular Expression Error",
MB_SETFOREGROUND | MB_SYSTEMMODAL, err);
return - 1;
} i = strlen(buf);
if (flags &FR_DOWN)
i = re_search(&patbuf, buf, i, pos, i - pos, ®isters);
else
i = re_search(&patbuf, buf, i, pos, - pos, ®isters);
if (i < 0)
return - 1;
if (r)
*r = ®isters;
if (n)
*n = patbuf.re_nsub;
*len = registers.end[0] - registers.start[0];
pos = registers.start[0] + buf;
#endif
}
else if (flags &FR_DOWN)
{
if (flags &FR_MATCHCASE)
pos = (int)strstr(buf + pos, find->lpstrFindWhat);
else
pos = (int)stristr(buf + pos, find->lpstrFindWhat);
}
else
{
do
{
int l = strlen(find->lpstrFindWhat);
if (flags &FR_MATCHCASE)
{
if (!strncmp(buf + pos, find->lpstrFindWhat, l))
break;
}
else
if (!strnicmp(buf + pos, find->lpstrFindWhat, l))
break;
pos--;
}
while (pos >= 0);
if (pos < 0)
pos = 0;
else
pos = pos + buf;
}
if (pos)
{
pos = (char*)pos - buf;
if (flags &FR_WHOLEWORD)
{
if (pos && isalnum(buf[pos - 1]))
pos += *len;
else if (!buf[pos + *len] || !isalnum(buf[pos + *len]))
return pos;
else
pos += *len;
}
else
return pos;
}
else
return - 1;
}
}
//-------------------------------------------------------------------------
void MoveFindWindow(HWND editwnd, int left, int right)
{
POINTL ptl, ptr;
RECT w, f, s;
int th = SendMessage(editwnd, EM_GETTEXTHEIGHT, 0, 0);
SendMessage(editwnd, EM_POSFROMCHAR, (WPARAM) &ptl, left);
SendMessage(editwnd, EM_POSFROMCHAR, (WPARAM) &ptr, right);
GetWindowRect(editwnd, &w);
GetWindowRect(hwndFind, &f);
if (IntersectRect(&s, &w, &f))
{
if (ptl.y >= (w.bottom - w.top) / 2)
{
MoveWindow(hwndFind, f.left, w.top, f.right - f.left, f.bottom -
f.top, TRUE);
}
else
{
MoveWindow(hwndFind, f.left, w.bottom - (f.bottom - f.top), f.right
- f.left, f.bottom - f.top, TRUE);
}
}
}
//-------------------------------------------------------------------------
int FindNextString(HWND hwnd, FINDREPLACE *find, struct re_registers **r, int
*n)
{
char *buf = GetEditData(GetDlgItem(hwnd, ID_EDITCHILD));
int len;
if (buf)
{
int pos;
charinfo a;
// SendMessage(GetDlgItem(hwnd,ID_EDITCHILD),EM_GETSEL, (WPARAM)&pos,0) ;
SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_EXGETSEL, 0, (LPARAM) &a)
;
pos = a.min;
if (pos != lastfound && findpos != - 1)
findpos = pos;
if (findpos == - 1)
if (find->Flags &FR_DOWN)
findpos = 0;
else
findpos = strlen(buf);
findpos = xfind(find, buf, findpos, &len, r, n);
lastfound = findpos;
free(buf);
if (findpos >= 0)
{
charinfo r;
r.min = findpos;
r.max = findpos + len;
SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_EXSETSEL, 0, (LPARAM)
&r);
SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_SCROLLCARET, 0, 0);
UpdateWindow(GetDlgItem(hwnd, ID_EDITCHILD));
SendMessage(hwnd, WM_COMMAND, ID_REDRAWSTATUS, 0);
if (find->Flags &FR_DOWN)
findpos += len;
else
{
findpos -= len;
if (findpos < 0)
{
findpos = 0;
goto done;
}
}
MoveFindWindow(GetDlgItem(hwnd, ID_EDITCHILD), findpos, findpos +
len);
}
else
{
done: SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_SETSEL, - 1,
0);
SendMessage(hwnd, WM_COMMAND, ID_REDRAWSTATUS, 0);
if (!(find->Flags &FR_REPLACEALL))
{
ExtendedMessageBox("Search", MB_SETFOREGROUND | MB_SYSTEMMODAL,
"No more matches found");
}
findpos = - 1;
return TRUE;
}
return FALSE;
}
return TRUE;
}
//-------------------------------------------------------------------------
void ReplaceNextString(HWND hwnd, FINDREPLACE *replace)
{
char buf[256];
int flags;
static struct re_registers *registers;
int regnum;
charinfo a;
int selected;
selected = IsDlgButtonChecked(hwndFind, IDC_RADIO_SELECTED_TEXT);
if (selected)
{
SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_EXGETSEL, 0, (LPARAM) &a)
;
} replace->Flags |= FR_DOWN;
flags = replace->Flags;
SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_HIDESELECTION, 1, 0);
while (TRUE)
{
int notthere = FALSE;
if (!found || (flags &FR_FINDNEXT))
{
notthere = FindNextString(hwnd, replace, ®isters, ®num);
if (!found && !(flags &FR_REPLACEALL))
{
found = !notthere;
SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_HIDESELECTION, 0,
0);
SendMessage(hwnd, WM_COMMAND, ID_REDRAWSTATUS, 0);
return ;
}
found = !notthere;
}
if (notthere || selected && findpos >= a.max)
{
findpos = - 1;
SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_HIDESELECTION, 0, 0);
SendMessage(hwnd, WM_COMMAND, ID_REDRAWSTATUS, 0);
if (selected && (flags &FR_REPLACEALL))
{
SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_EXSETSEL, 0,
(LPARAM) &a);
}
return ;
}
if (flags &(FR_REPLACE | FR_REPLACEALL))
{
int readonly = SendMessage(GetDlgItem(hwnd, ID_EDITCHILD),
EM_GETREADONLY, 0, 0);
if (!readonly)
{
if (IsWindow(GetDlgItem(hwndFind, 990)) && IsDlgButtonChecked
(hwndFind, 990))
{
int i, dest = 0;
char *dta = GetEditData(GetDlgItem(hwnd, ID_EDITCHILD));
for (i = 0; i < strlen(replace->lpstrReplaceWith) && dest <
255; i++)
{
if (replace->lpstrReplaceWith[i] == '\\')
{
if (replace->lpstrReplaceWith[++i])
{
int index = replace->lpstrReplaceWith[i];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -