home *** CD-ROM | disk | FTP | other *** search
- // **************************************************************************
- // Copyright 1996 David Allison
- //
- // VV VV IIIIII SSSSS TTTTTT AA
- // VV VV II SS TT AA AA
- // VV VV II SSSS TT AA AA
- // VV VV II SS TT AAAAAAAA
- // VV IIIIII SSSS TT AA AA
- //
- // MULTI-THREADED C++ WIMP CLASS LIBRARY
- // for RISC OS
- // **************************************************************************
- //
- // P U B L I C D O M A I N L I C E N C E
- // -------------------------------------------
- //
- // This library is copyright. You may not sell the library for
- // profit, but you may sell products which use it providing
- // those products are presented as executable code and are not
- // libraries themselves. The library is supplied without any
- // warranty and the copyright owner cannot be held responsible for
- // damage resulting from failure of any part of this library.
- //
- // See the User Manual for details of the licence.
- //
- // *************************************************************************
-
- //
- // menus
- //
-
- #ifndef __menu_h
- #define __menu_h
-
- #ifndef __icon_h
- #include "Vista:icon.h"
- #endif
-
- #include <stdarg.h>
-
-
- class Menu ;
- class MenuData ;
- class MenuSet ;
- class Task ;
-
- struct MenuItemData
- {
- int item_flags ;
- union
- {
- MenuData *submenu ;
- int window_handle ;
- } ;
- int icon_flags ;
- IconData icon_data ;
- } ;
-
- struct MenuData
- {
- char title[12] ;
- char title_fore_colour ;
- char title_back_colour ;
- char work_fore_colour ;
- char work_back_colour ;
- int item_width ;
- int item_height ;
- int item_gap ;
- MenuItemData items[1] ;
- } ;
-
- class MenuItem
- {
- friend class Menu ;
- public:
- enum menu_item_flags
- {
- TICKED = 1,
- SEPARATOR = 1 << 1,
- WRITEABLE = 1 << 2,
- MENUWARNING = 1 << 3,
- OPENANYWAY = 1 << 4,
- LAST = 1 << 7,
- TITLEINDIRECTED = 1 << 8
- } ;
- MenuItem(char *name, Menu *menu, char *text, int length) ; // text entry
- MenuItem(char *name, Menu *menu, char *sprite, void *sprite_area) ; // sprite entry
- void tick() ; // tick item
- void untick() ; // untick item
- void fade() ; // grey out item
- void unfade() ; // ungrey out item
- int flags(int f = 0, int m = 0) ; // set and read flags
- operator int() ; // convert to index
- operator char*() ; // convert to name
- int is_ticked() ; // is item ticked
- int is_faded() ; // is item faded
- void set_submenu (Menu *submenu) ;
- void make_writeable (char *buffer, int length, char *valid) ;
- void print (char *format ...) ; // print to the menu item
- void vprint (char *format, va_list ap) ;
- void read (int &) ; // read a number
- void read (char *) ; // read a string
- private:
- char *name ;
- MenuItem *next ; // next in list
- Menu *menu ; // menu I am in
- int index ; // index into menu
- Menu *submenu ; // my submenu
- } ;
-
- class Menu
- {
- friend class MenuItem ;
- friend class MenuSet ;
- public:
- Menu (char *name, char *title) ; // create a new menu with name given
- Menu (char *name, char *title, MenuItem *item) ; // create a sub menu
- ~Menu() ;
- MenuItem *selection(int *hits) ; // translate a selection
- bool invalid_selection (int *hits) ; // is selection invalid
- MenuItem *item (char *iname) ; // get an item from its name
- void print (char *item, char *format ...) ;
- void read (char *item, char *s) ;
- void read (char *item, int &i) ;
- void finish() ; // close off a menu
- void open (int x, int y) ; // open the menu on the screen
- void close() ; // close the menu
- void iconbar_adjust (int &x, int &y) ; // adjust for iconbar display
- private:
- void init(char *name, char *title) ; // initialisation
- int add_item (MenuItem *item) ; // add a new item and return its index
- char *name ; // name of menu
- Menu *next ; // next in list
- MenuData *data ; // actual menu data
- MenuItem *items ; // list of items
- int num_items ; // number of items
- int max_items ; // max space for items
- int max_width ;
- int item_adjust ; // adjustment for items with separators
- } ;
-
- //
- // the set of menus in a task
- //
-
- class MenuSet
- {
- public:
- MenuSet (Task *t, char *filename) ; // read menu set from file
- ~MenuSet();
- Menu *find (char *name) ; // find a menu
- void add_menu(Menu *menu); // add a new menu
- private:
- void parse_menu () ;
- void parse_menu_details(Menu *menu) ;
- void parse_item (Menu *menu) ;
- Menu *menus ; // the menus
- Task *task ;
- } ;
-
- #endif
-