kernel - Fix races created by a comedy of circumstansces (3)
[dragonfly.git] / contrib / dialog / mouse.c
blob33af6a474721a9edff9a5ade80d8cb2be4d9ebf1
1 /*
2 * $Id: mouse.c,v 1.21 2015/05/13 20:56:28 tom Exp $
4 * mouse.c -- mouse support for dialog
6 * Copyright 2002-2012,2015 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 #if USE_MOUSE
29 static int basex, basey, basecode;
31 static mseRegion *regionList = NULL;
33 /*=========== region related functions =============*/
35 static mseRegion *
36 find_region_by_code(int code)
38 mseRegion *butPtr;
40 for (butPtr = regionList; butPtr; butPtr = butPtr->next) {
41 if (code == butPtr->code)
42 break;
44 return butPtr;
47 void
48 dlg_mouse_setbase(int x, int y)
50 basex = x;
51 basey = y;
54 void
55 dlg_mouse_setcode(int code)
57 basecode = code;
60 void
61 dlg_mouse_mkbigregion(int y, int x,
62 int height, int width,
63 int code,
64 int step_y, int step_x,
65 int mode)
67 mseRegion *butPtr = dlg_mouse_mkregion(y, x, height, width, -DLGK_MOUSE(code));
68 butPtr->mode = mode;
69 butPtr->step_x = MAX(1, step_x);
70 butPtr->step_y = MAX(1, step_y);
73 void
74 dlg_mouse_free_regions(void)
76 while (regionList != 0) {
77 mseRegion *butPtr = regionList->next;
78 free(regionList);
79 regionList = butPtr;
83 mseRegion *
84 dlg_mouse_mkregion(int y, int x, int height, int width, int code)
86 mseRegion *butPtr;
88 if ((butPtr = find_region_by_code(basecode + code)) == 0) {
89 butPtr = dlg_malloc(mseRegion, 1);
90 assert_ptr(butPtr, "dlg_mouse_mkregion");
91 butPtr->next = regionList;
92 regionList = butPtr;
95 butPtr->mode = -1;
96 butPtr->step_x = 0;
97 butPtr->step_y = 0;
98 butPtr->y = basey + y;
99 butPtr->Y = basey + y + height;
100 butPtr->x = basex + x;
101 butPtr->X = basex + x + width;
102 butPtr->code = basecode + code;
104 return butPtr;
107 /* retrieve the frame under the pointer */
108 static mseRegion *
109 any_mouse_region(int y, int x, int small)
111 mseRegion *butPtr;
113 for (butPtr = regionList; butPtr; butPtr = butPtr->next) {
114 if (small ^ (butPtr->code >= 0)) {
115 continue;
117 if (y < butPtr->y || y >= butPtr->Y) {
118 continue;
120 if (x < butPtr->x || x >= butPtr->X) {
121 continue;
123 break; /* found */
125 return butPtr;
128 /* retrieve the frame under the pointer */
129 mseRegion *
130 dlg_mouse_region(int y, int x)
132 return any_mouse_region(y, x, TRUE);
135 /* retrieve the bigframe under the pointer */
136 mseRegion *
137 dlg_mouse_bigregion(int y, int x)
139 return any_mouse_region(y, x, FALSE);
142 #else
143 void mouse_dummy(void);
144 void
145 mouse_dummy(void)
148 #endif /* USE_MOUSE */