mdefault.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1986 AT&T
* All Rights Reserved
*/
#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.22 */
#include <stdio.h>
#include "wish.h"
#include "menu.h"
#include "menudefs.h"
#include "vtdefs.h"
#include "terror.h"
#include "ctl.h"
#include "sizes.h"
char *shrink_descriptor();
#define MAX_MITEMS 10
int num; /* menu number */
char *title; /* menu title */
int startrow; /* start row for the menu frame */
int startcol; /* start column for the menu frame */
int menurows; /* default menu rows */
int menucols; /* default menu cols */
char *arg;
{
register int total; /* total items */
register int itemwidth; /* width of longest item */
register int descwidth; /* width of longest description */
register int menuwidth; /* width of the menu */
int cols_specified; /* are number of cols specified? */
int rows_specified; /* are number of rows specified? */
bool has_description = FALSE;
/*
* Determine ITEMWIDTH and DESCRIPTION WIDTH
* as well as the TOTAL number of items
*/
{
} /* no description */
}
if (!total)
/* an item which fits may still need truncation to show that description
* didn't fit. - 4 becaue of " - " and min 1 char of description
*/
{
mflags |= MENU_TRUNC;
descwidth = 1;
}
else /* full name fits, truncate description if needed */
{
{
if (ml.description)
{
/* the "3" below is for the " - " separator */
}
}
}
if (descwidth) {
/*
* If ANY item has a description, then stay single column,
*
* width = longest highlight +
* longest description +
* 3 (for the " - ") +
* 2 (for space between text and sides)
*
*/
if (rows_specified) {
/*
* actual rows = min(specified rows,
* fittable rows,
* needed rows);
*/
;
}
else {
/*
* actual rows = min(MAX_MITEMS, needed rows);
*/
}
menucols = 1;
/*
* if the description is too long, then truncate
*/
;
}
else if (rows_specified && !cols_specified) {
/*
* determine probable rows, then probable columns
*
* probable rows = min(specified rows, "fittable" rows)
*/
;
/*
* determine actual rows and columns
*/
/*
* menu not displayable in multi-columns ...
*
* actual rows = probable rows
* actual cols = 1
*
* truncate the menu if necessary
*/
menucols = 1;
menuwidth--;
}
else {
/*
* actual rows = probable cols == 1 ?
* min(specified rows, fittable rows) :
* probable rows
* actual cols = probable cols
*/
if (probcols == 1) {
;
}
else
}
/*
* Eliminate white-space from unused rows
*/
}
else if (cols_specified && !rows_specified) {
/*
* determine probable columns, then probable rows
*
* If necessary, truncate the length of each
* column until the menu fits
*/
itemwidth--;
if (itemwidth <= 0) {
/*
* give up ...
* default to single column and
* truncate the menu if necessary.
*/
probcols = 1;
probwidth--;
break;
}
}
/*
* determine actual rows and columns
*/
/*
* menu too big ...
*
* actual cols = 1
* actual rows = min(MAX_MITEMS, total)
*/
menucols = 1;
menuwidth--;
}
else {
}
/*
* Eliminate white-space from unused columns ...
* First compute the number of columns to chop and
* then subtract it from menucols
*/
if (menucols > 1) {
if (chop) {
}
}
}
else if (rows_specified && cols_specified) {
/*
* determine probable columns, then probable rows
*
* If necessary, truncate the length of each
* column until the menu fits
*/
itemwidth--;
if (itemwidth <= 0) {
/*
* give up ...
* default to single column and
* truncate the menu if necessary.
*/
probcols = 1;
probwidth--;
break;
}
}
/*
* determine actual rows and columns
*/
/*
* Menu can't be displayed in multi-columns ...
*
* actual cols = 1;
* actual rows = min(specified rows, fittable rows);
*/
menucols = 1;
menuwidth--;
;
}
else {
/*
* actual rows = probable cols == 1 ?
* min(specified rows, fittable rows) :
* probable rows
* actual cols = probable cols
*/
if (probcols == 1) {
;
}
else
}
/*
* Eliminate white-space from unused columns ...
* First compute the number of columns to chop and
* then subtract it from menucols
*/
if (menucols > 1) {
if (chop) {
}
}
}
else {
/*
* ROWS and COLUMNS are not specified so churn away ...
*/
if (total <= MAX_MITEMS) {
/*
* use single column ... truncate menu if necessary
*/
menucols = 1;
menuwidth--; /* truncate until it fits */
}
else {
/*
* 1) make menu at least as wide as the title,
*
* 2) make its aspect as close to 1:3
* (height:width) as possible).
*
* These are arbitrarily pleasing values.
*
*/
menucols = 1;
break;
menucols++;
}
/*
* try "backing-off" one column and
* recomputing rows.
*/
/*
* if all else fails ... resort to
* single column.
*/
menucols = 1;
menuwidth--;
}
}
if (menucols == 1)
}
}
/*
* Make sure the menu VT (frame) can house the title
* vt_create adds the border cols hence FIXED_TITLE - 2
*/
/*
* Create a VT (frame) to house the menu
*/
menuwidth)) == VT_UNDEFINED)
{
/*
* try putting the VT anywhere
*/
}
/*
* If the menu still can't be displayed then return FAIL
*/
if (vid == VT_UNDEFINED) {
mess_temp("Object can not be displayed, frame may be too large for the screen");
}
if (num >= 0)
}
unsigned flags;
int menurows;
int menucols;
char *arg;
{
char *s;
if (oldmid >= 0)
else
}
return newmid;
}
/* shrink_descriptor truncates the provided string so it will fit in a
** window thats the screen width minus reserved_col wide. The
** end of the string is replaced with TRUNCATE_STR to show that
** the string was truncated.
** RETURN VALUE: Pointer to the truncated string.
** SIDE AFFECTS: The string parameter is itself may be modified.
** this routine does not make a copy before truncation.
** If called with the result of a multi_eval, the
** cur field of the attribute will be modified, affecting
** future multi_evals if the descriptor is not
** EVAL_ALWAYS
*/
char *
char *str;
int reserved_cols;
{
int max_len;
return(str);
}