home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
MENUSFLD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-09-11
|
2KB
|
91 lines
/*
menusfld.c 4/11/88
% menu_SwapFields
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
4/16/89 jmd adjusted for jarray macros
3/28/90 jmd ansi-fied
9/11/90 jdc added swap of name-to-fieldno references
*/
#include "menu.h"
void menu_SwapFields(menu_type menu, int fieldno_1, int fieldno_2)
/*
Swaps two fields in the field array.
*/
{
field_type field_1, field_2;
int rfld, lfld, row, temp, nameno;
/* test menu and field number */
cs_Assert(menu_Ok(menu), CS_M_SWF_MENU, 0); /* passed bad menu */
cs_Assert(fieldno_1 >= 0 && fieldno_1 < menu->fieldcount &&
fieldno_2 >= 0 && fieldno_2 < menu->fieldcount, CS_M_SWF_ARG, 0); /* passed bad args */
/* swap the references to the fields in their neighboring fields */
/* field 1 */
rfld = menu_GetFieldRight(menu, fieldno_1);
lfld = menu_GetFieldLeft(menu, fieldno_1);
if (lfld >= 0) {
menu_SetFieldRight(menu, lfld, fieldno_2);
}
else {
/* adjust row array entry */
row = menu_GetFieldRow(menu, fieldno_1);
temp = fieldno_2 + 1;
ia_Put((menu)->fgrid, row, temp);
}
if (rfld >= 0) {
menu_SetFieldLeft(menu, rfld, fieldno_2);
}
/* field 2 */
rfld = menu_GetFieldRight(menu, fieldno_2);
lfld = menu_GetFieldLeft(menu, fieldno_2);
if (lfld >= 0) {
menu_SetFieldRight(menu, lfld, fieldno_1);
}
else {
/* adjust row array entry */
row = menu_GetFieldRow(menu, fieldno_2);
temp = fieldno_1 + 1;
ia_Put((menu)->fgrid, row, temp);
}
if (rfld >= 0) {
menu_SetFieldLeft(menu, rfld, fieldno_1);
}
/* swap fields in field array */
field_1 = menu_GetField(menu, fieldno_1);
field_2 = menu_GetField(menu, fieldno_2);
xa_Put(menu->fa, fieldno_1, (VOID *) field_2);
xa_Put(menu->fa, fieldno_2, (VOID *) field_1);
/* swap name-to-field references */
if ((nameno = field_GetNameNo(field_1)) >= 0
&& *((int *)oslist_GetData(menu->namelist, nameno)) == fieldno_1) {
oslist_SetData(menu->namelist,
field_GetNameNo(field_1), (VOID*)&fieldno_2);
}
if ((nameno = field_GetNameNo(field_2)) >= 0
&& *((int *)oslist_GetData(menu->namelist, nameno)) == fieldno_2) {
oslist_SetData(menu->namelist,
field_GetNameNo(field_2), (VOID*)&fieldno_1);
}
}