From 35eaa182969aae253ccc7120af1bb966e38576d3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 15 Apr 2016 19:09:41 +0000 Subject: clists code cleaning & optimization git-svn-id: http://svn.miranda-ng.org/main/trunk@16668 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Clist_modern/src/modern_cachefuncs.cpp | 3 +- plugins/Clist_modern/src/modern_clc.cpp | 4 +- plugins/Clist_modern/src/modern_clcutils.cpp | 13 +-- plugins/Clist_modern/src/modern_contact.cpp | 116 ++++++++++----------- .../Clist_modern/src/modern_rowheight_funcs.cpp | 7 +- plugins/Clist_nicer/src/clcutils.cpp | 10 +- plugins/Clist_nicer/src/rowheight_funcs.cpp | 4 +- 7 files changed, 73 insertions(+), 84 deletions(-) (limited to 'plugins') diff --git a/plugins/Clist_modern/src/modern_cachefuncs.cpp b/plugins/Clist_modern/src/modern_cachefuncs.cpp index ebf7b25640..9aaeabbe22 100644 --- a/plugins/Clist_modern/src/modern_cachefuncs.cpp +++ b/plugins/Clist_modern/src/modern_cachefuncs.cpp @@ -707,8 +707,9 @@ void Cache_ProceedAvatarInList(ClcData *dat, ClcContact *contact) } // Create objs - void * pt; HDC hdc = CreateCompatibleDC(dat->avatar_cache.hdc); + + void *pt; HBITMAP hDrawBmp = ske_CreateDIB32Point(width_clip, height_clip, &pt); HBITMAP oldBmp = (HBITMAP)SelectObject(hdc, hDrawBmp); diff --git a/plugins/Clist_modern/src/modern_clc.cpp b/plugins/Clist_modern/src/modern_clc.cpp index 99703afe5f..fb79cbd2b0 100644 --- a/plugins/Clist_modern/src/modern_clc.cpp +++ b/plugins/Clist_modern/src/modern_clc.cpp @@ -1500,7 +1500,7 @@ static LRESULT clcOnIntmNameChanged(ClcData *dat, HWND hwnd, UINT msg, WPARAM wP if (contact) { mir_tstrncpy(contact->szText, pcli->pfnGetContactDisplayName(wParam, 0), _countof(contact->szText)); Cache_GetText(dat, contact, 1); - cliRecalcScrollBar(hwnd, dat); + // cliRecalcScrollBar(hwnd, dat); } dat->needsResort = 1; @@ -1523,7 +1523,7 @@ static LRESULT clcOnIntmStatusMsgChanged(ClcData *dat, HWND hwnd, UINT msg, WPAR if (contact) { Cache_GetText(dat, contact, 1); - cliRecalcScrollBar(hwnd, dat); + // cliRecalcScrollBar(hwnd, dat); PostMessage(hwnd, INTM_INVALIDATE, 0, 0); } return corecli.pfnContactListControlWndProc(hwnd, msg, hContact, lParam); diff --git a/plugins/Clist_modern/src/modern_clcutils.cpp b/plugins/Clist_modern/src/modern_clcutils.cpp index 5a48d2c855..8d29148d99 100644 --- a/plugins/Clist_modern/src/modern_clcutils.cpp +++ b/plugins/Clist_modern/src/modern_clcutils.cpp @@ -296,22 +296,13 @@ void cliBeginRenameSelection(HWND hwnd, ClcData *dat) { - RECT rectW; - int h2; GetWindowRect(hwnd, &rectW); - // w = contact->pos_full_first_row.right-contact->pos_full_first_row.left; - // h = contact->pos_full_first_row.bottom-contact->pos_full_first_row.top; - //w = clRect.right-x; - //w = clRect.right-x; - //x += rectW.left;//+contact->pos_full_first_row.left; - //y += rectW.top;//+contact->pos_full_first_row.top; + x = contact->pos_rename_rect.left + rectW.left; y = contact->pos_label.top + rectW.top; w = contact->pos_rename_rect.right - contact->pos_rename_rect.left; - h2 = contact->pos_label.bottom - contact->pos_label.top + 4; - h = h2;//max(h,h2); - + h = contact->pos_label.bottom - contact->pos_label.top + 4; } { diff --git a/plugins/Clist_modern/src/modern_contact.cpp b/plugins/Clist_modern/src/modern_contact.cpp index 988b7d1e31..891168dffb 100644 --- a/plugins/Clist_modern/src/modern_contact.cpp +++ b/plugins/Clist_modern/src/modern_contact.cpp @@ -45,6 +45,8 @@ static statusModeOrder[] = { ID_STATUS_OUTTOLUNCH, 425 } }; +static int LocaleId = -1; + static int GetContactStatus(MCONTACT hContact) { return (GetContactCachedStatus(hContact)); @@ -94,68 +96,62 @@ int GetProtoIndex(char * szName) return -1; } -int CompareContacts2(const ClcContact *contact1, const ClcContact *contact2, int by) -{ - TCHAR *namea, *nameb; - int statusa, statusb; - char *szProto1, *szProto2; - - if ((INT_PTR)contact1 < 100 || (INT_PTR)contact2 < 100) return 0; - - MCONTACT a = contact1->hContact; - MCONTACT b = contact2->hContact; - - namea = (TCHAR *)contact1->szText; - statusa = GetContactCachedStatus(contact1->hContact); - szProto1 = contact1->proto; - - nameb = (TCHAR *)contact2->szText; - statusb = GetContactCachedStatus(contact2->hContact); - szProto2 = contact2->proto; - - if (by == SORTBY_STATUS) { //status - int ordera, orderb; - ordera = GetStatusModeOrdering(statusa); - orderb = GetStatusModeOrdering(statusb); - return (ordera != orderb) ? ordera - orderb : 0; - } - - //one is offline: offline goes below online - if (g_CluiData.fSortNoOfflineBottom == 0 && (statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE)) - return 2 * (statusa == ID_STATUS_OFFLINE) - 1; - - if (by == SORTBY_NAME) //name - return mir_tstrcmpi(namea, nameb); - - if (by == SORTBY_NAME_LOCALE) { - //name - static int LocaleId = -1; - if (LocaleId == -1) LocaleId = Langpack_GetDefaultLocale(); - return (CompareString(LocaleId, NORM_IGNORECASE, SAFETSTRING(namea), -1, SAFETSTRING(nameb), -1)) - 2; - } - if (by == SORTBY_LASTMSG) { - //last message - DWORD ta = CompareContacts2_getLMTime(a); - DWORD tb = CompareContacts2_getLMTime(b); - return tb - ta; - } - if (by == SORTBY_PROTO) { - int rc = GetProtoIndex(szProto1) - GetProtoIndex(szProto2); - if (rc != 0 && (szProto1 != NULL && szProto2 != NULL)) - return rc; - } - else if (by == SORTBY_RATE) - return contact2->bContactRate - contact1->bContactRate; - // else :o) - return 0; -} - int cliCompareContacts(const ClcContact *contact1, const ClcContact *contact2) { - int i, r; - for (i = 0; i < _countof(g_CluiData.bSortByOrder); i++) - { - r = CompareContacts2(contact1, contact2, g_CluiData.bSortByOrder[i]); + if ((INT_PTR)contact1 < 100 || (INT_PTR)contact2 < 100) + return 0; + + ClcCacheEntry *c1 = cliGetCacheEntry(contact1->hContact); + ClcCacheEntry *c2 = cliGetCacheEntry(contact2->hContact); + + for (int i = 0; i < _countof(g_CluiData.bSortByOrder); i++) { + int by = g_CluiData.bSortByOrder[i]; + if (by == SORTBY_STATUS) { //status + int ordera = GetStatusModeOrdering(c1->getStatus()); + int orderb = GetStatusModeOrdering(c2->getStatus()); + if (ordera == orderb) + continue; + return ordera - orderb; + } + + // one is offline: offline goes below online + if (g_CluiData.fSortNoOfflineBottom == 0) { + int statusa = c1->getStatus(); + int statusb = c1->getStatus(); + if ((statusa == ID_STATUS_OFFLINE) != (statusb == ID_STATUS_OFFLINE)) + return 2 * (statusa == ID_STATUS_OFFLINE) - 1; + } + + int r; + switch (by) { + case SORTBY_NAME: // name + r = mir_tstrcmpi(contact1->szText, contact2->szText); + break; + + case SORTBY_NAME_LOCALE: // name + if (LocaleId == -1) + LocaleId = Langpack_GetDefaultLocale(); + r = CompareString(LocaleId, NORM_IGNORECASE, SAFETSTRING(contact1->szText), -1, SAFETSTRING(contact2->szText), -1) - 2; + break; + + case SORTBY_LASTMSG: // last message + r = (int)CompareContacts2_getLMTime(contact1->hContact) - (int)CompareContacts2_getLMTime(contact1->hContact); + break; + + case SORTBY_PROTO: + if (contact1->proto == NULL || contact1->proto == NULL) + continue; + r = GetProtoIndex(contact1->proto) - GetProtoIndex(contact2->proto); + break; + + case SORTBY_RATE: + r = contact2->bContactRate - contact1->bContactRate; // reverse order + break; + + default: // should never happen + continue; + } + if (r != 0) return r; } diff --git a/plugins/Clist_modern/src/modern_rowheight_funcs.cpp b/plugins/Clist_modern/src/modern_rowheight_funcs.cpp index c8a181b3d5..3a2de1caf3 100644 --- a/plugins/Clist_modern/src/modern_rowheight_funcs.cpp +++ b/plugins/Clist_modern/src/modern_rowheight_funcs.cpp @@ -110,7 +110,8 @@ int mod_CalcRowHeight_worker(ClcData *dat, HWND hwnd, ClcContact *contact, int i contact->group->parent->groupId == 0 && contact->group->parent->cl.items[0] != contact) tmp += dat->row_before_group_space; - if (item != -1) dat->row_heights[item] = tmp; + if (item != -1) + dat->row_heights[item] = tmp; return tmp; } @@ -314,7 +315,8 @@ int mod_CalcRowHeight_worker(ClcData *dat, HWND hwnd, ClcContact *contact, int i height = cppCalculateRowHeight(gl_RowRoot); height += dat->row_border * 2; height = max(height, dat->row_min_heigh); - if (item != -1) dat->row_heights[item] = height; + if (item != -1) + dat->row_heights[item] = height; return height; } @@ -324,7 +326,6 @@ BOOL RowHeights_Initialize(struct ClcData *dat) dat->row_heights_size = 0; dat->row_heights_allocated = 0; dat->row_heights = NULL; - return TRUE; } diff --git a/plugins/Clist_nicer/src/clcutils.cpp b/plugins/Clist_nicer/src/clcutils.cpp index 38bd82ebe9..303556b998 100644 --- a/plugins/Clist_nicer/src/clcutils.cpp +++ b/plugins/Clist_nicer/src/clcutils.cpp @@ -397,13 +397,12 @@ void ScrollTo(HWND hwnd, struct ClcData *dat, int desty, int noSmooth) void RecalcScrollBar(HWND hwnd, struct ClcData *dat) { - SCROLLINFO si = { 0 }; - RECT clRect; - NMCLISTCONTROL nm; - RowHeight::calcRowHeights(dat, hwnd); + RECT clRect; GetClientRect(hwnd, &clRect); + + SCROLLINFO si = { 0 }; si.cbSize = sizeof(si); si.fMask = SIF_ALL; si.nMin = 0; @@ -426,12 +425,13 @@ void RecalcScrollBar(HWND hwnd, struct ClcData *dat) SetScrollInfo(hwnd, SB_VERT, &si, TRUE); } ScrollTo(hwnd, dat, dat->yScroll, 1); + + NMCLISTCONTROL nm; nm.hdr.code = CLN_LISTSIZECHANGE; nm.hdr.hwndFrom = hwnd; nm.hdr.idFrom = GetDlgCtrlID(hwnd); nm.pt.y = si.nMax; SendMessage(GetParent(hwnd), WM_NOTIFY, 0, (LPARAM)& nm); - //saveRecalcScrollBar(hwnd, dat); } void SetGroupExpand(HWND hwnd, struct ClcData *dat, ClcGroup *group, int newState) diff --git a/plugins/Clist_nicer/src/rowheight_funcs.cpp b/plugins/Clist_nicer/src/rowheight_funcs.cpp index db18cbb6f7..79090e0b5c 100644 --- a/plugins/Clist_nicer/src/rowheight_funcs.cpp +++ b/plugins/Clist_nicer/src/rowheight_funcs.cpp @@ -126,7 +126,7 @@ int RowHeight::getMaxRowHeight(ClcData *dat, const HWND hwnd) return max_height; } -// Calc and store row height for all itens in the list +// Calc and store row height for all items in the list void RowHeight::calcRowHeights(ClcData *dat, HWND hwnd) { int indent, subindex, line_num; @@ -159,7 +159,7 @@ void RowHeight::calcRowHeights(ClcData *dat, HWND hwnd) // Calc row height getRowHeight(dat, Drawing, line_num, dwStyle); - if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP && /*!IsBadCodePtr((FARPROC)group->cl.items[group->scanIndex]->group) && */ (group->cl.items[group->scanIndex]->group->expanded & 0x0000ffff)) { + if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP && (group->cl.items[group->scanIndex]->group->expanded & 0x0000ffff)) { group = group->cl.items[group->scanIndex]->group; indent++; group->scanIndex = 0; -- cgit v1.2.3