| 598 | } |
| 599 | |
| 600 | void |
| 601 | onPaint(HWND hWnd) |
| 602 | { |
| 603 | PAINTSTRUCT ps; |
| 604 | HDC hdc; |
| 605 | PNHMessageWindow data; |
| 606 | RECT client_rt, draw_rt; |
| 607 | int FirstLine, LastLine; |
| 608 | int i, y; |
| 609 | HGDIOBJ oldFont; |
| 610 | TCHAR wbuf[MAXWINDOWTEXT + 2]; |
| 611 | size_t wlen; |
| 612 | COLORREF OldBg, OldFg; |
| 613 | |
| 614 | hdc = BeginPaint(hWnd, &ps); |
| 615 | |
| 616 | OldBg = SetBkColor( |
| 617 | hdc, message_bg_brush ? message_bg_color |
| 618 | : (COLORREF) GetSysColor(DEFAULT_COLOR_BG_MSG)); |
| 619 | OldFg = setMsgTextColor(hdc, 0); |
| 620 | |
| 621 | data = (PNHMessageWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA); |
| 622 | |
| 623 | GetClientRect(hWnd, &client_rt); |
| 624 | |
| 625 | if (!IsRectEmpty(&ps.rcPaint)) { |
| 626 | FirstLine = max( |
| 627 | 0, data->yPos - (client_rt.bottom - ps.rcPaint.top) / data->yChar |
| 628 | + 1); |
| 629 | LastLine = |
| 630 | min(MSG_LINES - 1, |
| 631 | data->yPos |
| 632 | - (client_rt.bottom - ps.rcPaint.bottom) / data->yChar); |
| 633 | y = min(ps.rcPaint.bottom, client_rt.bottom); |
| 634 | for (i = LastLine; i >= FirstLine; i--) { |
| 635 | char tmptext[MAXWINDOWTEXT + 1]; |
| 636 | |
| 637 | draw_rt.left = LINE_PADDING_LEFT(data); |
| 638 | draw_rt.right = client_rt.right - LINE_PADDING_RIGHT(data); |
| 639 | draw_rt.top = y - data->yChar; |
| 640 | draw_rt.bottom = y; |
| 641 | |
| 642 | cached_font * font = mswin_get_font(NHW_MESSAGE, |
| 643 | data->window_text[i].attr, hdc, FALSE); |
| 644 | oldFont = SelectObject(hdc, font->hFont); |
| 645 | |
| 646 | /* convert to UNICODE stripping newline */ |
| 647 | strcpy(tmptext, data->window_text[i].text); |
| 648 | strip_newline(tmptext); |
| 649 | NH_A2W(tmptext, wbuf, sizeof(wbuf)); |
| 650 | wbuf[SIZE(wbuf) - 1] = '\0'; |
| 651 | wlen = _tcslen(wbuf); |
| 652 | setMsgTextColor(hdc, i < (MSG_LINES - data->lines_last_turn)); |
| 653 | #ifdef MSG_WRAP_TEXT |
| 654 | /* Find out how large the bounding rectangle of the text is */ |
| 655 | DrawText(hdc, wbuf, wlen, &draw_rt, |
| 656 | DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT); |
| 657 | /* move that rectangle up, so that the bottom remains at the same |
no test coverage detected