/***************************************************************************
 * newmenus.h -   WorkBench 2.0 gadtools.library NewMenu functions for 1.3 *
 * ----------------------------------------------------------------------- *
 * Header file for use if 2.0 includes are not available - use in place of *
 * libraries/gadtools.h                                                    *
 ***************************************************************************/

#ifndef NEWMENUS_H
#define NEWMENUS_H

/* Utility TagItem structure for various purposes
   (copied from 2.0 utility/tagitem.h without permission) */

typedef ULONG   Tag;

struct TagItem  {
    Tag         ti_Tag;
    ULONG       ti_Data;
};
#define TAG_DONE   (0L) /* terminates array of TagItems. ti_Data unused */
#define TAG_END TAG_DONE

/* ---- user tag identification ----------------------- */
#define TAG_USER  (1L<<31)    /* differentiates user tags from system tags*/


/* gadtools NewMenu structures, constants, and macros
   (copied from 2.0 libraries/gadtools.h without permission) */

struct NewMenu
{
   UBYTE nm_Type;             /*  See below */
   STRPTR nm_Label;           /*  Menu's label */
   STRPTR nm_CommKey;         /*  MenuItem Command Key Equiv */
   UWORD nm_Flags;            /*  Menu or MenuItem flags (see note) */
   LONG nm_MutualExclude;     /*  MenuItem MutualExclude word */
   APTR nm_UserData;          /*  For your own use, see note */
};

/*  Each nm_Type should be one of these: */
#define NM_TITLE        1
#define NM_ITEM         2
#define NM_SUB          3
#define NM_END          0

#define MENU_IMAGE      128
#define IM_ITEM         (NM_ITEM | MENU_IMAGE)
#define IM_SUB          (NM_SUB | MENU_IMAGE)

/*  If you set your label to NM_BARLABEL, you'll get a separator bar. */
#define NM_BARLABEL     ((STRPTR)-1)

/*  The nm_Flags field is used to fill out either the Menu->Flags or
    MenuItem->Flags field.  Note that the sense of the MENUENABLED or
    ITEMENABLED bit is inverted between this use and Intuition's use,
    in other words, NewMenus are enabled by default.  The following
    labels are provided to disable them: */
#define NM_MENUDISABLED MENUENABLED
#define NM_ITEMDISABLED ITEMENABLED

/*  The following are pre-cleared (COMMSEQ, ITEMTEXT, and HIGHxxx are set
    later as appropriate): */
#define NM_FLAGMASK     (~(COMMSEQ | ITEMTEXT | HIGHFLAGS))

/*  You may choose among CHECKIT, MENUTOGGLE, and CHECKED.
    Toggle-select menuitems are of type CHECKIT|MENUTOGGLE, along
    with CHECKED if currently selected.  Mutually exclusive ones
    are of type CHECKIT, and possibly CHECKED too.  The nm_MutualExclude
    is a bit-wise representation of the items excluded by this one,
    so in the simplest case (choose 1 among n), these flags would be
    ~1, ~2, ~4, ~8, ~16, etc.  See the Intuition Menus chapter. */

/*  A UserData pointer can be associated with each Menu and MenuItem structure.
    The CreateMenus() call allocates space for a UserData after each
    Menu or MenuItem (header, item or sub-item).  You should use the
    GTMENU_USERDATA() or GTMENUITEM_USERDATA() macro to extract it. */

#define GTMENU_USERDATA(menu)         (*((APTR *)(((struct Menu *)menu)+1)))
#define GTMENUITEM_USERDATA(menuitem) (*((APTR *)(((struct MenuItem *)menuitem)+1)))

/* TagItem codes */
#define GT_TagBase           TAG_USER + 0x80000

#define GTMN_TextAttr        GT_TagBase+49 /* MenuItem font TextAttr */
#define GTMN_FrontPen        GT_TagBase+50 /* MenuItem text pen color */
#define GTMN_Menu            GT_TagBase+60 /* Pointer to Menu for use by */
                                           /* LayoutMenuItems() */
/* V37 tags (new to V37 gadtools) */
#define GTMN_FullMenu        GT_TagBase+62 /* Asks CreateMenus() to
                         validate that this is a complete menu structure */
#define GTMN_SecondaryError  GT_TagBase+63 /* ti_Data is a pointer
                to a ULONG to receive error reports from CreateMenus() */

/*  These return codes can be obtained through the GTMN_SecondaryError tag */
#define GTMENU_TRIMMED  0x00000001   /* Too many menus, items, or subitems,
                                        menu has been trimmed down */
#define GTMENU_INVALID  0x00000002   /* Invalid NewMenu array */
#define GTMENU_NOMEM    0x00000003   /* Out of memory */


/* NewMenu function prototypes */
struct Menu *CreateMenusA(struct NewMenu *newmenu, struct TagItem *taglist);
struct Menu *CreateMenus(struct NewMenu *newmenu, Tag tag1, ...);
BOOL LayoutMenuItemsA(struct MenuItem *firstitem, APTR vi, struct TagItem *taglist);
BOOL LayoutMenuItems(struct MenuItem *firstitem, APTR vi, Tag tag1, ...);
BOOL LayoutMenusA(struct Menu *firstmenu, APTR vi, struct TagItem *taglist);
BOOL LayoutMenus(struct Menu *firstmenu, APTR vi, Tag tag1, ...);
void FreeMenus(struct Menu *menu);

#endif /* NEWMENUS_H */
