' menu_toolbar.pb — Toolbar button simulation
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL btnIDs(50) AS LONG
    LOCAL btnStates(50) AS LONG
    LOCAL btnCount AS LONG
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL clickID AS LONG
    LOCAL pressedBtn AS LONG
    LOCAL result AS LONG
    LOCAL totalClicks AS LONG
    LOCAL enabledCount AS LONG
    LOCAL disabledCount AS LONG
    LOCAL maxButtons AS LONG
    LOCAL stateVal AS LONG
    LOCAL idVal AS LONG
    LOCAL iter AS LONG
    LOCAL found AS LONG

    maxButtons = 12

    btnIDs(0) = 200
    btnStates(0) = 1
    btnIDs(1) = 201
    btnStates(1) = 1
    btnIDs(2) = 202
    btnStates(2) = 1
    btnIDs(3) = 203
    btnStates(3) = 1
    btnIDs(4) = 204
    btnStates(4) = 1
    btnIDs(5) = 205
    btnStates(5) = 1
    btnIDs(6) = 206
    btnStates(6) = 1
    btnIDs(7) = 207
    btnStates(7) = 1
    btnIDs(8) = 208
    btnStates(8) = 1
    btnIDs(9) = 209
    btnStates(9) = 1
    btnIDs(10) = 210
    btnStates(10) = 1
    btnIDs(11) = 211
    btnStates(11) = 1
    btnCount = 12

    PRINT "=== Toolbar Manager ==="
    PRINT "Buttons: " + STR$(btnCount)

    FOR i = 0 TO btnCount - 1
        stateVal = btnStates(i)
        idVal = btnIDs(i)
        IF stateVal = 1 THEN
            IF idVal = 200 THEN
                PRINT "  [enabled] New (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 201 THEN
                PRINT "  [enabled] Open (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 202 THEN
                PRINT "  [enabled] Save (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 203 THEN
                PRINT "  [enabled] Print (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 204 THEN
                PRINT "  [enabled] Cut (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 205 THEN
                PRINT "  [enabled] Copy (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 206 THEN
                PRINT "  [enabled] Paste (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 207 THEN
                PRINT "  [enabled] Undo (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 208 THEN
                PRINT "  [enabled] Redo (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 209 THEN
                PRINT "  [enabled] Find (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 210 THEN
                PRINT "  [enabled] Help (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 211 THEN
                PRINT "  [enabled] Exit (ID=" + STR$(idVal) + ")"
            END IF
        END IF
        IF stateVal = 0 THEN
            IF idVal = 200 THEN
                PRINT "  [disabled] New (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 201 THEN
                PRINT "  [disabled] Open (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 202 THEN
                PRINT "  [disabled] Save (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 203 THEN
                PRINT "  [disabled] Print (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 204 THEN
                PRINT "  [disabled] Cut (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 205 THEN
                PRINT "  [disabled] Copy (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 206 THEN
                PRINT "  [disabled] Paste (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 207 THEN
                PRINT "  [disabled] Undo (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 208 THEN
                PRINT "  [disabled] Redo (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 209 THEN
                PRINT "  [disabled] Find (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 210 THEN
                PRINT "  [disabled] Help (ID=" + STR$(idVal) + ")"
            END IF
            IF idVal = 211 THEN
                PRINT "  [disabled] Exit (ID=" + STR$(idVal) + ")"
            END IF
        END IF
    NEXT i

    PRINT "Simulating button clicks..."
    totalClicks = 0
    FOR iter = 1 TO 8
        clickID = btnIDs(iter MOD btnCount)
        found = -1
        FOR j = 0 TO btnCount - 1
            IF btnIDs(j) = clickID THEN
                found = j
            END IF
        NEXT j
        IF found >= 0 THEN
            pressedBtn = found
        END IF
        IF btnStates(pressedBtn) = 1 THEN
            result = btnIDs(pressedBtn)
            totalClicks = totalClicks + 1
            PRINT "  Clicked ID " + STR$(result)
        ELSE
            PRINT "  Button " + STR$(btnIDs(pressedBtn)) + " disabled"
        END IF
    NEXT iter

    PRINT "Disabling Save and Cut..."
    btnStates(2) = 0
    btnStates(4) = 0

    enabledCount = 0
    disabledCount = 0
    FOR i = 0 TO btnCount - 1
        IF btnStates(i) = 1 THEN
            enabledCount = enabledCount + 1
        ELSE
            disabledCount = disabledCount + 1
        END IF
    NEXT i
    PRINT "Enabled: " + STR$(enabledCount) + " Disabled: " + STR$(disabledCount)
    PRINT "Total clicks: " + STR$(totalClicks)
    PRINT "=== End Toolbar ==="
    FUNCTION = 0
END FUNCTION
