]> granicus.if.org Git - nethack/commitdiff
U613 specifying alignment in win32 and CE (from Yitzhak)
authornethack.allison <nethack.allison>
Wed, 3 Sep 2003 03:57:32 +0000 (03:57 +0000)
committernethack.allison <nethack.allison>
Wed, 3 Sep 2003 03:57:32 +0000 (03:57 +0000)
> 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
sys/wince/mhdlg.c
win/win32/mhdlg.c

index f559d55f461891c4c0d0d409d8da8a4661f83c39..1ae5f29d626d1f81570c3f9b1e5fdd4307917ad6 100644 (file)
@@ -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
index af9dfcfa31374e7f381e37c17f08896b8cb64184..9b6e9a040647251853d1e95119e5b021c25bb935 100644 (file)
@@ -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);
        }
 }
 
index 4cd1110c32de2ecd5511ed0ae4283686b3da1532..d112c6b04123b3e3ccba61c2a5f5377ba5b0bf50 100644 (file)
@@ -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);
        }
 }