From 375c728e532139cb4ee4fe8c8266d511e5c9a289 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 7 Apr 2018 12:59:27 +0300 Subject: Clist_GetRealStatus & Clist_GetGeneralizedStatus: common code moved to mir_app --- src/core/stdclist/src/clcpaint.cpp | 57 +++---------------------------- src/mir_app/src/clcidents.cpp | 69 ++++++++++++++++++++++++++++++++------ src/mir_app/src/mir_app.def | 2 ++ src/mir_app/src/mir_app64.def | 2 ++ 4 files changed, 67 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/core/stdclist/src/clcpaint.cpp b/src/core/stdclist/src/clcpaint.cpp index 05114952f2..a5808fa46c 100644 --- a/src/core/stdclist/src/clcpaint.cpp +++ b/src/core/stdclist/src/clcpaint.cpp @@ -89,58 +89,10 @@ static void __inline SetHotTrackColour(HDC hdc, struct ClcData *dat) else SetTextColor(hdc, dat->hotTextColour); } -static int GetStatusOnlineness(int status) -{ - switch (status) { - case ID_STATUS_FREECHAT: return 110; - case ID_STATUS_ONLINE: return 100; - case ID_STATUS_OCCUPIED: return 60; - case ID_STATUS_ONTHEPHONE: return 50; - case ID_STATUS_DND: return 40; - case ID_STATUS_AWAY: return 30; - case ID_STATUS_OUTTOLUNCH: return 20; - case ID_STATUS_NA: return 10; - case ID_STATUS_INVISIBLE: return 5; - } - return 0; -} - -static int GetGeneralisedStatus(void) -{ - int status = ID_STATUS_OFFLINE; - int statusOnlineness = 0; - - for (int i = 0; i < pcli->hClcProtoCount; i++) { - int thisStatus = pcli->clcProto[i].dwStatus; - if (thisStatus == ID_STATUS_INVISIBLE) - return ID_STATUS_INVISIBLE; - - int thisOnlineness = GetStatusOnlineness(thisStatus); - if (thisOnlineness > statusOnlineness) { - status = thisStatus; - statusOnlineness = thisOnlineness; - } - } - return status; -} - -static int GetRealStatus(struct ClcContact *contact, int status) -{ - char *szProto = contact->proto; - if (!szProto) - return status; - - for (int i = 0; i < pcli->hClcProtoCount; i++) - if (!mir_strcmp(pcli->clcProto[i].szProto, szProto)) - return pcli->clcProto[i].dwStatus; - - return status; -} - void PaintClc(HWND hwnd, struct ClcData *dat, HDC hdc, RECT * rcPaint) { DWORD style = GetWindowLongPtr(hwnd, GWL_STYLE); - int status = GetGeneralisedStatus(); + int status = Clist_GetGeneralizedStatus(); // yes I know about GetSysColorBrush() COLORREF tmpbkcolour = style & CLS_CONTACTLIST ? (dat->bUseWindowsColours ? GetSysColor(COLOR_3DFACE) : dat->bkColour) : dat->bkColour; @@ -304,7 +256,7 @@ void PaintClc(HWND hwnd, struct ClcData *dat, HDC hdc, RECT * rcPaint) ChangeToFont(hdcMem, dat, FONTID_DIVIDERS, &fontHeight); else if (cc->type == CLCIT_CONTACT && cc->flags & CONTACTF_NOTONLIST) ChangeToFont(hdcMem, dat, FONTID_NOTONLIST, &fontHeight); - else if (cc->type == CLCIT_CONTACT && ((cc->flags & CONTACTF_INVISTO && GetRealStatus(cc, status) != ID_STATUS_INVISIBLE) || (cc->flags & CONTACTF_VISTO && GetRealStatus(cc, status) == ID_STATUS_INVISIBLE))) { + else if (cc->type == CLCIT_CONTACT && ((cc->flags & CONTACTF_INVISTO && Clist_GetRealStatus(cc, status) != ID_STATUS_INVISIBLE) || (cc->flags & CONTACTF_VISTO && Clist_GetRealStatus(cc, status) == ID_STATUS_INVISIBLE))) { // the contact is in the always visible list and the proto is invisible // the contact is in the always invisible and the proto is in any other mode ChangeToFont(hdcMem, dat, cc->flags & CONTACTF_ONLINE ? FONTID_INVIS : FONTID_OFFINVIS, &fontHeight); @@ -374,10 +326,9 @@ void PaintClc(HWND hwnd, struct ClcData *dat, HDC hdc, RECT * rcPaint) colourFg = dat->fontInfo[FONTID_NOTONLIST].colour; mode = ILD_BLEND50; } - if (cc->type == CLCIT_CONTACT && dat->bShowIdle && (cc->flags & CONTACTF_IDLE) && GetRealStatus(cc, ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) + if (cc->type == CLCIT_CONTACT && dat->bShowIdle && (cc->flags & CONTACTF_IDLE) && Clist_GetRealStatus(cc, ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) mode = ILD_SELECTED; - ImageList_DrawEx(himlCListClc, iImage, hdcMem, dat->leftMargin + indent * dat->groupIndent + checkboxWidth, - y + ((dat->rowHeight - 16) >> 1), 0, 0, CLR_NONE, colourFg, mode); + ImageList_DrawEx(himlCListClc, iImage, hdcMem, dat->leftMargin + indent * dat->groupIndent + checkboxWidth, y + ((dat->rowHeight - 16) >> 1), 0, 0, CLR_NONE, colourFg, mode); } // extra icons diff --git a/src/mir_app/src/clcidents.cpp b/src/mir_app/src/clcidents.cpp index 0111a182ac..e06eba4d51 100644 --- a/src/mir_app/src/clcidents.cpp +++ b/src/mir_app/src/clcidents.cpp @@ -189,32 +189,81 @@ int fnGetRowByIndex(ClcData *dat, int testindex, ClcContact **contact, ClcGroup return -1; } -MIR_APP_DLL(DWORD) Clist_ContactToHItem(ClcContact *contact) +MIR_APP_DLL(DWORD) Clist_ContactToHItem(ClcContact *cc) { - switch (contact->type) { + switch (cc->type) { case CLCIT_CONTACT: - return contact->hContact; + return cc->hContact; case CLCIT_GROUP: - return contact->groupId | HCONTACT_ISGROUP; + return cc->groupId | HCONTACT_ISGROUP; case CLCIT_INFO: - return contact->hContact | HCONTACT_ISINFO; + return cc->hContact | HCONTACT_ISINFO; } return 0; } -MIR_APP_DLL(HANDLE) Clist_ContactToItemHandle(ClcContact *contact, DWORD *nmFlags) +MIR_APP_DLL(HANDLE) Clist_ContactToItemHandle(ClcContact *cc, DWORD *nmFlags) { - switch (contact->type) { + switch (cc->type) { case CLCIT_CONTACT: - return (HANDLE)contact->hContact; + return (HANDLE)cc->hContact; case CLCIT_GROUP: if (nmFlags) *nmFlags |= CLNF_ISGROUP; - return (HANDLE)contact->groupId; + return (HANDLE)cc->groupId; case CLCIT_INFO: if (nmFlags) *nmFlags |= CLNF_ISINFO; - return (HANDLE)((UINT_PTR)contact->hContact | HCONTACT_ISINFO); + return (HANDLE)((UINT_PTR)cc->hContact | HCONTACT_ISINFO); } return nullptr; } + +MIR_APP_DLL(int) Clist_GetRealStatus(ClcContact *cc, int iDefaultValue) +{ + char *szProto = cc->proto; + if (szProto != nullptr) + for (int i = 0; i < cli.hClcProtoCount; i++) + if (!mir_strcmp(cli.clcProto[i].szProto, szProto)) + return cli.clcProto[i].dwStatus; + + return iDefaultValue; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) Clist_GetGeneralizedStatus(char **szProto) +{ + int status = ID_STATUS_OFFLINE; + int statusOnlineness = 0; + + for (int i = 0; i < cli.hClcProtoCount; i++) { + int thisStatus = cli.clcProto[i].dwStatus; + if (thisStatus == ID_STATUS_INVISIBLE) + return ID_STATUS_INVISIBLE; + + int iStatusWeight; + switch (thisStatus) { + case ID_STATUS_FREECHAT: iStatusWeight = 110; break; + case ID_STATUS_ONLINE: iStatusWeight = 100; break; + case ID_STATUS_OCCUPIED: iStatusWeight = 60; break; + case ID_STATUS_ONTHEPHONE: iStatusWeight = 50; break; + case ID_STATUS_DND: iStatusWeight = 40; break; + case ID_STATUS_AWAY: iStatusWeight = 30; break; + case ID_STATUS_OUTTOLUNCH: iStatusWeight = 20; break; + case ID_STATUS_NA: iStatusWeight = 10; break; + case ID_STATUS_INVISIBLE: iStatusWeight = 5; break; + default: + iStatusWeight = IsStatusConnecting(thisStatus) ? 120 : 0; + break; + } + + if (iStatusWeight > statusOnlineness) { + if (szProto != nullptr) + *szProto = cli.clcProto[i].szProto; + status = thisStatus; + statusOnlineness = iStatusWeight; + } + } + return status; +} diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index e274058e7e..a6aab7290b 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -576,3 +576,5 @@ Clist_SaveStateAndRebuildList @595 Clist_DeleteItemFromTree @596 Clist_RemoveItemFromGroup @597 Clist_ClcOptionsChanged @598 +Clist_GetRealStatus @599 +Clist_GetGeneralizedStatus @600 diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 37564261f0..3c749c9007 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -576,3 +576,5 @@ Clist_SaveStateAndRebuildList @595 Clist_DeleteItemFromTree @596 Clist_RemoveItemFromGroup @597 Clist_ClcOptionsChanged @598 +Clist_GetRealStatus @599 +Clist_GetGeneralizedStatus @600 -- cgit v1.2.3