|
|
|
@ -23,28 +23,38 @@
|
|
|
|
|
#include "Common.h"
|
|
|
|
|
#include "Utf8.h"
|
|
|
|
|
|
|
|
|
|
把代码逐行注释如下:
|
|
|
|
|
|
|
|
|
|
// 引入命名空间
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
// 定义 FindOption 类指针和静态变量 _options
|
|
|
|
|
FindOption * FindReplaceDlg::_env;
|
|
|
|
|
FindOption FindReplaceDlg::_options;
|
|
|
|
|
|
|
|
|
|
// 定义 SHIFTED 常量
|
|
|
|
|
#define SHIFTED 0x8000
|
|
|
|
|
|
|
|
|
|
// 向 Combo Box 中添加文本
|
|
|
|
|
void addText2Combo(const TCHAR * txt2add, HWND hCombo)
|
|
|
|
|
{
|
|
|
|
|
// 如果没有 Combo Box 或者 txt2add 为空,则返回
|
|
|
|
|
if (!hCombo) return;
|
|
|
|
|
if (!lstrcmp(txt2add, TEXT(""))) return;
|
|
|
|
|
|
|
|
|
|
// 查找是否已经存在该文本,如果存在则删除
|
|
|
|
|
auto i = ::SendMessage(hCombo, CB_FINDSTRINGEXACT, static_cast<WPARAM>(-1), reinterpret_cast<LPARAM>(txt2add));
|
|
|
|
|
if (i != CB_ERR) // found
|
|
|
|
|
{
|
|
|
|
|
::SendMessage(hCombo, CB_DELETESTRING, i, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将文本插入 Combo Box,并设置为当前选中项
|
|
|
|
|
i = ::SendMessage(hCombo, CB_INSERTSTRING, 0, reinterpret_cast<LPARAM>(txt2add));
|
|
|
|
|
::SendMessage(hCombo, CB_SETCURSEL, i, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 从 Combo Box 中获取文本
|
|
|
|
|
generic_string getTextFromCombo(HWND hCombo)
|
|
|
|
|
{
|
|
|
|
|
TCHAR str[FINDREPLACE_MAXLENGTH] = { '\0' };
|
|
|
|
@ -52,6 +62,7 @@ generic_string getTextFromCombo(HWND hCombo)
|
|
|
|
|
return generic_string(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除编辑框中光标左边的单词
|
|
|
|
|
void delLeftWordInEdit(HWND hEdit)
|
|
|
|
|
{
|
|
|
|
|
TCHAR str[FINDREPLACE_MAXLENGTH] = { '\0' };
|
|
|
|
@ -77,6 +88,7 @@ void delLeftWordInEdit(HWND hEdit)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 运行交换按钮处理函数
|
|
|
|
|
LRESULT run_swapButtonProc(WNDPROC oldEditProc, HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
{
|
|
|
|
|
switch (message)
|
|
|
|
@ -93,6 +105,7 @@ LRESULT run_swapButtonProc(WNDPROC oldEditProc, HWND hwnd, UINT message, WPARAM
|
|
|
|
|
return ::CallWindowProc(oldEditProc, hwnd, message, wParam, lParam);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将扩展字符转换为字符串
|
|
|
|
|
int Searching::convertExtendedToString(const TCHAR * query, TCHAR * result, int length)
|
|
|
|
|
{ //query may equal to result, since it always gets smaller
|
|
|
|
|
int i = 0, j = 0;
|
|
|
|
@ -186,6 +199,7 @@ int Searching::convertExtendedToString(const TCHAR * query, TCHAR * result, int
|
|
|
|
|
return j;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将字符串转换为指定进制的整数
|
|
|
|
|
bool Searching::readBase(const TCHAR * str, int * value, int base, int size)
|
|
|
|
|
{
|
|
|
|
|
int i = 0, temp = 0;
|
|
|
|
@ -218,36 +232,35 @@ bool Searching::readBase(const TCHAR * str, int * value, int base, int size)
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 在编辑框中显示查找结果
|
|
|
|
|
void Searching::displaySectionCentered(size_t posStart, size_t posEnd, ScintillaEditView * pEditView, bool isDownwards)
|
|
|
|
|
{
|
|
|
|
|
// Make sure target lines are unfolded
|
|
|
|
|
// 确保目标行未折叠
|
|
|
|
|
pEditView->execute(SCI_ENSUREVISIBLE, pEditView->execute(SCI_LINEFROMPOSITION, posStart));
|
|
|
|
|
pEditView->execute(SCI_ENSUREVISIBLE, pEditView->execute(SCI_LINEFROMPOSITION, posEnd));
|
|
|
|
|
|
|
|
|
|
// Jump-scroll to center, if current position is out of view
|
|
|
|
|
// 跳跃滚动到中心位置,如果当前位置不在视图内
|
|
|
|
|
pEditView->execute(SCI_SETVISIBLEPOLICY, CARET_JUMPS | CARET_EVEN);
|
|
|
|
|
pEditView->execute(SCI_ENSUREVISIBLEENFORCEPOLICY, pEditView->execute(SCI_LINEFROMPOSITION, isDownwards ? posEnd : posStart));
|
|
|
|
|
// When searching up, the beginning of the (possible multiline) result is important, when scrolling down the end
|
|
|
|
|
// 当向上查找时,结果的开头很重要,而向下滚动时则是结尾
|
|
|
|
|
pEditView->execute(SCI_GOTOPOS, isDownwards ? posEnd : posStart);
|
|
|
|
|
pEditView->execute(SCI_SETVISIBLEPOLICY, CARET_EVEN);
|
|
|
|
|
pEditView->execute(SCI_ENSUREVISIBLEENFORCEPOLICY, pEditView->execute(SCI_LINEFROMPOSITION, isDownwards ? posEnd : posStart));
|
|
|
|
|
|
|
|
|
|
// Adjust so that we see the entire match; primarily horizontally
|
|
|
|
|
// 调整以便看到整个匹配;主要是水平方向
|
|
|
|
|
pEditView->execute(SCI_SCROLLRANGE, posStart, posEnd);
|
|
|
|
|
|
|
|
|
|
// Move cursor to end of result and select result
|
|
|
|
|
// 将光标移动到结果的结尾并选择结果
|
|
|
|
|
pEditView->execute(SCI_GOTOPOS, posEnd);
|
|
|
|
|
pEditView->execute(SCI_SETANCHOR, posStart);
|
|
|
|
|
|
|
|
|
|
// Update Scintilla's knowledge about what column the caret is in, so that if user
|
|
|
|
|
// does up/down arrow as first navigation after the search result is selected,
|
|
|
|
|
// the caret doesn't jump to an unexpected column
|
|
|
|
|
// 更新 Scintilla 对插入符所在列的了解,以便如果用户在选择搜索结果后的首次导航时使用上/下箭头,则插入符不会跳到意外的列
|
|
|
|
|
pEditView->execute(SCI_CHOOSECARETX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 定义静态变量 originalFinderProc 和 originalComboEditProc
|
|
|
|
|
WNDPROC FindReplaceDlg::originalFinderProc = nullptr;
|
|
|
|
|
WNDPROC FindReplaceDlg::originalComboEditProc = nullptr;
|
|
|
|
|
|
|
|
|
|
// important : to activate all styles
|
|
|
|
|
const int STYLING_MASK = 255;
|
|
|
|
|
|
|
|
|
|