home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
v
/
vista
/
c
/
icon
< prev
next >
Wrap
Text File
|
1996-02-01
|
23KB
|
962 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.icon
//
#include "Vista:icon.h"
#include "Vista:window.h"
#include <kernel.h>
#include <stdlib.h>
#include <swis.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include "Vista:task.h"
#include <ctype.h>
Icon::Icon() // default constructor
{
}
Icon::Icon (int priority, int window, int x0, int y0, int x1, int y1, iconflags flags, IconData *data, void *ref)
{
_kernel_swi_regs r ;
_kernel_oserror *e ;
int icon[9] ;
r.r[0] = priority ;
r.r[1] = (int)icon ;
icon[0] = window ;
icon[1] = x0 ;
icon[2] = y0 ;
icon[3] = x1 ;
icon[4] = y1 ;
icon[5] = (int)flags ;
memcpy (&icon[6], data, sizeof (IconData)) ;
if ((e = _kernel_swi (Wimp_CreateIcon, &r, &r)) != NULL)
throw (e) ;
delete_wimp_icon = true ;
window = NULL ;
handle = r.r[0] ;
prev = NULL ;
next = NULL ;
user_ref = ref ;
default_menu = NULL ;
}
Icon::Icon (Window *w, int iconnum, void *ref, char *menu)
{
prev = NULL ;
next = NULL ;
user_ref = ref ;
if (menu == NULL)
default_menu = NULL ;
else
{
default_menu = w->task->find_menu (menu) ;
if (default_menu == NULL)
throw ("Unknown menu") ;
}
delete_wimp_icon = false ;
attach (w,iconnum) ;
}
Icon::~Icon()
{
if (window != NULL)
{
if (delete_wimp_icon)
{
_kernel_swi_regs r ;
_kernel_oserror *e ;
int block[2] ;
r.r[1] = (int)block ;
block[0] = window->handle ;
block[1] = handle ;
if ((e = _kernel_swi (Wimp_DeleteIcon, &r, &r)) != NULL)
throw (e) ;
}
window->remove_icon (this) ;
}
}
Icon::Icon (Window *w, Icon *temp, Direction direction, int gap, void *ref, char *menu)
{
_kernel_swi_regs r ;
_kernel_oserror *e ;
int block[40] ;
if (menu == NULL)
default_menu = NULL ;
else
{
default_menu = w->task->find_menu (menu) ;
if (default_menu == NULL)
throw ("Unknown menu") ;
}
block[0] = w->handle ;
block[1] = temp->handle ;
r.r[1] = (int)block ;
if ((e = _kernel_swi (Wimp_GetIconState, &r, &r)) != NULL)
throw (e) ;
int size ;
Box *box = (Box*)&block[2] ;
IconData *data = (IconData*)&block[7] ;
switch (direction)
{
case UP:
size = box->y1 - box->y0 + gap ;
box->y0 += size ;
box->y1 += size ;
break ;
case DOWN:
size = box->y1 - box->y0 + gap ;
box->y0 -= size ;
box->y1 -= size ;
break ;
case LEFT:
size = box->x1 - box->x0 + gap ;
box->x0 -= size ;
box->x1 -= size ;
break ;
case RIGHT:
size = box->x1 - box->x0 + gap ;
box->x0 += size ;
box->x1 += size ;
break ;
}
if (block[6] & INDIRECT && block[6] & ITEXT)
{
char *p = (char*)malloc (data->indirecttext.bufflen) ;
if (p == NULL)
throw ("Out of Memory") ;
data->indirecttext.buffer = p ;
p[0] = 0 ;
}
block[1] = w->handle ; // copy window handle to right place
r.r[1] = (int)&block[1] ;
if ((e = _kernel_swi (Wimp_CreateIcon, &r, &r)) != NULL)
throw (e) ;
prev = NULL ;
next = NULL ;
user_ref = ref ;
delete_wimp_icon = true ;
attach (w,r.r[0]) ;
}
Icon::Icon (Window *w, Icon *temp, int x, int y, void *ref, char *menu)
{
_kernel_swi_regs r ;
_kernel_oserror *e ;
int block[40] ;
if (menu == NULL)
default_menu = NULL ;
else
{
default_menu = w->task->find_menu (menu) ;
if (default_menu == NULL)
throw ("Unknown menu") ;
}
block[0] = w->handle ;
block[1] = temp->handle ;
r.r[1] = (int)block ;
if ((e = _kernel_swi (Wimp_GetIconState, &r, &r)) != NULL)
throw (e) ;
int xsize, ysize ;
Box *box = (Box*)&block[2] ;
IconData *data = (IconData*)&block[7] ;
xsize = box->x1 - box->x0 ;
ysize = box->y1 - box->y0 ;
box->x0 = x ;
box->x1 = box->x0 + xsize ;
box->y0 = y ;
box->y1 = box->y0 + ysize ;
if (block[6] & INDIRECT && block[6] & ITEXT)
{
char *p = (char*)malloc (data->indirecttext.bufflen) ;
if (p == NULL)
throw ("Out of Memory") ;
data->indirecttext.buffer = p ;
p[0] = 0 ;
}
block[1] = w->handle ; // copy window handle to right place
r.r[1] = (int)&block[1] ;
if ((e = _kernel_swi (Wimp_CreateIcon, &r, &r)) != NULL)
throw (e) ;
prev = NULL ;
next = NULL ;
user_ref = ref ;
delete_wimp_icon = true ;
attach (w,r.r[0]) ;
}
void Icon::attach (Window *w, int iconnum)
{
window = w ;
handle = iconnum ;
w->add_icon (this) ;
}
void Icon::move (int dx, int dy)
{
_kernel_swi_regs r ;
_kernel_oserror *e ;
int block[40] ;
int delblock[2] ;
block[0] = window->handle ;
block[1] = handle ;
r.r[1] = (int)block ;
if ((e = _kernel_swi (Wimp_GetIconState, &r, &r)) != NULL)
throw (e) ;
Box *box = (Box*)&block[2] ;
box->x0 += dx ;
box->x1 += dx ;
box->y0 += dy ;
box->y1 += dy ;
delblock[0] = window->handle ;
delblock[1] = handle ;
r.r[1] = (int)delblock ;
if ((e = _kernel_swi (Wimp_DeleteIcon, &r, &r)) != NULL)
throw (e) ;
r.r[1] = (int)&block[1] ;
r.r[0] = handle ;
block[1] = window->handle ; // set window handle
if ((e = _kernel_swi (Wimp_CreateIcon, &r, &r)) != NULL)
throw (e) ;
r.r[0] = window->handle ;
r.r[1] = block[2] ;
r.r[2] = block[3] ;
r.r[3] = block[4] ;
r.r[4] = block[5] ;
if ((e = _kernel_swi (Wimp_ForceRedraw, &r, &r)) != NULL)
throw (e) ;
}
void Icon::move (Direction direction, int dist)
{
_kernel_swi_regs r ;
_kernel_oserror *e ;
int block[40] ;
int delblock[2] ;
block[0] = window->handle ;
block[1] = handle ;
r.r[1] = (int)block ;
if ((e = _kernel_swi (Wimp_GetIconState, &r, &r)) != NULL)
throw (e) ;
Box *box = (Box*)&block[2] ;
switch (direction)
{
case UP:
box->y0 += dist ;
box->y1 += dist ;
break ;
case DOWN:
box->y0 -= dist ;
box->y1 -= dist ;
break ;
case LEFT:
box->x0 += dist ;
box->x1 += dist ;
break ;
case RIGHT:
box->x0 -= dist ;
box->x1 -= dist ;
break ;
}
delblock[0] = window->handle ;
delblock[1] = handle ;
r.r[1] = (int)delblock ;
if ((e = _kernel_swi (Wimp_DeleteIcon, &r, &r)) != NULL)
throw (e) ;
r.r[1] = (int)&block[1] ;
r.r[0] = handle ;
block[1] = window->handle ; // set window handle
if ((e = _kernel_swi (Wimp_CreateIcon, &r, &r)) != NULL)
throw (e) ;
r.r[0] = window->handle ;
r.r[1] = block[2] ;
r.r[2] = block[3] ;
r.r[3] =