https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f7f2ed201a2522ce25586…
commit f7f2ed201a2522ce255864f2f9f7ebdc0fda6000
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Mon Feb 20 21:59:16 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Mon Feb 20 21:59:16 2023 +0900
[NOTEPAD] Make "UTF-8 without BOM" default (#5081)
- Define a constant ENCODING_DEFAULT that is equal to ENCODING_UTF8.
- Initialize Globals.encFile as ENCODING_DEFAULT.
- Reset encoding and line ending in DIALOG_FileNew.
- AnalyzeEncoding returns ENCODING_DEFAULT for non-zero ASCII text.
- Remove unnecessary DIALOG_StatusBarAlignParts calls.
CORE-18837
---
base/applications/notepad/dialog.c | 25 ++++++++++++-------------
base/applications/notepad/main.c | 1 +
base/applications/notepad/main.h | 3 +--
base/applications/notepad/text.c | 22 +++++++++++-----------
4 files changed, 25 insertions(+), 26 deletions(-)
diff --git a/base/applications/notepad/dialog.c b/base/applications/notepad/dialog.c
index 0b76b4711fd..12424dd30a9 100644
--- a/base/applications/notepad/dialog.c
+++ b/base/applications/notepad/dialog.c
@@ -167,7 +167,6 @@ static VOID DIALOG_StatusBarUpdateEncoding(VOID)
static VOID DIALOG_StatusBarUpdateAll(VOID)
{
- DIALOG_StatusBarAlignParts();
DIALOG_StatusBarUpdateCaretPos();
DIALOG_StatusBarUpdateLineEndings();
DIALOG_StatusBarUpdateEncoding();
@@ -405,8 +404,6 @@ BOOL DoCloseFile(VOID)
break;
case IDCANCEL:
- return FALSE;
-
default:
return FALSE;
}
@@ -463,24 +460,26 @@ VOID DoOpenFile(LPCTSTR szFileName)
SetFileName(szFileName);
UpdateWindowCaption(TRUE);
NOTEPAD_EnableSearchMenu();
+ DIALOG_StatusBarUpdateAll();
done:
if (hFile != INVALID_HANDLE_VALUE)
CloseHandle(hFile);
-
- DIALOG_StatusBarUpdateAll();
}
VOID DIALOG_FileNew(VOID)
{
/* Close any files and prompt to save changes */
- if (DoCloseFile()) {
- SetWindowText(Globals.hEdit, empty_str);
- SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
- SetFocus(Globals.hEdit);
- NOTEPAD_EnableSearchMenu();
- DIALOG_StatusBarUpdateAll();
- }
+ if (!DoCloseFile())
+ return;
+
+ SetWindowText(Globals.hEdit, NULL);
+ SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
+ Globals.iEoln = EOLN_CRLF;
+ Globals.encFile = ENCODING_DEFAULT;
+
+ NOTEPAD_EnableSearchMenu();
+ DIALOG_StatusBarUpdateAll();
}
VOID DIALOG_FileNewWindow(VOID)
@@ -930,7 +929,7 @@ VOID DoShowHideStatusBar(VOID)
}
/* Update layout of controls */
- PostMessageW(Globals.hMainWnd, WM_SIZE, 0, 0);
+ SendMessageW(Globals.hMainWnd, WM_SIZE, 0, 0);
if (Globals.hStatusBar == NULL)
return;
diff --git a/base/applications/notepad/main.c b/base/applications/notepad/main.c
index 2768d87fa8d..f99fb40621a 100644
--- a/base/applications/notepad/main.c
+++ b/base/applications/notepad/main.c
@@ -580,6 +580,7 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE prev, LPTSTR
cmdline, int sh
ZeroMemory(&Globals, sizeof(Globals));
Globals.hInstance = hInstance;
+ Globals.encFile = ENCODING_DEFAULT;
NOTEPAD_LoadSettingsFromRegistry();
ZeroMemory(&wndclass, sizeof(wndclass));
diff --git a/base/applications/notepad/main.h b/base/applications/notepad/main.h
index e2140c2b52b..34d7e542670 100644
--- a/base/applications/notepad/main.h
+++ b/base/applications/notepad/main.h
@@ -44,8 +44,7 @@ typedef enum
ENCODING_UTF8BOM = 4
} ENCODING;
-// #define MIN_ENCODING 0
-// #define MAX_ENCODING 3
+#define ENCODING_DEFAULT ENCODING_UTF8 // ENCODING_ANSI
typedef enum
{
diff --git a/base/applications/notepad/text.c b/base/applications/notepad/text.c
index 7f0511229a1..8b8de3c9c1a 100644
--- a/base/applications/notepad/text.c
+++ b/base/applications/notepad/text.c
@@ -24,25 +24,25 @@
#include "notepad.h"
#include <assert.h>
-BOOL IsTextNonZeroASCII(const void *pText, DWORD dwSize)
+static BOOL IsTextNonZeroASCII(LPCVOID pText, DWORD dwSize)
{
- const signed char *pBytes = pText;
+ const signed char *pch = pText;
while (dwSize-- > 0)
{
- if (*pBytes <= 0)
+ if (*pch <= 0)
return FALSE;
- ++pBytes;
+ ++pch;
}
return TRUE;
}
-ENCODING AnalyzeEncoding(const char *pBytes, DWORD dwSize)
+static ENCODING AnalyzeEncoding(const BYTE *pBytes, DWORD dwSize)
{
INT flags = IS_TEXT_UNICODE_STATISTICS | IS_TEXT_UNICODE_REVERSE_STATISTICS;
- if (dwSize <= 1 || IsTextNonZeroASCII(pBytes, dwSize))
- return ENCODING_ANSI;
+ if (IsTextNonZeroASCII(pBytes, dwSize))
+ return ENCODING_DEFAULT;
if (IsTextUnicode(pBytes, dwSize, &flags))
return ENCODING_UTF16LE;
@@ -51,7 +51,7 @@ ENCODING AnalyzeEncoding(const char *pBytes, DWORD dwSize)
return ENCODING_UTF16BE;
/* is it UTF-8? */
- if (MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, pBytes, dwSize, NULL, 0))
+ if (MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, (LPCSTR)pBytes, dwSize, NULL,
0))
return ENCODING_UTF8;
return ENCODING_ANSI;
@@ -170,7 +170,7 @@ ReadText(HANDLE hFile, HLOCAL *phLocal, ENCODING *pencFile, EOLN
*piEoln)
DWORD dwSize, dwPos;
SIZE_T i, cchText, cbContent;
BOOL bSuccess = FALSE;
- ENCODING encFile = ENCODING_ANSI;
+ ENCODING encFile;
UINT iCodePage;
HANDLE hMapping = INVALID_HANDLE_VALUE;
HLOCAL hNewLocal;
@@ -191,7 +191,7 @@ ReadText(HANDLE hFile, HLOCAL *phLocal, ENCODING *pencFile, EOLN
*piEoln)
*phLocal = hNewLocal;
*piEoln = EOLN_CRLF;
- *pencFile = ENCODING_UTF8;
+ *pencFile = ENCODING_DEFAULT;
return TRUE;
}
@@ -222,7 +222,7 @@ ReadText(HANDLE hFile, HLOCAL *phLocal, ENCODING *pencFile, EOLN
*piEoln)
}
else
{
- encFile = AnalyzeEncoding((LPCSTR)pBytes, dwSize);
+ encFile = AnalyzeEncoding(pBytes, dwSize);
}
switch(encFile)