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
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]
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 /* common mouse interface functions */
35 #include <stdio.h> /* NULL */
36 #include <stdlib.h> /* NULL */
37 #include <string.h> /* NULL */
38 #include <ctype.h> /* isdigit */
41 #define ctrl(x) (x & 037)
45 static MOUSEMENU
*loadedmenu
;
46 static BOOL changemenu
= YES
;
48 /* see if there is a mouse interface */
55 if ((term
= getenv("TERM")) == NULL
) {
58 if (strcmp(term
, "emacsterm") == 0 || strcmp(term
, "viterm") == 0) {
60 } else if ((s
= getenv("MOUSE")) != NULL
&& strcmp(s
, "myx") == 0) {
62 * the MOUSE enviroment variable is for 5620 terminal
63 * programs that have mouse support but the TERM environment
64 * variable is the same as a terminal without a mouse, such
69 if ((s
= getenv("MOUSEMENU")) != NULL
&& strcmp(s
, "none") == 0) {
75 /* reinitialize the mouse in case curses changed the attributes */
80 if (mouse
== EMACSTERM
) {
83 * enable the mouse click and sweep coordinate control
86 (void) printf("\033{2");
88 (void) printf("\033#2"); /* switch to menu 2 */
90 (void) fflush(stdout
);
94 /* restore any original mouse attributes not handled by terminfo */
101 if (mouse
== MYX
&& loadedmenu
!= NULL
) {
102 /* remove the mouse menu */
103 (void) printf("\033[6;0X\033[9;0X");
104 for (i
= 0; loadedmenu
[i
].text
!= NULL
; ++i
) {
105 (void) printf("\033[0;0x");
111 /* download a mouse menu */
114 downloadmenu(MOUSEMENU
*menu
)
122 (void) printf("\033V1"); /* display the scroll bar */
124 (void) printf("\033M0@%s@%s@", menu
[0].text
,
126 for (i
= 1; menu
[i
].text
!= NULL
; ++i
) {
127 (void) printf("\033M@%s@%s@", menu
[i
].text
,
131 (void) fflush(stdout
);
136 (void) printf("\033[6;1X\033[9;1X");
137 for (i
= 0; menu
[i
].text
!= NULL
; ++i
) {
138 len
= strlen(menu
[i
].text
);
139 (void) printf("\033[%d;%dx%s%s", len
,
140 len
+ strlen(menu
[i
].value
),
141 menu
[i
].text
, menu
[i
].value
);
143 (void) fflush(stdout
);
153 /* draw the scroll bar */
156 drawscrollbar(int top
, int bot
, int total
)
160 if (mouse
== EMACSTERM
) {
161 if (bot
> top
&& total
> 0) {
162 p1
= 16 + (top
- 1) * 100 / total
;
163 p2
= 16 + (bot
- 1) * 100 / total
;
171 * don't send ^S or ^Q to avoid hanging a layer using
174 if (p1
== ctrl('Q') || p1
== ctrl('S')) {
177 if (p2
== ctrl('Q') || p2
== ctrl('S')) {
183 (void) printf("\033W%c%c", p1
, p2
);
187 /* translate a mouse click or sweep to a selection */
190 mouseselection(MOUSEEVENT
*p
, int offset
, int maxselection
)
197 } else if (i
>= maxselection
) {
198 i
= maxselection
- 1;
203 /* get the mouse event */
210 if (mouse
== EMACSTERM
) {
212 case ctrl('_'): /* click */
213 if ((m
.button
= mygetch()) == '0') { /* if scroll bar */
214 m
.percent
= getpercent();
216 m
.x1
= getcoordinate();
217 m
.y1
= getcoordinate();
222 case ctrl(']'): /* sweep */
223 m
.button
= mygetch();
224 m
.x1
= getcoordinate();
225 m
.y1
= getcoordinate();
226 m
.x2
= getcoordinate();
227 m
.y2
= getcoordinate();
237 /* get a row or column coordinate from a mouse button click or sweep */
246 if (c
== ctrl('A')) {
253 return (next
+ c
- ' ');
256 /* get a percentage */
273 /* update the window label area */
284 (void) printf("\033L1"); /* force it on */
286 (void) printf("\033L!%s!", s
);
289 (void) printf("\033[?%dv%s", strlen(s
), s
);
294 return (0); /* no label area */