home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
v
/
vista
/
c
/
test
< prev
next >
Wrap
Text File
|
1996-02-01
|
17KB
|
729 lines
//
// main test
//
// this program is used as a test for Vista development. It is
// not a particularly good example of the use of the library
// but does use much of the facilities. Hopefully
// it will suffice until I write somethine better.
// David Allison 30/3/95
#include "Vista:vista.h"
#include <stdio.h>
#include <kernel.h>
#include <swis.h>
#include <string.h>
//
// a little counter to show threading
//
class Counter: public Window, public Thread
{
public:
Counter(Task *) ;
~Counter() ;
void run() ;
void close () ;
private:
int count ;
Icon *display ;
int running ;
} ;
Counter::Counter(Task *t)
: Window (t, "counter"),
Thread ("counter")
{
running = 1 ;
count = 0 ;
display = new Icon (this, 0) ;
}
Counter::~Counter()
{
}
void Counter::run()
{
do_open() ;
while (running)
{
display->print ("%d",count++) ;
sleep (100) ;
}
do_close() ;
}
void Counter::close()
{
running = 0 ;
wakeup() ;
}
//
// this class saves something using the DataSave protocol
//
class Saver: public DataSave
{
public:
Saver(Task *task) ;
~Saver() ;
void receive (int action, int task, int my_ref, int your_ref, int data_length, void *data) ; // receive a message
void save(int window, int icon, int x, int y, char *leaf) ;
void save (char *path) ;
} ;
Saver::Saver (Task *task) : DataSave (task)
{
}
Saver::~Saver()
{
}
void Saver::receive (int action, int task, int my_ref, int your_ref, int data_length, void *data)
{
switch ((Task::events)action)
{
case Task::Message_DataSaveAck:
{ // save to this file
DataSave::saveackdata *s = (DataSave::saveackdata *)data ;
save (s->pathname) ;
dataload (task, your_ref, my_ref, data_length, data) ;
break ;
}
case Task::Message_DataLoadAck:
// delete this ;
break ;
}
}
void Saver::save (int window, int icon, int x, int y, char *leaf)
{
datasave (window, icon, x, y, 1024, 0xfff, leaf) ;
}
void Saver::save (char *path)
{
FILE *fp = fopen (path, "w") ;
if (fp == NULL)
throw ("cant open file") ;
fprintf (fp,"hello world\n") ;
fclose (fp) ;
}
class Loader ;
//
// an icon grid
//
class LibraryDisplay : public IconGrid
{
public:
LibraryDisplay (Task *t, char *tname, int ticon, char *menu = 0) : IconGrid (t,tname,ticon,menu) { set_flag (SORTED) ; }
void menu (MenuItem items[]) ;
void drag_icon (int mx, int my, int buttons, Icon *icon) ;
void drag (int x0, int y0, int x1, int y1, int id) ;
void drag_selection (int mx, int my, int buttons, int x0, int y0, int x1, int y1) ;
} ;
void LibraryDisplay::menu (MenuItem items[])
{
}
void LibraryDisplay::drag_icon (int mx, int my, int buttons, Icon *icon)
{
icon->drag (mx, my, buttons) ;
task->register_drag (this,1) ;
}
void LibraryDisplay::drag_selection (int mx, int my, int buttons,int x0, int y0, int x1, int y1)
{
do_drag (5, x0, y0, x1, y1) ;
task->register_drag (this,1) ;
}
void LibraryDisplay::drag (int x0, int y0, int x1, int y1, int id)
{
if (id != 1) // not my drag?
{
IconGrid::drag (x0,y0,x1,y1,id) ;
return ;
}
int block[5] ;
_kernel_swi_regs r ;
_kernel_oserror *e ;
r.r[1] = (int)block ;
if ((e = _kernel_swi (Wimp_GetPointerInfo, &r, &r)) != NULL)
throw (e) ;
Saver *saver = new Saver(task) ;
saver->save (block[3], block[4], block[0], block[1], "newfile") ;
}
//
// this class loads files into the icon grid
//
class Loader: public DataSave
{
public:
Loader(Task *task, IconGrid *grid) ;
~Loader() ;
void receive (int action, int task, int my_ref, int your_ref, int data_length, void *data) ; // receive a message
private:
IconGrid *grid ;
} ;
Loader::Loader (Task *task, IconGrid *grid) : DataSave (task)
{
this->grid = grid ;
}
Loader::~Loader()
{
}
void Loader::receive (int action, int task, int my_ref, int your_ref, int data_length, void *data)
{
switch ((Task::events)action)
{
case Task::Message_DataSave: // save to this file
datasaveack (your_ref, (DataSave::saveackdata *)data, "<Wimp$Scrap>") ;
break ;
case Task::Message_DataLoad:
{
DataSave::saveackdata *s = (DataSave::saveackdata *)data ;
char *leaf = strrchr (s->pathname, '.') ;
if (leaf == NULL)
leaf = s->pathname ;
else
leaf++ ;
grid->insert_icon (leaf) ;
dataloadack (task, your_ref, my_ref, data_length, data) ;
break ;
}
}
}
//
// declare a class which is the main task
//
class Vista : public Task
{
public:
Vista() ;
void click(int x, int y, int button, int icon) ; // I want iconbar clicks
char *get_iconbar_menu (int icon) ;
void menu (MenuItem items[]) ; // iconbar menu hit
char *help (int mx, int my, int buttons, int w, int i) ;
Window *mainwin ; // main window
Window *win2 ; // another window
LibraryDisplay *lib ; // the icon grid
Window *txt ; // a text window
Loader *loader ; // icon grid file loader
} ;
//
// declare the main task variable
//
Vista *vista ;
//
// this class is for an action button
//
class Compile : public Icon
{
public:
Compile(Window *w, int icon) ;
void click(int mx, int my, int button, int icon) ;
char *help (int mx, int my, int buttons) ;
} ;
Compile::Compile(Window *w, int icon) : Icon (w,icon)
{
}
void Compile::click(int mx, int my, int button, int icon)
{
// Counter *c = new Counter (window->task) ;
// c->start() ;
window->task->show_threads() ;
Window *w = new Window (window->task, "counter") ;
Icon *ic = new Icon (w, 0) ;
w->do_open() ;
for (int i = 0 ; i < 20 ; i++)
{
ic->print ("%d",i) ;
window->task->sleep (100) ;
}
w->do_close() ;
delete ic ;
delete w ;
}
char *Compile::help (int mx, int my, int buttons)
{
return "This is the counter icon|MClick select to start a new counter" ;
}
//
// this class is for an action button which adds a new icon to the
// scrolling list
//
class Add : public Icon
{
public:
Add(Window *w, int icon, IconGrid *scroll) ;
void click(int mx, int my, int button, int icon) ;
private:
IconGrid *scroll ;
int num ;
} ;
Add::Add(Window *w, int icon, IconGrid *scroll) : Icon (w,icon)
{
this->scroll = scroll ;
num = 0 ;
}
void Add::click(int mx, int my, int button, int icon)
{
char buf[256] ;
sprintf (buf,"Icon %d",num++) ;
scroll->insert_icon (buf) ;
}
//
// this class adds a new icon to the icon grid
//
class AddIcon : public Icon
{
public:
AddIcon(Window *w, int icon, IconGrid *grid) ;
void click(int mx, int my, int button, int icon) ;
private:
IconGrid *grid ;
int num ;
} ;
AddIcon::AddIcon(Window *w, int icon, IconGrid *grid) : Icon (w,icon)
{
this->grid = grid ;
num = 0 ;
}
void AddIcon::click(int mx, int my, int button, int icon)
{
char buf[256] ;
sprintf (buf,"Icon %d",num++) ;
grid->insert_icon (buf) ;
grid->set_title ("%d icons",num) ;
}
//
// a small sub window (a scrolling list)
//
class SubWindow: public IconGrid
{
public:
SubWindow (Window *w, int ticon) : IconGrid (w, "sub1", ticon, "submenu") {}
void menu (MenuItem items[]) ;
char *help (int mx, int my, int buttons, int icon) ;
} ;
void SubWindow::menu (MenuItem items[])
{
}
char *SubWindow::help (int mx, int my, int buttons, int icon)
{
return "This is a scrolling window" ;
}
//
// a dialogue box
//
class TestBox : public DialogueBox
{
public:
TestBox (Task *task) ;
~TestBox() ;
private:
char string[32] ; //