From 4813e22b08398091946738cd324d73455f9b5b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Tue, 9 Dec 2014 17:08:21 +0000 Subject: Steam: Fix showing xstatus icon in contact list (step 2) git-svn-id: http://svn.miranda-ng.org/main/trunk@11301 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Steam/src/common.h | 1 + protocols/Steam/src/steam_proto.cpp | 7 ++-- protocols/Steam/src/steam_proto.h | 9 +++-- protocols/Steam/src/steam_xstatus.cpp | 67 +++++++++++++++++++++++++++++------ 4 files changed, 67 insertions(+), 17 deletions(-) (limited to 'protocols/Steam') diff --git a/protocols/Steam/src/common.h b/protocols/Steam/src/common.h index 3e654c1d8a..37822139b9 100644 --- a/protocols/Steam/src/common.h +++ b/protocols/Steam/src/common.h @@ -32,6 +32,7 @@ #include #include #include +#include #include "resource.h" #include "version.h" diff --git a/protocols/Steam/src/steam_proto.cpp b/protocols/Steam/src/steam_proto.cpp index bd255c5e10..1cd0193702 100644 --- a/protocols/Steam/src/steam_proto.cpp +++ b/protocols/Steam/src/steam_proto.cpp @@ -58,9 +58,10 @@ CSteamProto::CSteamProto(const char* protoName, const TCHAR* userName) : CreateProtoService(PS_GETAVATARCAPS, &CSteamProto::GetAvatarCaps); CreateProtoService(PS_GETMYAVATART, &CSteamProto::GetMyAvatar); // custom status API - CreateProtoService(PS_GETCUSTOMSTATUSEX, &CSteamProto::GetXStatusEx); - CreateProtoService(PS_GETCUSTOMSTATUSICON, &CSteamProto::GetXStatusIcon); - CreateProtoService(PS_GETADVANCEDSTATUSICON, &CSteamProto::RequestAdvStatusIconIdx); + CreateProtoService(PS_GETCUSTOMSTATUSEX, &CSteamProto::OnGetXStatusEx); + CreateProtoService(PS_GETCUSTOMSTATUSICON, &CSteamProto::OnGetXStatusIcon); + CreateProtoService(PS_GETADVANCEDSTATUSICON, &CSteamProto::OnRequestAdvStatusIconIdx); + HookEvent(ME_SKIN2_ICONSCHANGED, OnReloadIcons); } CSteamProto::~CSteamProto() diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 850f97b581..47fe830eef 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -255,9 +255,10 @@ protected: INT_PTR __cdecl GetMyAvatar(WPARAM, LPARAM); // xstatuses - INT_PTR __cdecl GetXStatusEx(WPARAM wParam, LPARAM lParam); - INT_PTR __cdecl GetXStatusIcon(WPARAM wParam, LPARAM lParam); - INT_PTR __cdecl RequestAdvStatusIconIdx(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl OnGetXStatusEx(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl OnGetXStatusIcon(WPARAM wParam, LPARAM lParam); + INT_PTR __cdecl OnRequestAdvStatusIconIdx(WPARAM wParam, LPARAM lParam); + HICON GetXStatusIcon(int status, UINT flags); int GetContactXStatus(MCONTACT hContact); // events @@ -289,4 +290,6 @@ protected: inline int IdleSeconds() { return m_idleTS ? time(0) - m_idleTS : 0; } }; +int OnReloadIcons(WPARAM wParam, LPARAM lParam); + #endif //_STEAM_PROTO_H_ \ No newline at end of file diff --git a/protocols/Steam/src/steam_xstatus.cpp b/protocols/Steam/src/steam_xstatus.cpp index f7e5ac59a7..c67ddf5f6b 100644 --- a/protocols/Steam/src/steam_xstatus.cpp +++ b/protocols/Steam/src/steam_xstatus.cpp @@ -3,12 +3,21 @@ #define STATUS_TITLE_MAX 64 #define STATUS_DESC_MAX 255 +static std::vector xstatusIconsValid; +static std::map xstatusIcons; + +int OnReloadIcons(WPARAM wParam, LPARAM lParam) +{ + xstatusIconsValid.clear(); + return 0; +} + int CSteamProto::GetContactXStatus(MCONTACT hContact) { return getDword(hContact, "XStatusId", 0) ? 1 : 0; } -INT_PTR CSteamProto::GetXStatusEx(WPARAM wParam, LPARAM lParam) +INT_PTR CSteamProto::OnGetXStatusEx(WPARAM wParam, LPARAM lParam) { MCONTACT hContact = (MCONTACT)wParam; @@ -73,7 +82,19 @@ INT_PTR CSteamProto::GetXStatusEx(WPARAM wParam, LPARAM lParam) return 0; } -INT_PTR CSteamProto::GetXStatusIcon(WPARAM wParam, LPARAM lParam) +HICON CSteamProto::GetXStatusIcon(int status, UINT flags) +{ + if (status < 1) + return 0; + + char iconName[100]; + mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, "gaming"); + + HICON icon = Skin_GetIcon(iconName, (flags & LR_BIGICON) ? 32 : 16); + return (flags & LR_SHARED) ? icon : CopyIcon(icon); +} + +INT_PTR CSteamProto::OnGetXStatusIcon(WPARAM wParam, LPARAM lParam) { if (!wParam) wParam = GetContactXStatus(NULL); @@ -81,18 +102,42 @@ INT_PTR CSteamProto::GetXStatusIcon(WPARAM wParam, LPARAM lParam) if (wParam < 1) return 0; - char iconName[100]; - mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, "gaming"); - - HICON icon = Skin_GetIcon(iconName, (lParam & LR_BIGICON) ? 32 : 16); - return (lParam & LR_SHARED) ? (INT_PTR)icon : (INT_PTR)CopyIcon(icon); + return (INT_PTR)GetXStatusIcon(wParam, lParam); } -INT_PTR CSteamProto::RequestAdvStatusIconIdx(WPARAM wParam, LPARAM lParam) +INT_PTR CSteamProto::OnRequestAdvStatusIconIdx(WPARAM wParam, LPARAM lParam) { int status = GetContactXStatus(wParam); - if (status < 1) - return -1; + if (status) + { + if (std::find(xstatusIconsValid.begin(), xstatusIconsValid.end(), status) == xstatusIconsValid.end()) + { + // adding/updating icon + HIMAGELIST clistImageList = (HIMAGELIST)CallService(MS_CLIST_GETICONSIMAGELIST, 0, 0); + if (clistImageList) + { + HICON hXStatusIcon = GetXStatusIcon(status, LR_SHARED); + + std::map::iterator it = xstatusIcons.find(status); + if (it != xstatusIcons.end() && it->second > 0) + ImageList_ReplaceIcon(clistImageList, it->first, hXStatusIcon); + else + xstatusIcons.insert(std::make_pair(status, ImageList_AddIcon(clistImageList, hXStatusIcon))); + + // mark icon index in the array as valid + xstatusIconsValid.push_back(status); + + Skin_ReleaseIcon(hXStatusIcon); + } + } + + if (std::find(xstatusIconsValid.begin(), xstatusIconsValid.end(), status) != xstatusIconsValid.end()) + { + std::map::iterator it = xstatusIcons.find(status); + if (it != xstatusIcons.end()) + return (it->second & 0xFFFF) << 16; + } + } - return ((status & 0xFFFF) << 16); + return -1; } \ No newline at end of file -- cgit v1.2.3