void gtk_form_freeze(GtkForm *form) { g_return_if_fail(GTK_IS_FORM(form)); ++form->freeze_count; }
static void gtk_form_draw(GtkWidget *widget, GdkRectangle *area) { GtkForm *form; GList *children; GtkFormChild *child; GdkRectangle child_area; g_return_if_fail(GTK_IS_FORM(widget)); if (GTK_WIDGET_DRAWABLE(widget)) { form = GTK_FORM(widget); children = form->children; while (children) { child = children->data; if (GTK_WIDGET_DRAWABLE(child->widget) && gtk_widget_intersect(child->widget, area, &child_area)) gtk_widget_draw(child->widget, &child_area); children = children->next; } } }
static void gtk_form_size_request(GtkWidget *widget, GtkRequisition *requisition) { g_return_if_fail(GTK_IS_FORM(widget)); g_return_if_fail(requisition != NULL); requisition->width = 1; requisition->height = 1; }
static void gtk_form_realize(GtkWidget *widget) { GList *tmp_list; GtkForm *form; GdkWindowAttr attributes; gint attributes_mask; g_return_if_fail(GTK_IS_FORM(widget)); form = GTK_FORM(widget); GTK_WIDGET_SET_FLAGS(form, GTK_REALIZED); attributes.window_type = GDK_WINDOW_CHILD; attributes.x = widget->allocation.x; attributes.y = widget->allocation.y; attributes.width = widget->allocation.width; attributes.height = widget->allocation.height; attributes.wclass = GDK_INPUT_OUTPUT; attributes.visual = gtk_widget_get_visual(widget); attributes.colormap = gtk_widget_get_colormap(widget); attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK; attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; widget->window = gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, attributes_mask); gdk_window_set_user_data(widget->window, widget); attributes.x = 0; attributes.y = 0; attributes.event_mask = gtk_widget_get_events(widget); form->bin_window = gdk_window_new(widget->window, &attributes, attributes_mask); gdk_window_set_user_data(form->bin_window, widget); gtk_form_set_static_gravity(form->bin_window, TRUE); widget->style = gtk_style_attach(widget->style, widget->window); gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL); gtk_style_set_background(widget->style, form->bin_window, GTK_STATE_NORMAL); gdk_window_add_filter(widget->window, gtk_form_main_filter, form); gdk_window_add_filter(form->bin_window, gtk_form_filter, form); for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next) { GtkFormChild *child = tmp_list->data; gtk_form_attach_child_window(form, child); if (GTK_WIDGET_VISIBLE(child->widget)) gtk_form_realize_child(form, child); } }
void gtk_form_thaw(GtkForm *form) { g_return_if_fail(GTK_IS_FORM(form)); if (form->freeze_count) { if (!(--form->freeze_count)) { gtk_form_position_children(form); gtk_widget_queue_draw(GTK_WIDGET(form)); } } }
/* Container method */ static void gtk_form_remove(GtkContainer *container, GtkWidget *widget) { GList *tmp_list; GtkForm *form; GtkFormChild *child = NULL; /* init for gcc */ g_return_if_fail(GTK_IS_FORM(container)); form = GTK_FORM(container); tmp_list = form->children; while (tmp_list) { child = tmp_list->data; if (child->widget == widget) break; tmp_list = tmp_list->next; } if (tmp_list) { #if GTK_CHECK_VERSION(3,0,0) const gboolean was_visible = gtk_widget_get_visible(widget); #endif if (child->window) { g_signal_handlers_disconnect_by_func(G_OBJECT(child->widget), FUNC2GENERIC(>k_form_child_map), child); g_signal_handlers_disconnect_by_func(G_OBJECT(child->widget), FUNC2GENERIC(>k_form_child_unmap), child); /* FIXME: This will cause problems for reparenting NO_WINDOW * widgets out of a GtkForm */ gdk_window_set_user_data(child->window, NULL); gdk_window_destroy(child->window); } gtk_widget_unparent(widget); #if GTK_CHECK_VERSION(3,0,0) if (was_visible) gtk_widget_queue_resize(GTK_WIDGET(container)); #endif form->children = g_list_remove_link(form->children, tmp_list); g_list_free_1(tmp_list); g_free(child); } }
static void gtk_form_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { GList *tmp_list; GtkForm *form; gboolean need_reposition; GtkAllocation cur_alloc; g_return_if_fail(GTK_IS_FORM(widget)); gtk_widget_get_allocation(widget, &cur_alloc); if (cur_alloc.x == allocation->x && cur_alloc.y == allocation->y && cur_alloc.width == allocation->width && cur_alloc.height == allocation->height) return; need_reposition = cur_alloc.width != allocation->width || cur_alloc.height != allocation->height; form = GTK_FORM(widget); if (need_reposition) { tmp_list = form->children; while (tmp_list) { GtkFormChild *child = tmp_list->data; gtk_form_position_child(form, child, TRUE); tmp_list = tmp_list->next; } } if (gtk_widget_get_realized(widget)) { gdk_window_move_resize(gtk_widget_get_window(widget), allocation->x, allocation->y, allocation->width, allocation->height); gdk_window_move_resize(GTK_FORM(widget)->bin_window, 0, 0, allocation->width, allocation->height); } gtk_widget_set_allocation(widget, allocation); if (need_reposition) gtk_form_send_configure(form); }
static void gtk_form_unrealize(GtkWidget *widget) { GList *tmp_list; GtkForm *form; g_return_if_fail(GTK_IS_FORM(widget)); form = GTK_FORM(widget); tmp_list = form->children; gdk_window_set_user_data(form->bin_window, NULL); gdk_window_destroy(form->bin_window); form->bin_window = NULL; while (tmp_list) { GtkFormChild *child = tmp_list->data; if (child->window != NULL) { g_signal_handlers_disconnect_by_func(G_OBJECT(child->widget), FUNC2GENERIC(gtk_form_child_map), child); g_signal_handlers_disconnect_by_func(G_OBJECT(child->widget), FUNC2GENERIC(gtk_form_child_unmap), child); gdk_window_set_user_data(child->window, NULL); gdk_window_destroy(child->window); child->window = NULL; } tmp_list = tmp_list->next; } #if GTK_CHECK_VERSION(3,0,0) if (GTK_WIDGET_CLASS (gtk_form_parent_class)->unrealize) (* GTK_WIDGET_CLASS (gtk_form_parent_class)->unrealize) (widget); #else if (GTK_WIDGET_CLASS (parent_class)->unrealize) (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); #endif }
static gint gtk_form_expose(GtkWidget *widget, GdkEventExpose *event) { GList *tmp_list; GtkForm *form; g_return_val_if_fail(GTK_IS_FORM(widget), FALSE); form = GTK_FORM(widget); if (event->window == form->bin_window) return FALSE; for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next) { #ifdef HAVE_GTK2 GtkFormChild *formchild = tmp_list->data; GtkWidget *child = formchild->widget; /* * The following chunk of code is taken from gtkcontainer.c. The * gtk1.x code synthesized expose events directly on the child widgets, * which can't be done in gtk2 */ if (GTK_WIDGET_DRAWABLE(child) && GTK_WIDGET_NO_WINDOW(child) && child->window == event->window) { GdkEventExpose child_event; child_event = *event; child_event.region = gtk_widget_region_intersect(child, event->region); if (!gdk_region_empty(child_event.region)) { gdk_region_get_clipbox(child_event.region, &child_event.area); gtk_widget_send_expose(child, (GdkEvent *)&child_event); } } #else /* !HAVE_GTK2 */ GtkFormChild *child = tmp_list->data; if (event->window == child->window) return gtk_widget_event(child->widget, (GdkEvent *) event); #endif /* !HAVE_GTK2 */ } return FALSE; }
void gtk_form_put(GtkForm *form, GtkWidget *child_widget, gint x, gint y) { GtkFormChild *child; g_return_if_fail(GTK_IS_FORM(form)); /* LINTED: avoid warning: conversion to 'unsigned long' */ child = g_new(GtkFormChild, 1); if (child == NULL) return; child->widget = child_widget; child->window = NULL; child->x = x; child->y = y; #if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_size_request(child->widget, -1, -1); #else child->widget->requisition.width = 0; child->widget->requisition.height = 0; #endif child->mapped = FALSE; form->children = g_list_append(form->children, child); /* child->window must be created and attached to the widget _before_ * it has been realized, or else things will break with GTK2. Note * that gtk_widget_set_parent() realizes the widget if it's visible * and its parent is mapped. */ if (gtk_widget_get_realized(GTK_WIDGET(form))) gtk_form_attach_child_window(form, child); gtk_widget_set_parent(child_widget, GTK_WIDGET(form)); if (gtk_widget_get_realized(GTK_WIDGET(form)) && !gtk_widget_get_realized(child_widget)) gtk_form_realize_child(form, child); gtk_form_position_child(form, child, TRUE); }
static void gtk_form_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { GList *tmp_list; GtkForm *form; gboolean need_reposition; g_return_if_fail(GTK_IS_FORM(widget)); if (widget->allocation.x == allocation->x && widget->allocation.y == allocation->y && widget->allocation.width == allocation->width && widget->allocation.height == allocation->height) return; need_reposition = widget->allocation.width != allocation->width || widget->allocation.height != allocation->height; form = GTK_FORM(widget); if (need_reposition) { tmp_list = form->children; while (tmp_list) { GtkFormChild *child = tmp_list->data; gtk_form_position_child(form, child, TRUE); tmp_list = tmp_list->next; } } if (GTK_WIDGET_REALIZED(widget)) { gdk_window_move_resize(widget->window, allocation->x, allocation->y, allocation->width, allocation->height); gdk_window_move_resize(GTK_FORM(widget)->bin_window, 0, 0, allocation->width, allocation->height); } widget->allocation = *allocation; if (need_reposition) gtk_form_send_configure(form); }
void gtk_form_set_size(GtkForm *form, guint width, guint height) { g_return_if_fail(GTK_IS_FORM(form)); /* prevent unneccessary calls */ if (form->width == width && form->height == height) return; form->width = width; form->height = height; /* signal the change */ #ifdef HAVE_GTK2 gtk_widget_queue_resize(gtk_widget_get_parent(GTK_WIDGET(form))); #else gtk_container_queue_resize(GTK_CONTAINER(GTK_WIDGET(form)->parent)); #endif }
void gtk_form_thaw(GtkForm *form) { g_return_if_fail(GTK_IS_FORM(form)); if (form->freeze_count) { if (!(--form->freeze_count)) { gtk_form_position_children(form); #ifdef HAVE_GTK2 gtk_widget_queue_draw(GTK_WIDGET(form)); #else gtk_widget_draw(GTK_WIDGET(form), NULL); #endif } } }
/* Container method */ static void gtk_form_remove(GtkContainer *container, GtkWidget *widget) { GList *tmp_list; GtkForm *form; GtkFormChild *child = NULL; /* init for gcc */ g_return_if_fail(GTK_IS_FORM(container)); form = GTK_FORM(container); tmp_list = form->children; while (tmp_list) { child = tmp_list->data; if (child->widget == widget) break; tmp_list = tmp_list->next; } if (tmp_list) { if (child->window) { gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget), GTK_SIGNAL_FUNC(>k_form_child_map), child); gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget), GTK_SIGNAL_FUNC(>k_form_child_unmap), child); /* FIXME: This will cause problems for reparenting NO_WINDOW * widgets out of a GtkForm */ gdk_window_set_user_data(child->window, NULL); gdk_window_destroy(child->window); } gtk_widget_unparent(widget); form->children = g_list_remove_link(form->children, tmp_list); g_list_free_1(tmp_list); g_free(child); } }
/* To get gtk_widget_draw() to work, it is required to call * gtk_widget_size_allocate() in advance with a well-posed * allocation for a given child widget in order to set a * certain private GtkWidget variable, called * widget->priv->alloc_need, to the proper value; otherwise, * gtk_widget_draw() fails and the relevant scrollbar won't * appear on the screen. * * Calling gtk_form_position_child() like this is one of ways * to make sure of that. */ gtk_form_position_child(form, formchild, TRUE); gtk_form_render_background(formchild->widget, cr); } } return GTK_WIDGET_CLASS(gtk_form_parent_class)->draw(widget, cr); } #else /* !GTK_CHECK_VERSION(3,0,0) */ static gint gtk_form_expose(GtkWidget *widget, GdkEventExpose *event) { GList *tmp_list; GtkForm *form; g_return_val_if_fail(GTK_IS_FORM(widget), FALSE); form = GTK_FORM(widget); if (event->window == form->bin_window) return FALSE; for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next) gtk_container_propagate_expose(GTK_CONTAINER(widget), GTK_WIDGET(((GtkFormChild *)tmp_list->data)->widget), event); return FALSE; }
static void gtk_form_unrealize(GtkWidget *widget) { GList *tmp_list; GtkForm *form; g_return_if_fail(GTK_IS_FORM(widget)); form = GTK_FORM(widget); tmp_list = form->children; gdk_window_set_user_data(form->bin_window, NULL); gdk_window_destroy(form->bin_window); form->bin_window = NULL; while (tmp_list) { GtkFormChild *child = tmp_list->data; if (child->window != NULL) { gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget), GTK_SIGNAL_FUNC(gtk_form_child_map), child); gtk_signal_disconnect_by_func(GTK_OBJECT(child->widget), GTK_SIGNAL_FUNC(gtk_form_child_unmap), child); gdk_window_set_user_data(child->window, NULL); gdk_window_destroy(child->window); child->window = NULL; } tmp_list = tmp_list->next; } if (GTK_WIDGET_CLASS (parent_class)->unrealize) (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); }
static void gtk_form_size_request(GtkWidget *widget, GtkRequisition *requisition) { GList *tmp_list; GtkForm *form; g_return_if_fail(GTK_IS_FORM(widget)); form = GTK_FORM(widget); requisition->width = form->width; requisition->height = form->height; tmp_list = form->children; while (tmp_list) { GtkFormChild *child = tmp_list->data; gtk_widget_size_request(child->widget, NULL); tmp_list = tmp_list->next; } }
static void gtk_form_forall(GtkContainer *container, gboolean include_internals UNUSED, GtkCallback callback, gpointer callback_data) { GtkForm *form; GtkFormChild *child; GList *tmp_list; g_return_if_fail(GTK_IS_FORM(container)); g_return_if_fail(callback != NULL); form = GTK_FORM(container); tmp_list = form->children; while (tmp_list) { child = tmp_list->data; tmp_list = tmp_list->next; (*callback) (child->widget, callback_data); } }
/* After reading the documentation at * http://developer.gnome.org/doc/API/2.0/gtk/gtk-changes-2-0.html * I think it should be possible to remove this function when compiling * against gtk-2.0. It doesn't seem to cause problems, though. * * Well, I reckon at least the gdk_window_show(form->bin_window) * is necessary. GtkForm is anything but a usual container widget. */ static void gtk_form_map(GtkWidget *widget) { GList *tmp_list; GtkForm *form; g_return_if_fail(GTK_IS_FORM(widget)); form = GTK_FORM(widget); GTK_WIDGET_SET_FLAGS(widget, GTK_MAPPED); gdk_window_show(widget->window); gdk_window_show(form->bin_window); for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next) { GtkFormChild *child = tmp_list->data; if (GTK_WIDGET_VISIBLE(child->widget) && !GTK_WIDGET_MAPPED(child->widget)) gtk_widget_map(child->widget); } }
/* After reading the documentation at * http://developer.gnome.org/doc/API/2.0/gtk/gtk-changes-2-0.html * I think it should be possible to remove this function when compiling * against gtk-2.0. It doesn't seem to cause problems, though. * * Well, I reckon at least the gdk_window_show(form->bin_window) * is necessary. GtkForm is anything but a usual container widget. */ static void gtk_form_map(GtkWidget *widget) { GList *tmp_list; GtkForm *form; g_return_if_fail(GTK_IS_FORM(widget)); form = GTK_FORM(widget); gtk_widget_set_mapped(widget, TRUE); gdk_window_show(gtk_widget_get_window(widget)); gdk_window_show(form->bin_window); for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next) { GtkFormChild *child = tmp_list->data; if (gtk_widget_get_visible(child->widget) && !gtk_widget_get_mapped(child->widget)) gtk_widget_map(child->widget); } }
static gboolean gtk_form_draw(GtkWidget *widget, cairo_t *cr) { GList *tmp_list = NULL; GtkForm *form = NULL; g_return_val_if_fail(GTK_IS_FORM(widget), FALSE); gtk_form_render_background(widget, cr); form = GTK_FORM(widget); for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next) { GtkFormChild * const formchild = tmp_list->data; if (!gtk_widget_get_has_window(formchild->widget) && gtk_cairo_should_draw_window(cr, formchild->window)) { /* To get gtk_widget_draw() to work, it is required to call * gtk_widget_size_allocate() in advance with a well-posed * allocation for a given child widget in order to set a * certain private GtkWidget variable, called * widget->priv->alloc_need, to the proper value; otherwise, * gtk_widget_draw() fails and the relevant scrollbar won't * appear on the screen. * * Calling gtk_form_position_child() like this is one of ways * to make sure of that. */ gtk_form_position_child(form, formchild, TRUE); gtk_form_render_background(formchild->widget, cr); } } return GTK_WIDGET_CLASS(gtk_form_parent_class)->draw(widget, cr); }
void gtk_form_move(GtkForm *form, GtkWidget *child_widget, gint x, gint y) { GList *tmp_list; GtkFormChild *child; g_return_if_fail(GTK_IS_FORM(form)); for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next) { child = tmp_list->data; if (child->widget == child_widget) { child->x = x; child->y = y; gtk_form_position_child(form, child, TRUE); return; } } }
static void gtk_form_realize(GtkWidget *widget) { GList *tmp_list; GtkForm *form; GdkWindowAttr attributes; gint attributes_mask; GtkAllocation allocation; g_return_if_fail(GTK_IS_FORM(widget)); form = GTK_FORM(widget); gtk_widget_set_realized(widget, TRUE); gtk_widget_get_allocation(widget, &allocation); attributes.window_type = GDK_WINDOW_CHILD; attributes.x = allocation.x; attributes.y = allocation.y; attributes.width = allocation.width; attributes.height = allocation.height; attributes.wclass = GDK_INPUT_OUTPUT; attributes.visual = gtk_widget_get_visual(widget); #if GTK_CHECK_VERSION(3,0,0) attributes.event_mask = GDK_EXPOSURE_MASK; #else attributes.colormap = gtk_widget_get_colormap(widget); attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK; #endif #if GTK_CHECK_VERSION(3,0,0) attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL; #else attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; #endif gtk_widget_set_window(widget, gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, attributes_mask)); gdk_window_set_user_data(gtk_widget_get_window(widget), widget); attributes.x = 0; attributes.y = 0; attributes.event_mask = gtk_widget_get_events(widget); form->bin_window = gdk_window_new(gtk_widget_get_window(widget), &attributes, attributes_mask); gdk_window_set_user_data(form->bin_window, widget); #if GTK_CHECK_VERSION(3,0,0) { GtkStyleContext * const sctx = gtk_widget_get_style_context(widget); gtk_style_context_add_class(sctx, "gtk-form"); gtk_style_context_set_state(sctx, GTK_STATE_FLAG_NORMAL); # if !GTK_CHECK_VERSION(3,18,0) gtk_style_context_set_background(sctx, gtk_widget_get_window(widget)); gtk_style_context_set_background(sctx, form->bin_window); # endif } #else widget->style = gtk_style_attach(widget->style, widget->window); gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL); gtk_style_set_background(widget->style, form->bin_window, GTK_STATE_NORMAL); #endif for (tmp_list = form->children; tmp_list; tmp_list = tmp_list->next) { GtkFormChild *child = tmp_list->data; gtk_form_attach_child_window(form, child); if (gtk_widget_get_visible(child->widget)) gtk_form_realize_child(form, child); } }