summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-06-29 21:55:35 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-06-29 21:55:35 +0000
commit1ac7427e92a1bb2a9bab2b576325b05b018108f6 (patch)
tree7f97da34c633ef7f631f7880feccd2732bef15ae /src
parente926dec9996611f89fe579778886419a0c2945cc (diff)
menu object processing code cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@14447 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/genmenu.cpp99
-rw-r--r--src/mir_app/src/genmenu.h15
-rw-r--r--src/mir_app/src/genmenuopt.cpp26
3 files changed, 60 insertions, 80 deletions
diff --git a/src/mir_app/src/genmenu.cpp b/src/mir_app/src/genmenu.cpp
index f4134d0218..4821c15d84 100644
--- a/src/mir_app/src/genmenu.cpp
+++ b/src/mir_app/src/genmenu.cpp
@@ -54,7 +54,7 @@ static int CompareMenus(const TIntMenuObject* p1, const TIntMenuObject* p2)
return mir_strcmp(p1->pszName, p2->pszName);
}
-LIST<TIntMenuObject> g_menus(10, CompareMenus);
+LIST<TIntMenuObject> g_menus(10, NumericKeySortT);
void FreeAndNil(void **p)
{
@@ -67,7 +67,7 @@ void FreeAndNil(void **p)
}
}
-int GetMenuObjbyId(int id)
+TIntMenuObject* GetMenuObjbyId(int id)
{
switch (id) {
case MO_MAIN: id = hMainMenuObject; break;
@@ -80,11 +80,7 @@ int GetMenuObjbyId(int id)
id = hMainMenuObject;
}
- for (int i = 0; i < g_menus.getCount(); i++)
- if (g_menus[i]->id == id)
- return i;
-
- return -1;
+ return g_menus.find((TIntMenuObject*)&id);
}
LPTSTR GetMenuItemText(TMO_IntMenuItem *pimi)
@@ -209,11 +205,11 @@ EXTERN_C MIR_APP_DLL(BOOL) Menu_ProcessHotKey(int hMenuObject, int key)
return -1;
mir_cslock lck(csMenuHook);
- int objidx = GetMenuObjbyId(hMenuObject);
- if (objidx == -1)
+ TIntMenuObject *pmo = GetMenuObjbyId(hMenuObject);
+ if (pmo == NULL)
return FALSE;
- for (TMO_IntMenuItem *pimi = g_menus[objidx]->m_items.first; pimi != NULL; pimi = pimi->next) {
+ for (TMO_IntMenuItem *pimi = pmo->m_items.first; pimi != NULL; pimi = pimi->next) {
if (pimi->hotKey == 0) continue;
if (HIWORD(pimi->hotKey) != key) continue;
if (!(LOWORD(pimi->hotKey) & MOD_ALT) != !(GetKeyState(VK_MENU) & 0x8000)) continue;
@@ -237,13 +233,11 @@ MIR_APP_DLL(HGENMENU) Menu_GetProtocolRoot(const char *szProto)
if (db_get_b(NULL, "CList", "MoveProtoMenus", TRUE))
return cli.pfnGetProtocolMenu(szProto);
- int objidx = GetMenuObjbyId((int)hMainMenuObject);
- if (objidx == -1)
+ TIntMenuObject *pmo = GetMenuObjbyId(hMainMenuObject);
+ if (pmo == NULL)
return NULL;
mir_cslock lck(csMenuHook);
-
- TIntMenuObject* pmo = g_menus[objidx];
for (TMO_IntMenuItem *p = pmo->m_items.first; p != NULL; p = p->next)
if (!mir_strcmp(p->UniqName, szProto))
return p;
@@ -417,11 +411,11 @@ int MO_ProcessCommandBySubMenuIdent(int menuID, int command, LPARAM lParam)
TMO_IntMenuItem *pimi;
{
mir_cslock lck(csMenuHook);
- int objidx = GetMenuObjbyId(menuID);
- if (objidx == -1)
+ TIntMenuObject *pmo = GetMenuObjbyId(menuID);
+ if (pmo == NULL)
return -1;
- pimi = MO_RecursiveWalkMenu(g_menus[objidx]->m_items.first, FindMenuByCommand, (void*)command);
+ pimi = MO_RecursiveWalkMenu(pmo->m_items.first, FindMenuByCommand, (void*)command);
}
return (pimi) ? Menu_ProcessCommand(pimi, lParam) : -1;
@@ -495,38 +489,31 @@ MIR_APP_DLL(int) Menu_ConfigureItem(HGENMENU hItem, int iOption, INT_PTR value)
MIR_APP_DLL(int) Menu_ConfigureObject(int hMenuObject, int setting, INT_PTR value)
{
if (!bIsGenMenuInited)
- return -1;
+ return false;
mir_cslock lck(csMenuHook);
-
- int pimoidx = GetMenuObjbyId(hMenuObject);
- int res = pimoidx != -1;
- if (res) {
- TIntMenuObject* pmo = g_menus[pimoidx];
-
+ TIntMenuObject *pmo = GetMenuObjbyId(hMenuObject);
+ if (pmo != NULL) {
switch (setting) {
case MCO_OPT_ONADD_SERVICE:
- FreeAndNil((void**)&pmo->onAddService);
- pmo->onAddService = mir_strdup((char*)value);
- break;
+ replaceStr(pmo->onAddService, (char*)value);
+ return true;
case MCO_OPT_FREE_SERVICE:
- FreeAndNil((void**)&pmo->FreeService);
- pmo->FreeService = mir_strdup((char*)value);
- break;
+ replaceStr(pmo->FreeService, (char*)value);
+ return true;
case MCO_OPT_CHECK_SERVICE:
- FreeAndNil((void**)&pmo->CheckService);
- pmo->CheckService = mir_strdup((char*)value);
- break;
+ replaceStr(pmo->CheckService, (char*)value);
+ return true;
case MCO_OPT_USERDEFINEDITEMS:
pmo->m_bUseUserDefinedItems = (BOOL)value;
- break;
+ return true;
}
}
- return res;
+ return false;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -557,12 +544,12 @@ MIR_APP_DLL(int) Menu_RemoveObject(int hMenuObject)
return -1;
mir_cslock lck(csMenuHook);
- int objidx = GetMenuObjbyId(hMenuObject);
- if (objidx == -1)
+ TIntMenuObject *pmo = GetMenuObjbyId(hMenuObject);
+ if (pmo == NULL)
return -1;
- delete g_menus[objidx];
- g_menus.remove(objidx);
+ g_menus.remove(pmo);
+ delete pmo;
return 0;
}
@@ -678,11 +665,11 @@ static int FindRoot(TMO_IntMenuItem *pimi, void *param)
MIR_APP_DLL(HGENMENU) Menu_CreateRoot(int hMenuObject, LPCTSTR ptszName, int position, HANDLE hIcoLib, int hLang)
{
mir_cslock lck(csMenuHook);
- int objidx = GetMenuObjbyId(hMenuObject);
- if (objidx == -1)
+ TIntMenuObject *pmo = GetMenuObjbyId(hMenuObject);
+ if (pmo == NULL)
return NULL;
- TMO_IntMenuItem *oldroot = MO_RecursiveWalkMenu(g_menus[objidx]->m_items.first, FindRoot, (void*)ptszName);
+ TMO_IntMenuItem *oldroot = MO_RecursiveWalkMenu(pmo->m_items.first, FindRoot, (void*)ptszName);
if (oldroot != NULL)
return oldroot;
@@ -705,12 +692,10 @@ MIR_APP_DLL(HGENMENU) Menu_AddItem(int hMenuObject, TMO_MenuItem *pmi, void *pUs
return NULL;
mir_cslock lck(csMenuHook);
- int objidx = GetMenuObjbyId(hMenuObject);
- if (objidx == -1)
+ TIntMenuObject *pmo = GetMenuObjbyId(hMenuObject);
+ if (pmo == NULL)
return NULL;
- TIntMenuObject* pmo = g_menus[objidx];
-
TMO_IntMenuItem* p = (TMO_IntMenuItem*)mir_calloc(sizeof(TMO_IntMenuItem));
p->parent = pmo;
p->signature = MENUITEM_SIGNATURE;
@@ -871,7 +856,7 @@ static HMENU BuildRecursiveMenu(HMENU hMenu, TMO_IntMenuItem *pRootMenu, INT_PTR
if (pRootMenu == NULL)
return NULL;
- TIntMenuObject* pmo = pRootMenu->parent;
+ TIntMenuObject *pmo = pRootMenu->parent;
if (iRootLevel == 0)
while (GetMenuItemCount(hMenu) > 0)
@@ -1010,15 +995,15 @@ EXTERN_C MIR_APP_DLL(HMENU) Menu_Build(HMENU parent, int hMenuObject, WPARAM wPa
mir_cslock lck(csMenuHook);
- int pimoidx = GetMenuObjbyId(hMenuObject);
- if (pimoidx == -1)
- return 0;
+ TIntMenuObject *pmo = GetMenuObjbyId(hMenuObject);
+ if (pmo == NULL)
+ return NULL;
#if defined(_DEBUG)
- // DumpMenuItem(g_menus[pimoidx]->m_items.first);
+ // DumpMenuItem(pmo->m_items.first);
#endif
- return BuildRecursiveMenu(parent, g_menus[pimoidx]->m_items.first, 0, wParam, lParam);
+ return BuildRecursiveMenu(parent, pmo->m_items.first, 0, wParam, lParam);
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -1042,7 +1027,7 @@ int OnIconLibChanges(WPARAM, LPARAM)
{
mir_cslock lck(csMenuHook);
for (int mo = 0; mo < g_menus.getCount(); mo++)
- if ((int)hStatusMenuObject != g_menus[mo]->id) //skip status menu
+ if (hStatusMenuObject != g_menus[mo]->id) //skip status menu
MO_RecursiveWalkMenu(g_menus[mo]->m_items.first, MO_ReloadIcon, 0);
}
@@ -1106,7 +1091,7 @@ int RegisterAllIconsInIconLib()
{
// register all icons
for (int mo = 0; mo < g_menus.getCount(); mo++) {
- if ((int)hStatusMenuObject == g_menus[mo]->id) //skip status menu
+ if (hStatusMenuObject == g_menus[mo]->id) //skip status menu
continue;
MO_RecursiveWalkMenu(g_menus[mo]->m_items.first, MO_RegisterIcon, 0);
@@ -1117,11 +1102,11 @@ int RegisterAllIconsInIconLib()
int TryProcessDoubleClick(MCONTACT hContact)
{
- int iMenuID = GetMenuObjbyId((int)hContactMenuObject);
- if (iMenuID != -1) {
+ TIntMenuObject *pmo = GetMenuObjbyId(hContactMenuObject);
+ if (pmo != NULL) {
NotifyEventHooks(hPreBuildContactMenuEvent, hContact, 0);
- TMO_IntMenuItem *pimi = Menu_GetDefaultItem(g_menus[iMenuID]->m_items.first);
+ TMO_IntMenuItem *pimi = Menu_GetDefaultItem(pmo->m_items.first);
if (pimi != NULL) {
Menu_ProcessCommand(pimi, hContact);
return 0;
diff --git a/src/mir_app/src/genmenu.h b/src/mir_app/src/genmenu.h
index 5c7dfb1c1e..36521c4189 100644
--- a/src/mir_app/src/genmenu.h
+++ b/src/mir_app/src/genmenu.h
@@ -68,28 +68,28 @@ struct TIntMenuObject : public MZeroedObject
TIntMenuObject();
~TIntMenuObject();
- char *pszName;
+ int id;
+ char *pszName;
TCHAR *ptszDisplayName;
- int id;
//ExecService
//LPARAM lParam;//owner data
//WPARAM wParam;//allways lparam from winproc
- LPCSTR ExecService;
+ char *ExecService;
//CheckService called when building menu
//return false to skip item.
//LPARAM lParam;//0
//WPARAM wParam;//CheckParam
- LPCSTR CheckService;//analog to check_proc
+ char *CheckService;//analog to check_proc
//LPARAM lParam;//ownerdata
//WPARAM wParam;//menuitemhandle
- LPCSTR FreeService;//callback service used to free ownerdata for menuitems
+ char *FreeService;//callback service used to free ownerdata for menuitems
//LPARAM lParam;//MENUITEMINFO filled with all needed data
//WPARAM wParam;//menuitemhandle
- LPCSTR onAddService;//called just before add MENUITEMINFO to hMenu
+ char *onAddService;//called just before add MENUITEMINFO to hMenu
TMO_LinkedList m_items;
HIMAGELIST m_hMenuIcons;
@@ -128,9 +128,10 @@ BOOL FindMenuHanleByGlobalID(HMENU hMenu, int globalID, struct _MenuItemHandles
LPTSTR GetMenuItemText(TMO_IntMenuItem*);
int GenMenuOptInit(WPARAM wParam, LPARAM);
-int GetMenuObjbyId(const int id);
int GetMenuItembyId(const int objpos, const int id);
+TIntMenuObject* GetMenuObjbyId(const int id);
+
int ProtocolOrderOptInit(WPARAM wParam, LPARAM);
void FreeAndNil(void **p);
diff --git a/src/mir_app/src/genmenuopt.cpp b/src/mir_app/src/genmenuopt.cpp
index 2b306e5623..cd2653227f 100644
--- a/src/mir_app/src/genmenuopt.cpp
+++ b/src/mir_app/src/genmenuopt.cpp
@@ -78,14 +78,12 @@ class CGenMenuOptionsPage : public CDlgBase
tvi.pszText = idstr;
int count = 0;
- int menupos = GetMenuObjbyId(MenuObjectId);
- if (menupos == -1)
+ TIntMenuObject *pmo = GetMenuObjbyId(MenuObjectId);
+ if (pmo == NULL)
return;
- TIntMenuObject *pimo = g_menus[menupos];
-
char MenuNameItems[256];
- mir_snprintf(MenuNameItems, _countof(MenuNameItems), "%s_Items", pimo->pszName);
+ mir_snprintf(MenuNameItems, _countof(MenuNameItems), "%s_Items", pmo->pszName);
int runtimepos = 100;
while (tvi.hItem != NULL) {
@@ -147,20 +145,16 @@ class CGenMenuOptionsPage : public CDlgBase
{
FreeTreeData();
- int menupos = GetMenuObjbyId(MenuObjectId);
- if (menupos == -1)
- return false;
-
- TIntMenuObject* pimo = g_menus[menupos];
- if (pimo->m_items.first == NULL)
+ TIntMenuObject *pmo = GetMenuObjbyId(MenuObjectId);
+ if (pmo == NULL || pmo->m_items.first == NULL)
return false;
char menuItemName[256], MenuNameItems[256];
- mir_snprintf(MenuNameItems, _countof(MenuNameItems), "%s_Items", pimo->pszName);
+ mir_snprintf(MenuNameItems, _countof(MenuNameItems), "%s_Items", pmo->pszName);
LIST<MenuItemOptData> arItems(10, SortMenuItems);
- for (TMO_IntMenuItem *p = pimo->m_items.first; p != NULL; p = p->next) {
+ for (TMO_IntMenuItem *p = pmo->m_items.first; p != NULL; p = p->next) {
if (p->mi.root != (HGENMENU)-1 && p->mi.root != NULL)
continue;
@@ -237,9 +231,9 @@ class CGenMenuOptionsPage : public CDlgBase
m_menuItems.SendMsg(WM_SETREDRAW, TRUE, 0);
bRebuild = false;
- ShowWindow(m_warning.GetHwnd(), (pimo->m_bUseUserDefinedItems) ? SW_HIDE : SW_SHOW);
- m_menuItems.Enable(pimo->m_bUseUserDefinedItems);
- m_btnInsert.Enable(pimo->m_bUseUserDefinedItems);
+ ShowWindow(m_warning.GetHwnd(), (pmo->m_bUseUserDefinedItems) ? SW_HIDE : SW_SHOW);
+ m_menuItems.Enable(pmo->m_bUseUserDefinedItems);
+ m_btnInsert.Enable(pmo->m_bUseUserDefinedItems);
return 1;
}