GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Inserting text on a GtkTextView, with colors and styles

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code
Author Message
carlos
Familiar Face


Joined: 25 Mar 2008
Posts: 7

PostPosted: Tue Mar 25, 2008 10:19 pm    Post subject: Inserting text on a GtkTextView, with colors and styles Reply with quote

Code: (C)
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
#include <gtk/gtk.h>

int main (int argc, char **argv)
{
GtkWidget *window, *text;
GtkTextBuffer *buffer;
GtkTextIter iter;
GdkColor color;

gtk_init (&argc, &argv);

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window), 200, 100);

text = gtk_text_view_new ();
gtk_container_add (GTK_CONTAINER (window), text);
gtk_text_view_set_editable (GTK_TEXT_VIEW (text), FALSE);
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (text), FALSE);
gtk_text_view_set_justification (GTK_TEXT_VIEW (text), GTK_JUSTIFY_LEFT);
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text), GTK_WRAP_WORD);
gtk_widget_show (text);

gdk_color_parse ("yellow", &color);
gtk_widget_modify_base (text, GTK_STATE_NORMAL, &color);
gtk_widget_modify_base (text, GTK_STATE_ACTIVE, &color);
gtk_widget_modify_base (text, GTK_STATE_PRELIGHT, &color);
gtk_widget_modify_base (text, GTK_STATE_SELECTED, &color);
gtk_widget_modify_base (text, GTK_STATE_INSENSITIVE, &color);

buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text));

gdk_color_parse ("blue", &color);
gtk_text_buffer_create_tag (buffer, "color_blue", "foreground-gdk", &color, NULL);
gdk_color_parse ("red", &color);
gtk_text_buffer_create_tag (buffer, "color_red", "foreground-gdk", &color, NULL);

gtk_text_buffer_create_tag (buffer, "style_italic", "style", PANGO_STYLE_ITALIC, NULL);
gtk_text_buffer_create_tag (buffer, "weight_bold", "weight", PANGO_WEIGHT_BOLD, NULL);
gtk_text_buffer_create_tag (buffer, "size_medium", "scale", PANGO_SCALE_MEDIUM, NULL);
gtk_text_buffer_create_tag (buffer, "size_large", "scale", PANGO_SCALE_LARGE, NULL);

gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "Hello", -1,
"size_medium", "style_italic", "color_blue", NULL);
gtk_text_buffer_insert_with_tags_by_name (buffer, &iter, "World!", -1,
"size_large", "weight_bold", "color_red", NULL);

gtk_widget_show (window);

gtk_main ();
return 0;
}
[/code]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP