gtk_editable_select_region doesn't always work???
- From: Shilad Sen <shilad clairv com>
- To: gtk-list redhat com
- Subject: gtk_editable_select_region doesn't always work???
- Date: Thu, 27 Apr 2000 11:16:08 -0500 (CDT)
Hello,
I have recently started developing some apps that use GTK. I
came across a problem with the GtkText widget.
I want to have a select a region of text based on certain events
associated with keystrokes. I can't seem to select a region of text
in a callback and have it "stick". It appears that the selected
region is always removed later on.
I have tried connecting to "insert_text" and "changed" signals both
with gtk_signal_connect and gtk_signal_connect_after.
The problem can be boiled down to this useless example snippet
which is SUPPOSED to select all text when the text is equal to
"select".
Thanks in advance for any suggestions,
Shilad Sen
___________________________________________________________________
#include <gtk/gtk.h>
#include <stdio.h>
void
handle_key(GtkEditable *area,
const gchar *text,
gint length,
gint *position,
gpointer data)
{
char *cp;
cp = gtk_editable_get_chars(area, 0, -1);
if (strcmp(cp, "select") == 0) {
gtk_editable_select_region(area, 0, -1);
printf("selecting region\n");
}
g_free(cp);
}
int
main(int argc, char *argv[])
{
GtkWidget *win;
GtkWidget *area;
gtk_init(&argc, &argv);
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
area = gtk_text_new(NULL, NULL);
gtk_text_set_editable(GTK_TEXT(area), TRUE);
gtk_signal_connect_after(GTK_OBJECT(area), "insert_text",
GTK_SIGNAL_FUNC(handle_key), NULL);
gtk_container_add(GTK_CONTAINER(win), area);
gtk_widget_show(area);
gtk_widget_show(win);
gtk_main();
return(0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]