From 6a30c31e0a8dbfaeababa461e3c66564e5c6cf17 Mon Sep 17 00:00:00 2001 From: mmosoll Date: Wed, 4 Apr 2018 14:35:01 +0200 Subject: [PATCH] Add 2 new columns for HTML Code in the Character Panel Added 2 new columns showing HTML Code and HTML Name in the Character Panel for ANSI and Windows-1252 character sets. Modified NM_DBLCLK event to insert in document the current cell value when double clicked in the Character Panel. Modified translation files for French, English, Spanish and Spanish Argentina to include the new added columns in the Character Panel. Modified maximum length of the Character Panel title bar in Notepad_plus::launchAnsiCharPanel(). Close #4371 --- PowerEditor/installer/nativeLang/english.xml | 4 +- PowerEditor/installer/nativeLang/french.xml | 4 +- PowerEditor/installer/nativeLang/spanish.xml | 4 +- .../installer/nativeLang/spanish_ar.xml | 6 +- PowerEditor/src/Notepad_plus.cpp | 4 +- .../AnsiCharPanel/ansiCharPanel.cpp | 54 +++- .../WinControls/AnsiCharPanel/ansiCharPanel.h | 3 +- .../AnsiCharPanel/ansiCharPanel.rc | 2 +- .../AnsiCharPanel/asciiListView.cpp | 299 ++++++++++++++++++ .../WinControls/AnsiCharPanel/asciiListView.h | 2 + 10 files changed, 370 insertions(+), 12 deletions(-) diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index 92f817c0e..9a01c59d0 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -1098,10 +1098,12 @@ Continue?"/> - + + + diff --git a/PowerEditor/installer/nativeLang/french.xml b/PowerEditor/installer/nativeLang/french.xml index 1174575e8..4ff6a08bc 100644 --- a/PowerEditor/installer/nativeLang/french.xml +++ b/PowerEditor/installer/nativeLang/french.xml @@ -1070,10 +1070,12 @@ Voulez-vous les poursuivez ?"/> - + + + diff --git a/PowerEditor/installer/nativeLang/spanish.xml b/PowerEditor/installer/nativeLang/spanish.xml index d1ca2776b..eb17b0d7e 100644 --- a/PowerEditor/installer/nativeLang/spanish.xml +++ b/PowerEditor/installer/nativeLang/spanish.xml @@ -1041,10 +1041,12 @@ Es necesario darle otro."/> - + + + diff --git a/PowerEditor/installer/nativeLang/spanish_ar.xml b/PowerEditor/installer/nativeLang/spanish_ar.xml index 8ed4d3006..14dbac697 100644 --- a/PowerEditor/installer/nativeLang/spanish_ar.xml +++ b/PowerEditor/installer/nativeLang/spanish_ar.xml @@ -826,9 +826,11 @@ - + - + + + diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index e4a6c2a1a..8125fa872 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -5913,8 +5913,8 @@ void Notepad_plus::launchAnsiCharPanel() NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker(); generic_string title_temp = pNativeSpeaker->getAttrNameStr(AI_PROJECTPANELTITLE, "AsciiInsertion", "PanelTitle"); - static TCHAR title[32]; - if (title_temp.length() < 32) + static TCHAR title[85]; + if (title_temp.length() < 85) { wcscpy_s(title, title_temp.c_str()); data.pszName = title; diff --git a/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.cpp b/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.cpp index 22ae23e61..70f1da17d 100644 --- a/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.cpp +++ b/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.cpp @@ -47,10 +47,14 @@ INT_PTR CALLBACK AnsiCharPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM generic_string valStr = pNativeSpeaker->getAttrNameStr(TEXT("Value"), "AsciiInsertion", "ColumnVal"); generic_string hexStr = pNativeSpeaker->getAttrNameStr(TEXT("Hex"), "AsciiInsertion", "ColumnHex"); generic_string charStr = pNativeSpeaker->getAttrNameStr(TEXT("Character"), "AsciiInsertion", "ColumnChar"); + generic_string htmlNumberStr = pNativeSpeaker->getAttrNameStr(TEXT("HTML Number"), "AsciiInsertion", "ColumnHtmlNumber"); + generic_string htmlNameStr = pNativeSpeaker->getAttrNameStr(TEXT("HTML Name"), "AsciiInsertion", "ColumnHtmlName"); _listView.addColumn(columnInfo(valStr, nppParam->_dpiManager.scaleX(45))); _listView.addColumn(columnInfo(hexStr, nppParam->_dpiManager.scaleX(45))); _listView.addColumn(columnInfo(charStr, nppParam->_dpiManager.scaleX(70))); + _listView.addColumn(columnInfo(htmlNumberStr, nppParam->_dpiManager.scaleX(100))); + _listView.addColumn(columnInfo(htmlNameStr, nppParam->_dpiManager.scaleX(90))); _listView.init(_hInst, _hSelf); int codepage = (*_ppEditView)->getCurrentBuffer()->getEncoding(); @@ -67,12 +71,29 @@ INT_PTR CALLBACK AnsiCharPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM case NM_DBLCLK: { LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE) lParam; - int i = lpnmitem->iItem; + LVHITTESTINFO pInfo; + pInfo.pt = lpnmitem->ptAction; + ListView_SubItemHitTest(_listView.getHSelf(), &pInfo); + + int i = pInfo.iItem; + int j = pInfo.iSubItem; + wchar_t buffer[10]; + LVITEM item; + item.mask = LVIF_TEXT | LVIF_PARAM; + item.iItem = i; + item.iSubItem = j; + item.cchTextMax = 10; + item.pszText = buffer; + ListView_GetItem(_listView.getHSelf(), &item); if (i == -1) return TRUE; - insertChar(static_cast(i)); + if (j != 2) + insertString(item.pszText); + else + insertChar(static_cast(i)); + return TRUE; } @@ -147,4 +168,31 @@ void AnsiCharPanel::insertChar(unsigned char char2insert) const size_t len = (char2insert < 128) ? 1 : strlen(multiByteStr); (*_ppEditView)->execute(SCI_ADDTEXT, len, reinterpret_cast(multiByteStr)); (*_ppEditView)->getFocus(); -} \ No newline at end of file +} + +void AnsiCharPanel::insertString(LPWSTR string2insert) const +{ + char multiByteStr[10]; + int codepage = (*_ppEditView)->getCurrentBuffer()->getEncoding(); + if (codepage == -1) + { + bool isUnicode = ((*_ppEditView)->execute(SCI_GETCODEPAGE) == SC_CP_UTF8); + if (isUnicode) + { + WideCharToMultiByte(CP_UTF8, 0, string2insert, -1, multiByteStr, sizeof(multiByteStr), NULL, NULL); + } + else // ANSI + { + wcstombs(multiByteStr, string2insert, 10); + } + } + else + { + WideCharToMultiByte(CP_UTF8, 0, string2insert, -1, multiByteStr, sizeof(multiByteStr), NULL, NULL); + } + + (*_ppEditView)->execute(SCI_REPLACESEL, 0, reinterpret_cast("")); + size_t len = strlen(multiByteStr); + (*_ppEditView)->execute(SCI_ADDTEXT, len, reinterpret_cast(multiByteStr)); + (*_ppEditView)->getFocus(); +} diff --git a/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.h b/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.h index 91d3d2683..386187a46 100644 --- a/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.h +++ b/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.h @@ -36,7 +36,7 @@ #include "ListView.h" #include "asciiListView.h" -#define AI_PROJECTPANELTITLE TEXT("ASCII Insertion Panel") +#define AI_PROJECTPANELTITLE TEXT("ASCII/HTML Codes (ANSI or Windows-1252 character sets) Insertion Panel") class ScintillaEditView; @@ -55,6 +55,7 @@ public: void switchEncoding(); void insertChar(unsigned char char2insert) const; + void insertString(LPWSTR string2insert) const; virtual void setBackgroundColor(int bgColour) const { ListView_SetBkColor(_listView.getHSelf(), bgColour); diff --git a/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.rc b/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.rc index 41f99cc5c..f12fe8a67 100644 --- a/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.rc +++ b/PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.rc @@ -32,7 +32,7 @@ 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 "ASCII Insertion Panel" +CAPTION "ASCII/HTML Codes (ANSI or Windows-1252 character sets) 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 diff --git a/PowerEditor/src/WinControls/AnsiCharPanel/asciiListView.cpp b/PowerEditor/src/WinControls/AnsiCharPanel/asciiListView.cpp index 76cf6ef8f..0c9264173 100644 --- a/PowerEditor/src/WinControls/AnsiCharPanel/asciiListView.cpp +++ b/PowerEditor/src/WinControls/AnsiCharPanel/asciiListView.cpp @@ -126,6 +126,274 @@ generic_string AsciiListView::getAscii(unsigned char value) } } +generic_string AsciiListView::getHtmlName(unsigned char value) +{ + switch (value) + { + case 34: + return TEXT("""); + case 38: + return TEXT("&"); + case 60: + return TEXT("<"); + case 62: + return TEXT(">"); + case 128: + return TEXT("€"); + case 160: + return TEXT(" "); + case 161: + return TEXT("¡"); + case 162: + return TEXT("¢"); + case 163: + return TEXT("£"); + case 164: + return TEXT("¤"); + case 165: + return TEXT("¥"); + case 166: + return TEXT("¦"); + case 167: + return TEXT("§"); + case 168: + return TEXT("¨"); + case 169: + return TEXT("©"); + case 170: + return TEXT("ª"); + case 171: + return TEXT("«"); + case 172: + return TEXT("¬"); + case 173: + return TEXT("­"); + case 174: + return TEXT("®"); + case 175: + return TEXT("¯"); + case 176: + return TEXT("°"); + case 177: + return TEXT("±"); + case 178: + return TEXT("²"); + case 179: + return TEXT("³"); + case 180: + return TEXT("´"); + case 181: + return TEXT("µ"); + case 182: + return TEXT("¶"); + case 183: + return TEXT("·"); + case 184: + return TEXT("¸"); + case 185: + return TEXT("¹"); + case 186: + return TEXT("º"); + case 187: + return TEXT("»"); + case 188: + return TEXT("¼"); + case 189: + return TEXT("½"); + case 190: + return TEXT("¾"); + case 191: + return TEXT("¿"); + case 192: + return TEXT("À"); + case 193: + return TEXT("Á"); + case 194: + return TEXT("Â"); + case 195: + return TEXT("Ã"); + case 196: + return TEXT("Ä"); + case 197: + return TEXT("Å"); + case 198: + return TEXT("Æ"); + case 199: + return TEXT("Ç"); + case 200: + return TEXT("È"); + case 201: + return TEXT("É"); + case 202: + return TEXT("Ê"); + case 203: + return TEXT("Ë"); + case 204: + return TEXT("Ì"); + case 205: + return TEXT("Í"); + case 206: + return TEXT("Î"); + case 207: + return TEXT("Ï"); + case 208: + return TEXT("Ð"); + case 209: + return TEXT("Ñ"); + case 210: + return TEXT("Ò"); + case 211: + return TEXT("Ó"); + case 212: + return TEXT("Ô"); + case 213: + return TEXT("Õ"); + case 214: + return TEXT("Ö"); + case 215: + return TEXT("×"); + case 216: + return TEXT("Ø"); + case 217: + return TEXT("Ù"); + case 218: + return TEXT("Ú"); + case 219: + return TEXT("Û"); + case 220: + return TEXT("Ü"); + case 221: + return TEXT("Ý"); + case 222: + return TEXT("Þ"); + case 223: + return TEXT("ß"); + case 224: + return TEXT("à"); + case 225: + return TEXT("á"); + case 226: + return TEXT("â"); + case 227: + return TEXT("ã"); + case 228: + return TEXT("ä"); + case 229: + return TEXT("å"); + case 230: + return TEXT("æ"); + case 231: + return TEXT("ç"); + case 232: + return TEXT("è"); + case 233: + return TEXT("é"); + case 234: + return TEXT("ê"); + case 235: + return TEXT("ë"); + case 236: + return TEXT("ì"); + case 237: + return TEXT("í"); + case 238: + return TEXT("î"); + case 239: + return TEXT("ï"); + case 240: + return TEXT("ð"); + case 241: + return TEXT("ñ"); + case 242: + return TEXT("ò"); + case 243: + return TEXT("ó"); + case 244: + return TEXT("ô"); + case 245: + return TEXT("õ"); + case 246: + return TEXT("ö"); + case 247: + return TEXT("÷"); + case 248: + return TEXT("ø"); + case 249: + return TEXT("ù"); + case 250: + return TEXT("ú"); + case 251: + return TEXT("û"); + case 252: + return TEXT("ü"); + case 253: + return TEXT("ý"); + case 254: + return TEXT("þ"); + case 255: + return TEXT("ÿ"); + default: + { + return TEXT(""); + } + + } +} + +int AsciiListView::getHtmlNumber(unsigned char value) +{ + switch (value) + { + case 128: + return 8364; + case 130: + return 8218; + case 131: + return 402; + case 132: + return 8222; + case 133: + return 8230; + case 134: + return 8224; + case 135: + return 8225; + case 137: + return 8240; + case 138: + return 352; + case 140: + return 338; + case 145: + return 8216; + case 146: + return 8217; + case 147: + return 8220; + case 148: + return 8221; + case 149: + return 8226; + case 150: + return 8211; + case 151: + return 8212; + case 153: + return 8482; + case 154: + return 353; + case 156: + return 339; + case 159: + return 376; + default: + { + return -1; + } + + } +} + void AsciiListView::setValues(int codepage) { _codepage = codepage; @@ -134,15 +402,46 @@ void AsciiListView::setValues(int codepage) { TCHAR dec[8]; TCHAR hex[8]; + TCHAR htmlNumber[8]; + generic_string htmlName; generic_sprintf(dec, TEXT("%d"), i); generic_sprintf(hex, TEXT("%02X"), i); generic_string s = getAscii(static_cast(i)); + if (codepage == 0 || codepage == 1252) + { + if ((i >= 32 && i <= 126) || (i >= 160 && i <= 255)) + { + generic_sprintf(htmlNumber, TEXT("&#%d"), i); + } + else + { + int n = getHtmlNumber(static_cast(i)); + if (n > -1) + { + generic_sprintf(htmlNumber, TEXT("&#%d"), n); + } + else + { + generic_sprintf(htmlNumber, TEXT("")); + } + } + + htmlName = getHtmlName(static_cast(i)); + } + else + { + generic_sprintf(htmlNumber, TEXT("")); + htmlName = TEXT(""); + } + std::vector values2Add; values2Add.push_back(dec); values2Add.push_back(hex); values2Add.push_back(s); + values2Add.push_back(htmlNumber); + values2Add.push_back(htmlName); addLine(values2Add); } diff --git a/PowerEditor/src/WinControls/AnsiCharPanel/asciiListView.h b/PowerEditor/src/WinControls/AnsiCharPanel/asciiListView.h index e38f2c184..b951e79a3 100644 --- a/PowerEditor/src/WinControls/AnsiCharPanel/asciiListView.h +++ b/PowerEditor/src/WinControls/AnsiCharPanel/asciiListView.h @@ -36,6 +36,8 @@ public: void resetValues(int codepage); generic_string getAscii(unsigned char value); + generic_string getHtmlName(unsigned char value); + int getHtmlNumber(unsigned char value); private: int _codepage = -1; };