/* * AccSkel.c -- Accessory skeleton for b&pp * © 1995 Another Option */ /* ============================================================================ | DATE | WHAT ============================================================================ */ #define DBUG 0 /* define this to write to sd0:BP.dump instead of con: for dprintf */ //#define FILEDUMP #define THIS_TOOL_NAME "Askl" #define ACC_NAME "»»skeleton accessory««" #include #include #include #include #include #include #include #include #include #include "bars.h" #include "bplib.h" #include "barsmacros.h" #include "proto/bplib_protos.h" #include "proto/AccessSkel_protos.h" #if DBUG #include "debug.h" #endif static UBYTE const versiontag[] = "$VER: Accessory_Skeleton 38.1 (04.09.95)"; /* an image for the tool */ #include "/devicon.h" extern struct Functions *functions; static struct Accessory access; /*========================================================================== * CloseWindowSafely * * INPUT: pointer to window * RETURN: none * * EFFECT: safely replies to outstanding messages (compliments mark & dave) *=========================================================================*/ static void __inline CloseWindowSafely(struct Window *w) { struct IntuiMessage *msg,*succ; Forbid(); msg=(struct IntuiMessage *)w->UserPort->mp_MsgList.lh_Head; while(msg->ExecMessage.mn_Node.ln_Succ!=NULL) { succ=(struct IntuiMessage *)msg->ExecMessage.mn_Node.ln_Succ; if(msg->IDCMPWindow==w) { Remove((struct Node *)msg); ReplyMsg((struct Message *)msg); } msg=succ; } w->UserPort=NULL; ModifyIDCMP(w,0); Permit(); functions->FlashyCloseWindow(w); } /*========================================================================== * closewindow * * INPUT: * RETURN: * * EFFECT: *=========================================================================*/ static long __saveds closewindow(void) { struct IntuiMessage *msg; if (access.window) { if (access.window->MenuStrip) ClearMenuStrip(access.window); /* EmbossOff() gadgets */ NewWindowStructure1.LeftEdge = access.left = access.window->LeftEdge; NewWindowStructure1.TopEdge = access.top = access.window->TopEdge; CloseWindowSafely(access.window); access.window = NULL; Permit(); } return(1); } /*========================================================================== * openwindow * * INPUT: * RETURN: * * EFFECT: *=========================================================================*/ static long __saveds openwindow(void) { struct Window *window; if (!access.window) { // unnecessary because window location was stashed in NewWindow on close // NewWindowStructure1.LeftEdge = access.left; // NewWindowStructure1.TopEdge = access.top; NewWindowStructure1.Screen = functions->screen; NewWindowStructure1.IDCMPFlags = 0; access.window = functions->FlashyOpenWindow(&NewWindowStructure1); if (access.window) { functions->EmbossWindowOn(access.window,WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG, WTITLE,(short)-1,(short)-1,0,0); access.window->UserPort = functions->window->UserPort; ModifyIDCMP(access.window,functions->window->IDCMPFlags); /* EmbossOn() gadgets */ // PrintIText(access.window->RPort,&IntuiTextList1,0,0); SetWindowTitles(access.window,(UBYTE *)-1,WTITLE); SetMenuStrip(access.window,&MenuList1); } } return((long)access.window); } /*========================================================================== * editwindow * * INPUT: pointer to IntuiMessage * RETURN: 1 * * EFFECT: handles ui interaction *=========================================================================*/ static int __saveds editwindow(struct IntuiMessage *message) { struct Gadget *gadget = (struct Gadget *) message->IAddress; long code = message->Code; long class; ReplyMsg((struct Message *)message); class = (*functions->SystemGadgets)(window,class,gadget,code); if (class == CLOSEWINDOW) { closewindow(); } else if (class == GADGETUP) { switch (gadget->GadgetID) { default: break; } } else if (class == GADGETDOWN) { switch (gadget->GadgetID) { default: break; } } return(1); } /************************ Optional Accessory Functions ********* /*========================================================================== * sizedata * * INPUT: pointer to Environment * RETURN: number of bytes required to write this thing * * EFFECT: calculates the number of bytes need to write this thing *=========================================================================*/ static long __saveds sizedata(struct Environment *environment) { } /*========================================================================== * savedata * * INPUT: file id, pointer to Environment * RETURN: 0 if successful; 1 if not * * EFFECT: writes accessory data to a .song file *=========================================================================*/ static long __saveds savedata(long file, struct Environment *environment) { long size; size = access.id; if (functions->fastwrite(file,&size,4) == -1) return(1); size = sizedata(environment); if (functions->fastwrite(file,&size,4) == -1) return(1); /* now, write any peculiar stuff */ return(0); } /*========================================================================== * loaddata * * INPUT: file id, pointer to Environment, size of data to read * RETURN: 1 * * EFFECT: reads accessory data from .song file *=========================================================================*/ static long __saveds loaddata(long file,struct Environment *environment,long size) { functions->fastread(file,>>buffer<<,size); return(1); } **********************************************************/ static struct Accessory * __saveds inittoolmaster() { memset((char *)&access,0,sizeof(struct Accessory)); access.left = NewWindowStructure1.LeftEdge; access.top = NewWindowStructure1.TopEdge; access.id = TOOL_ID(THIS_TOOL_NAME); access.image = &DevIcon; access.onimage = NULL; access.open = openwindow; access.close = closewindow; access.edit = editwindow; /* access.remove = NULL; access.load = loaddata; access.save = savedata; access.size = sizedata; access.install = install; access.clear = clear; */ strcpy(access.name,ACC_NAME); return(&access); }