2 * Copyright (c) 2002 Robert Collins.
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.
9 * A copy of the GNU General Public License can be found at
12 * Written by Robert Collins <robertc@hotmail.com>
16 #include "PickPackageLine.h"
18 #include "package_db.h"
19 #include "package_version.h"
22 PickPackageLine::paint (HDC hdc
, HRGN unused
, int x
, int y
, int col_num
, int show_cat
)
24 int rb
= y
+ theView
.tm
.tmHeight
;
25 int by
= rb
- 11; // top of box images
28 if (col_num
== theView
.current_col
&& pkg
.installed
)
30 TextOut (hdc
, x
+ HMARGIN
/2, y
, pkg
.installed
.Canonical_version ().c_str(),
31 pkg
.installed
.Canonical_version ().size());
33 else if (col_num
== theView
.new_col
)
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
);
41 else if (col_num
== theView
.bintick_col
)
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
);
50 theView
.DrawIcon (hdc
, x
+ HMARGIN
/2, by
, theView
.bm_checkno
);
52 else if (col_num
== theView
.srctick_col
)
54 if ( /* uninstall */ !pkg
.desired
||
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
) ||
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
);
73 theView
.DrawIcon (hdc
, x
+ HMARGIN
/2, by
, theView
.bm_checkno
);
75 else if (col_num
== theView
.cat_col
)
77 /* shows "first" category - do we want to show any? */
78 if (pkg
.categories
.size () && show_cat
)
80 s
= pkg
.getReadableCategoryList();
81 TextOut (hdc
, x
+ HMARGIN
/ 2, y
, s
.c_str(), s
.size());
84 else if (col_num
== theView
.size_col
)
87 packageversion picked
;
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). */
95 else if (pkg
.installed
)
96 picked
= pkg
.installed
;
98 picked
= pkg
.trustp (false, theView
.deftrust
);
100 /* Include the size of the binary package, and if selected, the source
102 sz
+= picked
.source()->size
;
103 if (picked
.sourcePackage().picked())
104 sz
+= picked
.sourcePackage().source()->size
;
106 /* If size still 0, size must be unknown. */
107 s
= (sz
== 0) ? "?" : format_1000s((sz
+1023)/1024) + "k";
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());
113 else if (col_num
== theView
.pkg_col
)
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());
123 PickPackageLine::click (int const myrow
, int const ClickedRow
, int const x
)
125 // assert (myrow == ClickedRow);
126 if (x
>= theView
.headers
[theView
.new_col
].x
- HMARGIN
/ 2
127 && x
<= theView
.headers
[theView
.new_col
+ 1].x
- HMARGIN
/ 2)
132 if (x
>= theView
.headers
[theView
.bintick_col
].x
- HMARGIN
/ 2
133 && x
<= theView
.headers
[theView
.bintick_col
+ 1].x
- HMARGIN
/ 2)
135 if (pkg
.desired
.accessible ())
136 pkg
.desired
.pick (!pkg
.desired
.picked (), &pkg
);
138 else if (x
>= theView
.headers
[theView
.srctick_col
].x
- HMARGIN
/ 2
139 && x
<= theView
.headers
[theView
.srctick_col
+ 1].x
- HMARGIN
/ 2)
141 if (pkg
.desired
.sourcePackage ().accessible ())
142 pkg
.desired
.sourcePackage ().pick (
143 !pkg
.desired
.sourcePackage ().picked (), NULL
);
145 /* Unchecking binary while source is unchecked or vice versa is equivalent
146 to uninstalling. It's essential to set desired correctly, otherwise the
147 package gets uninstalled without visual feedback to the user. The package
148 will not even show up in the "Pending" view! */
149 if (!pkg
.desired
.picked () && !pkg
.desired
.sourcePackage ().picked ())
150 pkg
.desired
= packageversion ();
154 int PickPackageLine::set_action (packagemeta::_actions action
)
156 pkg
.set_action (action
, pkg
.trustp (true, theView
.deftrust
));