PalmWidgetsTest.borg

PalmWidgetsTest.borg


{
    load("examples/Libraries/PalmWidgets.borg");
    
    WINDOW_1::101;
    WINDOW_2::102;
    WINDOW_3::103;
    BUTTON_W1_1::201;
    BUTTON_W1_2::202;
    BUTTON_W2_1::203;
    BUTTON_W2_2::204;
    BUTTON_W3_1::205;
    BUTTON_W3_2::206;
    FIELD_W1::301;
    FIELD_W2::302;
    FIELD_W3::303;
    PBUTTON_W3_1::401;
    PBUTTON_W3_2::402;
    PBUTTON_W3_3::403;
    CHECKBOX_W3_1::501;
    CHECKBOX_W3_2::502;
    CHECKBOX_W3_3::503;
    RPTBUTTON_W3_1::601;
    MENUITEM_W2_1::701;
    MENUITEM_W2_2::702;
    MENUITEM_W2_3::703;
        
    nrWindowsActive:2;
    field_w3_hidden:0;

    stupidQuestions()::
    {
        if (showDialog(0, "Are you sure you want to quit? Very sure?") = 0, {
            if (showDialog(1, "Are you sure that you are sure?") = 0, {
                if (showDialog(2, "You are about to quit! You know that I hope?") = 0,
                    showDialog(3, "OK OK, go away then!"),
                    display("Not fair, I wanted to show something",eoln))
            }, display("Boehoe, now you didn't see all options :",eoln))
        })
    };
    
    CleanUP()::
    {
        display(eoln,"Destrooy",eoln);    
        stupidQuestions();
        uiCleanUp()
    };
    
    button_fun(id)::
    {
        if (id = BUTTON_W1_1, {
            text: fieldGetText(FIELD_W1);
            windowSetTitle(WINDOW_1, text)
        }, if (id = BUTTON_W1_2, {
            freeWindow(WINDOW_1);
            nrWindowsActive := nrWindowsActive-1;
            if (nrWindowsActive = 0, CleanUP())
        }, if (id = BUTTON_W2_1, {
            text: fieldGetText(FIELD_W2);
            windowSetTitle(WINDOW_2, text)
        }, if (id = BUTTON_W2_2, {
            freeWindow(WINDOW_2);
            nrWindowsActive := nrWindowsActive-1;
            if (nrWindowsActive = 0, CleanUP())
        }, if (id = BUTTON_W3_2, {
            widgetRemove(FIELD_W3);
            widgetRemove(PBUTTON_W3_3)
        })))))
    };
    
    rptbutton_fun(id)::
    {
        display("The id of the repeat button is: ", id, eoln);
        display("The states of the other buttons are: [");
        display(pushButtonGetValue(PBUTTON_W3_1),"--");
        display(checkBoxGetValue(CHECKBOX_W3_1),"]",eoln)
    };

    lefttoright_fun(id)::
    {
        display("Moving the values from left to right :",eoln);
        pushButtonSetValue(PBUTTON_W3_2, pushButtonGetValue(PBUTTON_W3_1));
        checkBoxSetValue(CHECKBOX_W3_2, checkBoxGetValue(CHECKBOX_W3_1))
    };
    
    checkbox_fun(id)::
    {
        display("Check!",eoln);
        if (id = CHECKBOX_W3_3,
            display("Still doing nothing!", eoln))
    };

    togglebutton_fun(id)::
    {
        display("Toggle [", id, "]",eoln);
        if (id = PBUTTON_W3_3,
            if (field_w3_hidden = 0, {
                widgetHide(FIELD_W3);
                field_w3_hidden := 1
            }, {
                widgetShow(FIELD_W3);
                field_w3_hidden := 0
            }))
    };
    
    menuitem_fun(id)::
    {
        display("Somebody selected something in the menu [", id, "]", eoln);
        if (id = MENUITEM_W2_2,
            menuHideItem(MENUITEM_W2_2),
            if (id = MENUITEM_W2_3,
                menuShowItem(MENUITEM_W2_2)))
    };

    showDialog(0,"Let the tests begin!!!");

    ` First window    
    newWindow(WINDOW_1, "Dit is een title");
    
    newButton(BUTTON_W1_1, "Set as window title!", 60, 10, "button_fun");
    widgetPlace(BUTTON_W1_1, 5, 145);
    newButton(BUTTON_W1_2, "Quit Demo!", 40, 10, "button_fun");
    widgetPlace(BUTTON_W1_2, 115, 145);
    newField(FIELD_W1, "grr", 150, 125, 999, 1, 0, 0, 0, 0, 0);
    widgetPlace(FIELD_W1, 5, 15);
    
    showWindow(WINDOW_1);
    
    ` Second window
    newWindow(WINDOW_2, "Dit is een title van venster2");

    menuAddItem(MENUITEM_W2_1, 0, "Testje", "c", "menuitem_fun");
    menuAddItem(MENUITEM_W2_2, MENUITEM_W2_1, "Hide me", "h", "menuitem_fun");
    menuAddItem(MENUITEM_W2_3, MENUITEM_W2_2, "Show Previous", "p", "menuitem_fun");
    newButton(BUTTON_W2_1, "Set as window title!", 60, 10, "button_fun");
    widgetPlace(BUTTON_W2_1, 5, 145);
    newButton(BUTTON_W2_2, "Quit Demo!", 40, 10, "button_fun");
    widgetPlace(BUTTON_W2_2, 115, 145);
    newField(FIELD_W2, "grr", 150, 125, 999, 1, 0, 0, 0, 0, 0);
    widgetPlace(FIELD_W2, 5, 15);
    
    showWindow(WINDOW_2);

    ` Third window
    newWindow(WINDOW_3, "Dit is de derde");

    newPushButton(PBUTTON_W3_1, "Push me", 40, 10, "togglebutton_fun");
    newCheckBox(CHECKBOX_W3_1, "Sex??", 40, 10, "checkbox_fun");
    newRepeatButton(RPTBUTTON_W3_1, "Print Values", 40,10, "rptbutton_fun", "rptbutton_fun");
    newButton(BUTTON_W3_1, "values left -> right", 50, 10, "lefttoright_fun");
    newPushButton(PBUTTON_W3_2, "Stop pushing me", 45, 10, "togglebutton_fun");
    newCheckBox(CHECKBOX_W3_2, "Sex??", 45, 10, "checkbox_fun");
    newPushButton(PBUTTON_W3_3, "hide something", 45, 10, "togglebutton_fun");
    newField(FIELD_W3, "This will be hidden (I hope)", 150, 10, 80, 0, 0, 1, 0, 0, 0);
    newButton(BUTTON_W3_2, "kill hide stuff", 45, 10, "button_fun");
    newCheckBox(CHECKBOX_W3_3, "", 10, 10, "checkbox_fun");
    
    widgetPlace(PBUTTON_W3_1, 5, 25);
    widgetPlace(CHECKBOX_W3_1, 5, 40);
    widgetPlace(RPTBUTTON_W3_1, 55, 25);
    widgetPlace(BUTTON_W3_1, 50, 40);
    widgetPlace(PBUTTON_W3_2, 105, 25);
    widgetPlace(CHECKBOX_W3_2, 105, 40);
    widgetPlace(PBUTTON_W3_3, 5, 70);
    widgetPlace(FIELD_W3, 5, 85);
    widgetPlace(BUTTON_W3_2, 5, 105);
    widgetPlace(CHECKBOX_W3_3, 5, 120);
    
    showWindow(WINDOW_3);
        
    display("Linux KCBorg WidgetAPI test (I hope).",eoln)
}