comparison os2/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 ab77a22a2a36
children 98cce029a611
comparison
equal deleted inserted replaced
89:ec311fe773da 90:eeb98f881663
248 dw_signal_disconnect_by_window(handle); 248 dw_signal_disconnect_by_window(handle);
249 #endif 249 #endif
250 250
251 if(ptr) 251 if(ptr)
252 { 252 {
253 dw_window_set_data(handle, NULL, NULL);
253 WinSetWindowPtr(handle, QWP_USER, 0); 254 WinSetWindowPtr(handle, QWP_USER, 0);
254 free(ptr); 255 free(ptr);
255 } 256 }
256 257
257 henum = WinBeginEnumWindows(handle); 258 henum = WinBeginEnumWindows(handle);
3750 * text: The text to be display by the static text widget. 3751 * text: The text to be display by the static text widget.
3751 * id: An ID to be used with WinWindowFromID() or 0L. 3752 * id: An ID to be used with WinWindowFromID() or 0L.
3752 */ 3753 */
3753 HWND dw_status_text_new(char *text, ULONG id) 3754 HWND dw_status_text_new(char *text, ULONG id)
3754 { 3755 {
3755 PFNWP *blah = malloc(sizeof(PFNWP)); 3756 WindowData *blah = calloc(sizeof(WindowData), 1);
3756 HWND tmp = WinCreateWindow(HWND_OBJECT, 3757 HWND tmp = WinCreateWindow(HWND_OBJECT,
3757 WC_STATIC, 3758 WC_STATIC,
3758 text, 3759 text,
3759 WS_VISIBLE | SS_TEXT, 3760 WS_VISIBLE | SS_TEXT,
3760 0,0,2000,1000, 3761 0,0,2000,1000,
3764 NULL, 3765 NULL,
3765 NULL); 3766 NULL);
3766 dw_window_set_font(tmp, DefaultFont); 3767 dw_window_set_font(tmp, DefaultFont);
3767 dw_window_set_color(tmp, DW_CLR_BLACK, DW_CLR_PALEGRAY); 3768 dw_window_set_color(tmp, DW_CLR_BLACK, DW_CLR_PALEGRAY);
3768 3769
3769 *blah = WinSubclassWindow(tmp, _statusproc); 3770 blah->oldproc = WinSubclassWindow(tmp, _statusproc);
3770 WinSetWindowPtr(tmp, QWP_USER, blah); 3771 WinSetWindowPtr(tmp, QWP_USER, blah);
3771 return tmp; 3772 return tmp;
3772 } 3773 }
3773 3774
3774 /* 3775 /*
3892 * text: The text to be display by the static text widget. 3893 * text: The text to be display by the static text widget.
3893 * id: An ID to be used with WinWindowFromID() or 0L. 3894 * id: An ID to be used with WinWindowFromID() or 0L.
3894 */ 3895 */
3895 HWND dw_button_new(char *text, ULONG id) 3896 HWND dw_button_new(char *text, ULONG id)
3896 { 3897 {
3897 BubbleButton *bubble = malloc(sizeof(BubbleButton)); 3898 BubbleButton *bubble = calloc(sizeof(BubbleButton), 1);
3898 3899
3899 HWND tmp = WinCreateWindow(HWND_OBJECT, 3900 HWND tmp = WinCreateWindow(HWND_OBJECT,
3900 WC_BUTTON, 3901 WC_BUTTON,
3901 text, 3902 text,
3902 WS_VISIBLE, 3903 WS_VISIBLE,
3957 */ 3958 */
3958 HWND dw_bitmapbutton_new(char *text, ULONG id) 3959 HWND dw_bitmapbutton_new(char *text, ULONG id)
3959 { 3960 {
3960 char idbuf[256]; 3961 char idbuf[256];
3961 HWND tmp; 3962 HWND tmp;
3962 BubbleButton *bubble = malloc(sizeof(BubbleButton)); 3963 BubbleButton *bubble = calloc(sizeof(BubbleButton), 1);
3963 3964
3964 _GenResIDStr(idbuf, id); 3965 _GenResIDStr(idbuf, id);
3965 3966
3966 tmp = WinCreateWindow(HWND_OBJECT, 3967 tmp = WinCreateWindow(HWND_OBJECT,
3967 WC_BUTTON, 3968 WC_BUTTON,
3991 * text: The text to be display by the static text widget. 3992 * text: The text to be display by the static text widget.
3992 * id: An ID to be used with WinWindowFromID() or 0L. 3993 * id: An ID to be used with WinWindowFromID() or 0L.
3993 */ 3994 */
3994 HWND dw_spinbutton_new(char *text, ULONG id) 3995 HWND dw_spinbutton_new(char *text, ULONG id)
3995 { 3996 {
3996 PFNWP *blah = malloc(sizeof(PFNWP)); 3997 WindowData *blah = calloc(sizeof(WindowData), 1);
3997 HWND tmp = WinCreateWindow(HWND_OBJECT, 3998 HWND tmp = WinCreateWindow(HWND_OBJECT,
3998 WC_SPINBUTTON, 3999 WC_SPINBUTTON,
3999 text, 4000 text,
4000 WS_VISIBLE | SPBS_MASTER, 4001 WS_VISIBLE | SPBS_MASTER,
4001 0,0,2000,1000, 4002 0,0,2000,1000,
4003 HWND_TOP, 4004 HWND_TOP,
4004 id, 4005 id,
4005 NULL, 4006 NULL,
4006 NULL); 4007 NULL);
4007 dw_window_set_font(tmp, DefaultFont); 4008 dw_window_set_font(tmp, DefaultFont);
4008 *blah = WinSubclassWindow(tmp, _entryproc); 4009 blah->oldproc = WinSubclassWindow(tmp, _entryproc);
4009 WinSetWindowPtr(tmp, QWP_USER, blah); 4010 WinSetWindowPtr(tmp, QWP_USER, blah);
4010 return tmp; 4011 return tmp;
4011 } 4012 }
4012 4013
4013 /* 4014 /*
4016 * text: The text to be display by the static text widget. 4017 * text: The text to be display by the static text widget.
4017 * id: An ID to be used with WinWindowFromID() or 0L. 4018 * id: An ID to be used with WinWindowFromID() or 0L.
4018 */ 4019 */
4019 HWND dw_radiobutton_new(char *text, ULONG id) 4020 HWND dw_radiobutton_new(char *text, ULONG id)
4020 { 4021 {
4021 PFNWP *blah = malloc(sizeof(PFNWP)); 4022 WindowData *blah = calloc(sizeof(WindowData), 1);
4022 HWND tmp = WinCreateWindow(HWND_OBJECT, 4023 HWND tmp = WinCreateWindow(HWND_OBJECT,
4023 WC_BUTTON, 4024 WC_BUTTON,
4024 text, 4025 text,
4025 WS_VISIBLE | 4026 WS_VISIBLE |
4026 BS_AUTORADIOBUTTON, 4027 BS_AUTORADIOBUTTON,
4030 id, 4031 id,
4031 NULL, 4032 NULL,
4032 NULL); 4033 NULL);
4033 dw_window_set_font(tmp, DefaultFont); 4034 dw_window_set_font(tmp, DefaultFont);
4034 dw_window_set_color(tmp, DW_CLR_BLACK, DW_CLR_PALEGRAY); 4035 dw_window_set_color(tmp, DW_CLR_BLACK, DW_CLR_PALEGRAY);
4035 *blah = WinSubclassWindow(tmp, _entryproc); 4036 blah->oldproc = WinSubclassWindow(tmp, _entryproc);
4036 WinSetWindowPtr(tmp, QWP_USER, blah); 4037 WinSetWindowPtr(tmp, QWP_USER, blah);
4037 return tmp; 4038 return tmp;
4038 } 4039 }
4039 4040
4040 /* 4041 /*
4093 * text: The text to be display by the static text widget. 4094 * text: The text to be display by the static text widget.
4094 * id: An ID to be used with WinWindowFromID() or 0L. 4095 * id: An ID to be used with WinWindowFromID() or 0L.
4095 */ 4096 */
4096 HWND dw_checkbox_new(char *text, ULONG id) 4097 HWND dw_checkbox_new(char *text, ULONG id)
4097 { 4098 {
4098 BubbleButton *bubble = malloc(sizeof(BubbleButton)); 4099 BubbleButton *bubble = calloc(sizeof(BubbleButton), 1);
4099 HWND tmp = WinCreateWindow(HWND_OBJECT, 4100 HWND tmp = WinCreateWindow(HWND_OBJECT,
4100 WC_BUTTON, 4101 WC_BUTTON,
4101 text, 4102 text,
4102 WS_VISIBLE | BS_AUTOCHECKBOX, 4103 WS_VISIBLE | BS_AUTOCHECKBOX,
4103 0,0,2000,1000, 4104 0,0,2000,1000,
4121 * id: An ID to be used with WinWindowFromID() or 0L. 4122 * id: An ID to be used with WinWindowFromID() or 0L.
4122 * multi: Multiple select TRUE or FALSE. 4123 * multi: Multiple select TRUE or FALSE.
4123 */ 4124 */
4124 HWND dw_listbox_new(ULONG id, int multi) 4125 HWND dw_listbox_new(ULONG id, int multi)
4125 { 4126 {
4126 PFNWP *blah = malloc(sizeof(PFNWP)); 4127 WindowData *blah = calloc(sizeof(WindowData), 1);
4127 HWND tmp = WinCreateWindow(HWND_OBJECT, 4128 HWND tmp = WinCreateWindow(HWND_OBJECT,
4128 WC_LISTBOX, 4129 WC_LISTBOX,
4129 NULL, 4130 NULL,
4130 WS_VISIBLE | LS_NOADJUSTPOS | 4131 WS_VISIBLE | LS_NOADJUSTPOS |
4131 (multi ? LS_MULTIPLESEL : 0), 4132 (multi ? LS_MULTIPLESEL : 0),
4134 HWND_TOP, 4135 HWND_TOP,
4135 id, 4136 id,
4136 NULL, 4137 NULL,
4137 NULL); 4138 NULL);
4138 dw_window_set_font(tmp, DefaultFont); 4139 dw_window_set_font(tmp, DefaultFont);
4139 *blah = WinSubclassWindow(tmp, _entryproc); 4140 blah->oldproc = WinSubclassWindow(tmp, _entryproc);
4140 WinSetWindowPtr(tmp, QWP_USER, blah); 4141 WinSetWindowPtr(tmp, QWP_USER, blah);
4141 return tmp; 4142 return tmp;
4142 } 4143 }
4143 4144
4144 /* 4145 /*
7050 void dw_window_function(HWND handle, void *function, void *data) 7051 void dw_window_function(HWND handle, void *function, void *data)
7051 { 7052 {
7052 WinSendMsg(handle, WM_USER, (MPARAM)function, (MPARAM)data); 7053 WinSendMsg(handle, WM_USER, (MPARAM)function, (MPARAM)data);
7053 } 7054 }
7054 7055
7056 /* Functions for managing the user data lists that are associated with
7057 * a given window handle. Used in dw_window_set_data() and
7058 * dw_window_get_data().
7059 */
7060 UserData *find_userdata(UserData **root, char *varname)
7061 {
7062 UserData *tmp = *root;
7063
7064 while(tmp)
7065 {
7066 if(stricmp(tmp->varname, varname) == 0)
7067 return tmp;
7068 tmp = tmp->next;
7069 }
7070 return NULL;
7071 }
7072
7073 int new_userdata(UserData **root, char *varname, void *data)
7074 {
7075 UserData *new = find_userdata(root, varname);
7076
7077 if(new)
7078 {
7079 new->data = data;
7080 return TRUE;
7081 }
7082 else
7083 {
7084 new = malloc(sizeof(UserData));
7085 if(new)
7086 {
7087 new->varname = strdup(varname);
7088 new->data = data;
7089
7090 new->next = NULL;
7091
7092 if (!*root)
7093 *root = new;
7094 else
7095 {
7096 UserData *prev = NULL, *tmp = *root;
7097 while(tmp)
7098 {
7099 prev = tmp;
7100 tmp = tmp->next;
7101 }
7102 if(prev)
7103 prev->next = new;
7104 else
7105 *root = new;
7106 }
7107 return TRUE;
7108 }
7109 }
7110 return FALSE;
7111 }
7112
7113 int remove_userdata(UserData **root, char *varname, int all)
7114 {
7115 UserData *prev = NULL, *tmp = *root;
7116
7117 while(tmp)
7118 {
7119 if(all || stricmp(tmp->varname, varname) == 0)
7120 {
7121 if(!prev)
7122 {
7123 free(tmp->varname);
7124 free(tmp);
7125 *root = NULL;
7126 return 0;
7127 }
7128 else
7129 {
7130 prev->next = tmp->next;
7131 free(tmp->varname);
7132 free(tmp);
7133 return 0;
7134 }
7135 }
7136 tmp = tmp->next;
7137 }
7138 return 0;
7139 }
7140
7141 /*
7142 * Add a named user data item to a window handle.
7143 * Parameters:
7144 * window: Window handle of signal to be called back.
7145 * dataname: A string pointer identifying which signal to be hooked.
7146 * data: User data to be passed to the handler function.
7147 */
7148 void dw_window_set_data(HWND window, char *dataname, void *data)
7149 {
7150 WindowData *blah = (WindowData *)WinQueryWindowPtr(window, QWP_USER);
7151
7152 if(blah)
7153 {
7154 if(data)
7155 new_userdata(&(blah->root), dataname, data);
7156 else
7157 {
7158 if(dataname)
7159 remove_userdata(&(blah->root), dataname, FALSE);
7160 else
7161 remove_userdata(&(blah->root), NULL, TRUE);
7162 }
7163 }
7164 }
7165
7166 /*
7167 * Gets a named user data item to a window handle.
7168 * Parameters:
7169 * window: Window handle of signal to be called back.
7170 * dataname: A string pointer identifying which signal to be hooked.
7171 * data: User data to be passed to the handler function.
7172 */
7173 void *dw_window_get_data(HWND window, char *dataname)
7174 {
7175 WindowData *blah = (WindowData *)WinQueryWindowPtr(window, QWP_USER);
7176
7177 if(blah && blah->root && dataname)
7178 {
7179 UserData *ud = find_userdata(&(blah->root), dataname);
7180 if(ud)
7181 return ud->data;
7182 }
7183 return NULL;
7184 }
7185
7055 #ifndef NO_SIGNALS 7186 #ifndef NO_SIGNALS
7056 /* 7187 /*
7057 * Add a callback to a window event. 7188 * Add a callback to a window event.
7058 * Parameters: 7189 * Parameters:
7059 * window: Window handle of signal to be called back. 7190 * window: Window handle of signal to be called back.