syncing wtextfield.c
[wmaker-crm.git] / WINGs / WUtil.h
blob9006d14320e8f1cda9f8af85ea712f074cbad0fe
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;
95 typedef struct W_Bag WMBag; /* equivalent to a linked list or array */
96 typedef struct W_HashTable WMHashTable;
97 typedef struct W_UserDefaults WMUserDefaults;
98 typedef struct W_Notification WMNotification;
99 typedef struct W_NotificationQueue WMNotificationQueue;
103 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
104 typedef struct {
105 void *table;
106 void *nextItem;
107 int index;
108 } WMHashEnumerator;
111 typedef struct {
112 /* NULL is pointer hash */
113 unsigned (*hash)(const void *);
114 /* NULL is pointer compare */
115 Bool (*keyIsEqual)(const void *, const void *);
116 /* NULL does nothing */
117 void* (*retainKey)(const void *);
118 /* NULL does nothing */
119 void (*releaseKey)(const void *);
120 } WMHashTableCallbacks;
124 #if 0
125 typedef struct {
126 char character; /* the escape character */
127 char *value; /* value to place */
128 } WMSEscapes;
129 #endif
133 typedef void WMNotificationObserverAction(void *observerData,
134 WMNotification *notification);
138 /*......................................................................*/
140 typedef void (waborthandler)(int);
142 waborthandler *wsetabort(waborthandler*);
145 void wfatal(const char *msg, ...);
146 void wwarning(const char *msg, ...);
147 void wsyserror(const char *msg, ...);
149 char *wfindfile(char *paths, char *file);
151 char *wfindfileinlist(char **path_list, char *file);
153 char *wfindfileinarray(proplist_t array, char *file);
155 char *wexpandpath(char *path);
157 /* don't free the returned string */
158 char *wgethomedir();
159 void *wmalloc(size_t size);
160 void *wrealloc(void *ptr, size_t newsize);
161 void wfree(void *ptr);
164 void wrelease(void *ptr);
165 void *wretain(void *ptr);
167 char *wstrdup(char *str);
169 char *wstrappend(char *dst, char *src);
171 char *wusergnusteppath();
173 char *wdefaultspathfordomain(char *domain);
175 void wusleep(unsigned int microsec);
177 #if 0
178 int wsprintesc(char *buffer, int length, char *format, WMSEscapes **escapes,
179 int count);
180 #endif
182 /*......................................................................*/
184 /* This function is used _only_ if you create a NON-GUI program.
185 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
186 * This function will handle all input/timer/idle events, then return.
189 void WHandleEvents();
191 /*......................................................................*/
194 WMHashTable *WMCreateHashTable(WMHashTableCallbacks callbacks);
196 void WMFreeHashTable(WMHashTable *table);
198 void WMResetHashTable(WMHashTable *table);
200 void *WMHashGet(WMHashTable *table, const void *key);
202 /* put data in table, replacing already existing data and returning
203 * the old value */
204 void *WMHashInsert(WMHashTable *table, void *key, void *data);
206 void WMHashRemove(WMHashTable *table, const void *key);
208 /* warning: do not manipulate the table while using these functions */
209 WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
211 void *WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
213 unsigned WMCountHashTable(WMHashTable *table);
218 /* some predefined callback sets */
220 extern const WMHashTableCallbacks WMIntHashCallbacks;
221 /* sizeof(keys) are <= sizeof(void*) */
223 extern const WMHashTableCallbacks WMStringHashCallbacks;
224 /* keys are strings. Strings will be copied with wstrdup()
225 * and freed with free() */
227 extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
228 /* keys are strings, bug they are not copied */
231 /*......................................................................*/
234 WMBag *WMCreateBag(int size);
236 int WMGetBagItemCount(WMBag *bag);
238 void WMAppendBag(WMBag *bag, WMBag *appendedBag);
240 void WMPutInBag(WMBag *bag, void *item);
242 void WMInsertInBag(WMBag *bag, int index, void *item);
244 int WMGetFirstInBag(WMBag *bag, void *item);
246 int WMGetLastInBag(WMBag *bag, void *item);
248 void WMRemoveFromBag(WMBag *bag, void *item);
250 void WMDeleteFromBag(WMBag *bag, int index);
252 void *WMGetFromBag(WMBag *bag, int index);
254 int WMCountInBag(WMBag *bag, void *item);
257 /* comparer must return:
258 * < 0 if a < b
259 * > 0 if a > b
260 * = 0 if a = b
262 void WMSortBag(WMBag *bag, int (*comparer)(const void*, const void*));
264 void WMEmptyBag(WMBag *bag);
266 void WMFreeBag(WMBag *bag);
268 WMBag *WMMapBag(WMBag *bag, void* (*function)(void*));
270 /*......................................................................*/
272 WMNotification *WMCreateNotification(char *name, void *object, void *clientData);
274 void WMReleaseNotification(WMNotification *notification);
276 WMNotification *WMRetainNotification(WMNotification *notification);
278 void *WMGetNotificationClientData(WMNotification *notification);
280 void *WMGetNotificationObject(WMNotification *notification);
282 char *WMGetNotificationName(WMNotification *notification);
285 void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
286 void *observer, char *name, void *object);
288 void WMPostNotification(WMNotification *notification);
290 void WMRemoveNotificationObserver(void *observer);
292 void WMRemoveNotificationObserverWithName(void *observer, char *name,
293 void *object);
295 void WMPostNotificationName(char *name, void *object, void *clientData);
297 WMNotificationQueue *WMGetDefaultNotificationQueue(void);
299 WMNotificationQueue *WMCreateNotificationQueue(void);
301 void WMDequeueNotificationMatching(WMNotificationQueue *queue,
302 WMNotification *notification,
303 unsigned mask);
305 void WMEnqueueNotification(WMNotificationQueue *queue,
306 WMNotification *notification,
307 WMPostingStyle postingStyle);
309 void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
310 WMNotification *notification,
311 WMPostingStyle postingStyle,
312 unsigned coalesceMask);
315 /*......................................................................*/
317 WMUserDefaults *WMGetStandardUserDefaults(void);
319 WMUserDefaults *WMGetDefaultsFromPath(char *path);
321 void WMSynchronizeUserDefaults(WMUserDefaults *database);
323 void WMSaveUserDefaults(WMUserDefaults *database);
325 proplist_t WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
327 void WMSetUDObjectForKey(WMUserDefaults *database, proplist_t object,
328 char *defaultName);
330 void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
332 /* you can free the returned string */
333 char *WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
335 int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
337 float WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
339 Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
341 void WMSetUDStringForKey(WMUserDefaults *database, char *value,
342 char *defaultName);
344 void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
345 char *defaultName);
347 void WMSetUDFloatForKey(WMUserDefaults *database, float value,
348 char *defaultName);
350 void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
351 char *defaultName);
353 proplist_t WMGetUDSearchList(WMUserDefaults *database);
355 void WMSetUDSearchList(WMUserDefaults *database, proplist_t list);
357 #ifdef __cplusplus
359 #endif /* __cplusplus */
362 #endif