home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 2
/
AUCD2.iso
/
program
/
vista.arc
/
!Vista
/
h
/
task
< prev
next >
Wrap
Text File
|
1996-01-27
|
12KB
|
354 lines
// **************************************************************************
// 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.
//
// *************************************************************************
//
// wimp task
//
#ifndef __task_h
#define __task_h
#include "Vista:defs.h"
#include "Vista:delete.h"
#ifndef __thread_h
#include "Vista:thread.h"
#endif
#ifndef __msgtrans_h
#include "Vista:msgtrans.h"
#endif
#ifndef __template_h
#include "Vista:template.h"
#endif
#ifndef __window_h
#include "Vista:window.h"
#endif
#ifndef __channel_h
#include "Vista:channel.h"
#endif
#ifndef NULL
#define NULL 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
extern void print (char * ...) ;
class Task ;
class ControlThread : public Thread
{
public:
ControlThread (Task *, int event, int *buf) ;
~ControlThread() ;
void run() ;
void init(int event, int *buf) ;
ControlThread *next ;
private:
Task *task ;
int buf[256/sizeof(int)] ; // event buffer
int event ;
} ;
class DebugWin : public Window
{
public:
DebugWin (Task *) ;
~DebugWin() ;
void print (char *format...) ;
private:
TextObject *text ;
int min_height ;
} ;
struct sprite_area
{
int size ;
int number ;
int sproff ;
int freeoff ;
} ;
class Task
{
friend class ControlThread ;
public:
enum events
{
ENULL, /* null event */
EREDRAW, /* redraw event */
EOPEN,
ECLOSE,
EPTRLEAVE,
EPTRENTER,
EBUT, /* mouse button change */
EUSERDRAG,
EKEY,
EMENU,
ESCROLL,
ELOSECARET,
EGAINCARET,
EPOLLNONZERO,
ESEND = 17, /* send message, don't worry if it doesn't arrive */
ESENDWANTACK = 18, /* send message, return ack if not acknowledged */
EACK = 19 /* acknowledge receipt of message. */
} ;
enum Buttons
{
BRIGHT = 0x001,
BMID = 0x002,
BLEFT = 0x004,
BDRAGRIGHT = 0x010,
BDRAGLEFT = 0x040,
BCLICKRIGHT = 0x100,
BCLICKLEFT = 0x400
} ;
enum Messages
{
Message_Quit = 0,
Message_DataSave = 1,
Message_DataSaveAck = 2,
Message_DataLoad = 3,
Message_DataLoadAck = 4,
Message_DataOpen = 5,
Message_RAMFetch = 6,
Message_RAMTransmit = 7,
Message_PreQuit = 8,
Message_PaletteChange = 9,
Message_SaveDesktop = 10,
Message_DeviceClaim = 11,
Message_DeviceInUse = 12,
Message_DataSaved = 13,
Message_Shutdown = 14,
Message_FilerOpenDir = 0x0400,
Message_FilerCloseDir = 0x0401,
Message_FilerOpenDirAt = 0x0402,
Message_FilerSelectionDirectory = 0x0403,
Message_FilerAddSelection = 0x0404,
Message_FilerAction = 0x0405,
Message_FilerControlAction = 0x0406,
Message_FilerSelection = 0x0407,
Message_Notify = 0x40040,
Message_MenuWarning = 0x400c0,
Message_ModeChange = 0x400c1,
Message_TaskInitialise = 0x400c2,
Message_TaskCloseDown = 0x400c3,
Message_SlotSize = 0x400c4,
Message_SetSlot = 0x400c5,
Message_TaskNameRq = 0x400c6,
Message_TaskNameIs = 0x400c7,
Message_TaskStarted = 0x400c8,
Message_MenusDeleted = 0x400c9,
Message_Iconize = 0x400ca,
Message_WindowClosed = 0x400cb,
Message_WindowInf = 0x400cc,
Message_AlarmSet = 0x500,
Message_AlarmGoneOff = 0x501,
Message_HelpRequest = 0x502,
Message_HelpReply = 0x503,
Message_PrintFile = 0x80140,
Message_WillPrint = 0x80141,
Message_WPrintSave = 0x80142,
Message_PrintInit = 0x80143,
Message_PrintError = 0x80144,
Message_PrintTypeOdd = 0x80145,
Message_PrintTypeUnknown = 0x80146,
Message_SetPrinter = 0x80147,
Message_PSPrinterQuery = 0x8014c,
Message_PSPrinterAck = 0x8014d,
Message_PSPrinterModified = 0x8014e,
Message_PSPrinterDefaults = 0x8014f,
Message_PSPrinterDefaulted = 0x80150,
Message_PSPrinterNotPS = 0x80151,
Message_ResetPrinter = 0x80152,
Message_PSIsFontPrintRunning = 0x80153,
TaskWindow_Input = 0x808c0,
TaskWindow_Output = 0x808c1,
TaskWindow_Ego = 0x808c2,
TaskWindow_Morio = 0x808c3,
TaskWindow_Morite = 0x808c4,
TaskWindow_NewTask = 0x808c5,
TaskWindow_Suspend = 0x808c6,
TaskWindow_Resume = 0x808c7
} ;
struct receiver
{
int message ;
Channel *channel ;
receiver *next ;
receiver *prev ;
receiver(Channel *ch, int m)
{
channel = ch ;
message = m ;
next = prev = NULL ;
}
} ;
public:
Task (char *taskname, char *applname, char *spritename, char *iconmenu = NULL, int pri = 0, int position = -1,
int wimp_version = 200, int *message_list = 0) ;
Task (char *taskname, char *applname,int wimp_version = 310, int *message_list = 0) ; // no icon on iconbar
Task (char *taskname, char *applname, Icon *iconbar, char *iconmenu = NULL, int pri = 0, int position = -1,
int wimp_version = 200, int *message_list = 0) ;
virtual ~Task() ;
void set_mask(int m) { poll_mask = m ; }
void run() ; // run the task
void exit(int status = 0) ;
void sleep (ThreadResource *, int pri = THREAD_BASE_PRIORITY) ; // sleep on a thread
void sleep (int time) ; // sleep for a number of centiseconds
void yield() ;
int spawn (char *command...) ; // spawn another task, return task handle
void add_window (Window *w) ; // add a window
void remove_window (Window *w) ; // remove a window
void delete_window (Window *w) ; // delete a window
void delete_deferred (DeferredDelete *) ; // add a deferred deletion
Window *find_window (int handle) ; // find a window
void *find_template(char *name) // find a template
{
return templates->find(name) ;
}
void free_template (void *defn)
{
templates->free (defn) ;
}
Menu *find_menu (char *name) // find a menu
{
return menus->find (name) ;
}
virtual char *get_iconbar_menu(int icon) ; // get a new menu
virtual void menu(MenuItem items[]) ; // menu hit
virtual void click(int x, int y, int buttons, int icon) ; // icon bar click
char *lookup(char *token)
#ifdef __EASY_C
{
char *s ;
if ((s = messages->lookup(token)) != NULL)
return s ;
return token ;
}
#else // cfront gives a 'sorry not implemented' error is this is inline
;
#endif
void send_message (events event, int action, int &task, int &my_ref, int your_ref, int data_length, void *data, int icon = 0) ;
void print (char *format,...) ;
virtual void pre_menu (Menu *menu) ; // give user a chance to adjust menu
void register_drag (Window *dragger, int id, bool dragging_sprite = false) ;
void register_object_drag (Object *dragger, int id, bool dragging_sprite = false) ;
void add_receiver (Channel *channel, int message) ;
void remove_receiver (Channel *channel, int message) ;
receiver *find_receiver (int message, int your_ref) ;
int open_font (char *name, int xisize, int ysize) ;
void close_font (int handle) ;
void spawn_control_thread(int event, int *buf) ;
void enter_critical() ;
void exit_critical() ;
void *find_sprite (char *name) ;
virtual void poll_word_non_zero (int *poll_word, int contents) ;
void set_menu (Menu *menu, Icon *icon) ;
void set_menu (Menu *menu, Object *object) ;
void set_menu (Menu *menu, Window *window) ;
virtual char *help (int mx, int my, int button, int window, int icon) ; // give help outside a window
void show_threads() ;
public:
events last_event ;
int last_event_data [256 / sizeof (int)] ;
Window *windows ; // windows in this task
Window *last_window ;
Template *templates ; // templates
MenuSet *menus ; // menus
MsgTrans *messages ; // messages
int poll_mask ;
int xeigfactor ; // shift for x pixel to os unit
int yeigfactor ; // shift for y pixel to os unit
Icon *iconbar_icon ; // iconbar icon
private:
void init(char *taskname, char *applname, char *iconmenu, int wimp_version, int *message_list) ;
int initialised ; // task is initialised
int running ;
int resume_pending ;
sprite_area *spr_area ;
char icon_name[12] ;
int icon_handle ;
Menu *current_menu ; // menu currently being displayed
Window *current_menu_window ; // window menu belongs to
Icon *current_menu_icon ; // icon menu belongs to
Object *current_menu_object ; // object menu belongs to
Menu *iconbar_menu ; // default iconbar menu
Window *dragger ; // window dragging
int dragger_id ;
Object *object_dragger ; // object being dragged
int object_dragger_id ; // id for object dragger
bool dragging_sprite ; // am I dragging a sprite?
int waiting ; // waiting (counter)
receiver *receivers ;
receiver *last_receiver ;
int num_open_fonts ;
int max_open_fonts ;
int *open_fonts ;
ThreadManager *thread_manager ;
ControlThread *control_threads ;
int threads_running ;
DeferredDelete *deferred_deletions ;
public:
DebugWin *debug ; // debugger display window
char *program ;
int handle ; // handle assigned by WIMP
char country[50] ;
} ;
class TaskError
{
public:
TaskError (int f, char *format ...) ;
char buf[256] ;
int fatal ;
} ;
#endif