From e382e3b0557d11206ed5ccbddba6e1fa312f31dd Mon Sep 17 00:00:00 2001 From: "nethack.allison" Date: Wed, 3 Sep 2003 03:57:32 +0000 Subject: [PATCH] U613 specifying alignment in win32 and CE (from Yitzhak) > The bug involved using the initalign (and related) indexes into > the array of alignments as indexes into the respective combo box, > and these are (apparently) not equivalent. To fix, the combo box > is queried one by one for the item with the index that produces > that proper alignment value, and then uses that index found. I > did not find an API that does this in one step, but this only > happens once, at dialog initialization. --- doc/fixes34.3 | 1 + sys/wince/mhdlg.c | 22 ++++++++++++++++++---- win/win32/mhdlg.c | 22 ++++++++++++++++++---- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/doc/fixes34.3 b/doc/fixes34.3 index f559d55f4..1ae5f29d6 100644 --- a/doc/fixes34.3 +++ b/doc/fixes34.3 @@ -10,6 +10,7 @@ grammar, spelling and other typos Platform- and/or Interface-Specific Fixes ----------------------------------------- win32tty: fix visible CRLF characters during lockfile error message +win32gui: you couldn't specify an alignment in defaults.nh and have it stick General New Features diff --git a/sys/wince/mhdlg.c b/sys/wince/mhdlg.c index af9dfcfa3..9b6e9a040 100644 --- a/sys/wince/mhdlg.c +++ b/sys/wince/mhdlg.c @@ -464,6 +464,20 @@ BOOL CALLBACK PlayerSelectorDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPAR return FALSE; } +void setComboBoxValue(HWND hWnd, int combo_box, int value) +{ + int index_max = SendDlgItemMessage(hWnd, combo_box, CB_GETCOUNT, 0, 0); + int index; + int value_to_set = LB_ERR; + for (index = 0; index < index_max; index++) { + if (SendDlgItemMessage(hWnd, combo_box, CB_GETITEMDATA, (WPARAM)index, 0) == value) { + value_to_set = index; + break; + } + } + SendDlgItemMessage(hWnd, combo_box, CB_SETCURSEL, (WPARAM)value_to_set, 0); +} + /* initialize player selector dialog */ void plselInitDialog(HWND hWnd) { @@ -497,7 +511,7 @@ void plselInitDialog(HWND hWnd) } else { CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_UNCHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), TRUE); - SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_LIST, CB_SETCURSEL, (WPARAM)flags.initrole, 0); + setComboBoxValue(hWnd, IDC_PLSEL_ROLE_LIST, flags.initrole); } /* intialize races list */ @@ -507,7 +521,7 @@ void plselInitDialog(HWND hWnd) } else { CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_UNCHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), TRUE); - SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_LIST, CB_SETCURSEL, (WPARAM)flags.initrace, 0); + setComboBoxValue(hWnd, IDC_PLSEL_RACE_LIST, flags.initrace); } /* intialize genders list */ @@ -517,7 +531,7 @@ void plselInitDialog(HWND hWnd) } else { CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_UNCHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), TRUE); - SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_LIST, CB_SETCURSEL, (WPARAM)flags.initgend, 0); + setComboBoxValue(hWnd, IDC_PLSEL_GENDER_LIST, flags.initgend); } /* intialize alignments list */ @@ -527,7 +541,7 @@ void plselInitDialog(HWND hWnd) } else { CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_UNCHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), TRUE); - SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_LIST, CB_SETCURSEL, (WPARAM)flags.initalign, 0); + setComboBoxValue(hWnd, IDC_PLSEL_ALIGN_LIST, flags.initalign); } } diff --git a/win/win32/mhdlg.c b/win/win32/mhdlg.c index 4cd1110c3..d112c6b04 100644 --- a/win/win32/mhdlg.c +++ b/win/win32/mhdlg.c @@ -438,6 +438,20 @@ BOOL CALLBACK PlayerSelectorDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPAR return FALSE; } +void setComboBoxValue(HWND hWnd, int combo_box, int value) +{ + int index_max = SendDlgItemMessage(hWnd, combo_box, CB_GETCOUNT, 0, 0); + int index; + int value_to_set = LB_ERR; + for (index = 0; index < index_max; index++) { + if (SendDlgItemMessage(hWnd, combo_box, CB_GETITEMDATA, (WPARAM)index, 0) == value) { + value_to_set = index; + break; + } + } + SendDlgItemMessage(hWnd, combo_box, CB_SETCURSEL, (WPARAM)value_to_set, 0); +} + /* initialize player selector dialog */ void plselInitDialog(HWND hWnd) { @@ -471,7 +485,7 @@ void plselInitDialog(HWND hWnd) } else { CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_UNCHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), TRUE); - SendDlgItemMessage(hWnd, IDC_PLSEL_ROLE_LIST, CB_SETCURSEL, (WPARAM)flags.initrole, 0); + setComboBoxValue(hWnd, IDC_PLSEL_ROLE_LIST, flags.initrole); } /* intialize races list */ @@ -481,7 +495,7 @@ void plselInitDialog(HWND hWnd) } else { CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_UNCHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), TRUE); - SendDlgItemMessage(hWnd, IDC_PLSEL_RACE_LIST, CB_SETCURSEL, (WPARAM)flags.initrace, 0); + setComboBoxValue(hWnd, IDC_PLSEL_RACE_LIST, flags.initrace); } /* intialize genders list */ @@ -491,7 +505,7 @@ void plselInitDialog(HWND hWnd) } else { CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_UNCHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), TRUE); - SendDlgItemMessage(hWnd, IDC_PLSEL_GENDER_LIST, CB_SETCURSEL, (WPARAM)flags.initgend, 0); + setComboBoxValue(hWnd, IDC_PLSEL_GENDER_LIST, flags.initgend); } /* intialize alignments list */ @@ -501,7 +515,7 @@ void plselInitDialog(HWND hWnd) } else { CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_UNCHECKED); EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), TRUE); - SendDlgItemMessage(hWnd, IDC_PLSEL_ALIGN_LIST, CB_SETCURSEL, (WPARAM)flags.initalign, 0); + setComboBoxValue(hWnd, IDC_PLSEL_ALIGN_LIST, flags.initalign); } } -- 2.40.0