Exemple #1
0
// handle a keypress in edit mode
// 0 = unhandled
// 1 = handled
// -1 = handled and return pressed (finished)
int textbox_keypress(textbox *tb, XEvent *ev)
{
	if (!(tb->flags & TB_EDITABLE)) return 0;

	KeySym key; Status stat; char pad[32];

	int len = XmbLookupString(tb->xic, &ev->xkey, pad, sizeof(pad), &key, &stat);
	pad[len] = 0;

	switch (key)
	{
		case XK_Left      : textbox_cursor_dec(tb);   return 1;
		case XK_Right     : textbox_cursor_inc(tb);   return 1;
		case XK_Home      : textbox_cursor_home(tb);  return 1;
		case XK_End       : textbox_cursor_end(tb);   return 1;
		case XK_Delete    : textbox_cursor_del(tb);   return 1;
		case XK_BackSpace : textbox_cursor_bkspc(tb); return 1;
		case XK_Return    : return -1;
		default:
			if (!iscntrl(*pad))
			{
				textbox_insert(tb, tb->cursor, pad);
				textbox_cursor_inc(tb);
				return 1;
			}
	}
	return 0;
}
Exemple #2
0
// 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;
}