home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
v
/
vista
/
c
/
window
< prev
next >
Wrap
Text File
|
1996-02-01
|
25KB
|
1,083 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.window
//
#include "Vista:task.h"
#include "Vista:window.h"
#include <swis.h>
#include <kernel.h>
#include <stdarg.h>
#include <stdio.h>
Window::Window (Task *tsk, char *tname, char *m)
{
void *defn ;
_kernel_swi_regs r ;
_kernel_oserror *e ;
int block[9] ;
task = tsk ;
//t->print ("creating window, tsk = %x, name = %s\n",tsk,tname) ;
if ((defn = tsk->find_template (tname)) == NULL)
throw ("No such Template") ;
r.r[1] = (int)defn ;
if ((e = _kernel_swi (Wimp_CreateWindow, &r, &r)) != NULL)
throw (e) ;
handle = r.r[0] ;
template_data = defn ;
block[0] = handle ;
r.r[1] = (int)block ;
if ((e = _kernel_swi (Wimp_GetWindowState, &r, &r)) != NULL)
throw (e) ;
x0 = block[1] ;
y0 = block[2] ;
x1 = block[3] ;
y1 = block[4] ;
scx = block[5] ;
scy = block[6] ;
prev = NULL ;
next = NULL ;
//::print ("window handle = %x",handle) ;
tsk->add_window(this) ; // add the window to the task
is_open = FALSE ;
icons = NULL ;
last_icon = NULL ;
objects = NULL ;
last_object = NULL ;
if (m == NULL)
default_menu = NULL ;
else
{
default_menu = tsk->find_menu (m) ;
if (default_menu == NULL)
throw ("Unknown menu") ;
}
sub_windows = NULL ; // no subwindows
parent = NULL ; // no parent
tracker = NULL ;
deleting = false ;
}
Window::Window (Window *w, char *tname, int anchor, char *m)
{
void *defn ;
_kernel_swi_regs r ;
_kernel_oserror *e ;
int block[9] ;
// ::print ("creating sub window, name = %s\n",tname) ;
this->anchor = anchor ;
task = w->task ;
if ((defn = task->find_template (tname)) == NULL)
throw ("No such Template") ;
r.r[1] = (int)defn ;
if ((e = _kernel_swi (Wimp_CreateWindow, &r, &r)) != NULL)
throw (e) ;
handle = r.r[0] ;
template_data = defn ;
block[0] = handle ;
r.r[1] = (int)block ;
if ((e = _kernel_swi (Wimp_GetWindowState, &r, &r)) != NULL)
throw (e) ;
// if the window is anchored then the coords are relative to the top of the parent
// window, otherwise they are relative to the bottom
switch (anchor)
{
case A_NONE:
case A_BOTTOM:
x0 = block[1] - w->x0 ;
y0 = block[2] - w->y0 ;
x1 = block[3] - w->x0 ;
y1 = block[4] - w->y0 ;
break ;
case A_LEFT:
case A_TOP:
x0 = block[1] - w->x0 ;
y0 = block[2] - w->y1 ;
x1 = block[3] - w->x0 ;
y1 = block[4] - w->y1 ;
break ;
case A_RIGHT:
x0 = block[1] - w->x1 ;
y0 = block[2] - w->y1 ;
x1 = block[3] - w->x1 ;
y1 = block[4] - w->y1 ;
break ;
}
scx = block[5] ;
scy = block[6] ;
//::print ("window handle = %x",handle) ;
prev = NULL ;
next = NULL ;
w->add_sub_window(this) ; // add the window to the task
is_open = FALSE ;
icons = NULL ;
last_icon = NULL ;
objects = NULL ;
last_object = NULL ;
if (m == NULL)
default_menu = NULL ;
else
{
default_menu = task->find_menu (m) ;
if (default_menu == NULL)
throw ("Unknown menu") ;
}
sub_windows = NULL ; // no subwindows
tracker = NULL ;
deleting = false ;
}
Window::~Window()
{
Icon *ni ;
Window *nw ;
Object *no ;
deleting = true ;
if (is_open)
do_close() ;
for (Icon *i = icons ; i != NULL ; i = ni)
{
ni = i->next ;
delete i ;
}
for (Window *w = sub_windows ; w != NULL ; w = nw)
{
nw = w->next ;
delete w ;
}
for (Object *o = objects ; o != NULL ; o = no)
{
no = o->next ;
delete o ;
}
task->remove_window (this) ;
if (parent != NULL)
parent->remove_sub_window (this) ;
if (tracker != NULL)
delete tracker ;
task->free_template(template_data) ; // free up the definition data
}
//
// get a sub window's x0 coordinate in screen coordinates
//
int Window::subx0(Window *sub)
{
int myx0 ; // my x0 coord
if (parent != NULL)
myx0 = parent->subx0(this) ;
else
myx0 = x0 ;
switch (sub->anchor)
{
case A_NONE:
case A_BOTTOM:
default:
return myx0 + sub->x0 ;
case A_LEFT:
case A_TOP:
return myx0 + sub->x0 ;
case A_RIGHT:
return myx0 + (x1-x0) + sub->x0 ; // == myx1 + sub->x0
}
}
//
// get the y1 coordinate for a sub window in screen coordinates
//
int Window::suby1(Window *sub)
{
int myy1 ; // my y1 coord
if (parent != NULL)
myy1 = parent->suby1(this) ;
else
myy1 = y1 ;
switch (sub->anchor)
{
case A_NONE:
case A_BOTTOM:
default:
return myy1 - (y1-y0) + sub->y1 ; // == myy0 + sub->y1
case A_LEFT:
case A_TOP:
return myy1 + sub->y1 ;
case A_RIGHT:
return myy1 + sub->y1 ;
}
}
void Window::add_icon(Icon *i)
{
i->next = NULL ;
if (icons == NULL)
icons = last_icon = i ;
else
{
last_icon->next = i ;
i->prev = last_icon ;
last_icon = i ;
}
}
void Window::remove_icon (Icon *i)
{
if (i->prev == NULL)
icons = i->next ;
else
i->prev->next = i->next ;
if (i->next == NULL)
last_icon = i->prev ;
else
i->next->prev = i->prev ;
}
void Window::add_object(Object *o)
{
Object *obj = objects ;
while (obj != NULL && obj->priority < o->priority) // find position
obj = obj->next ;
o->next = obj ;
if (obj == NULL) // at end of queue
o->prev = last_object ;
else
o->prev = obj->prev ;
if (o->prev == NULL)
objects = o ;
else
o->prev->next = o ;
if (o->next == NULL)
last_object = o ;
else
o->next->prev = o ;
}
void Window::remove_object (Object *o)
{
if (o->prev == NULL)
objects = o->next ;
else
o->prev->next = o->next ;
if (o->next == NULL)
last_object = o->prev ;
else
o->next->prev = o->prev ;
}
void Window::add_sub_window (Window *w)
{
if (sub_windows == NULL)
sub_windows = last_sub_window = w ;
else
{
last_sub_window->next = w ;
w->prev = last_sub_window ;
last_sub_window = w ;
}
w->parent = this ;
}
void Window::remove_sub_window (Window *w)
{
if (w->prev == NULL)
sub_windows = w->next ;
else
w->prev->next = w->next ;
if (w->next == NULL)
last_sub_window = w->prev ;
else
w->next->prev = w->prev ;
w->parent = NULL ;
}
void Window::do_open(int x0, int y0, int x1, int y1, int scx, int scy, int behind)
{
int block[8] ;
_kernel_swi_regs r ;
_kernel_oserror *