2014-10-05 03:37:11 +00:00
|
|
|
/* simple.c
|
|
|
|
* Copyright (C) 1997 Red Hat, Inc
|
|
|
|
* Author: Elliot Lee
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
get_content (void)
|
|
|
|
{
|
|
|
|
GString *s;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
s = g_string_new ("");
|
|
|
|
for (i = 1; i <= 150; i++)
|
|
|
|
g_string_append_printf (s, "Line %d\n", i);
|
|
|
|
|
|
|
|
return g_string_free (s, FALSE);
|
|
|
|
}
|
|
|
|
|
2014-10-09 21:03:52 +00:00
|
|
|
static void
|
|
|
|
mode_changed (GtkComboBox *combo, GtkScrolledWindow *sw)
|
|
|
|
{
|
|
|
|
gint active = gtk_combo_box_get_active (combo);
|
|
|
|
|
|
|
|
gtk_scrolled_window_set_overlay_scrolling (sw, active == 1);
|
|
|
|
}
|
2014-10-05 03:37:11 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2014-10-05 03:37:11 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
gchar *content;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *sw;
|
|
|
|
GtkWidget *tv;
|
|
|
|
GtkWidget *sb2;
|
|
|
|
GtkWidget *combo;
|
|
|
|
GtkAdjustment *adj;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2014-10-05 03:37:11 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2014-10-05 03:37:11 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2014-10-05 03:37:11 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
|
2014-10-05 03:37:11 +00:00
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 20);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), box);
|
2014-10-05 03:37:11 +00:00
|
|
|
|
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
|
|
|
GTK_POLICY_NEVER,
|
2014-10-09 21:03:52 +00:00
|
|
|
GTK_POLICY_AUTOMATIC);
|
2014-10-05 03:37:11 +00:00
|
|
|
|
2020-05-10 21:18:06 +00:00
|
|
|
gtk_widget_set_hexpand (sw, TRUE);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (box), sw);
|
2014-10-05 03:37:11 +00:00
|
|
|
|
|
|
|
content = get_content ();
|
|
|
|
|
|
|
|
tv = gtk_text_view_new ();
|
|
|
|
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (tv), GTK_WRAP_WORD);
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), tv);
|
2014-10-05 03:37:11 +00:00
|
|
|
gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (tv)),
|
|
|
|
content, -1);
|
|
|
|
g_free (content);
|
|
|
|
|
|
|
|
adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (tv));
|
|
|
|
|
|
|
|
combo = gtk_combo_box_text_new ();
|
|
|
|
gtk_widget_set_valign (combo, GTK_ALIGN_START);
|
2014-10-09 21:03:52 +00:00
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Traditional");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Overlay");
|
|
|
|
g_signal_connect (combo, "changed", G_CALLBACK (mode_changed), sw);
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 1);
|
2014-10-05 03:37:11 +00:00
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), combo);
|
|
|
|
|
|
|
|
sb2 = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, adj);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), sb2);
|
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2014-10-05 03:37:11 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2014-10-05 03:37:11 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|