Restructure how we look for Read files slightly.
[fvwm.git] / modules / FvwmTaskBar / List.c
blob949df0f0b42e018097e017a9d9ba6583b648909e
1 /* -*-c-*- */
2 /* FvwmTaskBar Module for Fvwm.
4 * Copyright 1994, Mike Finger (mfinger@mermaid.micro.umn.edu or
5 * Mike_Finger@atk.com)
7 * The functions in this source file are the original work of Mike Finger.
9 * No guarantees or warantees or anything are provided or implied in any way
10 * whatsoever. Use this program at your own risk. Permission to use this
11 * program for any purpose is given, as long as the copyright is kept intact.
15 /* This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "config.h"
31 #include "libs/Module.h"
33 #include <stdio.h>
35 #include "FvwmTaskBar.h"
36 #include "List.h"
37 #include "Mallocs.h"
39 extern ModuleArgs *module;
42 InitList - Initialize the list
44 void InitList(List *list)
46 list->head=list->tail=NULL;
47 list->count=0;
51 AddItem - Allocates spaces for and appends an item to the list
53 void AddItem(List *list, long id, ConfigWinPacket *cfgpacket,
54 long Desk, int count)
56 Item *new;
57 new=(Item *)safemalloc(sizeof(Item));
58 new->id=id;
59 new->name=NULL;
60 memcpy(&new->flags, &cfgpacket->flags, sizeof(new->flags));
61 new->Desk=Desk;
62 new->count=count;
63 memset((void *)&(new->p), 0, sizeof(FvwmPicture));
64 new->next=NULL;
65 if (list->tail==NULL) list->head=list->tail=new;
66 else {
67 list->tail->next=new;
68 list->tail=new;
70 list->count++;
74 AddItemName - Allocates spaces for and appends an item to the list
76 void AddItemName(List *list, char *string, int iconified)
78 Item *new;
80 new = (Item *)safemalloc(sizeof(Item));
81 new->id = 0L;
82 new->name = NULL;
83 UpdateString(&new->name, string);
84 SET_ICONIFIED(new,iconified);
85 new->next = NULL;
87 if (list->tail == NULL)
88 list->head = list->tail = new;
89 else
91 list->tail->next = new;
92 list->tail = new;
94 list->count++;
99 FindItem - Find the item in the list matching the id
101 int FindItem(List *list, long id)
103 Item *temp;
105 for(temp=list->head;temp!=NULL && temp->id!=id;temp=temp->next);
106 if (temp==NULL)
107 return -1;
108 return temp->count;
112 FindNameItem - Find the item in the list matching the string
114 int FindNameItem(List *list, char *string)
116 Item *temp;
118 for(temp=list->head;
119 temp!=NULL && strcmp(temp->name,string) != 0;
120 temp=temp->next);
121 if (temp==NULL) return -1;
122 return temp->count;
126 UpdateItem* - Update the item in the list
129 int UpdateItemName(List *list, long id, char *string)
131 Item *temp;
132 for(temp=list->head;temp!=NULL && id!=temp->id;temp=temp->next);
133 if (temp==NULL) return -1;
134 UpdateString(&temp->name,string);
135 return temp->count;
138 int UpdateItemIconifiedFlag(List *list, long id, int iconified)
140 Item *temp;
141 for(temp=list->head;temp!=NULL && id!=temp->id;temp=temp->next);
142 if (temp==NULL) return -1;
143 SET_ICONIFIED(temp,iconified);
144 return temp->count;
147 int UpdateItemGSFRFlags(List *list, ConfigWinPacket *cfgpacket)
149 Item *temp;
150 for(temp=list->head;temp!=NULL && cfgpacket->w!=temp->id;temp=temp->next);
151 if (temp==NULL) return -1;
152 temp->flags = cfgpacket->flags;
153 return temp->count;
156 int UpdateItemIndexDesk(List *list, int i, long desk)
158 Item *temp;
159 for(temp=list->head;temp!=NULL && temp->count!=i;temp=temp->next);
160 if (temp==NULL) return -1;
161 temp->Desk=desk;
162 return temp->count;
165 int UpdateNameItem(List *list, char *string, long id, int iconified)
167 Item *temp;
169 for(temp=list->head;
170 temp!=NULL && strcmp(temp->name,string) != 0;
171 temp=temp->next);
172 if (temp==NULL) return -1;
173 else {
174 if (id != -1) temp->id = id;
175 if (iconified != -1) SET_ICONIFIED(temp,iconified);
176 return temp->count;
180 int UpdateItemIndexGeometry(List *list, int i, rectangle *new_g)
182 Item *temp;
183 for(temp=list->head;temp!=NULL && temp->count!=i;temp=temp->next);
184 if (temp==NULL) return -1;
185 temp->win_g = *new_g;
186 return temp->count;
190 FreeItem - Frees allocated space for an Item
192 void FreeItem(Item *ptr)
194 if (ptr != NULL) {
195 if (ptr->name!=NULL) free(ptr->name);
196 free(ptr);
201 DeleteItem - Deletes an item from the list
203 int DeleteItem(List *list,long id)
205 Item *temp,*temp2;
206 int i;
207 if (list->head==NULL) return -1;
208 if (list->head->id==id) {
209 temp2=list->head;
210 temp=list->head=list->head->next;
211 i=temp2->count;
212 } else {
213 for(temp=list->head,temp2=temp->next; temp2; temp2=temp2->next) {
214 if (temp2->id == id)
215 break;
216 temp = temp2;
218 if (temp2 == NULL) return -1;
219 temp->next=temp2->next;
222 if (temp2==list->tail) list->tail=temp;
224 i=temp2->count;
225 FreeItem(temp2);
226 list->count--;
227 return i;
228 /* return i+1; */
232 FreeList - Free the entire list of Items
234 void FreeList(List *list)
236 Item *temp,*temp2;
237 for(temp=list->head;temp!=NULL;)
239 temp2=temp;
240 temp=temp->next;
241 FreeItem(temp2);
243 list->count=0;
247 PrintList - Print the list of item to stderr. (Debugging)
249 void PrintList(List *list)
251 Item *temp;
252 fprintf(stderr,"%s List of Items:\n", module->name);
253 fprintf(stderr," %10s %-15s %-15s %-15s %-15s Flgs\n","ID","Name","I-Name",
254 "R-Name","R-Class");
255 fprintf(stderr," ---------- --------------- --------------- --------------- --------------- ----\n");
256 for(temp=list->head;temp!=NULL;temp=temp->next) {
257 fprintf(stderr," %10ld %-15.15s\n",temp->id,
258 (temp->name==NULL) ? "<null>" : temp->name);
263 ItemName - Return the name of an Item
265 char *ItemName(List *list, int n)
267 Item *temp;
268 for(temp=list->head;temp!=NULL && temp->count!=n;temp=temp->next);
269 if (temp==NULL) return NULL;
270 return temp->name;
274 IsItemIndexIconified - Say if an item is iconified
276 int IsItemIconified(List *list, long id)
278 Item *temp;
279 for(temp=list->head;temp!=NULL && temp->id!=id;temp=temp->next);
280 if (temp==NULL) return -1;
281 return IS_ICONIFIED(temp);
285 IsItemIndexIconified - Say if an item of index i is iconified
287 int IsItemIndexIconified(List *list, int i)
289 Item *temp;
290 for(temp=list->head;temp!=NULL && temp->count!=i;temp=temp->next);
291 if (temp==NULL) return -1;
292 return IS_ICONIFIED(temp);
296 IsItemIndexSticky - Say if an item of index i is sticky
298 int IsItemIndexSticky(List *list, int i)
300 Item *temp;
301 for(temp=list->head;temp!=NULL && temp->count!=i;temp=temp->next);
302 if (temp==NULL) return -1;
303 return (IS_STICKY_ACROSS_DESKS(temp) ||
304 (IS_ICONIFIED(temp) && IS_ICON_STICKY_ACROSS_DESKS(temp)));
308 IsItemIndexSkipWindowList - Say if an item of index i is in the skip list
310 int IsItemIndexSkipWindowList(List *list, int i)
312 Item *temp;
313 for(temp=list->head;temp!=NULL && temp->count!=i;temp=temp->next);
314 if (temp==NULL) return -1;
315 return DO_SKIP_WINDOW_LIST(temp);
319 IsItemIndexIconSuppressed - Say if an item has a no icon style
321 int IsItemIndexIconSuppressed(List *list, int i)
323 Item *temp;
324 for(temp=list->head;temp!=NULL && temp->count!=i;temp=temp->next);
325 if (temp==NULL) return -1;
326 return IS_ICON_SUPPRESSED(temp);
330 ItemCount - Return the number of items inthe list
332 int ItemCount(List *list)
334 return list->count;
338 ItemID - Return the ID of the item in the list.
340 long ItemID(List *list, int n)
342 Item *temp;
343 for(temp=list->head;temp!=NULL && temp->count!=n;temp=temp->next);
344 if (temp==NULL) return -1;
345 return temp->id;
349 CopyItem - Copy an item from one list to another
351 void CopyItem(List *dest, List *source, int n)
353 Item *temp;
354 ConfigWinPacket cfgpkt;
356 for(temp=source->head;temp!=NULL && temp->count!=n;temp=temp->next);
357 if (temp==NULL) return;
358 memcpy(&cfgpkt.flags, &temp->flags, sizeof(cfgpkt.flags));
359 AddItem(dest, temp->id, &cfgpkt,temp->Desk,temp->count);
360 UpdateItemName(dest,temp->id,temp->name);
361 DeleteItem(source,temp->id);
365 UpdateItemPicture - Adds the picture information in the list
367 void UpdateItemPicture(List *list, int n, FvwmPicture *p)
369 Item *temp;
371 for (temp=list->head;temp && temp->count!=n;temp=temp->next);
372 if (temp==NULL) return;
373 if (p != NULL)
375 temp->p.picture = p->picture;
376 temp->p.mask = p->mask;
377 temp->p.alpha = p->alpha;
378 temp->p.width = p->width;
379 temp->p.height = p->height;
380 temp->p.depth = p->depth;
382 else
384 temp->p.picture = None;
385 temp->p.mask = None;
386 temp->p.alpha = None;
387 temp->p.width = 0;
388 temp->p.height = 0;
389 temp->p.depth = 0;
394 GetDeskNumber - Returns the desknumber of the item
396 int GetDeskNumber(List *list, int n, long *Desk)
398 Item *temp;
400 for (temp=list->head;temp && temp->count!=n;temp=temp->next);
401 if (temp==NULL) return 0;
402 *Desk=temp->Desk;
403 return 1;
407 GetItemPicture - Returns the picture
409 FvwmPicture *GetItemPicture(List *list, int n)
411 Item *temp;
413 for (temp=list->head;temp && temp->count!=n;temp=temp->next);
414 if (temp==NULL) return 0;
415 return &(temp->p);
419 GetItemGeometry - returns a pointer to the internal geometry rectangle
421 int GetItemGeometry(List *list, int n, rectangle **r)
423 Item *temp;
425 for (temp=list->head;temp && temp->count!=n;temp=temp->next);
426 if (temp==NULL) return 0;
427 *r=&temp->win_g;
428 return 1;