From 403e26da1ba75e97304d5b7d92de3d9716645121 Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Sat, 1 Oct 2005 00:36:17 +0000 Subject: [PATCH] Notepad: 1. Fixed bug in Goto line command 2. Wrap long lines setting is persisted in the registry 3. Fixed length limit bug when wrap long lines is toggled svn path=/trunk/; revision=18182 --- reactos/subsys/system/notepad/dialog.c | 9 ++++----- reactos/subsys/system/notepad/main.c | 5 ++++- reactos/subsys/system/notepad/main.h | 4 ++-- reactos/subsys/system/notepad/settings.c | 11 +++++++++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/reactos/subsys/system/notepad/dialog.c b/reactos/subsys/system/notepad/dialog.c index 17476aa60b9..950b41635f2 100644 --- a/reactos/subsys/system/notepad/dialog.c +++ b/reactos/subsys/system/notepad/dialog.c @@ -624,6 +624,8 @@ VOID DIALOG_EditWrap(VOID) DWORD size; LPWSTR pTemp; + Globals.bWrapLongLines = !Globals.bWrapLongLines; + size = GetWindowTextLength(Globals.hEdit) + 1; pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR)); if (!pTemp) @@ -639,13 +641,10 @@ VOID DIALOG_EditWrap(VOID) 0, 0, rc.right, rc.bottom, Globals.hMainWnd, NULL, Globals.hInstance, NULL); SendMessage(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)FALSE); + SendMessage(Globals.hEdit, EM_LIMITTEXT, 0, 0); SetWindowTextW(Globals.hEdit, pTemp); SetFocus(Globals.hEdit); HeapFree(GetProcessHeap(), 0, pTemp); - - Globals.bWrapLongLines = !Globals.bWrapLongLines; - CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP, - MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED)); } VOID DIALOG_SelectFont(VOID) @@ -770,7 +769,7 @@ VOID DIALOG_GoTo(VOID) if (nLine >= 1) { - for (i = 0; pszText[i] && (nLine > 1) && (i < dwStart - 1); i++) + for (i = 0; pszText[i] && (nLine > 1) && (i < nLength - 1); i++) { if (pszText[i] == '\n') nLine--; diff --git a/reactos/subsys/system/notepad/main.c b/reactos/subsys/system/notepad/main.c index 2605b97f901..4e47566b59e 100644 --- a/reactos/subsys/system/notepad/main.c +++ b/reactos/subsys/system/notepad/main.c @@ -258,6 +258,9 @@ static VOID NOTEPAD_InitMenuPopup(HMENU menu, int index) { int enable; + CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP, + MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED)); + EnableMenuItem(menu, CMD_UNDO, SendMessage(Globals.hEdit, EM_CANUNDO, 0, 0) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(menu, CMD_PASTE, @@ -286,7 +289,7 @@ static LRESULT WINAPI NOTEPAD_WndProc(HWND hWnd, UINT msg, WPARAM wParam, static const WCHAR editW[] = { 'e','d','i','t',0 }; RECT rc; GetClientRect(hWnd, &rc); - Globals.hEdit = CreateWindowEx(EDIT_EXSTYLE, editW, NULL, EDIT_STYLE, + Globals.hEdit = CreateWindowEx(EDIT_EXSTYLE, editW, NULL, Globals.bWrapLongLines ? EDIT_STYLE_WRAP : EDIT_STYLE, 0, 0, rc.right, rc.bottom, hWnd, NULL, Globals.hInstance, NULL); if (!Globals.hEdit) diff --git a/reactos/subsys/system/notepad/main.h b/reactos/subsys/system/notepad/main.h index 7e0c59b26b5..60bdee1fbe5 100644 --- a/reactos/subsys/system/notepad/main.h +++ b/reactos/subsys/system/notepad/main.h @@ -23,9 +23,9 @@ #include "notepad_res.h" -#define EDIT_STYLE (WS_CHILD | WS_VISIBLE | WS_VSCROLL \ +#define EDIT_STYLE_WRAP (WS_CHILD | WS_VISIBLE | WS_VSCROLL \ | ES_AUTOVSCROLL | ES_MULTILINE | ES_NOHIDESEL) -#define EDIT_STYLE_WRAP (EDIT_STYLE | WS_HSCROLL | ES_AUTOHSCROLL) +#define EDIT_STYLE (EDIT_STYLE_WRAP | WS_HSCROLL | ES_AUTOHSCROLL) #define EDIT_EXSTYLE (WS_EX_CLIENTEDGE) #define MAX_STRING_LEN 255 diff --git a/reactos/subsys/system/notepad/settings.c b/reactos/subsys/system/notepad/settings.c index c54f72ef49c..d05e2bfaf24 100644 --- a/reactos/subsys/system/notepad/settings.c +++ b/reactos/subsys/system/notepad/settings.c @@ -117,6 +117,15 @@ static BOOL QueryByte(HKEY hKey, LPCSTR pszValueName, BYTE *pbResult) return TRUE; } +static BOOL QueryBool(HKEY hKey, LPCSTR pszValueName, BOOL *pbResult) +{ + DWORD dwResult; + if (!QueryDword(hKey, pszValueName, &dwResult)) + return FALSE; + *pbResult = dwResult ? TRUE : FALSE; + return TRUE; +} + static BOOL QueryString(HKEY hKey, LPCSTR pszValueName, LPTSTR pszResult, DWORD dwResultSize) { return QueryGeneric(hKey, pszValueName, REG_SZ, pszResult, dwResultSize * sizeof(*pszResult)); @@ -143,6 +152,7 @@ void LoadSettings(void) QueryByte(hKey, "lfUnderline", &Globals.lfFont.lfUnderline); QueryDword(hKey, "lfWeight", (DWORD*)&Globals.lfFont.lfWeight); QueryDword(hKey, "iPointSize", &dwPointSize); + QueryBool(hKey, "fWrap", &Globals.bWrapLongLines); if (dwPointSize != 0) Globals.lfFont.lfHeight = HeightFromPointSize(dwPointSize); @@ -210,6 +220,7 @@ void SaveSettings(void) SaveDword(hKey, "lfUnderline", Globals.lfFont.lfUnderline); SaveDword(hKey, "lfWeight", Globals.lfFont.lfWeight); SaveDword(hKey, "iPointSize", PointSizeFromHeight(Globals.lfFont.lfHeight)); + SaveDword(hKey, "fWrap", Globals.bWrapLongLines ? 1 : 0); RegCloseKey(hKey); }