Esempio n. 1
0
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;
}
Esempio n. 2
0
static HMENU BuildRecursiveMenu(HMENU hMenu, TMO_IntMenuItem *pRootMenu, WPARAM wParam, LPARAM lParam)
{
	if (pRootMenu == NULL)
		return NULL;

	TIntMenuObject *pmo = pRootMenu->parent;

	if (pRootMenu->mi.root == NULL)
		while (GetMenuItemCount(hMenu) > 0)
			DeleteMenu(hMenu, 0, MF_BYPOSITION);

	for (TMO_IntMenuItem *pmi = pRootMenu; pmi != NULL; pmi = pmi->next) {
		TMO_MenuItem *mi = &pmi->mi;
		if (mi->flags & CMIF_HIDDEN)
			continue;

		if (pmo->CheckService != NULL) {
			TCheckProcParam CheckParam;
			CheckParam.wParam = wParam;
			CheckParam.lParam = lParam;
			CheckParam.MenuItemOwnerData = pmi->pUserData;
			CheckParam.MenuItemHandle = pmi;
			if (CallService(pmo->CheckService, (WPARAM)&CheckParam, 0) == false)
				continue;
		}

		// if we have to check & apply database settings
		if (!(mi->flags & CMIF_SYSTEM) && pmo->m_bUseUserDefinedItems) {
			char szModule[256], szSetting[256];
			mir_snprintf(szModule, "%s_Items", pmo->pszName);

			char menuItemName[256];
			GetMenuItemName(pmi, menuItemName, sizeof(menuItemName));

			// check if it visible
			mir_snprintf(szSetting, "%s_visible", menuItemName);
			if (!db_get_b(NULL, szModule, szSetting, 1))
				continue;

			// mi.name.t
			mir_snprintf(szSetting, "%s_name", menuItemName);
			TCHAR *tszCustomName = db_get_tsa(NULL, szModule, szSetting);
			if (tszCustomName != NULL) {
				mir_free(pmi->CustomName);
				pmi->CustomName = tszCustomName;
			}

			mir_snprintf(szSetting, "%s_pos", menuItemName);
			int pos = db_get_dw(NULL, szModule, szSetting, -1);
			if (pos == -1) {
				db_set_dw(NULL, szModule, szSetting, mi->position);
				if (pmi->submenu.first)
					mi->position = 0;
			}
			else mi->position = pos;
		}

		int i = WhereToPlace(hMenu, mi);

		MENUITEMINFO mii = { 0 };
		mii.cbSize = sizeof(mii);
		mii.dwItemData = (LPARAM)pmi;
		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(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->name.t;

		// 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, _T("%s (%d, id %x)"), mi->name.a, mi->position, mii.dwItemData);
				mii.dwTypeData = str;
			}
#endif

			InsertMenuItemWithSeparators(hMenu, i, &mii);
			BuildRecursiveMenu(mii.hSubMenu, pmi->submenu.first, wParam, lParam);
		}
		else {
			mii.wID = pmi->iCommand;

#ifdef PUTPOSITIONSONMENU
			if (GetKeyState(VK_CONTROL) & 0x8000) {
				TCHAR str[256];
				mir_sntprintf(str, _T("%s (%d, id %x)"), mi->name.a, 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;
}
Esempio n. 3
0
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;
}
int SaveTree(HWND hwndDlg)
{
	TVITEM tvi;
	int count;
	TCHAR idstr[100];
	char menuItemName[256],DBString[256],MenuNameItems[256];
	TCHAR *name;
	int menuitempos,menupos;
	int MenuObjectId,runtimepos;
	PIntMenuObject pimo;

	{
		TVITEM tvi;
		HTREEITEM hti = TreeView_GetSelection(GetDlgItem(hwndDlg,IDC_MENUOBJECTS));
		if ( hti == NULL )
			return(0);

		tvi.mask=TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_PARAM;
		tvi.hItem=hti;
		SendDlgItemMessage(hwndDlg, IDC_MENUOBJECTS, TVM_GETITEM, 0, (LPARAM)&tvi);
		MenuObjectId=tvi.lParam;
	}

	tvi.hItem=TreeView_GetRoot(GetDlgItem(hwndDlg,IDC_MENUITEMS));
	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=&MenuObjects[menupos];

	wsprintfA(MenuNameItems, "%s_Items", pimo->Name); 
	runtimepos=0;

	while (tvi.hItem!=NULL) {
		TreeView_GetItem(GetDlgItem(hwndDlg,IDC_MENUITEMS),&tvi);
		name=((MenuItemOptData *)tvi.lParam)->name;
		menuitempos=GetMenuItembyId(menupos,((MenuItemOptData *)tvi.lParam)->id);
		if (menuitempos!=-1) {
			GetMenuItemName( &pimo->MenuItems[menuitempos], menuItemName, sizeof(menuItemName));

			wsprintfA(DBString, "%s_visible", menuItemName); 
			DBWriteContactSettingByte(NULL, MenuNameItems, DBString, ((MenuItemOptData *)tvi.lParam)->show);

			wsprintfA(DBString, "%s_pos", menuItemName);                                 
			DBWriteContactSettingDword(NULL, MenuNameItems, DBString, runtimepos);

            if(name && ((MenuItemOptData *)tvi.lParam)->defname) {
                if( _tcscmp(name, ((MenuItemOptData *)tvi.lParam)->defname ) !=0 ) {
                    wsprintfA(DBString, "%s_name", menuItemName); 
                    DBWriteContactSettingTString(NULL, MenuNameItems, DBString, name);
                }
            }
			runtimepos+=100;
		}

		if (name && !_tcscmp(name, STR_SEPARATOR) && ((MenuItemOptData *)tvi.lParam)->show )
			runtimepos+=SEPARATORPOSITIONINTERVAL;

		tvi.hItem=TreeView_GetNextSibling(GetDlgItem(hwndDlg,IDC_MENUITEMS),tvi.hItem);                         
		count++;
	}
	return(1);
}
int BuildTree(HWND hwndDlg,int MenuObjectId)
{
	struct OrderData *dat;
	TVINSERTSTRUCT tvis;
	MenuItemOptData *PD;
	lpMenuItemOptData *PDar;
	boolean first;

	char menuItemName[256],MenuNameItems[256];
	char buf[256];
	int i,count,menupos,lastpos;
	PIntMenuObject pimo;

	FreeTreeData(hwndDlg);

	dat=(struct OrderData*)GetWindowLong(GetDlgItem(hwndDlg,IDC_MENUITEMS),GWL_USERDATA);
	tvis.hParent=NULL;
	tvis.hInsertAfter=TVI_LAST;
	tvis.item.mask=TVIF_PARAM|TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE;  
	TreeView_DeleteAllItems(GetDlgItem(hwndDlg,IDC_MENUITEMS));

	menupos=GetMenuObjbyId(MenuObjectId);
	if (menupos==-1)
		return(FALSE);

	pimo=&MenuObjects[menupos];

	if (pimo->MenuItemsCount==0)
		return(FALSE);

	wsprintfA(MenuNameItems, "%s_Items", pimo->Name); 

	//*PDar
	count=0;
	for (i=0;i<pimo->MenuItemsCount;i++) {
		if (pimo->MenuItems[i].mi.root!=-1)
			continue;

		count++;
	}

	PDar=mir_alloc(sizeof(lpMenuItemOptData)*count);

	count=0;
	for (i=0;i<pimo->MenuItemsCount;i++) {
		if (pimo->MenuItems[i].mi.root!=-1)
			continue;

		PD=(MenuItemOptData*)mir_alloc(sizeof(MenuItemOptData));
		ZeroMemory(PD,sizeof(MenuItemOptData));
		GetMenuItemName( &pimo->MenuItems[i], menuItemName, sizeof(menuItemName));
		{
			DBVARIANT dbv;
			wsprintfA(buf, "%s_name", menuItemName);

			if ( !DBGetContactSettingTString(NULL, MenuNameItems, buf, &dbv)) {
				PD->name = mir_tstrdup(dbv.ptszVal);            
				mir_free(dbv.pszVal);
			}
			else PD->name = mir_tstrdup(pimo->MenuItems[i].mi.pszName);
		}

		PD->defname=mir_tstrdup(pimo->MenuItems[i].mi.pszName);

		wsprintfA(buf, "%s_visible", menuItemName);
		PD->show=DBGetContactSettingByte(NULL,MenuNameItems, buf, 1);           

		wsprintfA(buf, "%s_pos", menuItemName);
		PD->pos=DBGetContactSettingDword(NULL,MenuNameItems, buf, 1);

		PD->id=pimo->MenuItems[i].id;
		{
			char buf[256];
			wsprintfA(buf,"buildtree name: %s,id: %d\r\n",pimo->MenuItems[i].mi.pszName,pimo->MenuItems[i].id);
		}

		if (pimo->MenuItems[i].UniqName) PD->uniqname=mir_strdup(pimo->MenuItems[i].UniqName);

		PDar[count]=PD;
		count++;
	}
	qsort(&(PDar[0]),count,sizeof(lpMenuItemOptData),sortfunc);

	SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, WM_SETREDRAW, FALSE, 0);
	lastpos=0;
	first=TRUE;
	for (i=0;i<count;i++) {

		if (PDar[i]->pos-lastpos>=SEPARATORPOSITIONINTERVAL) {
			PD=(MenuItemOptData*)mir_alloc(sizeof(MenuItemOptData));
			ZeroMemory(PD,sizeof(MenuItemOptData));
			PD->id=-1;
			PD->name=mir_tstrdup( _T("---------------------------------------------"));
			PD->pos=PDar[i]->pos-1;
			PD->show=TRUE;

			tvis.item.lParam=(LPARAM)(PD);
			tvis.item.pszText=(PD->name);
			tvis.item.iImage=tvis.item.iSelectedImage=PD->show;
			SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_INSERTITEM, 0, (LPARAM)&tvis);
		}

		tvis.item.lParam=(LPARAM)(PDar[i]);
		tvis.item.pszText=(PDar[i]->name);
		tvis.item.iImage=tvis.item.iSelectedImage=PDar[i]->show;
		{
			HTREEITEM hti = (HTREEITEM)SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_INSERTITEM, 0, (LPARAM)&tvis);
			if (first) {
				TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_MENUITEMS),hti);
				first=FALSE;
		}	}

		lastpos=PDar[i]->pos;   
	}

	SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, WM_SETREDRAW, TRUE, 0);
	mir_free(PDar);
	ShowWindow(GetDlgItem(hwndDlg,IDC_NOTSUPPORTWARNING),(pimo->bUseUserDefinedItems)?SW_HIDE:SW_SHOW);
	EnableWindow(GetDlgItem(hwndDlg,IDC_MENUITEMS),(pimo->bUseUserDefinedItems));
	EnableWindow(GetDlgItem(hwndDlg,IDC_INSERTSEPARATOR),(pimo->bUseUserDefinedItems));
	return 1;
}
Esempio n. 6
0
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;
}
Esempio n. 7
0
static int BuildTree(HWND hwndDlg,int MenuObjectId, BOOL bReread)
{
	char menuItemName[256],MenuNameItems[256];
	char buf[256];

	FreeTreeData( hwndDlg );
	TreeView_DeleteAllItems(GetDlgItem(hwndDlg,IDC_MENUITEMS));

	int menupos = GetMenuObjbyId( MenuObjectId );
	if ( menupos == -1 )
		return FALSE;

	TIntMenuObject* pimo = g_menus[menupos];
	if ( pimo->m_items.first == NULL )
		return FALSE;

	mir_snprintf( MenuNameItems, sizeof(MenuNameItems), "%s_Items", pimo->Name );

	int count = 0;
	{	
		for ( PMO_IntMenuItem p = pimo->m_items.first; p != NULL; p = p->next )
			if ( p->mi.root == ( HGENMENU )-1 || p->mi.root == NULL )
				count++;
	}

	lpMenuItemOptData *PDar = ( lpMenuItemOptData* )mir_alloc( sizeof( lpMenuItemOptData )*count );

	count = 0;
	{
		for ( PMO_IntMenuItem p = pimo->m_items.first; p != NULL; p = p->next ) {
			if ( p->mi.root != ( HGENMENU )-1 && p->mi.root != NULL )
				continue;

			MenuItemOptData *PD = ( MenuItemOptData* )mir_calloc( sizeof( MenuItemOptData ));
			GetMenuItemName( p, menuItemName, sizeof( menuItemName ));
			{
				DBVARIANT dbv;
				mir_snprintf(buf, SIZEOF(buf), "%s_name", menuItemName);

				if ( !DBGetContactSettingTString( NULL, MenuNameItems, buf, &dbv )) {
					PD->name = mir_tstrdup( dbv.ptszVal );
					DBFreeVariant( &dbv );
				}
				else PD->name = mir_tstrdup( p->mi.ptszName );
			}

			PD->pimi = p;
			PD->defname = mir_tstrdup( p->mi.ptszName );

			mir_snprintf( buf, SIZEOF(buf), "%s_visible", menuItemName );
			PD->show = DBGetContactSettingByte( NULL, MenuNameItems, buf, 1 );

			if ( bReread ) {
				mir_snprintf( buf, SIZEOF(buf), "%s_pos", menuItemName );
				PD->pos = DBGetContactSettingDword( NULL, MenuNameItems, buf, 1 );
			}
			else PD->pos = ( PD->pimi ) ? PD->pimi->originalPosition : 0;

			PD->id = p->iCommand;

			if ( p->UniqName )
				PD->uniqname = mir_strdup( p->UniqName );

			PDar[ count ] = PD;
			count++;
	}	}

	qsort( PDar, count, sizeof( lpMenuItemOptData ), sortfunc );

	SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, WM_SETREDRAW, FALSE, 0);
	int lastpos = 0;
	bool first = TRUE;

	TVINSERTSTRUCT tvis;
	tvis.hParent = NULL;
	tvis.hInsertAfter = TVI_LAST;
	tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
	for ( int i=0; i < count; i++ ) {
		if ( PDar[i]->pos - lastpos >= SEPARATORPOSITIONINTERVAL ) {
			MenuItemOptData *PD = ( MenuItemOptData* )mir_calloc( sizeof( MenuItemOptData ));
			PD->id = -1;
			PD->name = mir_tstrdup( STR_SEPARATOR );
			PD->pos = PDar[i]->pos - 1;
			PD->show = TRUE;

			tvis.item.lParam = ( LPARAM )PD;
			tvis.item.pszText = PD->name;
			tvis.item.iImage = tvis.item.iSelectedImage = PD->show;
			SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_INSERTITEM, 0, (LPARAM)&tvis);
		}

		tvis.item.lParam = ( LPARAM )PDar[i];
		tvis.item.pszText = PDar[i]->name;
		tvis.item.iImage = tvis.item.iSelectedImage = PDar[i]->show;
		
		HTREEITEM hti = (HTREEITEM)SendDlgItemMessage(hwndDlg, IDC_MENUITEMS, TVM_INSERTITEM, 0, (LPARAM)&tvis);
		if ( first ) {
			TreeView_SelectItem(GetDlgItem(hwndDlg,IDC_MENUITEMS),hti);
			first=FALSE;
		}

		lastpos = PDar[i]->pos;
	}

	SendDlgItemMessage( hwndDlg, IDC_MENUITEMS, WM_SETREDRAW, TRUE, 0 );
	mir_free( PDar );
	ShowWindow( GetDlgItem( hwndDlg, IDC_NOTSUPPORTWARNING ),( pimo->m_bUseUserDefinedItems ) ? SW_HIDE : SW_SHOW );
	EnableWindow( GetDlgItem( hwndDlg, IDC_MENUITEMS ), pimo->m_bUseUserDefinedItems );
	EnableWindow( GetDlgItem( hwndDlg, IDC_INSERTSEPARATOR ), pimo->m_bUseUserDefinedItems );
	return 1;
}
//----------------------------------------------------------------------------------------
//Window functions
//----------------------------------------------------------------------------------------
void SettingsMenuHandler::OpenInputMappingDetailsView(IDevice* targetDevice)
{
	std::set<IViewPresenter*> viewPresenters = GetOpenViewPresenters(MENUITEM_INPUTMAPPINGDETAILS);
	if(!viewPresenters.empty())
	{
		IViewPresenter* viewPresenter = *viewPresenters.begin();
		InputMappingDetailsViewPresenter* inputMappingDetailsViewPresenter = dynamic_cast<InputMappingDetailsViewPresenter*>(viewPresenter);
		if(inputMappingDetailsViewPresenter != 0)
		{
			inputMappingDetailsViewPresenter->SetTargetDevice(targetDevice);
		}
	}
	else
	{
		IViewPresenter* viewPresenter = new InputMappingDetailsViewPresenter(GetMenuHandlerName(), GetMenuItemName(MENUITEM_INPUTMAPPINGDETAILS), MENUITEM_INPUTMAPPINGDETAILS, owner, model, targetDevice);
		if(!AddCreatedView(MENUITEM_INPUTMAPPINGDETAILS, viewPresenter))
		{
			delete viewPresenter;
		}
	}
}