From: Jon Turney Date: Tue, 17 Jul 2018 18:26:23 +0000 (+0100) Subject: Use an icon to represent expanded/collapsed state X-Git-Tag: release_2.894^2~5 X-Git-Url: https://cygwin.com/git/?a=commitdiff_plain;h=db1c5abc5adae534968e941cef6e9286b96756e4;p=cygwin-apps%2Fsetup.git Use an icon to represent expanded/collapsed state Use a listview icon to represent expanded/collapsed state, rather than puttting '[+]'/'[-]' in front of the category name Just use the item icon directly to represent expanded/collapsed state, rather than using a state icon as otherwise we have empty space where the item icon would be, when it's size is being used for indenting. The icons were made by tracing the previously used .bmp in Inkscape to produce a .svg, then converting that to an icon with ImageMagick using 'convert -filter point -background transparent -define icon:auto-resize' v2: Drop execute mode (Achim Gratz) --- diff --git a/ListView.cc b/ListView.cc index a555caaf..0c451d15 100644 --- a/ListView.cc +++ b/ListView.cc @@ -13,6 +13,7 @@ #include "ListView.h" #include "LogSingleton.h" +#include "resource.h" #include @@ -54,6 +55,15 @@ ListView::init(HWND parent, int id, HeaderList headers) // populate with columns initColumns(headers); + + // create a small icon imagelist and assign to listview control + // (the order of images matches ListViewLine::State enum) + HIMAGELIST hImgList = ImageList_Create(GetSystemMetrics(SM_CXSMICON), + GetSystemMetrics(SM_CYSMICON), + ILC_COLOR32, 2, 0); + ImageList_AddIcon(hImgList, LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_TREE_PLUS))); + ImageList_AddIcon(hImgList, LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_TREE_MINUS))); + ListView_SetImageList(hWndListView, hImgList, LVSIL_SMALL); } void @@ -179,10 +189,11 @@ ListView::setContents(ListViewContents *_contents) for (i = 0; i < contents->size(); i++) { LVITEM lvi; - lvi.mask = LVIF_TEXT; + lvi.mask = LVIF_TEXT | LVIF_IMAGE; lvi.iItem = i; lvi.iSubItem = 0; lvi.pszText = LPSTR_TEXTCALLBACK; + lvi.iImage = I_IMAGECALLBACK; ListView_InsertItem(hWndListView, &lvi); } @@ -247,6 +258,11 @@ ListView::OnNotify (NMHDR *pNmHdr, LRESULT *pResult) static StringCache s; s = (*contents)[iRow]->get_text(iCol); pNmLvDispInfo->item.pszText = s; + + if (pNmLvDispInfo->item.iSubItem == 0) + { + pNmLvDispInfo->item.iImage = (int)((*contents)[pNmLvDispInfo->item.iItem]->get_state()); + } } return true; diff --git a/ListView.h b/ListView.h index b14777c3..f5aa1d96 100644 --- a/ListView.h +++ b/ListView.h @@ -27,8 +27,11 @@ class ListViewLine { public: + enum class State { collapsed, expanded, nothing=-1 }; + virtual ~ListViewLine() {}; virtual const std::string get_text(int col) const = 0; + virtual State get_state() const = 0; virtual ActionList *get_actions(int col) const = 0; virtual int do_action(int col, int id) = 0; }; diff --git a/Makefile.am b/Makefile.am index b37ade19..3c413897 100644 --- a/Makefile.am +++ b/Makefile.am @@ -47,7 +47,9 @@ EXTRA_DIST = \ cygwin-setup.ico \ cygwin-terminal.ico \ setup.exe.manifest \ - setup64.exe.manifest + setup64.exe.manifest \ + tree-minus.ico \ + tree-plus.ico # iniparse.hh is generated from iniparse.yy via bison -d, so it needs to be # included here for proper tracking (but not iniparse.cc, since automake diff --git a/PickCategoryLine.cc b/PickCategoryLine.cc index 736e3c62..21795b26 100644 --- a/PickCategoryLine.cc +++ b/PickCategoryLine.cc @@ -26,7 +26,7 @@ PickCategoryLine::get_text (int col_num) const if (col_num == pkgname_col) { std::ostringstream s; - s << (cat_tree->collapsed() ? "[+] " : "[-] ") << cat_tree->category().first; + s << cat_tree->category().first; if (pkgcount) s << " (" << pkgcount << ")"; return s.str(); @@ -70,3 +70,9 @@ PickCategoryLine::get_actions(int col) const return al; } + +ListViewLine::State +PickCategoryLine::get_state() const +{ + return cat_tree->collapsed() ? State::collapsed : State::expanded; +} diff --git a/PickCategoryLine.h b/PickCategoryLine.h index ec160f94..6b54c3f0 100644 --- a/PickCategoryLine.h +++ b/PickCategoryLine.h @@ -34,6 +34,7 @@ public: } const std::string get_text(int col) const; + State get_state() const; ActionList *get_actions(int col) const; int do_action(int col, int action_id); diff --git a/PickPackageLine.h b/PickPackageLine.h index 7d96d448..dacad288 100644 --- a/PickPackageLine.h +++ b/PickPackageLine.h @@ -30,6 +30,7 @@ public: { }; const std::string get_text(int col) const; + State get_state() const { return State::nothing; } ActionList *get_actions(int col_num) const; int do_action(int col, int action_id); private: diff --git a/res.rc b/res.rc index 27f0378e..10f20baf 100644 --- a/res.rc +++ b/res.rc @@ -519,6 +519,8 @@ CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "setup.exe.manifest" IDI_CYGWIN_SETUP ICON DISCARDABLE "cygwin-setup.ico" IDI_CYGWIN ICON DISCARDABLE "cygwin.ico" IDI_CYGWIN_TERMINAL ICON DISCARDABLE "cygwin-terminal.ico" +IDI_TREE_PLUS ICON DISCARDABLE "tree-plus.ico" +IDI_TREE_MINUS ICON DISCARDABLE "tree-minus.ico" ///////////////////////////////////////////////////////////////////////////// // diff --git a/resource.h b/resource.h index 2f1036b3..852bdc0b 100644 --- a/resource.h +++ b/resource.h @@ -76,6 +76,8 @@ #define IDI_CYGWIN_SETUP 401 #define IDI_CYGWIN 402 #define IDI_CYGWIN_TERMINAL 403 +#define IDI_TREE_PLUS 404 +#define IDI_TREE_MINUS 405 // controls diff --git a/tree-minus.ico b/tree-minus.ico new file mode 100644 index 00000000..46fd3b11 Binary files /dev/null and b/tree-minus.ico differ diff --git a/tree-minus.svg b/tree-minus.svg new file mode 100644 index 00000000..124918b9 --- /dev/null +++ b/tree-minus.svg @@ -0,0 +1,118 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + diff --git a/tree-plus.ico b/tree-plus.ico new file mode 100644 index 00000000..8ee3d5fe Binary files /dev/null and b/tree-plus.ico differ diff --git a/tree-plus.svg b/tree-plus.svg new file mode 100644 index 00000000..4d2eb3f1 --- /dev/null +++ b/tree-plus.svg @@ -0,0 +1,126 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + +