Turn 'Filename' into a dynamically allocated type with no arbitrary
[u/mdw/putty] / windows / winctrls.c
index 4afd3d0..fa79e64 100644 (file)
@@ -2098,25 +2098,28 @@ void dlg_editbox_set(union control *ctrl, void *dlg, char const *text)
     SetDlgItemText(dp->hwnd, c->base_id+1, text);
 }
 
-char *dlg_editbox_get(union control *ctrl, void *dlg)
+static char *getdlgitemtext_alloc(HWND hwnd, int id)
 {
-    struct dlgparam *dp = (struct dlgparam *)dlg;
-    struct winctrl *c = dlg_findbyctrl(dp, ctrl);
-    char *ret;
-    int size;
-    assert(c && c->ctrl->generic.type == CTRL_EDITBOX);
+    char *ret = NULL;
+    int size = 0;
 
-    size = 0;
-    ret = NULL;
     do {
        size = size * 4 / 3 + 512;
        ret = sresize(ret, size, char);
-       GetDlgItemText(dp->hwnd, c->base_id+1, ret, size);
+       GetDlgItemText(hwnd, id, ret, size);
     } while (!memchr(ret, '\0', size-1));
 
     return ret;
 }
 
+char *dlg_editbox_get(union control *ctrl, void *dlg)
+{
+    struct dlgparam *dp = (struct dlgparam *)dlg;
+    struct winctrl *c = dlg_findbyctrl(dp, ctrl);
+    assert(c && c->ctrl->generic.type == CTRL_EDITBOX);
+    return getdlgitemtext_alloc(dp->hwnd, c->base_id+1);
+}
+
 /* The `listbox' functions can also apply to combo boxes. */
 void dlg_listbox_clear(union control *ctrl, void *dlg)
 {
@@ -2294,21 +2297,25 @@ void dlg_label_change(union control *ctrl, void *dlg, char const *text)
     }
 }
 
-void dlg_filesel_set(union control *ctrl, void *dlg, Filename fn)
+void dlg_filesel_set(union control *ctrl, void *dlg, Filename *fn)
 {
     struct dlgparam *dp = (struct dlgparam *)dlg;
     struct winctrl *c = dlg_findbyctrl(dp, ctrl);
     assert(c && c->ctrl->generic.type == CTRL_FILESELECT);
-    SetDlgItemText(dp->hwnd, c->base_id+1, fn.path);
+    SetDlgItemText(dp->hwnd, c->base_id+1, fn->path);
 }
 
-void dlg_filesel_get(union control *ctrl, void *dlg, Filename *fn)
+Filename *dlg_filesel_get(union control *ctrl, void *dlg)
 {
     struct dlgparam *dp = (struct dlgparam *)dlg;
     struct winctrl *c = dlg_findbyctrl(dp, ctrl);
+    char *tmp;
+    Filename *ret;
     assert(c && c->ctrl->generic.type == CTRL_FILESELECT);
-    GetDlgItemText(dp->hwnd, c->base_id+1, fn->path, lenof(fn->path));
-    fn->path[lenof(fn->path)-1] = '\0';
+    tmp = getdlgitemtext_alloc(dp->hwnd, c->base_id+1);
+    ret = filename_from_str(tmp);
+    sfree(tmp);
+    return ret;
 }
 
 void dlg_fontsel_set(union control *ctrl, void *dlg, FontSpec *fs)