home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / DOpus4-GPL / Library / misc.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  5KB  |  191 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "dopuslib.h"
  32.  
  33. __asm __saveds DoRawkeyToStr(register __d0 USHORT code,
  34.     register __d1 USHORT qual,
  35.     register __a0 char *buf,
  36.     register __a1 char *kbuf,
  37.     register __d2 int len)
  38. {
  39.     struct InputEvent inev;
  40.     struct MsgPort *port;
  41.     struct IOStdReq *req;
  42.     struct Process *myproc;
  43.     struct ConsoleDevice *ConsoleDevice;
  44.     char ocbuf[20],cbuf[20],*foo;
  45.  
  46.     if (buf) buf[0]=0; ocbuf[0]=cbuf[0]=0;
  47.     if (code!=~0 && code!=0xff) {
  48.         if (code&IECODE_UP_PREFIX) code-=0x80;
  49.         if (code>=0x50 && code<=0x59) LSprintf(cbuf,"F%ld",code-0x4f);
  50.         else if (code!=~0 && code!=0xff) {
  51.             foo=NULL;
  52.             switch (code) {
  53.                 case 0x45: foo="ESCAPE"; break;
  54.                 case 0x46: foo="DELETE"; break;
  55.                 case 0x41: foo="BACKSPACE"; break;
  56.                 case 0x42: foo="TAB"; break;
  57.                 case 0x44:
  58.                 case 0x2b: foo="RETURN"; break;
  59.                 case 0x5f: foo="HELP"; break;
  60.                 case 0x60:
  61.                 case 0x4c: foo="CURSOR-UP"; break;
  62.                 case 0x4d: foo="CURSOR-DOWN"; break;
  63.                 case 0x4f: foo="CURSOR-LEFT"; break;
  64.                 case 0x4e: foo="CURSOR-RIGHT"; break;
  65.                 case 0x43: foo="ENTER"; break;
  66.                 case 0x40: foo="SPACE"; break;
  67.             }
  68.             if (foo) strcpy(cbuf,foo);
  69.             if (!(myproc=(struct Process *)FindTask(NULL))) return(0);
  70.             port=&myproc->pr_MsgPort;
  71.             if (!(req=(struct IOStdReq *)LCreateExtIO(port,sizeof(struct IOStdReq)))) return(0);
  72.             if (OpenDevice("console.device",-1,(struct IORequest *)req,0)) {
  73.                 LDeleteExtIO((struct IORequest *)req);
  74.                 return(0);
  75.             }
  76.             ConsoleDevice=(struct ConsoleDevice *)req->io_Device;
  77.             inev.ie_NextEvent=NULL;
  78.             inev.ie_Class=IECLASS_RAWKEY;
  79.             inev.ie_SubClass=NULL;
  80.             inev.ie_Code=code;
  81.             inev.ie_Qualifier=qual&(IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT);
  82.             inev.ie_EventAddress=NULL;
  83.             ocbuf[0]=0;
  84.             RawKeyConvert(&inev,ocbuf,2,NULL);
  85.             ocbuf[1]=0;
  86.             CloseDevice((struct IORequest *)req);
  87.             LDeleteExtIO((struct IORequest *)req);
  88.             if (kbuf) kbuf[0]=ocbuf[0];
  89.             if (!foo) strcpy(cbuf,ocbuf);
  90.         }
  91.     }
  92.     if (buf) {
  93.         if (qual&IEQUALIFIER_LCOMMAND) StrConcat(buf,"LAMIGA + ",len);
  94.         if (qual&IEQUALIFIER_RCOMMAND) StrConcat(buf,"RAMIGA + ",len);
  95.         if (qual&IEQUALIFIER_CONTROL) StrConcat(buf,"CONTROL + ",len);
  96.         if (qual&IEQUALIFIER_LSHIFT) StrConcat(buf,"LSHIFT + ",len);
  97.         if (qual&IEQUALIFIER_RSHIFT) StrConcat(buf,"RSHIFT + ",len);
  98.         if (qual&IEQUALIFIER_LALT) StrConcat(buf,"LALT + ",len);
  99.         if (qual&IEQUALIFIER_RALT) StrConcat(buf,"RALT + ",len);
  100.         if ((code==~0 || code==0xff || code==0) && buf[0]) buf[strlen(buf)-3]=0;
  101.         else if (cbuf[0]) {
  102.             StrToUpper(cbuf,ocbuf);
  103.             StrConcat(buf,"'",len);
  104.             StrConcat(buf,ocbuf,len);
  105.             StrConcat(buf,"'",len);
  106.         }
  107.     }
  108.     return(1);
  109. }
  110.  
  111. __asm __saveds DoCheckNumGad(register __a0 struct Gadget *gad,
  112.     register __a1 struct Window *win,
  113.     register __d0 int min,
  114.     register __d1 int max)
  115. {
  116.     struct StringInfo *sinfo;
  117.     int a,b;
  118.  
  119.     sinfo=(struct StringInfo *)gad->SpecialInfo;
  120.     a=b=atoi((char *)sinfo->Buffer);
  121.     if (a<min) a=min;
  122.     else if (a>max) a=max;
  123.     LSprintf((char *)sinfo->Buffer,"%ld",a);
  124.     if (a!=b) {
  125.         if (win) RefreshStrGad(gad,win);
  126.         return(1);
  127.     }
  128.     return(0);
  129. }
  130.  
  131. __asm __saveds DoCheckHexGad(register __a0 struct Gadget *gad,
  132.     register __a1 struct Window *win,
  133.     register __d0 int min,
  134.     register __d1 int max)
  135. {
  136.     struct StringInfo *sinfo;
  137.     int a,b;
  138.  
  139.     sinfo=(struct StringInfo *)gad->SpecialInfo;
  140.     b=DoAtoh((char *)sinfo->Buffer,0);
  141.     if (sinfo->Buffer[0]==0) a=0;
  142.     else {
  143.         a=b;
  144.         if (a<min) a=min;
  145.         else if (a>max) a=max;
  146.     }
  147.     LSprintf((char *)sinfo->Buffer,"%lx",a);
  148.     if (a!=b) {
  149.         if (win) RefreshStrGad(gad,win);
  150.         return(1);
  151.     }
  152.     return(0);
  153. }
  154.  
  155. void __asm __saveds DoDecode_RLE(register __a0 char *source,
  156.     register __a1 char *dest,
  157.     register __d0 int size)
  158. {
  159.     register int a;
  160.     register char copy,count;
  161.  
  162.     for (a=0;a<size;) {
  163.         if ((count=source[a++])>=0) {
  164.             copy=count+1;
  165.             while (copy--) *dest++=source[a++];
  166.         }
  167.         else if (count!=-128) {
  168.             copy=1-count;
  169.             while (copy--) *dest++=source[a];
  170.             ++a;
  171.         }
  172.     }
  173. }
  174.  
  175. static struct TagItem
  176.     busytags[2]={
  177.         {WA_BusyPointer,1},
  178.         {TAG_DONE,0}};
  179.  
  180. extern USHORT __chip busydata13[];
  181. extern USHORT __chip busydata20[];
  182.  
  183. void __asm __saveds DoSetBusyPointer(register __a0 struct Window *wind)
  184. {
  185.     if (IntuitionBase->LibNode.lib_Version>38)
  186.         SetWindowPointerA(wind,busytags);
  187.     else if (IntuitionBase->LibNode.lib_Version<36)
  188.         SetPointer(wind,busydata13,22,16,-6,0);
  189.     else SetPointer(wind,busydata20,16,16,-6,0);
  190. }
  191.