/*1* $Id: mousewget.c,v 1.25 2019/07/25 00:06:38 tom Exp $2*3* mousewget.c -- mouse/wgetch support for dialog4*5* Copyright 2000-2017,2019 Thomas E. Dickey6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU Lesser General Public License, version 2.19* as published by the Free Software Foundation.10*11* This program is distributed in the hope that it will be useful, but12* WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14* Lesser General Public License for more details.15*16* You should have received a copy of the GNU Lesser General Public17* License along with this program; if not, write to18* Free Software Foundation, Inc.19* 51 Franklin St., Fifth Floor20* Boston, MA 02110, USA.21*/2223#include <dialog.h>24#include <dlg_keys.h>2526static int27mouse_wgetch(WINDOW *win, int *fkey, bool ignore_errs)28{29int mouse_err = FALSE;30int key;3132do {3334key = dlg_getc(win, fkey);3536#if USE_MOUSE3738mouse_err = FALSE;39if (key == KEY_MOUSE) {40MEVENT event;4142if (getmouse(&event) != ERR) {43mseRegion *p;4445DLG_TRACE(("# mouse-click abs %d,%d (rel %d,%d)\n",46event.y, event.x,47event.y - getbegy(win),48event.x - getbegx(win)));49if ((p = dlg_mouse_region(event.y, event.x)) != 0) {50key = DLGK_MOUSE(p->code);51} else if ((p = dlg_mouse_bigregion(event.y, event.x)) != 0) {52int x = event.x - p->x;53int y = event.y - p->y;54int row = (p->X - p->x) / p->step_x;5556key = -(p->code);57switch (p->mode) {58case 1: /* index by lines */59key += y;60break;61case 2: /* index by columns */62key += (x / p->step_x);63break;64default:65case 3: /* index by cells */66key += (x / p->step_x) + (y * row);67break;68}69} else {70(void) beep();71mouse_err = TRUE;72}73} else {74(void) beep();75mouse_err = TRUE;76}77}78#endif7980} while (ignore_errs && mouse_err);8182return key;83}8485int86dlg_mouse_wgetch(WINDOW *win, int *fkey)87{88return mouse_wgetch(win, fkey, TRUE);89}9091int92dlg_mouse_wgetch_nowait(WINDOW *win, int *fkey)93{94return mouse_wgetch(win, fkey, FALSE);95}969798