diff options
Diffstat (limited to 'tipper/popwin.cpp')
-rw-r--r-- | tipper/popwin.cpp | 87 |
1 files changed, 66 insertions, 21 deletions
diff --git a/tipper/popwin.cpp b/tipper/popwin.cpp index d217883..4912c96 100644 --- a/tipper/popwin.cpp +++ b/tipper/popwin.cpp @@ -37,6 +37,7 @@ struct PopupWindowData { bool text_tip; int indent, sb_width; POINT start_cursor_pos; // work around bugs with hiding tips (timer check mouse position) + HBITMAP hBm; }; LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -256,6 +257,16 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa else _tcscpy(pwd->swzTitle, TranslateT("(Unknown)")); } + //get avatar if possible + char *proto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, (WPARAM)pwd->hContact, 0); + if(proto) { + char svc[256]; + mir_snprintf(svc, 256, "%s%s", proto, PS_GETAVATARINFO); + PROTO_AVATAR_INFORMATION AI = {0}; + AI.cbSize = sizeof(AI); + AI.hContact = pwd->hContact; + CallService(svc, (WPARAM)GAIF_FORCE, (LPARAM)&AI); + } SendMessage(hwnd, PUM_REFRESH_VALUES, 0, 0); } } @@ -374,7 +385,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa SetBkMode(hdc, TRANSPARENT); // avatar - if(!pwd->text_tip && options.av_layout != PAV_NONE && pwd->av_height) { + if(!pwd->text_tip && options.av_layout != PAV_NONE && pwd->av_height && pwd->hBm) { RECT avr; avr.top = options.av_padding; @@ -390,19 +401,47 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa avr.bottom = avr.top + pwd->real_av_height; - AVATARDRAWREQUEST adr = {0}; - adr.cbSize = sizeof(adr); - adr.hContact = pwd->hContact; - adr.hTargetDC = ps.hdc; - adr.rcDraw = avr; - adr.dwFlags = (options.av_round ? AVDRQ_ROUNDEDCORNER : 0); - if(!pwd->hContact) { // status bar tip? - adr.dwFlags |= AVDRQ_OWNPIC; - adr.szProto = pwd->clcit.proto; - } - adr.radius = (options.av_round ? 5 : 0); - - CallService(MS_AV_DRAWAVATAR, 0, (LPARAM)&adr); + HDC hdcMem = CreateCompatibleDC(hdc);
+ HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, pwd->hBm);
+ BITMAP bm;
+
+ GetObject(pwd->hBm, sizeof(bm), &bm);
+ HRGN rgn = 0;
+ if(options.av_round) {
+ rgn = CreateRoundRectRgn(avr.left, avr.top, avr.right + 1, avr.bottom + 1, 10, 10);
+ SelectClipRgn(hdc, rgn);
+ }
+
+ if(options.no_resize_av) {
+ BitBlt(hdc, avr.left, avr.top, avr.right - avr.left, avr.bottom - avr.top, hdcMem, 0, 0, SRCCOPY);
+ } else {
+ SetStretchBltMode(hdc, HALFTONE);
+ StretchBlt(hdc, avr.left, avr.top, avr.right - avr.left, avr.bottom - avr.top, hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
+ }
+
+ if(rgn) {
+ SelectClipRgn(hdc, 0);
+ DeleteObject(rgn);
+ }
+
+ SelectObject(hdcMem, hbmOld);
+ DeleteDC(hdcMem); + + /* + AVATARDRAWREQUEST adr = {0}; + adr.cbSize = sizeof(adr); + adr.hContact = pwd->hContact; + adr.hTargetDC = ps.hdc; + adr.rcDraw = avr; + adr.dwFlags = (options.av_round ? AVDRQ_ROUNDEDCORNER : 0);// | (options.no_resize_av ? AVDRQ_DONTRESIZEIFSMALLER : 0); + if(!pwd->hContact) { // status bar tip? + adr.dwFlags |= AVDRQ_OWNPIC; + adr.szProto = pwd->clcit.proto; + } + adr.radius = (options.av_round ? 5 : 0); + + CallService(MS_AV_DRAWAVATAR, 0, (LPARAM)&adr); + */ } RECT tr; @@ -538,6 +577,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa } free(pwd->rows); + if(pwd->hBm) DeleteObject(pwd->hBm); free(pwd); pwd = 0; SetWindowLong(hwnd, GWL_USERDATA, 0); } @@ -688,16 +728,21 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa AVATARCACHEENTRY *ace = 0; if(pwd->hContact) ace = (AVATARCACHEENTRY *)CallService(MS_AV_GETAVATARBITMAP, (WPARAM)pwd->hContact, 0); else ace = (AVATARCACHEENTRY *)CallService(MS_AV_GETMYAVATAR, 0, (LPARAM)pwd->clcit.proto); + if(ace && (ace->dwFlags & AVS_BITMAP_VALID) && !(ace->dwFlags & AVS_HIDEONCLIST)) { - if(options.no_resize_av) { - pwd->real_av_width = ace->bmWidth; - pwd->real_av_height = ace->bmHeight; + if(pwd->hBm) DeleteObject(pwd->hBm); + pwd->hBm = (HBITMAP)CallService(MS_UTILS_LOADBITMAP,0,(LPARAM)ace->szFilename); + BITMAP bm; + GetObject(pwd->hBm, sizeof(bm), &bm); + if(options.no_resize_av || (bm.bmHeight <= options.av_size && bm.bmWidth <= options.av_size)) { + pwd->real_av_width = bm.bmWidth; + pwd->real_av_height = bm.bmHeight; } else { - if(ace->bmHeight >= ace->bmWidth) { + if(bm.bmHeight >= bm.bmWidth) { pwd->real_av_height = options.av_size; - pwd->real_av_width = (int)(options.av_size * (ace->bmWidth / (double)ace->bmHeight)); + pwd->real_av_width = (int)(options.av_size * (bm.bmWidth / (double)bm.bmHeight)); } else { - pwd->real_av_height = (int)(options.av_size * (ace->bmHeight / (double)ace->bmWidth)); + pwd->real_av_height = (int)(options.av_size * (bm.bmHeight / (double)bm.bmWidth)); pwd->real_av_width = options.av_size; } } @@ -759,7 +804,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa if(width < options.win_width) { int wid = options.padding + pwd->indent + (pwd->rows[i].value_newline ? max(size.cx, smr.right - smr.left) : pwd->label_width + options.padding + (smr.right - smr.left)); if(pwd->tb_height + pwd->text_height + options.text_padding < pwd->av_height) - width = max(width, wid + options.av_size + 2 * options.av_padding); + width = max(width, wid + pwd->real_av_width + 2 * options.av_padding); else width = max(width, wid + options.padding); } |