Fix menu strings cut off regression for some localication

ref: https://github.com/notepad-plus-plus/notepad-plus-plus/issues/13556#issuecomment-1518197329

Fix #13556, close #13645
pull/13660/head
Don Ho 2 years ago
parent 2577594e2c
commit 34186d2e85

@ -504,14 +504,13 @@ LRESULT Notepad_plus::init(HWND hwnd)
ExternalLangContainer & externalLangContainer = nppParam.getELCFromIndex(i); ExternalLangContainer & externalLangContainer = nppParam.getELCFromIndex(i);
int numLangs = ::GetMenuItemCount(hLangMenu); int numLangs = ::GetMenuItemCount(hLangMenu);
const int bufferSize = 100; TCHAR buffer[menuItemStrLenMax]{};
TCHAR buffer[bufferSize] = { '\0' };
const TCHAR* lexerNameW = wmc.char2wchar(externalLangContainer._name.c_str(), CP_ACP); const TCHAR* lexerNameW = wmc.char2wchar(externalLangContainer._name.c_str(), CP_ACP);
int x = 0; int x = 0;
for (; (x == 0 || lstrcmp(lexerNameW, buffer) > 0) && x < numLangs; ++x) for (; (x == 0 || lstrcmp(lexerNameW, buffer) > 0) && x < numLangs; ++x)
{ {
::GetMenuString(hLangMenu, x, buffer, bufferSize, MF_BYPOSITION); ::GetMenuString(hLangMenu, x, buffer, menuItemStrLenMax, MF_BYPOSITION);
} }
::InsertMenu(hLangMenu, x - 1, MF_BYPOSITION, IDM_LANG_EXTERNAL + i, lexerNameW); ::InsertMenu(hLangMenu, x - 1, MF_BYPOSITION, IDM_LANG_EXTERNAL + i, lexerNameW);
@ -587,12 +586,12 @@ LRESULT Notepad_plus::init(HWND hwnd)
// Update Scintilla context menu strings (translated) // Update Scintilla context menu strings (translated)
vector<MenuItemUnit> & tmp = nppParam.getContextMenuItems(); vector<MenuItemUnit> & tmp = nppParam.getContextMenuItems();
size_t len = tmp.size(); size_t len = tmp.size();
TCHAR menuName[64]; TCHAR menuName[menuItemStrLenMax];
for (size_t i = 0; i < len; ++i) for (size_t i = 0; i < len; ++i)
{ {
if (tmp[i]._itemName.empty()) if (tmp[i]._itemName.empty())
{ {
::GetMenuString(_mainMenuHandle, tmp[i]._cmdID, menuName, 64, MF_BYCOMMAND); ::GetMenuString(_mainMenuHandle, tmp[i]._cmdID, menuName, menuItemStrLenMax, MF_BYCOMMAND);
tmp[i]._itemName = purgeMenuItemString(menuName); tmp[i]._itemName = purgeMenuItemString(menuName);
} }
} }
@ -605,7 +604,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
{ {
if (tmp2[i]._itemName.empty()) if (tmp2[i]._itemName.empty())
{ {
::GetMenuString(_mainMenuHandle, tmp2[i]._cmdID, menuName, 64, MF_BYCOMMAND); ::GetMenuString(_mainMenuHandle, tmp2[i]._cmdID, menuName, menuItemStrLenMax, MF_BYCOMMAND);
tmp2[i]._itemName = purgeMenuItemString(menuName); tmp2[i]._itemName = purgeMenuItemString(menuName);
} }
} }
@ -2613,11 +2612,11 @@ void Notepad_plus::checkLangsMenu(int id) const
if (curBuf->isUserDefineLangExt()) if (curBuf->isUserDefineLangExt())
{ {
const TCHAR *userLangName = curBuf->getUserDefineLangName(); const TCHAR *userLangName = curBuf->getUserDefineLangName();
TCHAR menuLangName[langNameLenMax]; TCHAR menuLangName[menuItemStrLenMax];
for (int i = IDM_LANG_USER + 1 ; i <= IDM_LANG_USER_LIMIT ; ++i) for (int i = IDM_LANG_USER + 1 ; i <= IDM_LANG_USER_LIMIT ; ++i)
{ {
if (::GetMenuString(_mainMenuHandle, i, menuLangName, langNameLenMax, MF_BYCOMMAND)) if (::GetMenuString(_mainMenuHandle, i, menuLangName, menuItemStrLenMax, MF_BYCOMMAND))
{ {
if (!lstrcmp(userLangName, menuLangName)) if (!lstrcmp(userLangName, menuLangName))
{ {
@ -2928,9 +2927,8 @@ void Notepad_plus::setUniModeText()
} }
cmdID += IDM_FORMAT_ENCODE; cmdID += IDM_FORMAT_ENCODE;
const int itemSize = 64; TCHAR uniModeText[menuItemStrLenMax]{};
TCHAR uniModeText[itemSize] = {}; ::GetMenuString(_mainMenuHandle, cmdID, uniModeText, menuItemStrLenMax, MF_BYCOMMAND);
::GetMenuString(_mainMenuHandle, cmdID, uniModeText, itemSize, MF_BYCOMMAND);
uniModeTextString = uniModeText; uniModeTextString = uniModeText;
// Remove the shortcut text from the menu text. // Remove the shortcut text from the menu text.
const size_t tabPos = uniModeTextString.find_last_of('\t'); const size_t tabPos = uniModeTextString.find_last_of('\t');
@ -6732,11 +6730,10 @@ void Notepad_plus::setWorkingDir(const TCHAR *dir)
int Notepad_plus::getLangFromMenuName(const TCHAR * langName) int Notepad_plus::getLangFromMenuName(const TCHAR * langName)
{ {
int id = 0; int id = 0;
const int menuSize = 64; TCHAR menuLangName[menuItemStrLenMax];
TCHAR menuLangName[menuSize];
for ( int i = IDM_LANG_C; i <= IDM_LANG_USER; ++i ) for ( int i = IDM_LANG_C; i <= IDM_LANG_USER; ++i )
if ( ::GetMenuString( _mainMenuHandle, i, menuLangName, menuSize, MF_BYCOMMAND ) ) if ( ::GetMenuString( _mainMenuHandle, i, menuLangName, menuItemStrLenMax, MF_BYCOMMAND ) )
if ( !lstrcmp( langName, menuLangName ) ) if ( !lstrcmp( langName, menuLangName ) )
{ {
id = i; id = i;
@ -6746,7 +6743,7 @@ int Notepad_plus::getLangFromMenuName(const TCHAR * langName)
if ( id == 0 ) if ( id == 0 )
{ {
for ( int i = IDM_LANG_USER + 1; i <= IDM_LANG_USER_LIMIT; ++i ) for ( int i = IDM_LANG_USER + 1; i <= IDM_LANG_USER_LIMIT; ++i )
if ( ::GetMenuString( _mainMenuHandle, i, menuLangName, menuSize, MF_BYCOMMAND ) ) if ( ::GetMenuString( _mainMenuHandle, i, menuLangName, menuItemStrLenMax, MF_BYCOMMAND ) )
if ( !lstrcmp( langName, menuLangName ) ) if ( !lstrcmp( langName, menuLangName ) )
{ {
id = i; id = i;
@ -6762,13 +6759,12 @@ generic_string Notepad_plus::getLangFromMenu(const Buffer * buf)
int id; int id;
generic_string userLangName; generic_string userLangName;
const int nbChar = 32; TCHAR menuLangName[menuItemStrLenMax]{};
TCHAR menuLangName[nbChar];
id = (NppParameters::getInstance()).langTypeToCommandID( buf->getLangType() ); id = (NppParameters::getInstance()).langTypeToCommandID( buf->getLangType() );
if ( ( id != IDM_LANG_USER ) || !( buf->isUserDefineLangExt() ) ) if ( ( id != IDM_LANG_USER ) || !( buf->isUserDefineLangExt() ) )
{ {
::GetMenuString(_mainMenuHandle, id, menuLangName, nbChar-1, MF_BYCOMMAND); ::GetMenuString(_mainMenuHandle, id, menuLangName, menuItemStrLenMax, MF_BYCOMMAND);
userLangName = menuLangName; userLangName = menuLangName;
} }
else else
@ -6822,12 +6818,12 @@ bool Notepad_plus::reloadLang()
// Update scintilla context menu strings // Update scintilla context menu strings
vector<MenuItemUnit> & tmp = nppParam.getContextMenuItems(); vector<MenuItemUnit> & tmp = nppParam.getContextMenuItems();
size_t len = tmp.size(); size_t len = tmp.size();
TCHAR menuName[64]; TCHAR menuName[menuItemStrLenMax];
for (size_t i = 0 ; i < len ; ++i) for (size_t i = 0 ; i < len ; ++i)
{ {
if (tmp[i]._itemName == TEXT("")) if (tmp[i]._itemName == TEXT(""))
{ {
::GetMenuString(_mainMenuHandle, tmp[i]._cmdID, menuName, 64, MF_BYCOMMAND); ::GetMenuString(_mainMenuHandle, tmp[i]._cmdID, menuName, menuItemStrLenMax, MF_BYCOMMAND);
tmp[i]._itemName = purgeMenuItemString(menuName); tmp[i]._itemName = purgeMenuItemString(menuName);
} }
} }
@ -8557,8 +8553,8 @@ void Notepad_plus::updateCommandShortcuts()
if (menuName.length() == 0) if (menuName.length() == 0)
{ {
TCHAR szMenuName[64]; TCHAR szMenuName[menuItemStrLenMax];
if (::GetMenuString(_mainMenuHandle, csc.getID(), szMenuName, _countof(szMenuName), MF_BYCOMMAND)) if (::GetMenuString(_mainMenuHandle, csc.getID(), szMenuName, menuItemStrLenMax, MF_BYCOMMAND))
menuName = purgeMenuItemString(szMenuName, true); menuName = purgeMenuItemString(szMenuName, true);
else else
menuName = csc.getShortcutName(); menuName = csc.getShortcutName();

@ -3936,8 +3936,8 @@ void Notepad_plus::command(int id)
} }
else if ((id > IDM_LANG_USER) && (id < IDM_LANG_USER_LIMIT)) else if ((id > IDM_LANG_USER) && (id < IDM_LANG_USER_LIMIT))
{ {
TCHAR langName[langNameLenMax]; TCHAR langName[menuItemStrLenMax];
::GetMenuString(_mainMenuHandle, id, langName, langNameLenMax, MF_BYCOMMAND); ::GetMenuString(_mainMenuHandle, id, langName, menuItemStrLenMax, MF_BYCOMMAND);
_pEditView->getCurrentBuffer()->setLangType(L_USER, langName); _pEditView->getCurrentBuffer()->setLangType(L_USER, langName);
if (_pDocMap) if (_pDocMap)
{ {
@ -3976,13 +3976,6 @@ void Notepad_plus::command(int id)
{ {
_pluginsManager.relayNppMessages(WM_COMMAND, id, 0); _pluginsManager.relayNppMessages(WM_COMMAND, id, 0);
} }
/*UNLOAD
else if ((id >= ID_PLUGINS_REMOVING) && (id < ID_PLUGINS_REMOVING_END))
{
int i = id - ID_PLUGINS_REMOVING;
_pluginsManager.unloadPlugin(i, _pPublicInterface->getHSelf());
}
*/
else if ((id >= IDM_WINDOW_MRU_FIRST) && (id <= IDM_WINDOW_MRU_LIMIT)) else if ((id >= IDM_WINDOW_MRU_FIRST) && (id <= IDM_WINDOW_MRU_LIMIT))
{ {
activateDoc(id - IDM_WINDOW_MRU_FIRST); activateDoc(id - IDM_WINDOW_MRU_FIRST);

@ -2031,8 +2031,8 @@ int NppParameters::getCmdIdFromMenuEntryItemName(HMENU mainMenuHadle, const gene
int nbMenuEntry = ::GetMenuItemCount(mainMenuHadle); int nbMenuEntry = ::GetMenuItemCount(mainMenuHadle);
for (int i = 0; i < nbMenuEntry; ++i) for (int i = 0; i < nbMenuEntry; ++i)
{ {
TCHAR menuEntryString[64]; TCHAR menuEntryString[menuItemStrLenMax];
::GetMenuString(mainMenuHadle, i, menuEntryString, 64, MF_BYPOSITION); ::GetMenuString(mainMenuHadle, i, menuEntryString, menuItemStrLenMax, MF_BYPOSITION);
if (wcsicmp(menuEntryName.c_str(), purgeMenuItemString(menuEntryString).c_str()) == 0) if (wcsicmp(menuEntryName.c_str(), purgeMenuItemString(menuEntryString).c_str()) == 0)
{ {
vector< pair<HMENU, int> > parentMenuPos; vector< pair<HMENU, int> > parentMenuPos;
@ -2056,8 +2056,8 @@ int NppParameters::getCmdIdFromMenuEntryItemName(HMENU mainMenuHadle, const gene
else else
{ {
// Check current menu position. // Check current menu position.
TCHAR cmdStr[256]; TCHAR cmdStr[menuItemStrLenMax];
::GetMenuString(currMenu, currMenuPos, cmdStr, 256, MF_BYPOSITION); ::GetMenuString(currMenu, currMenuPos, cmdStr, menuItemStrLenMax, MF_BYPOSITION);
if (wcsicmp(menuItemName.c_str(), purgeMenuItemString(cmdStr).c_str()) == 0) if (wcsicmp(menuItemName.c_str(), purgeMenuItemString(cmdStr).c_str()) == 0)
{ {
return ::GetMenuItemID(currMenu, currMenuPos); return ::GetMenuItemID(currMenu, currMenuPos);
@ -2091,16 +2091,16 @@ int NppParameters::getPluginCmdIdFromMenuEntryItemName(HMENU pluginsMenu, const
int nbPlugins = ::GetMenuItemCount(pluginsMenu); int nbPlugins = ::GetMenuItemCount(pluginsMenu);
for (int i = 0; i < nbPlugins; ++i) for (int i = 0; i < nbPlugins; ++i)
{ {
TCHAR menuItemString[256]; TCHAR menuItemString[menuItemStrLenMax];
::GetMenuString(pluginsMenu, i, menuItemString, 256, MF_BYPOSITION); ::GetMenuString(pluginsMenu, i, menuItemString, menuItemStrLenMax, MF_BYPOSITION);
if (wcsicmp(pluginName.c_str(), purgeMenuItemString(menuItemString).c_str()) == 0) if (wcsicmp(pluginName.c_str(), purgeMenuItemString(menuItemString).c_str()) == 0)
{ {
HMENU pluginMenu = ::GetSubMenu(pluginsMenu, i); HMENU pluginMenu = ::GetSubMenu(pluginsMenu, i);
int nbPluginCmd = ::GetMenuItemCount(pluginMenu); int nbPluginCmd = ::GetMenuItemCount(pluginMenu);
for (int j = 0; j < nbPluginCmd; ++j) for (int j = 0; j < nbPluginCmd; ++j)
{ {
TCHAR pluginCmdStr[256]; TCHAR pluginCmdStr[menuItemStrLenMax];
::GetMenuString(pluginMenu, j, pluginCmdStr, 256, MF_BYPOSITION); ::GetMenuString(pluginMenu, j, pluginCmdStr, menuItemStrLenMax, MF_BYPOSITION);
if (wcsicmp(pluginCmdName.c_str(), purgeMenuItemString(pluginCmdStr).c_str()) == 0) if (wcsicmp(pluginCmdName.c_str(), purgeMenuItemString(pluginCmdStr).c_str()) == 0)
{ {
return ::GetMenuItemID(pluginMenu, j); return ::GetMenuItemID(pluginMenu, j);

@ -157,10 +157,10 @@ string Shortcut::toString() const
void Shortcut::setName(const char* menuName, const char* shortcutName) void Shortcut::setName(const char* menuName, const char* shortcutName)
{ {
lstrcpynA(_menuName, menuName, nameLenMax); lstrcpynA(_menuName, menuName, menuItemStrLenMax);
char const * name = shortcutName ? shortcutName : menuName; char const * name = shortcutName ? shortcutName : menuName;
size_t i = 0, j = 0; size_t i = 0, j = 0;
while (name[j] != 0 && i < (nameLenMax - 1)) while (name[j] != 0 && i < (menuItemStrLenMax - 1))
{ {
if (name[j] != '&') if (name[j] != '&')
{ {
@ -318,10 +318,9 @@ void getNameStrFromCmd(DWORD cmd, wstring & str)
else else
{ {
HWND hNotepad_plus = ::FindWindow(Notepad_plus_Window::getClassName(), NULL); HWND hNotepad_plus = ::FindWindow(Notepad_plus_Window::getClassName(), NULL);
const int commandSize = 64; TCHAR cmdName[menuItemStrLenMax];
TCHAR cmdName[commandSize];
HMENU m = reinterpret_cast<HMENU>(::SendMessage(hNotepad_plus, NPPM_INTERNAL_GETMENU, 0, 0)); HMENU m = reinterpret_cast<HMENU>(::SendMessage(hNotepad_plus, NPPM_INTERNAL_GETMENU, 0, 0));
int nbChar = ::GetMenuString(m, cmd, cmdName, commandSize, MF_BYCOMMAND); int nbChar = ::GetMenuString(m, cmd, cmdName, menuItemStrLenMax, MF_BYCOMMAND);
if (!nbChar) if (!nbChar)
return; return;
bool fin = false; bool fin = false;
@ -485,8 +484,8 @@ intptr_t CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar
if (_canModifyName) if (_canModifyName)
{ {
TCHAR editName[nameLenMax]{}; TCHAR editName[menuItemStrLenMax]{};
::SendDlgItemMessage(_hSelf, IDC_NAME_EDIT, WM_GETTEXT, nameLenMax, reinterpret_cast<LPARAM>(editName)); ::SendDlgItemMessage(_hSelf, IDC_NAME_EDIT, WM_GETTEXT, menuItemStrLenMax, reinterpret_cast<LPARAM>(editName));
setName(wstring2string(editName, CP_UTF8).c_str()); setName(wstring2string(editName, CP_UTF8).c_str());
} }
::EndDialog(_hSelf, 0); ::EndDialog(_hSelf, 0);
@ -958,9 +957,8 @@ void ScintillaAccelerator::updateKeys()
void ScintillaAccelerator::updateMenuItemByID(const ScintillaKeyMap& skm, int id) void ScintillaAccelerator::updateMenuItemByID(const ScintillaKeyMap& skm, int id)
{ {
const int commandSize = 64; TCHAR cmdName[menuItemStrLenMax];
TCHAR cmdName[commandSize]; ::GetMenuString(_hAccelMenu, id, cmdName, menuItemStrLenMax, MF_BYCOMMAND);
::GetMenuString(_hAccelMenu, id, cmdName, commandSize, MF_BYCOMMAND);
int i = 0; int i = 0;
while (cmdName[i] != 0) while (cmdName[i] != 0)
{ {

@ -23,7 +23,8 @@
#include "Common.h" #include "Common.h"
#include "menuCmdID.h" #include "menuCmdID.h"
const size_t nameLenMax = 64; constexpr int menuItemStrLenMax = 64 + 64; // Add 64 "units" more for being compatible to the current localization file. See:
// https://github.com/notepad-plus-plus/notepad-plus-plus/issues/13556#issuecomment-1518197329
class NppParameters; class NppParameters;
@ -176,8 +177,8 @@ protected :
KeyCombo _keyCombo; KeyCombo _keyCombo;
virtual intptr_t CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); virtual intptr_t CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam);
bool _canModifyName = false; bool _canModifyName = false;
char _name[nameLenMax] = {'\0'}; //normal name is plain text (for display purposes) char _name[menuItemStrLenMax] {}; //normal name is plain text (for display purposes)
char _menuName[nameLenMax] = { '\0' }; //menu name has ampersands for quick keys char _menuName[menuItemStrLenMax] {}; //menu name has ampersands for quick keys
void updateConflictState(const bool endSession = false) const; void updateConflictState(const bool endSession = false) const;
}; };

Loading…
Cancel
Save