Fix customizing toolbar icon messed with dark mode

Ref:
d85b9a7464 (commitcomment-74498214)
This commit is contained in:
Don Ho 2022-05-27 04:06:11 +02:00
parent b25f37646d
commit fa3ba7e389
6 changed files with 70 additions and 71 deletions

View File

@ -613,8 +613,6 @@ LRESULT Notepad_plus::init(HWND hwnd)
_toolBar.init(_pPublicInterface->getHinst(), hwnd, tbStatus, toolBarIcons, sizeof(toolBarIcons) / sizeof(ToolBarButtonUnit)); _toolBar.init(_pPublicInterface->getHinst(), hwnd, tbStatus, toolBarIcons, sizeof(toolBarIcons) / sizeof(ToolBarButtonUnit));
changeToolBarIcons();
_rebarTop.init(_pPublicInterface->getHinst(), hwnd); _rebarTop.init(_pPublicInterface->getHinst(), hwnd);
_rebarBottom.init(_pPublicInterface->getHinst(), hwnd); _rebarBottom.init(_pPublicInterface->getHinst(), hwnd);
_toolBar.addToRebar(&_rebarTop); _toolBar.addToRebar(&_rebarTop);
@ -5113,11 +5111,6 @@ bool Notepad_plus::addCurrentMacro()
return false; return false;
} }
void Notepad_plus::changeToolBarIcons()
{
_toolBar.changeIcons();
}
bool Notepad_plus::switchToFile(BufferID id) bool Notepad_plus::switchToFile(BufferID id)
{ {
int i = 0; int i = 0;

View File

@ -207,7 +207,6 @@ public:
bool fileLoadSession(const TCHAR* fn = nullptr); bool fileLoadSession(const TCHAR* fn = nullptr);
const TCHAR * fileSaveSession(size_t nbFile, TCHAR ** fileNames, const TCHAR *sessionFile2save, bool includeFileBrowser = false); const TCHAR * fileSaveSession(size_t nbFile, TCHAR ** fileNames, const TCHAR *sessionFile2save, bool includeFileBrowser = false);
const TCHAR * fileSaveSession(size_t nbFile = 0, TCHAR** fileNames = nullptr); const TCHAR * fileSaveSession(size_t nbFile = 0, TCHAR** fileNames = nullptr);
void changeToolBarIcons();
bool doBlockComment(comment_mode currCommentMode); bool doBlockComment(comment_mode currCommentMode);
bool doStreamComment(); bool doStreamComment();

View File

@ -1988,7 +1988,7 @@ void Notepad_plus::command(int id)
bool isFolded = _pEditView->isCurrentLineFolded(); bool isFolded = _pEditView->isCurrentLineFolded();
mode = isFolded ? fold_uncollapse : fold_collapse; mode = isFolded ? fold_uncollapse : fold_collapse;
} }
_pEditView->foldCurrentPos(mode); _pEditView->foldCurrentPos(mode);
} }
break; break;
@ -2041,7 +2041,6 @@ void Notepad_plus::command(int id)
if (state != TB_SMALL) if (state != TB_SMALL)
{ {
_toolBar.reduce(); _toolBar.reduce();
changeToolBarIcons();
} }
} }
break; break;
@ -2053,7 +2052,6 @@ void Notepad_plus::command(int id)
if (state != TB_LARGE) if (state != TB_LARGE)
{ {
_toolBar.enlarge(); _toolBar.enlarge();
changeToolBarIcons();
} }
} }
break; break;
@ -2065,7 +2063,6 @@ void Notepad_plus::command(int id)
if (state != TB_SMALL2) if (state != TB_SMALL2)
{ {
_toolBar.reduceToSet2(); _toolBar.reduceToSet2();
changeToolBarIcons();
} }
} }
break; break;
@ -2077,7 +2074,6 @@ void Notepad_plus::command(int id)
if (state != TB_LARGE2) if (state != TB_LARGE2)
{ {
_toolBar.enlargeToSet2(); _toolBar.enlargeToSet2();
changeToolBarIcons();
} }
} }
break; break;

View File

@ -146,7 +146,9 @@ public :
bool replaceIcon(size_t witchList, size_t iconIndex, const TCHAR *iconLocation) const { bool replaceIcon(size_t witchList, size_t iconIndex, const TCHAR *iconLocation) const {
if ((witchList != HLIST_DEFAULT) && (witchList != HLIST_DISABLE) && if ((witchList != HLIST_DEFAULT) && (witchList != HLIST_DISABLE) &&
(witchList != HLIST_DEFAULT2) && (witchList != HLIST_DISABLE2)) (witchList != HLIST_DEFAULT2) && (witchList != HLIST_DISABLE2) &&
(witchList != HLIST_DEFAULT_DM) && (witchList != HLIST_DISABLE_DM) &&
(witchList != HLIST_DEFAULT_DM2) && (witchList != HLIST_DISABLE_DM2))
return false; return false;
return _iconListVector[witchList].changeIcon(iconIndex, iconLocation); return _iconListVector[witchList].changeIcon(iconIndex, iconLocation);

View File

@ -92,7 +92,12 @@ void ToolBar::initTheme(TiXmlDocument *toolIconsDocRoot)
locator += icoUnit._id; locator += icoUnit._id;
locator += ext; locator += ext;
if (::PathFileExists(locator.c_str())) if (::PathFileExists(locator.c_str()))
_customIconVect.push_back(iconLocator(0, i, locator)); {
_customIconVect.push_back(iconLocator(HLIST_DEFAULT, i, locator));
_customIconVect.push_back(iconLocator(HLIST_DEFAULT2, i, locator));
_customIconVect.push_back(iconLocator(HLIST_DEFAULT_DM, i, locator));
_customIconVect.push_back(iconLocator(HLIST_DEFAULT_DM2, i, locator));
}
if (icoUnit.hasDisabledIcon) if (icoUnit.hasDisabledIcon)
{ {
@ -102,7 +107,12 @@ void ToolBar::initTheme(TiXmlDocument *toolIconsDocRoot)
locator_dis += disabled_suffix; locator_dis += disabled_suffix;
locator_dis += ext; locator_dis += ext;
if (::PathFileExists(locator_dis.c_str())) if (::PathFileExists(locator_dis.c_str()))
_customIconVect.push_back(iconLocator(1, i, locator_dis)); {
_customIconVect.push_back(iconLocator(HLIST_DISABLE, i, locator_dis));
_customIconVect.push_back(iconLocator(HLIST_DISABLE2, i, locator_dis));
_customIconVect.push_back(iconLocator(HLIST_DISABLE_DM, i, locator_dis));
_customIconVect.push_back(iconLocator(HLIST_DISABLE_DM2, i, locator_dis));
}
} }
i++; i++;
} }
@ -264,10 +274,8 @@ void ToolBar::setToBmpIcons()
Window::redraw(); Window::redraw();
} }
void ToolBar::reset(bool create) void ToolBar::reset(bool create)
{ {
if (create && _hSelf) if (create && _hSelf)
{ {
//Store current button state information //Store current button state information
@ -307,6 +315,8 @@ void ToolBar::reset(bool create)
// backward compatibility. // backward compatibility.
::SendMessage(_hSelf, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); ::SendMessage(_hSelf, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
::SendMessage(_hSelf, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS); ::SendMessage(_hSelf, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS);
change2CustomIconsIfAny();
} }
if (!_hSelf) if (!_hSelf)
@ -317,73 +327,71 @@ void ToolBar::reset(bool create)
bool doOverrideToolbarIcons = _customIconVect.size() > 0; bool doOverrideToolbarIcons = _customIconVect.size() > 0;
if (doOverrideToolbarIcons) if (doOverrideToolbarIcons)
{ {
setDefaultImageList(); if (_state == TB_STANDARD)
setDisableImageList(); _state = TB_SMALL;
} }
else // use internal icons according the settings
{
if (_state != TB_STANDARD) //If non standard icons, use custom imagelists
{
if (_state == TB_SMALL || _state == TB_LARGE)
{
if (NppDarkMode::isEnabled())
{
setDefaultImageListDM();
setDisableImageListDM();
if (NppDarkMode::isWindows11()) if (_state != TB_STANDARD) //If non standard icons, use custom imagelists
{ {
setHoveredImageListDM(); if (_state == TB_SMALL || _state == TB_LARGE)
} {
} if (NppDarkMode::isEnabled())
else {
setDefaultImageListDM();
setDisableImageListDM();
if (NppDarkMode::isWindows11())
{ {
setDefaultImageList(); setHoveredImageListDM();
setDisableImageList();
} }
} }
else else
{ {
if (NppDarkMode::isEnabled()) setDefaultImageList();
{ setDisableImageList();
setDefaultImageListDM2();
setDisableImageListDM2();
if (NppDarkMode::isWindows11())
{
setHoveredImageListDM2();
}
}
else
{
setDefaultImageList2();
setDisableImageList2();
}
} }
} }
else else
{ {
//Else set the internal imagelist with standard bitmaps if (NppDarkMode::isEnabled())
int iconDpiDynamicalSize = NppParameters::getInstance()._dpiManager.scaleX(16); {
::SendMessage(_hSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(iconDpiDynamicalSize, iconDpiDynamicalSize)); setDefaultImageListDM2();
setDisableImageListDM2();
TBADDBITMAP addbmp = { 0, 0 }; if (NppDarkMode::isWindows11())
TBADDBITMAP addbmpdyn = { 0, 0 };
for (size_t i = 0; i < _nbButtons; ++i)
{
int icoID = _toolBarIcons.getStdIconAt(static_cast<int32_t>(i));
HBITMAP hBmp = static_cast<HBITMAP>(::LoadImage(_hInst, MAKEINTRESOURCE(icoID), IMAGE_BITMAP, iconDpiDynamicalSize, iconDpiDynamicalSize, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT));
addbmp.nID = reinterpret_cast<UINT_PTR>(hBmp);
::SendMessage(_hSelf, TB_ADDBITMAP, 1, reinterpret_cast<LPARAM>(&addbmp));
}
if (_nbDynButtons > 0)
{
for (size_t j = 0; j < _nbDynButtons; ++j)
{ {
addbmpdyn.nID = reinterpret_cast<UINT_PTR>(_vDynBtnReg.at(j)._hBmp); setHoveredImageListDM2();
::SendMessage(_hSelf, TB_ADDBITMAP, 1, reinterpret_cast<LPARAM>(&addbmpdyn));
} }
} }
else
{
setDefaultImageList2();
setDisableImageList2();
}
}
}
else
{
//Else set the internal imagelist with standard bitmaps
int iconDpiDynamicalSize = NppParameters::getInstance()._dpiManager.scaleX(16);
::SendMessage(_hSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(iconDpiDynamicalSize, iconDpiDynamicalSize));
TBADDBITMAP addbmp = { 0, 0 };
TBADDBITMAP addbmpdyn = { 0, 0 };
for (size_t i = 0; i < _nbButtons; ++i)
{
int icoID = _toolBarIcons.getStdIconAt(static_cast<int32_t>(i));
HBITMAP hBmp = static_cast<HBITMAP>(::LoadImage(_hInst, MAKEINTRESOURCE(icoID), IMAGE_BITMAP, iconDpiDynamicalSize, iconDpiDynamicalSize, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT));
addbmp.nID = reinterpret_cast<UINT_PTR>(hBmp);
::SendMessage(_hSelf, TB_ADDBITMAP, 1, reinterpret_cast<LPARAM>(&addbmp));
}
if (_nbDynButtons > 0)
{
for (size_t j = 0; j < _nbDynButtons; ++j)
{
addbmpdyn.nID = reinterpret_cast<UINT_PTR>(_vDynBtnReg.at(j)._hBmp);
::SendMessage(_hSelf, TB_ADDBITMAP, 1, reinterpret_cast<LPARAM>(&addbmpdyn));
}
} }
} }

View File

@ -82,7 +82,7 @@ public :
return _state; return _state;
}; };
bool changeIcons() { bool change2CustomIconsIfAny() {
if (!_toolIcons) return false; if (!_toolIcons) return false;
for (size_t i = 0, len = _customIconVect.size(); i < len; ++i) for (size_t i = 0, len = _customIconVect.size(); i < len; ++i)
@ -113,6 +113,7 @@ private :
ReBar * _pRebar = nullptr; ReBar * _pRebar = nullptr;
REBARBANDINFO _rbBand = {}; REBARBANDINFO _rbBand = {};
std::vector<iconLocator> _customIconVect; std::vector<iconLocator> _customIconVect;
TiXmlNode *_toolIcons = nullptr; TiXmlNode *_toolIcons = nullptr;
void setDefaultImageList() { void setDefaultImageList() {