From ed91513fc13221f63bb879c154354d7f646aac68 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Mon, 18 Mar 2019 00:02:44 +0100 Subject: [PATCH 1/3] + upd: uthash macros --- np3portableapp/build_np3portableapp.cmd | 2 +- uthash/uthash.h | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/np3portableapp/build_np3portableapp.cmd b/np3portableapp/build_np3portableapp.cmd index 84ab2125e..4d6012623 100644 --- a/np3portableapp/build_np3portableapp.cmd +++ b/np3portableapp/build_np3portableapp.cmd @@ -28,7 +28,7 @@ setlocal enableextensions :: ==================================================================================================================== -set NP3_LANGUAGE_SET=af-ZA be-BY de-DE en-GB es-ES fr-FR hu-HU it-IT ja-JP ko-KR nl-NL pt-BR ru-RU zh-CN +set NP3_LANGUAGE_SET=af-ZA be-BY de-DE en-GB es-ES fr-FR hu-HU it-IT ja-JP ko-KR nl-NL pl-PL pt-BR ru-RU zh-CN :: ==================================================================================================================== diff --git a/uthash/uthash.h b/uthash/uthash.h index 9385cbddd..15f347fab 100644 --- a/uthash/uthash.h +++ b/uthash/uthash.h @@ -175,9 +175,12 @@ do { #define HASH_FIND(hh,head,keyptr,keylen,out) \ do { \ - unsigned _hf_hashv; \ - HASH_VALUE(keyptr, keylen, _hf_hashv); \ - HASH_FIND_BYHASHVALUE(hh, head, keyptr, keylen, _hf_hashv, out); \ + (out) = NULL; \ + if (head) { \ + unsigned _hf_hashv; \ + HASH_VALUE(keyptr, keylen, _hf_hashv); \ + HASH_FIND_BYHASHVALUE(hh, head, keyptr, keylen, _hf_hashv, out); \ + } \ } while (0) #ifdef HASH_BLOOM From b1face37e4604f806dd6f1f0f487f25dfb80d3f9 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Mon, 18 Mar 2019 13:42:44 +0100 Subject: [PATCH 2/3] + cln: minor code cleanup --- src/Edit.c | 10 ++++++---- src/Helpers.c | 17 +++++++---------- src/MuiLanguage.c | 2 +- src/Notepad3.c | 6 +++--- src/Styles.c | 21 ++++++++++----------- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/src/Edit.c b/src/Edit.c index 3660fa5e4..75bd404db 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -7274,10 +7274,12 @@ static INT_PTR CALLBACK EditModifyLinesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam if (dwId >= 200 && dwId <= 205) { SetBkMode(hdc,TRANSPARENT); - if (GetSysColorBrush(COLOR_HOTLIGHT)) - SetTextColor(hdc,GetSysColor(COLOR_HOTLIGHT)); - else - SetTextColor(hdc,RGB(0, 0, 0xFF)); + if (GetSysColorBrush(COLOR_HOTLIGHT)) { + SetTextColor(hdc, GetSysColor(COLOR_HOTLIGHT)); + } + else { + SetTextColor(hdc, RGB(0, 0, 0xFF)); + } SelectObject(hdc,/*dwId == id_hover?*/hFontHover/*:hFontNormal*/); return (INT_PTR)GetSysColorBrush(COLOR_BTNFACE); } diff --git a/src/Helpers.c b/src/Helpers.c index f98664dfb..b2f95f50d 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -192,7 +192,7 @@ int IniSectionGetInt(LPCWSTR lpCachedIniSection, LPCWSTR lpName, int iDefault) { LPWSTR p = (LPWSTR)lpCachedIniSection; if (p) { - int ich = (int)StringCchLen(lpName,0); + int const ich = (int)StringCchLen(lpName,0); while (*p) { if ((StrCmpNI(p, lpName, ich) == 0) && (p[ich] == L'=')) { int i = 0; @@ -873,8 +873,9 @@ bool PathGetLnkPath(LPCWSTR pszLnkFile,LPWSTR pszResPath,int cchResPath) } // This additional check seems reasonable - if (!StringCchLen(pszResPath,cchResPath)) + if (StrIsEmpty(pszResPath)) { bSucceeded = false; + } if (bSucceeded) { ExpandEnvironmentStringsEx(pszResPath,cchResPath); @@ -935,8 +936,7 @@ bool PathCreateDeskLnk(LPCWSTR pszDocument) bool bSucceeded = false; BOOL fMustCopy; - if (!pszDocument || StringCchLen(pszDocument,MAX_PATH) == 0) - return true; + if (StrIsEmpty(pszDocument)) { return true; } // init strings GetModuleFileName(NULL,tchExeFile,COUNTOF(tchExeFile)); @@ -1002,8 +1002,7 @@ bool PathCreateFavLnk(LPCWSTR pszName,LPCWSTR pszTarget,LPCWSTR pszDir) IShellLink *psl; bool bSucceeded = false; - if (!pszName || StringCchLen(pszName,MAX_PATH) == 0) - return true; + if (StrIsEmpty(pszName)) { return true; } StringCchCopy(tchLnkFileName,COUNTOF(tchLnkFileName),pszDir); PathCchAppend(tchLnkFileName,COUNTOF(tchLnkFileName),pszName); @@ -1347,16 +1346,14 @@ DWORD NormalizePathEx(LPWSTR lpszPath, DWORD cchBuffer, bool bRealPath, bool bSe p += 2; *p = L'\\'; } - StringCchCopyW(lpszPath, MAX_PATH, p); + StringCchCopy(lpszPath, cchBuffer, p); } } } CloseHandle(hFile); } - size_t pathLen = 0; - StringCchLength(lpszPath, cchBuffer, &pathLen); - return (DWORD)pathLen; + return (DWORD)StringCchLen(lpszPath, cchBuffer); } diff --git a/src/MuiLanguage.c b/src/MuiLanguage.c index 88995991e..049720063 100644 --- a/src/MuiLanguage.c +++ b/src/MuiLanguage.c @@ -136,7 +136,7 @@ static bool _GetUserPreferredLanguage(LPWSTR pszPrefLocaleName, int cchBuffer, L LANGID lngID = *pLangID; WCHAR wchLngLocalName[LOCALE_NAME_MAX_LENGTH+1]; - if (StringCchLen(pszPrefLocaleName, cchBuffer) > 0) + if (StrIsNotEmpty(pszPrefLocaleName)) { res = ResolveLocaleName(pszPrefLocaleName, wchLngLocalName, COUNTOF(wchLngLocalName)); if (res > 0) { diff --git a/src/Notepad3.c b/src/Notepad3.c index b1d2200a1..9eb4a506d 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1804,7 +1804,7 @@ bool SelectExternalToolBar(HWND hwnd) if (GetOpenFileName(&ofn)) { PathQuoteSpaces(szFile); - if (StringCchLen(szArg2, COUNTOF(szArg2))) + if (StrIsNotEmpty(szArg2)) { StringCchCat(szFile, COUNTOF(szFile), L" "); StringCchCat(szFile, COUNTOF(szFile), szArg2); @@ -9790,7 +9790,7 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload, // bool FileRevert(LPCWSTR szFileName, bool bIgnoreCmdLnEnc) { - if (StringCchLen(szFileName, MAX_PATH) != 0) { + if (StrIsNotEmpty(szFileName)) { const DocPos iCurPos = SciCall_IsSelectionRectangle() ? SciCall_GetRectangularSelectionCaret() : SciCall_GetCurrentPos(); const DocPos iAnchorPos = SciCall_IsSelectionRectangle() ? SciCall_GetRectangularSelectionAnchor() : SciCall_GetAnchor(); @@ -10645,7 +10645,7 @@ void CancelCallTip() void InstallFileWatching(LPCWSTR lpszFile) { // Terminate - if (!Settings.FileWatchingMode || !lpszFile || StringCchLen(lpszFile,MAX_PATH) == 0) + if (!Settings.FileWatchingMode || StrIsEmpty(lpszFile)) { if (s_bRunningWatch) { diff --git a/src/Styles.c b/src/Styles.c index ccf7fbb86..9d6d68d68 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -943,23 +943,23 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) // Occurrences Marker if (!Style_StrGetColor(pCurrentStandard->Styles[STY_MARK_OCC].szValue, FOREGROUND_LAYER, &dColor)) { - WCHAR* sty = L""; switch (Settings.MarkOccurrences) { case 1: - sty = L"fore:0xFF0000"; dColor = RGB(0xFF, 0x00, 0x00); break; case 2: - sty = L"fore:0x00FF00"; dColor = RGB(0x00, 0xFF, 0x00); break; case 3: - default: - sty = L"fore:0x0000FF"; dColor = RGB(0x00, 0xFF, 0x00); break; + default: + dColor = GetSysColor(COLOR_HIGHLIGHT); + break; } - StringCchCopyW(pCurrentStandard->Styles[STY_MARK_OCC].szValue, COUNTOF(pCurrentStandard->Styles[0].szValue), sty); + WCHAR sty[32] = { L'\0' }; + StringCchPrintf(sty, COUNTOF(sty), L"fore:#%02X%02X%02X", (int)GetRValue(dColor), (int)GetGValue(dColor), (int)GetBValue(dColor)); + StringCchCopy(pCurrentStandard->Styles[STY_MARK_OCC].szValue, COUNTOF(pCurrentStandard->Styles[0].szValue), sty); } SendMessage(hwnd, SCI_INDICSETFORE, INDIC_NP3_MARK_OCCURANCE, dColor); @@ -1403,14 +1403,13 @@ void Style_SetLongLineColors(HWND hwnd) if (!Style_StrGetColor(GetCurrentStdLexer()->Styles[STY_LONG_LN_MRK].szValue, FOREGROUND_LAYER, &rgb)) { // edge fore rgb = GetSysColor(COLOR_3DLIGHT); } - SendMessage(hwnd,SCI_SETEDGECOLOUR,rgb,0); } else { - if (Style_StrGetColor(GetCurrentStdLexer()->Styles[STY_LONG_LN_MRK].szValue, BACKGROUND_LAYER, &rgb)) { // edge back - rgb = GetSysColor(COLOR_3DLIGHT); + if (!Style_StrGetColor(GetCurrentStdLexer()->Styles[STY_LONG_LN_MRK].szValue, BACKGROUND_LAYER, &rgb)) { // edge back + rgb = GetSysColor(COLOR_3DSHADOW); } - SendMessage(hwnd,SCI_SETEDGECOLOUR,rgb,0); } + SendMessage(hwnd, SCI_SETEDGECOLOUR, rgb, 0); } @@ -1764,7 +1763,7 @@ void Style_SetLexerFromFile(HWND hwnd,LPCWSTR lpszFile) } if (!bFound && s_bAutoSelect && /* s_bAutoSelect == false skips lexer search */ - (lpszFile && StringCchLen(lpszFile,MAX_PATH) > 0 && *lpszExt)) { + (StrIsNotEmpty(lpszFile) && *lpszExt)) { if (*lpszExt == L'.') ++lpszExt; From 04e75bb6e071eaef0f196fa7769ec242e79bd964 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Mon, 18 Mar 2019 16:01:34 +0100 Subject: [PATCH 3/3] + add: remember last used theme (if save settings is enabled) --- language/common_res.h | 2 +- src/Helpers.h | 14 ++++++-------- src/Notepad3.c | 1 + src/Styles.c | 45 ++++++++++++++++++++++++++++--------------- src/Styles.h | 1 - 5 files changed, 37 insertions(+), 26 deletions(-) diff --git a/language/common_res.h b/language/common_res.h index 8bd7fc730..b8be20fb0 100644 --- a/language/common_res.h +++ b/language/common_res.h @@ -411,7 +411,7 @@ #define IDS_MUI_LANG_ZH_CN 34516 #define IDS_MUI_MENU_THEMES 37000 -#define IDM_THEMES_DEFAULT 37001 +#define IDM_THEMES_DEFAULT 37001 #define IDM_THEMES_FILE_ITEM 37002 /// !!! dont use IDs until ...37100 diff --git a/src/Helpers.h b/src/Helpers.h index 10ab6ed33..b4554a209 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -286,13 +286,18 @@ bool GetKnownFolderPath(REFKNOWNFOLDERID, LPWSTR lpOutPath, size_t cchCount); void PathRelativeToApp(LPWSTR lpszSrc,LPWSTR lpszDest,int cchDest,bool,bool,bool); void PathAbsoluteFromApp(LPWSTR lpszSrc,LPWSTR lpszDest,int cchDest,bool); - bool PathIsLnkFile(LPCWSTR pszPath); bool PathGetLnkPath(LPCWSTR pszLnkFile,LPWSTR pszResPath,int cchResPath); bool PathIsLnkToDirectory(LPCWSTR pszPath,LPWSTR pszResPath,int cchResPath); bool PathCreateDeskLnk(LPCWSTR pszDocument); bool PathCreateFavLnk(LPCWSTR pszName,LPCWSTR pszTarget,LPCWSTR pszDir); +void ExpandEnvironmentStringsEx(LPWSTR lpSrc, DWORD dwSrc); +void PathCanonicalizeEx(LPWSTR lpszPath, DWORD cchBuffer); +DWORD GetLongPathNameEx(LPWSTR lpszPath, DWORD cchBuffer); +void PathGetDisplayName(LPWSTR lpszDestPath, DWORD cchDestBuffer, LPCWSTR lpszSourcePath); +DWORD NormalizePathEx(LPWSTR lpszPath, DWORD cchBuffer, bool bRealPath, bool bSearchPathIfRelative); + bool StrLTrim(LPWSTR pszSource,LPCWSTR pszTrimChars); @@ -322,13 +327,6 @@ void StrTab2Space(LPWSTR lpsz); void PathFixBackslashes(LPWSTR lpsz); -void ExpandEnvironmentStringsEx(LPWSTR lpSrc,DWORD dwSrc); -void PathCanonicalizeEx(LPWSTR lpszPath, DWORD cchBuffer); -DWORD GetLongPathNameEx(LPWSTR lpszPath, DWORD cchBuffer); -void PathGetDisplayName(LPWSTR lpszDestPath, DWORD cchDestBuffer, LPCWSTR lpszSourcePath); -DWORD NormalizePathEx(LPWSTR lpszPath, DWORD cchBuffer, bool bRealPath, bool bSearchPathIfRelative); - - size_t FormatNumberStr(LPWSTR lpNumberStr, size_t cch, int fixedWidth); bool SetDlgItemIntEx(HWND hwnd,int nIdItem,UINT uValue); diff --git a/src/Notepad3.c b/src/Notepad3.c index 9eb4a506d..383be4ee8 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -7571,6 +7571,7 @@ void SaveSettings(bool bSaveSettingsNow) Style_Save(); // Scintilla Styles + int ResX, ResY; GetCurrentMonitorResolution(Globals.hwndMain, &ResX, &ResY); diff --git a/src/Styles.c b/src/Styles.c index 9d6d68d68..ee27ce598 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -121,7 +121,7 @@ static int s_cyStyleSelectDlg = STYLESELECTDLG_Y; typedef struct _themeFiles { UINT rid; - WCHAR szFileName[80]; + WCHAR szName[80]; WCHAR szFilePath[MAX_PATH]; } THEMEFILES, * PTHEMEFILES; @@ -155,12 +155,10 @@ static THEMEFILES Theme_Files[] = { 0, L"", L"" }, { 0, L"", L"" } }; - unsigned ThemeItems_CountOf() { return COUNTOF(Theme_Files); } - - static unsigned s_idxSelectedTheme = 1; // Default(0), Standard(1) +const WCHAR* const STYLING_THEME_NAME = L"ThemeFileName"; static void _FillThemesMenuTable() { @@ -168,12 +166,12 @@ static void _FillThemesMenuTable() Theme_Files[0].rid = IDM_THEMES_DEFAULT; // factory default GetLngString(IDM_THEMES_DEFAULT, wchStdName, COUNTOF(wchStdName)); - StringCchCopy(Theme_Files[0].szFileName, COUNTOF(Theme_Files[0].szFileName), wchStdName); + StringCchCopy(Theme_Files[0].szName, COUNTOF(Theme_Files[0].szName), wchStdName); StringCchCopy(Theme_Files[0].szFilePath, COUNTOF(Theme_Files[0].szFilePath), L""); Theme_Files[1].rid = IDM_THEMES_FILE_ITEM; // NP3.ini settings GetLngString(IDM_THEMES_FILE_ITEM, wchStdName, COUNTOF(wchStdName)); - StringCchCopy(Theme_Files[1].szFileName, COUNTOF(Theme_Files[1].szFileName), wchStdName); + StringCchCopy(Theme_Files[1].szName, COUNTOF(Theme_Files[1].szName), wchStdName); StringCchCopy(Theme_Files[1].szFilePath, COUNTOF(Theme_Files[1].szFilePath), Globals.IniFile); unsigned iTheme = 1; // Standard @@ -209,7 +207,7 @@ static void _FillThemesMenuTable() StringCchCopy(tchThemePath, COUNTOF(tchThemePath), PathFindFileName(FindFileData.cFileName)); PathRemoveExtension(tchThemePath); - StringCchCopy(Theme_Files[iTheme].szFileName, COUNTOF(Theme_Files[iTheme].szFileName), tchThemePath); + StringCchCopy(Theme_Files[iTheme].szName, COUNTOF(Theme_Files[iTheme].szName), tchThemePath); StringCchCopy(tchThemePath, COUNTOF(tchThemePath), tchThemeDir); PathCchAppend(tchThemePath, COUNTOF(tchThemePath), FindFileData.cFileName); @@ -220,16 +218,17 @@ static void _FillThemesMenuTable() } FindClose(hFindFile); } - s_idxSelectedTheme = clampu(s_idxSelectedTheme, 0, iTheme); - for (++iTheme; iTheme < ThemeItems_CountOf(); ++iTheme) { + for (++iTheme; iTheme < ThemeItems_CountOf(); ++iTheme) + { Theme_Files[iTheme].rid = 0; // no themes available - Theme_Files[iTheme].szFileName[0] = L'\0'; + Theme_Files[iTheme].szName[0] = L'\0'; Theme_Files[iTheme].szFilePath[0] = L'\0'; } } + //============================================================================= // // Style_SetIniFile() @@ -250,9 +249,9 @@ bool Style_InsertThemesMenu(HMENU hMenuBar) HMENU hmenuThemes = CreatePopupMenu(); int const pos = GetMenuItemCount(hMenuBar) - 1; - AppendMenu(hmenuThemes, MF_ENABLED | MF_STRING, Theme_Files[0].rid, Theme_Files[0].szFileName); + AppendMenu(hmenuThemes, MF_ENABLED | MF_STRING, Theme_Files[0].rid, Theme_Files[0].szName); - AppendMenu(hmenuThemes, MF_ENABLED | MF_STRING, Theme_Files[1].rid, Theme_Files[1].szFileName); + AppendMenu(hmenuThemes, MF_ENABLED | MF_STRING, Theme_Files[1].rid, Theme_Files[1].szName); for (unsigned i = 2; i < ThemeItems_CountOf(); ++i) { @@ -260,7 +259,7 @@ bool Style_InsertThemesMenu(HMENU hMenuBar) AppendMenu(hmenuThemes, MF_SEPARATOR, 0, 0); } if (Theme_Files[i].rid > 0) { - AppendMenu(hmenuThemes, MF_ENABLED | MF_STRING, Theme_Files[i].rid, Theme_Files[i].szFileName); + AppendMenu(hmenuThemes, MF_ENABLED | MF_STRING, Theme_Files[i].rid, Theme_Files[i].szName); } else { break; // done @@ -479,12 +478,25 @@ void Style_Load() s_colorDefault[14] = RGB(0xB0, 0x00, 0xB0); s_colorDefault[15] = RGB(0xB2, 0x8B, 0x40); - Style_ImportFromFile(Theme_Files[s_idxSelectedTheme].szFilePath); - // 2nd Default Style has same filename extension list as (1st) Default Style StringCchCopyW(lexStandard2nd.szExtensions, COUNTOF(lexStandard2nd.szExtensions), lexStandard.szExtensions); _FillThemesMenuTable(); + + // get theme name from settings2 + WCHAR wchThemeName[80]; + IniGetString(L"Styles", STYLING_THEME_NAME, L"", wchThemeName, COUNTOF(wchThemeName)); + + unsigned iTheme = 1; + if (StrIsNotEmpty(wchThemeName)) { + for (; iTheme < ThemeItems_CountOf(); ++iTheme) + { + if (StringCchCompareXI(wchThemeName, Theme_Files[iTheme].szName) == 0) { break; } + } + } + s_idxSelectedTheme = (iTheme < ThemeItems_CountOf()) ? iTheme : 1; + + Style_ImportFromFile(Theme_Files[s_idxSelectedTheme].szFilePath); } @@ -615,7 +627,8 @@ bool Style_ImportFromFile(const WCHAR* szFile) // void Style_Save() { - Style_ExportToFile(Theme_Files[s_idxSelectedTheme].szFilePath, false); + Style_ExportToFile(Theme_Files[s_idxSelectedTheme].szFilePath, false); + IniSetString(L"Styles", STYLING_THEME_NAME, (s_idxSelectedTheme > 1) ? Theme_Files[s_idxSelectedTheme].szName : NULL); } diff --git a/src/Styles.h b/src/Styles.h index 361440bdc..54efd6f3c 100644 --- a/src/Styles.h +++ b/src/Styles.h @@ -29,7 +29,6 @@ #define NUMLEXERS 49 #define AVG_NUM_OF_STYLES_PER_LEXER 20 - void Style_Load(); bool Style_Import(HWND hwnd); bool Style_ImportFromFile(const WCHAR* szFile);