2015-07-29 23:07:56 +00:00
|
|
|
/* Text View/Multiple Views
|
2000-11-13 06:08:51 +00:00
|
|
|
*
|
|
|
|
* The GtkTextView widget displays a GtkTextBuffer. One GtkTextBuffer
|
|
|
|
* can be displayed by multiple GtkTextViews. This demo has two views
|
|
|
|
* displaying a single buffer, and shows off the widget's text
|
|
|
|
* formatting features.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2001-11-06 00:54:24 +00:00
|
|
|
#include <stdlib.h> /* for exit() */
|
2020-02-06 15:33:34 +00:00
|
|
|
#include "paintable.h"
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2001-11-06 18:25:15 +00:00
|
|
|
static void easter_egg_callback (GtkWidget *button, gpointer data);
|
|
|
|
|
2000-11-13 06:08:51 +00:00
|
|
|
static void
|
|
|
|
create_tags (GtkTextBuffer *buffer)
|
|
|
|
{
|
|
|
|
/* Create a bunch of tags. Note that it's also possible to
|
|
|
|
* create tags with gtk_text_tag_new() then add them to the
|
|
|
|
* tag table for the buffer, gtk_text_buffer_create_tag() is
|
|
|
|
* just a convenience function. Also note that you don't have
|
|
|
|
* to give tags a name; pass NULL for the name to create an
|
|
|
|
* anonymous tag.
|
|
|
|
*
|
|
|
|
* In any real app, another useful optimization would be to create
|
|
|
|
* a GtkTextTagTable in advance, and reuse the same tag table for
|
|
|
|
* all the buffers with the same tag set, instead of creating
|
|
|
|
* new copies of the same tags for every buffer.
|
|
|
|
*
|
|
|
|
* Tags are assigned default priorities in order of addition to the
|
2010-11-09 16:20:17 +00:00
|
|
|
* tag table. That is, tags created later that affect the same text
|
2001-03-16 19:32:20 +00:00
|
|
|
* property affected by an earlier tag will override the earlier
|
|
|
|
* tag. You can modify tag priorities with
|
|
|
|
* gtk_text_tag_set_priority().
|
2000-11-13 06:08:51 +00:00
|
|
|
*/
|
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "heading",
|
2010-11-09 16:20:17 +00:00
|
|
|
"weight", PANGO_WEIGHT_BOLD,
|
|
|
|
"size", 15 * PANGO_SCALE,
|
|
|
|
NULL);
|
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "italic",
|
2010-11-09 16:20:17 +00:00
|
|
|
"style", PANGO_STYLE_ITALIC, NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "bold",
|
2010-11-09 16:20:17 +00:00
|
|
|
"weight", PANGO_WEIGHT_BOLD, NULL);
|
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "big",
|
2010-11-09 16:20:17 +00:00
|
|
|
/* points times the PANGO_SCALE factor */
|
|
|
|
"size", 20 * PANGO_SCALE, NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2001-05-07 15:58:47 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "xx-small",
|
2010-11-09 16:20:17 +00:00
|
|
|
"scale", PANGO_SCALE_XX_SMALL, NULL);
|
2001-05-07 15:58:47 +00:00
|
|
|
|
|
|
|
gtk_text_buffer_create_tag (buffer, "x-large",
|
2010-11-09 16:20:17 +00:00
|
|
|
"scale", PANGO_SCALE_X_LARGE, NULL);
|
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "monospace",
|
2010-11-09 16:20:17 +00:00
|
|
|
"family", "monospace", NULL);
|
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "blue_foreground",
|
2010-11-09 16:20:17 +00:00
|
|
|
"foreground", "blue", NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "red_background",
|
2010-11-09 16:20:17 +00:00
|
|
|
"background", "red", NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "big_gap_before_line",
|
2010-11-09 16:20:17 +00:00
|
|
|
"pixels_above_lines", 30, NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "big_gap_after_line",
|
2010-11-09 16:20:17 +00:00
|
|
|
"pixels_below_lines", 30, NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "double_spaced_line",
|
2010-11-09 16:20:17 +00:00
|
|
|
"pixels_inside_wrap", 10, NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "not_editable",
|
2010-11-09 16:20:17 +00:00
|
|
|
"editable", FALSE, NULL);
|
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "word_wrap",
|
2010-11-09 16:20:17 +00:00
|
|
|
"wrap_mode", GTK_WRAP_WORD, NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "char_wrap",
|
2010-11-09 16:20:17 +00:00
|
|
|
"wrap_mode", GTK_WRAP_CHAR, NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "no_wrap",
|
2010-11-09 16:20:17 +00:00
|
|
|
"wrap_mode", GTK_WRAP_NONE, NULL);
|
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "center",
|
2010-11-09 16:20:17 +00:00
|
|
|
"justification", GTK_JUSTIFY_CENTER, NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "right_justify",
|
2010-11-09 16:20:17 +00:00
|
|
|
"justification", GTK_JUSTIFY_RIGHT, NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "wide_margins",
|
2010-11-09 16:20:17 +00:00
|
|
|
"left_margin", 50, "right_margin", 50,
|
|
|
|
NULL);
|
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "strikethrough",
|
2010-11-09 16:20:17 +00:00
|
|
|
"strikethrough", TRUE, NULL);
|
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "underline",
|
2010-11-09 16:20:17 +00:00
|
|
|
"underline", PANGO_UNDERLINE_SINGLE, NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "double_underline",
|
2010-11-09 16:20:17 +00:00
|
|
|
"underline", PANGO_UNDERLINE_DOUBLE, NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "superscript",
|
2010-11-09 16:20:17 +00:00
|
|
|
"rise", 10 * PANGO_SCALE, /* 10 pixels */
|
|
|
|
"size", 8 * PANGO_SCALE, /* 8 points */
|
|
|
|
NULL);
|
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_create_tag (buffer, "subscript",
|
2010-11-09 16:20:17 +00:00
|
|
|
"rise", -10 * PANGO_SCALE, /* 10 pixels */
|
|
|
|
"size", 8 * PANGO_SCALE, /* 8 points */
|
|
|
|
NULL);
|
2001-03-16 19:32:20 +00:00
|
|
|
|
|
|
|
gtk_text_buffer_create_tag (buffer, "rtl_quote",
|
2010-11-09 16:20:17 +00:00
|
|
|
"wrap_mode", GTK_WRAP_WORD,
|
|
|
|
"direction", GTK_TEXT_DIR_RTL,
|
|
|
|
"indent", 30,
|
|
|
|
"left_margin", 20,
|
|
|
|
"right_margin", 20,
|
|
|
|
NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-01 22:38:49 +00:00
|
|
|
insert_text (GtkTextView *view)
|
2000-11-13 06:08:51 +00:00
|
|
|
{
|
2020-02-01 23:27:14 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (view);
|
2020-02-01 22:38:49 +00:00
|
|
|
GtkTextBuffer *buffer = gtk_text_view_get_buffer (view);
|
2000-11-13 06:08:51 +00:00
|
|
|
GtkTextIter iter;
|
|
|
|
GtkTextIter start, end;
|
2013-11-05 20:29:54 +00:00
|
|
|
GtkIconTheme *icon_theme;
|
2020-02-04 16:19:22 +00:00
|
|
|
GtkIconPaintable *icon;
|
2020-02-06 15:33:34 +00:00
|
|
|
GdkPaintable *nuclear;
|
2013-11-05 20:29:54 +00:00
|
|
|
|
2020-02-01 23:27:14 +00:00
|
|
|
icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (widget));
|
2020-01-28 09:30:01 +00:00
|
|
|
icon = gtk_icon_theme_lookup_icon (icon_theme,
|
2020-02-06 15:33:34 +00:00
|
|
|
"face-cool",
|
2020-02-04 02:53:22 +00:00
|
|
|
NULL,
|
2020-01-28 15:14:52 +00:00
|
|
|
32, 1,
|
2020-02-01 23:27:14 +00:00
|
|
|
gtk_widget_get_direction (widget),
|
2020-02-04 03:26:19 +00:00
|
|
|
0);
|
2020-02-06 15:33:34 +00:00
|
|
|
nuclear = gtk_nuclear_animation_new ();
|
2000-11-14 04:57:33 +00:00
|
|
|
|
2000-11-13 06:08:51 +00:00
|
|
|
/* get start of buffer; each insertion will revalidate the
|
|
|
|
* iterator to point to just after the inserted text.
|
|
|
|
*/
|
|
|
|
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
|
|
|
|
|
2019-11-01 18:30:33 +00:00
|
|
|
gtk_text_buffer_begin_irreversible_action (buffer);
|
2010-11-09 16:20:17 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter,
|
|
|
|
"The text widget can display text with all kinds of nifty attributes. "
|
|
|
|
"It also supports multiple views of the same buffer; this demo is "
|
|
|
|
"showing the same buffer in two places.\n\n", -1);
|
|
|
|
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
|
|
|
"Font styles. ", -1,
|
|
|
|
"heading", NULL);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
|
|
|
gtk_text_buffer_insert (buffer, &iter, "For example, you can have ", -1);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"italic", -1,
|
|
|
|
"italic", NULL);
|
|
|
|
gtk_text_buffer_insert (buffer, &iter, ", ", -1);
|
2000-11-13 06:08:51 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"bold", -1,
|
|
|
|
"bold", NULL);
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, ", or ", -1);
|
2000-11-13 06:08:51 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"monospace (typewriter)", -1,
|
|
|
|
"monospace", NULL);
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, ", or ", -1);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"big", -1,
|
|
|
|
"big", NULL);
|
2001-05-07 15:58:47 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, " text. ", -1);
|
2010-11-09 16:20:17 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter,
|
|
|
|
"It's best not to hardcode specific text sizes; you can use relative "
|
|
|
|
"sizes as with CSS, such as ", -1);
|
2001-05-07 15:58:47 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"xx-small", -1,
|
|
|
|
"xx-small", NULL);
|
2001-05-07 15:58:47 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, " or ", -1);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"x-large", -1,
|
|
|
|
"x-large", NULL);
|
|
|
|
gtk_text_buffer_insert (buffer, &iter,
|
|
|
|
" to ensure that your program properly adapts if the user changes the "
|
|
|
|
"default font size.\n\n", -1);
|
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Colors. ", -1,
|
2010-11-09 16:20:17 +00:00
|
|
|
"heading", NULL);
|
|
|
|
|
|
|
|
gtk_text_buffer_insert (buffer, &iter, "Colors such as ", -1);
|
2000-11-13 06:08:51 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"a blue foreground", -1,
|
|
|
|
"blue_foreground", NULL);
|
|
|
|
gtk_text_buffer_insert (buffer, &iter, " or ", -1);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
|
|
|
"a red background", -1,
|
|
|
|
"red_background", NULL);
|
|
|
|
gtk_text_buffer_insert (buffer, &iter, " or even ", -1);
|
2000-11-13 06:08:51 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"a blue foreground on red background", -1,
|
|
|
|
"blue_foreground",
|
|
|
|
"red_background",
|
|
|
|
NULL);
|
|
|
|
gtk_text_buffer_insert (buffer, &iter, " (select that to read it) can be used.\n\n", -1);
|
|
|
|
|
2000-11-13 06:08:51 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"Underline, strikethrough, and rise. ", -1,
|
|
|
|
"heading", NULL);
|
|
|
|
|
2000-11-14 04:57:33 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"Strikethrough", -1,
|
|
|
|
"strikethrough", NULL);
|
2000-11-14 04:57:33 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, ", ", -1);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"underline", -1,
|
|
|
|
"underline", NULL);
|
2000-11-14 04:57:33 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, ", ", -1);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"double underline", -1,
|
|
|
|
"double_underline", NULL);
|
2000-11-14 04:57:33 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, ", ", -1);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"superscript", -1,
|
|
|
|
"superscript", NULL);
|
2000-11-14 04:57:33 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, ", and ", -1);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"subscript", -1,
|
|
|
|
"subscript", NULL);
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, " are all supported.\n\n", -1);
|
2000-11-14 04:57:33 +00:00
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Images. ", -1,
|
2010-11-09 16:20:17 +00:00
|
|
|
"heading", NULL);
|
|
|
|
|
2000-11-14 04:57:33 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, "The buffer can have images in it: ", -1);
|
2020-02-06 15:33:34 +00:00
|
|
|
gtk_text_buffer_insert_paintable (buffer, &iter, GDK_PAINTABLE (icon));
|
|
|
|
gtk_text_buffer_insert_paintable (buffer, &iter, GDK_PAINTABLE (icon));
|
|
|
|
|
|
|
|
gtk_text_buffer_insert_paintable (buffer, &iter, nuclear);
|
|
|
|
|
2001-03-16 19:32:20 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, " for example.\n\n", -1);
|
|
|
|
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Spacing. ", -1,
|
2010-11-09 16:20:17 +00:00
|
|
|
"heading", NULL);
|
|
|
|
|
|
|
|
gtk_text_buffer_insert (buffer, &iter,
|
|
|
|
"You can adjust the amount of space before each line.\n", -1);
|
2001-03-16 19:32:20 +00:00
|
|
|
|
2000-11-14 04:57:33 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"This line has a whole lot of space before it.\n", -1,
|
|
|
|
"big_gap_before_line", "wide_margins", NULL);
|
2000-11-14 04:57:33 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"You can also adjust the amount of space after each line; "
|
|
|
|
"this line has a whole lot of space after it.\n", -1,
|
|
|
|
"big_gap_after_line", "wide_margins", NULL);
|
|
|
|
|
2000-11-14 04:57:33 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"You can also adjust the amount of space between wrapped lines; "
|
|
|
|
"this line has extra space between each wrapped line in the same "
|
|
|
|
"paragraph. To show off wrapping, some filler text: the quick "
|
|
|
|
"brown fox jumped over the lazy dog. Blah blah blah blah blah "
|
|
|
|
"blah blah blah blah.\n", -1,
|
|
|
|
"double_spaced_line", "wide_margins", NULL);
|
|
|
|
|
|
|
|
gtk_text_buffer_insert (buffer, &iter,
|
|
|
|
"Also note that those lines have extra-wide margins.\n\n", -1);
|
2000-11-14 04:57:33 +00:00
|
|
|
|
2010-11-09 16:20:17 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
|
|
|
"Editability. ", -1,
|
|
|
|
"heading", NULL);
|
2001-03-16 19:32:20 +00:00
|
|
|
|
2000-11-14 04:57:33 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"This line is 'locked down' and can't be edited by the user - just "
|
|
|
|
"try it! You can't delete this line.\n\n", -1,
|
|
|
|
"not_editable", NULL);
|
2000-11-14 04:57:33 +00:00
|
|
|
|
2010-11-09 16:20:17 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
|
|
|
"Wrapping. ", -1,
|
|
|
|
"heading", NULL);
|
2001-03-16 19:32:20 +00:00
|
|
|
|
|
|
|
gtk_text_buffer_insert (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"This line (and most of the others in this buffer) is word-wrapped, "
|
|
|
|
"using the proper Unicode algorithm. Word wrap should work in all "
|
2019-02-05 09:19:57 +00:00
|
|
|
"scripts and languages that GTK supports. Let's make this a long "
|
2010-11-09 16:20:17 +00:00
|
|
|
"paragraph to demonstrate: blah blah blah blah blah blah blah blah "
|
|
|
|
"blah blah blah blah blah blah blah blah blah blah blah\n\n", -1);
|
|
|
|
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
|
|
|
"This line has character-based wrapping, and can wrap between any two "
|
|
|
|
"character glyphs. Let's make this a long paragraph to demonstrate: "
|
|
|
|
"blah blah blah blah blah blah blah blah blah blah blah blah blah blah "
|
|
|
|
"blah blah blah blah blah\n\n", -1, "char_wrap", NULL);
|
|
|
|
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
|
|
|
"This line has all wrapping turned off, so it makes the horizontal "
|
|
|
|
"scrollbar appear.\n\n\n", -1, "no_wrap", NULL);
|
|
|
|
|
2000-11-14 04:57:33 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"Justification. ", -1,
|
|
|
|
"heading", NULL);
|
|
|
|
|
2000-11-14 04:57:33 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"\nThis line has center justification.\n", -1,
|
|
|
|
"center", NULL);
|
2001-03-16 19:32:20 +00:00
|
|
|
|
2000-11-14 04:57:33 +00:00
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"This line has right justification.\n", -1,
|
|
|
|
"right_justify", NULL);
|
2000-11-14 04:57:33 +00:00
|
|
|
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"\nThis line has big wide margins. Text text text text text text text "
|
|
|
|
"text text text text text text text text text text text text text text "
|
|
|
|
"text text text text text text text text text text text text text text "
|
|
|
|
"text.\n", -1, "wide_margins", NULL);
|
2000-11-14 04:57:33 +00:00
|
|
|
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"Internationalization. ", -1,
|
|
|
|
"heading", NULL);
|
|
|
|
|
|
|
|
gtk_text_buffer_insert (buffer, &iter,
|
|
|
|
"You can put all sorts of Unicode text in the buffer.\n\nGerman "
|
|
|
|
"(Deutsch S\303\274d) Gr\303\274\303\237 Gott\nGreek "
|
|
|
|
"(\316\225\316\273\316\273\316\267\316\275\316\271\316\272\316\254) "
|
|
|
|
"\316\223\316\265\316\271\316\254 \317\203\316\261\317\202\nHebrew "
|
|
|
|
"\327\251\327\234\327\225\327\235\nJapanese "
|
|
|
|
"(\346\227\245\346\234\254\350\252\236)\n\nThe widget properly handles "
|
|
|
|
"bidirectional text, word wrapping, DOS/UNIX/Unicode paragraph separators, "
|
|
|
|
"grapheme boundaries, and so on using the Pango internationalization "
|
|
|
|
"framework.\n", -1);
|
2001-03-16 19:32:20 +00:00
|
|
|
|
|
|
|
gtk_text_buffer_insert (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"Here's a word-wrapped quote in a right-to-left language:\n", -1);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
|
|
|
|
"\331\210\331\202\330\257 \330\250\330\257\330\243 "
|
|
|
|
"\330\253\331\204\330\247\330\253 \331\205\331\206 "
|
|
|
|
"\330\243\331\203\330\253\330\261 \330\247\331\204\331\205\330\244\330\263\330\263\330\247\330\252 "
|
|
|
|
"\330\252\331\202\330\257\331\205\330\247 \331\201\331\212 "
|
|
|
|
"\330\264\330\250\331\203\330\251 \330\247\331\203\330\263\331\212\331\210\331\206 "
|
|
|
|
"\330\250\330\261\330\247\331\205\330\254\331\207\330\247 "
|
|
|
|
"\331\203\331\205\331\206\330\270\331\205\330\247\330\252 "
|
|
|
|
"\331\204\330\247 \330\252\330\263\330\271\331\211 \331\204\331\204\330\261\330\250\330\255\330\214 "
|
|
|
|
"\330\253\331\205 \330\252\330\255\331\210\331\204\330\252 "
|
|
|
|
"\331\201\331\212 \330\247\331\204\330\263\331\206\331\210\330\247\330\252 "
|
|
|
|
"\330\247\331\204\330\256\331\205\330\263 \330\247\331\204\331\205\330\247\330\266\331\212\330\251 "
|
|
|
|
"\330\245\331\204\331\211 \331\205\330\244\330\263\330\263\330\247\330\252 "
|
|
|
|
"\331\205\330\247\331\204\331\212\330\251 \331\205\331\206\330\270\331\205\330\251\330\214 "
|
|
|
|
"\331\210\330\250\330\247\330\252\330\252 \330\254\330\262\330\241\330\247 "
|
|
|
|
"\331\205\331\206 \330\247\331\204\331\206\330\270\330\247\331\205 "
|
|
|
|
"\330\247\331\204\331\205\330\247\331\204\331\212 \331\201\331\212 "
|
|
|
|
"\330\250\331\204\330\257\330\247\331\206\331\207\330\247\330\214 "
|
|
|
|
"\331\210\331\204\331\203\331\206\331\207\330\247 \330\252\330\252\330\256\330\265\330\265 "
|
|
|
|
"\331\201\331\212 \330\256\330\257\331\205\330\251 \331\202\330\267\330\247\330\271 "
|
|
|
|
"\330\247\331\204\331\205\330\264\330\261\331\210\330\271\330\247\330\252 "
|
|
|
|
"\330\247\331\204\330\265\330\272\331\212\330\261\330\251. \331\210\330\243\330\255\330\257 "
|
|
|
|
"\330\243\331\203\330\253\330\261 \331\207\330\260\331\207 "
|
|
|
|
"\330\247\331\204\331\205\330\244\330\263\330\263\330\247\330\252 "
|
|
|
|
"\331\206\330\254\330\247\330\255\330\247 \331\207\331\210 "
|
|
|
|
"\302\273\330\250\330\247\331\206\331\203\331\210\330\263\331\210\331\204\302\253 "
|
|
|
|
"\331\201\331\212 \330\250\331\210\331\204\331\212\331\201\331\212\330\247.\n\n", -1,
|
|
|
|
"rtl_quote", NULL);
|
2001-03-16 19:32:20 +00:00
|
|
|
|
2010-11-09 16:20:17 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter,
|
|
|
|
"You can put widgets in the buffer: Here's a button: ", -1);
|
2011-05-27 02:22:24 +00:00
|
|
|
gtk_text_buffer_create_child_anchor (buffer, &iter);
|
2001-11-06 00:54:24 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, " and a menu: ", -1);
|
2011-05-27 02:22:24 +00:00
|
|
|
gtk_text_buffer_create_child_anchor (buffer, &iter);
|
2001-11-06 00:54:24 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, " and a scale: ", -1);
|
2011-05-27 02:22:24 +00:00
|
|
|
gtk_text_buffer_create_child_anchor (buffer, &iter);
|
2001-11-06 00:54:24 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, " finally a text entry: ", -1);
|
2011-05-27 02:22:24 +00:00
|
|
|
gtk_text_buffer_create_child_anchor (buffer, &iter);
|
2001-11-06 00:54:24 +00:00
|
|
|
gtk_text_buffer_insert (buffer, &iter, ".\n", -1);
|
2010-11-09 16:20:17 +00:00
|
|
|
|
|
|
|
gtk_text_buffer_insert (buffer, &iter,
|
|
|
|
"\n\nThis demo doesn't demonstrate all the GtkTextBuffer features; "
|
|
|
|
"it leaves out, for example: invisible/hidden text, tab stops, "
|
|
|
|
"application-drawn areas on the sides of the widget for displaying "
|
|
|
|
"breakpoints and such...", -1);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
|
|
|
/* Apply word_wrap tag to whole buffer */
|
|
|
|
gtk_text_buffer_get_bounds (buffer, &start, &end);
|
|
|
|
gtk_text_buffer_apply_tag_by_name (buffer, "word_wrap", &start, &end);
|
2000-11-14 04:57:33 +00:00
|
|
|
|
2019-11-01 18:30:33 +00:00
|
|
|
gtk_text_buffer_end_irreversible_action (buffer);
|
|
|
|
|
2020-02-06 15:33:34 +00:00
|
|
|
g_object_unref (icon);
|
|
|
|
g_object_unref (nuclear);
|
2000-11-13 06:08:51 +00:00
|
|
|
}
|
|
|
|
|
2001-11-06 00:54:24 +00:00
|
|
|
static gboolean
|
|
|
|
find_anchor (GtkTextIter *iter)
|
|
|
|
{
|
|
|
|
while (gtk_text_iter_forward_char (iter))
|
|
|
|
{
|
|
|
|
if (gtk_text_iter_get_child_anchor (iter))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
attach_widgets (GtkTextView *text_view)
|
|
|
|
{
|
|
|
|
GtkTextIter iter;
|
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
int i;
|
2010-11-09 16:20:17 +00:00
|
|
|
|
2001-11-06 00:54:24 +00:00
|
|
|
buffer = gtk_text_view_get_buffer (text_view);
|
|
|
|
|
|
|
|
gtk_text_buffer_get_start_iter (buffer, &iter);
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while (find_anchor (&iter))
|
|
|
|
{
|
|
|
|
GtkTextChildAnchor *anchor;
|
|
|
|
GtkWidget *widget;
|
2010-11-09 16:20:17 +00:00
|
|
|
|
2001-11-06 00:54:24 +00:00
|
|
|
anchor = gtk_text_iter_get_child_anchor (&iter);
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
widget = gtk_button_new_with_label ("Click Me");
|
2001-11-06 18:25:15 +00:00
|
|
|
|
2002-09-29 21:24:24 +00:00
|
|
|
g_signal_connect (widget, "clicked",
|
2001-11-06 18:25:15 +00:00
|
|
|
G_CALLBACK (easter_egg_callback),
|
|
|
|
NULL);
|
2001-11-06 00:54:24 +00:00
|
|
|
}
|
|
|
|
else if (i == 1)
|
|
|
|
{
|
2010-10-02 16:19:46 +00:00
|
|
|
widget = gtk_combo_box_text_new ();
|
2001-11-06 00:54:24 +00:00
|
|
|
|
2010-10-02 16:19:46 +00:00
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Option 1");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Option 2");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (widget), "Option 3");
|
2001-11-06 00:54:24 +00:00
|
|
|
}
|
|
|
|
else if (i == 2)
|
|
|
|
{
|
2010-10-30 00:07:28 +00:00
|
|
|
widget = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, NULL);
|
2001-11-06 00:54:24 +00:00
|
|
|
gtk_range_set_range (GTK_RANGE (widget), 0, 100);
|
|
|
|
gtk_widget_set_size_request (widget, 70, -1);
|
|
|
|
}
|
|
|
|
else if (i == 3)
|
|
|
|
{
|
|
|
|
widget = gtk_entry_new ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
widget = NULL; /* avoids a compiler warning */
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_text_view_add_child_at_anchor (text_view,
|
|
|
|
widget,
|
|
|
|
anchor);
|
|
|
|
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-18 23:59:30 +00:00
|
|
|
GtkWidget *
|
2003-11-08 22:08:05 +00:00
|
|
|
do_textview (GtkWidget *do_widget)
|
2000-11-13 06:08:51 +00:00
|
|
|
{
|
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
GtkWidget *vpaned;
|
|
|
|
GtkWidget *view1;
|
|
|
|
GtkWidget *view2;
|
2000-11-14 04:57:33 +00:00
|
|
|
GtkWidget *sw;
|
2000-11-13 06:08:51 +00:00
|
|
|
GtkTextBuffer *buffer;
|
2010-11-09 16:20:17 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2020-05-09 16:03:11 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 450, 450);
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2015-06-20 01:59:15 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Multiple Views");
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2010-10-29 23:47:13 +00:00
|
|
|
vpaned = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), vpaned);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
|
|
|
/* For convenience, we just use the autocreated buffer from
|
|
|
|
* the first text view; you could also create the buffer
|
|
|
|
* by itself with gtk_text_buffer_new(), then later create
|
|
|
|
* a view widget.
|
|
|
|
*/
|
|
|
|
view1 = gtk_text_view_new ();
|
|
|
|
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view1));
|
|
|
|
view2 = gtk_text_view_new_with_buffer (buffer);
|
2010-11-09 16:20:17 +00:00
|
|
|
|
2000-11-14 04:57:33 +00:00
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
2010-11-09 16:20:17 +00:00
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2020-05-07 12:30:39 +00:00
|
|
|
gtk_paned_set_start_child (GTK_PANED (vpaned), sw);
|
|
|
|
gtk_paned_set_resize_start_child (GTK_PANED (vpaned), FALSE);
|
|
|
|
gtk_paned_set_shrink_start_child (GTK_PANED (vpaned), TRUE);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), view1);
|
2000-11-14 04:57:33 +00:00
|
|
|
|
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
2010-11-09 16:20:17 +00:00
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2020-05-07 12:30:39 +00:00
|
|
|
gtk_paned_set_end_child (GTK_PANED (vpaned), sw);
|
|
|
|
gtk_paned_set_resize_end_child (GTK_PANED (vpaned), TRUE);
|
|
|
|
gtk_paned_set_shrink_end_child (GTK_PANED (vpaned), TRUE);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), view2);
|
2000-11-13 06:08:51 +00:00
|
|
|
|
|
|
|
create_tags (buffer);
|
2020-02-01 22:38:49 +00:00
|
|
|
insert_text (GTK_TEXT_VIEW (view1));
|
2001-11-06 00:54:24 +00:00
|
|
|
|
|
|
|
attach_widgets (GTK_TEXT_VIEW (view1));
|
|
|
|
attach_widgets (GTK_TEXT_VIEW (view2));
|
2000-11-13 06:08:51 +00:00
|
|
|
}
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (window))
|
2000-11-18 23:59:30 +00:00
|
|
|
{
|
|
|
|
gtk_widget_show (window);
|
|
|
|
}
|
2000-11-13 06:08:51 +00:00
|
|
|
else
|
2000-11-18 23:59:30 +00:00
|
|
|
{
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2000-11-18 23:59:30 +00:00
|
|
|
window = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return window;
|
2000-11-13 06:08:51 +00:00
|
|
|
}
|
|
|
|
|
2001-11-06 18:25:15 +00:00
|
|
|
static void
|
|
|
|
recursive_attach_view (int depth,
|
|
|
|
GtkTextView *view,
|
|
|
|
GtkTextChildAnchor *anchor)
|
|
|
|
{
|
2014-10-03 04:59:14 +00:00
|
|
|
GtkWidget *child_view, *frame;
|
2010-11-09 16:20:17 +00:00
|
|
|
|
2001-11-06 18:25:15 +00:00
|
|
|
if (depth > 4)
|
|
|
|
return;
|
2010-11-09 16:20:17 +00:00
|
|
|
|
2001-11-06 18:25:15 +00:00
|
|
|
child_view = gtk_text_view_new_with_buffer (gtk_text_view_get_buffer (view));
|
|
|
|
|
2014-10-03 04:59:14 +00:00
|
|
|
/* Frame is to add a black border around each child view */
|
|
|
|
frame = gtk_frame_new (NULL);
|
2020-05-01 17:41:22 +00:00
|
|
|
gtk_frame_set_child (GTK_FRAME (frame), child_view);
|
2001-11-06 18:25:15 +00:00
|
|
|
|
2014-10-03 04:59:14 +00:00
|
|
|
gtk_text_view_add_child_at_anchor (view, frame, anchor);
|
2001-11-06 18:25:15 +00:00
|
|
|
|
|
|
|
recursive_attach_view (depth + 1, GTK_TEXT_VIEW (child_view), anchor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
easter_egg_callback (GtkWidget *button,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
static GtkWidget *window = NULL;
|
2008-07-18 18:27:30 +00:00
|
|
|
gpointer window_ptr;
|
2001-11-06 18:25:15 +00:00
|
|
|
GtkTextBuffer *buffer;
|
|
|
|
GtkWidget *view;
|
|
|
|
GtkTextIter iter;
|
|
|
|
GtkTextChildAnchor *anchor;
|
|
|
|
GtkWidget *sw;
|
|
|
|
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
gtk_window_present (GTK_WINDOW (window));
|
|
|
|
return;
|
|
|
|
}
|
2010-11-09 16:20:17 +00:00
|
|
|
|
2001-11-06 18:25:15 +00:00
|
|
|
buffer = gtk_text_buffer_new (NULL);
|
|
|
|
|
|
|
|
gtk_text_buffer_get_start_iter (buffer, &iter);
|
|
|
|
|
|
|
|
gtk_text_buffer_insert (buffer, &iter,
|
2010-11-09 16:20:17 +00:00
|
|
|
"This buffer is shared by a set of nested text views.\n Nested view:\n", -1);
|
2001-11-06 18:25:15 +00:00
|
|
|
anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
|
|
|
|
gtk_text_buffer_insert (buffer, &iter,
|
|
|
|
"\nDon't do this in real applications, please.\n", -1);
|
|
|
|
|
|
|
|
view = gtk_text_view_new_with_buffer (buffer);
|
2010-11-09 16:20:17 +00:00
|
|
|
|
2001-11-06 18:25:15 +00:00
|
|
|
recursive_attach_view (0, GTK_TEXT_VIEW (view), anchor);
|
2010-11-09 16:20:17 +00:00
|
|
|
|
2002-09-29 21:24:24 +00:00
|
|
|
g_object_unref (buffer);
|
2001-11-06 18:25:15 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2001-11-06 18:25:15 +00:00
|
|
|
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);
|
2001-11-06 18:25:15 +00:00
|
|
|
|
2008-07-18 18:27:30 +00:00
|
|
|
window_ptr = &window;
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), window_ptr);
|
2001-11-06 18:25:15 +00:00
|
|
|
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 300, 400);
|
2010-11-09 16:20:17 +00:00
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2001-11-06 18:25:15 +00:00
|
|
|
}
|