[dia/zbrown/test-build: 3/6] areas: use gtk3 style drawing with a gtk2 thunk
- From: Zander Brown <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia/zbrown/test-build: 3/6] areas: use gtk3 style drawing with a gtk2 thunk
- Date: Fri, 24 Sep 2021 18:56:49 +0000 (UTC)
commit 36f931cb234bdc026d2fb4cc21e7e969bcf0d976
Author: Zander Brown <zbrown gnome org>
Date: Fri Sep 24 03:15:44 2021 +0100
areas: use gtk3 style drawing with a gtk2 thunk
In theory they now build against both 2 and (with lots of warnings) 3
Once we are gtk3 we can just drop the thunks
Ironically gtk4 will need cairo glue again, ce'st la vie
app/dia-colour-area.c | 32 ++++++++++++++++++++++++++------
app/dia-line-width-area.c | 32 ++++++++++++++++++++++++++------
2 files changed, 52 insertions(+), 12 deletions(-)
---
diff --git a/app/dia-colour-area.c b/app/dia-colour-area.c
index 8008d1b1c..5c457977e 100644
--- a/app/dia-colour-area.c
+++ b/app/dia-colour-area.c
@@ -67,15 +67,14 @@ dia_colour_area_target (DiaColourArea *self,
return -1;
}
+
static gboolean
-dia_colour_area_draw (GtkWidget *self, /*cairo_t *ctx*/
- GdkEventExpose *event)
+dia_colour_area_draw (GtkWidget *self, cairo_t *ctx)
{
GdkColor fg, bg;
int rect_w, rect_h;
int img_width, img_height;
DiaColourArea *priv = DIA_COLOUR_AREA (self);
- cairo_t *ctx = gdk_cairo_create (gtk_widget_get_window (self));
GtkAllocation alloc;
gtk_widget_get_allocation (GTK_WIDGET (self), &alloc);
@@ -116,6 +115,24 @@ dia_colour_area_draw (GtkWidget *self, /*cairo_t *ctx*/
}
+#if !GTK_CHECK_VERSION (3, 0, 0)
+static gboolean
+dia_colour_area_expose_event (GtkWidget *widget, GdkEventExpose *event)
+{
+ cairo_t *ctx;
+ gboolean res;
+
+ ctx = gdk_cairo_create (GDK_DRAWABLE (gtk_widget_get_window (widget)));
+
+ res = dia_colour_area_draw (widget, ctx);
+
+ cairo_destroy (ctx);
+
+ return res;
+}
+#endif
+
+
static void
dia_colour_area_response (GtkDialog *chooser,
int response,
@@ -266,10 +283,13 @@ dia_colour_area_button_press_event (GtkWidget *widget,
static void
dia_colour_area_class_init (DiaColourAreaClass *class)
{
- GtkWidgetClass *widget_class;
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
- widget_class = GTK_WIDGET_CLASS (class);
- widget_class->expose_event = dia_colour_area_draw;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ widget_class->draw = dia_colour_area_draw;
+#else
+ widget_class->expose_event = dia_colour_area_expose_event;
+#endif
widget_class->button_press_event = dia_colour_area_button_press_event;
attributes_set_foreground (persistence_register_color ("fg_color",
diff --git a/app/dia-line-width-area.c b/app/dia-line-width-area.c
index d1ad0df69..c0d569d83 100644
--- a/app/dia-line-width-area.c
+++ b/app/dia-line-width-area.c
@@ -140,9 +140,9 @@ dia_line_width_area_create_dialog (DiaLineWidthArea *self,
persistence_register_window (GTK_WINDOW (self->dialog));
}
+
static gboolean
-dia_line_width_area_draw (GtkWidget *self, /*cairo_t *ctx*/
- GdkEventExpose *event)
+dia_line_width_area_draw (GtkWidget *self, cairo_t *ctx)
{
GdkColor fg;
int i;
@@ -151,7 +151,6 @@ dia_line_width_area_draw (GtkWidget *self, /*cairo_t *ctx*/
double dashes[] = { 3 };
DiaLineWidthArea *priv = DIA_LINE_WIDTH_AREA (self);
GtkAllocation alloc;
- cairo_t *ctx = gdk_cairo_create (gtk_widget_get_window (self));
gtk_widget_get_allocation (self, &alloc);
@@ -186,6 +185,24 @@ dia_line_width_area_draw (GtkWidget *self, /*cairo_t *ctx*/
}
+#if !GTK_CHECK_VERSION (3, 0, 0)
+static gboolean
+dia_line_width_area_expose_event (GtkWidget *widget, GdkEventExpose *event)
+{
+ cairo_t *ctx;
+ gboolean res;
+
+ ctx = gdk_cairo_create (GDK_DRAWABLE (gtk_widget_get_window (widget)));
+
+ res = dia_line_width_area_draw (widget, ctx);
+
+ cairo_destroy (ctx);
+
+ return res;
+}
+#endif
+
+
static gboolean
dia_line_width_area_button_press_event (GtkWidget *self,
GdkEventButton *event)
@@ -221,10 +238,13 @@ dia_line_width_area_button_press_event (GtkWidget *self,
static void
dia_line_width_area_class_init (DiaLineWidthAreaClass *class)
{
- GtkWidgetClass *widget_class;
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
- widget_class = GTK_WIDGET_CLASS (class);
- widget_class->expose_event = dia_line_width_area_draw;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ widget_class->draw = dia_line_width_area_draw;
+#else
+ widget_class->expose_event = dia_line_width_area_expose_event;
+#endif
widget_class->button_press_event = dia_line_width_area_button_press_event;
attributes_set_default_linewidth (persistence_register_real ("linewidth", 0.1));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]