summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2015-12-02 23:10:56 -0500
committerMatthias Clasen <mclasen@redhat.com>2015-12-02 23:10:56 -0500
commit574246a3d8a687a14a9104ce93528aa2a7665c90 (patch)
treed70354b8df7e49c95afdf65447b03c95ea6991a5 /tests
parent16eed47e87559cd7e4194a110d0af2762010d5e7 (diff)
downloadgtk+-574246a3d8a687a14a9104ce93528aa2a7665c90.tar.gz
Add a selected text example
Diffstat (limited to 'tests')
-rw-r--r--tests/foreigndrawing.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/foreigndrawing.c b/tests/foreigndrawing.c
index 03b1a6aa9b..3b9d9bdfba 100644
--- a/tests/foreigndrawing.c
+++ b/tests/foreigndrawing.c
@@ -100,6 +100,54 @@ draw_horizontal_scrollbar (GtkWidget *widget,
g_object_unref (scrollbar_context);
}
+static void
+draw_text (GtkWidget *widget,
+ cairo_t *cr,
+ gint x,
+ gint y,
+ gint width,
+ gint height,
+ const gchar *text,
+ GtkStateFlags state)
+{
+ GtkStyleContext *label_context;
+ GtkStyleContext *selection_context;
+ GtkStyleContext *context;
+ PangoLayout *layout;
+
+ PathElt label_path[1] = {
+ { GTK_TYPE_LABEL, "label", "view", NULL },
+ };
+
+ PathElt selection_path[2] = {
+ { GTK_TYPE_LABEL, "label", "view", NULL },
+ { G_TYPE_NONE, "selection", NULL, NULL }
+ };
+
+ label_context = get_style (label_path, G_N_ELEMENTS (label_path));
+ selection_context = get_style (selection_path, G_N_ELEMENTS (selection_path));
+ gtk_style_context_set_parent (selection_context, label_context);
+
+ gtk_style_context_set_state (label_context, state);
+
+
+ if (state & GTK_STATE_FLAG_SELECTED)
+ context = selection_context;
+ else
+ context = label_context;
+
+ layout = gtk_widget_create_pango_layout (widget, text);
+
+ gtk_render_background (context, cr, x, y, width, height);
+ gtk_render_frame (context, cr, x, y, width, height);
+ gtk_render_layout (context, cr, x, y, layout);
+
+ g_object_unref (layout);
+
+ g_object_unref (selection_context);
+ g_object_unref (label_context);
+}
+
static gboolean
draw_cb (GtkWidget *widget,
cairo_t *cr)
@@ -112,6 +160,9 @@ draw_cb (GtkWidget *widget,
draw_horizontal_scrollbar (widget, cr, 10, 30, width - 20, 10, 40, GTK_STATE_FLAG_PRELIGHT);
draw_horizontal_scrollbar (widget, cr, 10, 50, width - 20, 10, 50, GTK_STATE_FLAG_ACTIVE|GTK_STATE_FLAG_PRELIGHT);
+ draw_text (widget, cr, 10, 70, width - 20, 20, "Not selected", GTK_STATE_FLAG_NORMAL);
+ draw_text (widget, cr, 10, 100, width - 20, 20, "Selected", GTK_STATE_FLAG_SELECTED);
+
return FALSE;
}