Exemple #1
0
static void UpdateSubmenuParentPtrs(menu_t *menu)
{
	for (int i = 0; i < (int)menu->u.normal.subMenus.size; i++)
	{
		menu_t *subMenu = CArrayGet(&menu->u.normal.subMenus, i);
		subMenu->parentMenu = menu;
		if (MenuTypeHasSubMenus(subMenu->type))
		{
			UpdateSubmenuParentPtrs(subMenu);
		}
	}
}
Exemple #2
0
void MenuDestroySubmenus(menu_t *menu)
{
	if (menu == NULL)
	{
		return;
	}
	CFREE(menu->name);
	if (MenuTypeHasSubMenus(menu->type))
	{
		for (int i = 0; i < (int)menu->u.normal.subMenus.size; i++)
		{
			menu_t *subMenu = CArrayGet(&menu->u.normal.subMenus, i);
			MenuDestroySubmenus(subMenu);
		}
		CArrayTerminate(&menu->u.normal.subMenus);
	}
}
Exemple #3
0
void MenuDestroySubmenus(menu_t *menu)
{
	if (menu == NULL)
	{
		return;
	}
	if (MenuTypeHasSubMenus(menu->type) && menu->u.normal.subMenus != NULL)
	{
		int i;
		for (i = 0; i < menu->u.normal.numSubMenus; i++)
		{
			menu_t *subMenu = &menu->u.normal.subMenus[i];
			MenuDestroySubmenus(subMenu);
		}
		CFREE(menu->u.normal.subMenus);
	}
}
Exemple #4
0
void MenuAddSubmenu(menu_t *menu, menu_t *subMenu)
{
	menu_t *subMenuLoc = NULL;
	int i;

	menu->u.normal.numSubMenus++;
	CREALLOC(menu->u.normal.subMenus, menu->u.normal.numSubMenus*sizeof(menu_t));
	subMenuLoc = &menu->u.normal.subMenus[menu->u.normal.numSubMenus - 1];
	memcpy(subMenuLoc, subMenu, sizeof(menu_t));
	if (subMenu->type == MENU_TYPE_QUIT)
	{
		menu->u.normal.quitMenuIndex = menu->u.normal.numSubMenus - 1;
	}
	CFREE(subMenu);

	// update all parent pointers, in grandchild menus as well
	for (i = 0; i < menu->u.normal.numSubMenus; i++)
	{
		subMenuLoc = &menu->u.normal.subMenus[i];
		subMenuLoc->parentMenu = menu;
		if (MenuTypeHasSubMenus(subMenuLoc->type))
		{
			int j;

			for (j = 0; j < subMenuLoc->u.normal.numSubMenus; j++)
			{
				menu_t *subSubMenu = &subMenuLoc->u.normal.subMenus[j];
				subSubMenu->parentMenu = subMenuLoc;
			}
		}
	}

	// move cursor in case first menu item(s) are separators
	while (menu->u.normal.index < menu->u.normal.numSubMenus &&
		menu->u.normal.subMenus[menu->u.normal.index].type == MENU_TYPE_SEPARATOR)
	{
		menu->u.normal.index++;
	}
}