[setup - the official Cygwin setup program] branch master, updated. release_2.909-16-g6ddcf16b

Jon TURNEY jturney@sourceware.org
Fri Oct 1 13:14:35 GMT 2021




https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=6ddcf16baab947863d1750d452057fc151e73b7f

commit 6ddcf16baab947863d1750d452057fc151e73b7f
Author: Jon Turney <jon.turney@dronecode.org.uk>
Date:   Mon May 10 16:39:37 2021 +0100

    Move column header strings to string table resource

https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=f7711c51c965bcf685392332d092f474c27cb58f

commit f7711c51c965bcf685392332d092f474c27cb58f
Author: Jon Turney <jon.turney@dronecode.org.uk>
Date:   Mon May 10 15:18:24 2021 +0100

    Move view mode strings to string table resource

https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=35ee780b29a05a8189ef7cba5bac0ff514ad481c

commit 35ee780b29a05a8189ef7cba5bac0ff514ad481c
Author: Jon Turney <jon.turney@dronecode.org.uk>
Date:   Mon May 10 15:36:39 2021 +0100

    Use package action strings from resources for column width
    
    Use the package action strings from string table resource for computing
    the column width.
    
    (This should have been done as part of f34a20e7, but we didn't notice
    the strings were also duplicated here.)
    
    This requires a bit of enhancement to ListView::noteColumnWidth() to
    work for wstrings as well.


Diff:
---
 ListView.cc | 29 +++++++++++++++++++++++++----
 ListView.h  |  5 +++--
 PickView.cc | 29 ++++++++++++++++-------------
 PickView.h  |  2 +-
 choose.cc   | 17 +++++++++--------
 res.rc      | 13 +++++++++++++
 resource.h  | 13 +++++++++++++
 7 files changed, 80 insertions(+), 28 deletions(-)

diff --git a/ListView.cc b/ListView.cc
index 9966fbd9..dc420e2c 100644
--- a/ListView.cc
+++ b/ListView.cc
@@ -108,18 +108,20 @@ ListView::initColumns(HeaderList headers_)
   headers = headers_;
 
   // create the columns
-  LVCOLUMN lvc;
+  LVCOLUMNW lvc;
   lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
 
   int i;
   for (i = 0; headers[i].text != 0; i++)
     {
+      std::wstring h = LoadStringW(headers[i].text);
+
       lvc.iSubItem = i;
-      lvc.pszText = const_cast <char *> (headers[i].text);
+      lvc.pszText = const_cast <wchar_t *> (h.c_str());
       lvc.cx = 100;
       lvc.fmt = headers[i].fmt;
 
-      ListView_InsertColumn(hWndListView, i, &lvc);
+      SendMessage(hWndListView, LVM_INSERTCOLUMNW, i, (LPARAM)&lvc);
     }
 
   // now do some width calculations
@@ -149,8 +151,23 @@ ListView::noteColumnWidthStart()
     }
 }
 
+// wrappers to help instantiations of the noteColumnWidth() template call the
+// right version of GetTextExtentPoint32
+#undef GetTextExtentPoint32
+
+static BOOL GetTextExtentPoint32(HDC hdc, LPCSTR lpString, int c, LPSIZE psizl)
+{
+  return GetTextExtentPoint32A(hdc, lpString, c, psizl);
+}
+
+static BOOL GetTextExtentPoint32(HDC hdc, LPCWSTR lpString, int c, LPSIZE psizl)
+{
+  return GetTextExtentPoint32W(hdc, lpString, c, psizl);
+}
+
+template <typename T>
 void
-ListView::noteColumnWidth(int col_num, const std::string& string)
+ListView::noteColumnWidth(int col_num, const T& string)
 {
   SIZE s = { 0, 0 };
 
@@ -173,6 +190,10 @@ ListView::noteColumnWidth(int col_num, const std::string& string)
     headers[col_num].width = width;
 }
 
+// explicit instantiation
+template void ListView::noteColumnWidth(int col_num, const std::string& string);
+template void ListView::noteColumnWidth(int col_num, const std::wstring& wstring);
+
 void
 ListView::noteColumnWidthEnd()
 {
diff --git a/ListView.h b/ListView.h
index d6a5e32f..8c43fcc7 100644
--- a/ListView.h
+++ b/ListView.h
@@ -56,7 +56,7 @@ class ListView
   class Header
   {
   public:
-    const char *text;
+    unsigned int text; // resource id of header text
     int fmt;
     ControlType type;
     int width;
@@ -67,7 +67,8 @@ class ListView
   void init(HWND parent, int id, HeaderList headers);
 
   void noteColumnWidthStart();
-  void noteColumnWidth(int col_num, const std::string& string);
+  template <typename T>
+  void noteColumnWidth(int col_num, const T& string);
   void noteColumnWidthEnd();
   void resizeColumns(void);
 
diff --git a/PickView.cc b/PickView.cc
index ac07687a..c961b9f2 100644
--- a/PickView.cc
+++ b/PickView.cc
@@ -96,25 +96,25 @@ PickView::getViewMode ()
   return view_mode;
 }
 
-const char *
+unsigned int
 PickView::mode_caption (views mode)
 {
   switch (mode)
     {
     case views::PackageFull:
-      return "Full";
+      return IDS_VIEW_FULL;
     case views::PackagePending:
-      return "Pending";
+      return IDS_VIEW_PENDING;
     case views::PackageKeeps:
-      return "Up To Date";
+      return IDS_VIEW_UPTODATE;
     case views::PackageSkips:
-      return "Not Installed";
+      return IDS_VIEW_NOTINSTALLED;
     case views::PackageUserPicked:
-      return "Picked";
+      return IDS_VIEW_PICKED;
     case views::Category:
-      return "Category";
+      return IDS_VIEW_CATEGORY;
     default:
-      return "";
+      return 0;
     }
 }
 
@@ -238,7 +238,7 @@ PickView::init_headers (void)
 
   // width of the 'src' checkbox column just needs to accommodate the
   // column name
-  listview->noteColumnWidth (srctick_col, "");
+  listview->noteColumnWidth (srctick_col, std::string(""));
 
   // (In category view) accommodate the width of each category name
   packagedb db;
@@ -295,11 +295,14 @@ PickView::init_headers (void)
         }
     }
 
-  // ensure that the new_col is wide enough for all the labels
-  const char *captions[] = { "Uninstall", "Skip", "Reinstall", "Retrieve",
-                             "Source", "Keep", NULL };
+  // also ensure that new_col is wide enough for all the action labels
+  unsigned int captions[] = {
+    IDS_ACTION_UNINSTALL, IDS_ACTION_SKIP, IDS_ACTION_REINSTALL,
+    IDS_ACTION_RETRIEVE, IDS_ACTION_SOURCE, IDS_ACTION_KEEP,
+    IDS_ACTION_UNKNOWN, 0
+  };
   for (int i = 0; captions[i]; i++)
-    listview->noteColumnWidth (new_col, captions[i]);
+    listview->noteColumnWidth (new_col, LoadStringW(captions[i]));
 
   listview->noteColumnWidthEnd();
   listview->resizeColumns();
diff --git a/PickView.h b/PickView.h
index 2db0562c..1e14a74e 100644
--- a/PickView.h
+++ b/PickView.h
@@ -46,7 +46,7 @@ public:
   views getViewMode ();
   void init(views _mode, ListView *_listview, Window *parent);
   void build_category_tree();
-  static const char *mode_caption (views mode);
+  static unsigned int mode_caption (views mode);
   void setObsolete (bool doit);
   void refresh();
   void init_headers ();
diff --git a/choose.cc b/choose.cc
index 51d7197e..44148283 100644
--- a/choose.cc
+++ b/choose.cc
@@ -131,13 +131,13 @@ ChooserPage::~ChooserPage ()
 }
 
 static ListView::Header pkg_headers[] = {
-  {"Package",     LVCFMT_LEFT,  ListView::ControlType::text},
-  {"Current",     LVCFMT_LEFT,  ListView::ControlType::text},
-  {"New",         LVCFMT_LEFT,  ListView::ControlType::popup},
-  {"Src?",        LVCFMT_LEFT,  ListView::ControlType::checkbox},
-  {"Categories",  LVCFMT_LEFT,  ListView::ControlType::text},
-  {"Size",        LVCFMT_RIGHT, ListView::ControlType::text},
-  {"Description", LVCFMT_LEFT,  ListView::ControlType::text},
+  {IDS_COLUMN_PACKAGE,    LVCFMT_LEFT,  ListView::ControlType::text},
+  {IDS_COLUMN_CURRENT,    LVCFMT_LEFT,  ListView::ControlType::text},
+  {IDS_COLUMN_NEW,        LVCFMT_LEFT,  ListView::ControlType::popup},
+  {IDS_COLUMN_SOURCE,     LVCFMT_LEFT,  ListView::ControlType::checkbox},
+  {IDS_COLUMN_CATEGORIES, LVCFMT_LEFT,  ListView::ControlType::text},
+  {IDS_COLUMN_SIZE,       LVCFMT_RIGHT, ListView::ControlType::text},
+  {IDS_COLUMN_DESCR,      LVCFMT_LEFT,  ListView::ControlType::text},
   {0}
 };
 
@@ -262,7 +262,8 @@ ChooserPage::OnInit ()
        view <= (int)PickView::views::Category;
        view++)
     {
-      SendMessage(viewlist, CB_ADDSTRING, 0, (LPARAM)PickView::mode_caption((PickView::views)view));
+      std::wstring mode = LoadStringW(PickView::mode_caption((PickView::views)view));
+      SendMessageW(viewlist, CB_ADDSTRING, 0, (LPARAM)mode.c_str());
     }
 
   if (source == IDC_SOURCE_DOWNLOAD)
diff --git a/res.rc b/res.rc
index 5fc8f243..c3d075ef 100644
--- a/res.rc
+++ b/res.rc
@@ -628,4 +628,17 @@ BEGIN
     IDS_ACTION_RETRIEVE "Retrieve"
     IDS_ACTION_UNKNOWN "Unknown"
     IDS_ACTION_SOURCE "Source"
+    IDS_VIEW_FULL "Full"
+    IDS_VIEW_PENDING "Pending"
+    IDS_VIEW_UPTODATE "Up To Date"
+    IDS_VIEW_NOTINSTALLED "Not Installed"
+    IDS_VIEW_PICKED "Picked"
+    IDS_VIEW_CATEGORY "Category"
+    IDS_COLUMN_PACKAGE "Package"
+    IDS_COLUMN_CURRENT "Current"
+    IDS_COLUMN_NEW "New"
+    IDS_COLUMN_SOURCE "Src?"
+    IDS_COLUMN_CATEGORIES "Categories"
+    IDS_COLUMN_SIZE "Size"
+    IDS_COLUMN_DESCR "Description"
 END
diff --git a/resource.h b/resource.h
index f377e572..463cfafa 100644
--- a/resource.h
+++ b/resource.h
@@ -63,6 +63,19 @@
 #define IDS_ACTION_RETRIEVE               163
 #define IDS_ACTION_UNKNOWN                164
 #define IDS_ACTION_SOURCE                 165
+#define IDS_VIEW_FULL                     166
+#define IDS_VIEW_PENDING                  167
+#define IDS_VIEW_UPTODATE                 168
+#define IDS_VIEW_NOTINSTALLED             169
+#define IDS_VIEW_PICKED                   170
+#define IDS_VIEW_CATEGORY                 171
+#define IDS_COLUMN_PACKAGE                172
+#define IDS_COLUMN_CURRENT                173
+#define IDS_COLUMN_NEW                    174
+#define IDS_COLUMN_SOURCE                 175
+#define IDS_COLUMN_CATEGORIES             176
+#define IDS_COLUMN_SIZE                   177
+#define IDS_COLUMN_DESCR                  178
 
 // Dialogs
 



More information about the Cygwin-apps-cvs mailing list