| 1508 | |
| 1509 | |
| 1510 | ResultType GuiType::ControlSetPic(GuiControlType &aControl, LPTSTR aContents, ResultToken &aResultToken) |
| 1511 | { |
| 1512 | // Update: The below doesn't work, so it will be documented that a picture control |
| 1513 | // should be always be referred to by its original filename even if the picture changes. |
| 1514 | // Set the text unconditionally even if the picture can't be loaded. This text must |
| 1515 | // be set to allow GuiControl(Get) to be able to operate upon the picture without |
| 1516 | // needing to identify it via something like "Static14". |
| 1517 | //SetWindowText(control.hwnd, aContents); |
| 1518 | //SendMessage(control.hwnd, WM_SETTEXT, 0, (LPARAM)aContents); |
| 1519 | |
| 1520 | // Set default options, to be possibly overridden by any options actually present: |
| 1521 | // Fixed for v1.0.23: Below should use GetClientRect() vs. GetWindowRect(), otherwise |
| 1522 | // a size too large will be returned if the control has a border: |
| 1523 | RECT rect; |
| 1524 | GetClientRect(aControl.hwnd, &rect); |
| 1525 | int width = rect.right - rect.left; |
| 1526 | int height = rect.bottom - rect.top; |
| 1527 | int icon_number = 0; // Zero means "load icon or bitmap (doesn't matter)". |
| 1528 | // Note that setting the control's picture handle to NULL sometimes or always shrinks |
| 1529 | // the control down to zero dimensions, so must be done only after the above. |
| 1530 | |
| 1531 | // Parse any options that are present in front of the filename: |
| 1532 | LPTSTR next_option = omit_leading_whitespace(aContents); |
| 1533 | if (*next_option == '*') // Options are present. Must check this here and in the for-loop to avoid omitting legitimate whitespace in a filename that starts with spaces. |
| 1534 | { |
| 1535 | LPTSTR option_end; |
| 1536 | TCHAR orig_char; |
| 1537 | for (; *next_option == '*'; next_option = omit_leading_whitespace(option_end)) |
| 1538 | { |
| 1539 | // Find the end of this option item: |
| 1540 | if ( !(option_end = StrChrAny(next_option, _T(" \t"))) ) // Space or tab. |
| 1541 | option_end = next_option + _tcslen(next_option); // Set to position of zero terminator instead. |
| 1542 | // Permanently terminate in between options to help eliminate ambiguity for words contained |
| 1543 | // inside other words, and increase confidence in decimal and hexadecimal conversion. |
| 1544 | orig_char = *option_end; |
| 1545 | *option_end = '\0'; |
| 1546 | ++next_option; // Skip over the asterisk. It might point to a zero terminator now. |
| 1547 | if (!_tcsnicmp(next_option, _T("Icon"), 4)) |
| 1548 | icon_number = ATOI(next_option + 4); // LoadPicture() correctly handles any negative value. |
| 1549 | else |
| 1550 | { |
| 1551 | switch (ctoupper(*next_option)) |
| 1552 | { |
| 1553 | case 'W': |
| 1554 | width = ATOI(next_option + 1); |
| 1555 | break; |
| 1556 | case 'H': |
| 1557 | height = ATOI(next_option + 1); |
| 1558 | break; |
| 1559 | // If not one of the above, such as zero terminator or a number, just ignore it. |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | *option_end = orig_char; // Undo the temporary termination so that loop's omit_leading() will work. |
| 1564 | } // for() each item in option list |
| 1565 | |
| 1566 | // The below assigns option_end + 1 vs. next_option in case the filename is contained in a |
| 1567 | // variable ref and/ that filename contains leading spaces. Example: |
nothing calls this directly
no test coverage detected