map_g_choose()

Purpose

Chooses an option from a menu with greying out

Old name

#define gm_choose map_g_choose

Syntax

int map_g_choose(mapnr, option, banned_list)

Parameters

int mapnr

Map number to choose from

 

int* option

Pointer to variable to hold chosen field

 

short* banned_list

Pointer to an array of integers, terminating with zero, containing the field numbers to grey out

 

The parameter banned_list should point to an array of short integers, terminating with a zero, which gives the list of fields to be greyed out.

Description

The map_g_choose() function is similar to map_choose(). It allows the user to choose an option from a menu and, in addition, options can be greyed out to make them inaccessible to the user.

If there are no fields to grey out, a pointer to a zero value should be passed. Never pass NULL as a value for the parameter banned_list.

If all the fields have been greyed out, ESCAPE is returned without any user interaction.

The initial value of the parameter option gives the field to be highlighted first of all. If it is greyed out, the next valid field will be used.

This function restores the original value of the global variable range on exiting. It is implemented using the field_eg_choose() function, with the parameter flags set to the value (NR_KEYS | NOT_MISSING_FIELD).

Return values

Returns the value of the global variable abort_code

See also

map_choose()

Example

/*
C Functions Reference Manual
----------------------------
Filename: MAP_G_CH.C
Example: map_g_choose
Purpose: Allows options to be selected from a menu
using map_g_choose. The program also
illustrates 'greying out' of menu options
by supplying a list of banned options to
map_g_choose.
*/

/*#db salesord
#c
#end
*/
#include "dp4.h"
#include "map_g_ch.h"
/* generate this file by running LIBMAKE */
/* prototypes */
static short DP4P banned_list(void);
static void call_menu_fn(int*);
static void customers(void);
static void new_prospects(void);

void process()
{
int option = 1; /* header map */
map_draw(1,RETAIN);
while (!map_g_choose(2,&option,banned_list()))
{
call_menu_fn(&option);
}
}

static void call_menu_fn(int* option)
/* call associated menu option function */
{
switch (*option)
{
case 1:
break;
case 2:
customers();
break;
case 3:
break;
case 4:
new_prospects();
break;
case 5:
break;
default:
break;
}
}

static short DP4P banned_list()
/* get banned fields for menu */
{
static int ban[6];
/* let's ban 1 3 and 5 */
ban[0] = 1;
ban[1] = 3;
ban[2] = 5;
/* must end with a zero */
ban[3] = 0;
return ban;
}

/* support functions - just display a map*/
void customers()
{
map_pause(50);
}

void new_prospects()
{
map_pause(51);
}