void rtgui_menu_pop(struct rtgui_menu* menu, int x, int y) { rtgui_rect_t rect; struct rtgui_event_resize eresize; if (menu == RT_NULL) return; /* set window extent */ rect.x1 = 0; rect.y1 = 0; rect.x2 = 100; rect.y2 = menu->items_count * (rtgui_theme_get_selected_height() + 2) + 5; rtgui_rect_moveto(&rect, x, y); rtgui_win_set_rect(RTGUI_WIN(menu), &rect); rtgui_rect_inflate(&rect, -1); rtgui_widget_set_rect(RTGUI_WIDGET(menu->items_list), &rect); eresize.parent.type = RTGUI_EVENT_RESIZE; eresize.x = rect.x1; eresize.y = rect.y1; eresize.h = rect.y2 - rect.y1; eresize.w = rect.x2 - rect.x1; rtgui_listctrl_event_handler(RTGUI_WIDGET(menu->items_list), &(eresize.parent)); /* on menu pop handler */ if (menu->on_menupop != RT_NULL) { menu->on_menupop(RTGUI_WIDGET(menu), RT_NULL); } /* show menu window */ rtgui_win_show(RTGUI_WIN(menu), RT_FALSE); }
static rt_bool_t apps_listctrl_event_handler(struct rtgui_object* object, struct rtgui_event* event) { struct rtgui_listctrl* ctrl; ctrl = RTGUI_LISTCTRL(object); if (event->type == RTGUI_EVENT_MOUSE_BUTTON) { struct rtgui_rect rect, close_rect; struct rtgui_event_mouse* emouse; emouse = (struct rtgui_event_mouse*)event; if (emouse->button & RTGUI_MOUSE_BUTTON_UP) { /* get physical extent information */ rtgui_widget_get_extent(RTGUI_WIDGET(ctrl), &rect); close_rect = rect; close_rect.x1 = close_rect.x2 - 50; if ((rtgui_rect_contains_point(&close_rect, emouse->x, emouse->y) == RT_EOK) && (ctrl->items_count > 0)) { rt_uint16_t index; index = (emouse->y - rect.y1) / (2 + ctrl->item_height); if ((index < ctrl->page_items) && (ctrl->current_item/ctrl->page_items)* ctrl->page_items + index < ctrl->items_count) { rt_uint16_t cur_item; /* get current item */ cur_item = (ctrl->current_item/ctrl->page_items) * ctrl->page_items + index; if (cur_item == ctrl->current_item) { rt_kprintf("close app\n"); rtgui_app_close(app_items[ctrl->current_item].app); return RT_TRUE; } } } } } return rtgui_listctrl_event_handler(object, event); }