home *** CD-ROM | disk | FTP | other *** search
- /*
- fnradio.c
-
- by mla 2/14/90 (ripped off most of it from check_funcs)
-
- % radio_funcs
-
- Car radio style check marked field functions
- for creating single choice lists
-
- All fields of the same name are considered a radio group.
- Only one selection per group is allowed.
-
- To have radio_funcs simulate real radio buttons (ie one field must be
- chosen and only one field may be chosen), the programmer must initialize
- all variables in the group to FALSE except one (the default choice)
- which must be initialized to TRUE. The #define ALWAYS_ONE line should
- be removed if the user is to be permited to choose none of the fields.
-
- The field variable should be a boolean *.
- The record should contain a writable position for the check mark.
-
- C-scape 3.2
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 2/15/90 jmd made space bar work
- 3/28/90 jmd ansi-fied
- 10/04/90 pmcm removed isprint from search
- 10/25/90 pmcm added null field name check in for search loop
- */
-
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
-
- #include "cscape.h"
- #include "fnfunc.h" /* for field functions */
- #include "scancode.h"
-
- /* remove this line if no choice is an option */
- #define ALWAYS_ONE
-
- #ifdef OAK_DOS
- # define CHECK_MARK "\xfb"
- #endif
-
- #ifdef OAK_OS2
- # define CHECK_MARK "\xfb"
- #endif
-
- #ifndef CHECK_MARK
- # define CHECK_MARK "*"
- #endif
-
- OGLOBAL field_funcs_struct radio_funcs = {
- stdNoCur_fenter,
- std_fexit,
- radio_fkey,
- check_senter,
- check_sexit,
- sizeof(boolean)
- };
-
- void radio_fkey(sed_type sed)
- /*
- Up and down keys move cursor.
- letters search for choices.
- space bar toggles choice selection.
- Baton contains field number + 1 when ENTER is pressed
- or 0 if ESC pressed.
- */
- {
- int scancode, letter, choice, i;
- char *group;
- char *fieldname;
-
- scancode = kb_Read();
-
- if (sed_DoSpecial(sed, scancode))
- return;
- if (special_key(sed, scancode))
- return;
-
- if (scancode == ENTER) { /* intercept inter_field() */
- sed_SetBaton(sed, sed_GetFieldNo(sed) + 1);
- sed_ToggleExit(sed);
- return;
- }
-
- if (inter_field(sed, scancode))
- return;
- if (inter_page(sed, scancode))
- return;
-
- /* make space equivalent to mouse click */
- if (ascii(scancode) == ' ') {
- scancode = MOU_CLICK;
- }
-
- switch(scancode) {
- case HOME:
- sed_GotoFirstField(sed);
- break;
- case END:
- sed_GotoLastField(sed);
- break;
- case ' ':
- case MOU_CLICK:
- group = sed_GetFieldName(sed, sed_GetFieldNo(sed));
- if (group != NULL) {
- if (*sed_GetCurrRecord(sed) == '\0') { /* curr field unchecked */
- for (i = sed_GetFieldCount(sed); i-- > 0; ) {
-
- if ((fieldname = sed_GetFieldName(sed, i)) != NULL &&
- !strcmp(fieldname, group)) {
-
- if (i == sed_GetFieldNo(sed)) {
- sed_SetRecord(sed, CHECK_MARK, i); /* check it */
- }
- else {
- sed_SetRecord(sed, "", i); /* uncheck the rest */
- }
- sed_UpdateField(sed, i);
- }
- }
- }
- else { /* curr field checked */
- for (i = sed_GetFieldCount(sed); i-- > 0; ) {
- if ((fieldname = sed_GetFieldName(sed, i)) != NULL &&
- !strcmp(fieldname, group)) {
- #ifdef ALWAYS_ONE /* do we want to uncheck it? */
- if (i != sed_GetFieldNo(sed)) {
- #endif /* uncheck the rest anyway */
- sed_SetRecord(sed, "", i);
- #ifdef ALWAYS_ONE
- }
- #endif
- sed_UpdateField(sed, i);
- }
- }
- }
- break;
- }
- default:
- /* do first letter search */
- letter = ascii(scancode);
- if ((choice = sed_SearchMerge(sed, (char)letter)) != -1) {
- sed_GotoField(sed, choice);
- }
-
- /* reset baton */
- sed_SetBaton(sed, -1);
- }
- }
-