Fix some bugs, DisableMiniwindows, _KWM_WIN_ICON_GEOMETRY..
[wmaker-crm.git] / WINGs / WUtil.h
blob31a67ee432159e09324ff3752c00f744484d11cb
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 *wfindfileinarray(proplist_t array, char *file);
141 char *wexpandpath(char *path);
143 /* don't free the returned string */
144 char *wgethomedir();
146 void *wmalloc(size_t size);
147 void *wrealloc(void *ptr, size_t newsize);
149 void wrelease(void *ptr);
150 void *wretain(void *ptr);
152 char *wstrdup(char *str);
154 char *wstrappend(char *dst, char *src);
156 char *wusergnusteppath();
158 char *wdefaultspathfordomain(char *domain);
160 void wusleep(unsigned int microsec);
162 #if 0
163 int wsprintesc(char *buffer, int length, char *format, WMSEscapes **escapes,
164 int count);
165 #endif
166 /*......................................................................*/
169 WMHashTable *WMCreateHashTable(WMHashTableCallbacks callbacks);
171 void WMFreeHashTable(WMHashTable *table);
173 void WMResetHashTable(WMHashTable *table);
175 void *WMHashGet(WMHashTable *table, const void *key);
177 /* put data in table, replacing already existing data and returning
178 * the old value */
179 void *WMHashInsert(WMHashTable *table, void *key, void *data);
181 void WMHashRemove(WMHashTable *table, const void *key);
183 /* warning: do not manipulate the table while using these functions */
184 WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
186 void *WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
188 unsigned WMCountHashTable(WMHashTable *table);
193 /* some predefined callback sets */
195 extern const WMHashTableCallbacks WMIntHashCallbacks;
196 /* sizeof(keys) are <= sizeof(void*) */
198 extern const WMHashTableCallbacks WMStringHashCallbacks;
199 /* keys are strings. Strings will be copied with wstrdup()
200 * and freed with free() */
202 extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
203 /* keys are strings, bug they are not copied */
205 /*......................................................................*/
207 WMNotification *WMCreateNotification(char *name, void *object, void *clientData);
209 void WMReleaseNotification(WMNotification *notification);
211 WMNotification *WMRetainNotification(WMNotification *notification);
213 void *WMGetNotificationClientData(WMNotification *notification);
215 void *WMGetNotificationObject(WMNotification *notification);
217 char *WMGetNotificationName(WMNotification *notification);
220 void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
221 void *observer, char *name, void *object);
223 void WMPostNotification(WMNotification *notification);
225 void WMRemoveNotificationObserver(void *observer);
227 void WMRemoveNotificationObserverWithName(void *observer, char *name,
228 void *object);
230 void WMPostNotificationName(char *name, void *object, void *clientData);
232 WMNotificationQueue *WMGetDefaultNotificationQueue(void);
234 WMNotificationQueue *WMCreateNotificationQueue(void);
236 void WMDequeueNotificationMatching(WMNotificationQueue *queue,
237 WMNotification *notification,
238 unsigned mask);
240 void WMEnqueueNotification(WMNotificationQueue *queue,
241 WMNotification *notification,
242 WMPostingStyle postingStyle);
244 void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
245 WMNotification *notification,
246 WMPostingStyle postingStyle,
247 unsigned coalesceMask);
250 /*......................................................................*/
252 WMUserDefaults *WMGetStandardUserDefaults(void);
254 void WMSynchronizeUserDefaults(WMUserDefaults *database);
256 proplist_t WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
258 void WMSetUDObjectForKey(WMUserDefaults *database, proplist_t object,
259 char *defaultName);
261 void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
263 /* you can free the returned string */
264 char *WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
266 int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
268 float WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
270 Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
272 void WMSetUDStringForKey(WMUserDefaults *database, char *value,
273 char *defaultName);
275 void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
276 char *defaultName);
278 void WMSetUDFloatForKey(WMUserDefaults *database, float value,
279 char *defaultName);
281 void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
282 char *defaultName);
284 proplist_t WMGetUDSearchList(WMUserDefaults *database);
286 void WMSetUDSearchList(WMUserDefaults *database, proplist_t list);
288 #ifdef __cplusplus
290 #endif /* __cplusplus */
293 #endif