]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/trace/lib_tracemse.c
ncurses 6.1 - patch 20180210
[ncurses.git] / ncurses / trace / lib_tracemse.c
1 /****************************************************************************
2  * Copyright (c) 1998-2012,2014 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: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32  *     and: Thomas E. Dickey                        1996-on                 *
33  ****************************************************************************/
34
35 /*
36  *      lib_tracemse.c - Tracing/Debugging routines (mouse events)
37  */
38
39 #include <curses.priv.h>
40
41 MODULE_ID("$Id: lib_tracemse.c,v 1.22 2014/10/10 09:06:26 tom Exp $")
42
43 #ifdef TRACE
44
45 #define my_buffer sp->tracemse_buf
46
47 NCURSES_EXPORT(char *)
48 _nc_trace_mmask_t(SCREEN *sp, mmask_t code)
49 {
50 #define SHOW(m, s) \
51     if ((code & m) == m) { \
52         size_t n = strlen(my_buffer); \
53         if (n && (my_buffer[n-1] != '{')) \
54         _nc_STRCAT(my_buffer, ", ", sizeof(my_buffer)); \
55         _nc_STRCAT(my_buffer, s, sizeof(my_buffer)); \
56     }
57
58     SHOW(BUTTON1_RELEASED, "release-1");
59     SHOW(BUTTON1_PRESSED, "press-1");
60     SHOW(BUTTON1_CLICKED, "click-1");
61     SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
62     SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
63 #if NCURSES_MOUSE_VERSION == 1
64     SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
65 #endif
66
67     SHOW(BUTTON2_RELEASED, "release-2");
68     SHOW(BUTTON2_PRESSED, "press-2");
69     SHOW(BUTTON2_CLICKED, "click-2");
70     SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
71     SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
72 #if NCURSES_MOUSE_VERSION == 1
73     SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
74 #endif
75
76     SHOW(BUTTON3_RELEASED, "release-3");
77     SHOW(BUTTON3_PRESSED, "press-3");
78     SHOW(BUTTON3_CLICKED, "click-3");
79     SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
80     SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
81 #if NCURSES_MOUSE_VERSION == 1
82     SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
83 #endif
84
85     SHOW(BUTTON4_RELEASED, "release-4");
86     SHOW(BUTTON4_PRESSED, "press-4");
87     SHOW(BUTTON4_CLICKED, "click-4");
88     SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
89     SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
90 #if NCURSES_MOUSE_VERSION == 1
91     SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
92 #endif
93
94 #if NCURSES_MOUSE_VERSION == 2
95     SHOW(BUTTON5_RELEASED, "release-5");
96     SHOW(BUTTON5_PRESSED, "press-5");
97     SHOW(BUTTON5_CLICKED, "click-5");
98     SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
99     SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
100 #endif
101
102     SHOW(BUTTON_CTRL, "ctrl");
103     SHOW(BUTTON_SHIFT, "shift");
104     SHOW(BUTTON_ALT, "alt");
105     SHOW(ALL_MOUSE_EVENTS, "all-events");
106     SHOW(REPORT_MOUSE_POSITION, "position");
107
108 #undef SHOW
109
110     if (my_buffer[strlen(my_buffer) - 1] == ' ')
111         my_buffer[strlen(my_buffer) - 2] = '\0';
112
113     return (my_buffer);
114 }
115
116 NCURSES_EXPORT(char *)
117 _nc_tracemouse(SCREEN *sp, MEVENT const *ep)
118 {
119     char *result = 0;
120
121     if (sp != 0) {
122         _nc_SPRINTF(my_buffer, _nc_SLIMIT(sizeof(my_buffer))
123                     TRACEMSE_FMT,
124                     ep->id,
125                     ep->x,
126                     ep->y,
127                     ep->z,
128                     (unsigned long) ep->bstate);
129
130         (void) _nc_trace_mmask_t(sp, ep->bstate);
131         _nc_STRCAT(my_buffer, "}", sizeof(my_buffer));
132         result = (my_buffer);
133     }
134     return result;
135 }
136
137 NCURSES_EXPORT(mmask_t)
138 _nc_retrace_mmask_t(SCREEN *sp, mmask_t code)
139 {
140     if (sp != 0) {
141         *my_buffer = '\0';
142         T((T_RETURN("{%s}"), _nc_trace_mmask_t(sp, code)));
143     } else {
144         T((T_RETURN("{?}")));
145     }
146     return code;
147 }
148
149 NCURSES_EXPORT(char *)
150 _tracemouse(MEVENT const *ep)
151 {
152     return _nc_tracemouse(CURRENT_SCREEN, ep);
153 }
154
155 #else /* !TRACE */
156 EMPTY_MODULE(_nc_lib_tracemouse)
157 #endif