C Language Development Kit/Snippets/Menu/ShowTextSelectionMenu

From OptiWiki

Jump to: navigation, search
Description Show a text style selection menu that sizes the layout depending on the terminal type and the fontsize.
void ShowTextSelectionMenu( int *nIndex, const char *txtHeader, sSelMenu *menuSelItems, int nMax, int nOptions, long *lValue );
int *nIndex

Holds the index number of the currently selected menu item.

const char *txtHeader

Contains the text of the header above the menu. sSelMenu *menuItems
menuItems is a pointer to a structure that holds information about a menu item that is displayed in the menu. Besides the line of text of the menu item, this structure also contains the value that is returned when this menu item is selected.

typedef struct
    char text;     // the displayed line of text of the menu item
    long *value;   // value that is placed in ulValue parameter of the
                   // ShowTextSelectionMenu() function
int nMax

The number of menuItems that need to be displayed.

int nOptions

The nOptions parameter can be one or an orred combination of these values.

MENU_FIXED scrolling is possible from menu item 1 to nMax and from nMax to 1.
MENU_LOOP Scrolling will loop when reaching beyond nMax to item 1 and vice versa.
MENU_MULTIPLE Multiple items can be selected see the '*' mark behind the menu number.
MENU_RET_SINGLE Setting this option in will result direct returning from the menu when an item is selected.

The MENU_MULTIPLE and the MENU_RET_SINGLE can not be used together.

long *lValue

The lValue holds the return value. The return value depends on the nOptions parameter. When MENU_MULTIPLE is filled into the nOption parameter the value items of the sSelMenu are XOR'ed. If MENU_MULTIPLE isn't used, then the value item of the seletected menu item is copied into lValue parameter.

Returns None.
Remarks Filling the txtHeader with and empty string (NULL) will result that an additional menu line will become available.

For terminals that have no CLR_KEY filling the menuItems[].value with -1 will return (exit) from the ShowTextSelectionMenu() function. When in the nOptions item the MENU_FIXED and MENU_LOOP are OR(red) the MENU_LOOP wil be used by the ShowTextSelectionMenu() function. The MENU_MULTIPLE and MENU_RET_SINGLE must not be used together. Important note when using the PHLxxxx:
Do not declare constant strings directly inside a structure, because the Microtec compiler will place such constant strings in RAM-memory instead of in ROM-memory. This means the string data will be lost as soon as the battery is empty or removed. Therefore DO NOT declare strings inside a constant structure like in the following example:

const sSelMenu mnuSetFont[] = {
    (char*)"String 1", 1,    // This implementation causes "String 1" to be
    (char*)"String 2", 2     // placed in RAM-memory by the Microtec compiler
};                           // (no matter what cast you use)!

Use the following implementation instead:

const char mnuTextStr1[] = "String 1";
const char mnuTextStr2[] = "String 2";
const sSelMenu mnuSetFont[] = {
    (char*)mnuTextStr1, 1,    // This implementation causes "String 1" to be placed
    (char*)mnuTextStr2, 2     // in ROM-memory by the Microtec compiler,
};                            // so it can't be lost
#include <stdio.h>
#include <stdlib.h>
#include "lib.h"
#include "menu.h"     //Holds the menu functions
#include "input.h"    //Holds the input functions
const char textMultipleA[] = "Barcode A type sample";
const char textMultipleB[] = "Barcode B type sample";
const char textMultipleC[] = "Barcode C type sample";
const char textMultipleD[] = "Barcode D type sample";
const char textMultipleE[] = "Barcode E type sample";
const char textMultipleF[] = "Barcode F type sample";
const char textMultipleG[] = "Barcode G type sample";
const char textMultipleH[] = "Barcode H type sample";
const char textMultipleI[] = "Barcode I type sample";
const char textMultipleJ[] = "Barcode J type sample";
const sSelMenu mnuSelMultiple[] = {
    (char*)textMultipleA, 0x0001,
    (char*)textMultipleB, 0x0002,
    (char*)textMultipleC, 0x0004,
    (char*)textMultipleD, 0x0008,
    (char*)textMultipleE, 0x0010,
    (char*)textMultipleF, 0x0020,
    (char*)textMultipleG, 0x0040,
    (char*)textMultipleH, 0x0080,
    (char*)textMultipleI, 0x0100,
    (char*)textMultipleJ, 0x0200
const char textSingleA[] = "Choice A type";
const char textSingleB[] = "Choice B type";
const char textSingleC[] = "Choice C type";
const char textSingleD[] = "Choice D type";
const char textSingleE[] = "Choice E type";
const char textSingleF[] = "Choice F type";
const char textSingleG[] = "Choice G type";
const char textSingleH[] = "Choice H type";
const char textSingleI[] = "Choice I type";
const char textSingleJ[] = "Choice J type";
const sSelMenu mnuSelSingle[] = {
    (char*)textSingleA, 1,
    (char*)textSingleB, 2,
    (char*)textSingleC, 3,
    (char*)textSingleD, 4,
    (char*)textSingleE, 5,
    (char*)textSingleF, 6,
    (char*)textSingleG, 7,
    (char*)textSingleH, 8,
    (char*)textSingleI, 9,
    (char*)textSingleJ, 10
void main( void )
    int i;
    int nIndex = 0;
    long lSelValues;
        nIndex = 0;
        lSelValues = 1L; // the first item will be selected
        ShowTextSelectionMenu( &nIndex,
                                "Multiple Selection header",
                                sizeof( mnuSelMultiple ) / sizeof( sSelMenu ),
                                MENU_FIXED | MENU_MULTIPLE,
                                &lSelValues );
        if( lSelValues != 0L )
            for(i=0; i<(mnuSelMultiple, sizeof(mnuSelMultiple)/sizeof(sSelMenu)); ++i)
                if( mnuSelMultiple[i].value & lSelValues )
                    printf("\f%s\nis selected\npress a key", mnuSelMultiple[i].text );
            printf("No items selected\nPress a key");
        nIndex = 0;
        lSelValues = 1L; // the first item will be selected
        ShowTextSelectionMenu( &nIndex,
                               "Single Selection header",
                               sizeof( mnuSelSingle ) / sizeof( sSelMenu ),
                               &lSelValues );
        printf("\f%s\nis selected\npress a key", mnuSelSingle[ulSelValues-1].text );

Personal tools