]> ncurses.scripts.mit.edu Git - ncurses.git/blob - lib_adabind.c
e049b2b04700c58dfa49f915c4803278bfdae36b
[ncurses.git] / lib_adabind.c
1 /****************************************************************************
2  * Copyright (c) 1998 Free Software Foundation, Inc.                        *
3  *                                                                          *
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:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
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.                               *
22  *                                                                          *
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       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *   Author: Juergen Pfeifer <Juergen.Pfeifer@T-Online.de> 1996,1997        *
31  ****************************************************************************/
32
33 /*
34 //      lib_adabind.c
35 //
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
40 //      subdirectory.
41 */
42 #include "curses.priv.h"
43
44 MODULE_ID("$Id: lib_adabind.c,v 1.7 1998/02/11 12:13:59 tom Exp $")
45
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
49 //  small wrappers.
50 */
51
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);
63
64 int _nc_ada_getmaxyx (const WINDOW *win, int *y, int *x)
65 {
66   if (win && y && x)
67     {
68       getmaxyx(win,*y,*x);
69       return OK;
70     }
71   else
72     return ERR;
73 }
74
75 int _nc_ada_getbegyx (const WINDOW *win, int *y, int *x)
76 {
77   if (win && y && x)
78     {
79       getbegyx(win,*y,*x);
80       return OK;
81     }
82   else
83     return ERR;
84 }
85
86 int _nc_ada_getyx (const WINDOW *win, int *y, int *x)
87 {
88   if (win && y && x)
89     {
90       getyx(win,*y,*x);
91       return OK;
92     }
93   else
94     return ERR;
95 }
96
97 int _nc_ada_getparyx (const WINDOW *win, int *y, int *x)
98 {
99   if (win && y && x)
100     {
101       getparyx(win,*y,*x);
102       return OK;
103     }
104   else
105     return ERR;
106 }
107
108 int _nc_ada_isscroll (const WINDOW *win)
109 {
110   return win ? (win->_scroll ? TRUE : FALSE) : ERR;
111 }
112
113 int _nc_ada_coord_transform (const WINDOW *win, int *Y, int *X, int dir)
114 {
115   if (win && Y && X)
116     {
117       int y = *Y; int x = *X;
118       if (dir)
119         { /* to screen coordinates */
120           y += win->_yoffset;
121           y += win->_begy;
122           x += win->_begx;
123           if (!wenclose(win,y,x))
124             return FALSE;
125         }
126       else
127         { /* from screen coordinates */
128           if (!wenclose(win,y,x))
129             return FALSE;
130           y -= win->_yoffset;
131           y -= win->_begy;
132           x -= win->_begx;
133         }
134       *X = x;
135       *Y = y;
136       return TRUE;
137     }
138   return FALSE;
139 }
140
141 #define BUTTON1_EVENTS (BUTTON1_RELEASED        |\
142                         BUTTON1_PRESSED         |\
143                         BUTTON1_CLICKED         |\
144                         BUTTON1_DOUBLE_CLICKED  |\
145                         BUTTON1_TRIPLE_CLICKED  |\
146                         BUTTON1_RESERVED_EVENT  )
147
148 #define BUTTON2_EVENTS (BUTTON2_RELEASED        |\
149                         BUTTON2_PRESSED         |\
150                         BUTTON2_CLICKED         |\
151                         BUTTON2_DOUBLE_CLICKED  |\
152                         BUTTON2_TRIPLE_CLICKED  |\
153                         BUTTON2_RESERVED_EVENT  )
154
155 #define BUTTON3_EVENTS (BUTTON3_RELEASED        |\
156                         BUTTON3_PRESSED         |\
157                         BUTTON3_CLICKED         |\
158                         BUTTON3_DOUBLE_CLICKED  |\
159                         BUTTON3_TRIPLE_CLICKED  |\
160                         BUTTON3_RESERVED_EVENT  )
161
162 #define BUTTON4_EVENTS (BUTTON4_RELEASED        |\
163                         BUTTON4_PRESSED         |\
164                         BUTTON4_CLICKED         |\
165                         BUTTON4_DOUBLE_CLICKED  |\
166                         BUTTON4_TRIPLE_CLICKED  |\
167                         BUTTON4_RESERVED_EVENT  )
168
169 void _nc_ada_mouse_event( mmask_t m, int *b, int *s )
170 {
171   int k = 0;
172
173   if ( m & BUTTON1_EVENTS)
174     {
175       k = 1;
176     }
177   else if ( m & BUTTON2_EVENTS)
178     {
179       k = 2;
180     }
181   else if ( m & BUTTON3_EVENTS)
182     {
183       k = 3;
184     }
185   else if ( m & BUTTON4_EVENTS)
186     {
187       k = 4;
188     }
189
190   if (k)
191     {
192       *b = k-1;
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;
199       else
200         {
201           *s = -1;
202         }
203     }
204   else
205     {
206       *s = 1;
207       if (m & BUTTON_CTRL) *b = 4;
208       else if (m & BUTTON_SHIFT) *b = 5;
209       else if (m & BUTTON_ALT) *b = 6;
210       else
211         {
212           *b = -1;
213         }
214     }
215 }
216
217 int _nc_ada_mouse_mask ( int button, int state, mmask_t *mask )
218 {
219   mmask_t b = (button<4) ? ((1<<button) << (6 * state)) :
220     (BUTTON_CTRL << (button-4));
221
222   if (button>=4 && state!=1)
223     return ERR;
224
225   *mask |= b;
226   return OK;
227 }
228
229 /*
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.
235  */
236 int  _nc_ada_vcheck (int major, int  minor)
237 {
238   if (major==NCURSES_VERSION_MAJOR) {
239     if (minor==NCURSES_VERSION_MINOR)
240       return 1;
241     else
242       return 2;
243   }
244   else
245     return 0;
246 }