Fixed code in wevent.c to allow the callback handler to remove its InputHandler
[wmaker-crm.git] / WINGs / WUtil.h
blobadf2b860398df4e3212dab925bcb1955f480a09e
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 #ifdef DEBUG
49 #include <assert.h>
51 #define wassertr(expr) assert(expr)
53 #define wassertrv(expr, val) assert(expr)
55 #else /* !DEBUG */
57 #define wassertr(expr) \
58 if (!(expr)) { \
59 wwarning("%s line %i (%s): assertion %s failed",\
60 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
61 return;\
64 #define wassertrv(expr, val) \
65 if (!(expr)) { \
66 wwarning("%s line %i (%s): assertion %s failed",\
67 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
68 return (val);\
70 #endif /* !DEBUG */
72 #endif /* !NDEBUG */
75 #ifdef __cplusplus
76 extern "C" {
77 #endif /* __cplusplus */
80 typedef enum {
81 WMPostWhenIdle = 1,
82 WMPostASAP = 2,
83 WMPostNow = 3
84 } WMPostingStyle;
87 typedef enum {
88 WNCNone = 0,
89 WNCOnName = 1,
90 WNCOnSender = 2
91 } WMNotificationCoalescing;
96 typedef struct W_HashTable WMHashTable;
97 typedef struct W_UserDefaults WMUserDefaults;
98 typedef struct W_Notification WMNotification;
99 typedef struct W_NotificationQueue WMNotificationQueue;
102 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
103 typedef struct {
104 void *table;
105 void *nextItem;
106 int index;
107 } WMHashEnumerator;
110 typedef struct {
111 /* NULL is pointer hash */
112 unsigned (*hash)(const void *);
113 /* NULL is pointer compare */
114 Bool (*keyIsEqual)(const void *, const void *);
115 /* NULL does nothing */
116 void* (*retainKey)(const void *);
117 /* NULL does nothing */
118 void (*releaseKey)(const void *);
119 } WMHashTableCallbacks;
122 #if 0
123 typedef struct {
124 char character; /* the escape character */
125 char *value; /* value to place */
126 } WMSEscapes;
127 #endif
130 typedef void WMNotificationObserverAction(void *observerData,
131 WMNotification *notification);
135 /*......................................................................*/
137 typedef void (waborthandler)(int);
139 waborthandler *wsetabort(waborthandler*);
142 void wfatal(const char *msg, ...);
143 void wwarning(const char *msg, ...);
144 void wsyserror(const char *msg, ...);
146 char *wfindfile(char *paths, char *file);
148 char *wfindfileinlist(char **path_list, char *file);
150 char *wfindfileinarray(proplist_t array, char *file);
152 char *wexpandpath(char *path);
154 /* don't free the returned string */
155 char *wgethomedir();
157 void *wmalloc(size_t size);
158 void *wrealloc(void *ptr, size_t newsize);
160 void wrelease(void *ptr);
161 void *wretain(void *ptr);
163 char *wstrdup(char *str);
165 char *wstrappend(char *dst, char *src);
167 char *wusergnusteppath();
169 char *wdefaultspathfordomain(char *domain);
171 void wusleep(unsigned int microsec);
173 #if 0
174 int wsprintesc(char *buffer, int length, char *format, WMSEscapes **escapes,
175 int count);
176 #endif
177 /*......................................................................*/
180 WMHashTable *WMCreateHashTable(WMHashTableCallbacks callbacks);
182 void WMFreeHashTable(WMHashTable *table);
184 void WMResetHashTable(WMHashTable *table);
186 void *WMHashGet(WMHashTable *table, const void *key);
188 /* put data in table, replacing already existing data and returning
189 * the old value */
190 void *WMHashInsert(WMHashTable *table, void *key, void *data);
192 void WMHashRemove(WMHashTable *table, const void *key);
194 /* warning: do not manipulate the table while using these functions */
195 WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
197 void *WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
199 unsigned WMCountHashTable(WMHashTable *table);
204 /* some predefined callback sets */
206 extern const WMHashTableCallbacks WMIntHashCallbacks;
207 /* sizeof(keys) are <= sizeof(void*) */
209 extern const WMHashTableCallbacks WMStringHashCallbacks;
210 /* keys are strings. Strings will be copied with wstrdup()
211 * and freed with free() */
213 extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
214 /* keys are strings, bug they are not copied */
216 /*......................................................................*/
218 WMNotification *WMCreateNotification(char *name, void *object, void *clientData);
220 void WMReleaseNotification(WMNotification *notification);
222 WMNotification *WMRetainNotification(WMNotification *notification);
224 void *WMGetNotificationClientData(WMNotification *notification);
226 void *WMGetNotificationObject(WMNotification *notification);
228 char *WMGetNotificationName(WMNotification *notification);
231 void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
232 void *observer, char *name, void *object);
234 void WMPostNotification(WMNotification *notification);
236 void WMRemoveNotificationObserver(void *observer);
238 void WMRemoveNotificationObserverWithName(void *observer, char *name,
239 void *object);
241 void WMPostNotificationName(char *name, void *object, void *clientData);
243 WMNotificationQueue *WMGetDefaultNotificationQueue(void);
245 WMNotificationQueue *WMCreateNotificationQueue(void);
247 void WMDequeueNotificationMatching(WMNotificationQueue *queue,
248 WMNotification *notification,
249 unsigned mask);
251 void WMEnqueueNotification(WMNotificationQueue *queue,
252 WMNotification *notification,
253 WMPostingStyle postingStyle);
255 void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
256 WMNotification *notification,
257 WMPostingStyle postingStyle,
258 unsigned coalesceMask);
261 /*......................................................................*/
263 WMUserDefaults *WMGetStandardUserDefaults(void);
265 WMUserDefaults *WMGetDefaultsFromPath(char *path);
267 void WMSynchronizeUserDefaults(WMUserDefaults *database);
269 proplist_t WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
271 void WMSetUDObjectForKey(WMUserDefaults *database, proplist_t object,
272 char *defaultName);
274 void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
276 /* you can free the returned string */
277 char *WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
279 int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
281 float WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
283 Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
285 void WMSetUDStringForKey(WMUserDefaults *database, char *value,
286 char *defaultName);
288 void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
289 char *defaultName);
291 void WMSetUDFloatForKey(WMUserDefaults *database, float value,
292 char *defaultName);
294 void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
295 char *defaultName);
297 proplist_t WMGetUDSearchList(WMUserDefaults *database);
299 void WMSetUDSearchList(WMUserDefaults *database, proplist_t list);
301 #ifdef __cplusplus
303 #endif /* __cplusplus */
306 #endif