Refactoring some code of Dark mode
This commit is contained in:
parent
9a2dcaa5f8
commit
51207a4fe5
|
@ -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;
|
||||||
|
|
|
@ -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,141 +79,137 @@ 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:
|
|
||||||
{
|
{
|
||||||
if (!NppDarkMode::isEnabled())
|
case WM_ERASEBKGND:
|
||||||
{
|
{
|
||||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
if (!NppDarkMode::isEnabled())
|
||||||
|
{
|
||||||
|
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
RECT rc;
|
||||||
|
GetClientRect(hWnd, &rc);
|
||||||
|
FillRect((HDC)wParam, &rc, NppDarkMode::getBackgroundBrush());
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
RECT rc;
|
case WM_PAINT:
|
||||||
GetClientRect(hWnd, &rc);
|
|
||||||
FillRect((HDC)wParam, &rc, NppDarkMode::getBackgroundBrush());
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
case WM_PAINT:
|
|
||||||
{
|
|
||||||
if (!NppDarkMode::isEnabled())
|
|
||||||
{
|
{
|
||||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
if (!NppDarkMode::isEnabled())
|
||||||
|
{
|
||||||
|
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct {
|
||||||
|
int horizontal;
|
||||||
|
int vertical;
|
||||||
|
int between;
|
||||||
|
} borders = { 0 };
|
||||||
|
|
||||||
|
SendMessage(hWnd, SB_GETBORDERS, 0, (LPARAM)&borders);
|
||||||
|
|
||||||
|
DWORD style = GetWindowLong(hWnd, GWL_STYLE);
|
||||||
|
bool isSizeGrip = style & SBARS_SIZEGRIP;
|
||||||
|
|
||||||
|
PAINTSTRUCT ps;
|
||||||
|
HDC hdc = BeginPaint(hWnd, &ps);
|
||||||
|
|
||||||
|
HFONT holdFont = (HFONT)::SelectObject(hdc, NppParameters::getInstance().getDefaultUIFont());
|
||||||
|
|
||||||
|
RECT rcClient;
|
||||||
|
GetClientRect(hWnd, &rcClient);
|
||||||
|
|
||||||
|
FillRect(hdc, &ps.rcPaint, NppDarkMode::getBackgroundBrush());
|
||||||
|
|
||||||
|
int nParts = static_cast<int>(SendMessage(hWnd, SB_GETPARTS, 0, 0));
|
||||||
|
std::wstring str;
|
||||||
|
for (int i = 0; i < nParts; ++i)
|
||||||
|
{
|
||||||
|
RECT rcPart = { 0 };
|
||||||
|
SendMessage(hWnd, SB_GETRECT, i, (LPARAM)&rcPart);
|
||||||
|
RECT rcIntersect = { 0 };
|
||||||
|
if (!IntersectRect(&rcIntersect, &rcPart, &ps.rcPaint))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
RECT rcDivider = { rcPart.right - borders.vertical, rcPart.top, rcPart.right, rcPart.bottom };
|
||||||
|
|
||||||
|
DWORD cchText = 0;
|
||||||
|
cchText = LOWORD(SendMessage(hWnd, SB_GETTEXTLENGTH, i, 0));
|
||||||
|
str.resize(cchText + 1);
|
||||||
|
LRESULT lr = SendMessage(hWnd, SB_GETTEXT, i, (LPARAM)str.data());
|
||||||
|
bool ownerDraw = false;
|
||||||
|
if (cchText == 0 && (lr & ~(SBT_NOBORDERS | SBT_POPOUT | SBT_RTLREADING)) != 0)
|
||||||
|
{
|
||||||
|
// this is a pointer to the text
|
||||||
|
ownerDraw = true;
|
||||||
|
}
|
||||||
|
SetBkMode(hdc, TRANSPARENT);
|
||||||
|
SetTextColor(hdc, NppDarkMode::getTextColor());
|
||||||
|
|
||||||
|
rcPart.left += borders.between;
|
||||||
|
rcPart.right -= borders.vertical;
|
||||||
|
|
||||||
|
if (ownerDraw)
|
||||||
|
{
|
||||||
|
UINT id = GetDlgCtrlID(hWnd);
|
||||||
|
DRAWITEMSTRUCT dis = {
|
||||||
|
0
|
||||||
|
, 0
|
||||||
|
, static_cast<UINT>(i)
|
||||||
|
, ODA_DRAWENTIRE
|
||||||
|
, id
|
||||||
|
, hWnd
|
||||||
|
, hdc
|
||||||
|
, rcPart
|
||||||
|
, static_cast<ULONG_PTR>(lr)
|
||||||
|
};
|
||||||
|
|
||||||
|
SendMessage(GetParent(hWnd), WM_DRAWITEM, id, (LPARAM)&dis);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DrawText(hdc, str.data(), static_cast<int>(str.size()), &rcPart, DT_SINGLELINE | DT_VCENTER | DT_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isSizeGrip && i < (nParts - 1))
|
||||||
|
{
|
||||||
|
FillRect(hdc, &rcDivider, NppDarkMode::getSofterBackgroundBrush());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSizeGrip)
|
||||||
|
{
|
||||||
|
pStatusBarInfo->ensureTheme(hWnd);
|
||||||
|
SIZE gripSize = { 0 };
|
||||||
|
GetThemePartSize(pStatusBarInfo->hTheme, hdc, SP_GRIPPER, 0, &rcClient, TS_DRAW, &gripSize);
|
||||||
|
RECT rc = rcClient;
|
||||||
|
rc.left = rc.right - gripSize.cx;
|
||||||
|
rc.top = rc.bottom - gripSize.cy;
|
||||||
|
DrawThemeBackground(pStatusBarInfo->hTheme, hdc, SP_GRIPPER, 0, &rc, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
::SelectObject(hdc, holdFont);
|
||||||
|
|
||||||
|
EndPaint(hWnd, &ps);
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct {
|
case WM_NCDESTROY:
|
||||||
int horizontal;
|
RemoveWindowSubclass(hWnd, StatusBarSubclass, g_statusBarSubclassID);
|
||||||
int vertical;
|
break;
|
||||||
int between;
|
|
||||||
} borders = { 0 };
|
|
||||||
|
|
||||||
SendMessage(hWnd, SB_GETBORDERS, 0, (LPARAM)&borders);
|
case WM_THEMECHANGED:
|
||||||
|
pStatusBarInfo->closeTheme();
|
||||||
DWORD style = GetWindowLong(hWnd, GWL_STYLE);
|
break;
|
||||||
bool isSizeGrip = style & SBARS_SIZEGRIP;
|
|
||||||
|
|
||||||
PAINTSTRUCT ps;
|
|
||||||
HDC hdc = BeginPaint(hWnd, &ps);
|
|
||||||
|
|
||||||
HFONT holdFont = (HFONT)::SelectObject(hdc, NppParameters::getInstance().getDefaultUIFont());
|
|
||||||
|
|
||||||
RECT rcClient;
|
|
||||||
GetClientRect(hWnd, &rcClient);
|
|
||||||
|
|
||||||
FillRect(hdc, &ps.rcPaint, NppDarkMode::getBackgroundBrush());
|
|
||||||
|
|
||||||
int nParts = static_cast<int>(SendMessage(hWnd, SB_GETPARTS, 0, 0));
|
|
||||||
std::wstring str;
|
|
||||||
for (int i = 0; i < nParts; ++i)
|
|
||||||
{
|
|
||||||
RECT rcPart = { 0 };
|
|
||||||
SendMessage(hWnd, SB_GETRECT, i, (LPARAM)&rcPart);
|
|
||||||
RECT rcIntersect = { 0 };
|
|
||||||
if (!IntersectRect(&rcIntersect, &rcPart, &ps.rcPaint))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
RECT rcDivider = { rcPart.right - borders.vertical, rcPart.top, rcPart.right, rcPart.bottom };
|
|
||||||
|
|
||||||
DWORD cchText = 0;
|
|
||||||
cchText = LOWORD(SendMessage(hWnd, SB_GETTEXTLENGTH, i, 0));
|
|
||||||
str.resize(cchText + 1);
|
|
||||||
LRESULT lr = SendMessage(hWnd, SB_GETTEXT, i, (LPARAM)str.data());
|
|
||||||
bool ownerDraw = false;
|
|
||||||
if (cchText == 0 && (lr & ~(SBT_NOBORDERS | SBT_POPOUT | SBT_RTLREADING)) != 0)
|
|
||||||
{
|
|
||||||
// this is a pointer to the text
|
|
||||||
ownerDraw = true;
|
|
||||||
}
|
|
||||||
SetBkMode(hdc, TRANSPARENT);
|
|
||||||
SetTextColor(hdc, NppDarkMode::getTextColor());
|
|
||||||
|
|
||||||
rcPart.left += borders.between;
|
|
||||||
rcPart.right -= borders.vertical;
|
|
||||||
|
|
||||||
if (ownerDraw)
|
|
||||||
{
|
|
||||||
UINT id = GetDlgCtrlID(hWnd);
|
|
||||||
DRAWITEMSTRUCT dis = {
|
|
||||||
0
|
|
||||||
, 0
|
|
||||||
, static_cast<UINT>(i)
|
|
||||||
, ODA_DRAWENTIRE
|
|
||||||
, id
|
|
||||||
, hWnd
|
|
||||||
, hdc
|
|
||||||
, rcPart
|
|
||||||
, static_cast<ULONG_PTR>(lr)
|
|
||||||
};
|
|
||||||
|
|
||||||
SendMessage(GetParent(hWnd), WM_DRAWITEM, id, (LPARAM)&dis);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
DrawText(hdc, str.data(), static_cast<int>(str.size()), &rcPart, DT_SINGLELINE | DT_VCENTER | DT_LEFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isSizeGrip && i < (nParts - 1))
|
|
||||||
{
|
|
||||||
FillRect(hdc, &rcDivider, NppDarkMode::getSofterBackgroundBrush());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSizeGrip)
|
|
||||||
{
|
|
||||||
pStatusBarInfo->ensureTheme(hWnd);
|
|
||||||
SIZE gripSize = { 0 };
|
|
||||||
GetThemePartSize(pStatusBarInfo->hTheme, hdc, SP_GRIPPER, 0, &rcClient, TS_DRAW, &gripSize);
|
|
||||||
RECT rc = rcClient;
|
|
||||||
rc.left = rc.right - gripSize.cx;
|
|
||||||
rc.top = rc.bottom - gripSize.cy;
|
|
||||||
DrawThemeBackground(pStatusBarInfo->hTheme, hdc, SP_GRIPPER, 0, &rc, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
::SelectObject(hdc, holdFont);
|
|
||||||
|
|
||||||
EndPaint(hWnd, &ps);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
case WM_NCDESTROY:
|
|
||||||
RemoveWindowSubclass(hWnd, StatusBarSubclass, g_statusBarSubclassID);
|
|
||||||
delete pStatusBarInfo;
|
|
||||||
break;
|
|
||||||
case WM_THEMECHANGED:
|
|
||||||
pStatusBarInfo->closeTheme();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
return DefSubclassProc(hWnd, uMsg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
};
|
};
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue