home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / vista_1 / !Vista_h_menu < prev    next >
Encoding:
Text File  |  1996-01-25  |  5.3 KB  |  162 lines

  1. // **************************************************************************
  2. //                     Copyright 1996 David Allison
  3. //
  4. //             VV    VV    IIIIII     SSSSS     TTTTTT       AA
  5. //             VV    VV      II      SS           TT       AA  AA
  6. //             VV    VV      II        SSSS       TT      AA    AA
  7. //              VV  VV       II           SS      TT      AAAAAAAA
  8. //                VV       IIIIII     SSSS        TT      AA    AA
  9. //
  10. //                    MULTI-THREADED C++ WIMP CLASS LIBRARY
  11. //                                for RISC OS
  12. // **************************************************************************
  13. //
  14. //             P U B L I C    D O M A I N    L I C E N C E
  15. //             -------------------------------------------
  16. //
  17. //     This library is copyright. You may not sell the library for
  18. //     profit, but you may sell products which use it providing
  19. //     those products are presented as executable code and are not
  20. //     libraries themselves.  The library is supplied without any
  21. //     warranty and the copyright owner cannot be held responsible for
  22. //     damage resulting from failure of any part of this library.
  23. //
  24. //          See the User Manual for details of the licence.
  25. //
  26. // *************************************************************************
  27.  
  28. //
  29. // menus
  30. //
  31.  
  32. #ifndef __menu_h
  33. #define __menu_h
  34.  
  35. #ifndef __icon_h
  36. #include "Vista:icon.h"
  37. #endif
  38.  
  39. #include <stdarg.h>
  40.  
  41.  
  42. class Menu ;
  43. class MenuData ;
  44. class MenuSet ;
  45. class Task ;
  46.  
  47. struct MenuItemData
  48.    {
  49.    int item_flags ;
  50.    union
  51.       {
  52.       MenuData *submenu ;
  53.       int window_handle ;
  54.       } ;
  55.    int icon_flags ;
  56.    IconData icon_data ;
  57.    } ;
  58.  
  59. struct MenuData
  60.    {
  61.    char title[12] ;
  62.    char title_fore_colour ;
  63.    char title_back_colour ;
  64.    char work_fore_colour ;
  65.    char work_back_colour ;
  66.    int item_width ;
  67.    int item_height ;
  68.    int item_gap ;
  69.    MenuItemData items[1] ;
  70.    } ;
  71.  
  72. class MenuItem
  73.    {
  74.    friend class Menu ;
  75.    public:
  76.       enum menu_item_flags
  77.          {
  78.          TICKED = 1,
  79.          SEPARATOR = 1 << 1,
  80.          WRITEABLE = 1 << 2,
  81.          MENUWARNING = 1 << 3,
  82.          OPENANYWAY = 1 << 4,
  83.          LAST = 1 << 7,
  84.          TITLEINDIRECTED = 1 << 8
  85.          } ;
  86.       MenuItem(char *name, Menu *menu, char *text, int length) ;                        //  text entry
  87.       MenuItem(char *name, Menu *menu, char *sprite, void *sprite_area) ;   // sprite entry
  88.       void tick() ;                 //  tick item
  89.       void untick() ;               // untick item
  90.       void fade() ;                 // grey out item
  91.       void unfade() ;               // ungrey out item
  92.       int flags(int f = 0, int m = 0) ;     // set and read flags
  93.       operator int() ;                 // convert to index
  94.       operator char*() ;               // convert to name
  95.       int is_ticked() ;                // is item ticked
  96.       int is_faded() ;                 // is item faded
  97.       void set_submenu (Menu *submenu) ;
  98.       void make_writeable (char *buffer, int length, char *valid) ;
  99.       void print (char *format ...) ;   // print to the menu item
  100.       void vprint (char *format, va_list ap) ;
  101.       void read (int &) ;               // read a number
  102.       void read (char *) ;              // read a string
  103.    private:
  104.       char *name ;
  105.       MenuItem *next ;                // next in list
  106.       Menu *menu ;                    // menu I am in
  107.       int index ;                     // index into menu
  108.       Menu *submenu ;                 // my submenu
  109.    } ;
  110.  
  111. class Menu
  112.    {
  113.    friend class MenuItem ;
  114.    friend class MenuSet ;
  115.    public:
  116.       Menu (char *name, char *title) ;                // create a new menu with name given
  117.       Menu (char *name, char *title, MenuItem *item) ; // create a sub menu
  118.       ~Menu() ;
  119.       MenuItem *selection(int *hits) ;         // translate a selection
  120.       bool invalid_selection (int *hits) ;     // is selection invalid
  121.       MenuItem *item (char *iname) ;            // get an item from its name
  122.       void print (char *item, char *format ...) ;
  123.       void read (char *item, char *s) ;
  124.       void read (char *item, int &i) ;
  125.       void finish() ;                           // close off a menu
  126.       void open (int x, int y) ;                // open the menu on the screen
  127.       void close() ;                            // close the menu
  128.       void iconbar_adjust (int &x, int &y) ;    // adjust for iconbar display
  129.    private:
  130.       void init(char *name, char *title) ;     // initialisation
  131.       int add_item (MenuItem *item) ;    // add a new item and return its index
  132.       char *name ;          // name of menu
  133.       Menu *next ;          // next in list
  134.       MenuData *data ;      // actual menu data
  135.       MenuItem *items ;     // list of items
  136.       int num_items ;       // number of items
  137.       int max_items ;       // max space for items
  138.       int max_width ;
  139.       int item_adjust ;     // adjustment for items with separators
  140.    } ;
  141.  
  142. //
  143. // the set of menus in a task
  144. //
  145.  
  146. class MenuSet
  147.    {
  148.    public:
  149.       MenuSet (Task *t, char *filename) ;        // read menu set from file
  150.       ~MenuSet();
  151.       Menu *find (char *name) ;         // find a menu
  152.       void add_menu(Menu *menu);        // add a new menu
  153.    private:
  154.       void parse_menu () ;
  155.       void parse_menu_details(Menu *menu) ;
  156.       void parse_item (Menu *menu) ;
  157.       Menu *menus ;                     // the menus
  158.       Task *task ;
  159.    } ;
  160.  
  161. #endif
  162.