1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-02-09 16:36:34 +00:00

GTK 3 prep: stop using *nearly* all GTK deprecated functions.

Building with -DGTK_DISABLE_DEPRECATED, we now suffer only one compile
failure, for the use of gtk_quit_add() in idle_toplevel_callback_func.
That function is apparently removed with no replacement in GTK 3, so
I'll need to find a completely different approach to getting toplevel
callbacks to run only in the outermost instance of gtk_main().

Also, this change doesn't do anything about the use of *GDK*
deprecated functions, because those include the entire family of
old-style drawing functions - i.e. the only way to build cleanly with
-DGDK_DISABLE_DEPRECATED will be to switch to Cairo drawing.
This commit is contained in:
Simon Tatham 2015-08-08 18:02:01 +01:00
parent 5e55b7a978
commit 5fa22495c7
4 changed files with 53 additions and 37 deletions

View File

@ -38,6 +38,8 @@
#define GDK_GRAB_SUCCESS GrabSuccess #define GDK_GRAB_SUCCESS GrabSuccess
#define gtk_widget_set_size_request gtk_widget_set_usize #define gtk_widget_set_size_request gtk_widget_set_usize
#define gtk_radio_button_get_group gtk_radio_button_group
#define gtk_notebook_set_current_page gtk_notebook_set_page
#define gtk_dialog_get_content_area(dlg) ((dlg)->vbox) #define gtk_dialog_get_content_area(dlg) ((dlg)->vbox)
#define gtk_dialog_get_action_area(dlg) ((dlg)->action_area) #define gtk_dialog_get_action_area(dlg) ((dlg)->action_area)

View File

@ -330,12 +330,8 @@ char *dlg_editbox_get(union control *ctrl, void *dlg)
#if GTK_CHECK_VERSION(2,4,0) #if GTK_CHECK_VERSION(2,4,0)
if (uc->combo) { if (uc->combo) {
#if GTK_CHECK_VERSION(2,6,0)
return dupstr(gtk_combo_box_get_active_text(GTK_COMBO_BOX(uc->combo)));
#else
return dupstr(gtk_entry_get_text return dupstr(gtk_entry_get_text
(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(uc->combo))))); (GTK_ENTRY(gtk_bin_get_child(GTK_BIN(uc->combo)))));
#endif
} }
#endif #endif
@ -1038,6 +1034,7 @@ static void errmsg_button_clicked(GtkButton *button, gpointer data)
static void set_transient_window_pos(GtkWidget *parent, GtkWidget *child) static void set_transient_window_pos(GtkWidget *parent, GtkWidget *child)
{ {
#if !GTK_CHECK_VERSION(2,0,0)
gint x, y, w, h, dx, dy; gint x, y, w, h, dx, dy;
GtkRequisition req; GtkRequisition req;
gtk_window_set_position(GTK_WINDOW(child), GTK_WIN_POS_NONE); gtk_window_set_position(GTK_WINDOW(child), GTK_WIN_POS_NONE);
@ -1063,6 +1060,7 @@ static void set_transient_window_pos(GtkWidget *parent, GtkWidget *child)
else else
dy = y + 3*h/4 - req.height; /* work from bottom edges */ dy = y + 3*h/4 - req.height; /* work from bottom edges */
gtk_widget_set_uposition(GTK_WIDGET(child), dx, dy); gtk_widget_set_uposition(GTK_WIDGET(child), dx, dy);
#endif
} }
void dlg_error_msg(void *dlg, const char *msg) void dlg_error_msg(void *dlg, const char *msg)
@ -1802,7 +1800,7 @@ static void label_sizealloc(GtkWidget *widget, GtkAllocation *alloc,
struct dlgparam *dp = (struct dlgparam *)data; struct dlgparam *dp = (struct dlgparam *)data;
struct uctrl *uc = dlg_find_bywidget(dp, widget); struct uctrl *uc = dlg_find_bywidget(dp, widget);
gtk_widget_set_usize(uc->text, alloc->width, -1); gtk_widget_set_size_request(uc->text, alloc->width, -1);
gtk_label_set_text(GTK_LABEL(uc->text), uc->ctrl->generic.label); gtk_label_set_text(GTK_LABEL(uc->text), uc->ctrl->generic.label);
g_signal_handler_disconnect(G_OBJECT(uc->text), uc->textsig); g_signal_handler_disconnect(G_OBJECT(uc->text), uc->textsig);
} }
@ -1962,7 +1960,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
b = (gtk_radio_button_new_with_label b = (gtk_radio_button_new_with_label
(group, ctrl->radio.buttons[i])); (group, ctrl->radio.buttons[i]));
uc->buttons[i] = b; uc->buttons[i] = b;
group = gtk_radio_button_group(GTK_RADIO_BUTTON(b)); group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(b));
colstart = i % ctrl->radio.ncolumns; colstart = i % ctrl->radio.ncolumns;
columns_add(COLUMNS(w), b, colstart, columns_add(COLUMNS(w), b, colstart,
(i == ctrl->radio.nbuttons-1 ? (i == ctrl->radio.nbuttons-1 ?
@ -2002,8 +2000,8 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
*/ */
uc->listmodel = gtk_list_store_new(2, G_TYPE_INT, uc->listmodel = gtk_list_store_new(2, G_TYPE_INT,
G_TYPE_STRING); G_TYPE_STRING);
w = gtk_combo_box_entry_new_with_model w = gtk_combo_box_new_with_model_and_entry
(GTK_TREE_MODEL(uc->listmodel), 1); (GTK_TREE_MODEL(uc->listmodel));
/* We cannot support password combo boxes. */ /* We cannot support password combo boxes. */
assert(!ctrl->editbox.password); assert(!ctrl->editbox.password);
uc->combo = w; uc->combo = w;
@ -2038,7 +2036,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
* label vertically beside it. * label vertically beside it.
*/ */
gtk_widget_size_request(w, &req); gtk_widget_size_request(w, &req);
gtk_widget_set_usize(w, 10, req.height); gtk_widget_set_size_request(w, 10, req.height);
if (ctrl->generic.label) { if (ctrl->generic.label) {
GtkWidget *label, *container; GtkWidget *label, *container;
@ -2062,7 +2060,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
columns_force_left_align(COLUMNS(container), label); columns_force_left_align(COLUMNS(container), label);
columns_add(COLUMNS(container), w, 1, 1); columns_add(COLUMNS(container), w, 1, 1);
/* Centre the label vertically. */ /* Centre the label vertically. */
gtk_widget_set_usize(label, -1, req.height); gtk_widget_set_size_request(label, -1, req.height);
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
} }
gtk_widget_show(label); gtk_widget_show(label);
@ -2101,7 +2099,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
uc->entry = ww = gtk_entry_new(); uc->entry = ww = gtk_entry_new();
gtk_widget_size_request(ww, &req); gtk_widget_size_request(ww, &req);
gtk_widget_set_usize(ww, 10, req.height); gtk_widget_set_size_request(ww, 10, req.height);
columns_add(COLUMNS(w), ww, 0, 1); columns_add(COLUMNS(w), ww, 0, 1);
gtk_widget_show(ww); gtk_widget_show(ww);
@ -2246,7 +2244,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
{ {
int edge; int edge;
edge = GTK_WIDGET(uc->list)->style->klass->ythickness; edge = GTK_WIDGET(uc->list)->style->klass->ythickness;
gtk_widget_set_usize(w, 10, gtk_widget_set_size_request(w, 10,
2*edge + (ctrl->listbox.height * 2*edge + (ctrl->listbox.height *
get_listitemheight(w))); get_listitemheight(w)));
} }
@ -2388,7 +2386,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
columns_add(COLUMNS(container), w, 1, 1); columns_add(COLUMNS(container), w, 1, 1);
/* Centre the label vertically. */ /* Centre the label vertically. */
gtk_widget_size_request(w, &req); gtk_widget_size_request(w, &req);
gtk_widget_set_usize(label, -1, req.height); gtk_widget_set_size_request(label, -1, req.height);
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
} }
gtk_widget_show(label); gtk_widget_show(label);
@ -2480,7 +2478,7 @@ static void treeselection_changed(GtkTreeSelection *treeselection,
sp = &sps[spindex]; sp = &sps[spindex];
page_num = gtk_notebook_page_num(sp->panels, sp->panel); page_num = gtk_notebook_page_num(sp->panels, sp->panel);
gtk_notebook_set_page(sp->panels, page_num); gtk_notebook_set_current_page(sp->panels, page_num);
dlg_refresh(NULL, sp->dp); dlg_refresh(NULL, sp->dp);
@ -2740,10 +2738,20 @@ int tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
static void shortcut_highlight(GtkWidget *labelw, int chr) static void shortcut_highlight(GtkWidget *labelw, int chr)
{ {
GtkLabel *label = GTK_LABEL(labelw); GtkLabel *label = GTK_LABEL(labelw);
gchar *currstr, *pattern; const gchar *currstr;
gchar *pattern;
int i; int i;
gtk_label_get(label, &currstr); #if !GTK_CHECK_VERSION(2,0,0)
{
gchar *currstr_nonconst;
gtk_label_get(label, &currstr_nonconst);
currstr = currstr_nonconst;
}
#else
currstr = gtk_label_get_text(label);
#endif
for (i = 0; currstr[i]; i++) for (i = 0; currstr[i]; i++)
if (tolower((unsigned char)currstr[i]) == chr) { if (tolower((unsigned char)currstr[i]) == chr) {
GtkRequisition req; GtkRequisition req;
@ -2752,7 +2760,7 @@ static void shortcut_highlight(GtkWidget *labelw, int chr)
gtk_widget_size_request(GTK_WIDGET(label), &req); gtk_widget_size_request(GTK_WIDGET(label), &req);
gtk_label_set_pattern(label, pattern); gtk_label_set_pattern(label, pattern);
gtk_widget_set_usize(GTK_WIDGET(label), -1, req.height); gtk_widget_set_size_request(GTK_WIDGET(label), -1, req.height);
sfree(pattern); sfree(pattern);
break; break;
@ -2866,7 +2874,7 @@ void set_dialog_action_area(GtkDialog *dlg, GtkWidget *w)
w, FALSE, TRUE, 0); w, FALSE, TRUE, 0);
gtk_widget_show(w); gtk_widget_show(w);
gtk_widget_hide(gtk_dialog_get_action_area(dlg)); gtk_widget_hide(gtk_dialog_get_action_area(dlg));
gtk_dialog_set_has_separator(dlg, FALSE); g_object_set(G_OBJECT(dlg), "has-separator", TRUE, (const char *)NULL);
#endif #endif
} }
@ -3009,7 +3017,8 @@ int do_config_box(const char *title, Conf *conf, int midsession,
page_num = gtk_notebook_page_num(GTK_NOTEBOOK(panels), page_num = gtk_notebook_page_num(GTK_NOTEBOOK(panels),
panelvbox); panelvbox);
gtk_notebook_set_page(GTK_NOTEBOOK(panels), page_num); gtk_notebook_set_current_page(GTK_NOTEBOOK(panels),
page_num);
} }
if (nselparams >= selparamsize) { if (nselparams >= selparamsize) {
@ -3283,7 +3292,7 @@ int messagebox(GtkWidget *parentwin, const char *title, const char *msg,
gtk_widget_show(w0); gtk_widget_show(w0);
w1 = layout_ctrls(&dp, &scs, s1, GTK_WINDOW(window)); w1 = layout_ctrls(&dp, &scs, s1, GTK_WINDOW(window));
gtk_container_set_border_width(GTK_CONTAINER(w1), 10); gtk_container_set_border_width(GTK_CONTAINER(w1), 10);
gtk_widget_set_usize(w1, minwid+20, -1); gtk_widget_set_size_request(w1, minwid+20, -1);
gtk_box_pack_start gtk_box_pack_start
(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(window))), (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(window))),
w1, TRUE, TRUE, 0); w1, TRUE, TRUE, 0);
@ -3757,10 +3766,10 @@ void showeventlog(void *estuff, void *parentwin)
gtk_widget_show(w0); gtk_widget_show(w0);
w1 = layout_ctrls(&es->dp, &es->scs, s1, GTK_WINDOW(window)); w1 = layout_ctrls(&es->dp, &es->scs, s1, GTK_WINDOW(window));
gtk_container_set_border_width(GTK_CONTAINER(w1), 10); gtk_container_set_border_width(GTK_CONTAINER(w1), 10);
gtk_widget_set_usize(w1, 20 + gtk_widget_set_size_request(w1, 20 + string_width
string_width("LINE OF TEXT GIVING WIDTH OF EVENT LOG" ("LINE OF TEXT GIVING WIDTH OF EVENT LOG IS "
" IS QUITE LONG 'COS SSH LOG ENTRIES" "QUITE LONG 'COS SSH LOG ENTRIES ARE WIDE"),
" ARE WIDE"), -1); -1);
gtk_box_pack_start gtk_box_pack_start
(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(window))), (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(window))),
w1, TRUE, TRUE, 0); w1, TRUE, TRUE, 0);

View File

@ -2190,7 +2190,8 @@ static void unifontsel_select_font(unifontsel_internal *fs,
* Grey out the font size edit box if we're not using a * Grey out the font size edit box if we're not using a
* scalable font. * scalable font.
*/ */
gtk_entry_set_editable(GTK_ENTRY(fs->size_entry), fs->selected->size == 0); gtk_editable_set_editable(GTK_EDITABLE(fs->size_entry),
fs->selected->size == 0);
gtk_widget_set_sensitive(fs->size_entry, fs->selected->size == 0); gtk_widget_set_sensitive(fs->size_entry, fs->selected->size == 0);
unifontsel_draw_preview_text(fs); unifontsel_draw_preview_text(fs);

View File

@ -1476,7 +1476,7 @@ static gint idle_toplevel_callback_func(gpointer data)
* can reschedule us with a chance of actually taking action. * can reschedule us with a chance of actually taking action.
*/ */
if (inst->idle_fn_scheduled) { /* double-check, just in case */ if (inst->idle_fn_scheduled) { /* double-check, just in case */
gtk_idle_remove(inst->toplevel_callback_idle_id); g_source_remove(inst->toplevel_callback_idle_id);
inst->idle_fn_scheduled = FALSE; inst->idle_fn_scheduled = FALSE;
} }
} else { } else {
@ -1490,7 +1490,7 @@ static gint idle_toplevel_callback_func(gpointer data)
* event loop. * event loop.
*/ */
if (!toplevel_callback_pending() && inst->idle_fn_scheduled) { if (!toplevel_callback_pending() && inst->idle_fn_scheduled) {
gtk_idle_remove(inst->toplevel_callback_idle_id); g_source_remove(inst->toplevel_callback_idle_id);
inst->idle_fn_scheduled = FALSE; inst->idle_fn_scheduled = FALSE;
} }
@ -1503,7 +1503,7 @@ static void notify_toplevel_callback(void *frontend)
if (!inst->idle_fn_scheduled) { if (!inst->idle_fn_scheduled) {
inst->toplevel_callback_idle_id = inst->toplevel_callback_idle_id =
gtk_idle_add(idle_toplevel_callback_func, inst); g_idle_add(idle_toplevel_callback_func, inst);
inst->idle_fn_scheduled = TRUE; inst->idle_fn_scheduled = TRUE;
} }
} }
@ -1518,7 +1518,7 @@ static gint timer_trigger(gpointer data)
* Destroy the timer we got here on. * Destroy the timer we got here on.
*/ */
if (timer_id) { if (timer_id) {
gtk_timeout_remove(timer_id); g_source_remove(timer_id);
timer_id = 0; timer_id = 0;
} }
@ -1535,8 +1535,7 @@ static gint timer_trigger(gpointer data)
ticks = 0; ticks = 0;
else else
ticks = next - now; ticks = next - now;
timer_id = gtk_timeout_add(ticks, timer_trigger, timer_id = g_timeout_add(ticks, timer_trigger, LONG_TO_GPOINTER(next));
LONG_TO_GPOINTER(next));
} }
/* /*
@ -1552,14 +1551,13 @@ void timer_change_notify(unsigned long next)
long ticks; long ticks;
if (timer_id) if (timer_id)
gtk_timeout_remove(timer_id); g_source_remove(timer_id);
ticks = next - GETTICKCOUNT(); ticks = next - GETTICKCOUNT();
if (ticks <= 0) if (ticks <= 0)
ticks = 1; /* just in case */ ticks = 1; /* just in case */
timer_id = gtk_timeout_add(ticks, timer_trigger, timer_id = g_timeout_add(ticks, timer_trigger, LONG_TO_GPOINTER(next));
LONG_TO_GPOINTER(next));
} }
void fd_input_func(gpointer data, gint sourcefd, GdkInputCondition condition) void fd_input_func(gpointer data, gint sourcefd, GdkInputCondition condition)
@ -3820,9 +3818,15 @@ int pt_main(int argc, char **argv)
inst->height = conf_get_int(inst->conf, CONF_height); inst->height = conf_get_int(inst->conf, CONF_height);
cache_conf_values(inst); cache_conf_values(inst);
gtk_drawing_area_size(GTK_DRAWING_AREA(inst->area), {
inst->font_width * inst->width + 2*inst->window_border, int w = inst->font_width * inst->width + 2*inst->window_border;
inst->font_height * inst->height + 2*inst->window_border); int h = inst->font_height * inst->height + 2*inst->window_border;
#if GTK_CHECK_VERSION(2,0,0)
gtk_widget_set_size_request(inst->area, w, h);
#else
gtk_drawing_area_size(GTK_DRAWING_AREA(inst->area), w, h);
#endif
}
inst->sbar_adjust = GTK_ADJUSTMENT(gtk_adjustment_new(0,0,0,0,0,0)); inst->sbar_adjust = GTK_ADJUSTMENT(gtk_adjustment_new(0,0,0,0,0,0));
inst->sbar = gtk_vscrollbar_new(inst->sbar_adjust); inst->sbar = gtk_vscrollbar_new(inst->sbar_adjust);
inst->hbox = GTK_BOX(gtk_hbox_new(FALSE, 0)); inst->hbox = GTK_BOX(gtk_hbox_new(FALSE, 0));