summaryrefslogtreecommitdiff
path: root/tests/syncscroll.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2014-10-09 20:17:10 -0400
committerMatthias Clasen <mclasen@redhat.com>2014-10-09 20:18:51 -0400
commit9dcb33ad344d00c5548cb2bc1479dcda9e4580aa (patch)
tree3a6cab933cd6f4ced6b74607d6862157b716a2f8 /tests/syncscroll.c
parent94b680c2cd3c4573067322082860dde26cf5bffa (diff)
downloadgtk+-9dcb33ad344d00c5548cb2bc1479dcda9e4580aa.tar.gz
Add an example for synchronized scrolling
This example uses GTK_POLICY_EXTERNAL to share a scrollbar among multiple scrolled windows.
Diffstat (limited to 'tests/syncscroll.c')
-rw-r--r--tests/syncscroll.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/syncscroll.c b/tests/syncscroll.c
new file mode 100644
index 0000000000..881ad647b5
--- /dev/null
+++ b/tests/syncscroll.c
@@ -0,0 +1,69 @@
+#include <gtk/gtk.h>
+
+static void
+fill_text_view (GtkWidget *tv, const gchar *text)
+{
+ gint i;
+ GString *s;
+
+ s = g_string_new ("");
+ for (i = 0; i < 200; i++)
+ g_string_append_printf (s, "%s %d\n", text, i);
+
+ gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv)),
+ g_string_free (s, FALSE), -1);
+}
+
+int
+main (int argc, char *argv[])
+{
+ GtkWidget *win, *box, *tv, *sw, *sb;
+ GtkAdjustment *adj;
+
+ gtk_init (NULL, NULL);
+
+ win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size (GTK_WINDOW (win), 640, 480);
+
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
+ gtk_container_add (GTK_CONTAINER (win), box);
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_NEVER,
+ GTK_POLICY_EXTERNAL);
+ gtk_box_pack_start (GTK_BOX (box), sw, TRUE, TRUE, 0);
+ tv = gtk_text_view_new ();
+ fill_text_view (tv, "Left");
+ gtk_container_add (GTK_CONTAINER (sw), tv);
+
+ adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (sw));
+
+ sw = gtk_scrolled_window_new (NULL, adj);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_NEVER,
+ GTK_POLICY_EXTERNAL);
+ gtk_box_pack_start (GTK_BOX (box), sw, TRUE, TRUE, 0);
+ tv = gtk_text_view_new ();
+ fill_text_view (tv, "Middle");
+ gtk_container_add (GTK_CONTAINER (sw), tv);
+
+ sw = gtk_scrolled_window_new (NULL, adj);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_NEVER,
+ GTK_POLICY_EXTERNAL);
+ gtk_box_pack_start (GTK_BOX (box), sw, TRUE, TRUE, 0);
+ tv = gtk_text_view_new ();
+ fill_text_view (tv, "Right");
+ gtk_container_add (GTK_CONTAINER (sw), tv);
+
+ sb = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, adj);
+
+ gtk_container_add (GTK_CONTAINER (box), sb);
+
+ gtk_widget_show_all (win);
+
+ gtk_main ();
+
+ return 0;
+}