From c0fea55f25ad1f675f40815cefb34b435f32119b Mon Sep 17 00:00:00 2001 From: sje Date: Thu, 23 Nov 2006 03:22:51 +0000 Subject: use ansi font services if unicode ones unavailable bugfixes to allow pure ansi build git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@57 4f64403b-2f21-0410-a795-97e2b3489a10 --- yapp/popwin.cpp | 52 ++++++++++++++-------------------------------------- 1 file changed, 14 insertions(+), 38 deletions(-) (limited to 'yapp/popwin.cpp') diff --git a/yapp/popwin.cpp b/yapp/popwin.cpp index 9915961..3e327b3 100644 --- a/yapp/popwin.cpp +++ b/yapp/popwin.cpp @@ -2,6 +2,7 @@ #include "popwin.h" #include "message_pump.h" #include "options.h" +#include "str_utils.h" HMODULE hUserDll; BOOL (WINAPI *MySetLayeredWindowAttributes)(HWND,COLORREF,BYTE,DWORD) = 0; @@ -149,19 +150,6 @@ struct PopupWindowData { HANDLE hNotify; }; -void trim(TCHAR *str) { - int len = _tcslen(str), pos; - // trim whitespace (e.g. from OTR detection) - for(pos = len - 1; pos >= 0; pos--) { - if(str[pos] == _T(' ') || str[pos] == _T('\t') || str[pos] == _T('\r') || str[pos] == _T('\n')) str[pos] = 0; - else break; - } - - // remove tabs - for(pos = len - 1; pos >= 0; pos--) - if(str[pos] == _T('\t')) str[pos] = _T(' '); -} - LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { PopupWindowData *pwd = (PopupWindowData *)GetWindowLong(hwnd, GWL_USERDATA); POPUPDATAW *pd = 0; @@ -176,8 +164,8 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa pwd->pd = pd; pwd->hNotify = 0; - trim(pwd->pd->lpwzContactName); - trim(pwd->pd->lpwzText); + trimW(pwd->pd->lpwzContactName); + trimW(pwd->pd->lpwzText); pwd->is_round = options.round; pwd->av_is_round = options.av_round; @@ -417,7 +405,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa if(pwd->custom_col) SetTextColor(ps.hdc, pd->colorText); else SetTextColor(ps.hdc, colTime); if(hFontTime) SelectObject(hdc, (HGDIOBJ)hFontTime); - DrawText(ps.hdc, pwd->tbuff, wcslen(pwd->tbuff), &avr, DT_VCENTER | DT_CENTER | DT_LEFT | DT_SINGLELINE | DT_NOPREFIX); + DrawText(ps.hdc, pwd->tbuff, _tcslen(pwd->tbuff), &avr, DT_VCENTER | DT_CENTER | DT_LEFT | DT_SINGLELINE | DT_NOPREFIX); avr.top = avr.bottom + options.av_padding; } @@ -465,12 +453,12 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa case PT_LEFT: ttr.left = textxmin; ttr.right = ttr.left + pwd->time_width; textxmin += pwd->time_width + options.padding; - DrawText(ps.hdc, pwd->tbuff, wcslen(pwd->tbuff), &ttr, DT_VCENTER | DT_LEFT | DT_SINGLELINE | DT_NOPREFIX); + DrawText(ps.hdc, pwd->tbuff, _tcslen(pwd->tbuff), &ttr, DT_VCENTER | DT_LEFT | DT_SINGLELINE | DT_NOPREFIX); break; case PT_RIGHT: ttr.right = textxmax; ttr.left = ttr.right - pwd->time_width; textxmax -= pwd->time_width + options.padding; - DrawText(ps.hdc, pwd->tbuff, wcslen(pwd->tbuff), &ttr, DT_VCENTER | DT_LEFT | DT_SINGLELINE | DT_NOPREFIX); + DrawText(ps.hdc, pwd->tbuff, _tcslen(pwd->tbuff), &ttr, DT_VCENTER | DT_LEFT | DT_SINGLELINE | DT_NOPREFIX); break; default: break; @@ -486,7 +474,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa if(pwd->custom_col) SetTextColor(ps.hdc, pd->colorText); else SetTextColor(ps.hdc, colFirstLine); - DrawText(ps.hdc, pd->lpwzContactName, wcslen(pd->lpwzContactName), &tr, DT_VCENTER | DT_LEFT | DT_END_ELLIPSIS | DT_SINGLELINE | DT_NOPREFIX); + DrawTextW(ps.hdc, pd->lptzContactName, wcslen(pd->lpwzContactName), &tr, DT_VCENTER | DT_LEFT | DT_END_ELLIPSIS | DT_SINGLELINE | DT_NOPREFIX); // second line(s) int len_second = wcslen(pd->lpwzText); @@ -500,7 +488,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa GetClientRect(hwnd, &r); tr.left = r.left + options.padding + options.text_indent; tr.right = r.right - options.padding; tr.top = tr.bottom + options.padding; tr.bottom = r.bottom - options.padding; - DrawText(ps.hdc, pd->lpwzText, len_second, &tr, DT_NOPREFIX | DT_WORDBREAK | DT_EXTERNALLEADING | DT_TOP | DT_LEFT | DT_WORD_ELLIPSIS); + DrawTextW(ps.hdc, pd->lpwzText, len_second, &tr, DT_NOPREFIX | DT_WORDBREAK | DT_EXTERNALLEADING | DT_TOP | DT_LEFT | DT_WORD_ELLIPSIS); } EndPaint(hwnd, &ps); @@ -586,14 +574,14 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa if(options.time_layout != PT_NONE) { SIZE size_t; if(hFontTime) SelectObject(hdc, (HGDIOBJ)hFontTime); - GetTextExtentPoint32(hdc, pwd->tbuff, wcslen(pwd->tbuff), &size_t); + GetTextExtentPoint32(hdc, pwd->tbuff, _tcslen(pwd->tbuff), &size_t); pwd->time_height = size_t.cy; pwd->time_width = size_t.cx; } // titlebar height if(hFontFirstLine) SelectObject(hdc, (HGDIOBJ)hFontFirstLine); - GetTextExtentPoint32(hdc, pd->lpwzContactName, wcslen(pd->lpwzContactName), &size); + GetTextExtentPoint32W(hdc, pd->lpwzContactName, wcslen(pd->lptzContactName), &size); pwd->tb_height = size.cy; if(options.time_layout == PT_LEFT || options.time_layout == PT_RIGHT) { if(pwd->tb_height < pwd->time_height) pwd->tb_height = pwd->time_height; @@ -617,7 +605,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa } // text height - int len_second = wcslen(pd->lpwzText); + int len_second = wcslen(pd->lptzText); if(len_second) { RECT r; r.left = r.top = 0; @@ -630,7 +618,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa r.right -= pwd->time_width + options.padding; if(hFontSecondLine) SelectObject(hdc, (HGDIOBJ)hFontSecondLine); - DrawText(hdc, pd->lpwzText, len_second, &r, DT_CALCRECT | DT_NOPREFIX | DT_WORDBREAK | DT_EXTERNALLEADING | DT_TOP | DT_LEFT | DT_WORD_ELLIPSIS); + DrawTextW(hdc, pd->lpwzText, len_second, &r, DT_CALCRECT | DT_NOPREFIX | DT_WORDBREAK | DT_EXTERNALLEADING | DT_TOP | DT_LEFT | DT_WORD_ELLIPSIS); pwd->text_height = r.bottom; } @@ -694,23 +682,11 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa pd->lchContact = (HANDLE)MNotifyGetDWord(pwd->hNotify, NFOPT_CONTACT, 0); pd->lchIcon = (HICON)MNotifyGetDWord(pwd->hNotify, NFOPT_ICON, 0); const wchar_t *swzName = MNotifyGetWString(pwd->hNotify, NFOPT_TITLEW, 0); - if(swzName) { - wcsncpy(pd->lpwzContactName, swzName, MAX_CONTACTNAME); - } else { - const char *szName = MNotifyGetString(pwd->hNotify, NFOPT_TITLE, 0); - if(szName) MultiByteToWideChar(code_page, 0, szName, -1, pd->lpwzContactName, MAX_CONTACTNAME); - else pd->lpwzContactName[0] = 0; - } + wcsncpy(pd->lpwzContactName, swzName, MAX_CONTACTNAME); pd->lpwzContactName[MAX_CONTACTNAME - 1] = 0; const wchar_t *swzText = MNotifyGetWString(pwd->hNotify, NFOPT_TEXTW, 0); - if(swzText) { - wcsncpy(pd->lpwzText, swzText, MAX_SECONDLINE); - } else { - const char *szText = MNotifyGetString(pwd->hNotify, NFOPT_TEXT, 0); - if(szText) MultiByteToWideChar(code_page, 0, szText, -1, pd->lpwzText, MAX_SECONDLINE); - else pd->lpwzText[0] = 0; - } + wcsncpy(pd->lpwzText, swzText, MAX_SECONDLINE); pd->lpwzText[MAX_SECONDLINE - 1] = 0; InvalidateRect(hwnd, 0, TRUE); RepositionWindows(); -- cgit v1.2.3