Skip to content

Commit

Permalink
Add new API NPPM_ADDTOOLBARICON_FORDARKMODE for darkmode
Browse files Browse the repository at this point in the history
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
  • Loading branch information
donho committed May 31, 2021
1 parent 219dfda commit 8a898ba
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
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

5 comments on commit 8a898ba

@dinkumoil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@donho

Some questions:

  1. What is the intended size of the icons for dark mode?
  2. The preferences dialog provides the ability to set 5 different types of icons:
    * small standard icons
    * dark mode filled small and large
    * dark mode unfilled small and large
    but the struct toolbarIconsWithDarkMode provides only 3 handles. What is about the remaining 2 icon types?

@donho
Copy link
Member Author

@donho donho commented on 8a898ba Jun 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dinkumoil

What is the intended size of the icons for dark mode?

32x32 + 16x16

The preferences dialog provides the ability to set 5 different types of icons:
but the struct toolbarIconsWithDarkMode provides only 3 handles. What is about the remaining 2 icon types?

So the first answer relies 2 questions :)

@dinkumoil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@donho

That means:

  • 16x16 as BMP for small standard icons
  • 32x32 as ICO for dark mode icons, whereas the small (16x16) dark mode icons are created at runtime by downscaling the 32x32 icons

Is this correct? If yes, IMO the idea of downscaling the large icons to their small versions is not a good idea. It gives mostly poor results.

@donho
Copy link
Member Author

@donho donho commented on 8a898ba Jun 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dinkumoil

  • small standard icons : 16 x 16 BMP
  • dark mode filled small and large : 16 x 16 + 32 x 32 ICO
  • dark mode unfilled small and large : 16 x 16 + 32 x 32 ICO

Notepad++ can reduce/stretch the icon if the size format is missing.

@shriprem
Copy link
Contributor

@shriprem shriprem commented on 8a898ba Jun 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@donho, this API may still need some tweaks. It is only mapping to the unfilled Fluent UI icons, and not for distinctive Filled Fluent UI icons. I have opened issue #10032 on this. Thank you!

Please sign in to comment.