Make number of languages and and styles unlimited and independent

A clean version of #10483 thanks to @ozone10 and @chcg.
The proper fix for #10206 without any compile-time limits.

Fix #10483, fix #10206, close #10491
This commit is contained in:
Ivan Ustûžanin 2021-08-31 21:58:12 +03:00 committed by Don Ho
parent d4781bd4a3
commit 156784722a
9 changed files with 277 additions and 551 deletions

View File

@ -681,13 +681,11 @@ LRESULT Notepad_plus::init(HWND hwnd)
// Initialize the default foreground & background color // Initialize the default foreground & background color
// //
{ {
StyleArray & globalStyles = nppParam.getGlobalStylers(); const Style * pStyle = nppParam.getGlobalStylers().findByID(STYLE_DEFAULT);
int i = globalStyles.getStylerIndexByID(STYLE_DEFAULT); if (pStyle)
if (i != -1)
{ {
Style & style = globalStyles.getStyler(i); nppParam.setCurrentDefaultFgColor(pStyle->_fgColor);
nppParam.setCurrentDefaultFgColor(style._fgColor); nppParam.setCurrentDefaultBgColor(pStyle->_bgColor);
nppParam.setCurrentDefaultBgColor(style._bgColor);
} }
} }
@ -2259,12 +2257,9 @@ void Notepad_plus::setupColorSampleBitmapsOnMainMenuItems()
for (int j = 0; j < sizeof(bitmapOnStyleMenuItemsInfo) / sizeof(bitmapOnStyleMenuItemsInfo[0]); ++j) for (int j = 0; j < sizeof(bitmapOnStyleMenuItemsInfo) / sizeof(bitmapOnStyleMenuItemsInfo[0]); ++j)
{ {
StyleArray& stylers = NppParameters::getInstance().getMiscStylerArray(); const Style * pStyle = NppParameters::getInstance().getMiscStylerArray().findByID(bitmapOnStyleMenuItemsInfo[j].styleIndic);
int iFind = stylers.getStylerIndexByID(bitmapOnStyleMenuItemsInfo[j].styleIndic); if (pStyle)
if (iFind != -1)
{ {
Style const* pStyle = &(stylers.getStyler(iFind));
HDC hDC = GetDC(NULL); HDC hDC = GetDC(NULL);
const int bitmapXYsize = 16; const int bitmapXYsize = 16;
@ -6369,16 +6364,7 @@ generic_string Notepad_plus::getLangFromMenu(const Buffer * buf)
Style * Notepad_plus::getStyleFromName(const TCHAR *styleName) Style * Notepad_plus::getStyleFromName(const TCHAR *styleName)
{ {
StyleArray & stylers = (NppParameters::getInstance()).getMiscStylerArray(); return NppParameters::getInstance().getMiscStylerArray().findByName(styleName);
int i = stylers.getStylerIndexByName(styleName);
Style * st = NULL;
if (i != -1)
{
Style & style = stylers.getStyler(i);
st = &style;
}
return st;
} }
bool Notepad_plus::noOpenedDoc() const bool Notepad_plus::noOpenedDoc() const

View File

@ -1796,67 +1796,68 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
drawDocumentMapColoursFromStylerArray(); drawDocumentMapColoursFromStylerArray();
// Update default fg/bg colors in Parameters for both internal/plugins docking dialog // Update default fg/bg colors in Parameters for both internal/plugins docking dialog
StyleArray & globalStyles = (NppParameters::getInstance()).getGlobalStylers(); const Style * pStyle = NppParameters::getInstance().getGlobalStylers().findByID(STYLE_DEFAULT);
int i = globalStyles.getStylerIndexByID(STYLE_DEFAULT); if (pStyle)
Style & style = globalStyles.getStyler(i); {
(NppParameters::getInstance()).setCurrentDefaultFgColor(style._fgColor); NppParameters::getInstance().setCurrentDefaultFgColor(pStyle->_fgColor);
(NppParameters::getInstance()).setCurrentDefaultBgColor(style._bgColor); NppParameters::getInstance().setCurrentDefaultBgColor(pStyle->_bgColor);
}
NppDarkMode::calculateTreeViewStyle(); NppDarkMode::calculateTreeViewStyle();
auto refreshOnlyTreeView = static_cast<LPARAM>(TRUE); auto refreshOnlyTreeView = static_cast<LPARAM>(TRUE);
// Set default fg/bg colors on internal docking dialog // Set default fg/bg colors on internal docking dialog
if (_pFuncList) if (pStyle && _pFuncList)
{ {
_pFuncList->setBackgroundColor(style._bgColor); _pFuncList->setBackgroundColor(pStyle->_bgColor);
_pFuncList->setForegroundColor(style._fgColor); _pFuncList->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pFuncList->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); ::SendMessage(_pFuncList->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
} }
if (_pAnsiCharPanel) if (pStyle && _pAnsiCharPanel)
{ {
_pAnsiCharPanel->setBackgroundColor(style._bgColor); _pAnsiCharPanel->setBackgroundColor(pStyle->_bgColor);
_pAnsiCharPanel->setForegroundColor(style._fgColor); _pAnsiCharPanel->setForegroundColor(pStyle->_fgColor);
} }
if (_pDocumentListPanel) if (pStyle && _pDocumentListPanel)
{ {
_pDocumentListPanel->setBackgroundColor(style._bgColor); _pDocumentListPanel->setBackgroundColor(pStyle->_bgColor);
_pDocumentListPanel->setForegroundColor(style._fgColor); _pDocumentListPanel->setForegroundColor(pStyle->_fgColor);
} }
if (_pClipboardHistoryPanel) if (pStyle && _pClipboardHistoryPanel)
{ {
_pClipboardHistoryPanel->setBackgroundColor(style._bgColor); _pClipboardHistoryPanel->setBackgroundColor(pStyle->_bgColor);
_pClipboardHistoryPanel->setForegroundColor(style._fgColor); _pClipboardHistoryPanel->setForegroundColor(pStyle->_fgColor);
_pClipboardHistoryPanel->redraw(true); _pClipboardHistoryPanel->redraw(true);
} }
if (_pProjectPanel_1) if (pStyle && _pProjectPanel_1)
{ {
_pProjectPanel_1->setBackgroundColor(style._bgColor); _pProjectPanel_1->setBackgroundColor(pStyle->_bgColor);
_pProjectPanel_1->setForegroundColor(style._fgColor); _pProjectPanel_1->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pProjectPanel_1->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); ::SendMessage(_pProjectPanel_1->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
} }
if (_pProjectPanel_2) if (pStyle && _pProjectPanel_2)
{ {
_pProjectPanel_2->setBackgroundColor(style._bgColor); _pProjectPanel_2->setBackgroundColor(pStyle->_bgColor);
_pProjectPanel_2->setForegroundColor(style._fgColor); _pProjectPanel_2->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pProjectPanel_2->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); ::SendMessage(_pProjectPanel_2->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
} }
if (_pProjectPanel_3) if (pStyle && _pProjectPanel_3)
{ {
_pProjectPanel_3->setBackgroundColor(style._bgColor); _pProjectPanel_3->setBackgroundColor(pStyle->_bgColor);
_pProjectPanel_3->setForegroundColor(style._fgColor); _pProjectPanel_3->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pProjectPanel_3->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); ::SendMessage(_pProjectPanel_3->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
} }
if (_pFileBrowser) if (pStyle && _pFileBrowser)
{ {
_pFileBrowser->setBackgroundColor(style._bgColor); _pFileBrowser->setBackgroundColor(pStyle->_bgColor);
_pFileBrowser->setForegroundColor(style._fgColor); _pFileBrowser->setForegroundColor(pStyle->_fgColor);
::SendMessage(_pFileBrowser->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView); ::SendMessage(_pFileBrowser->getHSelf(), NPPM_INTERNAL_REFRESHDARKMODE, 0, refreshOnlyTreeView);
} }
@ -2534,13 +2535,11 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
ScintillaViewParams &svp = const_cast<ScintillaViewParams &>(nppParam.getSVP()); ScintillaViewParams &svp = const_cast<ScintillaViewParams &>(nppParam.getSVP());
StyleArray & stylers = NppParameters::getInstance().getMiscStylerArray();
COLORREF multiEdgeColor = liteGrey; COLORREF multiEdgeColor = liteGrey;
int i = stylers.getStylerIndexByName(TEXT("Edge colour")); const Style * pStyle = NppParameters::getInstance().getMiscStylerArray().findByName(TEXT("Edge colour"));
if (i != -1) if (pStyle)
{ {
Style & style = stylers.getStyler(i); multiEdgeColor = pStyle->_fgColor;
multiEdgeColor = style._fgColor;
} }
const size_t twoPower13 = 8192; const size_t twoPower13 = 8192;

View File

@ -926,8 +926,8 @@ bool NppParameters::reloadStylers(const TCHAR* stylePath)
_pXmlUserStylerDoc = NULL; _pXmlUserStylerDoc = NULL;
return false; return false;
} }
_lexerStylerVect.eraseAll(); _lexerStylerVect.clear();
_widgetStyleArray.setNbStyler( 0 ); _widgetStyleArray.clear();
getUserStylersFromXmlTree(); getUserStylersFromXmlTree();
@ -1594,22 +1594,19 @@ UserLangContainer* NppParameters::getULCFromName(const TCHAR *userLangName)
COLORREF NppParameters::getCurLineHilitingColour() COLORREF NppParameters::getCurLineHilitingColour()
{ {
int i = _widgetStyleArray.getStylerIndexByName(TEXT("Current line background colour")); const Style * pStyle = _widgetStyleArray.findByName(TEXT("Current line background colour"));
if (i == -1) if (!pStyle)
return i; return COLORREF(-1);
Style & style = _widgetStyleArray.getStyler(i); return pStyle->_bgColor;
return style._bgColor;
} }
void NppParameters::setCurLineHilitingColour(COLORREF colour2Set) void NppParameters::setCurLineHilitingColour(COLORREF colour2Set)
{ {
int i = _widgetStyleArray.getStylerIndexByName(TEXT("Current line background colour")); Style * pStyle = _widgetStyleArray.findByName(TEXT("Current line background colour"));
if (i == -1) if (!pStyle)
return; return;
pStyle->_bgColor = colour2Set;
Style& style = _widgetStyleArray.getStyler(i);
style._bgColor = colour2Set;
} }
@ -2774,11 +2771,11 @@ std::pair<unsigned char, unsigned char> NppParameters::feedUserLang(TiXmlNode *n
feedUserStyles(stylesRoot); feedUserStyles(stylesRoot);
// styles that were not read from xml file should get default values // styles that were not read from xml file should get default values
for (int i=0; i<SCE_USER_STYLE_TOTAL_STYLES; ++i) for (int i = 0 ; i < SCE_USER_STYLE_TOTAL_STYLES ; ++i)
{ {
Style & style = _userLangArray[_nbUserLang - 1]->_styles.getStyler(i); const Style * pStyle = _userLangArray[_nbUserLang - 1]->_styles.findByID(i);
if (style._styleID == -1) if (!pStyle)
_userLangArray[_nbUserLang - 1]->_styles.addStyler(i, globalMappper().styleNameMapper[i].c_str()); _userLangArray[_nbUserLang - 1]->_styles.addStyler(i, globalMappper().styleNameMapper[i]);
} }
} }
@ -3098,12 +3095,8 @@ void NppParameters::writeNonDefaultUDL()
void NppParameters::writeNeed2SaveUDL() void NppParameters::writeNeed2SaveUDL()
{ {
stylerStrOp(DUP);
writeDefaultUDL(); writeDefaultUDL();
writeNonDefaultUDL(); writeNonDefaultUDL();
stylerStrOp(FREE);
} }
@ -3570,8 +3563,6 @@ bool NppParameters::feedStylerArray(TiXmlNode *node)
childNode ; childNode ;
childNode = childNode->NextSibling(TEXT("LexerType")) ) childNode = childNode->NextSibling(TEXT("LexerType")) )
{ {
if (!_lexerStylerVect.hasEnoughSpace()) return false;
TiXmlElement *element = childNode->ToElement(); TiXmlElement *element = childNode->ToElement();
const TCHAR *lexerName = element->Attribute(TEXT("name")); const TCHAR *lexerName = element->Attribute(TEXT("name"));
const TCHAR *lexerDesc = element->Attribute(TEXT("desc")); const TCHAR *lexerDesc = element->Attribute(TEXT("desc"));
@ -3597,8 +3588,6 @@ bool NppParameters::feedStylerArray(TiXmlNode *node)
childNode ; childNode ;
childNode = childNode->NextSibling(TEXT("WidgetStyle")) ) childNode = childNode->NextSibling(TEXT("WidgetStyle")) )
{ {
if (!_widgetStyleArray.hasEnoughSpace()) return false;
TiXmlElement *element = childNode->ToElement(); TiXmlElement *element = childNode->ToElement();
const TCHAR *styleIDStr = element->Attribute(TEXT("styleID")); const TCHAR *styleIDStr = element->Attribute(TEXT("styleID"));
@ -3613,7 +3602,8 @@ bool NppParameters::feedStylerArray(TiXmlNode *node)
void LexerStylerArray::addLexerStyler(const TCHAR *lexerName, const TCHAR *lexerDesc, const TCHAR *lexerUserExt , TiXmlNode *lexerNode) void LexerStylerArray::addLexerStyler(const TCHAR *lexerName, const TCHAR *lexerDesc, const TCHAR *lexerUserExt , TiXmlNode *lexerNode)
{ {
LexerStyler & ls = _lexerStylerVect[_nbLexerStyler++]; _lexerStylerVect.emplace_back();
LexerStyler & ls = _lexerStylerVect.back();
ls.setLexerName(lexerName); ls.setLexerName(lexerName);
if (lexerDesc) if (lexerDesc)
ls.setLexerDesc(lexerDesc); ls.setLexerDesc(lexerDesc);
@ -3625,9 +3615,6 @@ void LexerStylerArray::addLexerStyler(const TCHAR *lexerName, const TCHAR *lexer
childNode ; childNode ;
childNode = childNode->NextSibling(TEXT("WordsStyle")) ) childNode = childNode->NextSibling(TEXT("WordsStyle")) )
{ {
if (!ls.hasEnoughSpace())
return;
TiXmlElement *element = childNode->ToElement(); TiXmlElement *element = childNode->ToElement();
const TCHAR *styleIDStr = element->Attribute(TEXT("styleID")); const TCHAR *styleIDStr = element->Attribute(TEXT("styleID"));
@ -3642,35 +3629,19 @@ void LexerStylerArray::addLexerStyler(const TCHAR *lexerName, const TCHAR *lexer
} }
} }
void LexerStylerArray::eraseAll()
{
for (int i = 0 ; i < _nbLexerStyler ; ++i)
{
_lexerStylerVect[i].setNbStyler( 0 );
}
_nbLexerStyler = 0;
}
void StyleArray::addStyler(int styleID, TiXmlNode *styleNode) void StyleArray::addStyler(int styleID, TiXmlNode *styleNode)
{ {
int index = _nbStyler;
bool isUser = styleID >> 16 == L_USER; bool isUser = styleID >> 16 == L_USER;
if (isUser) if (isUser)
{ {
styleID = (styleID & 0xFFFF); styleID = (styleID & 0xFFFF);
index = styleID; if (styleID >= SCE_USER_STYLE_TOTAL_STYLES || findByID(styleID))
if (index >= SCE_USER_STYLE_TOTAL_STYLES || _styleVect[index]._styleID != -1)
return;
}
else
{
if (index >= STYLE_ARR_MAX_SIZE)
return; return;
} }
_styleVect[index]._styleID = styleID; _styleVect.emplace_back();
Style & s = _styleVect.back();
s._styleID = styleID;
if (styleNode) if (styleNode)
{ {
@ -3684,16 +3655,16 @@ void StyleArray::addStyler(int styleID, TiXmlNode *styleNode)
if (str) if (str)
{ {
if (isUser) if (isUser)
_styleVect[index]._styleDesc = globalMappper().styleNameMapper[index].c_str(); s._styleDesc = globalMappper().styleNameMapper[styleID];
else else
_styleVect[index]._styleDesc = str; s._styleDesc = str;
} }
str = element->Attribute(TEXT("fgColor")); str = element->Attribute(TEXT("fgColor"));
if (str) if (str)
{ {
unsigned long result = hexStrVal(str); unsigned long result = hexStrVal(str);
_styleVect[index]._fgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000); s._fgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000);
} }
@ -3701,49 +3672,51 @@ void StyleArray::addStyler(int styleID, TiXmlNode *styleNode)
if (str) if (str)
{ {
unsigned long result = hexStrVal(str); unsigned long result = hexStrVal(str);
_styleVect[index]._bgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000); s._bgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000);
} }
str = element->Attribute(TEXT("colorStyle")); str = element->Attribute(TEXT("colorStyle"));
if (str) if (str)
{ {
_styleVect[index]._colorStyle = decStrVal(str); s._colorStyle = decStrVal(str);
} }
str = element->Attribute(TEXT("fontName")); str = element->Attribute(TEXT("fontName"));
_styleVect[index]._fontName = str; if (str)
{
s._fontName = str;
}
str = element->Attribute(TEXT("fontStyle")); str = element->Attribute(TEXT("fontStyle"));
if (str) if (str)
{ {
_styleVect[index]._fontStyle = decStrVal(str); s._fontStyle = decStrVal(str);
} }
str = element->Attribute(TEXT("fontSize")); str = element->Attribute(TEXT("fontSize"));
if (str) if (str)
{ {
_styleVect[index]._fontSize = decStrVal(str); s._fontSize = decStrVal(str);
} }
str = element->Attribute(TEXT("nesting")); str = element->Attribute(TEXT("nesting"));
if (str) if (str)
{ {
_styleVect[index]._nesting = decStrVal(str); s._nesting = decStrVal(str);
} }
str = element->Attribute(TEXT("keywordClass")); str = element->Attribute(TEXT("keywordClass"));
if (str) if (str)
{ {
_styleVect[index]._keywordClass = getKwClassFromName(str); s._keywordClass = getKwClassFromName(str);
} }
TiXmlNode *v = styleNode->FirstChild(); TiXmlNode *v = styleNode->FirstChild();
if (v) if (v)
{ {
_styleVect[index]._keywords = new generic_string(v->Value()); s._keywords = v->Value();
} }
} }
++_nbStyler;
} }
bool NppParameters::writeRecentFileHistorySettings(int nbMaxFile) const bool NppParameters::writeRecentFileHistorySettings(int nbMaxFile) const
@ -7089,14 +7062,11 @@ generic_string NppParameters::writeStyles(LexerStylerArray & lexersStylers, Styl
{ {
TiXmlElement *grElement = grChildNode->ToElement(); TiXmlElement *grElement = grChildNode->ToElement();
const TCHAR *styleName = grElement->Attribute(TEXT("name")); const TCHAR *styleName = grElement->Attribute(TEXT("name"));
const Style * pStyle = pLs->findByName(styleName);
int i = pLs->getStylerIndexByName(styleName); Style * pStyle2Sync = pLs2 ? pLs2->findByName(styleName) : nullptr;
if (i != -1) if (pStyle && pStyle2Sync)
{ {
Style & style = pLs->getStyler(i); writeStyle2Element(*pStyle, *pStyle2Sync, grElement);
Style & style2Sync = pLs2->getStyler(i);
writeStyle2Element(style, style2Sync, grElement);
} }
} }
} }
@ -7126,14 +7096,11 @@ generic_string NppParameters::writeStyles(LexerStylerArray & lexersStylers, Styl
{ {
TiXmlElement *grElement = grChildNode->ToElement(); TiXmlElement *grElement = grChildNode->ToElement();
const TCHAR *styleName = grElement->Attribute(TEXT("name")); const TCHAR *styleName = grElement->Attribute(TEXT("name"));
const Style * pStyle = pLs->findByName(styleName);
int i = pLs->getStylerIndexByName(styleName); Style * pStyle2Sync = pLs2 ? pLs2->findByName(styleName) : nullptr;
if (i != -1) if (pStyle && pStyle2Sync)
{ {
Style & style = pLs->getStyler(i); writeStyle2Element(*pStyle, *pStyle2Sync, grElement);
Style & style2Sync = pLs2->getStyler(i);
writeStyle2Element(style, style2Sync, grElement);
} }
} }
} }
@ -7149,14 +7116,11 @@ generic_string NppParameters::writeStyles(LexerStylerArray & lexersStylers, Styl
{ {
TiXmlElement *pElement = childNode->ToElement(); TiXmlElement *pElement = childNode->ToElement();
const TCHAR *styleName = pElement->Attribute(TEXT("name")); const TCHAR *styleName = pElement->Attribute(TEXT("name"));
int i = _widgetStyleArray.getStylerIndexByName(styleName); const Style * pStyle = _widgetStyleArray.findByName(styleName);
Style * pStyle2Sync = globalStylers.findByName(styleName);
if (i != -1) if (pStyle && pStyle2Sync)
{ {
Style & style = _widgetStyleArray.getStyler(i); writeStyle2Element(*pStyle, *pStyle2Sync, pElement);
Style & style2Sync = globalStylers.getStyler(i);
writeStyle2Element(style, style2Sync, pElement);
} }
} }
@ -7194,7 +7158,7 @@ bool NppParameters::insertTabInfo(const TCHAR *langName, int tabInfo)
return false; return false;
} }
void NppParameters::writeStyle2Element(Style & style2Write, Style & style2Sync, TiXmlElement *element) void NppParameters::writeStyle2Element(const Style & style2Write, Style & style2Sync, TiXmlElement *element)
{ {
if (HIBYTE(HIWORD(style2Write._fgColor)) != 0xFF) if (HIBYTE(HIWORD(style2Write._fgColor)) != 0xFF)
{ {
@ -7217,13 +7181,13 @@ void NppParameters::writeStyle2Element(Style & style2Write, Style & style2Sync,
element->SetAttribute(TEXT("colorStyle"), style2Write._colorStyle); element->SetAttribute(TEXT("colorStyle"), style2Write._colorStyle);
} }
if (style2Write._fontName) if (!style2Write._fontName.empty())
{ {
const TCHAR *oldFontName = element->Attribute(TEXT("fontName")); const TCHAR * oldFontName = element->Attribute(TEXT("fontName"));
if (lstrcmp(oldFontName, style2Write._fontName)) if (oldFontName && oldFontName != style2Write._fontName)
{ {
element->SetAttribute(TEXT("fontName"), style2Write._fontName); element->SetAttribute(TEXT("fontName"), style2Write._fontName);
style2Sync._fontName = style2Write._fontName = element->Attribute(TEXT("fontName")); style2Sync._fontName = style2Write._fontName;
} }
} }
@ -7241,14 +7205,14 @@ void NppParameters::writeStyle2Element(Style & style2Write, Style & style2Sync,
} }
if (style2Write._keywords) if (!style2Write._keywords.empty())
{ {
TiXmlNode *teteDeNoeud = element->LastChild(); TiXmlNode *teteDeNoeud = element->LastChild();
if (teteDeNoeud) if (teteDeNoeud)
teteDeNoeud->SetValue(style2Write._keywords->c_str()); teteDeNoeud->SetValue(style2Write._keywords.c_str());
else else
element->InsertEndChild(TiXmlText(style2Write._keywords->c_str())); element->InsertEndChild(TiXmlText(style2Write._keywords.c_str()));
} }
} }
@ -7291,10 +7255,9 @@ void NppParameters::insertUserLang2Tree(TiXmlNode *node, UserLangContainer *user
TiXmlElement *styleRootElement = (rootElement->InsertEndChild(TiXmlElement(TEXT("Styles"))))->ToElement(); TiXmlElement *styleRootElement = (rootElement->InsertEndChild(TiXmlElement(TEXT("Styles"))))->ToElement();
for (int i = 0 ; i < SCE_USER_STYLE_TOTAL_STYLES ; ++i) for (const Style & style2Write : userLang->_styles)
{ {
TiXmlElement *styleElement = (styleRootElement->InsertEndChild(TiXmlElement(TEXT("WordsStyle"))))->ToElement(); TiXmlElement *styleElement = (styleRootElement->InsertEndChild(TiXmlElement(TEXT("WordsStyle"))))->ToElement();
Style style2Write = userLang->_styles.getStyler(i);
if (style2Write._styleID == -1) if (style2Write._styleID == -1)
continue; continue;
@ -7322,7 +7285,7 @@ void NppParameters::insertUserLang2Tree(TiXmlNode *node, UserLangContainer *user
styleElement->SetAttribute(TEXT("colorStyle"), style2Write._colorStyle); styleElement->SetAttribute(TEXT("colorStyle"), style2Write._colorStyle);
} }
if (style2Write._fontName) if (!style2Write._fontName.empty())
{ {
styleElement->SetAttribute(TEXT("fontName"), style2Write._fontName); styleElement->SetAttribute(TEXT("fontName"), style2Write._fontName);
} }
@ -7348,43 +7311,6 @@ void NppParameters::insertUserLang2Tree(TiXmlNode *node, UserLangContainer *user
} }
} }
void NppParameters::stylerStrOp(bool op)
{
for (int i = 0 ; i < _nbUserLang ; ++i)
{
for (int j = 0 ; j < SCE_USER_STYLE_TOTAL_STYLES ; ++j)
{
Style & style = _userLangArray[i]->_styles.getStyler(j);
if (op == DUP)
{
const size_t strLen = lstrlen(style._styleDesc) + 1;
TCHAR *str = new TCHAR[strLen];
wcscpy_s(str, strLen, style._styleDesc);
style._styleDesc = str;
if (style._fontName)
{
const size_t strLen2 = lstrlen(style._fontName) + 1;
str = new TCHAR[strLen2];
wcscpy_s(str, strLen2, style._fontName);
style._fontName = str;
}
else
{
str = new TCHAR[2];
str[0] = str[1] = '\0';
style._fontName = str;
}
}
else
{
delete [] style._styleDesc;
delete [] style._fontName;
}
}
}
}
void NppParameters::addUserModifiedIndex(size_t index) void NppParameters::addUserModifiedIndex(size_t index)
{ {
size_t len = _customizedShortcuts.size(); size_t len = _customizedShortcuts.size();

View File

@ -380,81 +380,21 @@ const int COLORSTYLE_ALL = COLORSTYLE_FOREGROUND|COLORSTYLE_BACKGROUND;
struct Style struct Style final
{ {
int _styleID = -1; int _styleID = STYLE_NOT_USED;
const TCHAR* _styleDesc = nullptr; generic_string _styleDesc;
COLORREF _fgColor = COLORREF(STYLE_NOT_USED); COLORREF _fgColor = COLORREF(STYLE_NOT_USED);
COLORREF _bgColor = COLORREF(STYLE_NOT_USED); COLORREF _bgColor = COLORREF(STYLE_NOT_USED);
int _colorStyle = COLORSTYLE_ALL; int _colorStyle = COLORSTYLE_ALL;
const TCHAR* _fontName = nullptr; generic_string _fontName;
int _fontStyle = FONTSTYLE_NONE; int _fontStyle = FONTSTYLE_NONE;
int _fontSize = STYLE_NOT_USED; int _fontSize = STYLE_NOT_USED;
int _nesting = FONTSTYLE_NONE; int _nesting = FONTSTYLE_NONE;
int _keywordClass = STYLE_NOT_USED; int _keywordClass = STYLE_NOT_USED;
generic_string* _keywords = nullptr; generic_string _keywords;
Style() = default;
Style(const Style & style)
{
_styleID = style._styleID;
_styleDesc = style._styleDesc;
_fgColor = style._fgColor;
_bgColor = style._bgColor;
_colorStyle = style._colorStyle;
_fontName = style._fontName;
_fontSize = style._fontSize;
_fontStyle = style._fontStyle;
_keywordClass = style._keywordClass;
_nesting = style._nesting;
_keywords = (style._keywords) ? new generic_string(*(style._keywords)) : nullptr;
}
~Style()
{
delete _keywords;
}
Style& operator = (const Style & style)
{
if (this != &style)
{
_styleID = style._styleID;
_styleDesc = style._styleDesc;
_fgColor = style._fgColor;
_bgColor = style._bgColor;
_colorStyle = style._colorStyle;
_fontName = style._fontName;
_fontSize = style._fontSize;
_fontStyle = style._fontStyle;
_keywordClass = style._keywordClass;
_nesting = style._nesting;
if (!(_keywords) && style._keywords)
_keywords = new generic_string(*(style._keywords));
else if (_keywords && style._keywords)
_keywords->assign(*(style._keywords));
else if (_keywords && !(style._keywords))
{
delete (_keywords);
_keywords = nullptr;
}
}
return *this;
}
void setKeywords(const TCHAR *str)
{
if (!_keywords)
_keywords = new generic_string(str);
else
*_keywords = str;
}
}; };
@ -470,70 +410,53 @@ struct GlobalOverride final
bool enableUnderLine = false; bool enableUnderLine = false;
}; };
const int STYLE_ARR_MAX_SIZE = 31;
struct StyleArray struct StyleArray
{ {
public: //auto size() const { return _styleVect.size(); }
StyleArray & operator=(const StyleArray & sa) auto begin() { return _styleVect.begin(); }
{ auto end() { return _styleVect.end(); }
if (this != &sa) void clear() { _styleVect.clear(); }
{
this->_nbStyler = sa._nbStyler;
for (int i = 0 ; i < _nbStyler ; ++i)
{
this->_styleVect[i] = sa._styleVect[i];
}
}
return *this;
}
int getNbStyler() const {return _nbStyler;}; Style & getStyler(size_t index)
void setNbStyler(int nb) {_nbStyler = nb;};
Style& getStyler(size_t index)
{ {
assert(index < STYLE_ARR_MAX_SIZE); assert(index < _styleVect.size());
return _styleVect[index]; return _styleVect[index];
} }
bool hasEnoughSpace() {return (_nbStyler < STYLE_ARR_MAX_SIZE);};
void addStyler(int styleID, TiXmlNode *styleNode); void addStyler(int styleID, TiXmlNode *styleNode);
void addStyler(int styleID, const TCHAR *styleName) void addStyler(int styleID, const generic_string & styleName)
{ {
_styleVect[styleID]._styleID = styleID; _styleVect.emplace_back();
_styleVect[styleID]._styleDesc = styleName; Style & s = _styleVect.back();
_styleVect[styleID]._fgColor = black; s._styleID = styleID;
_styleVect[styleID]._bgColor = white; s._styleDesc = styleName;
++_nbStyler; s._fgColor = black;
s._bgColor = white;
} }
int getStylerIndexByID(int id) Style * findByID(int id)
{ {
for (int i = 0 ; i < _nbStyler ; ++i) for (size_t i = 0 ; i < _styleVect.size() ; ++i)
{ {
if (_styleVect[i]._styleID == id) if (_styleVect[i]._styleID == id)
return i; return &(_styleVect[i]);
} }
return -1; return nullptr;
} }
int getStylerIndexByName(const TCHAR *name) const Style * findByName(const generic_string & name)
{ {
if (!name) for (size_t i = 0 ; i < _styleVect.size() ; ++i)
return -1;
for (int i = 0 ; i < _nbStyler ; ++i)
{ {
if (!lstrcmp(_styleVect[i]._styleDesc, name)) if (_styleVect[i]._styleDesc == name)
return i; return &(_styleVect[i]);
} }
return -1; return nullptr;
} }
protected: protected:
std::vector<Style> _styleVect = std::vector<Style>(STYLE_ARR_MAX_SIZE); std::vector<Style> _styleVect;
int _nbStyler = 0;
}; };
@ -579,49 +502,33 @@ private :
const int MAX_LEXER_STYLE = 100;
struct LexerStylerArray struct LexerStylerArray
{ {
public : size_t getNbLexer() const { return _lexerStylerVect.size(); }
LexerStylerArray() : _nbLexerStyler(0){}; void clear() { _lexerStylerVect.clear(); }
LexerStylerArray & operator=(const LexerStylerArray & lsa) LexerStyler & getLexerFromIndex(size_t index)
{
if (this != &lsa)
{
this->_nbLexerStyler = lsa._nbLexerStyler;
for (int i = 0 ; i < this->_nbLexerStyler ; ++i)
this->_lexerStylerVect[i] = lsa._lexerStylerVect[i];
}
return *this;
}
int getNbLexer() const {return _nbLexerStyler;};
LexerStyler & getLexerFromIndex(int index)
{ {
assert(index < _lexerStylerVect.size());
return _lexerStylerVect[index]; return _lexerStylerVect[index];
}; };
const TCHAR * getLexerNameFromIndex(int index) const {return _lexerStylerVect[index].getLexerName();} const TCHAR * getLexerNameFromIndex(size_t index) const { return _lexerStylerVect[index].getLexerName(); }
const TCHAR * getLexerDescFromIndex(int index) const {return _lexerStylerVect[index].getLexerDesc();} const TCHAR * getLexerDescFromIndex(size_t index) const { return _lexerStylerVect[index].getLexerDesc(); }
LexerStyler * getLexerStylerByName(const TCHAR *lexerName) { LexerStyler * getLexerStylerByName(const TCHAR *lexerName) {
if (!lexerName) return NULL; if (!lexerName) return nullptr;
for (int i = 0 ; i < _nbLexerStyler ; ++i) for (size_t i = 0 ; i < _lexerStylerVect.size() ; ++i)
{ {
if (!lstrcmp(_lexerStylerVect[i].getLexerName(), lexerName)) if (!lstrcmp(_lexerStylerVect[i].getLexerName(), lexerName))
return &(_lexerStylerVect[i]); return &(_lexerStylerVect[i]);
} }
return NULL; return nullptr;
}; };
bool hasEnoughSpace() {return (_nbLexerStyler < MAX_LEXER_STYLE);};
void addLexerStyler(const TCHAR *lexerName, const TCHAR *lexerDesc, const TCHAR *lexerUserExt, TiXmlNode *lexerNode); void addLexerStyler(const TCHAR *lexerName, const TCHAR *lexerDesc, const TCHAR *lexerUserExt, TiXmlNode *lexerNode);
void eraseAll();
private : private :
std::vector<LexerStyler> _lexerStylerVect = std::vector<LexerStyler>(MAX_LEXER_STYLE); std::vector<LexerStyler> _lexerStylerVect;
int _nbLexerStyler;
}; };
@ -1107,10 +1014,8 @@ public:
this->_forcePureLC = ulc._forcePureLC; this->_forcePureLC = ulc._forcePureLC;
this->_decimalSeparator = ulc._decimalSeparator; this->_decimalSeparator = ulc._decimalSeparator;
this->_foldCompact = ulc._foldCompact; this->_foldCompact = ulc._foldCompact;
int nbStyler = this->_styles.getNbStyler(); for (Style & st : this->_styles)
for (int i = 0 ; i < nbStyler ; ++i)
{ {
Style & st = this->_styles.getStyler(i);
if (st._bgColor == COLORREF(-1)) if (st._bgColor == COLORREF(-1))
st._bgColor = white; st._bgColor = white;
if (st._fgColor == COLORREF(-1)) if (st._fgColor == COLORREF(-1))
@ -1375,8 +1280,6 @@ struct UdlXmlFileState final {
}; };
const int NB_LANG = 100; const int NB_LANG = 100;
const bool DUP = true;
const bool FREE = false;
const int RECENTFILES_SHOWFULLPATH = -1; const int RECENTFILES_SHOWFULLPATH = -1;
const int RECENTFILES_SHOWONLYFILENAME = 0; const int RECENTFILES_SHOWONLYFILENAME = 0;
@ -1958,14 +1861,13 @@ private:
void getActions(TiXmlNode *node, Macro & macro); void getActions(TiXmlNode *node, Macro & macro);
bool getShortcuts(TiXmlNode *node, Shortcut & sc); bool getShortcuts(TiXmlNode *node, Shortcut & sc);
void writeStyle2Element(Style & style2Write, Style & style2Sync, TiXmlElement *element); void writeStyle2Element(const Style & style2Write, Style & style2Sync, TiXmlElement *element);
void insertUserLang2Tree(TiXmlNode *node, UserLangContainer *userLang); void insertUserLang2Tree(TiXmlNode *node, UserLangContainer *userLang);
void insertCmd(TiXmlNode *cmdRoot, const CommandShortcut & cmd); void insertCmd(TiXmlNode *cmdRoot, const CommandShortcut & cmd);
void insertMacro(TiXmlNode *macrosRoot, const MacroShortcut & macro); void insertMacro(TiXmlNode *macrosRoot, const MacroShortcut & macro);
void insertUserCmd(TiXmlNode *userCmdRoot, const UserCommand & userCmd); void insertUserCmd(TiXmlNode *userCmdRoot, const UserCommand & userCmd);
void insertScintKey(TiXmlNode *scintKeyRoot, const ScintillaKeyMap & scintKeyMap); void insertScintKey(TiXmlNode *scintKeyRoot, const ScintillaKeyMap & scintKeyMap);
void insertPluginCmd(TiXmlNode *pluginCmdRoot, const PluginCmdShortcut & pluginCmd); void insertPluginCmd(TiXmlNode *pluginCmdRoot, const PluginCmdShortcut & pluginCmd);
void stylerStrOp(bool op);
TiXmlElement * insertGUIConfigBoolNode(TiXmlNode *r2w, const TCHAR *name, bool bVal); TiXmlElement * insertGUIConfigBoolNode(TiXmlNode *r2w, const TCHAR *name, bool bVal);
void insertDockingParamNode(TiXmlNode *GUIRoot); void insertDockingParamNode(TiXmlNode *GUIRoot);
void writeExcludedLangList(TiXmlElement *element); void writeExcludedLangList(TiXmlElement *element);

View File

@ -4259,43 +4259,40 @@ void Finder::setFinderStyle()
LexerStyler *pStyler = (NppParameters::getInstance().getLStylerArray()).getLexerStylerByName(lexerName); LexerStyler *pStyler = (NppParameters::getInstance().getLStylerArray()).getLexerStylerByName(lexerName);
if (pStyler) if (pStyler)
{ {
int i = pStyler->getStylerIndexByID(SCE_SEARCHRESULT_CURRENT_LINE); const Style * pStyle = pStyler->findByID(SCE_SEARCHRESULT_CURRENT_LINE);
if (i != -1) if (pStyle)
{ {
Style & style = pStyler->getStyler(i); _scintView.execute(SCI_SETCARETLINEBACK, pStyle->_bgColor);
_scintView.execute(SCI_SETCARETLINEBACK, style._bgColor);
} }
} }
_scintView.setSearchResultLexer(); _scintView.setSearchResultLexer();
// Override foreground & background colour by default foreground & background coulour // Override foreground & background colour by default foreground & background coulour
StyleArray & stylers = NppParameters::getInstance().getMiscStylerArray(); StyleArray & stylers = NppParameters::getInstance().getMiscStylerArray();
int iStyleDefault = stylers.getStylerIndexByID(STYLE_DEFAULT); Style * pStyleDefault = stylers.findByID(STYLE_DEFAULT);
if (iStyleDefault != -1) if (pStyleDefault)
{ {
Style & styleDefault = stylers.getStyler(iStyleDefault); _scintView.setStyle(*pStyleDefault);
_scintView.setStyle(styleDefault);
GlobalOverride & go = NppParameters::getInstance().getGlobalOverrideStyle(); GlobalOverride & go = NppParameters::getInstance().getGlobalOverrideStyle();
if (go.isEnable()) if (go.isEnable())
{ {
int iGlobalOverride = stylers.getStylerIndexByName(TEXT("Global override")); const Style * pStyleGlobalOverride = stylers.findByName(TEXT("Global override"));
if (iGlobalOverride != -1) if (pStyleGlobalOverride)
{ {
Style & styleGlobalOverride = stylers.getStyler(iGlobalOverride);
if (go.enableFg) if (go.enableFg)
{ {
styleDefault._fgColor = styleGlobalOverride._fgColor; pStyleDefault->_fgColor = pStyleGlobalOverride->_fgColor;
} }
if (go.enableBg) if (go.enableBg)
{ {
styleDefault._bgColor = styleGlobalOverride._bgColor; pStyleDefault->_bgColor = pStyleGlobalOverride->_bgColor;
} }
} }
} }
_scintView.execute(SCI_STYLESETFORE, SCE_SEARCHRESULT_DEFAULT, styleDefault._fgColor); _scintView.execute(SCI_STYLESETFORE, SCE_SEARCHRESULT_DEFAULT, pStyleDefault->_fgColor);
_scintView.execute(SCI_STYLESETBACK, SCE_SEARCHRESULT_DEFAULT, styleDefault._bgColor); _scintView.execute(SCI_STYLESETBACK, SCE_SEARCHRESULT_DEFAULT, pStyleDefault->_bgColor);
} }
_scintView.execute(SCI_COLOURISE, 0, -1); _scintView.execute(SCI_COLOURISE, 0, -1);

View File

@ -513,18 +513,16 @@ void ScintillaEditView::setSpecialStyle(const Style & styleToSet)
if ( styleToSet._colorStyle & COLORSTYLE_BACKGROUND ) if ( styleToSet._colorStyle & COLORSTYLE_BACKGROUND )
execute(SCI_STYLESETBACK, styleID, styleToSet._bgColor); execute(SCI_STYLESETBACK, styleID, styleToSet._bgColor);
if (styleToSet._fontName && lstrcmp(styleToSet._fontName, TEXT("")) != 0) if (!styleToSet._fontName.empty())
{ {
WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance();
if (!NppParameters::getInstance().isInFontList(styleToSet._fontName)) if (!NppParameters::getInstance().isInFontList(styleToSet._fontName))
{ {
execute(SCI_STYLESETFONT, styleID, reinterpret_cast<LPARAM>(DEFAULT_FONT_NAME)); execute(SCI_STYLESETFONT, styleID, reinterpret_cast<LPARAM>(DEFAULT_FONT_NAME));
} }
else else
{ {
const char * fontNameA = wmc.wchar2char(styleToSet._fontName, CP_UTF8); std::string fontNameA = wstring2string(styleToSet._fontName, CP_UTF8);
execute(SCI_STYLESETFONT, styleID, reinterpret_cast<LPARAM>(fontNameA)); execute(SCI_STYLESETFONT, styleID, reinterpret_cast<LPARAM>(fontNameA.c_str()));
} }
} }
int fontStyle = styleToSet._fontStyle; int fontStyle = styleToSet._fontStyle;
@ -558,18 +556,15 @@ void ScintillaEditView::setStyle(Style styleToSet)
if (go.isEnable()) if (go.isEnable())
{ {
StyleArray & stylers = NppParameters::getInstance().getMiscStylerArray(); const Style * pStyle = NppParameters::getInstance().getMiscStylerArray().findByName(TEXT("Global override"));
int i = stylers.getStylerIndexByName(TEXT("Global override")); if (pStyle)
if (i != -1)
{ {
Style & style = stylers.getStyler(i);
if (go.enableFg) if (go.enableFg)
{ {
if (style._colorStyle & COLORSTYLE_FOREGROUND) if (pStyle->_colorStyle & COLORSTYLE_FOREGROUND)
{ {
styleToSet._colorStyle |= COLORSTYLE_FOREGROUND; styleToSet._colorStyle |= COLORSTYLE_FOREGROUND;
styleToSet._fgColor = style._fgColor; styleToSet._fgColor = pStyle->_fgColor;
} }
else else
{ {
@ -582,10 +577,10 @@ void ScintillaEditView::setStyle(Style styleToSet)
if (go.enableBg) if (go.enableBg)
{ {
if (style._colorStyle & COLORSTYLE_BACKGROUND) if (pStyle->_colorStyle & COLORSTYLE_BACKGROUND)
{ {
styleToSet._colorStyle |= COLORSTYLE_BACKGROUND; styleToSet._colorStyle |= COLORSTYLE_BACKGROUND;
styleToSet._bgColor = style._bgColor; styleToSet._bgColor = pStyle->_bgColor;
} }
else else
{ {
@ -595,30 +590,30 @@ void ScintillaEditView::setStyle(Style styleToSet)
styleToSet._colorStyle &= ~COLORSTYLE_BACKGROUND; styleToSet._colorStyle &= ~COLORSTYLE_BACKGROUND;
} }
} }
if (go.enableFont && style._fontName && style._fontName[0]) if (go.enableFont && !pStyle->_fontName.empty())
styleToSet._fontName = style._fontName; styleToSet._fontName = pStyle->_fontName;
if (go.enableFontSize && (style._fontSize > 0)) if (go.enableFontSize && (pStyle->_fontSize > 0))
styleToSet._fontSize = style._fontSize; styleToSet._fontSize = pStyle->_fontSize;
if (style._fontStyle != STYLE_NOT_USED) if (pStyle->_fontStyle != STYLE_NOT_USED)
{ {
if (go.enableBold) if (go.enableBold)
{ {
if (style._fontStyle & FONTSTYLE_BOLD) if (pStyle->_fontStyle & FONTSTYLE_BOLD)
styleToSet._fontStyle |= FONTSTYLE_BOLD; styleToSet._fontStyle |= FONTSTYLE_BOLD;
else else
styleToSet._fontStyle &= ~FONTSTYLE_BOLD; styleToSet._fontStyle &= ~FONTSTYLE_BOLD;
} }
if (go.enableItalic) if (go.enableItalic)
{ {
if (style._fontStyle & FONTSTYLE_ITALIC) if (pStyle->_fontStyle & FONTSTYLE_ITALIC)
styleToSet._fontStyle |= FONTSTYLE_ITALIC; styleToSet._fontStyle |= FONTSTYLE_ITALIC;
else else
styleToSet._fontStyle &= ~FONTSTYLE_ITALIC; styleToSet._fontStyle &= ~FONTSTYLE_ITALIC;
} }
if (go.enableUnderLine) if (go.enableUnderLine)
{ {
if (style._fontStyle & FONTSTYLE_UNDERLINE) if (pStyle->_fontStyle & FONTSTYLE_UNDERLINE)
styleToSet._fontStyle |= FONTSTYLE_UNDERLINE; styleToSet._fontStyle |= FONTSTYLE_UNDERLINE;
else else
styleToSet._fontStyle &= ~FONTSTYLE_UNDERLINE; styleToSet._fontStyle &= ~FONTSTYLE_UNDERLINE;
@ -864,15 +859,13 @@ void ScintillaEditView::setUserLexer(const TCHAR *userLangName)
sprintf(intBuffer, "%" PRIuPTR, reinterpret_cast<uintptr_t>(_currentBufferID)); // use numeric value of BufferID pointer sprintf(intBuffer, "%" PRIuPTR, reinterpret_cast<uintptr_t>(_currentBufferID)); // use numeric value of BufferID pointer
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("userDefine.currentBufferID"), reinterpret_cast<LPARAM>(intBuffer)); execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>("userDefine.currentBufferID"), reinterpret_cast<LPARAM>(intBuffer));
for (int i = 0 ; i < SCE_USER_STYLE_TOTAL_STYLES ; ++i) for (const Style & style : userLangContainer->_styles)
{ {
Style & style = userLangContainer->_styles.getStyler(i);
if (style._styleID == STYLE_NOT_USED) if (style._styleID == STYLE_NOT_USED)
continue; continue;
char nestingBuffer[32]; char nestingBuffer[32];
sprintf(nestingBuffer, "userDefine.nesting.%02d", i ); sprintf(nestingBuffer, "userDefine.nesting.%02d", style._styleID);
sprintf(intBuffer, "%d", style._nesting); sprintf(intBuffer, "%d", style._nesting);
execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>(nestingBuffer), reinterpret_cast<LPARAM>(intBuffer)); execute(SCI_SETPROPERTY, reinterpret_cast<WPARAM>(nestingBuffer), reinterpret_cast<LPARAM>(intBuffer));
@ -893,18 +886,16 @@ void ScintillaEditView::setExternalLexer(LangType typeDoc)
LexerStyler *pStyler = (NppParameters::getInstance().getLStylerArray()).getLexerStylerByName(name); LexerStyler *pStyler = (NppParameters::getInstance().getLStylerArray()).getLexerStylerByName(name);
if (pStyler) if (pStyler)
{ {
for (int i = 0 ; i < pStyler->getNbStyler() ; ++i) for (const Style & style : *pStyler)
{ {
Style & style = pStyler->getStyler(i);
setStyle(style); setStyle(style);
if (style._keywordClass >= 0 && style._keywordClass <= KEYWORDSET_MAX) if (style._keywordClass >= 0 && style._keywordClass <= KEYWORDSET_MAX)
{ {
basic_string<char> keywordList(""); basic_string<char> keywordList("");
if (style._keywords) if (!style._keywords.empty())
{ {
keywordList = wstring2string(*(style._keywords), CP_ACP); keywordList = wstring2string(style._keywords, CP_ACP);
} }
execute(SCI_SETKEYWORDS, style._keywordClass, reinterpret_cast<LPARAM>(getCompleteKeywordList(keywordList, typeDoc, style._keywordClass))); execute(SCI_SETKEYWORDS, style._keywordClass, reinterpret_cast<LPARAM>(getCompleteKeywordList(keywordList, typeDoc, style._keywordClass)));
} }
@ -982,9 +973,8 @@ void ScintillaEditView::setJsLexer()
LexerStyler *pNewStyler = (NppParameters::getInstance().getLStylerArray()).getLexerStylerByName(newLexerName); LexerStyler *pNewStyler = (NppParameters::getInstance().getLStylerArray()).getLexerStylerByName(newLexerName);
if (pNewStyler) // New js styler is available, so we can use it do more modern styling if (pNewStyler) // New js styler is available, so we can use it do more modern styling
{ {
for (int i = 0, nb = pNewStyler->getNbStyler(); i < nb; ++i) for (const Style & style : *pNewStyler)
{ {
Style & style = pNewStyler->getStyler(i);
setStyle(style); setStyle(style);
} }
@ -1024,9 +1014,8 @@ void ScintillaEditView::setJsLexer()
if (pOldStyler) if (pOldStyler)
{ {
for (int i = 0, nb = pOldStyler->getNbStyler(); i < nb; ++i) for (Style style : *pOldStyler) //not by reference, but copy
{ {
Style style = pOldStyler->getStyler(i); //not by reference, but copy
int cppID = style._styleID; int cppID = style._styleID;
switch (style._styleID) switch (style._styleID)
@ -1293,14 +1282,13 @@ void ScintillaEditView::makeStyle(LangType language, const TCHAR **keywordArray)
LexerStyler *pStyler = (NppParameters::getInstance().getLStylerArray()).getLexerStylerByName(lexerName); LexerStyler *pStyler = (NppParameters::getInstance().getLStylerArray()).getLexerStylerByName(lexerName);
if (pStyler) if (pStyler)
{ {
for (int i = 0, nb = pStyler->getNbStyler(); i < nb ; ++i) for (const Style & style : *pStyler)
{ {
Style & style = pStyler->getStyler(i);
setStyle(style); setStyle(style);
if (keywordArray) if (keywordArray)
{ {
if ((style._keywordClass != STYLE_NOT_USED) && (style._keywords)) if ((style._keywordClass != STYLE_NOT_USED) && (!style._keywords.empty()))
keywordArray[style._keywordClass] = style._keywords->c_str(); keywordArray[style._keywordClass] = style._keywords.c_str();
} }
} }
} }
@ -1359,120 +1347,69 @@ void ScintillaEditView::setWordChars()
void ScintillaEditView::defineDocType(LangType typeDoc) void ScintillaEditView::defineDocType(LangType typeDoc)
{ {
StyleArray & stylers = NppParameters::getInstance().getMiscStylerArray(); StyleArray & stylers = NppParameters::getInstance().getMiscStylerArray();
int iStyleDefault = stylers.getStylerIndexByID(STYLE_DEFAULT); Style * pStyleDefault = stylers.findByID(STYLE_DEFAULT);
if (iStyleDefault != -1) if (pStyleDefault)
{ {
Style & styleDefault = stylers.getStyler(iStyleDefault); pStyleDefault->_colorStyle = COLORSTYLE_ALL; //override transparency
styleDefault._colorStyle = COLORSTYLE_ALL; //override transparency setStyle(*pStyleDefault);
setStyle(styleDefault); }
}
execute(SCI_STYLECLEARALL); execute(SCI_STYLECLEARALL);
Style *pStyle;
Style defaultIndicatorStyle; Style defaultIndicatorStyle;
const Style * pStyle;
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE; defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE;
defaultIndicatorStyle._bgColor = red; defaultIndicatorStyle._bgColor = red;
pStyle = &defaultIndicatorStyle; pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
int iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE); setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_SMART; defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_SMART;
defaultIndicatorStyle._bgColor = liteGreen; defaultIndicatorStyle._bgColor = liteGreen;
pStyle = &defaultIndicatorStyle; pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_SMART); setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_INC; defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_INC;
defaultIndicatorStyle._bgColor = blue; defaultIndicatorStyle._bgColor = blue;
pStyle = &defaultIndicatorStyle; pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_INC); setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_TAGMATCH; defaultIndicatorStyle._styleID = SCE_UNIVERSAL_TAGMATCH;
defaultIndicatorStyle._bgColor = RGB(0x80, 0x00, 0xFF); defaultIndicatorStyle._bgColor = RGB(0x80, 0x00, 0xFF);
pStyle = &defaultIndicatorStyle; pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_TAGMATCH); setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_TAGATTR; defaultIndicatorStyle._styleID = SCE_UNIVERSAL_TAGATTR;
defaultIndicatorStyle._bgColor = yellow; defaultIndicatorStyle._bgColor = yellow;
pStyle = &defaultIndicatorStyle; pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_TAGATTR); setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT1; defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT1;
defaultIndicatorStyle._bgColor = cyan; defaultIndicatorStyle._bgColor = cyan;
pStyle = &defaultIndicatorStyle; pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT1); setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT2; defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT2;
defaultIndicatorStyle._bgColor = orange; defaultIndicatorStyle._bgColor = orange;
pStyle = &defaultIndicatorStyle; pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT2); setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT3; defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT3;
defaultIndicatorStyle._bgColor = yellow; defaultIndicatorStyle._bgColor = yellow;
pStyle = &defaultIndicatorStyle; pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT3); setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT4; defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT4;
defaultIndicatorStyle._bgColor = purple; defaultIndicatorStyle._bgColor = purple;
pStyle = &defaultIndicatorStyle; pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT4); setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT5; defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT5;
defaultIndicatorStyle._bgColor = darkGreen; defaultIndicatorStyle._bgColor = darkGreen;
pStyle = &defaultIndicatorStyle; pStyle = stylers.findByID(defaultIndicatorStyle._styleID);
iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT5); setSpecialIndicator(pStyle ? *pStyle : defaultIndicatorStyle);
if (iFind != -1)
{
pStyle = &(stylers.getStyler(iFind));
}
setSpecialIndicator(*pStyle);
// Il faut surtout faire un test ici avant d'exécuter SCI_SETCODEPAGE // Il faut surtout faire un test ici avant d'exécuter SCI_SETCODEPAGE
// Sinon y'aura un soucis de performance! // Sinon y'aura un soucis de performance!
@ -1554,13 +1491,12 @@ void ScintillaEditView::defineDocType(LangType typeDoc)
if (pStyler) if (pStyler)
{ {
int i = pStyler->getStylerIndexByName(TEXT("DEFAULT")); const Style * pStyle = pStyler->findByName(TEXT("DEFAULT"));
if (i != -1) if (pStyle)
{ {
Style & style = pStyler->getStyler(i); nfoStyle._bgColor = pStyle->_bgColor;
nfoStyle._bgColor = style._bgColor; nfoStyle._fgColor = pStyle->_fgColor;
nfoStyle._fgColor = style._fgColor; nfoStyle._colorStyle = pStyle->_colorStyle;
nfoStyle._colorStyle = style._colorStyle;
} }
} }
setSpecialStyle(nfoStyle); setSpecialStyle(nfoStyle);
@ -1769,32 +1705,28 @@ void ScintillaEditView::defineDocType(LangType typeDoc)
} }
//All the global styles should put here //All the global styles should put here
int indexOfIndentGuide = stylers.getStylerIndexByID(STYLE_INDENTGUIDE); pStyle = stylers.findByID(STYLE_INDENTGUIDE);
if (indexOfIndentGuide != -1) if (pStyle)
{ {
Style & styleIG = stylers.getStyler(indexOfIndentGuide); setStyle(*pStyle);
setStyle(styleIG); }
} pStyle = stylers.findByID(STYLE_BRACELIGHT);
int indexOfBraceLight = stylers.getStylerIndexByID(STYLE_BRACELIGHT); if (pStyle)
if (indexOfBraceLight != -1) {
{ setStyle(*pStyle);
Style & styleBL = stylers.getStyler(indexOfBraceLight); }
setStyle(styleBL);
}
//setStyle(STYLE_CONTROLCHAR, liteGrey); //setStyle(STYLE_CONTROLCHAR, liteGrey);
int indexBadBrace = stylers.getStylerIndexByID(STYLE_BRACEBAD); pStyle = stylers.findByID(STYLE_BRACEBAD);
if (indexBadBrace != -1) if (pStyle)
{ {
Style & styleBB = stylers.getStyler(indexBadBrace); setStyle(*pStyle);
setStyle(styleBB); }
} pStyle = stylers.findByID(STYLE_LINENUMBER);
int indexLineNumber = stylers.getStylerIndexByID(STYLE_LINENUMBER); if (pStyle)
if (indexLineNumber != -1) {
{ setSpecialStyle(*pStyle);
Style & styleLN = stylers.getStyler(indexLineNumber); }
setSpecialStyle(styleLN); setTabSettings(NppParameters::getInstance().getLangFromID(typeDoc));
}
setTabSettings(NppParameters::getInstance().getLangFromID(typeDoc));
if (svp._indentGuideLineShow) if (svp._indentGuideLineShow)
{ {
@ -2617,21 +2549,19 @@ void ScintillaEditView::performGlobalStyles()
NppParameters& nppParams = NppParameters::getInstance(); NppParameters& nppParams = NppParameters::getInstance();
StyleArray & stylers = nppParams.getMiscStylerArray(); StyleArray & stylers = nppParams.getMiscStylerArray();
int i = stylers.getStylerIndexByName(TEXT("Current line background colour")); const Style * pStyle = stylers.findByName(TEXT("Current line background colour"));
if (i != -1) if (pStyle)
{ {
Style & style = stylers.getStyler(i); execute(SCI_SETCARETLINEBACK, pStyle->_bgColor);
execute(SCI_SETCARETLINEBACK, style._bgColor);
} }
COLORREF selectColorBack = grey; COLORREF selectColorBack = grey;
COLORREF selectColorFore = black; COLORREF selectColorFore = black;
i = stylers.getStylerIndexByName(TEXT("Selected text colour")); pStyle = stylers.findByName(TEXT("Selected text colour"));
if (i != -1) if (pStyle)
{ {
Style & style = stylers.getStyler(i); selectColorBack = pStyle->_bgColor;
selectColorBack = style._bgColor; selectColorFore = pStyle->_fgColor;
selectColorFore = style._fgColor;
} }
execute(SCI_SETSELBACK, 1, selectColorBack); execute(SCI_SETSELBACK, 1, selectColorBack);
@ -2639,61 +2569,55 @@ void ScintillaEditView::performGlobalStyles()
execute(SCI_SETSELFORE, 1, selectColorFore); execute(SCI_SETSELFORE, 1, selectColorFore);
COLORREF caretColor = black; COLORREF caretColor = black;
i = stylers.getStylerIndexByID(SCI_SETCARETFORE); pStyle = stylers.findByID(SCI_SETCARETFORE);
if (i != -1) if (pStyle)
{ {
Style & style = stylers.getStyler(i); caretColor = pStyle->_fgColor;
caretColor = style._fgColor;
} }
execute(SCI_SETCARETFORE, caretColor); execute(SCI_SETCARETFORE, caretColor);
COLORREF edgeColor = liteGrey; COLORREF edgeColor = liteGrey;
i = stylers.getStylerIndexByName(TEXT("Edge colour")); pStyle = stylers.findByName(TEXT("Edge colour"));
if (i != -1) if (pStyle)
{ {
Style & style = stylers.getStyler(i); edgeColor = pStyle->_fgColor;
edgeColor = style._fgColor;
} }
execute(SCI_SETEDGECOLOUR, edgeColor); execute(SCI_SETEDGECOLOUR, edgeColor);
::SendMessage(_hParent, NPPM_INTERNAL_EDGEMULTISETSIZE, 0, 0); ::SendMessage(_hParent, NPPM_INTERNAL_EDGEMULTISETSIZE, 0, 0);
COLORREF foldMarginColor = grey; COLORREF foldMarginColor = grey;
COLORREF foldMarginHiColor = white; COLORREF foldMarginHiColor = white;
i = stylers.getStylerIndexByName(TEXT("Fold margin")); pStyle = stylers.findByName(TEXT("Fold margin"));
if (i != -1) if (pStyle)
{ {
Style & style = stylers.getStyler(i); foldMarginHiColor = pStyle->_fgColor;
foldMarginHiColor = style._fgColor; foldMarginColor = pStyle->_bgColor;
foldMarginColor = style._bgColor;
} }
execute(SCI_SETFOLDMARGINCOLOUR, true, foldMarginColor); execute(SCI_SETFOLDMARGINCOLOUR, true, foldMarginColor);
execute(SCI_SETFOLDMARGINHICOLOUR, true, foldMarginHiColor); execute(SCI_SETFOLDMARGINHICOLOUR, true, foldMarginHiColor);
COLORREF bookmarkMarginColor = veryLiteGrey; COLORREF bookmarkMarginColor = veryLiteGrey;
i = stylers.getStylerIndexByName(TEXT("Bookmark margin")); pStyle = stylers.findByName(TEXT("Bookmark margin"));
if (i == -1) if (!pStyle)
{ {
int j = stylers.getStylerIndexByName(TEXT("Line number margin")); pStyle = stylers.findByName(TEXT("Line number margin"));
if (j != -1) if (pStyle)
{ {
Style & style = stylers.getStyler(j); bookmarkMarginColor = pStyle->_bgColor;
bookmarkMarginColor = style._bgColor;
} }
} }
else else
{ {
Style & style = stylers.getStyler(i); bookmarkMarginColor = pStyle->_bgColor;
bookmarkMarginColor = style._bgColor;
} }
execute(SCI_SETMARGINTYPEN, _SC_MARGE_SYBOLE, SC_MARGIN_COLOUR); execute(SCI_SETMARGINTYPEN, _SC_MARGE_SYBOLE, SC_MARGIN_COLOUR);
execute(SCI_SETMARGINBACKN, _SC_MARGE_SYBOLE, bookmarkMarginColor); execute(SCI_SETMARGINBACKN, _SC_MARGE_SYBOLE, bookmarkMarginColor);
COLORREF urlHoveredFG = grey; COLORREF urlHoveredFG = grey;
i = stylers.getStylerIndexByName(TEXT("URL hovered")); pStyle = stylers.findByName(TEXT("URL hovered"));
if (i != -1) if (pStyle)
{ {
Style & style = stylers.getStyler(i); urlHoveredFG = pStyle->_fgColor;
urlHoveredFG = style._fgColor;
} }
execute(SCI_INDICSETHOVERFORE, URL_INDIC, urlHoveredFG); execute(SCI_INDICSETHOVERFORE, URL_INDIC, urlHoveredFG);
@ -2707,11 +2631,10 @@ void ScintillaEditView::performGlobalStyles()
execute(SCI_MARKERENABLEHIGHLIGHT, true); execute(SCI_MARKERENABLEHIGHLIGHT, true);
COLORREF wsSymbolFgColor = black; COLORREF wsSymbolFgColor = black;
i = stylers.getStylerIndexByName(TEXT("White space symbol")); pStyle = stylers.findByName(TEXT("White space symbol"));
if (i != -1) if (pStyle)
{ {
Style & style = stylers.getStyler(i); wsSymbolFgColor = pStyle->_fgColor;
wsSymbolFgColor = style._fgColor;
} }
execute(SCI_SETWHITESPACEFORE, true, wsSymbolFgColor); execute(SCI_SETWHITESPACEFORE, true, wsSymbolFgColor);
} }
@ -3785,19 +3708,17 @@ void ScintillaEditView::getFoldColor(COLORREF& fgColor, COLORREF& bgColor, COLOR
{ {
StyleArray & stylers = NppParameters::getInstance().getMiscStylerArray(); StyleArray & stylers = NppParameters::getInstance().getMiscStylerArray();
int i = stylers.getStylerIndexByName(TEXT("Fold")); const Style * pStyle = stylers.findByName(TEXT("Fold"));
if (i != -1) if (pStyle)
{ {
Style & style = stylers.getStyler(i); fgColor = pStyle->_bgColor;
fgColor = style._bgColor; bgColor = pStyle->_fgColor;
bgColor = style._fgColor;
} }
i = stylers.getStylerIndexByName(TEXT("Fold active")); pStyle = stylers.findByName(TEXT("Fold active"));
if (i != -1) if (pStyle)
{ {
Style & style = stylers.getStyler(i); activeFgColor = pStyle->_fgColor;
activeFgColor = style._fgColor;
} }
} }

View File

@ -199,10 +199,6 @@ public:
for (BufferStyleMap::iterator it(_hotspotStyles.begin()); it != _hotspotStyles.end(); ++it ) for (BufferStyleMap::iterator it(_hotspotStyles.begin()); it != _hotspotStyles.end(); ++it )
{ {
for (StyleMap::iterator it2(it->second->begin()) ; it2 != it->second->end() ; ++it2)
{
delete [] it2->second._fontName;
}
delete it->second; delete it->second;
} }
} }

View File

@ -1763,7 +1763,7 @@ INT_PTR CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPAR
::SendMessage(hFontNameCombo, CB_SETITEMDATA, k, reinterpret_cast<LPARAM>(fontlist[j].c_str())); ::SendMessage(hFontNameCombo, CB_SETITEMDATA, k, reinterpret_cast<LPARAM>(fontlist[j].c_str()));
} }
i = ::SendMessage(hFontNameCombo, CB_FINDSTRINGEXACT, static_cast<WPARAM>(-1), reinterpret_cast<LPARAM>(style._fontName)); i = ::SendMessage(hFontNameCombo, CB_FINDSTRINGEXACT, static_cast<WPARAM>(-1), reinterpret_cast<LPARAM>(style._fontName.c_str()));
if (i == CB_ERR) if (i == CB_ERR)
i = 0; i = 0;
::SendMessage(hFontNameCombo, CB_SETCURSEL, i, 0); ::SendMessage(hFontNameCombo, CB_SETCURSEL, i, 0);

View File

@ -146,11 +146,11 @@ INT_PTR CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM l
::EnableWindow(::GetDlgItem(_hSelf, IDOK), _isDirty); ::EnableWindow(::GetDlgItem(_hSelf, IDOK), _isDirty);
::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), FALSE/*!_isSync*/); ::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), FALSE/*!_isSync*/);
loadLangListFromNppParam();
updateGlobalOverrideCtrls(); updateGlobalOverrideCtrls();
setVisualFromStyleList(); setVisualFromStyleList();
goToCenter(); goToCenter();
loadLangListFromNppParam();
return TRUE; return TRUE;
} }
@ -545,7 +545,7 @@ void WordStyleDlg::loadLangListFromNppParam()
::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(TEXT("Global Styles"))); ::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(TEXT("Global Styles")));
// All the lexers // All the lexers
for (int i = 0, nb = _lsArray.getNbLexer() ; i < nb ; ++i) for (size_t i = 0, nb = _lsArray.getNbLexer() ; i < nb ; ++i)
{ {
::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(_lsArray.getLexerDescFromIndex(i))); ::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(_lsArray.getLexerDescFromIndex(i)));
} }
@ -675,7 +675,7 @@ void WordStyleDlg::updateUserKeywords()
len += 1; len += 1;
TCHAR *kw = new TCHAR[len]; TCHAR *kw = new TCHAR[len];
::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_GETTEXT, len, reinterpret_cast<LPARAM>(kw)); ::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_GETTEXT, len, reinterpret_cast<LPARAM>(kw));
style.setKeywords(kw); style._keywords = kw;
delete [] kw; delete [] kw;
} }
@ -808,10 +808,9 @@ void WordStyleDlg::setStyleListFromLexer(int index)
StyleArray & lexerStyler = index?_lsArray.getLexerFromIndex(index-1):_globalStyles; StyleArray & lexerStyler = index?_lsArray.getLexerFromIndex(index-1):_globalStyles;
for (int i = 0, nb = lexerStyler.getNbStyler(); i < nb ; ++i) for (const Style & style : lexerStyler)
{ {
Style & style = lexerStyler.getStyler(i); ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(style._styleDesc.c_str()));
::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(style._styleDesc));
} }
::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_SETCURSEL, 0, 0); ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_SETCURSEL, 0, 0);
setVisualFromStyleList(); setVisualFromStyleList();
@ -824,7 +823,7 @@ void WordStyleDlg::setVisualFromStyleList()
Style & style = getCurrentStyler(); Style & style = getCurrentStyler();
// Global override style // Global override style
if (style._styleDesc && lstrcmp(style._styleDesc, TEXT("Global override")) == 0) if (style._styleDesc == TEXT("Global override"))
{ {
showGlobalOverrideCtrls(true); showGlobalOverrideCtrls(true);
} }
@ -874,7 +873,7 @@ void WordStyleDlg::setVisualFromStyleList()
} }
// Selected text colour style // Selected text colour style
if (style._styleDesc && lstrcmp(style._styleDesc, TEXT("Selected text colour")) == 0) if (style._styleDesc == TEXT("Selected text colour"))
{ {
isEnable = false; // disable by default for "Selected text colour" style isEnable = false; // disable by default for "Selected text colour" style
@ -895,9 +894,9 @@ void WordStyleDlg::setVisualFromStyleList()
//-- font name //-- font name
isEnable = false; isEnable = false;
LRESULT iFontName; LRESULT iFontName;
if (style._fontName != NULL) if (!style._fontName.empty())
{ {
iFontName = ::SendMessage(_hFontNameCombo, CB_FINDSTRING, 1, reinterpret_cast<LPARAM>(style._fontName)); iFontName = ::SendMessage(_hFontNameCombo, CB_FINDSTRING, 1, reinterpret_cast<LPARAM>(style._fontName.c_str()));
if (iFontName == CB_ERR) if (iFontName == CB_ERR)
iFontName = 0; iFontName = 0;
isEnable = true; isEnable = true;
@ -964,7 +963,7 @@ void WordStyleDlg::setVisualFromStyleList()
kws = TEXT(""); kws = TEXT("");
::SendDlgItemMessage(_hSelf, IDC_DEF_KEYWORDS_EDIT, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(kws)); ::SendDlgItemMessage(_hSelf, IDC_DEF_KEYWORDS_EDIT, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(kws));
const TCHAR *ckwStr = (style._keywords)?style._keywords->c_str():TEXT(""); const TCHAR *ckwStr = style._keywords.c_str();
::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(ckwStr)); ::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(ckwStr));
} }