/******************************************************************************
 *
 *    Name: combo.c
 *
 *    $Id:$
 *
 *    Purpose: Example file for testing combo mulitCombo box support in the UI
 *             Dialog Library.
 *
 *    Copyright 2013 Citrix Systems, Inc. All rights reserved.
 *
 *****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "UIDialogLibCall.h"

int main(int argc, char *argv[])
{
    const char *result;
    char *icaroot;
    UIDIALOG *comboDialog;

    struct formsElement heading =   {
                                        {L_Heading, "Select options", NULL},
                                        {
                                            I_None,
                                            NULL,
                                            FALSE,
                                            {{ 0 }}}
                                    };

    struct formsElement combo =     {
                                        {L_Plain, "combo", NULL},
                                        {
                                            I_ComboBox,
                                            "Take your pick",
                                            TRUE,
                                            {{ 0 }}
                                        }
                                    };

    struct formsElement multicombo =    {
                                            {L_Plain, "multiCombo", NULL},
                                            {
                                                I_MultiComboBox,
                                                "Take your pick",
                                                TRUE,
                                                {{ 0 }}
                                            }
                                        };


    struct formsElement ok =        {
                                        {L_Plain, NULL, NULL},
                                        {
                                            I_Button,
                                            NULL,
                                            FALSE,
                                            {
                                                .button = {"okId", "OK", NULL}
                                            }
                                        }
                                    };

    struct selection opt1 = {"0", "option 1", NULL, FALSE};
    struct selection opt2 = {"1", "option 2", NULL, TRUE};
    struct selection opt3 = {"2", "option 3", NULL, FALSE};

    struct selection multiopt1 = {"0", "option 1", NULL, FALSE};
    struct selection multiopt2 = {"1", "option 2", NULL, TRUE};
    struct selection multiopt3 = {"2", "option 3", NULL, TRUE};

    struct formsElement *form[] = {&heading, &combo, &multicombo, &ok, NULL};
    struct selection *poptions[] = {&opt1, &opt2, &opt3, NULL};
    struct selection *pmultioptions[] = {&multiopt1, &multiopt2, &multiopt3, NULL};

    combo.input.inputUnion.comboBox = poptions;
    multicombo.input.inputUnion.comboBox = pmultioptions;

    /* Setup ICAROOT. */
    icaroot = getenv("ICAROOT");

    if (icaroot == NULL)
        icaroot = "/opt/Citrix/ICAClient";

    /* Load the UI Dialog Library. */ 
    UIDialogLibLoad(icaroot);    

    /* Initialise the UI Dialog Library */
    UI_DIALOG_INIT(icaroot);
    UI_DIALOG_LOOP_INIT(&argc, &argv);

    comboDialog = UI_DIALOG_ALLOCATE();

    /* Display the Selection Dialog. */
    result = UI_DIALOG_DISPLAY(comboDialog, form, S_None, NULL, CITRIX_BRANDNAME,
                             "okId", 0, NULL);

    /* Close the dialog. */
    UI_DIALOG_CLOSE(comboDialog);


    free(comboDialog);

    printf("Received the following id=%s\n", result);
    return 0;
}
