Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new API NPPM_ADDTOOLBARICON_FORDARKMODE for dark mode #9928

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64 };
#define NPPM_SETMENUITEMCHECK (NPPMSG + 40)
//void WM_PIMENU_CHECK(UINT funcItem[X]._cmdID, TRUE/FALSE)

#define NPPM_ADDTOOLBARICON (NPPMSG + 41)
//void NPPM_ADDTOOLBARICON(UINT funcItem[X]._cmdID, toolbarIcons icon)
#define NPPM_ADDTOOLBARICON_DEPRECATED (NPPMSG + 41)
//void NPPM_ADDTOOLBARICON(UINT funcItem[X]._cmdID, toolbarIcons iconHandles) -- DEPRECATED : use NPPM_ADDTOOLBARICON_FORDARKMODE instead
//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
struct toolbarIcons {
Expand Down Expand Up @@ -244,7 +244,6 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64 };
// wParam: Buffer to reload
// lParam: 0 if no alert, else alert


#define NPPM_GETBUFFERLANGTYPE (NPPMSG + 64)
// INT NPPM_GETBUFFERLANGTYPE(UINT_PTR bufferID, 0)
// wParam: BufferID to get LangType from
Expand Down Expand Up @@ -439,6 +438,16 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64 };
// INT NPPM_GETLINENUMBERWIDTHMODE(0, 0)
// 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 FULL_CURRENT_PATH 1
Expand Down
8 changes: 7 additions & 1 deletion PowerEditor/src/NppBigSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2155,12 +2155,18 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
return NULL;
}

case NPPM_ADDTOOLBARICON:
case NPPM_ADDTOOLBARICON_DEPRECATED:
{
_toolBar.registerDynBtn(static_cast<UINT>(wParam), reinterpret_cast<toolbarIcons*>(lParam), _pPublicInterface->getAbsentIcoHandle());
return TRUE;
}

case NPPM_ADDTOOLBARICON_FORDARKMODE:
{
_toolBar.registerDynBtnDM(static_cast<UINT>(wParam), reinterpret_cast<toolbarIconsWithDarkMode*>(lParam));
return TRUE;
}

case NPPM_SETMENUITEMCHECK:
{
::CheckMenuItem(_mainMenuHandle, static_cast<UINT>(wParam), MF_BYCOMMAND | (static_cast<BOOL>(lParam) ? MF_CHECKED : MF_UNCHECKED));
Expand Down
8 changes: 4 additions & 4 deletions PowerEditor/src/WinControls/ImageListSet/ImageListSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ void ToolBarIcons::reInit(int size)
_iconListVector[HLIST_DISABLE2].addIcon(i._hIcon);


_iconListVector[HLIST_DEFAULT_DM].addIcon(i._hIcon);
_iconListVector[HLIST_DISABLE_DM].addIcon(i._hIcon);
_iconListVector[HLIST_DEFAULT_DM2].addIcon(i._hIcon);
_iconListVector[HLIST_DISABLE_DM2].addIcon(i._hIcon);
_iconListVector[HLIST_DEFAULT_DM].addIcon(i._hIcon_DM ? i._hIcon_DM : i._hIcon);
_iconListVector[HLIST_DISABLE_DM].addIcon(i._hIcon_DM ? i._hIcon_DM : i._hIcon);
_iconListVector[HLIST_DEFAULT_DM2].addIcon(i._hIcon_DM ? i._hIcon_DM : i._hIcon);
_iconListVector[HLIST_DISABLE_DM2].addIcon(i._hIcon_DM ? i._hIcon_DM : i._hIcon);
}
}

Expand Down
7 changes: 4 additions & 3 deletions PowerEditor/src/WinControls/ImageListSet/ImageListSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ typedef struct
} ToolBarButtonUnit;

struct DynamicCmdIcoBmp {
UINT _message; // identification of icon in tool bar (menu ID)
HBITMAP _hBmp; // bitmap for toolbar
HICON _hIcon; // icon for toolbar
UINT _message = 0; // identification of icon in tool bar (menu ID)
HBITMAP _hBmp = nullptr; // bitmap for toolbar
HICON _hIcon = nullptr; // icon for toolbar
HICON _hIcon_DM = nullptr; // dark mode icon for toolbar
};

typedef std::vector<ToolBarButtonUnit> ToolBarIconIDs;
Expand Down
23 changes: 19 additions & 4 deletions PowerEditor/src/WinControls/ToolBar/ToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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!
if ((_hSelf == NULL) && (messageID != 0) && (tIcon->hToolbarBmp != NULL))
if ((_hSelf == NULL) && (messageID != 0) && (iconHandles->hToolbarBmp != NULL))
{
DynamicCmdIcoBmp dynList;
dynList._message = messageID;
dynList._hBmp = tIcon->hToolbarBmp;
dynList._hIcon = tIcon->hToolbarIcon ? tIcon->hToolbarIcon : absentIco;
dynList._hBmp = iconHandles->hToolbarBmp;
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);
}
}
Expand Down
3 changes: 2 additions & 1 deletion PowerEditor/src/WinControls/ToolBar/ToolBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public :
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

Expand Down