2 Copyright (C) 1994 Miguel de Icaza.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 /* Events received by clients of this library have their coordinates 0 */
24 #include <sys/types.h>
28 #include <signal.h> /* For kill() and SIGQUIT */
30 #if (!defined(__IBMC__) && !defined(__IBMCPP__)) && !defined(OS2_NT)
38 #include "global.h" /* ESC_STR */
39 #include "util.h" /* xmalloc */
40 #include "key.h" /* define sequence */
41 #include "tty.h" /* get ncurses header */
46 * This chunk of NCURSES internals is used to support the keyok() function for
47 * NCURSES versions between 1.9.6 (when the mouse code was introduced in 1995),
48 * and 4.2 (when the keyok function will be release).
51 #ifdef NCURSES_MOUSE_VERSION /* first defined for ncurses 1.9.6 */
52 #ifdef NCURSES_970530 /* defined by configure script */
54 * ncurses 1.9.8a ported to QNX doesn't provide the SP pointer as a global
55 * symbol in the library...
60 struct tries
*sibling
;
68 #if NCURSES_970530 >= 2
69 char *_setbuf
; /*4.0*/
75 #if NCURSES_970530 >= 1
76 short _lines_avail
; /*1.9.9g*/
77 short _topstolen
; /*1.9.9g*/
79 struct _win_st
*_curscr
;
80 struct _win_st
*_newscr
;
81 struct _win_st
*_stdscr
;
82 struct tries
*_keytry
; /* "Try" for use with keypad mode */
83 /* there's more, but this is just for alignment */
85 extern struct screen
*SP
;
88 * Remove a code from the specified tree, freeing the unused nodes. Returns
89 * true if the code was found/removed.
92 int _nc_remove_key(struct tries
**tree
, unsigned short code
)
94 struct tries
*ptr
= (*tree
);
98 if (_nc_remove_key(&(ptr
->child
), code
)) {
101 if (ptr
->value
== code
) {
113 keyok(int code
, bool flag
)
115 _nc_remove_key(&(SP
->_keytry
), code
);
119 #endif /* NCURSES_970530 */
120 #endif /* NCURSES_MOUSE_VERSION */
121 #endif /* HAVE_KEYOK */
124 static int mouse_d
; /* Handle to the mouse server */
128 /* Only used for debugging */
129 static int top_event
= 0;
135 void show_mouse_pointer (int x
, int y
)
138 if (use_mouse_p
== GPM_MOUSE
){
139 Gpm_DrawPointer (x
, y
, gpm_consolefd
);
144 #endif /* HAVE_LIBGPM */
146 int mouse_handler (Gpm_Event
*gpm_event
)
148 MouseEvent
*event
= mouse_events
;
149 int x
= last_x
= gpm_event
->x
;
150 int y
= last_y
= gpm_event
->y
;
153 /* DEBUGM ((log, "Mouse [%d, %d]\n", x, y)); */
155 /* Call any registered event handlers */
156 for (; event
; event
= (MouseEvent
*) event
->next
){
157 if ((event
->x1
<= x
) && (x
<= event
->x2
)
158 && (event
->y1
<= y
) && (y
<= event
->y2
)){
159 gpm_event
->x
-= event
->x1
;
160 gpm_event
->y
-= event
->y1
;
161 last_mouse_event
= event
;
162 redo
= (*(event
->mouse_callback
))(gpm_event
, event
->data
);
163 gpm_event
->x
+= event
->x1
;
164 gpm_event
->y
+= event
->y1
;
171 int redo_mouse (Gpm_Event
*event
)
173 if (last_mouse_event
){
175 event
->x
-= last_mouse_event
->x1
;
176 event
->y
-= last_mouse_event
->y1
;
177 result
= (*(last_mouse_event
->mouse_callback
))
178 (event
,last_mouse_event
->data
);
179 event
->x
+= last_mouse_event
->x1
;
180 event
->y
+= last_mouse_event
->y1
;
187 void init_mouse (void)
190 * MC's use of xterm mouse is incompatible with NCURSES's support. The
191 * simplest solution is to disable NCURSE's mouse.
193 #ifdef NCURSES_MOUSE_VERSION
194 /* See the comment above about QNX/ncurses 1.9.8a ... */
196 keyok(KEY_MOUSE
, FALSE
);
198 #endif /* NCURSES_MOUSE_VERSION */
200 #if defined(NCURSES_970530)
209 conn
.eventMask
= ~GPM_MOVE
;
210 conn
.defaultMask
= GPM_MOVE
;
214 if ((mouse_d
= Gpm_Open (&conn
, 0)) == -1)
218 log
= fopen ("mouse.log", "w");
222 #endif /* HAVE_LIBGPM */
226 /* save old highlight mouse tracking */
227 printf("%c[?1001s",27);
229 /* enable mouse tracking */
230 printf("%c[?1000h",27);
235 define_sequence (MCKEY_MOUSE
, ESC_STR
"[M", MCKEY_NOACTION
);
241 } /* switch (use_mouse_p) */
244 void shut_mouse (void)
246 switch (use_mouse_p
){
255 /* disable mouse tracking */
256 /* Changed the 1 for an 'l' below: */
257 printf("%c[?1000l",27);
259 /* restore old highlight mouse tracking */
260 printf("%c[?1001r",27);
274 void mouse_log (char *function
, char *file
, int line
)
276 fprintf (log
, "%s called from %s:%d\n", function
, file
, line
);