[BUG_FIXED] Fix incorrect insertion under the different codepage.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@746 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2011-04-14 00:34:47 +00:00
parent 28fa54583e
commit 6a468a8741
7 changed files with 140 additions and 28 deletions

View File

@ -1457,6 +1457,9 @@ void Notepad_plus::checkDocState()
enableConvertMenuItems(curBuf->getFormat());
checkUnicodeMenuItems(/*curBuf->getUnicodeMode()*/);
checkLangsMenu(-1);
if (_pAnsiCharPanel)
_pAnsiCharPanel->switchEncoding();
}
void Notepad_plus::checkUndoState()

View File

@ -59,27 +59,123 @@ void ListView::init(HINSTANCE hInst, HWND parent)
LVCOLUMN lvColumn;
lvColumn.mask = LVCF_TEXT|LVCF_WIDTH;
lvColumn.cx = 45;
lvColumn.cx = 45;
lvColumn.pszText = TEXT("Value");
ListView_InsertColumn(_hSelf, 0, &lvColumn);
lvColumn.pszText = TEXT("Char");
lvColumn.cx = 70;
lvColumn.pszText = TEXT("Character");
ListView_InsertColumn(_hSelf, 1, &lvColumn);
lvColumn.pszText = TEXT("Ctrl char");
lvColumn.cx = 90;
ListView_InsertColumn(_hSelf, 2, &lvColumn);
//ListView_SetImageList(_hSelf, hImaLst, LVSIL_SMALL);
//ListView_SetItemState(_hSelf, _currentIndex, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
//ListView_SetBkColor(_hSelf, lightYellow);
}
void ListView::resetValues(int codepage)
{
if (codepage == -1)
codepage = 0;
if (_codepage == codepage)
return;
ListView_DeleteAllItems(_hSelf);
setValues(codepage);
}
generic_string ListView::getAscii(unsigned char value)
{
switch (value)
{
case 0:
return TEXT("NULL");
case 1:
return TEXT("SOH");
case 2:
return TEXT("STX");
case 3:
return TEXT("ETX");
case 4:
return TEXT("EOT");
case 5:
return TEXT("ENQ");
case 6:
return TEXT("ACK");
case 7:
return TEXT("BEL");
case 8:
return TEXT("BS");
case 9:
return TEXT("TAB");
case 10:
return TEXT("LF");
case 11:
return TEXT("VT");
case 12:
return TEXT("FF");
case 13:
return TEXT("CR");
case 14:
return TEXT("SO");
case 15:
return TEXT("SI");
case 16:
return TEXT("DLE");
case 17:
return TEXT("DC1");
case 18:
return TEXT("DC2");
case 19:
return TEXT("DC3");
case 20:
return TEXT("DC4");
case 21:
return TEXT("NAK");
case 22:
return TEXT("SYN");
case 23:
return TEXT("ETB");
case 24:
return TEXT("CAN");
case 25:
return TEXT("EM");
case 26:
return TEXT("SUB");
case 27:
return TEXT("ESC");
case 28:
return TEXT("FS");
case 29:
return TEXT("GS");
case 30:
return TEXT("RS");
case 31:
return TEXT("US");
case 32:
return TEXT("Space");
case 127:
return TEXT("DEL");
default:
{
TCHAR charStr[10];
#ifdef UNICODE
char ascii[2];
ascii[0] = value;
ascii[1] = '\0';
MultiByteToWideChar(_codepage, 0, ascii, -1, charStr, sizeof(charStr));
#else
charStr[0] = (unsigned char)i;
charStr[1] = '\0';
#endif
return charStr;
}
}
return TEXT("");
}
void ListView::setValues(int codepage)
{
_codepage = codepage;
for (int i = 0 ; i < 256 ; i++)
{
LVITEM item;
@ -91,19 +187,12 @@ void ListView::resetValues(int codepage)
item.iSubItem = 0;
ListView_InsertItem(_hSelf, &item);
char ascii[8];
ascii[0] = (unsigned char)i;
ascii[1] = '\0';
#ifdef UNICODE
wchar_t wCharStr[10];
MultiByteToWideChar(codepage, 0, ascii, -1, wCharStr, sizeof(wCharStr));
ListView_SetItemText(_hSelf, i, 1, wCharStr);
#else
codepage = 0; // make it compile in ANSI Release mode
ListView_SetItemText(_hSelf, i, 1, ascii);
#endif
generic_string s = getAscii((unsigned char)i);
ListView_SetItemText(_hSelf, i, 1, (LPTSTR)s.c_str());
}
}
void ListView::destroy()
{
::DestroyWindow(_hSelf);

View File

@ -29,9 +29,13 @@ public:
virtual void init(HINSTANCE hInst, HWND hwnd);
virtual void destroy();
void resetValues(int codepage = 0);
void setValues(int codepage = 0);
void resetValues(int codepage);
generic_string getAscii(unsigned char value);
protected:
int _codepage;
WNDPROC _defaultProc;
LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);

View File

@ -21,6 +21,12 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "ansiCharPanel.h"
#include "ScintillaEditView.h"
void AnsiCharPanel::switchEncoding()
{
int codepage = (*_ppEditView)->getCurrentBuffer()->getEncoding();
_listView.resetValues(codepage);
}
BOOL CALLBACK AnsiCharPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
@ -32,7 +38,7 @@ BOOL CALLBACK AnsiCharPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPa
_listView.init(_hInst, _hSelf);
int codepage = (*_ppEditView)->getCurrentBuffer()->getEncoding();
_listView.resetValues(codepage==-1?0:codepage);
_listView.setValues(codepage==-1?0:codepage);
_listView.display();
return TRUE;
@ -59,8 +65,17 @@ BOOL CALLBACK AnsiCharPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPa
int codepage = (*_ppEditView)->getCurrentBuffer()->getEncoding();
if (codepage == -1)
{
multiByteStr[0] = charStr[0];
multiByteStr[1] = charStr[1];
bool isUnicode = ((*_ppEditView)->execute(SCI_GETCODEPAGE) == SC_CP_UTF8);
if (isUnicode)
{
MultiByteToWideChar(0, 0, charStr, -1, wCharStr, sizeof(wCharStr));
WideCharToMultiByte(CP_UTF8, 0, wCharStr, -1, multiByteStr, sizeof(multiByteStr), NULL, NULL);
}
else // ANSI
{
multiByteStr[0] = charStr[0];
multiByteStr[1] = charStr[1];
}
}
else
{

View File

@ -47,6 +47,8 @@ public:
_hParent = parent2set;
};
void switchEncoding();
protected:
virtual BOOL CALLBACK AnsiCharPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);

View File

@ -23,7 +23,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
IDD_ANSIASCII_PANEL DIALOGEX 26, 41, 142, 324
STYLE DS_SETFONT | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE
CAPTION "ANSI Characters"
CAPTION "ASCII Insertion Panel"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
//LISTBOX IDC_LIST_ANSICHAR,50,44,78,120,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP

View File

@ -348,7 +348,6 @@ BOOL CALLBACK WindowsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam
else if (pNMHDR->code == NM_DBLCLK)
{
::PostMessage(_hSelf, WM_COMMAND, IDOK, 0);
//activateCurrent();
return TRUE;
}
else if (pNMHDR->code == LVN_KEYDOWN)