1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */
24*7c478bd9Sstevel@tonic-gate
25*7c478bd9Sstevel@tonic-gate
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate * Copyright (c) 1997, by Sun Mircrosystems, Inc.
28*7c478bd9Sstevel@tonic-gate * All rights reserved.
29*7c478bd9Sstevel@tonic-gate */
30*7c478bd9Sstevel@tonic-gate
31*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
32*7c478bd9Sstevel@tonic-gate
33*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
34*7c478bd9Sstevel@tonic-gate #include "private.h"
35*7c478bd9Sstevel@tonic-gate
36*7c478bd9Sstevel@tonic-gate void
_post_item(MENU * m,ITEM * k)37*7c478bd9Sstevel@tonic-gate _post_item(MENU *m, ITEM *k)
38*7c478bd9Sstevel@tonic-gate {
39*7c478bd9Sstevel@tonic-gate int foreon = FALSE;
40*7c478bd9Sstevel@tonic-gate int backon = FALSE;
41*7c478bd9Sstevel@tonic-gate int greyon = FALSE;
42*7c478bd9Sstevel@tonic-gate chtype c;
43*7c478bd9Sstevel@tonic-gate int i;
44*7c478bd9Sstevel@tonic-gate
45*7c478bd9Sstevel@tonic-gate /* Display the mark region of the item */
46*7c478bd9Sstevel@tonic-gate
47*7c478bd9Sstevel@tonic-gate if (!Selectable(k)) {
48*7c478bd9Sstevel@tonic-gate (void) wattron(Win(m), Grey(m));
49*7c478bd9Sstevel@tonic-gate greyon = TRUE;
50*7c478bd9Sstevel@tonic-gate for (i = Marklen(m); i > 0; i--) {
51*7c478bd9Sstevel@tonic-gate (void) waddch(Win(m), ' ');
52*7c478bd9Sstevel@tonic-gate }
53*7c478bd9Sstevel@tonic-gate } else {
54*7c478bd9Sstevel@tonic-gate if (Value(k) || k == Current(m)) {
55*7c478bd9Sstevel@tonic-gate (void) wattron(Win(m), Fore(m));
56*7c478bd9Sstevel@tonic-gate foreon = TRUE;
57*7c478bd9Sstevel@tonic-gate } else {
58*7c478bd9Sstevel@tonic-gate (void) wattron(Win(m), Back(m));
59*7c478bd9Sstevel@tonic-gate backon = TRUE;
60*7c478bd9Sstevel@tonic-gate }
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate /* Display the mark */
63*7c478bd9Sstevel@tonic-gate if (Value(k) || (OneValue(m) && k == Current(m))) {
64*7c478bd9Sstevel@tonic-gate if (Marklen(m)) {
65*7c478bd9Sstevel@tonic-gate (void) waddstr(Win(m), Mark(m));
66*7c478bd9Sstevel@tonic-gate }
67*7c478bd9Sstevel@tonic-gate } else {
68*7c478bd9Sstevel@tonic-gate for (i = Marklen(m); i > 0; i--) {
69*7c478bd9Sstevel@tonic-gate (void) waddch(Win(m), ' ');
70*7c478bd9Sstevel@tonic-gate }
71*7c478bd9Sstevel@tonic-gate }
72*7c478bd9Sstevel@tonic-gate }
73*7c478bd9Sstevel@tonic-gate
74*7c478bd9Sstevel@tonic-gate /* Display the name */
75*7c478bd9Sstevel@tonic-gate
76*7c478bd9Sstevel@tonic-gate (void) waddnstr(Win(m), Name(k), MaxName(m));
77*7c478bd9Sstevel@tonic-gate if (ShowDesc(m) && MaxDesc(m) != 0) {
78*7c478bd9Sstevel@tonic-gate c = Pad(m);
79*7c478bd9Sstevel@tonic-gate } else {
80*7c478bd9Sstevel@tonic-gate c = ' ';
81*7c478bd9Sstevel@tonic-gate }
82*7c478bd9Sstevel@tonic-gate for (i = MaxName(m) - NameLen(k); i > 0; i--) {
83*7c478bd9Sstevel@tonic-gate (void) waddch(Win(m), c);
84*7c478bd9Sstevel@tonic-gate }
85*7c478bd9Sstevel@tonic-gate
86*7c478bd9Sstevel@tonic-gate /* Display the description */
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate if (ShowDesc(m) && MaxDesc(m) != 0) {
89*7c478bd9Sstevel@tonic-gate (void) waddch(Win(m), Pad(m));
90*7c478bd9Sstevel@tonic-gate if (DescriptionLen(k) != 0) {
91*7c478bd9Sstevel@tonic-gate (void) waddstr(Win(m), Description(k));
92*7c478bd9Sstevel@tonic-gate }
93*7c478bd9Sstevel@tonic-gate for (i = MaxDesc(m) - DescriptionLen(k); i > 0; i--) {
94*7c478bd9Sstevel@tonic-gate (void) waddch(Win(m), ' ');
95*7c478bd9Sstevel@tonic-gate }
96*7c478bd9Sstevel@tonic-gate }
97*7c478bd9Sstevel@tonic-gate if (foreon) {
98*7c478bd9Sstevel@tonic-gate (void) wattroff(Win(m), Fore(m));
99*7c478bd9Sstevel@tonic-gate }
100*7c478bd9Sstevel@tonic-gate if (backon) {
101*7c478bd9Sstevel@tonic-gate (void) wattroff(Win(m), Back(m));
102*7c478bd9Sstevel@tonic-gate }
103*7c478bd9Sstevel@tonic-gate if (greyon) {
104*7c478bd9Sstevel@tonic-gate (void) wattroff(Win(m), Grey(m));
105*7c478bd9Sstevel@tonic-gate }
106*7c478bd9Sstevel@tonic-gate }
107*7c478bd9Sstevel@tonic-gate
108*7c478bd9Sstevel@tonic-gate void
_move_post_item(MENU * m,ITEM * k)109*7c478bd9Sstevel@tonic-gate _move_post_item(MENU *m, ITEM *k)
110*7c478bd9Sstevel@tonic-gate {
111*7c478bd9Sstevel@tonic-gate (void) wmove(Win(m), Y(k), X(k) * (Itemlen(m)+1));
112*7c478bd9Sstevel@tonic-gate _post_item(m, k);
113*7c478bd9Sstevel@tonic-gate }
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate int
unpost_menu(MENU * m)116*7c478bd9Sstevel@tonic-gate unpost_menu(MENU *m)
117*7c478bd9Sstevel@tonic-gate {
118*7c478bd9Sstevel@tonic-gate if (!m) {
119*7c478bd9Sstevel@tonic-gate return (E_BAD_ARGUMENT);
120*7c478bd9Sstevel@tonic-gate }
121*7c478bd9Sstevel@tonic-gate if (Indriver(m)) {
122*7c478bd9Sstevel@tonic-gate return (E_BAD_STATE);
123*7c478bd9Sstevel@tonic-gate }
124*7c478bd9Sstevel@tonic-gate if (!Posted(m)) {
125*7c478bd9Sstevel@tonic-gate return (E_NOT_POSTED);
126*7c478bd9Sstevel@tonic-gate }
127*7c478bd9Sstevel@tonic-gate Iterm(m);
128*7c478bd9Sstevel@tonic-gate Mterm(m);
129*7c478bd9Sstevel@tonic-gate (void) werase(US(m));
130*7c478bd9Sstevel@tonic-gate wsyncup(US(m));
131*7c478bd9Sstevel@tonic-gate (void) delwin(Sub(m));
132*7c478bd9Sstevel@tonic-gate Sub(m) = (WINDOW *) NULL;
133*7c478bd9Sstevel@tonic-gate (void) delwin(Win(m));
134*7c478bd9Sstevel@tonic-gate Win(m) = (WINDOW *) NULL;
135*7c478bd9Sstevel@tonic-gate ResetPost(m);
136*7c478bd9Sstevel@tonic-gate return (E_OK);
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gate /*
140*7c478bd9Sstevel@tonic-gate * This routine draws the item indicated by oldcur first and then
141*7c478bd9Sstevel@tonic-gate * draws the item indicated by Current. This will have the affect
142*7c478bd9Sstevel@tonic-gate * of unselecting the first item and selecting the next.
143*7c478bd9Sstevel@tonic-gate */
144*7c478bd9Sstevel@tonic-gate void
_movecurrent(MENU * m,ITEM * oldcur)145*7c478bd9Sstevel@tonic-gate _movecurrent(MENU *m, ITEM *oldcur)
146*7c478bd9Sstevel@tonic-gate {
147*7c478bd9Sstevel@tonic-gate if (oldcur != Current(m)) {
148*7c478bd9Sstevel@tonic-gate _move_post_item(m, oldcur);
149*7c478bd9Sstevel@tonic-gate _move_post_item(m, Current(m));
150*7c478bd9Sstevel@tonic-gate }
151*7c478bd9Sstevel@tonic-gate }
152*7c478bd9Sstevel@tonic-gate
153*7c478bd9Sstevel@tonic-gate /*
154*7c478bd9Sstevel@tonic-gate * Draw the entire menu into the super window
155*7c478bd9Sstevel@tonic-gate * This routine assumes all items have been linked and
156*7c478bd9Sstevel@tonic-gate * that the menu is in at least a pre-post state.
157*7c478bd9Sstevel@tonic-gate */
158*7c478bd9Sstevel@tonic-gate
159*7c478bd9Sstevel@tonic-gate void
_draw(MENU * m)160*7c478bd9Sstevel@tonic-gate _draw(MENU *m)
161*7c478bd9Sstevel@tonic-gate {
162*7c478bd9Sstevel@tonic-gate int k;
163*7c478bd9Sstevel@tonic-gate ITEM *i, *j;
164*7c478bd9Sstevel@tonic-gate ITEM *si, *sj;
165*7c478bd9Sstevel@tonic-gate
166*7c478bd9Sstevel@tonic-gate k = 0; /* Line number */
167*7c478bd9Sstevel@tonic-gate i = IthItem(m, 0);
168*7c478bd9Sstevel@tonic-gate si = Cyclic(m) ? i : (ITEM *) NULL;
169*7c478bd9Sstevel@tonic-gate do {
170*7c478bd9Sstevel@tonic-gate (void) wmove(Win(m), k++, 0);
171*7c478bd9Sstevel@tonic-gate j = i;
172*7c478bd9Sstevel@tonic-gate sj = Cyclic(m) ? j : (ITEM *) NULL;
173*7c478bd9Sstevel@tonic-gate do {
174*7c478bd9Sstevel@tonic-gate _post_item(m, j);
175*7c478bd9Sstevel@tonic-gate if ((j = Right(j)) != sj) {
176*7c478bd9Sstevel@tonic-gate (void) waddch(Win(m), ' ');
177*7c478bd9Sstevel@tonic-gate }
178*7c478bd9Sstevel@tonic-gate } while (j != sj);
179*7c478bd9Sstevel@tonic-gate } while ((i = Down(i)) != si);
180*7c478bd9Sstevel@tonic-gate }
181*7c478bd9Sstevel@tonic-gate
182*7c478bd9Sstevel@tonic-gate int
post_menu(MENU * m)183*7c478bd9Sstevel@tonic-gate post_menu(MENU *m)
184*7c478bd9Sstevel@tonic-gate {
185*7c478bd9Sstevel@tonic-gate ITEM **ip;
186*7c478bd9Sstevel@tonic-gate int r, c; /* visible # of rows and cols */
187*7c478bd9Sstevel@tonic-gate
188*7c478bd9Sstevel@tonic-gate if (!m) {
189*7c478bd9Sstevel@tonic-gate return (E_BAD_ARGUMENT);
190*7c478bd9Sstevel@tonic-gate }
191*7c478bd9Sstevel@tonic-gate if (Indriver(m)) {
192*7c478bd9Sstevel@tonic-gate return (E_BAD_STATE);
193*7c478bd9Sstevel@tonic-gate }
194*7c478bd9Sstevel@tonic-gate if (Posted(m)) {
195*7c478bd9Sstevel@tonic-gate return (E_POSTED);
196*7c478bd9Sstevel@tonic-gate }
197*7c478bd9Sstevel@tonic-gate /* Make sure there is at least one item present */
198*7c478bd9Sstevel@tonic-gate if (Items(m) && IthItem(m, 0)) {
199*7c478bd9Sstevel@tonic-gate getmaxyx(US(m), r, c);
200*7c478bd9Sstevel@tonic-gate
201*7c478bd9Sstevel@tonic-gate /* Make sure the menu fits into the window horizontally */
202*7c478bd9Sstevel@tonic-gate if (c < Width(m) || r < Height(m)) {
203*7c478bd9Sstevel@tonic-gate return (E_NO_ROOM);
204*7c478bd9Sstevel@tonic-gate }
205*7c478bd9Sstevel@tonic-gate
206*7c478bd9Sstevel@tonic-gate /* Create the menu window and derived windows */
207*7c478bd9Sstevel@tonic-gate if ((Win(m) = newwin(Rows(m), Width(m), 0, 0)) ==
208*7c478bd9Sstevel@tonic-gate (WINDOW *) NULL) {
209*7c478bd9Sstevel@tonic-gate return (E_SYSTEM_ERROR);
210*7c478bd9Sstevel@tonic-gate }
211*7c478bd9Sstevel@tonic-gate
212*7c478bd9Sstevel@tonic-gate /*
213*7c478bd9Sstevel@tonic-gate * Take the minimum of the height of the menu (Height), the
214*7c478bd9Sstevel@tonic-gate * physical height of the window (r), and the number of rows
215*7c478bd9Sstevel@tonic-gate * in the menu (Rows).
216*7c478bd9Sstevel@tonic-gate */
217*7c478bd9Sstevel@tonic-gate r = min(min(r, Rows(m)), Height(m));
218*7c478bd9Sstevel@tonic-gate
219*7c478bd9Sstevel@tonic-gate if ((Sub(m) = derwin(Win(m), r, Width(m), 0, 0)) ==
220*7c478bd9Sstevel@tonic-gate (WINDOW *) NULL) {
221*7c478bd9Sstevel@tonic-gate return (E_SYSTEM_ERROR);
222*7c478bd9Sstevel@tonic-gate }
223*7c478bd9Sstevel@tonic-gate
224*7c478bd9Sstevel@tonic-gate /* If needed, link all items in the menu */
225*7c478bd9Sstevel@tonic-gate if (LinkNeeded(m)) {
226*7c478bd9Sstevel@tonic-gate _link_items(m);
227*7c478bd9Sstevel@tonic-gate }
228*7c478bd9Sstevel@tonic-gate
229*7c478bd9Sstevel@tonic-gate SetPost(m);
230*7c478bd9Sstevel@tonic-gate
231*7c478bd9Sstevel@tonic-gate /* If only one value can be set then unset all values */
232*7c478bd9Sstevel@tonic-gate /* to start. */
233*7c478bd9Sstevel@tonic-gate if (OneValue(m)) {
234*7c478bd9Sstevel@tonic-gate for (ip = Items(m); *ip; ip++) {
235*7c478bd9Sstevel@tonic-gate Value(*ip) = FALSE;
236*7c478bd9Sstevel@tonic-gate }
237*7c478bd9Sstevel@tonic-gate }
238*7c478bd9Sstevel@tonic-gate
239*7c478bd9Sstevel@tonic-gate /* Go do the drawing of the menu */
240*7c478bd9Sstevel@tonic-gate _draw(m);
241*7c478bd9Sstevel@tonic-gate
242*7c478bd9Sstevel@tonic-gate Minit(m);
243*7c478bd9Sstevel@tonic-gate Iinit(m);
244*7c478bd9Sstevel@tonic-gate _show(m); /* Display the menu */
245*7c478bd9Sstevel@tonic-gate return (E_OK);
246*7c478bd9Sstevel@tonic-gate }
247*7c478bd9Sstevel@tonic-gate return (E_NOT_CONNECTED);
248*7c478bd9Sstevel@tonic-gate }
249