|
@@ -11,13 +11,6 @@ static rt_bool_t rtgui_menu_on_deactivate(rtgui_widget_t* widget, rtgui_event_t*
|
|
|
|
|
|
static void _rtgui_menu_constructor(rtgui_menu_t *menu)
|
|
static void _rtgui_menu_constructor(rtgui_menu_t *menu)
|
|
{
|
|
{
|
|
- rtgui_box_t* box;
|
|
|
|
- rtgui_rect_t rect = {0, 0, RTGUI_MENU_DEFAULT_WIDTH, RTGUI_BORDER_DEFAULT_WIDTH << 1};
|
|
|
|
-
|
|
|
|
- /* set default rect */
|
|
|
|
- menu->width = RTGUI_MENU_DEFAULT_WIDTH;
|
|
|
|
- menu->height = (RTGUI_BORDER_DEFAULT_WIDTH << 1);
|
|
|
|
- rtgui_widget_set_rect(RTGUI_WIDGET(menu), &rect);
|
|
|
|
/* set window style */
|
|
/* set window style */
|
|
RTGUI_WIN(menu)->style = RTGUI_WIN_STYLE_NO_TITLE;
|
|
RTGUI_WIN(menu)->style = RTGUI_WIN_STYLE_NO_TITLE;
|
|
|
|
|
|
@@ -25,14 +18,52 @@ static void _rtgui_menu_constructor(rtgui_menu_t *menu)
|
|
rtgui_win_set_ondeactivate(RTGUI_WIN(menu), rtgui_menu_on_deactivate);
|
|
rtgui_win_set_ondeactivate(RTGUI_WIN(menu), rtgui_menu_on_deactivate);
|
|
|
|
|
|
/* set proper of control */
|
|
/* set proper of control */
|
|
- menu->parent_item = RT_NULL;
|
|
|
|
- menu->select_item = RT_NULL;
|
|
|
|
|
|
+ menu->parent_menu = RT_NULL;
|
|
|
|
+ menu->items = RT_NULL;
|
|
|
|
+ menu->items_count = 0;
|
|
|
|
+ menu->current_item = 0;
|
|
|
|
+ menu->items_list = RT_NULL;
|
|
|
|
+
|
|
menu->on_menupop = RT_NULL;
|
|
menu->on_menupop = RT_NULL;
|
|
menu->on_menuhide = RT_NULL;
|
|
menu->on_menuhide = RT_NULL;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void _rtgui_menu_destructor(rtgui_menu_t* menu)
|
|
|
|
+{
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void _rtgui_menu_item_ondraw(struct rtgui_listctrl *list, struct rtgui_dc* dc, rtgui_rect_t* rect, rt_uint16_t index)
|
|
|
|
+{
|
|
|
|
+ struct rtgui_menu_item* item;
|
|
|
|
+
|
|
|
|
+ /* get menu item */
|
|
|
|
+ item = (rtgui_menu_item_t*)list->items;
|
|
|
|
+ item = &item[index];
|
|
|
|
+
|
|
|
|
+ if (item->type == RTGUI_ITEM_SUBMENU)
|
|
|
|
+ {
|
|
|
|
+ rtgui_dc_draw_text(dc, item->label, &rect);
|
|
|
|
+ rtgui_dc_draw_byte(dc, left_arraw, &rect);
|
|
|
|
+ }
|
|
|
|
+ else if (item->type == RTGUI_ITEM_SEPARATOR)
|
|
|
|
+ {
|
|
|
|
+ rtgui_dc_draw_vline(dc, &rect);
|
|
|
|
+ }
|
|
|
|
+ else if (item->type == RTGUI_ITEM_CHECK)
|
|
|
|
+ {
|
|
|
|
+ /* not support right now */
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ /* normal menu item */
|
|
|
|
+ rtgui_dc_draw_text(dc, item->label, &rect);
|
|
|
|
+ if (item->image != RT_NULL)
|
|
|
|
+ rtgui_image_blit(item->image, dc, &rect);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
|
|
- /* create box */
|
|
|
|
- box = rtgui_box_create(RTGUI_VERTICAL, &rect);
|
|
|
|
- rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(box));
|
|
|
|
|
|
+static void _rtgui_menu_item_onmouse()
|
|
|
|
+{
|
|
}
|
|
}
|
|
|
|
|
|
rtgui_type_t *rtgui_menu_type_get(void)
|
|
rtgui_type_t *rtgui_menu_type_get(void)
|
|
@@ -42,7 +73,9 @@ rtgui_type_t *rtgui_menu_type_get(void)
|
|
if (!menu_type)
|
|
if (!menu_type)
|
|
{
|
|
{
|
|
menu_type = rtgui_type_create("menu", RTGUI_WIN_TYPE,
|
|
menu_type = rtgui_type_create("menu", RTGUI_WIN_TYPE,
|
|
- sizeof(rtgui_menu_t), RTGUI_CONSTRUCTOR(_rtgui_menu_constructor), RT_NULL);
|
|
|
|
|
|
+ sizeof(rtgui_menu_t),
|
|
|
|
+ RTGUI_CONSTRUCTOR(_rtgui_menu_constructor),
|
|
|
|
+ RTGUI_DESTRUCTOR (_rtgui_menu_destructor));
|
|
}
|
|
}
|
|
|
|
|
|
return menu_type;
|
|
return menu_type;
|
|
@@ -52,17 +85,14 @@ static rt_bool_t rtgui_menu_on_deactivate(rtgui_widget_t* widget, rtgui_event_t*
|
|
{
|
|
{
|
|
rtgui_menu_t* menu = (rtgui_menu_t*) widget;
|
|
rtgui_menu_t* menu = (rtgui_menu_t*) widget;
|
|
|
|
|
|
- if (menu->select_item != RT_NULL)
|
|
|
|
|
|
+ /* submenu is activate */
|
|
|
|
+ if (menu->items[menu->current_item].type == RTGUI_ITEM_SUBMEN)
|
|
{
|
|
{
|
|
- /* try to wake through to find sub menu activated */
|
|
|
|
- if (menu->select_item->type == RTGUI_ITEM_SUBMENU)
|
|
|
|
|
|
+ /* if sub menu activated, not hide menu */
|
|
|
|
+ if (menu->select_item->sub_menu != RT_NULL &&
|
|
|
|
+ rtgui_win_is_activated(RTGUI_WIN(menu->select_item->sub_menu)))
|
|
{
|
|
{
|
|
- /* if sub menu activated, not hide menu */
|
|
|
|
- if (menu->select_item->sub_menu != RT_NULL &&
|
|
|
|
- rtgui_win_is_activated(RTGUI_WIN(menu->select_item->sub_menu)))
|
|
|
|
- {
|
|
|
|
- return RT_TRUE;
|
|
|
|
- }
|
|
|
|
|
|
+ return RT_TRUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -73,29 +103,33 @@ static rt_bool_t rtgui_menu_on_deactivate(rtgui_widget_t* widget, rtgui_event_t*
|
|
}
|
|
}
|
|
|
|
|
|
/* if it's a submenu, try to hide parent menu */
|
|
/* if it's a submenu, try to hide parent menu */
|
|
- if (menu->parent_item != RT_NULL &&
|
|
|
|
- !rtgui_win_is_activated(RTGUI_WIN(menu->parent_item->parent_menu)))
|
|
|
|
|
|
+ if (menu->parent_menu != RT_NULL &&
|
|
|
|
+ !rtgui_win_is_activated(RTGUI_WIN(menu->parent_menu)))
|
|
{
|
|
{
|
|
rtgui_menu_on_deactivate(RTGUI_WIDGET(menu->parent_item->parent_menu), event);
|
|
rtgui_menu_on_deactivate(RTGUI_WIDGET(menu->parent_item->parent_menu), event);
|
|
}
|
|
}
|
|
|
|
|
|
- /* unselected all items */
|
|
|
|
- if (menu->select_item != RT_NULL)
|
|
|
|
- {
|
|
|
|
- // rtgui_menu_item_unselect(menu->select_item);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
return RT_TRUE;
|
|
return RT_TRUE;
|
|
}
|
|
}
|
|
|
|
|
|
-struct rtgui_menu* rtgui_menu_create(const char* title)
|
|
|
|
|
|
+struct rtgui_menu* rtgui_menu_create(const char* title, struct rtgui_menu* parent_menu,
|
|
|
|
+ const struct rtgui_menu_item* items, rt_uint16_t count)
|
|
{
|
|
{
|
|
|
|
+ rtgui_rect_t rect = {0, 0, 100, 100};
|
|
struct rtgui_menu* menu;
|
|
struct rtgui_menu* menu;
|
|
|
|
|
|
menu = (struct rtgui_menu*) rtgui_widget_create ( RTGUI_MENU_TYPE );
|
|
menu = (struct rtgui_menu*) rtgui_widget_create ( RTGUI_MENU_TYPE );
|
|
if (menu != RT_NULL)
|
|
if (menu != RT_NULL)
|
|
{
|
|
{
|
|
rtgui_win_set_title(RTGUI_WIN(menu), title);
|
|
rtgui_win_set_title(RTGUI_WIN(menu), title);
|
|
|
|
+ menu->parent_menu = parent_menu;
|
|
|
|
+ menu->items = items;
|
|
|
|
+ menu->items_count = count;
|
|
|
|
+
|
|
|
|
+ rtgui_widget_set_rect(RTGUI_WIDGET(menu), &rect);
|
|
|
|
+ rtgui_rect_inflate(&rect, -1);
|
|
|
|
+ /* create menu item list */
|
|
|
|
+ menu->items_list = rtgui_listctrl_create(items, count, &rect, _rtgui_menu_item_ondraw);
|
|
}
|
|
}
|
|
|
|
|
|
return menu;
|
|
return menu;
|
|
@@ -134,11 +168,6 @@ void rtgui_menu_pop(struct rtgui_menu* menu, int x, int y)
|
|
rect.y2 = y + menu->height;
|
|
rect.y2 = y + menu->height;
|
|
rtgui_win_set_rect(RTGUI_WIN(menu), &rect);
|
|
rtgui_win_set_rect(RTGUI_WIN(menu), &rect);
|
|
|
|
|
|
- /* layout box */
|
|
|
|
- box = (rtgui_box_t*) rtgui_container_get_first_child(RTGUI_CONTAINER(menu));
|
|
|
|
- RTGUI_WIDGET(box)->extent = rect;
|
|
|
|
- rtgui_box_layout(box);
|
|
|
|
-
|
|
|
|
/* on menu pop handler */
|
|
/* on menu pop handler */
|
|
if (menu->on_menupop != RT_NULL)
|
|
if (menu->on_menupop != RT_NULL)
|
|
{
|
|
{
|
|
@@ -149,80 +178,3 @@ void rtgui_menu_pop(struct rtgui_menu* menu, int x, int y)
|
|
rtgui_win_show(RTGUI_WIN(menu), RT_FALSE);
|
|
rtgui_win_show(RTGUI_WIN(menu), RT_FALSE);
|
|
}
|
|
}
|
|
|
|
|
|
-rtgui_menu_item_t* rtgui_menu_item_new(struct rtgui_menu* menu, char* text, int type,
|
|
|
|
- rt_bool_t (*on_menu)(rtgui_widget_t* widget, rtgui_event_t* event))
|
|
|
|
-{
|
|
|
|
- rtgui_menu_item_t* item;
|
|
|
|
-
|
|
|
|
- if (menu == RT_NULL) return RT_NULL;
|
|
|
|
- item = rtgui_menu_item_create(text);
|
|
|
|
- if (item == RT_NULL) return RT_NULL;
|
|
|
|
-
|
|
|
|
- item->type = type;
|
|
|
|
- item->image = RT_NULL;
|
|
|
|
- item->on_menuaction = on_menu;
|
|
|
|
-
|
|
|
|
- rtgui_menu_item_add(menu, item);
|
|
|
|
-
|
|
|
|
- return item;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-rtgui_menu_item_t* rtgui_menu_item_new_separator(struct rtgui_menu* menu)
|
|
|
|
-{
|
|
|
|
- rtgui_menu_item_t* item;
|
|
|
|
-
|
|
|
|
- if (menu == RT_NULL) return RT_NULL;
|
|
|
|
-
|
|
|
|
- item = rtgui_menu_item_create("--");
|
|
|
|
- if (item == RT_NULL) return RT_NULL;
|
|
|
|
-
|
|
|
|
- item->type = RTGUI_ITEM_SEPARATOR;
|
|
|
|
- item->image = RT_NULL;
|
|
|
|
- item->on_menuaction = RT_NULL;
|
|
|
|
-
|
|
|
|
- /* resize item extent */
|
|
|
|
- rtgui_widget_set_miniheight(RTGUI_WIDGET(item), 2);
|
|
|
|
- RTGUI_WIDGET(item)->extent.y2 = RTGUI_WIDGET(item)->extent.y1 + 2;
|
|
|
|
-
|
|
|
|
- rtgui_menu_item_add(menu, item);
|
|
|
|
-
|
|
|
|
- return item;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void rtgui_menu_item_add(struct rtgui_menu* menu, struct rtgui_menu_item* item)
|
|
|
|
-{
|
|
|
|
- rtgui_box_t* box;
|
|
|
|
-
|
|
|
|
- if (menu == RT_NULL || item == RT_NULL) return;
|
|
|
|
-
|
|
|
|
- box = (rtgui_box_t*) rtgui_container_get_first_child(RTGUI_CONTAINER(menu));
|
|
|
|
-
|
|
|
|
- menu->height += rtgui_rect_height(RTGUI_WIDGET(item)->extent);
|
|
|
|
- if (menu->width < rtgui_rect_width(RTGUI_WIDGET(item)->extent) + RTGUI_MENU_IMAGE_MAGIN + RTGUI_MENU_SUBMENU_MAGIN)
|
|
|
|
- {
|
|
|
|
- menu->width = rtgui_rect_width(RTGUI_WIDGET(item)->extent) + RTGUI_MENU_IMAGE_MAGIN + RTGUI_MENU_SUBMENU_MAGIN;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- item->parent_menu = menu;
|
|
|
|
- if (item->type == RTGUI_ITEM_SUBMENU)
|
|
|
|
- {
|
|
|
|
- item->sub_menu->parent_item = item;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- rtgui_box_append(box, RTGUI_WIDGET(item));
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-struct rtgui_menu_item* rtgui_menu_get_first_item(struct rtgui_menu* menu)
|
|
|
|
-{
|
|
|
|
- rtgui_box_t* box;
|
|
|
|
- rtgui_menu_item_t* item;
|
|
|
|
-
|
|
|
|
- if (menu == RT_NULL) return RT_NULL;
|
|
|
|
-
|
|
|
|
- box = (rtgui_box_t*) rtgui_container_get_first_child(RTGUI_CONTAINER(menu));
|
|
|
|
- if (box == RT_NULL) return RT_NULL;
|
|
|
|
-
|
|
|
|
- item = (rtgui_menu_item_t*) rtgui_container_get_first_child(RTGUI_CONTAINER(box));
|
|
|
|
-
|
|
|
|
- return item;
|
|
|
|
-}
|
|
|