void rtgui_menu_hiden(struct rtgui_menu* menu) { rtgui_win_hiden(RTGUI_WIN(menu)); if (menu->parent_menu != RT_NULL) rtgui_menu_hiden(menu->parent_menu); }
static rt_bool_t _rtgui_win_deal_close(struct rtgui_win *win, struct rtgui_event *event, rt_bool_t force_close) { if (win->on_close != RT_NULL) { if ((win->on_close(RTGUI_OBJECT(win), event) == RT_FALSE) && !force_close) return RT_FALSE; } rtgui_win_hiden(win); win->flag |= RTGUI_WIN_FLAG_CLOSED; if (win->flag & RTGUI_WIN_FLAG_MODAL) { rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL); } else if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE) { rtgui_win_destroy(win); } return RT_TRUE; }
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; }
static rt_bool_t rtgui_combobox_pulldown_hide(struct rtgui_object* object, struct rtgui_event* event) { struct rtgui_widget *widget; struct rtgui_combobox *box; RT_ASSERT(object != RT_NULL); RT_ASSERT(event != RT_NULL); widget = RTGUI_WIDGET(object); box = RTGUI_COMBOBOX(object); if (widget == RT_NULL) return RT_TRUE; box = (struct rtgui_combobox*) (((struct rtgui_win*)widget)->user_data); if (box == RT_NULL) return RT_TRUE; /* hide pull down window */ rtgui_win_hiden(RTGUI_WIN(box->pd_win)); /* clear pull down button state */ box->pd_pressed = RT_FALSE; rtgui_widget_update(RTGUI_WIDGET(box)); return RT_TRUE; }
void rtgui_menu_hiden(struct rtgui_menu* menu) { rtgui_win_hiden(RTGUI_WIN(menu)); /* un-select item */ menu->items_list->current_item = -1; if (menu->parent_menu != RT_NULL) rtgui_menu_hiden(menu->parent_menu); }
static rt_bool_t rtgui_menu_on_deactivate(struct rtgui_object *object, rtgui_event_t* event) { rtgui_menu_t* menu; RTGUI_WIDGET_EVENT_HANDLER_PREPARE menu = RTGUI_MENU(object); if (menu->parent_menu != RT_NULL) { /* whether click on parent menu */ if (rtgui_win_is_activated(RTGUI_WIN(menu->parent_menu)) == RT_TRUE && menu->parent_menu->items[menu->parent_menu->items_list->current_item].submenu == (struct rtgui_menu_item_t *)menu->items) return RT_TRUE; } /* submenu is activate */ if (menu->items[menu->items_list->current_item].type == RTGUI_ITEM_SUBMENU) { /* if sub menu activated, not hide menu. But we cannot use the * activated flag as criteria since the old window is deactivated * before the new window got activated. But the window will be shown in * this context, so use 'is not hide'. */ if (menu->sub_menu != RT_NULL && !RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(menu->sub_menu))) return RT_TRUE; } rtgui_win_hiden(RTGUI_WIN(menu)); if (menu->on_menuhide != RT_NULL) { menu->on_menuhide(RTGUI_OBJECT(menu), RT_NULL); } /* un-select item */ menu->items_list->current_item = -1; /* if it's a submenu, try to hide parent menu */ if (menu->parent_menu != RT_NULL && rtgui_win_is_activated(RTGUI_WIN(menu->parent_menu)) == RT_FALSE) { rtgui_menu_on_deactivate(RTGUI_OBJECT(menu->parent_menu), event); } return RT_TRUE; }
void rtgui_combobox_pdwin_onitem(struct rtgui_widget* widget, struct rtgui_event* event) { rtgui_win_t* pd_win; rtgui_combobox_t* combo; rtgui_listbox_t* list; list = RTGUI_LISTBOX(widget); pd_win = RTGUI_WIN(rtgui_widget_get_toplevel(widget)); combo = RTGUI_COMBOBOX(pd_win->user_data); combo->current_item = list->current_item; if (combo->on_selected != RT_NULL) combo->on_selected(RTGUI_WIDGET(combo), RT_NULL); rtgui_win_hiden(pd_win); rtgui_widget_update(RTGUI_WIDGET(combo)); return ; }
rt_bool_t rtgui_combobox_event_handler(struct rtgui_object* object, struct rtgui_event* event) { struct rtgui_combobox *box; RTGUI_WIDGET_EVENT_HANDLER_PREPARE box = RTGUI_COMBOBOX(object); switch (event->type) { case RTGUI_EVENT_PAINT: #ifndef RTGUI_USING_SMALL_SIZE if (widget->on_draw != RT_NULL) widget->on_draw(RTGUI_OBJECT(widget), event); else #endif rtgui_combobox_ondraw(box); break; case RTGUI_EVENT_MOUSE_BUTTON: return rtgui_combobox_onmouse_button(box, (struct rtgui_event_mouse*)event); case RTGUI_EVENT_FOCUSED: { /* item focused */ struct rtgui_event_focused* focused; focused = (struct rtgui_event_focused*) event; if (focused->widget != RT_NULL) { /* hide pull down window */ rtgui_win_hiden(RTGUI_WIN(box->pd_win)); rtgui_combobox_ondraw(box); } } break; default: return rtgui_widget_event_handler(object, event); } return RT_FALSE; }
static rt_bool_t rtgui_filelist_view_on_folder_item(rtgui_object_t* object, struct rtgui_event* event) { rtgui_win_t *menu; rtgui_listbox_t *listbox; rtgui_filelist_view_t *view; listbox = RTGUI_LISTBOX(object); menu = RTGUI_WIN(rtgui_widget_get_toplevel(RTGUI_WIDGET(object))); view = RTGUI_FILELIST_VIEW(menu->user_data); /* hide window */ rtgui_win_hiden(menu); switch (listbox->current_item) { case 0: { char* dir_ptr; /* destroy menu window */ rtgui_win_destroy(menu); dir_ptr = (char*) rtgui_malloc (256); rtgui_filelist_view_get_fullpath(view, dir_ptr, 256); rtgui_filelist_view_set_directory(view, dir_ptr); rtgui_free(dir_ptr); } break; case 1: /* destroy menu window */ rtgui_win_destroy(menu); break; default: /* destroy menu window */ rtgui_win_destroy(menu); break; } return RT_TRUE; }
rt_bool_t rtgui_combobox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { struct rtgui_combobox* box = (struct rtgui_combobox*)widget; switch (event->type) { case RTGUI_EVENT_PAINT: #ifndef RTGUI_USING_SMALL_SIZE if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); else #endif rtgui_combobox_ondraw(box); break; case RTGUI_EVENT_MOUSE_BUTTON: return rtgui_combobox_onmouse_button(box, (struct rtgui_event_mouse*)event); case RTGUI_EVENT_FOCUSED: { /* item focused */ struct rtgui_item* item; struct rtgui_event_focused* focused; focused = (struct rtgui_event_focused*) event; item = (struct rtgui_item*) (focused->widget); if (item != RT_NULL) { /* hide pull down window */ rtgui_win_hiden(RTGUI_WIN(box->pd_win)); rtgui_combobox_ondraw(box); } } break; } return RT_FALSE; }
static rt_bool_t rtgui_menu_on_deactivate(rtgui_widget_t* widget, rtgui_event_t* event) { rtgui_menu_t* menu = (rtgui_menu_t*) widget; if (menu->parent_menu != RT_NULL) { /* whether click on parent menu */ if (rtgui_win_is_activated(RTGUI_WIN(menu->parent_menu)) == RT_TRUE && menu->parent_menu->items[menu->parent_menu->items_list->current_item].submenu == (struct rtgui_menu_item_t *)menu->items) return RT_TRUE; } /* submenu is activate */ if (menu->items[menu->items_list->current_item].type == RTGUI_ITEM_SUBMENU) { /* if sub menu activated, not hide menu */ if (menu->sub_menu != RT_NULL && rtgui_win_is_activated(RTGUI_WIN(menu->sub_menu)) == RT_TRUE) return RT_TRUE; } rtgui_win_hiden(RTGUI_WIN(menu)); if (menu->on_menuhide != RT_NULL) { menu->on_menuhide(RTGUI_WIDGET(menu), RT_NULL); } /* un-select item */ menu->items_list->current_item = -1; /* if it's a submenu, try to hide parent menu */ if (menu->parent_menu != RT_NULL && rtgui_win_is_activated(RTGUI_WIN(menu->parent_menu)) == RT_FALSE) { rtgui_menu_on_deactivate(RTGUI_WIDGET(menu->parent_menu), event); } return RT_TRUE; }
rt_bool_t rtgui_combobox_pdwin_onitem(struct rtgui_object* object, struct rtgui_event* event) { struct rtgui_widget *widget; rtgui_win_t* pd_win; rtgui_combobox_t* combo; rtgui_listbox_t* list; RT_ASSERT(object != RT_NULL); widget = RTGUI_WIDGET(object); list = RTGUI_LISTBOX(widget); pd_win = RTGUI_WIN(rtgui_widget_get_toplevel(widget)); combo = RTGUI_COMBOBOX(pd_win->user_data); combo->current_item = list->current_item; if (combo->on_selected != RT_NULL) combo->on_selected(RTGUI_OBJECT(combo), RT_NULL); rtgui_win_hiden(pd_win); rtgui_widget_update(RTGUI_WIDGET(combo)); return RT_FALSE; }
rt_bool_t rtgui_win_event_handler(struct rtgui_object* object, struct rtgui_event* event) { struct rtgui_win* win; RT_ASSERT(object != RT_NULL); RT_ASSERT(event != RT_NULL); win = RTGUI_WIN(object); switch (event->type) { case RTGUI_EVENT_WIN_SHOW: rtgui_win_show(win, RT_FALSE); break; case RTGUI_EVENT_WIN_HIDE: rtgui_win_hiden(win); break; case RTGUI_EVENT_WIN_CLOSE: _rtgui_win_deal_close(win, event); /* don't broadcast WIN_CLOSE event to others */ return RT_TRUE; case RTGUI_EVENT_WIN_MOVE: { struct rtgui_event_win_move* emove = (struct rtgui_event_win_move*)event; /* move window */ rtgui_win_move(win, emove->x, emove->y); } break; case RTGUI_EVENT_WIN_ACTIVATE: if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win))) { /* activate a hide window */ return RT_TRUE; } win->flag |= RTGUI_WIN_FLAG_ACTIVATE; #ifndef RTGUI_USING_SMALL_SIZE if (RTGUI_WIDGET(object)->on_draw != RT_NULL) RTGUI_WIDGET(object)->on_draw(object, event); else #endif rtgui_widget_update(RTGUI_WIDGET(win)); if (win->on_activate != RT_NULL) { win->on_activate(RTGUI_OBJECT(object), event); } break; case RTGUI_EVENT_WIN_DEACTIVATE: if (win->flag & RTGUI_WIN_FLAG_MODAL) { /* FIXME: make modal concept clear and easy. See the comment of * rtgui_topwin_modal_enter. */ /* There are various reason that a modal window got deactivated: * 1, it has child windows and the user activate one of them. * 2, the application has more than one root window and the * user switched to one of the others. * * In any of the cases, we have nothing to do here. */ } else { win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE; #ifndef RTGUI_USING_SMALL_SIZE if (RTGUI_WIDGET(object)->on_draw != RT_NULL) RTGUI_WIDGET(object)->on_draw(object, event); else #endif rtgui_widget_update(RTGUI_WIDGET(win)); if (win->on_deactivate != RT_NULL) { win->on_deactivate(RTGUI_OBJECT(object), event); } } break; case RTGUI_EVENT_PAINT: #ifndef RTGUI_USING_SMALL_SIZE if (RTGUI_WIDGET(object)->on_draw != RT_NULL) RTGUI_WIDGET(object)->on_draw(object, event); else #endif rtgui_win_ondraw(win); break; case RTGUI_EVENT_MOUSE_BUTTON: /* check whether has widget which handled mouse event before */ if (win->last_mevent_widget != RT_NULL) { RTGUI_OBJECT(win->last_mevent_widget)->event_handler( RTGUI_OBJECT(win->last_mevent_widget), event); /* clean last mouse event handled widget */ win->last_mevent_widget = RT_NULL; } else if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win), (struct rtgui_event_mouse*)event) == RT_FALSE) { #ifndef RTGUI_USING_SMALL_SIZE if (RTGUI_WIDGET(object)->on_mouseclick != RT_NULL) { return RTGUI_WIDGET(object)->on_mouseclick(object, event); } #endif } break; case RTGUI_EVENT_MOUSE_MOTION: #if 0 if (rtgui_widget_dispatch_mouse_event(widget, (struct rtgui_event_mouse*)event) == RT_FALSE) { #ifndef RTGUI_USING_SMALL_SIZE /* handle event in current widget */ if (widget->on_mousemotion != RT_NULL) { return widget->on_mousemotion(widget, event); } #endif } else return RT_TRUE; #endif break; case RTGUI_EVENT_KBD: /* we should dispatch key event firstly */ if (!(win->flag & RTGUI_WIN_FLAG_HANDLE_KEY)) { rt_bool_t res = RT_FALSE; /* we should dispatch the key event just once. Once entered the * dispatch mode, we should swtich to key handling mode. */ win->flag |= RTGUI_WIN_FLAG_HANDLE_KEY; /* dispatch the key event */ if (win->focused_widget != RT_NULL && RTGUI_OBJECT(win->focused_widget)->event_handler != RT_NULL) res = RTGUI_OBJECT(win->focused_widget)->event_handler( RTGUI_OBJECT(win->focused_widget), event); /* if the focused widget doesn't handle it, I will handle it. */ if (res != RT_TRUE && win->on_key != RT_NULL) res = win->on_key(RTGUI_OBJECT(win), event); win->flag &= ~RTGUI_WIN_FLAG_HANDLE_KEY; return res; } else { /* in key handling mode(it may reach here in * win->focused_widget->event_handler call) */ if (win->on_key != RT_NULL) return win->on_key(RTGUI_OBJECT(win), event); } break; default: /* call parent event handler */ return rtgui_toplevel_event_handler(object, event); } return RT_FALSE; }
rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { struct rtgui_win* win = (struct rtgui_win*)widget; RT_ASSERT((win != RT_NULL) && (event != RT_NULL)); switch (event->type) { case RTGUI_EVENT_WIN_SHOW: rtgui_win_show(win, RT_FALSE); break; case RTGUI_EVENT_WIN_HIDE: rtgui_win_hiden(win); break; case RTGUI_EVENT_WIN_CLOSE: if (win->on_close != RT_NULL) { if (win->on_close(widget, event) == RT_FALSE) return RT_TRUE; } if (win->style & RTGUI_WIN_STYLE_MODAL) { rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL); } else { /* destroy window */ rtgui_win_destroy(win); } /* exit event loop */ return RT_TRUE; case RTGUI_EVENT_WIN_MOVE: { struct rtgui_event_win_move* emove = (struct rtgui_event_win_move*)event; /* move window */ rtgui_win_move(win, emove->x, emove->y); } break; case RTGUI_EVENT_WIN_ACTIVATE: if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win))) { /* activate a hide window */ return RT_TRUE; } win->style |= RTGUI_WIN_STYLE_ACTIVATE; #ifndef RTGUI_USING_SMALL_SIZE if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); else #endif rtgui_widget_update(RTGUI_WIDGET(win)); if (win->on_activate != RT_NULL) { win->on_activate(widget, event); } break; case RTGUI_EVENT_WIN_DEACTIVATE: if (win->style & RTGUI_WIN_STYLE_MODAL) { /* do not deactivate a modal win, re-send win-show event */ struct rtgui_event_win_show eshow; RTGUI_EVENT_WIN_SHOW_INIT(&eshow); eshow.wid = win; rtgui_thread_send(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&eshow), sizeof(struct rtgui_event_win_show)); } else { win->style &= ~RTGUI_WIN_STYLE_ACTIVATE; #ifndef RTGUI_USING_SMALL_SIZE if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); else #endif rtgui_win_ondraw(win); if (win->on_deactivate != RT_NULL) { win->on_deactivate(widget, event); } } break; case RTGUI_EVENT_PAINT: #ifndef RTGUI_USING_SMALL_SIZE if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); else #endif rtgui_win_ondraw(win); break; case RTGUI_EVENT_MOUSE_BUTTON: if (win->style & RTGUI_WIN_STYLE_UNDER_MODAL) { if (win->modal_widget != RT_NULL) return win->modal_widget->event_handler(win->modal_widget, event); } else if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win), (struct rtgui_event_mouse*)event) == RT_FALSE) { #ifndef RTGUI_USING_SMALL_SIZE if (widget->on_mouseclick != RT_NULL) { return widget->on_mouseclick(widget, event); } #endif } break; case RTGUI_EVENT_MOUSE_MOTION: #if 0 if (rtgui_widget_dispatch_mouse_event(widget, (struct rtgui_event_mouse*)event) == RT_FALSE) { #ifndef RTGUI_USING_SMALL_SIZE /* handle event in current widget */ if (widget->on_mousemotion != RT_NULL) { return widget->on_mousemotion(widget, event); } #endif } else return RT_TRUE; #endif break; case RTGUI_EVENT_KBD: if (win->style & RTGUI_WIN_STYLE_UNDER_MODAL) { if (win->modal_widget != RT_NULL) return win->modal_widget->event_handler(win->modal_widget, event); } else if (RTGUI_CONTAINER(win)->focused != widget) { RTGUI_CONTAINER(win)->focused->event_handler(RTGUI_CONTAINER(win)->focused, event); } break; default: /* call parent event handler */ return rtgui_toplevel_event_handler(widget, event); } return RT_FALSE; }
rt_bool_t rtgui_combobox_pdwin_ondeactive(struct rtgui_widget* widget, struct rtgui_event* event) { rtgui_win_hiden(RTGUI_WIN(widget)); return RT_TRUE; }
rt_bool_t rtgui_combobox_pdwin_ondeactive(struct rtgui_object* object, struct rtgui_event* event) { rtgui_win_hiden(RTGUI_WIN(object)); return RT_TRUE; }