README: document some recent changes in the build environment
[cygwin-setup.git] / PickCategoryLine.cc
blob24fecb348a21cb57b5b93ad2a199befecb63b99a
1 /*
2 * Copyright (c) 2002 Robert Collins.
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.
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
12 * Written by Robert Collins <robertc@hotmail.com>
16 #include "PickCategoryLine.h"
17 #include "package_db.h"
18 #include "PickView.h"
20 void
21 PickCategoryLine::empty (void)
23 while (bucket.size ())
25 PickLine *line = *bucket.begin ();
26 delete line;
27 bucket.erase (bucket.begin ());
31 void
32 PickCategoryLine::paint (HDC hdc, HRGN hUpdRgn, int x, int y, int row, int show_cat)
34 int r = y + row * theView.row_height;
35 if (show_label)
37 int x2 = x + theView.headers[theView.cat_col].x + HMARGIN / 2 + depth * TREE_INDENT;
38 int by = r + (theView.tm.tmHeight / 2) - 5;
40 // draw the '+' or '-' box
41 theView.DrawIcon (hdc, x2, by, (collapsed ? theView.bm_treeplus : theView.bm_treeminus));
43 // draw the category name
44 TextOut (hdc, x2 + 11 + ICON_MARGIN, r, cat.first.c_str(), cat.first.size());
45 if (!labellength)
47 SIZE s;
48 GetTextExtentPoint32 (hdc, cat.first.c_str(), cat.first.size(), &s);
49 labellength = s.cx;
52 // draw the 'spin' glyph
53 spin_x = x2 + 11 + ICON_MARGIN + labellength + ICON_MARGIN;
54 theView.DrawIcon (hdc, spin_x, by, theView.bm_spin);
56 // draw the caption ('Default', 'Install', etc)
57 TextOut (hdc, spin_x + SPIN_WIDTH + ICON_MARGIN, r,
58 current_default.caption (), strlen (current_default.caption ()));
59 row++;
61 if (collapsed)
62 return;
64 // are the siblings containers?
65 if (bucket.size () && bucket[0]->IsContainer ())
67 for (size_t n = 0; n < bucket.size (); n++)
69 bucket[n]->paint (hdc, hUpdRgn, x, y, row, show_cat);
70 row += bucket[n]->itemcount ();
73 else
75 // calculate the maximum y value we expect for this group of lines
76 int max_y = y + (row + bucket.size ()) * theView.row_height;
78 // paint all contained rows, columnwise
79 for (int i = 0; theView.headers[i].text; i++)
81 RECT r;
82 r.left = x + theView.headers[i].x;
83 r.right = r.left + theView.headers[i].width;
85 // set up a clipping mask if necessary
86 if (theView.headers[i].needs_clip)
87 IntersectClipRect (hdc, r.left, y, r.right, max_y);
89 // draw each row in this column
90 for (unsigned int n = 0; n < bucket.size (); n++)
92 // test for visibility
93 r.top = y + ((row + n) * theView.row_height);
94 r.bottom = r.top + theView.row_height;
95 if (RectVisible (hdc, &r) != 0)
96 bucket[n]->paint (hdc, hUpdRgn, (int)r.left, (int)r.top, i, show_cat);
99 // restore original clipping area
100 if (theView.headers[i].needs_clip)
101 SelectClipRgn (hdc, hUpdRgn);
107 PickCategoryLine::click (int const myrow, int const ClickedRow, int const x)
109 if (myrow == ClickedRow && show_label)
111 if ((size_t) x >= spin_x)
113 ++current_default;
115 return set_action (current_default);
117 else
119 collapsed = !collapsed;
120 int accum_row = 0;
121 for (size_t n = 0; n < bucket.size (); ++n)
122 accum_row += bucket[n]->itemcount ();
123 return collapsed ? accum_row : -accum_row;
126 else
128 int accum_row = myrow + (show_label ? 1 : 0);
129 for (size_t n = 0; n < bucket.size (); ++n)
131 if (accum_row + bucket[n]->itemcount () > ClickedRow)
132 return bucket[n]->click (accum_row, ClickedRow, x);
133 accum_row += bucket[n]->itemcount ();
135 return 0;
139 int
140 PickCategoryLine::set_action (packagemeta::_actions action)
142 theView.GetParent ()->SetBusy ();
143 current_default = action;
144 int accum_diff = 0;
145 for (size_t n = 0; n < bucket.size (); n++)
146 accum_diff += bucket[n]->set_action (current_default);
147 theView.GetParent ()->ClearBusy ();
148 return accum_diff;