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

  1. /* > $.CLIB.C.iconfind
  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 find icons given variouse things to serach for.
  21.  */
  22. #include "includes.h"
  23.  
  24. /*
  25.  *      given a icon structure, return the contents (title) of the icon.
  26.  */
  27. char *haswin_geticontitle(icon *iptr) {
  28.  
  29.         char    *ptr;
  30.  
  31.         if ((iptr) && (iptr->ic)) {
  32.                 if (iptr->ic[4] & 0x00000100) {
  33.                         ptr = (char *)(iptr->ic[5]);
  34.                         ptr[iptr->ic[7]] = '\0';
  35.                 } else {
  36.                         ptr = &((char *)iptr->ic)[20];
  37.                         asciilen(ptr);
  38.                 }
  39.                 return(ptr);
  40.         } else
  41.                 return("don't know");
  42. }
  43.  
  44. /*
  45.  *      given a icon structure, return the name of the icon. This does
  46.  *      not change even in writeable icons.
  47.  */
  48. char *haswin_geticonname(icon *ic) {
  49.  
  50.         if ((ic) && (ic->name))
  51.                 return(ic->name);
  52.         else
  53.                 return("don't know");
  54. }
  55.  
  56. /*
  57.  *      given a window and an icon name find the icon structure.
  58.  *      Note that window handles -1 and -2 are both on the icon bar.
  59.  */
  60. icon *haswin_findiconname(window *win, char *name) {
  61.  
  62.         register icon    *iptr;
  63.         register int     length;
  64.  
  65.         if ((!win) || (!name))
  66.                 return((icon *)0);
  67.         switch ((int)win) {
  68.         case ICONBAR_LEFT:
  69.         case ICONBAR_RIGHT:
  70.                 iptr = haswin_baricons;
  71.                 break;
  72.         default:
  73.                 iptr = win->icons;
  74.                 break;
  75.         }
  76.         length = asciilen(name);
  77.         while (iptr) {
  78.                 if (!strncmp(name, iptr->name, length))
  79.                         return(iptr);
  80.                 iptr=iptr->next;
  81.         }
  82.         return((icon *)0);
  83. }
  84. /*
  85.  *      given a window and an icon title find the icon structure.
  86.  *      Note that window handles -1 and -2 are both on the icon bar.
  87.  */
  88.  
  89. icon *haswin_findicontitle(window *win, char *name) {
  90.  
  91.         register icon    *iptr;
  92.         register int     length;
  93.  
  94.         if ((!win) || (!name))
  95.                 return((icon *)0);
  96.         switch ((int)win) {
  97.         case ICONBAR_LEFT:
  98.         case ICONBAR_RIGHT:
  99.                 iptr = haswin_baricons;
  100.                 break;
  101.         default:
  102.                 iptr = win->icons;
  103.                 break;
  104.         }
  105.         length = asciilen(name);
  106.         while (iptr) {
  107.                 if (!strncmp(name, haswin_geticontitle(iptr), length))
  108.                         return(iptr);
  109.                 iptr=iptr->next;
  110.         }
  111.         return((icon *)0);
  112. }
  113.  
  114. /*
  115.  *      given a window, and icon handle find the icon structure associated
  116.  *      with an icon.
  117.  *      Note that window handles -1 and -2 are both on the icon bar.
  118.  */
  119. icon *haswin_findiconhandle(window *win, int inum) {
  120.  
  121.         register icon    *iptr;
  122.  
  123.         if ((!win) || (inum < 0))
  124.                 return((icon *)0);
  125.         switch ((int)win) {
  126.         case ICONBAR_LEFT:
  127.         case ICONBAR_RIGHT:
  128.                 iptr = haswin_baricons;
  129.                 break;
  130.         default:
  131.                 iptr = win->icons;
  132.                 break;
  133.         }
  134.         while (iptr) {
  135.                 if (iptr->ihandle == inum)
  136.                         return(iptr);
  137.                 iptr=iptr->next;
  138.         }
  139.         return((icon *)0);
  140. }
  141.  
  142.  
  143.