コード例 #1
0
static rt_bool_t _rtgui_menu_onitem(struct rtgui_object* object, struct rtgui_event* event)
{
	struct rtgui_menu* menu;

	/* event will be NULL, don't check it. */
	RT_ASSERT(object);

	/* get menu */
	menu = RTGUI_MENU(rtgui_widget_get_toplevel(RTGUI_WIDGET(object)));
	if (menu->items[menu->items_list->current_item].type == RTGUI_ITEM_SUBMENU)
	{
		const rtgui_menu_item_t* items;
		rt_uint16_t count;
		rtgui_rect_t item_rect;

		items = (rtgui_menu_item_t*)menu->items[menu->items_list->current_item].submenu;
		count = menu->items[menu->items_list->current_item].submenu_count;
		if (menu->sub_menu != RT_NULL)
		{
			if (menu->sub_menu->items == items)
			{
				if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(menu->sub_menu)))
				{
					/* hide this sub menu */
					rtgui_win_hiden(RTGUI_WIN(menu->sub_menu));
					return RT_FALSE;
				}

				/* show this sub menu */
				rtgui_listctrl_get_item_rect(menu->items_list, menu->items_list->current_item, &item_rect);
				rtgui_menu_pop(menu->sub_menu, item_rect.x2, item_rect.y1);
				return RT_FALSE;
			}

			/* delete sub menu */
			rtgui_menu_destroy(menu->sub_menu);
			menu->sub_menu = RT_NULL;
		}

		/* create sub menu */
		menu->sub_menu = rtgui_menu_create("submenu", menu, items, count);

		rtgui_listctrl_get_item_rect(menu->items_list, menu->items_list->current_item, &item_rect);
		rtgui_menu_pop(menu->sub_menu, item_rect.x2 + 5, item_rect.y1);
	}
	else /* other menu item */
	{
		/* invoke action */
		if (menu->items[menu->items_list->current_item].on_menuaction != RT_NULL)
			menu->items[menu->items_list->current_item].on_menuaction(RTGUI_OBJECT(menu), RT_NULL);

		/* hide sub-menu */
		if (menu->sub_menu != RT_NULL)
		{
			rtgui_menu_hiden(menu->sub_menu);
		}
		rtgui_menu_hiden(menu);
	}
	return RT_FALSE;
}
コード例 #2
0
ファイル: menu.c プロジェクト: pengdonglin137/iboot
static void _rtgui_menu_destructor(rtgui_menu_t* menu)
{
	if (menu->sub_menu != RT_NULL)
	{
		rtgui_menu_destroy(menu->sub_menu);
		menu->sub_menu = RT_NULL;
	}

	rtgui_listctrl_destroy(menu->items_list);
	menu->items_list = RT_NULL;
}