From 18f7e9261c885e953f220ba6836e8bca43a6fc88 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 15 Apr 2016 13:40:58 +0000 Subject: contact list groups: - finally database is not used anymore (only as a settings' storage); - MGROUP type introduced to replace HANDLE for group ids; - MS_CLIST_GROUP* services became Clist_Group* functions; - CLIST_INTERFACE members pfnGetGroupName & pfnRenameGroup also transformed into static Clist_Group* functions git-svn-id: http://svn.miranda-ng.org/main/trunk@16659 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- bin10/lib/mir_app.lib | Bin 67842 -> 69976 bytes bin10/lib/mir_app64.lib | Bin 65660 -> 67628 bytes bin10/lib/mir_core.lib | Bin 301578 -> 301568 bytes bin10/lib/mir_core64.lib | Bin 302568 -> 302552 bytes bin12/lib/mir_app.lib | Bin 67842 -> 69976 bytes bin12/lib/mir_app64.lib | Bin 65660 -> 67628 bytes bin12/lib/mir_core.lib | Bin 301578 -> 301568 bytes bin12/lib/mir_core64.lib | Bin 302568 -> 302552 bytes bin14/lib/mir_app.lib | Bin 67842 -> 69976 bytes bin14/lib/mir_app64.lib | Bin 65660 -> 67628 bytes bin14/lib/mir_core.lib | Bin 301578 -> 301568 bytes bin14/lib/mir_core64.lib | Bin 302568 -> 302552 bytes include/delphi/m_clist.inc | 129 +---- include/delphi/m_clistint.inc | 5 - include/m_clist.h | 86 ++- include/m_clistint.h | 5 +- include/m_gui.h | 7 +- plugins/AddContactPlus/src/addcontact.cpp | 2 +- plugins/Clist_modern/src/modern_clc.cpp | 17 +- plugins/Clist_modern/src/modern_clcitems.cpp | 4 +- plugins/Clist_modern/src/modern_viewmodebar.cpp | 2 +- plugins/Clist_nicer/src/clcitems.cpp | 2 +- plugins/Clist_nicer/src/clui.cpp | 2 +- plugins/Clist_nicer/src/contact.cpp | 2 +- plugins/Clist_nicer/src/viewmodes.cpp | 2 +- plugins/ContactsPlus/src/receive.cpp | 4 +- plugins/DbEditorPP/src/exportimport.cpp | 13 +- plugins/FavContacts/src/menu.cpp | 2 +- plugins/Import/src/utils.cpp | 2 +- plugins/NewAwaySysMod/src/ContactList.cpp | 2 +- plugins/NewsAggregator/Src/ExportImport.cpp | 30 +- plugins/Non-IM Contact/src/contactinfo.cpp | 4 +- plugins/Quotes/src/ImportExport.cpp | 2 +- plugins/SendScreenshotPlus/src/CSendDropbox.cpp | 1 - plugins/StopSpamMod/src/options.cpp | 8 +- plugins/StopSpamMod/src/utilities.cpp | 14 +- plugins/StopSpamPlus/src/services.cpp | 8 +- plugins/StopSpamPlus/src/stopspam.cpp | 3 +- .../src/ex_import/classExImContactBase.cpp | 11 +- plugins/Utils.pas/mirutils.pas | 2 +- protocols/AimOscar/src/utility.cpp | 2 +- protocols/FacebookRM/src/connection.cpp | 2 +- protocols/FacebookRM/src/dialogs.cpp | 2 +- protocols/Gadu-Gadu/src/import.cpp | 2 +- protocols/IcqOscarJ/src/icq_servlist.cpp | 10 +- protocols/JabberG/src/jabber_iq_handlers.cpp | 2 +- protocols/JabberG/src/jabber_iqid.cpp | 2 +- protocols/JabberG/src/jabber_privacy.cpp | 10 +- protocols/MRA/src/Mra_proto.cpp | 2 +- protocols/MSN/src/msn_srv.cpp | 2 +- protocols/Sametime/src/userlist.cpp | 18 +- protocols/SkypeWeb/src/skype_options.cpp | 2 +- protocols/Steam/src/steam_options.cpp | 2 +- protocols/Tlen/src/tlen_iqid.cpp | 4 +- protocols/Tlen/src/tlen_thread.cpp | 2 +- protocols/Tox/src/tox_options.cpp | 4 +- protocols/Twitter/src/connection.cpp | 4 +- protocols/VKontakte/src/vk_options.cpp | 2 +- protocols/VKontakte/src/vk_proto.cpp | 2 +- protocols/WhatsApp/src/proto.cpp | 2 +- src/mir_app/src/addcontact.cpp | 20 +- src/mir_app/src/chat_clist.cpp | 6 +- src/mir_app/src/clc.cpp | 70 +-- src/mir_app/src/clc.h | 4 +- src/mir_app/src/clcitems.cpp | 6 +- src/mir_app/src/clcmsgs.cpp | 2 +- src/mir_app/src/clcutils.cpp | 8 +- src/mir_app/src/clistcore.cpp | 3 - src/mir_app/src/clistgroups.cpp | 530 ++++++++++++++++++ src/mir_app/src/clui.cpp | 4 +- src/mir_app/src/contact.cpp | 4 +- src/mir_app/src/groups.cpp | 608 --------------------- src/mir_app/src/menu_groups.cpp | 2 +- src/mir_app/src/mir_app.def | 9 + src/mir_app/src/mir_app64.def | 9 + src/mir_core/src/mir_core.def | 2 +- src/mir_core/src/mir_core64.def | 2 +- src/mir_core/src/ui_utils.cpp | 4 +- 78 files changed, 721 insertions(+), 1021 deletions(-) create mode 100644 src/mir_app/src/clistgroups.cpp delete mode 100644 src/mir_app/src/groups.cpp diff --git a/bin10/lib/mir_app.lib b/bin10/lib/mir_app.lib index 7b207b43c1..3cdb2bba84 100644 Binary files a/bin10/lib/mir_app.lib and b/bin10/lib/mir_app.lib differ diff --git a/bin10/lib/mir_app64.lib b/bin10/lib/mir_app64.lib index 31ef8b0b07..8e5f3527b9 100644 Binary files a/bin10/lib/mir_app64.lib and b/bin10/lib/mir_app64.lib differ diff --git a/bin10/lib/mir_core.lib b/bin10/lib/mir_core.lib index 7cb68df575..885a7f985d 100644 Binary files a/bin10/lib/mir_core.lib and b/bin10/lib/mir_core.lib differ diff --git a/bin10/lib/mir_core64.lib b/bin10/lib/mir_core64.lib index 3bf83695fb..bb8acd7e4c 100644 Binary files a/bin10/lib/mir_core64.lib and b/bin10/lib/mir_core64.lib differ diff --git a/bin12/lib/mir_app.lib b/bin12/lib/mir_app.lib index 7b207b43c1..3cdb2bba84 100644 Binary files a/bin12/lib/mir_app.lib and b/bin12/lib/mir_app.lib differ diff --git a/bin12/lib/mir_app64.lib b/bin12/lib/mir_app64.lib index 31ef8b0b07..8e5f3527b9 100644 Binary files a/bin12/lib/mir_app64.lib and b/bin12/lib/mir_app64.lib differ diff --git a/bin12/lib/mir_core.lib b/bin12/lib/mir_core.lib index 7cb68df575..885a7f985d 100644 Binary files a/bin12/lib/mir_core.lib and b/bin12/lib/mir_core.lib differ diff --git a/bin12/lib/mir_core64.lib b/bin12/lib/mir_core64.lib index 3bf83695fb..bb8acd7e4c 100644 Binary files a/bin12/lib/mir_core64.lib and b/bin12/lib/mir_core64.lib differ diff --git a/bin14/lib/mir_app.lib b/bin14/lib/mir_app.lib index 7b207b43c1..3cdb2bba84 100644 Binary files a/bin14/lib/mir_app.lib and b/bin14/lib/mir_app.lib differ diff --git a/bin14/lib/mir_app64.lib b/bin14/lib/mir_app64.lib index 31ef8b0b07..8e5f3527b9 100644 Binary files a/bin14/lib/mir_app64.lib and b/bin14/lib/mir_app64.lib differ diff --git a/bin14/lib/mir_core.lib b/bin14/lib/mir_core.lib index 7cb68df575..885a7f985d 100644 Binary files a/bin14/lib/mir_core.lib and b/bin14/lib/mir_core.lib differ diff --git a/bin14/lib/mir_core64.lib b/bin14/lib/mir_core64.lib index 3bf83695fb..bb8acd7e4c 100644 Binary files a/bin14/lib/mir_core64.lib and b/bin14/lib/mir_core64.lib differ diff --git a/include/delphi/m_clist.inc b/include/delphi/m_clist.inc index 57f0f8440d..eeb564581d 100644 --- a/include/delphi/m_clist.inc +++ b/include/delphi/m_clist.inc @@ -33,23 +33,20 @@ const } MS_CLIST_GETSTATUSMODE:PAnsiChar = 'CList/GetStatusMode'; -function Menu_BuildContactMenu(hContact:TMCONTACT) : HMENU; stdcall; - external AppDll name 'Menu_BuildContactMenu'; +function Menu_BuildContactMenu(hContact:TMCONTACT) : HMENU; stdcall; external AppDll; { Affect : Modify an existing menu item, see notes Returns: 0 on success, [non zero] on failure } -function Menu_ModifyItem(hMenu:HGENMENU; const name:PWideChar; icon:THANDLE=INVALID_HANDLE_VALUE; flags:int=-1) : int; stdcall; - external AppDll name 'Menu_ModifyItem'; +function Menu_ModifyItem(hMenu:HGENMENU; const name:PWideChar; icon:THANDLE=INVALID_HANDLE_VALUE; flags:int=-1) : int; stdcall; external AppDll; { Notes : changes menu item's visibility } -procedure Menu_ShowItem(hMenu:HGENMENU; bShow:BYTE); stdcall; - external AppDll name 'Menu_ShowItem'; +procedure Menu_ShowItem(hMenu:HGENMENU; bShow:BYTE); stdcall; external AppDll; { wParam : TMCONTACT @@ -276,128 +273,12 @@ type const ME_CLIST_GROUPCHANGE:PAnsiChar = 'CList/GroupChange'; - { - checks that a group exists - wParam : 0 (unused) - lParam : (PWideChar)groupName - returns 0 if a group is not found or group handle on success - } - MS_CLIST_GROUPEXISTS:PAnsiChar = 'CList/GroupExists'; - - { - wParam : HPARENTGROUP - lParam : 0 or Pointer to new group name - Affect : Create a new group and calls CLUI to display it, see notes - Returns: A handle to the new group. - Notes : If HPARENTGROUP is NULL(0) it will create a group at the root. - Version: v0.1.1.0+ - } - MS_CLIST_GROUPCREATE:PAnsiChar = 'CList/GroupCreate'; - - { - wParam : HGROUP - lParam : 0 - Affect : Delete a group and call CLUI to display the change - Returns: 0 on success, [non zero] on failure - Version: v0.1.1.0+ - } - MS_CLIST_GROUPDELETE:PAnsiChar = 'CList/GroupDelete'; - - { - wParam : HGROUP - lParam : newState - Affect : Change the expanded state flag for a group internally, see notes - Returns: 0 on success, [non zero] on failure - Notes : if newState is non zero then the group is expanded, 0 it's collapsed - CLUI IS *NOT* called when the change is made. - Version: v0.1.1.0+ - } - MS_CLIST_GROUPSETEXPANDED:PAnsiChar = 'CList/GroupSetExpanded'; - - { - wParam : HGROUP - lParam : MAKELPARAM(flags, flagsMask) - Affect : Change the flag for a group, see notes - Returns: 0 on success, [non zero] on failure - Notes : only if flags given in flagsmask are altered, - CLUI is called on change to GROUPF_HIDEOFFLINE - Version: v0.1.2.1+ - } - MS_CLIST_GROUPSETFLAGS:PAnsiChar = 'CList/GroupSetFlags'; - - { - wParam : HGROUP - lParam : Pointer to a integer to be filled with expanded state - Affect : get the name of a group, see notes - Returns: a static buffer pointing to the name of the group - returns NULL(0) if HGROUP is invalid. - Notes : the returned buffer is only valid til the next call - to this service, lParam can be NULL(0) if you don't - want to know if the group is expanded - Version: v0.1.1.0+ - } - MS_CLIST_GROUPGETNAME:PAnsiChar = 'CList/GroupGetName'; - - { - wParam : HGROUP - lParam : Pointer to flags - Affect : Get the name of the group, see notes - Returns: A static buffer pointing to the name of the group - returns NULL(0) if HGROUP is invalid - Note : this buffer is only valid til the next call to this service - flags can be NULL(0), otherwise it'll return GROUPF_* constants - Version: v0.1.2.1+ - } - MS_CLIST_GROUPGETNAME2:PAnsiChar = 'CList/GroupGetName2'; - GROUPF_EXPANDED = $04; GROUPF_HIDEOFFLINE = $08; - { - wParam : HGROUP - lParam : HBEFOREGROUP - Affect : Move a group directly before another group - Returns: the new handle of the group on success, NULL(0) on failure - Notes : the order is represented by the order in which MS_CLUI_GROUPADDED - is called, however UI's are free to ignore this order and sort - if they wish. - Version: v0.1.2.1+ - } - MS_CLIST_GROUPMOVEBEFORE:PAnsiChar = 'CList/GroupMoveBefore'; - { - wParam : HGROUP - lParam : Pointer to a null terminated string containing the new name - Affect : Rename a group internally, see notes - Returns: 0 on success, [non zero] on failure - Notes : this will fail if the group name is a duplicate of an existing - a name, CLUI is not called when this change is made. - Version: v0.1.1.0+ - } - MS_CLIST_GROUPRENAME:PAnsiChar = 'CList/GroupRename'; - - { - wParam : 0 - lParam : 0 - Affect : Build a menu of the group tree, see notes - Returns: Handle to the menu, NULL(0) on failure - Notes : NULL be returned if the user doesn't have any groups - the dwItemData of every menu item is the handle to that group. - Menu item ID's are assigned starting at 100 in no particular order - Version: v0.1.2.1+ - } - MS_CLIST_GROUPBUILDMENU:PAnsiChar = 'CList/GroupBuildMenu'; - - { - wParam : newValue - lParam : 0 - Affect : Changes the 'hide offline contacts' flag and calls CLUI, see notes - Returns: 0 success, [non zero] on failure - Notes : newValue is 0 to show all contacts, 1 to show only online contacts - -1 to toggle the value - Version: v0.1.1.0+ - } - MS_CLIST_SETHIDEOFFLINE:PAnsiChar = 'CList/SetHideOffline'; +function Clist_GroupCreate(hParentGroup:integer; groupName:PWideChar) : integer; stdcall; external AppDll; +const { wParam : TMCONTACT lParam : 0 diff --git a/include/delphi/m_clistint.inc b/include/delphi/m_clistint.inc index dd9526d786..88fcb303ad 100644 --- a/include/delphi/m_clistint.inc +++ b/include/delphi/m_clistint.inc @@ -51,7 +51,6 @@ const INTM_NAMECHANGED = WM_USER+10; INTM_ICONCHANGED = WM_USER+11; INTM_GROUPCHANGED = WM_USER+12; - INTM_GROUPSCHANGED = WM_USER+13; INTM_CONTACTADDED = WM_USER+14; INTM_CONTACTDELETED = WM_USER+15; INTM_HIDDENCHANGED = WM_USER+16; @@ -438,10 +437,6 @@ type (* docking.c *) pfnDocking_ProcessWindowMessage : function (wParam:WPARAM; lParam:LPARAM):int; cdecl; - (* group.c *) - pfnGetGroupName : function (idx:int; var pdwFlags:dword):TChar; cdecl; - pfnRenameGroup : function (groupID:int; newName:TChar):int; cdecl; - (* keyboard.c *) pfnHotKeysRegister : function (hwnd:HWND):int; cdecl; pfnHotKeysUnregister : procedure (hwnd:HWND); cdecl; diff --git a/include/m_clist.h b/include/m_clist.h index a66e48cf45..1475fca43d 100644 --- a/include/m_clist.h +++ b/include/m_clist.h @@ -271,7 +271,7 @@ typedef struct { ///////////////////////////////////////////////////////////////////////////////////////// //processes a menu selection from a menu //wParam = MAKEWPARAM(LOWORD(wParam from WM_COMMAND), flags) -//lParam = (LPARAM)(HANDLE)hContact +//lParam = (LPARAM)(MCONTACT)hContact //returns TRUE if it processed the command, FALSE otherwise //hContact is the currently selected contact. It it not used if this is a main //menu command. If this is NULL and the command is a contact menu one, the @@ -293,9 +293,9 @@ typedef struct { // Otherwise, you HAVE TO distinguish WM_COMMAND from clist menus and from youк internal menu and // DO NOT call MS_CLIST_MENUPROCESSCOMMAND for non clist menus. - #define MPCF_CONTACTMENU 1 //test commands from a contact menu #define MPCF_MAINMENU 2 //test commands from the main menu + #define MS_CLIST_MENUPROCESSCOMMAND "CList/MenuProcessCommand" ///////////////////////////////////////////////////////////////////////////////////////// @@ -343,94 +343,77 @@ typedef struct { // lParam = pointer to CLISTGROUPCHANGE typedef struct { - int cbSize; //size in bytes of this structure - TCHAR* pszOldName; //old group name - TCHAR* pszNewName; //new group name + int cbSize; // size in bytes of this structure + TCHAR *pszOldName; // old group name, NULL if a new group was created + TCHAR *pszNewName; // new group name, NULL if an old group was deleted } CLISTGROUPCHANGE; #define ME_CLIST_GROUPCHANGE "CList/GroupChange" ///////////////////////////////////////////////////////////////////////////////////////// // checks that a group exists -// wParam = 0 (unused) -// lParam = (TCHAR*)groupName // returns 0 if a group is not found or group handle on success -#define MS_CLIST_GROUPEXISTS "CList/GroupExists" -__forceinline HANDLE Clist_GroupExists(LPCTSTR ptszGroupName) -{ return (HANDLE)CallService(MS_CLIST_GROUPEXISTS, 0, (LPARAM)ptszGroupName); -} +typedef int MGROUP; + +EXTERN_C MIR_APP_DLL(MGROUP) Clist_GroupExists(LPCTSTR ptszGroupName); ///////////////////////////////////////////////////////////////////////////////////////// // creates a new group and calls CLUI to display it -// wParam = hParentGroup -// lParam = groupName // returns a handle to the new group // hParentGroup is NULL to create the new group at the root, or can be the // handle of the group of which the new group should be a subgroup. // groupName is a TCHAR* pointing to the group name to create or NULL for // API to create unique name by itself -#define MS_CLIST_GROUPCREATE "CList/GroupCreate" -__forceinline HANDLE Clist_CreateGroup(HANDLE hParent, LPCTSTR ptszGroupName) -{ return (HANDLE)CallService(MS_CLIST_GROUPCREATE, (WPARAM)hParent, (LPARAM)ptszGroupName); -} +EXTERN_C MIR_APP_DLL(MGROUP) Clist_GroupCreate(MGROUP hParent, const TCHAR *ptszGroupName); ///////////////////////////////////////////////////////////////////////////////////////// // deletes a group and calls CLUI to display the change -// wParam = (WPARAM)(HANDLE)hGroup -// lParam = 0 // returns 0 on success, nonzero on failure -#define MS_CLIST_GROUPDELETE "CList/GroupDelete" + +EXTERN_C MIR_APP_DLL(int) Clist_GroupDelete(MGROUP hGroup); + +///////////////////////////////////////////////////////////////////////////////////////// +// renames a group +// returns 0 on success, nonzero on failure + +EXTERN_C MIR_APP_DLL(int) Clist_GroupRename(MGROUP hGroup, const TCHAR *ptszNewName); + +///////////////////////////////////////////////////////////////////////////////////////// +// retrieves a group's name +// returns a TCHAR* on success, NULL on failure +// if pdwFlags is not NULL, also stores group flags into it (one of GROUPF_* constants + +#define GROUPF_EXPANDED 0x04 +#define GROUPF_HIDEOFFLINE 0x08 + +EXTERN_C MIR_APP_DLL(TCHAR*) Clist_GroupGetName(MGROUP hGroup, DWORD *pdwFlags = NULL); ///////////////////////////////////////////////////////////////////////////////////////// // change the expanded state flag for a group internally -// wParam = (WPARAM)(HANDLE)hGroup -// lParam = newState // returns 0 on success, nonzero on failure // newState is nonzero if the group is expanded, 0 if it's collapsed // CLUI is not called when this change is made -#define MS_CLIST_GROUPSETEXPANDED "CList/GroupSetExpanded" + +EXTERN_C MIR_APP_DLL(int) Clist_GroupSetExpanded(MGROUP hGroup, int iNewState); ///////////////////////////////////////////////////////////////////////////////////////// // changes the flags for a group -// wParam = (WPARAM)(HANDLE)hGroup -// lParam = MAKELPARAM(flags, flagsMask) +// iNewFlags = MAKELPARAM(flags, flagsMask) // returns 0 on success, nonzero on failure // Only the flags given in flagsMask are altered. // CLUI is called on changes to GROUPF_HIDEOFFLINE. -#define MS_CLIST_GROUPSETFLAGS "CList/GroupSetFlags" - -///////////////////////////////////////////////////////////////////////////////////////// -// get the name of a group -// wParam = (WPARAM)(HANDLE)hGroup -// lParam = (LPARAM)(int*)&isExpanded -// returns a static buffer pointing to the name of the group -// returns NULL if hGroup is invalid. -// this buffer is only valid until the next call to this service -// & isExpanded can be NULL if you don't want to know if the group is expanded or not. -#define MS_CLIST_GROUPGETNAME "CList/GroupGetName" -#define GROUPF_EXPANDED 0x04 -#define GROUPF_HIDEOFFLINE 0x08 +EXTERN_C MIR_APP_DLL(int) Clist_GroupSetFlags(MGROUP hGroup, LPARAM iNewFlags); ///////////////////////////////////////////////////////////////////////////////////////// // move a group to directly before another group -// wParam = (WPARAM)(HANDLE)hGroup -// lParam = (LPARAM)(HANDLE)hBeforeGroup // returns the new handle of the group on success, NULL on failure // The order is represented by the order in which MS_CLUI_GROUPADDED is called, // however UIs are free to ignore this order and sort alphabetically if they wish. -#define MS_CLIST_GROUPMOVEBEFORE "CList/GroupMoveBefore" -///////////////////////////////////////////////////////////////////////////////////////// -// rename a group internally -// wParam = (WPARAM)(HANDLE)hGroup -// lParam = (LPARAM)(char*)szNewName -// returns 0 on success, nonzero on failure -// this will fail if the group name is a duplicate of an existing name -// CLUI is not called when this change is made -#define MS_CLIST_GROUPRENAME "CList/GroupRename" +EXTERN_C MIR_APP_DLL(int) Clist_GroupMoveBefore(MGROUP hGroup, MGROUP hGroupBefore); ///////////////////////////////////////////////////////////////////////////////////////// // build a menu of the group tree @@ -439,7 +422,8 @@ __forceinline HANDLE Clist_CreateGroup(HANDLE hParent, LPCTSTR ptszGroupName) // NULL will be returned if the user doesn't have any groups // The dwItemData of every menu item is the handle to that group. // Menu item IDs are assigned starting at 100, in no particular order. -#define MS_CLIST_GROUPBUILDMENU "CList/GroupBuildMenu" + +EXTERN_C MIR_APP_DLL(HMENU) Clist_GroupBuildMenu(void); ///////////////////////////////////////////////////////////////////////////////////////// // changes the 'hide offline contacts' flag and call CLUI @@ -468,7 +452,7 @@ __forceinline HANDLE Clist_CreateGroup(HANDLE hParent, LPCTSTR ptszGroupName) ///////////////////////////////////////////////////////////////////////////////////////// // change the group a contact belongs to // wParam = (MCONTACT)hContact -// lParam = (LPARAM)(HANDLE)hGroup +// lParam = (LPARAM)(MGROUP)hGroup // returns 0 on success, nonzero on failure // use hGroup = NULL to put the contact in no group #define MS_CLIST_CONTACTCHANGEGROUP "CList/ContactChangeGroup" diff --git a/include/m_clistint.h b/include/m_clistint.h index a78ff48c6e..56d542a011 100644 --- a/include/m_clistint.h +++ b/include/m_clistint.h @@ -50,7 +50,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define INTM_NAMECHANGED (WM_USER+10) #define INTM_ICONCHANGED (WM_USER+11) #define INTM_GROUPCHANGED (WM_USER+12) -#define INTM_GROUPSCHANGED (WM_USER+13) #define INTM_CONTACTADDED (WM_USER+14) #define INTM_CONTACTDELETED (WM_USER+15) #define INTM_HIDDENCHANGED (WM_USER+16) @@ -397,8 +396,8 @@ struct CLIST_INTERFACE int (*pfnDocking_ProcessWindowMessage)(WPARAM wParam, LPARAM lParam); /* group.c */ - WCHAR* (*pfnGetGroupName)(int idx, DWORD* pdwFlags); - int (*pfnRenameGroup)(int groupID, WCHAR* newName); + WCHAR* (*tobedeleted)(int idx, DWORD* pdwFlags); + int (*tobedeleted2)(int groupID, const WCHAR *newName); /* keyboard.c */ int (*pfnHotKeysRegister)(HWND hwnd); diff --git a/include/m_gui.h b/include/m_gui.h index c8b5383b73..76beacdf2a 100644 --- a/include/m_gui.h +++ b/include/m_gui.h @@ -540,6 +540,11 @@ protected: ///////////////////////////////////////////////////////////////////////////////////////// // CCtrlClc + +#if !defined(MGROUP) + typedef int MGROUP; +#endif + class MIR_CORE_EXPORT CCtrlClc : public CCtrlBase { typedef CCtrlBase CSuper; @@ -556,7 +561,7 @@ public: void EnsureVisible(HANDLE hItem, bool partialOk); void Expand(HANDLE hItem, DWORD flags); HANDLE FindContact(MCONTACT hContact); - HANDLE FindGroup(HANDLE hGroup); + HANDLE FindGroup(MGROUP hGroup); COLORREF GetBkColor(); bool GetCheck(HANDLE hItem); int GetCount(); diff --git a/plugins/AddContactPlus/src/addcontact.cpp b/plugins/AddContactPlus/src/addcontact.cpp index 8255c97ac2..e4138f02ec 100644 --- a/plugins/AddContactPlus/src/addcontact.cpp +++ b/plugins/AddContactPlus/src/addcontact.cpp @@ -170,7 +170,7 @@ INT_PTR CALLBACK AddContactDlgProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM) HookEventMessage(ME_PROTO_ACCLISTCHANGED, hdlg, DM_ADDCONTACT_CHANGEACCLIST); { TCHAR *szGroup; - for (int i = 1; (szGroup = pcli->pfnGetGroupName(i, NULL)) != NULL; i++) { + for (int i = 1; (szGroup = Clist_GroupGetName(i, NULL)) != NULL; i++) { int id = SendDlgItemMessage(hdlg, IDC_GROUP, CB_ADDSTRING, 0, (LPARAM)szGroup); SendDlgItemMessage(hdlg, IDC_GROUP, CB_SETITEMDATA, (WPARAM)id, (LPARAM)i); } diff --git a/plugins/Clist_modern/src/modern_clc.cpp b/plugins/Clist_modern/src/modern_clc.cpp index 169089957b..99703afe5f 100644 --- a/plugins/Clist_modern/src/modern_clc.cpp +++ b/plugins/Clist_modern/src/modern_clc.cpp @@ -128,9 +128,7 @@ static int clcHookSettingChanged(WPARAM hContact, LPARAM lParam) DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING*)lParam; if (hContact == NULL) { - if (!strcmp(cws->szModule, "CListGroups")) - pcli->pfnClcBroadcast(INTM_GROUPSCHANGED, hContact, lParam); - else if (!strcmp(cws->szSetting, "XStatusId") || !strcmp(cws->szSetting, "XStatusName")) + if (!strcmp(cws->szSetting, "XStatusId") || !strcmp(cws->szSetting, "XStatusName")) cliCluiProtocolStatusChanged(0, cws->szModule); else if (!strcmp(cws->szModule, "CList")) { if (!strcmp(cws->szSetting, "OnTop")) @@ -352,13 +350,13 @@ static LRESULT clcOnCommand(ClcData *dat, HWND hwnd, UINT, WPARAM wParam, LPARAM if (contact->type == CLCIT_GROUP) { SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) & ~CLS_HIDEEMPTYGROUPS); SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | CLS_USEGROUPS); - CallService(MS_CLIST_GROUPCREATE, contact->groupId, 0); + Clist_GroupCreate(contact->groupId, 0); } return 0; case POPUP_GROUPSHOWOFFLINE: if (contact->type == CLCIT_GROUP) { - CallService(MS_CLIST_GROUPSETFLAGS, contact->groupId, MAKELPARAM(CLCItems_IsShowOfflineGroup(contact->group) ? 0 : GROUPF_SHOWOFFLINE, GROUPF_SHOWOFFLINE)); + Clist_GroupSetFlags(contact->groupId, MAKELPARAM(CLCItems_IsShowOfflineGroup(contact->group) ? 0 : GROUPF_SHOWOFFLINE, GROUPF_SHOWOFFLINE)); pcli->pfnClcBroadcast(CLM_AUTOREBUILD, 0, 0); } return 0; @@ -1251,9 +1249,9 @@ static LRESULT clcOnLButtonUp(ClcData *dat, HWND hwnd, UINT msg, WPARAM wParam, pcli->pfnGetRowByIndex(dat, dat->iDragItem, &contact, &group); int i = pcli->pfnGetRowByIndex(dat, dat->iInsertionMark, &destcontact, &destgroup); if (i != -1 && group->groupId != destgroup->groupId) { - TCHAR *groupName = mir_tstrdup(pcli->pfnGetGroupName(contact->groupId, 0)); + TCHAR *groupName = mir_tstrdup(Clist_GroupGetName(contact->groupId, 0)); TCHAR *shortGroup = NULL; - TCHAR *sourceGrName = mir_tstrdup(pcli->pfnGetGroupName(destgroup->groupId, 0)); + TCHAR *sourceGrName = mir_tstrdup(Clist_GroupGetName(destgroup->groupId, 0)); if (groupName) { int len = (int)mir_tstrlen(groupName); do { len--; } while (len >= 0 && groupName[len] != '\\'); @@ -1272,10 +1270,11 @@ static LRESULT clcOnLButtonUp(ClcData *dat, HWND hwnd, UINT msg, WPARAM wParam, mir_free(groupName); mir_free(sourceGrName); } - int newIndex = CallService(MS_CLIST_GROUPMOVEBEFORE, contact->groupId, (destcontact && i != -1) ? destcontact->groupId : 0); + + int newIndex = Clist_GroupMoveBefore(contact->groupId, (destcontact && i != -1) ? destcontact->groupId : 0); newIndex = newIndex ? newIndex : contact->groupId; if (NeedRename) - pcli->pfnRenameGroup(newIndex, newName); + Clist_GroupRename(newIndex, newName); } break; diff --git a/plugins/Clist_modern/src/modern_clcitems.cpp b/plugins/Clist_modern/src/modern_clcitems.cpp index d393cd87dc..14f8632f26 100644 --- a/plugins/Clist_modern/src/modern_clcitems.cpp +++ b/plugins/Clist_modern/src/modern_clcitems.cpp @@ -262,7 +262,7 @@ bool CLCItems_IsShowOfflineGroup(ClcGroup *group) if (group->hideOffline) return false; DWORD groupFlags = 0; - pcli->pfnGetGroupName(group->groupId, &groupFlags); + Clist_GroupGetName(group->groupId, &groupFlags); return (groupFlags & GROUPF_SHOWOFFLINE) != 0; } @@ -324,7 +324,7 @@ void cliRebuildEntireList(HWND hwnd, ClcData *dat) for (int i = 1;; i++) { DWORD groupFlags; - TCHAR *szGroupName = pcli->pfnGetGroupName(i, &groupFlags); //UNICODE + TCHAR *szGroupName = Clist_GroupGetName(i, &groupFlags); //UNICODE if (szGroupName == NULL) break; cli_AddGroup(hwnd, dat, szGroupName, groupFlags, i, 0); diff --git a/plugins/Clist_modern/src/modern_viewmodebar.cpp b/plugins/Clist_modern/src/modern_viewmodebar.cpp index ecb2d33ab8..130129bb4b 100644 --- a/plugins/Clist_modern/src/modern_viewmodebar.cpp +++ b/plugins/Clist_modern/src/modern_viewmodebar.cpp @@ -246,7 +246,7 @@ static int FillDialog(HWND hwnd) SendMessage(hwndList, LVM_INSERTITEM, 0, (LPARAM)&item); TCHAR *szGroup; - for (int i = 1; (szGroup = pcli->pfnGetGroupName(i, NULL)) != NULL; i++) { + for (int i = 1; (szGroup = Clist_GroupGetName(i, NULL)) != NULL; i++) { item.pszText = szGroup; SendMessage(hwndList, LVM_INSERTITEM, 0, (LPARAM)&item); } diff --git a/plugins/Clist_nicer/src/clcitems.cpp b/plugins/Clist_nicer/src/clcitems.cpp index 0cd08daeba..6f4324c90e 100644 --- a/plugins/Clist_nicer/src/clcitems.cpp +++ b/plugins/Clist_nicer/src/clcitems.cpp @@ -166,7 +166,7 @@ void RebuildEntireList(HWND hwnd, struct ClcData *dat) { for (int i = 1;; i++) { DWORD groupFlags; - TCHAR *szGroupName = pcli->pfnGetGroupName(i, &groupFlags); + TCHAR *szGroupName = Clist_GroupGetName(i, &groupFlags); if (szGroupName == NULL) break; pcli->pfnAddGroup(hwnd, dat, szGroupName, groupFlags, i, 0); diff --git a/plugins/Clist_nicer/src/clui.cpp b/plugins/Clist_nicer/src/clui.cpp index c4cd90451a..6fcc9a0b85 100644 --- a/plugins/Clist_nicer/src/clui.cpp +++ b/plugins/Clist_nicer/src/clui.cpp @@ -1497,7 +1497,7 @@ buttons_done: case POPUP_NEWGROUP: SendMessage(pcli->hwndContactTree, CLM_SETHIDEEMPTYGROUPS, 0, 0); SendMessage(pcli->hwndContactTree, CLM_SETUSEGROUPS, 1, 0); - Clist_CreateGroup(NULL, NULL); + Clist_GroupCreate(NULL, NULL); break; case POPUP_HIDEOFFLINE: case IDC_TBHIDEOFFLINE: diff --git a/plugins/Clist_nicer/src/contact.cpp b/plugins/Clist_nicer/src/contact.cpp index 4f0b1046db..b5ff16c270 100644 --- a/plugins/Clist_nicer/src/contact.cpp +++ b/plugins/Clist_nicer/src/contact.cpp @@ -131,7 +131,7 @@ void LoadContactTree(void) CallService(MS_CLUI_LISTBEGINREBUILD, 0, 0); for (i = 1;; i++) { - if (pcli->pfnGetGroupName(i, NULL) == NULL) + if (Clist_GroupGetName(i, NULL) == NULL) break; CallService(MS_CLUI_GROUPADDED, i, 0); } diff --git a/plugins/Clist_nicer/src/viewmodes.cpp b/plugins/Clist_nicer/src/viewmodes.cpp index 5ac4b928c0..c68cc5b022 100644 --- a/plugins/Clist_nicer/src/viewmodes.cpp +++ b/plugins/Clist_nicer/src/viewmodes.cpp @@ -200,7 +200,7 @@ static int FillDialog(HWND hwnd) SendMessage(hwndList, LVM_INSERTITEM, 0, (LPARAM)&item); TCHAR *grpName; - for (i = 1; (grpName = pcli->pfnGetGroupName(i, NULL)) != NULL; i++) { + for (i = 1; (grpName = Clist_GroupGetName(i, NULL)) != NULL; i++) { item.pszText = grpName; SendMessage(hwndList, LVM_INSERTITEM, 0, (LPARAM)&item); } diff --git a/plugins/ContactsPlus/src/receive.cpp b/plugins/ContactsPlus/src/receive.cpp index 6606c2fdbb..a04891ad58 100644 --- a/plugins/ContactsPlus/src/receive.cpp +++ b/plugins/ContactsPlus/src/receive.cpp @@ -103,7 +103,7 @@ static void EnableGroupCombo(HWND hwndDlg) static void RebuildGroupCombo(HWND hwndDlg) { - int bHasGroups = pcli->pfnGetGroupName(0, NULL) != 0; + int bHasGroups = Clist_GroupGetName(0, NULL) != 0; HWND hGroupsCombo = GetDlgItem(hwndDlg, IDC_GROUPS); if (bHasGroups) { @@ -120,7 +120,7 @@ static void RebuildGroupCombo(HWND hwndDlg) SendMessage(hGroupsCombo, CB_RESETCONTENT, 0, 0); TCHAR *szGroup; - for (int i=1; (szGroup = pcli->pfnGetGroupName(i, NULL)) != NULL; i++) { + for (int i=1; (szGroup = Clist_GroupGetName(i, NULL)) != NULL; i++) { int nIndex = SendMessage(hGroupsCombo, CB_ADDSTRING, 0, (LPARAM)szGroup); SendMessage(hGroupsCombo, CB_SETITEMDATA, nIndex, i); } diff --git a/plugins/DbEditorPP/src/exportimport.cpp b/plugins/DbEditorPP/src/exportimport.cpp index 18790a530c..a9f5d33b7f 100644 --- a/plugins/DbEditorPP/src/exportimport.cpp +++ b/plugins/DbEditorPP/src/exportimport.cpp @@ -356,18 +356,13 @@ void importSettings(MCONTACT hContact, char *utf8) // get the type type = *(end + 1); if (mir_strcmp(module, "CList") == 0 && mir_strcmp(setting, "Group") == 0) { - ptrA GroupName(mir_utf8decodeA(end + 2)); + ptrT GroupName(mir_utf8decodeT(end + 2)); if (!GroupName) continue; - HANDLE GroupHandle = (HANDLE)CallService(MS_CLIST_GROUPEXISTS, 0, LPARAM(GroupName)); - if (GroupHandle == 0) { - GroupHandle = (HANDLE)CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)GroupName); - if (GroupHandle) { - CallService(MS_CLUI_GROUPADDED, (WPARAM)GroupHandle, 0); - CallService(MS_CLIST_GROUPSETEXPANDED, (WPARAM)GroupHandle, 1); - } - } + MGROUP GroupHandle = Clist_GroupCreate(0, GroupName); + CallService(MS_CLUI_GROUPADDED, GroupHandle, 0); + Clist_GroupSetExpanded(GroupHandle, true); } switch (type) { diff --git a/plugins/FavContacts/src/menu.cpp b/plugins/FavContacts/src/menu.cpp index ea979685fa..150145e693 100644 --- a/plugins/FavContacts/src/menu.cpp +++ b/plugins/FavContacts/src/menu.cpp @@ -35,7 +35,7 @@ static TCHAR* sttGetGroupName(int id) return TranslateT("Favorite Contacts"); } - return pcli->pfnGetGroupName(id - 1, NULL); + return Clist_GroupGetName(id - 1, NULL); } static BOOL sttMeasureItem_Group(LPMEASUREITEMSTRUCT lpmis, Options *options) diff --git a/plugins/Import/src/utils.cpp b/plugins/Import/src/utils.cpp index 25f856e5bb..05d4e1d0ad 100644 --- a/plugins/Import/src/utils.cpp +++ b/plugins/Import/src/utils.cpp @@ -42,7 +42,7 @@ int CreateGroup(const TCHAR *group, MCONTACT hContact) return 0; } - Clist_CreateGroup(NULL, group); + Clist_GroupCreate(NULL, group); if (hContact) db_set_ts(hContact, "CList", "Group", group); return 1; diff --git a/plugins/NewAwaySysMod/src/ContactList.cpp b/plugins/NewAwaySysMod/src/ContactList.cpp index 503eeb5a81..17f12f5f65 100644 --- a/plugins/NewAwaySysMod/src/ContactList.cpp +++ b/plugins/NewAwaySysMod/src/ContactList.cpp @@ -382,7 +382,7 @@ HTREEITEM CCList::AddGroup(TCString GroupName) if (GroupName == _T("")) return TVI_ROOT; - HANDLE hGroupId = Clist_GroupExists(GroupName); + MGROUP hGroupId = Clist_GroupExists(GroupName); if (hGroupId == NULL) return NULL; diff --git a/plugins/NewsAggregator/Src/ExportImport.cpp b/plugins/NewsAggregator/Src/ExportImport.cpp index 45aac14986..7f2f403941 100644 --- a/plugins/NewsAggregator/Src/ExportImport.cpp +++ b/plugins/NewsAggregator/Src/ExportImport.cpp @@ -139,12 +139,12 @@ INT_PTR CALLBACK DlgProcImportOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM parent = xmlGetParent(parent); } - TCHAR *utfgroup = NULL; + TCHAR *ptszGroup = NULL; if (group) { - utfgroup = mir_utf8decodeT(_T2A(group)); - if ( !utfgroup) { + ptszGroup = mir_utf8decodeT(_T2A(group)); + if ( !ptszGroup) { isGroupUTF = false; - utfgroup = group; + ptszGroup = group; } else isGroupUTF = 1; } @@ -158,26 +158,12 @@ INT_PTR CALLBACK DlgProcImportOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM db_set_dw(hContact, MODULE, "UpdateTime", DEFAULT_UPDATE_TIME); db_set_ts(hContact, MODULE, "MsgFormat", TAGSDEFAULT); db_set_w(hContact, MODULE, "Status", CallProtoService(MODULE, PS_GETSTATUS, 0, 0)); - if (utfgroup) { - db_set_ts(hContact, "CList", "Group", utfgroup); - int hGroup = 1; - char *group_name; - BYTE GroupExist = 0; - do { - group_name = (char *)CallService(MS_CLIST_GROUPGETNAME, (WPARAM)hGroup, 0); - if (group_name != NULL && !mir_strcmp(group_name, _T2A(utfgroup))) { - GroupExist = 1; - break; - } - hGroup++; - } - while (group_name); - - if(!GroupExist) - CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)utfgroup); + if (ptszGroup) { + db_set_ts(hContact, "CList", "Group", ptszGroup); + Clist_GroupCreate(0, ptszGroup); } if (isGroupUTF) - mir_free(utfgroup); + mir_free(ptszGroup); } if (isTextUTF) mir_free(text); diff --git a/plugins/Non-IM Contact/src/contactinfo.cpp b/plugins/Non-IM Contact/src/contactinfo.cpp index 095d04bc7d..7e4e27a535 100644 --- a/plugins/Non-IM Contact/src/contactinfo.cpp +++ b/plugins/Non-IM Contact/src/contactinfo.cpp @@ -132,7 +132,7 @@ INT_PTR CALLBACK DlgProcOtherStuff(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP /* group*/ TCHAR *szGroup; - for (int i = 1; (szGroup = pcli->pfnGetGroupName(i, NULL)) != NULL; i++) + for (int i = 1; (szGroup = Clist_GroupGetName(i, NULL)) != NULL; i++) SendDlgItemMessage(hwnd, IDC_GROUP, CB_INSERTSTRING, 0, LPARAM(szGroup)); if (!db_get_ts(hContact, "CList", "Group", &dbv)) { @@ -236,7 +236,7 @@ INT_PTR CALLBACK DlgProcOtherStuff(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP if (GetWindowTextLength(GetDlgItem(hwnd, IDC_GROUP))) { TCHAR text[512]; GetDlgItemText(hwnd, IDC_GROUP, text, _countof(text)); - Clist_CreateGroup(NULL, text); + Clist_GroupCreate(NULL, text); db_set_ts(hContact, "CList", "Group", text); } else db_unset(hContact, "CList", "Group"); diff --git a/plugins/Quotes/src/ImportExport.cpp b/plugins/Quotes/src/ImportExport.cpp index f32b4fcb61..29b5f0f8e6 100644 --- a/plugins/Quotes/src/ImportExport.cpp +++ b/plugins/Quotes/src/ImportExport.cpp @@ -349,7 +349,7 @@ bool handle_module(MCONTACT hContact, const IXMLNode::TXMLNodePtr& pXmlModule) } if ((true == bCListModule) && (0 == mir_tstrcmpi(sName.c_str(), _T("Group")))) - CallService(MS_CLIST_GROUPCREATE, NULL, reinterpret_cast(sValue.c_str())); + Clist_GroupCreate(NULL, sValue.c_str()); } } } diff --git a/plugins/SendScreenshotPlus/src/CSendDropbox.cpp b/plugins/SendScreenshotPlus/src/CSendDropbox.cpp index dc675a6a40..2bcebe5287 100644 --- a/plugins/SendScreenshotPlus/src/CSendDropbox.cpp +++ b/plugins/SendScreenshotPlus/src/CSendDropbox.cpp @@ -58,7 +58,6 @@ void CSendDropbox::SendThread() DropboxUploadInfo ui = { m_pszFile, _T("SendSS") }; - char **test = &m_URL; if (CallService(MS_DROPBOX_UPLOAD, (WPARAM)&m_URL, (LPARAM)&ui)) { Error(LPGENT("%s (%i):\nCould not add a share to the Dropbox plugin."), TranslateTS(m_pszSendTyp), 0); diff --git a/plugins/StopSpamMod/src/options.cpp b/plugins/StopSpamMod/src/options.cpp index c4c32f55dc..5878c9ce40 100755 --- a/plugins/StopSpamMod/src/options.cpp +++ b/plugins/StopSpamMod/src/options.cpp @@ -17,8 +17,6 @@ #include "stdafx.h" -int CreateCListGroup(TCHAR* szGroupName); - char *pluginDescription = LPGEN("No more spam! Robots can't go! Only human beings invited!\r\n\r\nThis plugin works pretty simple:\r\nWhile messages from users on your contact list go as there is no any anti-spam software, messages from unknown users are not delivered to you. But also they are not ignored, this plugin replies with a simple question, and if user gives the right answer, plugin adds him to your contact list so that he can contact you."); TCHAR const *defQuestion = TranslateT("Spammers made me to install small anti-spam system you are now speaking with.\r\nPlease reply \"nospam\" without quotes and spaces if you want to contact me."); @@ -280,7 +278,7 @@ INT_PTR CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar db_set_ws(NULL, pluginName, "SpammersGroup", NewGroupName.c_str()); gbSpammersGroup = DBGetContactSettingStringPAN(NULL, pluginName, "SpammersGroup", _T("Spammers")); if (!GroupExist && gbSpecialGroup) - CreateCListGroup((TCHAR*)gbSpammersGroup.c_str()); + Clist_GroupCreate(0, gbSpammersGroup.c_str()); } } db_set_b(NULL, pluginName, "SpecialGroup", gbSpecialGroup = BST_CHECKED == IsDlgButtonChecked(hwnd, ID_SPECIALGROUP)); @@ -304,7 +302,7 @@ INT_PTR CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar db_set_ws(NULL, pluginName, "AutoAuthGroup", NewAGroupName.c_str()); gbAutoAuthGroup = DBGetContactSettingStringPAN(NULL, pluginName, "AutoAuthGroup", _T("Not Spammers")); if (!GroupExist && gbAutoAddToServerList) - CreateCListGroup((TCHAR*)gbAutoAuthGroup.c_str()); + Clist_GroupCreate(0, gbAutoAuthGroup.c_str()); } } return TRUE; @@ -317,6 +315,8 @@ INT_PTR CALLBACK AdvancedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar HINSTANCE hInst; MIRANDA_HOOK_EVENT(ME_OPT_INITIALISE, w, l) { + UNREFERENCED_PARAMETER(l); + OPTIONSDIALOGPAGE odp = { 0 }; odp.ptszGroup = LPGENT("Message sessions"); odp.ptszTitle = LPGENT("StopSpam"); diff --git a/plugins/StopSpamMod/src/utilities.cpp b/plugins/StopSpamMod/src/utilities.cpp index 2cad3a82a6..cc13f07cbd 100755 --- a/plugins/StopSpamMod/src/utilities.cpp +++ b/plugins/StopSpamMod/src/utilities.cpp @@ -64,16 +64,6 @@ bool ProtoInList(std::string proto) return std::string::npos != GetProtoList().find(proto + "\r\n"); } -int CreateCListGroup(TCHAR* szGroupName) -{ - int hGroup = CallService(MS_CLIST_GROUPCREATE, 0, 0); - - TCHAR* usTmp = szGroupName; - pcli->pfnRenameGroup(hGroup, usTmp); - - return hGroup; -} - void DeleteCListGroupsByName(TCHAR* szGroupName) { BYTE ConfirmDelete = db_get_b(NULL, "CList", "ConfirmDelete", SETTING_CONFIRMDELETE_DEFAULT); @@ -81,9 +71,9 @@ void DeleteCListGroupsByName(TCHAR* szGroupName) db_set_b(NULL, "CList", "ConfirmDelete", 0); TCHAR *szGroup; - for (int i = 1; (szGroup = pcli->pfnGetGroupName(i, NULL)) != NULL; i++) + for (int i = 1; (szGroup = Clist_GroupGetName(i, NULL)) != NULL; i++) if (!mir_wstrcmp(szGroupName, szGroup)) - CallService(MS_CLIST_GROUPDELETE, i, 0); + Clist_GroupDelete(i); if (ConfirmDelete) db_set_b(NULL, "CList", "ConfirmDelete", ConfirmDelete); diff --git a/plugins/StopSpamPlus/src/services.cpp b/plugins/StopSpamPlus/src/services.cpp index 2872181726..0310bb6c13 100644 --- a/plugins/StopSpamPlus/src/services.cpp +++ b/plugins/StopSpamPlus/src/services.cpp @@ -47,15 +47,15 @@ INT_PTR RemoveTempContacts(WPARAM, LPARAM lParam) } int hGroup = 1; - char *group_name; + TCHAR *group_name; do { - group_name = (char *)CallService(MS_CLIST_GROUPGETNAME, (WPARAM)hGroup, 0); - if (group_name != NULL && strstr(group_name, "Not In List")) { + group_name = Clist_GroupGetName(hGroup, 0); + if (group_name != NULL && _tcsstr(group_name, TranslateT("Not In List"))) { BYTE ConfirmDelete = db_get_b(NULL, "CList", "ConfirmDelete", SETTING_CONFIRMDELETE_DEFAULT); if (ConfirmDelete) db_set_b(NULL, "CList", "ConfirmDelete", 0); - CallService(MS_CLIST_GROUPDELETE, (WPARAM)hGroup, 0); + Clist_GroupDelete(hGroup); if (ConfirmDelete) db_set_b(NULL, "CList", "ConfirmDelete", ConfirmDelete); break; diff --git a/plugins/StopSpamPlus/src/stopspam.cpp b/plugins/StopSpamPlus/src/stopspam.cpp index c7ccac01ea..13fd6dbd21 100644 --- a/plugins/StopSpamPlus/src/stopspam.cpp +++ b/plugins/StopSpamPlus/src/stopspam.cpp @@ -21,7 +21,7 @@ PLUGININFOEX pluginInfoEx = { { 0x553811ee, 0xdeb6, 0x48b8, { 0x89, 0x2, 0xa8, 0xa0, 0xc, 0x1f, 0xd6, 0x79 } } }; - +CLIST_INTERFACE *pcli; HINSTANCE hInst; extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) @@ -38,6 +38,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) extern "C" int __declspec(dllexport) Load(void) { mir_getLP(&pluginInfoEx); + mir_getCLI(); plSets = new Settings; diff --git a/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp b/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp index 456c704ad8..6963b75b55 100644 --- a/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp +++ b/plugins/UserInfoEx/src/ex_import/classExImContactBase.cpp @@ -256,16 +256,9 @@ MCONTACT CExImContactBase::toDB() // add group if (_pszGroup) { - ptrT ptszGroup( mir_utf8decodeT(_pszGroup)); + ptrT ptszGroup(mir_utf8decodeT(_pszGroup)); db_set_ts(_hContact, MOD_CLIST, "Group", ptszGroup); - if ( Clist_GroupExists(ptszGroup) == NULL) { - HANDLE hGroup = Clist_CreateGroup(NULL, NULL); - if (hGroup) { - // renaming twice is stupid but the only way to avoid error dialog telling shit like - // a group with that name does exist - CallService(MS_CLIST_GROUPRENAME, (WPARAM)hGroup, (LPARAM)ptszGroup); - } - } + Clist_GroupCreate(NULL, ptszGroup); } } return _hContact; diff --git a/plugins/Utils.pas/mirutils.pas b/plugins/Utils.pas/mirutils.pas index 67f085fe0a..dee3bbdc87 100644 --- a/plugins/Utils.pas/mirutils.pas +++ b/plugins/Utils.pas/mirutils.pas @@ -341,7 +341,7 @@ begin exit; end; - CallService(MS_CLIST_GROUPCREATE,0,lparam(name)); + Clist_GroupCreate(0,name); if hContact<>0 then DBWriteUnicode(hContact,strCList,clGroup,name); diff --git a/protocols/AimOscar/src/utility.cpp b/protocols/AimOscar/src/utility.cpp index 0c2b28e1a1..c535797fd4 100755 --- a/protocols/AimOscar/src/utility.cpp +++ b/protocols/AimOscar/src/utility.cpp @@ -364,7 +364,7 @@ void create_group(const char *group) if (mir_strcmp(group, AIM_DEFAULT_GROUP) == 0) return; TCHAR* szGroupName = mir_utf8decodeT(group); - Clist_CreateGroup(0, szGroupName); + Clist_GroupCreate(0, szGroupName); mir_free(szGroupName); } diff --git a/protocols/FacebookRM/src/connection.cpp b/protocols/FacebookRM/src/connection.cpp index 1924d94923..4a34435549 100644 --- a/protocols/FacebookRM/src/connection.cpp +++ b/protocols/FacebookRM/src/connection.cpp @@ -203,7 +203,7 @@ bool FacebookProto::NegotiateConnection() // Create default group for new contacts if (m_tszDefaultGroup) - Clist_CreateGroup(0, m_tszDefaultGroup); + Clist_GroupCreate(0, m_tszDefaultGroup); return facy.login(username, password); } diff --git a/protocols/FacebookRM/src/dialogs.cpp b/protocols/FacebookRM/src/dialogs.cpp index 9eb3a946a0..2b8ec51728 100644 --- a/protocols/FacebookRM/src/dialogs.cpp +++ b/protocols/FacebookRM/src/dialogs.cpp @@ -407,7 +407,7 @@ INT_PTR CALLBACK FBOptionsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp { proto->m_tszDefaultGroup = mir_tstrdup(tstr); proto->setTString(FACEBOOK_KEY_DEF_GROUP, tstr); - Clist_CreateGroup(0, tstr); + Clist_GroupCreate(0, tstr); } else { proto->delSetting(FACEBOOK_KEY_DEF_GROUP); diff --git a/protocols/Gadu-Gadu/src/import.cpp b/protocols/Gadu-Gadu/src/import.cpp index 0eda9f87f7..9db2f2e3a9 100644 --- a/protocols/Gadu-Gadu/src/import.cpp +++ b/protocols/Gadu-Gadu/src/import.cpp @@ -217,7 +217,7 @@ void GGPROTO::parsecontacts(char *contacts) // Write group if (hContact && strGroup) { ptrT tszGrpName( mir_a2t(strGroup)); - Clist_CreateGroup(0, tszGrpName); + Clist_GroupCreate(0, tszGrpName); db_set_ts(hContact, "CList", "Group", tszGrpName); } diff --git a/protocols/IcqOscarJ/src/icq_servlist.cpp b/protocols/IcqOscarJ/src/icq_servlist.cpp index 5229455a4c..1c1ea58350 100644 --- a/protocols/IcqOscarJ/src/icq_servlist.cpp +++ b/protocols/IcqOscarJ/src/icq_servlist.cpp @@ -1380,7 +1380,7 @@ int CIcqProto::getCListGroupExists(const char *szGroup) if (utf8_to_tchar_static(szGroup, tszGroup, size)) for (int i = 1; TRUE; i++) { - TCHAR *tszGroupName = (TCHAR*)pcli->pfnGetGroupName(i, NULL); + TCHAR *tszGroupName = (TCHAR*)Clist_GroupGetName(i, NULL); if (!tszGroupName) break; @@ -1395,12 +1395,8 @@ int CIcqProto::getCListGroupExists(const char *szGroup) int CIcqProto::moveContactToCListGroup(MCONTACT hContact, const char *szGroup) { - HANDLE hGroup = Clist_CreateGroup(0, ptrT(mir_utf8decodeT(szGroup))); - - if (ServiceExists(MS_CLIST_CONTACTCHANGEGROUP)) - return CallService(MS_CLIST_CONTACTCHANGEGROUP, hContact, (LPARAM)hGroup); - else /// TODO: is this neccessary ? - return db_set_utf(hContact, "CList", "Group", szGroup); + MGROUP hGroup = Clist_GroupCreate(0, ptrT(mir_utf8decodeT(szGroup))); + return CallService(MS_CLIST_CONTACTCHANGEGROUP, hContact, hGroup); } diff --git a/protocols/JabberG/src/jabber_iq_handlers.cpp b/protocols/JabberG/src/jabber_iq_handlers.cpp index 9d0bfde672..13e3cc5cca 100644 --- a/protocols/JabberG/src/jabber_iq_handlers.cpp +++ b/protocols/JabberG/src/jabber_iq_handlers.cpp @@ -278,7 +278,7 @@ BOOL CJabberProto::OnRosterPushRequest(HXML, CJabberIqInfo *pInfo) if (!m_options.IgnoreRosterGroups) { if (item->group != NULL) { - Clist_CreateGroup(0, item->group); + Clist_GroupCreate(0, item->group); db_set_ts(hContact, "CList", "Group", item->group); } else db_unset(hContact, "CList", "Group"); diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index 8b1aba4adb..a227f52819 100644 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -451,7 +451,7 @@ void CJabberProto::OnIqResultGetRoster(HXML iqNode, CJabberIqInfo *pInfo) if (!m_options.IgnoreRosterGroups) { if (item->group != NULL) { - Clist_CreateGroup(0, item->group); + Clist_GroupCreate(0, item->group); // Don't set group again if already correct, or Miranda may show wrong group count in some case ptrT tszGroup(db_get_tsa(hContact, "CList", "Group")); diff --git a/protocols/JabberG/src/jabber_privacy.cpp b/protocols/JabberG/src/jabber_privacy.cpp index 4b2c0c1d80..0f56b27c7a 100644 --- a/protocols/JabberG/src/jabber_privacy.cpp +++ b/protocols/JabberG/src/jabber_privacy.cpp @@ -453,7 +453,7 @@ public: SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_RESETCONTENT, 0, 0); { TCHAR *grpName; - for (int i=1; (grpName = pcli->pfnGetGroupName(i, NULL)) != NULL; i++) + for (int i=1; (grpName = Clist_GroupGetName(i, NULL)) != NULL; i++) SendDlgItemMessage(m_hwnd, IDC_COMBO_VALUES, CB_ADDSTRING, 0, (LPARAM)grpName); } @@ -1355,8 +1355,8 @@ void CJabberDlgPrivacyLists::CListApplyList(HWND hwndList, CPrivacyList *pList) CListResetIcons(hwndList, clc_info.hItemSubTo, bHideIcons); // group handles start with 1 (0 is "root") - for (int iGroup = 1; pcli->pfnGetGroupName(iGroup, NULL) != NULL; iGroup++) { - HANDLE hItem = m_clcClist.FindGroup((HANDLE)iGroup); + for (MGROUP iGroup = 1; Clist_GroupGetName(iGroup, NULL) != NULL; iGroup++) { + HANDLE hItem = m_clcClist.FindGroup(iGroup); if (hItem) CListResetIcons(hwndList, hItem, bHideIcons); } @@ -1475,8 +1475,8 @@ void CJabberDlgPrivacyLists::CListBuildList(HWND hwndList, CPrivacyList *pList) // group handles start with 1 (0 is "root") TCHAR *grpName; - for (int iGroup = 1; (grpName = pcli->pfnGetGroupName(iGroup, NULL)) != NULL; iGroup++) { - hItem = m_clcClist.FindGroup((HANDLE)iGroup); + for (MGROUP iGroup = 1; (grpName = Clist_GroupGetName(iGroup, NULL)) != NULL; iGroup++) { + hItem = m_clcClist.FindGroup(iGroup); if (dwPackets = CListGetPackets(hwndList, hItem, true)) pList->AddRule(Group, grpName, TRUE, dwOrder++, dwPackets); if (dwPackets = CListGetPackets(hwndList, hItem, false)) diff --git a/protocols/MRA/src/Mra_proto.cpp b/protocols/MRA/src/Mra_proto.cpp index 83c0d89f49..7026623302 100644 --- a/protocols/MRA/src/Mra_proto.cpp +++ b/protocols/MRA/src/Mra_proto.cpp @@ -1089,7 +1089,7 @@ bool CMraProto::CmdClist2(BinBuffer &buf) if (dwControlParam > 1) { // все параметры правильно инициализированны! if (!(dwGroupFlags & CONTACT_FLAG_REMOVED)) { m_groups.insert(new MraGroupItem(dwID, dwGroupFlags, wszGroupName)); - Clist_CreateGroup(0, wszGroupName); + Clist_GroupCreate(0, wszGroupName); } debugLogW(L"'%s', flags: %lu (", wszGroupName, dwGroupFlags); diff --git a/protocols/MSN/src/msn_srv.cpp b/protocols/MSN/src/msn_srv.cpp index 73f69e8e39..33f1a10da5 100644 --- a/protocols/MSN/src/msn_srv.cpp +++ b/protocols/MSN/src/msn_srv.cpp @@ -38,7 +38,7 @@ void CMsnProto::MSN_AddGroup(const char* grpName, const char *grpId, bool init) m_arGroups.insert(p); if (init) - Clist_CreateGroup(0, ptrT(mir_utf8decodeT(grpName))); + Clist_GroupCreate(0, ptrT(mir_utf8decodeT(grpName))); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/Sametime/src/userlist.cpp b/protocols/Sametime/src/userlist.cpp index 2b85a75c0e..d9ea2ea318 100644 --- a/protocols/Sametime/src/userlist.cpp +++ b/protocols/Sametime/src/userlist.cpp @@ -48,15 +48,9 @@ void CSametimeProto::AddGroup(const char* name, bool expanded) if (name && mir_strcmp(name, Translate("None")) == 0) return; - ptrT ptszGroup(mir_utf8decodeT(name)); - HANDLE hGroup = Clist_GroupExists(ptszGroup); - if (hGroup == NULL) { - hGroup = Clist_CreateGroup(NULL, ptszGroup); - if (hGroup) { - CallService(MS_CLUI_GROUPADDED, (WPARAM)hGroup, 0); - CallService(MS_CLIST_GROUPSETEXPANDED, (WPARAM)hGroup, expanded ? 1 : 0); - } - } + MGROUP hGroup = Clist_GroupCreate(NULL, ptrT(mir_utf8decodeT(name))); + CallService(MS_CLUI_GROUPADDED, hGroup, 0); + Clist_GroupSetExpanded(hGroup, expanded); } MCONTACT CSametimeProto::AddContact(mwSametimeUser* user, bool temporary) @@ -245,10 +239,10 @@ void CSametimeProto::ExportContactsToList(mwSametimeList* user_list) //group_open = (db_get_b(0, szProtoGroups, buff, 0) == 1); ptrT ptszGroup(mir_utf8decodeT(group_alias)); - HANDLE hGroup = Clist_GroupExists(ptszGroup); + MGROUP hGroup = Clist_GroupExists(ptszGroup); if (hGroup) { - int expanded; - CallService(MS_CLIST_GROUPGETNAME, (WPARAM)hGroup, (LPARAM)&expanded); + DWORD expanded; + Clist_GroupGetName(hGroup, &expanded); group_open = (expanded != 0); } else { diff --git a/protocols/SkypeWeb/src/skype_options.cpp b/protocols/SkypeWeb/src/skype_options.cpp index fe161f1d5d..fc6136012c 100644 --- a/protocols/SkypeWeb/src/skype_options.cpp +++ b/protocols/SkypeWeb/src/skype_options.cpp @@ -63,7 +63,7 @@ void CSkypeOptionsMain::OnApply() m_proto->setString("Password", szNewPassword); ptrT group(m_group.GetText()); if (mir_tstrlen(group) > 0 && !Clist_GroupExists(group)) - Clist_CreateGroup(0, group); + Clist_GroupCreate(0, group); } ///////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/Steam/src/steam_options.cpp b/protocols/Steam/src/steam_options.cpp index 7dc841451a..666e206978 100644 --- a/protocols/Steam/src/steam_options.cpp +++ b/protocols/Steam/src/steam_options.cpp @@ -27,7 +27,7 @@ void CSteamOptionsMain::OnApply() { TCHAR *group = m_group.GetText(); if (mir_tstrlen(group) > 0 && !Clist_GroupExists(group)) - Clist_CreateGroup(0, group); + Clist_GroupCreate(0, group); if (m_proto->IsOnline()) { diff --git a/protocols/Tlen/src/tlen_iqid.cpp b/protocols/Tlen/src/tlen_iqid.cpp index aa27bb4e04..810c3b9f66 100644 --- a/protocols/Tlen/src/tlen_iqid.cpp +++ b/protocols/Tlen/src/tlen_iqid.cpp @@ -112,7 +112,7 @@ void TlenResultSetRoster(TlenProtocol *proto, XmlNode *queryNode) { if (item->group) mir_free(item->group); if ((groupNode = TlenXmlGetChild(itemNode, "group")) != NULL && groupNode->text != NULL) { item->group = TlenGroupDecode(groupNode->text); - Clist_CreateGroup(0, _A2T(item->group)); + Clist_GroupCreate(0, _A2T(item->group)); // Don't set group again if already correct, or Miranda may show wrong group count in some case if (!db_get(hContact, "CList", "Group", &dbv)) { if (mir_strcmp(dbv.pszVal, item->group)) @@ -184,7 +184,7 @@ void TlenIqResultRoster(TlenProtocol *proto, XmlNode *iqNode) if (item->group) mir_free(item->group); if ((groupNode = TlenXmlGetChild(itemNode, "group")) != NULL && groupNode->text != NULL) { item->group = TlenGroupDecode(groupNode->text); - Clist_CreateGroup(0, _A2T(item->group)); + Clist_GroupCreate(0, _A2T(item->group)); // Don't set group again if already correct, or Miranda may show wrong group count in some case if (!db_get(hContact, "CList", "Group", &dbv)) { if (mir_strcmp(dbv.pszVal, item->group)) diff --git a/protocols/Tlen/src/tlen_thread.cpp b/protocols/Tlen/src/tlen_thread.cpp index 99a27ba533..77dac550d6 100644 --- a/protocols/Tlen/src/tlen_thread.cpp +++ b/protocols/Tlen/src/tlen_thread.cpp @@ -807,7 +807,7 @@ static void TlenProcessIq(XmlNode *node, ThreadData *info) if (item->group) mir_free(item->group); if ((groupNode=TlenXmlGetChild(itemNode, "group")) != NULL && groupNode->text != NULL) { item->group = TlenGroupDecode(groupNode->text); - Clist_CreateGroup(0, _A2T(item->group)); + Clist_GroupCreate(0, _A2T(item->group)); db_set_s(hContact, "CList", "Group", item->group); } else { diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index a5f63da6ee..f28009ade5 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -80,7 +80,7 @@ void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*) { ptrT group(m_group.GetText()); if (mir_tstrlen(group) > 0 && Clist_GroupExists(group)) - Clist_CreateGroup(0, group); + Clist_GroupCreate(0, group); m_proto->UninitToxCore(&toxThread); @@ -158,7 +158,7 @@ void CToxOptionsMain::OnApply() { ptrT group(m_group.GetText()); if (mir_tstrlen(group) > 0 && Clist_GroupExists(group)) - Clist_CreateGroup(0, group); + Clist_GroupCreate(0, group); if (m_proto->IsOnline()) { diff --git a/protocols/Twitter/src/connection.cpp b/protocols/Twitter/src/connection.cpp index 1fda6d3cb1..80bdf2b14d 100644 --- a/protocols/Twitter/src/connection.cpp +++ b/protocols/Twitter/src/connection.cpp @@ -176,7 +176,7 @@ bool TwitterProto::NegotiateConnection() } if (!getTString(TWITTER_KEY_GROUP, &dbv)) { - CallService(MS_CLIST_GROUPCREATE, 0, (LPARAM)dbv.ptszVal); + Clist_GroupCreate(0, dbv.ptszVal); db_free(&dbv); } @@ -193,7 +193,7 @@ bool TwitterProto::NegotiateConnection() realAccessTok = true; //debugLogW("**NegotiateConnection - we have an oauthAccessToken already in the db - %s", oauthAccessToken); } - else { debugLogA("**NegotiateConnection - oauthAccesToken too small? this is.. weird."); } + else debugLogA("**NegotiateConnection - oauthAccesToken too small? this is.. weird."); } dbTOKSec = getWString(TWITTER_KEY_OAUTH_ACCESS_TOK_SECRET, &dbv); diff --git a/protocols/VKontakte/src/vk_options.cpp b/protocols/VKontakte/src/vk_options.cpp index dcf0bfb609..feb6800aa5 100644 --- a/protocols/VKontakte/src/vk_options.cpp +++ b/protocols/VKontakte/src/vk_options.cpp @@ -196,7 +196,7 @@ void CVkOptionAccountForm::OnApply() ptrT ptszGroupName(m_edtGroupName.GetText()); if (mir_tstrcmp(m_ptszOldGroup, ptszGroupName)) { - Clist_CreateGroup(NULL, ptszGroupName); + Clist_GroupCreate(NULL, ptszGroupName); m_ptszOldGroup = ptszGroupName; } diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 5f015cde7b..7012ebde4a 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -70,7 +70,7 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) : nlu.ptszDescriptiveName = descr; m_hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); - Clist_CreateGroup(NULL, m_vkOptions.ptszDefaultGroup); + Clist_GroupCreate(NULL, m_vkOptions.ptszDefaultGroup); CMStringA szListeningTo(FORMAT, "%sEnabled", m_szModuleName); db_set_b(NULL, "ListeningTo", szListeningTo, m_vkOptions.iMusicSendMetod == 0 ? 0 : 1); diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp index 3d63355f19..c4fa89948d 100644 --- a/protocols/WhatsApp/src/proto.cpp +++ b/protocols/WhatsApp/src/proto.cpp @@ -55,7 +55,7 @@ WhatsAppProto::WhatsAppProto(const char *proto_name, const TCHAR *username) if (m_tszDefaultGroup == NULL) m_tszDefaultGroup = mir_tstrdup(_T("WhatsApp")); - Clist_CreateGroup(0, m_tszDefaultGroup); + Clist_GroupCreate(0, m_tszDefaultGroup); SetAllContactStatuses(ID_STATUS_OFFLINE, true); } diff --git a/src/mir_app/src/addcontact.cpp b/src/mir_app/src/addcontact.cpp index eeaf7620ef..24aff743ff 100644 --- a/src/mir_app/src/addcontact.cpp +++ b/src/mir_app/src/addcontact.cpp @@ -24,15 +24,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -static TCHAR* sttDecodeString(DWORD dwFlags, MAllStrings &src) -{ - if (dwFlags & PSR_UNICODE) - return mir_u2t(src.w); - - if (dwFlags & PSR_UTF8) - return mir_utf8decodeT(src.a); - - return mir_a2t(src.a); +static TCHAR* sttDecodeString(DWORD dwFlags, MAllStrings &src) +{ + if (dwFlags & PSR_UNICODE) + return mir_u2t(src.w); + + if (dwFlags & PSR_UTF8) + return mir_utf8decodeT(src.a); + + return mir_a2t(src.a); } class CAddContactDlg : public CDlgBase @@ -122,7 +122,7 @@ public: int groupSel = 0; ptrT tszGroup(db_get_tsa(hContact, "CList", "Group")); TCHAR *grpName; - for (int groupId = 1; (grpName = cli.pfnGetGroupName(groupId, NULL)) != NULL; groupId++) { + for (int groupId = 1; (grpName = Clist_GroupGetName(groupId, NULL)) != NULL; groupId++) { int id = m_group.AddString(grpName, groupId); if (!mir_tstrcmpi(tszGroup, grpName)) groupSel = id; diff --git a/src/mir_app/src/chat_clist.cpp b/src/mir_app/src/chat_clist.cpp index 62c313c8b2..767368d911 100644 --- a/src/mir_app/src/chat_clist.cpp +++ b/src/mir_app/src/chat_clist.cpp @@ -32,12 +32,12 @@ MCONTACT AddRoom(const char *pszModule, const TCHAR *pszRoom, const TCHAR *pszDi mir_tstrcpy(pszGroup, _T("Chat rooms")); if (pszGroup[0]) { - HANDLE hGroup = Clist_GroupExists(pszGroup); + MGROUP hGroup = Clist_GroupExists(pszGroup); if (hGroup == 0) { - hGroup = Clist_CreateGroup(0, pszGroup); + hGroup = Clist_GroupCreate(0, pszGroup); if (hGroup) { CallService(MS_CLUI_GROUPADDED, (WPARAM)hGroup, 0); - CallService(MS_CLIST_GROUPSETEXPANDED, (WPARAM)hGroup, 1); + Clist_GroupSetExpanded(hGroup, 1); } } } diff --git a/src/mir_app/src/clc.cpp b/src/mir_app/src/clc.cpp index 0a0d5edd0b..8ea5f48ef4 100644 --- a/src/mir_app/src/clc.cpp +++ b/src/mir_app/src/clc.cpp @@ -65,11 +65,6 @@ void fnClcOptionsChanged(void) static int ClcSettingChanged(WPARAM hContact, LPARAM lParam) { DBCONTACTWRITESETTING *cws = (DBCONTACTWRITESETTING *) lParam; - if (hContact == NULL) { - if (!strcmp(cws->szModule, "CListGroups")) - cli.pfnClcBroadcast(INTM_GROUPSCHANGED, hContact, lParam); - return 0; - } if (!strcmp(cws->szModule, "CList")) { if (!strcmp(cws->szSetting, "MyHandle")) { @@ -387,55 +382,6 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam case WM_GETFONT: return (LRESULT)dat->fontInfo[FONTID_CONTACTS].hFont; - case INTM_GROUPSCHANGED: - { - DBCONTACTWRITESETTING *dbcws = (DBCONTACTWRITESETTING *)lParam; - if (dbcws->value.type == DBVT_ASCIIZ || dbcws->value.type == DBVT_UTF8) { - int groupId = atoi(dbcws->szSetting) + 1; - TCHAR szFullName[512]; - int i, eq; - //check name of group and ignore message if just being expanded/collapsed - if (cli.pfnFindItem(hwnd, dat, groupId | HCONTACT_ISGROUP, &contact, &group, NULL)) { - mir_tstrcpy(szFullName, contact->szText); - while (group->parent) { - for (i = 0; i < group->parent->cl.count; i++) - if (group->parent->cl.items[i]->group == group) - break; - if (i == group->parent->cl.count) { - szFullName[0] = '\0'; - break; - } - group = group->parent; - size_t nameLen = mir_tstrlen(group->cl.items[i]->szText); - if (mir_tstrlen(szFullName) + 1 + nameLen > _countof(szFullName)) { - szFullName[0] = '\0'; - break; - } - memmove(szFullName + 1 + nameLen, szFullName, sizeof(TCHAR)*(mir_tstrlen(szFullName) + 1)); - memcpy(szFullName, group->cl.items[i]->szText, sizeof(TCHAR)*nameLen); - szFullName[nameLen] = '\\'; - } - - if (dbcws->value.type == DBVT_ASCIIZ) { - WCHAR* wszGrpName = mir_a2u(dbcws->value.pszVal + 1); - eq = !mir_tstrcmp(szFullName, wszGrpName); - mir_free(wszGrpName); - } - else { - char* szGrpName = NEWSTR_ALLOCA(dbcws->value.pszVal + 1); - WCHAR* wszGrpName; - Utf8Decode(szGrpName, &wszGrpName); - eq = !mir_tstrcmp(szFullName, wszGrpName); - mir_free(wszGrpName); - } - if (eq && (contact->group->hideOffline != 0) == ((dbcws->value.pszVal[0] & GROUPF_HIDEOFFLINE) != 0)) - break; //only expanded has changed: no action reqd - } - } - cli.pfnSaveStateAndRebuildList(hwnd, dat); - } - break; - case INTM_NAMEORDERCHANGED: cli.pfnInitAutoRebuild(hwnd); break; @@ -1130,8 +1076,8 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam CallService(MS_CLIST_CONTACTCHANGEGROUP, (WPARAM)contacto->hContact, contactn->groupId); else if (contacto->type == CLCIT_GROUP) { //dropee is a group TCHAR szNewName[120]; - mir_sntprintf(szNewName, _T("%s\\%s"), cli.pfnGetGroupName(contactn->groupId, NULL), contacto->szText); - cli.pfnRenameGroup(contacto->groupId, szNewName); + mir_sntprintf(szNewName, _T("%s\\%s"), Clist_GroupGetName(contactn->groupId, NULL), contacto->szText); + Clist_GroupRename(contacto->groupId, szNewName); } } break; @@ -1142,11 +1088,11 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam ClcContact *destcontact; ClcGroup *destgroup; if (cli.pfnGetRowByIndex(dat, dat->iInsertionMark, &destcontact, &destgroup) == -1 || destgroup != contact->group->parent) - CallService(MS_CLIST_GROUPMOVEBEFORE, contact->groupId, 0); + Clist_GroupMoveBefore(contact->groupId, 0); else { if (destcontact->type == CLCIT_GROUP) destgroup = destcontact->group; - CallService(MS_CLIST_GROUPMOVEBEFORE, contact->groupId, destgroup->groupId); + Clist_GroupMoveBefore(contact->groupId, destgroup->groupId); } } break; @@ -1170,7 +1116,7 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam if (contact->type == CLCIT_GROUP) { //dropee is a group TCHAR szNewName[120]; mir_tstrncpy(szNewName, contact->szText, _countof(szNewName)); - cli.pfnRenameGroup(contact->groupId, szNewName); + Clist_GroupRename(contact->groupId, szNewName); } else if (contact->type == CLCIT_CONTACT) //dropee is a contact CallService(MS_CLIST_CONTACTCHANGEGROUP, (WPARAM)contact->hContact, 0); @@ -1270,18 +1216,18 @@ LRESULT CALLBACK fnContactListControlWndProc(HWND hwnd, UINT uMsg, WPARAM wParam if (contact->type != CLCIT_GROUP) break; SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) & ~CLS_HIDEEMPTYGROUPS); - CallService(MS_CLIST_GROUPCREATE, contact->groupId, 0); + Clist_GroupCreate(contact->groupId, 0); break; case POPUP_RENAMEGROUP: cli.pfnBeginRenameSelection(hwnd, dat); break; case POPUP_DELETEGROUP: if (contact->type == CLCIT_GROUP) - CallService(MS_CLIST_GROUPDELETE, contact->groupId, 0); + Clist_GroupDelete(contact->groupId); break; case POPUP_GROUPHIDEOFFLINE: if (contact->type == CLCIT_GROUP) - CallService(MS_CLIST_GROUPSETFLAGS, contact->groupId, MAKELPARAM(contact->group->hideOffline ? 0 : GROUPF_HIDEOFFLINE, GROUPF_HIDEOFFLINE)); + Clist_GroupSetFlags(contact->groupId, MAKELPARAM(contact->group->hideOffline ? 0 : GROUPF_HIDEOFFLINE, GROUPF_HIDEOFFLINE)); break; } diff --git a/src/mir_app/src/clc.h b/src/mir_app/src/clc.h index 19f64a5762..bebef650b7 100644 --- a/src/mir_app/src/clc.h +++ b/src/mir_app/src/clc.h @@ -191,8 +191,8 @@ int fnSetHideOffline(WPARAM wParam, LPARAM lParam); int fnDocking_ProcessWindowMessage(WPARAM wParam, LPARAM lParam); /* group.c */ -TCHAR* fnGetGroupName(int idx, DWORD* pdwFlags); -int fnRenameGroup(int groupID, TCHAR* newName); +TCHAR* fnGetGroupName(MGROUP idx, DWORD *pdwFlags); +int fnRenameGroup(MGROUP groupID, const TCHAR *newName); /* keyboard.c */ int fnHotKeysRegister(HWND hwnd); diff --git a/src/mir_app/src/clcitems.cpp b/src/mir_app/src/clcitems.cpp index c1de101a5f..7933b9ef52 100644 --- a/src/mir_app/src/clcitems.cpp +++ b/src/mir_app/src/clcitems.cpp @@ -243,7 +243,7 @@ void fnAddContactToTree(HWND hwnd, struct ClcData *dat, MCONTACT hContact, int u } if (checkHideOffline && cli.pfnIsHiddenMode(dat, status)) { for (i = 1;; i++) { - szGroupName = cli.pfnGetGroupName(i, &groupFlags); + szGroupName = Clist_GroupGetName(i, &groupFlags); if (szGroupName == NULL) { mir_free(dbv.ptszVal); return; @@ -257,7 +257,7 @@ void fnAddContactToTree(HWND hwnd, struct ClcData *dat, MCONTACT hContact, int u } } for (i = 1;; i++) { - szGroupName = cli.pfnGetGroupName(i, &groupFlags); + szGroupName = Clist_GroupGetName(i, &groupFlags); if (szGroupName == NULL) { mir_free(dbv.ptszVal); return; @@ -359,7 +359,7 @@ void fnRebuildEntireList(HWND hwnd, struct ClcData *dat) for (int i = 1;; i++) { DWORD groupFlags; - TCHAR *szGroupName = cli.pfnGetGroupName(i, &groupFlags); + TCHAR *szGroupName = Clist_GroupGetName(i, &groupFlags); if (szGroupName == NULL) break; cli.pfnAddGroup(hwnd, dat, szGroupName, groupFlags, i, 0); diff --git a/src/mir_app/src/clcmsgs.cpp b/src/mir_app/src/clcmsgs.cpp index d448ce91e8..80d3e47f19 100644 --- a/src/mir_app/src/clcmsgs.cpp +++ b/src/mir_app/src/clcmsgs.cpp @@ -43,7 +43,7 @@ LRESULT fnProcessExternalMessages(HWND hwnd, struct ClcData *dat, UINT msg, WPAR case CLM_ADDGROUP: { DWORD groupFlags; - TCHAR *szName = cli.pfnGetGroupName(wParam, &groupFlags); + TCHAR *szName = Clist_GroupGetName(wParam, &groupFlags); if (szName == NULL) break; cli.pfnAddGroup(hwnd, dat, szName, groupFlags, wParam, 0); diff --git a/src/mir_app/src/clcutils.cpp b/src/mir_app/src/clcutils.cpp index 67148b1ac4..41231fc40d 100644 --- a/src/mir_app/src/clcutils.cpp +++ b/src/mir_app/src/clcutils.cpp @@ -411,11 +411,11 @@ void fnEndRename(HWND, struct ClcData *dat, int save) if (contact->group->parent && contact->group->parent->parent) { TCHAR szFullName[256]; mir_sntprintf(szFullName, _T("%s\\%s"), - cli.pfnGetGroupName(contact->group->parent->groupId, NULL), text); - cli.pfnRenameGroup(contact->groupId, szFullName); + Clist_GroupGetName(contact->group->parent->groupId, NULL), text); + Clist_GroupRename(contact->groupId, szFullName); } else - cli.pfnRenameGroup(contact->groupId, text); + Clist_GroupRename(contact->groupId, text); } else if (contact->type == CLCIT_CONTACT) { cli.pfnInvalidateDisplayNameCacheEntry(contact->hContact); @@ -442,7 +442,7 @@ void fnDeleteFromContactList(HWND hwnd, struct ClcData *dat) return; switch (contact->type) { case CLCIT_GROUP: - CallService(MS_CLIST_GROUPDELETE, (WPARAM)contact->groupId, 0); + Clist_GroupDelete(contact->groupId); break; case CLCIT_CONTACT: CallService("CList/DeleteContactCommand", (WPARAM)contact->hContact, (LPARAM)hwnd); diff --git a/src/mir_app/src/clistcore.cpp b/src/mir_app/src/clistcore.cpp index 50ea19f515..70b8ef420c 100644 --- a/src/mir_app/src/clistcore.cpp +++ b/src/mir_app/src/clistcore.cpp @@ -189,9 +189,6 @@ static INT_PTR srvRetrieveInterface(WPARAM, LPARAM) cli.pfnShowHide = fnShowHide; cli.pfnGetStatusModeDescription = fnGetStatusModeDescription; - cli.pfnGetGroupName = fnGetGroupName; - cli.pfnRenameGroup = fnRenameGroup; - cli.pfnHotKeysRegister = fnHotKeysRegister; cli.pfnHotKeysUnregister = fnHotKeysUnregister; cli.pfnHotKeysProcess = fnHotKeysProcess; diff --git a/src/mir_app/src/clistgroups.cpp b/src/mir_app/src/clistgroups.cpp new file mode 100644 index 0000000000..a1eef33b00 --- /dev/null +++ b/src/mir_app/src/clistgroups.cpp @@ -0,0 +1,530 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (с) 2012-16 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" +#include "clc.h" + +struct CGroupInternal +{ + CGroupInternal(int _id, const TCHAR *_name) : + groupId(_id), + groupName(mir_tstrdup(_name)) + {} + + int groupId; + TCHAR *groupName; + + void save() + { + char idstr[33]; + itoa(groupId, idstr, 10); + db_set_ts(NULL, "CListGroups", idstr, groupName); + } +}; + +///////////////////////////////////////////////////////////////////////////////////////// + +static int CompareGrpByName(const CGroupInternal *p1, const CGroupInternal *p2) +{ return mir_tstrcmp(p1->groupName+1, p2->groupName+1); +} + +static LIST arByName(20, CompareGrpByName); + +///////////////////////////////////////////////////////////////////////////////////////// + +struct CGroupList : public LIST +{ + CGroupList() : + LIST(20, NumericKeySortT) + {} + + __inline CGroupInternal* find(int key) + { return LIST::find((CGroupInternal*)&key); + } +}; + +static CGroupList arByIds; + +///////////////////////////////////////////////////////////////////////////////////////// + +HANDLE hGroupChangeEvent; + +static mir_cs csGroups; + +///////////////////////////////////////////////////////////////////////////////////////// + +static int GroupNameExists(const TCHAR *ptszGroupName, int skipGroup) +{ + if (ptszGroupName == 0) + return 0; + + TCHAR str[256]; + _tcsncpy_s(str + 1, _countof(str) - 1, ptszGroupName, _TRUNCATE); + + CGroupInternal *tmp = (CGroupInternal*)_alloca(sizeof(CGroupInternal)); + tmp->groupName = (TCHAR*)str; + if (tmp = arByName.find(tmp)) + return (skipGroup == tmp->groupId) ? 0 : tmp->groupId + 1; + return 0; +} + +MIR_APP_DLL(MGROUP) Clist_GroupExists(LPCTSTR ptszGroupName) +{ + return GroupNameExists(ptszGroupName, -1); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +static INT_PTR CreateGroupInternal(MGROUP hParent, const TCHAR *ptszName) +{ + TCHAR newBaseName[127], newName[128]; + + const TCHAR *grpName = ptszName ? ptszName : TranslateT("New group"); + if (hParent) { + CGroupInternal *tmp = arByIds.find(hParent-1); + if (tmp == NULL) + return NULL; + + mir_sntprintf(newBaseName, _T("%s\\%s"), tmp->groupName+1, grpName); + } + else _tcsncpy_s(newBaseName, grpName, _TRUNCATE); + + mir_tstrncpy(newName + 1, newBaseName, _countof(newName) - 1); + if (ptszName) { + int id = GroupNameExists(newBaseName, -1); + if (id) + return id; + } + else { + for (int idCopy = 1; GroupNameExists(newName + 1, -1); idCopy++) + mir_sntprintf(newName + 1, _countof(newName) - 1, _T("%s (%d)"), newBaseName, idCopy); + } + + int newId = arByIds.getCount(); + newName[0] = 1 | GROUPF_EXPANDED; // 1 is required so we never get '\0' + CGroupInternal *pNew = new CGroupInternal(newId, newName); + pNew->save(); + arByIds.insert(pNew); + arByName.insert(pNew); + + CallService(MS_CLUI_GROUPADDED, newId + 1, 1); + + CLISTGROUPCHANGE grpChg = { sizeof(grpChg), NULL, newName }; + NotifyEventHooks(hGroupChangeEvent, 0, (LPARAM)&grpChg); + + return newId + 1; +} + +MIR_APP_DLL(MGROUP) Clist_GroupCreate(MGROUP hParent, LPCTSTR ptszGroupName) +{ + // no name specified. just create a new group with a default name + if (ptszGroupName == 0) + return CreateGroupInternal(hParent, NULL); + + if (ptszGroupName == NULL || ptszGroupName[0] == '\0' || ptszGroupName[0] == '\\') + return 0; + + TCHAR *tszName = NEWTSTR_ALLOCA(ptszGroupName); + for (TCHAR *p = tszName; *p; p++) { + if (*p == '\\') { + *p = '\0'; + CreateGroupInternal(hParent, tszName); + *p = '\\'; + } + } + return CreateGroupInternal(hParent, tszName); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(TCHAR*) Clist_GroupGetName(MGROUP hGroup, DWORD *pdwFlags) +{ + CGroupInternal *p = arByIds.find(hGroup-1); + if (p == NULL) + return NULL; + + if (pdwFlags != NULL) + *pdwFlags = p->groupName[0] & ~1; + return p->groupName+1; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) Clist_GroupDelete(MGROUP hGroup) +{ + // get the name + CGroupInternal *pGroup = arByIds.find(hGroup-1); + if (pGroup == NULL) + return 1; + + if (db_get_b(NULL, "CList", "ConfirmDelete", SETTING_CONFIRMDELETE_DEFAULT)) { + TCHAR szQuestion[256 + 100]; + mir_sntprintf(szQuestion, TranslateT("Are you sure you want to delete group '%s'? This operation cannot be undone."), pGroup->groupName+1); + if (MessageBox(cli.hwndContactList, szQuestion, TranslateT("Delete group"), MB_YESNO | MB_ICONQUESTION) == IDNO) + return 1; + } + + SetCursor(LoadCursor(NULL, IDC_WAIT)); + + // must remove setting from all child contacts too + // children are demoted to the next group up, not deleted. + TCHAR *szNewParent = NEWTSTR_ALLOCA(pGroup->groupName+1); + { + TCHAR *pszLastBackslash = _tcsrchr(szNewParent, '\\'); + if (pszLastBackslash) + pszLastBackslash[0] = '\0'; + else + szNewParent[0] = '\0'; + } + + for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + ptrT tszGroupName(db_get_tsa(hContact, "CList", "Group")); + if (mir_tstrcmp(tszGroupName, pGroup->groupName+1)) + continue; + + CLISTGROUPCHANGE grpChg = { sizeof(grpChg), NULL, NULL }; + grpChg.pszOldName = pGroup->groupName+1; + if (szNewParent[0]) { + db_set_ts(hContact, "CList", "Group", szNewParent); + grpChg.pszNewName = szNewParent; + } + else { + db_unset(hContact, "CList", "Group"); + grpChg.pszNewName = NULL; + } + + NotifyEventHooks(hGroupChangeEvent, hContact, (LPARAM)&grpChg); + } + + // shuffle list of groups up to fill gap + arByIds.remove(pGroup); + arByName.remove(pGroup); + + for (int i = hGroup-1; i < arByIds.getCount(); i++) { + CGroupInternal *p = arByIds[i]; + p->groupId--; + p->save(); + } + + char idstr[33]; + _itoa(arByIds.getCount(), idstr, 10); + db_unset(NULL, "CListGroups", idstr); + + // rename subgroups + TCHAR szNewName[256]; + size_t len = mir_tstrlen(pGroup->groupName+1); + for (int i = 0; i < arByIds.getCount(); i++) { + CGroupInternal *p = arByIds[i]; + + if (!_tcsncmp(pGroup->groupName+1, p->groupName+1, len) && p->groupName[len+1] == '\\' && _tcschr(p->groupName + len + 2, '\\') == NULL) { + if (szNewParent[0]) + mir_sntprintf(szNewName, _T("%s\\%s"), szNewParent, p->groupName + len + 2); + else + mir_tstrncpy(szNewName, p->groupName + len + 2, _countof(szNewName)); + Clist_GroupRename(i + 1, szNewName); + } + } + + SetCursor(LoadCursor(NULL, IDC_ARROW)); + cli.pfnLoadContactTree(); + + const CLISTGROUPCHANGE grpChg = { sizeof(grpChg), pGroup->groupName+1, NULL }; + NotifyEventHooks(hGroupChangeEvent, 0, (LPARAM)&grpChg); + + mir_free(pGroup->groupName); + delete(pGroup); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) Clist_GroupMoveBefore(MGROUP hGroup, MGROUP hGroupBefore) +{ + if (hGroup == 0 || hGroup == hGroupBefore) + return 0; + + CGroupInternal *pGroup = arByIds.find(hGroup - 1); + if (pGroup == NULL) + return 0; + + // shuffle list of groups up to fill gap + int shuffleFrom, shuffleTo, shuffleStep; + if (hGroupBefore == 0) { + shuffleFrom = hGroup - 1; + shuffleTo = -1; + shuffleStep = 1; + } + else { + CGroupInternal *pDest = arByIds.find(hGroupBefore - 1); + if (pDest == NULL) + return 0; + + if (hGroup < hGroupBefore) { + shuffleFrom = hGroup - 1; + shuffleTo = hGroupBefore - 2; + shuffleStep = 1; + } + else { + shuffleFrom = hGroup - 1; + shuffleTo = hGroupBefore - 1; + shuffleStep = -1; + } + } + + arByIds.remove(pGroup); + + for (int i = shuffleFrom; i != shuffleTo; i += shuffleStep) { + CGroupInternal *p = arByIds[i + shuffleStep]; + p->groupId -= shuffleStep; + p->save(); + } + + pGroup->groupId = shuffleTo; // reinsert group back + pGroup->save(); + + arByIds.insert(pGroup); + return shuffleTo + 1; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +static int RenameGroupWithMove(int groupId, const TCHAR *szName, int move) +{ + if (GroupNameExists(szName, groupId)) { + MessageBox(NULL, TranslateT("You already have a group with that name. Please enter a unique name for the group."), TranslateT("Rename group"), MB_ICONERROR | MB_OK); + return 1; + } + + CGroupInternal *pGroup = arByIds.find(groupId); + if (pGroup == NULL) + return 0; + + // do the change + TCHAR *oldName = NEWTSTR_ALLOCA(pGroup->groupName+1); + + TCHAR str[256]; + str[0] = pGroup->groupName[0]; + mir_tstrncpy(str + 1, szName, _countof(str) - 1); + + pGroup->groupName = mir_tstrdup(str); + pGroup->save(); + + // must rename setting in all child contacts too + for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + ClcCacheEntry *cache = cli.pfnGetCacheEntry(hContact); + if (!mir_tstrcmp(cache->tszGroup, oldName)) { + db_set_ts(hContact, "CList", "Group", szName); + replaceStrT(cache->tszGroup, szName); + } + } + + // rename subgroups + size_t len = mir_tstrlen(oldName); + for (int i = 0; i < arByIds.getCount(); i++) { + if (i == groupId) + continue; + + CGroupInternal *p = arByIds[i]; + if (!_tcsncmp(p->groupName+1, oldName, len) && p->groupName[len+1] == '\\' && _tcschr(p->groupName + len + 2, '\\') == NULL) { + TCHAR szNewName[256]; + mir_sntprintf(szNewName, _T("%s\\%s"), szName, p->groupName + len + 2); + RenameGroupWithMove(i, szNewName, 0); // luckily, child groups will never need reordering + } + } + + // finally must make sure it's after any parent items + if (move) { + _tcsncpy_s(str, szName, _TRUNCATE); + TCHAR *pszLastBackslash = _tcsrchr(str, '\\'); + if (pszLastBackslash != NULL) { + *pszLastBackslash = '\0'; + for (int i = 0; i < arByIds.getCount(); i++) { + CGroupInternal *p = arByIds[i]; + if (!mir_tstrcmp(p->groupName+1, str)) { + if (i >= groupId) + Clist_GroupMoveBefore(groupId + 1, i + 2); + break; + } + } + } + cli.pfnInitAutoRebuild(cli.hwndContactTree); + } + + const CLISTGROUPCHANGE grpChg = { sizeof(grpChg), oldName, (TCHAR*)szName }; + NotifyEventHooks(hGroupChangeEvent, 0, (LPARAM)&grpChg); + return 0; +} + +MIR_APP_DLL(int) Clist_GroupRename(MGROUP hGroup, const TCHAR *ptszNewName) +{ + return 0 != RenameGroupWithMove(hGroup-1, ptszNewName, 1); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) Clist_GroupSetExpanded(MGROUP hGroup, int iNewState) +{ + CGroupInternal *pGroup = arByIds.find(hGroup-1); + if (pGroup == NULL) + return 1; + + if (iNewState) + pGroup->groupName[0] |= GROUPF_EXPANDED; + else + pGroup->groupName[0] &= ~GROUPF_EXPANDED; + pGroup->save(); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(int) Clist_GroupSetFlags(MGROUP hGroup, LPARAM iNewFlags) +{ + CGroupInternal *pGroup = arByIds.find(hGroup-1); + if (pGroup == NULL) + return 1; + + int flags = LOWORD(iNewFlags) & HIWORD(iNewFlags); + int oldval = pGroup->groupName[0]; + pGroup->groupName[0] = ((oldval & ~HIWORD(iNewFlags)) | flags) & 0x7f; + pGroup->save(); + + if ((oldval & GROUPF_HIDEOFFLINE) != (pGroup->groupName[0] & GROUPF_HIDEOFFLINE)) + cli.pfnLoadContactTree(); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(HMENU) Clist_GroupBuildMenu() +{ + if (arByIds.getCount() == 0) + return NULL; + + int nextMenuId = 100; + + HMENU hRootMenu = CreateMenu(); + for (int i = 0; i < arByIds.getCount(); i++) { + const TCHAR *pNextField = arByIds[i]->groupName + 1; + HMENU hThisMenu = hRootMenu; + + MENUITEMINFO mii = { 0 }; + mii.cbSize = sizeof(mii); + + TCHAR szThisField[128], szThisMenuItem[128]; + do { + const TCHAR *pBackslash = _tcschr(pNextField, '\\'); + if (pBackslash == NULL) { + mir_tstrncpy(szThisField, pNextField, _countof(szThisField)); + pNextField = NULL; + } + else { + mir_tstrncpy(szThisField, pNextField, min(_countof(szThisField), pBackslash - pNextField + 1)); + pNextField = pBackslash + 1; + } + int compareResult = 1; + int menuId, menuItemCount = GetMenuItemCount(hThisMenu); + for (menuId = 0; menuId < menuItemCount; menuId++) { + mii.fMask = MIIM_TYPE | MIIM_SUBMENU | MIIM_DATA; + mii.cch = _countof(szThisMenuItem); + mii.dwTypeData = szThisMenuItem; + GetMenuItemInfo(hThisMenu, menuId, TRUE, &mii); + compareResult = mir_tstrcmp(szThisField, szThisMenuItem); + if (compareResult == 0) { + if (pNextField == NULL) { + mii.fMask = MIIM_DATA; + mii.dwItemData = i + 1; + SetMenuItemInfo(hThisMenu, menuId, TRUE, &mii); + } + else { + if (mii.hSubMenu == NULL) { + mii.fMask = MIIM_SUBMENU; + mii.hSubMenu = CreateMenu(); + SetMenuItemInfo(hThisMenu, menuId, TRUE, &mii); + mii.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID; + //dwItemData doesn't change + mii.fType = MFT_STRING; + mii.dwTypeData = TranslateT("This group"); + mii.wID = nextMenuId++; + InsertMenuItem(mii.hSubMenu, 0, TRUE, &mii); + mii.fMask = MIIM_TYPE; + mii.fType = MFT_SEPARATOR; + InsertMenuItem(mii.hSubMenu, 1, TRUE, &mii); + } + hThisMenu = mii.hSubMenu; + } + break; + } + if ((int)mii.dwItemData - 1 > i) + break; + } + if (compareResult) { + mii.fMask = MIIM_TYPE | MIIM_ID; + mii.wID = nextMenuId++; + mii.dwTypeData = szThisField; + mii.fType = MFT_STRING; + if (pNextField) { + mii.fMask |= MIIM_SUBMENU; + mii.hSubMenu = CreateMenu(); + } + else { + mii.fMask |= MIIM_DATA; + mii.dwItemData = i + 1; + } + InsertMenuItem(hThisMenu, menuId, TRUE, &mii); + if (pNextField) + hThisMenu = mii.hSubMenu; + } + } while (pNextField); + } + return hRootMenu; +} + +int InitGroupServices(void) +{ + for (int i = 0;; i++) { + char str[32]; + _itoa(i, str, 10); + ptrT tszGroup(db_get_tsa(NULL, "CListGroups", str)); + if (tszGroup == NULL) + break; + + CGroupInternal *p = new CGroupInternal(i, tszGroup); + arByIds.insert(p); + arByName.insert(p); + } + + hGroupChangeEvent = CreateHookableEvent(ME_CLIST_GROUPCHANGE); + return 0; +} + +void UninitGroupServices(void) +{ + for (int i = 0; i < arByIds.getCount(); i++) { + mir_free(arByIds[i]->groupName); + delete arByIds[i]; + } + arByIds.destroy(); + arByName.destroy(); +} diff --git a/src/mir_app/src/clui.cpp b/src/mir_app/src/clui.cpp index 468b57b905..d3f19c7a5c 100644 --- a/src/mir_app/src/clui.cpp +++ b/src/mir_app/src/clui.cpp @@ -700,7 +700,7 @@ CLS_HIDEEMPTYGROUPS : 0), 0, 0, 0, 0, hwnd, NULL, cli.hInst, NULL); case POPUP_NEWGROUP: SendMessage(cli.hwndContactTree, CLM_SETHIDEEMPTYGROUPS, 0, 0); - CallService(MS_CLIST_GROUPCREATE, 0, 0); + Clist_GroupCreate(0, 0); break; case POPUP_HIDEOFFLINE: @@ -764,7 +764,7 @@ CLS_HIDEEMPTYGROUPS : 0), 0, 0, 0, 0, hwnd, NULL, cli.hInst, NULL); NMCLISTCONTROL *nmc = (NMCLISTCONTROL*)lParam; switch (((LPNMHDR)lParam)->code) { case CLN_EXPANDED: - CallService(MS_CLIST_GROUPSETEXPANDED, (WPARAM)nmc->hItem, nmc->action); + Clist_GroupSetExpanded((MGROUP)nmc->hItem, nmc->action); return FALSE; case CLN_DRAGGING: diff --git a/src/mir_app/src/contact.cpp b/src/mir_app/src/contact.cpp index ad96790d5e..fb57f3a9e9 100644 --- a/src/mir_app/src/contact.cpp +++ b/src/mir_app/src/contact.cpp @@ -46,7 +46,7 @@ void fnLoadContactTree(void) { CallService(MS_CLUI_LISTBEGINREBUILD, 0, 0); for (int i = 1;; i++) { - if (cli.pfnGetGroupName(i, NULL) == NULL) + if (Clist_GroupGetName(i, NULL) == NULL) break; CallService(MS_CLUI_GROUPADDED, i, 0); } @@ -68,7 +68,7 @@ INT_PTR ContactChangeGroup(WPARAM wParam, LPARAM lParam) if ((HANDLE) lParam == NULL) db_unset(wParam, "CList", "Group"); else { - grpChg.pszNewName = cli.pfnGetGroupName(lParam, NULL); + grpChg.pszNewName = Clist_GroupGetName(lParam, NULL); db_set_ts(wParam, "CList", "Group", grpChg.pszNewName); } CallService(MS_CLUI_CONTACTADDED, wParam, diff --git a/src/mir_app/src/groups.cpp b/src/mir_app/src/groups.cpp deleted file mode 100644 index d01bcb8074..0000000000 --- a/src/mir_app/src/groups.cpp +++ /dev/null @@ -1,608 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (с) 2012-16 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "stdafx.h" -#include "clc.h" - -HANDLE hGroupChangeEvent; - -struct CGroupInternal -{ - CGroupInternal(const TCHAR *_name, int _id) : - groupId(_id), - groupName(mir_tstrdup(_name)) - {} - - int groupId; - TCHAR *groupName; -}; - -static int CompareGrpByName(const CGroupInternal *p1, const CGroupInternal *p2) -{ return mir_tstrcmp(p1->groupName, p2->groupName); -} -static LIST arByName(20, CompareGrpByName); - -static LIST arByIds(20, NumericKeySortT); - -static void BuildGroupList() -{ - for (int i = 0;; i++) { - char str[32]; - _itoa(i, str, 10); - ptrT tszGroup(db_get_tsa(NULL, "CListGroups", str)); - if (tszGroup == NULL) - break; - - if (tszGroup[0] & 0x80) { - tszGroup[0] &= 0x7f; - db_set_ts(NULL, "CListGroups", str, tszGroup); - } - - CGroupInternal *p = new CGroupInternal((TCHAR*)tszGroup + 1, i); - arByIds.insert(p); - arByName.insert(p); - } -} - -static void WipeGroupList() -{ - for (int i = 0; i < arByIds.getCount(); i++) { - mir_free(arByIds[i]->groupName); - delete arByIds[i]; - } - arByIds.destroy(); - arByName.destroy(); -} - -static int CountGroups(void) -{ - return arByIds.getCount(); -} - -static int GroupNameExists(const TCHAR *name, int skipGroup) -{ - CGroupInternal *tmp = (CGroupInternal*)_alloca(sizeof(CGroupInternal)); - tmp->groupName = (TCHAR*)name; - if (tmp = arByName.find(tmp)) - return (skipGroup == tmp->groupId) ? 0 : tmp->groupId + 1; - return 0; -} - -static INT_PTR GroupExists(WPARAM, LPARAM lParam) -{ - if (lParam == 0) - return FALSE; - - return GroupNameExists((LPCTSTR)lParam, -1); -} - -static INT_PTR CreateGroupInternal(INT_PTR iParent, const TCHAR *ptszName) -{ - TCHAR newBaseName[127], newName[128]; - char str[33]; - int i; - - const TCHAR *grpName = ptszName ? ptszName : TranslateT("New group"); - if (iParent) { - _itoa(iParent - 1, str, 10); - DBVARIANT dbv; - if (db_get_ts(NULL, "CListGroups", str, &dbv)) - return 0; - - mir_sntprintf(newBaseName, _T("%s\\%s"), dbv.ptszVal + 1, grpName); - mir_free(dbv.pszVal); - } - else mir_tstrncpy(newBaseName, grpName, _countof(newBaseName)); - - int newId = CountGroups(); - _itoa(newId, str, 10); - mir_tstrncpy(newName + 1, newBaseName, _countof(newName) - 1); - if (ptszName) { - i = GroupNameExists(newBaseName, -1); - if (i) newId = i - 1; - i = !i; - } - else { - i = 1; - while (GroupNameExists(newName + 1, -1)) - mir_sntprintf(newName + 1, _countof(newName) - 1, _T("%s (%d)"), newBaseName, i++); - } - if (i) { - CLISTGROUPCHANGE grpChg = { sizeof(grpChg), NULL, newName }; - - newName[0] = 1 | GROUPF_EXPANDED; //1 is required so we never get '\0' - db_set_ts(NULL, "CListGroups", str, newName); - CallService(MS_CLUI_GROUPADDED, newId + 1, 1); - - NotifyEventHooks(hGroupChangeEvent, 0, (LPARAM)&grpChg); - } - - return newId + 1; -} - -static INT_PTR CreateGroup(WPARAM wParam, LPARAM lParam) -{ - if (lParam == 0) - return CreateGroupInternal(wParam, NULL); - - LPCTSTR ptszName = (LPCTSTR)lParam; - if (ptszName == NULL || ptszName[0] == '\0' || ptszName[0] == '\\') - return 0; - - TCHAR *tszName = NEWTSTR_ALLOCA(ptszName); - for (TCHAR *p = tszName; *p; p++) { - if (*p == '\\') { - *p = '\0'; - CreateGroupInternal(wParam, tszName); - *p = '\\'; - } - } - return CreateGroupInternal(wParam, tszName); -} - -static INT_PTR GetGroupName2(WPARAM wParam, LPARAM lParam) -{ - char idstr[33]; - DBVARIANT dbv; - static char name[128]; - - _itoa(wParam - 1, idstr, 10); - if (db_get_s(NULL, "CListGroups", idstr, &dbv)) - return (INT_PTR)(char *)NULL; - mir_strncpy(name, dbv.pszVal + 1, _countof(name)); - if ((DWORD *)lParam != NULL) - *(DWORD *)lParam = dbv.pszVal[0]; - db_free(&dbv); - return (INT_PTR)name; -} - -TCHAR* fnGetGroupName(int idx, DWORD* pdwFlags) -{ - char idstr[33]; - DBVARIANT dbv; - static TCHAR name[128]; - - _itoa(idx - 1, idstr, 10); - if (db_get_ts(NULL, "CListGroups", idstr, &dbv)) - return NULL; - - mir_tstrncpy(name, dbv.ptszVal + 1, _countof(name)); - if (pdwFlags != NULL) - *pdwFlags = dbv.ptszVal[0]; - db_free(&dbv); - return name; -} - -static INT_PTR GetGroupName(WPARAM wParam, LPARAM lParam) -{ - INT_PTR ret; - ret = GetGroupName2(wParam, lParam); - if ((int *)lParam) - *(int *)lParam = 0 != (*(int *)lParam & GROUPF_EXPANDED); - return ret; -} - -static INT_PTR DeleteGroup(WPARAM wParam, LPARAM) -{ - int i; - char str[33]; - DBVARIANT dbv; - MCONTACT hContact; - TCHAR name[256], szNewParent[256], *pszLastBackslash; - - //get the name - _itoa(wParam - 1, str, 10); - if (db_get_ts(NULL, "CListGroups", str, &dbv)) - return 1; - - mir_tstrncpy(name, dbv.ptszVal + 1, _countof(name)); - db_free(&dbv); - if (db_get_b(NULL, "CList", "ConfirmDelete", SETTING_CONFIRMDELETE_DEFAULT)) { - TCHAR szQuestion[256 + 100]; - mir_sntprintf(szQuestion, TranslateT("Are you sure you want to delete group '%s'? This operation cannot be undone."), name); - if (MessageBox(cli.hwndContactList, szQuestion, TranslateT("Delete group"), MB_YESNO | MB_ICONQUESTION) == IDNO) - return 1; - } - SetCursor(LoadCursor(NULL, IDC_WAIT)); - - // must remove setting from all child contacts too - // children are demoted to the next group up, not deleted. - mir_tstrcpy(szNewParent, name); - pszLastBackslash = _tcsrchr(szNewParent, '\\'); - if (pszLastBackslash) - pszLastBackslash[0] = '\0'; - else - szNewParent[0] = '\0'; - - for (hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { - if (db_get_ts(hContact, "CList", "Group", &dbv)) - continue; - - if (mir_tstrcmp(dbv.ptszVal, name)) { - db_free(&dbv); - continue; - } - db_free(&dbv); - - CLISTGROUPCHANGE grpChg = { sizeof(grpChg), NULL, NULL }; - if (szNewParent[0]) { - db_set_ts(hContact, "CList", "Group", szNewParent); - grpChg.pszNewName = szNewParent; - } - else db_unset(hContact, "CList", "Group"); - - NotifyEventHooks(hGroupChangeEvent, hContact, (LPARAM)&grpChg); - } - - // shuffle list of groups up to fill gap - for (i = wParam - 1;; i++) { - _itoa(i + 1, str, 10); - if (db_get_utf(NULL, "CListGroups", str, &dbv)) - break; - _itoa(i, str, 10); - db_set_utf(NULL, "CListGroups", str, dbv.pszVal); - db_free(&dbv); - } - _itoa(i, str, 10); - db_unset(NULL, "CListGroups", str); - - // rename subgroups - { - TCHAR szNewName[256]; - size_t len = mir_tstrlen(name); - for (i = 0;; i++) { - _itoa(i, str, 10); - if (db_get_ts(NULL, "CListGroups", str, &dbv)) - break; - if (!_tcsncmp(dbv.ptszVal + 1, name, len) && dbv.pszVal[len + 1] == '\\' && _tcschr(dbv.ptszVal + len + 2, '\\') == NULL) { - if (szNewParent[0]) - mir_sntprintf(szNewName, _T("%s\\%s"), szNewParent, dbv.ptszVal + len + 2); - else - mir_tstrncpy(szNewName, dbv.ptszVal + len + 2, _countof(szNewName)); - cli.pfnRenameGroup(i + 1, szNewName); - } - db_free(&dbv); - } - } - - WipeGroupList(); - BuildGroupList(); - - SetCursor(LoadCursor(NULL, IDC_ARROW)); - cli.pfnLoadContactTree(); - - const CLISTGROUPCHANGE grpChg = { sizeof(grpChg), name, NULL }; - NotifyEventHooks(hGroupChangeEvent, 0, (LPARAM)&grpChg); - return 0; -} - -static INT_PTR MoveGroupBefore(WPARAM wParam, LPARAM lParam) -{ - int i, shuffleFrom, shuffleTo, shuffleDir; - char str[33]; - TCHAR *szMoveName; - DBVARIANT dbv; - - if (wParam == 0 || (LPARAM)wParam == lParam) - return 0; - _itoa(wParam - 1, str, 10); - if (db_get_ts(NULL, "CListGroups", str, &dbv)) - return 0; - szMoveName = dbv.ptszVal; - //shuffle list of groups up to fill gap - if (lParam == 0) { - shuffleFrom = wParam - 1; - shuffleTo = -1; - shuffleDir = -1; - } - else { - if ((LPARAM)wParam < lParam) { - shuffleFrom = wParam - 1; - shuffleTo = lParam - 2; - shuffleDir = -1; - } - else { - shuffleFrom = wParam - 1; - shuffleTo = lParam - 1; - shuffleDir = 1; - } - } - if (shuffleDir == -1) { - for (i = shuffleFrom; i != shuffleTo; i++) { - _itoa(i + 1, str, 10); - if (db_get_utf(NULL, "CListGroups", str, &dbv)) { - shuffleTo = i; - break; - } - _itoa(i, str, 10); - db_set_utf(NULL, "CListGroups", str, dbv.pszVal); - db_free(&dbv); - } - } - else { - for (i = shuffleFrom; i != shuffleTo; i--) { - _itoa(i - 1, str, 10); - if (db_get_utf(NULL, "CListGroups", str, &dbv)) { - mir_free(szMoveName); - return 1; - } //never happens - _itoa(i, str, 10); - db_set_utf(NULL, "CListGroups", str, dbv.pszVal); - db_free(&dbv); - } - } - _itoa(shuffleTo, str, 10); - db_set_ts(NULL, "CListGroups", str, szMoveName); - mir_free(szMoveName); - - WipeGroupList(); - BuildGroupList(); - - return shuffleTo + 1; -} - -static int RenameGroupWithMove(int groupId, const TCHAR *szName, int move) -{ - char idstr[33]; - TCHAR str[256], oldName[256]; - DBVARIANT dbv; - - if (GroupNameExists(szName, groupId)) { - MessageBox(NULL, TranslateT("You already have a group with that name. Please enter a unique name for the group."), TranslateT("Rename group"), MB_ICONERROR | MB_OK); - return 1; - } - - //do the change - _itoa(groupId, idstr, 10); - if (db_get_ts(NULL, "CListGroups", idstr, &dbv)) - return 1; - str[0] = dbv.pszVal[0] & 0x7F; - mir_tstrncpy(oldName, dbv.ptszVal + 1, _countof(oldName)); - db_free(&dbv); - mir_tstrncpy(str + 1, szName, _countof(str) - 1); - db_set_ts(NULL, "CListGroups", idstr, str); - - //must rename setting in all child contacts too - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { - ClcCacheEntry *cache = cli.pfnGetCacheEntry(hContact); - if (!mir_tstrcmp(cache->tszGroup, oldName)) { - db_set_ts(hContact, "CList", "Group", szName); - mir_free(cache->tszGroup); - cache->tszGroup = 0; - cli.pfnCheckCacheItem(cache); - } - } - - // rename subgroups - { - TCHAR szNewName[256]; - size_t len = mir_tstrlen(oldName); - for (int i = 0;; i++) { - if (i == groupId) - continue; - _itoa(i, idstr, 10); - if (db_get_ts(NULL, "CListGroups", idstr, &dbv)) - break; - if (!_tcsncmp(dbv.ptszVal + 1, oldName, len) && dbv.ptszVal[len + 1] == '\\' && _tcschr(dbv.ptszVal + len + 2, '\\') == NULL) { - mir_sntprintf(szNewName, _T("%s\\%s"), szName, dbv.ptszVal + len + 2); - RenameGroupWithMove(i, szNewName, 0); //luckily, child groups will never need reordering - } - db_free(&dbv); - } - } - - // finally must make sure it's after any parent items - if (move) { - mir_tstrncpy(str, szName, _countof(str)); - TCHAR *pszLastBackslash = _tcsrchr(str, '\\'); - if (pszLastBackslash != NULL) { - *pszLastBackslash = '\0'; - for (int i = 0;; i++) { - _itoa(i, idstr, 10); - if (db_get_ts(NULL, "CListGroups", idstr, &dbv)) - break; - if (!mir_tstrcmp(dbv.ptszVal + 1, str)) { - if (i < groupId) - break; //is OK - MoveGroupBefore(groupId + 1, i + 2); - break; - } - db_free(&dbv); - } - } - - WipeGroupList(); - BuildGroupList(); - } - - const CLISTGROUPCHANGE grpChg = { sizeof(grpChg), oldName, (TCHAR*)szName }; - NotifyEventHooks(hGroupChangeEvent, 0, (LPARAM)&grpChg); - return 0; -} - -int fnRenameGroup(int groupID, TCHAR* newName) -{ - return -1 != RenameGroupWithMove(groupID - 1, newName, 1); -} - -static INT_PTR RenameGroup(WPARAM wParam, LPARAM lParam) -{ - WCHAR* temp = mir_a2u((char*)lParam); - int result = (-1 != RenameGroupWithMove(wParam - 1, temp, 1)); - mir_free(temp); - return result; -} - -static INT_PTR SetGroupExpandedState(WPARAM wParam, LPARAM lParam) -{ - char idstr[33]; - DBVARIANT dbv; - - _itoa(wParam - 1, idstr, 10); - if (db_get_utf(NULL, "CListGroups", idstr, &dbv)) - return 1; - if (lParam) - dbv.pszVal[0] |= GROUPF_EXPANDED; - else - dbv.pszVal[0] = dbv.pszVal[0] & ~GROUPF_EXPANDED; - db_set_utf(NULL, "CListGroups", idstr, dbv.pszVal); - db_free(&dbv); - return 0; -} - -static INT_PTR SetGroupFlags(WPARAM wParam, LPARAM lParam) -{ - char idstr[33]; - DBVARIANT dbv; - int flags, oldval, newval; - - _itoa(wParam - 1, idstr, 10); - if (db_get_utf(NULL, "CListGroups", idstr, &dbv)) - return 1; - flags = LOWORD(lParam) & HIWORD(lParam); - oldval = dbv.pszVal[0]; - newval = dbv.pszVal[0] = ((oldval & ~HIWORD(lParam)) | flags) & 0x7f; - db_set_utf(NULL, "CListGroups", idstr, dbv.pszVal); - db_free(&dbv); - if ((oldval & GROUPF_HIDEOFFLINE) != (newval & GROUPF_HIDEOFFLINE)) - cli.pfnLoadContactTree(); - return 0; -} - -static INT_PTR BuildGroupMenu(WPARAM, LPARAM) -{ - char idstr[33]; - DBVARIANT dbv; - int groupId; - HMENU hRootMenu, hThisMenu; - int nextMenuId = 100; - TCHAR *pBackslash, *pNextField, szThisField[128], szThisMenuItem[128]; - int menuId, compareResult, menuItemCount; - - if (db_get_utf(NULL, "CListGroups", "0", &dbv)) - return (INT_PTR)(HMENU)NULL; - db_free(&dbv); - hRootMenu = CreateMenu(); - for (groupId = 0;; groupId++) { - _itoa(groupId, idstr, 10); - if (db_get_ts(NULL, "CListGroups", idstr, &dbv)) - break; - - pNextField = dbv.ptszVal + 1; - hThisMenu = hRootMenu; - - MENUITEMINFO mii = { 0 }; - mii.cbSize = sizeof(mii); - do { - pBackslash = _tcschr(pNextField, '\\'); - if (pBackslash == NULL) { - mir_tstrncpy(szThisField, pNextField, _countof(szThisField)); - pNextField = NULL; - } - else { - mir_tstrncpy(szThisField, pNextField, min(_countof(szThisField), pBackslash - pNextField + 1)); - pNextField = pBackslash + 1; - } - compareResult = 1; - menuItemCount = GetMenuItemCount(hThisMenu); - for (menuId = 0; menuId < menuItemCount; menuId++) { - mii.fMask = MIIM_TYPE | MIIM_SUBMENU | MIIM_DATA; - mii.cch = _countof(szThisMenuItem); - mii.dwTypeData = szThisMenuItem; - GetMenuItemInfo(hThisMenu, menuId, TRUE, &mii); - compareResult = mir_tstrcmp(szThisField, szThisMenuItem); - if (compareResult == 0) { - if (pNextField == NULL) { - mii.fMask = MIIM_DATA; - mii.dwItemData = groupId + 1; - SetMenuItemInfo(hThisMenu, menuId, TRUE, &mii); - } - else { - if (mii.hSubMenu == NULL) { - mii.fMask = MIIM_SUBMENU; - mii.hSubMenu = CreateMenu(); - SetMenuItemInfo(hThisMenu, menuId, TRUE, &mii); - mii.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID; - //dwItemData doesn't change - mii.fType = MFT_STRING; - mii.dwTypeData = TranslateT("This group"); - mii.wID = nextMenuId++; - InsertMenuItem(mii.hSubMenu, 0, TRUE, &mii); - mii.fMask = MIIM_TYPE; - mii.fType = MFT_SEPARATOR; - InsertMenuItem(mii.hSubMenu, 1, TRUE, &mii); - } - hThisMenu = mii.hSubMenu; - } - break; - } - if ((int)mii.dwItemData - 1 > groupId) - break; - } - if (compareResult) { - mii.fMask = MIIM_TYPE | MIIM_ID; - mii.wID = nextMenuId++; - mii.dwTypeData = szThisField; - mii.fType = MFT_STRING; - if (pNextField) { - mii.fMask |= MIIM_SUBMENU; - mii.hSubMenu = CreateMenu(); - } - else { - mii.fMask |= MIIM_DATA; - mii.dwItemData = groupId + 1; - } - InsertMenuItem(hThisMenu, menuId, TRUE, &mii); - if (pNextField) - hThisMenu = mii.hSubMenu; - } - } while (pNextField); - - db_free(&dbv); - } - return (INT_PTR)hRootMenu; -} - -int InitGroupServices(void) -{ - BuildGroupList(); - - CreateServiceFunction(MS_CLIST_GROUPEXISTS, GroupExists); - CreateServiceFunction(MS_CLIST_GROUPCREATE, CreateGroup); - CreateServiceFunction(MS_CLIST_GROUPDELETE, DeleteGroup); - CreateServiceFunction(MS_CLIST_GROUPRENAME, RenameGroup); - CreateServiceFunction(MS_CLIST_GROUPGETNAME, GetGroupName); - CreateServiceFunction(MS_CLIST_GROUPSETEXPANDED, SetGroupExpandedState); - CreateServiceFunction(MS_CLIST_GROUPSETFLAGS, SetGroupFlags); - CreateServiceFunction(MS_CLIST_GROUPMOVEBEFORE, MoveGroupBefore); - CreateServiceFunction(MS_CLIST_GROUPBUILDMENU, BuildGroupMenu); - - hGroupChangeEvent = CreateHookableEvent(ME_CLIST_GROUPCHANGE); - return 0; -} - -void UninitGroupServices(void) -{ - WipeGroupList(); -} diff --git a/src/mir_app/src/menu_groups.cpp b/src/mir_app/src/menu_groups.cpp index 051dc2d569..58efbff0b7 100644 --- a/src/mir_app/src/menu_groups.cpp +++ b/src/mir_app/src/menu_groups.cpp @@ -131,7 +131,7 @@ INT_PTR CreateGroupHelper(WPARAM, LPARAM) { SendMessage(cli.hwndContactTree, CLM_SETHIDEEMPTYGROUPS, 0, 0); SendMessage(cli.hwndContactTree, CLM_SETUSEGROUPS, 1, 0); - Clist_CreateGroup(0, 0); + Clist_GroupCreate(0, 0); return 0; } diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index d82042dec2..7461945320 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -248,3 +248,12 @@ KillModuleFonts @246 KillModuleHotkeys @247 KillModuleSounds @248 IsPluginLoaded @249 +Clist_GroupBuildMenu @250 +Clist_GroupCreate @251 +Clist_GroupDelete @252 +Clist_GroupExists @253 +Clist_GroupMoveBefore @254 +Clist_GroupSetExpanded @255 +Clist_GroupSetFlags @256 +Clist_GroupGetName @257 +Clist_GroupRename @258 diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 9cfc6c404d..70c2db00b7 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -248,3 +248,12 @@ KillModuleFonts @246 KillModuleHotkeys @247 KillModuleSounds @248 IsPluginLoaded @249 +Clist_GroupBuildMenu @250 +Clist_GroupCreate @251 +Clist_GroupDelete @252 +Clist_GroupExists @253 +Clist_GroupMoveBefore @254 +Clist_GroupSetExpanded @255 +Clist_GroupSetFlags @256 +Clist_GroupGetName @257 +Clist_GroupRename @258 diff --git a/src/mir_core/src/mir_core.def b/src/mir_core/src/mir_core.def index dedd3f240e..08474a3565 100644 --- a/src/mir_core/src/mir_core.def +++ b/src/mir_core/src/mir_core.def @@ -611,7 +611,7 @@ mir_wstrcmpi @280 ?Expand@CCtrlTreeView@@QAEXPAU_TREEITEM@@K@Z @753 NONAME ?FindContact@CCtrlClc@@QAEPAXI@Z @754 NONAME ?FindControl@CDlgBase@@AAEPAVCCtrlBase@@H@Z @755 NONAME -?FindGroup@CCtrlClc@@QAEPAXPAX@Z @756 NONAME +?FindGroup@CCtrlClc@@QAEPAXH@Z @756 NONAME ?FindItem@CCtrlListView@@QAEHHPBUtagLVFINDINFOW@@@Z @757 NONAME ?FindNamedItem@CCtrlTreeView@@QAEPAU_TREEITEM@@PAU2@PB_W@Z @758 NONAME ?FindString@CCtrlCombo@@QAEHPB_WH_N@Z @759 NONAME diff --git a/src/mir_core/src/mir_core64.def b/src/mir_core/src/mir_core64.def index f81f27fc19..8f80acc931 100644 --- a/src/mir_core/src/mir_core64.def +++ b/src/mir_core/src/mir_core64.def @@ -611,7 +611,7 @@ mir_wstrcmpi @280 ?Expand@CCtrlTreeView@@QEAAXPEAU_TREEITEM@@K@Z @753 NONAME ?FindContact@CCtrlClc@@QEAAPEAXI@Z @754 NONAME ?FindControl@CDlgBase@@AEAAPEAVCCtrlBase@@H@Z @755 NONAME -?FindGroup@CCtrlClc@@QEAAPEAXPEAX@Z @756 NONAME +?FindGroup@CCtrlClc@@QEAAPEAXH@Z @756 NONAME ?FindItem@CCtrlListView@@QEAAHHPEBUtagLVFINDINFOW@@@Z @757 NONAME ?FindNamedItem@CCtrlTreeView@@QEAAPEAU_TREEITEM@@PEAU2@PEB_W@Z @758 NONAME ?FindString@CCtrlCombo@@QEAAHPEB_WH_N@Z @759 NONAME diff --git a/src/mir_core/src/ui_utils.cpp b/src/mir_core/src/ui_utils.cpp index 00db886616..f9dec18581 100644 --- a/src/mir_core/src/ui_utils.cpp +++ b/src/mir_core/src/ui_utils.cpp @@ -751,8 +751,8 @@ HANDLE CCtrlClc::FindContact(MCONTACT hContact) { return (HANDLE)SendMessage(m_hwnd, CLM_FINDCONTACT, hContact, 0); } -HANDLE CCtrlClc::FindGroup(HANDLE hGroup) -{ return (HANDLE)SendMessage(m_hwnd, CLM_FINDGROUP, (WPARAM)hGroup, 0); +HANDLE CCtrlClc::FindGroup(MGROUP hGroup) +{ return (HANDLE)SendMessage(m_hwnd, CLM_FINDGROUP, hGroup, 0); } COLORREF CCtrlClc::GetBkColor() -- cgit v1.2.3