home *** CD-ROM | disk | FTP | other *** search
- /*
- #### # # # #
- # # # # # The FreeWare C library for
- # # ## ### # # # # ### RISC OS machines
- # # # # # # # # # # # ___________________________________
- # # #### ### ## # # # #
- # # # # # # # # # # Please refer to the accompanying
- #### ### #### # # ##### # ### documentation for conditions of use
- ________________________________________________________________________
-
- File: Menu.h
- Author: Copyright © 1993 Jason Williams
- Thanks to Shaun Blackmore, Tim Browse, and others for various
- bits and pieces, menu template ideas, etc, which were mostly
- not used for this simple implementation, but may be used in
- the future.
- Version: 1.00 (30 Apr 1993)
- Purpose: Equivalent of RISC OS Lib's "menus" functions - Give a simple
- method for creating and showing menus.
-
- Notes: These are simple menu create and show functions along very
- similar lines to RISC OS Lib's 'menu' functions. However, there
- are major differences -
- + menu items are ALWAYS indexed starting from 0.
- + menu pointers point to real Wimp menu structures, no
- messing about
- + Menu_Show is provided to show the menus for you, including
- placing a menu in the correct position over the icon bar.
- */
-
-
- #ifndef __dl_menu_h
- #define __dl_menu_h
-
- #ifndef __dl_core_h
- #include "Core.h"
- #endif
-
- #ifndef __dl_wimp_h
- #include "Wimp.h"
- #endif
-
- #ifndef __dl_event_h
- #include "Event.h"
- #endif
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- /* Menu_New()
- * Creates a new menu. "title" should be no more than 12 characters long
- * (including the terminator). "description" is a RISC OS Lib style
- * menu_new() string (Desktop C manual, page 240, but note their syntax
- * AND their example are both WRONG!), i.e.
- * opt :- " " no special options (i.e. leading spaces are skipped)
- * "!" ticked
- * "~" shaded
- * ">" has submenu/subwindow
- * "-" dotted
- * name :- any character except "," and "|"
- * entry :- {opt}* name
- * sep :- "," to separate normal items
- * "|" to separate items and place a dotted line between them
- * descr :- entry {sep entry}*
- *
- * EXAMPLES:
- * "!Ticked,~Disabled,>Sub-menu,!~Ticked and disabled, Normal"
- * ">Info, Create| Quit" ; info with sublink arrow
- * ; then create, dotted line, quit.
- *
- * NOTES:
- * Menu_New needs Screen_() functions. It assumes you have called
- * Screen_CacheModeInfo() in this screen mode (to get screen_delta.x)
- * If this call fails (out of malloc memory) then it will call
- * Error_OutOfMemory() and then return NULL.
- */
- extern menu_ptr Menu_New(char *title, char *description);
-
-
- /* Menu_Extend()
- * Extends (if possible) the menu by appending the items in "description"
- * onto the menu structure "menu". If the memory reallocation fails, it
- * returns the pointer to the old, UNCHANGED menu structure.
- * "description" is the same as for Menu_New().
- */
- extern menu_ptr Menu_Extend(menu_ptr menu, char *description);
-
-
- /* Menu_Show()
- * Shows the given menu on screen, at the given x and y position.
- * Set (y = -1) to place the menu at the correct position above the
- * icon bar.
- */
- extern void Menu_Show(menu_ptr menu, int x, int y);
-
-
- /* Menu_ShowLast()
- * Re-opens the last menu opened (call when a menu item is chosen using
- * the adjust mouse button to keep the menu open).
- * Note that if no menu has been opened, or if the last menu opened
- * has been "dispose"d, this will have bad (dire) results.
- */
- extern void Menu_ShowLast(void);
-
-
- /* Menu_AddSubMenu()
- * Adds a menu to an existing menu as a submenu at a particular item.
- */
- extern void Menu_AddSubMenu(menu_ptr menu, int entry, menu_ptr submenu);
-
-
- /* Menu_MakeWritable()
- * Makes a menu item writable. You supply the buffer into which the
- * menu item data will be written, as well as the size of this buffer
- * (including terminator), plus the validation string (as in Wimp icons)
- */
- extern void Menu_MakeWritable(menu_ptr menu, int entry,
- char *buffer, int size, char *valid);
-
- /* Menu_SetFlags()
- * Alters the state of a menu item. Setting ticked/shaded to 0 will
- * turn off the tick/make the item selectable. Setting them to 1 will
- * turn on a tick/make the item unselectable. Values other than 0 and 1
- * are undefined, so ensure the values you use are 0 and 1.
- */
- extern void Menu_SetFlags(menu_ptr menu, int entry, int ticked, int shaded);
-
-
- /* Menu_GetFlags()
- * Reads the state of a menu item. If ticked/shaded are non-null
- * pointers then the ints will be updated to reflect the current
- * state of the menu entry.
- */
- extern void Menu_GetFlags(menu_ptr menu, int entry, int *ticked, int *shaded);
-
-
- /* Menu_SetText()
- * Sets the text for a menu entry.
- */
- extern void Menu_SetText(menu_ptr menu, int entry, char *text);
-
-
- /* Menu_GetText()
- * Finds the address of the text of a menu entry.
- * NOTE that this is the actual menu item text buffer, so treat it with
- * care!
- */
- extern char *Menu_GetText(menu_ptr menu, int entry);
-
-
- /* Menu_CalcHeight()
- * Calculates the height of a menu in OS coords. For internal use.
- */
- extern int Menu_CalcHeight(menu_ptr menu);
-
-
- /* Menu_SysHandle()
- * Returns a pointer to the 'underlying' Wimp menu definition. In DeskLib
- * this IS the menu definition.
- */
- #define Menu_SysHandle(menu) (menu)
-
-
- /* Menu_SDispose()
- * Frees up the memory used by a menu. Note that this is a simple Dispose
- * which does not recursively dispose of attached submenus, and does not
- * dispose of memory used by long (indirected) item text.
- */
- #define Menu_SDispose(menu) free(menu)
-
-
- /*
- * Menu_RemoveItem()
- * Removes a menu item from a menu, shuffling items following it up the
- * menu. If there is only one item in the menu, nothing happens.
- */
- extern void Menu_RemoveItem(menu_ptr menu, int entry);
-
-
-
- /* Menu_Warn()
- * Sets up the given menu item as needing a message when the user follows
- * the submenu arrow. If yesno is TRUE, attaches the given handler to
- * menuwarnings, else releases the handler. Uses EventMsg.
- */
- extern void Menu_Warn(menu_ptr menu, int entry, BOOL yesno,
- event_handler handler, void *reference);
-
-
- /* Global variables
- * menu_currentpos holds the x,y position where the last menu was opened
- * menu_currentopen is a pointer to the last menu opened.
- * If no menu has been opened, or the last menu has been disposed, then
- * these values will be invalid - use with care.
- */
- extern wimp_point menu_currentpos;
- extern menu_ptr menu_currentopen;
-
- #ifdef __cplusplus
- }
- #endif
-
- #endif
-