Mercurial > dwindows
comparison win/dw.c @ 90:eeb98f881663
Committed the dw_window_set/get_data() changes from the FX tree.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 22 Apr 2002 08:34:35 +0000 |
parents | ec311fe773da |
children | 98cce029a611 |
comparison
equal
deleted
inserted
replaced
89:ec311fe773da | 90:eeb98f881663 |
---|---|
349 dw_signal_disconnect_by_window(handle); | 349 dw_signal_disconnect_by_window(handle); |
350 #endif | 350 #endif |
351 | 351 |
352 if(thiscinfo) | 352 if(thiscinfo) |
353 { | 353 { |
354 /* Delete the brush so as not to leak GDI objects */ | |
354 if(thiscinfo->hbrush) | 355 if(thiscinfo->hbrush) |
355 DeleteObject(thiscinfo->hbrush); | 356 DeleteObject(thiscinfo->hbrush); |
356 | 357 |
358 /* Free user data linked list memory */ | |
359 if(thiscinfo->root) | |
360 dw_window_set_data(handle, NULL, NULL); | |
361 | |
357 SetWindowLong(handle, GWL_USERDATA, 0); | 362 SetWindowLong(handle, GWL_USERDATA, 0); |
363 #if 0 | |
358 free(thiscinfo); | 364 free(thiscinfo); |
365 #endif | |
359 } | 366 } |
360 return TRUE; | 367 return TRUE; |
361 } | 368 } |
362 | 369 |
363 /* This function returns 1 if the window (widget) handle | 370 /* This function returns 1 if the window (widget) handle |
3289 * flStyle: Style flags, see the DW reference. | 3296 * flStyle: Style flags, see the DW reference. |
3290 */ | 3297 */ |
3291 HWND dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) | 3298 HWND dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) |
3292 { | 3299 { |
3293 HWND hwndframe; | 3300 HWND hwndframe; |
3294 Box *newbox = malloc(sizeof(Box)); | 3301 Box *newbox = calloc(sizeof(Box), 1); |
3295 ULONG flStyleEx = 0; | 3302 ULONG flStyleEx = 0; |
3296 | 3303 |
3297 newbox->pad = 0; | 3304 newbox->pad = 0; |
3298 newbox->type = BOXVERT; | 3305 newbox->type = BOXVERT; |
3299 newbox->count = 0; | 3306 newbox->count = 0; |
3307 newbox->cinfo.fore = newbox->cinfo.back = -1; | |
3300 | 3308 |
3301 if(hwndOwner) | 3309 if(hwndOwner) |
3302 flStyleEx |= WS_EX_MDICHILD; | 3310 flStyleEx |= WS_EX_MDICHILD; |
3303 | 3311 |
3304 if(!(flStyle & WS_CAPTION)) | 3312 if(!(flStyle & WS_CAPTION)) |
3334 * type: Either BOXVERT (vertical) or BOXHORZ (horizontal). | 3342 * type: Either BOXVERT (vertical) or BOXHORZ (horizontal). |
3335 * pad: Number of pixels to pad around the box. | 3343 * pad: Number of pixels to pad around the box. |
3336 */ | 3344 */ |
3337 HWND dw_box_new(int type, int pad) | 3345 HWND dw_box_new(int type, int pad) |
3338 { | 3346 { |
3339 Box *newbox = malloc(sizeof(Box)); | 3347 Box *newbox = calloc(sizeof(Box), 1); |
3340 HWND hwndframe; | 3348 HWND hwndframe; |
3341 | 3349 |
3342 newbox->pad = pad; | 3350 newbox->pad = pad; |
3343 newbox->type = type; | 3351 newbox->type = type; |
3344 newbox->count = 0; | 3352 newbox->count = 0; |
3345 newbox->grouphwnd = (HWND)NULL; | 3353 newbox->grouphwnd = (HWND)NULL; |
3354 newbox->cinfo.fore = newbox->cinfo.back = -1; | |
3346 | 3355 |
3347 hwndframe = CreateWindow(FRAMECLASSNAME, | 3356 hwndframe = CreateWindow(FRAMECLASSNAME, |
3348 "", | 3357 "", |
3349 WS_CHILD | WS_CLIPCHILDREN, | 3358 WS_CHILD | WS_CLIPCHILDREN, |
3350 0,0,2000,1000, | 3359 0,0,2000,1000, |
3367 * pad: Number of pixels to pad around the box. | 3376 * pad: Number of pixels to pad around the box. |
3368 * title: Text to be displayined in the group outline. | 3377 * title: Text to be displayined in the group outline. |
3369 */ | 3378 */ |
3370 HWND dw_groupbox_new(int type, int pad, char *title) | 3379 HWND dw_groupbox_new(int type, int pad, char *title) |
3371 { | 3380 { |
3372 Box *newbox = malloc(sizeof(Box)); | 3381 Box *newbox = calloc(sizeof(Box), 1); |
3373 HWND hwndframe; | 3382 HWND hwndframe; |
3374 | 3383 |
3375 newbox->pad = pad; | 3384 newbox->pad = pad; |
3376 newbox->type = type; | 3385 newbox->type = type; |
3377 newbox->count = 0; | 3386 newbox->count = 0; |
3387 newbox->cinfo.fore = newbox->cinfo.back = -1; | |
3378 | 3388 |
3379 hwndframe = CreateWindow(FRAMECLASSNAME, | 3389 hwndframe = CreateWindow(FRAMECLASSNAME, |
3380 "", | 3390 "", |
3381 WS_CHILD, | 3391 WS_CHILD, |
3382 0,0,2000,1000, | 3392 0,0,2000,1000, |
3885 NULL, | 3895 NULL, |
3886 NULL); | 3896 NULL); |
3887 ColorInfo *cinfo = (ColorInfo *)calloc(1, sizeof(ColorInfo)); | 3897 ColorInfo *cinfo = (ColorInfo *)calloc(1, sizeof(ColorInfo)); |
3888 ColorInfo *cinfo2 = (ColorInfo *)calloc(1, sizeof(ColorInfo)); | 3898 ColorInfo *cinfo2 = (ColorInfo *)calloc(1, sizeof(ColorInfo)); |
3889 | 3899 |
3890 if(!cinfo) | 3900 if(!cinfo || !cinfo2) |
3891 { | 3901 { |
3902 if(cinfo) | |
3903 free(cinfo); | |
3904 if(cinfo2) | |
3905 free(cinfo2); | |
3892 DestroyWindow(tmp); | 3906 DestroyWindow(tmp); |
3893 return NULL; | 3907 return NULL; |
3894 } | 3908 } |
3895 | 3909 |
3896 cinfo2->fore = cinfo->fore = -1; | 3910 cinfo2->fore = cinfo->fore = -1; |
6027 * Returns: | 6041 * Returns: |
6028 * A handle to the widget or NULL on failure. | 6042 * A handle to the widget or NULL on failure. |
6029 */ | 6043 */ |
6030 HWND dw_render_new(unsigned long id) | 6044 HWND dw_render_new(unsigned long id) |
6031 { | 6045 { |
6032 Box *newbox = malloc(sizeof(Box)); | 6046 Box *newbox = calloc(sizeof(Box), 1); |
6033 HWND tmp = CreateWindow(ObjectClassName, | 6047 HWND tmp = CreateWindow(ObjectClassName, |
6034 "", | 6048 "", |
6035 WS_CHILD | WS_CLIPCHILDREN, | 6049 WS_CHILD | WS_CLIPCHILDREN, |
6036 0,0,2000,1000, | 6050 0,0,2000,1000, |
6037 DW_HWND_OBJECT, | 6051 DW_HWND_OBJECT, |
6934 * data: Pointer to the data to be passed to the function. | 6948 * data: Pointer to the data to be passed to the function. |
6935 */ | 6949 */ |
6936 void dw_window_function(HWND handle, void *function, void *data) | 6950 void dw_window_function(HWND handle, void *function, void *data) |
6937 { | 6951 { |
6938 SendMessage(handle, WM_USER, (WPARAM)function, (LPARAM)data); | 6952 SendMessage(handle, WM_USER, (WPARAM)function, (LPARAM)data); |
6953 } | |
6954 | |
6955 /* Functions for managing the user data lists that are associated with | |
6956 * a given window handle. Used in dw_window_set_data() and | |
6957 * dw_window_get_data(). | |
6958 */ | |
6959 UserData *find_userdata(UserData **root, char *varname) | |
6960 { | |
6961 UserData *tmp = *root; | |
6962 | |
6963 while(tmp) | |
6964 { | |
6965 if(stricmp(tmp->varname, varname) == 0) | |
6966 return tmp; | |
6967 tmp = tmp->next; | |
6968 } | |
6969 return NULL; | |
6970 } | |
6971 | |
6972 int new_userdata(UserData **root, char *varname, void *data) | |
6973 { | |
6974 UserData *new = find_userdata(root, varname); | |
6975 | |
6976 if(new) | |
6977 { | |
6978 new->data = data; | |
6979 return TRUE; | |
6980 } | |
6981 else | |
6982 { | |
6983 new = malloc(sizeof(UserData)); | |
6984 if(new) | |
6985 { | |
6986 new->varname = strdup(varname); | |
6987 new->data = data; | |
6988 | |
6989 new->next = NULL; | |
6990 | |
6991 if (!*root) | |
6992 *root = new; | |
6993 else | |
6994 { | |
6995 UserData *prev = NULL, *tmp = *root; | |
6996 while(tmp) | |
6997 { | |
6998 prev = tmp; | |
6999 tmp = tmp->next; | |
7000 } | |
7001 if(prev) | |
7002 prev->next = new; | |
7003 else | |
7004 *root = new; | |
7005 } | |
7006 return TRUE; | |
7007 } | |
7008 } | |
7009 return FALSE; | |
7010 } | |
7011 | |
7012 int remove_userdata(UserData **root, char *varname, int all) | |
7013 { | |
7014 UserData *prev = NULL, *tmp = *root; | |
7015 | |
7016 while(tmp) | |
7017 { | |
7018 if(all || stricmp(tmp->varname, varname) == 0) | |
7019 { | |
7020 if(!prev) | |
7021 { | |
7022 free(tmp->varname); | |
7023 free(tmp); | |
7024 *root = NULL; | |
7025 return 0; | |
7026 } | |
7027 else | |
7028 { | |
7029 prev->next = tmp->next; | |
7030 free(tmp->varname); | |
7031 free(tmp); | |
7032 return 0; | |
7033 } | |
7034 } | |
7035 tmp = tmp->next; | |
7036 } | |
7037 return 0; | |
7038 } | |
7039 | |
7040 /* | |
7041 * Add a named user data item to a window handle. | |
7042 * Parameters: | |
7043 * window: Window handle of signal to be called back. | |
7044 * dataname: A string pointer identifying which signal to be hooked. | |
7045 * data: User data to be passed to the handler function. | |
7046 */ | |
7047 void dw_window_set_data(HWND window, char *dataname, void *data) | |
7048 { | |
7049 ColorInfo *cinfo = (ColorInfo *)GetWindowLong(window, GWL_USERDATA); | |
7050 | |
7051 if(cinfo) | |
7052 { | |
7053 if(data) | |
7054 new_userdata(&(cinfo->root), dataname, data); | |
7055 else | |
7056 { | |
7057 if(dataname) | |
7058 remove_userdata(&(cinfo->root), dataname, FALSE); | |
7059 else | |
7060 remove_userdata(&(cinfo->root), NULL, TRUE); | |
7061 } | |
7062 } | |
7063 } | |
7064 | |
7065 /* | |
7066 * Gets a named user data item to a window handle. | |
7067 * Parameters: | |
7068 * window: Window handle of signal to be called back. | |
7069 * dataname: A string pointer identifying which signal to be hooked. | |
7070 * data: User data to be passed to the handler function. | |
7071 */ | |
7072 void *dw_window_get_data(HWND window, char *dataname) | |
7073 { | |
7074 ColorInfo *cinfo = (ColorInfo *)GetWindowLong(window, GWL_USERDATA); | |
7075 | |
7076 if(cinfo && cinfo->root && dataname) | |
7077 { | |
7078 UserData *ud = find_userdata(&(cinfo->root), dataname); | |
7079 if(ud) | |
7080 return ud->data; | |
7081 } | |
7082 return NULL; | |
6939 } | 7083 } |
6940 | 7084 |
6941 #ifndef NO_SIGNALS | 7085 #ifndef NO_SIGNALS |
6942 /* | 7086 /* |
6943 * Add a callback to a window event. | 7087 * Add a callback to a window event. |