From 713bbe5f5ab45b2b91bb4b9f22aa2d12ae169ecc Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Fri, 11 Aug 2000 18:00:38 +0000 Subject: [PATCH] * choose.cc: add new chooser dialog * fromcwd.cc: use IDD_CHOOSE * ini.cc: use IDD_CHOOSE * main.cc: use IDD_CHOOSE * ini.h: cosmetic changes * res.rc: add choose dialog, bitmaps * choose-spin.bmp: new * choose-rtarrow.bmp: new * resource.h: add choose dialog controls * mount.cc: remove debug statement --- ChangeLog | 14 + choose-rtarrow.bmp | Bin 0 -> 106 bytes choose-spin.bmp | Bin 0 -> 106 bytes choose.cc | 666 ++++++++++++++++++++++++++++++++++++++++++--- fromcwd.cc | 2 +- ini.cc | 2 +- ini.h | 5 +- main.cc | 2 +- mount.cc | 1 - res.rc | 30 ++ resource.h | 17 +- 11 files changed, 692 insertions(+), 47 deletions(-) create mode 100644 choose-rtarrow.bmp create mode 100644 choose-spin.bmp diff --git a/ChangeLog b/ChangeLog index 51e985bd..c1fff3c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2000-08-11 DJ Delorie + + * choose.cc: add new chooser dialog + * fromcwd.cc: use IDD_CHOOSE + * ini.cc: use IDD_CHOOSE + * main.cc: use IDD_CHOOSE + * ini.h: cosmetic changes + * res.rc: add choose dialog, bitmaps + * choose-spin.bmp: new + * choose-rtarrow.bmp: new + * resource.h: add choose dialog controls + + * mount.cc: remove debug statement + 2000-08-08 DJ Delorie * Makefile.in (version.c): make version checking more robust diff --git a/choose-rtarrow.bmp b/choose-rtarrow.bmp new file mode 100644 index 0000000000000000000000000000000000000000..5f719e164628689d539f0ef648a69c88d76079a8 GIT binary patch literal 106 zcmZ?r&0>H6J0PV2#N1HK$iN7e&;gT}#Q*>Q8U8 literal 0 HcmV?d00001 diff --git a/choose-spin.bmp b/choose-spin.bmp new file mode 100644 index 0000000000000000000000000000000000000000..8779f6dc20ebfb35c22b7b97afda8fcad8d93664 GIT binary patch literal 106 zcmZ?r&0>H6J0PV2#N1HK$iN7e&;gT}#Q*>Q89qK>V0Z___Y)Wx*nyZ$fq|h9h&QU?G_z7YTb literal 0 HcmV?d00001 diff --git a/choose.cc b/choose.cc index 359a127d..3f079a68 100644 --- a/choose.cc +++ b/choose.cc @@ -29,6 +29,9 @@ static char *cvsid = "\n%%% $Id$\n"; #include "win32.h" #include +#include +#include + #include "dialog.h" #include "resource.h" #include "state.h" @@ -36,62 +39,603 @@ static char *cvsid = "\n%%% $Id$\n"; #include "concat.h" #include "msg.h" -void -do_choose (HINSTANCE h) +#define HMARGIN 10 +#define ROW_MARGIN 5 +#define ICON_MARGIN 4 + +#define TRUST_KEEP 101 +#define TRUST_UNINSTALL 102 +#define TRUST_NONE 103 + +static int initialized = 0; + +static int full_list = 0; + +static int scroll_ulc_x, scroll_ulc_y; + +static HWND lv, nextbutton; +static TEXTMETRIC tm; +static int header_height; +static HANDLE sysfont; +static int row_height; +static HANDLE bm_spin, bm_rtarrow; +static HDC bitmap_dc; + +static struct { + char *text; + int slen; + int width; + int x; +} headers[] = { + { "Current", 7, 0, 0 }, + { "New", 3, 0, 0 }, + { "Package", 7, 0, 0 }, + { 0, 0, 0, 0 } +}; + +int *package_indexes, nindexes; + +struct ExtraPackageInfo { + char *installed_file; /* filename of previous "install" file */ + char *installed_ver; /* version part */ + int installed_size; /* ditto, size. */ + + int in_partial_list; + int pick; + int npick; + int which_is_installed; /* == TRUST* or -1 */ + + struct { + int trust; /* may be keep or uninstall */ + char *caption; /* ==0 at EOL */ + } chooser[NTRUST+3]; /* one extra for NULL above */ +}; + +static ExtraPackageInfo *extra; + +static void +paint (HWND hwnd) { - int trust_prefs[NTRUST]; - int i, t; + HDC hdc; + PAINTSTRUCT ps; + int x, y, i, j, ii; - /* support this later */ - trust_level = TRUST_CURR; + hdc = BeginPaint (hwnd, &ps); - t = 0; - for (i=trust_level; i>=0; i--) - trust_prefs[t++] = i; - for (i=trust_level+1; i 1) { - package[i].trust = tp; - break; + SelectObject (bitmap_dc, bm_spin); + BitBlt (hdc, x+headers[1].x, by, 11, 11, + bitmap_dc, 0, 0, SRCCOPY); } } + + if (package[i].name) + TextOut (hdc, x+headers[2].x, r, package[i].name, strlen(package[i].name)); } + + EndPaint (hwnd, &ps); +} + +static void +scroll_common (HWND hwnd, int which, int *var, int code) +{ + int v = *var; - if (root_dir) + SCROLLINFO si; + si.cbSize = sizeof (si); + si.fMask = SIF_ALL; + GetScrollInfo (hwnd, which, &si); + + switch (code) { - char line[1000], pkg[1000], inst[1000], src[1000]; - int instsz, srcsz; - FILE *db = fopen (concat (root_dir, "/etc/setup/installed.db", 0), "rt"); - if (db) + case SB_THUMBTRACK: + si.nPos = si.nTrackPos; + break; + case SB_THUMBPOSITION: + break; + case SB_BOTTOM: + si.nPos = si.nMax; + break; + case SB_TOP: + si.nPos = 0; + break; + case SB_LINEDOWN: + si.nPos += row_height; + break; + case SB_LINEUP: + si.nPos -= row_height; + break; + case SB_PAGEDOWN: + si.nPos += si.nPage * 9/10; + break; + case SB_PAGEUP: + si.nPos -= si.nPage * 9/10; + break; + } + + if ((int)si.nPos < 0) + si.nPos = 0; + if (si.nPos + si.nPage > si.nMax) + si.nPos = si.nMax - si.nPage; + + si.fMask = SIF_POS; + SetScrollInfo (hwnd, which, &si, TRUE); + + int ox = scroll_ulc_x; + int oy = scroll_ulc_y; + *var = si.nPos; + + RECT cr, sr; + GetClientRect (hwnd, &cr); + sr = cr; + sr.top += header_height; + ScrollWindow (hwnd, ox - scroll_ulc_x, oy - scroll_ulc_y, &sr, &sr); + sr.bottom = sr.top; + sr.top = cr.top; + ScrollWindow (hwnd, ox - scroll_ulc_x, 0, &sr, &sr); +} + +static LRESULT CALLBACK +list_vscroll (HWND hwnd, HWND hctl, UINT code, int pos) +{ + scroll_common (hwnd, SB_VERT, &scroll_ulc_y, code); +} + +static LRESULT CALLBACK +list_hscroll (HWND hwnd, HWND hctl, UINT code, int pos) +{ + scroll_common (hwnd, SB_HORZ, &scroll_ulc_x, code); +} + +static LRESULT CALLBACK +list_click (HWND hwnd, BOOL dblclk, int x, int y, UINT hitCode) +{ + int r; + + if (y < header_height) + return 0; + x += scroll_ulc_x; + y += scroll_ulc_y - header_height; + + if (x < headers[1].x - HMARGIN/2 || x > headers[2].x - HMARGIN/2) + return 0; + + r = (y + ROW_MARGIN/2) / row_height; + + if (r < 0 || r >= npackages) + return 0; + + int p = package_indexes[r]; + + extra[p].pick ++; + if (extra[p].chooser[extra[p].pick].caption == 0) + extra[p].pick = 0; + + RECT rect; + rect.left = headers[1].x - scroll_ulc_x; + rect.right = headers[2].x - scroll_ulc_x; + rect.top = header_height + r * row_height - scroll_ulc_y; + rect.bottom = rect.top + row_height; + InvalidateRect (hwnd, &rect, TRUE); +} + +static LRESULT CALLBACK +listview_proc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) { + case WM_HSCROLL: + return HANDLE_WM_HSCROLL (hwnd, wParam, lParam, list_hscroll); + case WM_VSCROLL: + return HANDLE_WM_VSCROLL (hwnd, wParam, lParam, list_vscroll); + case WM_LBUTTONDOWN: + return HANDLE_WM_LBUTTONDOWN (hwnd, wParam, lParam, list_click); + case WM_PAINT: + paint (hwnd); + return 0; + default: + return DefWindowProc (hwnd, message, wParam, lParam); + } +} + +static void +register_windows (HINSTANCE hinst) +{ + WNDCLASSEX wcex; + static int done = 0; + + if (done) + return; + done = 1; + + memset (&wcex, 0, sizeof (wcex)); + wcex.cbSize = sizeof (WNDCLASSEX); + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = listview_proc; + wcex.hInstance = hinst; + wcex.hIcon = LoadIcon (0, IDI_APPLICATION); + wcex.hCursor = LoadCursor (0, IDC_ARROW); + wcex.hbrBackground = (HBRUSH) (COLOR_WINDOW+1); + wcex.lpszClassName = "listview"; + + RegisterClassEx (&wcex); +} + +static void +note_width (HDC dc, char *string, int addend, int column) +{ + if (!string) + return; + SIZE s; + GetTextExtentPoint32 (dc, string, strlen (string), &s); + if (headers[column].width < s.cx + addend) + headers[column].width = s.cx + addend; +} + +static int +best_trust (int p, int trust) +{ + int t; + for (t=trust; t>=0; t--) + if (package[p].info[t].install) + return t; + for (t=trust+1; t<=NTRUST; t++) + if (package[p].info[t].install) + return t; + if (extra[p].installed_file) + return TRUST_KEEP; + return TRUST_NONE; +} + +static void +default_trust (HWND h, int trust) +{ + int i, t, c; + + for (i=0; ileft, r->top, + r->right-r->left+1, r->bottom-r->top+1, + dlg, + MAKEINTRESOURCE(IDC_CHOOSE_LIST), + hinstance, + 0); + ShowWindow (lv, SW_SHOW); + + for (i=0; headers[i].text; i++) + headers[i].width = 0; + + HDC dc = GetDC (lv); + sysfont = GetStockObject (DEFAULT_GUI_FONT); + SelectObject (dc, sysfont); + GetTextMetrics (dc, &tm); + header_height = tm.tmHeight + 5 + 3; + + bitmap_dc = CreateCompatibleDC (dc); + + row_height = (tm.tmHeight + tm.tmExternalLeading + ROW_MARGIN); + int irh = tm.tmExternalLeading + tm.tmDescent + 11 + ROW_MARGIN; + if (row_height < irh) + row_height = irh; + + for (i=0; headers[i].text; i++) + note_width (dc, headers[i].text, 0, i); + for (i=0; ileft; + p.y = r->top; + ScreenToClient (parent, &p); + r->left = p.x; + r->top = p.y; + p.x = r->right; + p.y = r->bottom; + ScreenToClient (parent, &p); + r->right = p.x; + r->bottom = p.y; +} + +static BOOL CALLBACK +dialog_proc (HWND h, UINT message, WPARAM wParam, LPARAM lParam) +{ + int i, j; + HWND frame; + RECT r; + switch (message) + { + case WM_INITDIALOG: + nextbutton = GetDlgItem (h, IDOK); + frame = GetDlgItem (h, IDC_LISTVIEW_POS); + GetParentRect (h, frame, &r); + r.top += 2; + r.bottom -= 2; + create_listview (h, &r); +#if 0 + load_dialog (h); +#endif + return FALSE; + case WM_COMMAND: + return HANDLE_WM_COMMAND (h, wParam, lParam, dialog_cmd); + } + return FALSE; +} + +static void +read_installed_db () +{ + int i; + if (!root_dir) + return; + + char line[1000], pkg[1000], inst[1000], src[1000]; + int instsz, srcsz; + + FILE *db = fopen (concat (root_dir, "/etc/setup/installed.db", 0), "rt"); + if (!db) + return; + + while (fgets (line, 1000, db)) + { + src[0] = 0; + srcsz = 0; + sscanf (line, "%s %s %d %s %d", pkg, inst, &instsz, src, &srcsz); + + for (i=0; i",IDOK,175,185,45,15 + PUSHBUTTON "Cancel",IDCANCEL,240,185,45,15 + LTEXT "Select packages to install",IDC_STATIC,55,5,85,8 + PUSHBUTTON "<-- Back",IDC_BACK,130,185,45,15 + ICON IDI_CYGWIN,IDC_STATIC,5,5,20,20 + CONTROL "",IDC_LISTVIEW_POS,"Static",SS_BLACKFRAME | NOT + WS_VISIBLE,55,15,230,155 + CONTROL "SPIN",IDC_STATIC,"Static",SS_BITMAP,55,170,15,13 + LTEXT "= click to choose action, (p) = previous version, (x) = experimental", + IDC_STATIC,65,170,220,8 + PUSHBUTTON "Full/Part",IDC_CHOOSE_FULLPART,250,5,35,10 + PUSHBUTTON "Exp",IDC_CHOOSE_EXP,215,5,25,10 + PUSHBUTTON "Curr",IDC_CHOOSE_CURR,190,5,25,10 + PUSHBUTTON "Prev",IDC_CHOOSE_PREV,165,5,25,10 +END + #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// @@ -277,6 +298,15 @@ END #endif // APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Bitmap +// + +SPIN BITMAP DISCARDABLE "choose-spin.bmp" +IDB_SPIN BITMAP DISCARDABLE "choose-spin.bmp" +IDB_RTARROW BITMAP DISCARDABLE "choose-rtarrow.bmp" + ///////////////////////////////////////////////////////////////////////////// // // String Table diff --git a/resource.h b/resource.h index ca10a171..ff4bb668 100644 --- a/resource.h +++ b/resource.h @@ -27,7 +27,7 @@ #define IDD_DLSTATUS 106 #define IDD_S_LOAD_INI 107 #define IDD_S_FROM_CWD 108 -#define IDD_S_CHOOSE 109 +#define IDD_CHOOSE 109 #define IDD_S_DOWNLOAD 110 #define IDD_S_INSTALL 111 #define IDD_INSTATUS 112 @@ -36,7 +36,10 @@ #define IDD_S_POSTINSTALL 114 #define IDD_NET_AUTH 114 #define IDD_SPLASH 115 -#define IDI_CYGWIN 200 +#define IDB_SPIN 115 +#define IDB_RTARROW 116 +#define IDI_SPIN 117 +#define IDI_CYGWIN 118 #define IDC_SOURCE_DOWNLOAD 1000 #define IDC_SOURCE_NETINST 1001 #define IDC_SOURCE_CWD 1002 @@ -67,6 +70,12 @@ #define IDC_NET_USER 1030 #define IDC_NET_PASSWD 1031 #define IDC_VERSION 1033 +#define IDC_LISTVIEW_POS 1034 +#define IDC_CHOOSE_FULLPART 1035 +#define IDC_CHOOSE_EXP 1036 +#define IDC_CHOOSE_CURR 1037 +#define IDC_CHOOSE_PREV 1038 +#define IDC_CHOOSE_LIST 1039 #define IDC_STATIC -1 // Next default values for new objects @@ -75,9 +84,9 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 #define _APS_3D_CONTROLS 1 -#define _APS_NEXT_RESOURCE_VALUE 115 +#define _APS_NEXT_RESOURCE_VALUE 119 #define _APS_NEXT_COMMAND_VALUE 40003 -#define _APS_NEXT_CONTROL_VALUE 1034 +#define _APS_NEXT_CONTROL_VALUE 1040 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif -- 2.43.5