# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1019464475 0 # Node ID eeb98f881663c443fef3ce0500eb1d905d8fd987 # Parent ec311fe773da7bf7438a374c5449c471940ccf36 Committed the dw_window_set/get_data() changes from the FX tree. diff -r ec311fe773da -r eeb98f881663 dw.def --- a/dw.def Fri Apr 19 17:52:38 2002 +0000 +++ b/dw.def Mon Apr 22 08:34:35 2002 +0000 @@ -218,3 +218,5 @@ dw_slider_query_pos @391 dw_slider_set_pos @392 + dw_window_set_data @400 + dw_window_get_data @401 diff -r ec311fe773da -r eeb98f881663 dw.h --- a/dw.h Fri Apr 19 17:52:38 2002 +0000 +++ b/dw.h Mon Apr 22 08:34:35 2002 +0000 @@ -21,6 +21,13 @@ #define SPLITBAR_WIDTH 3 #define BUBBLE_HELP_MAX 256 +typedef struct _user_data +{ + struct _user_data *next; + void *data; + char *varname; +} UserData; + #if defined(__OS2__) || defined(__EMX__) #define INCL_DOS #define INCL_WIN @@ -119,6 +126,7 @@ typedef struct _window_data { PFNWP oldproc; + UserData *root; HWND clickdefault; ULONG flags; void *data; @@ -272,6 +280,7 @@ HBRUSH hbrush; char fontname[128]; WNDPROC pOldProc; + UserData *root; } ColorInfo; typedef struct _notebookpage { @@ -327,6 +336,7 @@ ColorInfo cinfo; #elif defined(__OS2__) || defined(__EMX__) PFNWP oldproc; + UserData *root; HWND hwndtitle; int titlebar; #endif @@ -356,14 +366,14 @@ #if defined(__WIN32__) || defined(WINNT) ColorInfo cinfo; int checkbox; + WNDPROC pOldProc; +#endif +#if defined(__OS2__) || defined(__EMX__) + PFNWP pOldProc; + UserData *root; #endif unsigned long id; char bubbletext[BUBBLE_HELP_MAX]; -#if defined(__OS2__) || defined(__EMX__) - PFNWP pOldProc; -#else - WNDPROC pOldProc; -#endif } BubbleButton; void dw_box_pack_start_stub(HWND box, HWND item, int width, int height, int hsize, int vsize, int pad); @@ -767,6 +777,8 @@ DWDialog *dw_dialog_new(void *data); int dw_dialog_dismiss(DWDialog *dialog, void *result); void *dw_dialog_wait(DWDialog *dialog); +void dw_window_set_data(HWND window, char *dataname, void *data); +void *dw_window_get_data(HWND window, char *dataname); #ifndef NO_SIGNALS void dw_signal_connect(HWND window, char *signame, void *sigfunc, void *data); void dw_signal_disconnect_by_window(HWND window); diff -r ec311fe773da -r eeb98f881663 dww.def --- a/dww.def Fri Apr 19 17:52:38 2002 +0000 +++ b/dww.def Mon Apr 22 08:34:35 2002 +0000 @@ -215,3 +215,5 @@ dw_slider_query_pos @391 dw_slider_set_pos @392 + dw_window_set_data @400 + dw_window_get_data @401 diff -r ec311fe773da -r eeb98f881663 gtk/dw.c --- a/gtk/dw.c Fri Apr 19 17:52:38 2002 +0000 +++ b/gtk/dw.c Mon Apr 22 08:34:35 2002 +0000 @@ -5778,6 +5778,46 @@ windowfunc(data); } +/* + * Add a named user data item to a window handle. + * Parameters: + * window: Window handle of signal to be called back. + * dataname: A string pointer identifying which signal to be hooked. + * data: User data to be passed to the handler function. + */ +void dw_window_set_data(HWND window, char *dataname, void *data) +{ + int _locked_by_me = FALSE; + + if(!window) + return; + + DW_MUTEX_LOCK; + gtk_object_set_data(GTK_OBJECT(window), dataname, (gpointer)data); + DW_MUTEX_UNLOCK; +} + +/* + * Gets a named user data item to a window handle. + * Parameters: + * window: Window handle of signal to be called back. + * dataname: A string pointer identifying which signal to be hooked. + * data: User data to be passed to the handler function. + */ +void *dw_window_get_data(HWND window, char *dataname) +{ + int _locked_by_me = FALSE; + void *ret; + + if(!window) + return; + + DW_MUTEX_LOCK; + ret = (void *)gtk_object_set_data(GTK_OBJECT(window), dataname); + DW_MUTEX_UNLOCK; + return ret; +} + #ifndef NO_SIGNALS /* * Add a callback to a window event. diff -r ec311fe773da -r eeb98f881663 os2/dw.c --- a/os2/dw.c Fri Apr 19 17:52:38 2002 +0000 +++ b/os2/dw.c Mon Apr 22 08:34:35 2002 +0000 @@ -250,6 +250,7 @@ if(ptr) { + dw_window_set_data(handle, NULL, NULL); WinSetWindowPtr(handle, QWP_USER, 0); free(ptr); } @@ -3752,7 +3753,7 @@ */ HWND dw_status_text_new(char *text, ULONG id) { - PFNWP *blah = malloc(sizeof(PFNWP)); + WindowData *blah = calloc(sizeof(WindowData), 1); HWND tmp = WinCreateWindow(HWND_OBJECT, WC_STATIC, text, @@ -3766,7 +3767,7 @@ dw_window_set_font(tmp, DefaultFont); dw_window_set_color(tmp, DW_CLR_BLACK, DW_CLR_PALEGRAY); - *blah = WinSubclassWindow(tmp, _statusproc); + blah->oldproc = WinSubclassWindow(tmp, _statusproc); WinSetWindowPtr(tmp, QWP_USER, blah); return tmp; } @@ -3894,7 +3895,7 @@ */ HWND dw_button_new(char *text, ULONG id) { - BubbleButton *bubble = malloc(sizeof(BubbleButton)); + BubbleButton *bubble = calloc(sizeof(BubbleButton), 1); HWND tmp = WinCreateWindow(HWND_OBJECT, WC_BUTTON, @@ -3959,7 +3960,7 @@ { char idbuf[256]; HWND tmp; - BubbleButton *bubble = malloc(sizeof(BubbleButton)); + BubbleButton *bubble = calloc(sizeof(BubbleButton), 1); _GenResIDStr(idbuf, id); @@ -3993,7 +3994,7 @@ */ HWND dw_spinbutton_new(char *text, ULONG id) { - PFNWP *blah = malloc(sizeof(PFNWP)); + WindowData *blah = calloc(sizeof(WindowData), 1); HWND tmp = WinCreateWindow(HWND_OBJECT, WC_SPINBUTTON, text, @@ -4005,7 +4006,7 @@ NULL, NULL); dw_window_set_font(tmp, DefaultFont); - *blah = WinSubclassWindow(tmp, _entryproc); + blah->oldproc = WinSubclassWindow(tmp, _entryproc); WinSetWindowPtr(tmp, QWP_USER, blah); return tmp; } @@ -4018,7 +4019,7 @@ */ HWND dw_radiobutton_new(char *text, ULONG id) { - PFNWP *blah = malloc(sizeof(PFNWP)); + WindowData *blah = calloc(sizeof(WindowData), 1); HWND tmp = WinCreateWindow(HWND_OBJECT, WC_BUTTON, text, @@ -4032,7 +4033,7 @@ NULL); dw_window_set_font(tmp, DefaultFont); dw_window_set_color(tmp, DW_CLR_BLACK, DW_CLR_PALEGRAY); - *blah = WinSubclassWindow(tmp, _entryproc); + blah->oldproc = WinSubclassWindow(tmp, _entryproc); WinSetWindowPtr(tmp, QWP_USER, blah); return tmp; } @@ -4095,7 +4096,7 @@ */ HWND dw_checkbox_new(char *text, ULONG id) { - BubbleButton *bubble = malloc(sizeof(BubbleButton)); + BubbleButton *bubble = calloc(sizeof(BubbleButton), 1); HWND tmp = WinCreateWindow(HWND_OBJECT, WC_BUTTON, text, @@ -4123,7 +4124,7 @@ */ HWND dw_listbox_new(ULONG id, int multi) { - PFNWP *blah = malloc(sizeof(PFNWP)); + WindowData *blah = calloc(sizeof(WindowData), 1); HWND tmp = WinCreateWindow(HWND_OBJECT, WC_LISTBOX, NULL, @@ -4136,7 +4137,7 @@ NULL, NULL); dw_window_set_font(tmp, DefaultFont); - *blah = WinSubclassWindow(tmp, _entryproc); + blah->oldproc = WinSubclassWindow(tmp, _entryproc); WinSetWindowPtr(tmp, QWP_USER, blah); return tmp; } @@ -7052,6 +7053,136 @@ WinSendMsg(handle, WM_USER, (MPARAM)function, (MPARAM)data); } +/* Functions for managing the user data lists that are associated with + * a given window handle. Used in dw_window_set_data() and + * dw_window_get_data(). + */ +UserData *find_userdata(UserData **root, char *varname) +{ + UserData *tmp = *root; + + while(tmp) + { + if(stricmp(tmp->varname, varname) == 0) + return tmp; + tmp = tmp->next; + } + return NULL; +} + +int new_userdata(UserData **root, char *varname, void *data) +{ + UserData *new = find_userdata(root, varname); + + if(new) + { + new->data = data; + return TRUE; + } + else + { + new = malloc(sizeof(UserData)); + if(new) + { + new->varname = strdup(varname); + new->data = data; + + new->next = NULL; + + if (!*root) + *root = new; + else + { + UserData *prev = NULL, *tmp = *root; + while(tmp) + { + prev = tmp; + tmp = tmp->next; + } + if(prev) + prev->next = new; + else + *root = new; + } + return TRUE; + } + } + return FALSE; +} + +int remove_userdata(UserData **root, char *varname, int all) +{ + UserData *prev = NULL, *tmp = *root; + + while(tmp) + { + if(all || stricmp(tmp->varname, varname) == 0) + { + if(!prev) + { + free(tmp->varname); + free(tmp); + *root = NULL; + return 0; + } + else + { + prev->next = tmp->next; + free(tmp->varname); + free(tmp); + return 0; + } + } + tmp = tmp->next; + } + return 0; +} + +/* + * Add a named user data item to a window handle. + * Parameters: + * window: Window handle of signal to be called back. + * dataname: A string pointer identifying which signal to be hooked. + * data: User data to be passed to the handler function. + */ +void dw_window_set_data(HWND window, char *dataname, void *data) +{ + WindowData *blah = (WindowData *)WinQueryWindowPtr(window, QWP_USER); + + if(blah) + { + if(data) + new_userdata(&(blah->root), dataname, data); + else + { + if(dataname) + remove_userdata(&(blah->root), dataname, FALSE); + else + remove_userdata(&(blah->root), NULL, TRUE); + } + } +} + +/* + * Gets a named user data item to a window handle. + * Parameters: + * window: Window handle of signal to be called back. + * dataname: A string pointer identifying which signal to be hooked. + * data: User data to be passed to the handler function. + */ +void *dw_window_get_data(HWND window, char *dataname) +{ + WindowData *blah = (WindowData *)WinQueryWindowPtr(window, QWP_USER); + + if(blah && blah->root && dataname) + { + UserData *ud = find_userdata(&(blah->root), dataname); + if(ud) + return ud->data; + } + return NULL; +} + #ifndef NO_SIGNALS /* * Add a callback to a window event. diff -r ec311fe773da -r eeb98f881663 win/dw.c --- a/win/dw.c Fri Apr 19 17:52:38 2002 +0000 +++ b/win/dw.c Mon Apr 22 08:34:35 2002 +0000 @@ -351,11 +351,18 @@ if(thiscinfo) { + /* Delete the brush so as not to leak GDI objects */ if(thiscinfo->hbrush) DeleteObject(thiscinfo->hbrush); + /* Free user data linked list memory */ + if(thiscinfo->root) + dw_window_set_data(handle, NULL, NULL); + SetWindowLong(handle, GWL_USERDATA, 0); +#if 0 free(thiscinfo); +#endif } return TRUE; } @@ -3291,12 +3298,13 @@ HWND dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) { HWND hwndframe; - Box *newbox = malloc(sizeof(Box)); + Box *newbox = calloc(sizeof(Box), 1); ULONG flStyleEx = 0; newbox->pad = 0; newbox->type = BOXVERT; newbox->count = 0; + newbox->cinfo.fore = newbox->cinfo.back = -1; if(hwndOwner) flStyleEx |= WS_EX_MDICHILD; @@ -3336,13 +3344,14 @@ */ HWND dw_box_new(int type, int pad) { - Box *newbox = malloc(sizeof(Box)); + Box *newbox = calloc(sizeof(Box), 1); HWND hwndframe; newbox->pad = pad; newbox->type = type; newbox->count = 0; newbox->grouphwnd = (HWND)NULL; + newbox->cinfo.fore = newbox->cinfo.back = -1; hwndframe = CreateWindow(FRAMECLASSNAME, "", @@ -3369,12 +3378,13 @@ */ HWND dw_groupbox_new(int type, int pad, char *title) { - Box *newbox = malloc(sizeof(Box)); + Box *newbox = calloc(sizeof(Box), 1); HWND hwndframe; newbox->pad = pad; newbox->type = type; newbox->count = 0; + newbox->cinfo.fore = newbox->cinfo.back = -1; hwndframe = CreateWindow(FRAMECLASSNAME, "", @@ -3887,8 +3897,12 @@ ColorInfo *cinfo = (ColorInfo *)calloc(1, sizeof(ColorInfo)); ColorInfo *cinfo2 = (ColorInfo *)calloc(1, sizeof(ColorInfo)); - if(!cinfo) + if(!cinfo || !cinfo2) { + if(cinfo) + free(cinfo); + if(cinfo2) + free(cinfo2); DestroyWindow(tmp); return NULL; } @@ -6029,7 +6043,7 @@ */ HWND dw_render_new(unsigned long id) { - Box *newbox = malloc(sizeof(Box)); + Box *newbox = calloc(sizeof(Box), 1); HWND tmp = CreateWindow(ObjectClassName, "", WS_CHILD | WS_CLIPCHILDREN, @@ -6938,6 +6952,136 @@ SendMessage(handle, WM_USER, (WPARAM)function, (LPARAM)data); } +/* Functions for managing the user data lists that are associated with + * a given window handle. Used in dw_window_set_data() and + * dw_window_get_data(). + */ +UserData *find_userdata(UserData **root, char *varname) +{ + UserData *tmp = *root; + + while(tmp) + { + if(stricmp(tmp->varname, varname) == 0) + return tmp; + tmp = tmp->next; + } + return NULL; +} + +int new_userdata(UserData **root, char *varname, void *data) +{ + UserData *new = find_userdata(root, varname); + + if(new) + { + new->data = data; + return TRUE; + } + else + { + new = malloc(sizeof(UserData)); + if(new) + { + new->varname = strdup(varname); + new->data = data; + + new->next = NULL; + + if (!*root) + *root = new; + else + { + UserData *prev = NULL, *tmp = *root; + while(tmp) + { + prev = tmp; + tmp = tmp->next; + } + if(prev) + prev->next = new; + else + *root = new; + } + return TRUE; + } + } + return FALSE; +} + +int remove_userdata(UserData **root, char *varname, int all) +{ + UserData *prev = NULL, *tmp = *root; + + while(tmp) + { + if(all || stricmp(tmp->varname, varname) == 0) + { + if(!prev) + { + free(tmp->varname); + free(tmp); + *root = NULL; + return 0; + } + else + { + prev->next = tmp->next; + free(tmp->varname); + free(tmp); + return 0; + } + } + tmp = tmp->next; + } + return 0; +} + +/* + * Add a named user data item to a window handle. + * Parameters: + * window: Window handle of signal to be called back. + * dataname: A string pointer identifying which signal to be hooked. + * data: User data to be passed to the handler function. + */ +void dw_window_set_data(HWND window, char *dataname, void *data) +{ + ColorInfo *cinfo = (ColorInfo *)GetWindowLong(window, GWL_USERDATA); + + if(cinfo) + { + if(data) + new_userdata(&(cinfo->root), dataname, data); + else + { + if(dataname) + remove_userdata(&(cinfo->root), dataname, FALSE); + else + remove_userdata(&(cinfo->root), NULL, TRUE); + } + } +} + +/* + * Gets a named user data item to a window handle. + * Parameters: + * window: Window handle of signal to be called back. + * dataname: A string pointer identifying which signal to be hooked. + * data: User data to be passed to the handler function. + */ +void *dw_window_get_data(HWND window, char *dataname) +{ + ColorInfo *cinfo = (ColorInfo *)GetWindowLong(window, GWL_USERDATA); + + if(cinfo && cinfo->root && dataname) + { + UserData *ud = find_userdata(&(cinfo->root), dataname); + if(ud) + return ud->data; + } + return NULL; +} + #ifndef NO_SIGNALS /* * Add a callback to a window event.