2 * $Id: mousewget.c,v 1.24 2017/01/31 00:27:21 tom Exp $
4 * mousewget.c -- mouse/wgetch support for dialog
6 * Copyright 2000-2016,2017 Thomas E. Dickey
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License, version 2.1
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this program; if not, write to
19 * Free Software Foundation, Inc.
20 * 51 Franklin St., Fifth Floor
21 * Boston, MA 02110, USA.
28 mouse_wgetch(WINDOW *win, int *fkey, bool ignore_errs)
30 int mouse_err = FALSE;
35 key = dlg_getc(win, fkey);
40 if (key == KEY_MOUSE) {
44 if (getmouse(&event) != ERR) {
45 DLG_TRACE(("# mouse-click abs %d,%d (rel %d,%d)\n",
47 event.y - getbegy(win),
48 event.x - getbegx(win)));
49 if ((p = dlg_mouse_region(event.y, event.x)) != 0) {
50 key = DLGK_MOUSE(p->code);
51 } else if ((p = dlg_mouse_bigregion(event.y, event.x)) != 0) {
52 int x = event.x - p->x;
53 int y = event.y - p->y;
54 int row = (p->X - p->x) / p->step_x;
58 case 1: /* index by lines */
61 case 2: /* index by columns */
62 key += (x / p->step_x);
65 case 3: /* index by cells */
66 key += (x / p->step_x) + (y * row);
80 } while (ignore_errs && mouse_err);
86 dlg_mouse_wgetch(WINDOW *win, int *fkey)
88 return mouse_wgetch(win, fkey, TRUE);
92 dlg_mouse_wgetch_nowait(WINDOW *win, int *fkey)
94 return mouse_wgetch(win, fkey, FALSE);