home *** CD-ROM | disk | FTP | other *** search
- /*
- Menu.h - a replacement for RISC_OSLib's menu module.
-
- */
- /*
-
- ##### # #
- # # # # #
- # # #
- # ## #### #### # ## ####
- # # # # # # # # # #
- # # # # # ### # # # #
- # # # # # # # # # #
- # ### # # # #### ##### ### ####
-
- -----------------------------------------------------------------------------
-
- This is source for use with the 'DeskLib' Wimp C programming library for
- Risc OS. I currently use v1.04 of DeskLib. This source is FreeWare, which
- means you can use it to write commercial applications, but you may not charge
- *in any way* for the distribution of this source. I (Tim Browse) retain
- all copyright on this source.
-
- This source is provided 'as is' and I offer no guarantees that is useful,
- bug-free, commented, that it will compile, or even that it exists.
-
- If it breaks in half, you own both pieces.
-
- All source © Tim Browse 1993
-
- -----------------------------------------------------------------------------
-
- */
-
- #ifndef __timslib__menu_h
- #define __timslib__menu_h
-
- /* DeskLib includes */
- #include "Core.h"
- #include "DeskLib.Wimp.h"
-
- typedef int menu;
-
- /* The following is for use inside menu makers - it is TRUE if the menu is being
- shown because it is being recreated due to an adjust click by the user.
- FALSE at all other times.
- */
- extern BOOL menu_adjust_pressed;
-
- /* The next two variables will indicate where the current menu came from.
-
- This is so that if you have a lot of similar menus attached to icons, you
- don't have to bother remembering in your code where exactly the user clicked
- to get this menu, and so all your handlers can be the same.
- After all, this is where this information ought to be - it's the Menu module
- that gets told about menu requests.
-
- When a menu is not open, or about to be opened, the value of these variables
- will be undefined. This is because the Wimp doesn't always explicitly tell the
- application when a menu is closed - e.g. when user clicks outside a menu to close
- it.
-
- Therefore stick to accessing them in your menu selection handlers or menu
- makers. Obviously, these variables are not updated if you just use Menu_Show
- and don't use Menu_AttachMenu{Maker}.
- */
- extern window_handle menu_current_window;
- extern icon_handle menu_current_icon;
-
-
- extern menu Menu_New(char *name, char *desc);
- /*
- Creates a menu with the given name and description. The description syntax
- is the same as for RISC_OSLib's menu module.
- */
-
- extern menu Menu_ColourMenu(char *title, char *last_item);
- /*
- Creates a 16-colour menu, with an optional last item, e.g. call with "None" or
- "Transparent". This entry is separated from the others by a dotted line.
-
- Pass NULL as last_item if you just want colours 0-15 with no special last field.
- NB Don't pass the empty string ( "" ) - it won't work - you'll just get an empty
- last field on the menu which will look real stoopid.
-
- Menu is created as a standard 'menu' type as used throughout this module, so
- use Menu_Dispose() when you don't need it any more.
- */
-
- extern void Menu_Dispose(menu the_menu, BOOL recursive);
- /*
- De-allocates memory associated with this menu. If recursive is TRUE, also
- recursively de-allocates all sub-menus of the_menu.
- */
-
- extern void Menu_SubMenu(menu parent, int entry, menu submenu);
- /*
- Attaches 'submenu' as a sub-menu onto the menu 'parent' at position 'entry'.
- */
-
- extern void Menu_AddDialogBox(menu the_menu, int entry, window_handle window);
- /*
- Attaches a window (dialogue box) as a submenu onto 'the_menu' at position
- 'entry'. Usually called for a menu warning event, just before dbox is
- shown.
- */
-
- extern void Menu_SetFlags(menu the_menu, int entry, BOOL tick, BOOL fade);
- /*
- This sets the flags on the given menu entry.
- */
-
- #define Menu_TickEntry(the_menu, entry) ((((menu_item *) (Menu_SysHandle(the_menu) + 1))[(entry)].menuflags.data.ticked) = TRUE)
- #define Menu_UnTickEntry(the_menu, entry) ((((menu_item *) (Menu_SysHandle(the_menu) + 1))[(entry)].menuflags.data.ticked) = FALSE)
-
- #define Menu_FadeEntry(the_menu, entry) ((((menu_item *) (Menu_SysHandle(the_menu) + 1))[(entry)].iconflags.data.shaded) = TRUE)
- #define Menu_UnFadeEntry(the_menu, entry) ((((menu_item *) (Menu_SysHandle(the_menu) + 1))[(entry)].iconflags.data.shaded) = FALSE)
- /*
- void Menu_TickEntry(menu the_menu, int entry)
- void Menu_UnTickEntry(menu the_menu, int entry)
- void Menu_FadeEntry(menu the_menu, int entry)
- void Menu_UnFadeEntry(menu the_menu, int entry)
-
- These are simple(!) macros for when you want to set the tick or fade flags on
- their own.
- */
-
-
- extern void Menu_MakeWritable(menu the_menu, int entry,
- char *buffer, int bufferlength, char *validation);
- /*
- This makes the specified menu entry writable. It preserves the text currently
- in the menu item - it is copied into 'buffer'.
- */
-
- extern void Menu_Show(menu the_menu, wimp_point mouse_pos, BOOL iconbar);
- /*
- This is used in response to a mouse button event with buttons = 4 (MENU
- pressed). The mouse_pos is used to position the menu - just pass the wimp_point
- from the mouse button event straight through.
- If iconbar is TRUE, it sets the vertical position correctly for an icon
- bar menu as per the Acorn guideline in RO2 PRMs p1315 - 96 OS units above the
- bottom of the screen.
- */
-
- /*
-
- extern menu_ptr Menu_SysHandle(menu the_menu);
-
- Returns a low-level handle to the menu, for manipulations not supported by
- this module.
-
- NB. Do NOT use free() on this pointer - it won't work!
- */
- #define Menu_SysHandle(menu) ((menu_ptr) (menu))
-
- /* Attaching menus for automatic handling */
-
- typedef void (*menu_handler)(void *reference, int *hit);
- typedef menu (*menu_maker)(void *reference);
-
- /* menu_selection: This variable indicates if an event is as a result of a menu
- selection or submenu activation - use it inside your 'menu_handler()'.
- TRUE => User actively clicked select/adjust on an item.
- FALSE => User followed submenu arrow which generated a menu warning event.
- (Use the '>' option to request menu warning events for items)
-
- This variable will hold the value 'TRUE' if accessed when menu handlers are
- not being called, which is the logical value. e.g. if a hot-key is used to
- open a dbox that would normally hang off a menu, it would behave as if the
- parent entry of the dbox had been selected by the user, which would cause the
- correct behaviour - i.e. dbox should open under the pointer.
- */
- extern BOOL menu_selection;
-
- /* menu_submenupos: This variable holds the position passed by any MenuWarning
- messages. This means if you want to do your own opening of sub-menus - e.g.
- custom dialogue boxes etc, just pass this position to Wimp_CreateSubMenu.
- The contents if this variable are undefined if used while a MenuWarn message
- is not being processed (use menu_selection - see above - to find out).
- */
- extern wimp_point menu_submenupos;
-
- extern void Menu_AttachMenu(menu the_menu, window_handle window, icon_handle icon,
- menu_handler handler, void *reference);
- /*
- the_menu the menu to attach
- window should be event_ANY - if not window specific, or
- a window handle - to attach only to that window
- icon should be event_ANY - if not icon-specific, or
- an icon handle - to attach ONLY to that icon
- (NOTE: if icon != event_ANY, window MUST be defined)
-
- handler is the address of your menu handler function
- reference is a handle for any user-data you want passed to the
- function whenever it is called.
-
- Note that menus attached to icons will be invoked by SELECT clicks as well
- as MENU clicks.
- */
-
-
- extern void Menu_AttachMenuMaker(menu_maker maker_proc,
- window_handle window, icon_handle icon,
- menu_handler handler, void *reference);
- /*
- the_menu the menu to attach
- window should be event_ANY - if not window specific, or
- a window handle - to attach only to that window
- icon should be event_ANY - if not icon-specific, or
- an icon handle - to attach ONLY to that icon
- (NOTE: if icon != event_ANY, window MUST be defined)
-
- handler is the address of your menu handler function
- reference is a handle for any user-data you want passed to the
- function whenever it is called.
-
- Note that menus attached to icons will be invoked by SELECT clicks as well
- as MENU clicks.
- */
-
- extern void Menu_AddDynamicDialogBox(window_handle window);
- /*
- This is used for sub-menu dialog boxes that are created on demand.
-
- This should be called from within the menu selection handler when
- a submenu is traversed that has been marked with a '>' option in the
- menu string. The handler should create the window to show as a submenu
- (but not open it) and pass the handle to this function, then return.
- The rest is automagic!
- */
-
-
- extern void Menu_DetachMenu(window_handle window, icon_handle icon);
- /*
- Detaches any menus or menu makers from the given window/icon.
- If called for a window, detaches *all* handlers for it, including
- icon specific ones.
- If the window is event_ANY, only removes the 'catch-all' handler - it
- does NOT remove all menu handlers.
-
- It is legal to call this even if no menus/makers are attached to the
- specified window/icon.
-
- window should be event_ANY - if not window specific, or
- a window handle - to detach only from that window
- icon should be event_ANY - if not icon-specific, or
- an icon handle - to detach ONLY from that icon
- (NOTE: if icon != event_ANY, window MUST be defined)
- */
-
- #endif
-