Updated korean menu files
[wmaker-crm.git] / WINGs / WUtil.h
blob15339e7ad470168dfa00232ba1488a0f80d6cb17
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();
160 void *wmalloc(size_t size);
161 void *wrealloc(void *ptr, size_t newsize);
163 void wrelease(void *ptr);
164 void *wretain(void *ptr);
166 char *wstrdup(char *str);
168 char *wstrappend(char *dst, char *src);
170 char *wusergnusteppath();
172 char *wdefaultspathfordomain(char *domain);
174 void wusleep(unsigned int microsec);
176 #if 0
177 int wsprintesc(char *buffer, int length, char *format, WMSEscapes **escapes,
178 int count);
179 #endif
181 /*......................................................................*/
183 /* This function is used _only_ if you create a NON-GUI program.
184 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
185 * This function will handle all input/timer/idle events, then return.
188 void WHandleEvents();
190 /*......................................................................*/
193 WMHashTable *WMCreateHashTable(WMHashTableCallbacks callbacks);
195 void WMFreeHashTable(WMHashTable *table);
197 void WMResetHashTable(WMHashTable *table);
199 void *WMHashGet(WMHashTable *table, const void *key);
201 /* put data in table, replacing already existing data and returning
202 * the old value */
203 void *WMHashInsert(WMHashTable *table, void *key, void *data);
205 void WMHashRemove(WMHashTable *table, const void *key);
207 /* warning: do not manipulate the table while using these functions */
208 WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
210 void *WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
212 unsigned WMCountHashTable(WMHashTable *table);
217 /* some predefined callback sets */
219 extern const WMHashTableCallbacks WMIntHashCallbacks;
220 /* sizeof(keys) are <= sizeof(void*) */
222 extern const WMHashTableCallbacks WMStringHashCallbacks;
223 /* keys are strings. Strings will be copied with wstrdup()
224 * and freed with free() */
226 extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
227 /* keys are strings, bug they are not copied */
230 /*......................................................................*/
233 WMBag *WMCreateBag(int size);
235 int WMGetBagItemCount(WMBag *bag);
237 void WMAppendBag(WMBag *bag, WMBag *appendedBag);
239 void WMPutInBag(WMBag *bag, void *item);
241 void WMInsertInBag(WMBag *bag, int index, void *item);
243 int WMGetFirstInBag(WMBag *bag, void *item);
245 int WMGetLastInBag(WMBag *bag, void *item);
247 void WMRemoveFromBag(WMBag *bag, void *item);
249 void WMDeleteFromBag(WMBag *bag, int index);
251 void *WMGetFromBag(WMBag *bag, int index);
253 int WMCountInBag(WMBag *bag, void *item);
256 /* comparer must return:
257 * < 0 if a < b
258 * > 0 if a > b
259 * = 0 if a = b
261 void WMSortBag(WMBag *bag, int (*comparer)(const void*, const void*));
263 void WMEmptyBag(WMBag *bag);
265 void WMFreeBag(WMBag *bag);
267 WMBag *WMMapBag(WMBag *bag, void* (*function)(void*));
269 /*......................................................................*/
271 WMNotification *WMCreateNotification(char *name, void *object, void *clientData);
273 void WMReleaseNotification(WMNotification *notification);
275 WMNotification *WMRetainNotification(WMNotification *notification);
277 void *WMGetNotificationClientData(WMNotification *notification);
279 void *WMGetNotificationObject(WMNotification *notification);
281 char *WMGetNotificationName(WMNotification *notification);
284 void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
285 void *observer, char *name, void *object);
287 void WMPostNotification(WMNotification *notification);
289 void WMRemoveNotificationObserver(void *observer);
291 void WMRemoveNotificationObserverWithName(void *observer, char *name,
292 void *object);
294 void WMPostNotificationName(char *name, void *object, void *clientData);
296 WMNotificationQueue *WMGetDefaultNotificationQueue(void);
298 WMNotificationQueue *WMCreateNotificationQueue(void);
300 void WMDequeueNotificationMatching(WMNotificationQueue *queue,
301 WMNotification *notification,
302 unsigned mask);
304 void WMEnqueueNotification(WMNotificationQueue *queue,
305 WMNotification *notification,
306 WMPostingStyle postingStyle);
308 void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
309 WMNotification *notification,
310 WMPostingStyle postingStyle,
311 unsigned coalesceMask);
314 /*......................................................................*/
316 WMUserDefaults *WMGetStandardUserDefaults(void);
318 WMUserDefaults *WMGetDefaultsFromPath(char *path);
320 void WMSynchronizeUserDefaults(WMUserDefaults *database);
322 void WMSaveUserDefaults(WMUserDefaults *database);
324 proplist_t WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
326 void WMSetUDObjectForKey(WMUserDefaults *database, proplist_t object,
327 char *defaultName);
329 void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
331 /* you can free the returned string */
332 char *WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
334 int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
336 float WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
338 Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
340 void WMSetUDStringForKey(WMUserDefaults *database, char *value,
341 char *defaultName);
343 void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
344 char *defaultName);
346 void WMSetUDFloatForKey(WMUserDefaults *database, float value,
347 char *defaultName);
349 void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
350 char *defaultName);
352 proplist_t WMGetUDSearchList(WMUserDefaults *database);
354 void WMSetUDSearchList(WMUserDefaults *database, proplist_t list);
356 #ifdef __cplusplus
358 #endif /* __cplusplus */
361 #endif