' menu_context.pb — Context menu (right-click) simulation
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL ctxIDs(50) AS LONG
    LOCAL ctxEnabled(50) AS LONG
    LOCAL ctxSeparator(50) AS LONG
    LOCAL ctxCount AS LONG
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL contextObj AS LONG
    LOCAL selectedID AS LONG
    LOCAL clickX AS LONG
    LOCAL clickY AS LONG
    LOCAL region AS LONG
    LOCAL totalSelections AS LONG
    LOCAL result AS LONG
    LOCAL maxItems AS LONG
    LOCAL idVal AS LONG
    LOCAL isEnabled AS LONG
    LOCAL isSep AS LONG
    LOCAL iter AS LONG
    LOCAL foundItem AS LONG

    maxItems = 15

    ctxIDs(0) = 300
    ctxEnabled(0) = 1
    ctxSeparator(0) = 0

    ctxIDs(1) = 301
    ctxEnabled(1) = 1
    ctxSeparator(1) = 0

    ctxIDs(2) = 302
    ctxEnabled(2) = 1
    ctxSeparator(2) = 0

    ctxIDs(3) = 0
    ctxEnabled(3) = 0
    ctxSeparator(3) = 1

    ctxIDs(4) = 303
    ctxEnabled(4) = 1
    ctxSeparator(4) = 0

    ctxIDs(5) = 304
    ctxEnabled(5) = 1
    ctxSeparator(5) = 0

    ctxIDs(6) = 0
    ctxEnabled(6) = 0
    ctxSeparator(6) = 1

    ctxIDs(7) = 305
    ctxEnabled(7) = 1
    ctxSeparator(7) = 0

    ctxCount = 8

    PRINT "=== Context Menu Simulator ==="
    PRINT "Items: " + STR$(ctxCount)

    FOR i = 0 TO ctxCount - 1
        isSep = ctxSeparator(i)
        isEnabled = ctxEnabled(i)
        idVal = ctxIDs(i)
        IF isSep = 1 THEN
            PRINT "  --------------------"
        ELSE
            IF isEnabled = 1 THEN
                IF idVal = 300 THEN
                    PRINT "  Cut (ID=" + STR$(idVal) + ")"
                END IF
                IF idVal = 301 THEN
                    PRINT "  Copy (ID=" + STR$(idVal) + ")"
                END IF
                IF idVal = 302 THEN
                    PRINT "  Paste (ID=" + STR$(idVal) + ")"
                END IF
                IF idVal = 303 THEN
                    PRINT "  Delete (ID=" + STR$(idVal) + ")"
                END IF
                IF idVal = 304 THEN
                    PRINT "  Rename (ID=" + STR$(idVal) + ")"
                END IF
                IF idVal = 305 THEN
                    PRINT "  Properties (ID=" + STR$(idVal) + ")"
                END IF
            ELSE
                IF idVal = 300 THEN
                    PRINT "  [disabled] Cut (ID=" + STR$(idVal) + ")"
                END IF
                IF idVal = 301 THEN
                    PRINT "  [disabled] Copy (ID=" + STR$(idVal) + ")"
                END IF
                IF idVal = 302 THEN
                    PRINT "  [disabled] Paste (ID=" + STR$(idVal) + ")"
                END IF
                IF idVal = 303 THEN
                    PRINT "  [disabled] Delete (ID=" + STR$(idVal) + ")"
                END IF
                IF idVal = 304 THEN
                    PRINT "  [disabled] Rename (ID=" + STR$(idVal) + ")"
                END IF
                IF idVal = 305 THEN
                    PRINT "  [disabled] Properties (ID=" + STR$(idVal) + ")"
                END IF
            END IF
        END IF
    NEXT i

    PRINT "Simulating right-click..."
    totalSelections = 0
    FOR iter = 1 TO 6
        clickX = iter * 30
        clickY = iter * 20

        IF clickX < 50 AND clickY < 50 THEN
            region = 0
        ELSE
            IF clickX < 100 AND clickY < 100 THEN
                region = 1
            ELSE
                region = 2
            END IF
        END IF

        IF region = 0 THEN
            contextObj = 1
        ELSE
            IF region = 1 THEN
                contextObj = 2
            ELSE
                contextObj = 3
            END IF
        END IF

        selectedID = 0
        FOR j = 0 TO ctxCount - 1
            isEnabled = ctxEnabled(j)
            isSep = ctxSeparator(j)
            idVal = ctxIDs(j)
            IF isEnabled = 1 AND isSep = 0 THEN
                IF selectedID = 0 THEN
                    selectedID = idVal
                END IF
            END IF
        NEXT j
        IF selectedID > 0 THEN
            totalSelections = totalSelections + 1
            PRINT "  Click at(" + STR$(clickX) + "," + STR$(clickY) + ") obj=" + STR$(contextObj) + " id=" + STR$(selectedID)
        END IF
    NEXT iter

    PRINT "Selections: " + STR$(totalSelections)
    PRINT "=== End Context Menu ==="
    FUNCTION = 0
END FUNCTION
