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