Initial revision
[wmaker-crm.git] / WINGs / WUtil.h
blob6de4fb85f27911d7c0609baa5c494f5973b5ccea
1 #ifndef _WUTIL_H_
2 #define _WUTIL_H_
4 #include <X11/Xlib.h>
6 #include <sys/types.h>
8 /*
9 * Warning: proplist.h #defines BOOL which will clash with the
10 * typedef BOOL in Xmd.h
11 * proplist.h should use Bool (which is a #define in Xlib.h) instead.
14 #include <proplist.h>
17 #ifndef WMAX
18 # define WMAX(a,b) ((a)>(b) ? (a) : (b))
19 #endif
20 #ifndef WMIN
21 # define WMIN(a,b) ((a)<(b) ? (a) : (b))
22 #endif
26 typedef enum {
27 WMPostWhenIdle = 1,
28 WMPostASAP = 2,
29 WMPostNow = 3
30 } WMPostingStyle;
33 typedef enum {
34 WNCNone = 0,
35 WNCOnName = 1,
36 WNCOnSender = 2
37 } WMNotificationCoalescing;
42 typedef struct W_HashTable WMHashTable;
43 typedef struct W_UserDefaults WMUserDefaults;
44 typedef struct W_Notification WMNotification;
45 typedef struct W_NotificationQueue WMNotificationQueue;
48 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
49 typedef struct {
50 void *table;
51 void *nextItem;
52 int index;
53 } WMHashEnumerator;
56 typedef struct {
57 /* NULL is pointer hash */
58 unsigned (*hash)(const void *);
59 /* NULL is pointer compare */
60 Bool (*keyIsEqual)(const void *, const void *);
61 /* NULL does nothing */
62 void* (*retainKey)(const void *);
63 /* NULL does nothing */
64 void (*releaseKey)(const void *);
65 } WMHashTableCallbacks;
71 typedef void WMNotificationObserverAction(void *observerData,
72 WMNotification *notification);
76 /*......................................................................*/
79 void wfatal(const char *msg, ...);
80 void wwarning(const char *msg, ...);
81 void wsyserror(const char *msg, ...);
83 char *wfindfile(char *paths, char *file);
85 char *wfindfileinlist(char **path_list, char *file);
87 char *wexpandpath(char *path);
89 /* don't free the returned string */
90 char *wgethomedir();
92 void *wmalloc(size_t size);
93 void *wrealloc(void *ptr, size_t newsize);
95 void wrelease(void *ptr);
96 void *wretain(void *ptr);
98 char *wstrdup(char *str);
100 char *wstrappend(char *dst, char *src);
102 char *wusergnusteppath();
104 char *wdefaultspathfordomain(char *domain);
106 void wusleep(unsigned int microsec);
108 /*......................................................................*/
111 WMHashTable *WMCreateHashTable(WMHashTableCallbacks callbacks);
113 void WMFreeHashTable(WMHashTable *table);
115 void WMResetHashTable(WMHashTable *table);
117 void *WMHashGet(WMHashTable *table, const void *key);
119 /* put data in table, replacing already existing data and returning
120 * the old value */
121 void *WMHashInsert(WMHashTable *table, void *key, void *data);
123 void WMHashRemove(WMHashTable *table, const void *key);
125 /* warning: do not manipulate the table while using these functions */
126 WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
128 void *WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
130 unsigned WMCountHashTable(WMHashTable *table);
135 /* some predefined callback sets */
137 extern const WMHashTableCallbacks WMIntHashCallbacks;
138 /* sizeof(keys) are <= sizeof(void*) */
140 extern const WMHashTableCallbacks WMStringHashCallbacks;
141 /* keys are strings. Strings will be copied with wstrdup()
142 * and freed with free() */
144 extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
145 /* keys are strings, bug they are not copied */
147 /*......................................................................*/
149 WMNotification *WMCreateNotification(char *name, void *object, void *clientData);
151 void WMReleaseNotification(WMNotification *notification);
153 WMNotification *WMRetainNotification(WMNotification *notification);
155 void *WMGetNotificationClientData(WMNotification *notification);
157 void *WMGetNotificationObject(WMNotification *notification);
159 char *WMGetNotificationName(WMNotification *notification);
162 void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
163 void *observer, char *name, void *object);
165 void WMPostNotification(WMNotification *notification);
167 void WMRemoveNotificationObserver(void *observer);
169 void WMRemoveNotificationObserverWithName(void *observer, char *name,
170 void *object);
172 void WMPostNotificationName(char *name, void *object, void *clientData);
174 WMNotificationQueue *WMGetDefaultNotificationQueue(void);
176 WMNotificationQueue *WMCreateNotificationQueue(void);
178 void WMDequeueNotificationMatching(WMNotificationQueue *queue, unsigned mask);
180 void WMEnqueueNotification(WMNotificationQueue *queue, WMNotification *notification,
181 WMPostingStyle postingStyle);
183 void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
184 WMNotification *notification,
185 WMPostingStyle postingStyle,
186 unsigned coalesceMask);
189 /*......................................................................*/
191 WMUserDefaults *WMGetStandardUserDefaults(void);
193 proplist_t WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
195 void WMSetUDObjectForKey(WMUserDefaults *database, proplist_t object,
196 char *defaultName);
198 void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
200 /* you can free the returned string */
201 char *WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
203 int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
205 int WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
207 Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
209 void WMSetUDStringForKey(WMUserDefaults *database, char *value,
210 char *defaultName);
212 void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
213 char *defaultName);
215 void WMSetUDFloatForKey(WMUserDefaults *database, float value,
216 char *defaultName);
218 void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
219 char *defaultName);
221 proplist_t WMGetUDSearchList(WMUserDefaults *database);
223 void WMSetUDSearchList(WMUserDefaults *database, proplist_t list);
227 #endif