Add new API NPPM_ADDTOOLBARICON_FORDARKMODE for darkmode

Usage:
void NPPM_ADDTOOLBARICON_FORDARKMODE(UINT funcItem[X]._cmdID, toolbarIconsWithDarkMode iconHandles)

This new API NPPM_ADDTOOLBARICON_FORDARKMODE is for replacing obsolete NPPM_ADDTOOLBARICON which doesn't support the dark mode.
2 formats / 3 icons are needed:  1 * BMP + 2 * ICO
All 3 handles below should be set so the icon will be displayed correctly if toolbar icon sets are changed by users, also in dark mode.
	struct toolbarIconsWithDarkMode {
		HBITMAP	hToolbarBmp;
		HICON	hToolbarIcon;
		HICON	hToolbarIconDarkMode;
	};

Close #9928
This commit is contained in:
Don HO 2021-05-31 13:28:27 +02:00
parent 219dfda6b3
commit 8a898bae3f
6 changed files with 48 additions and 16 deletions

View File

@ -145,8 +145,8 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64 };
#define NPPM_SETMENUITEMCHECK (NPPMSG + 40) #define NPPM_SETMENUITEMCHECK (NPPMSG + 40)
//void WM_PIMENU_CHECK(UINT funcItem[X]._cmdID, TRUE/FALSE) //void WM_PIMENU_CHECK(UINT funcItem[X]._cmdID, TRUE/FALSE)
#define NPPM_ADDTOOLBARICON (NPPMSG + 41) #define NPPM_ADDTOOLBARICON_DEPRECATED (NPPMSG + 41)
//void NPPM_ADDTOOLBARICON(UINT funcItem[X]._cmdID, toolbarIcons icon) //void NPPM_ADDTOOLBARICON(UINT funcItem[X]._cmdID, toolbarIcons iconHandles) -- DEPRECATED : use NPPM_ADDTOOLBARICON_FORDARKMODE instead
//2 formats of icon are needed: .ico & .bmp //2 formats of icon are needed: .ico & .bmp
//Both handles below should be set so the icon will be displayed correctly if toolbar icon sets are changed by users //Both handles below should be set so the icon will be displayed correctly if toolbar icon sets are changed by users
struct toolbarIcons { struct toolbarIcons {
@ -244,7 +244,6 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64 };
// wParam: Buffer to reload // wParam: Buffer to reload
// lParam: 0 if no alert, else alert // lParam: 0 if no alert, else alert
#define NPPM_GETBUFFERLANGTYPE (NPPMSG + 64) #define NPPM_GETBUFFERLANGTYPE (NPPMSG + 64)
// INT NPPM_GETBUFFERLANGTYPE(UINT_PTR bufferID, 0) // INT NPPM_GETBUFFERLANGTYPE(UINT_PTR bufferID, 0)
// wParam: BufferID to get LangType from // wParam: BufferID to get LangType from
@ -439,6 +438,16 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64 };
// INT NPPM_GETLINENUMBERWIDTHMODE(0, 0) // INT NPPM_GETLINENUMBERWIDTHMODE(0, 0)
// Get line number margin width in dynamic width mode (LINENUMWIDTH_DYNAMIC) or constant width mode (LINENUMWIDTH_CONSTANT) // Get line number margin width in dynamic width mode (LINENUMWIDTH_DYNAMIC) or constant width mode (LINENUMWIDTH_CONSTANT)
#define NPPM_ADDTOOLBARICON_FORDARKMODE (NPPMSG + 101)
// VOID NPPM_ADDTOOLBARICON_FORDARKMODE(UINT funcItem[X]._cmdID, toolbarIconsWithDarkMode iconHandles)
// Use NPPM_ADDTOOLBARICON_FORDARKMODE instead obsolete NPPM_ADDTOOLBARICON which doesn't support the dark mode
// 2 formats / 3 icons are needed: 1 * BMP + 2 * ICO
// All 3 handles below should be set so the icon will be displayed correctly if toolbar icon sets are changed by users, also in dark mode
struct toolbarIconsWithDarkMode {
HBITMAP hToolbarBmp;
HICON hToolbarIcon;
HICON hToolbarIconDarkMode;
};
#define VAR_NOT_RECOGNIZED 0 #define VAR_NOT_RECOGNIZED 0
#define FULL_CURRENT_PATH 1 #define FULL_CURRENT_PATH 1

View File

@ -2155,12 +2155,18 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
return NULL; return NULL;
} }
case NPPM_ADDTOOLBARICON: case NPPM_ADDTOOLBARICON_DEPRECATED:
{ {
_toolBar.registerDynBtn(static_cast<UINT>(wParam), reinterpret_cast<toolbarIcons*>(lParam), _pPublicInterface->getAbsentIcoHandle()); _toolBar.registerDynBtn(static_cast<UINT>(wParam), reinterpret_cast<toolbarIcons*>(lParam), _pPublicInterface->getAbsentIcoHandle());
return TRUE; return TRUE;
} }
case NPPM_ADDTOOLBARICON_FORDARKMODE:
{
_toolBar.registerDynBtnDM(static_cast<UINT>(wParam), reinterpret_cast<toolbarIconsWithDarkMode*>(lParam));
return TRUE;
}
case NPPM_SETMENUITEMCHECK: case NPPM_SETMENUITEMCHECK:
{ {
::CheckMenuItem(_mainMenuHandle, static_cast<UINT>(wParam), MF_BYCOMMAND | (static_cast<BOOL>(lParam) ? MF_CHECKED : MF_UNCHECKED)); ::CheckMenuItem(_mainMenuHandle, static_cast<UINT>(wParam), MF_BYCOMMAND | (static_cast<BOOL>(lParam) ? MF_CHECKED : MF_UNCHECKED));

View File

@ -123,10 +123,10 @@ void ToolBarIcons::reInit(int size)
_iconListVector[HLIST_DISABLE2].addIcon(i._hIcon); _iconListVector[HLIST_DISABLE2].addIcon(i._hIcon);
_iconListVector[HLIST_DEFAULT_DM].addIcon(i._hIcon); _iconListVector[HLIST_DEFAULT_DM].addIcon(i._hIcon_DM ? i._hIcon_DM : i._hIcon);
_iconListVector[HLIST_DISABLE_DM].addIcon(i._hIcon); _iconListVector[HLIST_DISABLE_DM].addIcon(i._hIcon_DM ? i._hIcon_DM : i._hIcon);
_iconListVector[HLIST_DEFAULT_DM2].addIcon(i._hIcon); _iconListVector[HLIST_DEFAULT_DM2].addIcon(i._hIcon_DM ? i._hIcon_DM : i._hIcon);
_iconListVector[HLIST_DISABLE_DM2].addIcon(i._hIcon); _iconListVector[HLIST_DISABLE_DM2].addIcon(i._hIcon_DM ? i._hIcon_DM : i._hIcon);
} }
} }

View File

@ -69,9 +69,10 @@ typedef struct
} ToolBarButtonUnit; } ToolBarButtonUnit;
struct DynamicCmdIcoBmp { struct DynamicCmdIcoBmp {
UINT _message; // identification of icon in tool bar (menu ID) UINT _message = 0; // identification of icon in tool bar (menu ID)
HBITMAP _hBmp; // bitmap for toolbar HBITMAP _hBmp = nullptr; // bitmap for toolbar
HICON _hIcon; // icon for toolbar HICON _hIcon = nullptr; // icon for toolbar
HICON _hIcon_DM = nullptr; // dark mode icon for toolbar
}; };
typedef std::vector<ToolBarButtonUnit> ToolBarIconIDs; typedef std::vector<ToolBarButtonUnit> ToolBarIconIDs;

View File

@ -372,15 +372,30 @@ void ToolBar::reset(bool create)
} }
} }
void ToolBar::registerDynBtn(UINT messageID, toolbarIcons* tIcon, HICON absentIco) void ToolBar::registerDynBtn(UINT messageID, toolbarIcons* iconHandles, HICON absentIco)
{ {
// Note: Register of buttons only possible before init! // Note: Register of buttons only possible before init!
if ((_hSelf == NULL) && (messageID != 0) && (tIcon->hToolbarBmp != NULL)) if ((_hSelf == NULL) && (messageID != 0) && (iconHandles->hToolbarBmp != NULL))
{ {
DynamicCmdIcoBmp dynList; DynamicCmdIcoBmp dynList;
dynList._message = messageID; dynList._message = messageID;
dynList._hBmp = tIcon->hToolbarBmp; dynList._hBmp = iconHandles->hToolbarBmp;
dynList._hIcon = tIcon->hToolbarIcon ? tIcon->hToolbarIcon : absentIco; dynList._hIcon = iconHandles->hToolbarIcon ? iconHandles->hToolbarIcon : absentIco;
_vDynBtnReg.push_back(dynList);
}
}
void ToolBar::registerDynBtnDM(UINT messageID, toolbarIconsWithDarkMode* iconHandles)
{
// Note: Register of buttons only possible before init!
if ((_hSelf == NULL) && (messageID != 0) && (iconHandles->hToolbarBmp != NULL) &&
(iconHandles->hToolbarIcon != NULL) && (iconHandles->hToolbarIconDarkMode != NULL))
{
DynamicCmdIcoBmp dynList;
dynList._message = messageID;
dynList._hBmp = iconHandles->hToolbarBmp;
dynList._hIcon = iconHandles->hToolbarIcon;
dynList._hIcon_DM = iconHandles->hToolbarIconDarkMode;
_vDynBtnReg.push_back(dynList); _vDynBtnReg.push_back(dynList);
} }
} }

View File

@ -94,7 +94,8 @@ public :
return _toolBarIcons.replaceIcon(whichLst, iconIndex, iconLocation); return _toolBarIcons.replaceIcon(whichLst, iconIndex, iconLocation);
}; };
void registerDynBtn(UINT message, toolbarIcons* hBmp, HICON absentIco); void registerDynBtn(UINT message, toolbarIcons* iconHandles, HICON absentIco);
void registerDynBtnDM(UINT message, toolbarIconsWithDarkMode* iconHandles);
void doPopop(POINT chevPoint); //show the popup if buttons are hidden void doPopop(POINT chevPoint); //show the popup if buttons are hidden