From c4582dd65b444e5dae29ada7cc3f6c9a9c20edf3 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 2 Dec 2012 18:19:49 +0000 Subject: new easy standard way of registering icons: Icon_Register git-svn-id: http://svn.miranda-ng.org/main/trunk@2601 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/SimpleStatusMsg/src/awaymsg.cpp | 12 ++-- plugins/SimpleStatusMsg/src/commonheaders.h | 2 +- plugins/SimpleStatusMsg/src/main.cpp | 69 +++++++++---------- plugins/SimpleStatusMsg/src/simplestatusmsg.h | 4 -- plugins/SimpleStatusMsg/src/utils.cpp | 99 +++++---------------------- 5 files changed, 60 insertions(+), 126 deletions(-) (limited to 'plugins/SimpleStatusMsg') diff --git a/plugins/SimpleStatusMsg/src/awaymsg.cpp b/plugins/SimpleStatusMsg/src/awaymsg.cpp index 0f50b6d15a..c4954e77dd 100644 --- a/plugins/SimpleStatusMsg/src/awaymsg.cpp +++ b/plugins/SimpleStatusMsg/src/awaymsg.cpp @@ -462,32 +462,32 @@ int LoadAwayMsgModule(void) CLISTMENUITEM mi = { sizeof(mi) }; mi.flags = CMIF_TCHAR; - CreateServiceFunctionEx(MS_AWAYMSG_SHOWAWAYMSG, GetMessageCommand); + CreateServiceFunction(MS_AWAYMSG_SHOWAWAYMSG, GetMessageCommand); mi.position = -2000005000; mi.ptszName = LPGENT("Re&ad Away Message"); mi.pszService = MS_AWAYMSG_SHOWAWAYMSG; hAwayMsgMenuItem = Menu_AddContactMenuItem(&mi); mi.flags |= CMIF_ICONFROMICOLIB; - CreateServiceFunctionEx(MS_SIMPLESTATUSMSG_COPYMSG, CopyAwayMsgCommand); + CreateServiceFunction(MS_SIMPLESTATUSMSG_COPYMSG, CopyAwayMsgCommand); mi.position = -2000006000; mi.icolibItem = GetIconHandle(IDI_COPY); mi.ptszName = LPGENT("Copy Away Message"); mi.pszService = MS_SIMPLESTATUSMSG_COPYMSG; hCopyMsgMenuItem = Menu_AddContactMenuItem(&mi); - CreateServiceFunctionEx(MS_SIMPLESTATUSMSG_GOTOURLMSG, GoToURLMsgCommand); + CreateServiceFunction(MS_SIMPLESTATUSMSG_GOTOURLMSG, GoToURLMsgCommand); mi.position = -2000007000; mi.icolibItem = GetIconHandle(IDI_GOTOURL); mi.ptszName = LPGENT("&Go to URL in Away Message"); mi.pszService = MS_SIMPLESTATUSMSG_GOTOURLMSG; hGoToURLMenuItem = Menu_AddContactMenuItem(&mi); - HookEventEx(ME_CLIST_PREBUILDCONTACTMENU, AwayMsgPreBuildMenu); + HookEvent(ME_CLIST_PREBUILDCONTACTMENU, AwayMsgPreBuildMenu); // Deprecated SimpleAway services - CreateServiceFunctionEx(MS_SA_COPYAWAYMSG, CopyAwayMsgCommand); - CreateServiceFunctionEx(MS_SA_GOTOURLMSG, GoToURLMsgCommand); + CreateServiceFunction(MS_SA_COPYAWAYMSG, CopyAwayMsgCommand); + CreateServiceFunction(MS_SA_GOTOURLMSG, GoToURLMsgCommand); return 0; } diff --git a/plugins/SimpleStatusMsg/src/commonheaders.h b/plugins/SimpleStatusMsg/src/commonheaders.h index 2fd1426354..843a3555fa 100644 --- a/plugins/SimpleStatusMsg/src/commonheaders.h +++ b/plugins/SimpleStatusMsg/src/commonheaders.h @@ -40,7 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include -#include +#include #include #include #include diff --git a/plugins/SimpleStatusMsg/src/main.cpp b/plugins/SimpleStatusMsg/src/main.cpp index bbac07d69a..acabd42297 100644 --- a/plugins/SimpleStatusMsg/src/main.cpp +++ b/plugins/SimpleStatusMsg/src/main.cpp @@ -1970,16 +1970,16 @@ static int OnModulesLoaded(WPARAM wParam, LPARAM lParam) LoadAwayMsgModule(); - HookEventEx(ME_TTB_MODULELOADED, AddTopToolbarButton); + HookEvent(ME_TTB_MODULELOADED, AddTopToolbarButton); RegisterHotkey(); - HookEventEx(ME_OPT_INITIALISE, InitOptions); + HookEvent(ME_OPT_INITIALISE, InitOptions); h_statusmodechange = HookEvent(ME_CLIST_STATUSMODECHANGE, ChangeStatusMessage); - HookEventEx(ME_PROTO_ACK, ProcessProtoAck); - HookEventEx(ME_IDLE_CHANGED, OnIdleChanged); + HookEvent(ME_PROTO_ACK, ProcessProtoAck); + HookEvent(ME_IDLE_CHANGED, OnIdleChanged); - HookEventEx(ME_CLIST_PREBUILDSTATUSMENU, ChangeStatusMsgPrebuild); + HookEvent(ME_CLIST_PREBUILDSTATUSMENU, ChangeStatusMsgPrebuild); ChangeStatusMsgPrebuild(0, 0); if (ServiceExists(MS_VARS_REGISTERTOKEN)) @@ -2020,7 +2020,7 @@ static int OnModulesLoaded(WPARAM wParam, LPARAM lParam) g_uUpdateMsgTimer = SetTimer(NULL, 0, DBGetContactSettingWord(NULL, "SimpleStatusMsg", "UpdateMsgInt", 10) * 1000, (TIMERPROC)UpdateMsgTimerProc); if (ServiceExists(MS_CS_SETSTATUSEX)) - HookEventEx(ME_CS_STATUSCHANGEEX, CSStatusChange); + HookEvent(ME_CS_STATUSCHANGEEX, CSStatusChange); if (accounts->statusCount == 0) return 0; @@ -2122,48 +2122,47 @@ extern "C" int __declspec(dllexport) Load(void) accounts = (PROTOACCOUNTS *)mir_alloc(sizeof(PROTOACCOUNTS)); DBWriteContactSettingWord(NULL, "CList", "Status", (WORD)ID_STATUS_OFFLINE); - HookEventEx(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); - HookEventEx(ME_PROTO_ACCLISTCHANGED, OnAccListChanged); + HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + HookEvent(ME_PROTO_ACCLISTCHANGED, OnAccListChanged); - CreateServiceFunctionEx(MS_AWAYMSG_GETSTATUSMSG, sttGetAwayMessage); - CreateServiceFunctionEx(MS_AWAYMSG_GETSTATUSMSGW, sttGetAwayMessageT); + CreateServiceFunction(MS_AWAYMSG_GETSTATUSMSG, sttGetAwayMessage); + CreateServiceFunction(MS_AWAYMSG_GETSTATUSMSGW, sttGetAwayMessageT); - CreateServiceFunctionEx(MS_SIMPLESTATUSMSG_SETSTATUS, SetStatusModeFromExtern); - CreateServiceFunctionEx(MS_SIMPLESTATUSMSG_SHOWDIALOG, ShowStatusMessageDialog); - CreateServiceFunctionEx(MS_SIMPLESTATUSMSG_CHANGESTATUSMSG, ChangeStatusMsg); - CreateServiceFunctionEx(MS_SIMPLESTATUSMSG_SHOWDIALOGINT, ShowStatusMessageDialogInternal); // internal use ONLY + CreateServiceFunction(MS_SIMPLESTATUSMSG_SETSTATUS, SetStatusModeFromExtern); + CreateServiceFunction(MS_SIMPLESTATUSMSG_SHOWDIALOG, ShowStatusMessageDialog); + CreateServiceFunction(MS_SIMPLESTATUSMSG_CHANGESTATUSMSG, ChangeStatusMsg); + CreateServiceFunction(MS_SIMPLESTATUSMSG_SHOWDIALOGINT, ShowStatusMessageDialogInternal); // internal use ONLY // Deprecated SimpleAway services - CreateServiceFunctionEx(MS_SA_ISSARUNNING, IsSARunning); - CreateServiceFunctionEx(MS_SA_CHANGESTATUSMSG, ChangeStatusMsg); - CreateServiceFunctionEx(MS_SA_TTCHANGESTATUSMSG, ShowStatusMessageDialogInternal); - CreateServiceFunctionEx(MS_SA_SHOWSTATUSMSGDIALOG, ShowStatusMessageDialog); - CreateServiceFunctionEx(MS_SA_SETSTATUSMODE, SetStatusModeFromExtern); - - CreateServiceFunctionEx(MS_SA_SETOFFLINESTATUS, SetOfflineStatus); - CreateServiceFunctionEx(MS_SA_SETONLINESTATUS, SetOnlineStatus); - CreateServiceFunctionEx(MS_SA_SETAWAYSTATUS, SetAwayStatus); - CreateServiceFunctionEx(MS_SA_SETDNDSTATUS, SetDNDStatus); - CreateServiceFunctionEx(MS_SA_SETNASTATUS, SetNAStatus); - CreateServiceFunctionEx(MS_SA_SETOCCUPIEDSTATUS, SetOccupiedStatus); - CreateServiceFunctionEx(MS_SA_SETFREECHATSTATUS, SetFreeChatStatus); - CreateServiceFunctionEx(MS_SA_SETINVISIBLESTATUS, SetInvisibleStatus); - CreateServiceFunctionEx(MS_SA_SETONTHEPHONESTATUS, SetOnThePhoneStatus); - CreateServiceFunctionEx(MS_SA_SETOUTTOLUNCHSTATUS, SetOutToLunchStatus); - - HookEventEx(ME_SYSTEM_OKTOEXIT, OnOkToExit); - HookEventEx(ME_SYSTEM_PRESHUTDOWN, OnPreShutdown); + CreateServiceFunction(MS_SA_ISSARUNNING, IsSARunning); + CreateServiceFunction(MS_SA_CHANGESTATUSMSG, ChangeStatusMsg); + CreateServiceFunction(MS_SA_TTCHANGESTATUSMSG, ShowStatusMessageDialogInternal); + CreateServiceFunction(MS_SA_SHOWSTATUSMSGDIALOG, ShowStatusMessageDialog); + CreateServiceFunction(MS_SA_SETSTATUSMODE, SetStatusModeFromExtern); + + CreateServiceFunction(MS_SA_SETOFFLINESTATUS, SetOfflineStatus); + CreateServiceFunction(MS_SA_SETONLINESTATUS, SetOnlineStatus); + CreateServiceFunction(MS_SA_SETAWAYSTATUS, SetAwayStatus); + CreateServiceFunction(MS_SA_SETDNDSTATUS, SetDNDStatus); + CreateServiceFunction(MS_SA_SETNASTATUS, SetNAStatus); + CreateServiceFunction(MS_SA_SETOCCUPIEDSTATUS, SetOccupiedStatus); + CreateServiceFunction(MS_SA_SETFREECHATSTATUS, SetFreeChatStatus); + CreateServiceFunction(MS_SA_SETINVISIBLESTATUS, SetInvisibleStatus); + CreateServiceFunction(MS_SA_SETONTHEPHONESTATUS, SetOnThePhoneStatus); + CreateServiceFunction(MS_SA_SETOUTTOLUNCHSTATUS, SetOutToLunchStatus); + + HookEvent(ME_SYSTEM_OKTOEXIT, OnOkToExit); + HookEvent(ME_SYSTEM_PRESHUTDOWN, OnPreShutdown); return 0; } extern "C" int __declspec(dllexport) Unload(void) { - UnhookEvents(); UnhookEvent(h_statusmodechange); UnhookProtoEvents(); - DestroyServiceFunctionsEx(); + mir_free(accounts); #ifdef _DEBUG diff --git a/plugins/SimpleStatusMsg/src/simplestatusmsg.h b/plugins/SimpleStatusMsg/src/simplestatusmsg.h index d66aba197c..95b3311273 100644 --- a/plugins/SimpleStatusMsg/src/simplestatusmsg.h +++ b/plugins/SimpleStatusMsg/src/simplestatusmsg.h @@ -90,12 +90,8 @@ void IconsInit(void); HICON LoadIconEx(const char* name); HANDLE GetIconHandle(int iconId); void ReleaseIconEx(const char* name); -HANDLE HookEventEx(const char *szEvent, MIRANDAHOOK hookProc); -void UnhookEvents(void); HANDLE HookProtoEvent(const char *szModule, const char *szEvent, MIRANDAHOOKPARAM hookProc); void UnhookProtoEvents(void); -HANDLE CreateServiceFunctionEx(const char *name, MIRANDASERVICE serviceProc); -void DestroyServiceFunctionsEx(void); int GetRandom(int from, int to); const TCHAR *GetDefaultMessage(int status); const char *StatusModeToDbSetting(int status, const char *suffix); diff --git a/plugins/SimpleStatusMsg/src/utils.cpp b/plugins/SimpleStatusMsg/src/utils.cpp index 7c706e7818..a6ff747867 100644 --- a/plugins/SimpleStatusMsg/src/utils.cpp +++ b/plugins/SimpleStatusMsg/src/utils.cpp @@ -20,49 +20,23 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "commonheaders.h" #include "simplestatusmsg.h" -static HANDLE *hHookList = NULL; -static HANDLE *hProtoHookList = NULL; -static HANDLE *hServiceList = NULL; -static int HookCount = 0; -static int ProtoHookCount = 0; -static int ServiceCount = 0; - -struct -{ - TCHAR *szDescr; - char *szName; - int defIconID; - HANDLE hIcolib; -} -static iconList[] = -{ - { LPGENT("Delete Selected"), "cross", IDI_CROSS }, - { LPGENT("Recent Message"), "recent", IDI_HISTORY }, - { LPGENT("Predefined Message"), "predef", IDI_MESSAGE }, - { LPGENT("Add to Predefined"), "add", IDI_PLUS }, - { LPGENT("Clear History"), "clear", IDI_CHIST }, - { LPGENT("Copy Away Message"), "copy", IDI_COPY }, - { LPGENT("Change Status Message"), "csmsg", IDI_CSMSG, }, - { LPGENT("Go to URL in Away Message"), "gotourl", IDI_GOTOURL } +static LIST arProtoHooks(5); + +static IconItem iconList[] = +{ + { LPGEN("Delete Selected"), "cross", IDI_CROSS }, + { LPGEN("Recent Message"), "recent", IDI_HISTORY }, + { LPGEN("Predefined Message"), "predef", IDI_MESSAGE }, + { LPGEN("Add to Predefined"), "add", IDI_PLUS }, + { LPGEN("Clear History"), "clear", IDI_CHIST }, + { LPGEN("Copy Away Message"), "copy", IDI_COPY }, + { LPGEN("Change Status Message"), "csmsg", IDI_CSMSG, }, + { LPGEN("Go to URL in Away Message"), "gotourl", IDI_GOTOURL } }; void IconsInit(void) { - TCHAR szFile[MAX_PATH]; - GetModuleFileName(g_hInst, szFile, SIZEOF(szFile)); - - SKINICONDESC sid = { sizeof(sid) }; - sid.flags = SIDF_ALL_TCHAR; - sid.ptszDefaultFile = szFile; - sid.ptszSection = _T("Simple Status Message"); - for (int i = 0; i < SIZEOF(iconList); i++) { - char szSettingName[100]; - mir_snprintf(szSettingName, SIZEOF(szSettingName), "SimpleStatusMsg_%s", iconList[i].szName); - sid.pszName = szSettingName; - sid.ptszDescription = (TCHAR*)iconList[i].szDescr; - sid.iDefaultIndex = -iconList[i].defIconID; - iconList[i].hIcolib = Skin_AddIcon(&sid); - } + Icon_Register(g_hInst, "Simple Status Message", iconList, SIZEOF(iconList), "SimpleStatusMsg"); } HICON LoadIconEx(const char* name) @@ -88,55 +62,20 @@ void ReleaseIconEx(const char* name) Skin_ReleaseIcon(szSettingName); } -HANDLE HookEventEx(const char *szEvent, MIRANDAHOOK hookProc) -{ - HookCount++; - hHookList = (HANDLE *)mir_realloc(hHookList, sizeof(HANDLE) * HookCount); - return hHookList[HookCount - 1] = HookEvent(szEvent, hookProc); -} - -void UnhookEvents(void) -{ - if (hHookList == NULL) return; - for (int i = 0; i < HookCount; ++i) - if (hHookList[i] != NULL) UnhookEvent(hHookList[i]); - mir_free(hHookList); - hHookList = NULL; - HookCount = 0; -} - HANDLE HookProtoEvent(const char *szModule, const char *szEvent, MIRANDAHOOKPARAM hookProc) { char szProtoEvent[MAXMODULELABELLENGTH]; mir_snprintf(szProtoEvent, sizeof(szProtoEvent), "%s%s", szModule, szEvent); - ProtoHookCount++; - hProtoHookList = (HANDLE *)mir_realloc(hProtoHookList, sizeof(HANDLE) * ProtoHookCount); - return hProtoHookList[ProtoHookCount - 1] = HookEventParam(szProtoEvent, hookProc, (LPARAM)szModule); + HANDLE res = HookEventParam(szProtoEvent, hookProc, (LPARAM)szModule); + arProtoHooks.insert(res); + return res; } void UnhookProtoEvents(void) { - if (hProtoHookList == NULL) return; - for (int i = 0; i < ProtoHookCount; ++i) - if (hProtoHookList[i] != NULL) UnhookEvent(hProtoHookList[i]); - mir_free(hProtoHookList); - hProtoHookList = NULL; - ProtoHookCount = 0; -} - -HANDLE CreateServiceFunctionEx(const char *name, MIRANDASERVICE serviceProc) -{ - ServiceCount++; - hServiceList = (HANDLE *)mir_realloc(hServiceList, sizeof(HANDLE) * ServiceCount); - return hServiceList[ServiceCount - 1] = CreateServiceFunction(name, serviceProc); -} - -void DestroyServiceFunctionsEx(void) -{ - for (int i = 0; i < ServiceCount; ++i) - if (hServiceList[i] != NULL) DestroyServiceFunction(hServiceList[i]); - mir_free(hServiceList); - ServiceCount = 0; + for (int i = 0; i < arProtoHooks.getCount(); ++i) + UnhookEvent( arProtoHooks[i] ); + arProtoHooks.destroy(); } // Generate random number in a specified range -- cgit v1.2.3