textbox.c
// handle a keypress in edit mode
// 0 = unhandled
// 1 = handled
// -1 = handled and return pressed (finished)
handle a keypress in edit mode
0 = unhandled
1 = handled
1 = handled and return pressed (finished)
handle a keypress in edit mode 0 = unhandled 1 = handled 1 = handled and return pressed ( finished )
int textbox_keypress(textbox *tb, XEvent *ev)
{
	KeySym key; Status stat;
	char pad[32]; int len;
	if (!(tb->flags & TB_EDITABLE)) return 0;
	len = XmbLookupString(tb->xic, &ev->xkey, pad, sizeof(pad), &key, &stat);
	pad[len] = 0;
	if (key == XK_Left)
	{
		textbox_cursor_dec(tb);
		return 1;
	}
	else
	if (key == XK_Right)
	{
		textbox_cursor_inc(tb);
		return 1;
	}
	else
	if (key == XK_Home)
	{
		textbox_cursor_home(tb);
		return 1;
	}
	else
	if (key == XK_End)
	{
		textbox_cursor_end(tb);
		return 1;
	}
	else
	if (key == XK_Delete)
	{
		textbox_cursor_del(tb);
		return 1;
	}
	else
	if (key == XK_BackSpace)
	{
		textbox_cursor_bkspc(tb);
		return 1;
	}
	else
	if (key == XK_Return)
	{
		return -1;
	}
	else
	if (!iscntrl(*pad))
	{
		textbox_insert(tb, tb->cursor, pad);
		textbox_cursor_inc(tb);
		return 1;
	}
	return 0;
}
int textbox_keypress ( textbox * tb , XEvent * ev ) { KeySym key ; Status stat ; char pad [ 32 ] ; int len ; if ( ! ( tb -> flags & TB_EDITABLE ) ) return 0 ; len = XmbLookupString ( tb -> xic , & ev -> xkey , pad , sizeof ( pad ) , & key , & stat ) ; pad [ len ] = 0 ; if ( key == XK_Left ) { textbox_cursor_dec ( tb ) ; return 1 ; } else if ( key == XK_Right ) { textbox_cursor_inc ( tb ) ; return 1 ; } else if ( key == XK_Home ) { textbox_cursor_home ( tb ) ; return 1 ; } else if ( key == XK_End ) { textbox_cursor_end ( tb ) ; return 1 ; } else if ( key == XK_Delete ) { textbox_cursor_del ( tb ) ; return 1 ; } else if ( key == XK_BackSpace ) { textbox_cursor_bkspc ( tb ) ; return 1 ; } else if ( key == XK_Return ) { return -1 ; } else if ( ! iscntrl ( * pad ) ) { textbox_insert ( tb , tb -> cursor , pad ) ; textbox_cursor_inc ( tb ) ; return 1 ; } return 0 ; }
handle a keypress in edit mode
0 = unhandled
1 = handled
1 = handled and return pressed (finished)
handle a keypress in edit mode 0 = unhandled 1 = handled 1 = handled and return pressed ( finished )