/*
	Copyright (c) 2024 PTC Inc. and/or Its Subsidiary Companies. All Rights Reserved.
*/



/*---------------------- Pro/Toolkit Includes ------------------------*/
#include <ProToolkit.h>
#include <ProMenu.h>

/*---------------------- Function Prototypes -------------------------*/
ProError ProUserBitToggle();
char ProUserBitsChange(char);


/*------------------------------------------------------------*\
    Define names for the bit values
\*------------------------------------------------------------*/
#define	EX10_BIT0	1<<0
#define	EX10_BIT1	1<<1
#define	EX10_BIT2	1<<2
#define	EX10_BIT3	1<<3

/*------------------------------------------------------------*\
    Button-action function to toggle the specified bit in the
    specified bit map
\*------------------------------------------------------------*/
ProError ProUserBitToggle(char *bitmap, int bit)
{
    *bitmap ^= (char)bit;
    return ( PRO_TK_NO_ERROR );
}

/*------------------------------------------------------------*\
    Function to get the user to toggle any of the first four bits
    in the input bit map. Returns the modified bit map.
\*------------------------------------------------------------*/
char ProUserBitsChange(char bits)
{
    int menuId;
    int action;

/*------------------------------------------------------------*\
    Set up the "Bit Values" menu 
\*------------------------------------------------------------*/
    ProMenuFileRegister("bit_values","bit_values.mnu", &menuId);
    ProMenubuttonActionSet("bit_values", "Bit 0",
		 (ProMenubuttonAction)ProUserBitToggle, &bits, EX10_BIT0);
    ProMenubuttonActionSet("bit_values", "Bit 1",
		 (ProMenubuttonAction)ProUserBitToggle, &bits, EX10_BIT1);
    ProMenubuttonActionSet("bit_values", "Bit 2",
		(ProMenubuttonAction)ProUserBitToggle, &bits, EX10_BIT2);
    ProMenubuttonActionSet("bit_values", "Bit 3",
		(ProMenubuttonAction)ProUserBitToggle, &bits, EX10_BIT3);
    ProMenubuttonActionSet("bit_values", "Accept",
		(ProMenubuttonAction)ProMenuDelete, NULL,  0);
    ProMenubuttonActionSet("bit_values", "bit_values",
		(ProMenubuttonAction)ProMenuHold, NULL,  0);

/*------------------------------------------------------------*\
    Make the menu a data menu (with check marks), so that we
    can have several buttons set.
\*------------------------------------------------------------*/
    ProMenuModeSet("bit_values", PROMENUMODE_DATA);
    ProMenuDatamodeSet("bit_values", 1);

/*------------------------------------------------------------*\
    Display the menu
\*------------------------------------------------------------*/
    ProMenuCreate(PROMENUTYPE_MAIN, "bit_values", &menuId);

/*------------------------------------------------------------*\
    Make the button settings show the current bit map values
\*------------------------------------------------------------*/
if(bits & EX10_BIT0)
    ProMenubuttonHighlight("bit_values","Bit 0");
if(bits & EX10_BIT1)
    ProMenubuttonHighlight("bit_values","Bit 1");
if(bits & EX10_BIT2)
    ProMenubuttonHighlight("bit_values","Bit 2");
if(bits & EX10_BIT3)
    ProMenubuttonHighlight("bit_values","Bit 3");

/*------------------------------------------------------------*\
    Make the menu active
\*------------------------------------------------------------*/
    ProMenuProcess("", &action);

    return((char)bits);
}