home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / haswinlib / c / iconset < prev    next >
Encoding:
Text File  |  1991-02-04  |  5.7 KB  |  189 lines

  1. /* > $.CLIB.C.iconset
  2.  *
  3.  *      HASWIN Graphics Library
  4.  *     =========================
  5.  *
  6.  *      Copyright (C) H.A.Shaw 1990.
  7.  *              Howard A. Shaw.
  8.  *              The Unit for Space Sciences,
  9.  *              Room 165,
  10.  *              Physics Building,
  11.  *              University of Kent at Canterbury.
  12.  *              Canterbury.
  13.  *              Kent.  CT2 7NJ
  14.  *      You may use and distribute this code freely, however please leave
  15.  *      it alone.  If you find bugs (and there will be many) please contact
  16.  *      me and the master source can be modified.  If you keep me informed
  17.  *      of who you give copies of this to then I can get release upgrades
  18.  *      to them.
  19.  *
  20.  *      These routines change or get things to do with icons.
  21.  */
  22. #include "includes.h"
  23.  
  24. /************************************************************************
  25.  *                                                                      *
  26.  *              Routines to control the Icon part of the WIMP.          *
  27.  *                                                                      *
  28.  ************************************************************************/
  29.  
  30. /*
  31.  *      change the data (title/spritename/contents) of an icon, and redraw.
  32.  *      For indirected sprites the pointer to the area pointer is the
  33.  *      validation string.  If ic->name is 0, then set icon data up for
  34.  *      the first time.
  35.  */
  36. int haswin_seticondata(icon *ic, char *data) {
  37.  
  38.         char    *stmp;
  39.         int     spritearea;
  40.         int     nic[9], dic[2];
  41.         window  *wptr;
  42.         _kernel_swi_regs  regs;
  43.  
  44.         if (!ic)
  45.                 return(-1);
  46.  
  47.         if (!ic->name) {
  48.                 ic->name = haswin_malloc(asciilen(data)+1, "haswin_seticondata", "icon name");
  49.                 strcpy(ic->name, data);
  50.         } else {
  51.                 if (!strcmp(haswin_geticontitle(ic), data))
  52.                         /* data has not changed, nothing to do! */
  53.                         return(ic->ihandle);
  54.         }
  55.         wptr = haswin_findwindowhandle(ic->whandle);
  56. /* create a new icon definition in nic */
  57.         nic[0] = ic->whandle;
  58.         nic[1] = ic->ic[0];
  59.         nic[2] = ic->ic[1];
  60.         nic[3] = ic->ic[2];
  61.         nic[4] = ic->ic[3];
  62.         nic[5] = ic->ic[4] | 0x00000100;
  63.         nic[6] = ic->ic[5];
  64.         nic[7] = ic->ic[6];
  65. /* if the icon is writable then don't shorten its length */
  66.         if (((ic->ic[4]&0xE000) == 0xE000) && (ic->ic[7] > strlen(data))) {
  67.                 stmp = haswin_realloc((void *)(ic->ic[5]), ic->ic[7]+1, "haswin_seticondata", "icon data 1");
  68.                 nic[8] = ic->ic[7];
  69.         } else {
  70.                 stmp = haswin_realloc((void *)(ic->ic[5]), strlen(data)+1, "haswin_seticondata", "icon data 2");
  71.                 nic[8] = strlen(data);
  72.         }
  73.         strcpy(stmp, data);
  74.         nic[6] = (int)stmp;
  75.         if ((nic[5] & 0x00000003) == 0x00000002) {
  76.                 /* icon is a sprite ! */
  77.                 /* find the sprite area control block for this sprite */
  78.                 /* if none found then put it in WIMP area */
  79.                 if ((spritearea=haswin_findsprite(stmp)) == HASWIN_UNKNOWN)
  80.                         spritearea = 1;
  81.                 nic[7] = (int)spritearea;
  82.         } else
  83.                 nic[7] = ((int *)ic->ic)[6];
  84. /* delete the existing icon definition */
  85.         dic[0] = ic->whandle;
  86.         dic[1] = ic->ihandle;
  87.         regs.r[1] = (int)dic;
  88.         if (!haswin_swi(HASWIN_Delete_icon, ®s))
  89.                 return(ic->ihandle);
  90. /* recreate the icon */
  91.         regs.r[1] = (int)nic;
  92.         if (!haswin_swi(HASWIN_Create_icon, ®s))
  93.                 return(-1);
  94.         ic->ihandle = regs.r[0];
  95.         ic->ic[0] = nic[1];
  96.         ic->ic[1] = nic[2];
  97.         ic->ic[2] = nic[3];
  98.         ic->ic[3] = nic[4];
  99.         ic->ic[4] = nic[5];
  100.         ic->ic[5] = nic[6];
  101.         ic->ic[6] = nic[7];
  102.         ic->ic[7] = nic[8];
  103.         haswin_redrawwindow(wptr, nic[1], nic[3], nic[2], nic[4]);
  104.         if (ic->ihandle > wptr->numicons)
  105.                 wptr->numicons = ic->ihandle;
  106.         return(ic->ihandle);
  107. }
  108.  
  109. /*
  110.  *      change the flags of an icon, and redraw.
  111.  *      Remember action is...
  112.  *      new-state = (old-state AND NOT mask) OR bits
  113.  */
  114. void haswin_seticonstate(icon *ic, int mask, int bits) {
  115.  
  116.         int     tmp[4];
  117.         _kernel_swi_regs  regs;
  118.  
  119.         if (!ic)
  120.                 return;
  121.         tmp[0] = ic->whandle;
  122.         tmp[1] = ic->ihandle;
  123.         tmp[2] = bits;
  124.         tmp[3] = mask;
  125.         ((int *)ic->ic)[4] &= ~mask;
  126.         ((int *)ic->ic)[4] |= bits;
  127.         regs.r[1] = (int)tmp;
  128.         haswin_swi(HASWIN_Set_icon_state, ®s);
  129.         return;
  130. }
  131.  
  132. int haswin_geticonxmin(icon *ic) {
  133.  
  134.         if ((!ic) || (!ic->ic))
  135.                 return(HASWIN_UNKNOWN);
  136.         return(ic->ic[0]);
  137. }
  138.  
  139. int haswin_geticonxmax(icon *ic) {
  140.  
  141.         if ((!ic) || (!ic->ic))
  142.                 return(HASWIN_UNKNOWN);
  143.         return(ic->ic[2]);
  144. }
  145.  
  146. int haswin_geticonymin(icon *ic) {
  147.  
  148.         if ((!ic) || (!ic->ic))
  149.                 return(HASWIN_UNKNOWN);
  150.         return(ic->ic[1]);
  151. }
  152.  
  153. int haswin_geticonymax(icon *ic) {
  154.  
  155.         if ((!ic) || (!ic->ic))
  156.                 return(HASWIN_UNKNOWN);
  157.         return(ic->ic[3]);
  158. }
  159.  
  160. int haswin_newiconflags(icon *ic, int new) {
  161.  
  162.         if (!ic)
  163.                 return(HASWIN_FALSE);
  164.         ic->flags = new;
  165.         return(HASWIN_TRUE);
  166. }
  167.  
  168. int haswin_seticonflags(icon *ic, int new) {
  169.  
  170.         if (!ic)
  171.                 return(HASWIN_FALSE);
  172.         return(haswin_newiconflags(ic, ic->flags | new));
  173. }
  174.  
  175. int haswin_cleariconflags(icon *ic, int new) {
  176.  
  177.         if (!ic)
  178.                 return(HASWIN_FALSE);
  179.         return(haswin_newiconflags(ic, ic->flags & ~new));
  180. }
  181.  
  182. int haswin_geticonflags(icon *ic) {
  183.  
  184.         if (!ic)
  185.                 return(HASWIN_UNKNOWN);
  186.         return(ic->flags);
  187. }
  188.  
  189.