]> cygwin.com Git - cygwin-apps/setup.git/commitdiff
Use an icon to represent expanded/collapsed state
authorJon Turney <jon.turney@dronecode.org.uk>
Tue, 17 Jul 2018 18:26:23 +0000 (19:26 +0100)
committerJon Turney <jon.turney@dronecode.org.uk>
Sat, 13 Oct 2018 17:03:35 +0000 (18:03 +0100)
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)

12 files changed:
ListView.cc
ListView.h
Makefile.am
PickCategoryLine.cc
PickCategoryLine.h
PickPackageLine.h
res.rc
resource.h
tree-minus.ico [new file with mode: 0644]
tree-minus.svg [new file with mode: 0644]
tree-plus.ico [new file with mode: 0644]
tree-plus.svg [new file with mode: 0644]

index a555caafa70fba16bebbce706a22707c84309c5d..0c451d15334f766362202addb1a45545ffc1f12d 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "ListView.h"
 #include "LogSingleton.h"
+#include "resource.h"
 
 #include <commctrl.h>
 
@@ -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;
index b14777c3acceb78e5e6c659b5ffa06278e3c84eb..f5aa1d96d3c497b003c094be710098d32f507a32 100644 (file)
 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;
 };
index b37ade195ce8557d91ebeeeeabbccde5b3001725..3c413897b1f4553c149657ed157657eac8185e8b 100644 (file)
@@ -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
index 736e3c620b64dfffece0d4ee04d012006ddccca3..21795b26cb0334037ce24699f9b79b809af6d297 100644 (file)
@@ -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;
+}
index ec160f94e3392be36ca980a8e985d6e1c759fe54..6b54c3f0e453355ca65b4a9d2023a2fc8efb965d 100644 (file)
@@ -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);
 
index 7d96d448f03a78f83073d4d4a81f471e86abf70a..dacad288aaadd990fe7cf910ae0f0d3b4201c7d3 100644 (file)
@@ -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 27f0378ead3034e968f7a32b83cff83f4d0a4d8f..10f20bafa62a744a26418b56a9d9212d87dbde34 100644 (file)
--- 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"
 
 /////////////////////////////////////////////////////////////////////////////
 //
index 2f1036b371edc5641f2590f38caf11516555aff3..852bdc0befdb7c9d04621c368c35140e64cfdc78 100644 (file)
@@ -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 (file)
index 0000000..46fd3b1
Binary files /dev/null and b/tree-minus.ico differ
diff --git a/tree-minus.svg b/tree-minus.svg
new file mode 100644 (file)
index 0000000..124918b
--- /dev/null
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="256px"
+   height="256px"
+   viewBox="0 0 256 256"
+   version="1.1"
+   id="SVGRoot"
+   inkscape:version="0.92.3 (2405546, 2018-03-11)"
+   sodipodi:docname="tree-minus.svg">
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="2.3754368"
+     inkscape:cx="135.00514"
+     inkscape:cy="129.49343"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="true"
+     inkscape:window-width="1680"
+     inkscape:window-height="1027"
+     inkscape:window-x="1912"
+     inkscape:window-y="22"
+     inkscape:window-maximized="1"
+     inkscape:grid-bbox="true"
+     showguides="false"
+     inkscape:object-nodes="true">
+    <inkscape:grid
+       type="xygrid"
+       id="grid4075" />
+  </sodipodi:namedview>
+  <defs
+     id="defs3756" />
+  <metadata
+     id="metadata3759">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     id="layer1"
+     inkscape:groupmode="layer"
+     inkscape:label="layer">
+    <g
+       id="box"
+       inkscape:label="box"
+       style="fill:#000000;fill-opacity:1"
+       transform="translate(8,8)">
+      <rect
+         y="56"
+         x="56"
+         height="16"
+         width="144"
+         id="top"
+         style="fill:#000000;fill-opacity:1"
+         inkscape:label="top" />
+      <rect
+         y="184"
+         x="56"
+         height="16"
+         width="144"
+         id="bottom"
+         style="fill:#000000;fill-opacity:1"
+         inkscape:label="bottom" />
+      <rect
+         transform="rotate(90)"
+         y="-72"
+         x="56"
+         height="16"
+         width="144"
+         id="left"
+         style="fill:#000000;fill-opacity:1"
+         inkscape:label="left" />
+      <rect
+         transform="rotate(90)"
+         y="-200"
+         x="56"
+         height="16"
+         width="144"
+         id="right"
+         style="fill:#000000;fill-opacity:1"
+         inkscape:label="right" />
+    </g>
+    <g
+       id="symbol"
+       inkscape:label="symbol"
+       style="fill:#000000;fill-opacity:1"
+       transform="translate(8,8)">
+      <rect
+         transform="rotate(90)"
+         y="-168"
+         x="120"
+         height="80"
+         width="16"
+         id="horiz"
+         style="fill:#000000;fill-opacity:1"
+         inkscape:label="horiz" />
+    </g>
+  </g>
+</svg>
diff --git a/tree-plus.ico b/tree-plus.ico
new file mode 100644 (file)
index 0000000..8ee3d5f
Binary files /dev/null and b/tree-plus.ico differ
diff --git a/tree-plus.svg b/tree-plus.svg
new file mode 100644 (file)
index 0000000..4d2eb3f
--- /dev/null
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="256px"
+   height="256px"
+   viewBox="0 0 256 256"
+   version="1.1"
+   id="SVGRoot"
+   inkscape:version="0.92.3 (2405546, 2018-03-11)"
+   sodipodi:docname="tree-plus.svg">
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="3.359375"
+     inkscape:cx="84.390698"
+     inkscape:cy="128"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="true"
+     inkscape:window-width="1680"
+     inkscape:window-height="1027"
+     inkscape:window-x="1912"
+     inkscape:window-y="22"
+     inkscape:window-maximized="1"
+     inkscape:grid-bbox="true"
+     showguides="false"
+     inkscape:object-nodes="true">
+    <inkscape:grid
+       type="xygrid"
+       id="grid4075" />
+  </sodipodi:namedview>
+  <defs
+     id="defs3756" />
+  <metadata
+     id="metadata3759">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     id="layer1"
+     inkscape:groupmode="layer"
+     inkscape:label="layer">
+    <g
+       id="box"
+       inkscape:label="box"
+       style="fill:#000000;fill-opacity:1"
+       transform="translate(8,8)">
+      <rect
+         y="56"
+         x="56"
+         height="16"
+         width="144"
+         id="top"
+         style="fill:#000000;fill-opacity:1"
+         inkscape:label="top" />
+      <rect
+         y="184"
+         x="56"
+         height="16"
+         width="144"
+         id="bottom"
+         style="fill:#000000;fill-opacity:1"
+         inkscape:label="bottom" />
+      <rect
+         transform="rotate(90)"
+         y="-72"
+         x="56"
+         height="16"
+         width="144"
+         id="left"
+         style="fill:#000000;fill-opacity:1"
+         inkscape:label="left" />
+      <rect
+         transform="rotate(90)"
+         y="-200"
+         x="56"
+         height="16"
+         width="144"
+         id="right"
+         style="fill:#000000;fill-opacity:1"
+         inkscape:label="right" />
+    </g>
+    <g
+       id="symbol"
+       inkscape:label="symbol"
+       style="fill:#000000;fill-opacity:1"
+       transform="translate(8,8)">
+      <rect
+         y="88"
+         x="120"
+         height="80"
+         width="16"
+         id="vert"
+         style="fill:#000000;fill-opacity:1"
+         inkscape:label="vert" />
+      <rect
+         transform="rotate(90)"
+         y="-168"
+         x="120"
+         height="80"
+         width="16"
+         id="horiz"
+         style="fill:#000000;fill-opacity:1"
+         inkscape:label="horiz" />
+    </g>
+  </g>
+</svg>
This page took 0.045462 seconds and 5 git commands to generate.