Implemented type-to-search in the font dialog.
This commit is contained in:
parent
edef521ded
commit
aa6778acbe
|
@ -19,7 +19,7 @@ struct fontDialog {
|
||||||
// on OK, these are what are read
|
// on OK, these are what are read
|
||||||
LRESULT curFamily;
|
LRESULT curFamily;
|
||||||
LRESULT curStyle;
|
LRESULT curStyle;
|
||||||
LRESULT curSize;
|
double curSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
static LRESULT cbAddString(HWND cb, WCHAR *str)
|
static LRESULT cbAddString(HWND cb, WCHAR *str)
|
||||||
|
@ -72,7 +72,7 @@ static BOOL cbGetCurSel(HWND cb, LRESULT *sel)
|
||||||
|
|
||||||
static void cbSetCurSel(HWND cb, WPARAM item)
|
static void cbSetCurSel(HWND cb, WPARAM item)
|
||||||
{
|
{
|
||||||
if (SendMessageW(cb, CB_SETCURSEL, item, 0) != 0)
|
if (SendMessageW(cb, CB_SETCURSEL, item, 0) != (LRESULT) item)
|
||||||
logLastError("error selecting combobox item in cbSetCurSel()");
|
logLastError("error selecting combobox item in cbSetCurSel()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +99,48 @@ static void cbWipeAndReleaseData(HWND cb)
|
||||||
SendMessageW(cb, CB_RESETCONTENT, 0, 0);
|
SendMessageW(cb, CB_RESETCONTENT, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static WCHAR *cbGetItemText(HWND cb, WPARAM item)
|
||||||
|
{
|
||||||
|
LRESULT len;
|
||||||
|
WCHAR *text;
|
||||||
|
|
||||||
|
// note: neither message includes the terminating L'\0'
|
||||||
|
len = SendMessageW(cb, CB_GETLBTEXTLEN, item, 0);
|
||||||
|
if (len == (LRESULT) CB_ERR)
|
||||||
|
logLastError("error getting item text length from combobox in cbGetItemText()");
|
||||||
|
text = (WCHAR *) uiAlloc((len + 1) * sizeof (WCHAR), "WCHAR[]");
|
||||||
|
if (SendMessageW(cb, CB_GETLBTEXT, item, (LPARAM) text) != len)
|
||||||
|
logLastError("error getting item text from combobox in cbGetItemText()");
|
||||||
|
}
|
||||||
|
|
||||||
|
static BOOL cbTypeToSelect(HWND cb, LRESULT *posOut, BOOL restoreAfter)
|
||||||
|
{
|
||||||
|
WCHAR *text;
|
||||||
|
LRESULT pos;
|
||||||
|
DWORD selStart, selEnd;
|
||||||
|
|
||||||
|
// start by saving the current selection as setting the item will change the selection
|
||||||
|
SendMessageW(cb, CB_GETEDITSEL, (WPARAM) (&selStart), (LPARAM) (&selEnd));
|
||||||
|
text = windowText(cb);
|
||||||
|
pos = SendMessageW(cb, CB_FINDSTRINGEXACT, (WPARAM) (-1), (LPARAM) text);
|
||||||
|
if (pos == (LRESULT) CB_ERR) {
|
||||||
|
uiFree(text);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
cbSetCurSel(cb, (WPARAM) pos);
|
||||||
|
if (posOut != NULL)
|
||||||
|
*posOut = pos;
|
||||||
|
if (restoreAfter)
|
||||||
|
if (SendMessageW(cb, WM_SETTEXT, 0, (LPARAM) text) != (LRESULT) TRUE)
|
||||||
|
logLastError("error restoring old combobox text in cbTypeToSelect()");
|
||||||
|
uiFree(text);
|
||||||
|
// and restore the selection like above
|
||||||
|
// TODO isn't there a 32-bit version of this
|
||||||
|
if (SendMessageW(cb, CB_SETEDITSEL, 0, MAKELPARAM(selStart, selEnd)) != (LRESULT) TRUE)
|
||||||
|
logLastError("error restoring combobox edit selection in cbTypeToSelect()");
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static void wipeStylesBox(struct fontDialog *f)
|
static void wipeStylesBox(struct fontDialog *f)
|
||||||
{
|
{
|
||||||
cbWipeAndReleaseData(f->styleCombobox);
|
cbWipeAndReleaseData(f->styleCombobox);
|
||||||
|
@ -157,6 +199,12 @@ static void familyChanged(struct fontDialog *f)
|
||||||
InvalidateRect(f->sampleBox, NULL, TRUE/*TODO*/);
|
InvalidateRect(f->sampleBox, NULL, TRUE/*TODO*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO search language variants like the sample does
|
||||||
|
static void familyEdited(struct fontDialog *f)
|
||||||
|
{
|
||||||
|
if (cbTypeToSelect(f->familyCombobox, &(f->curFamily), FALSE))
|
||||||
|
familyChanged(f);
|
||||||
|
}
|
||||||
|
|
||||||
static void fontDialogDrawSampleText(struct fontDialog *f, ID2D1RenderTarget *rt)
|
static void fontDialogDrawSampleText(struct fontDialog *f, ID2D1RenderTarget *rt)
|
||||||
{
|
{
|
||||||
|
@ -399,10 +447,15 @@ static INT_PTR CALLBACK fontDialogDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, L
|
||||||
return FALSE;
|
return FALSE;
|
||||||
return tryFinishDialog(f, wParam);
|
return tryFinishDialog(f, wParam);
|
||||||
case rcFontFamilyCombobox:
|
case rcFontFamilyCombobox:
|
||||||
if (HIWORD(wParam) != CBN_SELCHANGE)
|
if (HIWORD(wParam) == CBN_SELCHANGE) {
|
||||||
return FALSE;
|
familyChanged(f);
|
||||||
familyChanged(f);
|
return TRUE;
|
||||||
return TRUE;
|
}
|
||||||
|
if (HIWORD(wParam) == CBN_EDITCHANGE) {
|
||||||
|
familyEdited(f);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
// TODO
|
// TODO
|
||||||
case rcFontStyleCombobox:
|
case rcFontStyleCombobox:
|
||||||
case rcFontSizeCombobox:
|
case rcFontSizeCombobox:
|
||||||
|
|
Loading…
Reference in New Issue