1/* simple.c
2 * Copyright (C) 1997 Red Hat, Inc
3 * Author: Elliot Lee
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18#include <gtk/gtk.h>
19#include <string.h>
20
21static char *
22get_content (void)
23{
24 GString *s;
25 int i;
26
27 s = g_string_new (init: "");
28 for (i = 1; i <= 150; i++)
29 g_string_append_printf (string: s, format: "Line %d\n", i);
30
31 return g_string_free (string: s, FALSE);
32}
33
34static void
35mode_changed (GtkComboBox *combo, GtkScrolledWindow *sw)
36{
37 int active = gtk_combo_box_get_active (combo_box: combo);
38
39 gtk_scrolled_window_set_overlay_scrolling (scrolled_window: sw, overlay_scrolling: active == 1);
40}
41
42static void
43quit_cb (GtkWidget *widget,
44 gpointer data)
45{
46 gboolean *done = data;
47
48 *done = TRUE;
49
50 g_main_context_wakeup (NULL);
51}
52
53int
54main (int argc, char *argv[])
55{
56 GtkWidget *window;
57 char *content;
58 GtkWidget *box;
59 GtkWidget *sw;
60 GtkWidget *tv;
61 GtkWidget *sb2;
62 GtkWidget *combo;
63 GtkAdjustment *adj;
64 gboolean done = FALSE;
65
66 gtk_init ();
67
68 window = gtk_window_new ();
69 gtk_window_set_default_size (GTK_WINDOW (window), width: 640, height: 480);
70 g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
71
72 box = gtk_box_new (orientation: GTK_ORIENTATION_HORIZONTAL, spacing: 20);
73 gtk_window_set_child (GTK_WINDOW (window), child: box);
74
75 sw = gtk_scrolled_window_new ();
76 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
77 hscrollbar_policy: GTK_POLICY_NEVER,
78 vscrollbar_policy: GTK_POLICY_AUTOMATIC);
79
80 gtk_widget_set_hexpand (widget: sw, TRUE);
81 gtk_box_append (GTK_BOX (box), child: sw);
82
83 content = get_content ();
84
85 tv = gtk_text_view_new ();
86 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (tv), wrap_mode: GTK_WRAP_WORD);
87 gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), child: tv);
88 gtk_text_buffer_set_text (buffer: gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv)),
89 text: content, len: -1);
90 g_free (mem: content);
91
92 adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (tv));
93
94 combo = gtk_combo_box_text_new ();
95 gtk_widget_set_valign (widget: combo, align: GTK_ALIGN_START);
96 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text: "Traditional");
97 gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), text: "Overlay");
98 g_signal_connect (combo, "changed", G_CALLBACK (mode_changed), sw);
99 gtk_combo_box_set_active (GTK_COMBO_BOX (combo), index_: 1);
100
101 gtk_box_append (GTK_BOX (box), child: combo);
102
103 sb2 = gtk_scrollbar_new (orientation: GTK_ORIENTATION_VERTICAL, adjustment: adj);
104 gtk_box_append (GTK_BOX (box), child: sb2);
105
106 gtk_widget_show (widget: window);
107
108 while (!done)
109 g_main_context_iteration (NULL, TRUE);
110
111 return 0;
112}
113

source code of gtk/tests/overlayscroll.c