Icon creation in only one function
[wmaker-crm.git] / WINGs / WINGs / WUtil.h
blob30476e0951a3adb60fe7788cc83f52ec5207ad19
1 #ifndef _WUTIL_H_
2 #define _WUTIL_H_
4 #include <X11/Xlib.h>
5 #include <limits.h>
6 #include <sys/types.h>
8 /* SunOS 4.x Blargh.... */
9 #ifndef NULL
10 #define NULL ((void*)0)
11 #endif
14 #ifndef WMAX
15 # define WMAX(a,b) ((a)>(b) ? (a) : (b))
16 #endif
17 #ifndef WMIN
18 # define WMIN(a,b) ((a)<(b) ? (a) : (b))
19 #endif
22 #ifndef __ASSERT_FUNCTION
23 # if (!defined (__GNUC__) || (__GNUC__ < 2 && \
24 __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4)))
25 # define __ASSERT_FUNCTION ((char *) 0)
26 # else
27 # define __ASSERT_FUNCTION __PRETTY_FUNCTION__
28 # endif
29 #endif
31 #ifndef __GNUC__
32 #define __attribute__(x) /*NOTHING*/
33 #endif
35 #ifdef NDEBUG
37 #define wassertr(expr) {}
38 #define wassertrv(expr, val) {}
40 #else /* !NDEBUG */
42 #ifdef DEBUG
44 #include <assert.h>
46 #define wassertr(expr) assert(expr)
48 #define wassertrv(expr, val) assert(expr)
50 #else /* !DEBUG */
52 #define wassertr(expr) \
53 if (!(expr)) { \
54 wwarning("%s line %i (%s): assertion %s failed",\
55 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
56 return;\
59 #define wassertrv(expr, val) \
60 if (!(expr)) { \
61 wwarning("%s line %i (%s): assertion %s failed",\
62 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
63 return (val);\
65 #endif /* !DEBUG */
67 #endif /* !NDEBUG */
70 #ifdef __cplusplus
71 extern "C" {
72 #endif /* __cplusplus */
75 typedef enum {
76 WMPostWhenIdle = 1,
77 WMPostASAP = 2,
78 WMPostNow = 3
79 } WMPostingStyle;
82 typedef enum {
83 WNCNone = 0,
84 WNCOnName = 1,
85 WNCOnSender = 2
86 } WMNotificationCoalescing;
90 enum {
91 WBNotFound = INT_MIN, /* element was not found in WMBag */
92 WANotFound = -1 /* element was not found in WMArray */
96 typedef struct W_Array WMArray;
97 typedef struct W_Bag WMBag;
98 typedef struct W_Data WMData;
99 typedef struct W_TreeNode WMTreeNode;
100 typedef struct W_HashTable WMHashTable;
101 typedef struct W_UserDefaults WMUserDefaults;
102 typedef struct W_Notification WMNotification;
103 typedef struct W_NotificationQueue WMNotificationQueue;
104 typedef struct W_Host WMHost;
105 typedef struct W_Connection WMConnection;
106 typedef struct W_PropList WMPropList;
110 /* Some typedefs for the handler stuff */
111 typedef void *WMHandlerID;
113 typedef void WMCallback(void *data);
115 typedef void WMInputProc(int fd, int mask, void *clientData);
119 typedef int WMCompareDataProc(const void *item1, const void *item2);
120 typedef void WMTreeWalkProc(WMTreeNode *aNode, void *data);
122 typedef void WMFreeDataProc(void *data);
124 /* Used by WMBag or WMArray for matching data */
125 typedef int WMMatchDataProc(const void *item, const void *cdata);
129 typedef struct {
130 int position;
131 int count;
132 } WMRange;
136 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
137 typedef struct {
138 void *table;
139 void *nextItem;
140 int index;
141 } WMHashEnumerator;
144 typedef struct {
145 /* NULL is pointer hash */
146 unsigned (*hash)(const void *);
147 /* NULL is pointer compare */
148 Bool (*keyIsEqual)(const void *, const void *);
149 /* NULL does nothing */
150 void* (*retainKey)(const void *);
151 /* NULL does nothing */
152 void (*releaseKey)(const void *);
153 } WMHashTableCallbacks;
156 typedef int WMArrayIterator;
157 typedef void *WMBagIterator;
160 typedef void WMNotificationObserverAction(void *observerData,
161 WMNotification *notification);
164 /* ---[ WINGs/memory.c ]-------------------------------------------------- */
166 void* wmalloc(size_t size);
167 void* wrealloc(void *ptr, size_t newsize);
168 void wfree(void *ptr);
170 void wrelease(void *ptr);
171 void* wretain(void *ptr);
173 typedef void waborthandler(int);
175 waborthandler* wsetabort(waborthandler* handler);
177 /* ---[ WINGs/error.c ]--------------------------------------------------- */
179 enum {
180 WMESSAGE_TYPE_MESSAGE,
181 WMESSAGE_TYPE_WARNING,
182 WMESSAGE_TYPE_ERROR,
183 WMESSAGE_TYPE_FATAL
186 #define wmessage(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_MESSAGE, fmt, ## args)
187 #define wwarning(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_WARNING, fmt, ## args)
188 #define werror(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_ERROR, fmt, ## args)
189 #define wfatal(fmt, args...) __wmessage( __func__, __FILE__, __LINE__, WMESSAGE_TYPE_FATAL, fmt, ## args)
191 void __wmessage(const char *func, const char *file, int line, int type, const char *msg, ...)
192 __attribute__((__format__(printf,5,6)));
194 /* ---[ WINGs/findfile.c ]------------------------------------------------ */
196 char* wfindfile(char *paths, char *file);
198 char* wfindfileinlist(char **path_list, char *file);
200 char* wfindfileinarray(WMPropList* array, char *file);
202 char* wexpandpath(char *path);
204 int wcopy_file(char *toPath, char *srcFile, char *destFile);
206 /* don't free the returned string */
207 char* wgethomedir(void);
209 /* ---[ WINGs/proplist.c ]------------------------------------------------ */
211 int wmkdirhier(const char *path);
212 int wrmdirhier(const char *path);
214 /* ---[ WINGs/string.c ]-------------------------------------------------- */
216 char *wstrdup(const char *str);
217 char* wstrndup(const char *str, size_t len);
219 /* Concatenate str1 with str2 and return that in a newly malloc'ed string.
220 * str1 and str2 can be any strings including static and constant strings.
221 * str1 and str2 will not be modified.
222 * Free the returned string when you're done with it. */
223 char* wstrconcat(char *str1, char *str2);
225 /* This will append src to dst, and return dst. dst MUST be either NULL
226 * or a string that was a result of a dynamic allocation (malloc, realloc
227 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
228 * Modifies dst (no new string is created except if dst==NULL in which case
229 * it is equivalent to calling wstrdup(src) ).
230 * The returned address may be different from the original address of dst,
231 * so always assign the returned address to avoid dangling pointers. */
232 char* wstrappend(char *dst, char *src);
234 size_t wstrlcpy(char *, const char *, size_t);
235 size_t wstrlcat(char *, const char *, size_t);
238 void wtokensplit(char *command, char ***argv, int *argc);
240 char* wtokennext(char *word, char **next);
242 char* wtokenjoin(char **list, int count);
244 void wtokenfree(char **tokens, int count);
246 char* wtrimspace(const char *s);
248 /* transform `s' so that the result is safe to pass to the shell as an argument.
249 * returns a newly allocated string.
250 * with very heavy inspirations from NetBSD's shquote(3).
252 char *wshellquote(const char *s);
254 /* ---[ WINGs/wmisc.c ]--------------------------------------------------- */
256 WMRange wmkrange(int start, int count);
258 /* ---[ WINGs/usleep.c ]-------------------------------------------------- */
260 void wusleep(unsigned int usec);
262 /* ---[ WINGs/handlers.c ]------------------------------------------------ */
264 /* Event handlers: timer, idle, input */
266 WMHandlerID WMAddTimerHandler(int milliseconds, WMCallback *callback,
267 void *cdata);
269 WMHandlerID WMAddPersistentTimerHandler(int milliseconds, WMCallback *callback,
270 void *cdata);
272 void WMDeleteTimerWithClientData(void *cdata);
274 void WMDeleteTimerHandler(WMHandlerID handlerID);
276 WMHandlerID WMAddIdleHandler(WMCallback *callback, void *cdata);
278 void WMDeleteIdleHandler(WMHandlerID handlerID);
280 WMHandlerID WMAddInputHandler(int fd, int condition, WMInputProc *proc,
281 void *clientData);
283 void WMDeleteInputHandler(WMHandlerID handlerID);
286 /* This function is used _only_ if you create a non-GUI program.
287 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
288 * This function will handle all input/timer/idle events, then return.
291 void WHandleEvents(void);
293 /* ---[ WINGs/hashtable.c ]----------------------------------------------- */
296 WMHashTable* WMCreateHashTable(WMHashTableCallbacks callbacks);
298 void WMFreeHashTable(WMHashTable *table);
300 void WMResetHashTable(WMHashTable *table);
302 unsigned WMCountHashTable(WMHashTable *table);
304 void* WMHashGet(WMHashTable *table, const void *key);
306 /* Returns True if there is a value associated with <key> in the table, in
307 * which case <retKey> and <retItem> will contain the item's internal key
308 * address and the item's value respectively.
309 * If there is no value associated with <key> it will return False and in
310 * this case <retKey> and <retItem> will be undefined.
311 * Use this when you need to perform your own custom retain/release mechanism
312 * which requires access to the keys too.
314 Bool WMHashGetItemAndKey(WMHashTable *table, const void *key,
315 void **retItem, void **retKey);
317 /* put data in table, replacing already existing data and returning
318 * the old value */
319 void* WMHashInsert(WMHashTable *table, const void *key, const void *data);
321 void WMHashRemove(WMHashTable *table, const void *key);
323 /* warning: do not manipulate the table while using the enumerator functions */
324 WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
326 void* WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
328 void* WMNextHashEnumeratorKey(WMHashEnumerator *enumerator);
330 /* Returns True if there is a next element, in which case key and item
331 * will contain the next element's key and value respectively.
332 * If there is no next element available it will return False and in this
333 * case key and item will be undefined.
335 Bool WMNextHashEnumeratorItemAndKey(WMHashEnumerator *enumerator,
336 void **item, void **key);
341 /* some predefined callback sets */
343 extern const WMHashTableCallbacks WMIntHashCallbacks;
344 /* sizeof(keys) are <= sizeof(void*) */
346 extern const WMHashTableCallbacks WMStringHashCallbacks;
347 /* keys are strings. Strings will be copied with wstrdup()
348 * and freed with wfree() */
350 extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
351 /* keys are strings, but they are not copied */
354 /* ---[ WINGs/array.c ]--------------------------------------------------- */
357 * WMArray use an array to store the elements.
358 * Item indexes may be only positive integer numbers.
359 * The array cannot contain holes in it.
361 * Pros:
362 * Fast [O(1)] access to elements
363 * Fast [O(1)] push/pop
365 * Cons:
366 * A little slower [O(n)] for insertion/deletion of elements that
367 * aren't in the end
370 WMArray* WMCreateArray(int initialSize);
372 WMArray* WMCreateArrayWithDestructor(int initialSize, WMFreeDataProc *destructor);
374 WMArray* WMCreateArrayWithArray(WMArray *array);
376 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
378 void WMEmptyArray(WMArray *array);
380 void WMFreeArray(WMArray *array);
382 int WMGetArrayItemCount(WMArray *array);
384 /* appends other to array. other remains unchanged */
385 void WMAppendArray(WMArray *array, WMArray *other);
387 /* add will place the element at the end of the array */
388 void WMAddToArray(WMArray *array, void *item);
390 /* insert will increment the index of elements after it by 1 */
391 void WMInsertInArray(WMArray *array, int index, void *item);
393 /* replace and set will return the old item WITHOUT calling the
394 * destructor on it even if its available. Free the returned item yourself.
396 void* WMReplaceInArray(WMArray *array, int index, void *item);
398 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
400 /* delete and remove will remove the elements and cause the elements
401 * after them to decrement their indexes by 1. Also will call the
402 * destructor on the deleted element if there's one available.
404 int WMDeleteFromArray(WMArray *array, int index);
406 #define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
408 int WMRemoveFromArrayMatching(WMArray *array, WMMatchDataProc *match, void *cdata);
410 void* WMGetFromArray(WMArray *array, int index);
412 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
414 /* pop will return the last element from the array, also removing it
415 * from the array. The destructor is NOT called, even if available.
416 * Free the returned element if needed by yourself
418 void* WMPopFromArray(WMArray *array);
420 int WMFindInArray(WMArray *array, WMMatchDataProc *match, void *cdata);
422 int WMCountInArray(WMArray *array, void *item);
424 /* comparer must return:
425 * < 0 if a < b
426 * > 0 if a > b
427 * = 0 if a = b
429 void WMSortArray(WMArray *array, WMCompareDataProc *comparer);
431 void WMMapArray(WMArray *array, void (*function)(void*, void*), void *data);
433 WMArray* WMGetSubarrayWithRange(WMArray* array, WMRange aRange);
435 void* WMArrayFirst(WMArray *array, WMArrayIterator *iter);
437 void* WMArrayLast(WMArray *array, WMArrayIterator *iter);
439 /* The following 2 functions assume that the array doesn't change between calls */
440 void* WMArrayNext(WMArray *array, WMArrayIterator *iter);
442 void* WMArrayPrevious(WMArray *array, WMArrayIterator *iter);
445 /* The following 2 macros assume that the array doesn't change in the for loop */
446 #define WM_ITERATE_ARRAY(array, var, i) \
447 for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
448 var = WMArrayNext(array, &(i)))
450 #define WM_ETARETI_ARRAY(array, var, i) \
451 for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
452 var = WMArrayPrevious(array, &(i)))
454 /* ---[ WINGs/bagtree.c ]------------------------------------------------- */
457 * Tree bags use a red-black tree for storage.
458 * Item indexes may be any integer number.
460 * Pros:
461 * O(lg n) insertion/deletion/search
462 * Good for large numbers of elements with sparse indexes
464 * Cons:
465 * O(lg n) insertion/deletion/search
466 * Slow for storing small numbers of elements
469 #define WMCreateBag(size) WMCreateTreeBag()
471 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
473 WMBag* WMCreateTreeBag(void);
475 WMBag* WMCreateTreeBagWithDestructor(WMFreeDataProc *destructor);
477 int WMGetBagItemCount(WMBag *bag);
479 void WMAppendBag(WMBag *bag, WMBag *other);
481 void WMPutInBag(WMBag *bag, void *item);
483 /* insert will increment the index of elements after it by 1 */
484 void WMInsertInBag(WMBag *bag, int index, void *item);
486 /* erase will remove the element from the bag,
487 * but will keep the index of the other elements unchanged */
488 int WMEraseFromBag(WMBag *bag, int index);
490 /* delete and remove will remove the elements and cause the elements
491 * after them to decrement their indexes by 1 */
492 int WMDeleteFromBag(WMBag *bag, int index);
494 int WMRemoveFromBag(WMBag *bag, void *item);
496 void* WMGetFromBag(WMBag *bag, int index);
498 void* WMReplaceInBag(WMBag *bag, int index, void *item);
500 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
502 /* comparer must return:
503 * < 0 if a < b
504 * > 0 if a > b
505 * = 0 if a = b
507 void WMSortBag(WMBag *bag, WMCompareDataProc *comparer);
509 void WMEmptyBag(WMBag *bag);
511 void WMFreeBag(WMBag *bag);
513 void WMMapBag(WMBag *bag, void (*function)(void*, void*), void *data);
515 int WMGetFirstInBag(WMBag *bag, void *item);
517 int WMCountInBag(WMBag *bag, void *item);
519 int WMFindInBag(WMBag *bag, WMMatchDataProc *match, void *cdata);
521 void* WMBagFirst(WMBag *bag, WMBagIterator *ptr);
523 void* WMBagLast(WMBag *bag, WMBagIterator *ptr);
525 /* The following 4 functions assume that the bag doesn't change between calls */
526 void* WMBagNext(WMBag *bag, WMBagIterator *ptr);
528 void* WMBagPrevious(WMBag *bag, WMBagIterator *ptr);
530 void* WMBagIteratorAtIndex(WMBag *bag, int index, WMBagIterator *ptr);
532 int WMBagIndexForIterator(WMBag *bag, WMBagIterator ptr);
535 /* The following 2 macros assume that the bag doesn't change in the for loop */
536 #define WM_ITERATE_BAG(bag, var, i) \
537 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
538 var = WMBagNext(bag, &(i)))
540 #define WM_ETARETI_BAG(bag, var, i) \
541 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
542 var = WMBagPrevious(bag, &(i)))
546 /* ---[ WINGs/data.c ]---------------------------------------------------- */
548 /* WMData handling */
550 /* Creating/destroying data */
552 WMData* WMCreateDataWithCapacity(unsigned capacity);
554 WMData* WMCreateDataWithLength(unsigned length);
556 WMData* WMCreateDataWithBytes(void *bytes, unsigned length);
558 /* destructor is a function called to free the data when releasing the data
559 * object, or NULL if no freeing of data is necesary. */
560 WMData* WMCreateDataWithBytesNoCopy(void *bytes, unsigned length,
561 WMFreeDataProc *destructor);
563 WMData* WMCreateDataWithData(WMData *aData);
565 WMData* WMRetainData(WMData *aData);
567 void WMReleaseData(WMData *aData);
569 /* Adjusting capacity */
571 void WMSetDataCapacity(WMData *aData, unsigned capacity);
573 void WMSetDataLength(WMData *aData, unsigned length);
575 void WMIncreaseDataLengthBy(WMData *aData, unsigned extraLength);
577 /* Accessing data */
579 const void* WMDataBytes(WMData *aData);
581 void WMGetDataBytes(WMData *aData, void *buffer);
583 void WMGetDataBytesWithLength(WMData *aData, void *buffer, unsigned length);
585 void WMGetDataBytesWithRange(WMData *aData, void *buffer, WMRange aRange);
587 WMData* WMGetSubdataWithRange(WMData *aData, WMRange aRange);
589 /* Testing data */
591 Bool WMIsDataEqualToData(WMData *aData, WMData *anotherData);
593 unsigned WMGetDataLength(WMData *aData);
595 /* Adding data */
597 void WMAppendDataBytes(WMData *aData, void *bytes, unsigned length);
599 void WMAppendData(WMData *aData, WMData *anotherData);
601 /* Modifying data */
603 void WMReplaceDataBytesInRange(WMData *aData, WMRange aRange, void *bytes);
605 void WMResetDataBytesInRange(WMData *aData, WMRange aRange);
607 void WMSetData(WMData *aData, WMData *anotherData);
610 void WMSetDataFormat(WMData *aData, unsigned format);
612 unsigned WMGetDataFormat(WMData *aData);
613 /* Storing data */
615 /* ---[ WINGs/tree.c ]---------------------------------------------------- */
617 /* Generic Tree and TreeNode */
619 WMTreeNode* WMCreateTreeNode(void *data);
621 WMTreeNode* WMCreateTreeNodeWithDestructor(void *data, WMFreeDataProc *destructor);
623 WMTreeNode* WMInsertItemInTree(WMTreeNode *parent, int index, void *item);
625 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
627 WMTreeNode* WMInsertNodeInTree(WMTreeNode *parent, int index, WMTreeNode *aNode);
629 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
631 void WMDestroyTreeNode(WMTreeNode *aNode);
633 void WMDeleteLeafForTreeNode(WMTreeNode *aNode, int index);
635 void WMRemoveLeafForTreeNode(WMTreeNode *aNode, void *leaf);
637 void* WMReplaceDataForTreeNode(WMTreeNode *aNode, void *newData);
639 void* WMGetDataForTreeNode(WMTreeNode *aNode);
641 int WMGetTreeNodeDepth(WMTreeNode *aNode);
643 WMTreeNode* WMGetParentForTreeNode(WMTreeNode *aNode);
645 /* Sort only the leaves of the passed node */
646 void WMSortLeavesForTreeNode(WMTreeNode *aNode, WMCompareDataProc *comparer);
648 /* Sort all tree recursively starting from the passed node */
649 void WMSortTree(WMTreeNode *aNode, WMCompareDataProc *comparer);
651 /* Returns the first node which matches node's data with cdata by 'match' */
652 WMTreeNode* WMFindInTree(WMTreeNode *aTree, WMMatchDataProc *match, void *cdata);
654 /* Returns the first node where node's data matches cdata by 'match' and node is
655 * at most `limit' depths down from `aTree'. */
656 WMTreeNode *WMFindInTreeWithDepthLimit(WMTreeNode * aTree, WMMatchDataProc * match, void *cdata, int limit);
658 /* Returns first tree node that has data == cdata */
659 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(aTree, NULL, cdata)
661 /* Walk every node of aNode with `walk' */
662 void WMTreeWalk(WMTreeNode *aNode, WMTreeWalkProc * walk, void *data, Bool DepthFirst);
664 /* ---[ WINGs/data.c ]---------------------------------------------------- */
667 WMNotification* WMCreateNotification(const char *name, void *object, void *clientData);
669 void WMReleaseNotification(WMNotification *notification);
671 WMNotification* WMRetainNotification(WMNotification *notification);
673 void* WMGetNotificationClientData(WMNotification *notification);
675 void* WMGetNotificationObject(WMNotification *notification);
677 const char* WMGetNotificationName(WMNotification *notification);
680 void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
681 void *observer, const char *name, void *object);
683 void WMPostNotification(WMNotification *notification);
685 void WMRemoveNotificationObserver(void *observer);
687 void WMRemoveNotificationObserverWithName(void *observer, const char *name,
688 void *object);
690 void WMPostNotificationName(const char *name, void *object, void *clientData);
692 WMNotificationQueue* WMGetDefaultNotificationQueue(void);
694 WMNotificationQueue* WMCreateNotificationQueue(void);
696 void WMDequeueNotificationMatching(WMNotificationQueue *queue,
697 WMNotification *notification,
698 unsigned mask);
700 void WMEnqueueNotification(WMNotificationQueue *queue,
701 WMNotification *notification,
702 WMPostingStyle postingStyle);
704 void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
705 WMNotification *notification,
706 WMPostingStyle postingStyle,
707 unsigned coalesceMask);
710 /* ---[ WINGs/proplist.c ]------------------------------------------------ */
712 /* Property Lists handling */
714 void WMPLSetCaseSensitive(Bool caseSensitive);
716 WMPropList* WMCreatePLString(char *str);
718 WMPropList* WMCreatePLData(WMData *data);
720 WMPropList* WMCreatePLDataWithBytes(unsigned char *bytes, unsigned int length);
722 WMPropList* WMCreatePLDataWithBytesNoCopy(unsigned char *bytes,
723 unsigned int length,
724 WMFreeDataProc *destructor);
726 WMPropList* WMCreatePLArray(WMPropList *elem, ...);
728 WMPropList* WMCreatePLDictionary(WMPropList *key, WMPropList *value, ...);
730 WMPropList* WMRetainPropList(WMPropList *plist);
732 void WMReleasePropList(WMPropList *plist);
734 /* Objects inserted in arrays and dictionaries will be retained,
735 * so you can safely release them after insertion.
736 * For dictionaries both the key and value are retained.
737 * Objects removed from arrays or dictionaries are released */
738 void WMInsertInPLArray(WMPropList *plist, int index, WMPropList *item);
740 void WMAddToPLArray(WMPropList *plist, WMPropList *item);
742 void WMDeleteFromPLArray(WMPropList *plist, int index);
744 void WMRemoveFromPLArray(WMPropList *plist, WMPropList *item);
746 void WMPutInPLDictionary(WMPropList *plist, WMPropList *key, WMPropList *value);
748 void WMRemoveFromPLDictionary(WMPropList *plist, WMPropList *key);
750 /* It will insert all key/value pairs from source into dest, overwriting
751 * the values with the same keys from dest, keeping all values with keys
752 * only present in dest unchanged */
753 WMPropList* WMMergePLDictionaries(WMPropList *dest, WMPropList *source,
754 Bool recursive);
756 /* It will remove all key/value pairs from dest for which there is an
757 * identical key/value present in source. Entires only present in dest, or
758 * which have different values in dest than in source will be preserved. */
759 WMPropList* WMSubtractPLDictionaries(WMPropList *dest, WMPropList *source,
760 Bool recursive);
762 int WMGetPropListItemCount(WMPropList *plist);
764 Bool WMIsPLString(WMPropList *plist);
766 Bool WMIsPLData(WMPropList *plist);
768 Bool WMIsPLArray(WMPropList *plist);
770 Bool WMIsPLDictionary(WMPropList *plist);
772 Bool WMIsPropListEqualTo(WMPropList *plist, WMPropList *other);
774 /* Returns a reference. Do not free it! */
775 char* WMGetFromPLString(WMPropList *plist);
777 /* Returns a reference. Do not free it! */
778 WMData* WMGetFromPLData(WMPropList *plist);
780 /* Returns a reference. Do not free it! */
781 const unsigned char* WMGetPLDataBytes(WMPropList *plist);
783 int WMGetPLDataLength(WMPropList *plist);
785 /* Returns a reference. */
786 WMPropList* WMGetFromPLArray(WMPropList *plist, int index);
788 /* Returns a reference. */
789 WMPropList* WMGetFromPLDictionary(WMPropList *plist, WMPropList *key);
791 /* Returns a PropList array with all the dictionary keys. Release it when
792 * you're done. Keys in array are retained from the original dictionary
793 * not copied and need NOT to be released individually. */
794 WMPropList* WMGetPLDictionaryKeys(WMPropList *plist);
796 /* Creates only the first level deep object. All the elements inside are
797 * retained from the original */
798 WMPropList* WMShallowCopyPropList(WMPropList *plist);
800 /* Makes a completely separate replica of the original proplist */
801 WMPropList* WMDeepCopyPropList(WMPropList *plist);
803 WMPropList* WMCreatePropListFromDescription(char *desc);
805 /* Free the returned string when you no longer need it */
806 char* WMGetPropListDescription(WMPropList *plist, Bool indented);
808 WMPropList* WMReadPropListFromFile(char *file);
810 Bool WMWritePropListToFile(WMPropList *plist, char *path);
812 /* ---[ WINGs/userdefaults.c ]-------------------------------------------- */
814 char* wusergnusteppath(void);
816 char* wdefaultspathfordomain(char *domain);
818 char* wglobaldefaultspathfordomain(const char *domain);
820 WMUserDefaults* WMGetStandardUserDefaults(void);
822 WMUserDefaults* WMGetDefaultsFromPath(char *path);
824 void WMSynchronizeUserDefaults(WMUserDefaults *database);
826 void WMSaveUserDefaults(WMUserDefaults *database);
828 void WMEnableUDPeriodicSynchronization(WMUserDefaults *database, Bool enable);
830 /* Returns a WMPropList array with all the keys in the user defaults database.
831 * Free the array with WMReleasePropList() when no longer needed.
832 * Keys in array are just retained references to the original keys */
833 WMPropList* WMGetUDKeys(WMUserDefaults *database);
835 WMPropList* WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
837 void WMSetUDObjectForKey(WMUserDefaults *database, WMPropList *object,
838 char *defaultName);
840 void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
842 char* WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
844 int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
846 float WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
848 Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
850 void WMSetUDStringForKey(WMUserDefaults *database, char *value,
851 char *defaultName);
853 void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
854 char *defaultName);
856 void WMSetUDFloatForKey(WMUserDefaults *database, float value,
857 char *defaultName);
859 void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
860 char *defaultName);
862 WMPropList* WMGetUDSearchList(WMUserDefaults *database);
864 void WMSetUDSearchList(WMUserDefaults *database, WMPropList *list);
866 extern char *WMUserDefaultsDidChangeNotification;
869 /* ---[ WINGs/menuparser.c ]---------------------------------------------- */
872 typedef struct w_menu_parser *WMenuParser;
875 WMenuParser WMenuParserCreate(const char *file_name, void *file, const char *include_default_paths);
877 void WMenuParserRegisterSimpleMacro(WMenuParser parser, const char *name, const char *value);
879 void WMenuParserError(WMenuParser parser, const char *msg, ...)
880 __attribute__ ((format (printf, 2, 3)));
882 const char *WMenuParserGetFilename(WMenuParser parser);
884 Bool WMenuParserGetLine(WMenuParser parser, char **title, char **command, char **parameter, char **shortcut);
886 void WMenuParserDelete(WMenuParser parser);
889 /*-------------------------------------------------------------------------*/
891 /* Global variables */
893 extern int WCErrorCode;
896 /*-------------------------------------------------------------------------*/
898 #ifdef __cplusplus
900 #endif /* __cplusplus */
903 #endif