home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Enlightenment / enl_BETA-0.13.src.tar.gz / enl_BETA-0.13.src.tar / enl-0.13 / lists.c < prev    next >
C/C++ Source or Header  |  1997-11-17  |  3KB  |  180 lines

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