Replace treeview bmp with ico

- use recommended subclassing
- fix missing icons in function list when searching

ref #14959

Close #15405
pull/13533/head
ozone10 2024-07-05 13:40:26 +02:00 committed by Don Ho
parent 4cde33048f
commit bdbd65182c
30 changed files with 82 additions and 66 deletions

View File

@ -360,15 +360,15 @@ IDR_FIND_RESULT_ICO2 ICON "icons/light/panels/tabbar/findResul
IDR_FIND_RESULT_ICO_DM ICON "icons/dark/panels/tabbar/findResult.ico"
IDI_PROJECT_WORKSPACE BITMAP "icons/standard/panels/treeview/project_work_space.bmp"
IDI_PROJECT_WORKSPACEDIRTY BITMAP "icons/standard/panels/treeview/project_work_space_dirty.bmp"
IDI_PROJECT_PROJECT BITMAP "icons/standard/panels/treeview/project_root.bmp"
IDI_PROJECT_FOLDEROPEN BITMAP "icons/standard/panels/treeview/project_folder_open.bmp"
IDI_PROJECT_FOLDERCLOSE BITMAP "icons/standard/panels/treeview/project_folder_close.bmp"
IDI_PROJECT_FILE BITMAP "icons/standard/panels/treeview/project_file.bmp"
IDI_PROJECT_FILEINVALID BITMAP "icons/standard/panels/treeview/project_file_invalid.bmp"
IDI_FB_ROOTOPEN BITMAP "icons/standard/panels/treeview/fb_root_open.bmp"
IDI_FB_ROOTCLOSE BITMAP "icons/standard/panels/treeview/fb_root_close.bmp"
IDI_PROJECT_WORKSPACE ICON "icons/standard/panels/treeview/project_work_space.ico"
IDI_PROJECT_WORKSPACEDIRTY ICON "icons/standard/panels/treeview/project_work_space_dirty.ico"
IDI_PROJECT_PROJECT ICON "icons/standard/panels/treeview/project_root.ico"
IDI_PROJECT_FOLDEROPEN ICON "icons/standard/panels/treeview/project_folder_open.ico"
IDI_PROJECT_FOLDERCLOSE ICON "icons/standard/panels/treeview/project_folder_close.ico"
IDI_PROJECT_FILE ICON "icons/standard/panels/treeview/project_file.ico"
IDI_PROJECT_FILEINVALID ICON "icons/standard/panels/treeview/project_file_invalid.ico"
IDI_FB_ROOTOPEN ICON "icons/standard/panels/treeview/fb_root_open.ico"
IDI_FB_ROOTCLOSE ICON "icons/standard/panels/treeview/fb_root_close.ico"
IDI_FB_SELECTCURRENTFILE ICON "icons/standard/panels/toolbar/fb_select_current_file.ico"
IDI_FB_FOLDALL ICON "icons/standard/panels/toolbar/fb_fold_all.ico"
@ -377,9 +377,9 @@ IDI_FB_SELECTCURRENTFILE_DM ICON "icons/dark/panels/toolbar/fb_select
IDI_FB_FOLDALL_DM ICON "icons/dark/panels/toolbar/fb_fold_all.ico"
IDI_FB_EXPANDALL_DM ICON "icons/dark/panels/toolbar/fb_expand_all.ico"
//IDI_FUNCLIST_ROOT BITMAP "icons/standard/panels/treeview/project_file.bmp" // same file as IDI_PROJECT_FILE
IDI_FUNCLIST_NODE BITMAP "icons/standard/panels/treeview/funcList_node.bmp"
IDI_FUNCLIST_LEAF BITMAP "icons/standard/panels/treeview/funcList_leaf.bmp"
//IDI_FUNCLIST_ROOT ICON "icons/standard/panels/treeview/project_file.ico" // same file as IDI_PROJECT_FILE
IDI_FUNCLIST_NODE ICON "icons/standard/panels/treeview/funcList_node.ico"
IDI_FUNCLIST_LEAF ICON "icons/standard/panels/treeview/funcList_leaf.ico"
IDI_FUNCLIST_SORTBUTTON ICON "icons/standard/panels/toolbar/funclstSort.ico"
IDI_FUNCLIST_RELOADBUTTON ICON "icons/standard/panels/toolbar/funclstReload.ico"

View File

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

View File

@ -180,8 +180,9 @@ intptr_t CALLBACK FileBrowser::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
FileBrowser::initPopupMenus();
std::vector<int> imgIds{ IDI_FB_ROOTOPEN, IDI_FB_ROOTCLOSE, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE };
_treeView.init(_hInst, _hSelf, ID_FILEBROWSERTREEVIEW);
_treeView.setImageList(CX_BITMAP, CY_BITMAP, 5, IDI_FB_ROOTOPEN, IDI_FB_ROOTCLOSE, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE);
_treeView.setImageList(imgIds);
_treeView.addCanNotDropInList(INDEX_OPEN_ROOT);
_treeView.addCanNotDropInList(INDEX_CLOSE_ROOT);

View File

@ -710,39 +710,49 @@ void FunctionListPanel::searchFuncAndSwitchView()
_pTreeView->customSorting(_pTreeView->getRoot(), categorySortFunc, 0, true);
}
static WNDPROC oldFunclstToolbarProc = NULL;
static LRESULT CALLBACK funclstToolbarProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
static LRESULT CALLBACK funclstToolbarProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR /*dwRefData*/)
{
switch (message)
{
case WM_NCDESTROY:
{
::RemoveWindowSubclass(hwnd, funclstToolbarProc, uIdSubclass);
break;
}
case WM_CTLCOLOREDIT :
{
return ::SendMessage(::GetParent(hwnd), WM_CTLCOLOREDIT, wParam, lParam);
}
}
return oldFunclstToolbarProc(hwnd, message, wParam, lParam);
return ::DefSubclassProc(hwnd, message, wParam, lParam);
}
static WNDPROC oldFunclstSearchEditProc = NULL;
static LRESULT CALLBACK funclstSearchEditProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
static LRESULT CALLBACK funclstSearchEditProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR /*dwRefData*/)
{
switch (message)
{
case WM_NCDESTROY:
{
::RemoveWindowSubclass(hwnd, funclstSearchEditProc, uIdSubclass);
break;
}
case WM_CHAR:
{
if (wParam == VK_ESCAPE)
{
::SendMessage(hwnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(L""));
return FALSE;
return 0;
}
else if (wParam == VK_TAB)
{
::SendMessage(GetParent(hwnd), WM_COMMAND, VK_TAB, 1);
return FALSE;
return 0;
}
}
}
return oldFunclstSearchEditProc(hwnd, message, wParam, lParam);
return ::DefSubclassProc(hwnd, message, wParam, lParam);
}
bool FunctionListPanel::shouldSort()
@ -842,7 +852,8 @@ intptr_t CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LP
const DWORD tbExStyle = static_cast<DWORD>(::SendMessage(_hToolbarMenu, TB_GETEXTENDEDSTYLE, 0, 0));
::SendMessage(_hToolbarMenu, TB_SETEXTENDEDSTYLE, 0, tbExStyle | TBSTYLE_EX_DOUBLEBUFFER);
oldFunclstToolbarProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hToolbarMenu, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(funclstToolbarProc)));
constexpr UINT_PTR idSubclassFunclstToolbar = 2;
::SetWindowSubclass(_hToolbarMenu, funclstToolbarProc, idSubclassFunclstToolbar, 0);
const int iconSizeDyn = _dpiManager.scale(16);
constexpr int nbIcons = 3;
@ -918,7 +929,8 @@ intptr_t CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LP
2, 2, editWidth, editHeight,
_hToolbarMenu, reinterpret_cast<HMENU>(IDC_SEARCHFIELD_FUNCLIST), _hInst, 0 );
oldFunclstSearchEditProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSearchEdit, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(funclstSearchEditProc)));
constexpr UINT_PTR idSubclassFunclstSearchEdit = 3;
::SetWindowSubclass(_hSearchEdit, funclstSearchEditProc, idSubclassFunclstSearchEdit, 0);
if (_hFontSearchEdit == nullptr)
{
@ -931,10 +943,11 @@ intptr_t CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LP
::SendMessage(_hSearchEdit, WM_SETFONT, reinterpret_cast<WPARAM>(_hFontSearchEdit), MAKELPARAM(TRUE, 0));
}
std::vector<int> imgIds{ IDI_FUNCLIST_ROOT, IDI_FUNCLIST_NODE, IDI_FUNCLIST_LEAF };
_treeView.init(_hInst, _hSelf, IDC_LIST_FUNCLIST);
_treeView.setImageList(CX_BITMAP, CY_BITMAP, 3, IDI_FUNCLIST_ROOT, IDI_FUNCLIST_NODE, IDI_FUNCLIST_LEAF);
_treeView.setImageList(imgIds);
_treeViewSearchResult.init(_hInst, _hSelf, IDC_LIST_FUNCLIST_AUX);
_treeViewSearchResult.setImageList(CX_BITMAP, 3, CY_BITMAP, IDI_FUNCLIST_ROOT, IDI_FUNCLIST_NODE, IDI_FUNCLIST_LEAF);
_treeViewSearchResult.setImageList(imgIds);
_treeView.makeLabelEditable(false);

View File

@ -77,8 +77,9 @@ intptr_t CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM
SendMessage(_hToolbarMenu, TB_AUTOSIZE, 0, 0);
ShowWindow(_hToolbarMenu, SW_SHOW);
std::vector<int> imgIds{ IDI_PROJECT_WORKSPACE, IDI_PROJECT_WORKSPACEDIRTY, IDI_PROJECT_PROJECT, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE, IDI_PROJECT_FILEINVALID };
_treeView.init(_hInst, _hSelf, ID_PROJECTTREEVIEW);
_treeView.setImageList(CX_BITMAP, CY_BITMAP, 7, IDI_PROJECT_WORKSPACE, IDI_PROJECT_WORKSPACEDIRTY, IDI_PROJECT_PROJECT, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE, IDI_PROJECT_FILEINVALID);
_treeView.setImageList(imgIds);
_treeView.addCanNotDropInList(INDEX_LEAF);
_treeView.addCanNotDropInList(INDEX_LEAF_INVALID);

View File

@ -21,7 +21,8 @@
using namespace std;
#define CY_ITEMHEIGHT 18
constexpr int g_treeviewItemPadding = 1;
constexpr int g_treeviewIcoSize = 16;
void TreeView::init(HINSTANCE hInst, HWND parent, int treeViewID)
{
@ -47,11 +48,11 @@ void TreeView::init(HINSTANCE hInst, HWND parent, int treeViewID)
NppDarkMode::setTreeViewStyle(_hSelf);
int itemHeight = NppParameters::getInstance()._dpiManager.scaleY(CY_ITEMHEIGHT);
const int itemHeight = DPIManagerV2::scale(g_treeviewIcoSize + g_treeviewItemPadding * 2, _hParent);
TreeView_SetItemHeight(_hSelf, itemHeight);
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
_defaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(staticProc)));
constexpr UINT_PTR idSubclassTreeview = 1;
::SetWindowSubclass(_hSelf, staticProc, idSubclassTreeview, reinterpret_cast<DWORD_PTR>(this));
}
@ -95,7 +96,23 @@ LRESULT TreeView::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
}
}
}
return ::CallWindowProc(_defaultProc, hwnd, Message, wParam, lParam);
return ::DefSubclassProc(hwnd, Message, wParam, lParam);
}
LRESULT TreeView::staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
switch (Message)
{
case WM_NCDESTROY:
{
::RemoveWindowSubclass(hwnd, staticProc, uIdSubclass);
break;
}
default:
break;
}
return reinterpret_cast<TreeView*>(dwRefData)->runProc(hwnd, Message, wParam, lParam);
}
void TreeView::makeLabelEditable(bool toBeEnabled)
@ -264,43 +281,33 @@ HTREEITEM TreeView::searchSubItemByName(const wchar_t *itemName, HTREEITEM hPare
return nullptr;
}
BOOL TreeView::setImageList(int w, int h, int nbImage, int image_id, ...)
bool TreeView::setImageList(std::vector<int> imageIds, int imgSize)
{
HBITMAP hbmp;
COLORREF maskColour = RGB(192, 192, 192);
const int nbImage = static_cast<int>(imageIds.size());
if (imgSize <= 0)
imgSize = g_treeviewIcoSize;
// Creation of image list
int bmDpiDynW = NppParameters::getInstance()._dpiManager.scaleX(w);
int bmDpiDynH = NppParameters::getInstance()._dpiManager.scaleY(h);
if ((_hImaLst = ImageList_Create(bmDpiDynW, bmDpiDynH, ILC_COLOR32 | ILC_MASK, nbImage, 0)) == NULL)
return FALSE;
int dpiImgSize = DPIManagerV2::scale(imgSize, _hParent);
if ((_hImaLst = ::ImageList_Create(dpiImgSize, dpiImgSize, ILC_COLOR32 | ILC_MASK, nbImage, 0)) == nullptr)
return false;
// Add the bmp in the list
va_list argLst;
va_start(argLst, image_id);
int imageID = image_id;
for (int i = 0; i < nbImage; i++)
// Add the ico into the list
for (const int& id : imageIds)
{
if (i > 0)
imageID = va_arg(argLst, int);
HICON hIcon = nullptr;
DPIManagerV2::loadIcon(_hInst, MAKEINTRESOURCE(id), dpiImgSize, dpiImgSize, &hIcon, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);
if (hIcon == nullptr)
return false;
hbmp = (HBITMAP)::LoadImage(_hInst, MAKEINTRESOURCE(imageID), IMAGE_BITMAP, bmDpiDynW, bmDpiDynH, 0);
if (hbmp == NULL)
{
va_end(argLst);
return FALSE;
::ImageList_AddIcon(_hImaLst, hIcon);
::DestroyIcon(hIcon);
}
ImageList_AddMasked(_hImaLst, hbmp, maskColour);
DeleteObject(hbmp);
}
va_end(argLst);
// Set image list to the tree view
TreeView_SetImageList(_hSelf, _hImaLst, TVSIL_NORMAL);
//TreeView_SetImageList(_treeViewSearchResult.getHSelf(), _hTreeViewImaLst, TVSIL_NORMAL);
return TRUE;
return true;
}
void TreeView::cleanSubEntries(HTREEITEM hTreeItem)

View File

@ -21,9 +21,6 @@
#include "Window.h"
#include "Common.h"
#define CX_BITMAP 16
#define CY_BITMAP 16
struct TreeStateNode {
std::wstring _label;
std::wstring _extraData;
@ -119,16 +116,13 @@ public:
bool searchLeafAndBuildTree(const TreeView & tree2Build, const std::wstring & text2Search, int index2Search);
void sort(HTREEITEM hTreeItem, bool isRecusive);
void customSorting(HTREEITEM hTreeItem, PFNTVCOMPARE sortingCallbackFunc, LPARAM lParam, bool isRecursive);
BOOL setImageList(int w, int h, int nbImage, int image_id, ...);
bool setImageList(std::vector<int> imageIds, int imgSize = 0);
protected:
HIMAGELIST _hImaLst = nullptr;
WNDPROC _defaultProc = nullptr;
LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
return (((TreeView *)(::GetWindowLongPtr(hwnd, GWLP_USERDATA)))->runProc(hwnd, Message, wParam, lParam));
};
static LRESULT CALLBACK staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
void cleanSubEntries(HTREEITEM hTreeItem);
void dupTree(HTREEITEM hTree2Dup, HTREEITEM hParentItem);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 675 B

After

Width:  |  Height:  |  Size: 624 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 822 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB