home *** CD-ROM | disk | FTP | other *** search
- ''
- '' $Id: GadToolsMenus.bas,v 1.4 1994/03/16 13:53:36 alex Rel $
- ''
- '' GadTools Menu creation helper
- ''
- '' (c) Copyright 1994 HiSoft
- ''
-
- 'REM $INCLUDE Exec.bh
- 'REM $INCLUDE GadTools.bh
- 'REM $INCLUDE Utility.bc
-
- '
- ' NM_CI - add a new item to an existing NewMenu list
- '
- FUNCTION NM_CI%(nmEntry&, BYVAL nmType%, nmLabel$, BYVAL nmImage&, _
- nmCommKey$, BYVAL nmFlags%, BYVAL nmMutualExclude&, BYVAL nmUserData&)
- STATIC slen%, sptr&
-
- POKEB nmEntry& + nm_Type%, nmType% 'fill in entry type
-
- SELECT CASE nmType%
- CASE IM_ITEM&, IM_SUB&
- POKEL nmEntry& + nm_Label%, nmImage&
- CASE NM_END&
- POKEL nmEntry& + nm_Label%, NULL&
- CASE REMAINDER
- IF nmLabel$ = "" THEN
- ' treat null string as a separator
- POKEL nmEntry& + nm_Label%, NM_BARLABEL&
- ELSE
- slen% = LEN(nmLabel$) + 1
- sptr& = AllocVec&(slen%, MEMF_PUBLIC&) 'allocate memory for string
- IF sptr& <> NULL& THEN
- CopyMem SADD(nmLabel$ + CHR$(0)), sptr&, slen%
- POKEL nmEntry& + nm_Label%, sptr& 'fill in label
- ELSE
- NM_CI% = FALSE&
- EXIT FUNCTION
- END IF
- END IF
- END SELECT
-
- POKEL nmEntry& + nm_CommKey%, NULL&
- IF nmCommKey$ <> "" THEN
- ' treats null string as no commkey
- slen% = LEN(nmCommKey$)
- IF slen% = 1 OR PEEKW(LIBRARY("gadtools.library") + lib_Version%) >= 39 THEN
- IF slen% > 1 THEN
- nmFlags% = nmFlags% OR NM_COMMANDSTRING&
- END IF
- sptr& = AllocVec&(slen% + 1, MEMF_PUBLIC&) 'allocate memory for string
- IF sptr& <> NULL& THEN
- CopyMem SADD(nmCommKey$ + CHR$(0)), sptr&, slen% + 1
- POKEL nmEntry& + nm_CommKey%, sptr& 'fill in command key
- ELSE
- NM_CI% = FALSE&
- EXIT FUNCTION
- END IF
- END IF
- END IF
-
- POKEW nmEntry& + nm_Flags%, nmFlags%
- POKEL nmEntry& + nm_MutualExclude%, nmMutualExclude&
- POKEL nmEntry& + nm_UserData%, nmUserData&
-
- nmEntry& = nmEntry& + NewMenu_sizeof%
-
- NM_CI% = TRUE&
- END FUNCTION
-
- '
- ' Create a new menu title
- '
- ' nmEntry& - next free NewMenu slot
- ' nmLabel$ - label for this menu title (the title text itself)
- ' nmFlags% - initial flags for this title
- ' nmUserData& - user data (whatever you like!)
- '
- FUNCTION MenuTitle%(nmEntry&, nmLabel$, BYVAL nmFlags%, BYVAL nmUserData&)
- MenuTitle% = NM_CI%(nmEntry&, NM_TITLE&, nmLabel$, NULL&, "", _
- nmFlags%, 0&, nmUserData&)
- END FUNCTION
-
- '
- ' Create a new text menu item under the current title
- '
- ' nmEntry& - next free NewMenu slot
- ' nmLabel$ - label for this menu item (the item text itself)
- ' nmCommKey$ - the associated command key, a single character string for WB2,
- ' or a longer string for WB3 (the routine will automatically ignore
- ' longer strings for WB before V3)
- ' nmFlags% - initial flags for this title
- ' nmMutualExclude& - mutual exclude setting
- ' nmUserData& - user data (whatever you like!)
- '
- FUNCTION MenuItem%(nmEntry&, nmLabel$, nmCommKey$, _
- BYVAL nmFlags%, BYVAL nmMutualExclude&, BYVAL nmUserData&)
- MenuItem% = NM_CI%(nmEntry&, NM_ITEM&, nmLabel$, NULL&, nmCommKey$, _
- nmFlags%, nmMutualExclude&, nmUserData&)
- END FUNCTION
-
- '
- ' Create a new image menu item under the current title
- '
- ' nmEntry& - next free NewMenu slot
- ' nmImage& - address of the image which is to be used for this item
- ' nmCommKey$ - the associated command key, a single character string for WB2,
- ' or a longer string for WB3 (the routine will automatically ignore
- ' longer strings for WB before V3)
- ' nmFlags% - initial flags for this title
- ' nmMutualExclude& - mutual exclude setting
- ' nmUserData& - user data (whatever you like!)
- '
- FUNCTION MenuImageItem%(nmEntry&, BYVAL nmImage&, nmCommKey$, _
- BYVAL nmFlags%, BYVAL nmMutualExclude&, BYVAL nmUserData&)
- MenuImageItem% = NM_CI%(nmEntry&, IM_ITEM&, "", nmImage&, nmCommKey$, _
- nmFlags%, nmMutualExclude&, nmUserData&)
- END FUNCTION
-
- '
- ' Create a new text sub-menu item under the current item
- '
- ' nmEntry& - next free NewMenu slot
- ' nmLabel$ - label for this menu item (the item text itself)
- ' nmCommKey$ - the associated command key, a single character string for WB2,
- ' or a longer string for WB3 (the routine will automatically ignore
- ' longer strings for WB before V3)
- ' nmFlags% - initial flags for this title
- ' nmMutualExclude& - mutual exclude setting
- ' nmUserData& - user data (whatever you like!)
- '
- FUNCTION MenuSubItem%(nmEntry&, nmLabel$, nmCommKey$, _
- BYVAL nmFlags%, BYVAL nmMutualExclude&, BYVAL nmUserData&)
- MenuSubItem% = NM_CI%(nmEntry&, NM_SUB&, nmLabel$, NULL&, nmCommKey$, _
- nmFlags%, nmMutualExclude&, nmUserData&)
- END FUNCTION
-
- '
- ' Create a new image sub-menu item under the current item
- '
- ' nmEntry& - next free NewMenu slot
- ' nmImage& - address of the image which is to be used for this item
- ' nmCommKey$ - the associated command key, a single character string for WB2,
- ' or a longer string for WB3 (the routine will automatically ignore
- ' longer strings for WB before V3)
- ' nmFlags% - initial flags for this title
- ' nmMutualExclude& - mutual exclude setting
- ' nmUserData& - user data (whatever you like!)
- '
- FUNCTION MenuImageSubItem%(nmEntry&, BYVAL nmImage&, nmCommKey$, _
- BYVAL nmFlags%, BYVAL nmMutualExclude&, BYVAL nmUserData&)
- MenuImageSubItem% = NM_CI%(nmEntry&, IM_SUB&, "", nmImage&, nmCommKey$, _
- nmFlags%, nmMutualExclude&, nmUserData&)
- END FUNCTION
-
- '
- ' Terminate NewMenu building & construct the final menu strip
- '
- ' nmList& - base of NewMenu list
- ' nmEntry& - next free NewMenu slot
- ' tattr& - TextAttr to be used for this menu
- ' vi& - GadTools ViewInfo associated with this windows screen
- ' scaledcheck& - scaled checkmark image to be used (WB3)
- ' scaledamigakey& - scaled Amiga key image to be used (WB3)
- '
- FUNCTION MenuEnd%(nmEntry&, strip&, BYVAL nmList&, BYVAL tattr&, _
- BYVAL vi&, BYVAL scaledcheck&, BYVAL scaledamigakey&)
- STATIC NMME_tl&(10)
- STATIC fail%
-
- IF NM_CI%(nmEntry&, NM_END&, "", NULL&, "", 0, 0, NULL&) = TRUE& THEN
- nmEntry& = NULL&
-
- strip& = CreateMenusA&(nmList&, NULL&)
- IF strip& <> NULL& THEN
- TAGLIST VARPTR(NMME_tl&(0)), _
- GTMN_TextAttr&, tattr&, _
- GTMN_NewLookMenus&, TRUE&, _
- TAG_END&
-
- IF scaledcheck& AND scaledamigakey& THEN
- TAGLIST VARPTR(NMME_tl&(4)), _
- GTMN_Checkmark&, scaledcheck&, _
- GTMN_AmigaKey&, scaledamigakey&, _
- TAG_END&
- END IF
-
- MenuEnd% = LayoutMenusA&(strip&, vi&, VARPTR(NMME_tl&(0)))
- ELSE
- MenuEnd% = FALSE&
- EXIT FUNCTION
- END IF
- ELSE
- MenuEnd% = FALSE&
- EXIT FUNCTION
- END IF
- END FUNCTION
-
- '
- ' Allocate space for num_entries in a NewMenu structure
- '
- ' nmEntry& - space to store the initial NewMenu slot
- ' num_entries% - the number of menu entries you need (including the MenuEnd)
- '
- FUNCTION MenuAlloc&(nmEntry&, BYVAL num_entries%)
- nmEntry& = AllocVec&(num_entries% * NewMenu_sizeof%, MEMF_CLEAR&)
- MenuAlloc& = nmEntry&
- END FUNCTION
-
- '
- ' Free space which was allocated for the menu we built
- '
- ' nmList& - base of NewMenu list
- ' strip& - menu strip which was created (must have been detached from window!)
- '
- SUB MenuFree(nmList&, strip&)
- STATIC nmEntry&, label&
-
- IF strip& <> NULL& THEN
- FreeMenus strip&
- strip& = NULL&
- END IF
- IF nmList& THEN
- nmEntry& = nmList&
- WHILE PEEKL(nmEntry& + nm_Type%) <> NM_END&
- label& = PEEKL(nmEntry& + nm_Label%)
- IF label& <> NM_BARLABEL& THEN
- FreeVec label&
- END IF
- label& = PEEKL(nmEntry& + nm_CommKey%)
- IF label& <> NULL&
- FreeVec label&
- END IF
- nmEntry& = nmEntry& + NewMenu_sizeof%
- WEND
- FreeVec nmList&
- nmList& = NULL&
- END IF
- END SUB
-