/*-*-C-*-
 * menuedit include file
 */

#ifndef __menuedit_h
#define __menuedit_h

/*
 * Layout and colour parameters
 */

#define MENU_MARGIN 40    /* Gap to top/bot/left/right of menu (OS Units) */
#define MENU_TITLE_HEIGHT 40
#define ENTRY_HEIGHT_NORMAL 44
#define ENTRY_HEIGHT_SEPARATOR 20
#define MENU_TICK_WIDTH 24
#define MENU_ARROW_WIDTH 24
#define ENTRY_NORMAL_BG 0
#define ENTRY_SELECTED_FOCUS_BG 7
#define ENTRY_SELECTED_NOFOCUS_BG 2
#define ENTRY_NORMAL_FG 7
#define TITLE_NORMAL_BG 3
#define MENU_BORDER_FG 7


/*
 * Each menu entry is represented by one of these structures.  The malloced
 * strings are re-allocated to the exact length required every time their
 * contents change. Note the length required is that of the CURRENT contents,
 * not the max length.
 *
 * Separators are represented by one of these records with the "separator"
 * flag set.  If this is set the only other fields that are used are miny,
 * maxy, selected, owner and next.
 */


typedef struct
{
    unsigned int flags;
    ComponentID componentID;
    char *text;                 /* malloc */
    int maxtext;
    char *clickshow;            /* malloc */
    char *submenushow;          /* malloc */
    int submenuevent;
    int clickevent;
    char *helpmessage;          /* malloc */
    int maxentryhelp;
} EntryPropsRec, *EntryPropsPtr;


typedef struct _menuentryrec
{
    EntryPropsRec p;            /* fields edited by the menu entry dbox */

    WindowPtr dbox;             /* malloced; NULL if editing dbox has not
                                   been created; note that dbox only exists
                                   while it is open (ie on display) */
    int miny, maxy;             /* Work-area coords of the bottoms and top
                                   (half open) of the item */
    Bool selected;
    Bool separator;             /* This entry is a dotted line */

    struct _menuobjrec *owner;  /* The Menu that this entry is in */
    struct _menuentryrec *next; /* Link */
} MenuEntryRec, *MenuEntryPtr;


/*
 * Each menu is represented by one of these structures.  The malloced
 * strings are re-allocated to the exact length required every time their
 * contents change. Note the length allocated (and that stored in the Object
 * data format) is that of the CURRENT contents, not the max length.
 */

typedef struct
{
    unsigned int flags;
    char *title;                /* malloc */
    int maxtitle;
    char *helpmessage;          /* malloc */
    int maxhelp;
    int showevent;
    int hideevent;
} MenuPropsRec, *MenuPropsPtr;


typedef struct _menuobjrec
{
    MenuPropsRec p;             /* Fields updated by menu dbox */

    int numentries;             /* Number of menu entries incl. separators */

    MenuEntryPtr entries;       /* Link list of 'numentries' entries */
    int width, height;          /* Size of whole menu in OS Units (excludes
                                   border) */
    int entrywidth;             /* Each entry is this wide (excluding arrow
                                   and tick) */
    int margin;                 /* left/right margins in OS Units, at least
                                   MENU_MARGIN */
    int numselected;            /* Number of selected entries including
                                   separators */
    Bool weakselection;         /* Selection should be cleared when pop-up
                                   menu closes */

    Bool internal;              /* This is the "palette" */

    Opaque documentID;          /* As quoted by the shell */
    Opaque objectID;            /* As quoted by the shell */
    Bool modified;              /* Shell's version is out of date with
                                   respect to ours */
    Bool pendingclose;          /* Close as soon as transfer to shell is
                                   complete */

    WindowPtr window;           /* malloced */
    WindowPtr dbox;             /* malloced; NULL if editing dbox has not
                                   been created; note that dbox only exists
                                   while it is opne (ie on display) */

    char name[MAX_OBJECT_NAME]; /* As passed to us by the shell */

    char *objectdata;           /* used during the "send back" phase */
} MenuObjRec, *MenuObjPtr;



extern char *copystring (char *src);
extern error * clonestring (char **s);
extern Bool equalstrings (char *s, char *t);
extern error * menuedit_load_prototypes (void);
extern char * menuedit_find_keyname (char *string, char **padding);
extern void menuedit_get_entry_bbox (MenuObjPtr menu, MenuEntryPtr entry,
    RectPtr box);
extern void menuedit_get_selection_bbox (MenuObjPtr menu, RectPtr bbox);
extern void menuedit_calculate_menu_size (MenuObjPtr menu, int *workwidth,
    int *workheight);
extern error * menuedit_redraw_window (WindowRedrawPtr redraw,
    MenuObjPtr menu);
extern error * menuedit_fix_extent (MenuObjPtr menu);
extern error * menuedit_focus_claim (MenuObjPtr menu);
extern error * menuedit_mouse_click (MouseClickPtr mouse,
    unsigned int modifiers, MenuObjPtr menu);
extern error * menuedit_raise_window (MenuObjPtr menu);
extern error * menuedit_load (MenuObjPtr menu,
    ResourceFileObjectTemplateHeaderPtr object,
    MessageResEdObjectLoadPtr load);
extern error * menuedit_close_menu (MenuObjPtr menu, Bool notifyshell);
extern error * menuedit_rename_menu (MenuObjPtr menu, char *name);
extern error * menuedit_reopen_window (WindowPtr win, MenuObjPtr menu);
extern error * menuedit_close_window (MenuObjPtr menu);
extern int menuedit_object_size (MenuObjPtr menu, int *bodysize,
    int *stringsize, int *msgsize, int *numrelocs);
extern error * menuedit_save_object_to_memory (MenuObjPtr menu, char *buffer,
    int bodysize, int stringsize, int msgsize, int numrelocs);
extern error * menuedit_create_menu (void);
extern error * menuedit_key_pressed (MenuObjPtr menu, KeyPressPtr key,
    Bool *consumed);
extern error * menuedit_font_changed (void);
extern void menuedit_canonicalise (MenuObjPtr menu);
extern error * menuedit_justify_keycuts (MenuObjPtr menu);
extern error * menuedit_open_palette (void);
extern Bool menuedit_help_text (
    MenuObjPtr menu,
    PointPtr mouse,
    char *reply
);

#endif
