void DeleteItemFromTree(HWND hwnd,HANDLE hItem) { struct ClcContact *contact; struct ClcGroup *group; struct ClcData *dat=(struct ClcData*)GetWindowLong(hwnd,0); ClearRowByIndexCache(); if(!FindItem(hwnd,dat,hItem,&contact,&group,NULL,TRUE)) { DBVARIANT dbv; int i,nameOffset; if(!IsHContactContact(hItem)) return; ClearClcContactCache(dat,hItem); if(DBGetContactSettingTString(hItem,"CList","Group",&dbv)) {DBFreeVariant(&dbv); return;} //decrease member counts of all parent groups too group=&dat->list; nameOffset=0; for(i=0;;i++) { if(group->scanIndex==group->contactCount) break; if(group->contact[i].type==CLCIT_GROUP) { int len=lstrlen(group->contact[i].szText); //TODO unicode to dbv.pszVal if(!_tcsncmp(group->contact[i].szText,(TCHAR*)dbv.pszVal+nameOffset,len) && ((TCHAR)dbv.pszVal[nameOffset+len]==TEXT('\\') || (TCHAR)dbv.pszVal[nameOffset+len]==TEXT('\0'))) { group->totalMembers--; if((TCHAR)dbv.pszVal[nameOffset+len]==TEXT('\0')) break; } } } mir_free(dbv.pszVal); DBFreeVariant(&dbv); } else RemoveItemFromGroup(hwnd,group,contact,1); dat->NeedResort=1; ClearRowByIndexCache(); }
ClcGroup *RemoveItemFromGroup(HWND hwnd,ClcGroup *group,struct ClcContact *contact,int updateTotalCount) { ClearRowByIndexCache(); if (contact->type == CLCIT_CONTACT) { struct ClcData* dat = (struct ClcData*)GetWindowLongPtr(hwnd,0); ClearClcContactCache(dat,contact->hContact); } group = saveRemoveItemFromGroup(hwnd, group, contact, updateTotalCount); ClearRowByIndexCache(); return group; }
void DeleteItemFromTree(HWND hwnd,HANDLE hItem) { struct ClcContact *contact; ClcGroup *group; struct ClcData *dat = (struct ClcData*)GetWindowLongPtr(hwnd,0); ClearRowByIndexCache(); dat->needsResort = 1; if ( !FindItem(hwnd,dat,hItem,&contact,&group,NULL)) { DBVARIANT dbv; int i,nameOffset; if ( !IsHContactContact(hItem)) return; ClearClcContactCache(dat,hItem); if (db_get_ts(hItem,"CList","Group",&dbv)) return; //decrease member counts of all parent groups too group = &dat->list; nameOffset = 0; for (i = 0;;i++) { if (group->scanIndex == group->cl.count) break; if (group->cl.items[i]->type == CLCIT_GROUP) { int len = lstrlen(group->cl.items[i]->szText); if ( !_tcsncmp(group->cl.items[i]->szText,dbv.ptszVal+nameOffset,len) && (dbv.ptszVal[nameOffset+len] == '\\' || dbv.pszVal[nameOffset+len] == '\0')) { group->totalMembers--; if (dbv.pszVal[nameOffset+len] == '\0') break; } } } mir_free(dbv.pszVal); } else RemoveItemFromGroup(hwnd,group,contact,1); ClearRowByIndexCache(); }
struct ClcGroup *RemoveItemFromGroup(HWND hwnd,struct ClcGroup *group,struct ClcContact *contact,int updateTotalCount) { int iContact; struct ClcData* dat=(struct ClcData*)GetWindowLong(hwnd,0); ClearRowByIndexCache(); if(contact->type==CLCIT_CONTACT) ClearClcContactCache(dat,contact->hContact); iContact=((unsigned)contact-(unsigned)group->contact)/sizeof(struct ClcContact); if(iContact>=group->contactCount) return group; if(contact->type==CLCIT_GROUP) { FreeGroup(contact->group); mir_free(contact->group); } group->contactCount--; if(updateTotalCount && contact->type==CLCIT_CONTACT) group->totalMembers--; // free on contact deletion) if (contact->szText) mir_free(contact->szText); if (contact->szSecondLineText) mir_free(contact->szSecondLineText); if (contact->szThirdLineText) mir_free(contact->szThirdLineText); memmove(group->contact+iContact,group->contact+iContact+1,sizeof(struct ClcContact)*(group->contactCount-iContact)); if((GetWindowLong(hwnd,GWL_STYLE)&CLS_HIDEEMPTYGROUPS) && group->contactCount==0) { int i; if(group->parent==NULL) return group; for(i=0;i<group->parent->contactCount;i++) if(group->parent->contact[i].type==CLCIT_GROUP && group->parent->contact[i].groupId==group->groupId) break; if(i==group->parent->contactCount) return group; //never happens return RemoveItemFromGroup(hwnd,group->parent,&group->parent->contact[i],0); } ClearRowByIndexCache(); return group; }
void SortCLC(HWND hwnd,struct ClcData *dat,int useInsertionSort) { struct ClcContact *selcontact; struct ClcGroup *group=&dat->list,*selgroup; int dividers=dat->exStyle&CLS_EX_DIVIDERONOFF; HANDLE hSelItem; int tick=GetTickCount(); if (dat->NeedResort==1 &&1) { if(GetRowByIndex(dat,dat->selection,&selcontact,NULL)==-1) hSelItem=NULL; else hSelItem=ContactToHItem(selcontact); group->scanIndex=0; SortGroup(dat,group,useInsertionSort); for(;;) { if(group->scanIndex==group->contactCount) { group=group->parent; if(group==NULL) break; } else if(group->contact[group->scanIndex].type==CLCIT_GROUP) { group=group->contact[group->scanIndex].group; group->scanIndex=0; SortGroup(dat,group,useInsertionSort); continue; } group->scanIndex++; } ClearClcContactCache(dat,INVALID_HANDLE_VALUE); if(hSelItem) if(FindItem(hwnd,dat,hSelItem,&selcontact,&selgroup,NULL,FALSE)) dat->selection=GetRowsPriorTo(&dat->list,selgroup,selcontact-selgroup->contact); RecalcScrollBar(hwnd,dat); ClearRowByIndexCache(); }else { //TRACE("Not need to sort\r\n"); }; InvalidateRectZ(hwnd,NULL,FALSE); dat->NeedResort=0; // LOCK_IMAGE_UPDATING=1; // RecalcScrollBar(hwnd,dat); #ifdef _DEBUG tick=GetTickCount()-tick; { char buf[255]; //sprintf(buf,"%s %s took %i ms",__FILE__,__LINE__,tick); if (tick>5) { sprintf(buf,"SortCLC %d \r\n",tick); TRACE(buf); DBWriteContactSettingDword((HANDLE)0,"CLUI","PF:Last SortCLC Time:",tick); } } #endif }
void RebuildEntireList(HWND hwnd,struct ClcData *dat) { // char *szProto; DWORD style=GetWindowLong(hwnd,GWL_STYLE); HANDLE hContact; struct ClcContact * cont; struct ClcGroup *group; //DBVARIANT dbv; int tick=GetTickCount(); KillTimer(hwnd,TIMERID_REBUILDAFTER); //EnterCriticalSection(&(dat->lockitemCS)); //ShowTracePopup("RebuildEntireList"); #ifdef _DEBUG { static int num_calls = 0; char tmp[128]; mir_snprintf(tmp, sizeof(tmp), "********************* RebuildEntireList (%d)\r\n", num_calls); num_calls++; TRACE(tmp); } #endif ClearRowByIndexCache(); ClearClcContactCache(dat,INVALID_HANDLE_VALUE); ImageArray_Clear(&dat->avatar_cache); RowHeights_Clear(dat); RowHeights_GetMaxRowHeight(dat, hwnd); dat->list.expanded=1; dat->list.hideOffline=DBGetContactSettingByte(NULL,"CLC","HideOfflineRoot",0); dat->list.contactCount=0; dat->list.totalMembers=0; dat->NeedResort=1; dat->selection=-1; dat->HiLightMode=DBGetContactSettingByte(NULL,"CLC","HiLightMode",0); { int i; TCHAR *szGroupName; DWORD groupFlags; for(i=1;;i++) { szGroupName=(TCHAR*)CallService(MS_CLIST_GROUPGETNAMET,i,(LPARAM)&groupFlags); //UNICODE if(szGroupName==NULL) break; AddGroup(hwnd,dat,szGroupName,groupFlags,i,0); } lastGroupId=i; } hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDFIRST,0,0); while(hContact) { pdisplayNameCacheEntry cacheEntry; cont=NULL; cacheEntry=GetContactFullCacheEntry(hContact); //cacheEntry->ClcContact=NULL; ClearClcContactCache(dat,hContact); if((dat->IsMetaContactsEnabled||MyStrCmp(cacheEntry->szProto,"MetaContacts"))&&(style&CLS_SHOWHIDDEN || !cacheEntry->Hidden) && (!cacheEntry->HiddenSubcontact || !dat->IsMetaContactsEnabled )) { if(lstrlen(cacheEntry->szGroup)==0) group=&dat->list; else { group=AddGroup(hwnd,dat,cacheEntry->szGroup,(DWORD)-1,0,0); // if (!group) group=AddTempGroup(hwnd,dat,cacheEntry->szGroup,(DWORD)-1,0,0); //mir_free(dbv.pszVal); } if(group!=NULL) { if (cacheEntry->status==ID_STATUS_OFFLINE) if (DBGetContactSettingByte(NULL,"CList","PlaceOfflineToRoot",0)) group=&dat->list; group->totalMembers++; if(!(style&CLS_NOHIDEOFFLINE) && (style&CLS_HIDEOFFLINE || group->hideOffline)) { //szProto=(char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(WPARAM)hContact,0); if(cacheEntry->szProto==NULL) { if(!IsHiddenMode(dat,ID_STATUS_OFFLINE)||cacheEntry->noHiddenOffline) cont=AddContactToGroup(dat,group,cacheEntry); } else if(!IsHiddenMode(dat,cacheEntry->status)||cacheEntry->noHiddenOffline) cont=AddContactToGroup(dat,group,cacheEntry); } else cont=AddContactToGroup(dat,group,cacheEntry); } } if (cont) { cont->SubAllocated=0; if (cont->proto && strcmp(cont->proto,"MetaContacts")==0) AddSubcontacts(dat,cont); } hContact=(HANDLE)CallService(MS_DB_CONTACT_FINDNEXT,(WPARAM)hContact,0); } if(style&CLS_HIDEEMPTYGROUPS) { group=&dat->list; group->scanIndex=0; for(;;) { if(group->scanIndex==group->contactCount) { group=group->parent; if(group==NULL) break; } else if(group->contact[group->scanIndex].type==CLCIT_GROUP) { if(group->contact[group->scanIndex].group->contactCount==0) { group=RemoveItemFromGroup(hwnd,group,&group->contact[group->scanIndex],0); } else { group=group->contact[group->scanIndex].group; group->scanIndex=0; } continue; } group->scanIndex++; } } SortCLC(hwnd,dat,0); // LOCK_IMAGE_UPDATING=0; //LeaveCriticalSection(&(dat->lockitemCS)); #ifdef _DEBUG tick=GetTickCount()-tick; { char buf[255]; //sprintf(buf,"%s %s took %i ms",__FILE__,__LINE__,tick); sprintf(buf,"RebuildEntireList %d \r\n",tick); TRACE(buf); DBWriteContactSettingDword((HANDLE)0,"CLUI","PF:Last RebuildEntireList Time:",tick); } #endif }
void AddContactToTree(HWND hwnd,struct ClcData *dat,HANDLE hContact,int updateTotalCount,int checkHideOffline) { struct ClcGroup *group; struct ClcContact * cont; pdisplayNameCacheEntry cacheEntry; DWORD style=GetWindowLong(hwnd,GWL_STYLE); WORD status; char *szProto; if (FindItem(hwnd,dat,hContact,NULL,NULL,NULL,FALSE)==1){return;}; cacheEntry=GetContactFullCacheEntry(hContact); if (cacheEntry==NULL) return; if (dat->IsMetaContactsEnabled && cacheEntry->HiddenSubcontact) return; ///----- szProto=cacheEntry->szProto; //char *szProto=(char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(WPARAM)hContact,0); dat->NeedResort=1; ClearRowByIndexCache(); ClearClcContactCache(dat,hContact); if(style&CLS_NOHIDEOFFLINE) checkHideOffline=0; if(checkHideOffline) { if(szProto==NULL) status=ID_STATUS_OFFLINE; else status=cacheEntry->status; } if(lstrlen(cacheEntry->szGroup)==0) group=&dat->list; else { group=AddGroup(hwnd,dat,cacheEntry->szGroup,(DWORD)-1,0,0); if(group==NULL) { int i,len; DWORD groupFlags; TCHAR *szGroupName; if(!(style&CLS_HIDEEMPTYGROUPS)) { // /*mir_free(dbv.pszVal);*/AddTempGroup(hwnd,dat,cacheEntry->szGroup,(DWORD)-1,0,0); return; } if(checkHideOffline && IsHiddenMode(dat,status)) { for(i=1;;i++) { szGroupName=(TCHAR*)CallService(MS_CLIST_GROUPGETNAMET,i,(LPARAM)&groupFlags); //UNICODE if(szGroupName==NULL) {/*mir_free(dbv.pszVal);*/ return;} //never happens if(!lstrcmp(szGroupName,cacheEntry->szGroup)) break; } if(groupFlags&GROUPF_HIDEOFFLINE) {/*mir_free(dbv.pszVal);*/ return;} } for(i=1;;i++) { szGroupName=(TCHAR*)CallService(MS_CLIST_GROUPGETNAMET,i,(LPARAM)&groupFlags); //UNICODE if(szGroupName==NULL) {/*mir_free(dbv.pszVal);*/ return;} //never happens if(!lstrcmp(szGroupName,cacheEntry->szGroup)) break; len=lstrlen(szGroupName); if(!_tcsncmp(szGroupName,cacheEntry->szGroup,len) && cacheEntry->szGroup[len]=='\\') AddGroup(hwnd,dat,szGroupName,groupFlags,i,1); } group=AddGroup(hwnd,dat,cacheEntry->szGroup,groupFlags,i,1); } // mir_free(dbv.pszVal); } if (cacheEntry->status==ID_STATUS_OFFLINE) if (DBGetContactSettingByte(NULL,"CList","PlaceOfflineToRoot",0)) group=&dat->list; if(checkHideOffline) { if(IsHiddenMode(dat,status) && (style&CLS_HIDEOFFLINE || group->hideOffline)) { if(updateTotalCount) group->totalMembers++; return; } } if(dat->IsMetaContactsEnabled && cacheEntry->HiddenSubcontact) return; if(!dat->IsMetaContactsEnabled && !MyStrCmp(cacheEntry->szProto,"MetaContacts")) return; cont=AddContactToGroup(dat,group,cacheEntry); if (cont) if (cont->proto) { cont->SubAllocated=0; if (MyStrCmp(cont->proto,"MetaContacts")==0) AddSubcontacts(dat,cont); } if(updateTotalCount && group) group->totalMembers++; ClearRowByIndexCache(); }
void RebuildEntireList(HWND hwnd,struct ClcData *dat) { // char *szProto; DWORD style = GetWindowLongPtr(hwnd,GWL_STYLE); struct ClcContact * cont; ClcGroup *group; //DBVARIANT dbv; int tick = GetTickCount(); ClearRowByIndexCache(); ClearClcContactCache(dat,INVALID_HANDLE_VALUE); dat->list.expanded = 1; dat->list.hideOffline = db_get_b(NULL,"CLC","HideOfflineRoot",0); memset( &dat->list.cl, 0, sizeof( dat->list.cl )); dat->list.cl.increment = 30; dat->needsResort = 1; dat->selection = -1; { int i; TCHAR *szGroupName; DWORD groupFlags; for (i = 1;;i++) { szGroupName = pcli->pfnGetGroupName(i,&groupFlags); if (szGroupName == NULL) break; AddGroup(hwnd,dat,szGroupName,groupFlags,i,0); } } for (HANDLE hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { ClcCacheEntry *cacheEntry; cont = NULL; cacheEntry = GetContactFullCacheEntry(hContact); //cacheEntry->ClcContact = NULL; ClearClcContactCache(dat,hContact); if (cacheEntry == NULL) MessageBoxA(0,"Fail To Get CacheEntry for hContact","!!!!!!!!",0); if (style&CLS_SHOWHIDDEN || !cacheEntry->bIsHidden) { if (lstrlen(cacheEntry->tszGroup) == 0) group = &dat->list; else { group = AddGroup(hwnd,dat,cacheEntry->tszGroup,(DWORD)-1,0,0); //mir_free(dbv.pszVal); } if (group != NULL) { group->totalMembers++; if ( !(style & CLS_NOHIDEOFFLINE) && (style & CLS_HIDEOFFLINE || group->hideOffline)) { if (cacheEntry->szProto == NULL) { if ( !pcli->pfnIsHiddenMode(dat,ID_STATUS_OFFLINE)||cacheEntry->noHiddenOffline) cont = AddContactToGroup(dat,group,cacheEntry); } else if ( !pcli->pfnIsHiddenMode(dat,cacheEntry->status)||cacheEntry->noHiddenOffline) cont = AddContactToGroup(dat,group,cacheEntry); } else cont = AddContactToGroup(dat,group,cacheEntry); } } if (cont && cont->proto) { cont->SubAllocated = 0; if (strcmp(cont->proto,"MetaContacts") == 0) AddSubcontacts(cont); } } if (style&CLS_HIDEEMPTYGROUPS) { group = &dat->list; group->scanIndex = 0; for (;;) { if (group->scanIndex == group->cl.count) { group = group->parent; if (group == NULL) break; } else if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP) { if (group->cl.items[group->scanIndex]->group->cl.count == 0) { group = RemoveItemFromGroup(hwnd,group,group->cl.items[group->scanIndex],0); } else { group = group->cl.items[group->scanIndex]->group; group->scanIndex = 0; } continue; } group->scanIndex++; } } SortCLC(hwnd,dat,0); tick = GetTickCount()-tick; { char buf[255]; //sprintf(buf,"%s %s took %i ms",__FILE__,__LINE__,tick); mir_snprintf(buf, SIZEOF(buf), "RebuildEntireList %d \r\n", tick); OutputDebugStringA(buf); db_set_dw((HANDLE)0,"CLUI","PF:Last RebuildEntireList Time:",tick); } }
void AddContactToTree(HWND hwnd, ClcData *dat, HANDLE hContact, int updateTotalCount, int checkHideOffline) { if ( FindItem(hwnd,dat,hContact,NULL,NULL,NULL) == 1) return; ClcCacheEntry *cacheEntry = GetContactFullCacheEntry(hContact); if (cacheEntry == NULL) return; char *szProto = cacheEntry->szProto; dat->needsResort = 1; ClearRowByIndexCache(); ClearClcContactCache(dat,hContact); WORD status; DWORD style = GetWindowLongPtr(hwnd,GWL_STYLE); if (style & CLS_NOHIDEOFFLINE) checkHideOffline = 0; if (checkHideOffline) { if (szProto == NULL) status = ID_STATUS_OFFLINE; else status = cacheEntry->status; } ClcGroup *group; if (lstrlen(cacheEntry->tszGroup) == 0) group = &dat->list; else { group = AddGroup(hwnd,dat,cacheEntry->tszGroup,(DWORD)-1,0,0); if (group == NULL) { DWORD groupFlags; int i; if ( !(style & CLS_HIDEEMPTYGROUPS)) return; if (checkHideOffline && pcli->pfnIsHiddenMode(dat,status)) { for (i = 1;;i++) { TCHAR *szGroupName = pcli->pfnGetGroupName(i, &groupFlags); if (szGroupName == NULL) return; //never happens if ( !lstrcmp(szGroupName,cacheEntry->tszGroup)) break; } if (groupFlags & GROUPF_HIDEOFFLINE) return; } for (i = 1;; i++) { TCHAR *szGroupName = pcli->pfnGetGroupName(i, &groupFlags); if (szGroupName == NULL) return; //never happens if ( !lstrcmp(szGroupName,cacheEntry->tszGroup)) break; size_t len = lstrlen(szGroupName); if ( !_tcsncmp(szGroupName,cacheEntry->tszGroup,len) && cacheEntry->tszGroup[len] == '\\') AddGroup(hwnd,dat,szGroupName,groupFlags,i,1); } group = AddGroup(hwnd,dat,cacheEntry->tszGroup,groupFlags,i,1); } } if (checkHideOffline) { if (pcli->pfnIsHiddenMode(dat,status) && (style & CLS_HIDEOFFLINE || group->hideOffline)) { if (updateTotalCount) group->totalMembers++; return; } } ClcContact *cont = AddContactToGroup(dat,group,cacheEntry); if (cont && cont->proto) { cont->SubAllocated = 0; if (strcmp(cont->proto,"MetaContacts") == 0) AddSubcontacts(cont); } if (updateTotalCount) group->totalMembers++; ClearRowByIndexCache(); }