trapping key strokes



In a particular editable text window, I don't want to let the user
backspace over the first two columns on the left.  I'm trying to trap
the relevant keystrokes with this sort of thing:

void console_handler (GtkWidget *w, GdkEventKey *key)
{
    extern GtkWidget *console_view;
    int len = gtk_text_get_length(GTK_TEXT(console_view));

    /* don't allow backspace into first 2 cols */
    if (key->keyval == GDK_BackSpace) {
	int cw;

	cw = gdk_char_width(GTK_WIDGET(console_view)->style->font,
				    (gchar) 'X');
	if (GTK_TEXT(console_view)->cursor_pos_x / cw < 2) {
	    key->keyval = GDK_VoidSymbol;
	    return;
	}
    }
}

It's working partly: on screen, backspacing halts at col. 2 as
desired.  But the backspace keystroke is still being stored somehow in
the gtk_text.  When I fetch the text, after backspacing at col. 2,
it is not what appears on screen.  E.g.

"? this is what I see"

becomes

"hat I see"

I must be missing something with the logic of gdk events.  Any help
would be appreciated.

Allin Cottrell.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]