2 * $Id: mouse.c,v 1.24 2017/01/31 00:27:21 tom Exp $
4 * mouse.c -- mouse support for dialog
6 * Copyright 2002-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.
29 static int basex, basey, basecode;
31 static mseRegion *regionList = NULL;
33 /*=========== region related functions =============*/
36 find_region_by_code(int code)
40 for (butPtr = regionList; butPtr; butPtr = butPtr->next) {
41 if (code == butPtr->code)
48 dlg_mouse_setbase(int x, int y)
55 dlg_mouse_setcode(int code)
58 DLG_TRACE(("# mouse_setcode %d\n", code));
62 dlg_mouse_mkbigregion(int y, int x,
63 int height, int width,
65 int step_y, int step_x,
68 mseRegion *butPtr = dlg_mouse_mkregion(y, x, height, width, -DLGK_MOUSE(code));
70 butPtr->step_x = MAX(1, step_x);
71 butPtr->step_y = MAX(1, step_y);
75 dlg_mouse_free_regions(void)
77 while (regionList != 0) {
78 mseRegion *butPtr = regionList->next;
85 dlg_mouse_mkregion(int y, int x, int height, int width, int code)
89 if ((butPtr = find_region_by_code(basecode + code)) == 0) {
90 butPtr = dlg_calloc(mseRegion, 1);
91 assert_ptr(butPtr, "dlg_mouse_mkregion");
92 butPtr->next = regionList;
96 if ((butPtr->mode != -1) ||
97 (butPtr->step_x != 0) ||
98 (butPtr->step_y != 0) ||
99 (butPtr->y != (basey + y)) ||
100 (butPtr->Y != (basey + y + height)) ||
101 (butPtr->x != (basex + x)) ||
102 (butPtr->X != (basex + x + width)) ||
103 (butPtr->code != basecode + code)) {
104 DLG_TRACE(("# mouse_mkregion %d,%d %dx%d %d (%d)\n",
106 butPtr->code, code));
112 butPtr->y = basey + y;
113 butPtr->Y = basey + y + height;
114 butPtr->x = basex + x;
115 butPtr->X = basex + x + width;
116 butPtr->code = basecode + code;
121 /* retrieve the frame under the pointer */
123 any_mouse_region(int y, int x, int small)
127 for (butPtr = regionList; butPtr; butPtr = butPtr->next) {
128 if (small ^ (butPtr->code >= 0)) {
131 if (y < butPtr->y || y >= butPtr->Y) {
134 if (x < butPtr->x || x >= butPtr->X) {
142 /* retrieve the frame under the pointer */
144 dlg_mouse_region(int y, int x)
146 return any_mouse_region(y, x, TRUE);
149 /* retrieve the bigframe under the pointer */
151 dlg_mouse_bigregion(int y, int x)
153 return any_mouse_region(y, x, FALSE);
157 void mouse_dummy(void);
162 #endif /* USE_MOUSE */