From 0a3e5939597ada7509445cfe2caa28f16ec2459e Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 8 Aug 2015 15:53:43 +0100 Subject: [PATCH] GTK 3 prep: use accessor functions for object data fields. We now build cleanly in GTK2 with -DGSEAL_ENABLE. --- unix/gtkask.c | 10 ++-- unix/gtkcols.c | 40 +++++++------- unix/gtkcompat.h | 44 ++++++++++++++- unix/gtkdlg.c | 117 +++++++++++++++++++++++---------------- unix/gtkfont.c | 16 ++++-- unix/gtkwin.c | 140 ++++++++++++++++++++++++++--------------------- 6 files changed, 229 insertions(+), 138 deletions(-) diff --git a/unix/gtkask.c b/unix/gtkask.c index 38946842..69e609bf 100644 --- a/unix/gtkask.c +++ b/unix/gtkask.c @@ -167,9 +167,9 @@ static gint expose_area(GtkWidget *widget, GdkEventExpose *event, { struct drawing_area_ctx *ctx = (struct drawing_area_ctx *)data; - GdkGC *gc = gdk_gc_new(ctx->area->window); + GdkGC *gc = gdk_gc_new(gtk_widget_get_window(ctx->area)); gdk_gc_set_foreground(gc, &ctx->cols[ctx->current]); - gdk_draw_rectangle(widget->window, gc, TRUE, + gdk_draw_rectangle(gtk_widget_get_window(widget), gc, TRUE, 0, 0, ctx->width, ctx->height); gdk_gc_unref(gc); return TRUE; @@ -177,7 +177,8 @@ static gint expose_area(GtkWidget *widget, GdkEventExpose *event, static int try_grab_keyboard(struct askpass_ctx *ctx) { - int ret = gdk_keyboard_grab(ctx->dialog->window, FALSE, GDK_CURRENT_TIME); + int ret = gdk_keyboard_grab(gtk_widget_get_window(ctx->dialog), + FALSE, GDK_CURRENT_TIME); return ret == GDK_GRAB_SUCCESS; } @@ -302,7 +303,8 @@ static const char *gtk_askpass_setup(struct askpass_ctx *ctx, gtk_signal_connect(GTK_OBJECT(ctx->promptlabel), "key_release_event", GTK_SIGNAL_FUNC(key_event), ctx); #if GTK_CHECK_VERSION(2,0,0) - gtk_im_context_set_client_window(ctx->imc, ctx->dialog->window); + gtk_im_context_set_client_window(ctx->imc, + gtk_widget_get_window(ctx->dialog)); #endif gtk_widget_show(ctx->promptlabel); diff --git a/unix/gtkcols.c b/unix/gtkcols.c index 8cb5d14f..591cefc6 100644 --- a/unix/gtkcols.c +++ b/unix/gtkcols.c @@ -4,6 +4,7 @@ #include "gtkcols.h" #include +#include "gtkcompat.h" static void columns_init(Columns *cols); static void columns_class_init(ColumnsClass *klass); @@ -120,7 +121,7 @@ static void columns_class_init(ColumnsClass *klass) static void columns_init(Columns *cols) { - GTK_WIDGET_SET_FLAGS(cols, GTK_NO_WINDOW); + gtk_widget_set_has_window(GTK_WIDGET(cols), FALSE); cols->children = NULL; cols->spacing = 0; @@ -141,14 +142,14 @@ static void columns_map(GtkWidget *widget) g_return_if_fail(IS_COLUMNS(widget)); cols = COLUMNS(widget); - GTK_WIDGET_SET_FLAGS(cols, GTK_MAPPED); + gtk_widget_set_mapped(GTK_WIDGET(cols), TRUE); for (children = cols->children; children && (child = children->data); children = children->next) { if (child->widget && - GTK_WIDGET_VISIBLE(child->widget) && - !GTK_WIDGET_MAPPED(child->widget)) + gtk_widget_get_visible(child->widget) && + !gtk_widget_get_mapped(child->widget)) gtk_widget_map(child->widget); } } @@ -162,14 +163,14 @@ static void columns_unmap(GtkWidget *widget) g_return_if_fail(IS_COLUMNS(widget)); cols = COLUMNS(widget); - GTK_WIDGET_UNSET_FLAGS(cols, GTK_MAPPED); + gtk_widget_set_mapped(GTK_WIDGET(cols), FALSE); for (children = cols->children; children && (child = children->data); children = children->next) { if (child->widget && - GTK_WIDGET_VISIBLE(child->widget) && - GTK_WIDGET_MAPPED(child->widget)) + gtk_widget_get_visible(child->widget) && + gtk_widget_get_mapped(child->widget)) gtk_widget_unmap(child->widget); } } @@ -263,7 +264,7 @@ static void columns_remove(GtkContainer *container, GtkWidget *widget) if (child->widget != widget) continue; - was_visible = GTK_WIDGET_VISIBLE(widget); + was_visible = gtk_widget_get_visible(widget); gtk_widget_unparent(widget); cols->children = g_list_remove_link(cols->children, children); g_list_free(children); @@ -367,7 +368,7 @@ void columns_add(Columns *cols, GtkWidget *child, g_return_if_fail(cols != NULL); g_return_if_fail(IS_COLUMNS(cols)); g_return_if_fail(child != NULL); - g_return_if_fail(child->parent == NULL); + g_return_if_fail(gtk_widget_get_parent(child) == NULL); childdata = g_new(ColumnsChild, 1); childdata->widget = child; @@ -384,11 +385,12 @@ void columns_add(Columns *cols, GtkWidget *child, gtk_container_set_focus_chain(GTK_CONTAINER(cols), cols->taborder); #endif - if (GTK_WIDGET_REALIZED(cols)) + if (gtk_widget_get_realized(GTK_WIDGET(cols))) gtk_widget_realize(child); - if (GTK_WIDGET_VISIBLE(cols) && GTK_WIDGET_VISIBLE(child)) { - if (GTK_WIDGET_MAPPED(cols)) + if (gtk_widget_get_visible(GTK_WIDGET(cols)) && + gtk_widget_get_visible(child)) { + if (gtk_widget_get_mapped(GTK_WIDGET(cols))) gtk_widget_map(child); gtk_widget_queue_resize(child); } @@ -410,7 +412,7 @@ void columns_force_left_align(Columns *cols, GtkWidget *widget) continue; child->force_left = TRUE; - if (GTK_WIDGET_VISIBLE(widget)) + if (gtk_widget_get_visible(widget)) gtk_widget_queue_resize(GTK_WIDGET(cols)); break; } @@ -565,7 +567,7 @@ static void columns_size_request(GtkWidget *widget, GtkRequisition *req) } /* Only take visible widgets into account. */ - if (!GTK_WIDGET_VISIBLE(child->widget)) + if (!gtk_widget_get_visible(child->widget)) continue; gtk_widget_size_request(child->widget, &creq); @@ -634,8 +636,8 @@ static void columns_size_request(GtkWidget *widget, GtkRequisition *req) } } - req->width += 2*GTK_CONTAINER(cols)->border_width; - req->height += 2*GTK_CONTAINER(cols)->border_width; + req->width += 2*gtk_container_get_border_width(GTK_CONTAINER(cols)); + req->height += 2*gtk_container_get_border_width(GTK_CONTAINER(cols)); g_free(colypos); } @@ -654,8 +656,8 @@ static void columns_size_allocate(GtkWidget *widget, GtkAllocation *alloc) g_return_if_fail(alloc != NULL); cols = COLUMNS(widget); - widget->allocation = *alloc; - border = GTK_CONTAINER(cols)->border_width; + gtk_widget_set_allocation(widget, alloc); + border = gtk_container_get_border_width(GTK_CONTAINER(cols)); ncols = 1; percentages = onecol; @@ -701,7 +703,7 @@ static void columns_size_allocate(GtkWidget *widget, GtkAllocation *alloc) } /* Only take visible widgets into account. */ - if (!GTK_WIDGET_VISIBLE(child->widget)) + if (!gtk_widget_get_visible(child->widget)) continue; gtk_widget_get_child_requisition(child->widget, &creq); diff --git a/unix/gtkcompat.h b/unix/gtkcompat.h index 501107c5..d6cf7998 100644 --- a/unix/gtkcompat.h +++ b/unix/gtkcompat.h @@ -9,14 +9,56 @@ #include #include +/* Helper macro used in definitions below. Note that although it + * *expands* w and flag twice, it does not *evaluate* them twice + * because the evaluations are in exclusive branches of ?:. So it's + * a side-effect-safe macro. */ +#define gtk1_widget_set_unset_flag(w, flag, b) \ + ((b) ? GTK_WIDGET_SET_FLAGS(w, flag) : GTK_WIDGET_UNSET_FLAGS(w, flag)) + #define G_CALLBACK(x) GTK_SIGNAL_FUNC(x) #define G_OBJECT(x) GTK_OBJECT(x) + #define g_ascii_isspace(x) (isspace((unsigned char)(x))) #define g_signal_connect gtk_signal_connect +#define g_object_set_data gtk_object_set_data + #define GDK_GRAB_SUCCESS GrabSuccess + +#define gtk_widget_set_size_request gtk_widget_set_usize + #define gtk_dialog_get_content_area(dlg) ((dlg)->vbox) #define gtk_dialog_get_action_area(dlg) ((dlg)->action_area) -#define gtk_widget_set_size_request gtk_widget_set_usize +#define gtk_dialog_set_can_default(dlg) ((dlg)->action_area) +#define gtk_widget_get_window(w) ((w)->window) +#define gtk_widget_get_parent(w) ((w)->parent) +#define gtk_widget_set_allocation(w, a) ((w)->allocation = *(a)) +#define gtk_container_get_border_width(c) ((c)->border_width) +#define gtk_bin_get_child(b) ((b)->child) +#define gtk_color_selection_dialog_get_color_selection(cs) ((cs)->colorsel) +#define gtk_selection_data_get_target(sd) ((sd)->target) +#define gtk_selection_data_get_data_type(sd) ((sd)->type) +#define gtk_selection_data_get_data(sd) ((sd)->data) +#define gtk_selection_data_get_length(sd) ((sd)->length) +#define gtk_selection_data_get_format(sd) ((sd)->format) +#define gtk_adjustment_set_lower(a, val) ((a)->lower = (val)) +#define gtk_adjustment_set_upper(a, val) ((a)->upper = (val)) +#define gtk_adjustment_set_page_size(a, val) ((a)->page_size = (val)) +#define gtk_adjustment_set_page_increment(a, val) ((a)->page_increment = (val)) +#define gtk_adjustment_set_step_increment(a, val) ((a)->step_increment = (val)) +#define gtk_adjustment_get_value(a) ((a)->value) +#define gdk_visual_get_depth(v) ((v)->depth) + +#define gtk_widget_set_has_window(w, b) \ + gtk1_widget_set_unset_flag(w, GTK_NO_WINDOW, !(b)) +#define gtk_widget_set_mapped(w, b) \ + gtk1_widget_set_unset_flag(w, GTK_MAPPED, (b)) +#define gtk_widget_set_can_default(w, b) \ + gtk1_widget_set_unset_flag(w, GTK_CAN_DEFAULT, (b)) +#define gtk_widget_get_visible(w) GTK_WIDGET_VISIBLE(w) +#define gtk_widget_get_mapped(w) GTK_WIDGET_MAPPED(w) +#define gtk_widget_get_realized(w) GTK_WIDGET_REALIZED(w) +#define gtk_widget_get_state(w) GTK_WIDGET_STATE(w) #endif diff --git a/unix/gtkdlg.c b/unix/gtkdlg.c index 282396e6..9a492408 100644 --- a/unix/gtkdlg.c +++ b/unix/gtkdlg.c @@ -14,6 +14,8 @@ #include #include +#include "gtkcompat.h" + #include "gtkcols.h" #include "gtkfont.h" @@ -221,7 +223,7 @@ static struct uctrl *dlg_find_bywidget(struct dlgparam *dp, GtkWidget *w) ret = find234(dp->bywidget, w, uctrl_cmp_bywidget_find); if (ret) return ret; - w = w->parent; + w = gtk_widget_get_parent(w); } while (w); return ret; } @@ -1035,8 +1037,8 @@ static void set_transient_window_pos(GtkWidget *parent, GtkWidget *child) gtk_window_set_position(GTK_WINDOW(child), GTK_WIN_POS_NONE); gtk_widget_size_request(GTK_WIDGET(child), &req); - gdk_window_get_origin(GTK_WIDGET(parent)->window, &x, &y); - gdk_window_get_size(GTK_WIDGET(parent)->window, &w, &h); + gdk_window_get_origin(gtk_widget_get_window(GTK_WIDGET(parent)), &x, &y); + gdk_window_get_size(gtk_widget_get_window(GTK_WIDGET(parent)), &w, &h); /* * One corner of the transient will be offset inwards, by 1/4 @@ -1067,17 +1069,17 @@ void dlg_error_msg(void *dlg, const char *msg) gtk_misc_set_alignment(GTK_MISC(text), 0.0, 0.0); hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), text, FALSE, FALSE, 20); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(window))), hbox, FALSE, FALSE, 20); gtk_widget_show(text); gtk_widget_show(hbox); gtk_window_set_title(GTK_WINDOW(window), "Error"); gtk_label_set_line_wrap(GTK_LABEL(text), TRUE); ok = gtk_button_new_with_label("OK"); - gtk_box_pack_end(GTK_BOX(GTK_DIALOG(window)->action_area), + gtk_box_pack_end(GTK_BOX(gtk_dialog_get_action_area(GTK_DIALOG(window))), ok, FALSE, FALSE, 0); gtk_widget_show(ok); - GTK_WIDGET_SET_FLAGS(ok, GTK_CAN_DEFAULT); + gtk_widget_set_can_default(ok, TRUE); gtk_window_set_default(GTK_WINDOW(window), ok); gtk_signal_connect(GTK_OBJECT(ok), "clicked", GTK_SIGNAL_FUNC(errmsg_button_clicked), window); @@ -1127,38 +1129,50 @@ void dlg_coloursel_start(union control *ctrl, void *dlg, int r, int g, int b) struct dlgparam *dp = (struct dlgparam *)dlg; struct uctrl *uc = dlg_find_byctrl(dp, ctrl); gdouble cvals[4]; + GtkWidget *okbutton, *cancelbutton; GtkWidget *coloursel = gtk_color_selection_dialog_new("Select a colour"); GtkColorSelectionDialog *ccs = GTK_COLOR_SELECTION_DIALOG(coloursel); + GtkColorSelection *cs = GTK_COLOR_SELECTION + (gtk_color_selection_dialog_get_color_selection(ccs)); dp->coloursel_result.ok = FALSE; gtk_window_set_modal(GTK_WINDOW(coloursel), TRUE); #if GTK_CHECK_VERSION(2,0,0) - gtk_color_selection_set_has_opacity_control(GTK_COLOR_SELECTION(ccs->colorsel), FALSE); + gtk_color_selection_set_has_opacity_control(cs, FALSE); #else - gtk_color_selection_set_opacity(GTK_COLOR_SELECTION(ccs->colorsel), FALSE); + gtk_color_selection_set_opacity(cs, FALSE); #endif cvals[0] = r / 255.0; cvals[1] = g / 255.0; cvals[2] = b / 255.0; cvals[3] = 1.0; /* fully opaque! */ - gtk_color_selection_set_color(GTK_COLOR_SELECTION(ccs->colorsel), cvals); + gtk_color_selection_set_color(cs, cvals); - gtk_object_set_data(GTK_OBJECT(ccs->ok_button), "user-data", +#if GTK_CHECK_VERSION(2,0,0) + g_object_get(G_OBJECT(ccs), + "ok-button", &okbutton, + "cancel-button", &cancelbutton, + (const char *)NULL); +#else + okbutton = ccs->ok_button; + cancelbutton = ccs->cancel_button; +#endif + g_object_set_data(G_OBJECT(okbutton), "user-data", (gpointer)coloursel); - gtk_object_set_data(GTK_OBJECT(ccs->cancel_button), "user-data", + g_object_set_data(G_OBJECT(cancelbutton), "user-data", (gpointer)coloursel); gtk_object_set_data(GTK_OBJECT(coloursel), "user-data", (gpointer)uc); - gtk_signal_connect(GTK_OBJECT(ccs->ok_button), "clicked", + gtk_signal_connect(GTK_OBJECT(okbutton), "clicked", GTK_SIGNAL_FUNC(coloursel_ok), (gpointer)dp); - gtk_signal_connect(GTK_OBJECT(ccs->cancel_button), "clicked", + gtk_signal_connect(GTK_OBJECT(cancelbutton), "clicked", GTK_SIGNAL_FUNC(coloursel_cancel), (gpointer)dp); - gtk_signal_connect_object(GTK_OBJECT(ccs->ok_button), "clicked", + gtk_signal_connect_object(GTK_OBJECT(okbutton), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), (gpointer)coloursel); - gtk_signal_connect_object(GTK_OBJECT(ccs->cancel_button), "clicked", + gtk_signal_connect_object(GTK_OBJECT(cancelbutton), "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy), (gpointer)coloursel); gtk_widget_show(coloursel); @@ -1227,11 +1241,12 @@ static gboolean editbox_key(GtkWidget *widget, GdkEventKey *event, * Return in an edit box will now activate the default button * in the dialog just like it will everywhere else. */ - if (event->keyval == GDK_Return && widget->parent != NULL) { + GtkWidget *parent = gtk_widget_get_parent(widget); + if (event->keyval == GDK_Return && parent != NULL) { gboolean return_val; gtk_signal_emit_stop_by_name(GTK_OBJECT(widget), "key_press_event"); - gtk_signal_emit_by_name(GTK_OBJECT(widget->parent), "key_press_event", - event, &return_val); + gtk_signal_emit_by_name(GTK_OBJECT(parent), "key_press_event", + event, &return_val); return return_val; } return FALSE; @@ -1585,10 +1600,11 @@ static void coloursel_ok(GtkButton *button, gpointer data) struct dlgparam *dp = (struct dlgparam *)data; gpointer coloursel = gtk_object_get_data(GTK_OBJECT(button), "user-data"); struct uctrl *uc = gtk_object_get_data(GTK_OBJECT(coloursel), "user-data"); + GtkColorSelection *cs = GTK_COLOR_SELECTION + (gtk_color_selection_dialog_get_color_selection + (GTK_COLOR_SELECTION_DIALOG(coloursel))); gdouble cvals[4]; - gtk_color_selection_get_color - (GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(coloursel)->colorsel), - cvals); + gtk_color_selection_get_color(cs, cvals); dp->coloursel_result.r = (int) (255 * cvals[0]); dp->coloursel_result.g = (int) (255 * cvals[1]); dp->coloursel_result.b = (int) (255 * cvals[2]); @@ -1821,7 +1837,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, case CTRL_BUTTON: w = gtk_button_new_with_label(ctrl->generic.label); if (win) { - GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT); + gtk_widget_set_can_default(w, TRUE); if (ctrl->button.isdefault) gtk_window_set_default(win, w); if (ctrl->button.iscancel) @@ -1831,8 +1847,8 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, GTK_SIGNAL_FUNC(button_clicked), dp); gtk_signal_connect(GTK_OBJECT(w), "focus_in_event", GTK_SIGNAL_FUNC(widget_focus), dp); - shortcut_add(scs, GTK_BIN(w)->child, ctrl->button.shortcut, - SHORTCUT_UCTRL, uc); + shortcut_add(scs, gtk_bin_get_child(GTK_BIN(w)), + ctrl->button.shortcut, SHORTCUT_UCTRL, uc); break; case CTRL_CHECKBOX: w = gtk_check_button_new_with_label(ctrl->generic.label); @@ -1840,8 +1856,8 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, GTK_SIGNAL_FUNC(button_toggled), dp); gtk_signal_connect(GTK_OBJECT(w), "focus_in_event", GTK_SIGNAL_FUNC(widget_focus), dp); - shortcut_add(scs, GTK_BIN(w)->child, ctrl->checkbox.shortcut, - SHORTCUT_UCTRL, uc); + shortcut_add(scs, gtk_bin_get_child(GTK_BIN(w)), + ctrl->checkbox.shortcut, SHORTCUT_UCTRL, uc); left = TRUE; break; case CTRL_RADIO: @@ -1896,7 +1912,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs, gtk_signal_connect(GTK_OBJECT(b), "focus_in_event", GTK_SIGNAL_FUNC(widget_focus), dp); if (ctrl->radio.shortcuts) { - shortcut_add(scs, GTK_BIN(b)->child, + shortcut_add(scs, gtk_bin_get_child(GTK_BIN(b)), ctrl->radio.shortcuts[i], SHORTCUT_UCTRL, uc); } @@ -2786,11 +2802,13 @@ void set_dialog_action_area(GtkDialog *dlg, GtkWidget *w) gtk_alignment_set_padding(GTK_ALIGNMENT(align), 8, 8, 8, 8); #endif gtk_widget_show(align); - gtk_box_pack_end(GTK_BOX(dlg->vbox), align, FALSE, TRUE, 0); + gtk_box_pack_end(GTK_BOX(gtk_dialog_get_content_area(dlg)), + align, FALSE, TRUE, 0); w = gtk_hseparator_new(); - gtk_box_pack_end(GTK_BOX(dlg->vbox), w, FALSE, TRUE, 0); + gtk_box_pack_end(GTK_BOX(gtk_dialog_get_content_area(dlg)), + w, FALSE, TRUE, 0); gtk_widget_show(w); - gtk_widget_hide(dlg->action_area); + gtk_widget_hide(gtk_dialog_get_action_area(dlg)); gtk_dialog_set_has_separator(dlg, FALSE); #endif } @@ -2835,7 +2853,9 @@ int do_config_box(const char *title, Conf *conf, int midsession, gtk_window_set_title(GTK_WINDOW(window), title); hbox = gtk_hbox_new(FALSE, 4); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), hbox, TRUE, TRUE, 0); + gtk_box_pack_start + (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(window))), + hbox, TRUE, TRUE, 0); gtk_container_set_border_width(GTK_CONTAINER(hbox), 10); gtk_widget_show(hbox); vbox = gtk_vbox_new(FALSE, 4); @@ -3207,8 +3227,9 @@ int messagebox(GtkWidget *parentwin, const char *title, const char *msg, w1 = layout_ctrls(&dp, &scs, s1, GTK_WINDOW(window)); gtk_container_set_border_width(GTK_CONTAINER(w1), 10); gtk_widget_set_usize(w1, minwid+20, -1); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), - w1, TRUE, TRUE, 0); + gtk_box_pack_start + (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(window))), + w1, TRUE, TRUE, 0); gtk_widget_show(w1); dp.shortcuts = &scs; @@ -3463,35 +3484,38 @@ void about_box(void *window) sfree(title); w = gtk_button_new_with_label("Close"); - GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT); + gtk_widget_set_can_default(w, TRUE); gtk_window_set_default(GTK_WINDOW(aboutbox), w); - gtk_box_pack_end(GTK_BOX(GTK_DIALOG(aboutbox)->action_area), + gtk_box_pack_end(GTK_BOX(gtk_dialog_get_action_area(GTK_DIALOG(aboutbox))), w, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(w), "clicked", GTK_SIGNAL_FUNC(about_close_clicked), NULL); gtk_widget_show(w); w = gtk_button_new_with_label("View Licence"); - GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT); - gtk_box_pack_end(GTK_BOX(GTK_DIALOG(aboutbox)->action_area), + gtk_widget_set_can_default(w, TRUE); + gtk_box_pack_end(GTK_BOX(gtk_dialog_get_action_area(GTK_DIALOG(aboutbox))), w, FALSE, FALSE, 0); gtk_signal_connect(GTK_OBJECT(w), "clicked", GTK_SIGNAL_FUNC(licence_clicked), NULL); gtk_widget_show(w); w = gtk_label_new(appname); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(aboutbox)->vbox), - w, FALSE, FALSE, 0); + gtk_box_pack_start + (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(aboutbox))), + w, FALSE, FALSE, 0); gtk_widget_show(w); w = gtk_label_new(ver); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(aboutbox)->vbox), - w, FALSE, FALSE, 5); + gtk_box_pack_start + (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(aboutbox))), + w, FALSE, FALSE, 5); gtk_widget_show(w); 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_box_pack_start + (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(aboutbox))), + w, FALSE, FALSE, 5); gtk_widget_show(w); set_transient_window_pos(GTK_WIDGET(window), aboutbox); @@ -3595,7 +3619,7 @@ void eventlog_selection_get(GtkWidget *widget, GtkSelectionData *seldata, { struct eventlog_stuff *es = (struct eventlog_stuff *)data; - gtk_selection_data_set(seldata, seldata->target, 8, + gtk_selection_data_set(seldata, gtk_selection_data_get_target(seldata), 8, (unsigned char *)es->seldata, es->sellen); } @@ -3680,8 +3704,9 @@ void showeventlog(void *estuff, void *parentwin) string_width("LINE OF TEXT GIVING WIDTH OF EVENT LOG" " IS QUITE LONG 'COS SSH LOG ENTRIES" " ARE WIDE"), -1); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), - w1, TRUE, TRUE, 0); + gtk_box_pack_start + (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(window))), + w1, TRUE, TRUE, 0); gtk_widget_show(w1); es->dp.data = es; diff --git a/unix/gtkfont.c b/unix/gtkfont.c index 012dfea1..94e3fe20 100644 --- a/unix/gtkfont.c +++ b/unix/gtkfont.c @@ -2045,7 +2045,8 @@ static void unifontsel_draw_preview_text(unifontsel_internal *fs) 42, FALSE, FALSE, font->width); } gdk_gc_unref(gc); - gdk_window_invalidate_rect(fs->preview_area->window, NULL, FALSE); + gdk_window_invalidate_rect(gtk_widget_get_window(fs->preview_area), + NULL, FALSE); } if (font) info->fontclass->destroy(font); @@ -2478,8 +2479,9 @@ static gint unifontsel_expose_area(GtkWidget *widget, GdkEventExpose *event, unifontsel_internal *fs = (unifontsel_internal *)data; if (fs->preview_pixmap) { - gdk_draw_pixmap(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + gdk_draw_pixmap(gtk_widget_get_window(widget), + (gtk_widget_get_style(widget)->fg_gc + [gtk_widget_get_state(widget)]), fs->preview_pixmap, event->area.x, event->area.y, event->area.x, event->area.y, @@ -2507,14 +2509,15 @@ static gint unifontsel_configure_area(GtkWidget *widget, nx = (x > ox ? x : ox); ny = (y > oy ? y : oy); - fs->preview_pixmap = gdk_pixmap_new(widget->window, nx, ny, -1); + fs->preview_pixmap = gdk_pixmap_new(gtk_widget_get_window(widget), + nx, ny, -1); fs->preview_width = nx; fs->preview_height = ny; unifontsel_draw_preview_text(fs); } - gdk_window_invalidate_rect(widget->window, NULL, FALSE); + gdk_window_invalidate_rect(gtk_widget_get_window(widget), NULL, FALSE); return TRUE; } @@ -2584,7 +2587,8 @@ unifontsel *unifontsel_new(const char *wintitle) #else w = table; #endif - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(fs->u.window)->vbox), + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area + (GTK_DIALOG(fs->u.window))), w, TRUE, TRUE, 0); label = gtk_label_new_with_mnemonic("_Font:"); diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 6f59f687..5444db3f 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -37,6 +37,7 @@ #include "putty.h" #include "terminal.h" +#include "gtkcompat.h" #include "gtkfont.h" #define CAT2(x,y) x ## y @@ -316,7 +317,7 @@ void move_window(void *frontend, int x, int y) #if GTK_CHECK_VERSION(2,0,0) gtk_window_move(GTK_WINDOW(inst->window), x, y); #else - gdk_window_move(inst->window->window, x, y); + gdk_window_move(gtk_widget_get_window(inst->window), x, y); #endif } @@ -328,9 +329,9 @@ void set_zorder(void *frontend, int top) { struct gui_data *inst = (struct gui_data *)frontend; if (top) - gdk_window_raise(inst->window->window); + gdk_window_raise(gtk_widget_get_window(inst->window)); else - gdk_window_lower(inst->window->window); + gdk_window_lower(gtk_widget_get_window(inst->window)); } /* @@ -366,7 +367,7 @@ void set_zoomed(void *frontend, int zoomed) int is_iconic(void *frontend) { struct gui_data *inst = (struct gui_data *)frontend; - return !gdk_window_is_viewable(inst->window->window); + return !gdk_window_is_viewable(gtk_widget_get_window(inst->window)); } /* @@ -383,7 +384,7 @@ void get_window_pos(void *frontend, int *x, int *y) #if GTK_CHECK_VERSION(2,0,0) gtk_window_get_position(GTK_WINDOW(inst->window), x, y); #else - gdk_window_get_position(inst->window->window, x, y); + gdk_window_get_position(gtk_widget_get_window(inst->window), x, y); #endif } @@ -401,7 +402,7 @@ void get_window_pixels(void *frontend, int *x, int *y) #if GTK_CHECK_VERSION(2,0,0) gtk_window_get_size(GTK_WINDOW(inst->window), x, y); #else - gdk_window_get_size(inst->window->window, x, y); + gdk_window_get_size(gtk_widget_get_window(inst->window), x, y); #endif } @@ -429,17 +430,21 @@ static void update_mouseptr(struct gui_data *inst) switch (inst->busy_status) { case BUSY_NOT: if (!inst->mouseptr_visible) { - gdk_window_set_cursor(inst->area->window, inst->blankcursor); + gdk_window_set_cursor(gtk_widget_get_window(inst->area), + inst->blankcursor); } else if (send_raw_mouse) { - gdk_window_set_cursor(inst->area->window, inst->rawcursor); + gdk_window_set_cursor(gtk_widget_get_window(inst->area), + inst->rawcursor); } else { - gdk_window_set_cursor(inst->area->window, inst->textcursor); + gdk_window_set_cursor(gtk_widget_get_window(inst->area), + inst->textcursor); } break; case BUSY_WAITING: /* XXX can we do better? */ case BUSY_CPU: /* We always display these cursors. */ - gdk_window_set_cursor(inst->area->window, inst->waitcursor); + gdk_window_set_cursor(gtk_widget_get_window(inst->area), + inst->waitcursor); break; default: assert(0); @@ -456,7 +461,7 @@ static void show_mouseptr(struct gui_data *inst, int show) void draw_backing_rect(struct gui_data *inst) { - GdkGC *gc = gdk_gc_new(inst->area->window); + GdkGC *gc = gdk_gc_new(gtk_widget_get_window(inst->area)); gdk_gc_set_foreground(gc, &inst->cols[258]); /* default background */ gdk_draw_rectangle(inst->pixmap, gc, 1, 0, 0, inst->width * inst->font_width + 2*inst->window_border, @@ -488,7 +493,7 @@ gint configure_area(GtkWidget *widget, GdkEventConfigure *event, gpointer data) inst->pixmap = NULL; } - inst->pixmap = gdk_pixmap_new(widget->window, + inst->pixmap = gdk_pixmap_new(gtk_widget_get_window(widget), (w * inst->font_width + 2*inst->window_border), (h * inst->font_height + 2*inst->window_border), -1); @@ -502,7 +507,7 @@ gint configure_area(GtkWidget *widget, GdkEventConfigure *event, gpointer data) term_invalidate(inst->term); #if GTK_CHECK_VERSION(2,0,0) - gtk_im_context_set_client_window(inst->imc, widget->window); + gtk_im_context_set_client_window(inst->imc, gtk_widget_get_window(widget)); #endif return TRUE; @@ -517,8 +522,9 @@ gint expose_area(GtkWidget *widget, GdkEventExpose *event, gpointer data) * back to do the actual painting. */ if (inst->pixmap) { - gdk_draw_pixmap(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + gdk_draw_pixmap(gtk_widget_get_window(widget), + (gtk_widget_get_style(widget)->fg_gc + [gtk_widget_get_state(widget)]), inst->pixmap, event->area.x, event->area.y, event->area.x, event->area.y, @@ -1650,7 +1656,7 @@ void request_resize(void *frontend, int w, int h) * above. */ gtk_container_dequeue_resize_handler(GTK_CONTAINER(inst->window)); - gdk_window_resize(inst->window->window, + gdk_window_resize(gtk_widget_get_window(inst->window), area_x + offset_x, area_y + offset_y); #endif } @@ -1673,10 +1679,12 @@ static void real_palette_set(struct gui_data *inst, int n, int r, int g, int b) void set_window_background(struct gui_data *inst) { - if (inst->area && inst->area->window) - gdk_window_set_background(inst->area->window, &inst->cols[258]); - if (inst->window && inst->window->window) - gdk_window_set_background(inst->window->window, &inst->cols[258]); + if (inst->area && gtk_widget_get_window(inst->area)) + gdk_window_set_background(gtk_widget_get_window(inst->area), + &inst->cols[258]); + if (inst->window && gtk_widget_get_window(inst->window)) + gdk_window_set_background(gtk_widget_get_window(inst->window), + &inst->cols[258]); } void palette_set(void *frontend, int n, int r, int g, int b) @@ -1753,7 +1761,7 @@ void palette_reset(void *frontend) /* Since Default Background may have changed, ensure that space * between text area and window border is refreshed. */ set_window_background(inst); - if (inst->area && inst->area->window) { + if (inst->area && gtk_widget_get_window(inst->area)) { draw_backing_rect(inst); gtk_widget_queue_draw(inst->area); } @@ -1901,17 +1909,18 @@ void selection_get(GtkWidget *widget, GtkSelectionData *seldata, guint info, guint time_stamp, gpointer data) { struct gui_data *inst = (struct gui_data *)data; - if (seldata->target == utf8_string_atom) - gtk_selection_data_set(seldata, seldata->target, 8, - (unsigned char *)inst->pasteout_data_utf8, + GdkAtom target = gtk_selection_data_get_target(seldata); + if (target == utf8_string_atom) + gtk_selection_data_set(seldata, target, 8, + (unsigned char *)inst->pasteout_data_utf8, inst->pasteout_data_utf8_len); - else if (seldata->target == compound_text_atom) - gtk_selection_data_set(seldata, seldata->target, 8, - (unsigned char *)inst->pasteout_data_ctext, + else if (target == compound_text_atom) + gtk_selection_data_set(seldata, target, 8, + (unsigned char *)inst->pasteout_data_ctext, inst->pasteout_data_ctext_len); else - gtk_selection_data_set(seldata, seldata->target, 8, - (unsigned char *)inst->pasteout_data, + gtk_selection_data_set(seldata, target, 8, + (unsigned char *)inst->pasteout_data, inst->pasteout_data_len); } @@ -1980,8 +1989,13 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata, int free_list_required = 0; int free_required = 0; int charset; + GdkAtom seldata_target = gtk_selection_data_get_target(seldata); + GdkAtom seldata_type = gtk_selection_data_get_data_type(seldata); + const guchar *seldata_data = gtk_selection_data_get_data(seldata); + gint seldata_length = gtk_selection_data_get_length(seldata); + gint seldata_format = gtk_selection_data_get_format(seldata); - if (seldata->target == utf8_string_atom && seldata->length <= 0) { + if (seldata_target == utf8_string_atom && seldata_length <= 0) { /* * Failed to get a UTF-8 selection string. Try compound * text next. @@ -1992,7 +2006,7 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata, return; } - if (seldata->target == compound_text_atom && seldata->length <= 0) { + if (seldata_target == compound_text_atom && seldata_length <= 0) { /* * Failed to get UTF-8 or compound text. Try an ordinary * string. @@ -2007,16 +2021,16 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata, * If we have data, but it's not of a type we can deal with, * we have to ignore the data. */ - if (seldata->length > 0 && - seldata->type != GDK_SELECTION_TYPE_STRING && - seldata->type != compound_text_atom && - seldata->type != utf8_string_atom) + if (seldata_length > 0 && + seldata_type != GDK_SELECTION_TYPE_STRING && + seldata_type != compound_text_atom && + seldata_type != utf8_string_atom) return; /* * If we have no data, try looking in a cut buffer. */ - if (seldata->length <= 0) { + if (seldata_length <= 0) { text = retrieve_cutbuffer(&length); if (length == 0) return; @@ -2028,11 +2042,11 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata, /* * Convert COMPOUND_TEXT into UTF-8. */ - if (seldata->type == compound_text_atom) { - tp.value = seldata->data; - tp.encoding = (Atom) seldata->type; - tp.format = seldata->format; - tp.nitems = seldata->length; + if (seldata_type == compound_text_atom) { + tp.value = (unsigned char *)seldata_data; + tp.encoding = (Atom) seldata_type; + tp.format = seldata_format; + tp.nitems = seldata_length; ret = Xutf8TextPropertyToTextList(GDK_DISPLAY(), &tp, &list, &count); if (ret != 0 || count != 1) { @@ -2049,9 +2063,9 @@ void selection_received(GtkWidget *widget, GtkSelectionData *seldata, charset = CS_UTF8; free_list_required = 1; } else { - text = (char *)seldata->data; - length = seldata->length; - charset = (seldata->type == utf8_string_atom ? + text = (char *)seldata_data; + length = seldata_length; + charset = (seldata_type == utf8_string_atom ? CS_UTF8 : inst->ucsdata.line_codepage); } } @@ -2092,7 +2106,8 @@ static void set_window_titles(struct gui_data *inst) */ gtk_window_set_title(GTK_WINDOW(inst->window), inst->wintitle); if (!conf_get_int(inst->conf, CONF_win_name_always)) - gdk_window_set_icon_name(inst->window->window, inst->icontitle); + gdk_window_set_icon_name(gtk_widget_get_window(inst->window), + inst->icontitle); } void set_title(void *frontend, char *title) @@ -2126,12 +2141,12 @@ void set_sbar(void *frontend, int total, int start, int page) struct gui_data *inst = (struct gui_data *)frontend; if (!conf_get_int(inst->conf, CONF_scrollbar)) return; - inst->sbar_adjust->lower = 0; - inst->sbar_adjust->upper = total; - inst->sbar_adjust->value = start; - inst->sbar_adjust->page_size = page; - inst->sbar_adjust->step_increment = 1; - inst->sbar_adjust->page_increment = page/2; + gtk_adjustment_set_lower(inst->sbar_adjust, 0); + gtk_adjustment_set_upper(inst->sbar_adjust, total); + gtk_adjustment_set_value(inst->sbar_adjust, start); + gtk_adjustment_set_page_size(inst->sbar_adjust, page); + gtk_adjustment_set_step_increment(inst->sbar_adjust, 1); + gtk_adjustment_set_page_increment(inst->sbar_adjust, page/2); inst->ignore_sbar = TRUE; gtk_adjustment_changed(inst->sbar_adjust); inst->ignore_sbar = FALSE; @@ -2144,7 +2159,7 @@ void scrollbar_moved(GtkAdjustment *adj, gpointer data) if (!conf_get_int(inst->conf, CONF_scrollbar)) return; if (!inst->ignore_sbar) - term_scroll(inst->term, 1, (int)adj->value); + term_scroll(inst->term, 1, (int)gtk_adjustment_get_value(adj)); } void sys_cursor(void *frontend, int x, int y) @@ -2183,12 +2198,12 @@ Context get_ctx(void *frontend) struct gui_data *inst = (struct gui_data *)frontend; struct draw_ctx *dctx; - if (!inst->area->window) + if (!gtk_widget_get_window(inst->area)) return NULL; dctx = snew(struct draw_ctx); dctx->inst = inst; - dctx->gc = gdk_gc_new(inst->area->window); + dctx->gc = gdk_gc_new(gtk_widget_get_window(inst->area)); return dctx; } @@ -2215,7 +2230,8 @@ void do_text_internal(Context ctx, int x, int y, wchar_t *text, int len, GdkGC *gc = dctx->gc; int ncombining, combining; int nfg, nbg, t, fontid, shadow, rlen, widefactor, bold; - int monochrome = gtk_widget_get_visual(inst->area)->depth == 1; + int monochrome = + gdk_visual_get_depth(gtk_widget_get_visual(inst->area)) == 1; if (attr & TATTR_COMBINING) { ncombining = len; @@ -2384,7 +2400,7 @@ void do_text(Context ctx, int x, int y, wchar_t *text, int len, len *= 2; } - gdk_draw_pixmap(inst->area->window, gc, inst->pixmap, + gdk_draw_pixmap(gtk_widget_get_window(inst->area), gc, inst->pixmap, x*inst->font_width+inst->window_border, y*inst->font_height+inst->window_border, x*inst->font_width+inst->window_border, @@ -2491,7 +2507,7 @@ void do_cursor(Context ctx, int x, int y, wchar_t *text, int len, } /* else no cursor (e.g., blinked off) */ } - gdk_draw_pixmap(inst->area->window, gc, inst->pixmap, + gdk_draw_pixmap(gtk_widget_get_window(inst->area), gc, inst->pixmap, x*inst->font_width+inst->window_border, y*inst->font_height+inst->window_border, x*inst->font_width+inst->window_border, @@ -2635,7 +2651,7 @@ char *get_x_display(void *frontend) long get_windowid(void *frontend) { struct gui_data *inst = (struct gui_data *)frontend; - return (long)GDK_WINDOW_XWINDOW(inst->area->window); + return (long)GDK_WINDOW_XWINDOW(gtk_widget_get_window(inst->area)); } static void help(FILE *fp) { @@ -3511,9 +3527,9 @@ void set_window_icon(GtkWidget *window, const char *const *const *icon, return; gtk_widget_realize(window); - iconpm = gdk_pixmap_create_from_xpm_d(window->window, &iconmask, - NULL, (gchar **)icon[0]); - gdk_window_set_icon(window->window, NULL, iconpm, iconmask); + iconpm = gdk_pixmap_create_from_xpm_d(gtk_widget_get_window(window), + &iconmask, NULL, (gchar **)icon[0]); + gdk_window_set_icon(gtk_widget_get_window(window), NULL, iconpm, iconmask); #if GTK_CHECK_VERSION(2,0,0) iconlist = NULL; @@ -3523,7 +3539,7 @@ void set_window_icon(GtkWidget *window, const char *const *const *icon, gdk_pixbuf_new_from_xpm_data((const gchar **) icon[n])); } - gdk_window_set_icon_list(window->window, iconlist); + gdk_window_set_icon_list(gtk_widget_get_window(window), iconlist); #endif }