home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Enlightenment / enl_DR-0.10.tar.gz / enl_DR-0.10.tar / enl / lists.c < prev    next >
C/C++ Source or Header  |  1997-05-13  |  4KB  |  219 lines

  1. #include "enlightenment.h"
  2.  
  3. listhead *ListInit()
  4.       {
  5.           listhead *lh;
  6.           lh=(listhead *)malloc(sizeof(listhead));
  7.           lh->num=0;
  8.           lh->first=NULL;
  9.           lh->last=NULL;
  10.           return lh;
  11.       }
  12.  
  13. void ToFront(EWin *ewin)
  14. {
  15.     struct list *ptr;
  16.     struct list *pptr;
  17.     
  18.     ptr=global_l->first;
  19.     if (ptr) ptr->win->top=0;
  20.     ewin->top=1;
  21.     pptr=NULL;
  22.     while(ptr)
  23.       {
  24.           if (ptr->win==ewin)
  25.              {
  26.                  if (pptr)
  27.                     {
  28.                         pptr->next=ptr->next;
  29.                         ptr->next=global_l->first;
  30.                         global_l->first=ptr;
  31.                         if (global_l->last==ptr) global_l->last=pptr;
  32.                     }
  33.              }
  34.           pptr=ptr;
  35.           ptr=ptr->next;
  36.       }
  37. }
  38.  
  39. void ToBack(EWin *ewin)
  40. {
  41.     struct list *ptr;
  42.     struct list *pptr;
  43.     
  44.     ptr=global_l->first;
  45.     if (ptr) ptr->win->top=1;
  46.     ewin->top=0;
  47.     pptr=NULL;
  48.     while(ptr)
  49.       {
  50.           if (ptr->win==ewin)
  51.              {
  52.                  if (pptr)
  53.                     {
  54.                         if (ptr!=global_l->last)
  55.                           {
  56.                               pptr->next=ptr->next;
  57.                               ptr->next=NULL;
  58.                               global_l->last->next=ptr;
  59.                               global_l->last=ptr;
  60.                           }
  61.                     }
  62.                  else
  63.                     {
  64.                         global_l->last->next=ptr;
  65.                         global_l->last=ptr;
  66.                         global_l->first=ptr->next;
  67.                         ptr->next=NULL;
  68.                     }
  69.              }
  70.           pptr=ptr;
  71.           ptr=ptr->next;
  72.       }
  73. }
  74.  
  75. void ListKill(listhead *l)
  76. {
  77.     struct list *node;
  78.     
  79.    node=l->first;
  80.    while(node)
  81.      {
  82.           KillEWin(node->win);
  83.           node=node->next;
  84.           free(node);
  85.      }
  86.    free(l);
  87. }
  88.  
  89. void ListAdd(listhead *l, EWin *data)
  90. {
  91.     struct list *node;
  92.  
  93.     
  94.     data->top=1;
  95.    if (l->first==NULL)
  96.      {
  97.           l->first=(struct list*)malloc(sizeof(struct list));
  98.           l->last=l->first;
  99.           if(l->first==NULL)
  100.              {
  101.                  fprintf(stderr,"Enlightenment: FATAL!!!!! PANIC!!!!!\nCannont malloc memory for vital list element\n");
  102.                  exit(1);
  103.              }
  104.           l->first->next=NULL;
  105.           l->first->win=data;
  106.           l->num++;
  107.      }
  108.    else
  109.      {
  110.           l->first->win->top=0;
  111.           node=(struct list*)malloc(sizeof(struct list));
  112.           if(node==NULL)
  113.              {
  114.                  fprintf(stderr,"Enlightenment: FATAL!!!!! PANIC!!!!!\nCannont malloc memory for vital list element\n");
  115.                  exit(1);
  116.              }
  117.           node->next=l->first;
  118.           l->first=node;
  119.           node->win=data;
  120.           l->num++;
  121.      }
  122. }
  123.  
  124. void ListDelWinID(listhead *l, Window w)
  125. {
  126.    struct list *node;
  127.    struct list *pnode;
  128.  
  129.    pnode=NULL;
  130.    node=l->first;
  131.    while(node)
  132.      {
  133.     if (node->win->frame_win==w)
  134.       {
  135.          if (l->num<=1)
  136.            {
  137.           l->first=NULL;
  138.           l->last=NULL;
  139.           l->num=0;
  140.           KillEWin(node->win);
  141.           free(node);
  142.           return;
  143.            }
  144.          else if (pnode==NULL)
  145.            {
  146.           l->first=node->next;
  147.           KillEWin(node->win);
  148.           free(node);
  149.           l->num--;
  150.           return;
  151.            }
  152.          else
  153.            {
  154.           pnode->next=node->next;
  155.           if (node->next==NULL) l->last=pnode;
  156.           KillEWin(node->win);
  157.           free(node);
  158.           l->num--;
  159.           return;
  160.            }
  161.       }
  162.     pnode=node;
  163.     node=node->next;
  164.      }
  165. }
  166.  
  167.  
  168. EWin *ListGetWinID(listhead *l, Window w)
  169. {
  170.    struct list *node;
  171.  
  172.    node=l->first;
  173.    while(node)
  174.      {
  175.     if (node->win->frame_win==w)
  176.       {
  177.          return node->win;
  178.       }
  179.     node=node->next;
  180.      }
  181.    return NULL;
  182. }
  183.  
  184. EWin *ListGetClientWinID(listhead *l, Window w)
  185. {
  186.    struct list *node;
  187.  
  188.    node=l->first;
  189.    while(node)
  190.      {
  191.     if (node->win->client_win==w)
  192.       {
  193.          return node->win;
  194.       }
  195.     node=node->next;
  196.      }
  197.    return NULL;
  198. }
  199.  
  200. EWin *ListGetSubWinID(listhead *l, Window w)
  201. {
  202.    struct list *node;
  203.    int i;
  204.  
  205.    node=l->first;
  206.    while(node)
  207.      {
  208.     for (i=0;i<node->win->num_subwins;i++)
  209.       {
  210.          if (node->win->subwins[i]==w)
  211.            {
  212.           return node->win;
  213.            }
  214.       }
  215.     node=node->next;
  216.      }
  217.    return NULL;
  218. }
  219.