mirror of
https://github.com/rizonesoft/Notepad3.git
synced 2026-06-14 21:09:05 +08:00
Refactoring/Fixes:
- standard encoding is ANSI, (resp. UTF8 - if no(-1) encoding default is given in .ini-file: DefaultEncoding=n) - copy/paste non ANSI characters to ANSI encoded NP3 windo will recode them to ANSI (same as manually recode)
This commit is contained in:
parent
854f0a7cec
commit
67ff6f274e
34
src/Edit.c
34
src/Edit.c
@ -79,7 +79,7 @@ NP2ENCODING mEncoding[] = {
|
||||
{ NCP_UNICODE|NCP_UNICODE_REVERSE|NCP_UNICODE_BOM, 0, "", 61003, L"" },
|
||||
{ NCP_UNICODE|NCP_RECODE, 0, "utf-16,utf16,unicode,", 61004, L"" },
|
||||
{ NCP_UNICODE|NCP_UNICODE_REVERSE|NCP_RECODE, 0, "utf-16be,utf16be,unicodebe,", 61005, L"" },
|
||||
{ NCP_UTF8|NCP_RECODE, 0, "utf-8,utf8,", 61006, L"" },
|
||||
{ NCP_UTF8|NCP_RECODE, CP_UTF8, "utf-8,utf8,", 61006, L"" },
|
||||
{ NCP_UTF8|NCP_UTF8_SIGN, 0, "utf-8,utf8,", 61007, L"" },
|
||||
{ NCP_8BIT|NCP_RECODE, CP_UTF7, "utf-7,utf7,", 61008, L"" },
|
||||
{ NCP_8BIT|NCP_RECODE, 720, "DOS-720,dos720,", 61009, L"" },
|
||||
@ -350,8 +350,12 @@ BOOL EditConvertText(HWND hwnd,UINT cpSource,UINT cpDest,BOOL bSetSavePoint)
|
||||
SendMessage(hwnd,SCI_GETTEXTRANGE,0,(LPARAM)&tr);
|
||||
|
||||
pwchText = GlobalAlloc(GPTR,length*3+2);
|
||||
cbwText = MultiByteToWideChar(cpSource,0,pchText,length,pwchText,length*3+2);
|
||||
cbText = WideCharToMultiByte(cpDest,0,pwchText,cbwText,pchText,length*5+2,NULL,NULL);
|
||||
|
||||
UINT _cpSrc = (cpSource == CPI_ANSI) ? CP_ACP : ((cpSource == CPI_OEM) ? CP_OEMCP : CP_UTF8);
|
||||
UINT _cpDst = (cpDest == CPI_ANSI) ? CP_ACP : ((cpDest == CPI_OEM) ? CP_OEMCP : CP_UTF8);
|
||||
|
||||
cbwText = MultiByteToWideChar(_cpSrc,0,pchText,length,pwchText,length*3+2);
|
||||
cbText = WideCharToMultiByte(_cpDst,0,pwchText,cbwText,pchText,length*5+2,NULL,NULL);
|
||||
|
||||
SendMessage(hwnd,SCI_CANCEL,0,0);
|
||||
SendMessage(hwnd,SCI_SETUNDOCOLLECTION,0,0);
|
||||
@ -380,14 +384,14 @@ BOOL EditSetNewEncoding(HWND hwnd,int iCurrentEncoding,int iNewEncoding,BOOL bNo
|
||||
|
||||
if (iCurrentEncoding != iNewEncoding) {
|
||||
|
||||
if (iCurrentEncoding != CPI_DEFAULT && iNewEncoding != CPI_DEFAULT)
|
||||
if (iCurrentEncoding != CPI_ANSI && iNewEncoding != CPI_ANSI)
|
||||
return(TRUE);
|
||||
|
||||
if (SendMessage(hwnd,SCI_GETLENGTH,0,0) == 0) {
|
||||
|
||||
BOOL bIsEmptyUndoHistory = (SendMessage(hwnd,SCI_CANUNDO,0,0) == 0 && SendMessage(hwnd,SCI_CANREDO,0,0) == 0);
|
||||
|
||||
if ((iCurrentEncoding == CPI_DEFAULT || iNewEncoding == CPI_DEFAULT) &&
|
||||
if ((iCurrentEncoding == CPI_ANSI || iNewEncoding == CPI_ANSI) &&
|
||||
(bNoUI || bIsEmptyUndoHistory || InfoBox(MBYESNO,L"MsgConv2",IDS_ASK_ENCODING2) == IDYES)) {
|
||||
|
||||
EditConvertText(hwnd,
|
||||
@ -402,7 +406,7 @@ BOOL EditSetNewEncoding(HWND hwnd,int iCurrentEncoding,int iNewEncoding,BOOL bNo
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
else if ((iCurrentEncoding == CPI_DEFAULT || iNewEncoding == CPI_DEFAULT) &&
|
||||
else if ((iCurrentEncoding == CPI_ANSI || iNewEncoding == CPI_ANSI) &&
|
||||
(bNoUI || InfoBox(MBYESNO,L"MsgConv1",IDS_ASK_ENCODING) == IDYES)) {
|
||||
|
||||
BeginWaitCursor();
|
||||
@ -640,7 +644,7 @@ void Encoding_InitDefaults() {
|
||||
int Encoding_MapIniSetting(BOOL bLoad,int iSetting) {
|
||||
if (bLoad) {
|
||||
switch (iSetting) {
|
||||
case 0: return CPI_DEFAULT;
|
||||
case 0: return CPI_ANSI;
|
||||
case 1: return CPI_UNICODEBOM;
|
||||
case 2: return CPI_UNICODEBEBOM;
|
||||
case 3: return CPI_UTF8;
|
||||
@ -655,13 +659,13 @@ int Encoding_MapIniSetting(BOOL bLoad,int iSetting) {
|
||||
if ((mEncoding[i].uCodePage == (UINT)iSetting) && Encoding_IsValid(i))
|
||||
return(i);
|
||||
}
|
||||
return CPI_DEFAULT;
|
||||
return CPI_ANSI;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch (iSetting) {
|
||||
case CPI_DEFAULT: return 0;
|
||||
case CPI_ANSI: return 0;
|
||||
case CPI_UNICODEBOM: return 1;
|
||||
case CPI_UNICODEBEBOM: return 2;
|
||||
case CPI_UTF8: return 3;
|
||||
@ -787,7 +791,7 @@ void Encoding_AddToListView(HWND hwnd,int idSel,BOOL bRecodeOnly)
|
||||
else
|
||||
StrCpyN(wchBuf,pEE[i].wch,COUNTOF(wchBuf));
|
||||
|
||||
if (id == CPI_DEFAULT)
|
||||
if (id == CPI_ANSI)
|
||||
StrCatN(wchBuf,wchANSI,COUNTOF(wchBuf));
|
||||
else if (id == CPI_OEM)
|
||||
StrCatN(wchBuf,wchOEM,COUNTOF(wchBuf));
|
||||
@ -879,7 +883,7 @@ void Encoding_AddToComboboxEx(HWND hwnd,int idSel,BOOL bRecodeOnly)
|
||||
else
|
||||
StrCpyN(wchBuf,pEE[i].wch,COUNTOF(wchBuf));
|
||||
|
||||
if (id == CPI_DEFAULT)
|
||||
if (id == CPI_ANSI)
|
||||
StrCatN(wchBuf,wchANSI,COUNTOF(wchBuf));
|
||||
else if (id == CPI_OEM)
|
||||
StrCatN(wchBuf,wchOEM,COUNTOF(wchBuf));
|
||||
@ -1250,13 +1254,13 @@ BOOL EditLoadFile(
|
||||
}
|
||||
|
||||
if (!Encoding_IsValid(iDefaultEncoding))
|
||||
iDefaultEncoding = CPI_DEFAULT;
|
||||
iDefaultEncoding = CPI_ANSI;
|
||||
|
||||
_iDefaultEncoding = (bPreferOEM) ? g_DOSEncoding : iDefaultEncoding;
|
||||
if (iWeakSrcEncoding != -1 && Encoding_IsValid(iWeakSrcEncoding))
|
||||
_iDefaultEncoding = iWeakSrcEncoding;
|
||||
|
||||
*iEncoding = CPI_DEFAULT;
|
||||
*iEncoding = CPI_ANSI;
|
||||
|
||||
if (cbData == 0) {
|
||||
FileVars_Init(NULL,0,&fvCurFile);
|
||||
@ -1362,7 +1366,7 @@ BOOL EditLoadFile(
|
||||
*iEncoding = FileVars_GetEncoding(&fvCurFile);
|
||||
if (*iEncoding == -1) {
|
||||
if (fvCurFile.mask & FV_ENCODING)
|
||||
*iEncoding = CPI_DEFAULT;
|
||||
*iEncoding = CPI_ANSI;
|
||||
else {
|
||||
if (iWeakSrcEncoding == -1)
|
||||
*iEncoding = _iDefaultEncoding;
|
||||
@ -1401,7 +1405,7 @@ BOOL EditLoadFile(
|
||||
SendMessage(hwnd,SCI_SETCODEPAGE,iDefaultCodePage,0);
|
||||
EditSetNewText(hwnd,"",0);
|
||||
EditSetNewText(hwnd,lpData,cbData);
|
||||
*iEncoding = CPI_DEFAULT;
|
||||
*iEncoding = CPI_ANSI;
|
||||
*iEOLMode = EditDetectEOLMode(hwnd,lpData,cbData);
|
||||
GlobalFree(lpData);
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ extern int g_DOSEncoding;
|
||||
#define NCP_INTERNAL (NCP_DEFAULT|NCP_UTF8|NCP_UTF8_SIGN|NCP_UNICODE|NCP_UNICODE_REVERSE|NCP_UNICODE_BOM)
|
||||
#define NCP_RECODE 128
|
||||
#define CPI_NONE -1
|
||||
#define CPI_DEFAULT 0
|
||||
#define CPI_ANSI 0
|
||||
#define CPI_OEM 1
|
||||
#define CPI_UNICODEBOM 2
|
||||
#define CPI_UNICODEBEBOM 3
|
||||
|
||||
@ -919,7 +919,7 @@ HWND InitInstance(HINSTANCE hInstance,LPSTR pszCmdLine,int nCmdShow)
|
||||
if (iSrcEncoding != -1) {
|
||||
iEncoding = iSrcEncoding;
|
||||
iOriginalEncoding = iSrcEncoding;
|
||||
SendMessage(hwndEdit,SCI_SETCODEPAGE,(iEncoding == CPI_DEFAULT) ? iDefaultCodePage : SC_CP_UTF8,0);
|
||||
SendMessage(hwndEdit,SCI_SETCODEPAGE,(iEncoding == CPI_ANSI) ? iDefaultCodePage : SC_CP_UTF8,0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2747,7 +2747,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
||||
case IDM_ENCODING_UNICODEREV: iNewEncoding = CPI_UNICODEBEBOM; break;
|
||||
case IDM_ENCODING_UTF8: iNewEncoding = CPI_UTF8; break;
|
||||
case IDM_ENCODING_UTF8SIGN: iNewEncoding = CPI_UTF8SIGN; break;
|
||||
case IDM_ENCODING_ANSI: iNewEncoding = CPI_DEFAULT; break;
|
||||
case IDM_ENCODING_ANSI: iNewEncoding = CPI_ANSI; break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2760,7 +2760,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
||||
iOriginalEncoding = iNewEncoding;
|
||||
}
|
||||
else {
|
||||
if (iEncoding == CPI_DEFAULT || iNewEncoding == CPI_DEFAULT)
|
||||
if (iEncoding == CPI_ANSI || iNewEncoding == CPI_ANSI)
|
||||
iOriginalEncoding = -1;
|
||||
iEncoding = iNewEncoding;
|
||||
}
|
||||
@ -2782,8 +2782,8 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
||||
|
||||
WCHAR tchCurFile2[MAX_PATH];
|
||||
|
||||
int iNewEncoding = -1;
|
||||
if (iEncoding != CPI_DEFAULT)
|
||||
int iNewEncoding = CPI_NONE;
|
||||
if (iEncoding != CPI_ANSI)
|
||||
iNewEncoding = iEncoding;
|
||||
if (iEncoding == CPI_UTF8SIGN)
|
||||
iNewEncoding = CPI_UTF8;
|
||||
@ -4503,7 +4503,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
||||
{
|
||||
WCHAR tchCurFile2[MAX_PATH];
|
||||
if (lstrlen(szCurFile)) {
|
||||
iSrcEncoding = CPI_DEFAULT;
|
||||
iSrcEncoding = CPI_ANSI;
|
||||
lstrcpy(tchCurFile2,szCurFile);
|
||||
FileLoad(FALSE,FALSE,TRUE,FALSE,tchCurFile2);
|
||||
}
|
||||
@ -5669,9 +5669,9 @@ void LoadSettings()
|
||||
bViewEOLs = IniSectionGetInt(pIniSection,L"ViewEOLs",0);
|
||||
if (bViewEOLs) bViewEOLs = 1;
|
||||
|
||||
iDefaultEncoding = IniSectionGetInt(pIniSection,L"DefaultEncoding", CPI_DEFAULT);
|
||||
iDefaultEncoding = Encoding_MapIniSetting(TRUE,iDefaultEncoding);
|
||||
if (!Encoding_IsValid(iDefaultEncoding)) iDefaultEncoding = CPI_DEFAULT;
|
||||
iDefaultEncoding = IniSectionGetInt(pIniSection,L"DefaultEncoding", CPI_NONE);
|
||||
iDefaultEncoding = (iDefaultEncoding == CPI_NONE) ? CPI_UTF8 : Encoding_MapIniSetting(TRUE, iDefaultEncoding);
|
||||
if (!Encoding_IsValid(iDefaultEncoding)) iDefaultEncoding = CPI_ANSI;
|
||||
|
||||
bSkipUnicodeDetection = IniSectionGetInt(pIniSection,L"SkipUnicodeDetection",0);
|
||||
if (bSkipUnicodeDetection) bSkipUnicodeDetection = 1;
|
||||
@ -5837,13 +5837,12 @@ void LoadSettings()
|
||||
|
||||
LocalFree(pIniSection);
|
||||
|
||||
//iDefaultCodePage = (iDefaultEncoding == CPI_DEFAULT) ? Encoding_MapIniSetting(TRUE, (int)GetACP()) : iDefaultEncoding;
|
||||
iDefaultCodePage = iDefaultEncoding;
|
||||
iDefaultCodePage = (iDefaultEncoding == CPI_ANSI) ? 0 : SC_CP_UTF8;
|
||||
{
|
||||
// check for Chinese, Japan, Korean CPs
|
||||
// check for Chinese, Japan, Korean DBCS code pages
|
||||
int acp = GetACP();
|
||||
if (acp == 932 || acp == 936 || acp == 949 || acp == 950 || acp == 1361)
|
||||
iDefaultCodePage = Encoding_MapIniSetting(TRUE, acp);
|
||||
iDefaultCodePage = acp;
|
||||
}
|
||||
|
||||
{
|
||||
@ -6928,7 +6927,7 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp
|
||||
SendMessage(hwndEdit,SCI_SETEOLMODE,iLineEndings[iDefaultEOLMode],0);
|
||||
iEncoding = iDefaultEncoding;
|
||||
iOriginalEncoding = iDefaultEncoding;
|
||||
SendMessage(hwndEdit,SCI_SETCODEPAGE,(iDefaultEncoding == CPI_DEFAULT) ? iDefaultCodePage : SC_CP_UTF8,0);
|
||||
SendMessage(hwndEdit,SCI_SETCODEPAGE,(iDefaultEncoding == CPI_ANSI) ? iDefaultCodePage : SC_CP_UTF8,0);
|
||||
EditSetNewText(hwndEdit,"",0);
|
||||
SetWindowTitle(hwndMain,uidsAppTitle,fIsElevated,IDS_UNTITLED,szCurFile,
|
||||
iPathNameFormat,bModified || iEncoding != iOriginalEncoding,
|
||||
@ -6993,7 +6992,7 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp
|
||||
iEncoding = iDefaultEncoding;
|
||||
iOriginalEncoding = iDefaultEncoding;
|
||||
}
|
||||
SendMessage(hwndEdit,SCI_SETCODEPAGE,(iEncoding == CPI_DEFAULT) ? iDefaultCodePage : SC_CP_UTF8,0);
|
||||
SendMessage(hwndEdit,SCI_SETCODEPAGE,(iEncoding == CPI_ANSI) ? iDefaultCodePage : SC_CP_UTF8,0);
|
||||
bReadOnly = FALSE;
|
||||
EditSetNewText(hwndEdit,"",0);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user