Make icons in Function list/Project panel/Folder as Workspace display correctly under high DPI

And do some refactoring
This commit is contained in:
Don HO 2021-10-24 13:50:03 +02:00
parent abd1ea43c9
commit d192f58b5b
8 changed files with 49 additions and 170 deletions

View File

@ -24,9 +24,6 @@
#include "ReadDirectoryChanges.h"
#include "menuCmdID.h"
#define CX_BITMAP 16
#define CY_BITMAP 16
#define INDEX_OPEN_ROOT 0
#define INDEX_CLOSE_ROOT 1
#define INDEX_OPEN_NODE 2
@ -159,7 +156,7 @@ INT_PTR CALLBACK FileBrowser::run_dlgProc(UINT message, WPARAM wParam, LPARAM lP
FileBrowser::initPopupMenus();
_treeView.init(_hInst, _hSelf, ID_FILEBROWSERTREEVIEW);
setImageList(IDI_FB_ROOTOPEN, IDI_FB_ROOTCLOSE, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE);
_treeView.setImageList(CX_BITMAP, CY_BITMAP, 5, IDI_FB_ROOTOPEN, IDI_FB_ROOTCLOSE, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE);
_treeView.addCanNotDropInList(INDEX_OPEN_ROOT);
_treeView.addCanNotDropInList(INDEX_CLOSE_ROOT);
@ -425,57 +422,6 @@ bool FileBrowser::selectCurrentEditingFile() const
return selectItemFromPath(currentDocPathStr);
}
BOOL FileBrowser::setImageList(int root_clean_id, int root_dirty_id, int open_node_id, int closed_node_id, int leaf_id)
{
HBITMAP hbmp;
COLORREF maskColour = RGB(192, 192, 192);
const int nbBitmaps = 5;
// Creation of image list
if ((_hImaLst = ImageList_Create(CX_BITMAP, CY_BITMAP, ILC_COLOR32 | ILC_MASK, nbBitmaps, 0)) == NULL)
return FALSE;
// Add the bmp in the list
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(root_clean_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hImaLst, hbmp, maskColour);
DeleteObject(hbmp);
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(root_dirty_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hImaLst, hbmp, maskColour);
DeleteObject(hbmp);
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(open_node_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hImaLst, hbmp, maskColour);
DeleteObject(hbmp);
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(closed_node_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hImaLst, hbmp, maskColour);
DeleteObject(hbmp);
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(leaf_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hImaLst, hbmp, maskColour);
DeleteObject(hbmp);
if (ImageList_GetImageCount(_hImaLst) < nbBitmaps)
return FALSE;
// Set image list to the tree view
TreeView_SetImageList(_treeView.getHSelf(), _hImaLst, TVSIL_NORMAL);
return TRUE;
}
void FileBrowser::destroyMenus()
{
::DestroyMenu(_hGlobalMenu);

View File

@ -182,7 +182,6 @@ protected:
void initPopupMenus();
void destroyMenus();
BOOL setImageList(int root_open_id, int root_close_id, int open_node_id, int closed_node_id, int leaf_id);
BrowserNodeType getNodeType(HTREEITEM hItem);
void popupMenuCmd(int cmdID);

View File

@ -23,9 +23,6 @@
using nlohmann::json;
using namespace std;
#define CX_BITMAP 16
#define CY_BITMAP 16
#define INDEX_ROOT 0
#define INDEX_NODE 1
#define INDEX_LEAF 2
@ -636,45 +633,6 @@ void FunctionListPanel::notified(LPNMHDR notification)
}
}
BOOL FunctionListPanel::setTreeViewImageList(int root_id, int node_id, int leaf_id)
{
HBITMAP hbmp;
COLORREF maskColour = RGB(192, 192, 192);
const int nbBitmaps = 3;
// Creation of image list
if ((_hTreeViewImaLst = ImageList_Create(CX_BITMAP, CY_BITMAP, ILC_COLOR32 | ILC_MASK, nbBitmaps, 0)) == NULL)
return FALSE;
// Add the bmp in the list
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(root_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hTreeViewImaLst, hbmp, maskColour);
DeleteObject(hbmp);
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(node_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hTreeViewImaLst, hbmp, maskColour);
DeleteObject(hbmp);
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(leaf_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hTreeViewImaLst, hbmp, maskColour);
DeleteObject(hbmp);
if (ImageList_GetImageCount(_hTreeViewImaLst) < nbBitmaps)
return FALSE;
// Set image list to the tree view
TreeView_SetImageList(_treeView.getHSelf(), _hTreeViewImaLst, TVSIL_NORMAL);
TreeView_SetImageList(_treeViewSearchResult.getHSelf(), _hTreeViewImaLst, TVSIL_NORMAL);
return TRUE;
}
void FunctionListPanel::searchFuncAndSwitchView()
{
TCHAR text2search[MAX_PATH] ;
@ -905,10 +863,13 @@ INT_PTR CALLBACK FunctionListPanel::run_dlgProc(UINT message, WPARAM wParam, LPA
if (hf)
::SendMessage(_hSearchEdit, WM_SETFONT, reinterpret_cast<WPARAM>(hf), MAKELPARAM(TRUE, 0));
_treeViewSearchResult.init(_hInst, _hSelf, IDC_LIST_FUNCLIST_AUX);
_treeView.init(_hInst, _hSelf, IDC_LIST_FUNCLIST);
_treeView.setImageList(CX_BITMAP, CY_BITMAP, 3, IDI_FUNCLIST_ROOT, IDI_FUNCLIST_NODE, IDI_FUNCLIST_LEAF);
_treeViewSearchResult.init(_hInst, _hSelf, IDC_LIST_FUNCLIST_AUX);
_treeViewSearchResult.setImageList(CX_BITMAP, 3, CY_BITMAP, IDI_FUNCLIST_ROOT, IDI_FUNCLIST_NODE, IDI_FUNCLIST_LEAF);
_treeView.makeLabelEditable(false);
setTreeViewImageList(IDI_FUNCLIST_ROOT, IDI_FUNCLIST_NODE, IDI_FUNCLIST_LEAF);
_treeView.display();
return TRUE;

View File

@ -130,7 +130,6 @@ private:
void notified(LPNMHDR notification);
void addInStateArray(TreeStateNode tree2Update, const TCHAR *searchText, bool isSorted);
TreeParams* getFromStateArray(generic_string fullFilePath);
BOOL setTreeViewImageList(int root_id, int node_id, int leaf_id);
bool openSelection(const TreeView &treeView);
bool shouldSort();
void setSort(bool isEnabled);

View File

@ -23,9 +23,6 @@
#include "localization.h"
#include "Parameters.h"
#define CX_BITMAP 16
#define CY_BITMAP 16
#define INDEX_CLEAN_ROOT 0
#define INDEX_DIRTY_ROOT 1
#define INDEX_PROJECT 2
@ -82,8 +79,8 @@ INT_PTR CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
ShowWindow(_hToolbarMenu, SW_SHOW);
_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);
setImageList(IDI_PROJECT_WORKSPACE, IDI_PROJECT_WORKSPACEDIRTY, IDI_PROJECT_PROJECT, IDI_PROJECT_FOLDEROPEN, IDI_PROJECT_FOLDERCLOSE, IDI_PROJECT_FILE, IDI_PROJECT_FILEINVALID);
_treeView.addCanNotDropInList(INDEX_LEAF);
_treeView.addCanNotDropInList(INDEX_LEAF_INVALID);
@ -299,70 +296,6 @@ void ProjectPanel::initMenus()
::InsertMenu(_hFileMenu, 0, MF_BYCOMMAND, IDM_PROJECT_MODIFYFILEPATH, edit_modifyfile.c_str());
}
BOOL ProjectPanel::setImageList(int root_clean_id, int root_dirty_id, int project_id, int open_node_id, int closed_node_id, int leaf_id, int ivalid_leaf_id)
{
HBITMAP hbmp;
COLORREF maskColour = RGB(192, 192, 192);
const int nbBitmaps = 7;
// Creation of image list
if ((_hImaLst = ImageList_Create(CX_BITMAP, CY_BITMAP, ILC_COLOR32 | ILC_MASK, nbBitmaps, 0)) == NULL)
return FALSE;
// Add the bmp in the list
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(root_clean_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hImaLst, hbmp, maskColour);
DeleteObject(hbmp);
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(root_dirty_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hImaLst, hbmp, maskColour);
DeleteObject(hbmp);
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(project_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hImaLst, hbmp, maskColour);
DeleteObject(hbmp);
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(open_node_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hImaLst, hbmp, maskColour);
DeleteObject(hbmp);
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(closed_node_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hImaLst, hbmp, maskColour);
DeleteObject(hbmp);
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(leaf_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hImaLst, hbmp, maskColour);
DeleteObject(hbmp);
hbmp = LoadBitmap(_hInst, MAKEINTRESOURCE(ivalid_leaf_id));
if (hbmp == NULL)
return FALSE;
ImageList_AddMasked(_hImaLst, hbmp, maskColour);
DeleteObject(hbmp);
if (ImageList_GetImageCount(_hImaLst) < nbBitmaps)
return FALSE;
// Set image list to the tree view
TreeView_SetImageList(_treeView.getHSelf(), _hImaLst, TVSIL_NORMAL);
return TRUE;
}
void ProjectPanel::destroyMenus()
{
::DestroyMenu(_hWorkSpaceMenu);

View File

@ -120,7 +120,6 @@ protected:
void initMenus();
void destroyMenus();
BOOL setImageList(int root_clean_id, int root_dirty_id, int project_id, int open_node_id, int closed_node_id, int leaf_id, int ivalid_leaf_id);
void addFiles(HTREEITEM hTreeItem);
void addFilesFromDirectory(HTREEITEM hTreeItem);
void recursiveAddFilesFrom(const TCHAR *folderPath, HTREEITEM hTreeItem);

View File

@ -261,6 +261,42 @@ HTREEITEM TreeView::searchSubItemByName(const TCHAR *itemName, HTREEITEM hParent
return NULL;
}
BOOL TreeView::setImageList(int w, int h, int nbImage, int image_id, ...)
{
HBITMAP hbmp;
COLORREF maskColour = RGB(192, 192, 192);
// 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;
// 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++)
{
if (i > 0)
imageID = va_arg(argLst, int);
hbmp = (HBITMAP)::LoadImage(_hInst, MAKEINTRESOURCE(imageID), IMAGE_BITMAP, bmDpiDynW, bmDpiDynH, 0);
if (hbmp == NULL)
return FALSE;
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;
}
void TreeView::cleanSubEntries(HTREEITEM hTreeItem)
{
for (HTREEITEM hItem = getChildFrom(hTreeItem); hItem != NULL; hItem = getNextSibling(hItem))

View File

@ -21,6 +21,9 @@
#include "Window.h"
#include "Common.h"
#define CX_BITMAP 16
#define CY_BITMAP 16
struct TreeStateNode {
generic_string _label;
generic_string _extraData;
@ -116,14 +119,17 @@ public:
bool searchLeafAndBuildTree(TreeView & tree2Build, const generic_string & 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, ...);
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));
};
void cleanSubEntries(HTREEITEM hTreeItem);
void dupTree(HTREEITEM hTree2Dup, HTREEITEM hParentItem);
bool searchLeafRecusivelyAndBuildTree(HTREEITEM tree2Build, const generic_string & text2Search, int index2Search, HTREEITEM tree2Search);