askm_special()

Purpose

Waits in a map field

Old names

#define select(mapnr,fieldnr)
askm_special(mapnr,fieldnr,scrn_flags,0)
#define wait_map askm_special

Syntax

int askm_special(mapnr, fieldnr, flags, mnem_map)

Parameters

int mapnr

Number of owning map

 

int* fieldnr

Pointer to field to wait in

 

int flags

Parameter specifying display format

 

int mnem_map

Number of a map which is usually displayed on the screen with mnemonic letters

 

The parameter flags can take any of the following values:

 

Value

Meaning

 

FUNC_KEYS

Allows the use of the function and number keys to select an option

 

NR_KEYS

Allows the number keys to select an option

 

CURS_KEYS

Causes the <Ins>, <Del>, <Pg Up> and <Pg Dn> keys to select the currently highlighted option, and return with the global variable abort_code set to the appropriate value

 

NO_WRAP

This makes the function askm_special() return with the value of the key pressed if the user tries to move outside the choice array

Description

The askm_special() function highlights a field and waits for the user to press a key. It is often used to allow the user to select an option from a menu which has already been displayed. This menu is passed as the parameter mnem_map. If the menu is not being used, the parameter mnem_map should be set to 0.

If a mnemonic letter is pressed, the function askm_special() returns the value of the global variable abort_code, which is set to the number of the field whose mnemonic letter was pressed.

The parameter fieldnr is set to where the next input should be. If a mnemonic key is pressed, fieldnr does not change at all, and the function inpm_omit() should be called if the field is part of a data entry function.

If the global variable realpass is FALSE, the function always returns RIGHT. This occurs when the function map_get_inputs() is called with the parameter flag set to the value PREDISPLAY, or the function map_predisplay() is called.

The function askm_special() is unlike the function inpm_e() because it does not check that the number chosen corresponds to a field on the menu.

Return values

Returns the value of the global variable abort_code. If a mnemonic letter is pressed, it returns the corresponding field number

See also

inpm_e()

Example

/*
C Functions Reference Manual
----------------------------
Filename: ASKM_SPE.C
Example: askm_special
Purpose: Simple data entry for new employees using
a menu to get the grade
*/

/*
#db salesord
#c
#tables employee;
#end
*/

#include "dp4.h"
#include "askm_spe.h"
/* generate this file by running LIBMAKE */

/* prototypes */
void get_new_emp(void);
void init_new_emp(void);
void emp_inner(int,int*);
int pick_field(int,int*,int,int);
void process()
{
trm_read_user(); /* only required if using
Microsoft C: a bug in the
linker causes an unresolved
external error in the DP4
library */
map_datamap(1);
get_new_emp();
}
/**/
void get_new_emp()
{
/* initialise the new fields */
init_new_emp();
if (!map_get_inputs(2, 1, emp_inner, GI_GLOBALS))
/* Note: in 4.42x, the flag ASK_CONFIRM should be
passed to this function. In 4.500, Save/Cancel
buttons should be added to the map */
rec_post_commit(&employee.l);
}
/**/

void init_new_emp()
/* initialise fields for a new customer */
{
/* get last customer and add 1 */
rec_fetch_main(LAST, &employee.l);
employee.employee_number++;
employee.gender[0] = 'M';
memset(&employee.date_of_birth,0,
sizeof(employee.date_of_birth));
employee.grade[0] = 'W'; WIPE(employee.name);
}
/**/
void emp_inner(m, f)
int m; int* f;
{
int field_nr = *f;
switch (field_nr)
{
case 1:
inpm_c(employee.name);
break;
case 2: /* show it only */
show_h(m, 2, employee.employee_number);
inpm_omit();
break;
case 3:
{
int option = employee.gender[0]=='M' ? 1 : 2;
option = pick_field(m, f, 6, option);#
if (!abort_code)
employee.gender[0] = (option == 1) ?
(char) 'M': (char) 'F';
}
break;
case 5:
inpm_d(&employee.date_of_birth);
break;
case 6: /* region code choose from a menu */
{
static char grades[4] = {'D','M','C','W'};
int option = 4, i;
for (i = 0; i < 3; i++)
if (grades[i] == employee.grade[0])
option = i + 1;
option = pick_field(m, f, 10, option);
if (!abort_code)
employee.grade[0] = grades[option - 1];
}
break;
default:
inpm_omit();
break;
}
}
/**/
int pick_field(m, f, m1, option)
int m; int* f; int m1; int option;
{
int field_nr = *f;
int old_option = option;
if (realpass)
{
field_blank(m, field_nr + 1);
show_over(m, field_nr + 1, m1 + option);
map_menu(m1);
askm_special(m, f, NR_KEYS|CURS_KEYS, m1);
/* if space bar enter the menu or the field does not exist, highlight_field returns TRUE if the field does not exist */
if (abort_code == SPACE_BAR
|| (abort_code > 0 && !field_highlight(m1,
abort_code > 0 ? (option = abort_code) :
option)))
{
if (field_choose(m1, &option, DEFAULT))
{
*f = field_nr;
jump = FALSE;
map_clear_from(m1);
abort_code = 0;
return old_option;
}
}
else
if (abort_code > 0) /* mnemonic key pressed */
{
option = abort_code;
inpm_omit();
}
map_clear_from(m1);
}
else
inpm_omit();
if (abort_code != ESCAPE)
{
field_blank(m, field_nr + 1);
show_over(m, field_nr + 1, m1 + option);
abort_code = 0;
}
else
{
jump = FALSE;
*f = field_nr;
}
return option;
}
/**/