C Language Development Kit/Snippets/Menu/ShowGraphSelectionMenu

From OptiWiki

Jump to: navigation, search
Description Show a graphical style selection menu that sizes the layout depending on the terminal type.
Syntax
void ShowGraphSelectionMenu( sSelMenu *menuSelItems, int nMax, int nOptions, long *lValue );
Arguments
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
                   // ShowGraphSelectionMenu() function
 
}sSelMenu;
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_SINGLE Single selection menu. Only one item can be selected, cannot be orred with MENU_MULTIPLE.
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 selected menu item is copied into lValue parameter.
Returns None.
Remarks For terminals that have no CLR_KEY filling the menuItems[].value with -1 will return (exit) from the ShowGraphSelectionMenu() 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
Example
#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;
    long lSelValues;
 
    InitGraphMenu();
    for(;;)
    {
        lSelValues = 1L; // the first item will be selected
        ShowGraphSelectionMenu( (sSelMenu*)mnuSelMultiple,
                                sizeof( mnuSelMultiple ) / sizeof( sSelMenu ),
                                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 );
                    WaitForKey();
                }
            }
        }
        else
        {
            printf("No items selected\nPress a key");
            WaitForKey();
        }
 
        lSelValues = 1L; // the first item will be selected
        ShowGraphSelectionMenu( (sSelMenu*)mnuSelSingle,
                               sizeof( mnuSelSingle ) / sizeof( sSelMenu ),
                               MENU_SINGLE|MENU_RET_SEL,
                               &lSelValues );
 
        printf("\f%s\nis selected\npress a key", mnuSelSingle[ulSelValues-1].text );
        WaitForKey();
    }
}


Views
Personal tools