home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
v
/
vista
/
c
/
task
< prev
next >
Wrap
Text File
|
1996-02-01
|
36KB
|
1,323 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.
//
// *************************************************************************
//
// c.task
//
#include "Vista:task.h"
#include <kernel.h>
#include <swis.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <signal.h>
#include <setjmp.h>
ControlThread::ControlThread(Task *t, int event, int *buf)
: Thread ("control")
{
task = t ;
next = NULL ;
init (event, buf) ;
}
ControlThread::~ControlThread()
{
}
void ControlThread::init(int event, int *buf)
{
this->event = event ;
memcpy (this->buf, buf, sizeof (this->buf)) ;
}
void ControlThread::run()
{
int caught = 0 ;
Window *w ;
_kernel_oserror err ;
_kernel_oserror *e ;
_kernel_swi_regs r ;
int adjust_hit ; // adjust was hit on menu
Object *object ;
#ifdef __EASY_C
try
#endif
{
switch (event)
{
case Task::ENULL:
break ;
case Task::EREDRAW: /* this is handled as a special case */
#if 0
w = task->find_window (buf[0]) ;
if (w == NULL)
break ;
w->redraw() ;
#endif
break ;
case Task::EOPEN:
w = task->find_window (buf[0]) ;
if (w == NULL)
break ;
w->open(buf[1],buf[2],buf[3],buf[4], buf[5], buf[6], buf[7]) ;
break ;
case Task::ECLOSE:
w = task->find_window (buf[0]) ;
if (w == NULL)
break ;
w->close() ;
break ;
case Task::EPTRLEAVE:
case Task::EPTRENTER:
w = task->find_window (buf[0]) ;
if (w == NULL)
break ;
w->pointer (event == Task::EPTRENTER) ;
break ;
case Task::EBUT:
if (buf[3] >= 0) // in a window?
{
w = task->find_window (buf[3]) ; // find the window
if (w == NULL)
break ;
if (buf[2] & Task::BMID) // menu button?
{
Icon *icon ;
bool found = false ;
if (buf[4] != -1 && (icon = w->find_icon(buf[4])) != NULL) // find icon
{
task->current_menu = icon->display_menu (buf[0], buf[1], buf[2], buf[4]) ;
if (task->current_menu != NULL)
{
found = true ;
task->current_menu_icon = icon ;
}
}
if (!found && (object = w->find_object (buf[0], buf[1])) != NULL) // find object
{
task->current_menu = object->display_menu (buf[0], buf[1], buf[2], buf[4]) ;
if (task->current_menu != NULL)
{
found = true ;
task->current_menu_object = object ;
}
}
if (!found)
{
task->current_menu = w->display_menu (buf[0], buf[1], buf[2], buf[4]) ;
task->current_menu_window = w ;
}
}
else
{
if (buf[4] != -1) // on an icon?
{
Icon *icon ;
if ((icon = w->find_icon(buf[4])) != NULL) // find it
{
icon->click (buf[0], buf[1], buf[2], buf[4]) ; // say clicked
break ;
}
}
if ((object = w->find_object (buf[0], buf[1])) != NULL)
{
if (buf[2] & (4 * 16 + 16))
object->drag (buf[0], buf[1], buf[2]) ;
else if (buf[2] & (4 + 1))
object->double_click (buf[0], buf[1], buf[2]) ;
else
object->click (buf[0], buf[1], buf[2]) ;
}
else
w->click(buf[0], buf[1], buf[2], buf[4]) ; // tell window
}
}
else if (buf[3] == -2) // icon bar
{
task->current_menu_window = NULL ; // no window
task->current_menu_icon = NULL ; // no icon
task->current_menu_object = NULL ; // no object
if (buf[2] & Task::BMID)
{
if (task->iconbar_menu != NULL)
{
task->current_menu = task->iconbar_menu ;
task->pre_menu (task->iconbar_menu) ; // any user modifications
task->iconbar_menu->iconbar_adjust (buf[0], buf[1]) ;
task->iconbar_menu->open(buf[0] - 48, buf[1]) ;
}
else
{
char *menu_name = task->get_iconbar_menu (buf[4]) ;
if (menu_name != NULL)
{
task->current_menu = task->menus->find (menu_name) ;
task->current_menu->iconbar_adjust (buf[0], buf[1]) ;
task->current_menu->open (buf[0] - 48, buf[1]) ;
}
}
}
else
task->click (buf[0], buf[1], buf[2], buf[4]) ;
}
break ;
case Task::EUSERDRAG:
if (task->dragging_sprite)
{
_kernel_swi (DragASprite_Stop, &r, &r) ;
task->dragging_sprite = false ;
}
if (task->object_dragger != NULL)
{
task->object_dragger->end_drag (buf[0], buf[1], buf[2], buf[3], task->object_dragger_id) ;
task->object_dragger = NULL ;
}
if (task->dragger != NULL)
{
task->dragger->drag(buf[0], buf[1], buf[2], buf[3],task->dragger_id) ;
task->dragger = NULL ;
}
break ;
case Task::EKEY:
w = task->find_window (buf[0]) ;
if (w == NULL)
break ;
if (buf[1] != -1) // pressed in an icon?
{
Icon *icon ;
if ((icon = w->find_icon(buf[1])) != NULL) // find it
{
icon->key (buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]) ; // say key pressed
break ;
}
}
if ((object = w->find_object (buf[0], buf[1])) != NULL)
object->key (buf[2], buf[3], buf[4], buf[5], buf[6])