comdlg32: Add a helper function to select a combo box item.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2018-01-18 19:51:06 +01:00
parent 8a62752fe9
commit 77d65c3948
1 changed files with 22 additions and 38 deletions

View File

@ -483,6 +483,16 @@ static inline void CFn_ReleaseDC(const CHOOSEFONTW *lpcf, HDC hdc)
ReleaseDC(0, 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] * AddFontStyle [internal]
*/ */
@ -543,10 +553,7 @@ static void CFn_FitFontSize( HWND hDlg, int points)
if (points == (int)SendDlgItemMessageW if (points == (int)SendDlgItemMessageW
(hDlg,cmb3, CB_GETITEMDATA,i,0)) (hDlg,cmb3, CB_GETITEMDATA,i,0))
{ {
SendDlgItemMessageW(hDlg,cmb3,CB_SETCURSEL,i,0); select_combo_item( hDlg, cmb3, i );
SendMessageW(hDlg, WM_COMMAND,
MAKEWPARAM(cmb3, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb3));
return; return;
} }
} }
@ -559,21 +566,17 @@ static BOOL CFn_FitFontStyle( HWND hDlg, LONG packedstyle )
{ {
LONG id; LONG id;
int i; int i;
BOOL ret = FALSE;
/* look for fitting font style in combobox2 */ /* look for fitting font style in combobox2 */
for (i=0;i<TEXT_EXTRAS;i++) for (i=0;i<TEXT_EXTRAS;i++)
{ {
id = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0); id = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, i, 0);
if (packedstyle == id) if (packedstyle == id)
{ {
SendDlgItemMessageW(hDlg, cmb2, CB_SETCURSEL, i, 0); select_combo_item( hDlg, cmb2, i );
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb2, CBN_SELCHANGE), return TRUE;
(LPARAM)GetDlgItem(hDlg,cmb2));
ret = TRUE;
break;
} }
} }
return ret; return FALSE;
} }
@ -587,16 +590,12 @@ static BOOL CFn_FitCharSet( HWND hDlg, int charset )
cs =SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0); cs =SendDlgItemMessageW(hDlg, cmb5, CB_GETITEMDATA, i, 0);
if (charset == cs) if (charset == cs)
{ {
SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, i, 0); select_combo_item( hDlg, cmb5, i );
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb2));
return TRUE; return TRUE;
} }
} }
/* no charset fits: select the first one in the list */ /* no charset fits: select the first one in the list */
SendDlgItemMessageW(hDlg, cmb5, CB_SETCURSEL, 0, 0); select_combo_item( hDlg, cmb5, 0 );
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb5, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb2));
return FALSE; return FALSE;
} }
@ -729,9 +728,7 @@ static LRESULT CFn_WMInitDialog(HWND hDlg, LPARAM lParam, LPCHOOSEFONTW lpcf)
points = MulDiv( height, 72, GetScreenDPI()); points = MulDiv( height, 72, GetScreenDPI());
pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD: pstyle = MAKELONG(lpxx->lfWeight > FW_MEDIUM ? FW_BOLD:
FW_NORMAL,lpxx->lfItalic !=0); FW_NORMAL,lpxx->lfItalic !=0);
SendDlgItemMessageW(hDlg, cmb1, CB_SETCURSEL, j, 0); select_combo_item( hDlg, cmb1, j );
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE),
(LPARAM)GetDlgItem(hDlg,cmb1));
init = TRUE; init = TRUE;
/* look for fitting font style in combobox2 */ /* look for fitting font style in combobox2 */
CFn_FitFontStyle(hDlg, pstyle); CFn_FitFontStyle(hDlg, pstyle);
@ -742,18 +739,10 @@ static LRESULT CFn_WMInitDialog(HWND hDlg, LPARAM lParam, LPCHOOSEFONTW lpcf)
} }
if (!init) if (!init)
{ {
SendDlgItemMessageW(hDlg,cmb1,CB_SETCURSEL,0,0); select_combo_item( hDlg, cmb1, 0 );
SendMessageW(hDlg, WM_COMMAND, MAKEWPARAM(cmb1, CBN_SELCHANGE), select_combo_item( hDlg, cmb2, 0 );
(LPARAM)GetDlgItem(hDlg,cmb1)); select_combo_item( hDlg, cmb3, 0 );
SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,0,0); select_combo_item( hDlg, cmb5, 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));
} }
/* limit text length user can type in as font size */ /* limit text length user can type in as font size */
SendDlgItemMessageW(hDlg, cmb3, CB_LIMITTEXT, 5, 0); 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) if ((lpcf->Flags & CF_USESTYLE) && lpcf->lpszStyle)
{ {
j=SendDlgItemMessageW(hDlg,cmb2,CB_FINDSTRING,-1,(LPARAM)lpcf->lpszStyle); j=SendDlgItemMessageW(hDlg,cmb2,CB_FINDSTRING,-1,(LPARAM)lpcf->lpszStyle);
if (j!=CB_ERR) if (j!=CB_ERR) select_combo_item( hDlg, cmb2, j );
{
j=SendDlgItemMessageW(hDlg,cmb2,CB_SETCURSEL,j,0);
SendMessageW(hDlg,WM_COMMAND,cmb2,
MAKELONG(LOWORD(GetDlgItem(hDlg,cmb2)),CBN_SELCHANGE));
}
} }
CFn_ReleaseDC(lpcf, hdc); CFn_ReleaseDC(lpcf, hdc);
SetCursor(hcursor); SetCursor(hcursor);