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

View File

@ -23,6 +23,7 @@
#include "Common.h" #include "Common.h"
#include <vector> #include <vector>
struct StatusBarSubclassInfo;
class StatusBar final : public Window class StatusBar final : public Window
@ -51,4 +52,5 @@ private:
std::vector<int> _partWidthArray; std::vector<int> _partWidthArray;
int *_lpParts = nullptr; int *_lpParts = nullptr;
generic_string _lastSetText; 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 : // 3 status for each inactive tab and selected tab close item :
// normal / hover / pushed // normal / hover / pushed
int idCloseImg; int idCloseImg;
bool isDM = NppDarkMode::isEnabled();
if (_isCloseHover && (_currentHoverTabItem == nTab) && (_whichCloseClickDown == -1)) // hover 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 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 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; HDC hdcMemory;
hdcMemory = ::CreateCompatibleDC(hDC); hdcMemory = ::CreateCompatibleDC(hDC);