void rtgui_win_destroy(struct rtgui_win* win) { /* close the window first if it's not. */ if (!(win->flag & RTGUI_WIN_FLAG_CLOSED)) { struct rtgui_event_win_close eclose; RTGUI_EVENT_WIN_CLOSE_INIT(&eclose); eclose.wid = win; if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE) { _rtgui_win_deal_close(win, (struct rtgui_event*)&eclose, RT_TRUE); return; } else _rtgui_win_deal_close(win, (struct rtgui_event*)&eclose, RT_TRUE); } if (win->flag & RTGUI_WIN_FLAG_MODAL) { /* set the RTGUI_WIN_STYLE_DESTROY_ON_CLOSE flag so the window will be * destroyed after the event_loop */ win->style |= RTGUI_WIN_STYLE_DESTROY_ON_CLOSE; rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL); } else { rtgui_widget_destroy(RTGUI_WIDGET(win)); } }
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; }
void rtgui_win_destroy(struct rtgui_win* win) { if (win->flag & RTGUI_WIN_FLAG_MODAL) { /* set the RTGUI_WIN_STYLE_DESTROY_ON_CLOSE flag so the window will be * destroyed after the event_loop */ win->style |= RTGUI_WIN_STYLE_DESTROY_ON_CLOSE; rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL); } else rtgui_widget_destroy(RTGUI_WIDGET(win)); }
void rtgui_win_destroy(struct rtgui_win* win) { if (win->style & RTGUI_WIN_STYLE_MODAL) { /* end modal */ rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL); } else { rtgui_widget_destroy(RTGUI_WIDGET(win)); } }
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; }