check if text can be appended to the last line without wrapping */
| 781 | |
| 782 | /* check if text can be appended to the last line without wrapping */ |
| 783 | BOOL |
| 784 | can_append_text(HWND hWnd, int attr, const char *text) |
| 785 | { |
| 786 | PNHMessageWindow data; |
| 787 | char tmptext[MAXWINDOWTEXT + 1]; |
| 788 | HDC hdc; |
| 789 | HGDIOBJ saveFont; |
| 790 | RECT draw_rt; |
| 791 | BOOL retval = FALSE; |
| 792 | |
| 793 | data = (PNHMessageWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); |
| 794 | |
| 795 | /* cannot append if lines_not_seen is 0 (beginning of the new turn */ |
| 796 | if (data->lines_not_seen == 0) |
| 797 | return FALSE; |
| 798 | |
| 799 | /* cannot append text with different attributes */ |
| 800 | if (data->window_text[MSG_LINES - 1].attr != attr) |
| 801 | return FALSE; |
| 802 | |
| 803 | /* cannot append if current line ends in newline */ |
| 804 | if (str_end_is(data->window_text[MSG_LINES - 1].text, "\n")) |
| 805 | return FALSE; |
| 806 | |
| 807 | /* check if the maximum string length will be exceeded */ |
| 808 | if (strlen(data->window_text[MSG_LINES - 1].text) + 2 |
| 809 | + /* space characters */ |
| 810 | strlen(text) + strlen(MORE) |
| 811 | >= MAXWINDOWTEXT) |
| 812 | return FALSE; |
| 813 | |
| 814 | /* check if the text is going to fit into a single line */ |
| 815 | strcpy(tmptext, data->window_text[MSG_LINES - 1].text); |
| 816 | strcat(tmptext, " "); |
| 817 | strcat(tmptext, text); |
| 818 | strip_newline(tmptext); |
| 819 | strcat(tmptext, MORE); |
| 820 | |
| 821 | hdc = GetDC(hWnd); |
| 822 | cached_font * font = mswin_get_font(NHW_MESSAGE, |
| 823 | data->window_text[MSG_LINES - 1].attr, hdc, FALSE); |
| 824 | saveFont = SelectObject(hdc, font->hFont); |
| 825 | GetClientRect(hWnd, &draw_rt); |
| 826 | draw_rt.left += LINE_PADDING_LEFT(data); |
| 827 | draw_rt.right -= LINE_PADDING_RIGHT(data); |
| 828 | draw_rt.bottom = draw_rt.top; /* we only need width for the DrawText */ |
| 829 | DrawText(hdc, tmptext, strlen(tmptext), &draw_rt, |
| 830 | DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT); |
| 831 | |
| 832 | /* we will check against 1.5 of the font size in order to determine |
| 833 | if the text is single-line or not - just to be on the safe size */ |
| 834 | retval = (draw_rt.bottom - draw_rt.top) < (data->yChar + data->yChar / 2); |
| 835 | |
| 836 | /* free device context */ |
| 837 | SelectObject(hdc, saveFont); |
| 838 | ReleaseDC(hWnd, hdc); |
| 839 | return retval; |
| 840 | } |
no test coverage detected