home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 5
/
DATAFILE_PDCD5.iso
/
utilities
/
m
/
multimod
/
!MultiMod
/
c
/
wimpif
< prev
Wrap
Text File
|
1992-11-16
|
8KB
|
281 lines
/* wimpif.c contains the wimp stuff for the program */
#include "all.h"
#define DISPMENU "Large icons,Small icons,Full info|No sort,Sort on name,Sort on size,Reverse size"
absolute code = { CODE_INITIALISE } ;
/********************************* CONSTANTS ********************************/
/* Info box field for the version string */
#define Example_info_field 4
/******************************** GLOBAL DATA *******************************/
/* Application version */
char *example_Version_String = "1.00 (1 June 1992)";
/* The top of the menu tree */
menu bar_menu,disp_menu;
/* Handle for the example window */
file_info data; /* data[x]->(w|cm|m[y].(offset|size|display) */
usage using;
/***************************** WINDOW FUNCTIONS *****************************/
/*--- Create the window, yielding its handle. Return TRUE if ok. ---*/
BOOL example_create_window(char *name, wimp_w *handle)
{
template *t = template_copy(template_find(name));
/* Create the window, dealing with errors */
t->window.spritearea = (void *) 1; /* Set the sprite area pointer */
return (wimpt_complain(wimp_create_wind(&(t->window), handle)) == 0);
}
/*--- Individual event routines for the window ---*/
void example_redraw_window(wimp_w handle)
{
int i,more;
wimp_redrawstr r;
int bind = lookup_window_bind(handle);
SFI d = data[bind];
int e = d->entries;
display_types disp = d->disp;
/* Start the redraw */
r.w = handle;
wimpt_noerr(wimp_redraw_wind(&r, &more));
/* Do the redraw loop */
/* Use one of the array of procedures to find the correct icon drawer */
while (more)
{
if (bind > -1)
for (i = 0; i < e; i++) multi[disp].drawer(bind,i,&r);
wimp_get_rectangle(&r, &more);
}
}
void example_open_window(wimp_openstr *o)
{
/* Just pass the open request on to the wimp */
wimpt_noerr(wimp_open_wind(o));
}
/****************************** EVENT HANDLERS ******************************/
/*--- Event handler called on a left click on the icon. ---*/
void example_iconclick(wimp_i icon)
{
wimp_wstate state;
int new;
icon = icon; /* We don't need the handle: this stops compiler warning */
if ((new = allocate_untitled_window((char *)-1)) == -1)
werr(0,"Too many windows");
else
{
/* Get the state of the window */
if (wimpt_complain(wimp_get_wind_state(data[new]->w , &state)) == 0)
{
state.o.behind = -1; /* Make sure window is opened in front */
wimpt_noerr(wimp_open_wind(&state.o));
}
}
}
/*--- Display the program info box - called from the menu processor. ---*/
void example_info_about_program(void)
{
dbox d; /* Dialogue box handle */
/* Create the dialogue box */
if (d = dbox_new("Info"), d != NULL)
{
/* Fill in the version number */
dbox_setfield(d, Example_info_field, example_Version_String);
/* Show the dialogue box */
dbox_show(d);
/* Keep it on the screen as long as needed */
dbox_fillin(d);
/* Dispose of the dialogue box */
dbox_dispose(&d);
}
}
/*--- Event handler for the menu. ---*/
void example_menuproc(void *handle, char *hit)
{
handle = handle; /* We don't need handle: this stops compiler warning */
/* Find which menu item was hit and take action as appropriate */
switch (hit[0])
{
case bar_menu_info:
example_info_about_program();
break;
case bar_menu_new:
saveas(MultiModule_FileType,"Collection",0,save_empty_mm,0,0,-1);
break;
case bar_menu_quit:
/* Exit from the program. The wimp gets rid of the window and icon */
if (verify_quit()) exit(0);
}
}
#define DBOX_UNSAVED "Really discard modified file?"
/*--- Event handler for window. ---*/
void data_win_handler(wimp_eventstr *e, void *handle)
{
int bind;
char *name;
/* Deal with event */
switch (e->e)
{
case wimp_EREDRAW:
example_redraw_window(e->data.o.w);
break;
case wimp_EOPEN:
example_open_window(&e->data.o);
break;
case wimp_ECLOSE: /* Pass on close request */
bind = (int) handle;
if (data[bind]->changed) if (dboxquery(DBOX_UNSAVED) != dboxquery_YES) break;
wimpt_noerr(wimp_delete_wind(e->data.o.w));
destroy_data(bind);
break;
case wimp_ESEND:
case wimp_ESENDWANTACK:
switch (e->data.msg.hdr.action)
{
case wimp_MDATASAVE:
switch (xferrecv_checkimport(&bind))
{
case MultiModule_FileType:
if (e->data.msg.hdr.task != wimpt_task()) break;
werr(0,"To perform an import, save then drag the file in");
}
break;
case wimp_MDATALOAD:
switch (xferrecv_checkinsert(&name))
{
case MultiModule_FileType:
xferrecv_insertfileok();
insert_file((int) handle , name);
break;
case Module_FileType:
xferrecv_insertfileok();
add_module((int) handle , name);
break;
default:
werr(0,"You can only drop modules or module collections here");
}
break;
default: break;
}
break;
default: /* Ignore any other event */
break;
}
}
BOOL event_processor(wimp_eventstr *e,void *handle)
{
char *name;
wimp_w w;
int bind;
if (xferrecv_checkinsert(&name) == MultiModule_FileType)
{
xferrecv_insertfileok();
if ((bind = lookup_window_bind(w = e->data.msg.data.dataload.w)) < 0)
load_file(name);
else
insert_file(bind,name);
return TRUE;
}
return FALSE;
}
void iconbarload(wimp_eventstr *e,void *h) { event_processor(e,h); }
/****************************** INITIALISATION ******************************/
/*--- Initialise the program, returning TRUE if it was all OK. ---*/
BOOL example_initialise(void)
{
/* RISC_OSlib initialisation */
wimpt_init("Multi Module"); /* Main Wimp initialisation */
flex_init(); /* Memory management */
res_init("MultiMod"); /* Resources */
resspr_init(); /* Application sprites */
template_init(); /* Templates */
dbox_init(); /* Dialogue boxes */
data_init(); /* Our data structure */
/* Create the menu subtree */
if ((disp_menu = menu_new("Display",DISPMENU)) == NULL)
return FALSE; /* Menu create failed */
/* Create the menu tree */
if (bar_menu = menu_new("Multi Module", ">Info,>New File,Quit"), bar_menu == NULL)
return FALSE; /* Menu create failed */
/* Set up the icon on the icon bar, and declare its event handlers */
baricon("!multimod", (int)resspr_area(), example_iconclick);
if (!event_attachmenu(win_ICONBAR, bar_menu, example_menuproc, 0))
return FALSE; /* Unable to attach menu */
dboxquery(0);
win_add_unknown_event_processor(event_processor,0);
win_register_event_handler(win_ICONBARLOAD, iconbarload, 0);
/* All went ok */
return TRUE;
}
/******************************* MAIN PROGRAM ********************************/
/*--- Main entry point. ---*/
int main(int argc,char **argv)
{
int loop;
if (example_initialise())
{
if ((loop = argc) > 1)
{
if (strcmpic((UC *)argv[1],(UC *)"-print") == 0)
{
if (load_file(argv[1])) print_info("<Printer$Temp>",0);
return 0;
}
while (loop > 1) load_file(argv[--loop]);
}
/* The main event loop */
while (TRUE)
event_process();
}
return 0;
}