void menu_format(MENU *m, int *rows, int *cols) { if (m) { *rows = FRows(m); *cols = FCols(m); } else { *rows = FRows(Dfl_Menu); *cols = FCols(Dfl_Menu); } }
int set_menu_format(MENU *m, int rows, int cols) { if (rows < 0 || cols < 0) { return (E_BAD_ARGUMENT); } if (m) { if (Posted(m)) { return (E_POSTED); } if (rows == 0) { rows = FRows(m); } if (cols == 0) { cols = FCols(m); } /* The pattern buffer is allocated after items have been */ /* connected */ if (Pattern(m)) { IthPattern(m, 0) = '\0'; Pindex(m) = 0; } FRows(m) = rows; FCols(m) = cols; Cols(m) = min(cols, Nitems(m)); Rows(m) = (Nitems(m)-1) / cols + 1; Height(m) = min(rows, Rows(m)); Top(m) = 0; Current(m) = IthItem(m, 0); SetLink(m); _scale(m); } else { if (rows > 0) { FRows(Dfl_Menu) = rows; } if (cols > 0) { FCols(Dfl_Menu) = cols; } } return (E_OK); }
MENU * new_menu(ITEM **items) { MENU *m; if ((m = (MENU *) calloc(1, sizeof (MENU))) != (MENU *)0) { *m = *Dfl_Menu; Rows(m) = FRows(m); Cols(m) = FCols(m); if (items) { if (*items == (ITEM *)0 || !_connect(m, items)) { free(m); return ((MENU *)0); } } return (m); } return ((MENU *)0); }
int set_menu_opts(MENU *m, int opt) { ITEM **ip; if (m) { if (Posted(m)) { return (E_POSTED); } /* Check to see if the ROWMAJOR option is changing. If so, */ /* set top and current to 0. */ if ((opt & O_ROWMAJOR) != RowMajor(m)) { Top(m) = 0; Current(m) = IthItem(m, 0); (void) set_menu_format(m, FRows(m), FCols(m)); } /* if O_NONCYCLIC option changed, set bit to re-link items */ if ((opt & O_NONCYCLIC) != (Mopt(m) & O_NONCYCLIC)) { SetLink(m); } Mopt(m) = opt; if (OneValue(m) && Items(m)) { for (ip = Items(m); *ip; ip++) { /* Unset values if selection not allowed. */ Value(*ip) = FALSE; } } _scale(m); /* Redo sizing information */ } else { Mopt(Dfl_Menu) = opt; } return (E_OK); }