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; }
HMENU BuildRecursiveMenu(HMENU hMenu, PMO_IntMenuItem pRootMenu, ListParam *param) { if ( param == NULL || pRootMenu == NULL ) return NULL; TIntMenuObject* pmo = pRootMenu->parent; int rootlevel = ( param->rootlevel == -1 ) ? 0 : param->rootlevel; ListParam localparam = *param; while ( rootlevel == 0 && GetMenuItemCount( hMenu ) > 0 ) DeleteMenu( hMenu, 0, MF_BYPOSITION ); for ( PMO_IntMenuItem pmi = pRootMenu; pmi != NULL; pmi = pmi->next ) { PMO_MenuItem mi = &pmi->mi; if ( mi->cbSize != sizeof( TMO_MenuItem )) continue; if ( mi->flags & CMIF_HIDDEN ) continue; if ( pmo->CheckService != NULL ) { TCheckProcParam CheckParam; CheckParam.lParam = param->lParam; CheckParam.wParam = param->wParam; CheckParam.MenuItemOwnerData = mi->ownerdata; CheckParam.MenuItemHandle = pmi; if ( CallService( pmo->CheckService, ( WPARAM )&CheckParam, 0 ) == FALSE ) continue; } /**************************************/ if ( rootlevel == 0 && mi->root == NULL && pmo->m_bUseUserDefinedItems ) { char DBString[256]; DBVARIANT dbv = { 0 }; int pos; char MenuNameItems[256]; mir_snprintf(MenuNameItems, SIZEOF(MenuNameItems), "%s_Items", pmo->Name); char menuItemName[256]; GetMenuItemName( pmi, menuItemName, sizeof( menuItemName )); // check if it visible mir_snprintf( DBString, SIZEOF(DBString), "%s_visible", menuItemName ); if ( DBGetContactSettingByte( NULL, MenuNameItems, DBString, -1 ) == -1 ) DBWriteContactSettingByte( NULL, MenuNameItems, DBString, 1 ); pmi->OverrideShow = TRUE; if ( !DBGetContactSettingByte( NULL, MenuNameItems, DBString, 1 )) { pmi->OverrideShow = FALSE; continue; // find out what value to return if not getting added } // mi.pszName mir_snprintf( DBString, SIZEOF(DBString), "%s_name", menuItemName ); if ( !DBGetContactSettingTString( NULL, MenuNameItems, DBString, &dbv )) { if ( _tcslen( dbv.ptszVal ) > 0 ) { if ( pmi->CustomName ) mir_free( pmi->CustomName ); pmi->CustomName = mir_tstrdup( dbv.ptszVal ); } DBFreeVariant( &dbv ); } mir_snprintf( DBString, SIZEOF(DBString), "%s_pos", menuItemName ); if (( pos = DBGetContactSettingDword( NULL, MenuNameItems, DBString, -1 )) == -1 ) { DBWriteContactSettingDword( NULL, MenuNameItems, DBString, mi->position ); if ( pmi->submenu.first ) mi->position = 0; } else mi->position = pos; } /**************************************/ if ( rootlevel != (int)pmi->mi.root ) continue; MENUITEMINFO mii = { 0 }; mii.dwItemData = ( LPARAM )pmi; int i = WhereToPlace( hMenu, mi ); if ( !IsWinVer98Plus()) { mii.cbSize = MENUITEMINFO_V4_SIZE; mii.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID; mii.fType = MFT_STRING; } else { mii.cbSize = sizeof( mii ); mii.fMask = MIIM_DATA | MIIM_ID | MIIM_STRING; if ( pmi->iconId != -1 ) { mii.fMask |= MIIM_BITMAP; if (IsWinVerVistaPlus() && isThemeActive()) { if (pmi->hBmp == NULL) pmi->hBmp = ConvertIconToBitmap(NULL, pmi->parent->m_hMenuIcons, pmi->iconId); mii.hbmpItem = pmi->hBmp; } else mii.hbmpItem = HBMMENU_CALLBACK; } } mii.fMask |= MIIM_STATE; mii.fState = (( pmi->mi.flags & CMIF_GRAYED ) ? MFS_GRAYED : MFS_ENABLED ); mii.fState |= (( pmi->mi.flags & CMIF_CHECKED) ? MFS_CHECKED : MFS_UNCHECKED ); if ( pmi->mi.flags & CMIF_DEFAULT ) mii.fState |= MFS_DEFAULT; mii.dwTypeData = ( pmi->CustomName ) ? pmi->CustomName : mi->ptszName; // it's a submenu if ( pmi->submenu.first ) { mii.fMask |= MIIM_SUBMENU; mii.hSubMenu = CreatePopupMenu(); #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, &mii); localparam.rootlevel = LPARAM( pmi ); BuildRecursiveMenu( mii.hSubMenu, pmi->submenu.first, &localparam ); } else { mii.wID = pmi->iCommand; #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 ( pmo->onAddService != NULL ) if ( CallService( pmo->onAddService, ( WPARAM )&mii, ( LPARAM )pmi ) == FALSE ) continue; InsertMenuItemWithSeparators( hMenu, i, &mii ); } } return hMenu; }