stmenu.c revision 8883f1c270cc8e33c18dd088e744840092b47bbb
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#include <stdio.h>
#include <ctype.h>
#include "wish.h"
#include "menu.h"
#include "menudefs.h"
#include "vtdefs.h"
#include "token.h"
#include "ctl.h"
#include "moremacros.h"
#include "message.h"
#include "sizes.h"
static char *curstring;
static int menu_match();
/* mouse coordinates */
extern int Mouse_row;
extern int Mouse_col;
menu_stream(t)
register token t;
{
register struct menu *m;
void _menu_cleanup();
if (MNU_curid < 0)
return t;
/* curstring is set if we partial-matched on the previous character */
if (curstring) {
return TOK_NEXT;
}
else if (t == TOK_BACKSPACE) {
if (m->hcols > 1) {
return TOK_NEXT;
}
}
if (myisprint((int) t) && t != ' ') {
mess_lock();
return(TOK_BADCHAR);
}
}
/*
* NOTE: tokens that change the current menu item return
* TOK_NEXT so that application stream handler (objmenu_stream)
* is aware ...
*/
switch (t) {
case ' ':
case TOK_TAB: /* abs k16 */
case TOK_RIGHT:
if (m->ncols > 1) {
t = TOK_NEXT;
/*
* RIGHT ARROW
* Do not match inactive menu items.
*/
t = TOK_NEXT;
}
else {
mess_lock();
t = TOK_NOP;
break;
}
}
}
break;
}
/* FALL THROUGH */
case TOK_DOWN:
case TOK_NEXT:
t = TOK_NEXT;
/*
* DOWN ARROW
* Do not match inactive menu items.
*/
t = TOK_NEXT;
}
else {
menu_index(m, 0, MENU_ALL);
t = TOK_NEXT;
}
}
}
else {
menu_index(m, 0, MENU_ALL);
t = TOK_NEXT;
/*
* DOWN ARROW when you are at the bottom of
* the menu and the down arrow will take you
* to the first menu item.
*
* Do not match inactive menu items.
*/
t = TOK_NEXT;
}
}
break;
case TOK_BPRESSED: /* Button 1 press */
if (m->ncols > 1) {
/*
* Multicolumn menu: get frame size (rows)
* to determine menu item offset (newindex)
*/
}
else
t = TOK_BADCHAR; /* out of bounds */
t = TOK_NOP; /* do nothing */
else {
/*
* Do not match inactive menu items
*
* NOTE: The mouse code for inactive menu items
* will remain untested until ported to the 386.
* sfsup!njp 4/12/89
*/
mess_lock();
t = TOK_NOP;
}
else
t = TOK_NEXT;
}
break;
case TOK_BACKSPACE:
case TOK_BTAB: /* abs k16 */
case TOK_LEFT:
if (m->ncols > 1) {
t = TOK_NEXT;
/*
* LEFT ARROW
* Do not match inactive menu items.
*/
t = TOK_NEXT;
}
else {
mess_lock();
t = TOK_NOP;
break;
}
}
}
break;
}
/* FALL THROUGH */
case TOK_UP:
case TOK_PREVIOUS:
if (m->index > 0) {
t = TOK_NEXT;
/*
* UP ARROW
* Do not match inactive menu items.
*/
if (m->index > 0) {
t = TOK_NEXT;
}
else {
t = TOK_NEXT;
}
}
}
else {
t = TOK_NEXT;
/*
* UP ARROW when you are at the top of
* the menu and the up arrow will take you
* to the last menu item.
*
* Do not match inactive menu items.
*/
t = TOK_NEXT;
}
}
break;
case TOK_BRELEASED:
if (m->ncols > 1) {
/*
* Multicolumn menu: get frame size (rows)
* to determine menu item offset (newindex)
*/
}
else
t = TOK_NOP;
else if (m->flags & MENU_MSELECT)
t = TOK_MARK; /* multi-select menu */
else
t = TOK_OPEN;
break;
case TOK_RETURN:
case TOK_OPEN:
case TOK_ENTER:
t = TOK_OPEN;
break;
case TOK_HOME:
t = TOK_NEXT;
t = TOK_NEXT;
}
break;
case TOK_BEG:
menu_index(m, 0, MENU_ALL);
t = TOK_NEXT;
t = TOK_NEXT;
}
break;
case TOK_LL:
case TOK_SHOME: /* move to last item on cur. page */
{
t = TOK_NEXT;
t = TOK_NEXT;
}
}
break;
case TOK_END:
t = TOK_NEXT;
t = TOK_NEXT;
}
break;
case TOK_SR:
if (m->topline > 0) {
/* force reverse scroll */
/*reset position */
t = TOK_NEXT;
/*
* REVERSE SCROLL
* Do not match inactive menu items.
*/
if (m->topline > 0) {
/* force reverse scroll */
/*reset position */
t = TOK_NEXT;
}
else {
t = TOK_NOP;
break;
}
}
}
break;
case TOK_SF:
if (m->ncols == 1) {
int row;
int col;
/* cause scroll */
/* reset position */
t = TOK_NEXT;
/* cause scroll */
/* reset position */
t = TOK_NEXT;
}
else {
t = TOK_NOP;
break;
}
}
}
}
break;
case TOK_PPAGE:
if (m->ncols == 1) {
int row;
int col;
if (m->topline == 0)
break;
if (newindex < 0)
newindex = 0;
/*
* force middle of page
* then set position to top of window
*/
menu_index(m, newindex, 0);
t = TOK_NEXT;
if (m->index > 0) {
t = TOK_NEXT;
}
else {
t = TOK_NEXT;
}
}
}
break;
case TOK_NPAGE:
if (m->ncols == 1) {
int row;
int col;
break;
/*
* force middle of page
* then set position to top of window
*/
menu_index(m, newindex, 0);
t = TOK_NEXT;
t = TOK_NEXT;
}
else {
menu_index(m, 0, MENU_ALL);
t = TOK_NEXT;
}
}
}
break;
default:
if (myisprint((int) t)) {
}
else {
menu_index(m, 0, MENU_ALL);
}
}
return TOK_NEXT;
}
else {
mess_lock();
return(TOK_BADCHAR);
}
}
break;
}
return t;
}
void
{
if (curstring)
}
static void strtolower();
static int nocase_strncmp();
static int
menu_match(m, s, n, t)
register struct menu *m;
char *s;
int n;
token t;
{
register int i;
register int start;
register int count;
register char *p;
if (nocase_strncmp(p, s, n) == 0 && ((p[n] == t) ||
/*
* Do not match inactive menu items
*/
mess_lock();
return start;
}
else {
if (curstring)
}
}
return i;
}
if (++i >= m->number)
i = 0;
}
return FAIL;
}
static void
strtolower(s)
register char *s;
{
for (; *s != '\0'; s++)
*s = tolower(*s);
}
static int
nocase_strncmp(p, s, n)
register char *p, *s;
int n;
{
register int i;
if (!p || !s)
return(1);
for (i = 0; i < n; i++) {
if (!(*p || *s))
break; /* both strings shorter than n */
return(1);
}
return(0);
}