From 115d24e8ab3928220d64491a68704500089fa7a9 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Wed, 10 Jan 2018 17:18:59 +0100 Subject: [PATCH 01/14] + fix: handle "2nd Default Styles" as separate standard (2nd) lexer module --- src/Edit.c | 2 +- src/Notepad3.rc | 2 + src/Styles.c | 296 +++++++++++++++++++++++++----------------------- src/Styles.h | 2 +- 4 files changed, 159 insertions(+), 143 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index 0a2a5108a..7536e086d 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -5492,7 +5492,7 @@ int EditReplaceAllInRange(HWND hwnd, LPCEDITFINDREPLACE lpefr, BOOL bShowInfo, i EditEnterTargetTransaction(); - // @@@ found same ? + // found same ? //if ((iPos >= 0) && (start == (pPosPair->beg + offset)) && (end == (pPosPair->end + offset))) { SciCall_SetTargetRange(start, end); offset += ((int)SendMessage(hwnd, iReplaceMsg, (WPARAM)-1, (LPARAM)pszReplace) - pPosPair->end + pPosPair->beg); diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 96494adbf..2188849f9 100644 --- a/src/Notepad3.rc +++ b/src/Notepad3.rc @@ -1921,6 +1921,8 @@ STRINGTABLE BEGIN 63264 "Hyperlink Hotspots" 63265 "2nd Hyperlink Hotspots" + 63266 "2nd Default Text" + END #endif // English (United States) resources diff --git a/src/Styles.c b/src/Styles.c index 88d2ffaf9..fddd6e4b6 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -62,7 +62,7 @@ KEYWORDLIST KeyWords_NULL = { EDITLEXER lexStandard = { SCLEX_NULL, 63000, L"Default Text", L"txt; text; wtx; log; asc; doc", L"", &KeyWords_NULL, { - /* 0 */ { STYLE_DEFAULT, 63100, L"Default Style", L"font:Default; size:10", L"" }, // ! don't change name "Default Style" + /* 0 */ { STYLE_DEFAULT, 63100, L"Default Style", L"font:Default; size:10", L"" }, /* 1 */ { STYLE_LINENUMBER, 63101, L"Margins and Line Numbers", L"size:-2; fore:#FF0000", L"" }, /* 2 */ { STYLE_BRACELIGHT, 63102, L"Matching Braces (Indicator)", L"fore:#00FF40; alpha:40; alpha2:40; indic_roundbox", L"" }, /* 3 */ { STYLE_BRACEBAD, 63103, L"Matching Braces Error (Indicator)", L"fore:#FF0080; alpha:140; alpha2:140; indic_roundbox", L"" }, @@ -77,25 +77,28 @@ EDITLEXER lexStandard = { SCLEX_NULL, 63000, L"Default Text", L"txt; text; wtx; /* 12 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, 63124, L"Book Marks (Colors)", L"back:#00FF00; alpha:20", L"" }, /* 13 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, 63262, L"Mark Occurrences (Indicator)", L"indic_roundbox", L"" }, /* 14 */ { SCI_SETHOTSPOTACTIVEFORE, 63264, L"Hyperlink Hotspots", L"italic; fore:#0000FF", L"" }, - - /* 15 */ { STYLE_DEFAULT, 63112, L"2nd Default Style", L"font:Courier New; size:10", L"" }, // ! don't change name "2nd Default Style" - /* 16 */ { STYLE_LINENUMBER, 63113, L"2nd Margins and Line Numbers", L"font:Tahoma; size:-2; fore:#FF0000", L"" }, - /* 17 */ { STYLE_BRACELIGHT, 63114, L"2nd Matching Braces (Indicator)", L"fore:#00FF40; alpha:80; alpha2:220; indic_roundbox", L"" }, - /* 18 */ { STYLE_BRACEBAD, 63115, L"2nd Matching Braces Error (Indicator)", L"fore:#FF0080; alpha:140; alpha2:220; indic_roundbox", L"" }, - /* 19 */ { STYLE_CONTROLCHAR, 63116, L"2nd Control Characters (Font)", L"size:-1", L"" }, - /* 20 */ { STYLE_INDENTGUIDE, 63117, L"2nd Indentation Guide (Color)", L"fore:#A0A0A0", L"" }, - /* 21 */ { SCI_SETSELFORE + SCI_SETSELBACK, 63118, L"2nd Selected Text (Colors)", L"eolfilled", L"" }, - /* 22 */ { SCI_SETWHITESPACEFORE + SCI_SETWHITESPACEBACK + SCI_SETWHITESPACESIZE, 63119, L"2nd Whitespace (Colors, Size 0-5)", L"fore:#FF4000", L"" }, - /* 23 */ { SCI_SETCARETLINEBACK, 63120, L"2nd Current Line Background (Color)", L"back:#FFFF00; alpha:50", L"" }, - /* 24 */ { SCI_SETCARETFORE + SCI_SETCARETWIDTH, 63121, L"2nd Caret (Color, Size 1-3)", L"", L"" }, - /* 25 */ { SCI_SETEDGECOLOUR, 63122, L"2nd Long Line Marker (Colors)", L"fore:#FFC000", L"" }, - /* 26 */ { SCI_SETEXTRAASCENT + SCI_SETEXTRADESCENT, 63123, L"2nd Extra Line Spacing (Size)", L"", L"" }, - /* 27 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, 63125, L"2nd Book Marks (Colors)", L"back:#00FF00; alpha:20", L"" }, - /* 28 */ { SCI_MARKERSETBACK+SCI_MARKERSETALPHA, 63263, L"2nd Mark Occurrences (Indicator)", L"fore:#0x00FF00; alpha:100; alpha2:220; indic_box", L"" }, - /* 29 */ { SCI_SETHOTSPOTACTIVEFORE, 63265, L"2nd Hyperlink Hotspots", L"bold; fore:#FF0000", L"" }, - { -1, 00000, L"", L"", L"" } } }; + +EDITLEXER lexStandard2nd = { SCLEX_NULL, 63266, L"2nd Default Text", L"txt; text; wtx; log; asc; doc", L"", &KeyWords_NULL,{ + /* 0 */ { STYLE_DEFAULT, 63112, L"2nd Default Style", L"font:Courier New; size:10", L"" }, + /* 1 */ { STYLE_LINENUMBER, 63113, L"2nd Margins and Line Numbers", L"font:Tahoma; size:-2; fore:#FF0000", L"" }, + /* 2 */ { STYLE_BRACELIGHT, 63114, L"2nd Matching Braces (Indicator)", L"fore:#00FF40; alpha:80; alpha2:220; indic_roundbox", L"" }, + /* 3 */ { STYLE_BRACEBAD, 63115, L"2nd Matching Braces Error (Indicator)", L"fore:#FF0080; alpha:140; alpha2:220; indic_roundbox", L"" }, + /* 4 */ { STYLE_CONTROLCHAR, 63116, L"2nd Control Characters (Font)", L"size:-1", L"" }, + /* 5 */ { STYLE_INDENTGUIDE, 63117, L"2nd Indentation Guide (Color)", L"fore:#A0A0A0", L"" }, + /* 6 */ { SCI_SETSELFORE + SCI_SETSELBACK, 63118, L"2nd Selected Text (Colors)", L"eolfilled", L"" }, + /* 7 */ { SCI_SETWHITESPACEFORE + SCI_SETWHITESPACEBACK + SCI_SETWHITESPACESIZE, 63119, L"2nd Whitespace (Colors, Size 0-5)", L"fore:#FF4000", L"" }, + /* 8 */ { SCI_SETCARETLINEBACK, 63120, L"2nd Current Line Background (Color)", L"back:#FFFF00; alpha:50", L"" }, + /* 9 */ { SCI_SETCARETFORE + SCI_SETCARETWIDTH, 63121, L"2nd Caret (Color, Size 1-3)", L"", L"" }, + /* 10 */ { SCI_SETEDGECOLOUR, 63122, L"2nd Long Line Marker (Colors)", L"fore:#FFC000", L"" }, + /* 11 */ { SCI_SETEXTRAASCENT + SCI_SETEXTRADESCENT, 63123, L"2nd Extra Line Spacing (Size)", L"", L"" }, + /* 12 */ { SCI_MARKERSETBACK + SCI_MARKERSETALPHA, 63125, L"2nd Book Marks (Colors)", L"back:#00FF00; alpha:20", L"" }, + /* 13 */ { SCI_MARKERSETBACK + SCI_MARKERSETALPHA, 63263, L"2nd Mark Occurrences (Indicator)", L"fore:#0x00FF00; alpha:100; alpha2:220; indic_box", L"" }, + /* 14 */ { SCI_SETHOTSPOTACTIVEFORE, 63265, L"2nd Hyperlink Hotspots", L"bold; fore:#FF0000", L"" }, + { -1, 00000, L"", L"", L"" } } }; + + enum LexDefaultStyles { STY_DEFAULT = 0, STY_MARGIN = 1, @@ -111,16 +114,10 @@ enum LexDefaultStyles { STY_X_LN_SPACE = 11, STY_BOOK_MARK = 12, STY_MARK_OCC = 13, - STY_URL_HOTSPOT = 14, - - STY_CNT_LAST = 15 // STY_2ND_XXX = STY_XXX + STY_CNT_LAST + STY_URL_HOTSPOT = 14 }; -#define STDLEXID(id) ((id) + (Style_GetUse2ndDefault() ? STY_CNT_LAST : 0)) -//~ => Style[STDLEXID(STY_DEFAULT)].iStyle := STYLE_DEFAULT - - // ---------------------------------------------------------------------------- KEYWORDLIST KeyWords_HTML = { @@ -2825,13 +2822,13 @@ EDITLEXER lexNim = { SCLEX_NIM, 63044, L"Nim Source Code", L"nim", L"", &KeyWord - // This array holds all the lexers... // Don't forget to change the number of the lexer for HTML and XML // in Notepad2.c ParseCommandLine() if you change this array! static PEDITLEXER pLexArray[NUMLEXERS] = { &lexStandard, // Default Text + &lexStandard2nd, // 2nd Default Text &lexANSI, // ANSI Files &lexCONF, // Apache Config Files &lexASM, // Assembly Script @@ -2898,6 +2895,30 @@ extern BOOL bHyperlinkHotspot; extern BOOL bShowSelectionMargin; +//============================================================================= +// +// IsLexerStandard() +// + +BOOL __fastcall IsLexerStandard(PEDITLEXER pLexer) +{ + return ( (pLexer == &lexStandard) || (pLexer == &lexStandard2nd) ); +} + +PEDITLEXER __fastcall GetCurrentStdLexer() +{ + return (Style_GetUse2ndDefault() ? &lexStandard2nd : &lexStandard); +} + +BOOL __fastcall IsStyleStandardDefault(PEDITSTYLE pStyle) +{ + return ((pStyle->rid == 63100) || (pStyle->rid == 63112)); +} + +BOOL __fastcall IsStyleSchemeDefault(PEDITSTYLE pStyle) +{ + return (pStyle->rid == 63126); +} //============================================================================= @@ -3162,11 +3183,12 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { // Select standard if NULL is specified if (!pLexNew) { - pLexNew = &lexStandard; + pLexNew = GetCurrentStdLexer(); } // first set standard lexer's default values - g_pLexCurrent = &lexStandard; + g_pLexCurrent = GetCurrentStdLexer(); + const WCHAR* const wchStandardStyleStrg = g_pLexCurrent->Styles[STY_DEFAULT].szValue; // Lexer SendMessage(hwnd, SCI_SETLEXER, pLexNew->iLexer, 0); @@ -3213,8 +3235,6 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { // Clear SendMessage(hwnd, SCI_CLEARDOCUMENTSTYLE, 0, 0); - WCHAR* wchStandardStyleStrg = lexStandard.Styles[STDLEXID(STY_DEFAULT)].szValue; - // Idle Styling (very large text) SendMessage(hwnd, SCI_SETIDLESTYLING, SC_IDLESTYLING_AFTERVISIBLE, 0); //SendMessage(hwnd, SCI_SETIDLESTYLING, SC_IDLESTYLING_ALL, 0); @@ -3236,9 +3256,7 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { // constants Style_SetFontQuality(hwnd, wchStandardStyleStrg); - SendMessage(hwnd, SCI_STYLESETVISIBLE, STYLE_DEFAULT, (LPARAM)TRUE); - SendMessage(hwnd, SCI_STYLESETHOTSPOT, STYLE_DEFAULT, (LPARAM)FALSE); // default hotspot off @@ -3283,9 +3301,9 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { Style_SetStyles(hwnd, STYLE_DEFAULT, wchStandardStyleStrg); // --- apply current scheme specific settings to default style --- - if (pLexNew != &lexStandard) + if (!IsLexerStandard(pLexNew)) { - WCHAR* wchCurrentLexerStyleStrg = pLexNew->Styles[STY_DEFAULT].szValue; + const WCHAR* const wchCurrentLexerStyleStrg = pLexNew->Styles[STY_DEFAULT].szValue; // merge lexer styles Style_SetStyles(hwnd, STYLE_DEFAULT, wchCurrentLexerStyleStrg); // use this font size as current lexer's base @@ -3302,57 +3320,60 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { SendMessage(hwnd, SCI_STYLECLEARALL, 0, 0); // -------------------------------------------------------------------------- + + const PEDITLEXER pCurrentStandard = g_pLexCurrent; + // -------------------------------------------------------------------------- - Style_SetStyles(hwnd, lexStandard.Styles[STDLEXID(STY_MARGIN)].iStyle, - lexStandard.Styles[STDLEXID(STY_MARGIN)].szValue); // line number + Style_SetStyles(hwnd, pCurrentStandard->Styles[STY_MARGIN].iStyle, + pCurrentStandard->Styles[STY_MARGIN].szValue); // line number if (bUseOldStyleBraceMatching) { - Style_SetStyles(hwnd, lexStandard.Styles[STDLEXID(STY_BRACE_OK)].iStyle, - lexStandard.Styles[STDLEXID(STY_BRACE_OK)].szValue); // brace light + Style_SetStyles(hwnd, pCurrentStandard->Styles[STY_BRACE_OK].iStyle, + pCurrentStandard->Styles[STY_BRACE_OK].szValue); // brace light } else { - if (Style_StrGetColor(TRUE, lexStandard.Styles[STDLEXID(STY_BRACE_OK)].szValue, &iValue)) + if (Style_StrGetColor(TRUE, pCurrentStandard->Styles[STY_BRACE_OK].szValue, &iValue)) SendMessage(hwnd, SCI_INDICSETFORE, INDIC_NP3_MATCH_BRACE, iValue); - if (Style_StrGetAlpha(lexStandard.Styles[STDLEXID(STY_BRACE_OK)].szValue, &iValue, TRUE)) + if (Style_StrGetAlpha(pCurrentStandard->Styles[STY_BRACE_OK].szValue, &iValue, TRUE)) SendMessage(hwnd, SCI_INDICSETALPHA, INDIC_NP3_MATCH_BRACE, iValue); - if (Style_StrGetAlpha(lexStandard.Styles[STDLEXID(STY_BRACE_OK)].szValue, &iValue, FALSE)) + if (Style_StrGetAlpha(pCurrentStandard->Styles[STY_BRACE_OK].szValue, &iValue, FALSE)) SendMessage(hwnd, SCI_INDICSETOUTLINEALPHA, INDIC_NP3_MATCH_BRACE, iValue); iValue = -1; // need for retrieval - if (!Style_GetIndicatorType(lexStandard.Styles[STDLEXID(STY_BRACE_OK)].szValue, 0, &iValue)) { + if (!Style_GetIndicatorType(pCurrentStandard->Styles[STY_BRACE_OK].szValue, 0, &iValue)) { // got default, get string - StringCchCatW(lexStandard.Styles[STDLEXID(STY_BRACE_OK)].szValue, COUNTOF(lexStandard.Styles[0].szValue), L"; "); + StringCchCatW(pCurrentStandard->Styles[STY_BRACE_OK].szValue, COUNTOF(pCurrentStandard->Styles[0].szValue), L"; "); Style_GetIndicatorType(wchSpecificStyle, COUNTOF(wchSpecificStyle), &iValue); - StringCchCatW(lexStandard.Styles[STDLEXID(STY_BRACE_OK)].szValue, COUNTOF(lexStandard.Styles[0].szValue), wchSpecificStyle); + StringCchCatW(pCurrentStandard->Styles[STY_BRACE_OK].szValue, COUNTOF(pCurrentStandard->Styles[0].szValue), wchSpecificStyle); } SendMessage(hwnd, SCI_INDICSETSTYLE, INDIC_NP3_MATCH_BRACE, iValue); } if (bUseOldStyleBraceMatching) { - Style_SetStyles(hwnd, lexStandard.Styles[STDLEXID(STY_BRACE_BAD)].iStyle, - lexStandard.Styles[STDLEXID(STY_BRACE_BAD)].szValue); // brace bad + Style_SetStyles(hwnd, pCurrentStandard->Styles[STY_BRACE_BAD].iStyle, + pCurrentStandard->Styles[STY_BRACE_BAD].szValue); // brace bad } else { - if (Style_StrGetColor(TRUE, lexStandard.Styles[STDLEXID(STY_BRACE_BAD)].szValue, &iValue)) + if (Style_StrGetColor(TRUE, pCurrentStandard->Styles[STY_BRACE_BAD].szValue, &iValue)) SendMessage(hwnd, SCI_INDICSETFORE, INDIC_NP3_BAD_BRACE, iValue); - if (Style_StrGetAlpha(lexStandard.Styles[STDLEXID(STY_BRACE_BAD)].szValue, &iValue, TRUE)) + if (Style_StrGetAlpha(pCurrentStandard->Styles[STY_BRACE_BAD].szValue, &iValue, TRUE)) SendMessage(hwnd, SCI_INDICSETALPHA, INDIC_NP3_BAD_BRACE, iValue); - if (Style_StrGetAlpha(lexStandard.Styles[STDLEXID(STY_BRACE_BAD)].szValue, &iValue, FALSE)) + if (Style_StrGetAlpha(pCurrentStandard->Styles[STY_BRACE_BAD].szValue, &iValue, FALSE)) SendMessage(hwnd, SCI_INDICSETOUTLINEALPHA, INDIC_NP3_BAD_BRACE, iValue); iValue = -1; // need for retrieval - if (!Style_GetIndicatorType(lexStandard.Styles[STDLEXID(STY_BRACE_BAD)].szValue, 0, &iValue)) { + if (!Style_GetIndicatorType(pCurrentStandard->Styles[STY_BRACE_BAD].szValue, 0, &iValue)) { // got default, get string - StringCchCatW(lexStandard.Styles[STDLEXID(STY_BRACE_BAD)].szValue, COUNTOF(lexStandard.Styles[0].szValue), L"; "); + StringCchCatW(pCurrentStandard->Styles[STY_BRACE_BAD].szValue, COUNTOF(pCurrentStandard->Styles[0].szValue), L"; "); Style_GetIndicatorType(wchSpecificStyle, COUNTOF(wchSpecificStyle), &iValue); - StringCchCatW(lexStandard.Styles[STDLEXID(STY_BRACE_BAD)].szValue, COUNTOF(lexStandard.Styles[0].szValue), wchSpecificStyle); + StringCchCatW(pCurrentStandard->Styles[STY_BRACE_BAD].szValue, COUNTOF(pCurrentStandard->Styles[0].szValue), wchSpecificStyle); } SendMessage(hwnd, SCI_INDICSETSTYLE, INDIC_NP3_BAD_BRACE, iValue); } // Occurrences Marker - if (!Style_StrGetColor(TRUE, lexStandard.Styles[STDLEXID(STY_MARK_OCC)].szValue, &iValue)) + if (!Style_StrGetColor(TRUE, pCurrentStandard->Styles[STY_MARK_OCC].szValue, &iValue)) { WCHAR* sty = L""; switch (iMarkOccurrences) { @@ -3370,39 +3391,39 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { iValue = RGB(0x00, 0xFF, 0x00); break; } - StringCchCopyW(lexStandard.Styles[STDLEXID(STY_MARK_OCC)].szValue, COUNTOF(lexStandard.Styles[0].szValue), sty); + StringCchCopyW(pCurrentStandard->Styles[STY_MARK_OCC].szValue, COUNTOF(pCurrentStandard->Styles[0].szValue), sty); } SendMessage(hwnd, SCI_INDICSETFORE, INDIC_NP3_MARK_OCCURANCE, iValue); - if (!Style_StrGetAlpha(lexStandard.Styles[STDLEXID(STY_MARK_OCC)].szValue, &iValue, TRUE)) { + if (!Style_StrGetAlpha(pCurrentStandard->Styles[STY_MARK_OCC].szValue, &iValue, TRUE)) { iValue = 100; - StringCchCatW(lexStandard.Styles[STDLEXID(STY_MARK_OCC)].szValue, COUNTOF(lexStandard.Styles[0].szValue), L"; alpha:100"); + StringCchCatW(pCurrentStandard->Styles[STY_MARK_OCC].szValue, COUNTOF(pCurrentStandard->Styles[0].szValue), L"; alpha:100"); } SendMessage(hwnd, SCI_INDICSETALPHA, INDIC_NP3_MARK_OCCURANCE, iValue); - if (!Style_StrGetAlpha(lexStandard.Styles[STDLEXID(STY_MARK_OCC)].szValue, &iValue, FALSE)) { + if (!Style_StrGetAlpha(pCurrentStandard->Styles[STY_MARK_OCC].szValue, &iValue, FALSE)) { iValue = 100; - StringCchCatW(lexStandard.Styles[STDLEXID(STY_MARK_OCC)].szValue, COUNTOF(lexStandard.Styles[0].szValue), L"; alpha2:100"); + StringCchCatW(pCurrentStandard->Styles[STY_MARK_OCC].szValue, COUNTOF(pCurrentStandard->Styles[0].szValue), L"; alpha2:100"); } SendMessage(hwnd, SCI_INDICSETOUTLINEALPHA, INDIC_NP3_MARK_OCCURANCE, iValue); iValue = -1; // need for retrieval - if (!Style_GetIndicatorType(lexStandard.Styles[STDLEXID(STY_MARK_OCC)].szValue, 0, &iValue)) { + if (!Style_GetIndicatorType(pCurrentStandard->Styles[STY_MARK_OCC].szValue, 0, &iValue)) { // got default, get string - StringCchCatW(lexStandard.Styles[STDLEXID(STY_MARK_OCC)].szValue, COUNTOF(lexStandard.Styles[0].szValue), L"; "); + StringCchCatW(pCurrentStandard->Styles[STY_MARK_OCC].szValue, COUNTOF(pCurrentStandard->Styles[0].szValue), L"; "); Style_GetIndicatorType(wchSpecificStyle, COUNTOF(wchSpecificStyle), &iValue); - StringCchCatW(lexStandard.Styles[STDLEXID(STY_MARK_OCC)].szValue, COUNTOF(lexStandard.Styles[0].szValue), wchSpecificStyle); + StringCchCatW(pCurrentStandard->Styles[STY_MARK_OCC].szValue, COUNTOF(pCurrentStandard->Styles[0].szValue), wchSpecificStyle); } SendMessage(hwnd, SCI_INDICSETSTYLE, INDIC_NP3_MARK_OCCURANCE, iValue); // More default values... if (pLexNew != &lexANSI) - Style_SetStyles(hwnd, lexStandard.Styles[STDLEXID(STY_CTRL_CHR)].iStyle, lexStandard.Styles[STDLEXID(STY_CTRL_CHR)].szValue); // control char + Style_SetStyles(hwnd, pCurrentStandard->Styles[STY_CTRL_CHR].iStyle, pCurrentStandard->Styles[STY_CTRL_CHR].szValue); // control char - Style_SetStyles(hwnd, lexStandard.Styles[STDLEXID(STY_INDENT_GUIDE)].iStyle, lexStandard.Styles[STDLEXID(STY_INDENT_GUIDE)].szValue); // indent guide + Style_SetStyles(hwnd, pCurrentStandard->Styles[STY_INDENT_GUIDE].iStyle, pCurrentStandard->Styles[STY_INDENT_GUIDE].szValue); // indent guide - if (Style_StrGetColor(TRUE, lexStandard.Styles[STDLEXID(STY_SEL_TXT)].szValue, &rgb)) { // selection fore + if (Style_StrGetColor(TRUE, pCurrentStandard->Styles[STY_SEL_TXT].szValue, &rgb)) { // selection fore SendMessage(hwnd, SCI_SETSELFORE, TRUE, rgb); SendMessage(hwnd, SCI_SETADDITIONALSELFORE, rgb, 0); } @@ -3411,7 +3432,7 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { SendMessage(hwnd, SCI_SETADDITIONALSELFORE, 0, 0); } - if (Style_StrGetColor(FALSE, lexStandard.Styles[STDLEXID(STY_SEL_TXT)].szValue, &iValue)) { // selection back + if (Style_StrGetColor(FALSE, pCurrentStandard->Styles[STY_SEL_TXT].szValue, &iValue)) { // selection back SendMessage(hwnd, SCI_SETSELBACK, TRUE, iValue); SendMessage(hwnd, SCI_SETADDITIONALSELBACK, iValue, 0); } @@ -3420,7 +3441,7 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { SendMessage(hwnd, SCI_SETADDITIONALSELBACK, RGB(0xC0, 0xC0, 0xC0), 0); } - if (Style_StrGetAlpha(lexStandard.Styles[STDLEXID(STY_SEL_TXT)].szValue, &iValue, TRUE)) { // selection alpha + if (Style_StrGetAlpha(pCurrentStandard->Styles[STY_SEL_TXT].szValue, &iValue, TRUE)) { // selection alpha SendMessage(hwnd, SCI_SETSELALPHA, iValue, 0); SendMessage(hwnd, SCI_SETADDITIONALSELALPHA, iValue, 0); } @@ -3429,41 +3450,41 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { SendMessage(hwnd, SCI_SETADDITIONALSELALPHA, SC_ALPHA_NOALPHA, 0); } - if (StrStrI(lexStandard.Styles[STDLEXID(STY_SEL_TXT)].szValue, L"eolfilled")) // selection eolfilled + if (StrStrI(pCurrentStandard->Styles[STY_SEL_TXT].szValue, L"eolfilled")) // selection eolfilled SendMessage(hwnd, SCI_SETSELEOLFILLED, 1, 0); else SendMessage(hwnd, SCI_SETSELEOLFILLED, 0, 0); - if (Style_StrGetColor(TRUE, lexStandard.Styles[STDLEXID(STY_WHITESPACE)].szValue, &rgb)) // whitespace fore + if (Style_StrGetColor(TRUE, pCurrentStandard->Styles[STY_WHITESPACE].szValue, &rgb)) // whitespace fore SendMessage(hwnd, SCI_SETWHITESPACEFORE, TRUE, rgb); else SendMessage(hwnd, SCI_SETWHITESPACEFORE, 0, 0); - if (Style_StrGetColor(FALSE, lexStandard.Styles[STDLEXID(STY_WHITESPACE)].szValue, &rgb)) // whitespace back + if (Style_StrGetColor(FALSE, pCurrentStandard->Styles[STY_WHITESPACE].szValue, &rgb)) // whitespace back SendMessage(hwnd, SCI_SETWHITESPACEBACK, TRUE, rgb); else SendMessage(hwnd, SCI_SETWHITESPACEBACK, 0, 0); // use a default value... // whitespace dot size iValue = 1; - if (Style_StrGetSize(lexStandard.Styles[STDLEXID(STY_WHITESPACE)].szValue, &iValue)) { + if (Style_StrGetSize(pCurrentStandard->Styles[STY_WHITESPACE].szValue, &iValue)) { WCHAR tch[32] = { L'\0' }; WCHAR wchStyle[BUFSIZE_STYLE_VALUE]; - StringCchCopyN(wchStyle, COUNTOF(wchStyle), lexStandard.Styles[STDLEXID(STY_WHITESPACE)].szValue, - COUNTOF(lexStandard.Styles[STDLEXID(STY_WHITESPACE)].szValue)); + StringCchCopyN(wchStyle, COUNTOF(wchStyle), pCurrentStandard->Styles[STY_WHITESPACE].szValue, + COUNTOF(pCurrentStandard->Styles[STY_WHITESPACE].szValue)); iValue = max(min(iValue, 5), 0); - StringCchPrintf(lexStandard.Styles[STDLEXID(STY_WHITESPACE)].szValue, - COUNTOF(lexStandard.Styles[STDLEXID(STY_WHITESPACE)].szValue), L"size:%i", iValue); + StringCchPrintf(pCurrentStandard->Styles[STY_WHITESPACE].szValue, + COUNTOF(pCurrentStandard->Styles[STY_WHITESPACE].szValue), L"size:%i", iValue); if (Style_StrGetColor(TRUE, wchStyle, &rgb)) { StringCchPrintf(tch, COUNTOF(tch), L"; fore:#%02X%02X%02X", (int)GetRValue(rgb), (int)GetGValue(rgb), (int)GetBValue(rgb)); - StringCchCat(lexStandard.Styles[STDLEXID(STY_WHITESPACE)].szValue, - COUNTOF(lexStandard.Styles[STDLEXID(STY_WHITESPACE)].szValue), tch); + StringCchCat(pCurrentStandard->Styles[STY_WHITESPACE].szValue, + COUNTOF(pCurrentStandard->Styles[STY_WHITESPACE].szValue), tch); } if (Style_StrGetColor(FALSE, wchStyle, &rgb)) { @@ -3471,8 +3492,8 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { (int)GetRValue(rgb), (int)GetGValue(rgb), (int)GetBValue(rgb)); - StringCchCat(lexStandard.Styles[STDLEXID(STY_WHITESPACE)].szValue, - COUNTOF(lexStandard.Styles[STDLEXID(STY_WHITESPACE)].szValue), tch); + StringCchCat(pCurrentStandard->Styles[STY_WHITESPACE].szValue, + COUNTOF(pCurrentStandard->Styles[STY_WHITESPACE].szValue), tch); } } SendMessage(hwnd, SCI_SETWHITESPACESIZE, iValue, 0); @@ -3485,7 +3506,7 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { // caret style and width - if (StrStr(lexStandard.Styles[STDLEXID(STY_CARET)].szValue,L"block")) { + if (StrStr(pCurrentStandard->Styles[STY_CARET].szValue,L"block")) { SendMessage(hwnd,SCI_SETCARETSTYLE,CARETSTYLE_BLOCK,0); StringCchCopy(wchSpecificStyle,COUNTOF(wchSpecificStyle),L"block"); } @@ -3494,14 +3515,14 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { WCHAR wch[32] = { L'\0' }; iValue = 1; // default caret width - if (Style_StrGetSize(lexStandard.Styles[STDLEXID(STY_CARET)].szValue,&iValue)) { + if (Style_StrGetSize(pCurrentStandard->Styles[STY_CARET].szValue,&iValue)) { iValue = max(min(iValue,3),1); StringCchPrintf(wch,COUNTOF(wch),L"size:%i",iValue); StringCchCat(wchSpecificStyle,COUNTOF(wchSpecificStyle),wch); } SendMessage(hwnd,SCI_SETCARETWIDTH,iValue,0); } - if (StrStr(lexStandard.Styles[STDLEXID(STY_CARET)].szValue,L"noblink")) { + if (StrStr(pCurrentStandard->Styles[STY_CARET].szValue,L"noblink")) { SendMessage(hwnd,SCI_SETCARETPERIOD,(WPARAM)0,0); StringCchCat(wchSpecificStyle,COUNTOF(wchSpecificStyle),L"; noblink"); } @@ -3509,7 +3530,7 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { SendMessage(hwnd,SCI_SETCARETPERIOD,(WPARAM)GetCaretBlinkTime(),0); // caret fore - if (!Style_StrGetColor(TRUE,lexStandard.Styles[STDLEXID(STY_CARET)].szValue,&rgb)) + if (!Style_StrGetColor(TRUE,pCurrentStandard->Styles[STY_CARET].szValue,&rgb)) rgb = GetSysColor(COLOR_WINDOWTEXT); else { WCHAR wch[32] = { L'\0' }; @@ -3526,17 +3547,17 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { SendMessage(hwnd,SCI_SETADDITIONALCARETFORE,rgb,0); StrTrimW(wchSpecificStyle, L" ;"); - StringCchCopy(lexStandard.Styles[STDLEXID(STY_CARET)].szValue, - COUNTOF(lexStandard.Styles[STDLEXID(STY_CARET)].szValue),wchSpecificStyle); + StringCchCopy(pCurrentStandard->Styles[STY_CARET].szValue, + COUNTOF(pCurrentStandard->Styles[STY_CARET].szValue),wchSpecificStyle); if (SendMessage(hwnd,SCI_GETEDGEMODE,0,0) == EDGE_LINE) { - if (Style_StrGetColor(TRUE,lexStandard.Styles[STDLEXID(STY_LONG_LN_MRK)].szValue,&rgb)) // edge fore + if (Style_StrGetColor(TRUE,pCurrentStandard->Styles[STY_LONG_LN_MRK].szValue,&rgb)) // edge fore SendMessage(hwnd,SCI_SETEDGECOLOUR,rgb,0); else SendMessage(hwnd,SCI_SETEDGECOLOUR,GetSysColor(COLOR_3DLIGHT),0); } else { - if (Style_StrGetColor(FALSE,lexStandard.Styles[STDLEXID(STY_LONG_LN_MRK)].szValue,&rgb)) // edge back + if (Style_StrGetColor(FALSE,pCurrentStandard->Styles[STY_LONG_LN_MRK].szValue,&rgb)) // edge back SendMessage(hwnd,SCI_SETEDGECOLOUR,rgb,0); else SendMessage(hwnd,SCI_SETEDGECOLOUR,GetSysColor(COLOR_3DLIGHT),0); @@ -3544,13 +3565,13 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { // Extra Line Spacing iValue = 0; - if (Style_StrGetSize(lexStandard.Styles[STDLEXID(STY_X_LN_SPACE)].szValue,&iValue) && (pLexNew != &lexANSI)) { + if (Style_StrGetSize(pCurrentStandard->Styles[STY_X_LN_SPACE].szValue,&iValue) && (pLexNew != &lexANSI)) { int iAscent = 0; int iDescent = 0; int iValAdj = min(max(iValue,0),64); if (iValAdj != iValue) - StringCchPrintf(lexStandard.Styles[STDLEXID(STY_X_LN_SPACE)].szValue, - COUNTOF(lexStandard.Styles[STDLEXID(STY_X_LN_SPACE)].szValue), L"size:%i", iValAdj); + StringCchPrintf(pCurrentStandard->Styles[STY_X_LN_SPACE].szValue, + COUNTOF(pCurrentStandard->Styles[STY_X_LN_SPACE].szValue), L"size:%i", iValAdj); if ((iValAdj % 2) != 0) { iAscent++; @@ -3608,7 +3629,7 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { if (g_pLexCurrent->iLexer != SCLEX_NULL || g_pLexCurrent == &lexANSI) { int j; - int i = 1; // don't re-apply lexers default style + int i = 1; // don't re-apply lexer's default style while (g_pLexCurrent->Styles[i].iStyle != -1) { for (j = 0; j < 4 && (g_pLexCurrent->Styles[i].iStyle8[j] != 0 || j == 0); ++j) { @@ -3684,20 +3705,24 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { SCE_HP_IDENTIFIER, SCE_HPA_START, SCE_HPA_DEFAULT, SCE_HPA_COMMENTLINE, SCE_HPA_NUMBER, SCE_HPA_STRING, SCE_HPA_CHARACTER, SCE_HPA_WORD, SCE_HPA_TRIPLE, SCE_HPA_TRIPLEDOUBLE, SCE_HPA_CLASSNAME, SCE_HPA_DEFNAME, SCE_HPA_OPERATOR, SCE_HPA_IDENTIFIER }; - for (j = 0; j < COUNTOF(iRelated); j++) - Style_SetStyles(hwnd,iRelated[j],g_pLexCurrent->Styles[i].szValue); + + for (j = 0; j < COUNTOF(iRelated); j++) { + Style_SetStyles(hwnd, iRelated[j], g_pLexCurrent->Styles[i].szValue); + } } if (g_pLexCurrent->iLexer == SCLEX_CPP && g_pLexCurrent->Styles[i].iStyle8[0] == SCE_C_COMMENT) { int iRelated[] = { SCE_C_COMMENTLINE, SCE_C_COMMENTDOC, SCE_C_COMMENTLINEDOC, SCE_C_COMMENTDOCKEYWORD, SCE_C_COMMENTDOCKEYWORDERROR }; - for (j = 0; j < COUNTOF(iRelated); j++) - Style_SetStyles(hwnd,iRelated[j],g_pLexCurrent->Styles[i].szValue); + for (j = 0; j < COUNTOF(iRelated); j++) { + Style_SetStyles(hwnd, iRelated[j], g_pLexCurrent->Styles[i].szValue); + } } if (g_pLexCurrent -> iLexer == SCLEX_SQL && g_pLexCurrent->Styles[i].iStyle8[0] == SCE_SQL_COMMENT) { int iRelated[] = { SCE_SQL_COMMENTLINE, SCE_SQL_COMMENTDOC, SCE_SQL_COMMENTLINEDOC, SCE_SQL_COMMENTDOCKEYWORD, SCE_SQL_COMMENTDOCKEYWORDERROR }; - for (j = 0; j < COUNTOF(iRelated); j++) - Style_SetStyles(hwnd,iRelated[j],g_pLexCurrent->Styles[i].szValue); + for (j = 0; j < COUNTOF(iRelated); j++) { + Style_SetStyles(hwnd, iRelated[j], g_pLexCurrent->Styles[i].szValue); + } } i++; } @@ -3719,7 +3744,7 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { // int Style_GetHotspotStyleID() { - return (STYLE_LASTPREDEFINED + STDLEXID(STY_URL_HOTSPOT)); + return (STYLE_LASTPREDEFINED + STY_URL_HOTSPOT); } @@ -3734,7 +3759,8 @@ void Style_SetUrlHotSpot(HWND hwnd, BOOL bHotSpot) if (bHotSpot) { - const WCHAR* lpszStyleHotSpot = lexStandard.Styles[STDLEXID(STY_URL_HOTSPOT)].szValue; + + const WCHAR* const lpszStyleHotSpot = GetCurrentStdLexer()->Styles[STY_URL_HOTSPOT].szValue; SendMessage(hwnd, SCI_STYLESETHOTSPOT, iStyleHotSpot, (LPARAM)TRUE); SendMessage(hwnd, SCI_SETHOTSPOTSINGLELINE, FALSE, 0); @@ -3762,7 +3788,7 @@ void Style_SetUrlHotSpot(HWND hwnd, BOOL bHotSpot) } } else { - const WCHAR* lpszStyleHotSpot = lexStandard.Styles[STDLEXID(STY_DEFAULT)].szValue; + const WCHAR* lpszStyleHotSpot = GetCurrentStdLexer()->Styles[STY_DEFAULT].szValue; Style_SetStyles(hwnd, iStyleHotSpot, lpszStyleHotSpot); @@ -3783,13 +3809,13 @@ void Style_SetLongLineColors(HWND hwnd) if (SendMessage(hwnd,SCI_GETEDGEMODE,0,0) == EDGE_LINE) { - if (Style_StrGetColor(TRUE,lexStandard.Styles[STDLEXID(STY_LONG_LN_MRK)].szValue,&rgb)) // edge fore + if (Style_StrGetColor(TRUE, GetCurrentStdLexer()->Styles[STY_LONG_LN_MRK].szValue,&rgb)) // edge fore SendMessage(hwnd,SCI_SETEDGECOLOUR,rgb,0); else SendMessage(hwnd,SCI_SETEDGECOLOUR,GetSysColor(COLOR_3DLIGHT),0); } else { - if (Style_StrGetColor(FALSE,lexStandard.Styles[STDLEXID(STY_LONG_LN_MRK)].szValue,&rgb)) // edge back + if (Style_StrGetColor(FALSE, GetCurrentStdLexer()->Styles[STY_LONG_LN_MRK].szValue,&rgb)) // edge back SendMessage(hwnd,SCI_SETEDGECOLOUR,rgb,0); else SendMessage(hwnd,SCI_SETEDGECOLOUR,GetSysColor(COLOR_3DLIGHT),0); @@ -3806,13 +3832,13 @@ void Style_SetCurrentLineBackground(HWND hwnd, BOOL bHiLitCurrLn) if (bHiLitCurrLn) { int rgb = 0; - if (Style_StrGetColor(FALSE,lexStandard.Styles[STDLEXID(STY_CUR_LN_BCK)].szValue, &rgb)) // caret line back + if (Style_StrGetColor(FALSE, GetCurrentStdLexer()->Styles[STY_CUR_LN_BCK].szValue, &rgb)) // caret line back { SendMessage(hwnd,SCI_SETCARETLINEVISIBLE,TRUE,0); SendMessage(hwnd,SCI_SETCARETLINEBACK,rgb,0); int alpha = 0; - if (Style_StrGetAlpha(lexStandard.Styles[STDLEXID(STY_CUR_LN_BCK)].szValue, &alpha, TRUE)) + if (Style_StrGetAlpha(GetCurrentStdLexer()->Styles[STY_CUR_LN_BCK].szValue, &alpha, TRUE)) SendMessage(hwnd,SCI_SETCARETLINEBACKALPHA,alpha,0); else SendMessage(hwnd,SCI_SETCARETLINEBACKALPHA,SC_ALPHA_NOALPHA,0); @@ -3832,19 +3858,19 @@ void Style_SetCurrentLineBackground(HWND hwnd, BOOL bHiLitCurrLn) void Style_SetCurrentMargin(HWND hwnd, BOOL bShowSelMargin) { int alpha = 20; - Style_StrGetAlpha(lexStandard.Styles[STDLEXID(STY_BOOK_MARK)].szValue, &alpha, TRUE); + Style_StrGetAlpha(GetCurrentStdLexer()->Styles[STY_BOOK_MARK].szValue, &alpha, TRUE); int rgbFore = RGB(0xFF, 0, 0); // red - Style_StrGetColor(TRUE, lexStandard.Styles[STDLEXID(STY_BOOK_MARK)].szValue, &rgbFore); + Style_StrGetColor(TRUE, GetCurrentStdLexer()->Styles[STY_BOOK_MARK].szValue, &rgbFore); int rgbBack = RGB(0, 0xFF, 0); // green - Style_StrGetColor(FALSE, lexStandard.Styles[STDLEXID(STY_BOOK_MARK)].szValue, &rgbBack); + Style_StrGetColor(FALSE, GetCurrentStdLexer()->Styles[STY_BOOK_MARK].szValue, &rgbBack); // adjust background color by alpha in case of show margin if (bShowSelMargin) { //int bckgrnd = (int)SendMessage(hwnd, SCI_GETMARGINBACKN, MARGIN_NP3_BOOKMRK, 0); int bckgrnd = RGB(0xF0, 0xF0, 0xF0); - Style_StrGetColor(FALSE, lexStandard.Styles[STDLEXID(STY_MARGIN)].szValue, &bckgrnd); + Style_StrGetColor(FALSE, GetCurrentStdLexer()->Styles[STY_MARGIN].szValue, &bckgrnd); rgbBack = Style_RgbAlpha(rgbBack, bckgrnd, min(0xFF, alpha + 50)); } SendMessage(hwnd, SCI_MARKERSETFORE, MARKER_NP3_BOOKMARK, rgbFore); @@ -3989,7 +4015,7 @@ void Style_SetLexerFromFile(HWND hwnd,LPCWSTR lpszFile) StrTrimA(tchText," \t\n\r"); pLexSniffed = Style_SniffShebang(tchText); if (pLexSniffed) { - if (Encoding_Current(CPI_GET) != g_DOSEncoding || pLexSniffed != &lexStandard || ( + if ((Encoding_Current(CPI_GET) != g_DOSEncoding) || !IsLexerStandard(pLexSniffed) || ( StringCchCompareIX(lpszExt,L"nfo") && StringCchCompareIX(lpszExt,L"diz"))) { // Although .nfo and .diz were removed from the default lexer's // default extensions list, they may still presist in the user's INI @@ -4176,25 +4202,16 @@ void Style_SetDefaultFont(HWND hwnd, BOOL bGlobalDefault) { WCHAR newStyle[BUFSIZE_STYLE_VALUE] = { L'\0' }; - BOOL bIsStdLexer = (bGlobalDefault || (g_pLexCurrent == &lexStandard)); + const PEDITLEXER pLexer = bGlobalDefault ? GetCurrentStdLexer() : g_pLexCurrent; + const PEDITSTYLE pLexerDefStyle = &(pLexer->Styles[STY_DEFAULT]); - const PEDITLEXER pLexer = bIsStdLexer ? &lexStandard : g_pLexCurrent; - const int iStyle = bIsStdLexer ? STDLEXID(STY_DEFAULT) : STY_DEFAULT; + StringCchCopyW(newStyle, COUNTOF(newStyle), pLexer->Styles[STY_DEFAULT].szValue); - StringCchCopyW(newStyle, COUNTOF(newStyle), pLexer->Styles[iStyle].szValue); - - BOOL bIsGlobalDefault = ((pLexer->Styles[iStyle].rid == 63100) || (pLexer->Styles[iStyle].rid == 63112)); - //(StringCchCompareIX(pLexer->Styles[iStyle].pszName, L"Default Style") == 0) || - //(StringCchCompareIX(pLexer->Styles[iStyle].pszName, L"2nd Default Style") == 0); - - BOOL bIsCurrentDefault = (pLexer->Styles[iStyle].rid == 63126); - //(StringCchCompareIX(pLexer->Styles[iStyle].pszName, L"Default") == 0); - - if (Style_SelectFont(hwnd, newStyle, COUNTOF(newStyle), pLexer->pszName, pLexer->Styles[iStyle].pszName, - bIsGlobalDefault, bIsCurrentDefault, FALSE, TRUE)) + if (Style_SelectFont(hwnd, newStyle, COUNTOF(newStyle), pLexer->pszName, pLexer->Styles[STY_DEFAULT].pszName, + IsStyleStandardDefault(pLexerDefStyle), IsStyleSchemeDefault(pLexerDefStyle), FALSE, TRUE)) { // set new styles to current lexer's default text - StringCchCopyW(pLexer->Styles[iStyle].szValue, COUNTOF(pLexer->Styles[iStyle].szValue), newStyle); + StringCchCopyW(pLexerDefStyle->szValue, COUNTOF(pLexerDefStyle->szValue), newStyle); g_fStylesModified = TRUE; // redraw current(!) lexer Style_SetLexer(hwnd, g_pLexCurrent); @@ -4843,7 +4860,7 @@ BOOL Style_SelectFont(HWND hwnd,LPWSTR lpszStyle,int cchStyle, LPCWSTR sLexerNam WCHAR wchFontName[64] = { L'\0' }; if (!Style_StrGetFont(lpszStyle, wchFontName, COUNTOF(wchFontName))) { - if (!Style_StrGetFont(lexStandard.Styles[STDLEXID(STY_DEFAULT)].szValue, wchFontName, COUNTOF(wchFontName))) + if (!Style_StrGetFont(GetCurrentStdLexer()->Styles[STY_DEFAULT].szValue, wchFontName, COUNTOF(wchFontName))) { Style_StrGetFont(L"font:Default", wchFontName, COUNTOF(wchFontName)); } @@ -5187,7 +5204,8 @@ void Style_SetStyles(HWND hwnd, int iStyle, LPCWSTR lpszStyle) } // Size values are relative to iBaseFontSize - int iValue = (g_pLexCurrent == &lexStandard) ? Style_GetBaseFontSize(hwnd) : Style_GetCurrentFontSize(hwnd); + int iValue = IsLexerStandard(g_pLexCurrent) ? Style_GetBaseFontSize(hwnd) : Style_GetCurrentFontSize(hwnd); + if (Style_StrGetSize(lpszStyle, &iValue)) { SendMessage(hwnd, SCI_STYLESETSIZE, iStyle, (LPARAM)iValue); //or Fractional @@ -5485,7 +5503,7 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP bChgNfy = TRUE; \ } \ } \ - if (bChgNfy && ((pCurrentLexer == &lexStandard) || (pCurrentLexer == g_pLexCurrent))) { \ + if (bChgNfy && ( IsLexerStandard(pCurrentLexer) || (pCurrentLexer == g_pLexCurrent))) { \ Style_SetLexer(g_hwndEdit, g_pLexCurrent); \ } \ } @@ -5526,9 +5544,11 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP SetDlgItemText(hwnd, IDC_STYLEEDIT_ROOT, pCurrentLexer->szExtensions); DialogEnableWindow(hwnd, IDC_STYLEEDIT_ROOT, TRUE); - if (pCurrentLexer == &lexStandard) { - pCurrentStyle = &(pCurrentLexer->Styles[STDLEXID(STY_DEFAULT)]); - if (!Style_GetUse2ndDefault()) + if (IsLexerStandard(pCurrentLexer)) + { + pCurrentStyle = &(pCurrentLexer->Styles[STY_DEFAULT]); + + if (pCurrentStyle->rid == 63100) StringCchCopyW(label, COUNTOF(label), L"BASE (Default Style):"); else StringCchCopyW(label, COUNTOF(label), L"BASE (2nd Default Style):"); @@ -5552,8 +5572,9 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP // a style has been selected else { - if (pCurrentLexer == &lexStandard) { - if (!Style_GetUse2ndDefault()) + if (IsLexerStandard(pCurrentLexer)) + { + if (pCurrentLexer->Styles[STY_DEFAULT].rid == 63100) StringCchCopyW(label, COUNTOF(label), L"BASE (Default Style):"); else StringCchCopyW(label, COUNTOF(label), L"BASE (2nd Default Style):"); @@ -5563,8 +5584,7 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP } SetDlgItemText(hwnd, IDC_STYLELABEL_ROOT, label); - int iDSID = Style_GetUse2ndDefault() ? STDLEXID(STY_DEFAULT) : STY_DEFAULT; - SetDlgItemText(hwnd, IDC_STYLEEDIT_ROOT, pCurrentLexer->Styles[iDSID].szValue); + SetDlgItemText(hwnd, IDC_STYLEEDIT_ROOT, pCurrentLexer->Styles[STY_DEFAULT].szValue); DialogEnableWindow(hwnd, IDC_STYLEEDIT_ROOT, FALSE); pCurrentStyle = (PEDITSTYLE)lpnmtv->itemNew.lParam; @@ -5714,15 +5734,9 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP WCHAR tch[BUFSIZE_STYLE_VALUE] = { L'\0' }; GetDlgItemText(hwnd, IDC_STYLEEDIT, tch, COUNTOF(tch)); - BOOL bIsGlobalDefault = ((pCurrentStyle->rid == 63100) || (pCurrentStyle->rid == 63112)); - //(StringCchCompareIX(pCurrentStyle->pszName, L"Default Style") == 0) || - //(StringCchCompareIX(pCurrentStyle->pszName, L"2nd Default Style") == 0); - - BOOL bIsCurrentDefault = (pCurrentStyle->rid == 63126); - //(StringCchCompareIX(pCurrentStyle->pszName, L"Default") == 0); - if (Style_SelectFont(hwnd, tch, COUNTOF(tch), pCurrentLexer->pszName, pCurrentStyle->pszName, - bIsGlobalDefault, bIsCurrentDefault, FALSE, TRUE)) { + IsStyleStandardDefault(pCurrentStyle), IsStyleSchemeDefault(pCurrentStyle), FALSE, TRUE)) + { SetDlgItemText(hwnd, IDC_STYLEEDIT, tch); } } diff --git a/src/Styles.h b/src/Styles.h index d97282e3d..c21cace41 100644 --- a/src/Styles.h +++ b/src/Styles.h @@ -59,7 +59,7 @@ typedef struct _editlexer // Number of Lexers in pLexArray -#define NUMLEXERS 45 +#define NUMLEXERS 46 #define MAX_NUM_OF_STYLES_PER_LEXER 64 From 205ccc43438d3e3e9fb02c5dd816e359f1928ebe Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Wed, 10 Jan 2018 18:18:05 +0100 Subject: [PATCH 02/14] + fix: handling initial 1st or 2nd default style in case of "Default Text", shown on int "Customize Schemes..." + fix: crash on navigation between schemes beyond start/end of tree view --- src/Edit.c | 1 - src/Styles.c | 168 ++++++++++++++++++++++++++++----------------------- 2 files changed, 94 insertions(+), 75 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index 7536e086d..5a59be8a1 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -5479,7 +5479,6 @@ int EditReplaceAllInRange(HWND hwnd, LPCEDITFINDREPLACE lpefr, BOOL bShowInfo, i // === iterate over findings and replace strings === - int offset = 0; for (ReplPos_t* pPosPair = (ReplPos_t*)utarray_front(ReplPosUTArray); pPosPair != NULL; diff --git a/src/Styles.c b/src/Styles.c index fddd6e4b6..17eb1fdfe 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -2825,7 +2825,7 @@ EDITLEXER lexNim = { SCLEX_NIM, 63044, L"Nim Source Code", L"nim", L"", &KeyWord // This array holds all the lexers... // Don't forget to change the number of the lexer for HTML and XML // in Notepad2.c ParseCommandLine() if you change this array! -static PEDITLEXER pLexArray[NUMLEXERS] = +static PEDITLEXER g_pLexArray[NUMLEXERS] = { &lexStandard, // Default Text &lexStandard2nd, // 2nd Default Text @@ -2878,7 +2878,7 @@ static PEDITLEXER pLexArray[NUMLEXERS] = // Currently used lexer static int g_iDefaultLexer = 0; -static PEDITLEXER g_pLexCurrent = &lexStandard; // pLexArray[g_iDefaultLexer]; +static PEDITLEXER g_pLexCurrent = &lexStandard; // g_pLexArray[g_iDefaultLexer]; static BOOL g_fStylesModified = FALSE; static BOOL g_fWarnedNoIniFile = FALSE; @@ -2984,7 +2984,7 @@ void Style_Load() // default scheme g_iDefaultLexer = IniSectionGetInt(pIniSection,L"DefaultScheme",0); - g_iDefaultLexer = min(max(g_iDefaultLexer,0),COUNTOF(pLexArray)-1); + g_iDefaultLexer = min(max(g_iDefaultLexer,0),COUNTOF(g_pLexArray)-1); // auto select g_bAutoSelect = (IniSectionGetInt(pIniSection,L"AutoSelect",1)) ? 1 : 0; @@ -2996,16 +2996,16 @@ void Style_Load() g_cyStyleSelectDlg = IniSectionGetInt(pIniSection,L"SelectDlgSizeY",0); g_cyStyleSelectDlg = max(g_cyStyleSelectDlg,324); - for (iLexer = 0; iLexer < COUNTOF(pLexArray); iLexer++) { - LoadIniSection(pLexArray[iLexer]->pszName,pIniSection,cchIniSection); - IniSectionGetString(pIniSection, L"FileNameExtensions", pLexArray[iLexer]->pszDefExt, - pLexArray[iLexer]->szExtensions, COUNTOF(pLexArray[iLexer]->szExtensions)); + for (iLexer = 0; iLexer < COUNTOF(g_pLexArray); iLexer++) { + LoadIniSection(g_pLexArray[iLexer]->pszName,pIniSection,cchIniSection); + IniSectionGetString(pIniSection, L"FileNameExtensions", g_pLexArray[iLexer]->pszDefExt, + g_pLexArray[iLexer]->szExtensions, COUNTOF(g_pLexArray[iLexer]->szExtensions)); i = 0; - while (pLexArray[iLexer]->Styles[i].iStyle != -1) { - IniSectionGetString(pIniSection,pLexArray[iLexer]->Styles[i].pszName, - pLexArray[iLexer]->Styles[i].pszDefault, - pLexArray[iLexer]->Styles[i].szValue, - COUNTOF(pLexArray[iLexer]->Styles[i].szValue)); + while (g_pLexArray[iLexer]->Styles[i].iStyle != -1) { + IniSectionGetString(pIniSection,g_pLexArray[iLexer]->Styles[i].pszName, + g_pLexArray[iLexer]->Styles[i].pszDefault, + g_pLexArray[iLexer]->Styles[i].szValue, + COUNTOF(g_pLexArray[iLexer]->Styles[i].szValue)); i++; } } @@ -3056,15 +3056,15 @@ void Style_Save() return; } - for (iLexer = 0; iLexer < COUNTOF(pLexArray); iLexer++) { - IniSectionSetString(pIniSection,L"FileNameExtensions",pLexArray[iLexer]->szExtensions); + for (iLexer = 0; iLexer < COUNTOF(g_pLexArray); iLexer++) { + IniSectionSetString(pIniSection,L"FileNameExtensions",g_pLexArray[iLexer]->szExtensions); i = 0; - while (pLexArray[iLexer]->Styles[i].iStyle != -1) { - IniSectionSetString(pIniSection,pLexArray[iLexer]->Styles[i].pszName,pLexArray[iLexer]->Styles[i].szValue); + while (g_pLexArray[iLexer]->Styles[i].iStyle != -1) { + IniSectionSetString(pIniSection,g_pLexArray[iLexer]->Styles[i].pszName,g_pLexArray[iLexer]->Styles[i].szValue); i++; } - SaveIniSection(pLexArray[iLexer]->pszName,pIniSection); + SaveIniSection(g_pLexArray[iLexer]->pszName,pIniSection); ZeroMemory(pIniSection,LocalSize(pIniSection)); } LocalFree(pIniSection); @@ -3100,16 +3100,16 @@ BOOL Style_Import(HWND hwnd) WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR)*32*1024); int cchIniSection = (int)LocalSize(pIniSection)/sizeof(WCHAR); - for (iLexer = 0; iLexer < COUNTOF(pLexArray); iLexer++) { - if (GetPrivateProfileSection(pLexArray[iLexer]->pszName,pIniSection,cchIniSection,szFile)) { - IniSectionGetString(pIniSection, L"FileNameExtensions", pLexArray[iLexer]->pszDefExt, - pLexArray[iLexer]->szExtensions, COUNTOF(pLexArray[iLexer]->szExtensions)); + for (iLexer = 0; iLexer < COUNTOF(g_pLexArray); iLexer++) { + if (GetPrivateProfileSection(g_pLexArray[iLexer]->pszName,pIniSection,cchIniSection,szFile)) { + IniSectionGetString(pIniSection, L"FileNameExtensions", g_pLexArray[iLexer]->pszDefExt, + g_pLexArray[iLexer]->szExtensions, COUNTOF(g_pLexArray[iLexer]->szExtensions)); i = 0; - while (pLexArray[iLexer]->Styles[i].iStyle != -1) { - IniSectionGetString(pIniSection,pLexArray[iLexer]->Styles[i].pszName, - pLexArray[iLexer]->Styles[i].pszDefault, - pLexArray[iLexer]->Styles[i].szValue, - COUNTOF(pLexArray[iLexer]->Styles[i].szValue)); + while (g_pLexArray[iLexer]->Styles[i].iStyle != -1) { + IniSectionGetString(pIniSection,g_pLexArray[iLexer]->Styles[i].pszName, + g_pLexArray[iLexer]->Styles[i].pszDefault, + g_pLexArray[iLexer]->Styles[i].szValue, + COUNTOF(g_pLexArray[iLexer]->Styles[i].szValue)); i++; } } @@ -3149,14 +3149,14 @@ BOOL Style_Export(HWND hwnd) WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR)*32*1024); //int cchIniSection = (int)LocalSize(pIniSection)/sizeof(WCHAR); - for (int iLexer = 0; iLexer < COUNTOF(pLexArray); iLexer++) { - IniSectionSetString(pIniSection,L"FileNameExtensions",pLexArray[iLexer]->szExtensions); + for (int iLexer = 0; iLexer < COUNTOF(g_pLexArray); iLexer++) { + IniSectionSetString(pIniSection,L"FileNameExtensions",g_pLexArray[iLexer]->szExtensions); int i = 0; - while (pLexArray[iLexer]->Styles[i].iStyle != -1) { - IniSectionSetString(pIniSection,pLexArray[iLexer]->Styles[i].pszName,pLexArray[iLexer]->Styles[i].szValue); + while (g_pLexArray[iLexer]->Styles[i].iStyle != -1) { + IniSectionSetString(pIniSection,g_pLexArray[iLexer]->Styles[i].pszName,g_pLexArray[iLexer]->Styles[i].szValue); i++; } - if (!WritePrivateProfileSection(pLexArray[iLexer]->pszName,pIniSection,szFile)) + if (!WritePrivateProfileSection(g_pLexArray[iLexer]->pszName,pIniSection,szFile)) dwError = GetLastError(); ZeroMemory(pIniSection,LocalSize(pIniSection)); } @@ -3937,14 +3937,14 @@ PEDITLEXER __fastcall Style_SniffShebang(char *pchText) // PEDITLEXER __fastcall Style_MatchLexer(LPCWSTR lpszMatch,BOOL bCheckNames) { int i; - WCHAR tch[COUNTOF(pLexArray[0]->szExtensions)] = { L'\0' }; + WCHAR tch[COUNTOF(g_pLexArray[0]->szExtensions)] = { L'\0' }; WCHAR *p1,*p2; if (!bCheckNames) { - for (i = 0; i < COUNTOF(pLexArray); i++) { + for (i = 0; i < COUNTOF(g_pLexArray); i++) { ZeroMemory(tch,sizeof(WCHAR)*COUNTOF(tch)); - StringCchCopy(tch,COUNTOF(tch),pLexArray[i]->szExtensions); + StringCchCopy(tch,COUNTOF(tch),g_pLexArray[i]->szExtensions); p1 = tch; while (*p1) { p2 = StrChr(p1,L';'); @@ -3954,7 +3954,7 @@ PEDITLEXER __fastcall Style_MatchLexer(LPCWSTR lpszMatch,BOOL bCheckNames) { p2 = StrEnd(p1); StrTrim(p1,L" ."); if (StringCchCompareIX(p1,lpszMatch) == 0) - return(pLexArray[i]); + return(g_pLexArray[i]); p1 = p2 + 1; } } @@ -3965,9 +3965,9 @@ PEDITLEXER __fastcall Style_MatchLexer(LPCWSTR lpszMatch,BOOL bCheckNames) { int cch = lstrlen(lpszMatch); if (cch >= 3) { - for (i = 0; i < COUNTOF(pLexArray); i++) { - if (StrCmpNI(pLexArray[i]->pszName,lpszMatch,cch) == 0) - return(pLexArray[i]); + for (i = 0; i < COUNTOF(g_pLexArray); i++) { + if (StrCmpNI(g_pLexArray[i]->pszName,lpszMatch,cch) == 0) + return(g_pLexArray[i]); } } } @@ -3998,7 +3998,7 @@ void Style_SetLexerFromFile(HWND hwnd,LPCWSTR lpszFile) { LPWSTR lpszExt = PathFindExtension(lpszFile); BOOL bFound = FALSE; - PEDITLEXER pLexNew = pLexArray[g_iDefaultLexer]; + PEDITLEXER pLexNew = g_pLexArray[g_iDefaultLexer]; PEDITLEXER pLexSniffed; if ((fvCurFile.mask & FV_MODE) && fvCurFile.tchMode[0]) { @@ -4145,7 +4145,7 @@ void Style_SetLexerFromName(HWND hwnd,LPCWSTR lpszFile,LPCWSTR lpszName) // void Style_SetDefaultLexer(HWND hwnd) { - Style_SetLexer(hwnd, pLexArray[g_iDefaultLexer]); + Style_SetLexer(hwnd, g_pLexArray[g_iDefaultLexer]); } @@ -4175,8 +4175,8 @@ void Style_SetXMLLexer(HWND hwnd) // void Style_SetLexerFromID(HWND hwnd,int id) { - if (id >= 0 && id < COUNTOF(pLexArray)) { - Style_SetLexer(hwnd,pLexArray[id]); + if (id >= 0 && id < COUNTOF(g_pLexArray)) { + Style_SetLexer(hwnd,g_pLexArray[id]); } } @@ -5349,10 +5349,12 @@ HTREEITEM Style_AddLexerToTreeView(HWND hwnd,PEDITLEXER plex) tvis.hInsertAfter = TVI_LAST; tvis.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; + if (GetString(plex->rid,tch,COUNTOF(tch))) tvis.item.pszText = tch; else tvis.item.pszText = plex->pszName; + tvis.item.iImage = Style_GetLexerIconId(plex); tvis.item.iSelectedImage = tvis.item.iImage; tvis.item.lParam = (LPARAM)plex; @@ -5425,11 +5427,8 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP case WM_INITDIALOG: { - int i; SHFILEINFO shfi; LOGFONT lf; - HTREEITEM currentLex = NULL; - int found = 0; hwndTV = GetDlgItem(hwnd,IDC_STYLELIST); fDragging = FALSE; @@ -5438,24 +5437,35 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP (HIMAGELIST)SHGetFileInfo(L"C:\\",0,&shfi,sizeof(SHFILEINFO), SHGFI_SMALLICON | SHGFI_SYSICONINDEX),TVSIL_NORMAL); - // Add lexers - for (i = 0; i < COUNTOF(pLexArray); i++) - { - if (!found && (StringCchCompareX(pLexArray[i]->pszName,g_pLexCurrent->pszName) == 0)) - { - found = 1; - currentLex = Style_AddLexerToTreeView(hwndTV,pLexArray[i]); + // find current non-standard lexer + int found = -1; + for (int i = 2; i < COUNTOF(g_pLexArray); i++) { + if (StringCchCompareX(g_pLexArray[i]->pszName, g_pLexCurrent->pszName) == 0) { + found = i; + break; } + } + + // Build lexer tree view + HTREEITEM hCurrentTVLex = NULL; + for (int i = 0; i < COUNTOF(g_pLexArray); i++) + { + if (i == found) + hCurrentTVLex = Style_AddLexerToTreeView(hwndTV,g_pLexArray[i]); else - Style_AddLexerToTreeView(hwndTV,pLexArray[i]); + Style_AddLexerToTreeView(hwndTV,g_pLexArray[i]); + } + if (!hCurrentTVLex) + { + hCurrentTVLex = TreeView_GetRoot(hwndTV); + if (Style_GetUse2ndDefault()) + hCurrentTVLex = TreeView_GetNextSibling(hwndTV, hCurrentTVLex); } pCurrentLexer = NULL; pCurrentStyle = NULL; - //SetExplorerTheme(hwndTV); - //TreeView_Expand(hwndTV,TreeView_GetRoot(hwndTV),TVE_EXPAND); - TreeView_Select(hwndTV,currentLex,TVGN_CARET); + TreeView_Select(hwndTV, hCurrentTVLex, TVGN_CARET); SendDlgItemMessage(hwnd,IDC_STYLEEDIT,EM_LIMITTEXT, max(BUFSIZE_STYLE_VALUE, BUFZIZE_STYLE_EXTENTIONS)-1,0); @@ -5800,19 +5810,29 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP break; case IDC_PREVSTYLE: - APPLY_DIALOG_ITEM_TEXT; - if (TreeView_GetSelection(hwndTV)) { - TreeView_Select(hwndTV, TreeView_GetPrevVisible(hwndTV,TreeView_GetSelection(hwndTV)), TVGN_CARET); + { + APPLY_DIALOG_ITEM_TEXT; + HTREEITEM hSel = TreeView_GetSelection(hwndTV); + if (hSel) { + HTREEITEM hPrev = TreeView_GetPrevVisible(hwndTV, hSel); + if (hPrev) + TreeView_Select(hwndTV, hPrev, TVGN_CARET); + } + PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)(GetDlgItem(hwnd, IDC_STYLEEDIT)), 1); } - PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)(GetDlgItem(hwnd, IDC_STYLEEDIT)), 1); break; case IDC_NEXTSTYLE: - APPLY_DIALOG_ITEM_TEXT; - if (TreeView_GetSelection(hwndTV)) { - TreeView_Select(hwndTV, TreeView_GetNextVisible(hwndTV, TreeView_GetSelection(hwndTV)), TVGN_CARET); + { + APPLY_DIALOG_ITEM_TEXT; + HTREEITEM hSel = TreeView_GetSelection(hwndTV); + if (hSel) { + HTREEITEM hNext = TreeView_GetNextVisible(hwndTV, hSel); + if (hNext) + TreeView_Select(hwndTV, hNext, TVGN_CARET); + } + PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)(GetDlgItem(hwnd, IDC_STYLEEDIT)), 1); } - PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)(GetDlgItem(hwnd, IDC_STYLEEDIT)), 1); break; case IDOK: @@ -5850,11 +5870,11 @@ void Style_ConfigDlg(HWND hwnd) // Backup Styles c = 0; - for (iLexer = 0; iLexer < COUNTOF(pLexArray); iLexer++) { - StyleBackup[c++] = StrDup(pLexArray[iLexer]->szExtensions); + for (iLexer = 0; iLexer < COUNTOF(g_pLexArray); iLexer++) { + StyleBackup[c++] = StrDup(g_pLexArray[iLexer]->szExtensions); i = 0; - while (pLexArray[iLexer]->Styles[i].iStyle != -1) { - StyleBackup[c++] = StrDup(pLexArray[iLexer]->Styles[i].szValue); + while (g_pLexArray[iLexer]->Styles[i].iStyle != -1) { + StyleBackup[c++] = StrDup(g_pLexArray[iLexer]->Styles[i].szValue); i++; } } @@ -5867,11 +5887,11 @@ void Style_ConfigDlg(HWND hwnd) { // Restore Styles c = 0; - for (iLexer = 0; iLexer < COUNTOF(pLexArray); iLexer++) { - StringCchCopy(pLexArray[iLexer]->szExtensions,COUNTOF(pLexArray[iLexer]->szExtensions),StyleBackup[c++]); + for (iLexer = 0; iLexer < COUNTOF(g_pLexArray); iLexer++) { + StringCchCopy(g_pLexArray[iLexer]->szExtensions,COUNTOF(g_pLexArray[iLexer]->szExtensions),StyleBackup[c++]); i = 0; - while (pLexArray[iLexer]->Styles[i].iStyle != -1) { - StringCchCopy(pLexArray[iLexer]->Styles[i].szValue,COUNTOF(pLexArray[iLexer]->Styles[i].szValue),StyleBackup[c++]); + while (g_pLexArray[iLexer]->Styles[i].iStyle != -1) { + StringCchCopy(g_pLexArray[iLexer]->Styles[i].szValue,COUNTOF(g_pLexArray[iLexer]->Styles[i].szValue),StyleBackup[c++]); i++; } } @@ -5965,8 +5985,8 @@ INT_PTR CALLBACK Style_SelectLexerDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPAR ListView_InsertColumn(hwndLV,0,&lvc); // Add lexers - for (i = 0; i < COUNTOF(pLexArray); i++) { - Style_AddLexerToListView(hwndLV, pLexArray[i]); + for (i = 0; i < COUNTOF(g_pLexArray); i++) { + Style_AddLexerToListView(hwndLV, g_pLexArray[i]); } ListView_SetColumnWidth(hwndLV,0,LVSCW_AUTOSIZE_USEHEADER); From 13e53e36ed34e995d7ac204a1d4248029ce79fc2 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Wed, 10 Jan 2018 19:26:04 +0100 Subject: [PATCH 03/14] + fix: disable (using 1st Default Style) "Associated filename extensions" for "2nd Default Style" --- src/Styles.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Styles.c b/src/Styles.c index 17eb1fdfe..28dcfc3c4 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -5558,10 +5558,14 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP { pCurrentStyle = &(pCurrentLexer->Styles[STY_DEFAULT]); - if (pCurrentStyle->rid == 63100) + if (pCurrentStyle->rid == 63100) { StringCchCopyW(label, COUNTOF(label), L"BASE (Default Style):"); - else + } + else { StringCchCopyW(label, COUNTOF(label), L"BASE (2nd Default Style):"); + SetDlgItemText(hwnd, IDC_STYLEEDIT_ROOT, lexStandard.szExtensions); + DialogEnableWindow(hwnd, IDC_STYLEEDIT_ROOT, FALSE); + } } else { pCurrentStyle = &(pCurrentLexer->Styles[STY_DEFAULT]); From 5869b233f454dbf1bc65603e95c57b859d69aa87 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Wed, 10 Jan 2018 19:56:10 +0100 Subject: [PATCH 04/14] + fix: clone associated filename extension list of Default Style (for 2nd Default Style) --- src/Styles.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Styles.c b/src/Styles.c index 28dcfc3c4..11a465e77 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -3010,6 +3010,9 @@ void Style_Load() } } LocalFree(pIniSection); + + // 2nd Default Style has same filename extension list as (1st) Default Style + StringCchCopyW(lexStandard2nd.szExtensions, COUNTOF(lexStandard2nd.szExtensions), lexStandard.szExtensions); } @@ -5563,7 +5566,6 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP } else { StringCchCopyW(label, COUNTOF(label), L"BASE (2nd Default Style):"); - SetDlgItemText(hwnd, IDC_STYLEEDIT_ROOT, lexStandard.szExtensions); DialogEnableWindow(hwnd, IDC_STYLEEDIT_ROOT, FALSE); } } From b25565031db3202924c7ae671ec854cd484c32fe Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Wed, 10 Jan 2018 23:54:07 +0100 Subject: [PATCH 05/14] + enhancement: status bar information about usage of 2nd Default Style --- src/Notepad3.c | 35 +++++++++++++++++++---------------- src/Notepad3.rc | 2 +- src/Styles.c | 14 +++++++++++--- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/Notepad3.c b/src/Notepad3.c index da8a779e8..b7120db89 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1488,7 +1488,6 @@ void CreateBars(HWND hwnd,HINSTANCE hInstance) BOOL bExternalBitmap = FALSE; DWORD dwToolbarStyle = WS_TOOLBAR; - DWORD dwStatusbarStyle = WS_CHILD | WS_CLIPSIBLINGS; DWORD dwReBarStyle = WS_REBAR; BOOL bIsPrivAppThemed = PrivateIsAppThemed(); @@ -1617,6 +1616,8 @@ void CreateBars(HWND hwnd,HINSTANCE hInstance) SendMessage(hwndToolbar,TB_GETITEMRECT,0,(LPARAM)&rc); //SendMessage(hwndToolbar,TB_SETINDENT,2,0); + DWORD dwStatusbarStyle = WS_CHILD | WS_CLIPSIBLINGS; + if (bShowStatusbar) dwStatusbarStyle |= WS_VISIBLE; @@ -1852,11 +1853,11 @@ void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam) EndDeferWindowPos(hdwp); // Statusbar width - aWidth[0] = max(120,min(cx/3,StatusCalcPaneWidth(g_hwndStatus,L" Ln 9'999'999 : 9'999'999 Col 9'999'999 : 999 Sel 9'999'999 SelLn 9'999'999 Occ 9'999'999 "))); - aWidth[1] = aWidth[0] + StatusCalcPaneWidth(g_hwndStatus,L" 9'999'999 Bytes [UTF-8] "); - aWidth[2] = aWidth[1] + StatusCalcPaneWidth(g_hwndStatus,L" Unicode (UTF-8) Signature "); - aWidth[3] = aWidth[2] + StatusCalcPaneWidth(g_hwndStatus,L" CR+LF "); - aWidth[4] = aWidth[3] + StatusCalcPaneWidth(g_hwndStatus,L" OVR "); + aWidth[0] = max(150,min(cx*2/5,StatusCalcPaneWidth(g_hwndStatus,L" Ln 9'999'999 : 9'999'999 Col 9'999'999 : 999 Sel 9'999'999 SelLn 9'999'999 Occ 9'999'999 "))); + aWidth[1] = aWidth[0] + StatusCalcPaneWidth(g_hwndStatus,L" 9'999'999 Bytes [utf-8] "); + aWidth[2] = aWidth[1] + StatusCalcPaneWidth(g_hwndStatus,L" Unicode (UTF-8) Signature "); + aWidth[3] = aWidth[2] + StatusCalcPaneWidth(g_hwndStatus,L" CR+LF "); + aWidth[4] = aWidth[3] + StatusCalcPaneWidth(g_hwndStatus,L" OVR "); aWidth[5] = -1; SendMessage(g_hwndStatus,SB_SETPARTS,COUNTOF(aWidth),(LPARAM)aWidth); @@ -7212,7 +7213,8 @@ void UpdateStatusbar() static WCHAR tchDocPos[256] = { L'\0' }; static WCHAR tchBytes[64] = { L'\0' }; - static WCHAR tchDocSize[256] = { L'\0' }; + static WCHAR tchDocSize[64] = { L'\0' }; + static WCHAR tchEncoding[64] = { L'\0' }; static WCHAR tchEOLMode[32] = { L'\0' }; static WCHAR tchOvrMode[32] = { L'\0' }; @@ -7256,15 +7258,15 @@ void UpdateStatusbar() { if ((iMarkOccurrencesMaxCount < 0) || (iMarkOccurrencesCount < iMarkOccurrencesMaxCount)) { - StringCchPrintf(tchOcc, COUNTOF(tchOcc), L"%i", iMarkOccurrencesCount); + StringCchPrintf(tchOcc, COUNTOF(tchOcc), L"%i ", iMarkOccurrencesCount); FormatNumberStr(tchOcc); } else { - StringCchPrintf(tchOcc, COUNTOF(tchOcc), L">= %i", iMarkOccurrencesMaxCount); + StringCchPrintf(tchOcc, COUNTOF(tchOcc), L">= %i ", iMarkOccurrencesMaxCount); } } else { - StringCchCopy(tchOcc, COUNTOF(tchOcc), L"--"); + StringCchCopy(tchOcc, COUNTOF(tchOcc), L"-- "); } // Print number of selected lines in statusbar @@ -7288,30 +7290,31 @@ void UpdateStatusbar() FormatString(tchDocSize, COUNTOF(tchDocSize), IDS_DOCSIZE, tchBytes); Encoding_GetLabel(Encoding_Current(CPI_GET)); + StringCchPrintf(tchEncoding, COUNTOF(tchEncoding), L" %s ", mEncoding[Encoding_Current(CPI_GET)].wchLabel); if (iEOLMode == SC_EOL_CR) { - StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L" CR"); + StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L" CR "); } else if (iEOLMode == SC_EOL_LF) { - StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L" LF"); + StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L" LF "); } else { - StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L" CR+LF"); + StringCchCopy(tchEOLMode, COUNTOF(tchEOLMode), L" CR+LF "); } if (SendMessage(g_hwndEdit, SCI_GETOVERTYPE, 0, 0)) { - StringCchCopy(tchOvrMode, COUNTOF(tchOvrMode), L" OVR"); + StringCchCopy(tchOvrMode, COUNTOF(tchOvrMode), L" OVR "); } else { - StringCchCopy(tchOvrMode, COUNTOF(tchOvrMode), L" INS"); + StringCchCopy(tchOvrMode, COUNTOF(tchOvrMode), L" INS "); } Style_GetCurrentLexerName(tchLexerName, COUNTOF(tchLexerName)); StatusSetText(g_hwndStatus, STATUS_DOCPOS, tchDocPos); StatusSetText(g_hwndStatus, STATUS_DOCSIZE, tchDocSize); - StatusSetText(g_hwndStatus, STATUS_CODEPAGE, mEncoding[Encoding_Current(CPI_GET)].wchLabel); + StatusSetText(g_hwndStatus, STATUS_CODEPAGE, tchEncoding); StatusSetText(g_hwndStatus, STATUS_EOLMODE, tchEOLMode); StatusSetText(g_hwndStatus, STATUS_OVRMODE, tchOvrMode); StatusSetText(g_hwndStatus, STATUS_LEXER, tchLexerName); diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 2188849f9..b1b1c7368 100644 --- a/src/Notepad3.rc +++ b/src/Notepad3.rc @@ -1418,7 +1418,7 @@ BEGIN IDS_READONLY "(Read Only)" IDS_DOCPOS " Ln %s / %s Col %s Sel %s SelLn %s Occ %s " IDS_DOCPOS2 " Ln %s / %s Col %s / %s Sel %s SelLn %s Occ %s " - IDS_DOCSIZE " %s [UTF-8]" + IDS_DOCSIZE " %s [utf-8]" IDS_LOADFILE "Loading ""%s""..." IDS_SAVEFILE "Saving ""%s""..." IDS_PRINTFILE "Printing page %i..." diff --git a/src/Styles.c b/src/Styles.c index 11a465e77..bc9a63e16 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -5295,10 +5295,18 @@ void Style_SetFontQuality(HWND hwnd,LPCWSTR lpszStyle) { // // Style_GetCurrentLexerName() // -void Style_GetCurrentLexerName(LPWSTR lpszName,int cchName) +void Style_GetCurrentLexerName(LPWSTR lpszName, int cchName) { - if (!GetString(g_pLexCurrent->rid,lpszName,cchName)) - StringCchCopyN(lpszName,cchName,g_pLexCurrent->pszName,cchName); + if (IsLexerStandard(g_pLexCurrent)) { + StringCchPrintfW(lpszName, cchName, L" %s", GetCurrentStdLexer()->pszName); + } + else { + WCHAR wch[128] = { L'\0' }; + if (!GetString(g_pLexCurrent->rid, wch, COUNTOF(wch))) { + StringCchCopyW(wch, COUNTOF(wch), g_pLexCurrent->pszName); + } + StringCchPrintfW(lpszName, cchName, L" %s%s", wch, (Style_GetUse2ndDefault() ? L" [2nd]" : L"")); + } } From 82db0b8138f29356c61ddaac8b0da893568b130d Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 11 Jan 2018 00:28:16 +0100 Subject: [PATCH 06/14] + change: view "2nd Default Style" as (dbl-clickable) status bar item --- src/Notepad3.c | 40 +++++++++++++++++++++++++++------------- src/Notepad3.h | 3 ++- src/Styles.c | 6 ++---- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/Notepad3.c b/src/Notepad3.c index b7120db89..a58c7bc01 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1803,9 +1803,6 @@ void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam) int x,y,cx,cy; HDWP hdwp; - // Statusbar - int aWidth[6]; - if (wParam == SIZE_MINIMIZED) return; @@ -1853,12 +1850,16 @@ void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam) EndDeferWindowPos(hdwp); // Statusbar width - aWidth[0] = max(150,min(cx*2/5,StatusCalcPaneWidth(g_hwndStatus,L" Ln 9'999'999 : 9'999'999 Col 9'999'999 : 999 Sel 9'999'999 SelLn 9'999'999 Occ 9'999'999 "))); - aWidth[1] = aWidth[0] + StatusCalcPaneWidth(g_hwndStatus,L" 9'999'999 Bytes [utf-8] "); - aWidth[2] = aWidth[1] + StatusCalcPaneWidth(g_hwndStatus,L" Unicode (UTF-8) Signature "); - aWidth[3] = aWidth[2] + StatusCalcPaneWidth(g_hwndStatus,L" CR+LF "); - aWidth[4] = aWidth[3] + StatusCalcPaneWidth(g_hwndStatus,L" OVR "); - aWidth[5] = -1; + int aWidth[7]; + aWidth[STATUS_DOCPOS] = max(150,min(cx*2/5,StatusCalcPaneWidth(g_hwndStatus,L" Ln 9'999'999 : 9'999'999 Col 9'999'999 : 999 Sel 9'999'999 SelLn 9'999'999 Occ 9'999'999 "))); + aWidth[STATUS_DOCSIZE] = aWidth[STATUS_DOCPOS] + StatusCalcPaneWidth(g_hwndStatus,L" 9'999'999 Bytes [utf-8] "); + aWidth[STATUS_CODEPAGE] = aWidth[STATUS_DOCSIZE] + StatusCalcPaneWidth(g_hwndStatus,L" Unicode (UTF-8) Signature "); + aWidth[STATUS_EOLMODE] = aWidth[STATUS_CODEPAGE] + StatusCalcPaneWidth(g_hwndStatus,L" CR+LF "); + aWidth[STATUS_OVRMODE] = aWidth[STATUS_EOLMODE] + StatusCalcPaneWidth(g_hwndStatus,L" OVR "); + aWidth[STATUS_2ND_DEF] = aWidth[STATUS_OVRMODE] + StatusCalcPaneWidth(g_hwndStatus, L" 2ND "); + aWidth[STATUS_LEXER] = -1; + + SendMessage(g_hwndStatus,SB_SETPARTS,COUNTOF(aWidth),(LPARAM)aWidth); @@ -5902,14 +5903,18 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) SendMessage(hwnd,WM_COMMAND,MAKELONG(i,1),0); return TRUE; - case STATUS_LEXER: - SendMessage(hwnd,WM_COMMAND,MAKELONG(IDM_VIEW_SCHEME,1),0); - return TRUE; - case STATUS_OVRMODE: SendMessage(g_hwndEdit,SCI_EDITTOGGLEOVERTYPE,0,0); return TRUE; + case STATUS_2ND_DEF: + SendMessage(hwnd, WM_COMMAND, MAKELONG(IDM_VIEW_USE2NDDEFAULT, 1), 0); + return TRUE; + + case STATUS_LEXER: + SendMessage(hwnd, WM_COMMAND, MAKELONG(IDM_VIEW_SCHEME, 1), 0); + return TRUE; + default: return FALSE; } @@ -7218,6 +7223,7 @@ void UpdateStatusbar() static WCHAR tchEOLMode[32] = { L'\0' }; static WCHAR tchOvrMode[32] = { L'\0' }; + static WCHAR tch2ndDef[32] = { L'\0' }; static WCHAR tchLexerName[128] = { L'\0' }; static WCHAR tchLinesSelected[32] = { L'\0' }; @@ -7310,6 +7316,13 @@ void UpdateStatusbar() else { StringCchCopy(tchOvrMode, COUNTOF(tchOvrMode), L" INS "); } + if (Style_GetUse2ndDefault()) + { + StringCchCopy(tch2ndDef, COUNTOF(tch2ndDef), L" 2ND "); + } + else { + StringCchCopy(tch2ndDef, COUNTOF(tch2ndDef), L" STD "); + } Style_GetCurrentLexerName(tchLexerName, COUNTOF(tchLexerName)); StatusSetText(g_hwndStatus, STATUS_DOCPOS, tchDocPos); @@ -7317,6 +7330,7 @@ void UpdateStatusbar() StatusSetText(g_hwndStatus, STATUS_CODEPAGE, tchEncoding); StatusSetText(g_hwndStatus, STATUS_EOLMODE, tchEOLMode); StatusSetText(g_hwndStatus, STATUS_OVRMODE, tchOvrMode); + StatusSetText(g_hwndStatus, STATUS_2ND_DEF, tch2ndDef); StatusSetText(g_hwndStatus, STATUS_LEXER, tchLexerName); //InvalidateRect(g_hwndStatus,NULL,TRUE); diff --git a/src/Notepad3.h b/src/Notepad3.h index d08b30324..a378200b6 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -91,7 +91,8 @@ typedef enum { #define STATUS_CODEPAGE 2 #define STATUS_EOLMODE 3 #define STATUS_OVRMODE 4 -#define STATUS_LEXER 5 +#define STATUS_2ND_DEF 5 +#define STATUS_LEXER 6 #define STATUS_HELP 255 diff --git a/src/Styles.c b/src/Styles.c index bc9a63e16..3016e2082 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -5301,11 +5301,9 @@ void Style_GetCurrentLexerName(LPWSTR lpszName, int cchName) StringCchPrintfW(lpszName, cchName, L" %s", GetCurrentStdLexer()->pszName); } else { - WCHAR wch[128] = { L'\0' }; - if (!GetString(g_pLexCurrent->rid, wch, COUNTOF(wch))) { - StringCchCopyW(wch, COUNTOF(wch), g_pLexCurrent->pszName); + if (!GetString(g_pLexCurrent->rid, lpszName, cchName)) { + StringCchCopyW(lpszName, cchName, g_pLexCurrent->pszName); } - StringCchPrintfW(lpszName, cchName, L" %s%s", wch, (Style_GetUse2ndDefault() ? L" [2nd]" : L"")); } } From dcee85455b1bab9ae876d227371199818c063b43 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 11 Jan 2018 13:06:59 +0100 Subject: [PATCH 07/14] + cleanup: NimLexer = NimrodLexer -> rely on Scintilla distribution for Nim(rod) lexer --- scintilla/Scintilla.vcxproj | 2 +- scintilla/Scintilla.vcxproj.filters | 2 +- scintilla/include/SciLexer.h | 1 - scintilla/include/Scintilla.iface | 1 - scintilla/lexers/LexNim.cxx | 431 ---------------------------- scintilla/src/Catalogue.cxx | 2 +- src/Notepad3.c | 6 +- src/Styles.c | 36 +-- 8 files changed, 24 insertions(+), 457 deletions(-) delete mode 100644 scintilla/lexers/LexNim.cxx diff --git a/scintilla/Scintilla.vcxproj b/scintilla/Scintilla.vcxproj index bd769691f..0774548c5 100644 --- a/scintilla/Scintilla.vcxproj +++ b/scintilla/Scintilla.vcxproj @@ -271,7 +271,7 @@ - + diff --git a/scintilla/Scintilla.vcxproj.filters b/scintilla/Scintilla.vcxproj.filters index f51a20f50..458cb2b1d 100644 --- a/scintilla/Scintilla.vcxproj.filters +++ b/scintilla/Scintilla.vcxproj.filters @@ -441,7 +441,7 @@ onigmo - + lexers diff --git a/scintilla/include/SciLexer.h b/scintilla/include/SciLexer.h index 00415438b..b3bf96956 100644 --- a/scintilla/include/SciLexer.h +++ b/scintilla/include/SciLexer.h @@ -136,7 +136,6 @@ #define SCLEX_EDIFACT 121 #define SCLEX_INDENT 122 #define SCLEX_AHK 200 -#define SCLEX_NIM 201 #define SCLEX_AUTOMATIC 1000 #define SCE_P_DEFAULT 0 #define SCE_P_COMMENTLINE 1 diff --git a/scintilla/include/Scintilla.iface b/scintilla/include/Scintilla.iface index 889d3bc8a..4a833edad 100644 --- a/scintilla/include/Scintilla.iface +++ b/scintilla/include/Scintilla.iface @@ -2926,7 +2926,6 @@ val SCLEX_AUTOMATIC=1000 # Lexical states for SCLEX_PYTHON lex Python=SCLEX_PYTHON SCE_P_ lex Nimrod=SCLEX_NIMROD SCE_P_ -lex Nim=SCLEX_NIM SCE_P_ val SCE_P_DEFAULT=0 val SCE_P_COMMENTLINE=1 val SCE_P_NUMBER=2 diff --git a/scintilla/lexers/LexNim.cxx b/scintilla/lexers/LexNim.cxx deleted file mode 100644 index 311b0a26a..000000000 --- a/scintilla/lexers/LexNim.cxx +++ /dev/null @@ -1,431 +0,0 @@ -// Scintilla source code edit control -// Nim lexer -// (c) 2009 Andreas Rumpf -/** @file LexNim.cxx - ** Lexer for Nim. - **/ -// Copyright 1998-2002 by Neil Hodgson -// The License.txt file describes the conditions under which this software may be distributed. - -#include -#include -#include -#include -#include -#include - -#include "ILexer.h" -#include "Scintilla.h" -#include "SciLexer.h" - -#include "WordList.h" -#include "LexAccessor.h" -#include "Accessor.h" -#include "StyleContext.h" -#include "CharacterSet.h" -#include "LexerModule.h" - -using namespace Scintilla; - -static inline bool IsAWordChar(int ch) { - return (ch >= 0x80) || isalnum(ch) || ch == '_'; -} - -static Sci_Position tillEndOfTripleQuote(Accessor &styler, Sci_Position pos, Sci_Position max) { - /* search for """ */ - for (;;) { - if (styler.SafeGetCharAt(pos, '\0') == '\0') return pos; - if (pos >= max) return pos; - if (styler.Match(pos, "\"\"\"")) { - return pos + 2; - } - pos++; - } -} - -#define CR 13 /* use both because Scite allows changing the line ending */ -#define LF 10 - -static bool inline isNewLine(int ch) { - return ch == CR || ch == LF; -} - -static Sci_Position scanString(Accessor &styler, Sci_Position pos, Sci_Position max, bool rawMode) { - for (;;) { - if (pos >= max) return pos; - char ch = styler.SafeGetCharAt(pos, '\0'); - if (ch == CR || ch == LF || ch == '\0') return pos; - if (ch == '"') return pos; - if (ch == '\\' && !rawMode) { - pos += 2; - } else { - pos++; - } - } -} - -static Sci_Position scanChar(Accessor &styler, Sci_Position pos, Sci_Position max) { - for (;;) { - if (pos >= max) return pos; - char ch = styler.SafeGetCharAt(pos, '\0'); - if (ch == CR || ch == LF || ch == '\0') return pos; - if (ch == '\'' && !isalnum(styler.SafeGetCharAt(pos+1, '\0')) ) - return pos; - if (ch == '\\') { - pos += 2; - } else { - pos++; - } - } -} - -static Sci_Position scanIdent(Accessor &styler, Sci_Position pos, WordList &keywords) { - char buf[100]; /* copy to lowercase and ignore underscores */ - Sci_Position i = 0; - - for (;;) { - char ch = styler.SafeGetCharAt(pos, '\0'); - if (!IsAWordChar(ch)) break; - if (ch != '_' && i < ((int)sizeof(buf))-1) { - buf[i] = static_cast(tolower(ch)); - i++; - } - pos++; - } - buf[i] = '\0'; - /* look for keyword */ - if (keywords.InList(buf)) { - styler.ColourTo(pos-1, SCE_P_WORD); - } else { - styler.ColourTo(pos-1, SCE_P_IDENTIFIER); - } - return pos; -} - -static Sci_Position scanNumber(Accessor &styler, Sci_Position pos) { - char ch, ch2; - ch = styler.SafeGetCharAt(pos, '\0'); - ch2 = styler.SafeGetCharAt(pos+1, '\0'); - if (ch == '0' && (ch2 == 'b' || ch2 == 'B')) { - /* binary number: */ - pos += 2; - for (;;) { - ch = styler.SafeGetCharAt(pos, '\0'); - if (ch == '_' || (ch >= '0' && ch <= '1')) ++pos; - else break; - } - } else if (ch == '0' && - (ch2 == 'o' || ch2 == 'O' || ch2 == 'c' || ch2 == 'C')) { - /* octal number: */ - pos += 2; - for (;;) { - ch = styler.SafeGetCharAt(pos, '\0'); - if (ch == '_' || (ch >= '0' && ch <= '7')) ++pos; - else break; - } - } else if (ch == '0' && (ch2 == 'x' || ch2 == 'X')) { - /* hexadecimal number: */ - pos += 2; - for (;;) { - ch = styler.SafeGetCharAt(pos, '\0'); - if (ch == '_' || (ch >= '0' && ch <= '9') - || (ch >= 'a' && ch <= 'f') - || (ch >= 'A' && ch <= 'F')) ++pos; - else break; - } - } else { - // skip decimal part: - for (;;) { - ch = styler.SafeGetCharAt(pos, '\0'); - if (ch == '_' || (ch >= '0' && ch <= '9')) ++pos; - else break; - } - ch2 = styler.SafeGetCharAt(pos+1, '\0'); - if (ch == '.' && ch2 >= '0' && ch2 <= '9') { - ++pos; // skip '.' - for (;;) { - ch = styler.SafeGetCharAt(pos, '\0'); - if (ch == '_' || (ch >= '0' && ch <= '9')) ++pos; - else break; - } - } - if (ch == 'e' || ch == 'E') { - ++pos; - ch = styler.SafeGetCharAt(pos, '\0'); - if (ch == '-' || ch == '+') ++pos; - for (;;) { - ch = styler.SafeGetCharAt(pos, '\0'); - if (ch == '_' || (ch >= '0' && ch <= '9')) ++pos; - else break; - } - } - } - if (ch == '\'') { - /* a type suffix: */ - pos++; - for (;;) { - ch = styler.SafeGetCharAt(pos); - if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') - || (ch >= 'a' && ch <= 'z') || ch == '_') ++pos; - else break; - } - } - styler.ColourTo(pos-1, SCE_P_NUMBER); - return pos; -} - -/* rewritten from scratch, because I couldn't get rid of the bugs... - (A character based approach sucks!) -*/ -static void ColouriseNimDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, - WordList *keywordlists[], Accessor &styler) { - Sci_Position pos = startPos; - Sci_Position max = startPos + length; - char ch; - WordList &keywords = *keywordlists[0]; - - styler.StartAt(startPos); - styler.StartSegment(startPos); - - switch (initStyle) { - /* check where we are: */ - case SCE_P_TRIPLEDOUBLE: - pos = tillEndOfTripleQuote(styler, pos, max); - styler.ColourTo(pos, SCE_P_TRIPLEDOUBLE); - pos++; - break; - default: /* nothing to do: */ - break; - } - while (pos < max) { - ch = styler.SafeGetCharAt(pos, '\0'); - switch (ch) { - case '\0': return; - case '#': { - bool doccomment = (styler.SafeGetCharAt(pos+1) == '#'); - while (pos < max && !isNewLine(styler.SafeGetCharAt(pos, LF))) pos++; - if (doccomment) - styler.ColourTo(pos, SCE_C_COMMENTLINEDOC); - else - styler.ColourTo(pos, SCE_P_COMMENTLINE); - } break; - case 'r': case 'R': { - if (styler.SafeGetCharAt(pos+1) == '"') { - pos = scanString(styler, pos+2, max, true); - styler.ColourTo(pos, SCE_P_STRING); - pos++; - } else { - pos = scanIdent(styler, pos, keywords); - } - } break; - case '"': - if (styler.Match(pos+1, "\"\"")) { - pos = tillEndOfTripleQuote(styler, pos+3, max); - styler.ColourTo(pos, SCE_P_TRIPLEDOUBLE); - } else { - pos = scanString(styler, pos+1, max, false); - styler.ColourTo(pos, SCE_P_STRING); - } - pos++; - break; - case '\'': - pos = scanChar(styler, pos+1, max); - styler.ColourTo(pos, SCE_P_CHARACTER); - pos++; - break; - default: // identifers, numbers, operators, whitespace - if (ch >= '0' && ch <= '9') { - pos = scanNumber(styler, pos); - } else if (IsAWordChar(ch)) { - pos = scanIdent(styler, pos, keywords); - } else if (ch == '`') { - pos++; - while (pos < max) { - ch = styler.SafeGetCharAt(pos, LF); - if (ch == '`') { - ++pos; - break; - } - if (ch == CR || ch == LF) break; - ++pos; - } - styler.ColourTo(pos, SCE_P_IDENTIFIER); - } else if (strchr("()[]{}:=;-\\/&%$!+<>|^?,.*~@", ch)) { - styler.ColourTo(pos, SCE_P_OPERATOR); - pos++; - } else { - styler.ColourTo(pos, SCE_P_DEFAULT); - pos++; - } - break; - } - } -} - -static bool IsCommentLine(Sci_Position line, Accessor &styler) { - Sci_Position pos = styler.LineStart(line); - Sci_Position eol_pos = styler.LineStart(line + 1) - 1; - for (Sci_Position i = pos; i < eol_pos; i++) { - char ch = styler[i]; - if (ch == '#') - return true; - else if (ch != ' ' && ch != '\t') - return false; - } - return false; -} - -static bool IsQuoteLine(Sci_Position line, Accessor &styler) { - int style = styler.StyleAt(styler.LineStart(line)) & 31; - return ((style == SCE_P_TRIPLE) || (style == SCE_P_TRIPLEDOUBLE)); -} - - -static void FoldNimDoc(Sci_PositionU startPos, Sci_Position length, - int /*initStyle - unused*/, - WordList *[], Accessor &styler) { - const Sci_Position maxPos = startPos + length; - const Sci_Position maxLines = styler.GetLine(maxPos - 1); // Requested last line - const Sci_Position docLines = styler.GetLine(styler.Length() - 1); // Available last line - const bool foldComment = styler.GetPropertyInt("fold.comment.nim") != 0; - const bool foldQuotes = styler.GetPropertyInt("fold.quotes.nim") != 0; - - // Backtrack to previous non-blank line so we can determine indent level - // for any white space lines (needed esp. within triple quoted strings) - // and so we can fix any preceding fold level (which is why we go back - // at least one line in all cases) - int spaceFlags = 0; - Sci_Position lineCurrent = styler.GetLine(startPos); - int indentCurrent = styler.IndentAmount(lineCurrent, &spaceFlags, NULL); - while (lineCurrent > 0) { - lineCurrent--; - indentCurrent = styler.IndentAmount(lineCurrent, &spaceFlags, NULL); - if (!(indentCurrent & SC_FOLDLEVELWHITEFLAG) && - (!IsCommentLine(lineCurrent, styler)) && - (!IsQuoteLine(lineCurrent, styler))) - break; - } - int indentCurrentLevel = indentCurrent & SC_FOLDLEVELNUMBERMASK; - - // Set up initial loop state - startPos = styler.LineStart(lineCurrent); - int prev_state = SCE_P_DEFAULT & 31; - if (lineCurrent >= 1) - prev_state = styler.StyleAt(startPos - 1) & 31; - int prevQuote = foldQuotes && ((prev_state == SCE_P_TRIPLE) || - (prev_state == SCE_P_TRIPLEDOUBLE)); - int prevComment = 0; - if (lineCurrent >= 1) - prevComment = foldComment && IsCommentLine(lineCurrent - 1, styler); - - // Process all characters to end of requested range or end of any triple quote - // or comment that hangs over the end of the range. Cap processing in all cases - // to end of document (in case of unclosed quote or comment at end). - while ((lineCurrent <= docLines) && ((lineCurrent <= maxLines) || - prevQuote || prevComment)) { - - // Gather info - int lev = indentCurrent; - Sci_Position lineNext = lineCurrent + 1; - int indentNext = indentCurrent; - int quote = false; - if (lineNext <= docLines) { - // Information about next line is only available if not at end of document - indentNext = styler.IndentAmount(lineNext, &spaceFlags, NULL); - int style = styler.StyleAt(styler.LineStart(lineNext)) & 31; - quote = foldQuotes && ((style == SCE_P_TRIPLE) || (style == SCE_P_TRIPLEDOUBLE)); - } - const int quote_start = (quote && !prevQuote); - const int quote_continue = (quote && prevQuote); - const int comment = foldComment && IsCommentLine(lineCurrent, styler); - const int comment_start = (comment && !prevComment && (lineNext <= docLines) && - IsCommentLine(lineNext, styler) && - (lev > SC_FOLDLEVELBASE)); - const int comment_continue = (comment && prevComment); - if ((!quote || !prevQuote) && !comment) - indentCurrentLevel = indentCurrent & SC_FOLDLEVELNUMBERMASK; - if (quote) - indentNext = indentCurrentLevel; - if (indentNext & SC_FOLDLEVELWHITEFLAG) - indentNext = SC_FOLDLEVELWHITEFLAG | indentCurrentLevel; - - if (quote_start) { - // Place fold point at start of triple quoted string - lev |= SC_FOLDLEVELHEADERFLAG; - } else if (quote_continue || prevQuote) { - // Add level to rest of lines in the string - lev = lev + 1; - } else if (comment_start) { - // Place fold point at start of a block of comments - lev |= SC_FOLDLEVELHEADERFLAG; - } else if (comment_continue) { - // Add level to rest of lines in the block - lev = lev + 1; - } - - // Skip past any blank lines for next indent level info; we skip also - // comments (all comments, not just those starting in column 0) - // which effectively folds them into surrounding code rather - // than screwing up folding. - - while (!quote && - (lineNext < docLines) && - ((indentNext & SC_FOLDLEVELWHITEFLAG) || - (lineNext <= docLines && IsCommentLine(lineNext, styler)))) { - - lineNext++; - indentNext = styler.IndentAmount(lineNext, &spaceFlags, NULL); - } - - const int levelAfterComments = indentNext & SC_FOLDLEVELNUMBERMASK; - const int levelBeforeComments = - Maximum(indentCurrentLevel,levelAfterComments); - - // Now set all the indent levels on the lines we skipped - // Do this from end to start. Once we encounter one line - // which is indented more than the line after the end of - // the comment-block, use the level of the block before - - Sci_Position skipLine = lineNext; - int skipLevel = levelAfterComments; - - while (--skipLine > lineCurrent) { - int skipLineIndent = styler.IndentAmount(skipLine, &spaceFlags, NULL); - - if ((skipLineIndent & SC_FOLDLEVELNUMBERMASK) > levelAfterComments) - skipLevel = levelBeforeComments; - - int whiteFlag = skipLineIndent & SC_FOLDLEVELWHITEFLAG; - - styler.SetLevel(skipLine, skipLevel | whiteFlag); - } - - // Set fold header on non-quote/non-comment line - if (!quote && !comment && !(indentCurrent & SC_FOLDLEVELWHITEFLAG) ) { - if ((indentCurrent & SC_FOLDLEVELNUMBERMASK) < - (indentNext & SC_FOLDLEVELNUMBERMASK)) - lev |= SC_FOLDLEVELHEADERFLAG; - } - - // Keep track of triple quote and block comment state of previous line - prevQuote = quote; - prevComment = comment_start || comment_continue; - - // Set fold level for this line and move to next line - styler.SetLevel(lineCurrent, lev); - indentCurrent = indentNext; - lineCurrent = lineNext; - } - - // NOTE: Cannot set level of last line here because indentCurrent doesn't have - // header flag set; the loop above is crafted to take care of this case! - //styler.SetLevel(lineCurrent, indentCurrent); -} - -static const char * const nimWordListDesc[] = { - "Keywords", - 0 -}; - -LexerModule lmNim(SCLEX_NIM, ColouriseNimDoc, "nim", FoldNimDoc, - nimWordListDesc); diff --git a/scintilla/src/Catalogue.cxx b/scintilla/src/Catalogue.cxx index c6cb2c674..57a34a12b 100644 --- a/scintilla/src/Catalogue.cxx +++ b/scintilla/src/Catalogue.cxx @@ -141,7 +141,7 @@ int Scintilla_LinkLexers() { //LINK_LEXER(lmMSSQL); //LINK_LEXER(lmMySQL); //LINK_LEXER(lmNimrod); - LINK_LEXER(lmNim); + LINK_LEXER(lmNimrod); //LINK_LEXER(lmNncrontab); LINK_LEXER(lmNsis); LINK_LEXER(lmNull); diff --git a/src/Notepad3.c b/src/Notepad3.c index da8a779e8..8e45abc36 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -2360,7 +2360,7 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam) i == SCLEX_SQL || i == SCLEX_PERL || i == SCLEX_PYTHON || i == SCLEX_PROPERTIES ||i == SCLEX_CONF || i == SCLEX_POWERSHELL || i == SCLEX_BATCH || i == SCLEX_DIFF || i == SCLEX_BASH || i == SCLEX_TCL || i == SCLEX_AU3 || i == SCLEX_LATEX || i == SCLEX_AHK || i == SCLEX_RUBY || i == SCLEX_CMAKE || i == SCLEX_MARKDOWN || - i == SCLEX_YAML || i == SCLEX_REGISTRY || i == SCLEX_NIM)); + i == SCLEX_YAML || i == SCLEX_REGISTRY || i == SCLEX_NIMROD)); EnableCmd(hmenu,IDM_EDIT_INSERT_ENCODING,*mEncoding[Encoding_Current(CPI_GET)].pszParseNames); @@ -3729,7 +3729,7 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) case SCLEX_AVS: case SCLEX_YAML: case SCLEX_COFFEESCRIPT: - case SCLEX_NIM: + case SCLEX_NIMROD: BeginWaitCursor(NULL); EditToggleLineComments(g_hwndEdit,L"#",TRUE); EndWaitCursor(); @@ -3797,7 +3797,7 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) case SCLEX_YAML: case SCLEX_JSON: case SCLEX_REGISTRY: - case SCLEX_NIM: + case SCLEX_NIMROD: break; case SCLEX_HTML: case SCLEX_XML: diff --git a/src/Styles.c b/src/Styles.c index 88d2ffaf9..10806ecc8 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -2798,7 +2798,7 @@ EDITLEXER lexAwk = { SCLEX_PYTHON, 63024, L"Awk Script", L"awk", L"", &KeyWords -KEYWORDLIST KeyWords_Nim = { +KEYWORDLIST KeyWords_Nimrod = { "addr and as asm atomic bind block break case cast concept const continue converter " "defer discard distinct div do elif else end enum except export finally for from func " "generic if import in include interface is isnot iterator let macro method mixin mod " @@ -2807,21 +2807,21 @@ KEYWORDLIST KeyWords_Nim = { "", "", "", "", "", "", "", "" }; -EDITLEXER lexNim = { SCLEX_NIM, 63044, L"Nim Source Code", L"nim", L"", &KeyWords_Nim,{ - { STYLE_DEFAULT, 63126, L"Default", L"", L"" }, - //{ SCE_P_DEFAULT, 63126, L"Default", L"", L"" }, - { MULTI_STYLE(SCE_P_COMMENTLINE,SCE_P_COMMENTBLOCK,SCE_C_COMMENTLINEDOC,0), 63127, L"Comment", L"fore:#880000", L"" }, - { SCE_P_WORD, 63128, L"Keyword", L" bold; fore:#000088", L"" }, - { SCE_P_IDENTIFIER, 63129, L"Identifier", L"", L"" }, - { MULTI_STYLE(SCE_P_STRING,SCE_P_STRINGEOL,0,0), 63211, L"String double quoted", L"fore:#008800", L"" }, - { SCE_P_CHARACTER, 63212, L"String single quoted", L"fore:#008800", L"" }, - { SCE_P_TRIPLEDOUBLE, 63244, L"String triple double quotes", L"fore:#008800", L"" }, - { SCE_P_TRIPLE, 63245, L"String triple single quotes", L"fore:#008800", L"" }, - { SCE_P_NUMBER, 63130, L"Number", L"fore:#FF4000", L"" }, - { SCE_P_OPERATOR, 63132, L"Operator", L"bold; fore:#666600", L"" }, - //{ SCE_P_DEFNAME, 63247, L"Function name", L"fore:#660066", L"" }, - //{ SCE_P_CLASSNAME, 63246, L"Class name", L"fore:#660066", L"" }, - { -1, 00000, L"", L"", L"" } } }; +EDITLEXER lexNimrod = { SCLEX_NIMROD, 63044, L"Nim Source Code", L"nim; nimrod", L"", &KeyWords_Nimrod,{ + { STYLE_DEFAULT, 63126, L"Default", L"", L"" }, + //{ SCE_P_DEFAULT, 63126, L"Default", L"", L"" }, + { MULTI_STYLE(SCE_P_COMMENTLINE,SCE_P_COMMENTBLOCK,SCE_C_COMMENTLINEDOC,0), 63127, L"Comment", L"fore:#880000", L"" }, + { SCE_P_WORD, 63128, L"Keyword", L" bold; fore:#000088", L"" }, + { SCE_P_IDENTIFIER, 63129, L"Identifier", L"", L"" }, + { MULTI_STYLE(SCE_P_STRING,SCE_P_STRINGEOL,0,0), 63211, L"String double quoted", L"fore:#008800", L"" }, + { SCE_P_CHARACTER, 63212, L"String single quoted", L"fore:#008800", L"" }, + { SCE_P_TRIPLEDOUBLE, 63244, L"String triple double quotes", L"fore:#008800", L"" }, + { SCE_P_TRIPLE, 63245, L"String triple single quotes", L"fore:#008800", L"" }, + { SCE_P_NUMBER, 63130, L"Number", L"fore:#FF4000", L"" }, + { SCE_P_OPERATOR, 63132, L"Operator", L"bold; fore:#666600", L"" }, + //{ SCE_P_DEFNAME, 63247, L"Function name", L"fore:#660066", L"" }, + //{ SCE_P_CLASSNAME, 63246, L"Class name", L"fore:#660066", L"" }, + { -1, 00000, L"", L"", L"" } } }; @@ -2858,7 +2858,7 @@ static PEDITLEXER pLexArray[NUMLEXERS] = &lexMAK, // Makefiles &lexMARKDOWN, // Markdown &lexMATLAB, // MATLAB - &lexNim, // Nim + &lexNimrod, // Nim(rod) &lexNSIS, // NSIS Script &lexPAS, // Pascal Source Code &lexPL, // Perl Script @@ -4282,7 +4282,7 @@ void Style_SetIndentGuides(HWND hwnd,BOOL bShow) if (!flagSimpleIndentGuides) { switch (SendMessage(hwnd, SCI_GETLEXER, 0, 0)) { case SCLEX_PYTHON: - case SCLEX_NIM: + case SCLEX_NIMROD: iIndentView = SC_IV_LOOKFORWARD; break; default: From 57307acd16feac2bcb4df60394ea02db65848281 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 11 Jan 2018 15:53:38 +0100 Subject: [PATCH 08/14] + chagne: Word Wrap mode from WORD to SPACE to avoid wrapping at style change edges (bug in Scintilla ?) --- src/Edit.c | 2 +- src/Notepad3.c | 7 ++++--- src/Styles.c | 16 +++++++--------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index 5a59be8a1..5cbe22afd 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -6943,7 +6943,7 @@ BOOL FileVars_Apply(HWND hwnd,LPFILEVARS lpfv) { if (!bWordWrap) SendMessage(g_hwndEdit,SCI_SETWRAPMODE,SC_WRAP_NONE,0); else - SendMessage(g_hwndEdit,SCI_SETWRAPMODE,(iWordWrapMode == 0) ? SC_WRAP_WORD : SC_WRAP_CHAR,0); + SendMessage(g_hwndEdit,SCI_SETWRAPMODE,(iWordWrapMode == 0) ? SC_WRAP_WHITESPACE : SC_WRAP_CHAR,0); if (lpfv->mask & FV_LONGLINESLIMIT) iLongLinesLimit = lpfv->iLongLinesLimit; diff --git a/src/Notepad3.c b/src/Notepad3.c index 89c57527f..6d1a2521f 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1306,7 +1306,7 @@ LRESULT MsgCreate(HWND hwnd,WPARAM wParam,LPARAM lParam) if (!bWordWrap) SendMessage(g_hwndEdit,SCI_SETWRAPMODE,SC_WRAP_NONE,0); else - SendMessage(g_hwndEdit,SCI_SETWRAPMODE,(iWordWrapMode == 0) ? SC_WRAP_WORD : SC_WRAP_CHAR,0); + SendMessage(g_hwndEdit,SCI_SETWRAPMODE,(iWordWrapMode == 0) ? SC_WRAP_WHITESPACE : SC_WRAP_CHAR,0); if (iWordWrapIndent == 5) SendMessage(g_hwndEdit,SCI_SETWRAPINDENTMODE,SC_WRAPINDENT_SAME,0); @@ -4129,8 +4129,9 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) if (!bWordWrap) SendMessage(g_hwndEdit,SCI_SETWRAPMODE,SC_WRAP_NONE,0); else - SendMessage(g_hwndEdit,SCI_SETWRAPMODE,(iWordWrapMode == 0) ? SC_WRAP_WORD : SC_WRAP_CHAR,0); + SendMessage(g_hwndEdit,SCI_SETWRAPMODE,(iWordWrapMode == 0) ? SC_WRAP_WHITESPACE : SC_WRAP_CHAR,0); bWordWrapG = bWordWrap; + //EditApplyLexerStyle(g_hwndEdit, 0, -1); UpdateToolbar(); break; @@ -4139,7 +4140,7 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) if (WordWrapSettingsDlg(hwnd,IDD_WORDWRAP,&iWordWrapIndent)) { if (bWordWrap) - SendMessage(g_hwndEdit,SCI_SETWRAPMODE,(iWordWrapMode == 0) ? SC_WRAP_WORD : SC_WRAP_CHAR,0); + SendMessage(g_hwndEdit,SCI_SETWRAPMODE,(iWordWrapMode == 0) ? SC_WRAP_WHITESPACE : SC_WRAP_CHAR,0); if (iWordWrapIndent == 5) SendMessage(g_hwndEdit,SCI_SETWRAPINDENTMODE,SC_WRAPINDENT_SAME,0); else if (iWordWrapIndent == 6) diff --git a/src/Styles.c b/src/Styles.c index e089655fe..3cf9ad7b0 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -3732,12 +3732,14 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { } // apply lexer styles - Style_SetUrlHotSpot(hwnd, TRUE); - SendMessage(hwnd, SCI_COLOURISE, 0, (LPARAM)-1); + Style_SetUrlHotSpot(hwnd, FALSE); + EditApplyLexerStyle(g_hwndEdit, 0, -1); // update UI for hotspots - Style_SetUrlHotSpot(hwnd, bHyperlinkHotspot); - EditUpdateUrlHotspots(hwnd, 0, SciCall_GetTextLength(), bHyperlinkHotspot); + if (bHyperlinkHotspot) { + Style_SetUrlHotSpot(hwnd, bHyperlinkHotspot); + EditUpdateUrlHotspots(hwnd, 0, SciCall_GetTextLength(), bHyperlinkHotspot); + } } @@ -3762,7 +3764,6 @@ void Style_SetUrlHotSpot(HWND hwnd, BOOL bHotSpot) if (bHotSpot) { - const WCHAR* const lpszStyleHotSpot = GetCurrentStdLexer()->Styles[STY_URL_HOTSPOT].szValue; SendMessage(hwnd, SCI_STYLESETHOTSPOT, iStyleHotSpot, (LPARAM)TRUE); @@ -3791,11 +3792,8 @@ void Style_SetUrlHotSpot(HWND hwnd, BOOL bHotSpot) } } else { - const WCHAR* lpszStyleHotSpot = GetCurrentStdLexer()->Styles[STY_DEFAULT].szValue; - + const WCHAR* const lpszStyleHotSpot = GetCurrentStdLexer()->Styles[STY_DEFAULT].szValue; Style_SetStyles(hwnd, iStyleHotSpot, lpszStyleHotSpot); - - SendMessage(hwnd, SCI_SETHOTSPOTSINGLELINE, TRUE, 0); SendMessage(hwnd, SCI_STYLESETHOTSPOT, iStyleHotSpot, (LPARAM)FALSE); } From 9bad3532141b13fed23f53a2c1f07db8cd6d2a07 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 11 Jan 2018 16:18:23 +0100 Subject: [PATCH 09/14] + fix: move word wrap start symbol to margin (new WW mode SPACE (instead of WORD)) --- src/Notepad3.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Notepad3.c b/src/Notepad3.c index 6d1a2521f..f224bfd7f 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1333,8 +1333,8 @@ LRESULT MsgCreate(HWND hwnd,WPARAM wParam,LPARAM lParam) case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_END; break; } switch (((iWordWrapSymbols%100)-(iWordWrapSymbols%10))/10) { - case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break; - case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; break; + case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_MARGIN; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break; + case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_MARGIN; break; } SendMessage(g_hwndEdit,SCI_SETWRAPVISUALFLAGSLOCATION,wrapVisualFlagsLocation,0); SendMessage(g_hwndEdit,SCI_SETWRAPVISUALFLAGS,wrapVisualFlags,0); @@ -4166,8 +4166,8 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_END; break; } switch (((iWordWrapSymbols%100)-(iWordWrapSymbols%10))/10) { - case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break; - case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; break; + case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_MARGIN; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break; + case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_MARGIN; break; } SendMessage(g_hwndEdit,SCI_SETWRAPVISUALFLAGSLOCATION,wrapVisualFlagsLocation,0); SendMessage(g_hwndEdit,SCI_SETWRAPVISUALFLAGS,wrapVisualFlags,0); @@ -4355,8 +4355,8 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_END; break; } switch (((iWordWrapSymbols%100)-(iWordWrapSymbols%10))/10) { - case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break; - case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; break; + case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_MARGIN; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break; + case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_MARGIN; break; } SendMessage(g_hwndEdit,SCI_SETWRAPVISUALFLAGSLOCATION,wrapVisualFlagsLocation,0); SendMessage(g_hwndEdit,SCI_SETWRAPVISUALFLAGS,wrapVisualFlags,0); From caccc74cc747b9bf8e3b8662524b7011239adae1 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 11 Jan 2018 16:46:47 +0100 Subject: [PATCH 10/14] Revert "+ fix: move word wrap start symbol to margin (new WW mode SPACE (instead of WORD))" This reverts commit 9bad3532141b13fed23f53a2c1f07db8cd6d2a07. --- src/Notepad3.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Notepad3.c b/src/Notepad3.c index f224bfd7f..6d1a2521f 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1333,8 +1333,8 @@ LRESULT MsgCreate(HWND hwnd,WPARAM wParam,LPARAM lParam) case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_END; break; } switch (((iWordWrapSymbols%100)-(iWordWrapSymbols%10))/10) { - case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_MARGIN; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break; - case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_MARGIN; break; + case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break; + case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; break; } SendMessage(g_hwndEdit,SCI_SETWRAPVISUALFLAGSLOCATION,wrapVisualFlagsLocation,0); SendMessage(g_hwndEdit,SCI_SETWRAPVISUALFLAGS,wrapVisualFlags,0); @@ -4166,8 +4166,8 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_END; break; } switch (((iWordWrapSymbols%100)-(iWordWrapSymbols%10))/10) { - case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_MARGIN; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break; - case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_MARGIN; break; + case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break; + case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; break; } SendMessage(g_hwndEdit,SCI_SETWRAPVISUALFLAGSLOCATION,wrapVisualFlagsLocation,0); SendMessage(g_hwndEdit,SCI_SETWRAPVISUALFLAGS,wrapVisualFlags,0); @@ -4355,8 +4355,8 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_END; break; } switch (((iWordWrapSymbols%100)-(iWordWrapSymbols%10))/10) { - case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_MARGIN; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break; - case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_MARGIN; break; + case 1: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; wrapVisualFlagsLocation |= SC_WRAPVISUALFLAGLOC_START_BY_TEXT; break; + case 2: wrapVisualFlags |= SC_WRAPVISUALFLAG_START; break; } SendMessage(g_hwndEdit,SCI_SETWRAPVISUALFLAGSLOCATION,wrapVisualFlagsLocation,0); SendMessage(g_hwndEdit,SCI_SETWRAPVISUALFLAGS,wrapVisualFlags,0); From 177264cf52e9091930cc0882d0a0ae1c9fa52a04 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Thu, 11 Jan 2018 18:12:02 +0100 Subject: [PATCH 11/14] + fix: Mark Occurrences timeout on Find/Replace --- src/Edit.c | 36 +++++++++++++++++++++--------------- src/Notepad3.c | 4 ++-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index 5cbe22afd..8590035d4 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -4332,10 +4332,16 @@ RegExResult_t __fastcall EditFindHasMatch(HWND hwnd, LPCEDITFINDREPLACE lpefr, B // // EditFindReplaceDlgProcW() // -static void __fastcall EditSetTimerMarkAll(HWND hwnd) +static void __fastcall EditSetTimerMarkAll(HWND hwnd, int delay) { + if (delay < USER_TIMER_MINIMUM) { + TEST_AND_RESET(TIMER_BIT_MARK_OCC); + KillTimer(hwnd, IDT_TIMER_MRKALL); + SendMessage(hwnd, WM_COMMAND, MAKELONG(IDC_MARKALL_OCC, 1), 0); + return; + } TEST_AND_SET(TIMER_BIT_MARK_OCC); - SetTimer(hwnd, IDT_TIMER_MRKALL, 100, NULL); + SetTimer(hwnd, IDT_TIMER_MRKALL, delay, NULL); } @@ -4564,7 +4570,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA EditSetSearchFlags(hwnd, lpefr); bFlagsChanged = TRUE; - EditSetTimerMarkAll(hwnd); + EditSetTimerMarkAll(hwnd, 50); } return TRUE; @@ -4609,7 +4615,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA lpefr = (LPEDITFINDREPLACE)GetWindowLongPtr(hwnd, DWLP_USER); if (lpefr->bMarkOccurences) { bFlagsChanged = TRUE; - EditSetTimerMarkAll(hwnd); + EditSetTimerMarkAll(hwnd,50); } } return FALSE; @@ -4645,7 +4651,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA SendDlgItemMessage(hwnd, LOWORD(wParam), CB_SETEDITSEL, 0, MAKELPARAM(lSelEnd, lSelEnd)); } bFlagsChanged = TRUE; - EditSetTimerMarkAll(hwnd); + EditSetTimerMarkAll(hwnd,50); } break; @@ -4678,7 +4684,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA InvalidateRect(GetDlgItem(hwnd, IDC_FINDTEXT), NULL, TRUE); } bFlagsChanged = TRUE; - EditSetTimerMarkAll(hwnd); + EditSetTimerMarkAll(hwnd,0); } break; @@ -4736,7 +4742,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA CheckDlgButton(hwnd, IDC_FINDTRANSFORMBS, (lpefr->bTransformBS) ? BST_CHECKED : BST_UNCHECKED); } bFlagsChanged = TRUE; - EditSetTimerMarkAll(hwnd); + EditSetTimerMarkAll(hwnd,0); break; case IDC_DOT_MATCH_ALL: @@ -4749,7 +4755,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA lpefr->fuFlags &= ~(SCFIND_DOT_MATCH_ALL); } bFlagsChanged = TRUE; - EditSetTimerMarkAll(hwnd); + EditSetTimerMarkAll(hwnd,0); break; case IDC_WILDCARDSEARCH: @@ -4776,7 +4782,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA CheckDlgButton(hwnd, IDC_FINDTRANSFORMBS, (lpefr->bTransformBS) ? BST_CHECKED : BST_UNCHECKED); } bFlagsChanged = TRUE; - EditSetTimerMarkAll(hwnd); + EditSetTimerMarkAll(hwnd,0); break; case IDC_FINDTRANSFORMBS: @@ -4789,22 +4795,22 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA bSaveTFBackSlashes = FALSE; } bFlagsChanged = TRUE; - EditSetTimerMarkAll(hwnd); + EditSetTimerMarkAll(hwnd,0); break; case IDC_FINDCASE: bFlagsChanged = TRUE; - EditSetTimerMarkAll(hwnd); + EditSetTimerMarkAll(hwnd,0); break; case IDC_FINDWORD: bFlagsChanged = TRUE; - EditSetTimerMarkAll(hwnd); + EditSetTimerMarkAll(hwnd,0); break; case IDC_FINDSTART: bFlagsChanged = TRUE; - EditSetTimerMarkAll(hwnd); + EditSetTimerMarkAll(hwnd,0); break; @@ -4941,7 +4947,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA } } bFlagsChanged = TRUE; - EditSetTimerMarkAll(hwnd); + EditSetTimerMarkAll(hwnd,50); break; @@ -4959,7 +4965,7 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA SetDlgItemTextW(hwnd, IDC_FINDTEXT, wszRepl); SetDlgItemTextW(hwnd, IDC_REPLACETEXT, wszFind); bFlagsChanged = TRUE; - EditSetTimerMarkAll(hwnd); + EditSetTimerMarkAll(hwnd,50); } break; diff --git a/src/Notepad3.c b/src/Notepad3.c index 6d1a2521f..b0f2e6e7d 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -7129,7 +7129,7 @@ int CreateIniFileEx(LPCWSTR lpszIniFile) { // void MarkAllOccurrences(int delay) { - if (delay <= 0) { + if (delay < USER_TIMER_MINIMUM) { EditMarkAllOccurrences(); return; } @@ -7143,7 +7143,7 @@ void MarkAllOccurrences(int delay) // void UpdateVisibleUrlHotspot(int delay) { - if (delay <= 0) { + if (delay < USER_TIMER_MINIMUM) { EditUpdateVisibleUrlHotspot(); return; } From 36b978ea04c5c7d2c55516d2b48f5881df148ec9 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 12 Jan 2018 01:14:56 +0100 Subject: [PATCH 12/14] + fix: optimized status bar partitioning --- src/Notepad3.c | 6 +++--- src/Notepad3.rc | 3 +-- src/Styles.c | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Notepad3.c b/src/Notepad3.c index b0f2e6e7d..d0b7cc074 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1851,8 +1851,9 @@ void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam) // Statusbar width int aWidth[7]; - aWidth[STATUS_DOCPOS] = max(150,min(cx*2/5,StatusCalcPaneWidth(g_hwndStatus,L" Ln 9'999'999 : 9'999'999 Col 9'999'999 : 999 Sel 9'999'999 SelLn 9'999'999 Occ 9'999'999 "))); - aWidth[STATUS_DOCSIZE] = aWidth[STATUS_DOCPOS] + StatusCalcPaneWidth(g_hwndStatus,L" 9'999'999 Bytes [utf-8] "); + aWidth[STATUS_DOCPOS] = max(120,min(cx*36/100, StatusCalcPaneWidth(g_hwndStatus, + L" Ln 9'999'999 : 9'999'999 Col 9'999'999 : 999 Sel 9'999'999 SelLn 9'999'999 Occ 9'999'999 "))); + aWidth[STATUS_DOCSIZE] = aWidth[STATUS_DOCPOS] + StatusCalcPaneWidth(g_hwndStatus,L" 999 Bytes [UTF-8] "); aWidth[STATUS_CODEPAGE] = aWidth[STATUS_DOCSIZE] + StatusCalcPaneWidth(g_hwndStatus,L" Unicode (UTF-8) Signature "); aWidth[STATUS_EOLMODE] = aWidth[STATUS_CODEPAGE] + StatusCalcPaneWidth(g_hwndStatus,L" CR+LF "); aWidth[STATUS_OVRMODE] = aWidth[STATUS_EOLMODE] + StatusCalcPaneWidth(g_hwndStatus,L" OVR "); @@ -1860,7 +1861,6 @@ void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam) aWidth[STATUS_LEXER] = -1; - SendMessage(g_hwndStatus,SB_SETPARTS,COUNTOF(aWidth),(LPARAM)aWidth); UpdateStatusbar(); diff --git a/src/Notepad3.rc b/src/Notepad3.rc index b1b1c7368..cc4cd9d4a 100644 --- a/src/Notepad3.rc +++ b/src/Notepad3.rc @@ -1418,7 +1418,7 @@ BEGIN IDS_READONLY "(Read Only)" IDS_DOCPOS " Ln %s / %s Col %s Sel %s SelLn %s Occ %s " IDS_DOCPOS2 " Ln %s / %s Col %s / %s Sel %s SelLn %s Occ %s " - IDS_DOCSIZE " %s [utf-8]" + IDS_DOCSIZE " %s [UTF-8]" IDS_LOADFILE "Loading ""%s""..." IDS_SAVEFILE "Saving ""%s""..." IDS_PRINTFILE "Printing page %i..." @@ -1922,7 +1922,6 @@ BEGIN 63264 "Hyperlink Hotspots" 63265 "2nd Hyperlink Hotspots" 63266 "2nd Default Text" - END #endif // English (United States) resources diff --git a/src/Styles.c b/src/Styles.c index 3cf9ad7b0..68d338ba6 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -80,7 +80,7 @@ EDITLEXER lexStandard = { SCLEX_NULL, 63000, L"Default Text", L"txt; text; wtx; { -1, 00000, L"", L"", L"" } } }; -EDITLEXER lexStandard2nd = { SCLEX_NULL, 63266, L"2nd Default Text", L"txt; text; wtx; log; asc; doc", L"", &KeyWords_NULL,{ +EDITLEXER lexStandard2nd = { SCLEX_NULL, 63266, L"Default Text", L"txt; text; wtx; log; asc; doc", L"", &KeyWords_NULL,{ /* 0 */ { STYLE_DEFAULT, 63112, L"2nd Default Style", L"font:Courier New; size:10", L"" }, /* 1 */ { STYLE_LINENUMBER, 63113, L"2nd Margins and Line Numbers", L"font:Tahoma; size:-2; fore:#FF0000", L"" }, /* 2 */ { STYLE_BRACELIGHT, 63114, L"2nd Matching Braces (Indicator)", L"fore:#00FF40; alpha:80; alpha2:220; indic_roundbox", L"" }, From fca7de523d144f04a0751542c9d14ba313777a3c Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 12 Jan 2018 11:01:57 +0100 Subject: [PATCH 13/14] + fix: revert naming for "2nd Default Text" + clean code: reasonable assumption for memory allocation of style handling (backup, save, load) + tuning: statusbar partitioning --- src/Helpers.c | 5 ++--- src/Helpers.h | 2 +- src/Notepad3.c | 8 ++++---- src/Styles.c | 23 +++++++++++------------ src/Styles.h | 2 +- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/Helpers.c b/src/Helpers.c index 61d11ec75..a8af14d22 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -1982,8 +1982,7 @@ BOOL MRU_Load(LPMRULIST pmru) WCHAR tchName[32] = { L'\0' }; WCHAR tchItem[1024] = { L'\0' }; WCHAR wchBookMarks[MRU_BMRK_SIZE] = { L'\0' }; - WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR)*32*1024); - + WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR) * 2 * MRU_MAXITEMS * 1024); MRU_Empty(pmru); LoadIniSection(pmru->szRegKey,pIniSection,(int)LocalSize(pIniSection)/sizeof(WCHAR)); @@ -2019,7 +2018,7 @@ BOOL MRU_Save(LPMRULIST pmru) { int i; WCHAR tchName[32] = { L'\0' }; - WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR)*32*1024); + WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR) * 2 * MRU_MAXITEMS * 1024); //IniDeleteSection(pmru->szRegKey); diff --git a/src/Helpers.h b/src/Helpers.h index b7e487bac..4d9cc4bc8 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -217,7 +217,7 @@ UINT CharSetFromCodePage(UINT); //==== MRU Functions ========================================================== -#define MRU_MAXITEMS 24 +#define MRU_MAXITEMS 24 #define MRU_NOCASE 1 #define MRU_UTF8 2 #define MRU_BMRK_SIZE 1024 diff --git a/src/Notepad3.c b/src/Notepad3.c index d0b7cc074..7e2d5d4fe 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1586,7 +1586,7 @@ void CreateBars(HWND hwnd,HINSTANCE hInstance) DeleteObject(hbmpCopy); // Load toolbar labels - pIniSection = LocalAlloc(LPTR,sizeof(WCHAR)*32*1024); + pIniSection = LocalAlloc(LPTR,sizeof(WCHAR) * 32 * 1024); cchIniSection = (int)LocalSize(pIniSection)/sizeof(WCHAR); LoadIniSection(L"Toolbar Labels",pIniSection,cchIniSection); n = 1; @@ -1851,7 +1851,7 @@ void MsgSize(HWND hwnd,WPARAM wParam,LPARAM lParam) // Statusbar width int aWidth[7]; - aWidth[STATUS_DOCPOS] = max(120,min(cx*36/100, StatusCalcPaneWidth(g_hwndStatus, + aWidth[STATUS_DOCPOS] = max(100,min(cx/3, StatusCalcPaneWidth(g_hwndStatus, L" Ln 9'999'999 : 9'999'999 Col 9'999'999 : 999 Sel 9'999'999 SelLn 9'999'999 Occ 9'999'999 "))); aWidth[STATUS_DOCSIZE] = aWidth[STATUS_DOCPOS] + StatusCalcPaneWidth(g_hwndStatus,L" 999 Bytes [UTF-8] "); aWidth[STATUS_CODEPAGE] = aWidth[STATUS_DOCSIZE] + StatusCalcPaneWidth(g_hwndStatus,L" Unicode (UTF-8) Signature "); @@ -8096,7 +8096,7 @@ BOOL OpenFileDlg(HWND hwnd,LPWSTR lpstrFile,int cchFile,LPCWSTR lpstrInitialDir) { OPENFILENAME ofn; WCHAR szFile[MAX_PATH] = { L'\0' }; - WCHAR szFilter[NUMLEXERS*1024]; + WCHAR szFilter[NUMLEXERS * AVG_NUM_OF_STYLES_PER_LEXER * 100]; WCHAR tchInitialDir[MAX_PATH] = { L'\0' }; Style_GetOpenDlgFilterStr(szFilter,COUNTOF(szFilter)); @@ -8151,7 +8151,7 @@ BOOL SaveFileDlg(HWND hwnd,LPWSTR lpstrFile,int cchFile,LPCWSTR lpstrInitialDir) { OPENFILENAME ofn; WCHAR szNewFile[MAX_PATH] = { L'\0' }; - WCHAR szFilter[NUMLEXERS*1024] = { L'\0' }; + WCHAR szFilter[NUMLEXERS * AVG_NUM_OF_STYLES_PER_LEXER * 100] = { L'\0' }; WCHAR tchInitialDir[MAX_PATH] = { L'\0' }; StringCchCopy(szNewFile,COUNTOF(szNewFile),lpstrFile); diff --git a/src/Styles.c b/src/Styles.c index 68d338ba6..88f43d160 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -80,7 +80,7 @@ EDITLEXER lexStandard = { SCLEX_NULL, 63000, L"Default Text", L"txt; text; wtx; { -1, 00000, L"", L"", L"" } } }; -EDITLEXER lexStandard2nd = { SCLEX_NULL, 63266, L"Default Text", L"txt; text; wtx; log; asc; doc", L"", &KeyWords_NULL,{ +EDITLEXER lexStandard2nd = { SCLEX_NULL, 63266, L"2nd Default Text", L"txt; text; wtx; log; asc; doc", L"", &KeyWords_NULL,{ /* 0 */ { STYLE_DEFAULT, 63112, L"2nd Default Style", L"font:Courier New; size:10", L"" }, /* 1 */ { STYLE_LINENUMBER, 63113, L"2nd Margins and Line Numbers", L"font:Tahoma; size:-2; fore:#FF0000", L"" }, /* 2 */ { STYLE_BRACELIGHT, 63114, L"2nd Matching Braces (Indicator)", L"fore:#00FF40; alpha:80; alpha2:220; indic_roundbox", L"" }, @@ -2942,7 +2942,7 @@ void Style_Load() { int i,iLexer; WCHAR tch[32] = { L'\0' };; - WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR)*32*1024); + WCHAR *pIniSection = LocalAlloc(LPTR, sizeof(WCHAR) * NUMLEXERS * AVG_NUM_OF_STYLES_PER_LEXER * 100) ; int cchIniSection = (int)LocalSize(pIniSection)/sizeof(WCHAR); // Custom colors @@ -3022,13 +3022,12 @@ void Style_Load() // void Style_Save() { - int i,iLexer; WCHAR tch[32] = { L'\0' };; - WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR)*32*1024); + WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR)*NUMLEXERS * AVG_NUM_OF_STYLES_PER_LEXER * 100); //int cchIniSection = (int)LocalSize(pIniSection)/sizeof(WCHAR); // Custom colors - for (i = 0; i < 16; i++) { + for (int i = 0; i < 16; i++) { WCHAR wch[32] = { L'\0' }; StringCchPrintf(tch,COUNTOF(tch),L"%02i",i+1); StringCchPrintf(wch,COUNTOF(wch),L"#%02X%02X%02X", @@ -3059,11 +3058,11 @@ void Style_Save() return; } - for (iLexer = 0; iLexer < COUNTOF(g_pLexArray); iLexer++) { - IniSectionSetString(pIniSection,L"FileNameExtensions",g_pLexArray[iLexer]->szExtensions); - i = 0; + for (int iLexer = 0; iLexer < COUNTOF(g_pLexArray); iLexer++) { + IniSectionSetString(pIniSection,L"FileNameExtensions", g_pLexArray[iLexer]->szExtensions); + int i = 0; while (g_pLexArray[iLexer]->Styles[i].iStyle != -1) { - IniSectionSetString(pIniSection,g_pLexArray[iLexer]->Styles[i].pszName,g_pLexArray[iLexer]->Styles[i].szValue); + IniSectionSetString(pIniSection, g_pLexArray[iLexer]->Styles[i].pszName, g_pLexArray[iLexer]->Styles[i].szValue); i++; } @@ -3100,7 +3099,7 @@ BOOL Style_Import(HWND hwnd) if (GetOpenFileName(&ofn)) { int i,iLexer; - WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR)*32*1024); + WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR) * NUMLEXERS * AVG_NUM_OF_STYLES_PER_LEXER * 100); int cchIniSection = (int)LocalSize(pIniSection)/sizeof(WCHAR); for (iLexer = 0; iLexer < COUNTOF(g_pLexArray); iLexer++) { @@ -3149,7 +3148,7 @@ BOOL Style_Export(HWND hwnd) if (GetSaveFileName(&ofn)) { - WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR)*32*1024); + WCHAR *pIniSection = LocalAlloc(LPTR,sizeof(WCHAR) * NUMLEXERS * AVG_NUM_OF_STYLES_PER_LEXER * 100); //int cchIniSection = (int)LocalSize(pIniSection)/sizeof(WCHAR); for (int iLexer = 0; iLexer < COUNTOF(g_pLexArray); iLexer++) { @@ -5875,7 +5874,7 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP void Style_ConfigDlg(HWND hwnd) { - WCHAR* StyleBackup[NUMLEXERS * MAX_NUM_OF_STYLES_PER_LEXER]; + WCHAR* StyleBackup[NUMLEXERS * AVG_NUM_OF_STYLES_PER_LEXER]; int c,cItems,i,iLexer; // Backup Styles diff --git a/src/Styles.h b/src/Styles.h index c21cace41..cbe8e0699 100644 --- a/src/Styles.h +++ b/src/Styles.h @@ -60,7 +60,7 @@ typedef struct _editlexer // Number of Lexers in pLexArray #define NUMLEXERS 46 -#define MAX_NUM_OF_STYLES_PER_LEXER 64 +#define AVG_NUM_OF_STYLES_PER_LEXER 20 void Style_Load(); From 947797a501686383f9b65ea11087b769f94d4a02 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Fri, 12 Jan 2018 11:31:02 +0100 Subject: [PATCH 14/14] + fix: bug on switching between 1st and 2nd standard lexers --- src/Styles.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Styles.c b/src/Styles.c index 88f43d160..3dfb98779 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -4189,6 +4189,9 @@ void Style_ToggleUse2ndDefault(HWND hwnd) { BOOL use2ndDefStyle = Style_GetUse2ndDefault(); Style_SetUse2ndDefault(use2ndDefStyle ? FALSE : TRUE); // swap + if (IsLexerStandard(g_pLexCurrent)) { + g_pLexCurrent = Style_GetUse2ndDefault() ? &lexStandard2nd : &lexStandard; + } Style_SetLexer(hwnd,g_pLexCurrent); } @@ -6004,13 +6007,15 @@ INT_PTR CALLBACK Style_SelectLexerDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPAR lvi.mask = LVIF_PARAM; for (i = 0; i < lvItems; i++) { lvi.iItem = i; - ListView_GetItem(hwndLV,&lvi);; - if (StringCchCompareX(((PEDITLEXER)lvi.lParam)->pszName,g_pLexCurrent->pszName) == 0) { + ListView_GetItem(hwndLV,&lvi); + if (StringCchCompareX(((PEDITLEXER)lvi.lParam)->pszName, g_pLexCurrent->pszName) == 0) + { ListView_SetItemState(hwndLV,i,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED); ListView_EnsureVisible(hwndLV,i,FALSE); if (g_iDefaultLexer == i) { CheckDlgButton(hwnd,IDC_DEFAULTSCHEME,BST_CHECKED); } + break; } }