From: Jacob Czekalla jacobczekalla@gmail.com
--- programs/notepad/dialog.c | 2 ++ programs/notepad/main.c | 58 ++++++++++++++++++++++++++++++++++ programs/notepad/main.h | 6 ++++ programs/notepad/notepad.rc | 2 ++ programs/notepad/notepad_res.h | 2 ++ 5 files changed, 70 insertions(+)
diff --git a/programs/notepad/dialog.c b/programs/notepad/dialog.c index 2227a08cec7..7091d8f995a 100644 --- a/programs/notepad/dialog.c +++ b/programs/notepad/dialog.c @@ -27,6 +27,7 @@ #include <windows.h> #include <shellapi.h> #include <commdlg.h> +#include <commctrl.h> #include <shlwapi.h> #include <winternl.h>
@@ -1107,6 +1108,7 @@ VOID DIALOG_EditWrap(VOID) Globals.bWrapLongLines = !Globals.bWrapLongLines; CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP, MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED)); + SetWindowSubclass(Globals.hEdit, (SUBCLASSPROC)EDIT_CallBackProc, 0, 0); updateWindowSize(rc.right, rc.bottom); }
diff --git a/programs/notepad/main.c b/programs/notepad/main.c index 3d266a322e8..8939b029b4b 100644 --- a/programs/notepad/main.c +++ b/programs/notepad/main.c @@ -108,6 +108,33 @@ DWORD get_dpi(void) return dpi; }
+void UpdateStatusBar(void) +{ + int currentLine; + int currentCol = -1; + WCHAR statusTxt[256]; + int lineIndex; + DWORD selStart; + DWORD selEnd; + + SendMessageW(Globals.hEdit, EM_GETSEL, (WPARAM)&selStart, (LPARAM)&selEnd); + if(selStart == selEnd) + Globals.trackedSel = selStart; + if(selStart < Globals.trackedSel) + currentCol = selStart; + else + currentCol = selEnd; + currentLine = SendMessageW(Globals.hEdit, EM_LINEFROMCHAR, currentCol, 0); + lineIndex = SendMessageW(Globals.hEdit, EM_LINEINDEX, currentLine, 0); + if(Globals.lastLn != currentLine || Globals.lastCol != currentCol) + { + swprintf(statusTxt, ARRAY_SIZE(statusTxt), Globals.szStatusString, currentLine + 1, (currentCol - lineIndex) + 1); + SendMessageW(Globals.hStatusBar, SB_SETTEXTW, 0, (LPARAM)statusTxt); + Globals.lastLn = currentLine; + Globals.lastCol = currentCol; + } +} + static void ToggleStatusBar(void) { RECT rc; @@ -118,6 +145,7 @@ static void ToggleStatusBar(void) GetClientRect(Globals.hMainWnd, &rc); ShowWindow(Globals.hStatusBar, Globals.bStatusBar); updateWindowSize(rc.right, rc.bottom); + UpdateStatusBar(); }
void updateWindowSize(int width, int height) @@ -528,6 +556,31 @@ static void NOTEPAD_DoReplaceAll(FINDREPLACEW *fr) } }
+LRESULT CALLBACK EDIT_CallBackProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, + UINT_PTR uIdSubclass, DWORD_PTR dwRefData) +{ + switch (msg) + { + case WM_KEYDOWN: + case WM_KEYUP: + case WM_MBUTTONDOWN: + case WM_MBUTTONUP: + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + UpdateStatusBar(); + break; + case WM_MOUSEMOVE: + if(wParam == MK_LBUTTON) + UpdateStatusBar(); + break; + + default: + break; + } + return DefSubclassProc(hWnd, msg, wParam, lParam); +} + + /*********************************************************************** * * NOTEPAD_WndProc @@ -575,12 +628,17 @@ static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam, dwStyle, 0, 0, rc.right, rc.bottom, hWnd, NULL, Globals.hInstance, NULL);
+ SetWindowSubclass(Globals.hEdit, (SUBCLASSPROC)EDIT_CallBackProc, 0, 0); Globals.hFont = CreateFontIndirectW(&Globals.lfFont); SendMessageW(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, FALSE); SendMessageW(Globals.hEdit, EM_LIMITTEXT, 0, 0); Globals.hStatusBar = CreateWindowExW(0, STATUSCLASSNAMEW, NULL, WS_VISIBLE | WS_CHILD, 0, 0, 0, 0, hWnd, NULL, Globals.hInstance, NULL); + LoadStringW(Globals.hInstance, STRING_STATUSBAR, (LPWSTR)&Globals.szStatusString, 0); + Globals.lastLn = -1; + Globals.lastCol = -1; + UpdateStatusBar(); break; }
diff --git a/programs/notepad/main.h b/programs/notepad/main.h index 7f417789001..7d25ee967e8 100644 --- a/programs/notepad/main.h +++ b/programs/notepad/main.h @@ -45,6 +45,7 @@ typedef struct HFONT hFont; /* Font used by the edit control */ HWND hStatusBar; INT bStatusBar; + WCHAR* szStatusString; LOGFONTW lfFont; BOOL bWrapLongLines; WCHAR szFindText[MAX_PATH]; @@ -61,6 +62,9 @@ typedef struct INT iMarginRight; WCHAR szHeader[MAX_PATH]; WCHAR szFooter[MAX_PATH]; + INT trackedSel; + INT lastLn; + INT lastCol;
FINDREPLACEW find; FINDREPLACEW lastFind; @@ -73,4 +77,6 @@ extern NOTEPAD_GLOBALS Globals; VOID SetFileNameAndEncoding(LPCWSTR szFileName, ENCODING enc); void NOTEPAD_DoFind(FINDREPLACEW *fr); DWORD get_dpi(void); +void UpdateStatusBar(void); void updateWindowSize(int width, int height); +LRESULT CALLBACK EDIT_CallBackProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData); diff --git a/programs/notepad/notepad.rc b/programs/notepad/notepad.rc index 60cd03d9c0e..7371dba46f5 100644 --- a/programs/notepad/notepad.rc +++ b/programs/notepad/notepad.rc @@ -85,6 +85,8 @@ STRING_NOTSAVED, "File '%s' has been modified.\n\ Would you like to save the changes?" STRING_NOTFOUND, "'%s' could not be found."
+STRING_STATUSBAR, "Ln %ld, Col %ld" + STRING_UNICODE_LE, "Unicode (UTF-16)" STRING_UNICODE_BE, "Unicode (UTF-16 big-endian)" STRING_UTF8, "Unicode (UTF-8)" diff --git a/programs/notepad/notepad_res.h b/programs/notepad/notepad_res.h index bd994d9eede..416d6d775fd 100644 --- a/programs/notepad/notepad_res.h +++ b/programs/notepad/notepad_res.h @@ -79,6 +79,8 @@
#define STRING_NOTFOUND 0x17B
+#define STRING_STATUSBAR 0x206 + #define STRING_UNICODE_LE 0x180 #define STRING_UNICODE_BE 0x181 #define STRING_UTF8 0x182