pick_list()

Purpose

Picks an option from a fixed list of records

Old name

#define pick_optlist pick_list

Syntax

int pick_list(mapnr, extra_map, show_item,
item_count, choices, option_nr, flags,
ADDITIONAL)

Parameters

int mapnr

Number of display map

 

int extra_map

Number of extra map to display

 

void (show_item*)(int, int, int)

Pointer to function to call to display data

 

int item_count

Total number of items in list

 

int choices

Number of choices that can be displayed on the map

 

int* option_nr

Pointer to variable to hold the item number selected by the user

 

int flags

Parameter specifying display attributes and options

 

ADDITIONAL

Number of mnemonic map (required when parameter flags is set to ABORT_MNEMONICS)

 

The parameter flags can take the same values as for pick_record(), and the values have the same meaning except that: NO_DISP means the menu is on the screen, but the fields are redisplayed; NO_DISP+NO_READ means the menu is on the screen and the fields are correct.

Description

The function pick_list() is similar to the pick_record() function, but is used where the number of items in the list is known before the call is made.

This function differs from the function pick_record() in the following respects:

  • No user defined function for fetching records is required
  • No work area is required
  • No error map may be given. Only call the function when there are elements in the list

A user-defined function for displaying records is, however, required as with the function pick_record(). The display function is called by pick_list() to display each item in the appropriate way.

If the user selects a record the variable pointed to by the parameter option_nr is set to the selected field. Counting starts from 0. The initial value determined by the parameter option_nr indicates which field is highlighted when the map specified by the parameter choice is first displayed.

Return values

The return value indicates the key chosen, as follows:

 

Return Value

Key Pressed

 

0

If the <Enter> key is pressed

 

ESCAPE

If <Esc> is pressed

 

F<n>

Function key <n> is pressed (used when parameter flags includes the value ABORT_FUNC_KEYS)

 

PAGE UP

If there are no records

 

INSERT

If <Ins> is pressed, or <Enter> is pressed over the 'new record' message (used when parameter flags include the values ALLOW_NEW or ABORT_MNEMONICS)

 

DELETE

If <Del> is pressed (used when parameter flags includes the value ALLOW_DELETE)

 

The global variable abort_code is zero after a call to the function pick_list()

See also

pick_record()

Example

/*
C Functions Reference Manual
----------------------------
Filename: PICK_LIS.C
Example: pick_list
Purpose: Sample program on inserting order lines
for an order
*/

/*
#db salesord
#tables customer,
employee,
order_header,
order_line,
index_cust_name,
region;
#c
#end
*/

#include "dp4.h"
#include "pick_lis.h"
/* generate this file by running LIBMAKE */
#define MAX_LINES 8
#define MAX_ORD_LINES 200
#define PICK_LINE_MAP 3

static struct ORD_LINE
{
char mat_code[7];
int quantity;
double line_value;
} ord_line[200 + 1];

static int nr_lines = 1;
/* holds number of order lines + 1 for new line */
static int opt_line;
/* holds current line selected */
void edit_order(void);
void disp_total(void);
void del_line(void);
int pick_line(void);
void edit_line(int);
void line_inner(int,int*);
void process()
{
map_datamap(1);
trm_read_user();
/* only required if using Microsoft C: a bug in
the linker causes an unresolved external error
in the DP4 library */
/* put up imaginary order and customer */
map_datamap(2);
order_header.order_number = 1234L;
order_header.order_value = 0;
WIPE(customer.name);
memcpy(customer.name,"BROWN M",7);
customer.customer_number = 1234567L;
show_l(2,1,order_header.order_number);
show_c(2,2,"BROWN M");
show_n(2,3,order_header.order_value);
menu_flags = MENUMAP | RETAIN;
/* edit the order */
edit_order();
}

void edit_order()
{
/* put up mnemonic map */
menu(7);
for (;;)
{
switch (pick_line())
{
case ESCAPE:
case 5:
if (map_yes(8,FALSE))
return;
break;
case 0:
case 1: /* item selected */
if (pk_chosen_field != nr_lines)
{
edit_line(FALSE);
}
break;
case DELETE:
case 2:
if (pk_chosen_field != nr_lines)
{
if (map_yes(6,FALSE))
del_line();
}
break;
case INSERT:
case 3:
edit_line(TRUE);
break;
case 4: /* save option */
return;
default:
break;
}
disp_total();
}
}
void disp_total()
/* redisplay order value */
{
double total = 0.0;
register i = 0;
while (i < nr_lines - 1)
total += ord_line[i++].line_value;
show_n(2,3,order_header.order_value = total);
}

void show_line(m,field_nr,item)
int m, field_nr,item;
{
if (field_nr >= range)
{
show_over(m,field_nr,4);
}
else
{
map_attach(m,field_nr,5,DEFAULT);
show_c(5,1,ord_line[item].mat_code);
show_i(5,2,ord_line[item].quantity);
show_n(5,3,ord_line[item].line_value);
map_glue(m,5);
}
}

void del_line() /* delete line from the list */
{
movmem((char*)&ord_line[opt_line + 1],
(char*)&ord_line[opt_line],
(nr_lines - opt_line - 1) * sizeof(struct
ORD_LINE));
nr_lines--;
}
int pick_line() /* pickopt list */
{
return pick_list(PICK_LINE_MAP,0,show_line,
nr_lines,MAX_LINES, &opt_line,RETAIN|ALLOW_NEW|
ALLOW_DELETE|NEW_NORMAL|ABORT_MNEMONICS,7);
} /* this should be in a separate module */

static int new_item;
void edit_line(new_line)
int new_line;
{
map_attach(PICK_LINE_MAP,_option,5,DEFAULT);
new_item = new_line;
if (new_line) opt_line = nr_lines - 1;
if (!map_get_inputs(5,1,line_inner,NO_DISP|
(new_line ? 0: PREDISPLAY)))
{
if (new_line)
nr_lines++;
}
}

void line_inner(m,f)
int m; int* f;
{
int field_nr;
switch (field_nr = *f)
{
case 1: /* material code */
if (new_item)
inpm_u(ord_line[opt_line].mat_code);
else /* don't allow editing of this field */
{
show_c(m,field_nr,ord_line
[opt_line].mat_code);
inpm_omit();
}
/* should check and offer pickfill */
break;
case 2: /* quantity */
inpm_i(&ord_line[opt_line].quantity);
/* should now work out correct line value
there may be discounts etc. here just
multiply by 12 for effect. */
ord_line[opt_line].line_value = 12 *
ord_line[opt_line].quantity;
break;
case 3: /* display only */
show_n(m,field_nr,ord_line
[opt_line].line_value);
/* fall through to skip field */
default:
inpm_omit();
break;
}
}