From 77d65c39486ffc2b4c17aec958e361b180a029a1 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 18 Jan 2018 19:51:06 +0100 Subject: [PATCH] comdlg32: Add a helper function to select a combo box item. Signed-off-by: Alexandre Julliard --- dlls/comdlg32/fontdlg.c | 60 +++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 38 deletions(-) diff --git a/dlls/comdlg32/fontdlg.c b/dlls/comdlg32/fontdlg.c index 82992cb5a45..768ca4a6eae 100644 --- a/dlls/comdlg32/fontdlg.c +++ b/dlls/comdlg32/fontdlg.c @@ -483,6 +483,16 @@ static inline void CFn_ReleaseDC(const CHOOSEFONTW *lpcf, HDC hdc) ReleaseDC(0, hdc); } +/************************************************************************* + * select_combo_item [internal] + */ +static void select_combo_item( HWND dialog, int id, int sel ) +{ + HWND combo = GetDlgItem( dialog, id ); + SendMessageW( combo, CB_SETCURSEL, sel, 0 ); + SendMessageW( dialog, WM_COMMAND, MAKEWPARAM( id, CBN_SELCHANGE ), (LPARAM)combo ); +} + /*********************************************************************** * AddFontStyle [internal] */ @@ -543,10 +553,7 @@ static void CFn_FitFontSize( HWND hDlg, int points) if (points == (int)SendDlgItemMessageW (hDlg,cmb3, CB_GETITEMDATA,i,0)) { - SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,i,0); - SendMessageW(hDlg, WM_COMMAND, - MAKEWPARAM(cmb3, CBN_SELCHANGE), - (LPARAM)GetDlgItem(hDlg,cmb3)); + select_combo_item( hDlg, cmb3, i ); return; } } @@ -559,21 +566,17 @@ static BOOL CFn_FitFontStyle( HWND hDlg, LONG packedstyle ) { LONG id; int i; - BOOL ret = FALSE; /* look for fitting font style in combobox2 */ for (i=0;ilfWeight > FW_MEDIUM ? FW_BOLD: FW_NORMAL,lpxx->lfItalic !=0); - SendDlgItemMessageW(hDlg, cmb1, CB_SETCURSEL, j, 0); - SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE), - (LPARAM)GetDlgItem(hDlg,cmb1)); + select_combo_item( hDlg, cmb1, j ); init = TRUE; /* look for fitting font style in combobox2 */ CFn_FitFontStyle(hDlg, pstyle); @@ -742,18 +739,10 @@ static LRESULT CFn_WMInitDialog(HWND hDlg, LPARAM lParam, LPCHOOSEFONTW lpcf) } if (!init) { - SendDlgItemMessageW(hDlg,cmb1,CB_SETCURSEL,0,0); - SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE), - (LPARAM)GetDlgItem(hDlg,cmb1)); - SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,0,0); - SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE), - (LPARAM)GetDlgItem(hDlg,cmb1)); - SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,0,0); - SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb3, CBN_SELCHANGE), - (LPARAM)GetDlgItem(hDlg,cmb3)); - SendDlgItemMessageW(hDlg,cmb5,CB_SETCURSEL,0,0); - SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE), - (LPARAM)GetDlgItem(hDlg,cmb5)); + select_combo_item( hDlg, cmb1, 0 ); + select_combo_item( hDlg, cmb2, 0 ); + select_combo_item( hDlg, cmb3, 0 ); + select_combo_item( hDlg, cmb5, 0 ); } /* limit text length user can type in as font size */ SendDlgItemMessageW(hDlg, cmb3, CB_LIMITTEXT, 5, 0); @@ -761,12 +750,7 @@ static LRESULT CFn_WMInitDialog(HWND hDlg, LPARAM lParam, LPCHOOSEFONTW lpcf) if ((lpcf->Flags & CF_USESTYLE) && lpcf->lpszStyle) { j=SendDlgItemMessageW(hDlg,cmb2,CB_FINDSTRING,-1,(LPARAM)lpcf->lpszStyle); - if (j!=CB_ERR) - { - j=SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,j,0); - SendMessageW(hDlg,WM_COMMAND,cmb2, - MAKELONG(LOWORD(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE)); - } + if (j!=CB_ERR) select_combo_item( hDlg, cmb2, j ); } CFn_ReleaseDC(lpcf, hdc); SetCursor(hcursor);