GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Apr 24, 2014 3:23 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: color name from gtkcolorselctiondialog
PostPosted: Sat Oct 07, 2006 9:02 am 
Offline
GTK+ Geek

Joined: Fri Oct 06, 2006 6:37 am
Posts: 57
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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 08, 2006 2:57 am 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
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 ....

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 4:50 am 
Offline
GTK+ Geek

Joined: Fri Oct 06, 2006 6:37 am
Posts: 57
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 3:04 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
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:
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:
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:
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! :)

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject: thaank u
PostPosted: Wed Oct 11, 2006 9:03 am 
Offline
GTK+ Geek

Joined: Fri Oct 06, 2006 6:37 am
Posts: 57
thank u very much.
it is very useful to me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group