summaryrefslogtreecommitdiff
path: root/tests/testtextview.c
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2014-07-28 21:19:31 +0200
committerAlexander Larsson <alexl@redhat.com>2014-07-28 21:19:31 +0200
commit341108d4fc93217c0aa3cf634e8d84bf79604c30 (patch)
tree0db7de7546d02d9e6523fb79bc4e265a9fe4fb2b /tests/testtextview.c
parent5b53eb287c170d21de149b088be5a3608349139b (diff)
downloadgtk+-341108d4fc93217c0aa3cf634e8d84bf79604c30.tar.gz
Update testtextview.c to use draw_layer
This fixes a regression in the test from the revert in commit 4fe051bb4a017d2840f2b0f4299512971f17a837.
Diffstat (limited to 'tests/testtextview.c')
-rw-r--r--tests/testtextview.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/tests/testtextview.c b/tests/testtextview.c
index 22fe524010..c46a59b69e 100644
--- a/tests/testtextview.c
+++ b/tests/testtextview.c
@@ -3,6 +3,36 @@
#include "config.h"
#include <gtk/gtk.h>
+typedef struct {
+ GtkTextView parent;
+} MyTextView;
+
+typedef struct {
+ GtkTextViewClass parent_class;
+} MyTextViewClass;
+
+G_DEFINE_TYPE (MyTextView, my_text_view, GTK_TYPE_TEXT_VIEW);
+
+static void draw_background (GtkWidget *widget, cairo_t *cr);
+
+static void
+my_text_view_init (MyTextView *text_view)
+{
+}
+
+static void my_text_view_draw_layer (GtkWidget *widget,
+ GtkTextViewLayer layer,
+ cairo_t *cr)
+{
+ if (layer == GTK_TEXT_VIEW_LAYER_BELOW)
+ draw_background (widget, cr);
+}
+
+static void
+my_text_view_class_init (MyTextViewClass *klass)
+{
+ GTK_TEXT_VIEW_CLASS (klass)->draw_layer = my_text_view_draw_layer;
+}
static void
create_tags (GtkTextBuffer *buffer)
@@ -138,10 +168,14 @@ get_checkered (void)
static void
draw_background (GtkWidget *widget, cairo_t *cr)
{
+ GdkRectangle visible_rect;
cairo_pattern_t *pat;
cairo_save (cr);
+ gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (widget), &visible_rect);
+ cairo_translate (cr, -visible_rect.x, -visible_rect.y);
+
cairo_set_source_rgb (cr, CHECK_DARK, CHECK_DARK, CHECK_DARK);
cairo_paint (cr);
@@ -166,7 +200,7 @@ main (int argc, char **argv)
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
sw = gtk_scrolled_window_new (NULL, NULL);
- textview = gtk_text_view_new ();
+ textview = g_object_new (my_text_view_get_type (), NULL);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
button = gtk_button_new_with_label ("Fixed Child");
button2 = gtk_button_new_with_label ("Flowed Child");
@@ -195,9 +229,6 @@ main (int argc, char **argv)
gtk_text_view_add_child_at_anchor (GTK_TEXT_VIEW (textview),
button2, anchor);
- g_signal_connect (textview, "draw",
- G_CALLBACK (draw_background), NULL);
-
gtk_widget_show (window);
gtk_main ();