static int thumbbar_prompt_value(struct widget *widget, struct key_event *k)
{
        int c;

        if (!NO_MODIFIER(k->mod)) {
                /* annoying */
                return 0;
        }
        if (k->sym == SDLK_MINUS) {
                if (widget->d.thumbbar.min >= 0)
                        return 0;
                c = '-';
        } else {
                c = numeric_key_event(k, 0);
                if (c < 0)
                        return 0;
                c += '0';
        }

        numprompt_create("Enter Value", thumbbar_prompt_finish, c);

        return 1;
}
Example #2
0
static int _handle_ime(struct key_event *k)
{
	int c, m;
	static int alt_numpad = 0;
	static int alt_numpad_c = 0;
	static int digraph_n = 0;
	static int digraph_c = 0;
	static int cs_unicode = 0;
	static int cs_unicode_c = 0;
	struct key_event fake;

	if (ACTIVE_PAGE.selected_widget > -1 && ACTIVE_PAGE.selected_widget < ACTIVE_PAGE.total_widgets
	    && ACTIVE_PAGE.widgets[ACTIVE_PAGE.selected_widget].accept_text) {
		if (digraph_n == -1 && k->state == KEY_RELEASE) {
			digraph_n = 0;

		} else if (!(status.flags & CLASSIC_MODE) && (k->sym == SDLK_LCTRL || k->sym == SDLK_RCTRL)) {
			if (k->state == KEY_RELEASE && digraph_n >= 0) {
				digraph_n++;
				if (digraph_n >= 2)
					status_text_flash_bios("Enter digraph:");
			}
		} else if (k->sym == SDLK_LSHIFT || k->sym == SDLK_RSHIFT) {
			/* do nothing */
		} else if (!NO_MODIFIER((k->mod&~KMOD_SHIFT)) || (c=k->unicode) == 0 || digraph_n < 2) {
			if (k->state == KEY_PRESS && k->mouse == MOUSE_NONE) {
				if (digraph_n > 0) status_text_flash(" ");
				digraph_n = -1;
			}
		} else if (digraph_n >= 2) {
			if (k->state == KEY_RELEASE)
				return 1;
			if (!digraph_c) {
				digraph_c = c;
				status_text_flash_bios("Enter digraph: %c", c);
			} else {
				memset(&fake, 0, sizeof(fake));
				fake.unicode = char_digraph(digraph_c, c);
				if (fake.unicode) {
					status_text_flash_bios("Enter digraph: %c%c -> %c",
							       digraph_c, c, fake.unicode);
				} else {
					status_text_flash_bios("Enter digraph: %c%c -> INVALID", digraph_c, c);
				}
				digraph_n = digraph_c = 0;
				if (fake.unicode) {
					fake.is_synthetic = 3;
					handle_key(&fake);
					fake.state = KEY_RELEASE;
					handle_key(&fake);
				}
			}
			return 1;
		} else {
			if (digraph_n > 0) status_text_flash(" ");
			digraph_n = 0;
		}

		/* ctrl+shift -> unicode character */
		if ((k->sym==SDLK_LCTRL || k->sym==SDLK_RCTRL || k->sym==SDLK_LSHIFT || k->sym==SDLK_RSHIFT)) {
			if (k->state == KEY_RELEASE && cs_unicode_c > 0) {
				memset(&fake, 0, sizeof(fake));
				fake.unicode = char_unicode_to_cp437(cs_unicode);
				if (fake.unicode) {
					status_text_flash_bios("Enter Unicode: U+%04X -> %c",
							       cs_unicode, fake.unicode);
					fake.is_synthetic = 3;
					handle_key(&fake);
					fake.state = KEY_RELEASE;
					handle_key(&fake);
				} else {
					status_text_flash_bios("Enter Unicode: U+%04X -> INVALID", cs_unicode);
				}
				cs_unicode = cs_unicode_c = 0;
				alt_numpad = alt_numpad_c = 0;
				digraph_n = digraph_c = 0;
				return 1;
			}
		} else if (!(status.flags & CLASSIC_MODE) && (k->mod & KMOD_CTRL) && (k->mod & KMOD_SHIFT)) {
			if (cs_unicode_c >= 0) {
				/* bleh... */
				m = k->mod;
				k->mod = 0;
				c = kbd_char_to_hex(k);
				k->mod = m;
				if (c == -1) {
					cs_unicode = cs_unicode_c = -1;
				} else {
					if (k->state == KEY_PRESS) return 1;
					cs_unicode *= 16;
					cs_unicode += c;
					cs_unicode_c++;
					digraph_n = digraph_c = 0;
					status_text_flash_bios("Enter Unicode: U+%04X", cs_unicode);
					return 1;
				}
			}
		} else {
			cs_unicode = cs_unicode_c = 0;
		}

		/* alt+numpad -> char number */
		if (k->sym == SDLK_LALT || k->sym == SDLK_RALT
		    || k->sym == SDLK_LMETA || k->sym == SDLK_RMETA) {
			if (k->state == KEY_RELEASE && alt_numpad_c > 0 && (alt_numpad & 255) > 0) {
				memset(&fake, 0, sizeof(fake));
				fake.unicode = alt_numpad & 255;
				if (!(status.flags & CLASSIC_MODE))
					status_text_flash_bios("Enter DOS/ASCII: %d -> %c",
							       (int)fake.unicode, (int)fake.unicode);
				fake.is_synthetic = 3;
				handle_key(&fake);
				fake.state = KEY_RELEASE;
				handle_key(&fake);
				alt_numpad = alt_numpad_c = 0;
				digraph_n = digraph_c = 0;
				cs_unicode = cs_unicode_c = 0;
				return 1;
			}
		} else if (k->mod & KMOD_ALT && !(k->mod & (KMOD_CTRL|KMOD_SHIFT))) {
			if (alt_numpad_c >= 0) {
				m = k->mod;
				k->mod = 0;
				c = numeric_key_event(k, 1); /* kp only */
				k->mod = m;
				if (c == -1 || c > 9) {
					alt_numpad = alt_numpad_c = -1;
				} else {
					if (k->state == KEY_PRESS) return 1;
					alt_numpad *= 10;
					alt_numpad += c;
					alt_numpad_c++;
					if (!(status.flags & CLASSIC_MODE))
						status_text_flash_bios("Enter DOS/ASCII: %d", (int)alt_numpad);
					return 1;
				}
			}
		} else {
			alt_numpad = alt_numpad_c = 0;
		}
	} else {
		cs_unicode = cs_unicode_c = 0;
		alt_numpad = alt_numpad_c = 0;
		digraph_n = digraph_c = 0;
	}

	return 0;
}