From a421acc1e18762eb0810d1b9013285d083b95314 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 1 Dec 2012 00:19:57 +0000 Subject: - fixes for the menu icons related stuff; - some old code dropped; git-svn-id: http://svn.miranda-ng.org/main/trunk@2574 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/MetaContacts/MetaContacts_10.vcxproj | 4 ++ plugins/MetaContacts/src/addto.cpp | 64 ++++++++------------ plugins/MetaContacts/src/edit.cpp | 9 ++- plugins/MetaContacts/src/icons.cpp | 63 ++++--------------- plugins/MetaContacts/src/meta_main.cpp | 12 +--- plugins/MetaContacts/src/meta_menu.cpp | 23 +++---- plugins/MetaContacts/src/meta_services.cpp | 81 +++++++++++-------------- plugins/MetaContacts/src/meta_utils.cpp | 90 ++++++++++------------------ plugins/MetaContacts/src/metacontacts.h | 6 +- 9 files changed, 124 insertions(+), 228 deletions(-) (limited to 'plugins') diff --git a/plugins/MetaContacts/MetaContacts_10.vcxproj b/plugins/MetaContacts/MetaContacts_10.vcxproj index 81185178d8..272b2fee9a 100644 --- a/plugins/MetaContacts/MetaContacts_10.vcxproj +++ b/plugins/MetaContacts/MetaContacts_10.vcxproj @@ -164,6 +164,10 @@ WIN64;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) Use metacontacts.h + true + false + false + true $(IntDir)$(TargetName).lib diff --git a/plugins/MetaContacts/src/addto.cpp b/plugins/MetaContacts/src/addto.cpp index e99b4cb166..058be6394c 100644 --- a/plugins/MetaContacts/src/addto.cpp +++ b/plugins/MetaContacts/src/addto.cpp @@ -53,47 +53,36 @@ typedef struct { */ int FillList(HWND list, BOOL sort) { - DWORD metaID; - HANDLE hMetaUser = db_find_first(); int i=0; - int index; - //BOOL mbs = FALSE; - - while(hMetaUser) // The DB is searched through, to get all the metacontacts - { - if ((metaID = db_get_dw(hMetaUser, META_PROTO, META_ID,(DWORD)-1))==(DWORD)-1) - { - // This isn't a MetaContact, go to the next - hMetaUser = db_find_next(hMetaUser); + + // The DB is searched through, to get all the metacontacts + for (HANDLE hMetaUser = db_find_first(); hMetaUser; hMetaUser = db_find_next(hMetaUser)) { + // if it's not a MetaContact, go to the next + if ( db_get_dw(hMetaUser, META_PROTO, META_ID, (DWORD)-1) == (DWORD)-1) continue; - } - { - // get contact display name from clist - TCHAR *swzContactDisplayName = (TCHAR *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hMetaUser, GCDNF_TCHAR); - // don't insert huge strings that we have to compare with later - if (_tcslen(swzContactDisplayName) > 1023) - swzContactDisplayName[1024] = 0; + // get contact display name from clist + TCHAR *swzContactDisplayName = pcli->pfnGetContactDisplayName(hMetaUser, GCDNF_TCHAR); + // don't insert huge strings that we have to compare with later + if (_tcslen(swzContactDisplayName) > 1023) + swzContactDisplayName[1024] = 0; - if (sort) { + int index; + if (sort) { + for (int j = 0; j < i; j++) { TCHAR buff[1024]; - for (int j = 0; j < i; j++) { - SendMessage(list, LB_GETTEXT, j, (LPARAM)buff); - if (_tcscmp(buff, swzContactDisplayName) > 0) { - index = SendMessage(list, LB_INSERTSTRING, (WPARAM)j, (LPARAM)swzContactDisplayName); - break; - } + SendMessage(list, LB_GETTEXT, j, (LPARAM)buff); + if ( _tcscmp(buff, swzContactDisplayName) > 0) { + index = SendMessage(list, LB_INSERTSTRING, j, (LPARAM)swzContactDisplayName); + break; } - } else { - index = SendMessage(list, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)swzContactDisplayName); } - - SendMessage(list, LB_SETITEMDATA, (WPARAM)index, (LPARAM)hMetaUser); } + else index = SendMessage(list, LB_INSERTSTRING, (WPARAM)-1, (LPARAM)swzContactDisplayName); - i++; + SendMessage(list, LB_SETITEMDATA, index, (LPARAM)hMetaUser); - hMetaUser = db_find_next(hMetaUser); + i++; } return i; } @@ -107,14 +96,11 @@ int FillList(HWND list, BOOL sort) * * @returns An integer specifying the number of rows inserted or \c -1 if there was a problem */ + int BuildList(HWND list, BOOL sort) { - int ret=-1; SendMessage(list, LB_RESETCONTENT, 0, 0); - - ret = FillList(list, sort); - - return ret; + return FillList(list, sort); } /** Callback function for the 'Add To' Dialog. @@ -147,7 +133,7 @@ INT_PTR CALLBACK Meta_SelectDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP return TRUE; } - if (db_get_dw((HANDLE)lParam, META_PROTO, META_LINK, (DWORD)-1) != (DWORD)-1) { + if ( db_get_dw((HANDLE)lParam, META_PROTO, META_LINK, (DWORD)-1) != (DWORD)-1) { MessageBox(hwndDlg, TranslateT("This contact is already associated to a MetaContact.\nYou cannot add a contact to multiple MetaContacts."), TranslateT("Multiple MetaContacts"),MB_ICONERROR); @@ -170,7 +156,7 @@ INT_PTR CALLBACK Meta_SelectDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP } else { // get contact display name from clist - TCHAR *ptszCDN = (TCHAR*) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, lParam, GCDNF_TCHAR); + TCHAR *ptszCDN = pcli->pfnGetContactDisplayName((HANDLE)lParam, GCDNF_TCHAR); if (!ptszCDN) ptszCDN = TranslateT("a contact"); @@ -217,7 +203,7 @@ INT_PTR CALLBACK Meta_SelectDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LP case WM_DESTROY: // Free all allocated memory and return the focus to the CList HWND clist = GetParent(hwndDlg); - ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); + Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); EndDialog(hwndDlg,TRUE); SetFocus(clist); return TRUE; diff --git a/plugins/MetaContacts/src/edit.cpp b/plugins/MetaContacts/src/edit.cpp index a908734c50..a826e0f046 100644 --- a/plugins/MetaContacts/src/edit.cpp +++ b/plugins/MetaContacts/src/edit.cpp @@ -60,7 +60,7 @@ void FillContactList(HWND hWndDlg, CHANGES *chg) for (int i = 0; i < chg->num_contacts; i++) { LvItem.iItem = i; - TCHAR *ptszCDN = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)chg->hContact[i], GCDNF_TCHAR); + TCHAR *ptszCDN = pcli->pfnGetContactDisplayName(chg->hContact[i], GCDNF_TCHAR); if (ptszCDN == NULL) ptszCDN = TranslateT("(Unknown Contact)"); @@ -294,7 +294,7 @@ INT_PTR CALLBACK Meta_EditDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR case WMU_SETTITLE: { - TCHAR *ptszCDN = (TCHAR*) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)lParam, GCDNF_UNICODE); + TCHAR *ptszCDN = pcli->pfnGetContactDisplayName((HANDLE)lParam, GCDNF_TCHAR); if (ptszCDN == NULL) ptszCDN = TranslateT("(Unknown Contact)"); @@ -387,8 +387,7 @@ INT_PTR CALLBACK Meta_EditDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR if (changes.hDefaultContact == changes.hContact[sel]) { if (changes.num_contacts > 0) { changes.hDefaultContact = changes.hContact[0]; - TCHAR *str = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)changes.hDefaultContact, GCDNF_TCHAR); - SetWindowText(GetDlgItem(hwndDlg,IDC_ED_DEFAULT),str); + SetWindowText(GetDlgItem(hwndDlg,IDC_ED_DEFAULT), pcli->pfnGetContactDisplayName(changes.hDefaultContact, GCDNF_TCHAR)); } else { changes.hDefaultContact = 0; @@ -458,7 +457,7 @@ INT_PTR CALLBACK Meta_EditDialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPAR return TRUE; case WM_DESTROY: - ReleaseIconEx((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); + Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_SETICON, ICON_BIG, 0)); EndDialog(hwndDlg, IDCANCEL); break; } diff --git a/plugins/MetaContacts/src/icons.cpp b/plugins/MetaContacts/src/icons.cpp index 59e60ce5eb..3776212289 100644 --- a/plugins/MetaContacts/src/icons.cpp +++ b/plugins/MetaContacts/src/icons.cpp @@ -1,12 +1,13 @@ #include "metacontacts.h" -typedef struct { - char* szDescr; - char* szName; - int defIconID; -} IconStruct; - -static IconStruct iconList[] = { +struct +{ + char* szDescr; + char* szName; + int defIconID; + HANDLE hIcolib; +} +static iconList[] = { { LPGEN("Toggle Off"), "mc_off", IDI_MCMENUOFF }, { LPGEN("Toggle On"), "mc_on", IDI_MCMENU }, { LPGEN("Convert to MetaContact"), "mc_convert", IDI_MCCONVERT }, @@ -16,48 +17,14 @@ static IconStruct iconList[] = { { LPGEN("Remove"), "mc_remove", IDI_MCREMOVE }, }; - -HICON LoadIconEx(IconIndex i) -{ - return Skin_GetIcon(iconList[i].szName); -} - -void ReleaseIconEx(HICON hIcon) +HANDLE GetIconHandle(IconIndex i) { - Skin_ReleaseIcon(hIcon); + return iconList[i].hIcolib; } -int ReloadIcons(WPARAM wParam, LPARAM lParam) +HICON LoadIconEx(IconIndex i) { - // fix menu icons - CLISTMENUITEM mi = { sizeof(mi) }; - mi.flags = CMIM_ICON; - - mi.hIcon = LoadIconEx(Meta_IsEnabled() ? I_MENUOFF : I_MENU); - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuOnOff, (LPARAM)&mi); - ReleaseIconEx(mi.hIcon); - - mi.hIcon = LoadIconEx(I_CONVERT); - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuConvert, (LPARAM)&mi); - ReleaseIconEx(mi.hIcon); - - mi.hIcon = LoadIconEx(I_ADD); - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuAdd, (LPARAM)&mi); - ReleaseIconEx(mi.hIcon); - - mi.hIcon = LoadIconEx(I_EDIT); - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuEdit, (LPARAM)&mi); - ReleaseIconEx(mi.hIcon); - - mi.hIcon = LoadIconEx(I_SETDEFAULT); - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDefault, (LPARAM)&mi); - ReleaseIconEx(mi.hIcon); - - mi.hIcon = LoadIconEx(I_REMOVE); - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDelete, (LPARAM)&mi); - ReleaseIconEx(mi.hIcon); - - return 0; + return Skin_GetIcon(iconList[i].szName); } void InitIcons(void) @@ -74,10 +41,6 @@ void InitIcons(void) sid.pszDescription = iconList[i].szDescr; sid.pszName = iconList[i].szName; sid.iDefaultIndex = -iconList[i].defIconID; - Skin_AddIcon(&sid); + iconList[i].hIcolib = Skin_AddIcon(&sid); } - - HookEvent(ME_SKIN2_ICONSCHANGED, ReloadIcons); - - ReloadIcons(0, 0); } diff --git a/plugins/MetaContacts/src/meta_main.cpp b/plugins/MetaContacts/src/meta_main.cpp index cf98970716..288e344872 100644 --- a/plugins/MetaContacts/src/meta_main.cpp +++ b/plugins/MetaContacts/src/meta_main.cpp @@ -89,6 +89,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. BOOL os_unicode_enabled = FALSE; int hLangpack; +CLIST_INTERFACE *pcli = NULL; //! Information gathered by Miranda, displayed in the plugin pane of the Option Dialog PLUGININFOEX pluginInfo={ @@ -136,14 +137,6 @@ extern "C" __declspec(dllexport) int Unload(void) //MessageBox(0, "Unload complete", "MC", MB_OK); return 0; } - -BOOL IsUnicodeOS() -{ - OSVERSIONINFOW os; - memset(&os, 0, sizeof(OSVERSIONINFOW)); - os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW); - return (GetVersionExW(&os) != 0); -} /** Initializes the services provided and the link to those needed * Called when the plugin is loaded into Miranda @@ -151,8 +144,7 @@ BOOL IsUnicodeOS() extern "C" __declspec(dllexport) int Load(void) { mir_getLP(&pluginInfo); - - os_unicode_enabled = IsUnicodeOS(); + pcli = ( CLIST_INTERFACE* )CallService(MS_CLIST_RETRIEVE_INTERFACE, 0, (LPARAM)hInstance); CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (LPARAM)(META_PROTO "/Status")); CallService(MS_DB_SETSETTINGRESIDENT, TRUE, (LPARAM)(META_PROTO "/IdleTS")); diff --git a/plugins/MetaContacts/src/meta_menu.cpp b/plugins/MetaContacts/src/meta_menu.cpp index 18f446b0cc..e4eaf8257d 100644 --- a/plugins/MetaContacts/src/meta_menu.cpp +++ b/plugins/MetaContacts/src/meta_menu.cpp @@ -264,8 +264,6 @@ INT_PTR Meta_Delete(WPARAM wParam,LPARAM lParam) } else { HANDLE hMeta = (HANDLE)db_get_dw((HANDLE)wParam, META_PROTO, "Handle", 0); - - DWORD num_contacts = db_get_dw(hMeta, META_PROTO, "NumContacts", -1); if (num_contacts == 1) { @@ -341,17 +339,13 @@ HANDLE hMenuContact[MAX_CONTACTS]; int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam) { DBVARIANT dbv; - HANDLE hContact; char buf[512], idStr[512]; - int i, iconIndex; WORD status; CLISTMENUITEM mi = { sizeof(mi) }; mi.flags = CMIM_FLAGS; if (db_get_dw((HANDLE)wParam, META_PROTO, META_ID,-1) != (DWORD)-1) { - int num_contacts, i; - // save the mouse pos in case they open a subcontact menu GetCursorPos(&menuMousePoint); @@ -368,10 +362,10 @@ int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam) CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDelete, (LPARAM)&mi); //show subcontact menu items - num_contacts = db_get_dw((HANDLE)wParam, META_PROTO, "NumContacts", 0); - for (i = 0; i < MAX_CONTACTS; i++) { + int num_contacts = db_get_dw((HANDLE)wParam, META_PROTO, "NumContacts", 0); + for (int i = 0; i < MAX_CONTACTS; i++) { if (i < num_contacts) { - hContact = Meta_GetContactHandle((HANDLE)wParam, i); + HANDLE hContact = Meta_GetContactHandle((HANDLE)wParam, i); char *szProto = GetContactProto(hContact); if ( !szProto) status = ID_STATUS_OFFLINE; @@ -404,14 +398,14 @@ int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam) mi.flags = 0; } else { - mi.ptszName = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR); + mi.ptszName = pcli->pfnGetContactDisplayName(hContact, GCDNF_TCHAR); mi.flags = CMIF_TCHAR; } mi.flags |= CMIM_FLAGS | CMIM_NAME | CMIM_ICON; - iconIndex = (int)CallService(MS_CLIST_GETCONTACTICON, (WPARAM)hContact, 0); - mi.hIcon = ImageList_GetIcon((HIMAGELIST)CallService(MS_CLIST_GETICONSIMAGELIST, 0, 0), iconIndex, 0);; + int iconIndex = CallService(MS_CLIST_GETCONTACTICON, (WPARAM)hContact, 0); + mi.hIcon = ImageList_GetIcon((HIMAGELIST)CallService(MS_CLIST_GETICONSIMAGELIST, 0, 0), iconIndex, 0); CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuContact[i], (LPARAM)&mi); DestroyIcon(mi.hIcon); @@ -427,8 +421,7 @@ int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam) // wParam = char *szProto // lParam = BOOL show char serviceFunc[256]; - hContact = Meta_GetMostOnline((HANDLE)wParam); - mir_snprintf(serviceFunc, 256, "%s/SendNudge", GetContactProto(hContact)); + mir_snprintf(serviceFunc, 256, "%s/SendNudge", GetContactProto( Meta_GetMostOnline((HANDLE)wParam))); CallService(MS_NUDGE_SHOWMENU, (WPARAM)META_PROTO, (LPARAM)ServiceExists(serviceFunc)); } else { // This is a simple contact @@ -462,7 +455,7 @@ int Meta_ModifyMenu(WPARAM wParam, LPARAM lParam) CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuDefault, (LPARAM)&mi); } - for (i = 0; i < MAX_CONTACTS; i++) { + for (int i = 0; i < MAX_CONTACTS; i++) { mi.flags = CMIM_FLAGS | CMIF_HIDDEN; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuContact[i], (LPARAM)&mi); } diff --git a/plugins/MetaContacts/src/meta_services.cpp b/plugins/MetaContacts/src/meta_services.cpp index 4e491b50f6..bcb5668326 100644 --- a/plugins/MetaContacts/src/meta_services.cpp +++ b/plugins/MetaContacts/src/meta_services.cpp @@ -400,17 +400,17 @@ INT_PTR MetaFilter_RecvMessage(WPARAM wParam,LPARAM lParam) && db_get_b(hMeta, META_PROTO, "WindowOpen", 0) == 0 && options.flash_meta_message_icon) { - char toolTip[256], *contactName; + TCHAR toolTip[256]; CLISTEVENT cle = { sizeof(cle) }; cle.hContact = hMeta; + cle.flags = CLEF_TCHAR; cle.hDbEvent = ccs->hContact; // use subcontact handle as key - then we can remove all events if the subcontact window is opened cle.hIcon = LoadSkinnedIcon(SKINICON_EVENT_MESSAGE); cle.pszService = "MetaContacts/CListMessageEvent"; - contactName = (char *) CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hMeta, 0); - _snprintf(toolTip, sizeof(toolTip), Translate("Message from %s"), contactName); - cle.pszTooltip = toolTip; - CallService(MS_CLIST_ADDEVENT, 0, (LPARAM) & cle); + mir_sntprintf(toolTip, SIZEOF(toolTip), TranslateT("Message from %s"), pcli->pfnGetContactDisplayName(hMeta, GCDNF_TCHAR)); + cle.ptszTooltip = toolTip; + CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle); } if (options.metahistory) { @@ -1026,37 +1026,45 @@ int Meta_ModulesLoaded(WPARAM wParam, LPARAM lParam) HookEvent(ME_CLIST_PREBUILDCONTACTMENU, Meta_ModifyMenu); HookEvent(ME_CLIST_DOUBLECLICKED, Meta_ClistDoubleClicked ); + InitIcons(); + //////////////////////////////////////////////////////////////////////////// CLISTMENUITEM mi = { sizeof(mi) }; - mi.flags = CMIM_ALL; + mi.flags = CMIM_ALL | CMIF_ICONFROMICOLIB; // main menu item + mi.icolibItem = GetIconHandle(I_MENUOFF); mi.pszName = "Toggle MetaContacts Off"; mi.pszService = "MetaContacts/OnOff"; mi.position = 500010000; hMenuOnOff = Menu_AddMainMenuItem(&mi); // contact menu items + mi.icolibItem = GetIconHandle(I_CONVERT); mi.position = -200010; mi.pszName = "Convert to MetaContact"; mi.pszService = "MetaContacts/Convert"; hMenuConvert = Menu_AddContactMenuItem(&mi); + mi.icolibItem = GetIconHandle(I_ADD); mi.position = -200009; mi.pszName = "Add to existing MetaContact..."; mi.pszService = "MetaContacts/AddTo"; hMenuAdd = Menu_AddContactMenuItem(&mi); + mi.icolibItem = GetIconHandle(I_EDIT); mi.position = -200010; mi.pszName = "Edit MetaContact..."; mi.pszService = "MetaContacts/Edit"; hMenuEdit = Menu_AddContactMenuItem(&mi); + mi.icolibItem = GetIconHandle(I_SETDEFAULT); mi.position = -200009; mi.pszName = "Set as MetaContact default"; mi.pszService = "MetaContacts/Default"; hMenuDefault = Menu_AddContactMenuItem(&mi); + mi.icolibItem = GetIconHandle(I_REMOVE); mi.position = -200008; mi.pszName = "Delete MetaContact"; mi.pszService = "MetaContacts/Delete"; @@ -1066,6 +1074,7 @@ int Meta_ModulesLoaded(WPARAM wParam, LPARAM lParam) mi.pszContactOwner = META_PROTO; mi.position = -99000; + mi.flags &= ~CMIF_ICONFROMICOLIB; for (i = 0; i < MAX_CONTACTS; i++) { mi.position--; strcpy(buffer3, (char *)Translate("Context")); @@ -1095,57 +1104,43 @@ int Meta_ModulesLoaded(WPARAM wParam, LPARAM lParam) Meta_HideLinkedContacts(); - InitIcons(); - - if ( !Meta_IsEnabled()) - { + if ( !Meta_IsEnabled()) { // modify main menu item - mi.flags = CMIM_NAME; + mi.flags = CMIM_NAME | CMIM_ICON; + mi.icolibItem = GetIconHandle(I_MENU); mi.pszName = "Toggle MetaContacts On"; CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuOnOff, (LPARAM)&mi); Meta_HideMetaContacts(TRUE); - } else { - Meta_SuppressStatus(options.suppress_status); } + else Meta_SuppressStatus(options.suppress_status); // hook srmm window close/open events - message api ver 0.0.0.1+ if (HookEvent(ME_MSG_WINDOWEVENT, Meta_MessageWindowEvent)) message_window_api_enabled = TRUE; // hook protocol nudge events to forward to subcontacts - { - int i, numberOfProtocols,ret; - char str[MAXMODULELABELLENGTH + 10]; - HANDLE hNudgeEvent = NULL; - PROTOACCOUNT ** ppProtocolDescriptors; - ret = ProtoEnumAccounts(&numberOfProtocols, &ppProtocolDescriptors); - if (ret == 0) - { - for (i = 0; i < numberOfProtocols ; i++) - { - if (strcmp(ppProtocolDescriptors[i]->szModuleName, META_PROTO)) { - sprintf(str,"%s/Nudge",ppProtocolDescriptors[i]->szModuleName); - HookEvent(str, NudgeRecieved); - } - } + int numberOfProtocols; + PROTOACCOUNT ** ppProtocolDescriptors; + ProtoEnumAccounts(&numberOfProtocols, &ppProtocolDescriptors); + + for (int i = 0; i < numberOfProtocols ; i++) + if ( strcmp(ppProtocolDescriptors[i]->szModuleName, META_PROTO)) { + char str[MAXMODULELABELLENGTH + 10]; + sprintf(str,"%s/Nudge",ppProtocolDescriptors[i]->szModuleName); + HookEvent(str, NudgeRecieved); } - } + return 0; } static VOID CALLBACK sttMenuThread( PVOID param ) { - HMENU hMenu; - TPMPARAMS tpmp; - BOOL menuRet; - - hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)param, 0); + HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)param, 0); - ZeroMemory(&tpmp, sizeof(tpmp)); + TPMPARAMS tpmp = { 0 }; tpmp.cbSize = sizeof(tpmp); - - menuRet = TrackPopupMenuEx(hMenu, TPM_RETURNCMD, menuMousePoint.x, menuMousePoint.y, (HWND)CallService(MS_CLUI_GETHWND, 0, 0), &tpmp); + BOOL menuRet = TrackPopupMenuEx(hMenu, TPM_RETURNCMD, menuMousePoint.x, menuMousePoint.y, (HWND)CallService(MS_CLUI_GETHWND, 0, 0), &tpmp); CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(menuRet), MPCF_CONTACTMENU), (LPARAM)param); @@ -1410,24 +1405,20 @@ int Meta_CallMostOnline(WPARAM wParam, LPARAM lParam) INT_PTR Meta_OnOff(WPARAM wParam, LPARAM lParam) { CLISTMENUITEM mi = { sizeof(mi) }; + mi.flags = CMIM_NAME | CMIM_ICON; // just write to db - the rest is handled in the Meta_SettingChanged function if (db_get_b(0, META_PROTO, "Enabled", 1)) { db_set_b(0, META_PROTO, "Enabled", 0); // modify main mi item - mi.flags = CMIM_NAME | CMIM_ICON; - mi.hIcon = LoadIconEx(I_MENU); + mi.icolibItem = GetIconHandle(I_MENU); mi.pszName = "Toggle MetaContacts On"; - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuOnOff, (LPARAM)&mi); } else { db_set_b(0, META_PROTO, "Enabled", 1); // modify main mi item - mi.flags = CMIM_NAME | CMIM_ICON; - mi.hIcon = LoadIconEx(I_MENUOFF); + mi.icolibItem = GetIconHandle(I_MENUOFF); mi.pszName = "Toggle MetaContacts Off"; - CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuOnOff, (LPARAM)&mi); } - ReleaseIconEx(mi.hIcon); - + CallService(MS_CLIST_MODIFYMENUITEM, (WPARAM)hMenuOnOff, (LPARAM)&mi); return 0; } diff --git a/plugins/MetaContacts/src/meta_utils.cpp b/plugins/MetaContacts/src/meta_utils.cpp index 8f51404d61..f6370c6bea 100644 --- a/plugins/MetaContacts/src/meta_utils.cpp +++ b/plugins/MetaContacts/src/meta_utils.cpp @@ -237,14 +237,16 @@ BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default) WORD status; HANDLE most_online; - if ((metaID=db_get_dw(dest, META_PROTO, META_ID,(DWORD)-1))==-1) { + if ((metaID = db_get_dw(dest, META_PROTO, META_ID,(DWORD)-1))==-1) { MessageBox(0, TranslateT("Could not get MetaContact id"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); return FALSE; } - if ((num_contacts=db_get_dw(dest, META_PROTO, "NumContacts",(DWORD)-1))==-1) { + + if ((num_contacts = db_get_dw(dest, META_PROTO, "NumContacts",(DWORD)-1))==-1) { MessageBox(0, TranslateT("Could not retreive MetaContact contact count"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); return FALSE; } + char *szProto = GetContactProto(src); if (szProto == NULL) { MessageBox(0, TranslateT("Could not retreive contact protocol"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); @@ -274,7 +276,7 @@ BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default) // write the contact's protocol strcpy(buffer, "Protocol"); - strcat(buffer, _itoa((int)(num_contacts -1), szId, 10)); + strcat(buffer, _itoa(num_contacts-1, szId, 10)); if ( db_set_s(dest, META_PROTO, buffer, szProto)) { MessageBox(0, TranslateT("Could not write contact protocol to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); @@ -284,7 +286,7 @@ BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default) // write the login strcpy(buffer, "Login"); - strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10)); + strcat(buffer, szId); cws.szModule = META_PROTO; cws.szSetting = buffer; @@ -301,10 +303,10 @@ BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default) if ( !db_get(src,szProto,"Nick",&cws.value)) { // write the nickname strcpy(buffer, "Nick"); - strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10)); + strcat(buffer, szId); - cws.szModule=META_PROTO; - cws.szSetting=buffer; + cws.szModule = META_PROTO; + cws.szSetting = buffer; if (CallService(MS_DB_CONTACT_WRITESETTING,(WPARAM)dest,(LPARAM)&cws)) { MessageBox(0, TranslateT("Could not write nickname of contact to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); @@ -314,75 +316,44 @@ BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default) db_free(&cws.value); } - { - // Get the displayname of the subcontact - char *name = (char *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)src, 0); - wchar_t *wname = (wchar_t *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)src, GCDNF_UNICODE); - - // write the display name - strcpy(buffer, "CListName"); - strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10)); - - if (wname && strncmp(name, (char *)wname, strlen(name)) != 0) { - DBWriteContactSettingWString(dest, META_PROTO, buffer, wname); - } else - db_set_s(dest, META_PROTO, buffer, name); + // write the display name + strcpy(buffer, "CListName"); + strcat(buffer, szId); + db_set_ts(dest, META_PROTO, buffer, pcli->pfnGetContactDisplayName(src, GCDNF_TCHAR)); - // Get the status - if ( !szProto) - status = ID_STATUS_OFFLINE; - else - status = db_get_w(src, szProto, "Status", ID_STATUS_OFFLINE); - } + // Get the status + if ( !szProto) + status = ID_STATUS_OFFLINE; + else + status = db_get_w(src, szProto, "Status", ID_STATUS_OFFLINE); // write the status strcpy(buffer, "Status"); - strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10)); - if (db_set_w(dest, META_PROTO, buffer, status)) { - MessageBox(0, TranslateT("Could not write contact status to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); - return FALSE; - } + strcat(buffer, szId); + db_set_w(dest, META_PROTO, buffer, status); // write the handle strcpy(buffer, "Handle"); - strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10)); - if (db_set_dw(dest, META_PROTO, buffer, (DWORD)src)) { - MessageBox(0, TranslateT("Could not write contact handle to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); - return FALSE; - } + strcat(buffer, szId); + db_set_dw(dest, META_PROTO, buffer, (DWORD)src); // write status string strcpy(buffer, "StatusString"); - strcat(buffer, _itoa((int)(num_contacts - 1), szId, 10)); + strcat(buffer, szId); Meta_GetStatusString(status, buffer2, 512); - if (db_set_ts(dest, META_PROTO, buffer, buffer2)) { - MessageBox(0, TranslateT("Could not write contact status string to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); - return FALSE; - } + db_set_ts(dest, META_PROTO, buffer, buffer2); // Write the link in the contact - if (db_set_dw(src, META_PROTO, META_LINK,metaID)) { - MessageBox(0, TranslateT("Could not write MetaContact id to contact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); - return FALSE; - } + db_set_dw(src, META_PROTO, META_LINK, metaID); // Write the contact number in the contact - if (db_set_dw(src, META_PROTO, "ContactNumber",(DWORD)(num_contacts - 1))) { - MessageBox(0, TranslateT("Could not write MetaContact contact number to contact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); - return FALSE; - } + db_set_dw(src, META_PROTO, "ContactNumber", num_contacts-1); // Write the handle in the contact - if (db_set_dw(src, META_PROTO, "Handle",(DWORD)dest)) { - MessageBox(0, TranslateT("Could not write MetaContact contact number to contact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); - return FALSE; - } + db_set_dw(src, META_PROTO, "Handle", (DWORD)dest); // update count of contacts - if (db_set_dw(dest, META_PROTO, "NumContacts",num_contacts)) { - MessageBox(0, TranslateT("Could not write contact count to MetaContact"), TranslateT("Assignment Error"), MB_OK | MB_ICONWARNING); - return FALSE; - } + db_set_dw(dest, META_PROTO, "NumContacts", num_contacts); if (set_as_default) { db_set_dw(dest, META_PROTO, "Default", (WORD)(num_contacts - 1)); @@ -401,13 +372,12 @@ BOOL Meta_Assign(HANDLE src, HANDLE dest, BOOL set_as_default) most_online = Meta_GetMostOnlineSupporting(dest, PFLAGNUM_4, PF4_AVATARS); if (most_online == src) { PROTO_AVATAR_INFORMATIONT AI; - AI.cbSize = sizeof(AI); AI.hContact = dest; AI.format = PA_FORMAT_UNKNOWN; _tcscpy(AI.filename, _T("X")); - if ((int)CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS) + if ( CallProtoService(META_PROTO, PS_GETAVATARINFOT, 0, (LPARAM)&AI) == GAIR_SUCCESS) db_set_ts(dest, "ContactPhoto", "File",AI.filename); } @@ -1274,7 +1244,7 @@ int Meta_CopyContactNick(HANDLE hMeta, HANDLE hContact) { return 0; } } else if (options.clist_contact_name == CNNT_DISPLAYNAME) { - TCHAR *name = (TCHAR*)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)hContact, GCDNF_TCHAR); + TCHAR *name = pcli->pfnGetContactDisplayName(hContact, GCDNF_TCHAR); if (name && _tcscmp(name, TranslateT("(Unknown Contact)")) != 0) { db_set_ts(hMeta, META_PROTO, "Nick", name); db_free(&dbv_proto); diff --git a/plugins/MetaContacts/src/metacontacts.h b/plugins/MetaContacts/src/metacontacts.h index a41c8e4ba9..9488194ead 100644 --- a/plugins/MetaContacts/src/metacontacts.h +++ b/plugins/MetaContacts/src/metacontacts.h @@ -41,7 +41,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "m_metacontacts.h" #include -#include +#include #include #include #include @@ -208,7 +208,7 @@ void InitIcons(void); typedef enum {I_MENUOFF, I_MENU, I_CONVERT, I_ADD, I_EDIT, I_SETDEFAULT, I_REMOVE} IconIndex; HICON LoadIconEx(IconIndex i); -void ReleaseIconEx(HICON hIcon); +HANDLE GetIconHandle(IconIndex i); extern HANDLE hEventDefaultChanged, hEventForceSend, hEventUnforceSend, hSubcontactsChanged; @@ -233,8 +233,6 @@ extern BOOL meta_group_hack_disabled; #ifndef MS_CLUI_GETVERSION #define MS_CLUI_GETVERSION "CLUI/GetVersion" -extern BOOL os_unicode_enabled; - #define szDelMsg "You are going to remove all the contacts associated with this MetaContact.\nThis will delete the MetaContact.\n\nProceed Anyway?" #endif -- cgit v1.2.3