[gtk/abolish-size-allocate: 78/87] drawingarea: Add a ::resize signal
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/abolish-size-allocate: 78/87] drawingarea: Add a ::resize signal
- Date: Wed, 6 May 2020 18:01:55 +0000 (UTC)
commit c6d06bbd71f80693fea45a915e453ca28d5dca54
Author: Matthias Clasen <mclasen redhat com>
Date: Tue May 5 11:49:00 2020 -0400
drawingarea: Add a ::resize signal
This can be used as a replacement for ::size-allocate
to prepare size-dependent resources, like a backing
surface. It mirrors the GtkGLArea::resize signal.
gtk/gtkdrawingarea.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
gtk/gtkdrawingarea.h | 4 ++++
2 files changed, 47 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkdrawingarea.c b/gtk/gtkdrawingarea.c
index 0e3fd65bbb..201768e179 100644
--- a/gtk/gtkdrawingarea.c
+++ b/gtk/gtkdrawingarea.c
@@ -25,6 +25,7 @@
#include "config.h"
#include "gtkdrawingarea.h"
#include "gtkintl.h"
+#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtksnapshot.h"
#include "gtkstylecontext.h"
@@ -50,6 +51,13 @@ enum {
static GParamSpec *props[LAST_PROP] = { NULL, };
+enum {
+ RESIZE,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0, };
+
/**
* SECTION:gtkdrawingarea
* @Short_description: A simple widget for drawing with cairo
@@ -64,7 +72,7 @@ static GParamSpec *props[LAST_PROP] = { NULL, };
* when the widget is instantiated on a particular display.
* (Create GDK resources in response to this signal.)
*
- * - The #GtkWidget::size-allocate signal to take any necessary
+ * - The #GtkDrawingArea::resize signal to take any necessary
* actions when the widget changes size.
*
* - Call gtk_drawing_area_set_draw_func() to handle redrawing the
@@ -222,6 +230,15 @@ gtk_drawing_area_measure (GtkWidget *widget,
}
}
+static void
+gtk_drawing_area_size_allocate (GtkWidget *widget,
+ int width,
+ int height,
+ int baseline)
+{
+ g_signal_emit (widget, signals[RESIZE], 0, width, height);
+}
+
static void
gtk_drawing_area_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot)
@@ -264,6 +281,7 @@ gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
widget_class->snapshot = gtk_drawing_area_snapshot;
widget_class->focus = gtk_widget_focus_none;
widget_class->grab_focus = gtk_widget_grab_focus_none;
+ widget_class->size_allocate = gtk_drawing_area_size_allocate;
/**
* GtkDrawingArea:content-width
@@ -291,6 +309,29 @@ gtk_drawing_area_class_init (GtkDrawingAreaClass *class)
g_object_class_install_properties (gobject_class, LAST_PROP, props);
+ /**
+ * GtkDrawingArea::resize:
+ * @area: the #GtkDrawingArea that emitted the signal
+ * @width: the width of the viewport
+ * @height: the height of the viewport
+ *
+ * The ::resize signal is emitted once when the widget is realized, and
+ * then each time the widget is changed while realized. This is useful
+ * in order to keep state up to date with the widget size, like for
+ * instance a backing surface.
+ */
+ signals[RESIZE] =
+ g_signal_new (I_("resize"),
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkDrawingAreaClass, resize),
+ NULL, NULL,
+ _gtk_marshal_VOID__INT_INT,
+ G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
+ g_signal_set_va_marshaller (signals[RESIZE],
+ G_TYPE_FROM_CLASS (class),
+ _gtk_marshal_VOID__INT_INTv);
+
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_DRAWING_AREA);
}
@@ -419,7 +460,7 @@ gtk_drawing_area_get_content_height (GtkDrawingArea *self)
* @destroy: destroy notifier for @user_data
*
* Setting a draw function is the main thing you want to do when using a drawing
- * area. It is called whenever GTK needs to draw the contents of the drawing area
+ * area. It is called whenever GTK needs to draw the contents of the drawing area
* to the screen.
*
* The draw function will be called during the drawing stage of GTK. In the
diff --git a/gtk/gtkdrawingarea.h b/gtk/gtkdrawingarea.h
index 47cd8df622..4d49c3f27e 100644
--- a/gtk/gtkdrawingarea.h
+++ b/gtk/gtkdrawingarea.h
@@ -75,6 +75,10 @@ struct _GtkDrawingAreaClass
{
GtkWidgetClass parent_class;
+ void (* resize) (GtkDrawingArea *area,
+ int width,
+ int height);
+
/*< private >*/
gpointer padding[8];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]