1 /****************************************************************************
2 * Copyright (c) 1998 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> 1996,1997 *
31 ****************************************************************************/
36 // Some small wrappers to ease the implementation of an Ada95
37 // binding. Especially functionalities only available as macros
38 // in (n)curses are wrapped here by functions.
39 // See the documentation and copyright notices in the ../Ada95
42 #include "curses.priv.h"
44 MODULE_ID("$Id: lib_adabind.c,v 1.7 1998/02/11 12:13:59 tom Exp $")
46 /* In (n)curses are a few functionalities that can't be expressed as
47 // functions, because for historic reasons they use as macro argument
48 // variable names that are "out" parameters. For those macros we provide
52 /* Prototypes for the functions in this module */
53 int _nc_ada_getmaxyx (const WINDOW *win, int *y, int *x);
54 int _nc_ada_getbegyx (const WINDOW *win, int *y, int *x);
55 int _nc_ada_getyx (const WINDOW *win, int *y, int *x);
56 int _nc_ada_getparyx (const WINDOW *win, int *y, int *x);
57 int _nc_ada_isscroll (const WINDOW *win);
58 int _nc_ada_coord_transform (const WINDOW *win, int *Y, int *X, int dir);
59 void _nc_ada_mouse_event (mmask_t m, int *b, int *s);
60 int _nc_ada_mouse_mask (int button, int state, mmask_t *mask);
61 void _nc_ada_unregister_mouse (void);
62 int _nc_ada_vcheck (int major, int minor);
64 int _nc_ada_getmaxyx (const WINDOW *win, int *y, int *x)
75 int _nc_ada_getbegyx (const WINDOW *win, int *y, int *x)
86 int _nc_ada_getyx (const WINDOW *win, int *y, int *x)
97 int _nc_ada_getparyx (const WINDOW *win, int *y, int *x)
108 int _nc_ada_isscroll (const WINDOW *win)
110 return win ? (win->_scroll ? TRUE : FALSE) : ERR;
113 int _nc_ada_coord_transform (const WINDOW *win, int *Y, int *X, int dir)
117 int y = *Y; int x = *X;
119 { /* to screen coordinates */
123 if (!wenclose(win,y,x))
127 { /* from screen coordinates */
128 if (!wenclose(win,y,x))
141 #define BUTTON1_EVENTS (BUTTON1_RELEASED |\
144 BUTTON1_DOUBLE_CLICKED |\
145 BUTTON1_TRIPLE_CLICKED |\
146 BUTTON1_RESERVED_EVENT )
148 #define BUTTON2_EVENTS (BUTTON2_RELEASED |\
151 BUTTON2_DOUBLE_CLICKED |\
152 BUTTON2_TRIPLE_CLICKED |\
153 BUTTON2_RESERVED_EVENT )
155 #define BUTTON3_EVENTS (BUTTON3_RELEASED |\
158 BUTTON3_DOUBLE_CLICKED |\
159 BUTTON3_TRIPLE_CLICKED |\
160 BUTTON3_RESERVED_EVENT )
162 #define BUTTON4_EVENTS (BUTTON4_RELEASED |\
165 BUTTON4_DOUBLE_CLICKED |\
166 BUTTON4_TRIPLE_CLICKED |\
167 BUTTON4_RESERVED_EVENT )
169 void _nc_ada_mouse_event( mmask_t m, int *b, int *s )
173 if ( m & BUTTON1_EVENTS)
177 else if ( m & BUTTON2_EVENTS)
181 else if ( m & BUTTON3_EVENTS)
185 else if ( m & BUTTON4_EVENTS)
193 if (BUTTON_RELEASE(m,k)) *s = 0;
194 else if (BUTTON_PRESS(m,k)) *s = 1;
195 else if (BUTTON_CLICK(m,k)) *s = 2;
196 else if (BUTTON_DOUBLE_CLICK(m,k)) *s = 3;
197 else if (BUTTON_TRIPLE_CLICK(m,k)) *s = 4;
198 else if (BUTTON_RESERVED_EVENT(m,k)) *s = 5;
207 if (m & BUTTON_CTRL) *b = 4;
208 else if (m & BUTTON_SHIFT) *b = 5;
209 else if (m & BUTTON_ALT) *b = 6;
217 int _nc_ada_mouse_mask ( int button, int state, mmask_t *mask )
219 mmask_t b = (button<4) ? ((1<<button) << (6 * state)) :
220 (BUTTON_CTRL << (button-4));
222 if (button>=4 && state!=1)
230 * Allow Ada to check whether or not we are the correct library version
231 * for the binding. It calls this routine with the version it requests
232 * and this routine returns a 1 if it is a correct version, a 2 if the
233 * major version is correct but the minor version of the library differs
234 * and a 0 if the versions don't match.
236 int _nc_ada_vcheck (int major, int minor)
238 if (major==NCURSES_VERSION_MAJOR) {
239 if (minor==NCURSES_VERSION_MINOR)