8354 sync regcomp(3C) with upstream (fix make catalog)
[unleashed/tickless.git] / usr / src / lib / libcurses / screen / mouse.c
blobe94fc1437ce0ce725dc6f2274272d7e889de5e6d
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
40 #pragma ident "%Z%%M% %I% %E% SMI"
42 /*LINTLIBRARY*/
44 #include <sys/types.h>
45 #include "curses_inc.h"
47 int
48 mouse_set(long int mbe)
50 if (get_mouse) {
51 SP->_trap_mbe = mbe;
52 (void) tputs(tparm_p1(get_mouse, mbe), 1, _outch);
53 (void) fflush(SP->term_file);
54 return (OK);
56 return (ERR);
59 int
60 mouse_on(long int mbe)
62 if (get_mouse) {
63 SP->_trap_mbe |= mbe;
64 (void) tputs(tparm_p1(get_mouse, (long) SP->_trap_mbe),
65 1, _outch);
66 (void) fflush(SP->term_file);
67 return (OK);
69 return (ERR);
72 int
73 mouse_off(long int mbe)
75 if (get_mouse) {
76 SP->_trap_mbe &= ~mbe;
77 (void) tputs(tparm_p1(get_mouse, (long) SP->_trap_mbe),
78 1, _outch);
79 (void) fflush(SP->term_file);
80 return (OK);
82 return (ERR);
86 int
87 request_mouse_pos(void)
89 int i;
91 if (req_mouse_pos) {
92 (void) tputs(req_mouse_pos, 1, _outch);
93 (void) fflush(SP->term_file);
95 /* we now must wait for report of mouse position. How do */
96 /* we know that this is mouse position report an not any- */
97 /* thing else? thetch() returns KEY_MOUSE and the status */
98 /* off all the buttons remains unchanged. */
99 /* just to avoid going into infinite loop, we have a */
100 /* counter. if 1000 responses won't have what we need, */
101 /* we'll return error */
103 for (i = 0; i < 1000; i++) {
104 if ((tgetch(1) == KEY_MOUSE) && MOUSE_POS_REPORT)
105 break;
107 if (i == 1000)
108 return (ERR);
109 return (OK);
111 return (ERR);
114 void
115 wmouse_position(WINDOW *win, int *x, int *y)
117 /* mouse pointer outside the window, store -1's into x and y */
119 if (win->_begy > MOUSE_Y_POS || win->_begx > MOUSE_X_POS ||
120 win->_begy+win->_maxy < MOUSE_Y_POS ||
121 win->_begx+win->_maxx < MOUSE_X_POS) {
122 *x = -1; *y = -1;
123 } else {
124 *x = MOUSE_X_POS - win->_begx;
125 *y = MOUSE_Y_POS - win->_begy;
131 map_button(unsigned long a)
133 SP->_map_mbe_to_key = a;
134 return (OK);
138 unsigned long
139 getmouse(void)
141 return (SP->_trap_mbe);
145 unsigned long
146 getbmap(void)
148 return (SP->_map_mbe_to_key);