mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-28 01:07:08 -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:
parent
75b6e12f84
commit
55d413a47a
2
dialog.h
2
dialog.h
@ -574,7 +574,9 @@ int dlg_radiobutton_get(dlgcontrol *ctrl, dlgparam *dp);
|
||||
void dlg_checkbox_set(dlgcontrol *ctrl, dlgparam *dp, bool checked);
|
||||
bool dlg_checkbox_get(dlgcontrol *ctrl, dlgparam *dp);
|
||||
void dlg_editbox_set(dlgcontrol *ctrl, dlgparam *dp, char const *text);
|
||||
void dlg_editbox_set_utf8(dlgcontrol *ctrl, dlgparam *dp, char const *text);
|
||||
char *dlg_editbox_get(dlgcontrol *ctrl, dlgparam *dp); /* result must be freed by caller */
|
||||
char *dlg_editbox_get_utf8(dlgcontrol *ctrl, dlgparam *dp); /* result must be freed by caller */
|
||||
void dlg_editbox_select_range(dlgcontrol *ctrl, dlgparam *dp,
|
||||
size_t start, size_t len);
|
||||
/* The `listbox' functions can also apply to combo boxes. */
|
||||
|
@ -300,7 +300,7 @@ bool dlg_checkbox_get(dlgcontrol *ctrl, dlgparam *dp)
|
||||
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(uc->toplevel));
|
||||
}
|
||||
|
||||
void dlg_editbox_set(dlgcontrol *ctrl, dlgparam *dp, char const *text)
|
||||
void dlg_editbox_set_utf8(dlgcontrol *ctrl, dlgparam *dp, char const *text)
|
||||
{
|
||||
struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
|
||||
GtkWidget *entry;
|
||||
@ -338,7 +338,14 @@ void dlg_editbox_set(dlgcontrol *ctrl, dlgparam *dp, char const *text)
|
||||
sfree(tmpstring);
|
||||
}
|
||||
|
||||
char *dlg_editbox_get(dlgcontrol *ctrl, dlgparam *dp)
|
||||
void dlg_editbox_set(dlgcontrol *ctrl, dlgparam *dp, char const *text)
|
||||
{
|
||||
/* GTK specifies that its edit boxes are always in UTF-8 anyway,
|
||||
* so legacy behaviour is to use those strings unmodified */
|
||||
dlg_editbox_set_utf8(ctrl, dp, text);
|
||||
}
|
||||
|
||||
char *dlg_editbox_get_utf8(dlgcontrol *ctrl, dlgparam *dp)
|
||||
{
|
||||
struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
|
||||
assert(uc->ctrl->type == CTRL_EDITBOX);
|
||||
@ -357,6 +364,13 @@ char *dlg_editbox_get(dlgcontrol *ctrl, dlgparam *dp)
|
||||
unreachable("bad control type in editbox_get");
|
||||
}
|
||||
|
||||
char *dlg_editbox_get(dlgcontrol *ctrl, dlgparam *dp)
|
||||
{
|
||||
/* GTK specifies that its edit boxes are always in UTF-8 anyway,
|
||||
* so legacy behaviour is to use those strings unmodified */
|
||||
return dlg_editbox_get_utf8(ctrl, dp);
|
||||
}
|
||||
|
||||
void dlg_editbox_select_range(dlgcontrol *ctrl, dlgparam *dp,
|
||||
size_t start, size_t len)
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user