2016-11-29 21:39:21 +00:00
|
|
|
/* Text View/Tabs
|
|
|
|
*
|
|
|
|
* GtkTextView can position text at fixed positions, using tabs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
do_tabs (GtkWidget *do_widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
GtkWidget *view;
|
|
|
|
GtkWidget *sw;
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
PangoTabArray *tabs;
|
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2016-11-29 21:39:21 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Tabs");
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2016-11-29 21:39:21 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 450, 450);
|
2020-05-09 16:03:11 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
2016-11-29 21:39:21 +00:00
|
|
|
|
|
|
|
view = gtk_text_view_new ();
|
|
|
|
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD);
|
|
|
|
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (view), 20);
|
|
|
|
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (view), 20);
|
|
|
|
|
|
|
|
tabs = pango_tab_array_new (3, TRUE);
|
|
|
|
pango_tab_array_set_tab (tabs, 0, PANGO_TAB_LEFT, 0);
|
|
|
|
pango_tab_array_set_tab (tabs, 1, PANGO_TAB_LEFT, 150);
|
|
|
|
pango_tab_array_set_tab (tabs, 2, PANGO_TAB_LEFT, 300);
|
|
|
|
gtk_text_view_set_tabs (GTK_TEXT_VIEW (view), tabs);
|
|
|
|
pango_tab_array_free (tabs);
|
|
|
|
|
|
|
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
|
|
|
|
gtk_text_buffer_set_text (buffer, "one\ttwo\tthree\nfour\tfive\tsix\nseven\teight\tnine", -1);
|
|
|
|
|
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), sw);
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), view);
|
2016-11-29 21:39:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_widget_get_visible (window))
|
|
|
|
gtk_widget_show (window);
|
|
|
|
else
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2016-11-29 21:39:21 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|