[gtk+] testtextview: Add test for gtk_text_view_add_child_in_window
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] testtextview: Add test for gtk_text_view_add_child_in_window
- Date: Fri, 10 Jan 2014 11:06:26 +0000 (UTC)
commit 59bf558995e7994960da62c9a5dabcd5274b6ebe
Author: Alexander Larsson <alexl redhat com>
Date: Wed Jan 8 14:02:17 2014 +0100
testtextview: Add test for gtk_text_view_add_child_in_window
https://bugzilla.gnome.org/show_bug.cgi?id=711826
tests/testtextview.c | 38 +++++++++++++++++++++++++++++++-------
1 files changed, 31 insertions(+), 7 deletions(-)
---
diff --git a/tests/testtextview.c b/tests/testtextview.c
index 2a49539..22fe524 100644
--- a/tests/testtextview.c
+++ b/tests/testtextview.c
@@ -31,12 +31,13 @@ create_tags (GtkTextBuffer *buffer)
}
-static void
+static GtkTextChildAnchor *
insert_text (GtkTextBuffer *buffer)
{
GtkTextIter iter;
GtkTextIter start, end;
GtkTextMark *para_start;
+ GtkTextChildAnchor *anchor;
/* get start of buffer; each insertion will revalidate the
* iterator to point to just after the inserted text.
@@ -65,6 +66,8 @@ insert_text (GtkTextBuffer *buffer)
NULL);
gtk_text_buffer_insert (buffer, &iter, ".\n\n", -1);
+ anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
+
/* Store the beginning of the other paragraph */
para_start = gtk_text_buffer_create_mark (buffer, "para_start", &iter, TRUE);
@@ -99,6 +102,8 @@ insert_text (GtkTextBuffer *buffer)
/* Apply word_wrap tag to whole buffer */
gtk_text_buffer_get_bounds (buffer, &start, &end);
gtk_text_buffer_apply_tag_by_name (buffer, "word_wrap", &start, &end);
+
+ return anchor;
}
@@ -153,27 +158,46 @@ draw_background (GtkWidget *widget, cairo_t *cr)
int
main (int argc, char **argv)
{
- GtkWidget *window, *textview;
+ GtkWidget *window, *textview, *sw, *button, *button2;
GtkTextBuffer *buffer;
+ GtkTextChildAnchor *anchor;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ sw = gtk_scrolled_window_new (NULL, NULL);
textview = gtk_text_view_new ();
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");
+
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
- gtk_window_set_default_size (GTK_WINDOW (window), 400, -1);
+ gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
create_tags (buffer);
- insert_text (buffer);
-
+ anchor = insert_text (buffer);
+
+ gtk_widget_show (button);
+ gtk_widget_show (button2);
gtk_widget_show (textview);
- gtk_container_add (GTK_CONTAINER (window), textview);
+ gtk_widget_show (sw);
+
+ gtk_container_add (GTK_CONTAINER (window), sw);
+ gtk_container_add (GTK_CONTAINER (sw), textview);
+ gtk_text_view_add_child_in_window (GTK_TEXT_VIEW (textview),
+ button,
+ GTK_TEXT_WINDOW_TEXT,
+ 50, 150);
+
+ 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 ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]