RE: GtkTextView - reacting to some key events?
- From: martyn 2 russell bt com
- To: gtk-app-devel-list gnome org
- Subject: RE: GtkTextView - reacting to some key events?
- Date: Tue, 1 Apr 2003 15:04:57 +0100
I have a GtkTextView that is used to type in chat messages. I would
like to "know" when the user presses enter or control+enter while
typing some text in that view...what's the best way to do this ? (I
don't want to use GtkEntry since i need it to handle more
than one line)
You probably want something like this hooked up to the "key_release_event"
or the "key_press_event":
gboolean on_textview_send_key_release_event(GtkWidget *widget,
GdkEventKey *event, gpointer user_data)
{
GtkTextBuffer *buffer = NULL;
gint mod = 0;
if(event == NULL)
return FALSE;
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(mytextview));
/* set modifier (i.e. alt, ctrl, etc... ) */
mod = (GDK_CONTROL_MASK);
if((event->state & mod) == mod && (event->keyval == GDK_Return)
{
/* do something with CTRL+Return pressed */
GtkTextIter iter_start;
GtkTextIter iter_end;
gchar *buf = NULL;
gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(buffer),
&iter_start, &iter_end);
buf = gtk_text_buffer_get_slice(GTK_TEXT_BUFFER(buffer),
&iter_start, &iter_end, FALSE);
/* do something with text */
/* remove text entered after finished with it... */
gtk_text_buffer_delete(GTK_TEXT_BUFFER(buffer), &iter_start,
&iter_end);
if(buf != NULL) g_free(buf);
}
else if(event->keyval == GDK_Return)
{
/* do something with JUST return pressed */
}
return FALSE;
}
Regards,
Martyn
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]