Refactoring some code of Dark mode

This commit is contained in:
Don HO 2021-05-27 03:56:22 +02:00
parent 9a2dcaa5f8
commit 51207a4fe5
4 changed files with 129 additions and 128 deletions

View File

@ -147,6 +147,8 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64 };
#define NPPM_ADDTOOLBARICON (NPPMSG + 41)
//void NPPM_ADDTOOLBARICON(UINT funcItem[X]._cmdID, toolbarIcons icon)
//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 {
HBITMAP hToolbarBmp;
HICON hToolbarIcon;

View File

@ -44,7 +44,7 @@ StatusBar::~StatusBar()
}
void StatusBar::init(HINSTANCE /*hInst*/, HWND /*hPere*/)
void StatusBar::init(HINSTANCE, HWND)
{
assert(false and "should never be called");
}
@ -79,20 +79,14 @@ struct StatusBarSubclassInfo
constexpr UINT_PTR g_statusBarSubclassID = 42;
LRESULT CALLBACK StatusBarSubclass(
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam,
UINT_PTR uIdSubclass,
DWORD_PTR dwRefData
)
LRESULT CALLBACK StatusBarSubclass(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
UNREFERENCED_PARAMETER(uIdSubclass);
StatusBarSubclassInfo* pStatusBarInfo = reinterpret_cast<StatusBarSubclassInfo*>(dwRefData);
switch (uMsg) {
switch (uMsg)
{
case WM_ERASEBKGND:
{
if (!NppDarkMode::isEnabled())
@ -105,6 +99,7 @@ LRESULT CALLBACK StatusBarSubclass(
FillRect((HDC)wParam, &rc, NppDarkMode::getBackgroundBrush());
return TRUE;
}
case WM_PAINT:
{
if (!NppDarkMode::isEnabled())
@ -205,12 +200,13 @@ LRESULT CALLBACK StatusBarSubclass(
::SelectObject(hdc, holdFont);
EndPaint(hWnd, &ps);
return 0;
return FALSE;
}
case WM_NCDESTROY:
RemoveWindowSubclass(hWnd, StatusBarSubclass, g_statusBarSubclassID);
delete pStatusBarInfo;
break;
case WM_THEMECHANGED:
pStatusBarInfo->closeTheme();
break;
@ -235,7 +231,8 @@ void StatusBar::init(HINSTANCE hInst, HWND hPere, int nbParts)
if (!_hSelf)
throw std::runtime_error("StatusBar::init : CreateWindowEx() function return null");
auto* pStatusBarInfo = new StatusBarSubclassInfo();
StatusBarSubclassInfo* pStatusBarInfo = new StatusBarSubclassInfo();
_pStatusBarInfo = pStatusBarInfo;
SetWindowSubclass(_hSelf, StatusBarSubclass, g_statusBarSubclassID, reinterpret_cast<DWORD_PTR>(pStatusBarInfo));
@ -268,6 +265,7 @@ bool StatusBar::setPartWidth(int whichPart, int width)
void StatusBar::destroy()
{
::DestroyWindow(_hSelf);
delete _pStatusBarInfo;
}

View File

@ -23,6 +23,7 @@
#include "Common.h"
#include <vector>
struct StatusBarSubclassInfo;
class StatusBar final : public Window
@ -51,4 +52,5 @@ private:
std::vector<int> _partWidthArray;
int *_lpParts = nullptr;
generic_string _lastSetText;
StatusBarSubclassInfo* _pStatusBarInfo = nullptr;
};

View File

@ -1112,14 +1112,13 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode)
// 3 status for each inactive tab and selected tab close item :
// normal / hover / pushed
int idCloseImg;
bool isDM = NppDarkMode::isEnabled();
if (_isCloseHover && (_currentHoverTabItem == nTab) && (_whichCloseClickDown == -1)) // hover
idCloseImg = isDM ? IDR_CLOSETAB_HOVER_DM : IDR_CLOSETAB_HOVER;
idCloseImg = isDarkMode ? IDR_CLOSETAB_HOVER_DM : IDR_CLOSETAB_HOVER;
else if (_isCloseHover && (_currentHoverTabItem == nTab) && (_whichCloseClickDown == _currentHoverTabItem)) // pushed
idCloseImg = isDM ? IDR_CLOSETAB_PUSH_DM : IDR_CLOSETAB_PUSH;
idCloseImg = isDarkMode ? IDR_CLOSETAB_PUSH_DM : IDR_CLOSETAB_PUSH;
else
idCloseImg = isSelected ? (isDM ? IDR_CLOSETAB_DM : IDR_CLOSETAB) : (isDM ? IDR_CLOSETAB_INACT_DM : IDR_CLOSETAB_INACT);
idCloseImg = isSelected ? (isDarkMode ? IDR_CLOSETAB_DM : IDR_CLOSETAB) : (isDarkMode ? IDR_CLOSETAB_INACT_DM : IDR_CLOSETAB_INACT);
HDC hdcMemory;
hdcMemory = ::CreateCompatibleDC(hDC);