From 93004c40adaebe9c1f9a3e86546cfc3826ff9714 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 7 Jan 2001 13:39:31 +0000 Subject: [PATCH] Make the colour list failsafe. Patch due to Robert de Bath [originally from svn r837] --- windlg.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/windlg.c b/windlg.c index af430ecb..0ffe3c9d 100644 --- a/windlg.c +++ b/windlg.c @@ -519,7 +519,11 @@ static void init_dlg_ctrls(HWND hwnd) { CheckDlgButton (hwnd, IDC_BOLDCOLOUR, cfg.bold_colour); CheckDlgButton (hwnd, IDC_PALETTE, cfg.try_palette); { - int i; + int i, n; + n = SendDlgItemMessage (hwnd, IDC_COLOURLIST, LB_GETCOUNT, 0, 0); + for (i=n; i-- >0 ;) + SendDlgItemMessage (hwnd, IDC_COLOURLIST, + LB_DELETESTRING, i, 0); for (i=0; i<22; i++) if (cfg.bold_colour || permcolour[i]) SendDlgItemMessage (hwnd, IDC_COLOURLIST, LB_ADDSTRING, 0, @@ -1613,17 +1617,15 @@ static int GenericMainDlgProc (HWND hwnd, UINT msg, int n, i; cfg.bold_colour = IsDlgButtonChecked (hwnd, IDC_BOLDCOLOUR); n = SendDlgItemMessage (hwnd, IDC_COLOURLIST, LB_GETCOUNT, 0, 0); - if (cfg.bold_colour && n!=22) { - for (i=0; i<22; i++) - if (!permcolour[i]) - SendDlgItemMessage (hwnd, IDC_COLOURLIST, - LB_INSERTSTRING, i, - (LPARAM) colours[i]); - } else if (!cfg.bold_colour && n!=12) { - for (i=22; i-- ;) - if (!permcolour[i]) - SendDlgItemMessage (hwnd, IDC_COLOURLIST, + if (n != 12+10*cfg.bold_colour) { + for (i=n; i-- >0 ;) + SendDlgItemMessage (hwnd, IDC_COLOURLIST, LB_DELETESTRING, i, 0); + for (i=0; i<22; i++) + if (cfg.bold_colour || permcolour[i]) + SendDlgItemMessage (hwnd, IDC_COLOURLIST, + LB_ADDSTRING, 0, + (LPARAM) colours[i]); } } break;