Example #1
0
static int popup_cancel_button_handler(widget_list *w,
	int UNUSED(mx), int UNUSED(my), Uint32 flags)
{
	INPUT_POPUP *ipu = ipu_from_widget(w);
	if (ipu == NULL) return 0;

	// only handle mouse button clicks, not scroll wheels moves
	if ( (flags & ELW_MOUSE_BUTTON) == 0) return 0;

	// call the cancel function of the window owner then clear up
	if (ipu->popup_cancel != NULL)
		(*ipu->popup_cancel) (ipu->data);
	clear_popup_window (ipu);

	return 1;
}
Example #2
0
static int popup_keypress_handler(window_info *win,
	int UNUSED(mx), int UNUSED(my), Uint32 key, Uint32 unikey)
{
	INPUT_POPUP *ipu = ipu_from_window(win);
	if (ipu == NULL) return 0;

	if (key == SDLK_RETURN)
	{
		accept_popup_window (ipu);
		return 1;
	}
	else if (key == SDLK_ESCAPE)
	{
		if (ipu->popup_cancel != NULL)
			(*ipu->popup_cancel) (ipu->data);
		clear_popup_window (ipu);
		return 1;
	}
	else
	{
		// send other key presses to the text field
		widget_list *tfw = widget_find (win->window_id, ipu->popup_field);
		if (tfw != NULL)
		{
			// FIXME? This is a bit hackish, we don't allow the
			// widget to process keypresses, so that we end up
			// in this handler. But now we need the default
			// widget handler to take care of this keypress, so
			// we clear the flag, let the widget handle it, then
			// set the flag again.
			int res;
			tfw->Flags &= ~TEXT_FIELD_NO_KEYPRESS;
			res = widget_handle_keypress (tfw, mx - tfw->pos_x, my - tfw->pos_y, key, unikey);
			tfw->Flags |= TEXT_FIELD_NO_KEYPRESS;
			return res;
		}
	}

	// shouldn't get here
	return 0;
}
Example #3
0
static void accept_popup_window (INPUT_POPUP *ipu)
{
	int istart, iend, itmp, len = ipu->popup_text.len;
	char *data = ipu->popup_text.data;

	// skip leading spaces
	istart = 0;
	while ( istart < len && isspace (data[istart]) )
		istart++;
	if (istart >= len)
		// empty string
		return;

	// remove soft breaks
	iend = itmp = istart;
	while ( iend < len )
	{
		if (data[iend] != '\r')
			data[itmp++] = data[iend];
		iend++;
	}
	len = itmp;

	// stop at first non-printable character if allow_nonprint_chars not set
	iend = istart;
	while ( iend < len && (ipu->allow_nonprint_chars || is_printable (data[iend]) ))
		iend++;
	if (iend == istart)
		// empty string
		return;

	// send the entered text to the window owner then clear up
	data[iend] = '\0';
	if (ipu->popup_input != NULL)
		(*ipu->popup_input) (&data[istart], ipu->data);
	if (!ipu->accept_do_not_close)
		clear_popup_window (ipu);
}
Example #4
0
			void close(void) { if (get_show_window(ipu.popup_win)) clear_popup_window(&ipu); }