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 

color name from gtkcolorselctiondialog

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
cnu_sree
GTK+ Geek


Joined: 06 Oct 2006
Posts: 57

PostPosted: Sat Oct 07, 2006 9:02 am    Post subject: color name from gtkcolorselctiondialog Reply with quote

how can we get colorname from color selection dialog.
i now
gtk_color_button_get_color(colorbutton,&color);
but i want name of the color.
so that i can create text buffer tags
please help
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 386
Location: Fairfax, Virginia

PostPosted: Sun Oct 08, 2006 2:57 am    Post subject: Reply with quote

You don't need to get the "color name" for text tags ... you can use the foreground-gdk text tag. If you need the hex code, you should use g_strdup_printf() along with the standard printf() tags for hex digits ....
Back to top
cnu_sree
GTK+ Geek


Joined: 06 Oct 2006
Posts: 57

PostPosted: Mon Oct 09, 2006 4:50 am    Post subject: Reply with quote

at first thank u for ur reply.

actually iam presently dealing with IM project.
in that i have two textview let's say t1,t2.
if u enter text in t1.
if we click ok button then it should be moved to t2.
if change the color of the textt in t1.for colors iam using colorselctionbutton.
in this point i want to create a tag. so that i can add the text with tht color in t2.

i didn't get so please give me a small example.
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 386
Location: Fairfax, Virginia

PostPosted: Mon Oct 09, 2006 3:04 pm    Post subject: Reply with quote

Oh, ok, so you want to move the text from the entry GtkTextView into the display pane while keeping tags. Well, this is a 2 step process. Let us assume we have 2 GtkTextView widgets called view1 and view2. First, to apply the color to the user's entry pane, you use the following (note: I didn't compile this code, so you will have to check for syntax errors...):

Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
GdkColor color;
GtkTextTag *tag;
GtkTextIter start, end;
GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view1));

gtk_color_button_get_color (colorbutton,&color);
tag = gtk_text_buffer_create_tag (buffer, NULL, "foreground-gdk", color);

gtk_text_buffer_get_selection_bounds (buffer, &start, &end);
gtk_text_buffer_apply_tag (buffer, tag, &start, &end);


This code creates a new foreground-gdk tag on the first text buffer & applies the tag from start to end. If there is selected text, the selection will become that color. If there is no selection (meaning that start == end), then it will be applied to the current cursor position and any text typed from that position will be the color. This works for any tags found in the GtkTextTag API documentation.

Then, you need to move the text to the new buffer:

Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
GtkTextIter start, end, insert;
GtkTextBuffer buffer1, buffer2;
GtkTextTagTable *table1, *table2;
gchar *text;

buffer1 = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view1));
buffer2 = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view2));

table1 = gtk_text_buffer_get_tag_table (buffer1);
table2 = gtK_text_buffer_get_tag_table (buffer2);
gtk_text_tag_table_foreach (table1, (GtkTextTagTableForeach) add_tag, table2);

gtk_text_buffer_get_bounds (buffer1, &start, &end);
gtk_text_buffer_get_end_iter (buffer2, &insert);

text = gtk_text_buffer_get_text (buffer1, &start, &end, TRUE);
gtk_text_buffer_set_text (buffer2, text, -1);
gtk_text_buffer_delete (buffer1, &start, &end);


This will get the tag tables for each buffers, and call a function add_tag(), shown below, which will copy all of the tags over. It will then copy over the text from buffer1 into buffer2 and then remove the text in buffer1.

Code: (Plaintext)
1
2
3
4
5
static void
add_tag (GtkTextTag *tag, GtkTextTagTable *table2)
{
  gtk_text_tag_table_add (table2, tag);
}


That _should_ work, although you may need to alter a thing or two.

I also have to give a small plug ... in March of 2007, my book Foundations of GTK+ Development will be released. You can find information about it, including preordering it, at http://book.andrewkrause.net. Good luck! :)
Back to top
cnu_sree
GTK+ Geek


Joined: 06 Oct 2006
Posts: 57

PostPosted: Wed Oct 11, 2006 9:03 am    Post subject: thaank u Reply with quote

thank u very much.
it is very useful to me.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming 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