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 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.6 */
32*7c478bd9Sstevel@tonic-gate
33*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
34*7c478bd9Sstevel@tonic-gate
35*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
36*7c478bd9Sstevel@tonic-gate #include "private.h"
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate static void
link_col_major(MENU * m)39*7c478bd9Sstevel@tonic-gate link_col_major(MENU *m)
40*7c478bd9Sstevel@tonic-gate {
41*7c478bd9Sstevel@tonic-gate ITEM *i;
42*7c478bd9Sstevel@tonic-gate int n;
43*7c478bd9Sstevel@tonic-gate short c, r;
44*7c478bd9Sstevel@tonic-gate int left, up;
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gate r = 0;
47*7c478bd9Sstevel@tonic-gate c = 0;
48*7c478bd9Sstevel@tonic-gate for (i = IthItem(m, 0), n = 0; i; i = IthItem(m, ++n)) {
49*7c478bd9Sstevel@tonic-gate X(i) = c;
50*7c478bd9Sstevel@tonic-gate Y(i) = r;
51*7c478bd9Sstevel@tonic-gate Left(i) = c ? IthItem(m, n-Rows(m)) : (ITEM *) NULL;
52*7c478bd9Sstevel@tonic-gate if (n + Rows(m) >= Nitems(m)) {
53*7c478bd9Sstevel@tonic-gate Right(i) = (ITEM *) NULL;
54*7c478bd9Sstevel@tonic-gate } else {
55*7c478bd9Sstevel@tonic-gate Right(i) = IthItem(m, n + Rows(m));
56*7c478bd9Sstevel@tonic-gate }
57*7c478bd9Sstevel@tonic-gate Up(i) = r ? IthItem(m, n-1) : (ITEM *) NULL;
58*7c478bd9Sstevel@tonic-gate Down(i) = (r == Rows(m)-1) ? (ITEM *)0 : IthItem(m, n+1);
59*7c478bd9Sstevel@tonic-gate if (++r == Rows(m)) {
60*7c478bd9Sstevel@tonic-gate r = 0;
61*7c478bd9Sstevel@tonic-gate c += 1;
62*7c478bd9Sstevel@tonic-gate }
63*7c478bd9Sstevel@tonic-gate }
64*7c478bd9Sstevel@tonic-gate if (r) {
65*7c478bd9Sstevel@tonic-gate Down(IthItem(m, n-1)) = IthItem(m, n - Rows(m));
66*7c478bd9Sstevel@tonic-gate }
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate if (Cyclic(m)) {
69*7c478bd9Sstevel@tonic-gate /* Set up left and right links at edge of menu */
70*7c478bd9Sstevel@tonic-gate
71*7c478bd9Sstevel@tonic-gate r = Rows(m) * (Nitems(m)/Rows(m));
72*7c478bd9Sstevel@tonic-gate for (n = 0; n < Rows(m); n++) {
73*7c478bd9Sstevel@tonic-gate left = n + r;
74*7c478bd9Sstevel@tonic-gate if (left >= Nitems(m)) {
75*7c478bd9Sstevel@tonic-gate left -= Rows(m);
76*7c478bd9Sstevel@tonic-gate }
77*7c478bd9Sstevel@tonic-gate Left(IthItem(m, n)) = IthItem(m, left);
78*7c478bd9Sstevel@tonic-gate Right(IthItem(m, left)) = IthItem(m, n);
79*7c478bd9Sstevel@tonic-gate }
80*7c478bd9Sstevel@tonic-gate
81*7c478bd9Sstevel@tonic-gate /* Setup up and down links at edge of menu */
82*7c478bd9Sstevel@tonic-gate
83*7c478bd9Sstevel@tonic-gate for (n = 0; n < Nitems(m); n += Rows(m)) {
84*7c478bd9Sstevel@tonic-gate up = n + Rows(m) - 1;
85*7c478bd9Sstevel@tonic-gate if (up >= Nitems(m)) {
86*7c478bd9Sstevel@tonic-gate Up(IthItem(m, n)) = IthItem(m, n-1);
87*7c478bd9Sstevel@tonic-gate } else {
88*7c478bd9Sstevel@tonic-gate Up(IthItem(m, n)) = IthItem(m, up);
89*7c478bd9Sstevel@tonic-gate Down(IthItem(m, up)) = IthItem(m, n);
90*7c478bd9Sstevel@tonic-gate }
91*7c478bd9Sstevel@tonic-gate }
92*7c478bd9Sstevel@tonic-gate }
93*7c478bd9Sstevel@tonic-gate }
94*7c478bd9Sstevel@tonic-gate
95*7c478bd9Sstevel@tonic-gate static void
link_row_major(MENU * m)96*7c478bd9Sstevel@tonic-gate link_row_major(MENU *m)
97*7c478bd9Sstevel@tonic-gate {
98*7c478bd9Sstevel@tonic-gate int n;
99*7c478bd9Sstevel@tonic-gate short c, r;
100*7c478bd9Sstevel@tonic-gate ITEM *i;
101*7c478bd9Sstevel@tonic-gate int left, up;
102*7c478bd9Sstevel@tonic-gate
103*7c478bd9Sstevel@tonic-gate r = 0;
104*7c478bd9Sstevel@tonic-gate c = 0;
105*7c478bd9Sstevel@tonic-gate for (i = IthItem(m, 0), n = 0; i; i = IthItem(m, ++n)) {
106*7c478bd9Sstevel@tonic-gate X(i) = c;
107*7c478bd9Sstevel@tonic-gate Y(i) = r;
108*7c478bd9Sstevel@tonic-gate Left(i) = c ? IthItem(m, n-1) : (ITEM *) NULL;
109*7c478bd9Sstevel@tonic-gate Right(i) = (c == Cols(m)-1 || n == Nitems(m)-1) ? (ITEM *)0 :
110*7c478bd9Sstevel@tonic-gate IthItem(m, n+1);
111*7c478bd9Sstevel@tonic-gate Up(i) = r ? IthItem(m, n-Cols(m)) : (ITEM *) NULL;
112*7c478bd9Sstevel@tonic-gate
113*7c478bd9Sstevel@tonic-gate if (n+Cols(m) < Nitems(m)) {
114*7c478bd9Sstevel@tonic-gate Down(i) = IthItem(m, n + Cols(m));
115*7c478bd9Sstevel@tonic-gate } else {
116*7c478bd9Sstevel@tonic-gate if (r == Rows(m)-1) {
117*7c478bd9Sstevel@tonic-gate /* Down is undefined if this is a complete */
118*7c478bd9Sstevel@tonic-gate /* last column */
119*7c478bd9Sstevel@tonic-gate Down(i) = (ITEM *) NULL;
120*7c478bd9Sstevel@tonic-gate } else {
121*7c478bd9Sstevel@tonic-gate /* Down is set to last item if the last */
122*7c478bd9Sstevel@tonic-gate /* column isn't full */
123*7c478bd9Sstevel@tonic-gate Down(i) = IthItem(m, Nitems(m)-1);
124*7c478bd9Sstevel@tonic-gate }
125*7c478bd9Sstevel@tonic-gate }
126*7c478bd9Sstevel@tonic-gate if (++c == Cols(m)) {
127*7c478bd9Sstevel@tonic-gate c = 0;
128*7c478bd9Sstevel@tonic-gate r += 1;
129*7c478bd9Sstevel@tonic-gate }
130*7c478bd9Sstevel@tonic-gate }
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate if (Cyclic(m)) {
133*7c478bd9Sstevel@tonic-gate
134*7c478bd9Sstevel@tonic-gate /* Setup left and right links at edge of menu */
135*7c478bd9Sstevel@tonic-gate
136*7c478bd9Sstevel@tonic-gate for (n = 0; n < Nitems(m); n += Cols(m)) {
137*7c478bd9Sstevel@tonic-gate left = n + Cols(m) - 1;
138*7c478bd9Sstevel@tonic-gate if (left >= Nitems(m)) {
139*7c478bd9Sstevel@tonic-gate left = Nitems(m) - 1;
140*7c478bd9Sstevel@tonic-gate }
141*7c478bd9Sstevel@tonic-gate Left(IthItem(m, n)) = IthItem(m, left);
142*7c478bd9Sstevel@tonic-gate Right(IthItem(m, left)) = IthItem(m, n);
143*7c478bd9Sstevel@tonic-gate }
144*7c478bd9Sstevel@tonic-gate
145*7c478bd9Sstevel@tonic-gate /* Setup up and down links at edge of menu */
146*7c478bd9Sstevel@tonic-gate
147*7c478bd9Sstevel@tonic-gate r = (Rows(m) - 1) * Cols(m);
148*7c478bd9Sstevel@tonic-gate for (n = 0; n < Cols(m); n++) {
149*7c478bd9Sstevel@tonic-gate up = n + r;
150*7c478bd9Sstevel@tonic-gate
151*7c478bd9Sstevel@tonic-gate /* If there is an incomplete line below this one */
152*7c478bd9Sstevel@tonic-gate /* the point to the last item in the menu. */
153*7c478bd9Sstevel@tonic-gate
154*7c478bd9Sstevel@tonic-gate if (up >= Nitems(m)) {
155*7c478bd9Sstevel@tonic-gate Up(IthItem(m, n)) = IthItem(m, Nitems(m)-1);
156*7c478bd9Sstevel@tonic-gate } else {
157*7c478bd9Sstevel@tonic-gate Up(IthItem(m, n)) = IthItem(m, up);
158*7c478bd9Sstevel@tonic-gate Down(IthItem(m, up)) = IthItem(m, n);
159*7c478bd9Sstevel@tonic-gate }
160*7c478bd9Sstevel@tonic-gate }
161*7c478bd9Sstevel@tonic-gate }
162*7c478bd9Sstevel@tonic-gate }
163*7c478bd9Sstevel@tonic-gate
164*7c478bd9Sstevel@tonic-gate void
_link_items(MENU * m)165*7c478bd9Sstevel@tonic-gate _link_items(MENU *m)
166*7c478bd9Sstevel@tonic-gate {
167*7c478bd9Sstevel@tonic-gate if (Items(m) && IthItem(m, 0)) {
168*7c478bd9Sstevel@tonic-gate ResetLink(m);
169*7c478bd9Sstevel@tonic-gate if (RowMajor(m)) {
170*7c478bd9Sstevel@tonic-gate link_row_major(m);
171*7c478bd9Sstevel@tonic-gate } else {
172*7c478bd9Sstevel@tonic-gate link_col_major(m);
173*7c478bd9Sstevel@tonic-gate }
174*7c478bd9Sstevel@tonic-gate }
175*7c478bd9Sstevel@tonic-gate }
176