Replace tab bar close button BMP files with ICO

ref #15298

Close #15317
This commit is contained in:
ozone10 2024-06-17 22:33:17 +02:00 committed by Don Ho
parent 57a89b257a
commit 8760dd2c07
20 changed files with 68 additions and 32 deletions

View File

@ -326,14 +326,14 @@ IDR_FUNC_LIST BITMAP "icons/standard/toolbar/funcList.bmp"
IDR_FILEBROWSER BITMAP "icons/standard/toolbar/fileBrowser.bmp"
IDR_FILEMONITORING BITMAP "icons/standard/toolbar/monitoring.bmp"
IDR_CLOSETAB BITMAP "icons/standard/tabbar/closeTabButton.bmp"
IDR_CLOSETAB_INACT BITMAP "icons/standard/tabbar/closeTabButton_inact.bmp"
IDR_CLOSETAB_HOVER BITMAP "icons/standard/tabbar/closeTabButton_hover.bmp"
IDR_CLOSETAB_PUSH BITMAP "icons/standard/tabbar/closeTabButton_push.bmp"
IDR_CLOSETAB_DM BITMAP "icons/dark/tabbar/closeTabButton.bmp"
IDR_CLOSETAB_INACT_DM BITMAP "icons/dark/tabbar/closeTabButton_inact.bmp"
IDR_CLOSETAB_HOVER_DM BITMAP "icons/dark/tabbar/closeTabButton_hover.bmp"
IDR_CLOSETAB_PUSH_DM BITMAP "icons/dark/tabbar/closeTabButton_push.bmp"
IDR_CLOSETAB ICON "icons/standard/tabbar/closeTabButton.ico"
IDR_CLOSETAB_INACT ICON "icons/standard/tabbar/closeTabButton_inact.ico"
IDR_CLOSETAB_HOVER ICON "icons/standard/tabbar/closeTabButton_hover.ico"
IDR_CLOSETAB_PUSH ICON "icons/standard/tabbar/closeTabButton_push.ico"
IDR_CLOSETAB_DM ICON "icons/dark/tabbar/closeTabButton.ico"
IDR_CLOSETAB_INACT_DM ICON "icons/dark/tabbar/closeTabButton_inact.ico"
IDR_CLOSETAB_HOVER_DM ICON "icons/dark/tabbar/closeTabButton_hover.ico"
IDR_CLOSETAB_PUSH_DM ICON "icons/dark/tabbar/closeTabButton_push.ico"
IDR_DOCMAP_ICO ICON "icons/standard/panels/tabbar/docMap.ico"
IDR_DOCMAP_ICO2 ICON "icons/light/panels/tabbar/docMap.ico"

View File

@ -3678,6 +3678,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
_subDocTab.setFont();
_mainDocTab.resizeIconsDpi();
_subDocTab.resizeIconsDpi();
_subDocTab.setCloseBtnImageList();
_subDocTab.setCloseBtnImageList();
::SendMessage(_pPublicInterface->getHSelf(), WM_COMMAND, IDM_VIEW_REDUCETABBAR, 0);
changeDocumentListIconSet(false);

View File

@ -270,6 +270,12 @@ void TabBarPlus::destroy()
TabBar::destroy();
::DestroyWindow(_tooltips);
_tooltips = NULL;
if (_hCloseBtnImgLst != nullptr)
{
::ImageList_Destroy(_hCloseBtnImgLst);
_hCloseBtnImgLst = nullptr;
}
}
@ -339,6 +345,8 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMult
_tabBarDefaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(TabBarPlus_Proc)));
setFont();
setCloseBtnImageList();
}
void TabBar::setFont()
@ -452,6 +460,34 @@ void TabBarPlus::currentTabToEnd()
}
}
void TabBarPlus::setCloseBtnImageList()
{
if (_hCloseBtnImgLst != nullptr)
{
::ImageList_Destroy(_hCloseBtnImgLst);
_hCloseBtnImgLst = nullptr;
}
const int btnSize = _dpiManager.scale(g_TabCloseBtnSize);
const auto idsCloseIcons = {
IDR_CLOSETAB, IDR_CLOSETAB_INACT, IDR_CLOSETAB_HOVER, IDR_CLOSETAB_PUSH,
IDR_CLOSETAB_DM, IDR_CLOSETAB_INACT_DM, IDR_CLOSETAB_HOVER_DM, IDR_CLOSETAB_PUSH_DM };
_hCloseBtnImgLst = ::ImageList_Create(btnSize, btnSize, ILC_COLOR32 | ILC_MASK, static_cast<int>(idsCloseIcons.size()), 0);
for (const auto& id : idsCloseIcons)
{
HICON hIcon = nullptr;
DPIManagerV2::loadIcon(_hInst, MAKEINTRESOURCE(id), btnSize, btnSize, &hIcon);
::ImageList_AddIcon(_hCloseBtnImgLst, hIcon);
::DestroyIcon(hIcon);
}
_closeButtonZone._width = btnSize;
_closeButtonZone._height = btnSize;
}
void TabBarPlus::doVertical()
{
for (int i = 0 ; i < _nbCtrl ; ++i)
@ -1264,36 +1300,31 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode)
}
// draw close button
if (_drawTabCloseButton)
if (_drawTabCloseButton && _hCloseBtnImgLst != nullptr)
{
// 3 status for each inactive tab and selected tab close item :
// normal / hover / pushed
int idCloseImg;
int idxCloseImg = isDarkMode ? 4 : 0; // selected
if (_isCloseHover && (_currentHoverTabItem == nTab) && (_whichCloseClickDown == -1)) // hover
idCloseImg = isDarkMode ? IDR_CLOSETAB_HOVER_DM : IDR_CLOSETAB_HOVER;
else if (_isCloseHover && (_currentHoverTabItem == nTab) && (_whichCloseClickDown == _currentHoverTabItem)) // pushed
idCloseImg = isDarkMode ? IDR_CLOSETAB_PUSH_DM : IDR_CLOSETAB_PUSH;
else
idCloseImg = isSelected ? (isDarkMode ? IDR_CLOSETAB_DM : IDR_CLOSETAB) : (isDarkMode ? IDR_CLOSETAB_INACT_DM : IDR_CLOSETAB_INACT);
HDC hdcMemory = ::CreateCompatibleDC(hDC);
HBITMAP hBmp = ::LoadBitmap(_hInst, MAKEINTRESOURCE(idCloseImg));
BITMAP bmp{};
::GetObject(hBmp, sizeof(bmp), &bmp);
_closeButtonZone._width = _dpiManager.scale(bmp.bmWidth);
_closeButtonZone._height = _dpiManager.scale(bmp.bmHeight);
if (_isCloseHover && (_currentHoverTabItem == nTab))
{
if (_whichCloseClickDown == -1) // hover
{
idxCloseImg += 2;
}
else if (_whichCloseClickDown == _currentHoverTabItem) // pushed
{
idxCloseImg += 3;
}
}
else if (!isSelected) // inactive
{
idxCloseImg += 1;
}
RECT buttonRect = _closeButtonZone.getButtonRectFrom(rect, _isVertical);
// StretchBlt will crop image in RTL if there is no stretching, thus move image by -1
const bool isRTL = (::GetWindowLongPtr(::GetParent(_hSelf), GWL_EXSTYLE) & WS_EX_LAYOUTRTL) == WS_EX_LAYOUTRTL;
const int offset = isRTL && (_closeButtonZone._width == bmp.bmWidth) ? -1 : 0;
::SelectObject(hdcMemory, hBmp);
::StretchBlt(hDC, buttonRect.left + offset, buttonRect.top, _closeButtonZone._width, _closeButtonZone._height, hdcMemory, offset, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
::DeleteDC(hdcMemory);
::DeleteObject(hBmp);
::ImageList_Draw(_hCloseBtnImgLst, idxCloseImg, hDC, buttonRect.left, buttonRect.top, ILD_TRANSPARENT);
}
// draw image

View File

@ -229,6 +229,8 @@ public :
void currentTabToStart();
void currentTabToEnd();
void setCloseBtnImageList();
protected:
// it's the boss to decide if we do the drag N drop
static bool _doDragNDrop;
@ -248,6 +250,7 @@ protected:
int _currentHoverTabItem = -1; // -1 : no mouse on any tab
CloseButtonZone _closeButtonZone;
HIMAGELIST _hCloseBtnImgLst = nullptr;
bool _isCloseHover = false;
int _whichCloseClickDown = -1;
bool _lmbdHit = false; // Left Mouse Button Down Hit

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 246 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 467 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 467 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 456 B