1217309Snwhitehorn/* 2251843Sbapt * $Id: mousewget.c,v 1.22 2012/11/30 10:23:49 tom Exp $ 3217309Snwhitehorn * 4217309Snwhitehorn * mousewget.c -- mouse/wgetch support for dialog 5217309Snwhitehorn * 6251843Sbapt * Copyright 2000-2008,2012 Thomas E. Dickey 7217309Snwhitehorn * 8217309Snwhitehorn * This program is free software; you can redistribute it and/or modify 9217309Snwhitehorn * it under the terms of the GNU Lesser General Public License, version 2.1 10217309Snwhitehorn * as published by the Free Software Foundation. 11217309Snwhitehorn * 12217309Snwhitehorn * This program is distributed in the hope that it will be useful, but 13217309Snwhitehorn * WITHOUT ANY WARRANTY; without even the implied warranty of 14217309Snwhitehorn * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15217309Snwhitehorn * Lesser General Public License for more details. 16217309Snwhitehorn * 17217309Snwhitehorn * You should have received a copy of the GNU Lesser General Public 18217309Snwhitehorn * License along with this program; if not, write to 19217309Snwhitehorn * Free Software Foundation, Inc. 20217309Snwhitehorn * 51 Franklin St., Fifth Floor 21217309Snwhitehorn * Boston, MA 02110, USA. 22217309Snwhitehorn */ 23217309Snwhitehorn 24217309Snwhitehorn#include <dialog.h> 25217309Snwhitehorn#include <dlg_keys.h> 26217309Snwhitehorn 27217309Snwhitehornstatic int 28217309Snwhitehornmouse_wgetch(WINDOW *win, int *fkey, bool ignore_errs) 29217309Snwhitehorn{ 30217309Snwhitehorn int mouse_err = FALSE; 31217309Snwhitehorn int key; 32217309Snwhitehorn 33217309Snwhitehorn do { 34217309Snwhitehorn 35217309Snwhitehorn key = dlg_getc(win, fkey); 36217309Snwhitehorn 37217309Snwhitehorn#if USE_MOUSE 38217309Snwhitehorn 39217309Snwhitehorn mouse_err = FALSE; 40251843Sbapt if (key == KEY_MOUSE) { 41217309Snwhitehorn MEVENT event; 42217309Snwhitehorn mseRegion *p; 43217309Snwhitehorn 44217309Snwhitehorn if (getmouse(&event) != ERR) { 45217309Snwhitehorn if ((p = dlg_mouse_region(event.y, event.x)) != 0) { 46217309Snwhitehorn key = DLGK_MOUSE(p->code); 47217309Snwhitehorn } else if ((p = dlg_mouse_bigregion(event.y, event.x)) != 0) { 48217309Snwhitehorn int x = event.x - p->x; 49217309Snwhitehorn int y = event.y - p->y; 50217309Snwhitehorn int row = (p->X - p->x) / p->step_x; 51217309Snwhitehorn 52217309Snwhitehorn key = -(p->code); 53217309Snwhitehorn switch (p->mode) { 54217309Snwhitehorn case 1: /* index by lines */ 55217309Snwhitehorn key += y; 56217309Snwhitehorn break; 57217309Snwhitehorn case 2: /* index by columns */ 58217309Snwhitehorn key += (x / p->step_x); 59217309Snwhitehorn break; 60217309Snwhitehorn default: 61217309Snwhitehorn case 3: /* index by cells */ 62217309Snwhitehorn key += (x / p->step_x) + (y * row); 63217309Snwhitehorn break; 64217309Snwhitehorn } 65217309Snwhitehorn } else { 66217309Snwhitehorn (void) beep(); 67217309Snwhitehorn mouse_err = TRUE; 68217309Snwhitehorn } 69217309Snwhitehorn } else { 70217309Snwhitehorn (void) beep(); 71217309Snwhitehorn mouse_err = TRUE; 72217309Snwhitehorn } 73217309Snwhitehorn } 74217309Snwhitehorn#endif 75217309Snwhitehorn 76217309Snwhitehorn } while (ignore_errs && mouse_err); 77217309Snwhitehorn 78217309Snwhitehorn return key; 79217309Snwhitehorn} 80217309Snwhitehorn 81217309Snwhitehornint 82217309Snwhitehorndlg_mouse_wgetch(WINDOW *win, int *fkey) 83217309Snwhitehorn{ 84217309Snwhitehorn return mouse_wgetch(win, fkey, TRUE); 85217309Snwhitehorn} 86217309Snwhitehorn 87217309Snwhitehornint 88217309Snwhitehorndlg_mouse_wgetch_nowait(WINDOW *win, int *fkey) 89217309Snwhitehorn{ 90217309Snwhitehorn return mouse_wgetch(win, fkey, FALSE); 91217309Snwhitehorn} 92