]>
Commit | Line | Data |
---|---|---|
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" | |
18 | #include "package_version.h" | |
19 | ||
2fa7c5a4 RC |
20 | void |
21 | PickPackageLine::DrawCheck (int const checked, HDC hdc, int const column, HRGN const clip, int const x, int const by) | |
22 | { | |
23 | HANDLE check_bm; | |
24 | if (checked == 0) | |
25 | check_bm = theView.bm_checkna; | |
26 | else if (checked == 1) | |
27 | check_bm = theView.bm_checkyes; | |
28 | else if (checked == 2) | |
29 | check_bm = theView.bm_checkno; | |
30 | else | |
31 | return; | |
32 | ||
33 | SelectObject (theView.bitmap_dc, check_bm); | |
34 | IntersectClipRect (hdc, x + theView.headers[column].x, by, | |
35 | x + theView.headers[column].x + | |
36 | theView.headers[column].width, by + 11); | |
37 | BitBlt (hdc, x + theView.headers[column].x + HMARGIN / 2, by, 11, | |
38 | 11, theView.bitmap_dc, 0, 0, SRCCOPY); | |
39 | SelectClipRgn (hdc, clip); | |
40 | } | |
41 | ||
97647369 RC |
42 | void |
43 | PickPackageLine::paint (HDC hdc, int x, int y, int row, int show_cat) | |
44 | { | |
45 | int r = y + row * theView.row_height; | |
f2e49cf8 RC |
46 | int rb = r + theView.tm.tmHeight; |
47 | int by = rb - 11; // top of box images | |
97647369 RC |
48 | int oldDC = SaveDC (hdc); |
49 | if (!oldDC) | |
50 | return; | |
51 | HRGN oldClip = CreateRectRgn (0, 0, 0, 0); | |
52 | if (GetRandomRgn (hdc, oldClip, SYSRGN) == -1) | |
53 | { | |
54 | RestoreDC (hdc, oldDC); | |
55 | return; | |
56 | } | |
2fa7c5a4 RC |
57 | HRGN oldClip2; |
58 | if (Win32::OS() == Win32::WinNT) { | |
59 | ||
97647369 RC |
60 | unsigned int regionsize = GetRegionData (oldClip, 0, 0); |
61 | LPRGNDATA oldClipData = (LPRGNDATA) malloc (regionsize); | |
62 | if (GetRegionData (oldClip, regionsize, oldClipData) > regionsize) | |
63 | { | |
64 | RestoreDC (hdc, oldDC); | |
65 | DeleteObject (oldClip); | |
66 | return; | |
67 | } | |
68 | for (unsigned int n = 0; n < oldClipData->rdh.nCount; n++) | |
69 | for (unsigned int t = 0; t < 2; t++) | |
70 | ScreenToClient (WindowFromDC (hdc), | |
71 | &((POINT *) oldClipData->Buffer)[t + n * 2]); | |
72 | ||
2fa7c5a4 RC |
73 | oldClip2 = ExtCreateRegion (NULL, regionsize, oldClipData); |
74 | } | |
75 | else | |
76 | oldClip2 = oldClip; | |
77 | ||
97647369 RC |
78 | SelectClipRgn (hdc, oldClip2); |
79 | if (pkg.installed) | |
80 | { | |
81 | IntersectClipRect (hdc, x + theView.headers[theView.current_col].x, | |
f2e49cf8 | 82 | r, |
97647369 | 83 | x + theView.headers[theView.current_col].x + |
f2e49cf8 | 84 | theView.headers[theView.current_col].width, rb); |
97647369 RC |
85 | TextOut (hdc, |
86 | x + theView.headers[theView.current_col].x + HMARGIN / 2, r, | |
3c054baf RC |
87 | pkg.installed->Canonical_version ().cstr_oneuse(), |
88 | pkg.installed->Canonical_version ().size()); | |
97647369 RC |
89 | SelectObject (theView.bitmap_dc, theView.bm_rtarrow); |
90 | BitBlt (hdc, x + theView.headers[theView.new_col].x + HMARGIN / 2, | |
91 | by, 11, 11, theView.bitmap_dc, 0, 0, SRCCOPY); | |
92 | SelectClipRgn (hdc, oldClip2); | |
93 | } | |
94 | ||
3c054baf | 95 | String s = pkg.action_caption (); |
97647369 | 96 | IntersectClipRect (hdc, x + theView.headers[theView.new_col].x, |
f2e49cf8 | 97 | r, |
97647369 | 98 | x + theView.headers[theView.new_col].x + |
f2e49cf8 | 99 | theView.headers[theView.new_col].width, rb); |
97647369 RC |
100 | TextOut (hdc, |
101 | x + theView.headers[theView.new_col].x + HMARGIN / 2 + | |
3c054baf | 102 | NEW_COL_SIZE_SLOP, r, s.cstr_oneuse(), s.size()); |
97647369 RC |
103 | SelectObject (theView.bitmap_dc, theView.bm_spin); |
104 | BitBlt (hdc, | |
105 | x + theView.headers[theView.new_col].x + ICON_MARGIN / 2 + | |
106 | RTARROW_WIDTH + HMARGIN / 2, by, 11, 11, theView.bitmap_dc, 0, 0, | |
107 | SRCCOPY); | |
108 | SelectClipRgn (hdc, oldClip2); | |
109 | ||
2fa7c5a4 RC |
110 | int checked; |
111 | ||
112 | if (/* uninstall or skip */ !pkg.desired || | |
113 | /* current version */ pkg.desired == pkg.installed || | |
114 | /* no source */ !pkg.desired->bin.sites.number ()) | |
115 | checked = 0; | |
116 | else if (pkg.desired->binpicked) | |
117 | checked = 1; | |
118 | else | |
119 | checked = 2; | |
120 | ||
121 | DrawCheck (checked, hdc, theView.bintick_col, oldClip2, x, by); | |
122 | ||
97647369 RC |
123 | if ( /* uninstall */ !pkg.desired || |
124 | /* source only */ (!pkg.desired->binpicked | |
2fa7c5a4 | 125 | && pkg.desired->srcpicked && pkg.desired == pkg.installed) || |
97647369 RC |
126 | /* when no source mirror available */ |
127 | !pkg.desired->src.sites.number ()) | |
2fa7c5a4 | 128 | checked = 0; |
97647369 | 129 | else if (pkg.desired->srcpicked) |
2fa7c5a4 | 130 | checked = 1; |
97647369 | 131 | else |
2fa7c5a4 | 132 | checked = 2; |
97647369 | 133 | |
2fa7c5a4 | 134 | DrawCheck (checked, hdc, theView.srctick_col, oldClip2, x, by); |
97647369 RC |
135 | |
136 | /* shows "first" category - do we want to show any? */ | |
137 | if (pkg.Categories.number () && show_cat) | |
138 | { | |
139 | int index = 1; | |
3c054baf | 140 | if (!pkg.Categories[1]->key.name.casecompare( "All")) |
97647369 | 141 | index = 2; |
f2e49cf8 | 142 | IntersectClipRect (hdc, x + theView.headers[theView.cat_col].x, r, |
97647369 | 143 | x + theView.headers[theView.cat_col].x + |
f2e49cf8 | 144 | theView.headers[theView.cat_col].x, rb); |
97647369 | 145 | TextOut (hdc, x + theView.headers[theView.cat_col].x + HMARGIN / 2, r, |
3c054baf RC |
146 | pkg.Categories[index]->key.name.cstr_oneuse(), |
147 | pkg.Categories[index]->key.name.size()); | |
97647369 RC |
148 | SelectClipRgn (hdc, oldClip2); |
149 | } | |
150 | ||
3c054baf RC |
151 | s = pkg.name; |
152 | if (pkg.SDesc ().size()) | |
153 | s += String(": ") + pkg.SDesc (); | |
f2e49cf8 | 154 | IntersectClipRect (hdc, x + theView.headers[theView.pkg_col].x, r, |
97647369 | 155 | x + theView.headers[theView.pkg_col].x + |
f2e49cf8 | 156 | theView.headers[theView.pkg_col].width, rb); |
3c054baf RC |
157 | TextOut (hdc, x + theView.headers[theView.pkg_col].x + HMARGIN / 2, r, s.cstr_oneuse(), |
158 | s.size()); | |
97647369 RC |
159 | DeleteObject (oldClip); |
160 | DeleteObject (oldClip2); | |
161 | RestoreDC (hdc, oldDC); | |
162 | } | |
163 | ||
164 | int | |
165 | PickPackageLine::click (int const myrow, int const ClickedRow, int const x) | |
166 | { | |
167 | // assert (myrow == ClickedRow); | |
2fa7c5a4 RC |
168 | if (pkg.desired && pkg.desired->bin.sites.number () |
169 | && x >= theView.headers[theView.bintick_col].x - HMARGIN / 2 | |
170 | && x <= theView.headers[theView.bintick_col + 1].x - HMARGIN / 2) | |
171 | pkg.desired->binpicked ^= 1; | |
97647369 | 172 | if (pkg.desired && pkg.desired->src.sites.number () |
2fa7c5a4 RC |
173 | && x >= theView.headers[theView.srctick_col].x - HMARGIN / 2 |
174 | && x <= theView.headers[theView.srctick_col + 1].x - HMARGIN / 2) | |
97647369 RC |
175 | pkg.desired->srcpicked ^= 1; |
176 | ||
177 | if (x >= theView.headers[theView.new_col].x - HMARGIN / 2 | |
178 | && x <= theView.headers[theView.new_col + 1].x - HMARGIN / 2) | |
179 | { | |
180 | pkg.set_action (pkg.trustp(theView.deftrust)); | |
181 | /* Add any packages that are needed by this package */ | |
182 | return pkg.set_requirements (); | |
183 | } | |
184 | return 0; | |
185 | } | |
7e8fc33c RC |
186 | |
187 | int PickPackageLine::set_action (packagemeta::_actions action) | |
188 | { | |
189 | pkg.set_action (action , pkg.trustp(theView.deftrust)); | |
190 | return pkg.set_requirements(theView.deftrust) + 1; | |
191 | } |