sbin/hammer: Fix hammer(8)
[dragonfly.git] / contrib / dialog / mousewget.c
blob6f5b04356c7de5a2aa5d14ff9b4e2898f1345cf2
1 /*
2 * $Id: mousewget.c,v 1.22 2012/11/30 10:23:49 tom Exp $
4 * mousewget.c -- mouse/wgetch support for dialog
6 * Copyright 2000-2008,2012 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.
24 #include <dialog.h>
25 #include <dlg_keys.h>
27 static int
28 mouse_wgetch(WINDOW *win, int *fkey, bool ignore_errs)
30 int mouse_err = FALSE;
31 int key;
33 do {
35 key = dlg_getc(win, fkey);
37 #if USE_MOUSE
39 mouse_err = FALSE;
40 if (key == KEY_MOUSE) {
41 MEVENT event;
42 mseRegion *p;
44 if (getmouse(&event) != ERR) {
45 if ((p = dlg_mouse_region(event.y, event.x)) != 0) {
46 key = DLGK_MOUSE(p->code);
47 } else if ((p = dlg_mouse_bigregion(event.y, event.x)) != 0) {
48 int x = event.x - p->x;
49 int y = event.y - p->y;
50 int row = (p->X - p->x) / p->step_x;
52 key = -(p->code);
53 switch (p->mode) {
54 case 1: /* index by lines */
55 key += y;
56 break;
57 case 2: /* index by columns */
58 key += (x / p->step_x);
59 break;
60 default:
61 case 3: /* index by cells */
62 key += (x / p->step_x) + (y * row);
63 break;
65 } else {
66 (void) beep();
67 mouse_err = TRUE;
69 } else {
70 (void) beep();
71 mouse_err = TRUE;
74 #endif
76 } while (ignore_errs && mouse_err);
78 return key;
81 int
82 dlg_mouse_wgetch(WINDOW *win, int *fkey)
84 return mouse_wgetch(win, fkey, TRUE);
87 int
88 dlg_mouse_wgetch_nowait(WINDOW *win, int *fkey)
90 return mouse_wgetch(win, fkey, FALSE);