home *** CD-ROM | disk | FTP | other *** search
- /*
- menuaftg.c 4/10/88
-
- % menu_AddFieldToGrid
-
- menu add field to grid
-
- C-scape 3.2
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 6/24/88 jmd converted to new xarray/iarray calls
- 12/11/88 jmd fixed first field in row problem
- 7/17/89 jdc added adjustment of menu->frowcount
- 3/28/90 jmd ansi-fied
- 9/24/90 jmd added call to ja_Ok
- */
-
- #include "menu.h"
-
- boolean menu_AddFieldToGrid(menu_type menu, int fieldno, int row, int col)
- /*
- Add a new field to the menu's field grid.
- returns TRUE if successful.
- Sets the field's row and column.
-
- Since most fields are placed next to previous fields
- take advantage of this with a hint:
- If we are on the same row as the previous field and
- we are past it and the previous field was the last field
- in the row then simply add the field after the previous one.
- */
- {
- int rfldno, lfldno, prevfldno, temp;
- field_type field, prevfield, rfield, lfield;
-
- field = menu_GetField(menu, fieldno);
-
- if ((prevfldno = fieldno - 1) >= 0) {
- /* Get a handle to the previous field */
- prevfield = menu_GetField(menu, prevfldno);
- }
-
- if ((prevfldno >= 0) &&
- (row == field_GetRow(prevfield)) &&
- (col >= field_GetCol(prevfield)) &&
- (field_GetRight(prevfield) == -1) ) {
-
- /* place the field after the previous one */
- field_SetLeft(field, prevfldno);
- field_SetRight(field, -1);
- field_SetGCol(field, field_GetGCol(prevfield) + 1);
-
- /* adjust previous field */
- field_SetRight(prevfield, fieldno);
- }
-
- else if ((rfldno = ia_Get((menu)->fgrid, row)) == 0) {
- /* first field in its row */
- temp = fieldno + 1; /* So that ia_Put macro works correctly */
- if (!ja_Ok((menu)->fgrid) || !ia_Put((menu)->fgrid, row, temp)) {
- return(FALSE);
- }
- field_SetLeft(field, -1);
- field_SetRight(field, -1);
- }
- else {
- /* insert field in the row */
- rfldno--;
- lfldno = -1;
- while (rfldno >= 0) {
- if (field_GetCol( (rfield = menu_GetField(menu, rfldno)) ) > col) {
- field_SetLeft(field, lfldno);
- field_SetRight(field, rfldno);
- field_SetGCol(field, field_GetGCol(rfield));
-
- /* adjust the neighbors */
- field_SetLeft(rfield, fieldno);
-
- if (lfldno >= 0) {
- field_SetRight(menu_GetField(menu, lfldno), fieldno);
- }
- else {
- /* adjust the grid array */
- temp = fieldno + 1; /* So that ia_Put macro works correctly */
- if (!ja_Ok((menu)->fgrid) || !ia_Put((menu)->fgrid, row, temp)) {
- return(FALSE);
- }
- }
- break;
- }
-
- lfldno = rfldno;
- rfldno = field_GetRight(rfield);
- }
- if (rfldno >= 0) {
- /* adjust the gcols for the rest of the line */
- while (rfldno >= 0) {
- field_IncGCol( rfield = menu_GetField(menu, rfldno) );
- rfldno = field_GetRight(rfield);
- }
- }
- else {
- /* Add field at the end of the line */
- field_SetLeft(field, lfldno);
- field_SetRight(field, -1);
- field_SetGCol(field, field_GetGCol(lfield = menu_GetField(menu, lfldno)) + 1);
-
- /* adjust previous field */
- field_SetRight(lfield, fieldno);
- }
- }
-
- field_SetRow(field, row);
- field_SetCol(field, col);
-
- if (row >= menu->frowcount) {
- menu->frowcount = row + 1;
- }
-
- return(TRUE);
- }
-