0.51.1 pre snapshot. Be careful, it may be buggy. It fixes some bugs though.
[wmaker-crm.git] / WINGs / WUtil.h
bloba2abc77a061c8c1fcab7ba8c1b6fad81ce50e80e
1 #ifndef _WUTIL_H_
2 #define _WUTIL_H_
4 #include <X11/Xlib.h>
6 #include <sys/types.h>
9 /* SunOS 4.x Blargh.... */
10 #ifndef NULL
11 #define NULL ((void*)0)
12 #endif
16 * Warning: proplist.h #defines BOOL which will clash with the
17 * typedef BOOL in Xmd.h
18 * proplist.h should use Bool (which is a #define in Xlib.h) instead.
21 #include <proplist.h>
24 #ifndef WMAX
25 # define WMAX(a,b) ((a)>(b) ? (a) : (b))
26 #endif
27 #ifndef WMIN
28 # define WMIN(a,b) ((a)<(b) ? (a) : (b))
29 #endif
32 #if (!defined (__GNUC__) || __GNUC__ < 2 || \
33 __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4))
34 #define __ASSERT_FUNCTION ((char *) 0)
35 #else
36 #define __ASSERT_FUNCTION __PRETTY_FUNCTION__
37 #endif
40 #ifdef NDEBUG
42 #define wassertr(expr) {}
43 #define wassertrv(expr, val) {}
45 #else /* !NDEBUG */
47 #define wassertr(expr) \
48 if (!(expr)) { \
49 wwarning("%s line %i (%s): assertion %s failed",\
50 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
51 return;\
54 #define wassertrv(expr, val) \
55 if (!(expr)) { \
56 wwarning("%s line %i (%s): assertion %s failed",\
57 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
58 return (val);\
61 #endif /* !NDEBUG */
64 #ifdef __cplusplus
65 extern "C" {
66 #endif /* __cplusplus */
69 typedef enum {
70 WMPostWhenIdle = 1,
71 WMPostASAP = 2,
72 WMPostNow = 3
73 } WMPostingStyle;
76 typedef enum {
77 WNCNone = 0,
78 WNCOnName = 1,
79 WNCOnSender = 2
80 } WMNotificationCoalescing;
85 typedef struct W_HashTable WMHashTable;
86 typedef struct W_UserDefaults WMUserDefaults;
87 typedef struct W_Notification WMNotification;
88 typedef struct W_NotificationQueue WMNotificationQueue;
91 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
92 typedef struct {
93 void *table;
94 void *nextItem;
95 int index;
96 } WMHashEnumerator;
99 typedef struct {
100 /* NULL is pointer hash */
101 unsigned (*hash)(const void *);
102 /* NULL is pointer compare */
103 Bool (*keyIsEqual)(const void *, const void *);
104 /* NULL does nothing */
105 void* (*retainKey)(const void *);
106 /* NULL does nothing */
107 void (*releaseKey)(const void *);
108 } WMHashTableCallbacks;
111 #if 0
112 typedef struct {
113 char character; /* the escape character */
114 char *value; /* value to place */
115 } WMSEscapes;
116 #endif
119 typedef void WMNotificationObserverAction(void *observerData,
120 WMNotification *notification);
124 /*......................................................................*/
126 typedef void (waborthandler)(int);
128 waborthandler *wsetabort(waborthandler*);
131 void wfatal(const char *msg, ...);
132 void wwarning(const char *msg, ...);
133 void wsyserror(const char *msg, ...);
135 char *wfindfile(char *paths, char *file);
137 char *wfindfileinlist(char **path_list, char *file);
139 char *wexpandpath(char *path);
141 /* don't free the returned string */
142 char *wgethomedir();
144 void *wmalloc(size_t size);
145 void *wrealloc(void *ptr, size_t newsize);
147 void wrelease(void *ptr);
148 void *wretain(void *ptr);
150 char *wstrdup(char *str);
152 char *wstrappend(char *dst, char *src);
154 char *wusergnusteppath();
156 char *wdefaultspathfordomain(char *domain);
158 void wusleep(unsigned int microsec);
160 #if 0
161 int wsprintesc(char *buffer, int length, char *format, WMSEscapes **escapes,
162 int count);
163 #endif
164 /*......................................................................*/
167 WMHashTable *WMCreateHashTable(WMHashTableCallbacks callbacks);
169 void WMFreeHashTable(WMHashTable *table);
171 void WMResetHashTable(WMHashTable *table);
173 void *WMHashGet(WMHashTable *table, const void *key);
175 /* put data in table, replacing already existing data and returning
176 * the old value */
177 void *WMHashInsert(WMHashTable *table, void *key, void *data);
179 void WMHashRemove(WMHashTable *table, const void *key);
181 /* warning: do not manipulate the table while using these functions */
182 WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
184 void *WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
186 unsigned WMCountHashTable(WMHashTable *table);
191 /* some predefined callback sets */
193 extern const WMHashTableCallbacks WMIntHashCallbacks;
194 /* sizeof(keys) are <= sizeof(void*) */
196 extern const WMHashTableCallbacks WMStringHashCallbacks;
197 /* keys are strings. Strings will be copied with wstrdup()
198 * and freed with free() */
200 extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
201 /* keys are strings, bug they are not copied */
203 /*......................................................................*/
205 WMNotification *WMCreateNotification(char *name, void *object, void *clientData);
207 void WMReleaseNotification(WMNotification *notification);
209 WMNotification *WMRetainNotification(WMNotification *notification);
211 void *WMGetNotificationClientData(WMNotification *notification);
213 void *WMGetNotificationObject(WMNotification *notification);
215 char *WMGetNotificationName(WMNotification *notification);
218 void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
219 void *observer, char *name, void *object);
221 void WMPostNotification(WMNotification *notification);
223 void WMRemoveNotificationObserver(void *observer);
225 void WMRemoveNotificationObserverWithName(void *observer, char *name,
226 void *object);
228 void WMPostNotificationName(char *name, void *object, void *clientData);
230 WMNotificationQueue *WMGetDefaultNotificationQueue(void);
232 WMNotificationQueue *WMCreateNotificationQueue(void);
234 void WMDequeueNotificationMatching(WMNotificationQueue *queue,
235 WMNotification *notification,
236 unsigned mask);
238 void WMEnqueueNotification(WMNotificationQueue *queue,
239 WMNotification *notification,
240 WMPostingStyle postingStyle);
242 void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
243 WMNotification *notification,
244 WMPostingStyle postingStyle,
245 unsigned coalesceMask);
248 /*......................................................................*/
250 WMUserDefaults *WMGetStandardUserDefaults(void);
252 proplist_t WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
254 void WMSetUDObjectForKey(WMUserDefaults *database, proplist_t object,
255 char *defaultName);
257 void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
259 /* you can free the returned string */
260 char *WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
262 int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
264 float WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
266 Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
268 void WMSetUDStringForKey(WMUserDefaults *database, char *value,
269 char *defaultName);
271 void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
272 char *defaultName);
274 void WMSetUDFloatForKey(WMUserDefaults *database, float value,
275 char *defaultName);
277 void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
278 char *defaultName);
280 proplist_t WMGetUDSearchList(WMUserDefaults *database);
282 void WMSetUDSearchList(WMUserDefaults *database, proplist_t list);
284 #ifdef __cplusplus
286 #endif /* __cplusplus */
289 #endif