1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 03:22:48 -05:00

Add UTF-8 versions of dlg_editbox_{get,set}.

There's no difficulty with implementing these, on either platform.
Windows has native Unicode support for its edit boxes: we can set and
retrieve the text as a wide-character string, and then converting it
to and from UTF-8 is easy. And GTK has specified its edit boxes as
being UTF-8 all along, no matter what the system locale.
This commit is contained in:
Simon Tatham
2024-09-23 14:20:44 +01:00
parent 75b6e12f84
commit 55d413a47a
3 changed files with 37 additions and 2 deletions

View File

@ -2210,6 +2210,15 @@ void dlg_editbox_set(dlgcontrol *ctrl, dlgparam *dp, char const *text)
SetDlgItemText(dp->hwnd, c->base_id+1, text);
}
void dlg_editbox_set_utf8(dlgcontrol *ctrl, dlgparam *dp, char const *text)
{
struct winctrl *c = dlg_findbyctrl(dp, ctrl);
assert(c && c->ctrl->type == CTRL_EDITBOX);
wchar_t *wtext = dup_mb_to_wc(CP_UTF8, text);
SetDlgItemTextW(dp->hwnd, c->base_id+1, wtext);
sfree(wtext);
}
char *dlg_editbox_get(dlgcontrol *ctrl, dlgparam *dp)
{
struct winctrl *c = dlg_findbyctrl(dp, ctrl);
@ -2217,6 +2226,16 @@ char *dlg_editbox_get(dlgcontrol *ctrl, dlgparam *dp)
return GetDlgItemText_alloc(dp->hwnd, c->base_id+1);
}
char *dlg_editbox_get_utf8(dlgcontrol *ctrl, dlgparam *dp)
{
struct winctrl *c = dlg_findbyctrl(dp, ctrl);
assert(c && c->ctrl->type == CTRL_EDITBOX);
wchar_t *wtext = GetDlgItemTextW_alloc(dp->hwnd, c->base_id+1);
char *text = dup_wc_to_mb(CP_UTF8, wtext, "");
sfree(wtext);
return text;
}
void dlg_editbox_select_range(dlgcontrol *ctrl, dlgparam *dp,
size_t start, size_t len)
{