Skip to content

Commit

Permalink
Replace tab bar close button BMP files with ICO
Browse files Browse the repository at this point in the history
  • Loading branch information
ozone10 authored and donho committed Jun 18, 2024
1 parent 57a89b2 commit 8760dd2
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 32 deletions.
16 changes: 8 additions & 8 deletions PowerEditor/src/Notepad_plus.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions PowerEditor/src/NppBigSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
79 changes: 55 additions & 24 deletions PowerEditor/src/WinControls/TabBar/TabBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ void TabBarPlus::destroy()
TabBar::destroy();
::DestroyWindow(_tooltips);
_tooltips = NULL;

if (_hCloseBtnImgLst != nullptr)
{
::ImageList_Destroy(_hCloseBtnImgLst);
_hCloseBtnImgLst = nullptr;
}
}


Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;

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);
int idxCloseImg = isDarkMode ? 4 : 0; // selected

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
Expand Down
3 changes: 3 additions & 0 deletions PowerEditor/src/WinControls/TabBar/TabBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -248,6 +250,7 @@ public :
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
Expand Down
Binary file removed PowerEditor/src/icons/dark/tabbar/closeTabButton.bmp
Binary file not shown.
Binary file added PowerEditor/src/icons/dark/tabbar/closeTabButton.ico
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 8760dd2

Please sign in to comment.