]>
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" | |
17 | #include "PickView.h" | |
18 | ||
97647369 RC |
19 | void |
20 | PickCategoryLine::empty (void) | |
21 | { | |
22 | while (bucket.number ()) | |
23 | { | |
24 | PickLine *line = bucket.removebyindex (1); | |
25 | delete line; | |
26 | } | |
27 | } | |
28 | ||
29 | void | |
30 | PickCategoryLine::paint (HDC hdc, int x, int y, int row, int show_cat) | |
31 | { | |
32 | int r = y + row * theView.row_height; | |
33 | if (show_label) | |
34 | { | |
35 | int by = r + theView.tm.tmHeight - 11; | |
3c054baf | 36 | String temp=(String("+ ") +cat.name); |
97647369 RC |
37 | TextOut (hdc, |
38 | x + theView.headers[theView.cat_col].x + HMARGIN / 2 + | |
3c054baf | 39 | depth * 8, r, temp.cstr_oneuse(), temp.size()); |
97647369 RC |
40 | if (!labellength) |
41 | { | |
42 | SIZE s; | |
3c054baf | 43 | GetTextExtentPoint32 (hdc, temp.cstr_oneuse(), temp.size(), &s); |
97647369 RC |
44 | labellength = s.cx; |
45 | } | |
46 | SelectObject (theView.bitmap_dc, theView.bm_spin); | |
47 | BitBlt (hdc, | |
48 | x + theView.headers[theView.cat_col].x + | |
49 | labellength + depth * 8 + | |
50 | ICON_MARGIN + | |
51 | HMARGIN / 2, by, 11, 11, theView.bitmap_dc, 0, 0, SRCCOPY); | |
52 | TextOut (hdc, | |
53 | x + theView.headers[theView.cat_col].x + | |
54 | labellength + depth * 8 + | |
55 | ICON_MARGIN + SPIN_WIDTH + | |
7e8fc33c | 56 | HMARGIN, r, current_default.caption (), strlen (current_default.caption ())); |
97647369 RC |
57 | } |
58 | if (collapsed) | |
59 | return; | |
60 | int accum_row = row + (show_label ? 1 : 0); | |
61 | for (size_t n = 1; n <= bucket.number (); n++) | |
62 | { | |
63 | bucket[n]->paint (hdc, x, y, accum_row, show_cat); | |
64 | accum_row += bucket[n]->itemcount (); | |
65 | } | |
66 | } | |
67 | ||
68 | int | |
69 | PickCategoryLine::click (int const myrow, int const ClickedRow, int const x) | |
70 | { | |
71 | if (myrow == ClickedRow && show_label) | |
72 | { | |
73 | if ((size_t) x >= theView.headers[theView.cat_col].x + | |
74 | labellength + depth * 8 + ICON_MARGIN + HMARGIN / 2) | |
75 | { | |
7e8fc33c RC |
76 | ++current_default; |
77 | ||
78 | return set_action (current_default); | |
97647369 RC |
79 | } |
80 | else | |
81 | { | |
82 | collapsed = !collapsed; | |
83 | int accum_row = 0; | |
84 | for (size_t n = 1; n <= bucket.number (); n++) | |
85 | accum_row += bucket[n]->itemcount (); | |
86 | return collapsed ? accum_row : -accum_row; | |
87 | } | |
88 | } | |
89 | else | |
90 | { | |
91 | int accum_row = myrow + (show_label ? 1 : 0); | |
92 | for (size_t n = 1; n <= bucket.number (); n++) | |
93 | { | |
94 | if (accum_row + bucket[n]->itemcount () > ClickedRow) | |
95 | return bucket[n]->click (accum_row, ClickedRow, x); | |
96 | accum_row += bucket[n]->itemcount (); | |
97 | } | |
98 | return 0; | |
99 | } | |
100 | } | |
7e8fc33c RC |
101 | |
102 | int | |
103 | PickCategoryLine::set_action (packagemeta::_actions action) | |
104 | { | |
105 | current_default = action; | |
106 | int accum_diff = 0; | |
107 | for (size_t n = 1; n <= bucket.number (); n++) | |
108 | accum_diff += bucket[n]->set_action (current_default); | |
109 | return accum_diff; | |
110 | } |