home *** CD-ROM | disk | FTP | other *** search
- /*
- sdfindf.c
-
- % sed_FindField
-
- C-scape 3.2
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 12/14/88 jmd Added preferred direction, optimized
- 2/02/89 jdc fixed outside menu cases and added bob support
- 6/04/89 jdc added prot flag
- 7/02/89 jdc added frowcount change
- 3/03/90 ted/pmcm Added return(-2) in case of protected fields for mouse handlers.
- 3/28/90 jmd ansi-fied
- */
-
- #include "sed.h"
-
- int sd_findfield(sed_type sed, ocbox *boxp, int pref, int prot)
- /*
- Finds the first field in the given box. The box should be in menu coords.
- Returns (-1) if no field was found in the box.
-
- If 'prot' is TRUE will find protected fields also.
- If 'prot' is FALSE and only protected fields are in the box, returns -2.
-
- 'pref' is the preferred direction to search from.
- (OAK_UP, OAK_DOWN, OAK_LEFT, OAK_RIGHT)
- (UP means we are moving UP into the box, startsearching from the
- bottom, etc. )
- */
- {
- register int row, fldno;
- int firstrow, lastrow, rowstep, lastfld = -1;
- menu_type menu;
- field_type field;
-
- menu = sed_GetMenu(sed);
-
- if (pref == OAK_UP) {
- if ( (firstrow = int_min(boxp->botrow, menu->frowcount - 1)) <=
- (lastrow = boxp->toprow - 1) ) {
- return(-1);
- }
- rowstep = -1;
- }
- else {
- if ( (firstrow = boxp->toprow) >=
- (lastrow = int_min(boxp->botrow + 1, menu->frowcount)) ) {
- return(-1);
- }
- rowstep = 1;
- }
- for (row = firstrow; row != lastrow; row += rowstep) {
- /* now find the matching field in the row */
- fldno = menu_GetGRow(menu, row) - 1;
- while (fldno >= 0) {
-
- field = menu_GetField(menu, fldno);
-
- if (boxp->leftcol <= field_GetLastCol(field) &&
- boxp->rightcol >= field_GetCol(field)) {
- if (prot || !field_GetProtected(field)) {
- if (pref != OAK_LEFT) {
- return(fldno);
- }
- else {
- /* remember this field, see if the next one is good */
- lastfld = fldno;
- }
- }
- else {
- if (prot == FALSE) {
- lastfld = -2; /* Return -2 for a protected field */
- }
- }
- }
- if (field_GetCol(field) > boxp->rightcol) {
- /* we've gone past the end, break */
- break;
- }
-
- /* get the next field in the row */
- fldno = field_GetRight(field);
- }
- }
- return(lastfld);
- }
-