| 16414 | |
| 16415 | |
| 16416 | ResultType GuiControlType::TV_Get(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount) |
| 16417 | // TV.Get() |
| 16418 | // Returns: Varies depending on param #2. |
| 16419 | // Parameters: |
| 16420 | // 1: HTREEITEM. |
| 16421 | // 2: Name of attribute to get. |
| 16422 | // TV.GetText() |
| 16423 | // Returns: Text on success. |
| 16424 | // Throws on failure. |
| 16425 | // Parameters: |
| 16426 | // 1: HTREEITEM. |
| 16427 | { |
| 16428 | bool get_text = aID == FID_TV_GetText; |
| 16429 | |
| 16430 | HWND control_hwnd = hwnd; |
| 16431 | |
| 16432 | if (!get_text) |
| 16433 | { |
| 16434 | // Loadtime validation has ensured that param #1 and #2 are present for all these cases. |
| 16435 | HTREEITEM hitem = (HTREEITEM)ParamIndexToInt64(0); |
| 16436 | UINT state_mask; |
| 16437 | switch (ctoupper(*omit_leading_whitespace(ParamIndexToString(1, _f_number_buf)))) |
| 16438 | { |
| 16439 | case 'E': state_mask = TVIS_EXPANDED; break; // Expanded |
| 16440 | case 'C': state_mask = TVIS_STATEIMAGEMASK; break; // Checked |
| 16441 | case 'B': state_mask = TVIS_BOLD; break; // Bold |
| 16442 | //case 'S' for "Selected" is not provided because TV.GetSelection() seems to cover that well enough. |
| 16443 | //case 'P' for "is item a parent?" is not provided because TV.GetChild() seems to cover that well enough. |
| 16444 | // (though it's possible that retrieving TVITEM's cChildren would perform a little better). |
| 16445 | } |
| 16446 | // Below seems to be need a bit-AND with state_mask to work properly, at least on XP SP2. Otherwise, |
| 16447 | // extra bits are present such as 0x2002 for "expanded" when it's supposed to be either 0x00 or 0x20. |
| 16448 | UINT result = state_mask & (UINT)SendMessage(control_hwnd, TVM_GETITEMSTATE, (WPARAM)hitem, state_mask); |
| 16449 | if (state_mask == TVIS_STATEIMAGEMASK) |
| 16450 | { |
| 16451 | if (result != 0x2000) // It doesn't have a checkmark state image. |
| 16452 | hitem = 0; |
| 16453 | } |
| 16454 | else // For all others, anything non-zero means the flag is present. |
| 16455 | if (!result) // Flag not present. |
| 16456 | hitem = 0; |
| 16457 | _o_return((size_t)hitem); |
| 16458 | } |
| 16459 | |
| 16460 | TCHAR text_buf[LV_TEXT_BUF_SIZE]; // i.e. uses same size as ListView. |
| 16461 | TVITEM tvi; |
| 16462 | tvi.hItem = (HTREEITEM)ParamIndexToInt64(0); |
| 16463 | tvi.mask = TVIF_TEXT; |
| 16464 | tvi.pszText = text_buf; |
| 16465 | tvi.cchTextMax = LV_TEXT_BUF_SIZE - 1; // -1 because of nagging doubt about size vs. length. Some MSDN examples subtract one), such as TabCtrl_GetItem()'s cchTextMax. |
| 16466 | |
| 16467 | if (SendMessage(control_hwnd, TVM_GETITEM, 0, (LPARAM)&tvi)) |
| 16468 | { |
| 16469 | // Must use tvi.pszText vs. text_buf because MSDN says: "Applications should not assume that the text will |
| 16470 | // necessarily be placed in the specified buffer. The control may instead change the pszText member |
| 16471 | // of the structure to point to the new text rather than place it in the buffer." |
| 16472 | _o_return(tvi.pszText); |
| 16473 | } |
nothing calls this directly
no test coverage detected