]>
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 "PickCategoryLine.h" | |
0d053c58 | 17 | #include "package_db.h" |
97647369 RC |
18 | #include "PickView.h" |
19 | ||
97647369 RC |
20 | void |
21 | PickCategoryLine::empty (void) | |
22 | { | |
0cf68afd | 23 | while (bucket.size ()) |
97647369 | 24 | { |
0cf68afd | 25 | PickLine *line = *bucket.begin (); |
97647369 | 26 | delete line; |
0cf68afd | 27 | bucket.erase (bucket.begin ()); |
97647369 RC |
28 | } |
29 | } | |
30 | ||
31 | void | |
82306ac2 | 32 | PickCategoryLine::paint (HDC hdc, HRGN hUpdRgn, int x, int y, int row, int show_cat) |
97647369 RC |
33 | { |
34 | int r = y + row * theView.row_height; | |
35 | if (show_label) | |
36 | { | |
82306ac2 BD |
37 | int x2 = x + theView.headers[theView.cat_col].x + HMARGIN / 2 + depth * TREE_INDENT; |
38 | int by = r + (theView.tm.tmHeight / 2) - 5; | |
39 | ||
40 | // draw the '+' or '-' box | |
41 | SelectObject (theView.bitmap_dc, | |
42 | (collapsed ? theView.bm_treeplus : theView.bm_treeminus)); | |
43 | BitBlt (hdc, x2, by, 11, 11, theView.bitmap_dc, 0, 0, SRCCOPY); | |
44 | ||
45 | // draw the category name | |
46 | TextOut (hdc, x2 + 11 + ICON_MARGIN, r, cat.first.c_str(), cat.first.size()); | |
97647369 RC |
47 | if (!labellength) |
48 | { | |
49 | SIZE s; | |
82306ac2 | 50 | GetTextExtentPoint32 (hdc, cat.first.c_str(), cat.first.size(), &s); |
97647369 RC |
51 | labellength = s.cx; |
52 | } | |
82306ac2 BD |
53 | |
54 | // draw the 'spin' glyph | |
97647369 | 55 | SelectObject (theView.bitmap_dc, theView.bm_spin); |
82306ac2 BD |
56 | spin_x = x2 + 11 + ICON_MARGIN + labellength + ICON_MARGIN; |
57 | BitBlt (hdc, spin_x, by, 11, 11, theView.bitmap_dc, 0, 0, SRCCOPY); | |
58 | ||
59 | // draw the caption ('Default', 'Install', etc) | |
60 | TextOut (hdc, spin_x + SPIN_WIDTH + ICON_MARGIN, r, | |
61 | current_default.caption (), strlen (current_default.caption ())); | |
62 | row++; | |
97647369 RC |
63 | } |
64 | if (collapsed) | |
65 | return; | |
82306ac2 BD |
66 | |
67 | // are the siblings containers? | |
68 | if (bucket.size () && bucket[0]->IsContainer ()) | |
69 | { | |
70 | for (size_t n = 0; n < bucket.size (); n++) | |
71 | { | |
72 | bucket[n]->paint (hdc, hUpdRgn, x, y, row, show_cat); | |
73 | row += bucket[n]->itemcount (); | |
74 | } | |
75 | } | |
76 | else | |
97647369 | 77 | { |
82306ac2 BD |
78 | // calculate the maximum y value we expect for this group of lines |
79 | int max_y = y + (row + bucket.size ()) * theView.row_height; | |
80 | ||
81 | // paint all contained rows, columnwise | |
82 | for (int i = 0; theView.headers[i].text; i++) | |
83 | { | |
84 | RECT r; | |
85 | r.left = x + theView.headers[i].x; | |
86 | r.right = r.left + theView.headers[i].width; | |
87 | ||
88 | // set up a clipping mask if necessary | |
89 | if (theView.headers[i].needs_clip) | |
90 | IntersectClipRect (hdc, r.left, y, r.right, max_y); | |
91 | ||
92 | // draw each row in this column | |
93 | for (unsigned int n = 0; n < bucket.size (); n++) | |
94 | { | |
95 | // test for visibility | |
96 | r.top = y + ((row + n) * theView.row_height); | |
97 | r.bottom = r.top + theView.row_height; | |
98 | if (RectVisible (hdc, &r) != 0) | |
99 | bucket[n]->paint (hdc, hUpdRgn, (int)r.left, (int)r.top, i, show_cat); | |
100 | } | |
101 | ||
102 | // restore original clipping area | |
103 | if (theView.headers[i].needs_clip) | |
104 | SelectClipRgn (hdc, hUpdRgn); | |
105 | } | |
97647369 RC |
106 | } |
107 | } | |
108 | ||
109 | int | |
110 | PickCategoryLine::click (int const myrow, int const ClickedRow, int const x) | |
111 | { | |
112 | if (myrow == ClickedRow && show_label) | |
113 | { | |
82306ac2 | 114 | if ((size_t) x >= spin_x) |
97647369 | 115 | { |
7e8fc33c RC |
116 | ++current_default; |
117 | ||
0d053c58 MB |
118 | packagedb().markUnVisited(); |
119 | ||
7e8fc33c | 120 | return set_action (current_default); |
97647369 RC |
121 | } |
122 | else | |
123 | { | |
124 | collapsed = !collapsed; | |
125 | int accum_row = 0; | |
0cf68afd | 126 | for (size_t n = 0; n < bucket.size (); ++n) |
97647369 RC |
127 | accum_row += bucket[n]->itemcount (); |
128 | return collapsed ? accum_row : -accum_row; | |
129 | } | |
130 | } | |
131 | else | |
132 | { | |
133 | int accum_row = myrow + (show_label ? 1 : 0); | |
0cf68afd | 134 | for (size_t n = 0; n < bucket.size (); ++n) |
97647369 RC |
135 | { |
136 | if (accum_row + bucket[n]->itemcount () > ClickedRow) | |
137 | return bucket[n]->click (accum_row, ClickedRow, x); | |
138 | accum_row += bucket[n]->itemcount (); | |
139 | } | |
140 | return 0; | |
141 | } | |
142 | } | |
7e8fc33c RC |
143 | |
144 | int | |
145 | PickCategoryLine::set_action (packagemeta::_actions action) | |
146 | { | |
147 | current_default = action; | |
148 | int accum_diff = 0; | |
0cf68afd | 149 | for (size_t n = 0; n < bucket.size (); n++) |
7e8fc33c RC |
150 | accum_diff += bucket[n]->set_action (current_default); |
151 | return accum_diff; | |
152 | } |