home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / vista_1 / !Vista_h_wins < prev    next >
Encoding:
Text File  |  1996-01-27  |  8.7 KB  |  285 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. // window types
  30. //
  31.  
  32. #ifndef __wins_h
  33. #define __wins_h
  34.  
  35. #ifndef __window_h
  36. #include "Vista:window.h"
  37. #endif
  38.  
  39. #ifndef __datasave_h
  40. #include "Vista:datasave.h"
  41. #endif
  42.  
  43. #ifndef __thread_h
  44. #include "Vista:thread.h"
  45. #endif
  46.  
  47. #include <stdarg.h>
  48.  
  49. //
  50. // an IconGrid is a window which contains a set of icons.  The icons are
  51. // flexibly arranged in a grid much like a filer window.  Each icon
  52. // contains some text and is copied from a template icon (which should
  53. // be hidden in the window)
  54. //
  55.  
  56.  
  57. const int ICONGRID_VERT_GAP = 4 ;
  58. const int ICONGRID_HOR_GAP = 32 ;
  59.  
  60. const int ICONGRID_LEFT_MARGIN = 10 ;
  61. const int ICONGRID_TOP_MARGIN = 10 ;
  62.  
  63.  
  64. class IconGrid : public Window
  65.    {
  66.    public:
  67.       enum flags
  68.          {
  69.          NONE,
  70.          NOSELECT = 0x01,        // click doesn't select icons
  71.          NODESELECT = 0x02,      // double-click doesn't deselect
  72.          SORTED = 0x04,          // keep icons sorted
  73.          } ;
  74.       IconGrid (Task *t, char *tname, int ticon, char *menu = 0) ;
  75.       IconGrid (Window *w, char *tname, int ticon, char *menu = 0) ;
  76.       virtual ~IconGrid() ;
  77.       Icon *insert_icon(char *text, void *ref = 0) ;
  78.       Icon *insert_icon(char *text, char *sprite, void *ref = 0) ;
  79.       void remove_icon (Icon *icon) ;      // virtual from Window
  80.       void delete_icon (void *ref) ;       // delete icon with ref
  81.       void open (int x0, int y0, int x1, int y1, int scx, int scy, int behind) ;
  82.       void click (int mx, int my, int buttons, int icon) ;
  83.       virtual void double_click (int mx, int my, int buttons, Icon *icon) ;
  84.       virtual void drag_icon (int mx, int my, int buttons, Icon *icon) ;
  85.       virtual void drag_selection (int mx, int my, int buttons, int x0, int y0, int x1, int y1) ;
  86.       Icon *find_icon (int icon) ;
  87.       virtual void select_all () ;       // select all icons
  88.       virtual void clear_selection() ;   // clear selection
  89.       void drag (int x0, int y0, int x1, int y1, int id) ;
  90.       void set_flag (flags flag) ;
  91.       void clear_flag (flags flag) ;
  92.       virtual void sort() ;               // sort the icons
  93.  
  94.    protected:
  95.       Icon *template_icon ;   // icon to copy
  96.       int num_icons ;         // number of icons in the window
  97.       int num_columns ;       // number of columns
  98.       int num_rows ;          // number of rows
  99.       int icon_width ;        // width of icons
  100.       int icon_height ;       // height of icons
  101.       int current_column ;    // current column number
  102.       int current_row ;       // current row number
  103.       Icon::buttontype template_button_type;
  104.       flags flag_set ;
  105.       int min_height ;        // minimum height of window in OS units
  106.  
  107.       void rearrange() ;      // rearrange the icons in the window
  108.       void init (int ticon) ;      // initialise
  109.    } ;
  110.  
  111.  
  112. class DialogueBox ;
  113.  
  114.  
  115. class Attribute
  116.    {
  117.    friend class DialogueBox ;
  118.    public:
  119.       Attribute (DialogueBox *d, int iconnum, char *menu = 0) ;
  120.       Attribute (DialogueBox *d, Icon *icon, char *menu = 0) ;
  121.       Attribute (DialogueBox *d) ;
  122.       virtual ~Attribute() ;
  123.       virtual void get() = 0 ;
  124.       virtual void set() = 0 ;
  125.       virtual void set_caret() ;
  126.       virtual int is_writeable() ;
  127.       Attribute *next ;
  128.       Attribute *prev ;
  129.    protected:
  130.       Icon *icon ;
  131.       char *default_menu ;
  132.       int my_icon ;
  133.    } ;
  134.  
  135.  
  136. class StringAttribute : public Attribute
  137.    {
  138.    public:
  139.       StringAttribute (DialogueBox *d, char *str, int iconnum, char *menu = 0) ;
  140.       StringAttribute (DialogueBox *d, char *str, Icon *icon, char *menu = 0) ;
  141.       ~StringAttribute() ;
  142.       void get() ;
  143.       void set() ;
  144.    protected:
  145.       char *string ;
  146.    } ;
  147.  
  148. class BoolAttribute : public Attribute
  149.    {
  150.    public:
  151.       BoolAttribute (DialogueBox *d, bool &v, int iconnum, char *menu = 0) ;
  152.       BoolAttribute (DialogueBox *d, bool &v, Icon *icon, char *menu = 0) ;
  153.       ~BoolAttribute() ;
  154.       void get() ;
  155.       void set() ;
  156.    protected:
  157.       bool *value ;
  158.    } ;
  159.  
  160. class IntegerAttribute : public Attribute
  161.    {
  162.    public:
  163.       IntegerAttribute (DialogueBox *d, int &number, int iconnum, char *menu = 0) ;
  164.       IntegerAttribute (DialogueBox *d, int &number, Icon *icon, char *menu = 0) ;
  165.       ~IntegerAttribute() ;
  166.       void get() ;
  167.       void set() ;
  168.    protected:
  169.       int *num ;
  170.    } ;
  171.  
  172. class SetAttribute : public Attribute
  173.    {
  174.    public:
  175.       SetAttribute (DialogueBox *d, bool *set, int num_values, int iconnum ...) ;
  176.       SetAttribute (DialogueBox *d, bool *set, int num_values, Icon *icon ...) ;
  177.       SetAttribute (DialogueBox *d, bool *set, int num_values, va_list ap) ;
  178.       ~SetAttribute() ;
  179.       void get() ;
  180.       void set() ;
  181.    protected:
  182.       bool *values ;
  183.       int num_values ;
  184.       Icon **icons ;
  185.    } ;
  186.  
  187.  
  188. class DialogueBox : public Window, public Thread
  189.    {
  190.    public:
  191.       DialogueBox (Task *t, char *tname, int cancel = -1, int ok = -1, char *menu = 0) ;
  192.       virtual ~DialogueBox() ;
  193.       void click (int mx, int my, int buttons, int icon) ;
  194.       void key(int icon, int x, int y, int height, int index, int code) ;
  195.       virtual void show() ;        // show the dialogue box
  196.       virtual void hide() ;        // hide it
  197.       void run() ;                 // thread main loop
  198.       void close() ;
  199.       Icon *find_icon (int icon) { return NULL ; }
  200.       virtual void cancel(int button) ;
  201.       virtual void ok(int button) ;
  202.       void add_attribute (Attribute *attr) ;
  203.       void create_attribute (int iconnum, char *str) ;
  204.       void create_attribute (int iconnum, int &num) ;
  205.       void create_attribute (int iconnum, bool &value) ;
  206.       void create_attribute (int num_values, bool *values, ...) ;
  207.       void create_attribute (Icon *icon, int &val) ;
  208.       void create_attribute (Icon *icon, char *val) ;
  209.       void create_attribute (Icon *icon, bool &value) ;
  210.       void next_attribute (int icon) ;
  211.       void prev_attribute (int icon) ;
  212.    protected:
  213.       Attribute *attributes ;
  214.       Attribute *last_attribute ;
  215.       Icon *cancel_icon ;
  216.       Icon *ok_icon ;
  217.       ThreadSemaphore *waiting ;
  218.       bool from_menu ;
  219.       bool ok_or_cancel_pressed ;
  220.    public:
  221.       bool cancelled ;
  222.    } ;
  223.  
  224. class CancelButton : public Icon
  225.    {
  226.    public:
  227.       CancelButton (DialogueBox *d, int iconnum) : Icon (d, iconnum)
  228.          { dbox = d ; }
  229.       ~CancelButton() {}
  230.       void click (int mx, int my, int button, int icon)
  231.          { dbox->cancel (button) ; }
  232.    protected:
  233.       DialogueBox *dbox ;
  234.    } ;
  235.  
  236. class OKButton: public Icon
  237.    {
  238.    public:
  239.       OKButton (DialogueBox *d, int iconnum) : Icon (d, iconnum)
  240.          { dbox = d ; }
  241.       ~OKButton() {}
  242.       void click (int mx, int my, int button, int icon)
  243.          { dbox->ok (button) ; }
  244.    protected:
  245.       DialogueBox *dbox ;
  246.    } ;
  247.  
  248. class SaveBox : public DialogueBox
  249.    {
  250.    public:
  251.       SaveBox (Task *t, char *tname, char *path, char *leafname, int type, DataSave *saver) ;
  252.       ~SaveBox() ;
  253.       void drag (int x0, int y0, int x1, int y1, int id) ;   // end of drag operation
  254.       void ok(int button) ;
  255.    protected:
  256.       DataSave *saver ;
  257.       char path[256] ;
  258.       Icon *file_icon ;
  259.       Attribute *name ;
  260.    } ;
  261.  
  262.  
  263. class SaverFile : public Icon
  264.    {
  265.    public:
  266.       SaverFile (SaveBox *box, int type) ;
  267.       ~SaverFile() ;
  268.       void click (int mx, int my, int button, int icon) ;
  269.    protected:
  270.       SaveBox *save_box ;
  271.       char *sprite ;
  272.    } ;
  273.  
  274. class ProgramInfo : public DialogueBox
  275.    {
  276.    public:
  277.       ProgramInfo (Task *t, int version_icon, char *version) ;
  278.       ~ProgramInfo() ;
  279.    private:
  280.       Icon *version ;
  281.    } ;
  282.  
  283.  
  284. #endif
  285.