| 15346 | |
| 15347 | |
| 15348 | ResultType GuiControlType::LV_GetText(ResultToken & aResultToken, int aID, int aFlags, ExprTokenType * aParam[], int aParamCount) |
| 15349 | // Returns: Text on success. |
| 15350 | // Throws on failure. |
| 15351 | // Parameters: |
| 15352 | // 1: Row index (one-based when it comes in). |
| 15353 | // 2: Column index (one-based when it comes in). |
| 15354 | { |
| 15355 | // Above sets default result in case of early return. For code reduction, a zero is returned for all |
| 15356 | // the following conditions: |
| 15357 | // Item not found in ListView. |
| 15358 | // And others. |
| 15359 | |
| 15360 | int row_index = ParamIndexToInt(0) - 1; // -1 to convert to zero-based. |
| 15361 | if (row_index < -1) // row_index==-1 is reserved to mean "get column heading's text". |
| 15362 | _o_throw_param(0); |
| 15363 | // If parameter 2 is omitted, default to the first column (index 0): |
| 15364 | int col_index = ParamIndexIsOmitted(1) ? 0 : ParamIndexToInt(1) - 1; // -1 to convert to zero-based. |
| 15365 | if (col_index < 0) |
| 15366 | _o_throw_param(1); |
| 15367 | |
| 15368 | TCHAR buf[LV_TEXT_BUF_SIZE]; |
| 15369 | |
| 15370 | if (row_index == -1) // Special mode to get column's text. |
| 15371 | { |
| 15372 | LVCOLUMN lvc; |
| 15373 | lvc.cchTextMax = LV_TEXT_BUF_SIZE - 1; // See notes below about -1. |
| 15374 | lvc.pszText = buf; |
| 15375 | lvc.mask = LVCF_TEXT; |
| 15376 | if (SendMessage(hwnd, LVM_GETCOLUMN, col_index, (LPARAM)&lvc)) // Assign. |
| 15377 | _o_return(lvc.pszText); // See notes below about why pszText is used instead of buf (might apply to this too). |
| 15378 | else // On failure, it seems best to throw. |
| 15379 | _o_throw(ERR_FAILED); |
| 15380 | } |
| 15381 | else // Get row's indicated item or subitem text. |
| 15382 | { |
| 15383 | LVITEM lvi; |
| 15384 | // Subtract 1 because of that nagging doubt about size vs. length. Some MSDN examples subtract one, such as |
| 15385 | // TabCtrl_GetItem()'s cchTextMax: |
| 15386 | lvi.iItem = row_index; |
| 15387 | lvi.iSubItem = col_index; // Which field to fetch. If it's zero, the item vs. subitem will be fetched. |
| 15388 | lvi.mask = LVIF_TEXT; |
| 15389 | lvi.pszText = buf; |
| 15390 | lvi.cchTextMax = LV_TEXT_BUF_SIZE - 1; // Note that LVM_GETITEM doesn't update this member to reflect the new length. |
| 15391 | // Unlike LVM_GETITEMTEXT, LVM_GETITEM indicates success or failure, which seems more useful/preferable |
| 15392 | // as a return value since a text length of zero would be ambiguous: could be an empty field or a failure. |
| 15393 | if (SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM)&lvi)) // Assign |
| 15394 | // Must use lvi.pszText vs. buf because MSDN says: "Applications should not assume that the text will |
| 15395 | // necessarily be placed in the specified buffer. The control may instead change the pszText member |
| 15396 | // of the structure to point to the new text rather than place it in the buffer." |
| 15397 | _o_return(lvi.pszText); |
| 15398 | else // On failure, it seems best to throw. |
| 15399 | _o_throw(ERR_FAILED); |
| 15400 | } |
| 15401 | } |
| 15402 | |
| 15403 | |
| 15404 |
nothing calls this directly
no outgoing calls
no test coverage detected