MIR_APP_DLL(int) Menu_ConfigureObject(int hMenuObject, int setting, INT_PTR value) { if (!bIsGenMenuInited) return false; mir_cslock lck(csMenuHook); TIntMenuObject *pmo = GetMenuObjbyId(hMenuObject); if (pmo != NULL) { switch (setting) { case MCO_OPT_ONADD_SERVICE: replaceStr(pmo->onAddService, (char*)value); return true; case MCO_OPT_FREE_SERVICE: replaceStr(pmo->FreeService, (char*)value); return true; case MCO_OPT_CHECK_SERVICE: replaceStr(pmo->CheckService, (char*)value); return true; case MCO_OPT_USERDEFINEDITEMS: pmo->m_bUseUserDefinedItems = (BOOL)value; return true; } } return false; }
MIR_APP_DLL(HGENMENU) Menu_GetProtocolRoot(PROTO_INTERFACE *pThis) { if (pThis == NULL) return 0; if (db_get_b(NULL, "CList", "MoveProtoMenus", TRUE)) { if (pThis->m_hMainMenuItem != NULL) { Menu_RemoveItem(pThis->m_hMainMenuItem); pThis->m_hMainMenuItem = NULL; } return cli.pfnGetProtocolMenu(pThis->m_szModuleName); } TIntMenuObject *pmo = GetMenuObjbyId(hMainMenuObject); if (pmo == NULL) return NULL; mir_cslock lck(csMenuHook); for (TMO_IntMenuItem *p = pmo->m_items.first; p != NULL; p = p->next) if (!mir_strcmp(p->UniqName, pThis->m_szModuleName)) return p; // create protocol root in the main menu CMenuItem mi; mi.name.t = pThis->m_tszUserName; mi.position = 500090000; mi.flags = CMIF_TCHAR | CMIF_KEEPUNTRANSLATED; mi.hIcolibItem = pThis->m_hProtoIcon; return pThis->m_hMainMenuItem = Menu_AddMainMenuItem(&mi); }
//wparam=MenuObjectHandle //lparam=vKey INT_PTR MO_ProcessHotKeys( HANDLE menuHandle, INT_PTR vKey ) { if ( !bIsGenMenuInited) return -1; EnterCriticalSection( &csMenuHook ); int objidx = GetMenuObjbyId( (int)menuHandle ); if ( objidx == -1 ) { LeaveCriticalSection( &csMenuHook ); return FALSE; } for ( PMO_IntMenuItem pimi = g_menus[objidx]->m_items.first; pimi != NULL; pimi = pimi->next ) { if ( pimi->mi.hotKey == 0 ) continue; if ( HIWORD(pimi->mi.hotKey) != vKey) continue; if ( !(LOWORD(pimi->mi.hotKey) & MOD_ALT ) != !( GetKeyState( VK_MENU ) & 0x8000)) continue; if ( !(LOWORD(pimi->mi.hotKey) & MOD_CONTROL ) != !( GetKeyState( VK_CONTROL ) & 0x8000)) continue; if ( !(LOWORD(pimi->mi.hotKey) & MOD_SHIFT ) != !( GetKeyState( VK_SHIFT ) & 0x8000)) continue; MO_ProcessCommand( pimi, 0 ); LeaveCriticalSection( &csMenuHook ); return TRUE; } LeaveCriticalSection( &csMenuHook ); return FALSE; }
//wparam=MenuObjectHandle //lparam=vKey int MO_ProcessHotKeys(WPARAM wParam,LPARAM lParam) { int objidx;//pos in array PMO_IntMenuItem pimi; int i; int vKey=(int)lParam; if (!isGenMenuInited) return -1; lockmo(); objidx=GetMenuObjbyId((int)wParam); if (objidx==-1){unlockmo();return(FALSE);} for(i=0;i<MenuObjects[objidx].MenuItemsCount;i++) { pimi=&MenuObjects[objidx].MenuItems[i]; if (pimi->mi.hotKey==0) continue; if (HIWORD(pimi->mi.hotKey)!=vKey) continue; if (!(LOWORD(pimi->mi.hotKey)&MOD_ALT)!=!(GetKeyState(VK_MENU)&0x8000)) continue; if (!(LOWORD(pimi->mi.hotKey)&MOD_CONTROL)!=!(GetKeyState(VK_CONTROL)&0x8000)) continue; if (!(LOWORD(pimi->mi.hotKey)&MOD_SHIFT)!=!(GetKeyState(VK_SHIFT)&0x8000)) continue; MO_ProcessCommand((WPARAM)getGlobalId(MenuObjects[objidx].id,pimi->id),(LPARAM)0); unlockmo(); return TRUE; } unlockmo(); return(FALSE); }
//wparam started hMenu //lparam ListParam* //result hMenu int MO_BuildMenu(WPARAM wParam,LPARAM lParam) { int res; int tick; int pimoidx; ListParam * lp; if (!isGenMenuInited) return -1; lockmo(); tick=GetTickCount(); lp=(ListParam *)lParam; pimoidx=GetMenuObjbyId(lp->MenuObjectHandle); if (pimoidx==-1){return(0);} res=(int)BuildRecursiveMenu((HMENU)wParam,(ListParam *)lParam); tick=GetTickCount()-tick; { char buf[256]; wsprintfA(buf,"build %s, %d ms\r\n",MenuObjects[pimoidx].Name,tick); } unlockmo(); return(res); }
static int SaveTree(HWND hwndDlg) { TVITEM tvi; int count; TCHAR idstr[100]; char menuItemName[256], DBString[256], MenuNameItems[256]; int menupos; int MenuObjectId, runtimepos; TIntMenuObject* pimo; MenuItemOptData* iod; HWND hTree = GetDlgItem( hwndDlg, IDC_MENUITEMS ); if ( !GetCurrentMenuObjectID( hwndDlg, &MenuObjectId )) return 0; tvi.hItem = TreeView_GetRoot( hTree ); tvi.cchTextMax = 99; tvi.mask = TVIF_TEXT | TVIF_PARAM | TVIF_HANDLE; tvi.pszText = idstr; count = 0; menupos = GetMenuObjbyId( MenuObjectId ); if ( menupos == -1 ) return -1; pimo = g_menus[menupos]; mir_snprintf( MenuNameItems, sizeof(MenuNameItems), "%s_Items", pimo->Name); runtimepos = 100; while ( tvi.hItem != NULL ) { TreeView_GetItem( hTree, &tvi ); iod = ( MenuItemOptData* )tvi.lParam; if ( iod->pimi ) { GetMenuItemName( iod->pimi, menuItemName, sizeof( menuItemName )); mir_snprintf( DBString, SIZEOF(DBString), "%s_visible", menuItemName ); DBWriteContactSettingByte( NULL, MenuNameItems, DBString, iod->show ); mir_snprintf( DBString, SIZEOF(DBString), "%s_pos", menuItemName ); DBWriteContactSettingDword( NULL, MenuNameItems, DBString, runtimepos ); mir_snprintf( DBString, SIZEOF(DBString), "%s_name", menuItemName ); if ( lstrcmp( iod->name, iod->defname ) != 0 ) DBWriteContactSettingTString( NULL, MenuNameItems, DBString, iod->name ); else DBDeleteContactSetting( NULL, MenuNameItems, DBString ); runtimepos += 100; } if ( iod->name && !_tcscmp( iod->name, STR_SEPARATOR) && iod->show ) runtimepos += SEPARATORPOSITIONINTERVAL; tvi.hItem = TreeView_GetNextSibling( hTree, tvi.hItem ); count++; } return 1; }
int RecursiveRemoveChilds(int pos,ListParam *param) { ListParam localparam; int rootid; int i=0; int menuitemid;//id int objidx;//pos in array int *MenuItemsCount; PMO_IntMenuItem *MenuItems=NULL; objidx=GetMenuObjbyId(param->MenuObjectHandle); if ((objidx==-1)){return(-1);} localparam=*param; //rootid=(*param->MenuItems)[pos].id|param->cntFlag; rootid=getGlobalId(MenuObjects[objidx].id,MenuObjects[objidx].MenuItems[pos].id); menuitemid=MenuObjects[objidx].MenuItems[pos].id; MenuItems=&MenuObjects[objidx].MenuItems; MenuItemsCount=&MenuObjects[objidx].MenuItemsCount; if ((*MenuItems)[pos].mi.flags&CMIF_ROOTPOPUP) { while(i<*MenuItemsCount) { if ((*MenuItems)[i].mi.root!=rootid||(*MenuItems)[i].mi.root==-1) { i++; continue; } if ((*MenuItems)[i].mi.flags&CMIF_ROOTPOPUP) { RecursiveRemoveChilds(i,&localparam); i=0; continue; } if ((*MenuItems)[i].mi.flags&CMIF_CHILDPOPUP) { FreeAndNil(&((*MenuItems)[i].mi.pszName)); FreeAndNil(&((*MenuItems)[i].CustomName)); FreeAndNil(&((*MenuItems)[i].UniqName)); if (MenuObjects[objidx].FreeService) CallService(MenuObjects[objidx].FreeService,(WPARAM)(*MenuItems)[i].globalid,(LPARAM)(*MenuItems)[i].mi.ownerdata); RemoveFromList(i,(void **)MenuItems,MenuItemsCount,sizeof(TMO_IntMenuItem)); i=0; continue; } } } i = GetMenuItembyId( objidx, menuitemid ); if ( i >= 0 && i < *MenuItemsCount ) { FreeAndNil(&((*MenuItems)[i].mi.pszName)); FreeAndNil(&((*MenuItems)[i].CustomName)); FreeAndNil(&((*MenuItems)[i].UniqName)); if (MenuObjects[objidx].FreeService) CallService(MenuObjects[objidx].FreeService,(WPARAM)(*MenuItems)[i].globalid,(LPARAM)(*MenuItems)[i].mi.ownerdata); RemoveFromList(i,(void **)MenuItems,MenuItemsCount,sizeof(TMO_IntMenuItem)); } return 0; }
//wparam=MenuObjectHandle //lparam=PMO_MenuItem int MO_AddOldNewMenuItem(WPARAM wParam,LPARAM lParam) { PMO_MenuItem pmi=(PMO_MenuItem)lParam; int objidx; int oldroot,i; if (!isGenMenuInited) return -1; if (pmi==NULL){return(-1);} objidx=GetMenuObjbyId(wParam); if (objidx==-1){return(-1);} if (pmi->cbSize!=sizeof(TMO_MenuItem)) return 0; if ((pmi->flags&CMIF_ROOTPOPUP||pmi->flags&CMIF_CHILDPOPUP)) {return(0);} //is item with popup or not if (pmi->root==0) { //yes,this without popup pmi->root=-1;//first level } else { //no,search for needed root and create it if need TCHAR* tszRoot = ( TCHAR* )CallService( MS_LANGPACK_PCHARTOTCHAR, 0, (LPARAM)pmi->root ); oldroot=-1; for(i=0;i<MenuObjects[objidx].MenuItemsCount;i++) { TMO_IntMenuItem *p = &MenuObjects[objidx].MenuItems[i]; if ( p->mi.pszName == NULL ) continue; if (( p->mi.flags & CMIF_ROOTPOPUP) && !_tcscmp( p->mi.pszName, tszRoot)) { oldroot = getGlobalId( MenuObjects[objidx].id, p->id ); break; } } mir_free( tszRoot ); if (oldroot==-1) { //not found,creating root TMO_MenuItem tmi; ZeroMemory(&tmi,sizeof(tmi)); tmi=*(PMO_MenuItem)lParam; tmi.flags|=CMIF_ROOTPOPUP; tmi.ownerdata=0; tmi.root=-1; //copy pszPopupName tmi.pszName=(TCHAR*)pmi->root; oldroot=MO_AddNewMenuItem(wParam,(LPARAM)&tmi); } pmi->root=oldroot; //popup will be created in next commands } pmi->flags|=CMIF_CHILDPOPUP; //add popup(root allready exists) return(MO_AddNewMenuItem(wParam,(LPARAM)pmi)); }
PMO_IntMenuItem MO_AddOldNewMenuItem( HANDLE menuobjecthandle, PMO_MenuItem pmi ) { if ( !bIsGenMenuInited || pmi == NULL ) return NULL; int objidx = GetMenuObjbyId( (int)menuobjecthandle ); if ( objidx == -1 ) return NULL; if ( pmi->cbSize != sizeof( TMO_MenuItem )) return NULL; if ( pmi->flags & CMIF_ROOTHANDLE ) return NULL; //is item with popup or not if ( pmi->root == 0 ) { //yes,this without popup pmi->root = NULL; //first level } else { // no,search for needed root and create it if need TCHAR* tszRoot; #if defined( _UNICODE ) if ( pmi->flags & CMIF_UNICODE ) tszRoot = mir_tstrdup(TranslateTS(( TCHAR* )pmi->root )); else tszRoot = LangPackPcharToTchar(( char* )pmi->root ); #else tszRoot = mir_tstrdup(TranslateTS(( TCHAR* )pmi->root )); #endif PMO_IntMenuItem oldroot = MO_RecursiveWalkMenu( g_menus[objidx]->m_items.first, FindRoot, tszRoot ); mir_free( tszRoot ); if ( oldroot == NULL ) { //not found,creating root TMO_MenuItem tmi = { 0 }; tmi = *pmi; tmi.flags |= CMIF_ROOTHANDLE; tmi.ownerdata = 0; tmi.root = NULL; //copy pszPopupName tmi.ptszName = ( TCHAR* )pmi->root; if (( oldroot = MO_AddNewMenuItem( menuobjecthandle, &tmi )) != NULL ) MO_SetOptionsMenuItem( oldroot, OPT_MENUITEMSETUNIQNAME, (INT_PTR)pmi->root ); } pmi->root = oldroot; //popup will be created in next commands } pmi->flags |= CMIF_ROOTHANDLE; //add popup(root allready exists) return MO_AddNewMenuItem( menuobjecthandle, pmi ); }
PMO_IntMenuItem MO_GetIntMenuItem(int globid) { int objid,menuitemid;//id int objidx,menuitemidx;//pos in array UnpackGlobalId(globid,&objid,&menuitemid); if ((objid==-1)||(menuitemid==-1)){return(0);} objidx=GetMenuObjbyId(objid); menuitemidx=GetMenuItembyId(objidx,menuitemid); if ((objidx==-1)||(menuitemidx==-1)){return(0);} return(&(MenuObjects[objidx].MenuItems[menuitemidx])); }
MIR_APP_DLL(HGENMENU) Menu_AddItem(int hMenuObject, TMO_MenuItem *pmi, void *pUserData) { if (!bIsGenMenuInited || pmi == NULL) return NULL; mir_cslock lck(csMenuHook); TIntMenuObject *pmo = GetMenuObjbyId(hMenuObject); if (pmo == NULL) return NULL; TMO_IntMenuItem* p = (TMO_IntMenuItem*)mir_calloc(sizeof(TMO_IntMenuItem)); p->parent = pmo; p->signature = MENUITEM_SIGNATURE; p->iCommand = GetNextObjectMenuItemId(); p->mi = *pmi; p->iconId = -1; p->originalPosition = pmi->position; p->pUserData = pUserData; if (pmi->flags & CMIF_UNICODE) p->mi.name.t = mir_tstrdup(pmi->name.t); else p->mi.name.t = mir_a2u(pmi->name.a); if (pmi->hIcon != NULL && !bIconsDisabled) { HANDLE hIcolibItem = IcoLib_IsManaged(pmi->hIcon); if (hIcolibItem != NULL) { HICON hIcon = IcoLib_GetIconByHandle(hIcolibItem, false); p->iconId = ImageList_AddIcon(pmo->m_hMenuIcons, hIcon); p->hIcolibItem = hIcolibItem; IcoLib_ReleaseIcon(hIcon); } else p->iconId = ImageList_AddIcon(pmo->m_hMenuIcons, pmi->hIcon); } TMO_IntMenuItem *pRoot = (p->mi.root != NULL) ? MO_GetIntMenuItem(p->mi.root) : NULL; if (pRoot) { p->owner = &pRoot->submenu; if (pRoot->iconId == -1) pRoot->iconId = p->iconId; } else p->owner = &pmo->m_items; if (!p->owner->first) p->owner->first = p; if (p->owner->last) p->owner->last->next = p; p->owner->last = p; return p; }
int TryProcessDoubleClick( HANDLE hContact ) { int iMenuID = GetMenuObjbyId( (int)hContactMenuObject ); if ( iMenuID != -1 ) { NotifyEventHooks(hPreBuildContactMenuEvent,(WPARAM)hContact,0); PMO_IntMenuItem pimi = ( PMO_IntMenuItem )MO_GetDefaultMenuItem(( WPARAM )g_menus[ iMenuID ]->m_items.first, 0 ); if ( pimi != NULL ) { MO_ProcessCommand( pimi, ( LPARAM )hContact ); return 0; } } return 1; }
MIR_APP_DLL(int) Menu_RemoveObject(int hMenuObject) { if (!bIsGenMenuInited || hMenuObject == 0) return -1; mir_cslock lck(csMenuHook); TIntMenuObject *pmo = GetMenuObjbyId(hMenuObject); if (pmo == NULL) return -1; g_menus.remove(pmo); delete pmo; return 0; }
int TryProcessDoubleClick(MCONTACT hContact) { TIntMenuObject *pmo = GetMenuObjbyId(hContactMenuObject); if (pmo != NULL) { NotifyEventHooks(hPreBuildContactMenuEvent, hContact, 0); TMO_IntMenuItem *pimi = Menu_GetDefaultItem(pmo->m_items.first); if (pimi != NULL) { Menu_ProcessCommand(pimi, hContact); return 0; } } return 1; }
//return 0-erorr,1-ok int GetAllIdx(const int globid,int *pobjidx,int *pmenuitemidx) { int objid,menuitemid;//id int objidx,menuitemidx;//pos in array if (pobjidx==NULL||pmenuitemidx==NULL){return(0);} UnpackGlobalId(globid,&objid,&menuitemid); if ((objid==-1)||(menuitemid==-1)){return(0);} objidx=GetMenuObjbyId(objid); menuitemidx=GetMenuItembyId(objidx,menuitemid); if ((objidx==-1)||(menuitemidx==-1)){return(0);} *pobjidx=objidx; *pmenuitemidx=menuitemidx; return(1); }
//wparam MenuItemHandle //return ownerdata useful to free ownerdata before delete menu item, //NULL on error. int MO_MenuItemGetOwnerData(WPARAM wParam,LPARAM lParam) { int objid,menuitemid;//id int objidx,menuitemidx;//pos in array int res=0; if (!isGenMenuInited) return -1; lockmo(); UnpackGlobalId(wParam,&objid,&menuitemid); if ((objid==-1)||(menuitemid==-1)){return(0);} objidx=GetMenuObjbyId(objid); menuitemidx=GetMenuItembyId(objidx,menuitemid); if ((objidx==-1)||(menuitemidx==-1)){return(0);} res=(int)MenuObjects[objidx].MenuItems[menuitemidx].mi.ownerdata; unlockmo(); return(res); }
//wparam=MenuObjectHandle int MO_RemoveMenuObject(WPARAM wParam,LPARAM lParam) { int objidx; if (!isGenMenuInited) return -1; lockmo(); objidx=GetMenuObjbyId((int)wParam); if (objidx==-1){unlockmo();return(-1);} RemoveAndClearOneObject(objidx); RemoveFromList(objidx,&MenuObjects,&MenuObjectsCount,sizeof(MenuObjects[objidx])); unlockmo(); return(0); }
EXTERN_C MIR_APP_DLL(HMENU) Menu_Build(HMENU parent, int hMenuObject, WPARAM wParam, LPARAM lParam) { if (!bIsGenMenuInited) return NULL; mir_cslock lck(csMenuHook); TIntMenuObject *pmo = GetMenuObjbyId(hMenuObject); if (pmo == NULL) return NULL; #if defined(_DEBUG) // DumpMenuItem(pmo->m_items.first); #endif return BuildRecursiveMenu(parent, pmo->m_items.first, wParam, lParam); }
int MO_ProcessCommandBySubMenuIdent(int menuID, int command, LPARAM lParam) { if (!bIsGenMenuInited) return -1; TMO_IntMenuItem *pimi; { mir_cslock lck(csMenuHook); TIntMenuObject *pmo = GetMenuObjbyId(menuID); if (pmo == NULL) return -1; pimi = MO_RecursiveWalkMenu(pmo->m_items.first, FindMenuByCommand, &command); } return (pimi) ? Menu_ProcessCommand(pimi, lParam) : -1; }
//wparam=MenuObjectHandle INT_PTR MO_RemoveMenuObject(WPARAM wParam, LPARAM) { int objidx; if ( !bIsGenMenuInited) return -1; EnterCriticalSection( &csMenuHook ); objidx = GetMenuObjbyId(( int )wParam ); if ( objidx == -1 ) { LeaveCriticalSection( &csMenuHook ); return -1; } delete g_menus[ objidx ]; g_menus.remove( objidx ); LeaveCriticalSection( &csMenuHook ); return 0; }
MIR_APP_DLL(HGENMENU) Menu_CreateRoot(int hMenuObject, LPCTSTR ptszName, int position, HANDLE hIcoLib, int _hLang) { mir_cslock lck(csMenuHook); TIntMenuObject *pmo = GetMenuObjbyId(hMenuObject); if (pmo == NULL) return NULL; TMO_IntMenuItem *oldroot = MO_RecursiveWalkMenu(pmo->m_items.first, FindRoot, (void*)ptszName); if (oldroot != NULL) return oldroot; CMenuItem mi; mi.flags = CMIF_TCHAR; mi.hIcolibItem = hIcoLib; mi.hLangpack = _hLang; mi.name.t = (TCHAR*)ptszName; mi.position = position; return Menu_AddItem(hMenuObject, &mi, NULL); }
int MO_SetOptionsMenuObject( HANDLE handle, int setting, INT_PTR value ) { int pimoidx; int res = 0; if ( !bIsGenMenuInited ) return -1; EnterCriticalSection( &csMenuHook ); __try { pimoidx = GetMenuObjbyId( (int)handle ); res = pimoidx != -1; if ( res ) { TIntMenuObject* pmo = g_menus[pimoidx]; switch ( setting ) { case OPT_MENUOBJECT_SET_ONADD_SERVICE: FreeAndNil(( void** )&pmo->onAddService ); pmo->onAddService = mir_strdup(( char* )value ); break; case OPT_MENUOBJECT_SET_FREE_SERVICE: FreeAndNil(( void** )&pmo->FreeService ); pmo->FreeService = mir_strdup(( char* )value ); break; case OPT_MENUOBJECT_SET_CHECK_SERVICE: FreeAndNil(( void** )&pmo->CheckService ); pmo->CheckService = mir_strdup(( char* )value); break; case OPT_USERDEFINEDITEMS: pmo->m_bUseUserDefinedItems = ( BOOL )value; break; } } } __except( EXCEPTION_EXECUTE_HANDLER ) {} LeaveCriticalSection( &csMenuHook ); return res; }
//wparam=MenuObjectHandle //lparam=PMO_MenuItem //return MenuItemHandle int MO_AddNewMenuItem(WPARAM wParam,LPARAM lParam) { PMO_MenuItem pmi=(PMO_MenuItem)lParam; int objidx,menuobjecthandle; int miidx,result; int res; if (!isGenMenuInited) return -1; if (pmi==NULL){return(-1);} lockmo(); menuobjecthandle=wParam; objidx=GetMenuObjbyId(menuobjecthandle); if (objidx==-1){unlockmo();return(-1);} if (pmi->cbSize!=sizeof(TMO_MenuItem)) {unlockmo();return -1;} if (!(pmi->flags&CMIF_ROOTPOPUP||pmi->flags&CMIF_CHILDPOPUP)){ //old mode unlockmo(); res=(int)MO_AddOldNewMenuItem(wParam,lParam); return(res); } MenuObjects[objidx].MenuItems=(PMO_IntMenuItem)mir_realloc(MenuObjects[objidx].MenuItems,sizeof(TMO_IntMenuItem)*(MenuObjects[objidx].MenuItemsCount+1)); miidx=MenuObjects[objidx].MenuItemsCount; ZeroMemory(&MenuObjects[objidx].MenuItems[miidx],sizeof(MenuObjects[objidx].MenuItems[miidx])); MenuObjects[objidx].MenuItems[miidx].id=NextObjectMenuItemId++; MenuObjects[objidx].MenuItems[miidx].globalid=getGlobalId(menuobjecthandle,MenuObjects[objidx].MenuItems[miidx].id); MenuObjects[objidx].MenuItems[miidx].mi=*pmi; MenuObjects[objidx].MenuItems[miidx].mi.pszName = (TCHAR*)CallService( MS_LANGPACK_PCHARTOTCHAR,0,(LPARAM)pmi->pszName); MenuObjects[objidx].MenuItems[miidx].iconId=-1; MenuObjects[objidx].MenuItems[miidx].OverrideShow=TRUE; MenuObjects[objidx].MenuItems[miidx].IconRegistred=FALSE; if (pmi->hIcon!=NULL) MenuObjects[objidx].MenuItems[miidx].iconId=ImageList_AddIcon(MenuObjects[objidx].hMenuIcons,pmi->hIcon); result=getGlobalId(wParam,MenuObjects[objidx].MenuItems[miidx].id); MenuObjects[objidx].MenuItemsCount++; unlockmo(); return(result); }
int MO_ProcessCommandBySubMenuIdent(int menuID, int command, LPARAM lParam) { if ( !bIsGenMenuInited ) return -1; EnterCriticalSection( &csMenuHook ); int objidx = GetMenuObjbyId( menuID ); if ( objidx == -1 ) { LeaveCriticalSection( &csMenuHook ); return -1; } PMO_IntMenuItem pimi = MO_RecursiveWalkMenu( g_menus[objidx]->m_items.first, FindMenuByCommand, ( void* )command ); if ( pimi ) { LeaveCriticalSection( &csMenuHook ); return MO_ProcessCommand( pimi, lParam ); } LeaveCriticalSection( &csMenuHook ); return -1; }
//wparam started hMenu //lparam ListParam* //result hMenu INT_PTR MO_BuildMenu(WPARAM wParam,LPARAM lParam) { if ( !bIsGenMenuInited ) return -1; EnterCriticalSection( &csMenuHook ); ListParam *lp = ( ListParam* )lParam; int pimoidx = GetMenuObjbyId( (int)lp->MenuObjectHandle ); if ( pimoidx == -1 ) { LeaveCriticalSection( &csMenuHook ); return 0; } #if defined( _DEBUG ) // DumpMenuItem( g_menus[pimoidx]->m_items.first ); #endif INT_PTR res = (INT_PTR)BuildRecursiveMenu(( HMENU )wParam, g_menus[pimoidx]->m_items.first, ( ListParam* )lParam ); LeaveCriticalSection( &csMenuHook ); return res; }
EXTERN_C MIR_APP_DLL(BOOL) Menu_ProcessHotKey(int hMenuObject, int key) { if (!bIsGenMenuInited) return -1; mir_cslock lck(csMenuHook); TIntMenuObject *pmo = GetMenuObjbyId(hMenuObject); if (pmo == NULL) return FALSE; 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; if (!(LOWORD(pimi->hotKey) & MOD_CONTROL) != !(GetKeyState(VK_CONTROL) & 0x8000)) continue; if (!(LOWORD(pimi->hotKey) & MOD_SHIFT) != !(GetKeyState(VK_SHIFT) & 0x8000)) continue; Menu_ProcessCommand(pimi, 0); return TRUE; } return FALSE; }
int MO_SetOptionsMenuObject(WPARAM wParam,LPARAM lParam) { int pimoidx; lpOptParam lpop; if (!isGenMenuInited) return -1; if (lParam==0){return(0);} lockmo(); __try { lpop=(lpOptParam)lParam; pimoidx=GetMenuObjbyId(lpop->Handle); if (pimoidx==-1){return(0);} switch(lpop->Setting) { case OPT_MENUOBJECT_SET_ONADD_SERVICE: FreeAndNil(&MenuObjects[pimoidx].onAddService); MenuObjects[pimoidx].onAddService=mir_strdup((char *)lpop->Value); break; case OPT_MENUOBJECT_SET_FREE_SERVICE: FreeAndNil(&MenuObjects[pimoidx].FreeService); MenuObjects[pimoidx].FreeService=mir_strdup((char *)lpop->Value); break; case OPT_USERDEFINEDITEMS: MenuObjects[pimoidx].bUseUserDefinedItems=(BOOL)lpop->Value; break; } return(1); } __finally { unlockmo(); } return 1; }
INT_PTR MO_GetProtoRootMenu(WPARAM wParam,LPARAM lParam) { char* szProto = ( char* )wParam; if ( szProto == NULL ) return 0; if ( DBGetContactSettingByte( NULL, "CList", "MoveProtoMenus", FALSE )) return ( INT_PTR )cli.pfnGetProtocolMenu( szProto ); int objidx = GetMenuObjbyId(( int )hMainMenuObject ); if ( objidx == -1 ) return NULL; EnterCriticalSection( &csMenuHook ); TIntMenuObject* pmo = g_menus[objidx]; PMO_IntMenuItem p; for ( p = pmo->m_items.first; p != NULL; p = p->next ) if ( !lstrcmpA( p->UniqName, szProto )) break; LeaveCriticalSection( &csMenuHook ); return ( INT_PTR )p; }
HMENU BuildRecursiveMenu(HMENU hMenu,ListParam *param) { int i,j; MENUITEMINFO mii; PMO_MenuItem mi; HMENU hSubMenu; ListParam localparam; TCheckProcParam CheckParam; //PIntMenuObject pimo=NULL; int pimoidx; PMO_IntMenuItem MenuItems=NULL; int rootlevel; // int cntFlag; int MenuItemsCount; char *checkproc=NULL; char *onAddproc=NULL; char MenuNameItems[256]; if (param==NULL) return(NULL); pimoidx=GetMenuObjbyId(param->MenuObjectHandle); if (pimoidx==-1){return(NULL);} //pimo=&MenuObjects[pimoidx]; MenuItems=MenuObjects[pimoidx].MenuItems; MenuItemsCount=MenuObjects[pimoidx].MenuItemsCount; rootlevel=param->rootlevel; //cntFlag=param->cntFlag; checkproc=MenuObjects[pimoidx].CheckService; onAddproc=MenuObjects[pimoidx].onAddService; localparam=*param; wsprintfA(MenuNameItems, "%s_Items", MenuObjects[pimoidx].Name); /* while((rootlevel==-1)&&(GetMenuItemCount(hMenu)>(param->cntFlag==MENU_CUSTOMITEMMAIN?1:0)) ) DeleteMenu(hMenu,0,MF_BYPOSITION); */ while((rootlevel==-1)&&GetMenuItemCount(hMenu)>0) DeleteMenu(hMenu,0,MF_BYPOSITION); for(j=0;j<MenuItemsCount;j++) { mi=&(MenuItems[j].mi); if (mi->cbSize!=sizeof(TMO_MenuItem)) continue; // // RegisterOneIcon(pimoidx,j); if (checkproc!=NULL) { CheckParam.lParam=param->lParam; CheckParam.wParam=param->wParam; CheckParam.MenuItemOwnerData=mi->ownerdata; CheckParam.MenuItemHandle=getGlobalId(param->MenuObjectHandle,MenuItems[j].id); if (CallService(checkproc,(WPARAM)&CheckParam,(LPARAM)0)==FALSE) continue; } /**************************************/ if (rootlevel==-1&&mi->root==-1&&MenuObjects[pimoidx].bUseUserDefinedItems) { char menuItemName[256]; char DBString[256]; DBVARIANT dbv; memset(&dbv,0,sizeof(dbv)); GetMenuItemName( &MenuItems[j], menuItemName, sizeof(menuItemName)); // check if it visible wsprintfA(DBString, "%s_visible", menuItemName); if (DBGetContactSettingByte(NULL, MenuNameItems, DBString, -1)==-1) DBWriteContactSettingByte(NULL,MenuNameItems, DBString,1); MenuItems[j].OverrideShow=TRUE; if (!DBGetContactSettingByte(NULL, MenuNameItems, DBString, 1)) { MenuItems[j].OverrideShow=FALSE; continue; // find out what value to return if not getting added } // mi.pszName wsprintfA(DBString, "%s_name", menuItemName); if (!DBGetContactSettingTString(NULL, MenuNameItems, DBString, &dbv)) { if (_tcslen(dbv.ptszVal)>0) { if (MenuItems[j].CustomName) mir_free(MenuItems[j].CustomName); MenuItems[j].CustomName=mir_tstrdup(dbv.ptszVal); } if (dbv.ptszVal) mir_free(dbv.ptszVal); } wsprintfA(DBString, "%s_pos", menuItemName); if (DBGetContactSettingDword(NULL, MenuNameItems, DBString, -1)==-1) DBWriteContactSettingDword(NULL,MenuNameItems, DBString,mi->position); mi->position = DBGetContactSettingDword(NULL, MenuNameItems, DBString, mi->position); } /**************************************/ ZeroMemory(&mii,sizeof(mii)); i=0; //hMenu=hMainMenu; mii.cbSize=MENUITEMINFO_V4_SIZE; mii.fMask=MIIM_SUBMENU|MIIM_TYPE|MIIM_DATA; mii.dwItemData=getGlobalId(param->MenuObjectHandle,MenuItems[j].id); hSubMenu=NULL; if (rootlevel!=(int)MenuItems[j].mi.root) continue; if ((MenuItems[j].mi.flags&CMIF_CHILDPOPUP)||(MenuItems[j].mi.flags&CMIF_ROOTPOPUP)) { if (rootlevel==(int)MenuItems[j].mi.root) { //our level if (MenuItems[j].mi.flags&CMIF_ROOTPOPUP) { i=WhereToPlace(hMenu,mi,&mii,&localparam); if (!IsWinVer98Plus()) { mii.cbSize=MENUITEMINFO_V4_SIZE; mii.fMask=MIIM_DATA|MIIM_TYPE|MIIM_ID|MIIM_SUBMENU; } else { mii.cbSize=sizeof(mii); mii.fMask=MIIM_DATA|MIIM_ID|MIIM_STRING|MIIM_SUBMENU; if (MenuItems[j].iconId!=-1) mii.fMask|=MIIM_BITMAP; } mii.fType=MFT_STRING; //mii.dwItemData=getGlobalId(param->MenuObjectHandle,MenuItems[j].id); mii.dwItemData=MenuItems[j].globalid; hSubMenu=CreatePopupMenu(); mii.hSubMenu=hSubMenu; mii.hbmpItem=HBMMENU_CALLBACK; mii.dwTypeData=(MenuItems[j].CustomName)?(MenuItems[j].CustomName):(mi->pszName); #ifdef PUTPOSITIONSONMENU if (GetKeyState(VK_CONTROL)&0x8000) { TCHAR str[256]; mir_sntprintf(str,SIZEOF(str),_T("%s (%d,id %x)"),mi->pszName,mi->position,mii.dwItemData); mii.dwTypeData=str; } #endif InsertMenuItemWithSeparators(hMenu,i,TRUE,&mii,&localparam); localparam.rootlevel=getGlobalId(param->MenuObjectHandle,MenuItems[j].id);//MenuItems[j].id|cntFlag; BuildRecursiveMenu(hSubMenu,&localparam); continue; } i=WhereToPlace(hMenu,mi,&mii,&localparam); if (!IsWinVer98Plus()) { mii.cbSize=MENUITEMINFO_V4_SIZE; mii.fMask=MIIM_DATA|MIIM_TYPE|MIIM_ID|MIIM_STATE; } else { mii.cbSize=sizeof(mii); mii.fMask=MIIM_DATA|MIIM_ID|MIIM_STRING|MIIM_STATE; if (MenuItems[j].iconId!=-1) mii.fMask|=MIIM_BITMAP; } mii.fState=((MenuItems[j].mi.flags&CMIF_GRAYED)?MFS_GRAYED:MFS_ENABLED); mii.fState|=((MenuItems[j].mi.flags&CMIF_CHECKED)?MFS_CHECKED:MFS_UNCHECKED); mii.fType=MFT_STRING; mii.wID=MenuItems[j].id; //mii.dwItemData=getGlobalId(param->MenuObjectHandle,MenuItems[j].id);//MenuItems[j].id|cntFlag; mii.dwItemData=MenuItems[j].globalid; mii.hbmpItem=HBMMENU_CALLBACK; mii.dwTypeData=(MenuItems[j].CustomName)?(MenuItems[j].CustomName):(mi->pszName); #ifdef PUTPOSITIONSONMENU if (GetKeyState(VK_CONTROL)&0x8000) { TCHAR str[256]; mir_sntprintf( str, SIZEOF(str), _T("%s (%d,id %x)"),mi->pszName,mi->position,mii.dwItemData); mii.dwTypeData=str; } #endif if (onAddproc!=NULL) if (CallService(onAddproc,(WPARAM)&mii,(LPARAM)MenuItems[j].globalid)==FALSE) continue; InsertMenuItemWithSeparators(hMenu,i,TRUE,&mii,&localparam); continue; } } else { //old items - not needed if (rootlevel==-1) { } } } return hMenu; }
static void InsertMenuItemWithSeparators(HMENU hMenu,int uItem,BOOL fByPosition,MENUITEMINFO *lpmii,ListParam *param) { int thisItemPosition,needSeparator,itemidx; MENUITEMINFO mii; PMO_IntMenuItem MenuItems=NULL; PMO_IntMenuItem pimi=NULL; int objid,menuitemid;//id int objidx,menuitemidx;//pos in array needSeparator=0; UnpackGlobalId(lpmii->dwItemData,&objid,&menuitemid); if ((objid==-1)||(menuitemid==-1)){return;} objidx=GetMenuObjbyId(objid); menuitemidx=GetMenuItembyId(objidx,menuitemid); if ((objidx==-1)||(menuitemidx==-1)){return;} MenuItems=MenuObjects[objidx].MenuItems; itemidx=menuitemidx; //timi= thisItemPosition=(MenuItems)[itemidx].mi.position; ZeroMemory(&mii,sizeof(mii)); mii.cbSize=MENUITEMINFO_V4_SIZE; //check for separator before if (uItem) { mii.fMask=MIIM_SUBMENU|MIIM_DATA|MIIM_TYPE; GetMenuItemInfo(hMenu,uItem-1,TRUE,&mii); pimi=MO_GetIntMenuItem(mii.dwItemData); if (pimi!=NULL) if (mii.fType==MFT_SEPARATOR) needSeparator=0; else needSeparator=((pimi->mi.position)/SEPARATORPOSITIONINTERVAL)!=thisItemPosition/SEPARATORPOSITIONINTERVAL; if (needSeparator) { //but might be supposed to be after the next one instead mii.fType=0; if (uItem<GetMenuItemCount(hMenu)) { mii.fMask=MIIM_SUBMENU|MIIM_DATA|MIIM_TYPE; GetMenuItemInfo(hMenu,uItem,TRUE,&mii); } if (mii.fType!=MFT_SEPARATOR) { mii.fMask=MIIM_TYPE; mii.fType=MFT_SEPARATOR; InsertMenuItem(hMenu,uItem,TRUE,&mii); } uItem++; } } //check for separator after if (uItem<GetMenuItemCount(hMenu)) { mii.fMask=MIIM_SUBMENU|MIIM_DATA|MIIM_TYPE; mii.cch=0; GetMenuItemInfo(hMenu,uItem,TRUE,&mii); pimi=MO_GetIntMenuItem(mii.dwItemData); if (pimi!=NULL) if (mii.fType==MFT_SEPARATOR) needSeparator=0; else needSeparator=((pimi->mi.position)/SEPARATORPOSITIONINTERVAL)!=thisItemPosition/SEPARATORPOSITIONINTERVAL; if (needSeparator) { mii.fMask=MIIM_TYPE; mii.fType=MFT_SEPARATOR; InsertMenuItem(hMenu,uItem,TRUE,&mii); } } if (uItem==GetMenuItemCount(hMenu)-1) { TCHAR str[32]; mii.fMask=MIIM_SUBMENU|MIIM_DATA|MIIM_TYPE; mii.dwTypeData=str; mii.cch=SIZEOF(str); GetMenuItemInfo(hMenu,uItem,TRUE,&mii); /*if (param->cntFlag==MENU_CUSTOMITEMMAIN) { if (mii.fType==MFT_STRING && !strcmp(mii.dwTypeData,Translate("E&xit"))) { //make sure we keep the separator before the exit menu item mii.fMask=MIIM_TYPE; mii.fType=MFT_SEPARATOR; InsertMenuItem(hMenu,uItem,TRUE,&mii); } } */ } InsertMenuItem(hMenu,uItem,TRUE,lpmii); }