home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / v / vista / Examples / !MyApps / h / myapps
Encoding:
Text File  |  1996-01-25  |  5.3 KB  |  199 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.  
  30. #ifndef __myapps_h
  31. #define __myapps_h
  32.  
  33. #include "Vista:vista.h"
  34. #include <stdio.h>
  35.  
  36. class MyApps ;
  37.  
  38. //
  39. // abstract class for object within window.  An instance of this class is
  40. // held with each icon in a window.  The user_ref of the icon points
  41. // to the instance
  42. //
  43.  
  44. class AppObject
  45.    {
  46.    public:
  47.       AppObject (Task *task, char *name) ;
  48.       AppObject (Task *task, char *name, char *sprite) ;
  49.       ~AppObject() ;
  50.       char *name ;                            // name in the directory
  51.       char *sprite ;                          // name of the sprite
  52.       virtual void rename(char *newname) ;    // give a new name
  53.       virtual void run() = 0 ;                // pure virtual run function (depends on derived class)
  54.    protected:
  55.       Task *task ;
  56.    } ;
  57.  
  58.  
  59. class AppGrid : public IconGrid
  60.    {
  61.    enum menu_items
  62.       {
  63.       APP,
  64.       NEW,
  65.       SELECT_ALL,
  66.       CLEAR_SEL,
  67.       SET_NAME
  68.       } ;
  69.    enum app_menu_items
  70.       {
  71.       RENAME,
  72.       REMOVE
  73.       } ;
  74.    public:
  75.       AppGrid (MyApps *myapps, bool ismain = false) ;
  76.       ~AppGrid() ;
  77.       void double_click (int mx, int my, int buttons, Icon *icon) ;    // double click on an icon
  78.       void pre_menu(Menu *m, int x, int y, int button, int icon) ;          // modify menu before display
  79.       void menu(MenuItem items[]) ;                                         // menu hit
  80.       void add_object (char *path) ;                                        // add a new object
  81.       void add_object (AppGrid *, char *) ;
  82.       AppGrid *next ;
  83.       AppGrid *prev ;
  84.    private:
  85.       AppObject *current_object ;
  86.       Icon *current_icon ;
  87.       int num_selected ;
  88.       MyApps *myapps ;
  89.       bool ismain ;
  90.    } ;
  91.  
  92. //
  93. // This application object represents a file with a path on disk
  94. //
  95.  
  96. class PathAppObject : public AppObject
  97.    {
  98.    public:
  99.       PathAppObject (Task *task, char *name, char *path) ;
  100.       ~PathAppObject() ;
  101.    protected:
  102.       char path[256] ;          // real path of object
  103.    } ;
  104.  
  105. //
  106. // This represents an application on disk
  107. //
  108.  
  109.  
  110. class ApplicationAppObject : public PathAppObject
  111.    {
  112.    public:
  113.       ApplicationAppObject (Task *task, char *name, char *path) ;
  114.       ~ApplicationAppObject() ;
  115.       void run() ;
  116.    } ;
  117.  
  118. // a directory
  119.  
  120. class DirAppObject : public PathAppObject
  121.    {
  122.    public:
  123.       DirAppObject (Task *task, char *name, char *path) ;
  124.       ~DirAppObject() ;
  125.       void run() ;
  126.    } ;
  127.  
  128. // a normal file
  129.  
  130. class FileAppObject : public PathAppObject
  131.    {
  132.    public:
  133.       FileAppObject (Task *task, char *name, char *path, int type) ;
  134.       ~FileAppObject() ;
  135.       void run() ;
  136.    } ;
  137.  
  138. //
  139. // This is one of my own windows
  140. //
  141.  
  142. class GridAppObject : public AppObject
  143.    {
  144.    public:
  145.       GridAppObject (Task *task, char *name, AppGrid *grid) ;
  146.       ~GridAppObject() ;
  147.       void run() ;
  148.       void rename (char *) ;
  149.    protected:
  150.       AppGrid *grid ;
  151.    } ;
  152.  
  153.  
  154. //
  155. // this class loads files into the icon grid
  156. //
  157.  
  158. class Loader: public DataSave
  159.    {
  160.    public:
  161.       Loader(MyApps *myapps) ;
  162.       ~Loader() ;
  163.       void receive (int action, int task, int my_ref, int your_ref, int data_length, void *data) ;   // receive a message
  164.    private:
  165.       MyApps *myapps ;
  166.    } ;
  167.  
  168. //
  169. // This class is the task itself.  The icon bar has a menu with 2 items.  The task responds
  170. // to clicks on the icon bar (click() function) and menu hits (menu() function).  Private
  171. // data includes the main window object.
  172. //
  173.  
  174.  
  175. class MyApps : public Task
  176.    {
  177.    enum menu_items
  178.       {
  179.       INFO,                          // program info
  180.       QUIT                           // quit application
  181.       } ;
  182.    public:
  183.       MyApps() ;
  184.       ~MyApps() ;
  185.       void save() ;
  186.       void click(int x, int y, int buttons, int icon) ;   // icon bar click
  187.       void menu (MenuItem items[]) ;                     // iconbar menu hit
  188.       AppGrid *find_grid (int window_handle) ;
  189.       void add_grid (AppGrid *) ;
  190.       void remove_grid (AppGrid*) ;
  191.    private:
  192.       Loader *loader ;
  193.       AppGrid *main_grid ;
  194.       AppGrid *grids, *last_grid ;
  195.       int num_grids ;
  196.    } ;
  197.  
  198. #endif
  199.