]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - unix/gtkdlg.c
Giant const-correctness patch of doom!
[PuTTY.git] / unix / gtkdlg.c
index a2d4992e1bef9f3fe120f99f474378c8d2d775f7..6c532024c488febf3b6784ad4d064f1a3d5cf00a 100644 (file)
@@ -37,8 +37,6 @@ struct Shortcuts {
 struct uctrl {
     union control *ctrl;
     GtkWidget *toplevel;
-    void *privdata;
-    int privdata_needs_free;
     GtkWidget **buttons; int nbuttons; /* for radio buttons */
     GtkWidget *entry;         /* for editbox, filesel, fontsel */
     GtkWidget *button;        /* for filesel, fontsel */
@@ -189,8 +187,6 @@ static void dlg_cleanup(struct dlgparam *dp)
     dp->byctrl = NULL;
     while ( (uc = index234(dp->bywidget, 0)) != NULL) {
        del234(dp->bywidget, uc);
-       if (uc->privdata_needs_free)
-           sfree(uc->privdata);
        sfree(uc->buttons);
        sfree(uc);
     }
@@ -228,34 +224,6 @@ static struct uctrl *dlg_find_bywidget(struct dlgparam *dp, GtkWidget *w)
     return ret;
 }
 
-void *dlg_get_privdata(union control *ctrl, void *dlg)
-{
-    struct dlgparam *dp = (struct dlgparam *)dlg;
-    struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
-    return uc->privdata;
-}
-
-void dlg_set_privdata(union control *ctrl, void *dlg, void *ptr)
-{
-    struct dlgparam *dp = (struct dlgparam *)dlg;
-    struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
-    uc->privdata = ptr;
-    uc->privdata_needs_free = FALSE;
-}
-
-void *dlg_alloc_privdata(union control *ctrl, void *dlg, size_t size)
-{
-    struct dlgparam *dp = (struct dlgparam *)dlg;
-    struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
-    /*
-     * This is an internal allocation routine, so it's allowed to
-     * use smalloc directly.
-     */
-    uc->privdata = smalloc(size);
-    uc->privdata_needs_free = FALSE;
-    return uc->privdata;
-}
-
 union control *dlg_last_focused(union control *ctrl, void *dlg)
 {
     struct dlgparam *dp = (struct dlgparam *)dlg;
@@ -330,11 +298,10 @@ void dlg_editbox_set(union control *ctrl, void *dlg, char const *text)
      * The first call to "changed", if allowed to proceed normally,
      * will cause an EVENT_VALCHANGE event on the edit box, causing
      * a call to dlg_editbox_get() which will read the empty string
-     * out of the GtkEntry - and promptly write it straight into
-     * the Config structure, which is precisely where our `text'
-     * pointer is probably pointing, so the second editing
-     * operation will insert that instead of the string we
-     * originally asked for.
+     * out of the GtkEntry - and promptly write it straight into the
+     * Conf structure, which is precisely where our `text' pointer
+     * is probably pointing, so the second editing operation will
+     * insert that instead of the string we originally asked for.
      *
      * Hence, we must take our own copy of the text before we do
      * this.
@@ -344,7 +311,7 @@ void dlg_editbox_set(union control *ctrl, void *dlg, char const *text)
     sfree(tmpstring);
 }
 
-void dlg_editbox_get(union control *ctrl, void *dlg, char *buffer, int length)
+char *dlg_editbox_get(union control *ctrl, void *dlg)
 {
     struct dlgparam *dp = (struct dlgparam *)dlg;
     struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
@@ -353,25 +320,16 @@ void dlg_editbox_get(union control *ctrl, void *dlg, char *buffer, int length)
 #if GTK_CHECK_VERSION(2,4,0)
     if (uc->combo) {
 #if GTK_CHECK_VERSION(2,6,0)
-       strncpy(buffer,
-               gtk_combo_box_get_active_text(GTK_COMBO_BOX(uc->combo)),
-               length);
+       return dupstr(gtk_combo_box_get_active_text(GTK_COMBO_BOX(uc->combo)));
 #else
-       strncpy(buffer,
-               gtk_entry_get_text
-               (GTK_ENTRY(gtk_bin_get_child(GTK_BIN(uc->combo)))),
-               length);
+       return dupstr(gtk_entry_get_text
+                     (GTK_ENTRY(gtk_bin_get_child(GTK_BIN(uc->combo)))));
 #endif
-       buffer[length-1] = '\0';
-       return;
     }
 #endif
 
     if (uc->entry) {
-       strncpy(buffer, gtk_entry_get_text(GTK_ENTRY(uc->entry)),
-               length);
-       buffer[length-1] = '\0';
-       return;
+       return dupstr(gtk_entry_get_text(GTK_ENTRY(uc->entry)));
     }
 
     assert(!"We shouldn't get here");
@@ -916,44 +874,48 @@ 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 uctrl *uc = dlg_find_byctrl(dp, ctrl);
+    /* We must copy fn->path before passing it to gtk_entry_set_text.
+     * See comment in dlg_editbox_set() for the reasons. */
+    char *duppath = dupstr(fn->path);
     assert(uc->ctrl->generic.type == CTRL_FILESELECT);
     assert(uc->entry != NULL);
-    gtk_entry_set_text(GTK_ENTRY(uc->entry), fn.path);
+    gtk_entry_set_text(GTK_ENTRY(uc->entry), duppath);
+    sfree(duppath);
 }
 
-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 uctrl *uc = dlg_find_byctrl(dp, ctrl);
     assert(uc->ctrl->generic.type == CTRL_FILESELECT);
     assert(uc->entry != NULL);
-    strncpy(fn->path, gtk_entry_get_text(GTK_ENTRY(uc->entry)),
-           lenof(fn->path));
-    fn->path[lenof(fn->path)-1] = '\0';
+    return filename_from_str(gtk_entry_get_text(GTK_ENTRY(uc->entry)));
 }
 
-void dlg_fontsel_set(union control *ctrl, void *dlg, FontSpec fs)
+void dlg_fontsel_set(union control *ctrl, void *dlg, FontSpec *fs)
 {
     struct dlgparam *dp = (struct dlgparam *)dlg;
     struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
+    /* We must copy fs->name before passing it to gtk_entry_set_text.
+     * See comment in dlg_editbox_set() for the reasons. */
+    char *dupname = dupstr(fs->name);
     assert(uc->ctrl->generic.type == CTRL_FONTSELECT);
     assert(uc->entry != NULL);
-    gtk_entry_set_text(GTK_ENTRY(uc->entry), fs.name);
+    gtk_entry_set_text(GTK_ENTRY(uc->entry), dupname);
+    sfree(dupname);
 }
 
-void dlg_fontsel_get(union control *ctrl, void *dlg, FontSpec *fs)
+FontSpec *dlg_fontsel_get(union control *ctrl, void *dlg)
 {
     struct dlgparam *dp = (struct dlgparam *)dlg;
     struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
     assert(uc->ctrl->generic.type == CTRL_FONTSELECT);
     assert(uc->entry != NULL);
-    strncpy(fs->name, gtk_entry_get_text(GTK_ENTRY(uc->entry)),
-           lenof(fs->name));
-    fs->name[lenof(fs->name)-1] = '\0';
+    return fontspec_new(gtk_entry_get_text(GTK_ENTRY(uc->entry)));
 }
 
 /*
@@ -1093,7 +1055,7 @@ static void set_transient_window_pos(GtkWidget *parent, GtkWidget *child)
     gtk_widget_set_uposition(GTK_WIDGET(child), dx, dy);
 }
 
-void dlg_error_msg(void *dlg, char *msg)
+void dlg_error_msg(void *dlg, const char *msg)
 {
     struct dlgparam *dp = (struct dlgparam *)dlg;
     GtkWidget *window, *hbox, *text, *ok;
@@ -1838,8 +1800,6 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
 
        uc = snew(struct uctrl);
        uc->ctrl = ctrl;
-       uc->privdata = NULL;
-       uc->privdata_needs_free = FALSE;
        uc->buttons = NULL;
        uc->entry = NULL;
 #if !GTK_CHECK_VERSION(2,4,0)
@@ -2038,7 +1998,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
             {
                 GtkWidget *ww;
                 GtkRequisition req;
-                char *browsebtn =
+                const char *browsebtn =
                     (ctrl->generic.type == CTRL_FILESELECT ?
                      "Browse..." : "Change...");
 
@@ -2282,15 +2242,22 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
                    cols = cols ? cols : 1;
                    for (i = 0; i < cols; i++) {
                        GtkTreeViewColumn *column;
+                        GtkCellRenderer *cellrend;
                        /*
                         * It appears that GTK 2 doesn't leave us any
                         * particularly sensible way to honour the
                         * "percentages" specification in the ctrl
                         * structure.
                         */
+                        cellrend = gtk_cell_renderer_text_new();
+                        if (!ctrl->listbox.hscroll) {
+                            gtk_object_set(GTK_OBJECT(cellrend),
+                                           "ellipsize", PANGO_ELLIPSIZE_END,
+                                           "ellipsize-set", TRUE,
+                                           NULL);
+                        }
                        column = gtk_tree_view_column_new_with_attributes
-                           ("heading", gtk_cell_renderer_text_new(),
-                            "text", i+1, (char *)NULL);
+                           ("heading", cellrend, "text", i+1, (char *)NULL);
                        gtk_tree_view_column_set_sizing
                            (column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
                        gtk_tree_view_append_column(GTK_TREE_VIEW(w), column);
@@ -2826,12 +2793,12 @@ void set_dialog_action_area(GtkDialog *dlg, GtkWidget *w)
 #endif
 }
 
-int do_config_box(const char *title, Config *cfg, int midsession,
+int do_config_box(const char *title, Conf *conf, int midsession,
                  int protcfginfo)
 {
     GtkWidget *window, *hbox, *vbox, *cols, *label,
        *tree, *treescroll, *panels, *panelvbox;
-    int index, level;
+    int index, level, protocol;
     struct controlbox *ctrlbox;
     char *path;
 #if GTK_CHECK_VERSION(2,0,0)
@@ -2859,8 +2826,9 @@ int do_config_box(const char *title, Config *cfg, int midsession,
     window = gtk_dialog_new();
 
     ctrlbox = ctrl_new_box();
-    setup_config_box(ctrlbox, midsession, cfg->protocol, protcfginfo);
-    unix_setup_config_box(ctrlbox, midsession, cfg->protocol);
+    protocol = conf_get_int(conf, CONF_protocol);
+    setup_config_box(ctrlbox, midsession, protocol, protcfginfo);
+    unix_setup_config_box(ctrlbox, midsession, protocol);
     gtk_setup_config_box(ctrlbox, midsession, window);
 
     gtk_window_set_title(GTK_WINDOW(window), title);
@@ -3095,7 +3063,7 @@ int do_config_box(const char *title, Config *cfg, int midsession,
     }
 #endif
 
-    dp.data = cfg;
+    dp.data = conf;
     dlg_refresh(NULL, &dp);
 
     dp.shortcuts = &selparams[0].shortcuts;
@@ -3170,7 +3138,8 @@ static void messagebox_handler(union control *ctrl, void *dlg,
     if (event == EVENT_ACTION)
        dlg_end(dlg, ctrl->generic.context.i);
 }
-int messagebox(GtkWidget *parentwin, char *title, char *msg, int minwid, ...)
+int messagebox(GtkWidget *parentwin, const char *title, const char *msg,
+               int minwid, ...)
 {
     GtkWidget *window, *w0, *w1;
     struct controlbox *ctrlbox;
@@ -3267,7 +3236,7 @@ int messagebox(GtkWidget *parentwin, char *title, char *msg, int minwid, ...)
     return dp.retval;
 }
 
-static int string_width(char *text)
+int string_width(const char *text)
 {
     GtkWidget *label = gtk_label_new(text);
     GtkRequisition req;
@@ -3289,8 +3258,8 @@ int reallyclose(void *frontend)
     return ret;
 }
 
-int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype,
-                        char *keystr, char *fingerprint,
+int verify_ssh_host_key(void *frontend, char *host, int port,
+                        const char *keytype, char *keystr, char *fingerprint,
                         void (*callback)(void *ctx, int result), void *ctx)
 {
     static const char absenttxt[] =
@@ -3387,14 +3356,21 @@ void old_keyfile_warning(void)
      */
 }
 
-void fatal_message_box(void *window, char *msg)
+void fatal_message_box(void *window, const char *msg)
 {
     messagebox(window, "PuTTY Fatal Error", msg,
                string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"),
                "OK", 'o', 1, 1, NULL);
 }
 
-void fatalbox(char *p, ...)
+void nonfatal_message_box(void *window, const char *msg)
+{
+    messagebox(window, "PuTTY Error", msg,
+               string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"),
+               "OK", 'o', 1, 1, NULL);
+}
+
+void fatalbox(const char *p, ...)
 {
     va_list ap;
     char *msg;
@@ -3406,6 +3382,17 @@ void fatalbox(char *p, ...)
     cleanup_exit(1);
 }
 
+void nonfatal(const char *p, ...)
+{
+    va_list ap;
+    char *msg;
+    va_start(ap, p);
+    msg = dupvprintf(p, ap);
+    va_end(ap);
+    nonfatal_message_box(NULL, msg);
+    sfree(msg);
+}
+
 static GtkWidget *aboutbox = NULL;
 
 static void about_close_clicked(GtkButton *button, gpointer data)
@@ -3418,13 +3405,13 @@ static void licence_clicked(GtkButton *button, gpointer data)
 {
     char *title;
 
-    char *licence =
-       "Copyright 1997-2010 Simon Tatham.\n\n"
+    const char *licence =
+       "Copyright 1997-2015 Simon Tatham.\n\n"
 
        "Portions copyright Robert de Bath, Joris van Rantwijk, Delian "
        "Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas "
        "Barry, Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, "
-       "Markus Kuhn, Colin Watson, and CORE SDI S.A.\n\n"
+       "Markus Kuhn, Colin Watson, Christopher Staite, and CORE SDI S.A.\n\n"
 
        "Permission is hereby granted, free of charge, to any person "
        "obtaining a copy of this software and associated documentation "
@@ -3500,7 +3487,7 @@ void about_box(void *window)
                       w, FALSE, FALSE, 5);
     gtk_widget_show(w);
 
-    w = gtk_label_new("Copyright 1997-2010 Simon Tatham. All rights reserved");
+    w = gtk_label_new("Copyright 1997-2015 Simon Tatham. All rights reserved");
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(aboutbox)->vbox),
                       w, FALSE, FALSE, 5);
     gtk_widget_show(w);
@@ -3530,6 +3517,7 @@ static void eventlog_destroy(GtkWidget *widget, gpointer data)
 
     es->window = NULL;
     sfree(es->seldata);
+    es->seldata = NULL;
     dlg_cleanup(&es->dp);
     ctrl_free_box(es->eventbox);
 }
@@ -3752,7 +3740,7 @@ void logevent_dlg(void *estuff, const char *string)
     es->nevents++;
 }
 
-int askappend(void *frontend, Filename filename,
+int askappend(void *frontend, Filename *filename,
              void (*callback)(void *ctx, int result), void *ctx)
 {
     static const char msgtemplate[] =
@@ -3764,7 +3752,7 @@ int askappend(void *frontend, Filename filename,
     char *mbtitle;
     int mbret;
 
-    message = dupprintf(msgtemplate, FILENAME_MAX, filename.path);
+    message = dupprintf(msgtemplate, FILENAME_MAX, filename->path);
     mbtitle = dupprintf("%s Log to File", appname);
 
     mbret = messagebox(get_window(frontend), mbtitle, message,