From: Robert Collins Date: Sun, 6 Jan 2002 13:37:09 +0000 (+0000) Subject: 2001-01-07 Robert Collins X-Git-Tag: cygnus_cvs_20020108_pre X-Git-Url: https://cygwin.com/git/?a=commitdiff_plain;h=d343da152219caf93d1edf34c7bb20c7ae831515;p=cygwin-apps%2Fsetup.git 2001-01-07 Robert Collins * category.cc (Categorycmp): Add a const safe version. * category.h (Categorycmp): Add a const safe version. (Category): Add operator ==. * choose.cc (fill_missing_category): Add every package to "All". (pick_category_line::paint): Add support for hidden labels, and a tree depth. (pick_category_line::click): Ditto. (view::view): Pass in a top level category to use. (view::insert_pkg): Special case - skip category "All". (view::insert_category): Ditto. (view::clear_view): Set the contents label state. (create_listview): Pass in a top level category to view(). * choose.h (topbucket): Make bucket available to derived classes. (pick_category_line): Add support for hidden labels, and a tree depth. Remove our second copy of bucket. (view): Pass in a top level category to the constructor. Use pick_category_line to allow three level display. --- diff --git a/ChangeLog b/ChangeLog index 6abd6b84..a59dfa7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2001-01-07 Robert Collins + + * category.cc (Categorycmp): Add a const safe version. + * category.h (Categorycmp): Add a const safe version. + (Category): Add operator ==. + * choose.cc (fill_missing_category): Add every package to "All". + (pick_category_line::paint): Add support for hidden labels, and a tree depth. + (pick_category_line::click): Ditto. + (view::view): Pass in a top level category to use. + (view::insert_pkg): Special case - skip category "All". + (view::insert_category): Ditto. + (view::clear_view): Set the contents label state. + (create_listview): Pass in a top level category to view(). + * choose.h (topbucket): Make bucket available to derived classes. + (pick_category_line): Add support for hidden labels, and a tree depth. + Remove our second copy of bucket. + (view): Pass in a top level category to the constructor. + Use pick_category_line to allow three level display. + 2001-01-06 Robert Collins * cygpackage.h (cygpackage): Make set_[s|l]desc virtual. diff --git a/category.cc b/category.cc index aec9b8fd..fe0592ba 100644 --- a/category.cc +++ b/category.cc @@ -36,7 +36,13 @@ packages (0) } int -Categorycmp (Category & a, Category & b) +Categorycmp (Category const & a, Category const & b) { return strcasecmp (a.name, b.name); } + +int +Categorycmp (Category & a, Category & b) +{ + return strcasecmp (a.name, b.name); +} diff --git a/category.h b/category.h index 542dc2c4..c678e670 100644 --- a/category.h +++ b/category.h @@ -18,13 +18,20 @@ #ifndef _CATEGORY_H_ #define _CATEGORY_H_ +class Category; class CategoryPackage; +int Categorycmp (Category const &, Category const &); +// Grrr template problem - couldn't get list to use int Ucmp (U const, U const), +// and gcc wouldn't cast on the fly. +int Categorycmp (Category &, Category &); + class Category { public: Category (); - Category (const char *); + Category (char const *); + bool operator== (Category const &rhs) const {return Categorycmp (*this, rhs) ? false : true;} Category *next; /* the next category in the list */ const char *name; /* the category */ @@ -32,6 +39,4 @@ public: CategoryPackage *packages; /* the packages in this category */ }; -int Categorycmp (Category &, Category &); - #endif /* _CATEGORY_H_ */ diff --git a/choose.cc b/choose.cc index f443a5ab..7426da73 100644 --- a/choose.cc +++ b/choose.cc @@ -504,6 +504,7 @@ fill_missing_category () packagemeta & pkg = *db.packages[n]; if (!pkg.Categories.number ()) pkg.add_category (db.categories.registerbykey ("Misc")); + pkg.add_category (db.categories.registerbykey ("All")); } } @@ -664,11 +665,12 @@ void pick_category_line::paint (HDC hdc, int x, int y, int row, int show_cat) { int r = y + row * row_height; - TextOut (hdc, x + chooser->headers[chooser->cat_col].x + HMARGIN / 2, r, + if (show_label) + TextOut (hdc, x + chooser->headers[chooser->cat_col].x + HMARGIN / 2 + depth * 8, r, cat.name, strlen (cat.name)); if (collapsed) return; - int accum_row = row + 1; + int accum_row = row + (show_label ? 1 : 0); for (size_t n = 1; n <= bucket.number (); n++) { bucket[n]->paint (hdc, x, y, accum_row, show_cat); @@ -698,7 +700,7 @@ pick_pkg_line::click (int const myrow, int const ClickedRow, int const x) int pick_category_line::click (int const myrow, int const ClickedRow, int const x) { - if (myrow == ClickedRow) + if (myrow == ClickedRow && show_label) { collapsed = !collapsed; int accum_row = 0; @@ -708,7 +710,7 @@ pick_category_line::click (int const myrow, int const ClickedRow, int const x) } else { - int accum_row = myrow + 1; + int accum_row = myrow + (show_label ? 1 : 0); for (size_t n = 1; n <= bucket.number (); n++) { if (accum_row + bucket[n]->itemcount () > ClickedRow) @@ -721,7 +723,8 @@ pick_category_line::click (int const myrow, int const ClickedRow, int const x) HWND DoCreateHeader (HWND hwndParent); -view::view (views _mode, HWND lv):listview (lv) +view::view (views _mode, HWND lv, Category &cat) : +contents (cat, 0, false, true), listview (lv) { HDC dc = GetDC (listview); @@ -924,7 +927,10 @@ view::insert_pkg (packagemeta & pkg) for (size_t x = 1; x <= pkg.Categories.number (); x++) { Category & cat = pkg.Categories[x]->key; - pick_category_line & catline = *new pick_category_line (cat); + // Special case - yuck + if (cat == Category ("All")) + continue; + pick_category_line & catline = *new pick_category_line (cat, 1); pick_pkg_line & line = *new pick_pkg_line (pkg); catline.insert (line); contents.insert (catline); @@ -935,8 +941,9 @@ view::insert_pkg (packagemeta & pkg) void view::insert_category (Category * cat, bool collapsed) { - - pick_category_line & catline = *new pick_category_line (*cat, collapsed); + if (*cat == Category ("All")) + return; + pick_category_line & catline = *new pick_category_line (*cat, 1, collapsed); for (CategoryPackage * catpkg = cat->packages; catpkg; catpkg = catpkg->next) { @@ -951,6 +958,20 @@ void view::clear_view (void) { contents.empty (); + switch (view_mode) + { + case VIEW_UNKNOWN: + break; + case VIEW_PACKAGE_FULL: + case VIEW_PACKAGE: + contents.ShowLabel (false); + break; + case VIEW_CATEGORY: + contents.ShowLabel (); + break; + default: + return; + } } static views @@ -1074,14 +1095,14 @@ create_listview (HWND dlg, RECT * r) (HMENU) MAKEINTRESOURCE (IDC_CHOOSE_LIST), hinstance, 0); ShowWindow (lv, SW_SHOW); - chooser = new view (VIEW_CATEGORY, lv); + packagedb db; + chooser = new view (VIEW_CATEGORY, lv, db.categories.registerbykey("All")); default_trust (lv, TRUST_CURR); set_view_mode (lv, VIEW_CATEGORY); if (!SetDlgItemText (dlg, IDC_CHOOSE_VIEWCAPTION, chooser->mode_caption ())) log (LOG_BABBLE, "Failed to set View button caption %ld", GetLastError ()); - packagedb db; for (size_t n = 1; n <= db.packages.number (); n++) { packagemeta & pkg = *db.packages[n]; diff --git a/choose.h b/choose.h index ac67bb62..c1c37906 100644 --- a/choose.h +++ b/choose.h @@ -150,7 +150,6 @@ public: protected: topbucket (topbucket const &); topbucket & operator= (topbucket const &); -private: list < pick_line, char const *, strcasecmp > bucket; }; @@ -158,43 +157,52 @@ private: class pick_category_line:public topbucket { public: - pick_category_line (Category & _cat, bool aBool = - true):cat (_cat), collapsed (aBool) - { + pick_category_line (Category & _cat, size_t thedepth = 0, bool aBool = + true, bool aBool2 = true):cat (_cat), depth(thedepth) + { + if (aBool) + { + collapsed = true; + show_label = true; + } + else + { + collapsed = false; + show_label = aBool2; + } + key = _cat.key; }; + void ShowLabel(bool aBool = true) {show_label = aBool; if (!show_label) collapsed = false;} virtual void paint (HDC hdc, int x, int y, int row, int show_cat); virtual int click (int const myrow, int const ClickedRow, int const x); virtual int itemcount () const { if (collapsed) return 1; - int t = 1; + int t = show_label ? 1 : 0; for (size_t n = 1; n <= bucket.number (); n++) t += bucket[n]->itemcount (); return t; }; - virtual void insert (pick_line & aLine) - { - bucket.registerbyobject (aLine); - } private: Category & cat; - list < pick_line, char const *, strcasecmp > bucket; bool collapsed; + bool show_label; + size_t depth; }; class view { public: int num_columns; - views get_view_mode () + views get_view_mode () { return view_mode; }; void set_view_mode (views _mode); struct _header *headers; - view (views mode, HWND listview); + view (views mode, HWND listview, Category &cat); const char *mode_caption (); void insert_pkg (packagemeta &); void insert_category (Category *, bool); @@ -206,9 +214,7 @@ public: int cat_col; int pkg_col; int last_col; -// pick_line *lines; -// int nlines; - topbucket contents; + pick_category_line contents; void scroll (HWND hwnd, int which, int *var, int code); HWND ListHeader (void) const {