27 Commits

Author SHA1 Message Date
8814830f89 Fix use of //wrlib:error_code in BUILD definition. 2025-01-01 00:10:59 -05:00
3256959257 Use thread-safe wrlib global error state implemented in Rust.
This should suffice as a basic demonstration that we can start rewriting parts
of this codebase in Rust. May still need to kick the tires a little.
2024-12-31 23:26:27 -05:00
639a401f7f Rust impl of global error status for wrlib.
Not wired into anything yet, but appears callable from C (per a simple unit
test).
2024-12-31 23:21:11 -05:00
0aecec095f Okay, it builds! 2024-12-30 22:27:06 -05:00
66e2ade2dc First crack at C<->Rust interaction.
Pushing elsewhere because this won't build on my laptop.
2024-12-30 22:00:38 -05:00
81b452fc87 Use pkg_config rules for ImageMagick, too.
This depends on a pending fix to the pkg_config
rule (https://github.com/cherrry/bazel_pkg_config/issues/1).
2024-12-28 21:54:58 -05:00
14c42f4092 Close to getting data file generation working properly.
Also adding a shell script that will copy the results of a test build to a
location from where it can be run.
2024-12-17 22:08:36 -05:00
7a5587acce Let's not track MODULE.bazel.lock at least for now. 2024-12-17 15:20:35 -05:00
1e17a1c2e6 Imitate most scripted data file generation. 2024-12-17 15:10:18 -05:00
8d005d055b Address corner case of stripped output file basename being empty. 2024-12-17 15:06:11 -05:00
0c35859424 Do string replacements in WindowMaker with a Python script that we can reuse elsewhere. 2024-11-12 10:05:43 -05:00
8fb7aba384 Start migrating data files to Bazel build. 2024-11-10 22:59:13 -05:00
86db9b25d3 Tweaks to BUILD files to build on laptop. 2024-11-07 21:41:12 -05:00
05b1cbf15f Locate packages with pkg-config (except for ImageMagick). 2024-11-02 14:52:07 -04:00
3566bd3a59 Add missing config files (which we are copying from autotools output for now). 2024-11-02 13:08:06 -04:00
b97c72e7e5 Remove Bazel symlinks and ignore them in the future. 2024-11-02 13:02:55 -04:00
20a5e6c38b wmaker builds (but not verified). 2024-11-01 08:46:06 -04:00
ba2d7dfaff Add missing files to wrlib build. 2024-11-01 00:32:02 -04:00
3f39e0094d Add missing files to WINGs build and name external repos with headers differently. 2024-11-01 00:31:15 -04:00
f036d0f02c WINGs builds (but the result is completely unverified). 2024-10-31 23:30:21 -04:00
d74a41d3a9 wrlib builds (but the result is completely unverified). 2024-10-31 22:11:35 -04:00
3667fbe247 Copy autotools-generated configs into Bazel tree. 2024-10-31 21:57:03 -04:00
1c3a2f17d3 Remove AC symbols from wraster.h. 2024-10-31 21:39:53 -04:00
ac0de4e9e9 Mark where optional XSHM support was made mandatory. 2024-10-31 21:39:22 -04:00
1034a39316 Copy warster.h.in as originally present. 2024-10-31 21:38:09 -04:00
7dc23051e2 Do a better job of remembering wraster.h provenance. 2024-10-31 21:37:39 -04:00
701eac0a1a Copy source files into bazel subdir to get our hands dirty. 2024-10-31 21:36:49 -04:00
760 changed files with 178070 additions and 9255 deletions

11
.gitignore vendored
View File

@@ -133,13 +133,16 @@ WPrefs.app/WPrefs.desktop
/WPrefs.app/po/*.mo
/util/po/*.pot
/util/po/*.mo
/wrlib/po/*.pot
/wrlib/po/*.mo
# Some text editors generate backup files
*~
.pc
# Rust stuff.
/*/target/**
# Bazel's build symlinks shouldn't be committed.
bazel-bazel
bazel-bin
bazel-out
bazel-testlogs
# Don't commit lockfile until things are more stable.
MODULE.bazel.lock

View File

@@ -21,7 +21,7 @@ Changes since version 0.95.7:
- debian: Ignore missing documentation for --runstatedir.
- debian: Use dh_autoreconf.
- debian: Simplify debian/rules.
- debian: Fix typo occurred. (Thanks, lintian.)
- debian: Fix typo occured. (Thanks, lintian.)
- debian: wmaker manpage moved from 1x to 1.
(Andreas Metzler <ametzler@bebt.de>)
- debian: Add wmiv to wmaker package.
@@ -498,7 +498,7 @@ Changes since version 0.95.6:
- doc: Add manpage for wmiv.
(Doug Torrance <dtorrance@monmouthcollege.edu>)
- wmaker: replaced old email address with the official one
- WINGs: Updated news with the API changes that occurred between 0.95.6 and
- WINGs: Updated news with the API changes that occured between 0.95.6 and
0.95.7
- WINGs: ran spell checker on the NEWS file
- WINGs: fix non-portable int conversion for printf in font panel size handling
@@ -969,7 +969,7 @@ Changes since version 0.95.5:
- WMaker: moved XGrab/XUngrabPointer into the conditional code
- News: created section dedicated to the changes related to 0.95.3
- News: added description of a change that may be interesting to users
- News: added section to describe the changes that have occurred in 0.95.4
- News: added section to describe the changes that have occured in 0.95.4
- News: marked the current changes as part of 0.95.5 and describe the drawers
feature
- News: described the new features for future 0.95.6 release
@@ -1103,7 +1103,7 @@ Changes since version 0.95.5:
#50158)
- WPrefs: fix NULL pointer handling when getting the Modifiers (Coverity
#50200)
- WPrefs: add warning when renderTexture encounters some unknown settings
- WPrefs: add warning when renderTexture encounters some unknow settings
(Christophe CURIS <christophe.curis@free.fr>)
- util/wmiv: add image auto orientation detection
(David Maciejak <david.maciejak@gmail.com>)

View File

@@ -39,7 +39,7 @@ ACLOCAL_AMFLAGS = -I m4
AM_DISTCHECK_CONFIGURE_FLAGS = --enable-silent-rules LINGUAS='*'
SUBDIRS = wrlib wutil-rs WINGs wmaker-rs src util po WindowMaker wmlib WPrefs.app doc
SUBDIRS = wrlib WINGs src util po WindowMaker wmlib WPrefs.app doc
DIST_SUBDIRS = $(SUBDIRS) test
EXTRA_DIST = TODO BUGS BUGFORM FAQ INSTALL \

View File

@@ -140,7 +140,7 @@ Changes since wmaker 0.64.0:
- Moved all internal handlers (timer, idle and input) to handlers.c
- simplified wevent.c and wutil.c.
- fixed handling of input with poll (was broken)
- fixed mem leak that occurred when input handling was done with poll
- fixed mem leak that occured when input handling was done with poll
- simpler and more straightforward event handling for timer, idle, input
and X events (also fixed some problems the old handling logic had)
- moved timer, idle and input handler definitions and prototypes from

View File

@@ -10,17 +10,14 @@ libWUtil_la_LDFLAGS = -version-info @WUTIL_VERSION@
lib_LTLIBRARIES = libWUtil.la libWINGs.la
wutilrs = $(top_builddir)/wutil-rs/target/debug/libwutil_rs.a
wraster = $(top_builddir)/wrlib/libwraster.la
LDADD= libWUtil.la libWINGs.la $(wraster) $(wutilrs) @INTLIBS@
libWINGs_la_LIBADD = libWUtil.la $(wraster) $(wutilrs) @XLIBS@ @XFT_LIBS@ @FCLIBS@ @LIBM@ @PANGO_LIBS@
libWUtil_la_LIBADD = $(wutilrs)
LDADD= libWUtil.la libWINGs.la $(top_builddir)/wrlib/libwraster.la @INTLIBS@
libWINGs_la_LIBADD = libWUtil.la $(top_builddir)/wrlib/libwraster.la @XLIBS@ @XFT_LIBS@ @FCLIBS@ @LIBM@ @PANGO_LIBS@
libWUtil_la_LIBADD = @LIBBSD@
EXTRA_DIST = BUGS make-rgb Examples Extras Tests
# wbutton.c
libWINGs_la_SOURCES = \
configuration.c \
@@ -65,15 +62,23 @@ libWINGs_la_SOURCES = \
wwindow.c
libWUtil_la_SOURCES = \
array.c \
bagtree.c \
data.c \
error.c \
error.h \
findfile.c \
handlers.c \
hashtable.c \
memory.c \
menuparser.c \
menuparser.h \
menuparser_macros.c \
misc.c \
notification.c \
proplist.c \
string.c \
tree.c \
userdefaults.c \
userdefaults.h \
usleep.c \

View File

@@ -233,7 +233,7 @@ typedef enum {
/* text movement types */
typedef enum {
enum {
WMIllegalTextMovement,
WMReturnTextMovement,
WMEscapeTextMovement,
@@ -243,13 +243,13 @@ typedef enum {
WMRightTextMovement,
WMUpTextMovement,
WMDownTextMovement
} WMTextMovementType;
};
/* text field special events */
typedef enum {
enum {
WMInsertTextEvent,
WMDeleteTextEvent
} WMTextFieldSpecialEventType;
};
enum {
@@ -533,11 +533,14 @@ typedef struct WMBrowserDelegate {
typedef struct WMTextFieldDelegate {
void *data;
void (*didBeginEditing)(struct WMTextFieldDelegate *self, WMTextMovementType reason);
void (*didBeginEditing)(struct WMTextFieldDelegate *self,
WMNotification *notif);
void (*didChange)(struct WMTextFieldDelegate *self, WMTextFieldSpecialEventType reason);
void (*didChange)(struct WMTextFieldDelegate *self,
WMNotification *notif);
void (*didEndEditing)(struct WMTextFieldDelegate *self, WMTextMovementType reason);
void (*didEndEditing)(struct WMTextFieldDelegate *self,
WMNotification *notif);
Bool (*shouldBeginEditing)(struct WMTextFieldDelegate *self,
WMTextField *tPtr);

View File

@@ -378,6 +378,10 @@ void W_InitNotificationCenter(void);
void W_ReleaseNotificationCenter(void);
void W_FlushASAPNotificationQueue(void);
void W_FlushIdleNotificationQueue(void);
/* ---[ selection.c ]----------------------------------------------------- */

View File

@@ -169,11 +169,15 @@ typedef struct {
unsigned (*hash)(const void *);
/* NULL is pointer compare */
Bool (*keyIsEqual)(const void *, const void *);
/* NULL does nothing */
void* (*retainKey)(const void *);
/* NULL does nothing */
void (*releaseKey)(const void *);
} WMHashTableCallbacks;
typedef int WMArrayIterator;
typedef int WMBagIterator;
typedef void *WMBagIterator;
typedef void WMNotificationObserverAction(void *observerData,
@@ -209,6 +213,10 @@ void wfree(void *ptr);
void wrelease(void *ptr);
void* wretain(void *ptr);
typedef void waborthandler(int);
waborthandler* wsetabort(waborthandler* handler);
/* ---[ WINGs/error.c ]--------------------------------------------------- */
enum {
@@ -240,14 +248,11 @@ char* wexpandpath(const char *path);
int wcopy_file(const char *toPath, const char *srcFile, const char *destFile);
/* You must free the returned string! */
char* wgethomedir(void);
/* don't free the returned string */
const char* wgethomedir(void);
/* ---[ WINGs/proplist.c ]------------------------------------------------ */
/*
* Creates the directory path and all its parents.
*/
int wmkdirhier(const char *path);
int wrmdirhier(const char *path);
@@ -271,9 +276,14 @@ char* wstrconcat(const char *str1, const char *str2);
* so always assign the returned address to avoid dangling pointers. */
char* wstrappend(char *dst, const char *src);
size_t wstrlcpy(char *, const char *, size_t);
size_t wstrlcat(char *, const char *, size_t);
void wtokensplit(char *command, char ***argv, int *argc);
char* wtokennext(char *word, char **next);
char* wtokenjoin(char **list, int count);
void wtokenfree(char **tokens, int count);
@@ -332,8 +342,7 @@ void WHandleEvents(void);
/* ---[ WINGs/hashtable.c ]----------------------------------------------- */
WMHashTable* WMCreateIdentityHashTable();
WMHashTable* WMCreateStringHashTable();
WMHashTable* WMCreateHashTable(const WMHashTableCallbacks callbacks);
void WMFreeHashTable(WMHashTable *table);
@@ -383,11 +392,15 @@ Bool WMNextHashEnumeratorItemAndKey(WMHashEnumerator *enumerator,
extern const WMHashTableCallbacks WMIntHashCallbacks;
/* sizeof(keys) are <= sizeof(void*) */
extern const WMHashTableCallbacks WMStringHashCallbacks;
/* keys are strings. Strings will be copied with wstrdup()
* and freed with wfree() */
extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
/* keys are strings, but they are not copied */
/* ---[ wutil-rs/src/array.rs ]--------------------------------------------------- */
/* ---[ WINGs/array.c ]--------------------------------------------------- */
/*
* WMArray use an array to store the elements.
@@ -409,22 +422,29 @@ WMArray* WMCreateArrayWithDestructor(int initialSize, WMFreeDataProc *destructor
WMArray* WMCreateArrayWithArray(WMArray *array);
#define WMDuplicateArray(array) WMCreateArrayWithArray(array)
void WMEmptyArray(WMArray *array);
void WMFreeArray(WMArray *array);
int WMGetArrayItemCount(WMArray *array);
/* appends other to array. other remains unchanged */
void WMAppendArray(WMArray *array, WMArray *other);
/* add will place the element at the end of the array */
void WMAddToArray(WMArray *array, void *item);
/* insert will increment the index of elements after it by 1 */
void WMInsertInArray(WMArray *array, int index, void *item);
/* set returns the old item WITHOUT calling the
/* replace and set will return the old item WITHOUT calling the
* destructor on it even if its available. Free the returned item yourself.
*/
void* WMSetInArray(WMArray *array, int index, void *item);
void* WMReplaceInArray(WMArray *array, int index, void *item);
#define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
/* delete and remove will remove the elements and cause the elements
* after them to decrement their indexes by 1. Also will call the
@@ -432,21 +452,20 @@ void* WMSetInArray(WMArray *array, int index, void *item);
*/
int WMDeleteFromArray(WMArray *array, int index);
int WMRemoveFromArray(WMArray *array, void *item);
#define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
int WMRemoveFromArrayMatching(WMArray *array, WMMatchDataProc *match, void *cdata);
void* WMGetFromArray(WMArray *array, int index);
#define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
/* pop will return the last element from the array, also removing it
* from the array. The destructor is NOT called, even if available.
* Free the returned element if needed by yourself
*/
void* WMPopFromArray(WMArray *array);
/* Like WMFindInArray(array, NULL, item) */
int WMGetFirstInArray(WMArray *array, void *item);
int WMFindInArray(WMArray *array, WMMatchDataProc *match, void *cdata);
int WMCountInArray(WMArray *array, void *item);
@@ -460,6 +479,8 @@ void WMSortArray(WMArray *array, WMCompareDataProc *comparer);
void WMMapArray(WMArray *array, void (*function)(void*, void*), void *data);
WMArray* WMGetSubarrayWithRange(WMArray* array, WMRange aRange);
void* WMArrayFirst(WMArray *array, WMArrayIterator *iter);
void* WMArrayLast(WMArray *array, WMArrayIterator *iter);
@@ -479,7 +500,7 @@ void* WMArrayPrevious(WMArray *array, WMArrayIterator *iter);
for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
var = WMArrayPrevious(array, &(i)))
/* ---[ wutil-rs/src/bag.rs ]------------------------------------------------- */
/* ---[ WINGs/bagtree.c ]------------------------------------------------- */
/*
* Tree bags use a red-black tree for storage.
@@ -494,16 +515,58 @@ void* WMArrayPrevious(WMArray *array, WMArrayIterator *iter);
* Slow for storing small numbers of elements
*/
#define WMCreateBag(size) WMCreateTreeBag()
#define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
WMBag* WMCreateTreeBag(void);
WMBag* WMCreateTreeBagWithDestructor(WMFreeDataProc *destructor);
int WMGetBagItemCount(WMBag *bag);
void WMAppendBag(WMBag *bag, WMBag *other);
void WMPutInBag(WMBag *bag, void *item);
/* insert will increment the index of elements after it by 1 */
void WMInsertInBag(WMBag *bag, int index, void *item);
/* erase will remove the element from the bag,
* but will keep the index of the other elements unchanged */
int WMEraseFromBag(WMBag *bag, int index);
/* delete and remove will remove the elements and cause the elements
* after them to decrement their indexes by 1 */
int WMDeleteFromBag(WMBag *bag, int index);
int WMRemoveFromBag(WMBag *bag, void *item);
void* WMGetFromBag(WMBag *bag, int index);
void WMSetInBag(WMBag *bag, int index, void *item);
void* WMReplaceInBag(WMBag *bag, int index, void *item);
#define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
/* comparer must return:
* < 0 if a < b
* > 0 if a > b
* = 0 if a = b
*/
void WMSortBag(WMBag *bag, WMCompareDataProc *comparer);
void WMEmptyBag(WMBag *bag);
void WMFreeBag(WMBag *bag);
void WMMapBag(WMBag *bag, void (*function)(void*, void*), void *data);
int WMGetFirstInBag(WMBag *bag, void *item);
int WMCountInBag(WMBag *bag, void *item);
int WMFindInBag(WMBag *bag, WMMatchDataProc *match, void *cdata);
void* WMBagFirst(WMBag *bag, WMBagIterator *ptr);
void* WMBagLast(WMBag *bag, WMBagIterator *ptr);
@@ -515,11 +578,16 @@ void* WMBagPrevious(WMBag *bag, WMBagIterator *ptr);
void* WMBagIteratorAtIndex(WMBag *bag, int index, WMBagIterator *ptr);
int WMBagIndexForIterator(WMBag *bag, WMBagIterator ptr);
/* The following macro assumes that the bag doesn't change in the for loop */
/* The following 2 macros assume that the bag doesn't change in the for loop */
#define WM_ITERATE_BAG(bag, var, i) \
for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
var = WMBagNext(bag, &(i)))
#define WM_ETARETI_BAG(bag, var, i) \
for (var = WMBagLast(bag, &(i)); (i) >= 0; \
for (var = WMBagLast(bag, &(i)); (i) != NULL; \
var = WMBagPrevious(bag, &(i)))
@@ -536,16 +604,37 @@ WMData* WMCreateDataWithLength(unsigned length);
WMData* WMCreateDataWithBytes(const void *bytes, unsigned length);
/* destructor is a function called to free the data when releasing the data
* object, or NULL if no freeing of data is necesary. */
WMData* WMCreateDataWithBytesNoCopy(void *bytes, unsigned length,
WMFreeDataProc *destructor);
WMData* WMCreateDataWithData(WMData *aData);
WMData* WMRetainData(WMData *aData);
void WMReleaseData(WMData *aData);
/* Adjusting capacity */
void WMSetDataCapacity(WMData *aData, unsigned capacity);
void WMSetDataLength(WMData *aData, unsigned length);
void WMIncreaseDataLengthBy(WMData *aData, unsigned extraLength);
/* Accessing data */
const void* WMDataBytes(WMData *aData);
void WMGetDataBytes(WMData *aData, void *buffer);
void WMGetDataBytesWithLength(WMData *aData, void *buffer, unsigned length);
void WMGetDataBytesWithRange(WMData *aData, void *buffer, WMRange aRange);
WMData* WMGetSubdataWithRange(WMData *aData, WMRange aRange);
/* Testing data */
Bool WMIsDataEqualToData(WMData *aData, WMData *anotherData);
@@ -560,6 +649,10 @@ void WMAppendData(WMData *aData, WMData *anotherData);
/* Modifying data */
void WMReplaceDataBytesInRange(WMData *aData, WMRange aRange, const void *bytes);
void WMResetDataBytesInRange(WMData *aData, WMRange aRange);
void WMSetData(WMData *aData, WMData *anotherData);
@@ -568,12 +661,14 @@ void WMSetDataFormat(WMData *aData, unsigned format);
unsigned WMGetDataFormat(WMData *aData);
/* Storing data */
/* ---[ wutil-rs/src/tree.rs ]---------------------------------------------------- */
/* ---[ WINGs/tree.c ]---------------------------------------------------- */
/* Generic Tree and TreeNode */
WMTreeNode* WMCreateTreeNode(void *data);
WMTreeNode* WMCreateTreeNodeWithDestructor(void *data, WMFreeDataProc *destructor);
WMTreeNode* WMInsertItemInTree(WMTreeNode *parent, int index, void *item);
#define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
@@ -582,23 +677,48 @@ WMTreeNode* WMInsertNodeInTree(WMTreeNode *parent, int index, WMTreeNode *aNode)
#define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
void WMDestroyTreeNode(WMTreeNode *aNode);
void WMDeleteLeafForTreeNode(WMTreeNode *aNode, int index);
void WMRemoveLeafForTreeNode(WMTreeNode *aNode, void *leaf);
void* WMReplaceDataForTreeNode(WMTreeNode *aNode, void *newData);
void* WMGetDataForTreeNode(WMTreeNode *aNode);
int WMGetTreeNodeDepth(WMTreeNode *aNode);
WMTreeNode* WMGetParentForTreeNode(WMTreeNode *aNode);
/* Sort only the leaves of the passed node */
void WMSortLeavesForTreeNode(WMTreeNode *aNode, WMCompareDataProc *comparer);
/* Sort all tree recursively starting from the passed node */
void WMSortTree(WMTreeNode *aNode, int (*comparer)(const WMTreeNode *a, const WMTreeNode *b));
void WMSortTree(WMTreeNode *aNode, WMCompareDataProc *comparer);
/* Returns the first node which matches node's data with cdata by 'match' */
WMTreeNode* WMFindInTree(WMTreeNode *aTree, WMMatchDataProc *match, void *cdata);
/* Returns the first node where node's data matches cdata by 'match' and node is
* at most `limit' depths down from `aTree'. */
WMTreeNode *WMFindInTreeWithDepthLimit(WMTreeNode * aTree, int (*match)(const WMTreeNode *item, const void *cdata), void *cdata, int limit);
WMTreeNode *WMFindInTreeWithDepthLimit(WMTreeNode * aTree, WMMatchDataProc * match, void *cdata, int limit);
/* Returns first tree node that has data == cdata */
#define WMGetFirstInTree(aTree, cdata) WMFindInTree(aTree, NULL, cdata)
/* Walk every node of aNode with `walk' */
void WMTreeWalk(WMTreeNode *aNode, WMTreeWalkProc * walk, void *data);
void WMTreeWalk(WMTreeNode *aNode, WMTreeWalkProc * walk, void *data, Bool DepthFirst);
/* ---[ WINGs/notification.c ]---------------------------------------------------- */
/* ---[ WINGs/data.c ]---------------------------------------------------- */
WMNotification* WMCreateNotification(const char *name, void *object, void *clientData);
void WMReleaseNotification(WMNotification *notification);
WMNotification* WMRetainNotification(WMNotification *notification);
void* WMGetNotificationClientData(WMNotification *notification);
void* WMGetNotificationObject(WMNotification *notification);
@@ -609,27 +729,52 @@ const char* WMGetNotificationName(WMNotification *notification);
void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
void *observer, const char *name, void *object);
void WMPostNotification(WMNotification *notification);
void WMRemoveNotificationObserver(void *observer);
void WMRemoveNotificationObserverWithName(void *observer, const char *name,
void *object);
void WMPostNotificationName(const char *name, void *object, void *clientData);
/* Property Lists handling */
WMNotificationQueue* WMGetDefaultNotificationQueue(void);
WMNotificationQueue* WMCreateNotificationQueue(void);
void WMDequeueNotificationMatching(WMNotificationQueue *queue,
WMNotification *notification,
unsigned mask);
void WMEnqueueNotification(WMNotificationQueue *queue,
WMNotification *notification,
WMPostingStyle postingStyle);
void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
WMNotification *notification,
WMPostingStyle postingStyle,
unsigned coalesceMask);
/* ---[ WINGs/proplist.c ]------------------------------------------------ */
WMPropList* WMCreatePLArray(WMPropList *elem, ...);
/* Property Lists handling */
/* ---[ wutil-rs/src/prop_list.rs ]--------------------------------------- */
void WMPLSetCaseSensitive(Bool caseSensitive);
WMPropList* WMCreatePLString(const char *str);
WMPropList* WMCreatePLArrayFromSlice(WMPropList *elems, unsigned int length);
WMPropList* WMCreatePLData(WMData *data);
WMPropList* WMCreateEmptyPLArray();
WMPropList* WMCreatePLDataWithBytes(const unsigned char *bytes, unsigned int length);
WMPropList* WMCreatePLDictionary(WMPropList *key, WMPropList *value);
WMPropList* WMCreatePLDataWithBytesNoCopy(unsigned char *bytes,
unsigned int length,
WMFreeDataProc *destructor);
WMPropList* WMCreateEmptyPLDictionary();
WMPropList* WMCreatePLArray(WMPropList *elem, ...);
WMPropList* WMCreatePLDictionary(WMPropList *key, WMPropList *value, ...);
WMPropList* WMRetainPropList(WMPropList *plist);
@@ -667,6 +812,8 @@ int WMGetPropListItemCount(WMPropList *plist);
Bool WMIsPLString(WMPropList *plist);
Bool WMIsPLData(WMPropList *plist);
Bool WMIsPLArray(WMPropList *plist);
Bool WMIsPLDictionary(WMPropList *plist);
@@ -676,6 +823,14 @@ Bool WMIsPropListEqualTo(WMPropList *plist, WMPropList *other);
/* Returns a reference. Do not free it! */
char* WMGetFromPLString(WMPropList *plist);
/* Returns a reference. Do not free it! */
WMData* WMGetFromPLData(WMPropList *plist);
/* Returns a reference. Do not free it! */
const unsigned char* WMGetPLDataBytes(WMPropList *plist);
int WMGetPLDataLength(WMPropList *plist);
/* Returns a reference. */
WMPropList* WMGetFromPLArray(WMPropList *plist, int index);
@@ -683,9 +838,14 @@ WMPropList* WMGetFromPLArray(WMPropList *plist, int index);
WMPropList* WMGetFromPLDictionary(WMPropList *plist, WMPropList *key);
/* Returns a PropList array with all the dictionary keys. Release it when
* you're done. */
* you're done. Keys in array are retained from the original dictionary
* not copied and need NOT to be released individually. */
WMPropList* WMGetPLDictionaryKeys(WMPropList *plist);
/* Creates only the first level deep object. All the elements inside are
* retained from the original */
WMPropList* WMShallowCopyPropList(WMPropList *plist);
/* Makes a completely separate replica of the original proplist */
WMPropList* WMDeepCopyPropList(WMPropList *plist);

363
WINGs/array.c Normal file
View File

@@ -0,0 +1,363 @@
/*
* Dynamically Resized Array
*
* Authors: Alfredo K. Kojima <kojima@windowmaker.info>
* Dan Pascu <dan@windowmaker.info>
*
* This code is released to the Public Domain, but
* proper credit is always appreciated :)
*/
#include <stdlib.h>
#include <string.h>
#include "WUtil.h"
#define INITIAL_SIZE 8
#define RESIZE_INCREMENT 8
typedef struct W_Array {
void **items; /* the array data */
int itemCount; /* # of items in array */
int allocSize; /* allocated size of array */
WMFreeDataProc *destructor; /* the destructor to free elements */
} W_Array;
WMArray *WMCreateArray(int initialSize)
{
return WMCreateArrayWithDestructor(initialSize, NULL);
}
WMArray *WMCreateArrayWithDestructor(int initialSize, WMFreeDataProc * destructor)
{
WMArray *array;
array = wmalloc(sizeof(WMArray));
if (initialSize <= 0) {
initialSize = INITIAL_SIZE;
}
array->items = wmalloc(sizeof(void *) * initialSize);
array->itemCount = 0;
array->allocSize = initialSize;
array->destructor = destructor;
return array;
}
WMArray *WMCreateArrayWithArray(WMArray * array)
{
WMArray *newArray;
newArray = wmalloc(sizeof(WMArray));
newArray->items = wmalloc(sizeof(void *) * array->allocSize);
memcpy(newArray->items, array->items, sizeof(void *) * array->itemCount);
newArray->itemCount = array->itemCount;
newArray->allocSize = array->allocSize;
newArray->destructor = NULL;
return newArray;
}
void WMEmptyArray(WMArray * array)
{
if (array->destructor) {
while (array->itemCount > 0) {
array->itemCount--;
array->destructor(array->items[array->itemCount]);
}
}
/*memset(array->items, 0, array->itemCount * sizeof(void*)); */
array->itemCount = 0;
}
void WMFreeArray(WMArray * array)
{
if (array == NULL)
return;
WMEmptyArray(array);
wfree(array->items);
wfree(array);
}
int WMGetArrayItemCount(WMArray * array)
{
if (array == NULL)
return 0;
return array->itemCount;
}
void WMAppendArray(WMArray * array, WMArray * other)
{
if (array == NULL || other == NULL)
return;
if (other->itemCount == 0)
return;
if (array->itemCount + other->itemCount > array->allocSize) {
array->allocSize += other->allocSize;
array->items = wrealloc(array->items, sizeof(void *) * array->allocSize);
}
memcpy(array->items + array->itemCount, other->items, sizeof(void *) * other->itemCount);
array->itemCount += other->itemCount;
}
void WMAddToArray(WMArray * array, void *item)
{
if (array == NULL)
return;
if (array->itemCount >= array->allocSize) {
array->allocSize += RESIZE_INCREMENT;
array->items = wrealloc(array->items, sizeof(void *) * array->allocSize);
}
array->items[array->itemCount] = item;
array->itemCount++;
}
void WMInsertInArray(WMArray * array, int index, void *item)
{
if (array == NULL)
return;
wassertr(index >= 0 && index <= array->itemCount);
if (array->itemCount >= array->allocSize) {
array->allocSize += RESIZE_INCREMENT;
array->items = wrealloc(array->items, sizeof(void *) * array->allocSize);
}
if (index < array->itemCount) {
memmove(array->items + index + 1, array->items + index,
sizeof(void *) * (array->itemCount - index));
}
array->items[index] = item;
array->itemCount++;
}
void *WMReplaceInArray(WMArray * array, int index, void *item)
{
void *old;
if (array == NULL)
return NULL;
wassertrv(index >= 0 && index <= array->itemCount, NULL);
/* is it really useful to perform append if index == array->itemCount ? -Dan */
if (index == array->itemCount) {
WMAddToArray(array, item);
return NULL;
}
old = array->items[index];
array->items[index] = item;
return old;
}
int WMDeleteFromArray(WMArray * array, int index)
{
if (array == NULL)
return 0;
wassertrv(index >= 0 && index < array->itemCount, 0);
if (array->destructor) {
array->destructor(array->items[index]);
}
if (index < array->itemCount - 1) {
memmove(array->items + index, array->items + index + 1,
sizeof(void *) * (array->itemCount - index - 1));
}
array->itemCount--;
return 1;
}
int WMRemoveFromArrayMatching(WMArray * array, WMMatchDataProc * match, void *cdata)
{
int i;
if (array == NULL)
return 1;
if (match != NULL) {
for (i = 0; i < array->itemCount; i++) {
if ((*match) (array->items[i], cdata)) {
WMDeleteFromArray(array, i);
return 1;
}
}
} else {
for (i = 0; i < array->itemCount; i++) {
if (array->items[i] == cdata) {
WMDeleteFromArray(array, i);
return 1;
}
}
}
return 0;
}
void *WMGetFromArray(WMArray * array, int index)
{
if (index < 0 || array == NULL || index >= array->itemCount)
return NULL;
return array->items[index];
}
void *WMPopFromArray(WMArray * array)
{
if (array == NULL || array->itemCount <= 0)
return NULL;
array->itemCount--;
return array->items[array->itemCount];
}
int WMFindInArray(WMArray * array, WMMatchDataProc * match, void *cdata)
{
int i;
if (array == NULL)
return WANotFound;
if (match != NULL) {
for (i = 0; i < array->itemCount; i++) {
if ((*match) (array->items[i], cdata))
return i;
}
} else {
for (i = 0; i < array->itemCount; i++) {
if (array->items[i] == cdata)
return i;
}
}
return WANotFound;
}
int WMCountInArray(WMArray * array, void *item)
{
int i, count;
if (array == NULL)
return 0;
for (i = 0, count = 0; i < array->itemCount; i++) {
if (array->items[i] == item)
count++;
}
return count;
}
void WMSortArray(WMArray * array, WMCompareDataProc * comparer)
{
if (array == NULL)
return;
if (array->itemCount > 1) { /* Don't sort empty or single element arrays */
qsort(array->items, array->itemCount, sizeof(void *), comparer);
}
}
void WMMapArray(WMArray * array, void (*function) (void *, void *), void *data)
{
int i;
if (array == NULL)
return;
for (i = 0; i < array->itemCount; i++) {
(*function) (array->items[i], data);
}
}
WMArray *WMGetSubarrayWithRange(WMArray * array, WMRange aRange)
{
WMArray *newArray;
if (aRange.count <= 0 || array == NULL)
return WMCreateArray(0);
if (aRange.position < 0)
aRange.position = 0;
if (aRange.position >= array->itemCount)
aRange.position = array->itemCount - 1;
if (aRange.position + aRange.count > array->itemCount)
aRange.count = array->itemCount - aRange.position;
newArray = WMCreateArray(aRange.count);
memcpy(newArray->items, array->items + aRange.position, sizeof(void *) * aRange.count);
newArray->itemCount = aRange.count;
return newArray;
}
void *WMArrayFirst(WMArray * array, WMArrayIterator * iter)
{
if (array == NULL || array->itemCount == 0) {
*iter = WANotFound;
return NULL;
} else {
*iter = 0;
return array->items[0];
}
}
void *WMArrayLast(WMArray * array, WMArrayIterator * iter)
{
if (array == NULL || array->itemCount == 0) {
*iter = WANotFound;
return NULL;
} else {
*iter = array->itemCount - 1;
return array->items[*iter];
}
}
void *WMArrayNext(WMArray * array, WMArrayIterator * iter)
{
if (array == NULL) {
*iter = WANotFound;
return NULL;
}
if (*iter >= 0 && *iter < array->itemCount - 1) {
return array->items[++(*iter)];
} else {
*iter = WANotFound;
return NULL;
}
}
void *WMArrayPrevious(WMArray * array, WMArrayIterator * iter)
{
if (array == NULL) {
*iter = WANotFound;
return NULL;
}
if (*iter > 0 && *iter < array->itemCount) {
return array->items[--(*iter)];
} else {
*iter = WANotFound;
return NULL;
}
}

745
WINGs/bagtree.c Normal file
View File

@@ -0,0 +1,745 @@
#include <stdlib.h>
#include <string.h>
#include "WUtil.h"
typedef struct W_Node {
struct W_Node *parent;
struct W_Node *left;
struct W_Node *right;
int color;
void *data;
int index;
} W_Node;
typedef struct W_Bag {
W_Node *root;
W_Node *nil; /* sentinel */
int count;
void (*destructor) (void *item);
} W_Bag;
#define IS_LEFT(node) (node == node->parent->left)
#define IS_RIGHT(node) (node == node->parent->right)
static void leftRotate(W_Bag * tree, W_Node * node)
{
W_Node *node2;
node2 = node->right;
node->right = node2->left;
node2->left->parent = node;
node2->parent = node->parent;
if (node->parent == tree->nil) {
tree->root = node2;
} else {
if (IS_LEFT(node)) {
node->parent->left = node2;
} else {
node->parent->right = node2;
}
}
node2->left = node;
node->parent = node2;
}
static void rightRotate(W_Bag * tree, W_Node * node)
{
W_Node *node2;
node2 = node->left;
node->left = node2->right;
node2->right->parent = node;
node2->parent = node->parent;
if (node->parent == tree->nil) {
tree->root = node2;
} else {
if (IS_LEFT(node)) {
node->parent->left = node2;
} else {
node->parent->right = node2;
}
}
node2->right = node;
node->parent = node2;
}
static void treeInsert(W_Bag * tree, W_Node * node)
{
W_Node *y = tree->nil;
W_Node *x = tree->root;
while (x != tree->nil) {
y = x;
if (node->index <= x->index)
x = x->left;
else
x = x->right;
}
node->parent = y;
if (y == tree->nil)
tree->root = node;
else if (node->index <= y->index)
y->left = node;
else
y->right = node;
}
static void rbTreeInsert(W_Bag * tree, W_Node * node)
{
W_Node *y;
treeInsert(tree, node);
node->color = 'R';
while (node != tree->root && node->parent->color == 'R') {
if (IS_LEFT(node->parent)) {
y = node->parent->parent->right;
if (y->color == 'R') {
node->parent->color = 'B';
y->color = 'B';
node->parent->parent->color = 'R';
node = node->parent->parent;
} else {
if (IS_RIGHT(node)) {
node = node->parent;
leftRotate(tree, node);
}
node->parent->color = 'B';
node->parent->parent->color = 'R';
rightRotate(tree, node->parent->parent);
}
} else {
y = node->parent->parent->left;
if (y->color == 'R') {
node->parent->color = 'B';
y->color = 'B';
node->parent->parent->color = 'R';
node = node->parent->parent;
} else {
if (IS_LEFT(node)) {
node = node->parent;
rightRotate(tree, node);
}
node->parent->color = 'B';
node->parent->parent->color = 'R';
leftRotate(tree, node->parent->parent);
}
}
}
tree->root->color = 'B';
}
static void rbDeleteFixup(W_Bag * tree, W_Node * node)
{
W_Node *w;
while (node != tree->root && node->color == 'B') {
if (IS_LEFT(node)) {
w = node->parent->right;
if (w->color == 'R') {
w->color = 'B';
node->parent->color = 'R';
leftRotate(tree, node->parent);
w = node->parent->right;
}
if (w->left->color == 'B' && w->right->color == 'B') {
w->color = 'R';
node = node->parent;
} else {
if (w->right->color == 'B') {
w->left->color = 'B';
w->color = 'R';
rightRotate(tree, w);
w = node->parent->right;
}
w->color = node->parent->color;
node->parent->color = 'B';
w->right->color = 'B';
leftRotate(tree, node->parent);
node = tree->root;
}
} else {
w = node->parent->left;
if (w->color == 'R') {
w->color = 'B';
node->parent->color = 'R';
rightRotate(tree, node->parent);
w = node->parent->left;
}
if (w->left->color == 'B' && w->right->color == 'B') {
w->color = 'R';
node = node->parent;
} else {
if (w->left->color == 'B') {
w->right->color = 'B';
w->color = 'R';
leftRotate(tree, w);
w = node->parent->left;
}
w->color = node->parent->color;
node->parent->color = 'B';
w->left->color = 'B';
rightRotate(tree, node->parent);
node = tree->root;
}
}
}
node->color = 'B';
}
static W_Node *treeMinimum(W_Node * node, W_Node * nil)
{
while (node->left != nil)
node = node->left;
return node;
}
static W_Node *treeMaximum(W_Node * node, W_Node * nil)
{
while (node->right != nil)
node = node->right;
return node;
}
static W_Node *treeSuccessor(W_Node * node, W_Node * nil)
{
W_Node *y;
if (node->right != nil) {
return treeMinimum(node->right, nil);
}
y = node->parent;
while (y != nil && node == y->right) {
node = y;
y = y->parent;
}
return y;
}
static W_Node *treePredecessor(W_Node * node, W_Node * nil)
{
W_Node *y;
if (node->left != nil) {
return treeMaximum(node->left, nil);
}
y = node->parent;
while (y != nil && node == y->left) {
node = y;
y = y->parent;
}
return y;
}
static W_Node *rbTreeDelete(W_Bag * tree, W_Node * node)
{
W_Node *nil = tree->nil;
W_Node *x, *y;
if (node->left == nil || node->right == nil) {
y = node;
} else {
y = treeSuccessor(node, nil);
}
if (y->left != nil) {
x = y->left;
} else {
x = y->right;
}
x->parent = y->parent;
if (y->parent == nil) {
tree->root = x;
} else {
if (IS_LEFT(y)) {
y->parent->left = x;
} else {
y->parent->right = x;
}
}
if (y != node) {
node->index = y->index;
node->data = y->data;
}
if (y->color == 'B') {
rbDeleteFixup(tree, x);
}
return y;
}
static W_Node *treeSearch(W_Node * root, W_Node * nil, int index)
{
if (root == nil || root->index == index) {
return root;
}
if (index < root->index) {
return treeSearch(root->left, nil, index);
} else {
return treeSearch(root->right, nil, index);
}
}
static W_Node *treeFind(W_Node * root, W_Node * nil, void *data)
{
W_Node *tmp;
if (root == nil || root->data == data)
return root;
tmp = treeFind(root->left, nil, data);
if (tmp != nil)
return tmp;
tmp = treeFind(root->right, nil, data);
return tmp;
}
#if 0
static char buf[512];
static void printNodes(W_Node * node, W_Node * nil, int depth)
{
if (node == nil) {
return;
}
printNodes(node->left, nil, depth + 1);
memset(buf, ' ', depth * 2);
buf[depth * 2] = 0;
if (IS_LEFT(node))
printf("%s/(%2i\n", buf, node->index);
else
printf("%s\\(%2i\n", buf, node->index);
printNodes(node->right, nil, depth + 1);
}
void PrintTree(WMBag * bag)
{
W_TreeBag *tree = (W_TreeBag *) bag->data;
printNodes(tree->root, tree->nil, 0);
}
#endif
WMBag *WMCreateTreeBag(void)
{
return WMCreateTreeBagWithDestructor(NULL);
}
WMBag *WMCreateTreeBagWithDestructor(WMFreeDataProc * destructor)
{
WMBag *bag;
bag = wmalloc(sizeof(WMBag));
bag->nil = wmalloc(sizeof(W_Node));
bag->nil->left = bag->nil->right = bag->nil->parent = bag->nil;
bag->nil->index = WBNotFound;
bag->root = bag->nil;
bag->destructor = destructor;
return bag;
}
int WMGetBagItemCount(WMBag * self)
{
return self->count;
}
void WMAppendBag(WMBag * self, WMBag * bag)
{
WMBagIterator ptr;
void *data;
for (data = WMBagFirst(bag, &ptr); data != NULL; data = WMBagNext(bag, &ptr)) {
WMPutInBag(self, data);
}
}
void WMPutInBag(WMBag * self, void *item)
{
W_Node *ptr;
ptr = wmalloc(sizeof(W_Node));
ptr->data = item;
ptr->index = self->count;
ptr->left = self->nil;
ptr->right = self->nil;
ptr->parent = self->nil;
rbTreeInsert(self, ptr);
self->count++;
}
void WMInsertInBag(WMBag * self, int index, void *item)
{
W_Node *ptr;
ptr = wmalloc(sizeof(W_Node));
ptr->data = item;
ptr->index = index;
ptr->left = self->nil;
ptr->right = self->nil;
ptr->parent = self->nil;
rbTreeInsert(self, ptr);
while ((ptr = treeSuccessor(ptr, self->nil)) != self->nil) {
ptr->index++;
}
self->count++;
}
static int treeDeleteNode(WMBag * self, W_Node *ptr)
{
if (ptr != self->nil) {
W_Node *tmp;
self->count--;
tmp = treeSuccessor(ptr, self->nil);
while (tmp != self->nil) {
tmp->index--;
tmp = treeSuccessor(tmp, self->nil);
}
ptr = rbTreeDelete(self, ptr);
if (self->destructor)
self->destructor(ptr->data);
wfree(ptr);
return 1;
}
return 0;
}
int WMRemoveFromBag(WMBag * self, void *item)
{
W_Node *ptr = treeFind(self->root, self->nil, item);
return treeDeleteNode(self, ptr);
}
int WMEraseFromBag(WMBag * self, int index)
{
W_Node *ptr = treeSearch(self->root, self->nil, index);
if (ptr != self->nil) {
self->count--;
ptr = rbTreeDelete(self, ptr);
if (self->destructor)
self->destructor(ptr->data);
wfree(ptr);
wassertrv(self->count == 0 || self->root->index >= 0, 1);
return 1;
} else {
return 0;
}
}
int WMDeleteFromBag(WMBag * self, int index)
{
W_Node *ptr = treeSearch(self->root, self->nil, index);
return treeDeleteNode(self, ptr);
}
void *WMGetFromBag(WMBag * self, int index)
{
W_Node *node;
node = treeSearch(self->root, self->nil, index);
if (node != self->nil)
return node->data;
else
return NULL;
}
int WMGetFirstInBag(WMBag * self, void *item)
{
W_Node *node;
node = treeFind(self->root, self->nil, item);
if (node != self->nil)
return node->index;
else
return WBNotFound;
}
static int treeCount(W_Node * root, W_Node * nil, void *item)
{
int count = 0;
if (root == nil)
return 0;
if (root->data == item)
count++;
if (root->left != nil)
count += treeCount(root->left, nil, item);
if (root->right != nil)
count += treeCount(root->right, nil, item);
return count;
}
int WMCountInBag(WMBag * self, void *item)
{
return treeCount(self->root, self->nil, item);
}
void *WMReplaceInBag(WMBag * self, int index, void *item)
{
W_Node *ptr = treeSearch(self->root, self->nil, index);
void *old = NULL;
if (item == NULL) {
self->count--;
ptr = rbTreeDelete(self, ptr);
if (self->destructor)
self->destructor(ptr->data);
wfree(ptr);
} else if (ptr != self->nil) {
old = ptr->data;
ptr->data = item;
} else {
W_Node *ptr;
ptr = wmalloc(sizeof(W_Node));
ptr->data = item;
ptr->index = index;
ptr->left = self->nil;
ptr->right = self->nil;
ptr->parent = self->nil;
rbTreeInsert(self, ptr);
self->count++;
}
return old;
}
void WMSortBag(WMBag * self, WMCompareDataProc * comparer)
{
void **items;
W_Node *tmp;
int i;
if (self->count == 0)
return;
items = wmalloc(sizeof(void *) * self->count);
i = 0;
tmp = treeMinimum(self->root, self->nil);
while (tmp != self->nil) {
items[i++] = tmp->data;
tmp = treeSuccessor(tmp, self->nil);
}
qsort(&items[0], self->count, sizeof(void *), comparer);
i = 0;
tmp = treeMinimum(self->root, self->nil);
while (tmp != self->nil) {
tmp->index = i;
tmp->data = items[i++];
tmp = treeSuccessor(tmp, self->nil);
}
wfree(items);
}
static void deleteTree(WMBag * self, W_Node * node)
{
if (node == self->nil)
return;
deleteTree(self, node->left);
if (self->destructor)
self->destructor(node->data);
deleteTree(self, node->right);
wfree(node);
}
void WMEmptyBag(WMBag * self)
{
deleteTree(self, self->root);
self->root = self->nil;
self->count = 0;
}
void WMFreeBag(WMBag * self)
{
WMEmptyBag(self);
wfree(self->nil);
wfree(self);
}
static void mapTree(W_Bag * tree, W_Node * node, void (*function) (void *, void *), void *data)
{
if (node == tree->nil)
return;
mapTree(tree, node->left, function, data);
(*function) (node->data, data);
mapTree(tree, node->right, function, data);
}
void WMMapBag(WMBag * self, void (*function) (void *, void *), void *data)
{
mapTree(self, self->root, function, data);
}
static int findInTree(W_Bag * tree, W_Node * node, WMMatchDataProc * function, void *cdata)
{
int index;
if (node == tree->nil)
return WBNotFound;
index = findInTree(tree, node->left, function, cdata);
if (index != WBNotFound)
return index;
if ((*function) (node->data, cdata)) {
return node->index;
}
return findInTree(tree, node->right, function, cdata);
}
int WMFindInBag(WMBag * self, WMMatchDataProc * match, void *cdata)
{
return findInTree(self, self->root, match, cdata);
}
void *WMBagFirst(WMBag * self, WMBagIterator * ptr)
{
W_Node *node;
node = treeMinimum(self->root, self->nil);
if (node == self->nil) {
*ptr = NULL;
return NULL;
} else {
*ptr = node;
return node->data;
}
}
void *WMBagLast(WMBag * self, WMBagIterator * ptr)
{
W_Node *node;
node = treeMaximum(self->root, self->nil);
if (node == self->nil) {
*ptr = NULL;
return NULL;
} else {
*ptr = node;
return node->data;
}
}
void *WMBagNext(WMBag * self, WMBagIterator * ptr)
{
W_Node *node;
if (*ptr == NULL)
return NULL;
node = treeSuccessor(*ptr, self->nil);
if (node == self->nil) {
*ptr = NULL;
return NULL;
} else {
*ptr = node;
return node->data;
}
}
void *WMBagPrevious(WMBag * self, WMBagIterator * ptr)
{
W_Node *node;
if (*ptr == NULL)
return NULL;
node = treePredecessor(*ptr, self->nil);
if (node == self->nil) {
*ptr = NULL;
return NULL;
} else {
*ptr = node;
return node->data;
}
}
void *WMBagIteratorAtIndex(WMBag * self, int index, WMBagIterator * ptr)
{
W_Node *node;
node = treeSearch(self->root, self->nil, index);
if (node == self->nil) {
*ptr = NULL;
return NULL;
} else {
*ptr = node;
return node->data;
}
}
int WMBagIndexForIterator(WMBag * bag, WMBagIterator ptr)
{
/* Parameter not used, but tell the compiler that it is ok */
(void) bag;
return ((W_Node *) ptr)->index;
}

289
WINGs/data.c Normal file
View File

@@ -0,0 +1,289 @@
/*
* WINGs WMData function library
*
* Copyright (c) 1999-2003 Dan Pascu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include <string.h>
#include "WUtil.h"
typedef struct W_Data {
unsigned length; /* How many bytes we have */
unsigned capacity; /* How many bytes it can hold */
unsigned growth; /* How much to grow */
void *bytes; /* Actual data */
unsigned retainCount;
WMFreeDataProc *destructor;
int format; /* 0, 8, 16 or 32 */
} W_Data;
/* Creating and destroying data objects */
WMData *WMCreateDataWithCapacity(unsigned capacity)
{
WMData *aData;
aData = (WMData *) wmalloc(sizeof(WMData));
if (capacity > 0)
aData->bytes = wmalloc(capacity);
else
aData->bytes = NULL;
aData->capacity = capacity;
aData->growth = capacity / 2 > 0 ? capacity / 2 : 1;
aData->length = 0;
aData->retainCount = 1;
aData->format = 0;
aData->destructor = wfree;
return aData;
}
WMData *WMCreateDataWithLength(unsigned length)
{
WMData *aData;
aData = WMCreateDataWithCapacity(length);
if (length > 0) {
aData->length = length;
}
return aData;
}
WMData *WMCreateDataWithBytes(const void *bytes, unsigned length)
{
WMData *aData;
aData = WMCreateDataWithCapacity(length);
aData->length = length;
memcpy(aData->bytes, bytes, length);
return aData;
}
WMData *WMCreateDataWithBytesNoCopy(void *bytes, unsigned length, WMFreeDataProc * destructor)
{
WMData *aData;
aData = (WMData *) wmalloc(sizeof(WMData));
aData->length = length;
aData->capacity = length;
aData->growth = length / 2 > 0 ? length / 2 : 1;
aData->bytes = bytes;
aData->retainCount = 1;
aData->format = 0;
aData->destructor = destructor;
return aData;
}
WMData *WMCreateDataWithData(WMData * aData)
{
WMData *newData;
if (aData->length > 0) {
newData = WMCreateDataWithBytes(aData->bytes, aData->length);
} else {
newData = WMCreateDataWithCapacity(0);
}
newData->format = aData->format;
return newData;
}
WMData *WMRetainData(WMData * aData)
{
aData->retainCount++;
return aData;
}
void WMReleaseData(WMData * aData)
{
aData->retainCount--;
if (aData->retainCount > 0)
return;
if (aData->bytes != NULL && aData->destructor != NULL) {
aData->destructor(aData->bytes);
}
wfree(aData);
}
/* Adjusting capacity */
void WMSetDataCapacity(WMData * aData, unsigned capacity)
{
if (aData->capacity != capacity) {
aData->bytes = wrealloc(aData->bytes, capacity);
aData->capacity = capacity;
aData->growth = capacity / 2 > 0 ? capacity / 2 : 1;
}
if (aData->length > capacity) {
aData->length = capacity;
}
}
void WMSetDataLength(WMData * aData, unsigned length)
{
if (length > aData->capacity) {
WMSetDataCapacity(aData, length);
}
if (length > aData->length) {
memset((unsigned char *)aData->bytes + aData->length, 0, length - aData->length);
}
aData->length = length;
}
void WMSetDataFormat(WMData * aData, unsigned format)
{
aData->format = format;
}
void WMIncreaseDataLengthBy(WMData * aData, unsigned extraLength)
{
WMSetDataLength(aData, aData->length + extraLength);
}
/* Accessing data */
const void *WMDataBytes(WMData * aData)
{
return aData->bytes;
}
void WMGetDataBytes(WMData * aData, void *buffer)
{
wassertr(aData->length > 0);
memcpy(buffer, aData->bytes, aData->length);
}
unsigned WMGetDataFormat(WMData * aData)
{
return aData->format;
}
void WMGetDataBytesWithLength(WMData * aData, void *buffer, unsigned length)
{
wassertr(aData->length > 0);
wassertr(length <= aData->length);
memcpy(buffer, aData->bytes, length);
}
void WMGetDataBytesWithRange(WMData * aData, void *buffer, WMRange aRange)
{
wassertr(aRange.position < aData->length);
wassertr(aRange.count <= aData->length - aRange.position);
memcpy(buffer, (unsigned char *)aData->bytes + aRange.position, aRange.count);
}
WMData *WMGetSubdataWithRange(WMData * aData, WMRange aRange)
{
void *buffer;
WMData *newData;
if (aRange.count <= 0)
return WMCreateDataWithCapacity(0);
buffer = wmalloc(aRange.count);
WMGetDataBytesWithRange(aData, buffer, aRange);
newData = WMCreateDataWithBytesNoCopy(buffer, aRange.count, wfree);
newData->format = aData->format;
return newData;
}
/* Testing data */
Bool WMIsDataEqualToData(WMData * aData, WMData * anotherData)
{
if (aData->length != anotherData->length)
return False;
else if (!aData->bytes && !anotherData->bytes) /* both are empty */
return True;
else if (!aData->bytes || !anotherData->bytes) /* one of them is empty */
return False;
return (memcmp(aData->bytes, anotherData->bytes, aData->length) == 0);
}
unsigned WMGetDataLength(WMData * aData)
{
return aData->length;
}
/* Adding data */
void WMAppendDataBytes(WMData * aData, const void *bytes, unsigned length)
{
unsigned oldLength = aData->length;
unsigned newLength = oldLength + length;
if (newLength > aData->capacity) {
unsigned nextCapacity = aData->capacity + aData->growth;
unsigned nextGrowth = aData->capacity ? aData->capacity : 1;
while (nextCapacity < newLength) {
unsigned tmp = nextCapacity + nextGrowth;
nextGrowth = nextCapacity;
nextCapacity = tmp;
}
WMSetDataCapacity(aData, nextCapacity);
aData->growth = nextGrowth;
}
memcpy((unsigned char *)aData->bytes + oldLength, bytes, length);
aData->length = newLength;
}
void WMAppendData(WMData * aData, WMData * anotherData)
{
if (anotherData->length > 0)
WMAppendDataBytes(aData, anotherData->bytes, anotherData->length);
}
/* Modifying data */
void WMReplaceDataBytesInRange(WMData * aData, WMRange aRange, const void *bytes)
{
wassertr(aRange.position < aData->length);
wassertr(aRange.count <= aData->length - aRange.position);
memcpy((unsigned char *)aData->bytes + aRange.position, bytes, aRange.count);
}
void WMResetDataBytesInRange(WMData * aData, WMRange aRange)
{
wassertr(aRange.position < aData->length);
wassertr(aRange.count <= aData->length - aRange.position);
memset((unsigned char *)aData->bytes + aRange.position, 0, aRange.count);
}
void WMSetData(WMData * aData, WMData * anotherData)
{
unsigned length = anotherData->length;
WMSetDataCapacity(aData, length);
if (length > 0)
memcpy(aData->bytes, anotherData->bytes, length);
aData->length = length;
}
/* Storing data */

View File

@@ -498,7 +498,7 @@ static void registerDescriptionList(WMScreen * scr, WMView * view, WMArray * ope
for (i = 0; i < count; i++) {
text = WMGetDragOperationItemText(WMGetFromArray(operationArray, i));
strlcpy(textListItem, text, size);
wstrlcpy(textListItem, text, size);
/* to next text offset */
textListItem = &(textListItem[strlen(textListItem) + 1]);

View File

@@ -34,6 +34,331 @@
#include <pwd.h>
#include <limits.h>
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
const char *wgethomedir(void)
{
static char *home = NULL;
char *tmp;
struct passwd *user;
if (home)
return home;
tmp = GETENV("HOME");
if (tmp) {
home = wstrdup(tmp);
return home;
}
user = getpwuid(getuid());
if (!user) {
werror(_("could not get password entry for UID %i"), getuid());
home = "/";
return home;
}
if (!user->pw_dir)
home = "/";
else
home = wstrdup(user->pw_dir);
return home;
}
/*
* Return the home directory for the specified used
*
* If user not found, returns NULL, otherwise always returns a path that is
* statically stored.
*
* Please note you must use the path before any other call to 'getpw*' or it
* may be erased. This is a design choice to avoid duplication considering
* the use case for this function.
*/
static const char *getuserhomedir(const char *username)
{
static const char default_home[] = "/";
struct passwd *user;
user = getpwnam(username);
if (!user) {
werror(_("could not get password entry for user %s"), username);
return NULL;
}
if (!user->pw_dir)
return default_home;
else
return user->pw_dir;
}
char *wexpandpath(const char *path)
{
const char *origpath = path;
char buffer2[PATH_MAX + 2];
char buffer[PATH_MAX + 2];
int i;
memset(buffer, 0, PATH_MAX + 2);
if (*path == '~') {
const char *home;
path++;
if (*path == '/' || *path == 0) {
home = wgethomedir();
if (strlen(home) > PATH_MAX ||
wstrlcpy(buffer, home, sizeof(buffer)) >= sizeof(buffer))
goto error;
} else {
int j;
j = 0;
while (*path != 0 && *path != '/') {
if (j > PATH_MAX)
goto error;
buffer2[j++] = *path;
buffer2[j] = 0;
path++;
}
home = getuserhomedir(buffer2);
if (!home || wstrlcat(buffer, home, sizeof(buffer)) >= sizeof(buffer))
goto error;
}
}
i = strlen(buffer);
while (*path != 0 && i <= PATH_MAX) {
char *tmp;
if (*path == '$') {
int j;
path++;
/* expand $(HOME) or $HOME style environment variables */
if (*path == '(') {
path++;
j = 0;
while (*path != 0 && *path != ')') {
if (j > PATH_MAX)
goto error;
buffer2[j++] = *(path++);
}
buffer2[j] = 0;
if (*path == ')') {
path++;
tmp = getenv(buffer2);
} else {
tmp = NULL;
}
if (!tmp) {
if ((i += strlen(buffer2) + 2) > PATH_MAX)
goto error;
buffer[i] = 0;
if (wstrlcat(buffer, "$(", sizeof(buffer)) >= sizeof(buffer) ||
wstrlcat(buffer, buffer2, sizeof(buffer)) >= sizeof(buffer))
goto error;
if (*(path-1)==')') {
if (++i > PATH_MAX ||
wstrlcat(buffer, ")", sizeof(buffer)) >= sizeof(buffer))
goto error;
}
} else {
if ((i += strlen(tmp)) > PATH_MAX ||
wstrlcat(buffer, tmp, sizeof(buffer)) >= sizeof(buffer))
goto error;
}
} else {
j = 0;
while (*path != 0 && *path != '/') {
if (j > PATH_MAX)
goto error;
buffer2[j++] = *(path++);
}
buffer2[j] = 0;
tmp = getenv(buffer2);
if (!tmp) {
if ((i += strlen(buffer2) + 1) > PATH_MAX ||
wstrlcat(buffer, "$", sizeof(buffer)) >= sizeof(buffer) ||
wstrlcat(buffer, buffer2, sizeof(buffer)) >= sizeof(buffer))
goto error;
} else {
if ((i += strlen(tmp)) > PATH_MAX ||
wstrlcat(buffer, tmp, sizeof(buffer)) >= sizeof(buffer))
goto error;
}
}
} else {
buffer[i++] = *path;
path++;
}
}
if (*path!=0)
goto error;
return wstrdup(buffer);
error:
errno = ENAMETOOLONG;
werror(_("could not expand %s"), origpath);
return NULL;
}
/* return address of next char != tok or end of string whichever comes first */
static const char *skipchar(const char *string, char tok)
{
while (*string != 0 && *string == tok)
string++;
return string;
}
/* return address of next char == tok or end of string whichever comes first */
static const char *nextchar(const char *string, char tok)
{
while (*string != 0 && *string != tok)
string++;
return string;
}
/*
*----------------------------------------------------------------------
* findfile--
* Finds a file in a : separated list of paths. ~ expansion is also
* done.
*
* Returns:
* The complete path for the file (in a newly allocated string) or
* NULL if the file was not found.
*
* Side effects:
* A new string is allocated. It must be freed later.
*
*----------------------------------------------------------------------
*/
char *wfindfile(const char *paths, const char *file)
{
char *path;
const char *tmp, *tmp2;
int len, flen;
char *fullpath;
if (!file)
return NULL;
if (*file == '/' || *file == '~' || *file == '$' || !paths || *paths == 0) {
if (access(file, F_OK) < 0) {
fullpath = wexpandpath(file);
if (!fullpath)
return NULL;
if (access(fullpath, F_OK) < 0) {
wfree(fullpath);
return NULL;
} else {
return fullpath;
}
} else {
return wstrdup(file);
}
}
flen = strlen(file);
tmp = paths;
while (*tmp) {
tmp = skipchar(tmp, ':');
if (*tmp == 0)
break;
tmp2 = nextchar(tmp, ':');
len = tmp2 - tmp;
path = wmalloc(len + flen + 2);
path = memcpy(path, tmp, len);
path[len] = 0;
if (path[len - 1] != '/' &&
wstrlcat(path, "/", len + flen + 2) >= len + flen + 2) {
wfree(path);
return NULL;
}
if (wstrlcat(path, file, len + flen + 2) >= len + flen + 2) {
wfree(path);
return NULL;
}
fullpath = wexpandpath(path);
wfree(path);
if (fullpath) {
if (access(fullpath, F_OK) == 0) {
return fullpath;
}
wfree(fullpath);
}
tmp = tmp2;
}
return NULL;
}
char *wfindfileinlist(char *const *path_list, const char *file)
{
int i;
char *path;
int len, flen;
char *fullpath;
if (!file)
return NULL;
if (*file == '/' || *file == '~' || !path_list) {
if (access(file, F_OK) < 0) {
fullpath = wexpandpath(file);
if (!fullpath)
return NULL;
if (access(fullpath, F_OK) < 0) {
wfree(fullpath);
return NULL;
} else {
return fullpath;
}
} else {
return wstrdup(file);
}
}
flen = strlen(file);
for (i = 0; path_list[i] != NULL; i++) {
len = strlen(path_list[i]);
path = wmalloc(len + flen + 2);
path = memcpy(path, path_list[i], len);
path[len] = 0;
if (wstrlcat(path, "/", len + flen + 2) >= len + flen + 2 ||
wstrlcat(path, file, len + flen + 2) >= len + flen + 2) {
wfree(path);
return NULL;
}
/* expand tilde */
fullpath = wexpandpath(path);
wfree(path);
if (fullpath) {
/* check if file exists */
if (access(fullpath, F_OK) == 0) {
return fullpath;
}
wfree(fullpath);
}
}
return NULL;
}
char *wfindfileinarray(WMPropList *array, const char *file)
{
@@ -76,8 +401,8 @@ char *wfindfileinarray(WMPropList *array, const char *file)
path = wmalloc(len + flen + 2);
path = memcpy(path, p, len);
path[len] = 0;
if (strlcat(path, "/", len + flen + 2) >= len + flen + 2 ||
strlcat(path, file, len + flen + 2) >= len + flen + 2) {
if (wstrlcat(path, "/", len + flen + 2) >= len + flen + 2 ||
wstrlcat(path, file, len + flen + 2) >= len + flen + 2) {
wfree(path);
return NULL;
}
@@ -94,3 +419,105 @@ char *wfindfileinarray(WMPropList *array, const char *file)
}
return NULL;
}
int wcopy_file(const char *dest_dir, const char *src_file, const char *dest_file)
{
char *path_dst;
int fd_src, fd_dst;
struct stat stat_src;
mode_t permission_dst;
const size_t buffer_size = 2 * 1024 * 1024; /* 4MB is a decent start choice to allow the OS to take advantage of modern disk's performance */
char *buffer; /* The buffer is not created on the stack to avoid possible stack overflow as our buffer is big */
try_again_src:
fd_src = open(src_file, O_RDONLY | O_NOFOLLOW);
if (fd_src == -1) {
if (errno == EINTR)
goto try_again_src;
werror(_("Could not open input file \"%s\": %s"), src_file, strerror(errno));
return -1;
}
/* Only accept to copy regular files */
if (fstat(fd_src, &stat_src) != 0 || !S_ISREG(stat_src.st_mode)) {
close(fd_src);
return -1;
}
path_dst = wstrconcat(dest_dir, dest_file);
try_again_dst:
fd_dst = open(path_dst, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd_dst == -1) {
if (errno == EINTR)
goto try_again_dst;
werror(_("Could not create target file \"%s\": %s"), path_dst, strerror(errno));
wfree(path_dst);
close(fd_src);
return -1;
}
buffer = malloc(buffer_size); /* Don't use wmalloc to avoid the memset(0) we don't need */
if (buffer == NULL) {
werror(_("could not allocate memory for the copy buffer"));
close(fd_dst);
goto cleanup_and_return_failure;
}
for (;;) {
ssize_t size_data;
const char *write_ptr;
size_t write_remain;
try_again_read:
size_data = read(fd_src, buffer, buffer_size);
if (size_data == 0)
break; /* End of File have been reached */
if (size_data < 0) {
if (errno == EINTR)
goto try_again_read;
werror(_("could not read from file \"%s\": %s"), src_file, strerror(errno));
close(fd_dst);
goto cleanup_and_return_failure;
}
write_ptr = buffer;
write_remain = size_data;
while (write_remain > 0) {
ssize_t write_done;
try_again_write:
write_done = write(fd_dst, write_ptr, write_remain);
if (write_done < 0) {
if (errno == EINTR)
goto try_again_write;
werror(_("could not write data to file \"%s\": %s"), path_dst, strerror(errno));
close(fd_dst);
goto cleanup_and_return_failure;
}
write_ptr += write_done;
write_remain -= write_done;
}
}
/* Keep only the permission-related part of the field: */
permission_dst = stat_src.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO | S_ISUID | S_ISGID | S_ISVTX);
if (fchmod(fd_dst, permission_dst) != 0)
wwarning(_("could not set permission 0%03o on file \"%s\": %s"),
permission_dst, path_dst, strerror(errno));
if (close(fd_dst) != 0) {
werror(_("could not close the file \"%s\": %s"), path_dst, strerror(errno));
cleanup_and_return_failure:
free(buffer);
close(fd_src);
unlink(path_dst);
wfree(path_dst);
return -1;
}
free(buffer);
wfree(path_dst);
close(fd_src);
return 0;
}

View File

@@ -126,7 +126,7 @@ WMHandlerID WMAddTimerHandler(int milliseconds, WMCallback * callback, void *cda
{
TimerHandler *handler;
handler = wmalloc(sizeof(TimerHandler));
handler = malloc(sizeof(TimerHandler));
if (!handler)
return NULL;
@@ -214,7 +214,7 @@ WMHandlerID WMAddIdleHandler(WMCallback * callback, void *cdata)
{
IdleHandler *handler;
handler = wmalloc(sizeof(IdleHandler));
handler = malloc(sizeof(IdleHandler));
if (!handler)
return NULL;
@@ -274,11 +274,12 @@ Bool W_CheckIdleHandlers(void)
WMArrayIterator iter;
if (!idleHandler || WMGetArrayItemCount(idleHandler) == 0) {
W_FlushIdleNotificationQueue();
/* make sure an observer in queue didn't added an idle handler */
return (idleHandler != NULL && WMGetArrayItemCount(idleHandler) > 0);
}
handlerCopy = WMCreateArrayWithArray(idleHandler);
handlerCopy = WMDuplicateArray(idleHandler);
WM_ITERATE_ARRAY(handlerCopy, handler, iter) {
/* check if the handler still exist or was removed by a callback */
@@ -291,6 +292,8 @@ Bool W_CheckIdleHandlers(void)
WMFreeArray(handlerCopy);
W_FlushIdleNotificationQueue();
/* this is not necesarrily False, because one handler can re-add itself */
return (WMGetArrayItemCount(idleHandler) > 0);
}
@@ -301,6 +304,7 @@ void W_CheckTimerHandlers(void)
struct timeval now;
if (!timerHandler) {
W_FlushASAPNotificationQueue();
return;
}
@@ -327,6 +331,8 @@ void W_CheckTimerHandlers(void)
wfree(handler);
}
}
W_FlushASAPNotificationQueue();
}
/*
@@ -378,6 +384,7 @@ Bool W_HandleInputEvents(Bool waitForInput, int inputfd)
nfds = 0;
if (!extrafd && nfds == 0) {
W_FlushASAPNotificationQueue();
return False;
}
@@ -422,7 +429,7 @@ Bool W_HandleInputEvents(Bool waitForInput, int inputfd)
count = poll(fds, nfds + extrafd, timeout);
if (count > 0 && nfds > 0) {
WMArray *handlerCopy = WMCreateArrayWithArray(inputHandler);
WMArray *handlerCopy = WMDuplicateArray(inputHandler);
int mask;
/* use WM_ITERATE_ARRAY() here */
@@ -454,6 +461,8 @@ Bool W_HandleInputEvents(Bool waitForInput, int inputfd)
wfree(fds);
W_FlushASAPNotificationQueue();
return (count > 0);
#else
#ifdef HAVE_SELECT
@@ -470,6 +479,7 @@ Bool W_HandleInputEvents(Bool waitForInput, int inputfd)
nfds = 0;
if (inputfd < 0 && nfds == 0) {
W_FlushASAPNotificationQueue();
return False;
}
@@ -517,7 +527,7 @@ Bool W_HandleInputEvents(Bool waitForInput, int inputfd)
count = select(1 + maxfd, &rset, &wset, &eset, timeoutPtr);
if (count > 0 && nfds > 0) {
WMArray *handlerCopy = WMCreateArrayWithArray(inputHandler);
WMArray *handlerCopy = WMDuplicateArray(inputHandler);
int mask;
/* use WM_ITERATE_ARRAY() here */
@@ -546,6 +556,8 @@ Bool W_HandleInputEvents(Bool waitForInput, int inputfd)
WMFreeArray(handlerCopy);
}
W_FlushASAPNotificationQueue();
return (count > 0);
#else /* not HAVE_SELECT, not HAVE_POLL */
# error Neither select nor poll. You lose.

422
WINGs/hashtable.c Normal file
View File

@@ -0,0 +1,422 @@
#include <config.h>
#include <sys/types.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "WUtil.h"
#define INITIAL_CAPACITY 23
typedef struct HashItem {
const void *key;
const void *data;
struct HashItem *next; /* collided item list */
} HashItem;
typedef struct W_HashTable {
WMHashTableCallbacks callbacks;
unsigned itemCount;
unsigned size; /* table size */
HashItem **table;
} HashTable;
#define HASH(table, key) (((table)->callbacks.hash ? \
(*(table)->callbacks.hash)(key) : hashPtr(key)) % (table)->size)
#define DUPKEY(table, key) ((table)->callbacks.retainKey ? \
(*(table)->callbacks.retainKey)(key) : (key))
#define RELKEY(table, key) if ((table)->callbacks.releaseKey) \
(*(table)->callbacks.releaseKey)(key)
static inline unsigned hashString(const void *param)
{
const char *key = param;
unsigned ret = 0;
unsigned ctr = 0;
while (*key) {
ret ^= *key++ << ctr;
ctr = (ctr + 1) % sizeof(char *);
}
return ret;
}
static inline unsigned hashPtr(const void *key)
{
return ((size_t) key / sizeof(char *));
}
static void rellocateItem(WMHashTable * table, HashItem * item)
{
unsigned h;
h = HASH(table, item->key);
item->next = table->table[h];
table->table[h] = item;
}
static void rebuildTable(WMHashTable * table)
{
HashItem *next;
HashItem **oldArray;
int i;
int oldSize;
int newSize;
oldArray = table->table;
oldSize = table->size;
newSize = table->size * 2;
table->table = wmalloc(sizeof(char *) * newSize);
table->size = newSize;
for (i = 0; i < oldSize; i++) {
while (oldArray[i] != NULL) {
next = oldArray[i]->next;
rellocateItem(table, oldArray[i]);
oldArray[i] = next;
}
}
wfree(oldArray);
}
WMHashTable *WMCreateHashTable(const WMHashTableCallbacks callbacks)
{
HashTable *table;
table = wmalloc(sizeof(HashTable));
table->callbacks = callbacks;
table->size = INITIAL_CAPACITY;
table->table = wmalloc(sizeof(HashItem *) * table->size);
return table;
}
void WMResetHashTable(WMHashTable * table)
{
HashItem *item, *tmp;
int i;
for (i = 0; i < table->size; i++) {
item = table->table[i];
while (item) {
tmp = item->next;
RELKEY(table, item->key);
wfree(item);
item = tmp;
}
}
table->itemCount = 0;
if (table->size > INITIAL_CAPACITY) {
wfree(table->table);
table->size = INITIAL_CAPACITY;
table->table = wmalloc(sizeof(HashItem *) * table->size);
} else {
memset(table->table, 0, sizeof(HashItem *) * table->size);
}
}
void WMFreeHashTable(WMHashTable * table)
{
HashItem *item, *tmp;
int i;
for (i = 0; i < table->size; i++) {
item = table->table[i];
while (item) {
tmp = item->next;
RELKEY(table, item->key);
wfree(item);
item = tmp;
}
}
wfree(table->table);
wfree(table);
}
unsigned WMCountHashTable(WMHashTable * table)
{
return table->itemCount;
}
static HashItem *hashGetItem(WMHashTable *table, const void *key)
{
unsigned h;
HashItem *item;
h = HASH(table, key);
item = table->table[h];
if (table->callbacks.keyIsEqual) {
while (item) {
if ((*table->callbacks.keyIsEqual) (key, item->key)) {
break;
}
item = item->next;
}
} else {
while (item) {
if (key == item->key) {
break;
}
item = item->next;
}
}
return item;
}
void *WMHashGet(WMHashTable * table, const void *key)
{
HashItem *item;
item = hashGetItem(table, key);
if (!item)
return NULL;
return (void *)item->data;
}
Bool WMHashGetItemAndKey(WMHashTable * table, const void *key, void **retItem, void **retKey)
{
HashItem *item;
item = hashGetItem(table, key);
if (!item)
return False;
if (retKey)
*retKey = (void *)item->key;
if (retItem)
*retItem = (void *)item->data;
return True;
}
void *WMHashInsert(WMHashTable * table, const void *key, const void *data)
{
unsigned h;
HashItem *item;
int replacing = 0;
h = HASH(table, key);
/* look for the entry */
item = table->table[h];
if (table->callbacks.keyIsEqual) {
while (item) {
if ((*table->callbacks.keyIsEqual) (key, item->key)) {
replacing = 1;
break;
}
item = item->next;
}
} else {
while (item) {
if (key == item->key) {
replacing = 1;
break;
}
item = item->next;
}
}
if (replacing) {
const void *old;
old = item->data;
item->data = data;
RELKEY(table, item->key);
item->key = DUPKEY(table, key);
return (void *)old;
} else {
HashItem *nitem;
nitem = wmalloc(sizeof(HashItem));
nitem->key = DUPKEY(table, key);
nitem->data = data;
nitem->next = table->table[h];
table->table[h] = nitem;
table->itemCount++;
}
/* OPTIMIZE: put this in an idle handler. */
if (table->itemCount > table->size) {
#ifdef DEBUG0
printf("rebuilding hash table...\n");
#endif
rebuildTable(table);
#ifdef DEBUG0
printf("finished rebuild.\n");
#endif
}
return NULL;
}
static HashItem *deleteFromList(HashTable * table, HashItem * item, const void *key)
{
HashItem *next;
if (item == NULL)
return NULL;
if ((table->callbacks.keyIsEqual && (*table->callbacks.keyIsEqual) (key, item->key))
|| (!table->callbacks.keyIsEqual && key == item->key)) {
next = item->next;
RELKEY(table, item->key);
wfree(item);
table->itemCount--;
return next;
}
item->next = deleteFromList(table, item->next, key);
return item;
}
void WMHashRemove(WMHashTable * table, const void *key)
{
unsigned h;
h = HASH(table, key);
table->table[h] = deleteFromList(table, table->table[h], key);
}
WMHashEnumerator WMEnumerateHashTable(WMHashTable * table)
{
WMHashEnumerator enumerator;
enumerator.table = table;
enumerator.index = 0;
enumerator.nextItem = table->table[0];
return enumerator;
}
void *WMNextHashEnumeratorItem(WMHashEnumerator * enumerator)
{
const void *data = NULL;
/* this assumes the table doesn't change between
* WMEnumerateHashTable() and WMNextHashEnumeratorItem() calls */
if (enumerator->nextItem == NULL) {
HashTable *table = enumerator->table;
while (++enumerator->index < table->size) {
if (table->table[enumerator->index] != NULL) {
enumerator->nextItem = table->table[enumerator->index];
break;
}
}
}
if (enumerator->nextItem) {
data = ((HashItem *) enumerator->nextItem)->data;
enumerator->nextItem = ((HashItem *) enumerator->nextItem)->next;
}
return (void *)data;
}
void *WMNextHashEnumeratorKey(WMHashEnumerator * enumerator)
{
const void *key = NULL;
/* this assumes the table doesn't change between
* WMEnumerateHashTable() and WMNextHashEnumeratorKey() calls */
if (enumerator->nextItem == NULL) {
HashTable *table = enumerator->table;
while (++enumerator->index < table->size) {
if (table->table[enumerator->index] != NULL) {
enumerator->nextItem = table->table[enumerator->index];
break;
}
}
}
if (enumerator->nextItem) {
key = ((HashItem *) enumerator->nextItem)->key;
enumerator->nextItem = ((HashItem *) enumerator->nextItem)->next;
}
return (void *)key;
}
Bool WMNextHashEnumeratorItemAndKey(WMHashEnumerator * enumerator, void **item, void **key)
{
/* this assumes the table doesn't change between
* WMEnumerateHashTable() and WMNextHashEnumeratorItemAndKey() calls */
if (enumerator->nextItem == NULL) {
HashTable *table = enumerator->table;
while (++enumerator->index < table->size) {
if (table->table[enumerator->index] != NULL) {
enumerator->nextItem = table->table[enumerator->index];
break;
}
}
}
if (enumerator->nextItem) {
if (item)
*item = (void *)((HashItem *) enumerator->nextItem)->data;
if (key)
*key = (void *)((HashItem *) enumerator->nextItem)->key;
enumerator->nextItem = ((HashItem *) enumerator->nextItem)->next;
return True;
}
return False;
}
static Bool compareStrings(const void *param1, const void *param2)
{
const char *key1 = param1;
const char *key2 = param2;
return strcmp(key1, key2) == 0;
}
typedef void *(*retainFunc) (const void *);
typedef void (*releaseFunc) (const void *);
const WMHashTableCallbacks WMIntHashCallbacks = {
NULL,
NULL,
NULL,
NULL
};
const WMHashTableCallbacks WMStringHashCallbacks = {
hashString,
compareStrings,
(retainFunc) wstrdup,
(releaseFunc) wfree
};
const WMHashTableCallbacks WMStringPointerHashCallbacks = {
hashString,
compareStrings,
NULL,
NULL
};

223
WINGs/memory.c Normal file
View File

@@ -0,0 +1,223 @@
/*
* Window Maker miscelaneous function library
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "wconfig.h"
#include "WUtil.h"
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <signal.h>
#ifdef HAVE_STDNORETURN
#include <stdnoreturn.h>
#endif
#ifdef USE_BOEHM_GC
#ifndef GC_DEBUG
#define GC_DEBUG
#endif /* !GC_DEBUG */
#include <gc/gc.h>
#endif /* USE_BOEHM_GC */
#ifndef False
# define False 0
#endif
#ifndef True
# define True 1
#endif
static void defaultHandler(int bla)
{
if (bla)
kill(getpid(), SIGABRT);
else
exit(1);
}
static waborthandler *aborthandler = defaultHandler;
static inline noreturn void wAbort(int bla)
{
(*aborthandler)(bla);
exit(-1);
}
waborthandler *wsetabort(waborthandler * handler)
{
waborthandler *old = aborthandler;
aborthandler = handler;
return old;
}
static int Aborting = 0; /* if we're in the middle of an emergency exit */
static WMHashTable *table = NULL;
void *wmalloc(size_t size)
{
void *tmp;
assert(size > 0);
#ifdef USE_BOEHM_GC
tmp = GC_MALLOC(size);
#else
tmp = malloc(size);
#endif
if (tmp == NULL) {
wwarning("malloc() failed. Retrying after 2s.");
sleep(2);
#ifdef USE_BOEHM_GC
tmp = GC_MALLOC(size);
#else
tmp = malloc(size);
#endif
if (tmp == NULL) {
if (Aborting) {
fputs("Really Bad Error: recursive malloc() failure.", stderr);
exit(-1);
} else {
wfatal("virtual memory exhausted");
Aborting = 1;
wAbort(False);
}
}
}
if (tmp != NULL)
memset(tmp, 0, size);
return tmp;
}
void *wrealloc(void *ptr, size_t newsize)
{
void *nptr;
if (!ptr) {
nptr = wmalloc(newsize);
} else if (newsize == 0) {
wfree(ptr);
nptr = NULL;
} else {
#ifdef USE_BOEHM_GC
nptr = GC_REALLOC(ptr, newsize);
#else
nptr = realloc(ptr, newsize);
#endif
if (nptr == NULL) {
wwarning("realloc() failed. Retrying after 2s.");
sleep(2);
#ifdef USE_BOEHM_GC
nptr = GC_REALLOC(ptr, newsize);
#else
nptr = realloc(ptr, newsize);
#endif
if (nptr == NULL) {
if (Aborting) {
fputs("Really Bad Error: recursive realloc() failure.", stderr);
exit(-1);
} else {
wfatal("virtual memory exhausted");
Aborting = 1;
wAbort(False);
}
}
}
}
return nptr;
}
void *wretain(void *ptr)
{
int *refcount;
if (!table) {
table = WMCreateHashTable(WMIntHashCallbacks);
}
refcount = WMHashGet(table, ptr);
if (!refcount) {
refcount = wmalloc(sizeof(int));
*refcount = 1;
WMHashInsert(table, ptr, refcount);
#ifdef VERBOSE
printf("== %i (%p)\n", *refcount, ptr);
#endif
} else {
(*refcount)++;
#ifdef VERBOSE
printf("+ %i (%p)\n", *refcount, ptr);
#endif
}
return ptr;
}
void wfree(void *ptr)
{
if (ptr)
#ifdef USE_BOEHM_GC
/* This should eventually be removed, once the criss-cross
* of wmalloc()d memory being free()d, malloc()d memory being
* wfree()d, various misuses of calling wfree() on objects
* allocated by libc malloc() and calling libc free() on
* objects allocated by Boehm GC (think external libraries)
* is cleaned up.
*/
if (GC_base(ptr) != 0)
GC_FREE(ptr);
else
free(ptr);
#else
free(ptr);
#endif
ptr = NULL;
}
void wrelease(void *ptr)
{
int *refcount;
refcount = WMHashGet(table, ptr);
if (!refcount) {
wwarning("trying to release unexisting data %p", ptr);
} else {
(*refcount)--;
if (*refcount < 1) {
#ifdef VERBOSE
printf("RELEASING %p\n", ptr);
#endif
WMHashRemove(table, ptr);
wfree(refcount);
wfree(ptr);
}
#ifdef VERBOSE
else {
printf("- %i (%p)\n", *refcount, ptr);
}
#endif
}
}

View File

@@ -536,14 +536,12 @@ found_end_define_fname:
while (*src != '\0') {
idx = 0;
if (*src == '~') {
char *home_head = wgethomedir();
char *home = home_head;;
const char *home = wgethomedir();
while (*home != '\0') {
if (idx < sizeof(buffer) - 2)
buffer[idx++] = *home;
home++;
}
wfree(home_head);
src++;
}

View File

@@ -652,7 +652,7 @@ static void mpm_get_hostname(WParserMacro *this, WMenuParser parser)
return;
}
}
strlcpy((char *) this->value, h, sizeof(this->value) );
wstrlcpy((char *) this->value, h, sizeof(this->value) );
}
/* Name of the current user */
@@ -677,7 +677,7 @@ static void mpm_get_user_name(WParserMacro *this, WMenuParser parser)
user = pw_user->pw_name;
if (user == NULL) goto error_no_username;
}
strlcpy((char *) this->value, user, sizeof(this->value) );
wstrlcpy((char *) this->value, user, sizeof(this->value) );
}
/* Number id of the user under which we are running */

482
WINGs/notification.c Normal file
View File

@@ -0,0 +1,482 @@
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "WUtil.h"
#include "WINGsP.h"
typedef struct W_Notification {
const char *name;
void *object;
void *clientData;
int refCount;
} Notification;
const char *WMGetNotificationName(WMNotification * notification)
{
return notification->name;
}
void *WMGetNotificationObject(WMNotification * notification)
{
return notification->object;
}
void *WMGetNotificationClientData(WMNotification * notification)
{
return notification->clientData;
}
WMNotification *WMCreateNotification(const char *name, void *object, void *clientData)
{
Notification *nPtr;
nPtr = wmalloc(sizeof(Notification));
nPtr->name = name;
nPtr->object = object;
nPtr->clientData = clientData;
nPtr->refCount = 1;
return nPtr;
}
void WMReleaseNotification(WMNotification * notification)
{
notification->refCount--;
if (notification->refCount < 1) {
wfree(notification);
}
}
WMNotification *WMRetainNotification(WMNotification * notification)
{
notification->refCount++;
return notification;
}
/***************** Notification Center *****************/
typedef struct NotificationObserver {
WMNotificationObserverAction *observerAction;
void *observer;
const char *name;
void *object;
struct NotificationObserver *prev; /* for tables */
struct NotificationObserver *next;
struct NotificationObserver *nextAction; /* for observerTable */
} NotificationObserver;
typedef struct W_NotificationCenter {
WMHashTable *nameTable; /* names -> observer lists */
WMHashTable *objectTable; /* object -> observer lists */
NotificationObserver *nilList; /* obervers that catch everything */
WMHashTable *observerTable; /* observer -> NotificationObserver */
} NotificationCenter;
/* default (and only) center */
static NotificationCenter *notificationCenter = NULL;
void W_InitNotificationCenter(void)
{
notificationCenter = wmalloc(sizeof(NotificationCenter));
notificationCenter->nameTable = WMCreateHashTable(WMStringPointerHashCallbacks);
notificationCenter->objectTable = WMCreateHashTable(WMIntHashCallbacks);
notificationCenter->nilList = NULL;
notificationCenter->observerTable = WMCreateHashTable(WMIntHashCallbacks);
}
void W_ReleaseNotificationCenter(void)
{
if (notificationCenter) {
if (notificationCenter->nameTable)
WMFreeHashTable(notificationCenter->nameTable);
if (notificationCenter->objectTable)
WMFreeHashTable(notificationCenter->objectTable);
if (notificationCenter->observerTable)
WMFreeHashTable(notificationCenter->observerTable);
wfree(notificationCenter);
notificationCenter = NULL;
}
}
void
WMAddNotificationObserver(WMNotificationObserverAction * observerAction,
void *observer, const char *name, void *object)
{
NotificationObserver *oRec, *rec;
oRec = wmalloc(sizeof(NotificationObserver));
oRec->observerAction = observerAction;
oRec->observer = observer;
oRec->name = name;
oRec->object = object;
oRec->next = NULL;
oRec->prev = NULL;
/* put this action in the list of actions for this observer */
rec = (NotificationObserver *) WMHashInsert(notificationCenter->observerTable, observer, oRec);
if (rec) {
/* if this is not the first action for the observer */
oRec->nextAction = rec;
} else {
oRec->nextAction = NULL;
}
if (!name && !object) {
/* catch-all */
oRec->next = notificationCenter->nilList;
if (notificationCenter->nilList) {
notificationCenter->nilList->prev = oRec;
}
notificationCenter->nilList = oRec;
} else if (!name) {
/* any message coming from object */
rec = (NotificationObserver *) WMHashInsert(notificationCenter->objectTable, object, oRec);
oRec->next = rec;
if (rec) {
rec->prev = oRec;
}
} else {
/* name && (object || !object) */
rec = (NotificationObserver *) WMHashInsert(notificationCenter->nameTable, name, oRec);
oRec->next = rec;
if (rec) {
rec->prev = oRec;
}
}
}
void WMPostNotification(WMNotification * notification)
{
NotificationObserver *orec, *tmp;
WMRetainNotification(notification);
/* tell the observers that want to know about a particular message */
orec = (NotificationObserver *) WMHashGet(notificationCenter->nameTable, notification->name);
while (orec) {
tmp = orec->next;
if (!orec->object || !notification->object || orec->object == notification->object) {
/* tell the observer */
if (orec->observerAction) {
(*orec->observerAction) (orec->observer, notification);
}
}
orec = tmp;
}
/* tell the observers that want to know about an object */
orec = (NotificationObserver *) WMHashGet(notificationCenter->objectTable, notification->object);
while (orec) {
tmp = orec->next;
/* tell the observer */
if (orec->observerAction) {
(*orec->observerAction) (orec->observer, notification);
}
orec = tmp;
}
/* tell the catch all observers */
orec = notificationCenter->nilList;
while (orec) {
tmp = orec->next;
/* tell the observer */
if (orec->observerAction) {
(*orec->observerAction) (orec->observer, notification);
}
orec = tmp;
}
WMReleaseNotification(notification);
}
void WMRemoveNotificationObserver(void *observer)
{
NotificationObserver *orec, *tmp, *rec;
/* get the list of actions the observer is doing */
orec = (NotificationObserver *) WMHashGet(notificationCenter->observerTable, observer);
/*
* FOREACH orec IN actionlist for observer
* DO
* remove from respective lists/tables
* free
* END
*/
while (orec) {
tmp = orec->nextAction;
if (!orec->name && !orec->object) {
/* catch-all */
if (notificationCenter->nilList == orec)
notificationCenter->nilList = orec->next;
} else if (!orec->name) {
/* any message coming from object */
rec = (NotificationObserver *) WMHashGet(notificationCenter->objectTable, orec->object);
if (rec == orec) {
/* replace table entry */
if (orec->next) {
WMHashInsert(notificationCenter->objectTable, orec->object, orec->next);
} else {
WMHashRemove(notificationCenter->objectTable, orec->object);
}
}
} else {
/* name && (object || !object) */
rec = (NotificationObserver *) WMHashGet(notificationCenter->nameTable, orec->name);
if (rec == orec) {
/* replace table entry */
if (orec->next) {
WMHashInsert(notificationCenter->nameTable, orec->name, orec->next);
} else {
WMHashRemove(notificationCenter->nameTable, orec->name);
}
}
}
if (orec->prev)
orec->prev->next = orec->next;
if (orec->next)
orec->next->prev = orec->prev;
wfree(orec);
orec = tmp;
}
WMHashRemove(notificationCenter->observerTable, observer);
}
void WMRemoveNotificationObserverWithName(void *observer, const char *name, void *object)
{
NotificationObserver *orec, *tmp, *rec;
NotificationObserver *newList = NULL;
/* get the list of actions the observer is doing */
orec = (NotificationObserver *) WMHashGet(notificationCenter->observerTable, observer);
WMHashRemove(notificationCenter->observerTable, observer);
/* rebuild the list of actions for the observer */
while (orec) {
tmp = orec->nextAction;
if (orec->name == name && orec->object == object) {
if (!name && !object) {
if (notificationCenter->nilList == orec)
notificationCenter->nilList = orec->next;
} else if (!name) {
rec =
(NotificationObserver *) WMHashGet(notificationCenter->objectTable,
orec->object);
if (rec == orec) {
assert(rec->prev == NULL);
/* replace table entry */
if (orec->next) {
WMHashInsert(notificationCenter->objectTable,
orec->object, orec->next);
} else {
WMHashRemove(notificationCenter->objectTable, orec->object);
}
}
} else {
rec = (NotificationObserver *) WMHashGet(notificationCenter->nameTable,
orec->name);
if (rec == orec) {
assert(rec->prev == NULL);
/* replace table entry */
if (orec->next) {
WMHashInsert(notificationCenter->nameTable,
orec->name, orec->next);
} else {
WMHashRemove(notificationCenter->nameTable, orec->name);
}
}
}
if (orec->prev)
orec->prev->next = orec->next;
if (orec->next)
orec->next->prev = orec->prev;
wfree(orec);
} else {
/* append this action in the new action list */
orec->nextAction = NULL;
if (!newList) {
newList = orec;
} else {
NotificationObserver *p;
p = newList;
while (p->nextAction) {
p = p->nextAction;
}
p->nextAction = orec;
}
}
orec = tmp;
}
/* reinsert the list to the table */
if (newList) {
WMHashInsert(notificationCenter->observerTable, observer, newList);
}
}
void WMPostNotificationName(const char *name, void *object, void *clientData)
{
WMNotification *notification;
notification = WMCreateNotification(name, object, clientData);
WMPostNotification(notification);
WMReleaseNotification(notification);
}
/**************** Notification Queues ****************/
typedef struct W_NotificationQueue {
WMArray *asapQueue;
WMArray *idleQueue;
struct W_NotificationQueue *next;
} NotificationQueue;
static WMNotificationQueue *notificationQueueList = NULL;
/* default queue */
static WMNotificationQueue *notificationQueue = NULL;
WMNotificationQueue *WMGetDefaultNotificationQueue(void)
{
if (!notificationQueue)
notificationQueue = WMCreateNotificationQueue();
return notificationQueue;
}
WMNotificationQueue *WMCreateNotificationQueue(void)
{
NotificationQueue *queue;
queue = wmalloc(sizeof(NotificationQueue));
queue->asapQueue = WMCreateArrayWithDestructor(8, (WMFreeDataProc *) WMReleaseNotification);
queue->idleQueue = WMCreateArrayWithDestructor(8, (WMFreeDataProc *) WMReleaseNotification);
queue->next = notificationQueueList;
notificationQueueList = queue;
return queue;
}
void WMEnqueueNotification(WMNotificationQueue * queue, WMNotification * notification, WMPostingStyle postingStyle)
{
WMEnqueueCoalesceNotification(queue, notification, postingStyle, WNCOnName | WNCOnSender);
}
#define NOTIF ((WMNotification*)cdata)
#define ITEM ((WMNotification*)item)
static int matchSenderAndName(const void *item, const void *cdata)
{
return (NOTIF->object == ITEM->object && strcmp(NOTIF->name, ITEM->name) == 0);
}
static int matchSender(const void *item, const void *cdata)
{
return (NOTIF->object == ITEM->object);
}
static int matchName(const void *item, const void *cdata)
{
return (strcmp(NOTIF->name, ITEM->name) == 0);
}
#undef NOTIF
#undef ITEM
void WMDequeueNotificationMatching(WMNotificationQueue * queue, WMNotification * notification, unsigned mask)
{
WMMatchDataProc *matchFunc;
if ((mask & WNCOnName) && (mask & WNCOnSender))
matchFunc = matchSenderAndName;
else if (mask & WNCOnName)
matchFunc = matchName;
else if (mask & WNCOnSender)
matchFunc = matchSender;
else
return;
WMRemoveFromArrayMatching(queue->asapQueue, matchFunc, notification);
WMRemoveFromArrayMatching(queue->idleQueue, matchFunc, notification);
}
void
WMEnqueueCoalesceNotification(WMNotificationQueue * queue,
WMNotification * notification, WMPostingStyle postingStyle, unsigned coalesceMask)
{
if (coalesceMask != WNCNone)
WMDequeueNotificationMatching(queue, notification, coalesceMask);
switch (postingStyle) {
case WMPostNow:
WMPostNotification(notification);
WMReleaseNotification(notification);
break;
case WMPostASAP:
WMAddToArray(queue->asapQueue, notification);
break;
case WMPostWhenIdle:
WMAddToArray(queue->idleQueue, notification);
break;
}
}
void W_FlushASAPNotificationQueue(void)
{
WMNotificationQueue *queue = notificationQueueList;
while (queue) {
while (WMGetArrayItemCount(queue->asapQueue)) {
WMPostNotification(WMGetFromArray(queue->asapQueue, 0));
WMDeleteFromArray(queue->asapQueue, 0);
}
queue = queue->next;
}
}
void W_FlushIdleNotificationQueue(void)
{
WMNotificationQueue *queue = notificationQueueList;
while (queue) {
while (WMGetArrayItemCount(queue->idleQueue)) {
WMPostNotification(WMGetFromArray(queue->idleQueue, 0));
WMDeleteFromArray(queue->idleQueue, 0);
}
queue = queue->next;
}
}

View File

@@ -9,7 +9,6 @@ msgstr ""
"PO-Revision-Date: 2003-02-09 12:10+0200\n"
"Last-Translator: Anton Zinoviev <zinoviev@debian.org>\n"
"Language-Team: Bulgarian <dict@linux.zonebg.com>\n"
"Language: bg\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@@ -14,7 +14,6 @@ msgstr ""
"PO-Revision-Date: 2003-09-16 23:16+0200\n"
"Last-Translator: Ernest Adrogué <eadrogue@gmx.net>\n"
"Language-Team: Catalan <ca@dodds.net>\n"
"Language: ca\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@@ -12,7 +12,6 @@ msgstr ""
"PO-Revision-Date: 2001-10-11 22:00+0100\n"
"Last-Translator: Jiří Hnídek <jiri.hnidek@vslib.cz>\n"
"Language-Team: Czech <cz@li.org>\n"
"Language: cs\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: unknown\n"

View File

@@ -15,7 +15,6 @@ msgstr ""
"PO-Revision-Date: 2004-11-05 23:48+0100\n"
"Last-Translator: shlomme@gmx.net\n"
"Language-Team: German\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@@ -10,7 +10,6 @@ msgstr ""
"PO-Revision-Date: 2002-01-09 21:20+0100\n"
"Last-Translator: Emmanuel Benoit <tseeker@neptune.fr>\n"
"Language-Team: Français <fr@li.org>\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: unknown\n"

View File

@@ -11,7 +11,7 @@ msgstr ""
"PO-Revision-Date: 2014-02-18 00:25+0100\n"
"Last-Translator: BALATON Zoltán <balaton@eik.bme.hu>\n"
"Language-Team: Hungarian\n"
"Language: hu\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@@ -843,6 +843,9 @@ msgstr "Kon invoerbestand \"%s\" niet openen"
msgid "Could not create target file \"%s\""
msgstr "Kon doelbestand \"%s\" niet aanmaken"
msgid "An error occured browsing '%s'."
msgstr "Er trad 'n fout op bij bladeren door '%s'."
msgid ""
"invalid characted '%c' in arg-list for macro \"%s\" while expecting "
"parameter name"
@@ -857,6 +860,9 @@ msgstr ""
"ongeldig letterteken '%c' in arg.-lijst voor macro \"%s\", verwachtte ',' "
"of ')'"
msgid "unknow directive '#%s'"
msgstr "onbekende aanwijzing '#%s'"
msgid "found #%s but have no matching #if"
msgstr "#%s gevonden, maar heeft geen bijbehorende #if"

View File

@@ -19,7 +19,6 @@ msgstr ""
"PO-Revision-Date: 2001-12-20 04:00+0100\n"
"Last-Translator: Jan \"judas\" Tomka <judas@linux.sk>\n"
"Language-Team: Slovak <sk@li.org>\n"
"Language: sk\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

File diff suppressed because it is too large Load Diff

View File

@@ -237,7 +237,7 @@ static void handleRequestEvent(XEvent * event)
}
/* delete handlers */
copy = WMCreateArrayWithArray(selHandlers);
copy = WMDuplicateArray(selHandlers);
WM_ITERATE_ARRAY(copy, handler, iter) {
if (handler && handler->flags.delete_pending) {
WMDeleteSelectionHandler(handler->view, handler->selection, handler->timestamp);
@@ -261,9 +261,8 @@ static WMData *getSelectionData(Display * dpy, Window win, Atom where)
bpi = bits / 8;
wdata = WMCreateDataWithBytes(data, len * bpi);
wdata = WMCreateDataWithBytesNoCopy(data, len * bpi, (void *) XFree);
WMSetDataFormat(wdata, bits);
XFree(data);
return wdata;
}
@@ -301,7 +300,7 @@ static void handleNotifyEvent(XEvent * event)
}
/* delete callbacks */
copy = WMCreateArrayWithArray(selCallbacks);
copy = WMDuplicateArray(selCallbacks);
WM_ITERATE_ARRAY(copy, handler, iter) {
if (handler && handler->flags.delete_pending) {
WMDeleteSelectionCallback(handler->view, handler->selection, handler->timestamp);

425
WINGs/string.c Normal file
View File

@@ -0,0 +1,425 @@
/*
* Until FreeBSD gets their act together;
* http://www.mail-archive.com/freebsd-hackers@freebsd.org/msg69469.html
*/
#if defined( FREEBSD )
# undef _XOPEN_SOURCE
#endif
#include "wconfig.h"
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <ctype.h>
#ifdef HAVE_BSD_STRING_H
#include <bsd/string.h>
#endif
#include "WUtil.h"
#define PRC_ALPHA 0
#define PRC_BLANK 1
#define PRC_ESCAPE 2
#define PRC_DQUOTE 3
#define PRC_EOS 4
#define PRC_SQUOTE 5
typedef struct {
short nstate;
short output;
} DFA;
static DFA mtable[9][6] = {
{{3, 1}, {0, 0}, {4, 0}, {1, 0}, {8, 0}, {6, 0}},
{{1, 1}, {1, 1}, {2, 0}, {3, 0}, {5, 0}, {1, 1}},
{{1, 1}, {1, 1}, {1, 1}, {1, 1}, {5, 0}, {1, 1}},
{{3, 1}, {5, 0}, {4, 0}, {1, 0}, {5, 0}, {6, 0}},
{{3, 1}, {3, 1}, {3, 1}, {3, 1}, {5, 0}, {3, 1}},
{{-1, -1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* final state */
{{6, 1}, {6, 1}, {7, 0}, {6, 1}, {5, 0}, {3, 0}},
{{6, 1}, {6, 1}, {6, 1}, {6, 1}, {5, 0}, {6, 1}},
{{-1, -1}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}}, /* final state */
};
char *wtokennext(char *word, char **next)
{
char *ptr;
char *ret, *t;
int state, ctype;
t = ret = wmalloc(strlen(word) + 1);
ptr = word;
state = 0;
while (1) {
if (*ptr == 0)
ctype = PRC_EOS;
else if (*ptr == '\\')
ctype = PRC_ESCAPE;
else if (*ptr == '"')
ctype = PRC_DQUOTE;
else if (*ptr == '\'')
ctype = PRC_SQUOTE;
else if (*ptr == ' ' || *ptr == '\t')
ctype = PRC_BLANK;
else
ctype = PRC_ALPHA;
if (mtable[state][ctype].output) {
*t = *ptr;
t++;
*t = 0;
}
state = mtable[state][ctype].nstate;
ptr++;
if (mtable[state][0].output < 0) {
break;
}
}
if (*ret == 0) {
wfree(ret);
ret = NULL;
}
if (ctype == PRC_EOS)
*next = NULL;
else
*next = ptr;
return ret;
}
/* separate a string in tokens, taking " and ' into account */
void wtokensplit(char *command, char ***argv, int *argc)
{
char *token, *line;
int count;
count = 0;
line = command;
do {
token = wtokennext(line, &line);
if (token) {
if (count == 0)
*argv = wmalloc(sizeof(**argv));
else
*argv = wrealloc(*argv, (count + 1) * sizeof(**argv));
(*argv)[count++] = token;
}
} while (token != NULL && line != NULL);
*argc = count;
}
char *wtokenjoin(char **list, int count)
{
int i, j;
char *flat_string, *wspace;
j = 0;
for (i = 0; i < count; i++) {
if (list[i] != NULL && list[i][0] != 0) {
j += strlen(list[i]);
if (strpbrk(list[i], " \t"))
j += 2;
}
}
flat_string = wmalloc(j + count + 1);
for (i = 0; i < count; i++) {
if (list[i] != NULL && list[i][0] != 0) {
if (i > 0 &&
wstrlcat(flat_string, " ", j + count + 1) >= j + count + 1)
goto error;
wspace = strpbrk(list[i], " \t");
if (wspace &&
wstrlcat(flat_string, "\"", j + count + 1) >= j + count + 1)
goto error;
if (wstrlcat(flat_string, list[i], j + count + 1) >= j + count + 1)
goto error;
if (wspace &&
wstrlcat(flat_string, "\"", j + count + 1) >= j + count + 1)
goto error;
}
}
return flat_string;
error:
wfree(flat_string);
return NULL;
}
void wtokenfree(char **tokens, int count)
{
while (count--)
wfree(tokens[count]);
wfree(tokens);
}
char *wtrimspace(const char *s)
{
const char *t;
if (s == NULL)
return NULL;
while (isspace(*s) && *s)
s++;
t = s + strlen(s) - 1;
while (t > s && isspace(*t))
t--;
return wstrndup(s, t - s + 1);
}
char *wstrdup(const char *str)
{
assert(str != NULL);
return strcpy(wmalloc(strlen(str) + 1), str);
}
char *wstrndup(const char *str, size_t len)
{
char *copy;
assert(str != NULL);
len = WMIN(len, strlen(str));
copy = strncpy(wmalloc(len + 1), str, len);
copy[len] = 0;
return copy;
}
char *wstrconcat(const char *str1, const char *str2)
{
char *str;
size_t slen, slen1;
if (!str1 && str2)
return wstrdup(str2);
else if (str1 && !str2)
return wstrdup(str1);
else if (!str1 && !str2)
return NULL;
slen1 = strlen(str1);
slen = slen1 + strlen(str2) + 1;
str = wmalloc(slen);
strcpy(str, str1);
strcpy(str + slen1, str2);
return str;
}
char *wstrappend(char *dst, const char *src)
{
size_t slen;
if (!src || *src == 0)
return dst;
else if (!dst)
return wstrdup(src);
slen = strlen(dst) + strlen(src) + 1;
dst = wrealloc(dst, slen);
strcat(dst, src);
return dst;
}
#ifdef HAVE_STRLCAT
size_t
wstrlcat(char *dst, const char *src, size_t siz)
{
return strlcat(dst, src, siz);
}
#else
/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
* If retval >= siz, truncation occurred.
*/
size_t
wstrlcat(char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;
size_t n = siz;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0')
d++;
dlen = d - dst;
n = siz - dlen;
if (n == 0)
return(dlen + strlen(s));
while (*s != '\0') {
if (n != 1) {
*d++ = *s;
n--;
}
s++;
}
*d = '\0';
return(dlen + (s - src)); /* count does not include NUL */
}
#endif /* HAVE_STRLCAT */
#ifdef HAVE_STRLCPY
size_t
wstrlcpy(char *dst, const char *src, size_t siz)
{
return strlcpy(dst, src, siz);
}
#else
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t
wstrlcpy(char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;
size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0) {
while (--n != 0) {
if ((*d++ = *s++) == '\0')
break;
}
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return(s - src - 1); /* count does not include NUL */
}
#endif /* HAVE_STRLCPY */
/* transform `s' so that the result is safe to pass to the shell as an argument.
* returns a newly allocated string.
* with very heavy inspirations from NetBSD's shquote(3).
*/
char *wshellquote(const char *s)
{
char *p, *r, *last, *ret;
size_t slen;
int needs_quoting;
if (!s)
return NULL;
needs_quoting = !*s; /* the empty string does need quoting */
/* do not quote if consists only of the following characters */
for (p = (char *)s; *p && !needs_quoting; p++) {
needs_quoting = !(isalnum(*p) || (*p == '+') || (*p == '/') ||
(*p == '.') || (*p == ',') || (*p == '-'));
}
if (!needs_quoting)
return wstrdup(s);
for (slen = 0, p = (char *)s; *p; p++) /* count space needed (worst case) */
slen += *p == '\'' ? 4 : 1; /* every single ' becomes ''\' */
slen += 2 /* leading + trailing "'" */ + 1 /* NULL */;
ret = r = wmalloc(slen);
p = (char *)s;
last = p;
if (*p != '\'') /* if string doesn't already begin with "'" */
*r++ ='\''; /* start putting it in quotes */
while (*p) {
last = p;
if (*p == '\'') { /* turn each ' into ''\' */
if (p != s) /* except if it's the first ', in which case */
*r++ = '\''; /* only escape it */
*r++ = '\\';
*r++ = '\'';
while (*++p && *p == '\'') { /* keep turning each consecutive 's into \' */
*r++ = '\\';
*r++ = '\'';
}
if (*p) /* if more input follows, terminate */
*r++ = '\''; /* what we have so far */
} else {
*r++ = *p++;
}
}
if (*last != '\'') /* if the last one isn't already a ' */
*r++ = '\''; /* terminate the whole shebang */
*r = '\0';
return ret; /* technically, we lose (but not leak) a couple of */
/* bytes (twice the number of consecutive 's in the */
/* input or so), but since these are relatively rare */
/* and short-lived strings, not sure if a trip to */
/* wstrdup+wfree worths the gain. */
}

255
WINGs/tree.c Normal file
View File

@@ -0,0 +1,255 @@
#include <string.h>
#include "WUtil.h"
typedef struct W_TreeNode {
void *data;
/*unsigned int uflags:16; */
WMArray *leaves;
int depth;
struct W_TreeNode *parent;
WMFreeDataProc *destructor;
} W_TreeNode;
static void destroyNode(void *data)
{
WMTreeNode *aNode = (WMTreeNode *) data;
if (aNode->destructor) {
(*aNode->destructor) (aNode->data);
}
if (aNode->leaves) {
WMFreeArray(aNode->leaves);
}
wfree(aNode);
}
WMTreeNode *WMCreateTreeNode(void *data)
{
return WMCreateTreeNodeWithDestructor(data, NULL);
}
WMTreeNode *WMCreateTreeNodeWithDestructor(void *data, WMFreeDataProc * destructor)
{
WMTreeNode *aNode;
aNode = (WMTreeNode *) wmalloc(sizeof(W_TreeNode));
aNode->destructor = destructor;
aNode->data = data;
aNode->parent = NULL;
aNode->depth = 0;
aNode->leaves = NULL;
/*aNode->leaves = WMCreateArrayWithDestructor(1, destroyNode); */
return aNode;
}
WMTreeNode *WMInsertItemInTree(WMTreeNode * parent, int index, void *item)
{
WMTreeNode *aNode;
wassertrv(parent != NULL, NULL);
aNode = WMCreateTreeNodeWithDestructor(item, parent->destructor);
aNode->parent = parent;
aNode->depth = parent->depth + 1;
if (!parent->leaves) {
parent->leaves = WMCreateArrayWithDestructor(1, destroyNode);
}
if (index < 0) {
WMAddToArray(parent->leaves, aNode);
} else {
WMInsertInArray(parent->leaves, index, aNode);
}
return aNode;
}
static void updateNodeDepth(WMTreeNode * aNode, int depth)
{
int i;
aNode->depth = depth;
if (aNode->leaves) {
for (i = 0; i < WMGetArrayItemCount(aNode->leaves); i++) {
updateNodeDepth(WMGetFromArray(aNode->leaves, i), depth + 1);
}
}
}
WMTreeNode *WMInsertNodeInTree(WMTreeNode * parent, int index, WMTreeNode * aNode)
{
wassertrv(parent != NULL, NULL);
wassertrv(aNode != NULL, NULL);
aNode->parent = parent;
updateNodeDepth(aNode, parent->depth + 1);
if (!parent->leaves) {
parent->leaves = WMCreateArrayWithDestructor(1, destroyNode);
}
if (index < 0) {
WMAddToArray(parent->leaves, aNode);
} else {
WMInsertInArray(parent->leaves, index, aNode);
}
return aNode;
}
void WMDestroyTreeNode(WMTreeNode * aNode)
{
wassertr(aNode != NULL);
if (aNode->parent && aNode->parent->leaves) {
WMRemoveFromArray(aNode->parent->leaves, aNode);
} else {
destroyNode(aNode);
}
}
void WMDeleteLeafForTreeNode(WMTreeNode * aNode, int index)
{
wassertr(aNode != NULL);
wassertr(aNode->leaves != NULL);
WMDeleteFromArray(aNode->leaves, index);
}
static int sameData(const void *item, const void *data)
{
return (((WMTreeNode *) item)->data == data);
}
void WMRemoveLeafForTreeNode(WMTreeNode * aNode, void *leaf)
{
int index;
wassertr(aNode != NULL);
wassertr(aNode->leaves != NULL);
index = WMFindInArray(aNode->leaves, sameData, leaf);
if (index != WANotFound) {
WMDeleteFromArray(aNode->leaves, index);
}
}
void *WMReplaceDataForTreeNode(WMTreeNode * aNode, void *newData)
{
void *old;
wassertrv(aNode != NULL, NULL);
old = aNode->data;
aNode->data = newData;
return old;
}
void *WMGetDataForTreeNode(WMTreeNode * aNode)
{
return aNode->data;
}
int WMGetTreeNodeDepth(WMTreeNode * aNode)
{
return aNode->depth;
}
WMTreeNode *WMGetParentForTreeNode(WMTreeNode * aNode)
{
return aNode->parent;
}
void WMSortLeavesForTreeNode(WMTreeNode * aNode, WMCompareDataProc * comparer)
{
wassertr(aNode != NULL);
if (aNode->leaves) {
WMSortArray(aNode->leaves, comparer);
}
}
static void sortLeavesForNode(WMTreeNode * aNode, WMCompareDataProc * comparer)
{
int i;
if (!aNode->leaves)
return;
WMSortArray(aNode->leaves, comparer);
for (i = 0; i < WMGetArrayItemCount(aNode->leaves); i++) {
sortLeavesForNode(WMGetFromArray(aNode->leaves, i), comparer);
}
}
void WMSortTree(WMTreeNode * aNode, WMCompareDataProc * comparer)
{
wassertr(aNode != NULL);
sortLeavesForNode(aNode, comparer);
}
static WMTreeNode *findNodeInTree(WMTreeNode * aNode, WMMatchDataProc * match, void *cdata, int limit)
{
if (match == NULL && aNode->data == cdata)
return aNode;
else if (match && (*match) (aNode->data, cdata))
return aNode;
if (aNode->leaves && limit != 0) {
WMTreeNode *leaf;
int i;
for (i = 0; i < WMGetArrayItemCount(aNode->leaves); i++) {
leaf = findNodeInTree(WMGetFromArray(aNode->leaves, i),
match, cdata, limit > 0 ? limit - 1 : limit);
if (leaf)
return leaf;
}
}
return NULL;
}
WMTreeNode *WMFindInTree(WMTreeNode * aTree, WMMatchDataProc * match, void *cdata)
{
wassertrv(aTree != NULL, NULL);
return findNodeInTree(aTree, match, cdata, -1);
}
WMTreeNode *WMFindInTreeWithDepthLimit(WMTreeNode * aTree, WMMatchDataProc * match, void *cdata, int limit)
{
wassertrv(aTree != NULL, NULL);
wassertrv(limit >= 0, NULL);
return findNodeInTree(aTree, match, cdata, limit);
}
void WMTreeWalk(WMTreeNode * aNode, WMTreeWalkProc * walk, void *data, Bool DepthFirst)
{
int i;
WMTreeNode *leaf;
wassertr(aNode != NULL);
if (DepthFirst)
(*walk)(aNode, data);
if (aNode->leaves) {
for (i = 0; i < WMGetArrayItemCount(aNode->leaves); i++) {
leaf = (WMTreeNode *)WMGetFromArray(aNode->leaves, i);
WMTreeWalk(leaf, walk, data, DepthFirst);
}
}
if (!DepthFirst)
(*walk)(aNode, data);
}

View File

@@ -46,6 +46,40 @@ static void synchronizeUserDefaults(void *foo);
#define UD_SYNC_INTERVAL 2000
#endif
const char *wusergnusteppath(void)
{
static const char subdir[] = "/" GSUSER_SUBDIR;
static char *path = NULL;
char *gspath;
const char *h;
int pathlen;
if (path)
/* Value have been already computed, re-use it */
return path;
gspath = GETENV("WMAKER_USER_ROOT");
if (gspath) {
gspath = wexpandpath(gspath);
if (gspath) {
path = gspath;
return path;
}
wwarning(_("variable WMAKER_USER_ROOT defined with invalid path, not used"));
}
h = wgethomedir();
if (!h)
return NULL;
pathlen = strlen(h);
path = wmalloc(pathlen + sizeof(subdir));
strcpy(path, h);
strcpy(path + pathlen, subdir);
return path;
}
const char *wuserdatapath(void)
{
static char *path = NULL;
@@ -297,7 +331,7 @@ WMUserDefaults *WMGetStandardUserDefaults(void)
/* terminate list */
defaults->searchList[2] = NULL;
defaults->searchListArray = WMCreateEmptyPLArray();
defaults->searchListArray = WMCreatePLArray(NULL, NULL);
i = 0;
while (defaults->searchList[i]) {
@@ -370,7 +404,7 @@ WMUserDefaults *WMGetDefaultsFromPath(const char *path)
/* terminate list */
defaults->searchList[1] = NULL;
defaults->searchListArray = WMCreateEmptyPLArray();
defaults->searchListArray = WMCreatePLArray(NULL, NULL);
i = 0;
while (defaults->searchList[i]) {

View File

@@ -44,6 +44,9 @@ void WMInitializeApplication(const char *applicationName, int *argc, char **argv
WMApplication.argv[i] = wstrdup(argv[i]);
}
WMApplication.argv[i] = NULL;
/* initialize notification center */
W_InitNotificationCenter();
}
void WMReleaseApplication(void) {
@@ -57,7 +60,7 @@ void WMReleaseApplication(void) {
*/
w_save_defaults_changes();
W_ClearNotificationCenter();
W_ReleaseNotificationCenter();
if (WMApplication.applicationName) {
wfree(WMApplication.applicationName);
@@ -98,21 +101,21 @@ static char *checkFile(const char *path, const char *folder, const char *ext, co
slen = strlen(path) + strlen(resource) + 1 + extralen;
ret = wmalloc(slen);
if (strlcpy(ret, path, slen) >= slen)
if (wstrlcpy(ret, path, slen) >= slen)
goto error;
if (folder &&
(strlcat(ret, "/", slen) >= slen ||
strlcat(ret, folder, slen) >= slen))
(wstrlcat(ret, "/", slen) >= slen ||
wstrlcat(ret, folder, slen) >= slen))
goto error;
if (ext &&
(strlcat(ret, "/", slen) >= slen ||
strlcat(ret, ext, slen) >= slen))
(wstrlcat(ret, "/", slen) >= slen ||
wstrlcat(ret, ext, slen) >= slen))
goto error;
if (strlcat(ret, "/", slen) >= slen ||
strlcat(ret, resource, slen) >= slen)
if (wstrlcat(ret, "/", slen) >= slen ||
wstrlcat(ret, resource, slen) >= slen)
goto error;
if (access(ret, F_OK) != 0)

View File

@@ -65,7 +65,7 @@ struct W_Balloon *W_CreateBalloon(WMScreen * scr)
W_ResizeView(bPtr->view, DEFAULT_WIDTH, DEFAULT_HEIGHT);
bPtr->flags.alignment = DEFAULT_ALIGNMENT;
bPtr->table = WMCreateIdentityHashTable();
bPtr->table = WMCreateHashTable(WMIntHashCallbacks);
bPtr->delay = DEFAULT_DELAY;

View File

@@ -314,7 +314,7 @@ static void removeColumn(WMBrowser * bPtr, int column)
wfree(bPtr->titles[i]);
bPtr->titles[i] = NULL;
}
WMRemoveNotificationObserver(bPtr->columns[i]);
WMRemoveNotificationObserverWithName(bPtr, WMListSelectionDidChangeNotification, bPtr->columns[i]);
WMDestroyWidget(bPtr->columns[i]);
bPtr->columns[i] = NULL;
}
@@ -720,14 +720,14 @@ char *WMGetBrowserPathToColumn(WMBrowser * bPtr, int column)
path = wmalloc(slen);
/* ignore first `/' */
for (i = 0; i <= column; i++) {
if (strlcat(path, bPtr->pathSeparator, slen) >= slen)
if (wstrlcat(path, bPtr->pathSeparator, slen) >= slen)
goto error;
item = WMGetListSelectedItem(bPtr->columns[i]);
if (!item)
break;
if (strlcat(path, item->text, slen) >= slen)
if (wstrlcat(path, item->text, slen) >= slen)
goto error;
}
@@ -782,7 +782,7 @@ WMArray *WMGetBrowserPaths(WMBrowser * bPtr)
path = wmalloc(slen);
/* ignore first `/' */
for (i = 0; i <= column; i++) {
strlcat(path, bPtr->pathSeparator, slen);
wstrlcat(path, bPtr->pathSeparator, slen);
if (i == column) {
item = lastItem;
} else {
@@ -790,7 +790,7 @@ WMArray *WMGetBrowserPaths(WMBrowser * bPtr)
}
if (!item)
break;
strlcat(path, item->text, slen);
wstrlcat(path, item->text, slen);
}
WMAddToArray(paths, path);
}
@@ -1130,25 +1130,25 @@ static char *createTruncatedString(WMFont * font, const char *text, int *textLen
if (width >= 3 * dLen) {
int tmpTextLen = *textLen;
if (strlcpy(textBuf, text, slen) >= slen)
if (wstrlcpy(textBuf, text, slen) >= slen)
goto error;
while (tmpTextLen && (WMWidthOfString(font, textBuf, tmpTextLen) + 3 * dLen > width))
tmpTextLen--;
if (strlcpy(textBuf + tmpTextLen, "...", slen) >= slen)
if (wstrlcpy(textBuf + tmpTextLen, "...", slen) >= slen)
goto error;
*textLen = tmpTextLen + 3;
} else if (width >= 2 * dLen) {
if (strlcpy(textBuf, "..", slen) >= slen)
if (wstrlcpy(textBuf, "..", slen) >= slen)
goto error;
*textLen = 2;
} else if (width >= dLen) {
if (strlcpy(textBuf, ".", slen) >= slen)
if (wstrlcpy(textBuf, ".", slen) >= slen)
goto error;
*textLen = 1;

View File

@@ -2994,13 +2994,10 @@ static void customPaletteMenuNewFromFile(W_ColorPanel * panel)
int i;
RImage *tmpImg = NULL;
if ((!panel->lastBrowseDir) || (strcmp(panel->lastBrowseDir, "\0") == 0)) {
char *homedir = wgethomedir();
spath = wexpandpath(homedir);
wfree(homedir);
} else {
if ((!panel->lastBrowseDir) || (strcmp(panel->lastBrowseDir, "\0") == 0))
spath = wexpandpath(wgethomedir());
else
spath = wexpandpath(panel->lastBrowseDir);
}
browseP = WMGetOpenPanel(scr);
WMSetFilePanelCanChooseDirectories(browseP, 0);

View File

@@ -513,12 +513,12 @@ static void listDirectoryOnColumn(WMFilePanel * panel, int column, const char *p
if (strcmp(dentry->d_name, ".") == 0 || strcmp(dentry->d_name, "..") == 0)
continue;
if (strlcpy(pbuf, path, sizeof(pbuf)) >= sizeof(pbuf))
if (wstrlcpy(pbuf, path, sizeof(pbuf)) >= sizeof(pbuf))
goto out;
if (strcmp(path, "/") != 0 &&
strlcat(pbuf, "/", sizeof(pbuf)) >= sizeof(pbuf))
wstrlcat(pbuf, "/", sizeof(pbuf)) >= sizeof(pbuf))
goto out;
if (strlcat(pbuf, dentry->d_name, sizeof(pbuf)) >= sizeof(pbuf))
if (wstrlcat(pbuf, dentry->d_name, sizeof(pbuf)) >= sizeof(pbuf))
goto out;
if (stat(pbuf, &stat_buf) != 0) {
@@ -626,11 +626,11 @@ static void createDir(WMWidget *widget, void *p_panel)
file = wmalloc(slen);
if (directory &&
(strlcat(file, directory, slen) >= slen ||
strlcat(file, "/", slen) >= slen))
(wstrlcat(file, directory, slen) >= slen ||
wstrlcat(file, "/", slen) >= slen))
goto out;
if (strlcat(file, dirName, slen) >= slen)
if (wstrlcat(file, dirName, slen) >= slen)
goto out;
if (mkdir(file, 00777) != 0) {
@@ -761,15 +761,17 @@ static void goFloppy(WMWidget *widget, void *p_panel)
static void goHome(WMWidget *widget, void *p_panel)
{
WMFilePanel *panel = p_panel;
char *home;
const char *home;
/* Parameter not used, but tell the compiler that it is ok */
(void) widget;
/* home is statically allocated. Don't free it! */
home = wgethomedir();
if (!home)
return;
WMSetFilePanelDirectory(panel, home);
wfree(home);
}
static void handleEvents(XEvent * event, void *data)

View File

@@ -51,15 +51,12 @@ static char *xlfdToFcName(const char *xlfd)
{
FcPattern *pattern;
char *fname;
char *result;
pattern = xlfdToFcPattern(xlfd);
fname = (char *)FcNameUnparse(pattern);
result = wstrdup(fname);
free(fname);
FcPatternDestroy(pattern);
return result;
return fname;
}
static Bool hasProperty(FcPattern * pattern, const char *property)
@@ -95,7 +92,6 @@ static Bool hasPropertyWithStringValue(FcPattern * pattern, const char *object,
static char *makeFontOfSize(const char *font, int size, const char *fallback)
{
FcPattern *pattern;
char *name;
char *result;
if (font[0] == '-') {
@@ -119,9 +115,7 @@ static char *makeFontOfSize(const char *font, int size, const char *fallback)
/*FcPatternPrint(pattern); */
name = (char *)FcNameUnparse(pattern);
result = wstrdup(name);
free(name);
result = (char *)FcNameUnparse(pattern);
FcPatternDestroy(pattern);
return result;
@@ -427,7 +421,7 @@ WMFont *WMCopyFontWithStyle(WMScreen * scrPtr, WMFont * font, WMFontStyle style)
name = (char *)FcNameUnparse(pattern);
copy = WMCreateFont(scrPtr, name);
FcPatternDestroy(pattern);
free(name);
wfree(name);
return copy;
}

View File

@@ -535,7 +535,7 @@ static void listFamilies(WMScreen * scr, WMFontPanel * panel)
if (pat)
FcPatternDestroy(pat);
families = WMCreateStringHashTable();
families = WMCreateHashTable(WMStringPointerHashCallbacks);
if (fs) {
for (i = 0; i < fs->nfont; i++) {
@@ -558,7 +558,7 @@ static void listFamilies(WMScreen * scr, WMFontPanel * panel)
WMListItem *item;
WM_ITERATE_ARRAY(array, fam, i) {
strlcpy(buffer, fam->name, sizeof(buffer));
wstrlcpy(buffer, fam->name, sizeof(buffer));
item = WMAddListItem(panel->famLs, buffer);
item->clientData = fam;
@@ -640,7 +640,7 @@ static void familyClick(WMWidget * w, void *data)
int top = 0;
WMListItem *fitem;
strlcpy(buffer, face->typeface, sizeof(buffer));
wstrlcpy(buffer, face->typeface, sizeof(buffer));
if (strcasecmp(face->typeface, "Roman") == 0)
top = 1;
if (strcasecmp(face->typeface, "Regular") == 0)
@@ -773,7 +773,7 @@ static void setFontPanelFontName(FontPanel * panel, const char *family, const ch
int top = 0;
WMListItem *fitem;
strlcpy(buffer, face->typeface, sizeof(buffer));
wstrlcpy(buffer, face->typeface, sizeof(buffer));
if (strcasecmp(face->typeface, "Roman") == 0)
top = 1;
if (top)

View File

@@ -610,9 +610,10 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
assert(W_ApplicationInitialized());
}
scrPtr = wmalloc(sizeof(W_Screen));
scrPtr = malloc(sizeof(W_Screen));
if (!scrPtr)
return NULL;
memset(scrPtr, 0, sizeof(W_Screen));
scrPtr->aflags.hasAppIcon = 1;
@@ -629,7 +630,7 @@ WMScreen *WMCreateScreenWithRContext(Display * display, int screen, RContext * c
scrPtr->rootWin = RootWindow(display, screen);
scrPtr->fontCache = WMCreateStringHashTable();
scrPtr->fontCache = WMCreateHashTable(WMStringPointerHashCallbacks);
scrPtr->xftdraw = XftDrawCreate(scrPtr->display, W_DRAWABLE(scrPtr), scrPtr->visual, scrPtr->colormap);

View File

@@ -166,6 +166,16 @@ typedef struct W_Text {
WMArray *xdndDestinationTypes;
} Text;
/* not used */
#if 0
#define NOTIFY(T,C,N,A) {\
WMNotification *notif = WMCreateNotification(N,T,A);\
if ((T)->delegate && (T)->delegate->C)\
(*(T)->delegate->C)((T)->delegate,notif);\
WMPostNotification(notif);\
WMReleaseNotification(notif);}
#endif
#define TYPETEXT 0
#if 0

View File

@@ -68,6 +68,12 @@ typedef struct W_TextField {
} flags;
} TextField;
#define NOTIFY(T,C,N,A) { WMNotification *notif = WMCreateNotification(N,T,A);\
if ((T)->delegate && (T)->delegate->C)\
(*(T)->delegate->C)((T)->delegate,notif);\
WMPostNotification(notif);\
WMReleaseNotification(notif);}
#define MIN_TEXT_BUFFER 2
#define TEXT_BUFFER_INCR 8
@@ -398,7 +404,7 @@ void WMInsertTextFieldText(WMTextField * tPtr, const char *text, int position)
if (position < 0 || position >= tPtr->textLen) {
/* append the text at the end */
strlcat(tPtr->text, text, tPtr->bufferSize);
wstrlcat(tPtr->text, text, tPtr->bufferSize);
tPtr->textLen += len;
tPtr->cursorPosition += len;
incrToFit(tPtr);
@@ -467,7 +473,7 @@ void WMSetTextFieldText(WMTextField * tPtr, const char *text)
tPtr->bufferSize = tPtr->textLen + TEXT_BUFFER_INCR;
tPtr->text = wrealloc(tPtr->text, tPtr->bufferSize);
}
strlcpy(tPtr->text, text, tPtr->bufferSize);
wstrlcpy(tPtr->text, text, tPtr->bufferSize);
}
tPtr->cursorPosition = tPtr->selection.position = tPtr->textLen;
@@ -900,10 +906,7 @@ static void handleEvents(XEvent * event, void *data)
paintTextField(tPtr);
if (tPtr->delegate && tPtr->delegate->didBeginEditing) {
(*tPtr->delegate->didBeginEditing)(tPtr->delegate, 0);
}
WMPostNotificationName(WMTextDidBeginEditingNotification, tPtr, NULL);
NOTIFY(tPtr, didBeginEditing, WMTextDidBeginEditingNotification, NULL);
tPtr->flags.notIllegalMovement = 0;
break;
@@ -918,10 +921,8 @@ static void handleEvents(XEvent * event, void *data)
paintTextField(tPtr);
if (!tPtr->flags.notIllegalMovement) {
if (tPtr->delegate && tPtr->delegate->didEndEditing) {
(*tPtr->delegate->didEndEditing)(tPtr->delegate, WMIllegalTextMovement);
}
WMPostNotificationName(WMTextDidEndEditingNotification, tPtr, (void *)WMIllegalTextMovement);
NOTIFY(tPtr, didEndEditing, WMTextDidEndEditingNotification,
(void *)WMIllegalTextMovement);
}
break;
@@ -942,8 +943,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
char buffer[64];
KeySym ksym;
const char *textEvent = NULL;
WMTextMovementType movement_type;
WMTextFieldSpecialEventType special_field_event_type;
void *data = NULL;
int count, refresh = 0;
int control_pressed = 0;
int cancelSelection = 1;
@@ -975,14 +975,14 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
tPtr->view->prevFocusChain);
tPtr->flags.notIllegalMovement = 1;
}
movement_type = WMBacktabTextMovement;
data = (void *)WMBacktabTextMovement;
} else {
if (tPtr->view->nextFocusChain) {
W_SetFocusOfTopLevel(W_TopLevelOfView(tPtr->view),
tPtr->view->nextFocusChain);
tPtr->flags.notIllegalMovement = 1;
}
movement_type = WMTabTextMovement;
data = (void *)WMTabTextMovement;
}
textEvent = WMTextDidEndEditingNotification;
@@ -994,7 +994,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
case XK_Escape:
if (!modified) {
movement_type = WMEscapeTextMovement;
data = (void *)WMEscapeTextMovement;
textEvent = WMTextDidEndEditingNotification;
relay = False;
@@ -1008,7 +1008,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
/* FALLTHRU */
case XK_Return:
if (!modified) {
movement_type = WMReturnTextMovement;
data = (void *)WMReturnTextMovement;
textEvent = WMTextDidEndEditingNotification;
relay = False;
@@ -1165,7 +1165,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
if (!modified) {
if (tPtr->selection.count) {
WMDeleteTextFieldRange(tPtr, tPtr->selection);
special_field_event_type = WMDeleteTextEvent;
data = (void *)WMDeleteTextEvent;
textEvent = WMTextDidChangeNotification;
} else if (tPtr->cursorPosition > 0) {
int i = oneUTF8CharBackward(&tPtr->text[tPtr->cursorPosition],
@@ -1174,7 +1174,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
range.position = tPtr->cursorPosition + i;
range.count = -i;
WMDeleteTextFieldRange(tPtr, range);
special_field_event_type = WMDeleteTextEvent;
data = (void *)WMDeleteTextEvent;
textEvent = WMTextDidChangeNotification;
}
@@ -1197,7 +1197,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
if (!modified) {
if (tPtr->selection.count) {
WMDeleteTextFieldRange(tPtr, tPtr->selection);
special_field_event_type = WMDeleteTextEvent;
data = (void *)WMDeleteTextEvent;
textEvent = WMTextDidChangeNotification;
} else if (tPtr->cursorPosition < tPtr->textLen) {
WMRange range;
@@ -1205,7 +1205,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
range.count = oneUTF8CharForward(&tPtr->text[tPtr->cursorPosition],
tPtr->textLen - tPtr->cursorPosition);
WMDeleteTextFieldRange(tPtr, range);
special_field_event_type = WMDeleteTextEvent;
data = (void *)WMDeleteTextEvent;
textEvent = WMTextDidChangeNotification;
}
@@ -1220,7 +1220,7 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
if (tPtr->selection.count)
WMDeleteTextFieldRange(tPtr, tPtr->selection);
WMInsertTextFieldText(tPtr, buffer, tPtr->cursorPosition);
special_field_event_type = WMInsertTextEvent;
data = (void *)WMInsertTextEvent;
textEvent = WMTextDidChangeNotification;
relay = False;
@@ -1255,22 +1255,21 @@ static void handleTextFieldKeyPress(TextField * tPtr, XEvent * event)
/*printf("(%d,%d)\n", tPtr->selection.position, tPtr->selection.count); */
if (textEvent) {
WMNotification *notif = WMCreateNotification(textEvent, tPtr, data);
if (tPtr->delegate) {
if (textEvent == WMTextDidBeginEditingNotification && tPtr->delegate->didBeginEditing)
(*tPtr->delegate->didBeginEditing) (tPtr->delegate, movement_type);
(*tPtr->delegate->didBeginEditing) (tPtr->delegate, notif);
else if (textEvent == WMTextDidEndEditingNotification && tPtr->delegate->didEndEditing)
(*tPtr->delegate->didEndEditing) (tPtr->delegate, movement_type);
(*tPtr->delegate->didEndEditing) (tPtr->delegate, notif);
else if (textEvent == WMTextDidChangeNotification && tPtr->delegate->didChange)
(*tPtr->delegate->didChange) (tPtr->delegate, special_field_event_type);
(*tPtr->delegate->didChange) (tPtr->delegate, notif);
}
if (textEvent == WMTextDidBeginEditingNotification || textEvent == WMTextDidEndEditingNotification) {
WMPostNotificationName(textEvent, tPtr, (void *)movement_type);
} else if (textEvent == WMTextDidChangeNotification) {
WMPostNotificationName(textEvent, tPtr, (void *)special_field_event_type);
}
WMPostNotification(notif);
WMReleaseNotification(notif);
}
if (refresh)
@@ -1346,10 +1345,7 @@ static void pasteText(WMView * view, Atom selection, Atom target, Time timestamp
str = (char *)WMDataBytes(data);
WMInsertTextFieldText(tPtr, str, tPtr->cursorPosition);
if (tPtr->delegate && tPtr->delegate->didChange) {
(*tPtr->delegate->didChange)(tPtr->delegate, WMInsertTextEvent);
}
WMPostNotificationName(WMTextDidChangeNotification, tPtr, (void *)WMInsertTextEvent);
NOTIFY(tPtr, didChange, WMTextDidChangeNotification, (void *)WMInsertTextEvent);
} else {
int n;
@@ -1359,10 +1355,7 @@ static void pasteText(WMView * view, Atom selection, Atom target, Time timestamp
str[n] = 0;
WMInsertTextFieldText(tPtr, str, tPtr->cursorPosition);
XFree(str);
if (tPtr->delegate && tPtr->delegate->didChange) {
(*tPtr->delegate->didChange)(tPtr->delegate, WMInsertTextEvent);
}
WMPostNotificationName(WMTextDidChangeNotification, tPtr, (void *)WMInsertTextEvent);
NOTIFY(tPtr, didChange, WMTextDidChangeNotification, (void *)WMInsertTextEvent);
}
}
}
@@ -1484,10 +1477,8 @@ static void handleTextFieldActionEvents(XEvent * event, void *data)
text[n] = 0;
WMInsertTextFieldText(tPtr, text, tPtr->cursorPosition);
XFree(text);
if (tPtr->delegate && tPtr->delegate->didChange) {
(*tPtr->delegate->didChange)(tPtr->delegate, WMInsertTextEvent);
}
WMPostNotificationName(WMTextDidChangeNotification, tPtr, (void *)WMInsertTextEvent);
NOTIFY(tPtr, didChange, WMTextDidChangeNotification,
(void *)WMInsertTextEvent);
}
} else {
tPtr->flags.waitingSelection = 1;

View File

@@ -1110,7 +1110,7 @@ static void deleteTexture(WMWidget * w, void *data)
static void extractTexture(WMWidget * w, void *data)
{
_Panel *panel = (_Panel *) data;
char *path, *homedir;
char *path;
WMOpenPanel *opanel;
WMScreen *scr = WMWidgetScreen(w);
@@ -1118,17 +1118,13 @@ static void extractTexture(WMWidget * w, void *data)
WMSetFilePanelCanChooseDirectories(opanel, False);
WMSetFilePanelCanChooseFiles(opanel, True);
homedir = wgethomedir();
if (WMRunModalFilePanelForDirectory(opanel, panel->parent, homedir, _("Select File"), NULL)) {
if (WMRunModalFilePanelForDirectory(opanel, panel->parent, wgethomedir(), _("Select File"), NULL)) {
path = WMGetFilePanelFileName(opanel);
OpenExtractPanelFor(panel);
wfree(path);
}
if (homedir) {
wfree(homedir);
}
}
static void changePage(WMWidget * w, void *data)
@@ -2228,7 +2224,7 @@ static void prepareForClose(_Panel * panel)
WMUserDefaults *udb = WMGetStandardUserDefaults();
int i;
textureList = WMCreateEmptyPLArray();
textureList = WMCreatePLArray(NULL, NULL);
/* store list of textures */
for (i = 8; i < WMGetListNumberOfRows(panel->texLs); i++) {
@@ -2250,7 +2246,7 @@ static void prepareForClose(_Panel * panel)
WMReleasePropList(textureList);
/* store list of colors */
textureList = WMCreateEmptyPLArray();
textureList = WMCreatePLArray(NULL, NULL);
for (i = 0; i < wlengthof(sample_colors); i++) {
WMColor *color;
char *str;

View File

@@ -129,7 +129,7 @@ static void autoDelayChanged(void *observerData, WMNotification *notification)
}
char *value = WMGetTextFieldText(anAutoDelayT);
adjustButtonSelectionBasedOnValue(panel, row, value);
wfree(value);
free(value);
return;
}
}

View File

@@ -138,7 +138,7 @@ static void storeData(_Panel * panel)
if (sscanf(str, "%i", &i) != 1)
i = 0;
SetIntegerForKey(i, "RaiseDelay");
wfree(str);
free(str);
SetBoolForKey(WMGetButtonSelected(panel->ignB), "IgnoreFocusClick");
SetBoolForKey(WMGetButtonSelected(panel->newB), "AutoFocus");

View File

@@ -288,7 +288,6 @@ static char *getSelectedFont(_Panel * panel, FcChar8 * curfont)
WMListItem *item;
FcPattern *pat;
char *name;
char *result;
if (curfont)
pat = FcNameParse(curfont);
@@ -322,12 +321,9 @@ static char *getSelectedFont(_Panel * panel, FcChar8 * curfont)
}
name = (char *)FcNameUnparse(pat);
result = wstrdup(name);
free(name);
FcPatternDestroy(pat);
return result;
return name;
}
static void updateSampleFont(_Panel * panel)

View File

@@ -147,11 +147,11 @@ static void storeData(_Panel * panel)
if (sscanf(str, "%i", &i) != 1)
i = 0;
SetIntegerForKey(i, "HotCornerDelay");
wfree(str);
free(str);
SetIntegerForKey(WMGetSliderValue(panel->hceS), "HotCornerEdge");
list = WMCreateEmptyPLArray();
list = WMCreatePLArray(NULL, NULL);
for (i = 0; i < sizeof(panel->hcactionsT) / sizeof(WMTextField *); i++) {
str = WMGetTextFieldText(panel->hcactionsT[i]);
if (strlen(str) == 0)

View File

@@ -365,7 +365,7 @@ char *capture_shortcut(Display *dpy, Bool *capturing, Bool convert_case)
if ((numlock_mask != Mod5Mask) && (ev.xkey.state & Mod5Mask))
strcat(buffer, "Mod5+");
strlcat(buffer, key, sizeof(buffer));
wstrlcat(buffer, key, sizeof(buffer));
return wstrdup(buffer);
}

View File

@@ -66,7 +66,6 @@ AM_CPPFLAGS = -DRESOURCE_PATH=\"$(wpdatadir)\" -DWMAKER_RESOURCE_PATH=\"$(pkgdat
WPrefs_DEPENDENCIES = $(top_builddir)/WINGs/libWINGs.la
WPrefs_LDADD = \
$(top_builddir)/wutil-rs/target/debug/libwutil_rs.a\
$(top_builddir)/WINGs/libWINGs.la\
$(top_builddir)/WINGs/libWUtil.la\
$(top_builddir)/wrlib/libwraster.la \

View File

@@ -203,7 +203,7 @@ static void storeData(_Panel * panel)
int i;
char *p;
list = WMCreateEmptyPLArray();
list = WMCreatePLArray(NULL, NULL);
for (i = 0; i < WMGetListNumberOfRows(panel->icoL); i++) {
p = WMGetListItem(panel->icoL, i)->text;
tmp = WMCreatePLString(p);
@@ -211,7 +211,7 @@ static void storeData(_Panel * panel)
}
SetObjectForKey(list, "IconPath");
list = WMCreateEmptyPLArray();
list = WMCreatePLArray(NULL, NULL);
for (i = 0; i < WMGetListNumberOfRows(panel->pixL); i++) {
p = WMGetListItem(panel->pixL, i)->text;
tmp = WMCreatePLString(p);

View File

@@ -627,7 +627,7 @@ static void browseImageCallback(WMWidget *w, void *data)
WMSetFilePanelCanChooseFiles(opanel, True);
if (!ipath)
ipath = wgethomedir();
ipath = wstrdup(wgethomedir());
if (WMRunModalFilePanelForDirectory(opanel, panel->win, ipath, _("Open Image"), NULL)) {
char *path, *fullpath;

View File

@@ -705,10 +705,10 @@ static void loadConfigurations(WMScreen * scr, WMWindow * mainw)
}
if (!db) {
db = WMCreateEmptyPLDictionary();
db = WMCreatePLDictionary(NULL, NULL);
}
if (!gdb) {
gdb = WMCreateEmptyPLDictionary();
gdb = WMCreatePLDictionary(NULL, NULL);
}
GlobalDB = gdb;

View File

@@ -824,15 +824,18 @@ static void stopEditItem(WEditMenu * menu, Bool apply)
menu->flags.isEditing = 0;
}
static void textEndedEditing(struct WMTextFieldDelegate *self, WMTextMovementType reason)
static void textEndedEditing(struct WMTextFieldDelegate *self, WMNotification * notif)
{
WEditMenu *menu = (WEditMenu *) self->data;
uintptr_t reason;
int i;
WEditMenuItem *item;
if (!menu->flags.isEditing)
return;
reason = (uintptr_t)WMGetNotificationClientData(notif);
switch (reason) {
case WMEscapeTextMovement:
stopEditItem(menu, False);

View File

@@ -47,6 +47,14 @@ struct {
static pid_t DeadChildren[MAX_DEATHS];
static int DeadChildrenCount = 0;
static noreturn void wAbort(Bool foo)
{
/* Parameter not used, but tell the compiler that it is ok */
(void) foo;
exit(1);
}
static void print_help(const char *progname)
{
printf(_("usage: %s [options]\n"), progname);
@@ -79,6 +87,8 @@ int main(int argc, char **argv)
int i;
char *display_name = "";
wsetabort(wAbort);
memset(DeadHandlers, 0, sizeof(DeadHandlers));
WMInitializeApplication("WPrefs", &argc, argv);
@@ -145,12 +155,7 @@ int main(int argc, char **argv)
exit(0);
}
/*
* Rust rewrite note: this API surface has been removed, but we leave in
* a record of where it was invoked to set a value other than the
* default, in case it helps to track down bugs in the future.
*/
/* WMPLSetCaseSensitive(False); */
WMPLSetCaseSensitive(False);
Initialize(scr);

View File

@@ -5,8 +5,7 @@ CATALOGS = @WPREFSMOFILES@
CLEANFILES = $(DOMAIN).pot $(CATALOGS)
EXTRA_DIST = bg.po ca.po cs.po de.po es.po et.po fi.po fr.po fy.po hr.po hu.po \
it.po ja.po ko.po nl.po pt.po ru.po sk.po sr.po tr.po uk.po zh_CN.po \
zh_TW.po
it.po ja.po ko.po nl.po pt.po ru.po sk.po tr.po uk.po zh_CN.po zh_TW.po
POTFILES = \
$(top_srcdir)/WPrefs.app/Appearance.c \

View File

@@ -8,7 +8,6 @@ msgstr ""
"PO-Revision-Date: 2001-04-18 23:22+03:00\n"
"Last-Translator: Anton Zinoviev <zinoviev@debian.org>\n"
"Language-Team: Bulgarian <dict@linux.zonebg.com>\n"
"Language: bg\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@@ -14,7 +14,6 @@ msgstr ""
"PO-Revision-Date: 2003-09-16 23:15+0200\n"
"Last-Translator: Ernest Adrogué <eadrogue@gmx.net>\n"
"Language-Team: Catalan <ca@dodds.net>\n"
"Language: ca\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@@ -16,7 +16,6 @@ msgstr ""
"PO-Revision-Date: 2001-10-14 21:07+0000\n"
"Last-Translator: Jiří Hnídek <jiri.hnidek@vslib.cz>\n"
"Language-Team: czech <cs@li.org>\n"
"Language: cs\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: unknown\n"

View File

@@ -18,7 +18,6 @@ msgstr ""
"PO-Revision-Date: 2010-02-02 10:49+0100\n"
"Last-Translator: Carlos R. Mafra <crmafra@gmail.com>\n"
"Language-Team: German <>\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@@ -8,7 +8,6 @@ msgstr ""
"PO-Revision-Date: 2003-09-19 03:05-0400\n"
"Last-Translator: Alberto Giménez <algibe@teleline.es>\n"
"Language-Team: Spanish \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: unknown\n"

View File

@@ -8,7 +8,6 @@ msgstr ""
"PO-Revision-Date: 2001-09-05 09:40+0200\n"
"Last-Translator: Ivar Smolin <okul@linux.ee>\n"
"Language-Team: Estonian <linux-ee@eenet.ee>\n"
"Language: et\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
@@ -476,7 +475,7 @@ msgstr "Window Maker vőttis vastu signaali %i."
#: ../src/dialog.c:1707
msgid ""
" This fatal error occurred probably due to a bug. Please fill the included "
" This fatal error occured probably due to a bug. Please fill the included "
"BUGFORM and report it to bugs@windowmaker.info."
msgstr ""
" See fataalviga on arvatavasti pőhjustatud programmi veast. Palun täitke "
@@ -1438,7 +1437,7 @@ msgstr "ei őnnestu käivitada alternatiivset aknahaldurit. Annan alla."
#: ../src/startup.c:419
msgid ""
"a fatal error has occurred, probably due to a bug. Please fill the included "
"a fatal error has occured, probably due to a bug. Please fill the included "
"BUGFORM and report it."
msgstr ""
"aset on leidnud fataalne viga, arvatavasti programmi viga. Palun täida "

View File

@@ -11,7 +11,6 @@ msgstr ""
"PO-Revision-Date: 2001-09-03 22:18+03:00\n"
"Last-Translator: Tomi Kajala <tomi@iki.fi>\n"
"Language-Team: Finnish <fi@li.org>\n"
"Language: fi\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8-bit\n"

View File

@@ -12,7 +12,6 @@ msgstr ""
"PO-Revision-Date: 1999-07-28 16:31-0100\n"
"Last-Translator: Antoine Hulin <antoine.hulin@origan.fdn.org>\n"
"Language-Team: French <fr@li.org>\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8-bit\n"

View File

@@ -9,7 +9,6 @@ msgstr ""
"PO-Revision-Date: 1998-08-24 14:36:41-0300\n"
"Last-Translator: Toni Bilić tbilic@oliver.efos.hr \n"
"Language-Team: Croatian \n"
"Language: hr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@@ -11,7 +11,7 @@ msgstr ""
"PO-Revision-Date: 2014-02-18 00:33+0100\n"
"Last-Translator: BALATON Zoltán <balaton@eik.bme.hu>\n"
"Language-Team: Hungarian\n"
"Language: hu\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@@ -11,7 +11,6 @@ msgstr ""
"PO-Revision-Date: 2001-05-21\n"
"Last-Translator: Michele Campeotto <micampe@f2s.com\n"
"Language-Team: Italian\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: unknown\n"

View File

@@ -12,7 +12,6 @@ msgstr ""
"PO-Revision-Date: 2013-08-13 19:26+0900\n"
"Last-Translator: \n"
"Language-Team: Korean\n"
"Language: ko\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@@ -12,7 +12,6 @@ msgstr ""
"PO-Revision-Date: 2000-01-04 18:25-0300\n"
"Last-Translator: Eliphas Levy Theodoro <eliphas@conectiva.com.br>\n"
"Language-Team: Portuguese \n"
"Language: pt\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8-bit\n"

View File

@@ -12,7 +12,6 @@ msgstr ""
"PO-Revision-Date: 2002-09-12 17:45+0300\n"
"Last-Translator: awn@bcs.zp.ua\n"
"Language-Team: Russian\n"
"Language: ru\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@@ -18,7 +18,6 @@ msgstr ""
"PO-Revision-Date: 2001-10-15 20:40+0100\n"
"Last-Translator: Jan \"judas\" Tomka <judas@linux.sk>\n"
"Language-Team: Slovak <sk@li.org>\n"
"Language: sk\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@@ -5,7 +5,6 @@ msgstr ""
"PO-Revision-Date: 2004-09-06 21:42+4000\n"
"Last-Translator: Victor Forsyuk <victor@ksi-linux.com>\n"
"Language-Team: KSI Linux Ukrainian <uk@ksi-linux.com>\n"
"Language: uk\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

View File

@@ -9,7 +9,6 @@ msgstr ""
"PO-Revision-Date: 1999-07-05 23:20+0800\n"
"Last-Translator: Wang Jian <larkw@263.net>\n"
"Language-Team: chinese <zh@li.org>\n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8-bit\n"

View File

@@ -10,7 +10,6 @@ msgstr ""
"PO-Revision-Date: 2005-01-11 17:46+0800\n"
"Last-Translator: Li Wei Jih <lwj83@cs.ccu.edu.tw>\n"
"Language-Team: chinese <zh@li.org>\n"
"Language: zh_TW\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8-bit\n"

View File

@@ -1,16 +1,26 @@
#!/bin/sh
srcdir=$(dirname $0)
test -z "$srcdir" && srcdir=.
# Generate the documentation about compiling Window Maker
$srcdir/script/generate-txt-from-texi.sh "$srcdir/doc/build/Compilation.texi" \
-o "$srcdir/INSTALL-WMAKER"
$srcdir/script/generate-txt-from-texi.sh "$srcdir/doc/build/Translations.texi" \
-o "$srcdir/README.i18n"
./script/generate-txt-from-texi.sh "doc/build/Compilation.texi" -o "INSTALL-WMAKER"
./script/generate-txt-from-texi.sh "doc/build/Translations.texi" -o "README.i18n"
# Change date of the files to the past so they will be regenerated by 'make'
touch -d '2000-01-01' $srcdir/INSTALL-WMAKER $srcdir/README.i18n
touch -d '2000-01-01' INSTALL-WMAKER README.i18n
# Generate the configure script from the 'configure.ac'
autoreconf -vfi -I m4 $srcdir
autoreconf -vfi -I m4
exit 0
if [ -x config.status -a -z "$*" ]; then
./config.status --recheck
else
if test -z "$*"; then
echo "I am going to run ./configure with no arguments - if you wish "
echo "to pass any to it, please specify them on the $0 command line."
echo "If you do not wish to run ./configure, press Ctrl-C now."
trap 'echo "configure aborted" ; exit 0' 1 2 15
sleep 1
fi
./configure "$@"
fi

6
bazel/MODULE.bazel Normal file
View File

@@ -0,0 +1,6 @@
###############################################################################
# Bazel now uses Bzlmod by default to manage external dependencies.
# Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel.
#
# For more details, please check https://github.com/bazelbuild/bazel/issues/18958
###############################################################################

3
bazel/WINGs/BUGS Normal file
View File

@@ -0,0 +1,3 @@
- filepanel does not reread / . If you add new files in / they will not be
visible until the program is restarted. Closing and reopening the file
panel does not help.

86
bazel/WINGs/BUILD.bazel Normal file
View File

@@ -0,0 +1,86 @@
cc_library(
name = "WINGs",
copts = [
"-DRESOURCE_PATH=\\\"Resources\\\"",
"-D_GNU_SOURCE",
"-DHAVE_BSD_STRING_H",
],
data = glob(['Resources/*']),
srcs = [
"array.c",
"bagtree.c",
"configuration.c",
"data.c",
"dragcommon.c",
"dragdestination.c",
"dragsource.c",
"error.c",
"findfile.c",
"handlers.c",
"hashtable.c",
"memory.c",
"menuparser.c",
"menuparser_macros.c",
"misc.c",
"notification.c",
"proplist.c",
"selection.c",
"string.c",
"tree.c",
"userdefaults.c",
"usleep.c",
"wapplication.c",
"wappresource.c",
"wballoon.c",
"wbox.c",
"wbrowser.c",
"wbutton.c",
"wcolor.c",
"wcolorpanel.c",
"wcolorwell.c",
"wevent.c",
"wfilepanel.c",
"wfont.c",
"wfontpanel.c",
"wframe.c",
"widgets.c",
"winputmethod.c",
"wlabel.c",
"wlist.c",
"wmenuitem.c",
"wmisc.c",
"wpanel.c",
"wpixmap.c",
"wpopupbutton.c",
"wprogressindicator.c",
"wruler.c",
"wscroller.c",
"wscrollview.c",
"wslider.c",
"wsplitview.c",
"wtabview.c",
"wtext.c",
"wtextfield.c",
"wview.c",
"wwindow.c",
],
hdrs = [
"menuparser.h",
"userdefaults.h",
"rgb.h",
"wconfig.h",
"WINGs.h",
"WINGsP.h",
"WUtil.h",
],
deps = [
"//config",
"//wmaker:gnustep_compat",
"//wrlib",
"@freetype2//:lib",
"@libbsd//:lib",
"@pango//:lib",
"@pangoxft//:lib",
],
visibility = ["//visibility:public"],
)

659
bazel/WINGs/ChangeLog Normal file
View File

@@ -0,0 +1,659 @@
Changes since wmaker 0.96.0:
............................
- added W_KeycodeToKeysym to replace XKeycodeToKeysym/XkbKeycodeToKeysym calls
Changes since wmaker 0.92.0:
............................
- updated the XDND code in to work with GDK based applications.
WINGs based applications should now work with both KDE and GNOME
applications (Sylvain Reynal <sreynal@nerim.net>)
- better check for the XDND protocol version when interoperating with other
applications. As it seems xdnd version 3 (which WINGs supports) and newer
are not backward compatible with xdnd version 1 and 2. This is why WINGs
applications cannot interoperate with GNUstep applications (which uses
xdnd version 2). Xdnd version 4 and 5 are backwards compatible with
version 3 though. (Sylvain Reynal <sreynal@nerim.net>)
- removed dependency on rgb.txt from X11 and issues with locating it on the
filesystem for different systems/distributions.
- Removed dependency on rgb.txt (from X11) and issues with locating it on the
filesystem for different systems/distributions.
Changes since wmaker 0.80.1:
............................
- Added WMSetConnectionShutdownOnClose()
- Added an extra member to the ConnectionDelegate: canResumeSending
see NEWS for details.
- WMDrawString() and WMDrawImageString() now take WMColor instead of GC as
arguments. WMDrawImageString() receives 2 colors (text & background).
This is to allow easy extension for Xft/Xrender and hide X low level details
Read NEWS for details since this will break backward compatibility.
- Added alpha channel to WMColor. 2 new functions also:
WMCreateRGBAColor() and WMSetColorAlpha()
- Miscelaneous code cleanups in wtext.c
- Added Xft2 support in WINGs (for drawing antialiased fonts with transparency).
- New options in WMGLOBAL: AntialiasedText. Check NEWS for details.
- Fixed some improper calls to snprintf in wfont.c
- Added double buffering when drawing a WMFrame title with an antialiased font
to avoid flickering.
- Added double buffering when drawing WMList items to avoid flickering.
Double buffering for list also works for user drawn lists. Read NEWS for
details and incompatibilities introduced by this change.
- Added WMGetColorAlpha(WMColor *color)
- Better outline when drawing balloons.
- Added WMCreateFontWithAttributes()
- You can now pass "SystemFont", "BoldSystemFont", "SystemFont-##" or
"BoldSystemFont-##", with ## being the font size to any font creating
function to create a font with the (bold) system font font specification.
- Added WMCopyFontWithChanges(). This is a more generic and powerful function
meant to replaces the obsoleted WMEmphasizeFont(), WMNormalizeFont(),
WMStrenghtenFont() and the other similar functions. To get the same effect
you pass some predefined structs to it: WFANormal, WFABold, WFAEmphasized,
etc which are declared in WINGs.h).
- Fixed a bug with empty frame titles (Alexey Voinov <voins@voins.program.ru>)
- Added WMGetWidgetBackgroundColor()
- Code cleanup in wtext.c
- Fixed a memory leak in wfontpanel.c
- Fixed WMGetTextDefaultColor() not to retain the returned color. It returns
only a reference to the internal color, which you shouldn't release
- Added wstrndup()
- Added WMGetFontName()
- Added fontpanel callback
- Added WMSetTableViewHasHorizontalScroller()
- Fixed bug that could cause SIGSEGV by accessing beyond the end of text in
a WINGs textfield widget.
- Fixed small memory leak in the font panel code.
- Fixed call to qsort in WMSortArray.
- Fixed a memleak in the file panel.
- Double/triple-click selection in text widgets
(Vitaly Ovtchinnikov <ov@rbcmail.ru>)
- Fixed bug in tableview (clicked row callback got incorrect row)
(Carlos Torres <vlaadbrain@operamail.com>)
- Fixed bug in resizing a scrollview
- Fixed bug with wrong text wrapping (Alexey Voinov <voins@voins.program.ru>)
- Added wmkrect()
- Added xdnd v3 support (Sylvain Reynal <sreynal@nerim.net>)
- Fixed and enhanced text wrapping.
Changes since wmaker 0.80.0:
............................
- fixed a bug in wfindfile() (rewrote wfindfile() with better logic).
- separated the font caches for normal fonts and fontsets in WINGs (they can
have the same names and collide in the cache giving unwanted results)
- fixed labels not to display '\n' as a character if multiple '\n' are passed
but just skip to the next line.
- better warning when importing non-digit characters in PropList Data.
- rewrote WMBox to use a WMArray for subviews. with this change fixed a bug
about arranging subviews after removing one and a memleak occuring in the
same case.
- Fixed WMGetViewScreenPosition() to consider the window decorations.
- Added ability to enable/disable individual WMTableViewItems.
- Fixed textfields regarding interpretation of special keys with modifiers.
- Fixed some functions that accept a boolean flag as a paramater, to set only
1 or 0 for the flag value, not the flag passed by the user.
- Added 2 functions to retrieve the default system fonts:
WMDefaultSystemFont(WMScreen *scr) and WMDefaultBoldSystemFont(WMScreen *scr)
- Added WMSetButtonImageDimsWhenDisabled() and WMGetButtonEnabled()
- Cleaned-up the header files of functions/vars declared but not implemented
- Added WMGetTextFieldDelegate()
Changes since wmaker 0.70.0:
............................
- added an internal strcasecmp() (only on systems where is not present)
- removed some redundant includes of ../src/config.h when wconfig.h is
included too
- removed a wsyserror() message when reading a property list from file
(the programmer should decide if to give that message or just ignore).
- added a 'Bool recursive' flag to WMMergePLDictionaries()
- added WMSubtractPLDictionaries()
Changes since wmaker 0.65.0:
............................
- fixed problem with WINGs based apps exiting with a "X_RotateProperties"
related error when text was selected in a textfiled.
- moved wstrdup(), wstrconcat() and wstrappend() from memory.c to string.c
- added property list handling code making libPropList unnecessary and
obsolete. Backward compatibility is provided through the
WINGs/proplist-compat.h header file which has #defines from old libPropList
function names to new function names with minimal changes. Read this
header file and the NEWS file for more details about this subject.
- Renamed WMGetUDAllKeys() to WMGetUDKeys()
Changes since wmaker 0.64.0:
............................
- made programmatic scroller changes send notifications
- replaced WMSetBoxExpandsToParent with WMSetViewExpands...
- added WMGetLabelFont()
- added WMAddPersistentTimerHandler()
- Moved all internal handlers (timer, idle and input) to handlers.c
- simplified wevent.c and wutil.c.
- fixed handling of input with poll (was broken)
- fixed mem leak that occured when input handling was done with poll
- simpler and more straightforward event handling for timer, idle, input
and X events (also fixed some problems the old handling logic had)
- moved timer, idle and input handler definitions and prototypes from
WINGs.h to WUtil.h because they're not GUI related.
- better and more robust handling of events (timer, idle, input, X) in
WMMaskEvent(). Also fixed a bug where input and timer events were not
treated for undefined periods of time under some circumstances.
- fixed secure textfields not to allow text selection, to avoid compromising
sensitive information by pasting it to a terminal.
- replaced wmkrange(), wmkpoint() and wmksize() functions with macros.
- added WMRemoveFromArrayMatching(array, match, cdata), which will remove the
first element in the array that is matched by match(item, cdata)==True.
- added WMArrayFirst(), WMArrayLast(), WMArrayNext() and WMArrayPrevious()
functions and also WM_ITERATE_ARRAY() and WM_ETARETI_ARRAY() macros, to make
interfaces to WMBag and WMArray similar and to make life a little simpler
when iterating through all elements of an array.
- replaced bags with arrays wherever appropriate. This will improve
performance a bit.
- replaced some recursive code with iterative code in selection.c
- added WMCreateBlendedPixmapFromRImage()
- small API change:
1. Renamed WMSetApplicationIconImage(), WMGetApplicationIconImage() and
WMSetWindowMiniwindowImage() to respectively WMSetApplicationIconPixmap(),
WMGetApplicationIconPixmap() and WMSetWindowMiniwindowPixmap()
They operate on a WMPixmap which is practically an X Pixmap with no alpha
channel information and the new name is more suggestive and also leaves
room for the new functions added for operating on images with alpha info.
2. Added WMSetApplicationIconImage() and WMGetApplicationIconImage() which
operate on an RImage and store alpha information too.
3. Added WMCreateApplicationIconBlendedPixmap() which will take the image
set by WMSetApplicationIconImage() and will combine it with a color.
If color is NULL it will blend using the default panel color (#aeaaae)
All these changes will allow WINGs to handle images with alpha blending
correctly in panels and wherever else needed. More about in NEWS.
- updated panels to use the newly available RImages if present and fallback
to old WMPixmaps if not, to properly show alpha blended images.
- replaced some still left malloc's with wmalloc's.
- fixed a bug in WMReparentWidget()
- added WMReparentWidget() to WINGs.h
- fixed a bug that made the scroller knob jump backwards when dragged (this
bug had no relation with the behavior that #define STRICT_NEXT_BEHAVIOUR
attempts to accomplish).
- fixed scrolling direction with mouse wheel for horizontal scroller.
changes since wmaker 0.63.1:
............................
- added WMRunModalLoop() and WMBreakModalLoop()
- added WMSetBoxExpandsToParent()
- added WMRemoveBoxSubview()
- moved WINGs headers in a WINGs subdirectory when installed.
use #include <WINGs/header_file_name> in your application from now on.
Also updated get-{wings|wutil}-flags.
- Fixed a mem leak in WMList.
- Fixed a bug that caused sigsegv for a WMList with more than 32767 items.
- Added an example of how to create a server type program with WMConnection.
- added WMOpenScreen()
changes since wmaker 0.62.1:
............................
- added WRuler widget
- added WText widget (rtf multiline text widget)
Nwanua Elumeze <nwanua@colorado.edu>
- added a new AUTO option for the UseMultiByte option
- added WMRaiseWidget()/WMLowerWidget()
- added missing EscapeTextMovement to textfield delegate/notification
- added WMGetLabelText()
- added WMReparentWidget()
- added WMCreateTabViewItem()
- added W_CreateUnmanagedTopView()
- added wtokenjoin(), wtokensplit(), wtokenfree(), wtrimspace()
- added WMWidgetIsMapped()
- added WMSetApplicationIconWindow()
- restructured the directory tree. Added Documentation, Examples and Tests
subdirectories
- removed WMArrayBag and reorganized WMTreeBag to be WMBag.
- added WMArray class.
- added WMSetWindowUserPosition()
- added WMGetListSelectedItems()
- added WMSetListAllowMultipleSelection(), WMListAllowsMultipleSelection().
- added WMSetListAllowEmptySelection(), WMListAllowsEmptySelection().
- WMListSelectionDidChangeNotification passes NULL as the notification
client data (previously passed the selected item row).
- added WMUnselectListItem(), WMSelectAllListItems(), WMUnselectAllListItems()
- better behavior of wheel mices in WMList. Simple mouse wheel events
will scroll by 1/3 of the WMList height. Using Shift as a modifier will
scroll line by line, while using Control as a modifier will scroll page
by page.
- better behavior of WMScroller regarding mouse wheel events. 'Shift' modifier
will scroll line by line, while 'Control' modifier will scroll page by page.
- fixed some buffer overflow allowing bugs.
- added WSDecrementWheel and WSIncrementWheel for handling mouse wheel in
scrollers and scrolled widgets. This should be treated like the WSxxxPage
counterparts, except it should scroll by page_size/3 instead of one full page
- added WMSetBrowserAllowMultipleSelection(), WMSetBrowserAllowEmptySelection()
WMBrowserAllowsMultipleSelection() and WMBrowserAllowsEmptySelection()
- WMBrowser now allows multiple selections.
- Added WMGetBrowserPaths() to retrieve the paths for browsers that allow
multiple selections.
- WMDestroyWidget() now calls WMUnmapWidget() first
- added WMScrollerDidScrollNotification to scroller
- added WMGetScrollViewVisibleRect()
- fixed a mem leak in the browser code.
- renamed wstrappend() to wstrconcat(). wstrconcat(str1, str2) concatenates
str1 with str2 and returns that in a newly malloc'ed string.
Be sure to rename wstrappend with wstrconcat in your code too, else
hazardous things can happen!
- implemented a new wstrappend() function. wstrappend(dst, src) will append
src to dst modifing dst and returning a pointer to it. No new string is
generated, except if dst is NULL, in which case its the same as calling
wstrdup(src).
dst can ONLY be NULL or a dynamically allocated string (obtained from a
call to malloc, realloc, wmalloc, wrealloc, ...). dst CANNOT be a static
or a constant string!
- added wmessage() for printing a variable formatted string to stderr, with
the program name prepended to it. Similar to wwarning(), except that it
doesn't add "warning:" in the output message.
- added WMBox widget
- added WMAddTabViewItemWithView()
- added W_SetViewCursor()
- made Extra widgets library
- added table widget in Extras library
- added WMGetConnectionUnsentData() (WMGetConnectionQueuedData() too as an
alias).
- added WMSetConnectionCloseOnExec() to specify if the socket associated
with a connection survives an exec* call or not. When a new connection is
created using the WMCreate... or WMAcceptConnection() calls, it has the
close on exec flag set automatically to 'True' by the library. Unless
you want to let the socket of some connection to survive across an exec*
call, you need not to call this function.
- removed all the wsyserror() and wwarning() calls from host.c and
connection.c and replaced where appropriate with assertions. If a function
returns some invalid result, you can still get the system error message if
you need, by calling wsyserrorwithcode() and passing WCErrorCode, if
WCErrorCode > 0. If WCErrorCode==0, that is not a system error, and
wsyserrorwithcode() should not be called in this case.
- added WMNextHashEnumeratorKey() to retrieve all keys in some hash enumerator
one by one.
- fixed a bug with mouse wheels scrolling in scrollers even with the widget
fully visible.
- Fixed a memory leak (the destroy function for a view was never called and
as a result the shaded windows didn't go away when closed. The non-shaded
windows were unmapped on close but not destroyed either so they only
apparently went away, but continued to use memory).
- Fixed a bug in the hashtable code which free'd the whole item instead of
just the item key in WMResetHashTable() (possible source of SIGSEGVs)
changes since wmaker 0.62.0:
............................
- added WMSetWidgetDefaultFont(), WMSetWidgetDefaultBoldFont()
changes since wmaker 0.62.0:
............................
- added WM{S,G}etDataFormat()
- added drag and drop
- changed selection code
- added clientdata to WMFindInBag
- removed SetWindowInitialSize()
- added SetWindowAspectRatio()
- added initial timeout when establishing a connection.
- added WMSetConnectionDefaultTimeout() and WMSetConnectionOpenTimeout();
- added WMGetConnectionTimeoutState()
changes since wmaker 0.61.1:
............................
- WARNING: semantic of bags has changed!
An index assigned to an item will always keep that index unless
you insert an item before it.
For example:
bag = WMCreateBag();
WMSetInBag(bag, 10, "bla");
That code will put "bla" in index 10, instead of 0, as it used to be.
- fixed WMInsertInBag(). It ignored index, and always put the new item at end.
- added WMSaveUserDefaults().
- rewrote WMPopUpButton to use WMMenuItem
- added WMGetPopUpButtonMenuItem(WMPopUpButton *bPtr, int index)
- WMSortListItemsWithComparer(WMList *lPtr, (int)(f)(const void*, const void*))
- WMSortBrowserColumnWithComparer()
- fixed bug with sorting list items.
- fixed bug in handling keyboard input associated with selection and
notification sending.
- filepanel puts dirs on top of list (Wolff <wolff@cybercable.fr>)
- added WMReplaceInBag (Wolff <wolff@cybercable.fr>)
- added vertical views and multiple views in WMSplitView (Wolff <wolff@cybercable.fr>)
- changed values of parameter values of WMSplitViewConstrainProc()
- configurable default fontsize patch (Igor P. Roboul <igor@mordor.myip.org>)
- fixed a bug that crashed the programm when a popup button was scrolled.
- fixed a bug that caused incorrect drawing position of the popup indicator.
- fixed a bug that prevented selecting no item (-1) in a popup button.
- an assertion will be raised if the program tries to select a popup button
item that is beyond the total number of items present in the popup button.
- changed names of functions for SplitView to be consistent. Some contained
SubView while other Subview. Now all have Subview.
- fixed a bug in how input events were posted. Establishing 2 or more input
handlers for the same file descriptor, handling different (read/write/except)
events, caused wrong handlers to be called.
- Reimplemented the input and idle handlers with WMBag to avoid a functional
problem with them: inability to remove handlers next to the called one, from
the called handler itself. Trying to do this with the old version caused the
program to crash.
- changed wrealloc behaviour to be like this: new = wrealloc(old, new_size);
1. if old is NULL, return wmalloc(new_size).
2. if new_size is 0, call wfree(old), and return NULL.
3. if both old is a valid pointer and new_size>0, call realloc.
- added wstrerror(int errnum) to return the string associated with errnum.
- new wsyserrorwithcode(int error, const char* fmt, ...), similar to
wsyserror(), but printing the message for the specified error code.
- added 3 new classes: WMData, WMHost and WMConnection
- fixed a big memory leak in the color panel code (from Pascal Hofstee).
- added scrolling to tabview
changes since wmaker 0.61.0:
............................
- added WMGetTextFieldFont()
- escape key in panels (craig nellist <crn@ozemail.com.au>)
- applied patch with fixes and enhancements to textfield
(Franck Wolff <wolff@cybercable.fr>)
- changed WMList to use WMBag internally, instead of a linked list
- replaced WMAddSortedListItem() with WMSortListItems()
- replaced WMAddSortedBrowserItem() with WMSortBrowserColumn()
changes since wmaker 0.60.0:
............................
- added WMScreenWidth() and WMScreenHeight() functions.
- fixed some problems when compiling with non gcc compilers.
- added WMSetTextFieldFont()
- added WMSetButtonImageDefault() (craig nellist <crn@ozemail.com.au>)
- added WMBag (array/list)
- added libWUtil, a library that is a subset of libWINGs. It contains utils
that can be used in writing non-GUI programs. They include: hashes,
notifications, input/idle/timer handlers, user defaults database handling,
memory handling, application resource handling, etc.
All the non-GUI stuff from libWINGs is present.
Still linWINGs contain all this stuff so if you use libWINGs, you don't
need to link against libWUtil too.
One notable aspect of libWUtil is that it has a modified version of the
event handling function. It is named WHandleEvents() and will handle all
input/idle/timer events the app has.
If your app has a permanent input handler (as for example a socket a server
is listening on), then the main loop of the app can be:
while(1) {
WHandleEvents();
}
but if there is no permanent input handler, you need to add some delay to
avoid a too high cpu load by your program:
while(1) {
WHandleEvents();
wusleep(5000);
}
A permanent input handler is one that is established when the program starts
and is present until the program exits.
One that is deleted and later reinstalled, is not considered permanent.
This difference is because if there is some input handler, the function will
block until some event appears, while if there is no input handler the
function will return almost immediately (after handling the timer/idle
stuff).
Except the stuff declared in WUtil.h, the following functions declared in
WINGs.h are also present in libWUtil (you will need to #include <WINGs.h>
if you use one of these):
WMInitializeApplication(char *applicationName, int *argc, char **argv);
WMSetResourcePath(char *path);
WMGetApplicationName();
WMPathForResourceOfType(char *resource, char *ext);
WMAddTimerHandler(int milliseconds, WMCallback *callback, void *cdata);
WMDeleteTimerWithClientData(void *cdata);
WMDeleteTimerHandler(WMHandlerID handlerID);
WMAddIdleHandler(WMCallback *callback, void *cdata);
WMDeleteIdleHandler(WMHandlerID handlerID);
WMAddInputHandler(int fd, int condition, WMInputProc *proc,
void *clientData);
WMDeleteInputHandler(WMHandlerID handlerID);
- added progress indicator widget
- Changed WMSetWindowUPosition() and WMSetWindowUSize() to
WMSetWindowInitialPosition() and WMSetWindowInitialSize() respectively,
for better naming conventions.
changes since wmaker 0.53.0:
............................
- added balloon help
- fixed a bug with setting initial path in browsers.
- added WMSetButtonImageDimsWhenDisabled()
- changed simple callback/notifications to delegate-like stuff. Affected
widgets are:
WMBrowser
- WMSetBrowserFillProc() was replaced with WMSetBrowserDelegate
- WMBrowserDidScrollNotification was replaced with a delegate callback
WMTextField (not completed yet)
The notifications will still work, but using the delegate is preferable
How to convert old code to delegate callbacks:
1 - create a variable (static or dynamic) of the type of the
delegate for the widget type.
2 - Replace the notification observers with the equivalent
delegate callbacks.
3 - Put pointers to the callbacks in the delegate variable.
Take a look in wfilepanel.c to see how it is used there.
- changed W_ViewProcedureTable to delegates
This will only affect user created widgets. If you have a custom
widget, you will need to update the callbacks and the declaration
of the W_ViewProcedureTable variable to be a W_ViewDelegate,
which is declared in WINGsP.h To setup the delegate, assign
the delegate variable to view->delegate.
- WMTextField
Removed all the didChange notifications that were sent when the text
was changed programmatically. Only changes made by user interaction
will be notified now. If you need the old behaviour, send notifications
manually when you change the text.
- added WMTabView
- added WMGetColorPanelColor(WMColorPanel *panel)
- made WMGetUDStringForKey() to only return a reference to the string, not a
wstrdup()'ed copy. DO NOT FREE IT ANYMORE!
- added MultiByteText option to userdefaults file to control use of multibyte
string drawing functions
- renamed WMCreateFont() to WMCreateFontSet()
- renamed WMCreateFontInDefaultEncoding() to WMCreateNormalFont()
- added WMCreateFont() with different semantics
changes since wmaker 0.52.0:
............................
- added int WMGetBrowserMaxVisibleColumns(WMBrowser *bPtr);
changes since wmaker 0.51.2:
............................
- added WMColorWellDidChangeNotification
- added wfindfileinarray()
- fixed bug in window title setting
(MANOME Tomonori <manome@itlb.te.noda.sut.ac.jp>)
changes since wmaker 0.51.1:
............................
- wusergnusteppath() will return a statically allocated string now.
DO NOT FREE IT ANYMORE!!
changes since wmaker 0.51.0:
............................
- applied c++ compat header patch from Martynas Kunigelis <mkunigelis@alna.lt>
- added WMSetTextFieldBeveled()
- removed W_GC() : use WMColorGC() instead
- added WMCreatePixmap()
- changed WMSetTextFieldEnabled() to WMSetTextFieldEditable()
changes since wmaker 0.50.1:
............................
- fixed various bugs
- added patch from Franck Wolff <frawolff@club-internet.fr>, with
many fixes and enhancements
- added notification queues, asynchronous notifications etc.
- added WMSetBrowserDoubleAction()
- fixed list double click action
changes since wmaker 0.50.2:
............................
- added wsetabort() - look WUtil.h
- fixed bug in WMList resize
- added notification sending when changing textfield programatically
- removed WMHideWindow()
- fixed bug in WMCloseWindow()
- added textfield selection patch
- added color panel code
- added auto name completion for the file panel
- added function to select text range, and to set cursor position in text
fields programatically
changes since wmaker 0.20.3:
............................
- added WMSetSliderImage(), WMSetSliderKnobThickness()
- added WMGetListItemHeight()
- added WMListDidScrollNotification
- added WSetColorWellBordered()
- added hacky color dragging in colorwell
- added poll() support in WMNextEvent. WARNING: the stuff needed for
WMAddInputHandler() is not yet implemented for the poll stuff
- added WMSetFilePanelAccessoryView(), WMGetFilePanelAccessoryView()
- added WMSetPopUpButtonEnabled()
- added WMGetLabelImage()
- autoscroll for popup button menus
- added WMDrawPixmap()
- WARNING: changed parameter list for WMListDrawProc
changes since wmaker 0.20.2:
............................
- WMSetBrowserMaxVisibleColumns() - untested
changes since wmaker 0.20.0:
............................
- added generic object field for WMListItem. This is for hanging generic
clientdata
changes since wmaker 0.20.0:
............................
- changed WMGetFilePanelFile() with WMGetFilePanelFileName()
- made SavePanel
changes since wmaker 0.19.3:
............................
- added WMCreatePanelForWindow()
- added extra parent parameter for filepanel, alertpanel and inputpanel
- WMCloseWindow()
- WMChangePanelOwner()
- added WMAddInputHandler()
- change range related function arguments (WMTextField) to use WMRange
changes since wmaker 0.19.1:
............................
- added wstrappend()
- fixed bug when changing selected radio button by hand
changes since wmaker 0.18.1:
............................
- removed textHeight arg from W_PaintImageAndText
- added WMCreateWindowWithStyle()
- added WMSetWindowBaseSize() and ResizeIncrements()
- added WMSetWindowLeve()
- added WMSetWindowDocumentEdited()
- added WMSetScrollViewLineScroll(), WMSetScrollViewPageScroll()
- added WMSetWindowMiniwindowTitle()
- added WMSetWindowMiniwindowImage()
changes since wmaker 0.18.0:
............................
- added functions to get RGB components and "#rrggbb" string from WMColor.
- added function to create color from a name
- fixed bug that caused blocking until some new event arrives, even
when there already were events in the queue
(like having to move the pointer over window to force the window to be
painted)
changes since wmaker 0.17.5:
............................
I don't remember everything, but here it goes:
- fixed some bugs in text field
- added a incomplete implementation of split view (not yet usable)
- added a slider
- changed the filepanel stuff. Each application can have only 1 file panel.
The same panel will be reused every time you call for it, unless you free it.
- changed semantics of WMCreateFont() so that it returns NULL if the requested
font can't be loaded
- removed WMAddDestroyCallback()
- fixed bug in WMRemovePopUpButtonItem()
- added function for user specified item height in WMList
- added WMSetPopUpButtonText(). It will set the default text in the button
when no options are selected
- fixed bug in remove/add item in already mapped popupbuttons. Note: it is
not good practice to change the contents of a popup button when it's
already visible and the user has probably interacted with it.
- fixed behaviour of "radio buttons"
- WMInitializeApplication() must be the first function to be called in the
program
- removed applicationName, argc and argv arguments from the WMCreateScree...
functions
- WMReleaseColor(scr,color) changed to WMReleaseColor(color)
- WMPaintColorRectangle() changed to WMPaintColorSwatch()
- added various functions in font and color handling
- added WMSetButtonFont()
- changed WMCreateCommandButton() so that the buttons it creates will change
their label when pushed
- added WMGetSystemPixmap(WMScreen *scr, int image)
- added partial I18N support
- added libPropList requirement and some related utility functions
- added a interface to prooplist, so that it works as a user defaults db
- added WMWidthOfString() (removed WMFontWidthOfString())
- added WMDrawString()
- added WMSetTextFieldSecure(WMTextField *tPtr, Bool flag)
- WMGetListItem() will dup the returned string
- removed need for ProgName being defined
- rewrote hashtable stuff and made it available for outside use
- added notification functions, with view resize notification
- added WMSetWindowMinSize() and MaxSize()
- text editing notification
- added WMSetListPosition() etc.
- added WMInsertBrowserItem()
- the above 2 functions return WMListItem*, instead of Bool
- rewrote browser
- WMGetListItem() will return WMListItem*
- removed WMGetListItems() and WMSetListItems()
- fixed focus stuff for multi-window apps
- changed all WMList function names that contained index to row

View File

@@ -0,0 +1,6 @@
## automake input file for WINGs - Documentation
AUTOMAKE_OPTIONS =
EXTRA_DIST =

View File

@@ -0,0 +1,21 @@
## automake input file for WINGs - Examples
AUTOMAKE_OPTIONS =
noinst_PROGRAMS = fontl puzzle colorpick
LDADD= $(top_builddir)/WINGs/libWINGs.la $(top_builddir)/wrlib/libwraster.la \
$(top_builddir)/WINGs/libWUtil.la \
@XFT_LIBS@ @INTLIBS@ @XLIBS@
colorpick_DEPENDENCIES = $(top_builddir)/WINGs/libWINGs.la
fontl_DEPENDENCIES = $(top_builddir)/WINGs/libWINGs.la
puzzle_DEPENDENCIES = $(top_builddir)/WINGs/libWINGs.la
AM_CPPFLAGS = -I$(top_srcdir)/WINGs -I$(top_srcdir)/wrlib -I$(top_srcdir)/src \
-DRESOURCE_PATH=\"$(datadir)/WINGs\" @HEADER_SEARCH_PATH@

View File

@@ -0,0 +1,12 @@
Files:
-----
colorpick - a color picker
puzzle - a nice zuPzel =)
fontl - a map of all characters with their corresponding ascii,
hex, decimal and octal representations.

View File

@@ -0,0 +1,40 @@
#include <stdlib.h>
#include <stdio.h>
#include <WINGs/WINGs.h>
void showSelectedColor(void *self, void *cdata)
{
WMColorPanel *panel = (WMColorPanel *) self;
(void) cdata;
printf("Selected Color: %s\n", WMGetColorRGBDescription(WMGetColorPanelColor(panel)));
}
int main(int argc, char **argv)
{
Display *dpy;
WMScreen *scr;
WMInitializeApplication("wmcolorpick", &argc, argv);
dpy = XOpenDisplay("");
if (!dpy) {
printf("could not open display\n");
exit(1);
}
scr = WMCreateScreen(dpy, DefaultScreen(dpy));
{
WMColorPanel *panel = WMGetColorPanel(scr);
WMSetColorPanelAction(panel, showSelectedColor, NULL);
WMShowColorPanel(panel);
}
WMScreenMainLoop(scr);
return 0;
}

View File

@@ -0,0 +1,100 @@
/*
* WINGs demo: font lister
*
* Copyright (c) 1998-2003 Alfredo K. Kojima
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <WINGs/WINGs.h>
#include <WINGs/WUtil.h>
#include <inttypes.h>
void wAbort()
{
exit(0);
}
void show(WMWidget * self, void *data)
{
char buf[60];
void *d;
WMLabel *l = (WMLabel *) data;
d = WMGetHangedData(self);
sprintf(buf, "%"PRIiPTR" - 0x%"PRIxPTR" - 0%"PRIoPTR, (intptr_t) d, (intptr_t) d, (intptr_t) d);
WMSetLabelText(l, buf);
}
void quit(WMWidget * self, void *data)
{
(void) self;
(void) data;
exit(0);
}
int main(int argc, char **argv)
{
Display *dpy;
WMWindow *win;
WMScreen *scr;
WMButton *lab, *l0 = NULL;
WMLabel *pos;
int x, y, c;
char buf[20];
WMInitializeApplication("FontView", &argc, argv);
dpy = XOpenDisplay("");
if (!dpy) {
wfatal("cant open display");
exit(0);
}
scr = WMCreateSimpleApplicationScreen(dpy);
win = WMCreateWindow(scr, "main");
WMResizeWidget(win, 20 * 33, 20 + 20 * 9);
WMSetWindowTitle(win, "Font Chars");
WMSetWindowCloseAction(win, quit, NULL);
pos = WMCreateLabel(win);
WMResizeWidget(pos, 20 * 33, 20);
WMMoveWidget(pos, 10, 5);
c = 0;
for (y = 0; y < 8; y++) {
for (x = 0; x < 32; x++, c++) {
lab = WMCreateCustomButton(win, WBBStateLightMask);
WMResizeWidget(lab, 20, 20);
WMMoveWidget(lab, 10 + x * 20, 30 + y * 20);
sprintf(buf, "%c", c);
WMSetButtonText(lab, buf);
WMSetButtonAction(lab, show, pos);
WMHangData(lab, (void *)(uintptr_t) c);
if (c > 0) {
WMGroupButtons(l0, lab);
} else {
l0 = lab;
}
}
}
WMRealizeWidget(win);
WMMapSubwidgets(win);
WMMapWidget(win);
WMScreenMainLoop(scr);
return 0;
}

View File

@@ -0,0 +1,236 @@
#include <stdlib.h>
#include <stdio.h>
#include <WINGs/WINGs.h>
#include <stdint.h>
#define MAX_SIZE 10*10
WMWindow *win;
WMButton *Button[MAX_SIZE];
signed char Map[MAX_SIZE];
int Size = 4;
int MoveCount;
#define MAP(x,y) Map[(x)+(y)*Size]
int WinSize = 120;
Bool CheckWin(void)
{
int i;
for (i = 0; i < Size * Size - 1; i++) {
if (Map[i] != i)
return False;
}
return True;
}
void MoveButton(int button, int x, int y)
{
WMMoveWidget(Button[button], x * (WinSize / Size), y * (WinSize / Size));
}
Bool SlideButton(int button)
{
int x = 0, y = 0, done = 0;
/* locate the button */
for (y = 0; y < Size; y++) {
for (x = 0; x < Size; x++) {
if (MAP(x, y) == button) {
done = 1;
break;
}
}
if (done)
break;
}
if (x > 0 && MAP(x - 1, y) < 0) {
MAP(x, y) = -1;
MoveButton(button, x - 1, y);
MAP(x - 1, y) = button;
} else if (x < Size - 1 && MAP(x + 1, y) < 0) {
MAP(x, y) = -1;
MoveButton(button, x + 1, y);
MAP(x + 1, y) = button;
} else if (y > 0 && MAP(x, y - 1) < 0) {
MAP(x, y) = -1;
MoveButton(button, x, y - 1);
MAP(x, y - 1) = button;
} else if (y < Size - 1 && MAP(x, y + 1) < 0) {
MAP(x, y) = -1;
MoveButton(button, x, y + 1);
MAP(x, y + 1) = button;
} else {
return False;
}
return True;
}
#define SWAP(a,b) {int tmp; tmp=a; a=b; b=tmp;}
void ResetGame(void)
{
int i, x, y, ox, oy;
MoveCount = 0;
for (i = 0; i < Size * Size - 1; i++) {
Map[i] = i;
}
Map[i] = -1;
ox = x = Size - 1;
oy = y = Size - 1;
for (i = 0; i < 1000; i++) {
int ok;
ok = 1;
switch (rand() % 4) {
case 0:
if (x > 0)
x--;
else
ok = 0;
break;
case 2:
if (x < Size - 1)
x++;
else
ok = 0;
break;
case 1:
if (y > 0)
y--;
else
ok = 0;
break;
case 3:
if (y < Size - 1)
y++;
else
ok = 0;
break;
}
if (ok) {
MoveButton(MAP(x, y), ox, oy);
SWAP(MAP(ox, oy), MAP(x, y));
while (XPending(WMScreenDisplay(WMWidgetScreen(win)))) {
XEvent ev;
WMNextEvent(WMScreenDisplay(WMWidgetScreen(win)), &ev);
WMHandleEvent(&ev);
}
ox = x;
oy = y;
}
}
}
void buttonClick(WMWidget * w, void *ptr)
{
char buffer[300];
if (SlideButton((uintptr_t)ptr)) {
MoveCount++;
if (CheckWin()) {
sprintf(buffer, "You finished the game in %i moves.", MoveCount);
if (WMRunAlertPanel(WMWidgetScreen(w), win, "You Won!", buffer,
"Wee!", "Gah! Lemme retry!", NULL) == WAPRDefault) {
exit(0);
}
ResetGame();
}
}
}
static void resizeObserver(void *self, WMNotification * notif)
{
WMSize size = WMGetViewSize(WMWidgetView(win));
int x, y;
(void) self;
(void) notif;
WinSize = size.width;
for (y = 0; y < Size; y++) {
for (x = 0; x < Size; x++) {
if (MAP(x, y) >= 0) {
WMResizeWidget(Button[(int)MAP(x, y)], WinSize / Size, WinSize / Size);
WMMoveWidget(Button[(int)MAP(x, y)], x * (WinSize / Size), y * (WinSize / Size));
}
}
}
}
int main(int argc, char **argv)
{
Display *dpy;
WMScreen *scr;
int x, y, i;
WMInitializeApplication("Puzzle", &argc, argv);
dpy = XOpenDisplay("");
if (!dpy) {
printf("could not open display\n");
exit(1);
}
scr = WMCreateScreen(dpy, DefaultScreen(dpy));
win = WMCreateWindow(scr, "puzzle");
WMResizeWidget(win, WinSize, WinSize);
WMSetWindowTitle(win, "zuPzel");
WMSetWindowMinSize(win, 80, 80);
WMSetWindowAspectRatio(win, 2, 2, 2, 2);
WMSetWindowResizeIncrements(win, Size, Size);
WMSetViewNotifySizeChanges(WMWidgetView(win), True);
WMAddNotificationObserver(resizeObserver, NULL, WMViewSizeDidChangeNotification, WMWidgetView(win));
for (i = y = 0; y < Size && i < Size * Size - 1; y++) {
for (x = 0; x < Size && i < Size * Size - 1; x++) {
char buf[32];
WMColor *color;
RColor col;
RHSVColor hsv;
hsv.hue = i * 360 / (Size * Size - 1);
hsv.saturation = 120;
hsv.value = 200;
RHSVtoRGB(&hsv, &col);
color = WMCreateRGBColor(scr, col.red << 8, col.green << 8, col.blue << 8, False);
MAP(x, y) = i;
Button[i] = WMCreateButton(win, WBTMomentaryLight);
WMSetWidgetBackgroundColor(Button[i], color);
WMReleaseColor(color);
WMSetButtonAction(Button[i], buttonClick, (void *)(uintptr_t) i);
WMResizeWidget(Button[i], WinSize / Size, WinSize / Size);
WMMoveWidget(Button[i], x * (WinSize / Size), y * (WinSize / Size));
sprintf(buf, "%i", i + 1);
WMSetButtonText(Button[i], buf);
WMSetButtonTextAlignment(Button[i], WACenter);
i++;
}
}
WMMapSubwidgets(win);
WMMapWidget(win);
WMRealizeWidget(win);
ResetGame();
WMScreenMainLoop(scr);
return 0;
}

View File

@@ -0,0 +1,30 @@
## automake input file for WINGs
AUTOMAKE_OPTIONS =
# is this a kluge? if so, how should i do it?
includedir = @includedir@/WINGs
include_HEADERS = wtableview.h wtabledelegates.h
lib_LTLIBRARIES = libExtraWINGs.la
noinst_PROGRAMS = tableview
EXTRA_DIST =
libExtraWINGs_la_SOURCES = \
wtableview.c \
wtabledelegates.c \
wtableview.h \
wtabledelegates.h
AM_CPPFLAGS = -I$(top_srcdir)/wrlib -I$(top_srcdir)/WINGs \
-DRESOURCE_PATH=\"$(datadir)/WINGs\" @HEADER_SEARCH_PATH@
LDADD= $(top_builddir)/WINGs/libWINGs.la $(top_builddir)/wrlib/libwraster.la \
$(top_builddir)/WINGs/libWUtil.la \
@XFT_LIBS@ @INTLIBS@ @XLIBS@
tableview_LDADD = wtableview.o wtabledelegates.o $(LDADD)

View File

@@ -0,0 +1,132 @@
#include <WINGs/WINGs.h>
#include <stdio.h>
#include <stdint.h>
#include "wtableview.h"
#include "wtabledelegates.h"
static char *col1[20] = { 0 };
static int col2[20];
static char *options[] = {
"Option1",
"Option2",
"Option3",
"Option4",
"Option5"
};
int numberOfRows(WMTableViewDelegate * self, WMTableView * table)
{
(void) self;
(void) table;
return 20;
}
void *valueForCell(WMTableViewDelegate * self, WMTableColumn * column, int row)
{
(void) self;
/*WMTableView *table = (WMTableView*)WMGetTableColumnTableView(column); */
int i;
if (col1[0] == 0) {
for (i = 0; i < 20; i++) {
char buf[128];
sprintf(buf, "Test row %i", i);
col1[i] = wstrdup(buf);
col2[i] = 0;
}
}
if ((uintptr_t)WMGetTableColumnId(column) == 1)
return col1[row];
else
return (void *)(uintptr_t) col2[row];
}
void setValueForCell(WMTableViewDelegate * self, WMTableColumn * column, int row, void *data)
{
(void) self;
if ((uintptr_t)WMGetTableColumnId(column) == 1)
col1[row] = data;
else
col2[row] = (uintptr_t) data;
}
static WMTableViewDelegate delegate = {
NULL,
numberOfRows,
valueForCell,
setValueForCell
};
void clickedTable(WMWidget * w, void *self)
{
(void) w;
int row = WMGetTableViewClickedRow((WMTableView *) self);
WMEditTableViewRow(self, row);
}
int main(int argc, char **argv)
{
WMScreen *scr;
WMWindow *win;
WMTableView *table;
WMTableColumn *col;
WMTableColumnDelegate *colDeleg;
WMInitializeApplication("test", &argc, argv);
scr = WMOpenScreen(NULL);
XSynchronize(WMScreenDisplay(scr), 1);
win = WMCreateWindow(scr, "eweq");
WMResizeWidget(win, 400, 200);
WMMapWidget(win);
table = WMCreateTableView(win);
WMSetTableViewHasHorizontalScroller(table, 0);
WMSetViewExpandsToParent(WMWidgetView(table), 10, 10, 10, 10);
WMSetTableViewBackgroundColor(table, WMWhiteColor(scr));
/*WMSetTableViewGridColor(table, WMGrayColor(scr)); */
WMSetTableViewHeaderHeight(table, 20);
WMSetTableViewDelegate(table, &delegate);
WMSetTableViewAction(table, clickedTable, table);
colDeleg = WTCreateStringEditorDelegate(table);
col = WMCreateTableColumn("Group");
WMSetTableColumnWidth(col, 180);
WMAddTableViewColumn(table, col);
WMSetTableColumnDelegate(col, colDeleg);
WMSetTableColumnId(col, (void *)1);
colDeleg = WTCreateEnumSelectorDelegate(table);
WTSetEnumSelectorOptions(colDeleg, options, 5);
col = WMCreateTableColumn("Package");
WMSetTableColumnWidth(col, 140);
WMAddTableViewColumn(table, col);
WMSetTableColumnDelegate(col, colDeleg);
WMSetTableColumnId(col, (void *)2);
colDeleg = WTCreateBooleanSwitchDelegate(table);
col = WMCreateTableColumn("Bool");
WMSetTableColumnWidth(col, 50);
WMAddTableViewColumn(table, col);
WMSetTableColumnDelegate(col, colDeleg);
WMSetTableColumnId(col, (void *)2);
WMMapWidget(table);
WMRealizeWidget(win);
WMScreenMainLoop(scr);
return 0;
}

View File

@@ -0,0 +1,522 @@
#include <stdint.h>
#include <WINGs/WINGsP.h>
#include "wtableview.h"
#include "wtabledelegates.h"
typedef struct {
WMTableView *table;
WMFont *font;
GC gc;
GC selGC;
WMColor *textColor;
} StringData;
typedef struct {
WMTableView *table;
GC selGc;
} PixmapData;
typedef struct {
WMTextField *widget;
WMTableView *table;
WMFont *font;
GC gc;
GC selGC;
WMColor *textColor;
} StringEditorData;
typedef struct {
WMPopUpButton *widget;
WMTableView *table;
WMFont *font;
char **options;
int count;
GC gc;
GC selGC;
WMColor *textColor;
} EnumSelectorData;
typedef struct {
WMButton *widget;
WMTableView *table;
Bool state;
GC gc;
GC selGC;
} BooleanSwitchData;
static char *SelectionColor = "#bbbbcc";
static void
stringDraw(WMScreen * scr, Drawable d, GC gc, GC sgc, WMColor * textColor,
WMFont * font, void *data, WMRect rect, Bool selected)
{
int x, y;
XRectangle rects[1];
Display *dpy = WMScreenDisplay(scr);
x = rect.pos.x + 5;
y = rect.pos.y + (rect.size.height - WMFontHeight(font)) / 2;
rects[0].x = rect.pos.x + 1;
rects[0].y = rect.pos.y + 1;
rects[0].width = rect.size.width - 1;
rects[0].height = rect.size.height - 1;
XSetClipRectangles(dpy, gc, 0, 0, rects, 1, YXSorted);
if (!selected) {
XFillRectangles(dpy, d, gc, rects, 1);
WMDrawString(scr, d, textColor, font, x, y, data, strlen(data));
} else {
XFillRectangles(dpy, d, sgc, rects, 1);
WMDrawString(scr, d, textColor, font, x, y, data, strlen(data));
}
XSetClipMask(dpy, gc, None);
}
static void pixmapDraw(WMScreen * scr, Drawable d, GC gc, GC sgc, WMPixmap * pixmap, WMRect rect, Bool selected)
{
int x, y;
XRectangle rects[1];
Display *dpy = WMScreenDisplay(scr);
WMSize size;
rects[0].x = rect.pos.x + 1;
rects[0].y = rect.pos.y + 1;
rects[0].width = rect.size.width - 1;
rects[0].height = rect.size.height - 1;
XSetClipRectangles(dpy, gc, 0, 0, rects, 1, YXSorted);
if (!selected) {
XFillRectangles(dpy, d, gc, rects, 1);
if (pixmap) {
size = WMGetPixmapSize(pixmap);
x = rect.pos.x + (rect.size.width - size.width) / 2;
y = rect.pos.y + (rect.size.height - size.height) / 2;
WMDrawPixmap(pixmap, d, x, y);
}
} else {
XFillRectangles(dpy, d, sgc, rects, 1);
if (pixmap) {
size = WMGetPixmapSize(pixmap);
x = rect.pos.x + (rect.size.width - size.width) / 2;
y = rect.pos.y + (rect.size.height - size.height) / 2;
WMDrawPixmap(pixmap, d, x, y);
}
}
XSetClipMask(dpy, gc, None);
}
/* ---------------------------------------------------------------------- */
static void SECellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
{
StringEditorData *strdata = (StringEditorData *) self->data;
WMTableView *table = WMGetTableColumnTableView(column);
stringDraw(WMWidgetScreen(table), d,
strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
WMTableViewDataForCell(table, column, row), WMTableViewRectForCell(table, column, row), False);
}
static void selectedSECellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
{
StringEditorData *strdata = (StringEditorData *) self->data;
WMTableView *table = WMGetTableColumnTableView(column);
stringDraw(WMWidgetScreen(table), d,
strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
WMTableViewDataForCell(table, column, row), WMTableViewRectForCell(table, column, row), True);
}
static void beginSECellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
{
StringEditorData *strdata = (StringEditorData *) self->data;
WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
void *data = WMTableViewDataForCell(strdata->table, column, row);
WMSetTextFieldText(strdata->widget, (char *)data);
WMMoveWidget(strdata->widget, rect.pos.x, rect.pos.y);
WMResizeWidget(strdata->widget, rect.size.width + 1, rect.size.height + 1);
WMMapWidget(strdata->widget);
}
static void endSECellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
{
StringEditorData *strdata = (StringEditorData *) self->data;
char *text;
WMUnmapWidget(strdata->widget);
text = WMGetTextFieldText(strdata->widget);
WMSetTableViewDataForCell(strdata->table, column, row, (void *)text);
}
WMTableColumnDelegate *WTCreateStringEditorDelegate(WMTableView * parent)
{
WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
WMScreen *scr = WMWidgetScreen(parent);
StringEditorData *data = wmalloc(sizeof(StringEditorData));
data->widget = WMCreateTextField(parent);
W_ReparentView(WMWidgetView(data->widget), WMGetTableViewDocumentView(parent), 0, 0);
data->table = parent;
data->font = WMSystemFontOfSize(scr, 12);
data->gc = WMColorGC(WMWhiteColor(scr));
data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
data->textColor = WMBlackColor(scr);
delegate->data = data;
delegate->drawCell = SECellPainter;
delegate->drawSelectedCell = selectedSECellPainter;
delegate->beginCellEdit = beginSECellEdit;
delegate->endCellEdit = endSECellEdit;
return delegate;
}
/* ---------------------------------------------------------------------- */
static void ESCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
{
EnumSelectorData *strdata = (EnumSelectorData *) self->data;
WMTableView *table = WMGetTableColumnTableView(column);
uintptr_t i = (uintptr_t)WMTableViewDataForCell(table, column, row);
stringDraw(WMWidgetScreen(table), d,
strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
strdata->options[i], WMTableViewRectForCell(table, column, row), False);
}
static void selectedESCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
{
EnumSelectorData *strdata = (EnumSelectorData *) self->data;
WMTableView *table = WMGetTableColumnTableView(column);
uintptr_t i = (uintptr_t)WMTableViewDataForCell(table, column, row);
stringDraw(WMWidgetScreen(table), d,
strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
strdata->options[i], WMTableViewRectForCell(table, column, row), True);
}
static void beginESCellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
{
EnumSelectorData *strdata = (EnumSelectorData *) self->data;
WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
uintptr_t data = (uintptr_t)WMTableViewDataForCell(strdata->table, column, row);
wassertr(data < strdata->count);
WMSetPopUpButtonSelectedItem(strdata->widget, data);
WMMoveWidget(strdata->widget, rect.pos.x, rect.pos.y);
WMResizeWidget(strdata->widget, rect.size.width, rect.size.height + 1);
WMMapWidget(strdata->widget);
}
static void endESCellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
{
EnumSelectorData *strdata = (EnumSelectorData *) self->data;
int option;
WMUnmapWidget(strdata->widget);
option = WMGetPopUpButtonSelectedItem(strdata->widget);
WMSetTableViewDataForCell(strdata->table, column, row, (void *)(uintptr_t) option);
}
WMTableColumnDelegate *WTCreateEnumSelectorDelegate(WMTableView * parent)
{
WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
WMScreen *scr = WMWidgetScreen(parent);
EnumSelectorData *data = wmalloc(sizeof(EnumSelectorData));
data->widget = WMCreatePopUpButton(parent);
W_ReparentView(WMWidgetView(data->widget), WMGetTableViewDocumentView(parent), 0, 0);
data->table = parent;
data->font = WMSystemFontOfSize(scr, 12);
data->gc = WMColorGC(WMWhiteColor(scr));
data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
data->textColor = WMBlackColor(scr);
data->count = 0;
data->options = NULL;
delegate->data = data;
delegate->drawCell = ESCellPainter;
delegate->drawSelectedCell = selectedESCellPainter;
delegate->beginCellEdit = beginESCellEdit;
delegate->endCellEdit = endESCellEdit;
return delegate;
}
void WTSetEnumSelectorOptions(WMTableColumnDelegate * delegate, char **options, int count)
{
EnumSelectorData *data = (EnumSelectorData *) delegate->data;
int i;
for (i = 0; i < WMGetPopUpButtonNumberOfItems(data->widget); i++) {
WMRemovePopUpButtonItem(data->widget, 0);
}
data->options = options;
data->count = count;
for (i = 0; i < count; i++) {
WMAddPopUpButtonItem(data->widget, options[i]);
}
}
/* ---------------------------------------------------------------------- */
static void BSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
{
BooleanSwitchData *strdata = (BooleanSwitchData *) self->data;
WMTableView *table = WMGetTableColumnTableView(column);
uintptr_t i = (uintptr_t)WMTableViewDataForCell(table, column, row);
WMScreen *scr = WMWidgetScreen(table);
if (i) {
pixmapDraw(scr, d,
strdata->gc, strdata->selGC, WMGetSystemPixmap(scr, WSICheckMark),
WMTableViewRectForCell(table, column, row), False);
} else {
pixmapDraw(scr, d,
strdata->gc, strdata->selGC, NULL, WMTableViewRectForCell(table, column, row), False);
}
}
static void selectedBSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
{
BooleanSwitchData *strdata = (BooleanSwitchData *) self->data;
WMTableView *table = WMGetTableColumnTableView(column);
uintptr_t i = (uintptr_t)WMTableViewDataForCell(table, column, row);
WMScreen *scr = WMWidgetScreen(table);
if (i) {
pixmapDraw(scr, d,
strdata->gc, strdata->selGC, WMGetSystemPixmap(scr, WSICheckMark),
WMTableViewRectForCell(table, column, row), True);
} else {
pixmapDraw(scr, d,
strdata->gc, strdata->selGC, NULL, WMTableViewRectForCell(table, column, row), True);
}
}
static void beginBSCellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
{
BooleanSwitchData *strdata = (BooleanSwitchData *) self->data;
WMRect rect = WMTableViewRectForCell(strdata->table, column, row);
uintptr_t data = (uintptr_t)WMTableViewDataForCell(strdata->table, column, row);
WMSetButtonSelected(strdata->widget, data);
WMMoveWidget(strdata->widget, rect.pos.x + 1, rect.pos.y + 1);
WMResizeWidget(strdata->widget, rect.size.width - 1, rect.size.height - 1);
WMMapWidget(strdata->widget);
}
static void endBSCellEdit(WMTableColumnDelegate * self, WMTableColumn * column, int row)
{
BooleanSwitchData *strdata = (BooleanSwitchData *) self->data;
int value;
value = WMGetButtonSelected(strdata->widget);
WMSetTableViewDataForCell(strdata->table, column, row, (void *)(uintptr_t) value);
WMUnmapWidget(strdata->widget);
}
WMTableColumnDelegate *WTCreateBooleanSwitchDelegate(WMTableView * parent)
{
WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
WMScreen *scr = WMWidgetScreen(parent);
BooleanSwitchData *data = wmalloc(sizeof(BooleanSwitchData));
WMColor *color;
data->widget = WMCreateSwitchButton(parent);
W_ReparentView(WMWidgetView(data->widget), WMGetTableViewDocumentView(parent), 0, 0);
WMSetButtonText(data->widget, NULL);
WMSetButtonImagePosition(data->widget, WIPImageOnly);
WMSetButtonImage(data->widget, NULL);
WMSetButtonAltImage(data->widget, WMGetSystemPixmap(scr, WSICheckMark));
data->table = parent;
color = WMCreateNamedColor(scr, SelectionColor, False);
WMSetWidgetBackgroundColor(data->widget, color);
data->gc = WMColorGC(WMWhiteColor(scr));
data->selGC = WMColorGC(color);
delegate->data = data;
delegate->drawCell = BSCellPainter;
delegate->drawSelectedCell = selectedBSCellPainter;
delegate->beginCellEdit = beginBSCellEdit;
delegate->endCellEdit = endBSCellEdit;
return delegate;
}
/* ---------------------------------------------------------------------- */
static void SCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
{
StringData *strdata = (StringData *) self->data;
WMTableView *table = WMGetTableColumnTableView(column);
stringDraw(WMWidgetScreen(table), d,
strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
WMTableViewDataForCell(table, column, row), WMTableViewRectForCell(table, column, row), False);
}
static void selectedSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
{
StringData *strdata = (StringData *) self->data;
WMTableView *table = WMGetTableColumnTableView(column);
stringDraw(WMWidgetScreen(table), d,
strdata->gc, strdata->selGC, strdata->textColor, strdata->font,
WMTableViewDataForCell(table, column, row), WMTableViewRectForCell(table, column, row), True);
}
WMTableColumnDelegate *WTCreateStringDelegate(WMTableView * parent)
{
WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
WMScreen *scr = WMWidgetScreen(parent);
StringData *data = wmalloc(sizeof(StringData));
data->table = parent;
data->font = WMSystemFontOfSize(scr, 12);
data->gc = WMColorGC(WMWhiteColor(scr));
data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
data->textColor = WMBlackColor(scr);
delegate->data = data;
delegate->drawCell = SCellPainter;
delegate->drawSelectedCell = selectedSCellPainter;
delegate->beginCellEdit = NULL;
delegate->endCellEdit = NULL;
return delegate;
}
/* ---------------------------------------------------------------------- */
static void PCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
{
StringData *strdata = (StringData *) self->data;
WMTableView *table = WMGetTableColumnTableView(column);
pixmapDraw(WMWidgetScreen(table), d,
strdata->gc, strdata->selGC,
(WMPixmap *) WMTableViewDataForCell(table, column, row),
WMTableViewRectForCell(table, column, row), False);
}
static void selectedPCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
{
StringData *strdata = (StringData *) self->data;
WMTableView *table = WMGetTableColumnTableView(column);
pixmapDraw(WMWidgetScreen(table), d,
strdata->gc, strdata->selGC,
(WMPixmap *) WMTableViewDataForCell(table, column, row),
WMTableViewRectForCell(table, column, row), True);
}
WMTableColumnDelegate *WTCreatePixmapDelegate(WMTableView * table)
{
WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
WMScreen *scr = WMWidgetScreen(table);
StringData *data = wmalloc(sizeof(StringData));
data->table = table;
data->gc = WMColorGC(WMWhiteColor(scr));
data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
delegate->data = data;
delegate->drawCell = PCellPainter;
delegate->drawSelectedCell = selectedPCellPainter;
delegate->beginCellEdit = NULL;
delegate->endCellEdit = NULL;
return delegate;
}
/* ---------------------------------------------------------------------- */
static void drawPSCell(WMTableColumnDelegate * self, Drawable d, WMTableColumn * column, int row, Bool selected)
{
StringData *strdata = (StringData *) self->data;
WMTableView *table = WMGetTableColumnTableView(column);
void **data;
WMPixmap *pix;
char *str;
WMRect rect;
WMSize size;
data = WMTableViewDataForCell(table, column, row);
str = (char *)data[0];
pix = (WMPixmap *) data[1];
rect = WMTableViewRectForCell(table, column, row);
if (pix) {
int owidth = rect.size.width;
size = WMGetPixmapSize(pix);
rect.size.width = size.width;
pixmapDraw(WMWidgetScreen(table),
WMViewXID(WMGetTableViewDocumentView(table)),
strdata->gc, strdata->selGC, pix, rect, selected);
rect.pos.x += size.width - 1;
rect.size.width = owidth - size.width + 1;
}
stringDraw(WMWidgetScreen(table), d, strdata->gc, strdata->selGC,
strdata->textColor, strdata->font, str, rect, selected);
}
static void PSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
{
drawPSCell(self, d, column, row, False);
}
static void selectedPSCellPainter(WMTableColumnDelegate * self, WMTableColumn * column, int row, Drawable d)
{
drawPSCell(self, d, column, row, True);
}
WMTableColumnDelegate *WTCreatePixmapStringDelegate(WMTableView * parent)
{
WMTableColumnDelegate *delegate = wmalloc(sizeof(WMTableColumnDelegate));
WMScreen *scr = WMWidgetScreen(parent);
StringData *data = wmalloc(sizeof(StringData));
data->table = parent;
data->font = WMSystemFontOfSize(scr, 12);
data->gc = WMColorGC(WMWhiteColor(scr));
data->selGC = WMColorGC(WMCreateNamedColor(scr, SelectionColor, False));
data->textColor = WMBlackColor(scr);
delegate->data = data;
delegate->drawCell = PSCellPainter;
delegate->drawSelectedCell = selectedPSCellPainter;
delegate->beginCellEdit = NULL;
delegate->endCellEdit = NULL;
return delegate;
}

View File

@@ -0,0 +1,25 @@
#ifndef _TABLEDELEGATES_H_
#define _TABLEDELEGATES_H_
#ifdef __cplusplus
extern "C" {
#endif
WMTableColumnDelegate *WTCreatePixmapDelegate(WMTableView *table);
WMTableColumnDelegate *WTCreateStringDelegate(WMTableView *table);
WMTableColumnDelegate *WTCreatePixmapStringDelegate(WMTableView *parent);
WMTableColumnDelegate *WTCreateStringEditorDelegate(WMTableView *table);
WMTableColumnDelegate *WTCreateEnumSelectorDelegate(WMTableView *table);
void WTSetEnumSelectorOptions(WMTableColumnDelegate *delegate,
char **options, int count);
WMTableColumnDelegate *WTCreateBooleanSwitchDelegate(WMTableView *parent);
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,121 @@
#ifndef _WTABLEVIEW_H_
#define _WTABLEVIEW_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef struct W_TableColumn WMTableColumn;
typedef struct W_TableView WMTableView;
extern const char *WMTableViewSelectionDidChangeNotification;
typedef struct WMTableColumnDelegate {
void *data;
void (*drawCell)(struct WMTableColumnDelegate *self,
WMTableColumn *column, int row, Drawable d);
void (*drawSelectedCell)(struct WMTableColumnDelegate *self,
WMTableColumn *column, int row, Drawable d);
void (*beginCellEdit)(struct WMTableColumnDelegate *self, WMTableColumn *column,
int row);
void (*endCellEdit)(struct WMTableColumnDelegate *self, WMTableColumn *column,
int row);
} WMTableColumnDelegate;
typedef struct W_TableViewDelegate {
void *data;
int (*numberOfRows)(struct W_TableViewDelegate *self,
WMTableView *table);
void *(*valueForCell)(struct W_TableViewDelegate *self,
WMTableColumn *column, int row);
void (*setValueForCell)(struct W_TableViewDelegate *self,
WMTableColumn *column, int row, void *value);
} WMTableViewDelegate;
WMTableColumn *WMCreateTableColumn(char *title);
void WMSetTableColumnWidth(WMTableColumn *column, unsigned width);
void WMSetTableColumnConstraints(WMTableColumn *column,
unsigned minWidth, unsigned maxWidth);
void WMSetTableColumnDelegate(WMTableColumn *column,
WMTableColumnDelegate *delegate);
WMTableView *WMGetTableColumnTableView(WMTableColumn *column);
void WMSetTableColumnId(WMTableColumn *column, void *id);
void *WMGetTableColumnId(WMTableColumn *column);
WMTableView *WMCreateTableView(WMWidget *parent);
void WMSetTableViewDataSource(WMTableView *table, void *source);
void *WMGetTableViewDataSource(WMTableView *table);
void WMSetTableViewHeaderHeight(WMTableView *table, unsigned height);
void WMAddTableViewColumn(WMTableView *table, WMTableColumn *column);
void WMSetTableViewDelegate(WMTableView *table, WMTableViewDelegate *delegate);
void WMSetTableViewAction(WMTableView *table, WMAction *action,
void *clientData);
void *WMGetTableViewClickedColumn(WMTableView *table);
int WMGetTableViewClickedRow(WMTableView *table);
WMArray *WMGetTableViewSelectedRows(WMTableView *table);
WMView *WMGetTableViewDocumentView(WMTableView *table);
void WMEditTableViewRow(WMTableView *table, int row);
void WMSelectTableViewRow(WMTableView *table, int row);
void *WMTableViewDataForCell(WMTableView *table, WMTableColumn *column,
int row);
void WMSetTableViewDataForCell(WMTableView *table, WMTableColumn *column,
int row, void *data);
WMRect WMTableViewRectForCell(WMTableView *table, WMTableColumn *column,
int row);
void WMSetTableViewBackgroundColor(WMTableView *table, WMColor *color);
void WMSetTableViewGridColor(WMTableView *table, WMColor *color);
void WMSetTableViewRowHeight(WMTableView *table, int height);
void WMReloadTableView(WMTableView *table);
void WMNoteTableViewNumberOfRowsChanged(WMTableView *table);
void WMScrollTableViewRowToVisible(WMTableView *table, int row);
void WMSetTableViewHasHorizontalScroller(WMTableView *tPtr, Bool flag);
#ifdef __cplusplus
}
#endif
#endif

119
bazel/WINGs/Makefile.am Normal file
View File

@@ -0,0 +1,119 @@
## automake input file for WINGs
AUTOMAKE_OPTIONS =
SUBDIRS = WINGs . po Documentation Resources
DIST_SUBDIRS = $(SUBDIRS) Tests Examples Extras
libWINGs_la_LDFLAGS = -version-info @WINGS_VERSION@
libWUtil_la_LDFLAGS = -version-info @WUTIL_VERSION@
lib_LTLIBRARIES = libWUtil.la libWINGs.la
LDADD= libWUtil.la libWINGs.la $(top_builddir)/wrlib/libwraster.la @INTLIBS@
libWINGs_la_LIBADD = libWUtil.la $(top_builddir)/wrlib/libwraster.la @XLIBS@ @XFT_LIBS@ @FCLIBS@ @LIBM@ @PANGO_LIBS@
libWUtil_la_LIBADD = @LIBBSD@
EXTRA_DIST = BUGS make-rgb Examples Extras Tests
# wbutton.c
libWINGs_la_SOURCES = \
configuration.c \
dragcommon.c \
dragdestination.c \
dragsource.c \
rgb.h \
selection.c \
wappresource.c \
wballoon.c \
wbox.c \
wbrowser.c \
wbutton.c \
wcolor.c \
wcolorpanel.c \
wcolorwell.c \
wconfig.h \
wevent.c \
wfilepanel.c \
wframe.c \
wfont.c \
wfontpanel.c \
widgets.c \
winputmethod.c \
wlabel.c \
wlist.c \
wmenuitem.c \
wmisc.c \
wpanel.c \
wpixmap.c \
wpopupbutton.c \
wprogressindicator.c \
wruler.c \
wscroller.c \
wscrollview.c \
wslider.c \
wsplitview.c \
wtabview.c \
wtext.c \
wtextfield.c \
wview.c \
wwindow.c
libWUtil_la_SOURCES = \
array.c \
bagtree.c \
data.c \
error.c \
error.h \
findfile.c \
handlers.c \
hashtable.c \
memory.c \
menuparser.c \
menuparser.h \
menuparser_macros.c \
misc.c \
notification.c \
proplist.c \
string.c \
tree.c \
userdefaults.c \
userdefaults.h \
usleep.c \
wapplication.c \
wconfig.h \
wutil.c
AM_CFLAGS = @PANGO_CFLAGS@
AM_CPPFLAGS = -DRESOURCE_PATH=\"$(datadir)/WINGs\" \
-I$(top_srcdir)/WINGs/WINGs -I$(top_builddir)/WINGs/WINGs \
-I$(top_builddir)/wrlib -I$(top_srcdir)/src \
@XFT_CFLAGS@ @HEADER_SEARCH_PATH@
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = WINGs.pc WUtil.pc
DISTCLEANFILES = $(pkgconfig_DATA)
WINGs.pc: Makefile
@echo "Generating $@"
@echo 'Name: WINGs' > $@
@echo 'Description: Small widget set with the NeXTStep(TM) look and feel' >> $@
@echo 'Version: $(VERSION)' >> $@
@echo 'Requires: wrlib WUtil' >> $@
@echo 'Libs: $(lib_search_path) -lWINGs' >> $@
@echo 'Libs.private: $(XFT_LIBS) $(PANGOLIBS) $(XLIBS) -lm $(INTLIBS)' >> $@
@echo 'Cflags: $(inc_search_path) @PANGO_CFLAGS@' >> $@
WUtil.pc: Makefile
@echo "Generating $@"
@echo 'Name: WUtil' > $@
@echo 'Description: Utility library for WINGs' >> $@
@echo 'Version: $(VERSION)' >> $@
@echo 'Libs: -L$(libdir) -lWUtil' >> $@
@echo 'Libs.private: $(INTLIBS)' >> $@
@echo 'Cflags: -I$(includedir)' >> $@

514
bazel/WINGs/NEWS Normal file
View File

@@ -0,0 +1,514 @@
** API and ABI modifications since wmaker 0.96.0
----------------------------------------------------
** libWINGs **
<WINGsP.h>
W_KeycodeToKeysym ADDED
struct W_DragDestinationInfo: new members added SIZE CHANGE
<WINGs.h>
WMGetTextFieldCursorPosition ADDED
WC_Matrix REMOVED from enum.
WMCreateProgressIndicator REMOVED
WMSetProgressIndicatorMinValue REMOVED
WMSetProgressIndicatorMaxValue REMOVED
WMSetProgressIndicatorValue REMOVED
WMGetProgressIndicatorMinValue REMOVED
WMGetProgressIndicatorMaxValue REMOVED
WMGetProgressIndicatorValue REMOVED
typedef struct W_Ruler WMRuler REMOVED
typedef struct WMRulerMargins REMOVED
WMAppendTextBlock REMOVED
WMAppendTextStream REMOVED
WMCreateRuler REMOVED
WMCreateTextBlockWithObject REMOVED
WMCreateTextBlockWithPixmap REMOVED
WMCreateTextBlockWithText REMOVED
WMCreateTextForDocumentType REMOVED
WMDestroyTextBlock REMOVED
WMFindInTextStream REMOVED
WMFreezeText REMOVED
WMGetGrabbedRulerMargin REMOVED
WMGetReleasedRulerMargin REMOVED
WMGetRulerMargins REMOVED
WMGetRulerOffset REMOVED
WMGetTextBlockProperties REMOVED
WMGetTextDefaultColor REMOVED
WMGetTextDefaultFont REMOVED
WMGetTextEditable REMOVED
WMGetTextIgnoresNewline REMOVED
WMGetTextInsertType REMOVED
WMGetTextObjects REMOVED
WMGetTextRulerShown REMOVED
WMGetTextSelectedObjects REMOVED
WMGetTextSelectedStream REMOVED
WMGetTextSelectionColor REMOVED
WMGetTextSelectionFont REMOVED
WMGetTextSelectionUnderlined REMOVED
WMGetTextStream REMOVED
WMGetTextUsesMonoFont REMOVED
WMIsMarginEqualToMargin REMOVED
WMPageText REMOVED
WMPrependTextBlock REMOVED
WMPrependTextStream REMOVED
WMRemoveTextBlock REMOVED
WMReplaceTextSelection REMOVED
WMScrollText REMOVED
WMSetRulerMargins REMOVED
WMSetRulerMoveAction REMOVED
WMSetRulerOffset REMOVED
WMSetRulerReleaseAction REMOVED
WMSetTextAlignment REMOVED
WMSetTextBackgroundColor REMOVED
WMSetTextBackgroundPixmap REMOVED
WMSetTextBlockProperties REMOVED
WMSetTextDefaultColor REMOVED
WMSetTextDefaultFont REMOVED
WMSetTextDelegate REMOVED
WMSetTextEditable REMOVED
WMSetTextForegroundColor REMOVED
WMSetTextHasHorizontalScroller REMOVED
WMSetTextHasRuler REMOVED
WMSetTextHasVerticalScroller REMOVED
WMSetTextIgnoresNewline REMOVED
WMSetTextIndentNewLines REMOVED
WMSetTextRelief REMOVED
WMSetTextSelectionColor REMOVED
WMSetTextSelectionFont REMOVED
WMSetTextSelectionUnderlined REMOVED
WMSetTextUsesMonoFont REMOVED
WMShowTextRuler REMOVED
WMThawText REMOVED
WMRefreshText REMOVED
WMCreateText REMOVED
WMClearText REMOVED
** libWutil **
enum WMConnectionState REMOVED
enum WMConnectionTimeoutState REMOVED
struct ConnectionDelegate REMOVED
__wmessage ADDED
wstrerror REMOVED
wmessage converted from function to wrapper macro
wwarning converted from function to wrapper macro
wfatal converted from function to wrapper macro
wsyserror converted from function to wrapper macro
wsyserror REMOVED (use werror instead)
werror macro ADDED (replaces wsyserror)
wsyserrorwithcode removed
wmkdirhier ADDED
wrmdirhier ADDED
wmalloc0 REMOVED
wnew REMOVED
wnew0 REMOVED
wstrlcpy ADDED
wstrlcat ADDED
WMPushInArray REMOVED
WMWritePropListToFile NUMBER OF FUNCTION ARGUMENTS CHANGED
WMGetCurrentHost
WMGetHostWithName
WMGetHostWithAddress
WMRetainHost
WMReleaseHost
WMSetHostCacheEnabled
WMIsHostCacheEnabled
WMFlushHostCache
WMIsHostEqualToHost
WMGetHostName
WMGetHostNames
WMGetHostAddress
WMCreateConnectionAsServerAtAddress REMOVED
WMCreateConnectionToAddress REMOVED
WMCreateConnectionToAddressAndNotify REMOVED
WMCloseConnection REMOVED
WMDestroyConnection REMOVED
WMConnection* WMAcceptConnection REMOVED
WMGetConnectionAvailableData REMOVED
WMSendConnectionData REMOVED
WMEnqueueConnectionData REMOVED
WMFlushConnection REMOVED
WMSetConnectionDelegate REMOVED
WMGetConnectionService REMOVED
WMGetConnectionProtocol REMOVED
WMSetConnectionNonBlocking REMOVED
WMSetConnectionCloseOnExec REMOVED
WMSetConnectionShutdownOnClose REMOVED
WMGetConnectionClientData REMOVED
WMSetConnectionClientData REMOVED
WMGetConnectionFlags REMOVED
WMSetConnectionFlags REMOVED
WMGetConnectionSocket REMOVED
WMGetConnectionState REMOVED
WMGetConnectionTimeoutState REMOVED
WMGetConnectionUnsentData REMOVED
WMGetConnectionQueuedData REMOVED
WMSetConnectionDefaultTimeout REMOVED
WMSetConnectionOpenTimeout REMOVED
WMSetConnectionSendTimeout REMOVED
WMTreeWalkProc ADDED
WMTreeWalk ADDED
wshellquote ADDED
----------------------------------------------------
*** Fri May 15 18:44:50 CEST 2015 - Christophe
New Tri-state type for WMButton
-------------------------------
A new check-box type button is available with state On/Off/Tri, the later being
generally used to express "leave as-is". The states are cycled through as user
click on the button. It is created with:
btn = WMCreateButton(parent_widget, WBTTriState);
There are is this case 3 possible values for WMSetButtonSelected/WMGetButtonSelected:
- 0 and 1, the legacy checked/unchecked states
- the new -1, when in the 3rd state
*** Sun Dec 7 10:52:21 CET 2014 - David
Support for pixmap in the background of Widget
----------------------------------------------
The new function WMSetWidgetBackgroundPixmap was introduced to specify a pixmap
that will be displayed as the background of a widget instead of the usual plain
color. The dual WMGetWidgetBackgroundPixmap is provided too.
*** Sun Nov 2 13:04:14 CET 2014 - David
Get the text of a button
------------------------
It was assumed that there was no need to retrieve the text from a button because
it is generally a static constant text, but there are some cases where this can
be useful, so the new function WMGetButtonText was added to the API.
*** Thu May 9 18:24:03 CEST 2013 - Christophe
Const-correctness API changes for WRaster, WUtils and WINGs
-----------------------------------------------------------
The 3 libraries have been modified to include appropriate 'const' qualifier
to the function parameters that are treated as such. This should provide
some hints to the compiler for better optimisation.
This change should have no impact on the binary interface, and will not
impact existing source code.
There is one exception however:
WUtil: wusergnusteppath()
This function now returns 'const char *' because its result must *not* be
modified, so it may generate a const related warning in old code.
*** Fri Mar 7 00:39:28 CET 2014 - David
New function WMCreateScaledBlendedPixmapFromFile
------------------------------------------------
This function can load an image from a file and if it is bigger than the
specified width/height then it will be scaled down to fit the size while
keeping the aspect ratio of the original image.
*** Mon Oct 14 19:42:42 EEST 2002 - Dan
Double buffering
----------------
To avoid flickering caused by redrawing the widgets on Expose events, a
double buffering technique was implemented for most of the widgets.
This flickering effect has gotten more visible with the introduction
of antialiased fonts. If with normal text one can redraw the text over the
old one over and over again without any degradation of the text (new pixels
simply overwrite old pixels), with antialiased text the situation is
different and text gets quickly corrupted. To avoid this corruption, one
needs to first erase the area where the text will go, which can cause the
before mentioned flickering.
The double buffer is implemented to solve this issue.
This is a change that that will be automatically available for any WINGs
applications and will require no change in the existing code.
However there is an exception from this in case of WMList if you delegate
the drawing of items to userspace (read below for the complete details).
*** Mon Oct 14 22:07:42 EEST 2002 - Dan
WMList change
-------------
In case of WMList there is the possibility to delegate the drawing of the
list items to the application that is linked with WINGs, and this code will
not be inside the WINGs library, but in userland. Since we use the double
buffering technique in this case too (to allow all widgets based on WMList
and the ones that draw their list items by themselves to benefit from the
double buffering advantage automatically), we no longer pass the window to
the user code doing item drawing, but instead pass this pixmap in which we
draw before copying to the real window.
Since one cannot use XClearWindow() or XClearArea() on pixmaps, but only on
windows, if the code drawing list items used to call these functions to clear
the item area before drawing it needs to change to using XFillRectangle()
instead.
With this change it also means that there is no longer any need to do any
double buffering in the user code, since it's already done by WINGs.
*** Mon Oct 14 19:28:35 EEST 2002 - Dan
API change
----------
WMDrawString() and WMDrawImageString() no longer take a GC as argument.
Instead WMDrawString() takes a WMColor* as the color for the string to be
drawn, while WMDrawImageString() takes 2 WMColor* arguments in place of the
old GC: first for text color and second for background color.
This change is required to support extending WMFont to allow it to handle
antialiased fonts through the XFree86 Xft2 extension.
This also has the advantage of hiding low level X11 details and use WINGs
internal objects instead.
To fix your old code to work with the new WINGs API you need to replace the
GC passed to WMDraw***String() in your code with a WMColor*.
Most of the old code used to be like this:
WMDrawString(screen, window, WMColorGC(color), font, x, y, txt, len);
for the new API it should be replaced by:
WMDrawString(screen, window, color, font, x, y, txt, len);
However if you used a particular GC created by yourself to suit your special
needs, you need to pass a color which is the same as the foreground color of
that gc.
For WMDrawImageString(), from:
WMDrawImageString(screen, window, gc, font, x, y, txt, len);
becomes
WMDrawImageString(screen, window, textColor, backColor, font, x, y, txt, len);
where textColor and backColor are declared like:
WMColor *textColor, *backColor;
and have the color of the foreground respective the background of the old gc.
*** Wed Oct 9 07:10:04 EEST 2002 - Dan
Antialiased font support
------------------------
With the addition of Xft2 support in the WINGs library, now WINGs can display
antialiased text with TrueType or any scalable fonts.
Antialiased text is enabled by default, but can be disabled by adding
AntialiasedText = NO; in ~/GNUstep/Defaults/WMGLOBAL
This will disable antialiased text for any WINGs based application. If you
only want to disable them for a specific application only, like WindowMaker
for example, then add the same option in the applications configuration file,
in this case ~/GNUstep/Defaults/WindowMaker
Note that bitmapped fonts look much better than TrueType when antialiasing is
disabled.
*** Mon Sep 09 06:58:30 EEST 2002 - Dan
New delegate for the WMConnection class
---------------------------------------
ConnectionDelegate structure has a new member: canResumeSending.
The purpose of this callback is to notify you that you can resume sending
data over a WMConnection.
It works in the following manner:
WMSendConnectionData() can return 3 values: -1, 0, 1
-1 - means that the connection has died. you should stop sending data and
close the connection ASAP.
1 - means that the data was successfully sent
0 - means that the data (or part of it) was not sent. however, it was saved
in a queue and the library will try to send it later when possible.
if the return value is 1, you can continue to send the next message, and so
on, until the return value of such a send call will be 0.
After it returns 0 you can continue sending, however, the data will not be
sent over the connection because the operating system cannot accept any more
data for the moment. Instead it will be queued inside the library, making your
program's memory footprint increase. If the amount of data you need to
send is limited and not too big, this shouldn't be a problem, because your
data will be queued and sent when the operating system will notify the
library that sending is possible again.
If this is the case you can just ignore the output of WMSendConnectionData()
and not set a callback for canResumeSending.
However, if the amount of data you have to send is undetermined and you
also want to keep a small memory footprint for your program (so that it
won't grow until it uses all your available memory ;) ), you will have to
stop sending data over the connection as soon as WMSendConnectionData()
returns with 0. Then you should somehow mark this situation in your program
to avoid it trying to send anymore data until notified that it can resume.
(You should have also set a canResumeSending callback when you initialized
your WMConnection object because else you cannot be notified when to resume.)
Now, when you receive such a 0 from the send operation, your last sent data
is put in a queue inside the library. At a later time when the operating
system notifies the library that sending is possible again, the library will
resume to send the data that is saved in the queue. After it will be able to
send all the data in the queue, the canResumeSending callback will be
called, letting you know that not only you can resume sending because the
operating system is again able to send data, but also that the queue was
completely flushed.
From the canResumeSending callback, you should again update the status of
your program marking that it can send again, and then resume sending the
data from where you were left.
*** Thu Oct 04 06:00:09 EEST 2001 -Dan
Property lists handling code
----------------------------
Code to handle property lists was added to WINGs. It is more robust
than the libPropList code, mostly because some conflicting concepts
borrowed from UserDefaults (which libPropList use) are no longer used in
the WINGs property lists code. These borrowed concepts conflicted with the
retain/release mechanism of property lists and could lead in certain cases
to segmentation faults when executing libPropList based code. But the worse
part was that these libPropList problems were practically unsolvable without
removing one of those conflicting concepts and without a complete redesign.
The new WINGs property lists code is also better integrated with the other
data types from WINGs and is actively maintained.
Practically the things that were removed from the WINGs property list
implementation compared to the old libPropList implementation, are exactly
the UserDefaults borrowed concepts that conflict with the retain/release
mechanism:
- The container of a proplist object and the associated functions are gone.
- The filename associated with a proplist object and the corresponding
functions are gone. Now the saving function needs the filename as a
parameter.
- The synchronization functions are no longer supported. They are part of
the UserDefaults and are implemented there.
- No functions related to domains/registering were implemented in the WINGs
property lists code, because they are also not part of property lists.
They are more in connection with UserDefaults and a central point of access
for domains.
The above 2 concepts: container and filename were added to libPropList just
to let it support synchronization which was borrowed from UserDefaults.
Property lists as defined in the openstep specification are just complex
data structures composed of strings, data, arrays, dictionaries and a mix of
them and are not associated with any file in particular. UserDefaults on the
other hand are property lists read from a specific file and they associate
that property list with that file and allow them to be synchronized.
Old libPropList based code can still be used by linking against the WINGs
library containing the new proplist code with minimal changes which are
described in detail in the comments at the top of the WINGs/proplist-compat.h
header file (the same file carries the #defines for mapping old libPropList
functions to the new WINGs proplist functions).
Our recommendation is to move to the new functions WINGs provide because
they better integrate with other function naming conventions in WINGs.
The proplist-compat.h header file is just a way to have old code up and
running with minimal changes so that we can remove the old and unmaintained
libPropList from systems while keeping to use old libPropList based code
without rewriting it and it should not be used for other purposes.
*** Sat Apr 21 09:12:09 EEST 2001 -Dan
API change
----------
To allow a correct display of icon images with alpha blending in panels and
other places where a WINGs based application may use them the following
changes took place:
1. The following functions were renamed:
- WMSetApplicationIconImage() --> WMSetApplicationIconPixmap()
- WMGetApplicationIconImage() --> WMGetApplicationIconPixmap()
- WMSetWindowMiniwindowImage() --> WMSetWindowMiniwindowPixmap()
2. The following functions were added:
- WMSetApplicationIconImage(WMScreen *scr, RImage *image)
- RImage* WMGetApplicationIconImage(WMScreen *scr)
- WMPixmap* WMCreateApplicationIconBlendedPixmap(WMScreen *scr, RColor *col)
As you can see the old functions that operated on WMPixmap images (which are
basically X Pixmaps that lack alpha information) were renamed to ...Pixmap()
to make them more suggestive about what they do and to make room for the
new functions that operate on RImages (that hold alpha information).
Since the corresponding WMGet... functions only retrieve the stored
image/pixmap from the application, I'll outline how the WMSet...
functions operate:
All WM...IconPixmap() functions operate on WMPixmaps
All WM...IconImage() functions operate on RImages
- WMSetApplicationIconImage() will set the RImage to be used in panels
and will also convert the RImage to a WMPixmap with a threshold of 128
and will use that pixmap for the appicon image. If that doesn't satisfy
you, you can make a call to WMSetApplicationIconPixmap() on your own to
set whatever WMPixmap you see fit for the appicon.
- WMSetApplicationIconPixmap() will set the WMPixmap to be used for the
appicon and for the panels
If you use only one of the above functions, the corresponding image/pixmap
will be used everywhere where needed (panels and appicon), but the pixmap
version will not be able to handle alpha blending correctly.
If you use both WMSetApplicationIconImage() and WMSetApplicationIconPixmap()
then the RImage will have priority in panels, and the WMPixmap will only be
used for the appicon. This allows you to better control what icon is
displayed in the appicon, in case the default conversion of the RImage to a
pixmap with a threshold of 128 is not good enough, or in case you want a
different icon to be shown in the appicon than in panels.
Also this new function was added:
- WMCreateApplicationIconBlendedPixmap() will use the RImage set with
WMSetApplicationIconImage() if available and will blend it with the color
you passed. This will make the image show well on a background of that
color. If the RImage was not set it will return NULL. You need to call
WMReleasePixmap() on it after you finish with it. Passing a NULL pointer
instead of a color will make the RImage be blended with the default color
of the WINGs widgets: '#aeaaae' making it suitable to be assigned to any
WINGs widget.
To make your existing code work as before all you need to do is to rename
the following functions:
- WMSetApplicationIconImage() --> WMSetApplicationIconPixmap()
- WMGetApplicationIconImage() --> WMGetApplicationIconPixmap()
- WMSetWindowMiniwindowImage() --> WMSetWindowMiniwindowPixmap()
But if you want to take advantage of the new abilities to show alpha
blended images you need to start using the new functions.

97
bazel/WINGs/README Normal file
View File

@@ -0,0 +1,97 @@
WINGs - WINGs Is Not GNUstep
by
Alfredo Kengi Kojima
kojima@windowmaker.info
WINGs is a small widget set with the N*XTSTEP look and feel. Its API
is inspired in OpenStep and its implementation borrows some ideas
from Tk. It has a reasonable set of widgets, sufficient for building
small applications (like a CDPlayer or hacking something like rxvt). It
also has other functions that are usefull for applications, like a
User Defaults alike configuration manager and a notification system.
The library is limited and its design is a little sloppy,
so it's not intended to build large or complex applications, like
anything more complex than a CDPlayer. GNUstep should be used for such
applications.
Since WINGs is written in C and is sort of low-level it is small
and faster than say, Motif or even Athena. Knowing Xlib will help you to
workaround some of its limitations, although you'll probably be able to
write something like a trivial tic-tac-toe game without knowing much Xlib.
Some of its functions are designed to support the Window Maker window
manager (see http://windowmaker.info) In fact, its primary role is to
support Window Maker. All other uses of it are just an added bonus.
It will help you to understand the API if you read the ApplicationKit
reference manual, distributed as a PDF by Apple. The function names,
structs and most of the intrinsics are very close to OpenStep classes.
Internationalization:
---------------------
Change ~/GNUstep/Defaults/WMGLOBAL to set the desired font set and
set MultiByteText = YES; to enable support for multibyte text.
Widgets provided by WINGs:
--------------------------
- button (command button, radio, switch etc. - all buttons defined in OpenStep)
- label
- textfield
- frame
- window
- popup menu button
- scroller
- selection list
- browser
- slider
- scrollable view
- color well
- split view
- tabbed view
- progress indicator
- selection (make pasteboard like?)
- drag&drop
- input box
- file panel
- color panel
- alert panel
- font panel
If you think you can code the following, please do. They are needed by
WPrefs.app, but the number of other things I have to do is huge.
- input method support (XIM). I have no idea of how to code it. People who use
different characters than ASCII will have trouble editing menus without it...
Wish list: (I don't have the know-how or time to do them)
---------------------------------------------------------
- text (with support for RTF)
- matrix (like NSMatrix)
- font manager (like NSFontManager)
- finish other wigets
- optimize list scrolling (XCopyArea() the area that's already drawn)
- InterfaceMaker?
- use XSetWMName and XSetWMIconName for the window/icon title setting.
This requires transforming the received text to a text property with
the proper encoding.
Copyright
---------
WINGs is copyright (c) Alfredo K. Kojima and is licensed through the GNU
Library General Public License (LGPL).

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,6 @@
resdatadir = $(datadir)/WINGs
resdata_DATA = Images.tiff Images.xpm defaultIcon.tiff defaultIcon.xpm
EXTRA_DIST = $(resdata_DATA) Images.xcf

Binary file not shown.

View File

@@ -0,0 +1,54 @@
/* XPM */
static char * defaultIcon_xpm[] = {
"48 48 3 1",
" c #000000000000",
". c None",
"X c #FFFFFFFFFFFF",
" ..",
" ..",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ..",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ..",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ",
" ",
" ",
".... ",
".... "};

14
bazel/WINGs/TODO Normal file
View File

@@ -0,0 +1,14 @@
- move paint to idle handlers
- check if its useful to add some WMBrowserSelectionDidChangeNotification
(actually a pass-through for WMListSelectionDidChangeNotification).
Or a delegate to be called when the list selection change.
- add some way to modify speed when scrolling WMList, depending on how
far the mouse is moved outside of the list.
- clean up header files of declared but not implemented anywhere functions
- implement a generic WMChangeFontAttribute(WMFont *font, enum attributes)
function
- optimize color allocation for repeated colors
- make it work in 8bpp
- optimize SystemFont allocation for repeated font sizes

Some files were not shown because too many files have changed in this diff Show More