1 /* 2 * CDDL HEADER START 3 * 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. 8 * 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. 13 * 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] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 1993 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28 /* All Rights Reserved */ 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #include <stdio.h> 33 #include <ctype.h> 34 #include "wish.h" 35 #include "token.h" 36 #include "vtdefs.h" 37 #include "actrec.h" 38 #include "slk.h" 39 #include "ctl.h" 40 #include "moremacros.h" 41 42 /* modes */ 43 #define MODE_MOVE 1 44 #define MODE_RESHAPE 2 45 46 static int mode; 47 static int srow; 48 static int scol; 49 static int rows; 50 static int cols; 51 static char position1[] = "Position "; 52 static char position2[] = " corner and press ENTER"; 53 static char *Savemsg = NULL; 54 55 /* mouse position */ 56 extern int Mouse_row; 57 extern int Mouse_col; 58 extern int Open_mouse_mode; 59 60 char *mess_perm(); 61 62 static int 63 wdw_close(rec) 64 struct actrec *rec; 65 { 66 (void) mess_perm(Savemsg); 67 make_box(0, 0, 0, 0, 0); 68 Open_mouse_mode = FALSE; 69 return SUCCESS; 70 } 71 72 /*ARGSUSED*/ 73 static int 74 wdw_ctl(rec, wdw, a1, a2, a3, a4, a5, a6) 75 struct actrec *rec; 76 int wdw; 77 int a1, a2, a3, a4, a5, a6; 78 { 79 return FAIL; 80 } 81 82 /*ARGSUSED*/ 83 static token 84 wdw_stream(rec, t) 85 struct actrec *rec; 86 register token t; 87 { 88 register int newsrow; 89 register int newscol; 90 register int newrows; 91 register int newcols; 92 register bool moving; 93 char *nstrcat(); 94 95 moving = FALSE; 96 newsrow = srow; 97 newscol = scol; 98 newrows = rows; 99 newcols = cols; 100 switch (t) { 101 case TOK_UP: 102 moving = TRUE; 103 if (mode & MODE_MOVE) 104 newsrow--; 105 else 106 newrows--; 107 break; 108 case TOK_DOWN: 109 moving = TRUE; 110 if (mode & MODE_MOVE) 111 newsrow++; 112 else 113 newrows++; 114 break; 115 case TOK_LEFT: 116 moving = TRUE; 117 if (mode & MODE_MOVE) 118 newscol--; 119 else 120 newcols--; 121 break; 122 case TOK_RIGHT: 123 moving = TRUE; 124 if (mode & MODE_MOVE) 125 newscol++; 126 else 127 newcols++; 128 break; 129 case TOK_BTAB: 130 moving = TRUE; 131 if (mode & MODE_MOVE) 132 newscol = (newscol - 1 & ~7); 133 else 134 newcols = (newcols - 1 & ~7); 135 break; 136 case TOK_TAB: 137 moving = TRUE; 138 if (mode & MODE_MOVE) 139 newscol = (newscol + 8 & ~7); 140 else 141 newcols = (newcols + 8 & ~7); 142 break; 143 case TOK_BPRESSED: 144 moving = TRUE; 145 if (mode & MODE_MOVE) { 146 newsrow = Mouse_row - 1; 147 newscol = Mouse_col; 148 } 149 else { 150 newrows = Mouse_row - srow; 151 newcols = Mouse_col - scol + 1; 152 } 153 break; 154 case TOK_BRELEASED: 155 case TOK_RETURN: 156 case TOK_ENTER: 157 #ifdef _DEBUG 158 _debug(stderr, "mode=%d\n", mode); 159 #endif 160 if (mode & MODE_RESHAPE && mode & MODE_MOVE) { 161 mode = MODE_RESHAPE; 162 make_box(1, srow, scol, rows, cols); 163 (void) mess_perm(nstrcat(position1, "bottom-right", position2, NULL)); 164 } else { 165 if (mode & MODE_RESHAPE) 166 ar_ctl(rec->odptr, CTSETSHAPE, srow, scol, rows, cols, NULL, NULL); 167 else { 168 vt_id vid; 169 170 vid = vt_current(ar_ctl(rec->odptr, CTGETVT, NULL, NULL, NULL, NULL, NULL, NULL)); 171 vt_move(srow, scol); 172 vt_current(vid); 173 } 174 ar_backup(); 175 } 176 t = TOK_NOP; 177 break; 178 case TOK_CANCEL: 179 ar_backup(); 180 t = TOK_NOP; 181 break; 182 } 183 if (moving) { 184 if (make_box(!(mode & MODE_MOVE), newsrow, newscol, newrows, newcols)) { 185 t = TOK_NOP; 186 srow = newsrow; 187 scol = newscol; 188 rows = newrows; 189 cols = newcols; 190 } 191 else { 192 t |= TOK_ERROR; 193 make_box(!(mode & MODE_MOVE), srow, scol, rows, cols); 194 } 195 } 196 return t; 197 } 198 199 static int 200 wdw_current(rec) 201 register struct actrec *rec; 202 { 203 vt_id vt; 204 205 vt = ar_ctl(rec->odptr, CTGETVT, NULL, NULL, NULL, NULL, NULL, NULL); 206 207 vt_ctl(vt, CTGETSTRT, &srow, &scol); 208 vt_ctl(vt, CTGETSIZ, &rows, &cols); 209 /* allow extra space for borders */ 210 make_box(0, --srow, --scol, rows += 2, cols += 2); 211 return SUCCESS; 212 } 213 214 void 215 enter_wdw_mode(rec, reshape) 216 struct actrec *rec; 217 bool reshape; 218 { 219 struct actrec a; 220 char *tmpstr, *nstrcat(); 221 struct actrec *ar_create(); 222 extern struct slk Echslk[]; 223 224 mode = (reshape ? (MODE_RESHAPE | MODE_MOVE) : MODE_MOVE); 225 a.id = 0; 226 a.flags = AR_SKIP; 227 a.path = NULL; 228 a.odptr = (char *) (rec ? rec : ar_get_current()); 229 a.fcntbl[AR_CLOSE] = wdw_close; 230 a.fcntbl[AR_REINIT] = AR_NOP; 231 a.fcntbl[AR_HELP] = AR_NOHELP; 232 a.fcntbl[AR_NONCUR] = AR_NOP; 233 a.fcntbl[AR_CURRENT] = wdw_current; 234 a.fcntbl[AR_TEMP_CUR] = wdw_current; /* abs k15. should be optimized. */ 235 a.fcntbl[AR_CTL] = wdw_ctl; 236 a.fcntbl[AR_ODSH] = (int (*)())wdw_stream; /* added cast abs 9/12/88 */ 237 a.lifetime = AR_SHORTERM; 238 a.slks = Echslk; 239 240 ar_current(ar_create(&a), FALSE); /* abs k15 */ 241 /* 242 * put up a permanent message, saving the old one 243 */ 244 tmpstr = mess_perm(nstrcat(position1, "top-left", position2, NULL)); 245 if (Savemsg) /* ehr3 */ 246 free(Savemsg); /* ehr3 */ 247 248 Savemsg = strsave(tmpstr); 249 Open_mouse_mode = TRUE; 250 } 251