]> cygwin.com Git - cygwin-apps/setup.git/blame - PickPackageLine.cc
* CHANGES: Update.
[cygwin-apps/setup.git] / PickPackageLine.cc
CommitLineData
97647369
RC
1/*
2 * Copyright (c) 2002 Robert Collins.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by Robert Collins <robertc@hotmail.com>
13 *
14 */
15
16#include "PickPackageLine.h"
17#include "PickView.h"
0d053c58 18#include "package_db.h"
97647369
RC
19#include "package_version.h"
20
21void
82306ac2 22PickPackageLine::paint (HDC hdc, HRGN unused, int x, int y, int col_num, int show_cat)
97647369 23{
82306ac2 24 int rb = y + theView.tm.tmHeight;
f2e49cf8 25 int by = rb - 11; // top of box images
9b0876b3 26 std::string s;
82306ac2
BD
27
28 if (col_num == theView.current_col && pkg.installed)
29 {
30 TextOut (hdc, x + HMARGIN/2, y, pkg.installed.Canonical_version ().c_str(),
31 pkg.installed.Canonical_version ().size());
51fc56a1 32 }
82306ac2 33 else if (col_num == theView.new_col)
97647369 34 {
82306ac2 35 // TextOut (hdc, x + HMARGIN/2 + NEW_COL_SIZE_SLOP, y, s.c_str(), s.size());
3d4c5ebb 36 // theView.DrawIcon (hdc, x + HMARGIN/2 + ICON_MARGIN/2 + RTARROW_WIDTH, by, theView.bm_spin);
51fc56a1 37 TextOut (hdc, x + HMARGIN/2 + ICON_MARGIN/2 + SPIN_WIDTH , y,
82306ac2 38 pkg.action_caption ().c_str(), pkg.action_caption ().size());
3d4c5ebb 39 theView.DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_spin);
97647369 40 }
82306ac2 41 else if (col_num == theView.bintick_col)
97647369 42 {
82306ac2
BD
43 if (/* uninstall or skip */ !pkg.desired ||
44 /* current version */ pkg.desired == pkg.installed ||
45 /* no source */ !pkg.desired.accessible())
3d4c5ebb 46 theView.DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkna);
82306ac2 47 else if (pkg.desired.picked())
3d4c5ebb 48 theView.DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkyes);
82306ac2 49 else
3d4c5ebb 50 theView.DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkno);
97647369 51 }
82306ac2
BD
52 else if (col_num == theView.srctick_col)
53 {
54 if ( /* uninstall */ !pkg.desired ||
97647369 55
82306ac2
BD
56#if 0
57 /* note: I'm not sure what the logic here is. With this following
58 check enabled, clicking on the "source" box for a package that
59 is already installed results it in showing "n/a", instead of a
60 cross-box. That seems very unintuitive, it should show a cross-
61 box to indicate that the source is going to be downloaded and
62 unpacked. Disabling this, but leaving the code as reference
63 in case there is some reason I'm missing for having it. --b.d. */
64 /* source only */ (!pkg.desired.picked()
65 && pkg.desired.sourcePackage().picked() && pkg.desired == pkg.installed) ||
66#endif
67 /* when no source mirror available */
68 !pkg.desired.sourcePackage().accessible())
3d4c5ebb 69 theView.DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkna);
82306ac2 70 else if (pkg.desired.sourcePackage().picked())
3d4c5ebb 71 theView.DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkyes);
82306ac2 72 else
3d4c5ebb 73 theView.DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkno);
82306ac2
BD
74 }
75 else if (col_num == theView.cat_col)
97647369 76 {
82306ac2
BD
77 /* shows "first" category - do we want to show any? */
78 if (pkg.categories.size () && show_cat)
79 {
80 s = pkg.getReadableCategoryList();
81 TextOut (hdc, x + HMARGIN / 2, y, s.c_str(), s.size());
82 }
97647369 83 }
0ac305ec
BD
84 else if (col_num == theView.size_col)
85 {
86 int sz = 0;
87 packageversion picked;
88
89 /* Find the size of the package. If user has chosen to upgrade/downgrade
90 the package, use that version. Otherwise use the currently installed
91 version, or if not installed then use the version that would be chosen
92 based on the current trust level (curr/prev/test). */
93 if (pkg.desired)
94 picked = pkg.desired;
95 else if (pkg.installed)
96 picked = pkg.installed;
97 else
98 picked = pkg.trustp (theView.deftrust);
99
100 /* Include the size of the binary package, and if selected, the source
101 package as well. */
102 sz += picked.source()->size;
103 if (picked.sourcePackage().picked())
104 sz += picked.sourcePackage().source()->size;
105
106 /* If size still 0, size must be unknown. */
107 s = (sz == 0) ? "?" : format_1000s((sz+1023)/1024) + "k";
108 SIZE tw;
109 GetTextExtentPoint32 (hdc, s.c_str(), s.size(), &tw);
110 int cw = theView.headers[col_num].width - HMARGIN - tw.cx;
111 TextOut (hdc, x + cw + HMARGIN / 2, y, s.c_str(), s.size());
112 }
82306ac2 113 else if (col_num == theView.pkg_col)
97647369 114 {
82306ac2
BD
115 s = pkg.name;
116 if (pkg.SDesc ().size())
9b0876b3 117 s += std::string(": ") + std::string(pkg.SDesc());
82306ac2 118 TextOut (hdc, x + HMARGIN / 2, y, s.c_str(), s.size());
97647369 119 }
97647369
RC
120}
121
122int
123PickPackageLine::click (int const myrow, int const ClickedRow, int const x)
124{
125 // assert (myrow == ClickedRow);
3f34f364 126 if (pkg.desired.accessible ()
2fa7c5a4
RC
127 && x >= theView.headers[theView.bintick_col].x - HMARGIN / 2
128 && x <= theView.headers[theView.bintick_col + 1].x - HMARGIN / 2)
3c196821 129 pkg.desired.pick(!pkg.desired.picked());
3f34f364 130 if (pkg.desired.sourcePackage ().accessible ()
2fa7c5a4
RC
131 && x >= theView.headers[theView.srctick_col].x - HMARGIN / 2
132 && x <= theView.headers[theView.srctick_col + 1].x - HMARGIN / 2)
3c196821 133 pkg.desired.sourcePackage().pick(!pkg.desired.sourcePackage().picked());
97647369
RC
134
135 if (x >= theView.headers[theView.new_col].x - HMARGIN / 2
136 && x <= theView.headers[theView.new_col + 1].x - HMARGIN / 2)
4f591f9d 137 pkg.set_action (pkg.trustp(theView.deftrust));
51fc56a1 138
0d053c58 139 packagedb().markUnVisited();
4f591f9d 140 /* Add any packages that are needed by this package */
98b84622
MB
141 /* TODO: This hardcoded TRUST_CURR does not seem right. */
142 return pkg.set_requirements (TRUST_CURR);
97647369 143}
7e8fc33c
RC
144
145int PickPackageLine::set_action (packagemeta::_actions action)
146{
147 pkg.set_action (action , pkg.trustp(theView.deftrust));
148 return pkg.set_requirements(theView.deftrust) + 1;
149}
This page took 0.0514 seconds and 5 git commands to generate.