*/
#include "PickCategoryLine.h"
+#include "package_db.h"
#include "PickView.h"
-char const *
-PickCategoryLine::actiontext ()
-{
- switch (current_default)
- {
- case Default_action:
- return "Default";
- case Install_action:
- return "Install";
- case Reinstall_action:
- return "Reinstall";
- case Uninstall_action:
- return "Uninstall";
- }
- // Pacify GCC: (all case options are checked above)
- return 0;
-}
-
void
PickCategoryLine::empty (void)
{
- while (bucket.number ())
+ while (bucket.size ())
{
- PickLine *line = bucket.removebyindex (1);
+ PickLine *line = *bucket.begin ();
delete line;
+ bucket.erase (bucket.begin ());
}
}
void
-PickCategoryLine::paint (HDC hdc, int x, int y, int row, int show_cat)
+PickCategoryLine::paint (HDC hdc, HRGN hUpdRgn, int x, int y, int row, int show_cat)
{
int r = y + row * theView.row_height;
if (show_label)
{
- int by = r + theView.tm.tmHeight - 11;
- TextOut (hdc,
- x + theView.headers[theView.cat_col].x + HMARGIN / 2 +
- depth * 8, r, cat.name, strlen (cat.name));
+ int x2 = x + theView.headers[theView.cat_col].x + HMARGIN / 2 + depth * TREE_INDENT;
+ int by = r + (theView.tm.tmHeight / 2) - 5;
+
+ // draw the '+' or '-' box
+ theView.DrawIcon (hdc, x2, by, (collapsed ? theView.bm_treeplus : theView.bm_treeminus));
+
+ // draw the category name
+ TextOut (hdc, x2 + 11 + ICON_MARGIN, r, cat.first.c_str(), cat.first.size());
if (!labellength)
{
SIZE s;
- GetTextExtentPoint32 (hdc, cat.name, strlen (cat.name), &s);
+ GetTextExtentPoint32 (hdc, cat.first.c_str(), cat.first.size(), &s);
labellength = s.cx;
}
- SelectObject (theView.bitmap_dc, theView.bm_spin);
- BitBlt (hdc,
- x + theView.headers[theView.cat_col].x +
- labellength + depth * 8 +
- ICON_MARGIN +
- HMARGIN / 2, by, 11, 11, theView.bitmap_dc, 0, 0, SRCCOPY);
- TextOut (hdc,
- x + theView.headers[theView.cat_col].x +
- labellength + depth * 8 +
- ICON_MARGIN + SPIN_WIDTH +
- HMARGIN, r, actiontext (), strlen (actiontext ()));
+
+ // draw the 'spin' glyph
+ spin_x = x2 + 11 + ICON_MARGIN + labellength + ICON_MARGIN;
+ theView.DrawIcon (hdc, spin_x, by, theView.bm_spin);
+
+ // draw the caption ('Default', 'Install', etc)
+ TextOut (hdc, spin_x + SPIN_WIDTH + ICON_MARGIN, r,
+ current_default.caption (), strlen (current_default.caption ()));
+ row++;
}
if (collapsed)
return;
- int accum_row = row + (show_label ? 1 : 0);
- for (size_t n = 1; n <= bucket.number (); n++)
+
+ // are the siblings containers?
+ if (bucket.size () && bucket[0]->IsContainer ())
{
- bucket[n]->paint (hdc, x, y, accum_row, show_cat);
- accum_row += bucket[n]->itemcount ();
+ for (size_t n = 0; n < bucket.size (); n++)
+ {
+ bucket[n]->paint (hdc, hUpdRgn, x, y, row, show_cat);
+ row += bucket[n]->itemcount ();
+ }
+ }
+ else
+ {
+ // calculate the maximum y value we expect for this group of lines
+ int max_y = y + (row + bucket.size ()) * theView.row_height;
+
+ // paint all contained rows, columnwise
+ for (int i = 0; theView.headers[i].text; i++)
+ {
+ RECT r;
+ r.left = x + theView.headers[i].x;
+ r.right = r.left + theView.headers[i].width;
+
+ // set up a clipping mask if necessary
+ if (theView.headers[i].needs_clip)
+ IntersectClipRect (hdc, r.left, y, r.right, max_y);
+
+ // draw each row in this column
+ for (unsigned int n = 0; n < bucket.size (); n++)
+ {
+ // test for visibility
+ r.top = y + ((row + n) * theView.row_height);
+ r.bottom = r.top + theView.row_height;
+ if (RectVisible (hdc, &r) != 0)
+ bucket[n]->paint (hdc, hUpdRgn, (int)r.left, (int)r.top, i, show_cat);
+ }
+
+ // restore original clipping area
+ if (theView.headers[i].needs_clip)
+ SelectClipRgn (hdc, hUpdRgn);
+ }
}
}
{
if (myrow == ClickedRow && show_label)
{
- if ((size_t) x >= theView.headers[theView.cat_col].x +
- labellength + depth * 8 + ICON_MARGIN + HMARGIN / 2)
+ if ((size_t) x >= spin_x)
{
- for (size_t n = 1; n <= bucket.number (); n++)
- ;
- return 0;
+ ++current_default;
+
+ return set_action (current_default);
}
else
{
collapsed = !collapsed;
int accum_row = 0;
- for (size_t n = 1; n <= bucket.number (); n++)
+ for (size_t n = 0; n < bucket.size (); ++n)
accum_row += bucket[n]->itemcount ();
return collapsed ? accum_row : -accum_row;
}
else
{
int accum_row = myrow + (show_label ? 1 : 0);
- for (size_t n = 1; n <= bucket.number (); n++)
+ for (size_t n = 0; n < bucket.size (); ++n)
{
if (accum_row + bucket[n]->itemcount () > ClickedRow)
return bucket[n]->click (accum_row, ClickedRow, x);
return 0;
}
}
+
+int
+PickCategoryLine::set_action (packagemeta::_actions action)
+{
+ theView.GetParent ()->SetBusy ();
+ current_default = action;
+ int accum_diff = 0;
+ for (size_t n = 0; n < bucket.size (); n++)
+ accum_diff += bucket[n]->set_action (current_default);
+ theView.GetParent ()->ClearBusy ();
+ return accum_diff;
+}