]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/lib_adabind.c
ncurses 4.1
[ncurses.git] / ncurses / lib_adabind.c
1
2 /***************************************************************************
3 *                            COPYRIGHT NOTICE                              *
4 ****************************************************************************
5 *                ncurses is copyright (C) 1992-1995                        *
6 *                          Zeyd M. Ben-Halim                               *
7 *                          zmbenhal@netcom.com                             *
8 *                          Eric S. Raymond                                 *
9 *                          esr@snark.thyrsus.com                           *
10 *                                                                          *
11 *        Permission is hereby granted to reproduce and distribute ncurses  *
12 *        by any means and for any fee, whether alone or as part of a       *
13 *        larger distribution, in source or in binary form, PROVIDED        *
14 *        this notice is included with any such distribution, and is not    *
15 *        removed from any of its header files. Mention of ncurses in any   *
16 *        applications linked with it is highly appreciated.                *
17 *                                                                          *
18 *        ncurses comes AS IS with no warranty, implied or expressed.       *
19 *                                                                          *
20 ***************************************************************************/
21
22 /*
23 **      lib_adabind.c
24 **
25 **      Some small wrappers to ease the implementation of an Ada95
26 **      binding. Especially functionalities only available as macros
27 **      in (n)curses are wrapped here by functions. 
28 **      See the documentation and copyright notices in the ../Ada95
29 **      subdirectory.
30 */
31 #include "curses.priv.h"
32
33 /*  In (n)curses are a few functionalities that can't be expressed as 
34 //  functions, because for historic reasons they use as macro argument
35 //  variable names that are "out" parameters. For those macros we provide
36 //  small wrappers.
37 */
38
39 /* Prototypes for the functions in this module */
40 int  _nc_ada_getmaxyx (WINDOW *win, int *y, int *x);
41 int  _nc_ada_getbegyx (WINDOW *win, int *y, int *x);
42 int  _nc_ada_getyx (WINDOW *win, int *y, int *x);
43 int  _nc_ada_getparyx (WINDOW *win, int *y, int *x);
44 int  _nc_ada_isscroll (WINDOW *win);
45 int  _nc_ada_coord_transform (WINDOW *win, int *Y, int *X, int dir);
46 void _nc_ada_mouse_event (mmask_t m, int *b, int *s);
47 int  _nc_ada_mouse_mask (int button, int state, mmask_t *mask);
48 void _nc_ada_unregister_mouse (void);
49
50
51 int _nc_ada_getmaxyx (WINDOW *win, int *y, int *x)
52 {
53   if (win && y && x)
54     {
55       getmaxyx(win,*y,*x);
56       return OK;
57     }
58   else
59     return ERR;
60 }
61
62 int _nc_ada_getbegyx (WINDOW *win, int *y, int *x)
63 {
64   if (win && y && x)
65     {
66       getbegyx(win,*y,*x);
67       return OK;
68     }
69   else
70     return ERR;
71 }
72
73 int _nc_ada_getyx (WINDOW *win, int *y, int *x)
74 {
75   if (win && y && x)
76     {
77       getyx(win,*y,*x);
78       return OK;
79     }
80   else
81     return ERR;
82 }
83
84 int _nc_ada_getparyx (WINDOW *win, int *y, int *x)
85 {
86   if (win && y && x)
87     {
88       getparyx(win,*y,*x);
89       return OK;
90     }
91   else
92     return ERR;
93 }
94
95 int _nc_ada_isscroll (WINDOW *win)
96 {
97   return win ? (win->_scroll ? TRUE : FALSE) : ERR;
98 }
99
100 int _nc_ada_coord_transform( WINDOW *win, int *Y, int *X, int dir)
101 {
102   if (win && Y && X)
103     {
104       int y = *Y; int x = *X;
105       if (dir)
106         { /* to screen coordinates */
107           y += win->_yoffset;
108           y += win->_begy;
109           x += win->_begx;
110           if (!wenclose(win,y,x))
111             return FALSE;
112         }
113       else
114         { /* from screen coordinates */
115           if (!wenclose(win,y,x))
116             return FALSE;
117           y -= win->_yoffset;
118           y -= win->_begy;
119           x -= win->_begx;
120         }
121       *X = x;
122       *Y = y;
123       return TRUE;
124     }
125   return FALSE;
126 }
127
128 #define BUTTON1_EVENTS (BUTTON1_RELEASED        |\
129                         BUTTON1_PRESSED         |\
130                         BUTTON1_CLICKED         |\
131                         BUTTON1_DOUBLE_CLICKED  |\
132                         BUTTON1_TRIPLE_CLICKED  |\
133                         BUTTON1_RESERVED_EVENT  )
134
135 #define BUTTON2_EVENTS (BUTTON2_RELEASED        |\
136                         BUTTON2_PRESSED         |\
137                         BUTTON2_CLICKED         |\
138                         BUTTON2_DOUBLE_CLICKED  |\
139                         BUTTON2_TRIPLE_CLICKED  |\
140                         BUTTON2_RESERVED_EVENT  )
141
142 #define BUTTON3_EVENTS (BUTTON3_RELEASED        |\
143                         BUTTON3_PRESSED         |\
144                         BUTTON3_CLICKED         |\
145                         BUTTON3_DOUBLE_CLICKED  |\
146                         BUTTON3_TRIPLE_CLICKED  |\
147                         BUTTON3_RESERVED_EVENT  )
148
149 #define BUTTON4_EVENTS (BUTTON4_RELEASED        |\
150                         BUTTON4_PRESSED         |\
151                         BUTTON4_CLICKED         |\
152                         BUTTON4_DOUBLE_CLICKED  |\
153                         BUTTON4_TRIPLE_CLICKED  |\
154                         BUTTON4_RESERVED_EVENT  )
155
156 void _nc_ada_mouse_event( mmask_t m, int *b, int *s )
157 {
158   int k = 0;
159
160   if ( m & BUTTON1_EVENTS)
161     {
162       k = 1;
163     }
164   else if ( m & BUTTON2_EVENTS)
165     {
166       k = 2;
167     }
168   else if ( m & BUTTON3_EVENTS)
169     {
170       k = 3;
171     }
172   else if ( m & BUTTON4_EVENTS)
173     {
174       k = 4;
175     }
176
177   if (k)
178     {
179       *b = k-1;
180       if (BUTTON_RELEASE(m,k)) *s = 0;
181       else if (BUTTON_PRESS(m,k)) *s = 1;
182       else if (BUTTON_CLICK(m,k)) *s = 2;
183       else if (BUTTON_DOUBLE_CLICK(m,k)) *s = 3;
184       else if (BUTTON_TRIPLE_CLICK(m,k)) *s = 4;
185       else if (BUTTON_RESERVED_EVENT(m,k)) *s = 5;
186       else
187         {
188           *s = -1;
189         }
190     }
191   else
192     {
193       *s = 1;
194       if (m & BUTTON_CTRL) *b = 4;
195       else if (m & BUTTON_SHIFT) *b = 5;
196       else if (m & BUTTON_ALT) *b = 6;
197       else
198         {
199           *b = -1;
200         }
201     }
202 }
203
204 int _nc_ada_mouse_mask ( int button, int state, mmask_t *mask )
205 {
206   mmask_t b = (button<4) ? ((1<<button) << (6 * state)) :
207     (BUTTON_CTRL << (button-4));
208
209   if (button>=4 && state!=1)
210     return ERR;
211
212   *mask |= b;
213   return OK;
214 }
215
216 void _nc_ada_unregister_mouse (void)
217 {
218   _nc_mouse_wrap(SP);
219 }
220