diff options
Diffstat (limited to 'yapp/popwin.cpp')
-rw-r--r-- | yapp/popwin.cpp | 113 |
1 files changed, 67 insertions, 46 deletions
diff --git a/yapp/popwin.cpp b/yapp/popwin.cpp index 2647d0b..8ff4619 100644 --- a/yapp/popwin.cpp +++ b/yapp/popwin.cpp @@ -139,7 +139,7 @@ void BroadcastMessage(UINT msg, WPARAM wParam, LPARAM lParam) { }
struct PopupWindowData {
- POPUPDATAW *pd;
+ PopupData pd;
int new_x, new_y;
bool is_round, av_is_round, mouse_in, close_on_leave;
bool custom_col;
@@ -154,20 +154,22 @@ struct PopupWindowData { LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
PopupWindowData *pwd = (PopupWindowData *)GetWindowLong(hwnd, GWL_USERDATA);
- POPUPDATAW *pd = 0;
- if(pwd) pd = pwd->pd;
+ PopupData *pd = 0;
+ if(pwd) pd = &pwd->pd;
switch(uMsg) {
case WM_CREATE:
{
CREATESTRUCT *cs = (CREATESTRUCT *)lParam;
pwd = (PopupWindowData *)malloc(sizeof(PopupWindowData));
- pd = (POPUPDATAW *)cs->lpCreateParams;
- pwd->pd = pd;
+ pd = (PopupData *)cs->lpCreateParams;
+ pwd->pd = *pd;
+ if(pd->pwzTitle) pwd->pd.pwzTitle = wcsdup(pd->pwzTitle);
+ if(pd->pwzText) pwd->pd.pwzText = wcsdup(pd->pwzText);
pwd->hNotify = 0;
- trimW(pwd->pd->lpwzContactName);
- trimW(pwd->pd->lpwzText);
+ trimW(pwd->pd.pwzTitle);
+ trimW(pwd->pd.pwzText);
pwd->is_round = options.round;
pwd->av_is_round = options.av_round;
@@ -202,14 +204,14 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa SetWindowLong(hwnd, GWL_USERDATA, (LONG)pwd);
- if(pd->iSeconds == -1 || (pd->iSeconds == 0 && options.default_timeout == -1)) {
+ if(pd->timeout == -1 || (pd->timeout == 0 && options.default_timeout == -1)) {
// make a really long timeout - say 7 days? ;)
SetTimer(hwnd, ID_CLOSETIMER, 7 * 24 * 60 * 60 * 1000, 0);
} else {
- if(pd->iSeconds == 0) {
+ if(pd->timeout == 0) {
SetTimer(hwnd, ID_CLOSETIMER, options.default_timeout * 1000, 0);
} else {
- SetTimer(hwnd, ID_CLOSETIMER, pd->iSeconds * 1000, 0);
+ SetTimer(hwnd, ID_CLOSETIMER, pd->timeout * 1000, 0);
}
}
@@ -240,7 +242,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa }
}
#endif
- PostMessage(hwnd, UM_INITPOPUP, (WPARAM)hwnd, 0);
+ PostMessage(hwnd, PM_INIT, (WPARAM)hwnd, 0);
return 0;
case WM_MOUSEMOVE:
if(pwd && !pwd->mouse_in) {
@@ -268,7 +270,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa if(pwd->mouse_in || (options.global_hover && global_mouse_in))
SetTimer(hwnd, ID_CLOSETIMER, 800, 0); // reset timer if mouse in window - allow another 800 ms
else {
- PostMessage(hwnd, UM_DESTROYPOPUP, 0, 0);
+ PostMessage(hwnd, PM_DESTROY, 0, 0);
}
return TRUE;
} else if(wParam == ID_MOVETIMER) {
@@ -423,7 +425,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa AVATARDRAWREQUEST adr = {0};
adr.cbSize = sizeof(adr);
- adr.hContact = pd->lchContact;
+ adr.hContact = pd->hContact;
adr.hTargetDC = ps.hdc;
adr.rcDraw = avr;
adr.dwFlags = (pwd->av_is_round ? AVDRQ_ROUNDEDCORNER : 0);
@@ -435,7 +437,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa // title icon
int iconx, textxmin = r.left + options.padding, textxmax = r.right - options.padding;
- if(pd->lchIcon) {
+ if(pd->hIcon) {
if(options.right_icon) {
iconx = r.right - (16 + options.padding);
textxmax -= 16 + options.padding;
@@ -443,7 +445,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa iconx = r.left + options.padding;
textxmin += 16 + options.padding;
}
- DrawIconEx(ps.hdc, iconx, options.padding + (pwd->tb_height - 16) / 2, pd->lchIcon, 16, 16, 0, NULL, DI_NORMAL);
+ DrawIconEx(ps.hdc, iconx, options.padding + (pwd->tb_height - 16) / 2, pd->hIcon, 16, 16, 0, NULL, DI_NORMAL);
}
// title time
@@ -478,7 +480,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);
- DrawTextW(ps.hdc, pd->lptzContactName, wcslen(pd->lpwzContactName), &tr, DT_VCENTER | DT_LEFT | DT_END_ELLIPSIS | DT_SINGLELINE | DT_NOPREFIX);
+ DrawTextW(ps.hdc, pd->pwzTitle, wcslen(pd->pwzTitle), &tr, DT_VCENTER | DT_LEFT | DT_END_ELLIPSIS | DT_SINGLELINE | DT_NOPREFIX);
// title underline
RECT tur;
@@ -489,7 +491,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa FillRect(ps.hdc, &tur, pwd->underlineBrush);
// second line(s)
- int len_second = wcslen(pd->lpwzText);
+ int len_second = wcslen(pd->pwzText);
if(len_second) {
if(hFontSecondLine) SelectObject(ps.hdc, (HGDIOBJ)hFontSecondLine);
if(!pwd->custom_col)
@@ -500,7 +502,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;
- DrawTextW(ps.hdc, pd->lpwzText, len_second, &tr, DT_NOPREFIX | DT_WORDBREAK | DT_EXTERNALLEADING | DT_TOP | DT_LEFT | DT_WORD_ELLIPSIS);
+ DrawTextW(ps.hdc, pd->pwzText, len_second, &tr, DT_NOPREFIX | DT_WORDBREAK | DT_EXTERNALLEADING | DT_TOP | DT_LEFT | DT_WORD_ELLIPSIS);
}
EndPaint(hwnd, &ps);
@@ -521,10 +523,11 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa RemoveWindowFromStack(hwnd);
- SendMessage(hwnd, UM_FREEPLUGINDATA, 0, 0);
+ SendMessage(hwnd, PM_DIENOTIFY, 0, 0);
- free(pd); pd = 0;
- free(pwd); pwd = 0;
+ if(pd->pwzTitle) free(pd->pwzTitle);
+ if(pd->pwzText) free(pd->pwzText);
+ free(pwd); pwd = 0; pd = 0;
SetWindowLong(hwnd, GWL_USERDATA, 0);
break;
@@ -563,7 +566,11 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa return TRUE;
case PUM_SETTEXT:
{
- wcscpy(pd->lpwzText, (wchar_t *)lParam);
+ if(pd->pszText) free(pd->pszText);
+ if(lParam)
+ pd->pwzText = wcsdup((wchar_t *)lParam);
+ else
+ pd->pwzText = 0;
// free((void *)lParam); // freed in message pump in case the window has gone
InvalidateRect(hwnd, 0, TRUE);
RepositionWindows();
@@ -573,7 +580,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa case PUM_GETCONTACT:
{
HANDLE *phContact = (HANDLE *)wParam;
- *phContact = pd->lchContact;
+ *phContact = pd->hContact;
if(lParam) SetEvent((HANDLE)lParam);
}
return TRUE;
@@ -594,7 +601,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa // titlebar height
if(hFontFirstLine) SelectObject(hdc, (HGDIOBJ)hFontFirstLine);
- GetTextExtentPoint32W(hdc, pd->lpwzContactName, wcslen(pd->lptzContactName), &size);
+ GetTextExtentPoint32W(hdc, pd->pwzTitle, wcslen(pd->pwzTitle), &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;
@@ -603,7 +610,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa // avatar height
if(options.av_layout != PAV_NONE && ServiceExists(MS_AV_DRAWAVATAR)) {
- AVATARCACHEENTRY *ace = (AVATARCACHEENTRY *)CallService(MS_AV_GETAVATARBITMAP, (WPARAM)pd->lchContact, 0);
+ AVATARCACHEENTRY *ace = (AVATARCACHEENTRY *)CallService(MS_AV_GETAVATARBITMAP, (WPARAM)pd->hContact, 0);
if(ace && (ace->dwFlags & AVS_BITMAP_VALID) && !(ace->dwFlags & AVS_HIDEONCLIST)) {
if(ace->bmHeight >= ace->bmWidth) {
pwd->real_av_height = options.av_size;
@@ -618,7 +625,7 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa }
// text height
- int len_second = wcslen(pd->lptzText);
+ int len_second = wcslen(pd->pwzText);
if(len_second) {
RECT r;
r.left = r.top = 0;
@@ -631,7 +638,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);
- DrawTextW(hdc, pd->lpwzText, len_second, &r, DT_CALCRECT | DT_NOPREFIX | DT_WORDBREAK | DT_EXTERNALLEADING | DT_TOP | DT_LEFT | DT_WORD_ELLIPSIS);
+ DrawTextW(hdc, pd->pwzText, len_second, &r, DT_CALCRECT | DT_NOPREFIX | DT_WORDBREAK | DT_EXTERNALLEADING | DT_TOP | DT_LEFT | DT_WORD_ELLIPSIS);
pwd->text_height = r.bottom;
}
@@ -653,25 +660,35 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa }
}
return TRUE;
- case PUM_GETPLUGINDATA:
+ case PUM_GETOPAQUE:
{
void **pData = (void **)wParam;
- if(pd) *pData = pd->PluginData;
+ if(pd) *pData = pd->opaque;
if(lParam) SetEvent((HANDLE)lParam);
}
return TRUE;
case PUM_CHANGE:
{
KillTimer(hwnd, ID_CLOSETIMER);
- free(pd);
- pwd->pd = pd = (POPUPDATAW *)malloc(sizeof(POPUPDATAW));
- memcpy(pd, (void *)lParam, sizeof(POPUPDATAW)); // the passed in value is freed in the message pump, in case the window has gone
+ PopupData *pdn = (PopupData *)lParam;
+ if(pd->pwzTitle) { free(pd->pwzTitle); pd->pwzTitle = 0; }
+ if(pd->pwzText) { free(pd->pwzText); pd->pwzText = 0; }
+
+ pwd->pd = *pdn;
+ if(pdn->flags & PDF_UNICODE) {
+ if(pdn->pwzTitle) pwd->pd.pwzTitle = wcsdup(pdn->pwzTitle);
+ if(pdn->pwzText) pwd->pd.pwzText = wcsdup(pdn->pwzText);
+ } else {
+ pwd->pd.flags |= PDF_UNICODE;
+ if(pd->pszTitle) pwd->pd.pwzTitle = a2w(pd->pszTitle);
+ if(pd->pszText) pwd->pd.pwzText = a2w(pd->pszText);
+ }
- if(pd->iSeconds != -1) {
- if(pd->iSeconds == 0) {
+ if(pd->timeout != -1) {
+ if(pd->timeout == 0) {
SetTimer(hwnd, ID_CLOSETIMER, 7 * 1000, 0);
} else {
- SetTimer(hwnd, ID_CLOSETIMER, pd->iSeconds * 1000, 0);
+ SetTimer(hwnd, ID_CLOSETIMER, pd->timeout * 1000, 0);
}
} else {
// make a really long timeout - say 7 days? ;)
@@ -691,16 +708,20 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa if(pwd->hNotify == (HANDLE)wParam) {
pd->colorBack = MNotifyGetDWord(pwd->hNotify, NFOPT_BACKCOLOR, colBg);
pd->colorText = MNotifyGetDWord(pwd->hNotify, NFOPT_TEXTCOLOR, colSecondLine);
- pd->iSeconds = MNotifyGetDWord(pwd->hNotify, NFOPT_TIMEOUT, options.default_timeout);
- pd->lchContact = (HANDLE)MNotifyGetDWord(pwd->hNotify, NFOPT_CONTACT, 0);
- pd->lchIcon = (HICON)MNotifyGetDWord(pwd->hNotify, NFOPT_ICON, 0);
+ pd->timeout = MNotifyGetDWord(pwd->hNotify, NFOPT_TIMEOUT, options.default_timeout);
+ pd->hContact = (HANDLE)MNotifyGetDWord(pwd->hNotify, NFOPT_CONTACT, 0);
+ pd->hIcon = (HICON)MNotifyGetDWord(pwd->hNotify, NFOPT_ICON, 0);
+
const wchar_t *swzName = MNotifyGetWString(pwd->hNotify, NFOPT_TITLEW, 0);
- wcsncpy(pd->lpwzContactName, swzName, MAX_CONTACTNAME);
- pd->lpwzContactName[MAX_CONTACTNAME - 1] = 0;
+ if(pd->pwzTitle) free(pd->pwzTitle);
+ if(swzName) pd->pwzTitle = wcsdup(swzName);
+ else pd->pwzTitle = 0;
const wchar_t *swzText = MNotifyGetWString(pwd->hNotify, NFOPT_TEXTW, 0);
- wcsncpy(pd->lpwzText, swzText, MAX_SECONDLINE);
- pd->lpwzText[MAX_SECONDLINE - 1] = 0;
+ if(pd->pwzText) free(pd->pwzText);
+ if(swzText) pd->pwzText = wcsdup(swzText);
+ else pd->pwzText= 0;
+
InvalidateRect(hwnd, 0, TRUE);
RepositionWindows();
}
@@ -711,18 +732,18 @@ LRESULT CALLBACK PopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa return TRUE;
// drop through
- case UM_DESTROYPOPUP:
+ case PM_DESTROY:
PostMPMessage(MUM_DELETEPOPUP, 0, (LPARAM)hwnd);
return TRUE;
}
- if(pd && pd->PluginWindowProc)
- return CallWindowProc(pd->PluginWindowProc, hwnd, uMsg, wParam, lParam);
+ if(pd && pd->windowProc)
+ return CallWindowProc(pd->windowProc, hwnd, uMsg, wParam, lParam);
else {
// provide a way to close popups, if no PluginWindowProc is provided
if(uMsg == WM_CONTEXTMENU) {
- SendMessage(hwnd, UM_DESTROYPOPUP, 0, 0);
+ SendMessage(hwnd, PM_DESTROY, 0, 0);
return TRUE;
} else
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|