]> cygwin.com Git - cygwin-apps/setup.git/blob - PickPackageLine.cc
* PickPackageLine.cc (PickPackageLine::{click,set_action}):
[cygwin-apps/setup.git] / PickPackageLine.cc
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"
18 #include "package_db.h"
19 #include "package_version.h"
20
21 void
22 PickPackageLine::paint (HDC hdc, HRGN unused, int x, int y, int col_num, int show_cat)
23 {
24 int rb = y + theView.tm.tmHeight;
25 int by = rb - 11; // top of box images
26 std::string s;
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());
32 }
33 else if (col_num == theView.new_col)
34 {
35 // TextOut (hdc, x + HMARGIN/2 + NEW_COL_SIZE_SLOP, y, s.c_str(), s.size());
36 // theView.DrawIcon (hdc, x + HMARGIN/2 + ICON_MARGIN/2 + RTARROW_WIDTH, by, theView.bm_spin);
37 TextOut (hdc, x + HMARGIN/2 + ICON_MARGIN/2 + SPIN_WIDTH , y,
38 pkg.action_caption ().c_str(), pkg.action_caption ().size());
39 theView.DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_spin);
40 }
41 else if (col_num == theView.bintick_col)
42 {
43 if (/* uninstall or skip */ !pkg.desired ||
44 /* current version */ pkg.desired == pkg.installed ||
45 /* no source */ !pkg.desired.accessible())
46 theView.DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkna);
47 else if (pkg.desired.picked())
48 theView.DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkyes);
49 else
50 theView.DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkno);
51 }
52 else if (col_num == theView.srctick_col)
53 {
54 if ( /* uninstall */ !pkg.desired ||
55
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())
69 theView.DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkna);
70 else if (pkg.desired.sourcePackage().picked())
71 theView.DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkyes);
72 else
73 theView.DrawIcon (hdc, x + HMARGIN/2, by, theView.bm_checkno);
74 }
75 else if (col_num == theView.cat_col)
76 {
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 }
83 }
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 }
113 else if (col_num == theView.pkg_col)
114 {
115 s = pkg.name;
116 if (pkg.SDesc ().size())
117 s += std::string(": ") + std::string(pkg.SDesc());
118 TextOut (hdc, x + HMARGIN / 2, y, s.c_str(), s.size());
119 }
120 }
121
122 int
123 PickPackageLine::click (int const myrow, int const ClickedRow, int const x)
124 {
125 // assert (myrow == ClickedRow);
126 if (pkg.desired.accessible ()
127 && x >= theView.headers[theView.bintick_col].x - HMARGIN / 2
128 && x <= theView.headers[theView.bintick_col + 1].x - HMARGIN / 2)
129 pkg.desired.pick(!pkg.desired.picked(), &pkg);
130 if (pkg.desired.sourcePackage ().accessible ()
131 && x >= theView.headers[theView.srctick_col].x - HMARGIN / 2
132 && x <= theView.headers[theView.srctick_col + 1].x - HMARGIN / 2)
133 pkg.desired.sourcePackage().pick(!pkg.desired.sourcePackage().picked(), NULL);
134
135 if (x >= theView.headers[theView.new_col].x - HMARGIN / 2
136 && x <= theView.headers[theView.new_col + 1].x - HMARGIN / 2)
137 pkg.set_action (pkg.trustp(theView.deftrust));
138
139 return 0;
140 }
141
142 int PickPackageLine::set_action (packagemeta::_actions action)
143 {
144 pkg.set_action (action, pkg.trustp(theView.deftrust));
145 return 1;
146 }
This page took 0.04669 seconds and 6 git commands to generate.