home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / dev / gui / intuigen2.lzh / IntuiGen / IntuiGenLibs / ListViewKind.c < prev   
Encoding:
C/C++ Source or Header  |  1993-12-22  |  3.1 KB  |  139 lines

  1. /*
  2. ListViewKind.c
  3.  
  4. (C) Copyright 1993 Justin Miller
  5.     This file is part of the IntuiGen package.
  6.     Use of this code is pursuant to the license outlined in
  7.     COPYRIGHT.txt, included with the IntuiGen package.
  8.  
  9.     As per COPYRIGHT.txt:
  10.  
  11.     1)  This file may be freely distributed providing that
  12.         it is unmodified, and included in a complete IntuiGen
  13.         2.0 package (it may not be distributed alone).
  14.  
  15.     2)  Programs using this code may not be distributed unless
  16.         their author has paid the Shareware fee for IntuiGen 2.0.
  17. */
  18.  
  19.  
  20. #include <exec/exec.h>
  21. #include <clib/exec_protos.h>
  22. #include <libraries/GadTools.h>
  23. #include <clib/intuition_protos.h>
  24. #include <IntuiGen/GTRequest.h>
  25.  
  26. #define ALPHA 1  /* For AddNamedNodeToList */
  27.  
  28. #define NODUPLICATES 1 /* For AddNodeAlpha */
  29.  
  30. #define FirstNode(l) FirstItem(l)
  31. #define NextNode(n) NextItem(n)
  32.  
  33. ULONG CountNodesInList(struct List *l)
  34. {
  35.     struct Node *n;
  36.     ULONG c;
  37.  
  38.     for (c=0,n=FirstNode(l);n;n=NextNode(n),++c);
  39.     return c;
  40. }
  41.  
  42. LONG AddNodeAlpha(struct List *l,struct Node *n,ULONG flags)
  43. {
  44.     if (l && n) {
  45.     struct Node *c;
  46.     int x=1;
  47.  
  48.     for (c=l->lh_Head;c->ln_Succ;c=c->ln_Succ) {
  49.         x=stricmp(n->ln_Name,c->ln_Name);
  50.         if (x<=0) break;
  51.     }
  52.     if (x || (!(flags & NODUPLICATES) && x<=0) ) {
  53.         c=c->ln_Pred;
  54.         Insert(l,n,c);
  55.         return 1;
  56.     }
  57.     }
  58.     return 0;
  59. }
  60.  
  61. struct Node *AddNamedNodeToList(struct Remember **key,struct List *l,UBYTE *name,ULONG size,
  62.                 ULONG flags)
  63. {
  64.     struct Node *n;
  65.  
  66.     if (!size) size=sizeof(struct Node);
  67.  
  68.     if (n=AllocRemember(key,size,MEMF_PUBLIC | MEMF_CLEAR)) {
  69.     if (n->ln_Name=AllocRemember(key,strlen(name)+1,MEMF_PUBLIC)) {
  70.         strcpy(n->ln_Name,name);
  71.         if (flags & ALPHA) {
  72.         AddNodeAlpha(l,n,0);
  73.         } else AddTail(l,n);
  74.     } else n=0;
  75.     }
  76.     return n;
  77. }
  78.  
  79. UBYTE ChangeNodesName(struct Remember **key,struct GTRequest *req,
  80.      struct GTControl *gtc,struct List *l,struct Node *n,UBYTE *newname)
  81. {
  82.     UBYTE retval=0;
  83.  
  84.     SetControlAttrs(req,gtc,GTLV_Labels,~0,TAG_DONE);
  85.  
  86.     if (n->ln_Name=AllocRemember(key,strlen(newname)+1,MEMF_PUBLIC)) {
  87.     strcpy(n->ln_Name,newname);
  88.     retval=1;
  89.     }
  90.  
  91.     SetControlAttrs(req,gtc,GTLV_Labels,l,TAG_DONE);
  92.  
  93.     return retval;
  94. }
  95.  
  96. struct Node *AddEntryToListBox(struct Remember **key,struct GTRequest *req,
  97.      struct GTControl *gtc,struct List *l,UBYTE *name,ULONG size,ULONG flags)
  98. {
  99.     struct Node *n;
  100.  
  101.     SetControlAttrs(req,gtc,GTLV_Labels,~0,TAG_DONE);
  102.     n=AddNamedNodeToList(key,l,name,size,flags);
  103.     SetControlAttrs(req,gtc,GTLV_Labels,l,TAG_DONE);
  104.  
  105.     return n;
  106. }
  107.  
  108. UBYTE RemoveEntryFromListBox(struct GTRequest *req,struct GTControl *gtc,
  109.             struct List *l,struct Node *n)
  110. {
  111.     SetControlAttrs(req,gtc,GTLV_Labels,~0,TAG_DONE);
  112.     Remove(n);
  113.     SetControlAttrs(req,gtc,GTLV_Labels,l,TAG_DONE);
  114.  
  115.     return 1;
  116. }
  117.  
  118. ULONG NodeToOrd(struct List *l,struct Node *n)
  119. {
  120.     ULONG x;
  121.     struct Node *c;
  122.  
  123.     for (x=0,c=FirstItem(l);c && c!=n;c=NextItem(c),++x);
  124.     return x;
  125. }
  126.  
  127. struct Node *OrdToNode(struct List *l,ULONG ord)
  128. {
  129.     ULONG x;
  130.     struct Node *n;
  131.  
  132.     if (ord==~0) return 0;
  133.  
  134.     for (x=0,n=FirstNode(l);n && x<ord;++x,n=NextNode(n));
  135.  
  136.     return n;
  137. }
  138.  
  139.