]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/dialog/mouse.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / dialog / mouse.c
1 /*
2  * $Id: mouse.c,v 1.18 2007/02/22 21:51:38 tom Exp $
3  *
4  * mouse.c -- mouse support for dialog
5  *
6  * Copyright 2002-2006,2007     Thomas E. Dickey
7  *
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.
11  *
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.
16  *
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.
22  */
23
24 #include <dialog.h>
25 #include <dlg_keys.h>
26
27 #if USE_MOUSE
28
29 static int basex, basey;
30
31 static mseRegion *regionList = NULL;
32
33 /*=========== region related functions =============*/
34
35 static mseRegion *
36 find_region_by_code(int code)
37 {
38     mseRegion *butPtr;
39
40     for (butPtr = regionList; butPtr; butPtr = butPtr->next) {
41         if (code == butPtr->code)
42             break;
43     }
44     return butPtr;
45 }
46
47 void
48 dlg_mouse_setbase(int x, int y)
49 {
50     basex = x;
51     basey = y;
52 }
53
54 void
55 dlg_mouse_mkbigregion(int y, int x,
56                       int height, int width,
57                       int code,
58                       int step_y, int step_x,
59                       int mode)
60 {
61     mseRegion *butPtr = dlg_mouse_mkregion(y, x, height, width, -DLGK_MOUSE(code));
62     butPtr->mode = mode;
63     butPtr->step_x = MAX(1, step_x);
64     butPtr->step_y = MAX(1, step_y);
65 }
66
67 void
68 dlg_mouse_free_regions(void)
69 {
70     while (regionList != 0) {
71         mseRegion *butPtr = regionList->next;
72         free(regionList);
73         regionList = butPtr;
74     }
75 }
76
77 mseRegion *
78 dlg_mouse_mkregion(int y, int x, int height, int width, int code)
79 {
80     mseRegion *butPtr;
81
82     if ((butPtr = find_region_by_code(code)) == 0) {
83         butPtr = dlg_malloc(mseRegion, 1);
84         assert_ptr(butPtr, "dlg_mouse_mkregion");
85         butPtr->next = regionList;
86         regionList = butPtr;
87     }
88     if (butPtr != 0) {
89         butPtr->mode = -1;
90         butPtr->step_x = 0;
91         butPtr->step_y = 0;
92         butPtr->y = basey + y;
93         butPtr->Y = basey + y + height;
94         butPtr->x = basex + x;
95         butPtr->X = basex + x + width;
96         butPtr->code = code;
97     }
98     return butPtr;
99 }
100
101 /* retrieve the frame under the pointer */
102 static mseRegion *
103 any_mouse_region(int y, int x, int small)
104 {
105     mseRegion *butPtr;
106
107     for (butPtr = regionList; butPtr; butPtr = butPtr->next) {
108         if (small ^ (butPtr->code >= 0))
109             continue;
110         if (y < butPtr->y || y >= butPtr->Y)
111             continue;
112         if (x < butPtr->x || x >= butPtr->X)
113             continue;
114         break;                  /* found */
115     }
116     return butPtr;
117 }
118
119 /* retrieve the frame under the pointer */
120 mseRegion *
121 dlg_mouse_region(int y, int x)
122 {
123     return any_mouse_region(y, x, TRUE);
124 }
125
126 /* retrieve the bigframe under the pointer */
127 mseRegion *
128 dlg_mouse_bigregion(int y, int x)
129 {
130     return any_mouse_region(y, x, FALSE);
131 }
132
133 #else
134 void mouse_dummy(void);
135 void
136 mouse_dummy(void)
137 {
138 }
139 #endif /* USE_MOUSE */