From b1face37e4604f806dd6f1f0f487f25dfb80d3f9 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Mon, 18 Mar 2019 13:42:44 +0100 Subject: [PATCH] + 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;