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 

gtkentry default selection

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
durgesh.mishra
Familiar Face


Joined: 11 Mar 2010
Posts: 21

PostPosted: Wed Mar 17, 2010 6:23 pm    Post subject: gtkentry default selection Reply with quote

Hi Experts,

I am creating gtkentry widget. I set default text in it. On running, the program I get the expected text but it comes by default selected. I do not want the text appearing in gtkentry as selected and I want to set the cursor to some 'x' position in the default text. How can I do that?

Thanks beforehand.

Kind Regards
-Durgesh O Mishra
Back to top
joelding
Familiar Face


Joined: 04 Jun 2009
Posts: 13

PostPosted: Thu Mar 18, 2010 2:12 pm    Post subject: Reply with quote

Hello -Durgesh O Mishra,

Please try gtk_editable_set_position ().

Joel Ding
Back to top
durgesh.mishra
Familiar Face


Joined: 11 Mar 2010
Posts: 21

PostPosted: Thu Mar 18, 2010 2:51 pm    Post subject: select region does not work Reply with quote

Hi,

set_position works but when I try to unselect the by default selected text by select_region of gtk_editable it simply does nothing.

Kind Regards
-Durgesh O Mishra
Back to top
tadeboro
Never Seen the Sunlight


Joined: 23 Jul 2008
Posts: 2114
Location: Slovenia

PostPosted: Sat Mar 20, 2010 12:01 am    Post subject: Reply with quote

Hello.

Can you post a minimalistic but complete (compilable) application that demonstrates this problem? I've done some GtkEntry patching cca. a week from now and I don't remember seeing anything unusual in it's code that would cause this behavior.

Tadej
Back to top
durgesh.mishra
Familiar Face


Joined: 11 Mar 2010
Posts: 21

PostPosted: Sun Mar 21, 2010 7:51 am    Post subject: Reply with quote

Here is the code.

Even after setting the region from 1 to 3. It still keeps the whole text selected by default.


gint destroyapp (GtkWidget *widget, gpointer gdata)
{
g_print ("Quitting...\n");
gtk_main_quit();
return (FALSE);
}




int main (int argc, char *argv[])
{
/*-- Declare the GTK Widgets used in the program --*/
GtkWidget *window;
GtkWidget *table;
GtkWidget *label1;
GtkWidget *label2;
GtkWidget *entry1;
GtkWidget *entry2;

/*-- Initialize GTK --*/
gtk_init (&argc, &argv);

/*-- Create the new window --*/
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

/*-- Create the entry widgets --*/
entry1 = gtk_entry_new();
entry2 = gtk_entry_new();

/*-- Set entry2 to be non-editable --*/
gtk_entry_set_editable(GTK_ENTRY(entry2), FALSE);

/*-- Create the text --*/
gtk_entry_set_text(GTK_ENTRY(entry1), "Some text...");
gtk_entry_append_text(GTK_ENTRY(entry1), "Some more text appended");
gtk_entry_set_text(GTK_ENTRY(entry2), "Some text...");
gtk_entry_append_text(GTK_ENTRY(entry2), "Some more text appended");

/* deselect the gtk_entry */
gtk_editable_select_region(GTK_EDITABLE(entry1),1,3);

/*--Create the labels --*/
label1 = gtk_label_new("Editable text entry widget:");
label2 = gtk_label_new("Non-editable text entry widget:");

/*-- Create the 2x2 table --*/
table = gtk_table_new(2, 2, FALSE);

/*-- Connect the window to the destroyapp function --*/
gtk_signal_connect(GTK_OBJECT(window), "delete_event", GTK_SIGNAL_FUNC(destroyapp), NULL);

/*-- Add the items to the table --*/
gtk_table_attach(GTK_TABLE(table), label1, 0, 1, 0, 1, GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
gtk_table_attach(GTK_TABLE(table), label2, 0, 1, 1, 2, GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
gtk_table_attach(GTK_TABLE(table), entry1, 1, 2, 0, 1, GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
gtk_table_attach(GTK_TABLE(table), entry2, 1, 2, 1, 2, GTK_EXPAND | GTK_SHRINK | GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);

/*-- Add the table to the window --*/
gtk_container_add(GTK_CONTAINER(window), table);

/*-- Set window border to zero so that text area takes up the whole window --*/
gtk_container_border_width (GTK_CONTAINER (window), 5);

/*-- Set the window to be 640 x 480 pixels --*/
gtk_window_set_default_size (GTK_WINDOW(window), 500, 100);

/*-- Set the window title --*/
gtk_window_set_title(GTK_WINDOW (window), "GtkEntry");

/*-- Display the widgets --*/
gtk_widget_show(table);
gtk_widget_show(entry1);
gtk_widget_show(entry2);
gtk_widget_show(label1);
gtk_widget_show(label2);
gtk_widget_show(window);

/*-- Start the GTK event loop --*/
gtk_main();

/*-- Return 0 if exit is successful --*/
return 0;
}
Back to top
tadeboro
Never Seen the Sunlight


Joined: 23 Jul 2008
Posts: 2114
Location: Slovenia

PostPosted: Sun Mar 21, 2010 4:01 pm    Post subject: Reply with quote

Hi.

You're having problems because GtkEntry and it's buffer are not properly initialized yet when you call gtk_editable_select_region(). Move this line of code after the last gtk_widget_show() call and thing will work as expected.

Tadej
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