summaryrefslogtreecommitdiff
path: root/tests/syncscroll.c
blob: d33b6ab850e4bc72e7e0aba26011a2728d45b9c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#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 ();

  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_container_add (GTK_CONTAINER (box), sw);
  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_container_add (GTK_CONTAINER (box), sw);
  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_container_add (GTK_CONTAINER (box), sw);
  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 (win);

  while (TRUE)
    g_main_context_iteration (NULL, TRUE);

  return 0;
}