https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0ef9cfb04e819a88bf4d5721cce0800193824e02
commit 0ef9cfb04e819a88bf4d5721cce0800193824e02 Author: Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com> AuthorDate: Sun Sep 10 22:27:16 2023 +0900 Commit: GitHub <nore...@github.com> CommitDate: Sun Sep 10 22:27:16 2023 +0900 [NOTEPAD] Use wait cursor (#5659) - Add WaitCursor helper function to display the wait cursor while heavy operation. - Manage the wait cursor by using a lock count. CORE-18837 --- base/applications/notepad/dialog.c | 43 ++++++++++++++++++++++++++++++++++++++ base/applications/notepad/dialog.h | 1 + base/applications/notepad/main.c | 6 +++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/base/applications/notepad/dialog.c b/base/applications/notepad/dialog.c index 111d0428a1d..82c6c5c57bc 100644 --- a/base/applications/notepad/dialog.c +++ b/base/applications/notepad/dialog.c @@ -111,6 +111,33 @@ void UpdateWindowCaption(BOOL clearModifyAlert) SetWindowText(Globals.hMainWnd, szCaption); } +VOID WaitCursor(BOOL bBegin) +{ + static HCURSOR s_hWaitCursor = NULL; + static HCURSOR s_hOldCursor = NULL; + static INT s_nLock = 0; + + if (bBegin) + { + if (s_nLock++ == 0) + { + if (s_hWaitCursor == NULL) + s_hWaitCursor = LoadCursor(NULL, IDC_WAIT); + s_hOldCursor = SetCursor(s_hWaitCursor); + } + else + { + SetCursor(s_hWaitCursor); + } + } + else + { + if (--s_nLock == 0) + SetCursor(s_hOldCursor); + } +} + + VOID DIALOG_StatusBarAlignParts(VOID) { static const int defaultWidths[] = {120, 120, 120}; @@ -220,11 +247,14 @@ static BOOL DoSaveFile(VOID) HANDLE hFile; DWORD cchText; + WaitCursor(TRUE); + hFile = CreateFileW(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { ShowLastError(); + WaitCursor(FALSE); return FALSE; } @@ -259,6 +289,7 @@ static BOOL DoSaveFile(VOID) SetFileName(Globals.szFileName); } + WaitCursor(FALSE); return bRet; } @@ -307,6 +338,8 @@ VOID DoOpenFile(LPCTSTR szFileName) if (!DoCloseFile()) return; + WaitCursor(TRUE); + hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) @@ -347,6 +380,7 @@ VOID DoOpenFile(LPCTSTR szFileName) done: if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); + WaitCursor(FALSE); } VOID DIALOG_FileNew(VOID) @@ -355,6 +389,8 @@ VOID DIALOG_FileNew(VOID) if (!DoCloseFile()) return; + WaitCursor(TRUE); + SetWindowText(Globals.hEdit, NULL); SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0); Globals.iEoln = EOLN_CRLF; @@ -362,13 +398,20 @@ VOID DIALOG_FileNew(VOID) NOTEPAD_EnableSearchMenu(); DIALOG_StatusBarUpdateAll(); + + WaitCursor(FALSE); } VOID DIALOG_FileNewWindow(VOID) { TCHAR pszNotepadExe[MAX_PATH]; + + WaitCursor(TRUE); + GetModuleFileName(NULL, pszNotepadExe, _countof(pszNotepadExe)); ShellExecute(NULL, NULL, pszNotepadExe, NULL, NULL, SW_SHOWNORMAL); + + WaitCursor(FALSE); } VOID DIALOG_FileOpen(VOID) diff --git a/base/applications/notepad/dialog.h b/base/applications/notepad/dialog.h index c9681df92f0..7b62a58063a 100644 --- a/base/applications/notepad/dialog.h +++ b/base/applications/notepad/dialog.h @@ -57,3 +57,4 @@ VOID DoOpenFile(LPCTSTR szFileName); VOID DoShowHideStatusBar(VOID); VOID DoCreateEditWindow(VOID); void UpdateWindowCaption(BOOL clearModifyAlert); +VOID WaitCursor(BOOL bBegin); diff --git a/base/applications/notepad/main.c b/base/applications/notepad/main.c index 599ad5c60df..77100a2e26a 100644 --- a/base/applications/notepad/main.c +++ b/base/applications/notepad/main.c @@ -433,6 +433,8 @@ NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) FINDREPLACE *pFindReplace = (FINDREPLACE *) lParam; Globals.find = *(FINDREPLACE *) lParam; + WaitCursor(TRUE); + if (pFindReplace->Flags & FR_FINDNEXT) NOTEPAD_FindNext(pFindReplace, FALSE, TRUE); else if (pFindReplace->Flags & FR_REPLACE) @@ -441,6 +443,8 @@ NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) NOTEPAD_ReplaceAll(pFindReplace); else if (pFindReplace->Flags & FR_DIALOGTERM) NOTEPAD_FindTerm(); + + WaitCursor(FALSE); break; } @@ -587,7 +591,7 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR cmdline, int sh wndclass.lpfnWndProc = NOTEPAD_WndProc; wndclass.hInstance = Globals.hInstance; wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NPICON)); - wndclass.hCursor = LoadCursor(0, IDC_ARROW); + wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wndclass.lpszMenuName = MAKEINTRESOURCE(MAIN_MENU); wndclass.lpszClassName = className;