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