]> cygwin.com Git - cygwin-apps/setup.git/blame - PickPackageLine.cc
2002-09-22 Max Bowsher <maxb@ukf.net>
[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"
18#include "package_version.h"
19
2fa7c5a4
RC
20void
21PickPackageLine::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
42void
43PickPackageLine::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,
3c196821
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 ||
3c196821 114 /* no source */ !pkg.desired.accessible())
2fa7c5a4 115 checked = 0;
3c196821 116 else if (pkg.desired.picked())
2fa7c5a4
RC
117 checked = 1;
118 else
119 checked = 2;
120
121 DrawCheck (checked, hdc, theView.bintick_col, oldClip2, x, by);
122
97647369 123 if ( /* uninstall */ !pkg.desired ||
3c196821
RC
124 /* source only */ (!pkg.desired.picked()
125 && pkg.desired.sourcePackage().picked() && pkg.desired == pkg.installed) ||
97647369 126 /* when no source mirror available */
3c196821 127 !pkg.desired.sourcePackage().accessible())
2fa7c5a4 128 checked = 0;
3c196821 129 else if (pkg.desired.sourcePackage().picked())
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? */
405d7186 137 if (pkg.categories.size () && show_cat)
97647369 138 {
bfdf6ac2 139 String catName = pkg.getReadableCategoryList();
f2e49cf8 140 IntersectClipRect (hdc, x + theView.headers[theView.cat_col].x, r,
97647369 141 x + theView.headers[theView.cat_col].x +
bfdf6ac2 142 theView.headers[theView.cat_col].width - HMARGIN / 2, rb);
97647369 143 TextOut (hdc, x + theView.headers[theView.cat_col].x + HMARGIN / 2, r,
405d7186
RC
144 catName.cstr_oneuse(),
145 catName.size());
97647369
RC
146 SelectClipRgn (hdc, oldClip2);
147 }
148
3c054baf
RC
149 s = pkg.name;
150 if (pkg.SDesc ().size())
151 s += String(": ") + pkg.SDesc ();
f2e49cf8 152 IntersectClipRect (hdc, x + theView.headers[theView.pkg_col].x, r,
97647369 153 x + theView.headers[theView.pkg_col].x +
f2e49cf8 154 theView.headers[theView.pkg_col].width, rb);
3c054baf
RC
155 TextOut (hdc, x + theView.headers[theView.pkg_col].x + HMARGIN / 2, r, s.cstr_oneuse(),
156 s.size());
97647369
RC
157 DeleteObject (oldClip);
158 DeleteObject (oldClip2);
159 RestoreDC (hdc, oldDC);
160}
161
162int
163PickPackageLine::click (int const myrow, int const ClickedRow, int const x)
164{
165 // assert (myrow == ClickedRow);
3f34f364 166 if (pkg.desired.accessible ()
2fa7c5a4
RC
167 && x >= theView.headers[theView.bintick_col].x - HMARGIN / 2
168 && x <= theView.headers[theView.bintick_col + 1].x - HMARGIN / 2)
3c196821 169 pkg.desired.pick(!pkg.desired.picked());
3f34f364 170 if (pkg.desired.sourcePackage ().accessible ()
2fa7c5a4
RC
171 && x >= theView.headers[theView.srctick_col].x - HMARGIN / 2
172 && x <= theView.headers[theView.srctick_col + 1].x - HMARGIN / 2)
3c196821 173 pkg.desired.sourcePackage().pick(!pkg.desired.sourcePackage().picked());
97647369
RC
174
175 if (x >= theView.headers[theView.new_col].x - HMARGIN / 2
176 && x <= theView.headers[theView.new_col + 1].x - HMARGIN / 2)
4f591f9d
RC
177 pkg.set_action (pkg.trustp(theView.deftrust));
178
179 /* Add any packages that are needed by this package */
180 return pkg.set_requirements ();
97647369 181}
7e8fc33c
RC
182
183int PickPackageLine::set_action (packagemeta::_actions action)
184{
185 pkg.set_action (action , pkg.trustp(theView.deftrust));
186 return pkg.set_requirements(theView.deftrust) + 1;
187}
This page took 0.045795 seconds and 5 git commands to generate.