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
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.
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]
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1997, by Sun Mircrosystems, Inc.
28 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.12 */
35 #include <sys/types.h>
39 _post_item(MENU
*m
, ITEM
*k
)
47 /* Display the mark region of the item */
50 (void) wattron(Win(m
), Grey(m
));
52 for (i
= Marklen(m
); i
> 0; i
--) {
53 (void) waddch(Win(m
), ' ');
56 if (Value(k
) || k
== Current(m
)) {
57 (void) wattron(Win(m
), Fore(m
));
60 (void) wattron(Win(m
), Back(m
));
64 /* Display the mark */
65 if (Value(k
) || (OneValue(m
) && k
== Current(m
))) {
67 (void) waddstr(Win(m
), Mark(m
));
70 for (i
= Marklen(m
); i
> 0; i
--) {
71 (void) waddch(Win(m
), ' ');
76 /* Display the name */
78 (void) waddnstr(Win(m
), Name(k
), MaxName(m
));
79 if (ShowDesc(m
) && MaxDesc(m
) != 0) {
84 for (i
= MaxName(m
) - NameLen(k
); i
> 0; i
--) {
85 (void) waddch(Win(m
), c
);
88 /* Display the description */
90 if (ShowDesc(m
) && MaxDesc(m
) != 0) {
91 (void) waddch(Win(m
), Pad(m
));
92 if (DescriptionLen(k
) != 0) {
93 (void) waddstr(Win(m
), Description(k
));
95 for (i
= MaxDesc(m
) - DescriptionLen(k
); i
> 0; i
--) {
96 (void) waddch(Win(m
), ' ');
100 (void) wattroff(Win(m
), Fore(m
));
103 (void) wattroff(Win(m
), Back(m
));
106 (void) wattroff(Win(m
), Grey(m
));
111 _move_post_item(MENU
*m
, ITEM
*k
)
113 (void) wmove(Win(m
), Y(k
), X(k
) * (Itemlen(m
)+1));
121 return (E_BAD_ARGUMENT
);
124 return (E_BAD_STATE
);
127 return (E_NOT_POSTED
);
131 (void) werase(US(m
));
133 (void) delwin(Sub(m
));
134 Sub(m
) = (WINDOW
*) NULL
;
135 (void) delwin(Win(m
));
136 Win(m
) = (WINDOW
*) NULL
;
142 * This routine draws the item indicated by oldcur first and then
143 * draws the item indicated by Current. This will have the affect
144 * of unselecting the first item and selecting the next.
147 _movecurrent(MENU
*m
, ITEM
*oldcur
)
149 if (oldcur
!= Current(m
)) {
150 _move_post_item(m
, oldcur
);
151 _move_post_item(m
, Current(m
));
156 * Draw the entire menu into the super window
157 * This routine assumes all items have been linked and
158 * that the menu is in at least a pre-post state.
168 k
= 0; /* Line number */
170 si
= Cyclic(m
) ? i
: (ITEM
*) NULL
;
172 (void) wmove(Win(m
), k
++, 0);
174 sj
= Cyclic(m
) ? j
: (ITEM
*) NULL
;
177 if ((j
= Right(j
)) != sj
) {
178 (void) waddch(Win(m
), ' ');
181 } while ((i
= Down(i
)) != si
);
188 int r
, c
; /* visible # of rows and cols */
191 return (E_BAD_ARGUMENT
);
194 return (E_BAD_STATE
);
199 /* Make sure there is at least one item present */
200 if (Items(m
) && IthItem(m
, 0)) {
201 getmaxyx(US(m
), r
, c
);
203 /* Make sure the menu fits into the window horizontally */
204 if (c
< Width(m
) || r
< Height(m
)) {
208 /* Create the menu window and derived windows */
209 if ((Win(m
) = newwin(Rows(m
), Width(m
), 0, 0)) ==
211 return (E_SYSTEM_ERROR
);
215 * Take the minimum of the height of the menu (Height), the
216 * physical height of the window (r), and the number of rows
217 * in the menu (Rows).
219 r
= min(min(r
, Rows(m
)), Height(m
));
221 if ((Sub(m
) = derwin(Win(m
), r
, Width(m
), 0, 0)) ==
223 return (E_SYSTEM_ERROR
);
226 /* If needed, link all items in the menu */
233 /* If only one value can be set then unset all values */
236 for (ip
= Items(m
); *ip
; ip
++) {
241 /* Go do the drawing of the menu */
246 _show(m
); /* Display the menu */
249 return (E_NOT_CONNECTED
);