diff options
author | George Hazan <george.hazan@gmail.com> | 2016-05-28 10:20:32 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2016-05-28 10:20:32 +0000 |
commit | 19e55c9c066703b870c116740821cc6727e72697 (patch) | |
tree | e552beebee52cee8d9ba7abb7169751b0312e378 | |
parent | 3a80b03cb1b3813b47fa878fae9a61632bd25d51 (diff) |
code simplification
git-svn-id: http://svn.miranda-ng.org/main/trunk@16880 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | include/delphi/m_clistint.inc | 10 | ||||
-rw-r--r-- | include/m_clistint.h | 7 | ||||
-rw-r--r-- | plugins/Clist_modern/src/modern_clcitems.cpp | 7 | ||||
-rw-r--r-- | plugins/Clist_nicer/src/clcitems.cpp | 15 | ||||
-rw-r--r-- | plugins/Clist_nicer/src/init.cpp | 16 | ||||
-rw-r--r-- | src/mir_app/src/clc.h | 8 | ||||
-rw-r--r-- | src/mir_app/src/clcitems.cpp | 56 | ||||
-rw-r--r-- | src/mir_app/src/clcmsgs.cpp | 8 |
8 files changed, 62 insertions, 65 deletions
diff --git a/include/delphi/m_clistint.inc b/include/delphi/m_clistint.inc index 09c1566154..a0a9a1a69e 100644 --- a/include/delphi/m_clistint.inc +++ b/include/delphi/m_clistint.inc @@ -335,12 +335,10 @@ type pfnFreeContact : procedure (var contact:TClcContact); cdecl;
pfnFreeGroup : procedure (var group:TClcGroup); cdecl;
- pfnAddInfoItemToGroup : function (var group:TClcGroup; flags:int; pszText:TChar):int; cdecl;
- pfnAddItemToGroup : function (var group:TClcGroup; iAboveItem:int):int; cdecl;
- pfnAddContactToGroup : function (var dat:TClcData; var group:TClcGroup;
- hContact:TMCONTACT):int; cdecl;
- pfnAddContactToTree : procedure (hwnd:HWND; var dat:TClcData; hContact:TMCONTACT;
- updateTotalCount:int; checkHideOffline:int); cdecl;
+ pfnAddInfoItemToGroup : function (var group:TClcGroup; flags:int; pszText:TChar):PClcContact; cdecl;
+ pfnAddItemToGroup : function (var group:TClcGroup; iAboveItem:int):PClcContact; cdecl;
+ pfnAddContactToGroup : function (var dat:TClcData; var group:TClcGroup; hContact:TMCONTACT):PClcContact; cdecl;
+ pfnAddContactToTree : procedure (hwnd:HWND; var dat:TClcData; hContact:TMCONTACT; updateTotalCount:int; checkHideOffline:int); cdecl;
pfnDeleteItemFromTree : procedure (hwnd:HWND; hItem:TMCONTACT); cdecl;
pfnRebuildEntireList : procedure (hwnd:HWND; var dat:TClcData); cdecl;
pfnGetGroupContentsCount : function (var group:TClcGroup; visibleOnly:int):int; cdecl;
diff --git a/include/m_clistint.h b/include/m_clistint.h index 8c312f4d63..d47aa89473 100644 --- a/include/m_clistint.h +++ b/include/m_clistint.h @@ -296,9 +296,10 @@ struct CLIST_INTERFACE void (*pfnFreeContact)(ClcContact *contact);
void (*pfnFreeGroup)(ClcGroup *group);
- int (*pfnAddInfoItemToGroup)(ClcGroup *group, int flags, const WCHAR *pszText);
- int (*pfnAddItemToGroup)(ClcGroup *group, int iAboveItem);
- int (*pfnAddContactToGroup)(struct ClcData *dat, ClcGroup *group, MCONTACT hContact);
+ ClcContact* (*pfnAddInfoItemToGroup)(ClcGroup *group, int flags, const WCHAR *pszText);
+ ClcContact* (*pfnAddItemToGroup)(ClcGroup *group, int iAboveItem);
+ ClcContact* (*pfnAddContactToGroup)(struct ClcData *dat, ClcGroup *group, MCONTACT hContact);
+
void (*pfnAddContactToTree)(HWND hwnd, struct ClcData *dat, MCONTACT hContact, int updateTotalCount, int checkHideOffline);
void (*pfnDeleteItemFromTree)(HWND hwnd, MCONTACT hItem);
void (*pfnRebuildEntireList)(HWND hwnd, struct ClcData *dat);
diff --git a/plugins/Clist_modern/src/modern_clcitems.cpp b/plugins/Clist_modern/src/modern_clcitems.cpp index 578a8b8fd0..08f2aed6fe 100644 --- a/plugins/Clist_modern/src/modern_clcitems.cpp +++ b/plugins/Clist_modern/src/modern_clcitems.cpp @@ -176,10 +176,9 @@ static ClcContact* AddContactToGroup(ClcData *dat, ClcGroup *group, MCONTACT hCo if (group->cl[i]->type != CLCIT_INFO || !(group->cl[i]->flags & CLCIIF_BELOWCONTACTS))
break;
- i = pcli->pfnAddItemToGroup(group, i + 1);
-
- _LoadDataToContact(group->cl[i], group, dat, hContact);
- return group->cl[i];
+ ClcContact *cc = pcli->pfnAddItemToGroup(group, i + 1);
+ _LoadDataToContact(cc, group, dat, hContact);
+ return cc;
}
void cli_AddContactToTree(HWND hwnd, ClcData *dat, MCONTACT hContact, int updateTotalCount, int checkHideOffline)
diff --git a/plugins/Clist_nicer/src/clcitems.cpp b/plugins/Clist_nicer/src/clcitems.cpp index bf91386ba2..82c614643d 100644 --- a/plugins/Clist_nicer/src/clcitems.cpp +++ b/plugins/Clist_nicer/src/clcitems.cpp @@ -53,13 +53,11 @@ ClcContact* CreateClcContact(void) return p;
}
-int AddInfoItemToGroup(ClcGroup *group, int flags, const TCHAR *pszText)
+ClcContact* AddInfoItemToGroup(ClcGroup *group, int flags, const TCHAR *pszText)
{
- int i = coreCli.pfnAddInfoItemToGroup(group, flags, pszText);
-
- ClcContact* p = group->cl[i];
+ ClcContact *p = coreCli.pfnAddInfoItemToGroup(group, flags, pszText);
p->avatarLeft = p->extraIconRightBegin = -1;
- return i;
+ return p;
}
ClcGroup *AddGroup(HWND hwnd, struct ClcData *dat, const TCHAR *szName, DWORD flags, int groupId, int calcTotalMembers)
@@ -97,10 +95,9 @@ void LoadAvatarForContact(ClcContact *p) p->cFlags &= ~ECF_AVATAR;
}
-int AddContactToGroup(struct ClcData *dat, ClcGroup *group, MCONTACT hContact)
+ClcContact* AddContactToGroup(struct ClcData *dat, ClcGroup *group, MCONTACT hContact)
{
- int i = coreCli.pfnAddContactToGroup(dat, group, hContact);
- ClcContact* p = group->cl[i];
+ ClcContact *p = coreCli.pfnAddContactToGroup(dat, group, hContact);
p->wStatus = db_get_w(hContact, p->proto, "Status", ID_STATUS_OFFLINE);
p->xStatus = db_get_b(hContact, p->proto, "XStatusId", 0);
@@ -140,7 +137,7 @@ int AddContactToGroup(struct ClcData *dat, ClcGroup *group, MCONTACT hContact) p->avatarLeft = p->extraIconRightBegin = -1;
p->flags |= db_get_b(p->hContact, "CList", "Priority", 0) ? CONTACTF_PRIORITY : 0;
- return i;
+ return p;
}
void RebuildEntireList(HWND hwnd, struct ClcData *dat)
diff --git a/plugins/Clist_nicer/src/init.cpp b/plugins/Clist_nicer/src/init.cpp index 6fa5357254..eb83a1df9d 100644 --- a/plugins/Clist_nicer/src/init.cpp +++ b/plugins/Clist_nicer/src/init.cpp @@ -50,14 +50,14 @@ int ShowHide(WPARAM wParam, LPARAM lParam); int ClcShutdown(WPARAM wParam, LPARAM lParam);
CListEvent* AddEvent(CLISTEVENT *cle);
-ClcGroup* AddGroup(HWND hwnd, struct ClcData *dat, const TCHAR *szName, DWORD flags, int groupId, int calcTotalMembers);
-
-int AddContactToGroup(struct ClcData *dat, ClcGroup *group, MCONTACT hContact);
-int AddInfoItemToGroup(ClcGroup *group, int flags, const TCHAR *pszText);
-LRESULT ProcessExternalMessages(HWND hwnd, struct ClcData *dat, UINT msg, WPARAM wParam, LPARAM lParam);
-int RemoveEvent(MCONTACT hContact, MEVENT hDbEvent);
-INT_PTR TrayIconProcessMessage(WPARAM wParam, LPARAM lParam);
-void RecalcScrollBar(HWND hwnd, struct ClcData *dat);
+ClcGroup* AddGroup(HWND hwnd, struct ClcData *dat, const TCHAR *szName, DWORD flags, int groupId, int calcTotalMembers);
+
+ClcContact* AddContactToGroup(struct ClcData *dat, ClcGroup *group, MCONTACT hContact);
+ClcContact* AddInfoItemToGroup(ClcGroup *group, int flags, const TCHAR *pszText);
+LRESULT ProcessExternalMessages(HWND hwnd, struct ClcData *dat, UINT msg, WPARAM wParam, LPARAM lParam);
+int RemoveEvent(MCONTACT hContact, MEVENT hDbEvent);
+INT_PTR TrayIconProcessMessage(WPARAM wParam, LPARAM lParam);
+void RecalcScrollBar(HWND hwnd, struct ClcData *dat);
LRESULT CALLBACK ContactListWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK ContactListControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
diff --git a/src/mir_app/src/clc.h b/src/mir_app/src/clc.h index 52e78bee00..ba2c718153 100644 --- a/src/mir_app/src/clc.h +++ b/src/mir_app/src/clc.h @@ -56,12 +56,14 @@ HANDLE fnContactToItemHandle(ClcContact *contact, DWORD *nmFlags); ClcGroup* fnAddGroup(HWND hwnd, struct ClcData *dat, const TCHAR *szName, DWORD flags, int groupId, int calcTotalMembers);
ClcGroup* fnRemoveItemFromGroup(HWND hwnd, ClcGroup *group, ClcContact *contact, int updateTotalCount);
+ClcContact* fnAddInfoItemToGroup(ClcGroup *group, int flags, const TCHAR *pszText);
+ClcContact* fnAddItemToGroup(ClcGroup *group, int iAboveItem);
+ClcContact* fnAddContactToGroup(struct ClcData *dat, ClcGroup *group, MCONTACT hContact);
+
void fnFreeContact(ClcContact *p);
void fnFreeGroup(ClcGroup *group);
-int fnAddInfoItemToGroup(ClcGroup *group, int flags, const TCHAR *pszText);
-int fnAddItemToGroup(ClcGroup *group, int iAboveItem);
+
void fnAddContactToTree(HWND hwnd, struct ClcData *dat, MCONTACT hContact, int updateTotalCount, int checkHideOffline);
-int fnAddContactToGroup(struct ClcData *dat, ClcGroup *group, MCONTACT hContact);
void fnDeleteItemFromTree(HWND hwnd, MCONTACT hItem);
void fnRebuildEntireList(HWND hwnd, struct ClcData *dat);
int fnGetGroupContentsCount(ClcGroup *group, int visibleOnly);
diff --git a/src/mir_app/src/clcitems.cpp b/src/mir_app/src/clcitems.cpp index be581876eb..772eecfb54 100644 --- a/src/mir_app/src/clcitems.cpp +++ b/src/mir_app/src/clcitems.cpp @@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // routines for managing adding/removal of items in the list, including sorting -int fnAddItemToGroup(ClcGroup *group, int iAboveItem) +ClcContact* fnAddItemToGroup(ClcGroup *group, int iAboveItem) { ClcContact* newItem = cli.pfnCreateClcContact(); newItem->type = CLCIT_DIVIDER; @@ -35,7 +35,7 @@ int fnAddItemToGroup(ClcGroup *group, int iAboveItem) newItem->szText[0] = '\0'; memset(newItem->iExtraImage, 0xFF, sizeof(newItem->iExtraImage)); group->cl.insert(newItem, iAboveItem); - return iAboveItem; + return newItem; } ClcGroup* fnAddGroup(HWND hwnd, ClcData *dat, const TCHAR *szName, DWORD flags, int groupId, int calcTotalMembers) @@ -85,7 +85,7 @@ ClcGroup* fnAddGroup(HWND hwnd, ClcData *dat, const TCHAR *szName, DWORD flags, if (groupId == 0) return NULL; - ClcContact *cc = group->cl[cli.pfnAddItemToGroup(group, i)]; + ClcContact *cc = cli.pfnAddItemToGroup(group, i); cc->type = CLCIT_GROUP; mir_tstrncpy(cc->szText, pThisField, _countof(cc->szText)); cc->groupId = (WORD)(pNextField ? 0 : groupId); @@ -137,7 +137,7 @@ void fnFreeGroup(ClcGroup *group) } static int iInfoItemUniqueHandle = 0; -int fnAddInfoItemToGroup(ClcGroup *group, int flags, const TCHAR *pszText) +ClcContact* fnAddInfoItemToGroup(ClcGroup *group, int flags, const TCHAR *pszText) { int i = 0; @@ -152,28 +152,30 @@ int fnAddInfoItemToGroup(ClcGroup *group, int flags, const TCHAR *pszText) for (; i < group->cl.getCount(); i++) if (group->cl[i]->type != CLCIT_INFO) break; - i = cli.pfnAddItemToGroup(group, i); + + ClcContact *cc = cli.pfnAddItemToGroup(group, i); iInfoItemUniqueHandle = LOWORD(iInfoItemUniqueHandle + 1); if (iInfoItemUniqueHandle == 0) ++iInfoItemUniqueHandle; - group->cl[i]->type = CLCIT_INFO; - group->cl[i]->flags = (BYTE)flags; - group->cl[i]->hContact = (MCONTACT)++iInfoItemUniqueHandle; - mir_tstrncpy(group->cl[i]->szText, pszText, _countof(group->cl[i]->szText)); - return i; + cc->type = CLCIT_INFO; + cc->flags = (BYTE)flags; + cc->hContact = (MCONTACT)++iInfoItemUniqueHandle; + mir_tstrncpy(cc->szText, pszText, _countof(cc->szText)); + return cc; } -int fnAddContactToGroup(ClcData *dat, ClcGroup *group, MCONTACT hContact) +ClcContact* fnAddContactToGroup(ClcData *dat, ClcGroup *group, MCONTACT hContact) { int i, index = -1; dat->bNeedsResort = true; for (i = group->cl.getCount() - 1; i >= 0; i--) { - if (group->cl[i]->hContact == hContact) - return i; + ClcContact *cc = group->cl[i]; + if (cc->hContact == hContact) + return cc; if (index == -1) - if (group->cl[i]->type != CLCIT_INFO || !(group->cl[i]->flags & CLCIIF_BELOWCONTACTS)) + if (cc->type != CLCIT_INFO || !(cc->flags & CLCIIF_BELOWCONTACTS)) index = i; } @@ -182,9 +184,7 @@ int fnAddContactToGroup(ClcData *dat, ClcGroup *group, MCONTACT hContact) ClcCacheEntry *pce = cli.pfnGetCacheEntry(hContact); replaceStrT(pce->tszGroup, NULL); - i = cli.pfnAddItemToGroup(group, index + 1); - - ClcContact *cc = group->cl[i]; + ClcContact *cc = cli.pfnAddItemToGroup(group, index + 1); cc->type = CLCIT_CONTACT; cc->iImage = cli.pfnGetContactIcon(hContact); cc->hContact = hContact; @@ -205,7 +205,7 @@ int fnAddContactToGroup(ClcData *dat, ClcGroup *group, MCONTACT hContact) if (idleMode) cc->flags |= CONTACTF_IDLE; mir_tstrncpy(cc->szText, cli.pfnGetContactDisplayName(hContact, 0), _countof(cc->szText)); - return i; + return cc; } void fnAddContactToTree(HWND hwnd, ClcData *dat, MCONTACT hContact, int updateTotalCount, int checkHideOffline) @@ -530,9 +530,9 @@ static void SortGroup(ClcData *dat, ClcGroup *group, int useInsertionSort) prevContactOnline = 1; else { if (prevContactOnline) { - i = cli.pfnAddItemToGroup(group, i); - group->cl[i]->type = CLCIT_DIVIDER; - mir_tstrcpy(group->cl[i]->szText, TranslateT("Offline")); + ClcContact *cc = cli.pfnAddItemToGroup(group, i); + cc->type = CLCIT_DIVIDER; + mir_tstrcpy(cc->szText, TranslateT("Offline")); } break; } @@ -603,10 +603,6 @@ struct SavedInfoState_t void fnSaveStateAndRebuildList(HWND hwnd, ClcData *dat) { - int i, j; - ClcGroup *group; - ClcContact *contact; - cli.pfnHideInfoTip(hwnd, dat); KillTimer(hwnd, TIMERID_INFOTIP); KillTimer(hwnd, TIMERID_RENAME); @@ -619,7 +615,7 @@ void fnSaveStateAndRebuildList(HWND hwnd, ClcData *dat) OBJLIST<SavedInfoState_t> saveInfo(10, NumericKeySortT); dat->bNeedsResort = true; - group = &dat->list; + ClcGroup *group = &dat->list; group->scanIndex = 0; for (;;) { if (group->scanIndex == group->cl.getCount()) { @@ -693,16 +689,18 @@ void fnSaveStateAndRebuildList(HWND hwnd, ClcData *dat) group->scanIndex++; } - for (i = 0; i < saveInfo.getCount(); i++) { + for (int i = 0; i < saveInfo.getCount(); i++) { if (saveInfo[i].parentId == -1) group = &dat->list; else { + ClcContact *contact; if (!cli.pfnFindItem(hwnd, dat, saveInfo[i].parentId | HCONTACT_ISGROUP, &contact, NULL, NULL)) continue; group = contact->group; } - j = cli.pfnAddInfoItemToGroup(group, saveInfo[i].contact.flags, _T("")); - *group->cl[j] = saveInfo[i].contact; + + ClcContact *cc = cli.pfnAddInfoItemToGroup(group, saveInfo[i].contact.flags, _T("")); + *cc = saveInfo[i].contact; } dat->bLockScrollbar = false; diff --git a/src/mir_app/src/clcmsgs.cpp b/src/mir_app/src/clcmsgs.cpp index 5c260bc000..b433ab3e7c 100644 --- a/src/mir_app/src/clcmsgs.cpp +++ b/src/mir_app/src/clcmsgs.cpp @@ -64,14 +64,16 @@ LRESULT fnProcessExternalMessages(HWND hwnd, ClcData *dat, UINT msg, WPARAM wPar return NULL;
group = contact->group;
}
+
+ ClcContact *cc;
if (msg == CLM_ADDINFOITEMA) {
WCHAR* wszText = mir_a2u((char*)cii->pszText);
- i = cli.pfnAddInfoItemToGroup(group, cii->flags, wszText);
+ cc = cli.pfnAddInfoItemToGroup(group, cii->flags, wszText);
mir_free(wszText);
}
- else i = cli.pfnAddInfoItemToGroup(group, cii->flags, cii->pszText);
+ else cc = cli.pfnAddInfoItemToGroup(group, cii->flags, cii->pszText);
cli.pfnRecalcScrollBar(hwnd, dat);
- return (LRESULT)group->cl[i]->hContact | HCONTACT_ISINFO;
+ return (LRESULT)cc->hContact | HCONTACT_ISINFO;
}
case CLM_AUTOREBUILD:
|