Fix some GCC and MSC warnings

-  optimize dark mode
-  add initializers

Fix #13867, close #13868
This commit is contained in:
ozone10 2023-06-11 12:26:00 +02:00 committed by Don Ho
parent d6bdc5d3f8
commit a647991cd7
12 changed files with 114 additions and 120 deletions

View File

@ -53,13 +53,13 @@ SUBMAKEFLAGS := -O --no-print-directory
ifeq "$(filter-out 0,$(DEBUG))" "" ifeq "$(filter-out 0,$(DEBUG))" ""
BUILD_TYPE := release BUILD_TYPE := release
BUILD_SUFFIX := BUILD_SUFFIX :=
CXXFLAGS += -O3 -Wconversion CXXFLAGS += -O3 -Wno-alloc-size-larger-than -Wconversion
CPP_DEFINE += NDEBUG CPP_DEFINE += NDEBUG
LDFLAGS += -s LDFLAGS += -s
else else
BUILD_TYPE := debug BUILD_TYPE := debug
BUILD_SUFFIX := -debug BUILD_SUFFIX := -debug
CXXFLAGS += -Og -g -Wpedantic -Wall -Wextra -Wno-cast-function-type -Wconversion CXXFLAGS += -Og -g -Wpedantic -Wall -Wextra -Wno-cast-function-type -Wno-overloaded-virtual -Wconversion
CPP_DEFINE += DEBUG CPP_DEFINE += DEBUG
endif endif

View File

@ -13,7 +13,7 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "Common.h"
#include "regExtDlg.h" #include "regExtDlg.h"
#include "resource.h" #include "resource.h"
#include "Parameters.h" #include "Parameters.h"
@ -108,22 +108,14 @@ intptr_t CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPa
} }
case WM_CTLCOLORLISTBOX: case WM_CTLCOLORLISTBOX:
{
if (NppDarkMode::isEnabled())
{ {
return NppDarkMode::onCtlColorListbox(wParam, lParam); return NppDarkMode::onCtlColorListbox(wParam, lParam);
} }
break;
}
case WM_CTLCOLORDLG: case WM_CTLCOLORDLG:
{
if (NppDarkMode::isEnabled())
{ {
return NppDarkMode::onCtlColorDarker(reinterpret_cast<HDC>(wParam)); return NppDarkMode::onCtlColorDarker(reinterpret_cast<HDC>(wParam));
} }
break;
}
case WM_CTLCOLORSTATIC: case WM_CTLCOLORSTATIC:
{ {
@ -136,13 +128,8 @@ intptr_t CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPa
{ {
return NppDarkMode::onCtlColorDarkerBGStaticText(hdcStatic, nppParam.isAdmin()); return NppDarkMode::onCtlColorDarkerBGStaticText(hdcStatic, nppParam.isAdmin());
} }
if (NppDarkMode::isEnabled())
{
return NppDarkMode::onCtlColorDarker(hdcStatic); return NppDarkMode::onCtlColorDarker(hdcStatic);
} }
return FALSE;
}
case WM_PRINTCLIENT: case WM_PRINTCLIENT:
{ {
@ -340,7 +327,7 @@ void RegExtDlg::getRegisteredExts()
int nbRegisteredKey = getNbSubKey(HKEY_CLASSES_ROOT); int nbRegisteredKey = getNbSubKey(HKEY_CLASSES_ROOT);
for (int i = 0 ; i < nbRegisteredKey ; ++i) for (int i = 0 ; i < nbRegisteredKey ; ++i)
{ {
TCHAR extName[extNameLen]; TCHAR extName[extNameLen]{};
//FILETIME fileTime; //FILETIME fileTime;
int extNameActualLen = extNameLen; int extNameActualLen = extNameLen;
int res = ::RegEnumKeyEx(HKEY_CLASSES_ROOT, i, extName, reinterpret_cast<LPDWORD>(&extNameActualLen), nullptr, nullptr, nullptr, nullptr); int res = ::RegEnumKeyEx(HKEY_CLASSES_ROOT, i, extName, reinterpret_cast<LPDWORD>(&extNameActualLen), nullptr, nullptr, nullptr, nullptr);

View File

@ -20,7 +20,7 @@
#include "regExtDlgRc.h" #include "regExtDlgRc.h"
#include "StaticDialog.h" #include "StaticDialog.h"
const int extNameLen = 32; constexpr int extNameLen = 32;
class RegExtDlg : public StaticDialog class RegExtDlg : public StaticDialog
{ {
@ -33,7 +33,7 @@ public :
private : private :
bool _isCustomize = false; bool _isCustomize = false;
intptr_t CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); intptr_t CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) override;
void getRegisteredExts(); void getRegisteredExts();
void getDefSupportedExts(); void getDefSupportedExts();
@ -42,13 +42,13 @@ private :
void writeNppPath(); void writeNppPath();
int getNbSubKey(HKEY hKey) const { int getNbSubKey(HKEY hKey) const {
int nbSubKey; int nbSubKey = 0;
long result = ::RegQueryInfoKey(hKey, NULL, NULL, NULL, (LPDWORD)&nbSubKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL); long result = ::RegQueryInfoKey(hKey, NULL, NULL, NULL, (LPDWORD)&nbSubKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
return (result == ERROR_SUCCESS)?nbSubKey:0; return (result == ERROR_SUCCESS)?nbSubKey:0;
} }
int getNbSubValue(HKEY hKey) const { int getNbSubValue(HKEY hKey) const {
int nbSubValue; int nbSubValue = 0;
long result = ::RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, (LPDWORD)&nbSubValue, NULL, NULL, NULL, NULL); long result = ::RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, (LPDWORD)&nbSubValue, NULL, NULL, NULL, NULL);
return (result == ERROR_SUCCESS)?nbSubValue:0; return (result == ERROR_SUCCESS)?nbSubValue:0;
} }

View File

@ -39,9 +39,11 @@
#define S_R3(v,w,x,y,z,i) {z+=(((w|x)&y)|(w&x))+SHABLK(i)+0x8F1BBCDC+ROL32(v,5);w=ROL32(w,30);} #define S_R3(v,w,x,y,z,i) {z+=(((w|x)&y)|(w&x))+SHABLK(i)+0x8F1BBCDC+ROL32(v,5);w=ROL32(w,30);}
#define S_R4(v,w,x,y,z,i) {z+=(w^x^y)+SHABLK(i)+0xCA62C1D6+ROL32(v,5);w=ROL32(w,30);} #define S_R4(v,w,x,y,z,i) {z+=(w^x^y)+SHABLK(i)+0xCA62C1D6+ROL32(v,5);w=ROL32(w,30);}
#if defined(_MSC_VER)
#pragma warning(push) #pragma warning(push)
// Disable compiler warning 'Conditional expression is constant' // Disable compiler warning 'Conditional expression is constant'
#pragma warning(disable: 4127) #pragma warning(disable: 4127)
#endif
CSHA1::CSHA1() CSHA1::CSHA1()
{ {
@ -172,9 +174,9 @@ bool CSHA1::HashFile(const TCHAR* tszFileName)
void CSHA1::Final() void CSHA1::Final()
{ {
UINT_32 i; UINT_32 i = 0;
UINT_8 pbFinalCount[8]; UINT_8 pbFinalCount[8]{};
for(i = 0; i < 8; ++i) for(i = 0; i < 8; ++i)
pbFinalCount[i] = static_cast<UINT_8>((m_count[((i >= 4) ? 0 : 1)] >> pbFinalCount[i] = static_cast<UINT_8>((m_count[((i >= 4) ? 0 : 1)] >>
((3 - (i & 3)) * 8) ) & 0xFF); // Endian independent ((3 - (i & 3)) * 8) ) & 0xFF); // Endian independent
@ -205,7 +207,7 @@ bool CSHA1::ReportHash(TCHAR* tszReport, REPORT_TYPE rtReportType) const
{ {
if(tszReport == NULL) return false; if(tszReport == NULL) return false;
TCHAR tszTemp[16]; TCHAR tszTemp[16]{};
if((rtReportType == REPORT_HEX) || (rtReportType == REPORT_HEX_SHORT)) if((rtReportType == REPORT_HEX) || (rtReportType == REPORT_HEX_SHORT))
{ {
@ -239,7 +241,7 @@ bool CSHA1::ReportHash(TCHAR* tszReport, REPORT_TYPE rtReportType) const
#ifdef SHA1_STL_FUNCTIONS #ifdef SHA1_STL_FUNCTIONS
bool CSHA1::ReportHashStl(std::basic_string<TCHAR>& strOut, REPORT_TYPE rtReportType) const bool CSHA1::ReportHashStl(std::basic_string<TCHAR>& strOut, REPORT_TYPE rtReportType) const
{ {
TCHAR tszOut[84]; TCHAR tszOut[84]{};
const bool bResult = ReportHash(tszOut, rtReportType); const bool bResult = ReportHash(tszOut, rtReportType);
if(bResult) strOut = tszOut; if(bResult) strOut = tszOut;
return bResult; return bResult;
@ -253,4 +255,6 @@ bool CSHA1::GetHash(UINT_8* pbDest20) const
return true; return true;
} }
#if defined(_MSC_VER)
#pragma warning(pop) #pragma warning(pop)
#endif

View File

@ -18,7 +18,9 @@
#include <wincrypt.h> #include <wincrypt.h>
#include "sha512.h" #include "sha512.h"
#pragma comment(lib, "crypt32.lib") //#if defined(_MSC_VER)
//#pragma comment(lib, "crypt32.lib")
//#endif
void calc_sha_512(unsigned char hash[64], const void *input, size_t len) { void calc_sha_512(unsigned char hash[64], const void *input, size_t len) {
HCRYPTPROV hProv = 0; HCRYPTPROV hProv = 0;

View File

@ -508,11 +508,10 @@ LRESULT Notepad_plus::init(HWND hwnd)
// Find the first separator which is between IDM_LANG_TEXT and languages // Find the first separator which is between IDM_LANG_TEXT and languages
int x = 0; int x = 0;
MENUITEMINFO menuItemInfo MENUITEMINFO menuItemInfo{};
{ menuItemInfo.cbSize = sizeof(MENUITEMINFO);
.cbSize = sizeof(MENUITEMINFO), menuItemInfo.fMask = MIIM_FTYPE;
.fMask = MIIM_FTYPE
};
for (; x < nbItem; ++x) for (; x < nbItem; ++x)
{ {
::GetMenuItemInfo(subMenu, x, TRUE, &menuItemInfo); ::GetMenuItemInfo(subMenu, x, TRUE, &menuItemInfo);

View File

@ -33,7 +33,9 @@
using namespace std; using namespace std;
#ifndef WM_DPICHANGED
#define WM_DPICHANGED 0x02E0 #define WM_DPICHANGED 0x02E0
#endif
struct SortTaskListPred final struct SortTaskListPred final
@ -374,8 +376,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_LAUNCHFINDINFILESDLG: case NPPM_LAUNCHFINDINFILESDLG:
{ {
// Find in files function code should be here due to the number of parameters (2) cannot be passed via WM_COMMAND // Find in files function code should be here due to the number of parameters (2) cannot be passed via WM_COMMAND
const int strSize = FINDREPLACE_MAXLENGTH; constexpr int strSize = FINDREPLACE_MAXLENGTH;
TCHAR str[strSize]; TCHAR str[strSize]{};
bool isFirstTime = !_findReplaceDlg.isCreated(); bool isFirstTime = !_findReplaceDlg.isCreated();
_findReplaceDlg.doDialog(FIND_DLG, _nativeLangSpeaker.isRTL()); _findReplaceDlg.doDialog(FIND_DLG, _nativeLangSpeaker.isRTL());
@ -397,8 +399,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_INTERNAL_FINDINPROJECTS: case NPPM_INTERNAL_FINDINPROJECTS:
{ {
const int strSize = FINDREPLACE_MAXLENGTH; constexpr int strSize = FINDREPLACE_MAXLENGTH;
TCHAR str[strSize]; TCHAR str[strSize]{};
bool isFirstTime = not _findReplaceDlg.isCreated(); bool isFirstTime = not _findReplaceDlg.isCreated();
_findReplaceDlg.doDialog(FIND_DLG, _nativeLangSpeaker.isRTL()); _findReplaceDlg.doDialog(FIND_DLG, _nativeLangSpeaker.isRTL());
@ -414,8 +416,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_INTERNAL_FINDINFINDERDLG: case NPPM_INTERNAL_FINDINFINDERDLG:
{ {
const int strSize = FINDREPLACE_MAXLENGTH; constexpr int strSize = FINDREPLACE_MAXLENGTH;
TCHAR str[strSize]; TCHAR str[strSize]{};
Finder *launcher = reinterpret_cast<Finder *>(wParam); Finder *launcher = reinterpret_cast<Finder *>(wParam);
bool isFirstTime = !_findInFinderDlg.isCreated(); bool isFirstTime = !_findInFinderDlg.isCreated();
@ -558,7 +560,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_RELOADFILE: case NPPM_RELOADFILE:
{ {
TCHAR longNameFullpath[MAX_PATH]; TCHAR longNameFullpath[MAX_PATH]{};
const TCHAR* pFilePath = reinterpret_cast<const TCHAR*>(lParam); const TCHAR* pFilePath = reinterpret_cast<const TCHAR*>(lParam);
wcscpy_s(longNameFullpath, MAX_PATH, pFilePath); wcscpy_s(longNameFullpath, MAX_PATH, pFilePath);
if (wcschr(longNameFullpath, '~')) if (wcschr(longNameFullpath, '~'))
@ -949,12 +951,12 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_GETFILENAMEATCURSOR: // wParam = buffer length, lParam = (TCHAR*)buffer case NPPM_GETFILENAMEATCURSOR: // wParam = buffer length, lParam = (TCHAR*)buffer
{ {
const int strSize = CURRENTWORD_MAXLENGTH; constexpr int strSize = CURRENTWORD_MAXLENGTH;
TCHAR str[strSize]; TCHAR str[strSize]{};
TCHAR strLine[strSize]; TCHAR strLine[strSize]{};
size_t lineNumber; size_t lineNumber = 0;
intptr_t col; intptr_t col = 0;
int hasSlash; int hasSlash = 0;
TCHAR *pTchar = reinterpret_cast<TCHAR *>(lParam); TCHAR *pTchar = reinterpret_cast<TCHAR *>(lParam);
_pEditView->getGenericSelectedText(str, strSize); // this is either the selected text, or the word under the cursor if there is no selection _pEditView->getGenericSelectedText(str, strSize); // this is either the selected text, or the word under the cursor if there is no selection
@ -966,8 +968,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
if (hasSlash == FALSE) if (hasSlash == FALSE)
{ {
// it's not a full file name so try to find the beginning and ending of it // it's not a full file name so try to find the beginning and ending of it
intptr_t start; intptr_t start = 0;
intptr_t end; intptr_t end = 0;
const TCHAR *delimiters; const TCHAR *delimiters;
lineNumber = _pEditView->getCurrentLineNumber(); lineNumber = _pEditView->getCurrentLineNumber();
@ -1004,8 +1006,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_GETNPPFULLFILEPATH: case NPPM_GETNPPFULLFILEPATH:
case NPPM_GETNPPDIRECTORY: case NPPM_GETNPPDIRECTORY:
{ {
const int strSize = MAX_PATH; constexpr int strSize = MAX_PATH;
TCHAR str[strSize]; TCHAR str[strSize]{};
::GetModuleFileName(NULL, str, strSize); ::GetModuleFileName(NULL, str, strSize);
@ -1222,7 +1224,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_DECODESCI: case NPPM_DECODESCI:
{ {
// convert to ASCII // convert to ASCII
ScintillaEditView *pSci; ScintillaEditView *pSci = nullptr;
if (wParam == MAIN_VIEW) if (wParam == MAIN_VIEW)
pSci = &_mainEditView; pSci = &_mainEditView;
else if (wParam == SUB_VIEW) else if (wParam == SUB_VIEW)
@ -1260,7 +1262,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_ENCODESCI: case NPPM_ENCODESCI:
{ {
// convert // convert
ScintillaEditView *pSci; ScintillaEditView *pSci = nullptr;
if (wParam == MAIN_VIEW) if (wParam == MAIN_VIEW)
pSci = &_mainEditView; pSci = &_mainEditView;
else if (wParam == SUB_VIEW) else if (wParam == SUB_VIEW)

View File

@ -41,7 +41,7 @@ DWORD WINAPI Notepad_plus::monitorFileOnChange(void * params)
const TCHAR *fullFileName = (const TCHAR *)buf->getFullPathName(); const TCHAR *fullFileName = (const TCHAR *)buf->getFullPathName();
//The folder to watch : //The folder to watch :
WCHAR folderToMonitor[MAX_PATH]; WCHAR folderToMonitor[MAX_PATH]{};
wcscpy_s(folderToMonitor, fullFileName); wcscpy_s(folderToMonitor, fullFileName);
::PathRemoveFileSpecW(folderToMonitor); ::PathRemoveFileSpecW(folderToMonitor);
@ -74,7 +74,7 @@ DWORD WINAPI Notepad_plus::monitorFileOnChange(void * params)
case WAIT_OBJECT_0 + 1: case WAIT_OBJECT_0 + 1:
// We've received a notification in the queue. // We've received a notification in the queue.
{ {
DWORD dwAction; DWORD dwAction = 0;
generic_string fn; generic_string fn;
// Process all available changes, ignore User actions // Process all available changes, ignore User actions
while (dirChanges.Pop(dwAction, fn)) while (dirChanges.Pop(dwAction, fn))
@ -125,9 +125,9 @@ bool resolveLinkFile(generic_string& linkFilePath)
{ {
bool isResolved = false; bool isResolved = false;
IShellLink* psl; IShellLink* psl = nullptr;
WCHAR targetFilePath[MAX_PATH]; WCHAR targetFilePath[MAX_PATH]{};
WIN32_FIND_DATA wfd = {}; WIN32_FIND_DATA wfd{};
HRESULT hres = CoInitialize(NULL); HRESULT hres = CoInitialize(NULL);
if (SUCCEEDED(hres)) if (SUCCEEDED(hres))
@ -135,7 +135,7 @@ bool resolveLinkFile(generic_string& linkFilePath)
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl); hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
if (SUCCEEDED(hres)) if (SUCCEEDED(hres))
{ {
IPersistFile* ppf; IPersistFile* ppf = nullptr;
hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf); hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
if (SUCCEEDED(hres)) if (SUCCEEDED(hres))
{ {
@ -661,7 +661,7 @@ bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy)
if (openInAdminModeRes == IDYES) if (openInAdminModeRes == IDYES)
{ {
TCHAR nppFullPath[MAX_PATH]; TCHAR nppFullPath[MAX_PATH]{};
::GetModuleFileName(NULL, nppFullPath, MAX_PATH); ::GetModuleFileName(NULL, nppFullPath, MAX_PATH);
generic_string args = TEXT("-multiInst"); generic_string args = TEXT("-multiInst");
@ -696,7 +696,7 @@ bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy)
if (openInAdminModeRes == IDYES) if (openInAdminModeRes == IDYES)
{ {
TCHAR nppFullPath[MAX_PATH]; TCHAR nppFullPath[MAX_PATH]{};
::GetModuleFileName(NULL, nppFullPath, MAX_PATH); ::GetModuleFileName(NULL, nppFullPath, MAX_PATH);
BufferID bufferID = _pEditView->getCurrentBufferID(); BufferID bufferID = _pEditView->getCurrentBufferID();
@ -1612,8 +1612,8 @@ bool Notepad_plus::fileSave(BufferID id)
} }
else if (backup == bak_verbose) else if (backup == bak_verbose)
{ {
const int temBufLen = 32; constexpr int temBufLen = 32;
TCHAR tmpbuf[temBufLen]; TCHAR tmpbuf[temBufLen]{};
time_t ltime = time(0); time_t ltime = time(0);
struct tm *today; struct tm *today;
@ -2412,7 +2412,7 @@ bool Notepad_plus::fileLoadSession(const TCHAR *fn)
} }
if (!isEmptyNpp && (nppGUI._multiInstSetting == multiInstOnSession || nppGUI._multiInstSetting == multiInst)) if (!isEmptyNpp && (nppGUI._multiInstSetting == multiInstOnSession || nppGUI._multiInstSetting == multiInst))
{ {
TCHAR nppFullPath[MAX_PATH]; TCHAR nppFullPath[MAX_PATH]{};
::GetModuleFileName(NULL, nppFullPath, MAX_PATH); ::GetModuleFileName(NULL, nppFullPath, MAX_PATH);

View File

@ -46,21 +46,21 @@ public:
void insertChar(unsigned char char2insert) const; void insertChar(unsigned char char2insert) const;
void insertString(LPWSTR string2insert) const; void insertString(LPWSTR string2insert) const;
virtual void setBackgroundColor(int bgColour) const { void setBackgroundColor(COLORREF bgColour) override {
ListView_SetBkColor(_listView.getHSelf(), bgColour); ListView_SetBkColor(_listView.getHSelf(), bgColour);
ListView_SetTextBkColor(_listView.getHSelf(), bgColour); ListView_SetTextBkColor(_listView.getHSelf(), bgColour);
_listView.redraw(true); _listView.redraw(true);
}; };
virtual void setForegroundColor(int fgColour) const {
void setForegroundColor(COLORREF fgColour) override {
ListView_SetTextColor(_listView.getHSelf(), fgColour); ListView_SetTextColor(_listView.getHSelf(), fgColour);
_listView.redraw(true); _listView.redraw(true);
}; };
protected: protected:
virtual intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override;
private: private:
ScintillaEditView **_ppEditView = nullptr; ScintillaEditView **_ppEditView = nullptr;
AsciiListView _listView; AsciiListView _listView;
}; };

View File

@ -121,22 +121,22 @@ private:
DockingCont *_pCont = nullptr; DockingCont *_pCont = nullptr;
// mouse offset in moving rectangle // mouse offset in moving rectangle
POINT _ptOffset = {}; POINT _ptOffset{};
// remembers old mouse point // remembers old mouse point
POINT _ptOld = {}; POINT _ptOld{};
BOOL _bPtOldValid = FALSE; BOOL _bPtOldValid = FALSE;
// remember last drawn rectangle (jg) // remember last drawn rectangle (jg)
RECT _rcPrev = {}; RECT _rcPrev{};
// for sorting tabs // for sorting tabs
HWND _hTab = nullptr; HWND _hTab = nullptr;
HWND _hTabSource = nullptr; HWND _hTabSource = nullptr;
BOOL _startMovingFromTab = FALSE; BOOL _startMovingFromTab = FALSE;
int _iItem = 0; int _iItem = 0;
RECT _rcItem = {}; RECT _rcItem{};
TCITEM _tcItem; TCITEM _tcItem{};
HDC _hdc = nullptr; HDC _hdc = nullptr;
HBITMAP _hbm = nullptr; HBITMAP _hbm = nullptr;

View File

@ -3255,11 +3255,9 @@ intptr_t CALLBACK LanguageSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
// Find the first separator which is between IDM_LANG_TEXT and languages // Find the first separator which is between IDM_LANG_TEXT and languages
int nbItem = ::GetMenuItemCount(subMenu); int nbItem = ::GetMenuItemCount(subMenu);
int x = 0; int x = 0;
MENUITEMINFO menuItemInfo MENUITEMINFO menuItemInfo{};
{ menuItemInfo.cbSize = sizeof(MENUITEMINFO);
.cbSize = sizeof(MENUITEMINFO), menuItemInfo.fMask = MIIM_FTYPE;
.fMask = MIIM_FTYPE
};
for (; x < nbItem; ++x) for (; x < nbItem; ++x)
{ {
::GetMenuItemInfo(subMenu, x, TRUE, &menuItemInfo); ::GetMenuItemInfo(subMenu, x, TRUE, &menuItemInfo);

View File

@ -73,7 +73,7 @@ LRESULT TreeView::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
// with the TVE_COLLAPSE and TVE_COLLAPSERESET flags set. // with the TVE_COLLAPSE and TVE_COLLAPSERESET flags set.
// That in turn removes child items which is unwanted. // That in turn removes child items which is unwanted.
// Below is a workaround for that. // Below is a workaround for that.
TVITEM tvItem = {}; TVITEM tvItem{};
tvItem.hItem = reinterpret_cast<HTREEITEM>(lParam); tvItem.hItem = reinterpret_cast<HTREEITEM>(lParam);
tvItem.mask = TVIF_STATE | TVIF_HANDLE | TVIF_PARAM; tvItem.mask = TVIF_STATE | TVIF_HANDLE | TVIF_PARAM;
tvItem.stateMask = TVIS_EXPANDEDONCE; tvItem.stateMask = TVIS_EXPANDEDONCE;
@ -83,7 +83,7 @@ LRESULT TreeView::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{ {
// If the flag is set, then manually notify parent that an item is collapsed/expanded // If the flag is set, then manually notify parent that an item is collapsed/expanded
// so that it can change icon, etc. // so that it can change icon, etc.
NMTREEVIEW nmtv = {}; NMTREEVIEW nmtv{};
nmtv.hdr.code = TVN_ITEMEXPANDED; nmtv.hdr.code = TVN_ITEMEXPANDED;
nmtv.hdr.hwndFrom = _hSelf; nmtv.hdr.hwndFrom = _hSelf;
nmtv.hdr.idFrom = 0; nmtv.hdr.idFrom = 0;
@ -112,7 +112,7 @@ bool TreeView::setItemParam(HTREEITEM Item2Set, LPARAM param)
if (!Item2Set) if (!Item2Set)
return false; return false;
TVITEM tvItem; TVITEM tvItem{};
tvItem.hItem = Item2Set; tvItem.hItem = Item2Set;
tvItem.mask = TVIF_PARAM; tvItem.mask = TVIF_PARAM;
tvItem.lParam = param; tvItem.lParam = param;
@ -126,7 +126,7 @@ LPARAM TreeView::getItemParam(HTREEITEM Item2Get) const
if (!Item2Get) if (!Item2Get)
return false; return false;
//TCHAR textBuffer[MAX_PATH]; //TCHAR textBuffer[MAX_PATH];
TVITEM tvItem; TVITEM tvItem{};
tvItem.hItem = Item2Get; tvItem.hItem = Item2Get;
tvItem.mask = TVIF_PARAM; tvItem.mask = TVIF_PARAM;
//tvItem.pszText = textBuffer; //tvItem.pszText = textBuffer;
@ -140,7 +140,7 @@ generic_string TreeView::getItemDisplayName(HTREEITEM Item2Set) const
if (!Item2Set) if (!Item2Set)
return TEXT(""); return TEXT("");
TCHAR textBuffer[MAX_PATH] = { '\0' }; TCHAR textBuffer[MAX_PATH] = { '\0' };
TVITEM tvItem; TVITEM tvItem{};
tvItem.hItem = Item2Set; tvItem.hItem = Item2Set;
tvItem.mask = TVIF_TEXT; tvItem.mask = TVIF_TEXT;
tvItem.pszText = textBuffer; tvItem.pszText = textBuffer;
@ -154,7 +154,7 @@ bool TreeView::renameItem(HTREEITEM Item2Set, const TCHAR *newName)
if (!Item2Set || !newName) if (!Item2Set || !newName)
return false; return false;
TVITEM tvItem; TVITEM tvItem{};
tvItem.hItem = Item2Set; tvItem.hItem = Item2Set;
tvItem.mask = TVIF_TEXT; tvItem.mask = TVIF_TEXT;
tvItem.pszText = (LPWSTR)newName; tvItem.pszText = (LPWSTR)newName;
@ -165,7 +165,7 @@ bool TreeView::renameItem(HTREEITEM Item2Set, const TCHAR *newName)
HTREEITEM TreeView::addItem(const TCHAR *itemName, HTREEITEM hParentItem, int iImage, LPARAM lParam) HTREEITEM TreeView::addItem(const TCHAR *itemName, HTREEITEM hParentItem, int iImage, LPARAM lParam)
{ {
TVITEM tvi; TVITEM tvi{};
tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
// Set the item label. // Set the item label.
@ -178,7 +178,7 @@ HTREEITEM TreeView::addItem(const TCHAR *itemName, HTREEITEM hParentItem, int iI
tvi.lParam = lParam; tvi.lParam = lParam;
TVINSERTSTRUCT tvInsertStruct; TVINSERTSTRUCT tvInsertStruct{};
tvInsertStruct.item = tvi; tvInsertStruct.item = tvi;
tvInsertStruct.hInsertAfter = TVI_LAST; tvInsertStruct.hInsertAfter = TVI_LAST;
tvInsertStruct.hParent = hParentItem; tvInsertStruct.hParent = hParentItem;
@ -192,7 +192,7 @@ void TreeView::removeItem(HTREEITEM hTreeItem)
cleanSubEntries(hTreeItem); cleanSubEntries(hTreeItem);
// Deallocate current entry // Deallocate current entry
TVITEM tvItem; TVITEM tvItem{};
tvItem.hItem = hTreeItem; tvItem.hItem = hTreeItem;
tvItem.mask = TVIF_PARAM; tvItem.mask = TVIF_PARAM;
SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvItem)); SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvItem));
@ -217,15 +217,15 @@ void TreeView::dupTree(HTREEITEM hTree2Dup, HTREEITEM hParentItem)
{ {
for (HTREEITEM hItem = getChildFrom(hTree2Dup); hItem != NULL; hItem = getNextSibling(hItem)) for (HTREEITEM hItem = getChildFrom(hTree2Dup); hItem != NULL; hItem = getNextSibling(hItem))
{ {
TCHAR textBuffer[MAX_PATH]; TCHAR textBuffer[MAX_PATH]{};
TVITEM tvItem; TVITEM tvItem{};
tvItem.hItem = hItem; tvItem.hItem = hItem;
tvItem.pszText = textBuffer; tvItem.pszText = textBuffer;
tvItem.cchTextMax = MAX_PATH; tvItem.cchTextMax = MAX_PATH;
tvItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvItem)); SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvItem));
TVINSERTSTRUCT tvInsertStruct; TVINSERTSTRUCT tvInsertStruct{};
tvInsertStruct.item = tvItem; tvInsertStruct.item = tvItem;
tvInsertStruct.hInsertAfter = TVI_LAST; tvInsertStruct.hInsertAfter = TVI_LAST;
tvInsertStruct.hParent = hParentItem; tvInsertStruct.hParent = hParentItem;
@ -236,16 +236,16 @@ void TreeView::dupTree(HTREEITEM hTree2Dup, HTREEITEM hParentItem)
HTREEITEM TreeView::searchSubItemByName(const TCHAR *itemName, HTREEITEM hParentItem) HTREEITEM TreeView::searchSubItemByName(const TCHAR *itemName, HTREEITEM hParentItem)
{ {
HTREEITEM hItem = NULL; HTREEITEM hItem = nullptr;
if (hParentItem != NULL) if (hParentItem != nullptr)
hItem = getChildFrom(hParentItem); hItem = getChildFrom(hParentItem);
else else
hItem = getRoot(); hItem = getRoot();
for ( ; hItem != NULL; hItem = getNextSibling(hItem)) while (hItem != nullptr)
{ {
TCHAR textBuffer[MAX_PATH] = { '\0' }; TCHAR textBuffer[MAX_PATH] = { '\0' };
TVITEM tvItem; TVITEM tvItem{};
tvItem.hItem = hItem; tvItem.hItem = hItem;
tvItem.pszText = textBuffer; tvItem.pszText = textBuffer;
tvItem.cchTextMax = MAX_PATH; tvItem.cchTextMax = MAX_PATH;
@ -256,8 +256,10 @@ HTREEITEM TreeView::searchSubItemByName(const TCHAR *itemName, HTREEITEM hParent
{ {
return hItem; return hItem;
} }
hItem = getNextSibling(hItem);
} }
return NULL; return nullptr;
} }
BOOL TreeView::setImageList(int w, int h, int nbImage, int image_id, ...) BOOL TreeView::setImageList(int w, int h, int nbImage, int image_id, ...)
@ -300,7 +302,7 @@ void TreeView::cleanSubEntries(HTREEITEM hTreeItem)
{ {
for (HTREEITEM hItem = getChildFrom(hTreeItem); hItem != NULL; hItem = getNextSibling(hItem)) for (HTREEITEM hItem = getChildFrom(hTreeItem); hItem != NULL; hItem = getNextSibling(hItem))
{ {
TVITEM tvItem; TVITEM tvItem{};
tvItem.hItem = hItem; tvItem.hItem = hItem;
tvItem.mask = TVIF_PARAM; tvItem.mask = TVIF_PARAM;
SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvItem)); SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvItem));
@ -350,7 +352,7 @@ void TreeView::foldExpandAll(bool isFold) const
void TreeView::setItemImage(HTREEITEM hTreeItem, int iImage, int iSelectedImage) void TreeView::setItemImage(HTREEITEM hTreeItem, int iImage, int iSelectedImage)
{ {
TVITEM tvItem; TVITEM tvItem{};
tvItem.hItem = hTreeItem; tvItem.hItem = hTreeItem;
tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvItem.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvItem.iImage = iImage; tvItem.iImage = iImage;
@ -384,7 +386,7 @@ void TreeView::beginDrag(NMTREEVIEW* tv)
void TreeView::dragItem(HWND parentHandle, int x, int y) void TreeView::dragItem(HWND parentHandle, int x, int y)
{ {
// convert the dialog coords to control coords // convert the dialog coords to control coords
POINT point; POINT point{};
point.x = (SHORT)x; point.x = (SHORT)x;
point.y = (SHORT)y; point.y = (SHORT)y;
::ClientToScreen(parentHandle, &point); ::ClientToScreen(parentHandle, &point);
@ -398,7 +400,7 @@ void TreeView::dragItem(HWND parentHandle, int x, int y)
// find out if the pointer is on an item // find out if the pointer is on an item
// If so, highlight the item as a drop target. // If so, highlight the item as a drop target.
TVHITTESTINFO hitTestInfo; TVHITTESTINFO hitTestInfo{};
hitTestInfo.pt.x = point.x; hitTestInfo.pt.x = point.x;
hitTestInfo.pt.y = point.y; hitTestInfo.pt.y = point.y;
HTREEITEM targetItem = reinterpret_cast<HTREEITEM>(::SendMessage(_hSelf, TVM_HITTEST, 0, reinterpret_cast<LPARAM>(&hitTestInfo))); HTREEITEM targetItem = reinterpret_cast<HTREEITEM>(::SendMessage(_hSelf, TVM_HITTEST, 0, reinterpret_cast<LPARAM>(&hitTestInfo)));
@ -486,15 +488,15 @@ bool TreeView::isParent(HTREEITEM targetItem, HTREEITEM draggedItem)
void TreeView::moveTreeViewItem(HTREEITEM draggedItem, HTREEITEM targetItem) void TreeView::moveTreeViewItem(HTREEITEM draggedItem, HTREEITEM targetItem)
{ {
TCHAR textBuffer[MAX_PATH]; TCHAR textBuffer[MAX_PATH]{};
TVITEM tvDraggingItem; TVITEM tvDraggingItem{};
tvDraggingItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvDraggingItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvDraggingItem.pszText = textBuffer; tvDraggingItem.pszText = textBuffer;
tvDraggingItem.cchTextMax = MAX_PATH; tvDraggingItem.cchTextMax = MAX_PATH;
tvDraggingItem.hItem = draggedItem; tvDraggingItem.hItem = draggedItem;
SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvDraggingItem)); SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvDraggingItem));
TVINSERTSTRUCT tvInsertStruct; TVINSERTSTRUCT tvInsertStruct{};
tvInsertStruct.item = tvDraggingItem; tvInsertStruct.item = tvDraggingItem;
tvInsertStruct.hInsertAfter = (HTREEITEM)TVI_LAST; tvInsertStruct.hInsertAfter = (HTREEITEM)TVI_LAST;
tvInsertStruct.hParent = targetItem; tvInsertStruct.hParent = targetItem;
@ -535,10 +537,10 @@ bool TreeView::swapTreeViewItem(HTREEITEM itemGoDown, HTREEITEM itemGoUp)
return false; return false;
// get both item infos // get both item infos
TCHAR textBufferUp[MAX_PATH]; TCHAR textBufferUp[MAX_PATH]{};
TCHAR textBufferDown[MAX_PATH]; TCHAR textBufferDown[MAX_PATH]{};
TVITEM tvUpItem; TVITEM tvUpItem{};
TVITEM tvDownItem; TVITEM tvDownItem{};
tvUpItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvUpItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvDownItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvDownItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvUpItem.pszText = textBufferUp; tvUpItem.pszText = textBufferUp;
@ -551,14 +553,14 @@ bool TreeView::swapTreeViewItem(HTREEITEM itemGoDown, HTREEITEM itemGoUp)
SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvDownItem)); SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvDownItem));
// add 2 new items // add 2 new items
TVINSERTSTRUCT tvInsertUp; TVINSERTSTRUCT tvInsertUp{};
tvInsertUp.item = tvUpItem; tvInsertUp.item = tvUpItem;
tvInsertUp.hInsertAfter = itemTop; tvInsertUp.hInsertAfter = itemTop;
tvInsertUp.hParent = parentGoUp; tvInsertUp.hParent = parentGoUp;
HTREEITEM hTreeParent1stInserted = reinterpret_cast<HTREEITEM>(::SendMessage(_hSelf, TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>(&tvInsertUp))); HTREEITEM hTreeParent1stInserted = reinterpret_cast<HTREEITEM>(::SendMessage(_hSelf, TVM_INSERTITEM, 0, reinterpret_cast<LPARAM>(&tvInsertUp)));
dupTree(itemGoUp, hTreeParent1stInserted); dupTree(itemGoUp, hTreeParent1stInserted);
TVINSERTSTRUCT tvInsertDown; TVINSERTSTRUCT tvInsertDown{};
tvInsertDown.item = tvDownItem; tvInsertDown.item = tvDownItem;
tvInsertDown.hInsertAfter = hTreeParent1stInserted; tvInsertDown.hInsertAfter = hTreeParent1stInserted;
tvInsertDown.hParent = parentGoDown; tvInsertDown.hParent = parentGoDown;
@ -587,7 +589,7 @@ bool TreeView::swapTreeViewItem(HTREEITEM itemGoDown, HTREEITEM itemGoUp)
bool TreeView::canDropIn(HTREEITEM targetItem) bool TreeView::canDropIn(HTREEITEM targetItem)
{ {
TVITEM tvItem; TVITEM tvItem{};
tvItem.mask = TVIF_IMAGE; tvItem.mask = TVIF_IMAGE;
tvItem.hItem = targetItem; tvItem.hItem = targetItem;
SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvItem)); SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvItem));
@ -603,7 +605,7 @@ bool TreeView::canDropIn(HTREEITEM targetItem)
bool TreeView::canDragOut(HTREEITEM targetItem) bool TreeView::canDragOut(HTREEITEM targetItem)
{ {
TVITEM tvItem; TVITEM tvItem{};
tvItem.mask = TVIF_IMAGE; tvItem.mask = TVIF_IMAGE;
tvItem.hItem = targetItem; tvItem.hItem = targetItem;
SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvItem)); SendMessage(_hSelf, TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvItem));
@ -632,7 +634,7 @@ bool TreeView::searchLeafRecusivelyAndBuildTree(HTREEITEM tree2Build, const gene
return false; return false;
TCHAR textBuffer[MAX_PATH] = { '\0' }; TCHAR textBuffer[MAX_PATH] = { '\0' };
TVITEM tvItem; TVITEM tvItem{};
tvItem.hItem = tree2Search; tvItem.hItem = tree2Search;
tvItem.pszText = textBuffer; tvItem.pszText = textBuffer;
tvItem.cchTextMax = MAX_PATH; tvItem.cchTextMax = MAX_PATH;
@ -647,7 +649,7 @@ bool TreeView::searchLeafRecusivelyAndBuildTree(HTREEITEM tree2Build, const gene
size_t res = itemNameUpperCase.find(text2SearchUpperCase); size_t res = itemNameUpperCase.find(text2SearchUpperCase);
if (res != generic_string::npos) if (res != generic_string::npos)
{ {
TVINSERTSTRUCT tvInsertStruct; TVINSERTSTRUCT tvInsertStruct{};
tvInsertStruct.item = tvItem; tvInsertStruct.item = tvItem;
tvInsertStruct.hInsertAfter = TVI_LAST; tvInsertStruct.hInsertAfter = TVI_LAST;
tvInsertStruct.hParent = tree2Build; tvInsertStruct.hParent = tree2Build;
@ -674,7 +676,7 @@ bool TreeView::retrieveFoldingStateTo(TreeStateNode & treeState2Construct, HTREE
return false; return false;
TCHAR textBuffer[MAX_PATH] = { '\0' }; TCHAR textBuffer[MAX_PATH] = { '\0' };
TVITEM tvItem; TVITEM tvItem{};
tvItem.hItem = treeviewNode; tvItem.hItem = treeviewNode;
tvItem.pszText = textBuffer; tvItem.pszText = textBuffer;
tvItem.cchTextMax = MAX_PATH; tvItem.cchTextMax = MAX_PATH;
@ -740,7 +742,7 @@ void TreeView::sort(HTREEITEM hTreeItem, bool isRecusive)
void TreeView::customSorting(HTREEITEM hTreeItem, PFNTVCOMPARE sortingCallbackFunc, LPARAM lParam, bool isRecusive) void TreeView::customSorting(HTREEITEM hTreeItem, PFNTVCOMPARE sortingCallbackFunc, LPARAM lParam, bool isRecusive)
{ {
TVSORTCB treeViewSortCB; TVSORTCB treeViewSortCB{};
treeViewSortCB.hParent = hTreeItem; treeViewSortCB.hParent = hTreeItem;
treeViewSortCB.lpfnCompare = sortingCallbackFunc; treeViewSortCB.lpfnCompare = sortingCallbackFunc;
treeViewSortCB.lParam = lParam; treeViewSortCB.lParam = lParam;