]> cygwin.com Git - cygwin-apps/setup.git/blobdiff - PickPackageLine.cc
Suppress bogus free-nonheap-object warning in iniparse.cc
[cygwin-apps/setup.git] / PickPackageLine.cc
index 1868b0c09e881c230331ec529c8482484c63b684..ae1e5204eff1d8e83cfbf92c4238e2eb2e4c0e3d 100644 (file)
 #include "PickPackageLine.h"
 #include "PickView.h"
 #include "package_db.h"
-#include "package_version.h"
 
-void
-PickPackageLine::DrawIcon (HDC hdc, int x, int y, HANDLE hIcon)
+const std::wstring
+PickPackageLine::get_text(int col_num) const
 {
-  SelectObject (theView.bitmap_dc, hIcon);
-  BitBlt (hdc, x, y, 11, 11, theView.bitmap_dc, 0, 0, SRCAND);
-}
-
-void
-PickPackageLine::paint (HDC hdc, HRGN unused, int x, int y, int col_num, int show_cat)
-{
-  int rb = y + theView.tm.tmHeight;
-  int by = rb - 11; // top of box images
-  std::string s;
-
-  if (col_num == theView.current_col && pkg.installed)
+  if (col_num == pkgname_col)
     {
-      TextOut (hdc, x + HMARGIN/2, y, pkg.installed.Canonical_version ().c_str(),
-               pkg.installed.Canonical_version ().size());
+      return string_to_wstring(pkg.name);
     }
-  else if (col_num == theView.new_col)
+  else if (col_num == current_col)
     {
-      // TextOut (hdc, x + HMARGIN/2 + NEW_COL_SIZE_SLOP, y, s.c_str(), s.size());
-      // DrawIcon (hdc, x + HMARGIN/2 + ICON_MARGIN/2 + RTARROW_WIDTH, by, theView.bm_spin);
-      TextOut (hdc, x + HMARGIN/2 + ICON_MARGIN/2 + SPIN_WIDTH , y,
-            pkg.action_caption ().c_str(), pkg.action_caption ().size());
-      DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_spin);
+      return string_to_wstring(pkg.installed.Canonical_version());
     }
-  else if (col_num == theView.bintick_col)
+  else if (col_num == new_col)
     {
-      if (/* uninstall or skip */ !pkg.desired ||
-          /* current version */ pkg.desired == pkg.installed ||
-          /* no source */ !pkg.desired.accessible())
-        DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkna);
-      else if (pkg.desired.picked())
-        DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkyes);
-      else
-        DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkno);
+      return pkg.action_caption ();
     }
-  else if (col_num == theView.srctick_col)
+  else if (col_num == srctick_col)
     {
+      const char *srctick = "?";
       if ( /* uninstall */ !pkg.desired ||
-
-#if 0
-          /* note: I'm not sure what the logic here is.  With this following
-             check enabled, clicking on the "source" box for a package that
-             is already installed results it in showing "n/a", instead of a
-             cross-box.  That seems very unintuitive, it should show a cross-
-             box to indicate that the source is going to be downloaded and
-             unpacked.  Disabling this, but leaving the code as reference
-             in case there is some reason I'm missing for having it. --b.d.  */
-          /* source only */ (!pkg.desired.picked()
-                        && pkg.desired.sourcePackage().picked() && pkg.desired == pkg.installed) ||
-#endif
-          /* when no source mirror available */
-          !pkg.desired.sourcePackage().accessible())
-        DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkna);
-      else if (pkg.desired.sourcePackage().picked())
-        DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkyes);
+           /* when no source mirror available */
+           !pkg.desired.sourcePackage().accessible())
+        srctick = "n/a";
+      else if (pkg.srcpicked())
+        srctick = "yes";
       else
-        DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkno);
+        srctick = "no";
+
+      return string_to_wstring(srctick);
     }
-  else if (col_num == theView.cat_col)
+  else if (col_num == cat_col)
     {
-      /* shows "first" category - do we want to show any? */
-      if (pkg.categories.size () && show_cat)
-        {
-          s = pkg.getReadableCategoryList();
-          TextOut (hdc, x + HMARGIN / 2, y, s.c_str(), s.size());
-        }
+      return string_to_wstring(pkg.getReadableCategoryList());
     }
-  else if (col_num == theView.size_col)
+  else if (col_num == size_col)
     {
       int sz = 0;
       packageversion picked;
@@ -102,55 +64,97 @@ PickPackageLine::paint (HDC hdc, HRGN unused, int x, int y, int col_num, int sho
       else if (pkg.installed)
         picked = pkg.installed;
       else
-        picked = pkg.trustp (theView.deftrust);
+        picked = pkg.trustp (false, theView.deftrust);
 
       /* Include the size of the binary package, and if selected, the source
          package as well.  */
       sz += picked.source()->size;
-      if (picked.sourcePackage().picked())
+      if (pkg.srcpicked())
         sz += picked.sourcePackage().source()->size;
 
       /* If size still 0, size must be unknown.  */
-      s = (sz == 0) ? "?" : format_1000s((sz+1023)/1024) + "k";
-      SIZE tw;
-      GetTextExtentPoint32 (hdc, s.c_str(), s.size(), &tw);
-      int cw = theView.headers[col_num].width - HMARGIN - tw.cx;
-      TextOut (hdc, x + cw + HMARGIN / 2, y, s.c_str(), s.size());
+      std::string size = (sz == 0) ? "?" : format_1000s((sz+1023)/1024) + "k";
+
+      return string_to_wstring(size);
     }
-  else if (col_num == theView.pkg_col)
+  else if (col_num == pkg_col)
     {
-      s = pkg.name;
-      if (pkg.SDesc ().size())
-        s += std::string(": ") + std::string(pkg.SDesc());
-      TextOut (hdc, x + HMARGIN / 2, y, s.c_str(), s.size());
+      return string_to_wstring(pkg.SDesc());
     }
+
+  return L"unknown";
+}
+
+const std::string
+PickPackageLine::get_tooltip(int col_num) const
+{
+  if (col_num == pkg_col)
+    {
+      return pkg.LDesc();
+    }
+
+  return "";
 }
 
 int
-PickPackageLine::click (int const myrow, int const ClickedRow, int const x)
+PickPackageLine::do_action(int col_num, int action_id)
 {
-  // assert (myrow == ClickedRow);
-  if (pkg.desired.accessible ()
-      && x >= theView.headers[theView.bintick_col].x - HMARGIN / 2
-      && x <= theView.headers[theView.bintick_col + 1].x - HMARGIN / 2)
-    pkg.desired.pick(!pkg.desired.picked());
-  if (pkg.desired.sourcePackage ().accessible ()
-      && x >= theView.headers[theView.srctick_col].x - HMARGIN / 2
-      && x <= theView.headers[theView.srctick_col + 1].x - HMARGIN / 2)
-    pkg.desired.sourcePackage().pick(!pkg.desired.sourcePackage().picked());
-
-  if (x >= theView.headers[theView.new_col].x - HMARGIN / 2
-      && x <= theView.headers[theView.new_col + 1].x - HMARGIN / 2)
-    pkg.set_action (pkg.trustp(theView.deftrust));
-
-  packagedb().markUnVisited();
-  /* Add any packages that are needed by this package */
-  /* TODO: This hardcoded TRUST_CURR does not seem right. */
-  return pkg.set_requirements (TRUST_CURR);
+  if (col_num == new_col)
+    {
+      pkg.select_action(action_id, theView.deftrust);
+      return 1;
+    }
+
+  if (col_num == srctick_col)
+    {
+      if (pkg.desired.sourcePackage ().accessible ())
+        pkg.srcpick (!pkg.srcpicked ());
+
+      return 1;
+    }
+
+  return 0;
+}
+
+int
+PickPackageLine::do_default_action(int col_num)
+{
+  if (col_num == new_col)
+    {
+      pkg.toggle_action();
+      return 1;
+    }
+  return 0;
+}
+
+ActionList *
+PickPackageLine::get_actions(int col_num) const
+{
+  if (col_num == new_col)
+    {
+      return pkg.list_actions (theView.deftrust);
+    }
+
+  return NULL;
+}
+
+int
+PickPackageLine::get_indent() const
+{
+  return indent;
 }
 
-int PickPackageLine::set_action (packagemeta::_actions action)
+bool
+PickPackageLine::map_key_to_action(WORD vkey, int *col_num, int *action_id) const
 {
-  pkg.set_action (action , pkg.trustp(theView.deftrust));
-  return pkg.set_requirements(theView.deftrust) + 1;
+  switch (vkey)
+    {
+    case VK_SPACE:
+    case VK_APPS:
+      *col_num = new_col;
+      *action_id = -1;
+      return true;
+    }
+
+  return false;
 }
This page took 0.027969 seconds and 5 git commands to generate.