1/****************************************************************************
2 * Copyright (c) 1998-2007,2008 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
41MODULE_ID("$Id: lib_tracemse.c,v 1.15 2008/08/03 15:39:29 tom Exp $")
42
43#ifdef TRACE
44
45#define my_buffer sp->tracemse_buf
46
47NCURSES_EXPORT(char *)
48_nc_tracemouse(SCREEN *sp, MEVENT const *ep)
49{
50    (void) sprintf(my_buffer, TRACEMSE_FMT,
51		   ep->id,
52		   ep->x,
53		   ep->y,
54		   ep->z,
55		   (unsigned long) ep->bstate);
56
57#define SHOW(m, s) if ((ep->bstate & m) == m) strcat(strcat(my_buffer, s), ", ")
58
59    SHOW(BUTTON1_RELEASED, "release-1");
60    SHOW(BUTTON1_PRESSED, "press-1");
61    SHOW(BUTTON1_CLICKED, "click-1");
62    SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
63    SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
64#if NCURSES_MOUSE_VERSION == 1
65    SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
66#endif
67
68    SHOW(BUTTON2_RELEASED, "release-2");
69    SHOW(BUTTON2_PRESSED, "press-2");
70    SHOW(BUTTON2_CLICKED, "click-2");
71    SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
72    SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
73#if NCURSES_MOUSE_VERSION == 1
74    SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
75#endif
76
77    SHOW(BUTTON3_RELEASED, "release-3");
78    SHOW(BUTTON3_PRESSED, "press-3");
79    SHOW(BUTTON3_CLICKED, "click-3");
80    SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
81    SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
82#if NCURSES_MOUSE_VERSION == 1
83    SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
84#endif
85
86    SHOW(BUTTON4_RELEASED, "release-4");
87    SHOW(BUTTON4_PRESSED, "press-4");
88    SHOW(BUTTON4_CLICKED, "click-4");
89    SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
90    SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
91#if NCURSES_MOUSE_VERSION == 1
92    SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
93#endif
94
95#if NCURSES_MOUSE_VERSION == 2
96    SHOW(BUTTON5_RELEASED, "release-5");
97    SHOW(BUTTON5_PRESSED, "press-5");
98    SHOW(BUTTON5_CLICKED, "click-5");
99    SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
100    SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
101#endif
102
103    SHOW(BUTTON_CTRL, "ctrl");
104    SHOW(BUTTON_SHIFT, "shift");
105    SHOW(BUTTON_ALT, "alt");
106    SHOW(ALL_MOUSE_EVENTS, "all-events");
107    SHOW(REPORT_MOUSE_POSITION, "position");
108
109#undef SHOW
110
111    if (my_buffer[strlen(my_buffer) - 1] == ' ')
112	my_buffer[strlen(my_buffer) - 2] = '\0';
113    (void) strcat(my_buffer, "}");
114    return (my_buffer);
115}
116
117NCURSES_EXPORT(char *)
118_tracemouse(MEVENT const *ep)
119{
120    return _nc_tracemouse(SP, ep);
121}
122
123#else /* !TRACE */
124EMPTY_MODULE(_nc_lib_tracemouse)
125#endif
126