Mercurial > dwindows
comparison os2/dw.c @ 1879:8a205b80617e
Initial OS/2 changes for separating string and data in containers (untested).
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 09 Aug 2013 22:40:54 +0000 |
parents | c836603d3f14 |
children | 6949c73e30fd |
comparison
equal
deleted
inserted
replaced
1878:313e5d64714d | 1879:8a205b80617e |
---|---|
9784 void _dw_container_free_strings(HWND handle, PRECORDCORE temp) | 9784 void _dw_container_free_strings(HWND handle, PRECORDCORE temp) |
9785 { | 9785 { |
9786 WindowData *blah = (WindowData *)WinQueryWindowPtr(handle, QWP_USER); | 9786 WindowData *blah = (WindowData *)WinQueryWindowPtr(handle, QWP_USER); |
9787 ULONG totalsize, size = 0, *flags = blah ? blah->data : 0; | 9787 ULONG totalsize, size = 0, *flags = blah ? blah->data : 0; |
9788 int z, count = 0; | 9788 int z, count = 0; |
9789 | 9789 char *oldtitle = (char *)temp->pszIcon; |
9790 | |
9790 if(!flags) | 9791 if(!flags) |
9791 return; | 9792 return; |
9792 | 9793 |
9793 while(flags[count]) | 9794 while(flags[count]) |
9794 count++; | 9795 count++; |
9795 | 9796 |
9797 /* Empty and free the title memory */ | |
9798 temp->pszIcon = temp->pszText = NULL; | |
9799 if(oldtitle) | |
9800 free(oldtitle); | |
9801 | |
9796 /* Figure out the offsets to the items in the struct */ | 9802 /* Figure out the offsets to the items in the struct */ |
9797 for(z=0;z<count;z++) | 9803 for(z=0;z<count;z++) |
9798 { | 9804 { |
9799 if(flags[z] & DW_CFA_BITMAPORICON) | 9805 if(flags[z] & DW_CFA_BITMAPORICON) |
9800 size += sizeof(HPOINTER); | 9806 size += sizeof(HPOINTER); |
10004 { | 10010 { |
10005 ContainerInfo *ci = (ContainerInfo *)pointer; | 10011 ContainerInfo *ci = (ContainerInfo *)pointer; |
10006 PRECORDCORE temp; | 10012 PRECORDCORE temp; |
10007 int z, currentcount; | 10013 int z, currentcount; |
10008 CNRINFO cnr; | 10014 CNRINFO cnr; |
10015 char *newtitle; | |
10009 | 10016 |
10010 if(!ci) | 10017 if(!ci) |
10011 return; | 10018 return; |
10012 | 10019 |
10013 temp = (PRECORDCORE)ci->data; | 10020 temp = (PRECORDCORE)ci->data; |
10020 currentcount = cnr.cRecords; | 10027 currentcount = cnr.cRecords; |
10021 | 10028 |
10022 for(z=0;z<(row-currentcount);z++) | 10029 for(z=0;z<(row-currentcount);z++) |
10023 temp = temp->preccNextRecord; | 10030 temp = temp->preccNextRecord; |
10024 | 10031 |
10025 temp->pszIcon = (PSZ)title; | 10032 newtitle = title ? strdup(title) : NULL; |
10026 temp->pszName = (PSZ)title; | 10033 temp->pszName = temp->pszIcon = (PSZ)title; |
10027 temp->pszText = (PSZ)title; | |
10028 } | 10034 } |
10029 | 10035 |
10030 /* | 10036 /* |
10031 * Changes the title of a row already inserted in the container. | 10037 * Changes the title of a row already inserted in the container. |
10032 * Parameters: | 10038 * Parameters: |
10041 | 10047 |
10042 while(pCore) | 10048 while(pCore) |
10043 { | 10049 { |
10044 if(count == row) | 10050 if(count == row) |
10045 { | 10051 { |
10046 pCore->pszIcon = (PSZ)title; | 10052 char *oldtitle = (char *)pCore->pszIcon; |
10047 pCore->pszName = (PSZ)title; | 10053 char *newtitle = title ? strdup(title) : NULL; |
10048 pCore->pszText = (PSZ)title; | 10054 pCore->pszName = pCore->pszIcon = (PSZ)title; |
10055 | |
10056 WinSendMsg(handle, CM_INVALIDATERECORD, (MPARAM)&pCore, MPFROM2SHORT(1, CMA_NOREPOSITION | CMA_TEXTCHANGED)); | |
10057 | |
10058 if(oldtitle) | |
10059 free(oldtitle); | |
10060 return; | |
10061 } | |
10062 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); | |
10063 count++; | |
10064 } | |
10065 } | |
10066 | |
10067 /* | |
10068 * Sets the data of a row in the container. | |
10069 * Parameters: | |
10070 * pointer: Pointer to the allocated memory in dw_container_alloc(). | |
10071 * row: Zero based row of data being set. | |
10072 * data: Data pointer. | |
10073 */ | |
10074 void API dw_container_set_row_data(void *pointer, int row, void *data) | |
10075 { | |
10076 ContainerInfo *ci = (ContainerInfo *)pointer; | |
10077 PRECORDCORE temp; | |
10078 int z, currentcount; | |
10079 CNRINFO cnr; | |
10080 | |
10081 if(!ci) | |
10082 return; | |
10083 | |
10084 temp = (PRECORDCORE)ci->data; | |
10085 | |
10086 z = 0; | |
10087 | |
10088 if(!_dw_send_msg(ci->handle, CM_QUERYCNRINFO, (MPARAM)&cnr, MPFROMSHORT(sizeof(CNRINFO)), 0)) | |
10089 return; | |
10090 | |
10091 currentcount = cnr.cRecords; | |
10092 | |
10093 for(z=0;z<(row-currentcount);z++) | |
10094 temp = temp->preccNextRecord; | |
10095 | |
10096 temp->pszText = (PSZ)data; | |
10097 } | |
10098 | |
10099 /* | |
10100 * Changes the data of a row already inserted in the container. | |
10101 * Parameters: | |
10102 * handle: Handle to the container window (widget). | |
10103 * row: Zero based row of data being set. | |
10104 * data: Data pointer. | |
10105 */ | |
10106 void API dw_container_change_row_data(HWND handle, int row, void *data) | |
10107 { | |
10108 PRECORDCORE pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)0L, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER)); | |
10109 int count = 0; | |
10110 | |
10111 while(pCore) | |
10112 { | |
10113 if(count == row) | |
10114 { | |
10115 pCore->pszText = (PSZ)data; | |
10049 | 10116 |
10050 WinSendMsg(handle, CM_INVALIDATERECORD, (MPARAM)&pCore, MPFROM2SHORT(1, CMA_NOREPOSITION | CMA_TEXTCHANGED)); | 10117 WinSendMsg(handle, CM_INVALIDATERECORD, (MPARAM)&pCore, MPFROM2SHORT(1, CMA_NOREPOSITION | CMA_TEXTCHANGED)); |
10051 return; | 10118 return; |
10052 } | 10119 } |
10053 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); | 10120 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); |
10213 while(pCore) | 10280 while(pCore) |
10214 { | 10281 { |
10215 if(pCore->flRecordAttr & flags) | 10282 if(pCore->flRecordAttr & flags) |
10216 { | 10283 { |
10217 dw_window_set_data(handle, "_dw_pcore", (void *)pCore); | 10284 dw_window_set_data(handle, "_dw_pcore", (void *)pCore); |
10218 return (char *)pCore->pszIcon; | 10285 return flags & DW_CR_RETDATA ? (char *)pCore->pszText : (char *)pCore->pszIcon; |
10219 } | 10286 } |
10220 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); | 10287 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); |
10221 } | 10288 } |
10222 } | 10289 } |
10223 else | 10290 else |
10224 { | 10291 { |
10225 dw_window_set_data(handle, "_dw_pcore", (void *)pCore); | 10292 dw_window_set_data(handle, "_dw_pcore", (void *)pCore); |
10226 return (char *)pCore->pszIcon; | 10293 return flags & DW_CR_RETDATA ? (char *)pCore->pszText : (char *)pCore->pszIcon; |
10227 } | 10294 } |
10228 } | 10295 } |
10229 return NULL; | 10296 return NULL; |
10230 } | 10297 } |
10231 | 10298 |
10250 while(pCore) | 10317 while(pCore) |
10251 { | 10318 { |
10252 if(pCore->flRecordAttr & flags) | 10319 if(pCore->flRecordAttr & flags) |
10253 { | 10320 { |
10254 dw_window_set_data(handle, "_dw_pcore", (void *)pCore); | 10321 dw_window_set_data(handle, "_dw_pcore", (void *)pCore); |
10255 return (char *)pCore->pszIcon; | 10322 return flags & DW_CR_RETDATA ? (char *)pCore->pszText : (char *)pCore->pszIcon; |
10256 } | 10323 } |
10257 | 10324 |
10258 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); | 10325 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); |
10259 } | 10326 } |
10260 } | 10327 } |
10261 else | 10328 else |
10262 { | 10329 { |
10263 dw_window_set_data(handle, "_dw_pcore", (void *)pCore); | 10330 dw_window_set_data(handle, "_dw_pcore", (void *)pCore); |
10264 return (char *)pCore->pszIcon; | 10331 return flags & DW_CR_RETDATA ? (char *)pCore->pszText : (char *)pCore->pszIcon; |
10265 } | 10332 } |
10266 } | 10333 } |
10267 return NULL; | 10334 return NULL; |
10268 } | 10335 } |
10269 | 10336 |
10275 */ | 10342 */ |
10276 void API dw_container_cursor(HWND handle, char *text) | 10343 void API dw_container_cursor(HWND handle, char *text) |
10277 { | 10344 { |
10278 RECTL viewport, item; | 10345 RECTL viewport, item; |
10279 PRECORDCORE pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)0L, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER)); | 10346 PRECORDCORE pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)0L, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER)); |
10280 int textcomp = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_textcomp")); | |
10281 | 10347 |
10282 while(pCore) | 10348 while(pCore) |
10283 { | 10349 { |
10284 if((textcomp && pCore->pszIcon && strcmp((char *)pCore->pszIcon, text) == 0) || (!textcomp && (char *)pCore->pszIcon == text)) | 10350 if(pCore->pszIcon && strcmp((char *)pCore->pszIcon, text) == 0) |
10285 { | 10351 { |
10286 QUERYRECORDRECT qrr; | 10352 QUERYRECORDRECT qrr; |
10287 int scrollpixels = 0, midway; | 10353 int scrollpixels = 0, midway; |
10288 | 10354 |
10289 qrr.cb = sizeof(QUERYRECORDRECT); | 10355 qrr.cb = sizeof(QUERYRECORDRECT); |
10313 * text: Text usually returned by dw_container_query(). | 10379 * text: Text usually returned by dw_container_query(). |
10314 */ | 10380 */ |
10315 void API dw_container_delete_row(HWND handle, char *text) | 10381 void API dw_container_delete_row(HWND handle, char *text) |
10316 { | 10382 { |
10317 PRECORDCORE pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)0L, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER)); | 10383 PRECORDCORE pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)0L, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER)); |
10384 | |
10385 while(pCore) | |
10386 { | |
10387 if(pCore->pszIcon && strcmp((char *)pCore->pszIcon, text) == 0) | |
10388 { | |
10389 WinSendMsg(handle, CM_REMOVERECORD, (MPARAM)&pCore, MPFROM2SHORT(1, CMA_FREE | CMA_INVALIDATE)); | |
10390 return; | |
10391 } | |
10392 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); | |
10393 } | |
10394 } | |
10395 | |
10396 /* | |
10397 * Cursors the item with the data speficied, and scrolls to that item. | |
10398 * Parameters: | |
10399 * handle: Handle to the window (widget) to be queried. | |
10400 * data: Data usually returned by dw_container_query(). | |
10401 */ | |
10402 void API dw_container_cursor_by_data(HWND handle, void *data) | |
10403 { | |
10404 RECTL viewport, item; | |
10405 PRECORDCORE pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)0L, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER)); | |
10406 | |
10407 while(pCore) | |
10408 { | |
10409 if((void *)pCore->pszText == data) | |
10410 { | |
10411 QUERYRECORDRECT qrr; | |
10412 int scrollpixels = 0, midway; | |
10413 | |
10414 qrr.cb = sizeof(QUERYRECORDRECT); | |
10415 qrr.pRecord = pCore; | |
10416 qrr.fRightSplitWindow = 0; | |
10417 qrr.fsExtent = CMA_TEXT; | |
10418 | |
10419 WinSendMsg(handle, CM_SETRECORDEMPHASIS, (MPARAM)pCore, MPFROM2SHORT(TRUE, CRA_CURSORED)); | |
10420 WinSendMsg(handle, CM_QUERYVIEWPORTRECT, (MPARAM)&viewport, MPFROM2SHORT(CMA_WORKSPACE, FALSE)); | |
10421 WinSendMsg(handle, CM_QUERYRECORDRECT, (MPARAM)&item, (MPARAM)&qrr); | |
10422 | |
10423 midway = (viewport.yTop - viewport.yBottom)/2; | |
10424 scrollpixels = viewport.yTop - (item.yTop + midway); | |
10425 | |
10426 WinSendMsg(handle, CM_SCROLLWINDOW, MPFROMSHORT(CMA_VERTICAL), MPFROMLONG(scrollpixels)); | |
10427 return; | |
10428 } | |
10429 | |
10430 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); | |
10431 } | |
10432 } | |
10433 | |
10434 /* | |
10435 * Deletes the item with the data speficied. | |
10436 * Parameters: | |
10437 * handle: Handle to the window (widget). | |
10438 * data: Data usually returned by dw_container_query(). | |
10439 */ | |
10440 void API dw_container_delete_row(HWND handle, void *data) | |
10441 { | |
10442 PRECORDCORE pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)0L, MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER)); | |
10318 int textcomp = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_textcomp")); | 10443 int textcomp = DW_POINTER_TO_INT(dw_window_get_data(handle, "_dw_textcomp")); |
10319 | 10444 |
10320 while(pCore) | 10445 while(pCore) |
10321 { | 10446 { |
10322 if((textcomp && pCore->pszIcon && strcmp((char *)pCore->pszIcon, text) == 0) || (!textcomp && (char *)pCore->pszIcon == text)) | 10447 if((void *)pCore->pszText == data) |
10323 { | 10448 { |
10324 WinSendMsg(handle, CM_REMOVERECORD, (MPARAM)&pCore, MPFROM2SHORT(1, CMA_FREE | CMA_INVALIDATE)); | 10449 WinSendMsg(handle, CM_REMOVERECORD, (MPARAM)&pCore, MPFROM2SHORT(1, CMA_FREE | CMA_INVALIDATE)); |
10325 return; | 10450 return; |
10326 } | 10451 } |
10327 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); | 10452 pCore = WinSendMsg(handle, CM_QUERYRECORD, (MPARAM)pCore, MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER)); |