' Menu editor: build, preview, modify menu structure
#COMPILE EXE
#DIM ALL

%ID_FILE_NEW   = 100
%ID_FILE_OPEN  = 101
%ID_FILE_SAVE  = 102
%ID_EDIT_CUT   = 200
%ID_EDIT_COPY  = 201
%ID_EDIT_PASTE = 202
%ID_HELP_ABOUT = 300

SUB PrintMenuItem(BYVAL pos AS LONG, BYVAL text AS STRING, BYVAL id AS LONG, BYVAL isPopup AS LONG)
    PRINT "  ["; pos; "] "
    IF isPopup THEN PRINT "[POPUP] ";
    PRINT text; " (ID "; id; ")"
END SUB

SUB PrintSeparator(BYVAL pos AS LONG)
    PRINT "  ["; pos; "] --------"
END SUB

SUB BuildFileMenu()
    PRINT "File menu:"
    PrintMenuItem(0, "&New", %ID_FILE_NEW, 0)
    PrintMenuItem(1, "&Open...", %ID_FILE_OPEN, 0)
    PrintMenuItem(2, "&Save", %ID_FILE_SAVE, 0)
    PrintSeparator(3)
    PrintMenuItem(4, "E&xit", 0, 0)
END SUB

SUB BuildEditMenu()
    PRINT "Edit menu:"
    PrintMenuItem(0, "Cu&t", %ID_EDIT_CUT, 0)
    PrintMenuItem(1, "&Copy", %ID_EDIT_COPY, 0)
    PrintMenuItem(2, "&Paste", %ID_EDIT_PASTE, 0)
END SUB

SUB EditMenuDemo()
    PRINT "--- Menu editor operations ---"
    PRINT "Initial File menu:"
    BuildFileMenu()
    PRINT ""
    PRINT "Inserting '&Find' at position 2:"
    PRINT "  [2] &Find (ID 203)"
    PRINT ""
    PRINT "Removing '&Save' (position 2):"
    DIM items(0:4) AS STRING
    DIM ids(0:4) AS LONG
    items(0) = "&New": ids(0) = 100
    items(1) = "&Open...": ids(1) = 101
    items(2) = "&Save": ids(2) = 102
    items(3) = "-": ids(3) = 0
    items(4) = "E&xit": ids(4) = 0
    PRINT "Before: "; items(0); ", "; items(1); ", "
    PRINT items(2); ", "; items(3); ", "; items(4)
    LOCAL i AS LONG
    FOR i = 2 TO 3
        items(i) = items(i + 1)
        ids(i) = ids(i + 1)
    NEXT i
    PRINT "After:  "; items(0); ", "; items(1); ", "
    PRINT items(2); ", "; items(3)
    PRINT ""
    PRINT "Renaming position 0: '&New' -> '&New File'"
    items(0) = "&New File"
    PRINT "  Result: "; items(0)
END SUB

SUB SeparatorDemo()
    PRINT "--- Separators ---"
    PrintMenuItem(0, "Item 1", 1, 0)
    PrintSeparator(1)
    PrintMenuItem(2, "Item 2", 2, 0)
    PrintSeparator(3)
    PrintMenuItem(4, "Item 3", 3, 0)
END SUB

SUB FullMenuDemo()
    PRINT "--- Full menu structure ---"
    PRINT "Menu bar:"
    PrintMenuItem(0, "&File", 0, 1)
    PrintMenuItem(1, "&Edit", 0, 1)
    PrintMenuItem(2, "&Help", 0, 1)
    PRINT ""
    BuildFileMenu()
    PRINT ""
    BuildEditMenu()
    PRINT ""
    PRINT "Help menu:"
    PrintMenuItem(0, "&About...", %ID_HELP_ABOUT, 0)
END SUB

FUNCTION PBMAIN() AS LONG
    PRINT "=== Menu Editor Demo ==="
    PRINT "Win32: CreateMenu, AppendMenu via DECLARE"
    PRINT ""
    FullMenuDemo()
    PRINT ""
    EditMenuDemo()
    PRINT ""
    SeparatorDemo()
    PRINT ""
    PRINT "=== End Menu Editor ==="
    FUNCTION = 0
END FUNCTION
