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