+ fix: handling of "Mark Occ." and "Focused View" in cooperation with find/replace dialog

This commit is contained in:
Rainer Kottenhoff 2018-05-08 00:14:39 +02:00
parent 1983bdb2b1
commit c0a2fac7b5
2 changed files with 132 additions and 127 deletions

View File

@ -95,10 +95,10 @@ static LRESULT CALLBACK _MsgBoxProc(INT nCode, WPARAM wParam, LPARAM lParam)
CenterDlgInParent(hChildWnd);
}
PostMessage(hChildWnd, WM_SETFOCUS, 0, 0);
// exit _MsgBoxProc hook
UnhookWindowsHookEx(hhkMsgBox);
}
else // otherwise, continue with any possible chained hooks
{
@ -146,23 +146,119 @@ int MsgBox(int iType,UINT uIdMsg,...)
int iIcon = MB_ICONHAND;
switch (iType) {
case MBINFO: iIcon = MB_ICONINFORMATION; break;
case MBWARN: iIcon = MB_ICONWARNING; break;
case MBINFO: iIcon = MB_ICONINFORMATION | MB_OK; break;
case MBWARN: iIcon = MB_ICONWARNING | MB_OK; break;
case MBYESNO: iIcon = MB_ICONQUESTION | MB_YESNO; break;
case MBYESNOCANCEL: iIcon = MB_ICONINFORMATION | MB_YESNOCANCEL; break;
case MBYESNOWARN: iIcon = MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON1; break;
case MBOKCANCEL: iIcon = MB_ICONEXCLAMATION | MB_OKCANCEL; break;
case MBRETRYCANCEL: iIcon = MB_ICONQUESTION | MB_RETRYCANCEL; break;
default: iIcon = MB_ICONSTOP | MB_TOPMOST | MB_OK; break;
default: iIcon = MB_ICONSTOP | MB_OK; break;
}
iIcon |= (MB_TOPMOST | MB_SETFOREGROUND);
// center message box to main
HWND focus = GetFocus();
HWND hwnd = focus ? focus : g_hwndMain;
hhkMsgBox = SetWindowsHookEx(WH_CBT, &_MsgBoxProc, 0, GetCurrentThreadId());
return MessageBox(hwnd, szText, szTitle, iIcon);
//return MessageBoxEx(hwnd, szText, szTitle, iIcon, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT));
}
//=============================================================================
//
// InfoBoxDlgProc()
//
//
typedef struct _infobox {
LPWSTR lpstrMessage;
LPWSTR lpstrSetting;
bool bDisableCheckBox;
} INFOBOX, *LPINFOBOX;
INT_PTR CALLBACK InfoBoxDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
LPINFOBOX lpib;
switch (umsg)
{
case WM_INITDIALOG:
lpib = (LPINFOBOX)lParam;
SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam);
SendDlgItemMessage(hwnd, IDC_INFOBOXICON, STM_SETICON,
(WPARAM)LoadIcon(NULL, IDI_EXCLAMATION), 0);
SetDlgItemText(hwnd, IDC_INFOBOXTEXT, lpib->lpstrMessage);
if (lpib->bDisableCheckBox)
DialogEnableWindow(hwnd, IDC_INFOBOXCHECK, false);
LocalFree(lpib->lpstrMessage);
CenterDlgInParent(hwnd);
return true;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
case IDYES:
case IDNO:
lpib = (LPINFOBOX)GetWindowLongPtr(hwnd, DWLP_USER);
if (IsDlgButtonChecked(hwnd, IDC_INFOBOXCHECK))
IniSetInt(L"Suppressed Messages", lpib->lpstrSetting, 1);
EndDialog(hwnd, LOWORD(wParam));
break;
}
return true;
}
return false;
}
//=============================================================================
//
// InfoBox()
//
//
extern WCHAR g_wchIniFile[MAX_PATH];
INT_PTR InfoBox(int iType, LPCWSTR lpstrSetting, int uidMessage, ...)
{
int iMode = IniGetInt(L"Suppressed Messages", lpstrSetting, 0);
if (lstrlen(lpstrSetting) > 0 && iMode == 1)
return (iType == MBYESNO) ? IDYES : IDOK;
WCHAR wchFormat[LARGE_BUFFER];
if (!GetString(uidMessage, wchFormat, COUNTOF(wchFormat)))
return(-1);
INFOBOX ib;
ib.lpstrMessage = LocalAlloc(LPTR, HUGE_BUFFER * sizeof(WCHAR));
StringCchVPrintfW(ib.lpstrMessage, HUGE_BUFFER, wchFormat, (LPVOID)((PUINT_PTR)&uidMessage + 1));
ib.lpstrSetting = (LPWSTR)lpstrSetting;
ib.bDisableCheckBox = (StringCchLenW(g_wchIniFile, COUNTOF(g_wchIniFile)) == 0 || lstrlen(lpstrSetting) == 0 || iMode == 2) ? true : false;
int idDlg;
switch (iType) {
case MBYESNO:
idDlg = IDD_INFOBOX2;
break;
case MBOKCANCEL:
idDlg = IDD_INFOBOX3;
break;
default:
idDlg = IDD_INFOBOX;
break;
}
MessageBeep(MB_ICONEXCLAMATION);
HWND focus = GetFocus();
HWND hwnd = focus ? focus : g_hwndMain;
hhkMsgBox = SetWindowsHookEx(WH_CBT, &_MsgBoxProc, 0, GetCurrentThreadId());
return MessageBoxEx(hwnd, szText, szTitle, MB_SETFOREGROUND | iIcon, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT));
return ThemedDialogBoxParam(g_hInstance, MAKEINTRESOURCE(idDlg), hwnd, InfoBoxDlgProc, (LPARAM)&ib);
}
@ -2525,54 +2621,6 @@ bool SelectDefLineEndingDlg(HWND hwnd,int *iOption)
}
//=============================================================================
//
// InfoBoxDlgProc()
//
//
typedef struct _infobox {
LPWSTR lpstrMessage;
LPWSTR lpstrSetting;
bool bDisableCheckBox;
} INFOBOX, *LPINFOBOX;
INT_PTR CALLBACK InfoBoxDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam)
{
LPINFOBOX lpib;
switch(umsg)
{
case WM_INITDIALOG:
lpib = (LPINFOBOX)lParam;
SetWindowLongPtr(hwnd,DWLP_USER,(LONG_PTR)lParam);
SendDlgItemMessage(hwnd,IDC_INFOBOXICON,STM_SETICON,
(WPARAM)LoadIcon(NULL,IDI_EXCLAMATION),0);
SetDlgItemText(hwnd,IDC_INFOBOXTEXT,lpib->lpstrMessage);
if (lpib->bDisableCheckBox)
DialogEnableWindow(hwnd,IDC_INFOBOXCHECK,false);
LocalFree(lpib->lpstrMessage);
CenterDlgInParent(hwnd);
return true;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
case IDYES:
case IDNO:
lpib = (LPINFOBOX)GetWindowLongPtr(hwnd,DWLP_USER);
if (IsDlgButtonChecked(hwnd,IDC_INFOBOXCHECK))
IniSetInt(L"Suppressed Messages",lpib->lpstrSetting,1);
EndDialog(hwnd,LOWORD(wParam));
break;
}
return true;
}
return false;
}
//=============================================================================
//
@ -2783,50 +2831,4 @@ void DialogUpdateCheck(HWND hwnd, bool bExecInstaller)
}
}
//=============================================================================
//
// InfoBox()
//
//
extern WCHAR g_wchIniFile[MAX_PATH];
INT_PTR InfoBox(int iType,LPCWSTR lpstrSetting,int uidMessage,...)
{
int iMode = IniGetInt(L"Suppressed Messages",lpstrSetting,0);
if (lstrlen(lpstrSetting) > 0 && iMode == 1)
return (iType == MBYESNO) ? IDYES : IDOK;
WCHAR wchFormat[LARGE_BUFFER];
if (!GetString(uidMessage,wchFormat,COUNTOF(wchFormat)))
return(-1);
INFOBOX ib;
ib.lpstrMessage = LocalAlloc(LPTR, HUGE_BUFFER * sizeof(WCHAR));
StringCchVPrintfW(ib.lpstrMessage,HUGE_BUFFER,wchFormat,(LPVOID)((PUINT_PTR)&uidMessage + 1));
ib.lpstrSetting = (LPWSTR)lpstrSetting;
ib.bDisableCheckBox = (StringCchLenW(g_wchIniFile,COUNTOF(g_wchIniFile)) == 0 || lstrlen(lpstrSetting) == 0 || iMode == 2) ? true : false;
int idDlg;
switch (iType) {
case MBYESNO:
idDlg = IDD_INFOBOX2;
break;
case MBOKCANCEL:
idDlg = IDD_INFOBOX3;
break;
default:
idDlg = IDD_INFOBOX;
break;
}
HWND focus = GetFocus();
HWND hwnd = focus ? focus : g_hwndMain;
MessageBeep(MB_ICONEXCLAMATION);
return ThemedDialogBoxParam(g_hInstance, MAKEINTRESOURCE(idDlg), hwnd, InfoBoxDlgProc, (LPARAM)&ib);
}
// End of Dialogs.c

View File

@ -5103,21 +5103,17 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA
g_iMarkOccurrences = iSaveMarkOcc;
g_bMarkOccurrencesMatchVisible = bSaveOccVisible;
if (g_iMarkOccurrences > 0) {
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_ONOFF, true);
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_TOGGLE_VIEW, !g_bMarkOccurrencesMatchVisible);
}
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_VISIBLE, g_bMarkOccurrencesMatchVisible);
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_ONOFF, true);
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_VISIBLE, true);
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_TOGGLE_VIEW, true);
iReplacedOccurrences = 0;
g_FindReplaceMatchFoundState = FND_NOP;
if ((g_iMarkOccurrences <= 0) || g_bMarkOccurrencesMatchVisible) {
if (EditToggleView(g_hwndEdit, false)) {
EditToggleView(g_hwndEdit, true);
EditClearAllOccurrenceMarkers(g_hwndEdit);
}
if (EditToggleView(g_hwndEdit, false)) {
EditToggleView(g_hwndEdit, true);
}
MarkAllOccurrences(50, true);
EditEnsureSelectionVisible(g_hwndEdit);
@ -5137,6 +5133,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA
}
return false;
case WM_ACTIVATE:
{
s_InitialSearchStart = SciCall_GetSelectionStart();
@ -5269,6 +5266,9 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA
_OBSERVE_NOTIFY_CHANGE_;
}
}
else {
MarkAllOccurrences(50, true);
}
}
return false;
@ -5285,23 +5285,25 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA
g_iMarkOccurrences = 0;
g_bMarkOccurrencesMatchVisible = false;
DialogEnableWindow(hwnd, IDC_TOGGLE_VISIBILITY, true);
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_ONOFF, false);
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_VISIBLE, false);
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_TOGGLE_VIEW, false);
}
else { // switched OFF
g_iMarkOccurrences = iSaveMarkOcc;
g_bMarkOccurrencesMatchVisible = bSaveOccVisible;
//DialogEnableWindow(hwnd, IDC_TOGGLE_VISIBILITY, (g_iMarkOccurrences > 0) && !g_bMarkOccurrencesMatchVisible);
DialogEnableWindow(hwnd, IDC_TOGGLE_VISIBILITY, false);
if (EditToggleView(g_hwndEdit, false)) {
EditToggleView(g_hwndEdit, true);
sg_pefrData->bStateChanged = true;
PostMessage(hwnd, WM_COMMAND, MAKELONG(IDC_TOGGLE_VISIBILITY, 1), 0);
}
DialogEnableWindow(hwnd, IDC_TOGGLE_VISIBILITY, (g_iMarkOccurrences > 0) && !g_bMarkOccurrencesMatchVisible);
EditClearAllOccurrenceMarkers(g_hwndEdit);
InvalidateRect(GetDlgItem(hwnd, IDC_FINDTEXT), NULL, true);
}
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_ONOFF, (g_iMarkOccurrences > 0));
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_VISIBLE, g_bMarkOccurrencesMatchVisible);
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_TOGGLE_VIEW, (g_iMarkOccurrences > 0) && !g_bMarkOccurrencesMatchVisible);
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_ONOFF, true);
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_MARKOCCUR_VISIBLE, true);
EnableCmd(GetMenu(g_hwndMain), IDM_VIEW_TOGGLE_VIEW, true);
}
_DelayMarkAll(hwnd, 0, s_InitialSearchStart);
}
break;
@ -5310,8 +5312,8 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA
case IDC_TOGGLE_VISIBILITY:
if (EditToggleView(g_hwndEdit, false)) {
EditToggleView(g_hwndEdit, true);
EditClearAllOccurrenceMarkers(g_hwndEdit);
sg_pefrData->bStateChanged = true;
EditClearAllOccurrenceMarkers(g_hwndEdit);
_DelayMarkAll(hwnd, 0, s_InitialSearchStart);
}
else {
@ -5855,16 +5857,17 @@ bool EditFindPrev(HWND hwnd, LPCEDITFINDREPLACE lpefr, bool bExtendSelection, bo
//
void EditMarkAllOccurrences(HWND hwnd, bool bForceClear)
{
if (g_iMarkOccurrences <= 0) {
g_iMarkOccurrencesCount = -1;
return;
}
if (_IsInTargetTransaction()) { return; } // do not block, next event occurs for sure
if (bForceClear) {
EditClearAllOccurrenceMarkers(hwnd);
}
if (g_iMarkOccurrences <= 0) {
g_iMarkOccurrencesCount = -1;
return;
}
bool const bWaitCursor = (g_iMarkOccurrencesCount > 4000) ? true : false;
if (bWaitCursor) { BeginWaitCursor(NULL); }
_IGNORE_NOTIFY_CHANGE_;