home *** CD-ROM | disk | FTP | other *** search
- /* > $.CLIB.C.pollmsgs
- *
- * HASWIN Graphics Library
- * =========================
- *
- * Copyright (C) H.A.Shaw 1990.
- * Howard A. Shaw.
- * The Unit for Space Sciences,
- * Room 165,
- * Physics Building,
- * University of Kent at Canterbury.
- * Canterbury.
- * Kent. CT2 7NJ
- * You may use and distribute this code freely, however please leave
- * it alone. If you find bugs (and there will be many) please contact
- * me and the master source can be modified. If you keep me informed
- * of who you give copies of this to then I can get release upgrades
- * to them.
- *
- * routine to perform the messages related return codes from
- * SWI(Wimp_Poll)
- */
- #include "c.poll_h"
- #include <stdio.h>
-
- int haswin_poll_message_ack(int (*user)(int, buffer *), buffer *pbuf) {
-
-
- if (user)
- (*user)(HASWIN_POLL_Message_Ack, pbuf);
- switch (pbuf->i[4]) {
- }
- return(HASWIN_TRUE);
- }
-
- int haswin_poll_message(int (*user)(int, buffer *), buffer *pbuf) {
-
- _kernel_swi_regs regs;
- window *wptr;
- icon *iptr;
- char tmp[256], *ptr;
- int i, len;
-
- if (pbuf->i[1] == haswin_taskid)
- return(HASWIN_TRUE);
- switch (pbuf->i[4]) {
- case MESSAGE_Quit:
- if (user)
- (*user)(HASWIN_POLL_poll_MQuit, pbuf);
- /* NB: we MUST quit now */
- haswin_exit(HASWIN_TRUE);
- break;
- case MESSAGE_PreQuit:
- /*
- * haswin_quitfrom = pbuf->i[1];
- * haswin_flags |= HASWIN_FLAGS_QUITING;
- * regs.r[0] = HASWIN_POLL_Message_Ack;
- * regs.r[1] = (int)pbuf;
- * regs.r[2] = haswin_quitfrom;
- * pbuf->i[3] = pbuf->i[2];
- * haswin_swi(HASWIN_Send_message, ®s);
- * haswin_reopenwindow(haswin_quitwin);
- */
- break;
- case MESSAGE_SetSlot:
- if ((pbuf->i[6] == haswin_taskid) && (haswin_flags & HASWIN_FLAGS_SETSLOT)) {
- if (pbuf->i[5] >= haswin_getprogramtop()) {
- haswin_initialiseuserheap(pbuf->i[5]-haswin_getprogramtop());
- }
- /* acknowledge the slot size change */
- regs.r[0] = HASWIN_POLL_Message_Ack;
- regs.r[1] = (int)pbuf;
- regs.r[2] = pbuf->i[1];
- pbuf->i[3] = pbuf->i[2];
- if (!haswin_swi(HASWIN_Send_message, ®s))
- return(HASWIN_FALSE);
- }
- break;
- /*
- * DataLoad message. Call the dataload routine and
- * then acknowledge it if it returns TRUE. If we are
- * using <Wimp$Scrap> then HASWIN_FLAGS_KILLWS will be
- * true, so remove <Wimp$Scrap>.
- */
- case MESSAGE_DataLoad:
- if ((user) && (!((*user)(HASWIN_POLL_poll_Load, pbuf))))
- return(HASWIN_FALSE);
- if (haswin_loadfileroutine) {
- if ((*haswin_loadfileroutine)(&pbuf->c[44], pbuf)) {
- if (haswin_flags & HASWIN_FLAGS_KILLWS) {
- /* delete the file <Wimp$Scrap> */
- haswin_flags &= ~HASWIN_FLAGS_KILLWS;
- if (remove("<Wimp$Scrap>") != 0)
- break;
- }
- regs.r[0] = HASWIN_POLL_Message;
- regs.r[1] = (int)pbuf;
- regs.r[2] = pbuf->i[1];
- pbuf->i[3] = pbuf->i[2];
- pbuf->i[4] = MESSAGE_DataLoadAck;
- if (!haswin_swi(HASWIN_Send_message, ®s))
- return(HASWIN_FALSE);
- }
- }
- break;
- /*
- * DataLoadAck message. If we are loading call the
- * dataload routine with the filename but no buffer.
- * If we are saving call the datasave routine with the
- * filename but no buffer. If we are printing call the
- * print routine with the filename but no buffer. This is
- * for the load/save/print routines to clear away files.
- */
- case MESSAGE_DataLoadAck:
- if (haswin_flags & HASWIN_FLAGS_SAVING) {
- if (haswin_savefileroutine)
- if ((*haswin_savefileroutine)(&pbuf->c[44], (buffer *)0))
- haswin_setfiletype(&pbuf->c[44], pbuf->i[10]);
- haswin_flags &= ~HASWIN_FLAGS_SAVING;
- } else if (haswin_flags & HASWIN_FLAGS_LOADING) {
- if (haswin_loadfileroutine)
- (*haswin_loadfileroutine)(&pbuf->c[44], (buffer *)0);
- haswin_flags &= ~HASWIN_FLAGS_LOADING;
- } else if (haswin_flags & HASWIN_FLAGS_PRINTING) {
- if (haswin_printfileroutine)
- (*haswin_printfileroutine)(&pbuf->c[44], (buffer *)0);
- haswin_flags &= ~HASWIN_FLAGS_PRINTING;
- }
- break;
- /*
- * DataSave message. If we can handle Ram receive
- * transfers then set the RAMGO flag and acknowledge with
- * a RAMFetch message giving the buffer and its size.
- */
- case MESSAGE_DataSave:
- if (haswin_ramrxroutine) {
- if ((user) && (!((*user)(HASWIN_POLL_poll_RAMrx, pbuf))))
- return(HASWIN_FALSE);
- /* can do a ram transfer, so go for it */
- regs.r[0] = HASWIN_POLL_Message_Rec;
- regs.r[1] = (int)pbuf;
- regs.r[2] = pbuf->i[1];
- pbuf->i[0] = 28;
- pbuf->i[3] = pbuf->i[2];
- pbuf->i[4] = MESSAGE_RAMFetch;
- pbuf->i[5] = (int)haswin_ramrxbuffer;
- pbuf->i[6] = haswin_ramrxlength;
- if (!haswin_swi(HASWIN_Send_message, ®s))
- return(HASWIN_FALSE);
- haswin_flags |= HASWIN_FLAGS_RAMGO;
- haswin_ramrxbytes = 0;
- } else {
- if ((user) && (!((*user)(HASWIN_POLL_poll_Save, pbuf))))
- return(HASWIN_FALSE);
- regs.r[0] = HASWIN_POLL_Message;
- regs.r[1] = (int)pbuf;
- regs.r[2] = pbuf->i[1];
- pbuf->i[0] = 60;
- pbuf->i[3] = pbuf->i[2];
- pbuf->i[4] = MESSAGE_DataSaveAck;
- pbuf->i[9] = -1;
- strcpy(&(pbuf->c[44]), "<Wimp$Scrap>");
- if (!haswin_swi(HASWIN_Send_message, ®s))
- return(HASWIN_FALSE);
- haswin_flags |= HASWIN_FLAGS_KILLWS;
- }
- break;
- case MESSAGE_DataSaveAck:
- if (haswin_flags & HASWIN_FLAGS_SAVING) {
- strncpy(haswin_defaultsavefile, &(pbuf->c[44]), 256);
- haswin_seticondata(haswin_saveiconname, haswin_defaultsavefile);
- if (haswin_savefileroutine) {
- if ((*haswin_savefileroutine)(&(pbuf->c[44]), pbuf)) {
- regs.r[0] = HASWIN_POLL_Message_Rec;
- regs.r[1] = (int)pbuf;
- regs.r[2] = pbuf->i[1];
- pbuf->i[3] = pbuf->i[2];
- pbuf->i[4] = MESSAGE_DataLoad;
- if (!haswin_swi(HASWIN_Send_message, ®s))
- return(HASWIN_FALSE);
- }
- }
- break;
- }
- if (haswin_flags & HASWIN_FLAGS_LOADING) {
- strncpy(haswin_defaultloadfile, &(pbuf->c[44]), 256);
- haswin_seticondata(haswin_loadiconname, haswin_defaultloadfile);
- regs.r[0] = HASWIN_POLL_Message_Ack;
- regs.r[1] = (int)pbuf;
- regs.r[2] = pbuf->i[1];
- pbuf->i[3] = pbuf->i[2];
- if (!haswin_swi(HASWIN_Send_message, ®s))
- return(HASWIN_FALSE);
- haswin_flags &= ~HASWIN_FLAGS_LOADING;
- }
- break;
- case MESSAGE_DataOpen:
- if ((haswin_autoloadroutine) && (haswin_autoloadtype == pbuf->i[10])) {
- /* we have a routine, and correct type, so
- acknowledge it */
- regs.r[0] = HASWIN_POLL_Message_Ack;
- regs.r[1] = (int)pbuf;
- regs.r[2] = pbuf->i[1];
- pbuf->i[3] = pbuf->i[2];
- if (!haswin_swi(HASWIN_Send_message, ®s))
- return(HASWIN_FALSE);
- /* now try to load it */
- (*haswin_autoloadroutine)(&(pbuf->c[44]), pbuf);
- }
- break;
- case MESSAGE_RAMFetch:
- if (haswin_ramtxroutine) {
- haswin_ramtxbuffer = haswin_realloc(haswin_ramtxbuffer, pbuf->i[6], "haswin_poll_message", "RAMTransmit buffer");
- if ((user) && (!((*user)(HASWIN_POLL_poll_RAMtx, pbuf))))
- return(HASWIN_FALSE);
- len=haswin_ramtxroutine(haswin_ramtxbuffer, pbuf->i[6], haswin_ramtxbytes, pbuf);
- if (len >= 0) {
- /* copy the data in the transmit buffer to
- the other application */
- regs.r[0] = haswin_gettaskid();
- regs.r[1] = (int)haswin_ramtxbuffer;
- regs.r[2] = pbuf->i[1];
- regs.r[3] = pbuf->i[5];
- regs.r[4] = len;
- if (!haswin_swi(HASWIN_Transfer_block,®s))
- return(HASWIN_FALSE);
- haswin_ramtxbytes += len;
- haswin_flags |= HASWIN_FLAGS_RAMGO;
- /* reply with a RAMTransmit */
- if (len == pbuf->i[6])
- /* not last transfer */
- regs.r[0] = HASWIN_POLL_Message_Rec;
- else {
- /* last transfer */
- regs.r[0] = HASWIN_POLL_Message;
- haswin_ramtxbytes = 0;
- }
- regs.r[1] = (int)pbuf;
- regs.r[2] = pbuf->i[1];
- pbuf->i[0] = 28;
- pbuf->i[3] = pbuf->i[2];
- pbuf->i[4] = MESSAGE_RAMTransmit;
- pbuf->i[6] = len;
- if (!haswin_swi(HASWIN_Send_message, ®s))
- return(HASWIN_FALSE);
- } else {
- haswin_ramtxbytes = 0;
- haswin_flags &= ~HASWIN_FLAGS_RAMGO;
- }
- }
- break;
- case MESSAGE_RAMTransmit:
- if (!(haswin_flags & HASWIN_FLAGS_RAMGO)) {
- haswin_internalerror("got a RAM transmit message with nothing to do!");
- return(HASWIN_FALSE);
- }
- /* transfer the data into our buffer */
- regs.r[0] = pbuf->i[1];
- regs.r[1] = pbuf->i[5];
- regs.r[2] = haswin_gettaskid();
- regs.r[3] = (int)haswin_ramrxbuffer;
- regs.r[4] = pbuf->i[6];
- if (!haswin_swi(HASWIN_Transfer_block, ®s))
- return(HASWIN_FALSE);
- /* pass this buffer to the user routine to deal with */
- if ((haswin_ramrxroutine) &&
- (*haswin_ramrxroutine)(haswin_ramrxbuffer, pbuf->i[6], haswin_ramrxbytes, pbuf) && (pbuf->i[6] == haswin_ramrxlength)) {
- /* User routine returned true and the buffers are
- transferring full, try for more data */
- haswin_ramrxbytes += pbuf->i[6];
- regs.r[0] = HASWIN_POLL_Message_Rec;
- regs.r[1] = (int)pbuf;
- regs.r[2] = pbuf->i[1];
- pbuf->i[0] = 28;
- pbuf->i[3] = pbuf->i[2];
- pbuf->i[4] = MESSAGE_RAMFetch;
- pbuf->i[5] = (int)haswin_ramrxbuffer;
- pbuf->i[6] = haswin_ramrxlength;
- if (!haswin_swi(HASWIN_Send_message, ®s))
- return(HASWIN_FALSE);
- } else {
- haswin_ramrxbytes = 0;
- haswin_flags &= ~HASWIN_FLAGS_RAMGO;
- }
- break;
- case MESSAGE_Palette:
- if (user)
- return((*user)(HASWIN_POLL_Message, pbuf));
- break;
- case MESSAGE_Notify:
- if (user)
- return((*user)(HASWIN_POLL_Message, pbuf));
- break;
- case MESSAGE_MenuWarning:
- if ((haswin_menu.actual) && (haswin_menu.message))
- return((*haswin_menu.message)(pbuf, &haswin_menu));
- if ((user) && (!((*user)(HASWIN_POLL_Message, pbuf))))
- return(HASWIN_FALSE);
- break;
- case MESSAGE_ModeChange:
- haswin_updateallvduvariables(0);
- if (user)
- return((*user)(HASWIN_POLL_Message, pbuf));
- break;
- case MESSAGE_HelpRequest:
- wptr = haswin_findwindowhandle(pbuf->i[8]);
- iptr = haswin_findiconhandle(wptr, pbuf->i[9]);
- tmp[0] = 0;
- if ((haswin_flags & HASWIN_FLAGS_HELPFUL) &&
- ((int)wptr > 0) && (wptr->flags & WINDOW_HELPFUL)) {
- /* we are being helpful, so look for icon */
- if (iptr) {
- /* got one, if helpmsg then use it else
- say something helpful */
- if (iptr->helpmsg)
- strcpy(tmp, iptr->helpmsg);
- else {
- sprintf(tmp, "This is Icon '%s' in Window '%s'|M", haswin_geticontitle(iptr), haswin_getwindowtitle(wptr));
- if (iptr->window) {
- strcat(tmp, "Click SELECT to open Window ");
- strcat(tmp, haswin_getwindowtitle(iptr->window));
- strcat(tmp, "|M");
- }
- i = 0;
- if (iptr->menu)
- i += 1;
- if (iptr->help)
- i += 2;
- if (iptr->flags & ICON_CANQUIT)
- i += 4;
- if (i == 1) {
- strcat(tmp, "Click MENU for a menu|M");
- } else if (i > 1) {
- strcat(tmp, "Click MENU for a menu to");
- if (i & 2)
- strcat(tmp, " get help,");
- if (i & 4)
- strcat(tmp, " quit,");
- i = strlen(tmp);
- tmp[i-1] = '|';
- tmp[i] = 'M';
- tmp[i+1] = '\0';
- }
- if (iptr->mousebutton)
- strcat(tmp,"Click ADJUST for action|M");
- }
- } else {
- /* got a window instead, one, if helpmsg
- then use it else say something helpful */
- if (wptr->helpmsg)
- strcpy(tmp, wptr->helpmsg);
- else {
- sprintf(tmp, "This is Window '%s'|M", haswin_getwindowtitle(wptr));
- if (wptr->mousebutton)
- strcat(tmp,"Click SELECT for action|M");
- i = 0;
- if (wptr->menu)
- i += 1;
- if (wptr->help)
- i += 2;
- switch (i) {
- case 0:
- break;
- case 1:
- strcat(tmp, "Click MENU for a menu|M");
- break;
- case 2:
- case 3:
- strcat(tmp, "Click MENU for a menu to get help|M");
- break;
- }
- if (wptr->mousebutton)
- strcat(tmp,"Click ADJUST for action|M");
- }
- }
- } else if ((haswin_flags & HASWIN_FLAGS_HELPFUL) &&
- ((int)wptr < 0) && (iptr)) {
- /* got icon on icon bar, if helpmsg then use it else
- say something helpful */
- if (iptr->helpmsg)
- strcpy(tmp, iptr->helpmsg);
- else {
- sprintf(tmp, "This is the %s Icon|M", haswin_gettaskname());
- if (iptr->window) {
- strcat(tmp, "Click SELECT to open Window ");
- strcat(tmp, haswin_getwindowtitle(iptr->window));
- strcat(tmp, "|M");
- }
- i = 0;
- if (iptr->menu)
- i += 1;
- if (iptr->help)
- i += 2;
- if (iptr->flags & ICON_CANQUIT)
- i += 4;
- if (haswin_flags & HASWIN_FLAGS_FILEMENU) {
- if (haswin_loadfileroutine)
- i += 8;
- if (haswin_savefileroutine)
- i += 16;
- }
- if (i == 1) {
- strcat(tmp, "Click MENU for a menu|M");
- } else if (i > 1) {
- strcat(tmp, "Click MENU for a menu to");
- if (i & 2)
- strcat(tmp, " get help,");
- if (i & 8)
- strcat(tmp, " load files,");
- if (i & 16)
- strcat(tmp, " save files,");
- if (i & 4)
- strcat(tmp, " quit,");
- i = strlen(tmp);
- tmp[i-1] = '|';
- tmp[i] = 'M';
- tmp[i+1] = '\0';
- }
- if (iptr->mousebutton)
- strcat(tmp,"Click ADJUST for action|M");
- }
- } else {
- /* we are not helpful, so print helpmsg if there is
- any, but don't do anything else */
- if ((iptr) && (iptr->helpmsg))
- strcpy(tmp, iptr->helpmsg);
- else if (((int)wptr > 0) && (wptr->helpmsg))
- strcpy(tmp, wptr->helpmsg);
- }
- if (tmp[0] != 0) {
- ptr = tmp;
- i = 20;
- while (*ptr) {
- if (*ptr == '\n') {
- pbuf->c[i++] = '|';
- pbuf->c[i++] = 'M';
- } else
- pbuf->c[i++] = *ptr++;
- }
- pbuf->c[i] = 0;
- regs.r[0] = HASWIN_POLL_Message;
- regs.r[1] = (int)pbuf;
- regs.r[2] = pbuf->i[1];
- pbuf->i[3] = pbuf->i[2];
- pbuf->i[4] = MESSAGE_HelpReply;
- pbuf->i[0] = (i+4) & 0xFFFFFFFC;
- if (!haswin_swi(HASWIN_Send_message, ®s))
- return(HASWIN_FALSE);
- }
- break;
- case MESSAGE_TaskNameRq:
- break;
- case MESSAGE_TaskNameIs:
- if (haswin_flags & HASWIN_FLAGS_TASKIS) {
- strcpy(haswin_tasknameis, &pbuf->c[28]);
- haswin_flags &= ~HASWIN_FLAGS_TASKIS;
- } else if (user)
- return((*user)(HASWIN_POLL_Message, pbuf));
- break;
- case MESSAGE_TaskInitialise:
- if (user)
- return((*user)(HASWIN_POLL_Message, pbuf));
- break;
- case MESSAGE_TaskClosedown:
- if (user)
- return((*user)(HASWIN_POLL_Message, pbuf));
- break;
- case MESSAGE_PrintFile:
- /*
- * this message is the reply the Printer Driver sends if we
- * drop a file on it, or ask it to print in some other way.
- * If the user program has not provided anything to print
- * the file with we will soon get a MESSAGE_DataSaveAck from
- * the printer driver so we need do nothing special to get a
- * go at a normal save to the printer driver.
- */
- haswin_flags &= ~(HASWIN_FLAGS_SAVING|HASWIN_FLAGS_LOADING);
- haswin_flags |= HASWIN_FLAGS_PRINTING;
- if ((user) && (!((*user)(HASWIN_POLL_poll_Print, pbuf))))
- return(HASWIN_FALSE);
- if (haswin_printfileroutine) {
- regs.r[0] = HASWIN_POLL_Message_Rec;
- regs.r[1] = (int)pbuf;
- regs.r[2] = pbuf->i[1];
- pbuf->i[3] = pbuf->i[2];
- pbuf->i[4] = MESSAGE_DataLoad;
- if (!haswin_swi(HASWIN_Send_message, ®s))
- return(HASWIN_FALSE);
- }
- break;
- case MESSAGE_WillPrint:
- haswin_errorprintf("WillPrint from id=%d", pbuf->i[1]);
- break;
- case MESSAGE_PrintSave:
- haswin_errorprintf("PrintSave from id=%d", pbuf->i[1]);
- break;
- case MESSAGE_SetPrinter:
- case MESSAGE_PrintInit:
- haswin_initialisepdriver();
- break;
- case MESSAGE_PrintBusy:
- haswin_errorprintf("PrintBusy from id=%d", pbuf->i[1]);
- break;
- case MESSAGE_PrintTypeOdd:
- /*
- * we get this when the printer driver wants to know how to
- * print a file. We ask the user print routine if it knows
- * the filetype and send a MESSAGE_PrintTypeKnown if it does
- * The user print routine must actually print to the file if
- * it knows how to.
- */
- if (haswin_printfileroutine) {
- strcpy(tmp, "<Printer$Temp>");
- if ((*haswin_printfileroutine)(tmp, pbuf)) {
- regs.r[0] = HASWIN_POLL_Message_Rec;
- regs.r[1] = (int)pbuf;
- regs.r[2] = pbuf->i[1];
- pbuf->i[3] = pbuf->i[2];
- pbuf->i[4] = MESSAGE_PrintTypeKnown;
- strcpy(&(pbuf->c[44]), tmp);
- pbuf->i[0] = (44 + strlen(tmp)) & 0xFFFFFFFC;
- if (!haswin_swi(HASWIN_Send_message, ®s))
- return(HASWIN_FALSE);
- }
- }
- break;
- case MESSAGE_PrintTypeKnown:
- haswin_errorprintf("PrintTypeKnown from id=%d", pbuf->i[1]);
- break;
- default:
- if (user)
- return((*user)(HASWIN_POLL_Message, pbuf));
- break;
- }
- return(HASWIN_TRUE);
- }
-
-