Code update for Window Maker version 0.50.0
[wmaker-crm.git] / WINGs / WUtil.h
blobfd90ca80b39324a0ca9dd88b396726a67b4ce933
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 ((__const char *) 0)
35 #else
36 #define __ASSERT_FUNCTION __PRETTY_FUNCTION__
37 #endif
40 #ifdef NDEBUG
42 #define wassertr(expr, val) ((void)0)
44 #else /* !NDEBUG */
46 #define wassertr(expr) \
47 if (!(expr)) { \
48 wwarning("%s line %i (%s): assertion %s failed",\
49 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
50 return;\
53 #define wassertrv(expr, val) \
54 if (!(expr)) { \
55 wwarning("%s line %i (%s): assertion %s failed",\
56 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
57 return (val);\
60 #endif /* !NDEBUG */
64 typedef enum {
65 WMPostWhenIdle = 1,
66 WMPostASAP = 2,
67 WMPostNow = 3
68 } WMPostingStyle;
71 typedef enum {
72 WNCNone = 0,
73 WNCOnName = 1,
74 WNCOnSender = 2
75 } WMNotificationCoalescing;
80 typedef struct W_HashTable WMHashTable;
81 typedef struct W_UserDefaults WMUserDefaults;
82 typedef struct W_Notification WMNotification;
83 typedef struct W_NotificationQueue WMNotificationQueue;
86 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
87 typedef struct {
88 void *table;
89 void *nextItem;
90 int index;
91 } WMHashEnumerator;
94 typedef struct {
95 /* NULL is pointer hash */
96 unsigned (*hash)(const void *);
97 /* NULL is pointer compare */
98 Bool (*keyIsEqual)(const void *, const void *);
99 /* NULL does nothing */
100 void* (*retainKey)(const void *);
101 /* NULL does nothing */
102 void (*releaseKey)(const void *);
103 } WMHashTableCallbacks;
106 #if 0
107 typedef struct {
108 char character; /* the escape character */
109 char *value; /* value to place */
110 } WMSEscapes;
111 #endif
114 typedef void WMNotificationObserverAction(void *observerData,
115 WMNotification *notification);
119 /*......................................................................*/
122 void wfatal(const char *msg, ...);
123 void wwarning(const char *msg, ...);
124 void wsyserror(const char *msg, ...);
126 char *wfindfile(char *paths, char *file);
128 char *wfindfileinlist(char **path_list, char *file);
130 char *wexpandpath(char *path);
132 /* don't free the returned string */
133 char *wgethomedir();
135 void *wmalloc(size_t size);
136 void *wrealloc(void *ptr, size_t newsize);
138 void wrelease(void *ptr);
139 void *wretain(void *ptr);
141 char *wstrdup(char *str);
143 char *wstrappend(char *dst, char *src);
145 char *wusergnusteppath();
147 char *wdefaultspathfordomain(char *domain);
149 void wusleep(unsigned int microsec);
151 #if 0
152 int wsprintesc(char *buffer, int length, char *format, WMSEscapes **escapes,
153 int count);
154 #endif
155 /*......................................................................*/
158 WMHashTable *WMCreateHashTable(WMHashTableCallbacks callbacks);
160 void WMFreeHashTable(WMHashTable *table);
162 void WMResetHashTable(WMHashTable *table);
164 void *WMHashGet(WMHashTable *table, const void *key);
166 /* put data in table, replacing already existing data and returning
167 * the old value */
168 void *WMHashInsert(WMHashTable *table, void *key, void *data);
170 void WMHashRemove(WMHashTable *table, const void *key);
172 /* warning: do not manipulate the table while using these functions */
173 WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
175 void *WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
177 unsigned WMCountHashTable(WMHashTable *table);
182 /* some predefined callback sets */
184 extern const WMHashTableCallbacks WMIntHashCallbacks;
185 /* sizeof(keys) are <= sizeof(void*) */
187 extern const WMHashTableCallbacks WMStringHashCallbacks;
188 /* keys are strings. Strings will be copied with wstrdup()
189 * and freed with free() */
191 extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
192 /* keys are strings, bug they are not copied */
194 /*......................................................................*/
196 WMNotification *WMCreateNotification(char *name, void *object, void *clientData);
198 void WMReleaseNotification(WMNotification *notification);
200 WMNotification *WMRetainNotification(WMNotification *notification);
202 void *WMGetNotificationClientData(WMNotification *notification);
204 void *WMGetNotificationObject(WMNotification *notification);
206 char *WMGetNotificationName(WMNotification *notification);
209 void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
210 void *observer, char *name, void *object);
212 void WMPostNotification(WMNotification *notification);
214 void WMRemoveNotificationObserver(void *observer);
216 void WMRemoveNotificationObserverWithName(void *observer, char *name,
217 void *object);
219 void WMPostNotificationName(char *name, void *object, void *clientData);
221 WMNotificationQueue *WMGetDefaultNotificationQueue(void);
223 WMNotificationQueue *WMCreateNotificationQueue(void);
225 void WMDequeueNotificationMatching(WMNotificationQueue *queue, unsigned mask);
227 void WMEnqueueNotification(WMNotificationQueue *queue, WMNotification *notification,
228 WMPostingStyle postingStyle);
230 void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
231 WMNotification *notification,
232 WMPostingStyle postingStyle,
233 unsigned coalesceMask);
236 /*......................................................................*/
238 WMUserDefaults *WMGetStandardUserDefaults(void);
240 proplist_t WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
242 void WMSetUDObjectForKey(WMUserDefaults *database, proplist_t object,
243 char *defaultName);
245 void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
247 /* you can free the returned string */
248 char *WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
250 int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
252 int WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
254 Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
256 void WMSetUDStringForKey(WMUserDefaults *database, char *value,
257 char *defaultName);
259 void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
260 char *defaultName);
262 void WMSetUDFloatForKey(WMUserDefaults *database, float value,
263 char *defaultName);
265 void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
266 char *defaultName);
268 proplist_t WMGetUDSearchList(WMUserDefaults *database);
270 void WMSetUDSearchList(WMUserDefaults *database, proplist_t list);
274 #endif