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.
- //
- // *************************************************************************
-
- //
- // window types
- //
-
- #ifndef __wins_h
- #define __wins_h
-
- #ifndef __window_h
- #include "Vista:window.h"
- #endif
-
- #ifndef __datasave_h
- #include "Vista:datasave.h"
- #endif
-
- #ifndef __thread_h
- #include "Vista:thread.h"
- #endif
-
- #include <stdarg.h>
-
- //
- // an IconGrid is a window which contains a set of icons. The icons are
- // flexibly arranged in a grid much like a filer window. Each icon
- // contains some text and is copied from a template icon (which should
- // be hidden in the window)
- //
-
-
- const int ICONGRID_VERT_GAP = 4 ;
- const int ICONGRID_HOR_GAP = 32 ;
-
- const int ICONGRID_LEFT_MARGIN = 10 ;
- const int ICONGRID_TOP_MARGIN = 10 ;
-
-
- class IconGrid : public Window
- {
- public:
- enum flags
- {
- NONE,
- NOSELECT = 0x01, // click doesn't select icons
- NODESELECT = 0x02, // double-click doesn't deselect
- SORTED = 0x04, // keep icons sorted
- } ;
- IconGrid (Task *t, char *tname, int ticon, char *menu = 0) ;
- IconGrid (Window *w, char *tname, int ticon, char *menu = 0) ;
- virtual ~IconGrid() ;
- Icon *insert_icon(char *text, void *ref = 0) ;
- Icon *insert_icon(char *text, char *sprite, void *ref = 0) ;
- void remove_icon (Icon *icon) ; // virtual from Window
- void delete_icon (void *ref) ; // delete icon with ref
- void open (int x0, int y0, int x1, int y1, int scx, int scy, int behind) ;
- void click (int mx, int my, int buttons, int icon) ;
- virtual void double_click (int mx, int my, int buttons, Icon *icon) ;
- virtual void drag_icon (int mx, int my, int buttons, Icon *icon) ;
- virtual void drag_selection (int mx, int my, int buttons, int x0, int y0, int x1, int y1) ;
- Icon *find_icon (int icon) ;
- virtual void select_all () ; // select all icons
- virtual void clear_selection() ; // clear selection
- void drag (int x0, int y0, int x1, int y1, int id) ;
- void set_flag (flags flag) ;
- void clear_flag (flags flag) ;
- virtual void sort() ; // sort the icons
-
- protected:
- Icon *template_icon ; // icon to copy
- int num_icons ; // number of icons in the window
- int num_columns ; // number of columns
- int num_rows ; // number of rows
- int icon_width ; // width of icons
- int icon_height ; // height of icons
- int current_column ; // current column number
- int current_row ; // current row number
- Icon::buttontype template_button_type;
- flags flag_set ;
- int min_height ; // minimum height of window in OS units
-
- void rearrange() ; // rearrange the icons in the window
- void init (int ticon) ; // initialise
- } ;
-
-
- class DialogueBox ;
-
-
- class Attribute
- {
- friend class DialogueBox ;
- public:
- Attribute (DialogueBox *d, int iconnum, char *menu = 0) ;
- Attribute (DialogueBox *d, Icon *icon, char *menu = 0) ;
- Attribute (DialogueBox *d) ;
- virtual ~Attribute() ;
- virtual void get() = 0 ;
- virtual void set() = 0 ;
- virtual void set_caret() ;
- virtual int is_writeable() ;
- Attribute *next ;
- Attribute *prev ;
- protected:
- Icon *icon ;
- char *default_menu ;
- int my_icon ;
- } ;
-
-
- class StringAttribute : public Attribute
- {
- public:
- StringAttribute (DialogueBox *d, char *str, int iconnum, char *menu = 0) ;
- StringAttribute (DialogueBox *d, char *str, Icon *icon, char *menu = 0) ;
- ~StringAttribute() ;
- void get() ;
- void set() ;
- protected:
- char *string ;
- } ;
-
- class BoolAttribute : public Attribute
- {
- public:
- BoolAttribute (DialogueBox *d, bool &v, int iconnum, char *menu = 0) ;
- BoolAttribute (DialogueBox *d, bool &v, Icon *icon, char *menu = 0) ;
- ~BoolAttribute() ;
- void get() ;
- void set() ;
- protected:
- bool *value ;
- } ;
-
- class IntegerAttribute : public Attribute
- {
- public:
- IntegerAttribute (DialogueBox *d, int &number, int iconnum, char *menu = 0) ;
- IntegerAttribute (DialogueBox *d, int &number, Icon *icon, char *menu = 0) ;
- ~IntegerAttribute() ;
- void get() ;
- void set() ;
- protected:
- int *num ;
- } ;
-
- class SetAttribute : public Attribute
- {
- public:
- SetAttribute (DialogueBox *d, bool *set, int num_values, int iconnum ...) ;
- SetAttribute (DialogueBox *d, bool *set, int num_values, Icon *icon ...) ;
- SetAttribute (DialogueBox *d, bool *set, int num_values, va_list ap) ;
- ~SetAttribute() ;
- void get() ;
- void set() ;
- protected:
- bool *values ;
- int num_values ;
- Icon **icons ;
- } ;
-
-
- class DialogueBox : public Window, public Thread
- {
- public:
- DialogueBox (Task *t, char *tname, int cancel = -1, int ok = -1, char *menu = 0) ;
- virtual ~DialogueBox() ;
- void click (int mx, int my, int buttons, int icon) ;
- void key(int icon, int x, int y, int height, int index, int code) ;
- virtual void show() ; // show the dialogue box
- virtual void hide() ; // hide it
- void run() ; // thread main loop
- void close() ;
- Icon *find_icon (int icon) { return NULL ; }
- virtual void cancel(int button) ;
- virtual void ok(int button) ;
- void add_attribute (Attribute *attr) ;
- void create_attribute (int iconnum, char *str) ;
- void create_attribute (int iconnum, int &num) ;
- void create_attribute (int iconnum, bool &value) ;
- void create_attribute (int num_values, bool *values, ...) ;
- void create_attribute (Icon *icon, int &val) ;
- void create_attribute (Icon *icon, char *val) ;
- void create_attribute (Icon *icon, bool &value) ;
- void next_attribute (int icon) ;
- void prev_attribute (int icon) ;
- protected:
- Attribute *attributes ;
- Attribute *last_attribute ;
- Icon *cancel_icon ;
- Icon *ok_icon ;
- ThreadSemaphore *waiting ;
- bool from_menu ;
- bool ok_or_cancel_pressed ;
- public:
- bool cancelled ;
- } ;
-
- class CancelButton : public Icon
- {
- public:
- CancelButton (DialogueBox *d, int iconnum) : Icon (d, iconnum)
- { dbox = d ; }
- ~CancelButton() {}
- void click (int mx, int my, int button, int icon)
- { dbox->cancel (button) ; }
- protected:
- DialogueBox *dbox ;
- } ;
-
- class OKButton: public Icon
- {
- public:
- OKButton (DialogueBox *d, int iconnum) : Icon (d, iconnum)
- { dbox = d ; }
- ~OKButton() {}
- void click (int mx, int my, int button, int icon)
- { dbox->ok (button) ; }
- protected:
- DialogueBox *dbox ;
- } ;
-
- class SaveBox : public DialogueBox
- {
- public:
- SaveBox (Task *t, char *tname, char *path, char *leafname, int type, DataSave *saver) ;
- ~SaveBox() ;
- void drag (int x0, int y0, int x1, int y1, int id) ; // end of drag operation
- void ok(int button) ;
- protected:
- DataSave *saver ;
- char path[256] ;
- Icon *file_icon ;
- Attribute *name ;
- } ;
-
-
- class SaverFile : public Icon
- {
- public:
- SaverFile (SaveBox *box, int type) ;
- ~SaverFile() ;
- void click (int mx, int my, int button, int icon) ;
- protected:
- SaveBox *save_box ;
- char *sprite ;
- } ;
-
- class ProgramInfo : public DialogueBox
- {
- public:
- ProgramInfo (Task *t, int version_icon, char *version) ;
- ~ProgramInfo() ;
- private:
- Icon *version ;
- } ;
-
-
- #endif
-