Mercurial > dwindows
comparison os2/dw.c @ 326:1c961a4d0f43
Old container code cleanups, and container code now allocates memory to
hold the strings so it acts like Windows and GTK.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 08 Apr 2003 09:33:21 +0000 |
parents | 83edbd751da9 |
children | e00aff2b899e |
comparison
equal
deleted
inserted
replaced
325:e5f0613b65cd | 326:1c961a4d0f43 |
---|---|
5990 void API dw_icon_free(unsigned long handle) | 5990 void API dw_icon_free(unsigned long handle) |
5991 { | 5991 { |
5992 WinDestroyPointer(handle); | 5992 WinDestroyPointer(handle); |
5993 } | 5993 } |
5994 | 5994 |
5995 /* A "safe" WinSendMsg() that tries multiple times in case the | |
5996 * queue is blocked for one reason or another. | |
5997 */ | |
5998 MRESULT _dw_send_msg(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2, int failure) | |
5999 { | |
6000 MRESULT res; | |
6001 int z = 0; | |
6002 | |
6003 while((int)(res = WinSendMsg(hwnd, msg, mp1, mp2)) == failure) | |
6004 { | |
6005 z++; | |
6006 if(z > 5000000) | |
6007 return (MRESULT)failure; | |
6008 dw_main_sleep(1); | |
6009 } | |
6010 return res; | |
6011 } | |
6012 | |
5995 /* | 6013 /* |
5996 * Allocates memory used to populate a container. | 6014 * Allocates memory used to populate a container. |
5997 * Parameters: | 6015 * Parameters: |
5998 * handle: Handle to the container window (widget). | 6016 * handle: Handle to the container window (widget). |
5999 * rowcount: The number of items to be populated. | 6017 * rowcount: The number of items to be populated. |
6030 | 6048 |
6031 totalsize = size + sizeof(RECORDCORE); | 6049 totalsize = size + sizeof(RECORDCORE); |
6032 | 6050 |
6033 z = 0; | 6051 z = 0; |
6034 | 6052 |
6035 while((blah = (void *)WinSendMsg(handle, CM_ALLOCRECORD, MPFROMLONG(size), MPFROMLONG(rowcount))) == NULL) | 6053 if(!(blah = (void *)_dw_send_msg(handle, CM_ALLOCRECORD, MPFROMLONG(size), MPFROMLONG(rowcount), 0))) |
6036 { | |
6037 z++; | |
6038 if(z > 5000000) | |
6039 break; | |
6040 dw_main_sleep(1); | |
6041 } | |
6042 | |
6043 if(!blah) | |
6044 return NULL; | 6054 return NULL; |
6045 | 6055 |
6046 temp = (PRECORDCORE)blah; | 6056 temp = (PRECORDCORE)blah; |
6047 | 6057 |
6048 for(z=0;z<rowcount;z++) | 6058 for(z=0;z<rowcount;z++) |
6070 void *dest; | 6080 void *dest; |
6071 | 6081 |
6072 if(!flags) | 6082 if(!flags) |
6073 return; | 6083 return; |
6074 | 6084 |
6075 z = 0; | 6085 if(!_dw_send_msg(handle, CM_QUERYCNRINFO, (MPARAM)&cnr, MPFROMSHORT(sizeof(CNRINFO)), 0)) |
6076 | 6086 return; |
6077 while(WinSendMsg(handle, CM_QUERYCNRINFO, (MPARAM)&cnr, MPFROMSHORT(sizeof(CNRINFO))) == 0) | 6087 |
6078 { | |
6079 z++; | |
6080 if(z > 5000000) | |
6081 return; | |
6082 dw_main_sleep(1); | |
6083 } | |
6084 currentcount = cnr.cRecords; | 6088 currentcount = cnr.cRecords; |
6085 | 6089 |
6086 /* Figure out the offsets to the items in the struct */ | 6090 /* Figure out the offsets to the items in the struct */ |
6087 for(z=0;z<column;z++) | 6091 for(z=0;z<column;z++) |
6088 { | 6092 { |
6106 dest = (void *)(((ULONG)temp)+((ULONG)totalsize)); | 6110 dest = (void *)(((ULONG)temp)+((ULONG)totalsize)); |
6107 | 6111 |
6108 if(flags[column] & DW_CFA_BITMAPORICON) | 6112 if(flags[column] & DW_CFA_BITMAPORICON) |
6109 memcpy(dest, data, sizeof(HPOINTER)); | 6113 memcpy(dest, data, sizeof(HPOINTER)); |
6110 else if(flags[column] & DW_CFA_STRING) | 6114 else if(flags[column] & DW_CFA_STRING) |
6111 memcpy(dest, data, sizeof(char *)); | 6115 { |
6116 char **newstr = (char **)data, **str = dest; | |
6117 | |
6118 if(*str) | |
6119 free(*str); | |
6120 | |
6121 if(newstr && *newstr) | |
6122 *str = strdup(*newstr); | |
6123 else | |
6124 *str = NULL; | |
6125 } | |
6112 else if(flags[column] & DW_CFA_ULONG) | 6126 else if(flags[column] & DW_CFA_ULONG) |
6113 memcpy(dest, data, sizeof(ULONG)); | 6127 memcpy(dest, data, sizeof(ULONG)); |
6114 else if(flags[column] & DW_CFA_DATE) | 6128 else if(flags[column] & DW_CFA_DATE) |
6115 memcpy(dest, data, sizeof(CDATE)); | 6129 memcpy(dest, data, sizeof(CDATE)); |
6116 else if(flags[column] & DW_CFA_TIME) | 6130 else if(flags[column] & DW_CFA_TIME) |
6117 memcpy(dest, data, sizeof(CTIME)); | 6131 memcpy(dest, data, sizeof(CTIME)); |
6118 } | 6132 } |
6119 | 6133 |
6134 /* Internal function that does the work for set_item and change_item */ | |
6135 void _dw_container_free_strings(HWND handle, PRECORDCORE temp) | |
6136 { | |
6137 WindowData *blah = (WindowData *)WinQueryWindowPtr(handle, QWP_USER); | |
6138 ULONG totalsize, size = 0, *flags = blah ? blah->data : 0; | |
6139 int z, count = 0; | |
6140 | |
6141 if(!flags) | |
6142 return; | |
6143 | |
6144 while(flags[count]) | |
6145 count++; | |
6146 | |
6147 /* Figure out the offsets to the items in the struct */ | |
6148 for(z=0;z<count;z++) | |
6149 { | |
6150 if(flags[z] & DW_CFA_BITMAPORICON) | |
6151 size += sizeof(HPOINTER); | |
6152 else if(flags[z] & DW_CFA_STRING) | |
6153 { | |
6154 char **str; | |
6155 | |
6156 totalsize = size + sizeof(RECORDCORE); | |
6157 | |
6158 str = (char **)(((ULONG)temp)+((ULONG)totalsize)); | |
6159 | |
6160 if(*str) | |
6161 { | |
6162 free(*str); | |
6163 *str = NULL; | |
6164 } | |
6165 size += sizeof(char *); | |
6166 } | |
6167 else if(flags[z] & DW_CFA_ULONG) | |
6168 size += sizeof(ULONG); | |
6169 else if(flags[z] & DW_CFA_DATE) | |
6170 size += sizeof(CDATE); | |
6171 else if(flags[z] & DW_CFA_TIME) | |
6172 size += sizeof(CTIME); | |
6173 } | |
6174 } | |
6175 | |
6120 /* | 6176 /* |
6121 * Sets an item in specified row and column to the given data. | 6177 * Sets an item in specified row and column to the given data. |
6122 * Parameters: | 6178 * Parameters: |
6123 * handle: Handle to the container window (widget). | 6179 * handle: Handle to the container window (widget). |
6124 * pointer: Pointer to the allocated memory in dw_container_alloc(). | 6180 * pointer: Pointer to the allocated memory in dw_container_alloc(). |
6151 | 6207 |
6152 while(pCore) | 6208 while(pCore) |
6153 { | 6209 { |
6154 if(count == row) | 6210 if(count == row) |
6155 { | 6211 { |
6156 _dw_container_set_item(handle, pCore, column, row, data); | 6212 _dw_container_set_item(handle, pCore, column, 0, data); |
6157 WinSendMsg(handle, CM_INVALIDATERECORD, (MPARAM)&pCore, MPFROM2SHORT(1, CMA_NOREPOSITION | CMA_TEXTCHANGED)); | 6213 WinSendMsg(handle, CM_INVALIDATERECORD, (MPARAM)&pCore, MPFROM2SHORT(1, CMA_NOREPOSITION | CMA_TEXTCHANGED)); |
6158 return; | 6214 return; |
6159 } | 6215 } |
6160 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); | 6216 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); |
6161 count++; | 6217 count++; |
6221 | 6277 |
6222 temp = (PRECORDCORE)ci->data; | 6278 temp = (PRECORDCORE)ci->data; |
6223 | 6279 |
6224 z = 0; | 6280 z = 0; |
6225 | 6281 |
6226 while(WinSendMsg(ci->handle, CM_QUERYCNRINFO, (MPARAM)&cnr, MPFROMSHORT(sizeof(CNRINFO))) == 0) | 6282 if(!_dw_send_msg(ci->handle, CM_QUERYCNRINFO, (MPARAM)&cnr, MPFROMSHORT(sizeof(CNRINFO)), 0)) |
6227 { | 6283 return; |
6228 z++; | 6284 |
6229 if(z > 5000000) | |
6230 return; | |
6231 dw_main_sleep(1); | |
6232 } | |
6233 currentcount = cnr.cRecords; | 6285 currentcount = cnr.cRecords; |
6234 | 6286 |
6235 for(z=0;z<(row-currentcount);z++) | 6287 for(z=0;z<(row-currentcount);z++) |
6236 temp = temp->preccNextRecord; | 6288 temp = temp->preccNextRecord; |
6237 | 6289 |
6249 */ | 6301 */ |
6250 void API dw_container_insert(HWND handle, void *pointer, int rowcount) | 6302 void API dw_container_insert(HWND handle, void *pointer, int rowcount) |
6251 { | 6303 { |
6252 RECORDINSERT recin; | 6304 RECORDINSERT recin; |
6253 ContainerInfo *ci = (ContainerInfo *)pointer; | 6305 ContainerInfo *ci = (ContainerInfo *)pointer; |
6254 int z; | |
6255 | 6306 |
6256 if(!ci) | 6307 if(!ci) |
6257 return; | 6308 return; |
6258 | 6309 |
6259 recin.cb = sizeof(RECORDINSERT); | 6310 recin.cb = sizeof(RECORDINSERT); |
6261 recin.pRecordParent = NULL; | 6312 recin.pRecordParent = NULL; |
6262 recin.zOrder = CMA_TOP; | 6313 recin.zOrder = CMA_TOP; |
6263 recin.fInvalidateRecord = TRUE; | 6314 recin.fInvalidateRecord = TRUE; |
6264 recin.cRecordsInsert = rowcount; | 6315 recin.cRecordsInsert = rowcount; |
6265 | 6316 |
6266 z = 0; | 6317 _dw_send_msg(handle, CM_INSERTRECORD, MPFROMP(ci->data), MPFROMP(&recin), 0); |
6267 | |
6268 while(WinSendMsg(handle, CM_INSERTRECORD, MPFROMP(ci->data), MPFROMP(&recin)) == 0) | |
6269 { | |
6270 z++; | |
6271 if(z > 5000000) | |
6272 break; | |
6273 dw_main_sleep(1); | |
6274 } | |
6275 | 6318 |
6276 free(ci); | 6319 free(ci); |
6277 } | 6320 } |
6278 | 6321 |
6279 /* | 6322 /* |
6282 * handle: Handle to the window (widget) to be cleared. | 6325 * handle: Handle to the window (widget) to be cleared. |
6283 * redraw: TRUE to cause the container to redraw immediately. | 6326 * redraw: TRUE to cause the container to redraw immediately. |
6284 */ | 6327 */ |
6285 void API dw_container_clear(HWND handle, int redraw) | 6328 void API dw_container_clear(HWND handle, int redraw) |
6286 { | 6329 { |
6287 int z = 0; | 6330 PCNRITEM pCore; |
6331 int container = (int)dw_window_get_data(handle, "_dw_container"); | |
6288 | 6332 |
6289 if(hwndEmph == handle) | 6333 if(hwndEmph == handle) |
6290 _clear_emphasis(); | 6334 _clear_emphasis(); |
6291 if(!dw_window_get_data(handle, "_dw_container")) | 6335 |
6292 { | 6336 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)0L, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER)); |
6293 PCNRITEM pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)0L, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER)); | 6337 |
6294 | 6338 while(pCore) |
6295 while(pCore) | 6339 { |
6340 if(container) | |
6341 _dw_container_free_strings(handle, (PRECORDCORE)pCore); | |
6342 else | |
6296 { | 6343 { |
6297 /* Free icon text */ | 6344 /* Free icon text */ |
6298 if(pCore->rc.pszIcon) | 6345 if(pCore->rc.pszIcon) |
6299 { | 6346 { |
6300 free(pCore->rc.pszIcon); | 6347 free(pCore->rc.pszIcon); |
6301 pCore->rc.pszIcon = 0; | 6348 pCore->rc.pszIcon = 0; |
6302 } | 6349 } |
6303 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); | 6350 } |
6304 } | 6351 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); |
6305 } | 6352 } |
6306 while((int)WinSendMsg(handle, CM_REMOVERECORD, (MPARAM)0L, MPFROM2SHORT(0, (redraw ? CMA_INVALIDATE : 0) | CMA_FREE)) == -1) | 6353 _dw_send_msg(handle, CM_REMOVERECORD, (MPARAM)0L, MPFROM2SHORT(0, (redraw ? CMA_INVALIDATE : 0) | CMA_FREE), -1); |
6307 { | |
6308 z++; | |
6309 if(z > 5000000) | |
6310 break; | |
6311 dw_main_sleep(1); | |
6312 } | |
6313 } | 6354 } |
6314 | 6355 |
6315 /* | 6356 /* |
6316 * Removes the first x rows from a container. | 6357 * Removes the first x rows from a container. |
6317 * Parameters: | 6358 * Parameters: |
6319 * rowcount: The number of rows to be deleted. | 6360 * rowcount: The number of rows to be deleted. |
6320 */ | 6361 */ |
6321 void API dw_container_delete(HWND handle, int rowcount) | 6362 void API dw_container_delete(HWND handle, int rowcount) |
6322 { | 6363 { |
6323 RECORDCORE *last, **prc = malloc(sizeof(RECORDCORE *) * rowcount); | 6364 RECORDCORE *last, **prc = malloc(sizeof(RECORDCORE *) * rowcount); |
6324 int current = 1, z; | 6365 int current = 1; |
6325 | 6366 |
6326 prc[0] = last = (RECORDCORE *)WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)0L, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER)); | 6367 prc[0] = last = (RECORDCORE *)WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)0L, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER)); |
6327 | 6368 |
6328 while(last && current < rowcount) | 6369 while(last && current < rowcount) |
6329 { | 6370 { |
6371 _dw_container_free_strings(handle, last); | |
6330 prc[current] = last = (RECORDCORE *)WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)last, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); | 6372 prc[current] = last = (RECORDCORE *)WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)last, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); |
6331 current++; | 6373 current++; |
6332 } | 6374 } |
6333 | 6375 |
6334 z = 0; | 6376 _dw_send_msg(handle, CM_REMOVERECORD, (MPARAM)prc, MPFROM2SHORT(current, CMA_INVALIDATE | CMA_FREE), -1); |
6335 | |
6336 while((int)WinSendMsg(handle, CM_REMOVERECORD, (MPARAM)prc, MPFROM2SHORT(current, CMA_INVALIDATE | CMA_FREE)) == -1) | |
6337 { | |
6338 z++; | |
6339 if(z > 5000000) | |
6340 break; | |
6341 dw_main_sleep(1); | |
6342 } | |
6343 | 6377 |
6344 free(prc); | 6378 free(prc); |
6345 } | 6379 } |
6346 | 6380 |
6347 /* | 6381 /* |