]> cygwin.com Git - cygwin-apps/setup.git/blob - PickCategoryLine.cc
2002-01-22 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / PickCategoryLine.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 "PickCategoryLine.h"
17 #include "PickView.h"
18
19 char const *
20 PickCategoryLine::actiontext ()
21 {
22 switch (current_default)
23 {
24 case Default_action:
25 return "Default";
26 case Install_action:
27 return "Install";
28 case Reinstall_action:
29 return "Reinstall";
30 case Uninstall_action:
31 return "Uninstall";
32 }
33 // Pacify GCC: (all case options are checked above)
34 return 0;
35 }
36
37 void
38 PickCategoryLine::empty (void)
39 {
40 while (bucket.number ())
41 {
42 PickLine *line = bucket.removebyindex (1);
43 delete line;
44 }
45 }
46
47 void
48 PickCategoryLine::paint (HDC hdc, int x, int y, int row, int show_cat)
49 {
50 int r = y + row * theView.row_height;
51 if (show_label)
52 {
53 int by = r + theView.tm.tmHeight - 11;
54 TextOut (hdc,
55 x + theView.headers[theView.cat_col].x + HMARGIN / 2 +
56 depth * 8, r, cat.name, strlen (cat.name));
57 if (!labellength)
58 {
59 SIZE s;
60 GetTextExtentPoint32 (hdc, cat.name, strlen (cat.name), &s);
61 labellength = s.cx;
62 }
63 SelectObject (theView.bitmap_dc, theView.bm_spin);
64 BitBlt (hdc,
65 x + theView.headers[theView.cat_col].x +
66 labellength + depth * 8 +
67 ICON_MARGIN +
68 HMARGIN / 2, by, 11, 11, theView.bitmap_dc, 0, 0, SRCCOPY);
69 TextOut (hdc,
70 x + theView.headers[theView.cat_col].x +
71 labellength + depth * 8 +
72 ICON_MARGIN + SPIN_WIDTH +
73 HMARGIN, r, actiontext (), strlen (actiontext ()));
74 }
75 if (collapsed)
76 return;
77 int accum_row = row + (show_label ? 1 : 0);
78 for (size_t n = 1; n <= bucket.number (); n++)
79 {
80 bucket[n]->paint (hdc, x, y, accum_row, show_cat);
81 accum_row += bucket[n]->itemcount ();
82 }
83 }
84
85 int
86 PickCategoryLine::click (int const myrow, int const ClickedRow, int const x)
87 {
88 if (myrow == ClickedRow && show_label)
89 {
90 if ((size_t) x >= theView.headers[theView.cat_col].x +
91 labellength + depth * 8 + ICON_MARGIN + HMARGIN / 2)
92 {
93 for (size_t n = 1; n <= bucket.number (); n++)
94 ;
95 return 0;
96 }
97 else
98 {
99 collapsed = !collapsed;
100 int accum_row = 0;
101 for (size_t n = 1; n <= bucket.number (); n++)
102 accum_row += bucket[n]->itemcount ();
103 return collapsed ? accum_row : -accum_row;
104 }
105 }
106 else
107 {
108 int accum_row = myrow + (show_label ? 1 : 0);
109 for (size_t n = 1; n <= bucket.number (); n++)
110 {
111 if (accum_row + bucket[n]->itemcount () > ClickedRow)
112 return bucket[n]->click (accum_row, ClickedRow, x);
113 accum_row += bucket[n]->itemcount ();
114 }
115 return 0;
116 }
117 }
This page took 0.043888 seconds and 6 git commands to generate.