home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / vista_1 / !Vista_h_icon < prev    next >
Encoding:
Text File  |  1996-01-25  |  7.6 KB  |  202 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. #ifndef __icon_h
  30. #define __icon_h
  31.  
  32. #include "Vista:defs.h"
  33.  
  34. class Window ;
  35.  
  36. struct Box
  37.    {
  38.    int x0 ;
  39.    int y0 ;
  40.    int x1 ;
  41.    int y1 ;
  42.    } ;
  43.  
  44. union IconData
  45.    {
  46.    char text[12] ;
  47.    char sprite_name[12] ;
  48.    struct indirectsprite
  49.       {
  50.       char *name ;
  51.       void *spritearea ;
  52.       int nameisname ;
  53.       } indirectsprite ;
  54.    struct indirecttext
  55.       {
  56.       char *buffer ;
  57.       char *validstring ;
  58.       int bufflen;
  59.       } indirecttext ;
  60.    } ;
  61.  
  62. #ifndef __menu_h
  63. #include "Vista:menu.h"
  64. #endif
  65.  
  66. class Icon
  67.    {
  68.    friend class Window ;
  69.  
  70.    public:
  71.       enum iconflags {                  /* icon flag set */
  72.            ITEXT      = 0x00000001,     /* icon contains text */
  73.            ISPRITE    = 0x00000002,     /* icon is a sprite */
  74.            IBORDER    = 0x00000004,     /* icon has a border */
  75.            IHCENTRE   = 0x00000008,     /* text is horizontally centred */
  76.            IVCENTRE   = 0x00000010,     /* text is vertically centred */
  77.            IFILLED    = 0x00000020,     /* icon has a filled background */
  78.            IFONT      = 0x00000040,     /* text is an anti-aliased font */
  79.            IREDRAW    = 0x00000080,     /* redraw needs application's help */
  80.            INDIRECT   = 0x00000100,     /* icon data is 'indirected' */
  81.            IRJUST     = 0x00000200,     /* text right justified in box */
  82.            IESG_NOC   = 0x00000400,     /* if selected by right button, don't
  83.                                          * cancel other icons in same ESG */
  84.            IHALVESPRITE=0x00000800,     /* plot sprites half-size */
  85.            IBTYPE     = 0x00001000,     /* 4-bit field: button type */
  86.            ISELECTED  = 0x00200000,     /* icon selected by user (inverted) */
  87.            INOSELECT  = 0x00400000,     /* icon cannot be selected (shaded) */
  88.            IDELETED   = 0x00800000,     /* icon has been deleted */
  89.            IFORECOL   = 0x01000000,     /* 4-bit field: foreground colour */
  90.            IBACKCOL   = 0x10000000      /* 4-bit field: background colour */
  91.            } ;
  92.       enum buttontype {                /* button types */
  93.            BIGNORE,               /* ignore all mouse ops */
  94.            BNOTIFY,
  95.            BCLICKAUTO,
  96.            BCLICKDEBOUNCE,
  97.            BSELREL,
  98.            BSELDOUBLE,
  99.            BDEBOUNCEDRAG,
  100.            BRELEASEDRAG,
  101.            BDOUBLEDRAG,
  102.            BSELNOTIFY,
  103.            BCLICKDRAGDOUBLE,
  104.            BCLICKSEL,              /* useful for on/off and radio buttons */
  105.            BWRITABLE = 15
  106.            } ;
  107.        enum Direction
  108.           {
  109.           UP,
  110.           DOWN,
  111.           LEFT,
  112.           RIGHT
  113.           } ;
  114.        enum ColourMask
  115.           {
  116.           ForeMask = (15 << 24),
  117.           BackMask = (15 << 28)
  118.           } ;
  119.    public:
  120.       Icon(int priority, int window, int x0, int y0, int x1, int y1, iconflags flags, IconData *data, void *ref = 0) ;
  121.       Icon(Window *w, int iconnum = -1, void *ref = 0, char *menu = 0) ;   // create an icon in a window
  122.       Icon() ;
  123.       Icon(Window *w,Icon *temp, Direction direction = DOWN, int gap = 0, void *ref = 0, char *menu = 0) ;  // create using a template
  124.       Icon(Window *w,Icon *temp, int x, int y, void *ref = 0, char *menu = 0) ;  // create using a template
  125.       virtual ~Icon() ;                             // delete the icon
  126.  
  127.       void attach (Window *w, int iconnum) ;   // attach the icon to a window
  128.       void move (int dx, int dy) ;
  129.       void move (Direction direction, int dist) ;
  130.       void move_to (int x, int y) ;
  131.       void resize (int width, int height) ;
  132.       void read_position (Box &pos) ;
  133.       void plot() ;
  134.       virtual void set_caret() ;                         // set the caret (if writeable)
  135.       virtual void drag (int mx, int my, int buttons) ;  // drag the icon
  136.       virtual void redraw (int x0, int y0, int x1, int y1) ;
  137.       virtual void click(int mx, int my, int button, int icon) ;   // icon has been clicked
  138.       virtual void key (int icon,  int x, int y, int height, int index, int code) ;
  139.       virtual void select() ;                  // select the icon
  140.       virtual void unselect() ;                // unselect the icon
  141.       virtual void fade() ;                    // fade the icon to grey
  142.       virtual void unfade() ;                  // unfade the icon
  143.       virtual void set_fore_colour (int colour) ;   // set foreground colour
  144.       virtual void set_back_colour (int colour) ;   // set background colour
  145.       virtual int is_writeable() ;             // is the icon writeable
  146.       virtual int is_selected() ;              // is the icon selected
  147.       virtual void print (char *format,...) ;  // print a string to an icon
  148.       virtual void change_sprite (char *sprite_name, int area = 1) ;
  149.       virtual void read_sprite (char *sprite_name) ;
  150.       virtual void read (char *s) ;
  151.       virtual void read (int &n) ;
  152.       virtual void read (float &n) ;
  153.       virtual void read (double &n) ;
  154.       virtual void write (char *s) ;
  155.       virtual void write (int n) ;
  156.       virtual void write (float n) ;
  157.       virtual void write (double n) ;
  158.  
  159.       virtual int compare(int icon) ;          // compare icon handle
  160.       virtual int compare (Icon *icon) ;       // compare contents with icon
  161.       virtual char *help (int mx, int my, int button) ;   // give help
  162.  
  163.       Menu *display_menu (int x, int y, int button, int icon) ;
  164.       virtual void pre_menu(Menu *m, int x, int y, int button, int icon) ;
  165.       virtual char *get_menu (int x, int y, int button, int icon) ;
  166.       virtual void menu(MenuItem items[]) ;
  167.  
  168.    public:
  169.       int handle ;                // WIMP icon handle
  170.       Window *window ;            // window I belong to
  171.       Icon *next ;                // next icon list
  172.       Icon *prev ;                // previous icon in list
  173.       void *user_ref ;            // user reference
  174.       Menu *default_menu ;        // default menu
  175.       bool delete_wimp_icon ;     // delete the wimp icon upon deletion
  176.    } ;
  177.  
  178.  
  179. class IconSet
  180.    {
  181.    public:
  182.       IconSet (int num_icons) ;
  183.       ~IconSet() ;
  184.       int compare(int icon) ;
  185.       void add_icon(int icon) ;
  186.       virtual void select (int icon) ;
  187.       virtual void select();
  188.       virtual void fade(int icon) ;
  189.       virtual void fade() ;
  190.       virtual void unselect (int icon) ;
  191.       virtual void unselect();
  192.       virtual void unfade(int icon) ;
  193.       virtual void unfade() ;
  194.    protected:
  195.       int max_icons ;
  196.       int num_icons ;
  197.       int *icons ;         // dynamic array
  198.    } ;
  199.  
  200.  
  201. #endif
  202.