void rtgui_win_move(struct rtgui_win* win, int x, int y) { struct rtgui_event_win_move emove; RTGUI_EVENT_WIN_MOVE_INIT(&emove); if (win == RT_NULL) return; /* move window to logic position */ rtgui_widget_move_to_logic(RTGUI_WIDGET(win), x - RTGUI_WIDGET(win)->extent.x1, y - RTGUI_WIDGET(win)->extent.y1); if (win->flag & RTGUI_WIN_FLAG_CONNECTED) { /* set win hide firstly */ RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win)); emove.wid = win; emove.x = x; emove.y = y; if (rtgui_server_post_event_sync(RTGUI_EVENT(&emove), sizeof(struct rtgui_event_win_move)) != RT_EOK) { return; } } /* set window visible */ RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win)); return; }
void rtgui_workbench_show_view(rtgui_workbench_t* workbench, rtgui_view_t* view) { RT_ASSERT(workbench != RT_NULL); RT_ASSERT(view != RT_NULL); /* already shown */ if (workbench->current_view == view) return; if (workbench->current_view != RT_NULL) { /* hide old view */ RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench->current_view)); } /* show view */ RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(view)); workbench->current_view = view; /* update workbench clip */ rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench)); if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(workbench))) { rtgui_widget_update(RTGUI_WIDGET(view)); } }
rt_err_t rtgui_workbench_show(rtgui_workbench_t* workbench) { RT_ASSERT(workbench != RT_NULL); if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL) { struct rtgui_event_panel_show eraise; RTGUI_EVENT_PANEL_SHOW_INIT(&eraise); eraise.workbench = workbench; eraise.panel = workbench->panel; if (rtgui_thread_send_sync(workbench->parent.server, RTGUI_EVENT(&eraise), sizeof(struct rtgui_event_panel_show)) != RT_EOK) return -RT_ERROR; RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(workbench)); rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench)); } else return -RT_ERROR; return RT_EOK; }
rt_base_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal) { struct rtgui_event_win_show eshow; rt_base_t exit_code = -1; RTGUI_EVENT_WIN_SHOW_INIT(&eshow); eshow.wid = win; if (win == RT_NULL) return exit_code; /* if it does not register into server, create it in server */ if (!(win->flag & RTGUI_WIN_FLAG_CONNECTED)) { if (_rtgui_win_create_in_server(win) == RT_FALSE) return exit_code; } if (rtgui_server_post_event_sync(RTGUI_EVENT(&eshow), sizeof(struct rtgui_event_win_show) ) != RT_EOK) { rt_kprintf("show win failed\n"); return exit_code; } /* set window unhidden */ RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win)); if (win->focused_widget == RT_NULL) rtgui_widget_focus(RTGUI_WIDGET(win)); if (is_modal == RT_TRUE) { struct rtgui_application *app; struct rtgui_event_win_modal_enter emodal; RTGUI_EVENT_WIN_MODAL_ENTER_INIT(&emodal); emodal.wid = win; app = rtgui_application_self(); RT_ASSERT(app != RT_NULL); win->flag |= RTGUI_WIN_FLAG_MODAL; if (rtgui_server_post_event_sync((struct rtgui_event*)&emodal, sizeof(emodal)) != RT_EOK) return exit_code; app->modal_object = RTGUI_OBJECT(win); exit_code = rtgui_application_run(app); app->modal_object = RT_NULL; win->flag &= ~RTGUI_WIN_FLAG_MODAL; if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE) { rtgui_win_destroy(win); } } return exit_code; }
rtgui_modal_code_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal) { rtgui_modal_code_t result; RT_ASSERT(win != RT_NULL); result = RTGUI_MODAL_CANCEL; /* if it does not register into server, create it in server */ if (RTGUI_TOPLEVEL(win)->server == RT_NULL) { if (_rtgui_win_create_in_server(win) == RT_FALSE) return result; } if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win))) { /* send show message to server */ struct rtgui_event_win_show eshow; RTGUI_EVENT_WIN_SHOW_INIT(&eshow); eshow.wid = win; if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&eshow), sizeof(struct rtgui_event_win_show)) != RT_EOK) { /* hide window failed */ return result; } /* set window unhidden */ RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win)); } else rtgui_widget_update(RTGUI_WIDGET(win)); if (is_modal == RT_TRUE) { if (win->parent_toplevel != RT_NULL) { rtgui_widget_t *parent_widget; /* set style */ win->style |= RTGUI_WIN_STYLE_MODAL; /* get root toplevel */ parent_widget = RTGUI_WIDGET(win->parent_toplevel); if (RTGUI_IS_WORKBENCH(parent_widget)) { rtgui_workbench_t* workbench; workbench = RTGUI_WORKBENCH(win->parent_toplevel); workbench->flag |= RTGUI_WORKBENCH_FLAG_MODAL_MODE; workbench->modal_widget = RTGUI_WIDGET(win); rtgui_workbench_event_loop(workbench); result = workbench->modal_code; workbench->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE; workbench->modal_widget = RT_NULL; } else if (RTGUI_IS_WIN(parent_widget)) { rtgui_win_t* parent_win; parent_win = RTGUI_WIN(win->parent_toplevel); parent_win->style |= RTGUI_WIN_STYLE_UNDER_MODAL; parent_win->modal_widget = RTGUI_WIDGET(win); rtgui_win_event_loop(parent_win); result = parent_win->modal_code; parent_win->style &= ~RTGUI_WIN_STYLE_UNDER_MODAL; parent_win->modal_widget = RT_NULL; } } else { /* which is a root window */ win->style |= RTGUI_WIN_STYLE_MODAL; rtgui_win_event_loop(win); result = win->modal_code; win->style &= ~RTGUI_WIN_STYLE_MODAL; } } return result; }
rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* event) { struct rtgui_workbench* workbench = (struct rtgui_workbench*)widget; switch (event->type) { case RTGUI_EVENT_PANEL_DETACH: RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench)); RTGUI_TOPLEVEL(workbench)->server = RT_NULL; return RT_TRUE; case RTGUI_EVENT_PANEL_SHOW: /* show workbench in server */ rtgui_workbench_show(workbench); break; case RTGUI_EVENT_PANEL_HIDE: /* hide widget */ RTGUI_WIDGET_HIDE(widget); break; case RTGUI_EVENT_MOUSE_MOTION: { struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event; struct rtgui_toplevel* top = RTGUI_TOPLEVEL(emouse->wid); /* check the destination window */ if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL) { RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event); } else { /* let viewer to handle it */ rtgui_view_t* view = workbench->current_view; if (view != RT_NULL && RTGUI_WIDGET(view)->event_handler != RT_NULL) { RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event); } } } break; case RTGUI_EVENT_MOUSE_BUTTON: { struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event; struct rtgui_toplevel* top = RTGUI_TOPLEVEL(emouse->wid); /* check the destination window */ if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL) { RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event); } else { if (RTGUI_WORKBENCH_IS_MODAL_MODE(workbench)) { /* let modal widget to handle it */ if (workbench->modal_widget != RT_NULL && workbench->modal_widget->event_handler != RT_NULL) { workbench->modal_widget->event_handler(workbench->modal_widget, event); } } else { /* let viewer to handle it */ rtgui_view_t* view = workbench->current_view; if (view != RT_NULL && RTGUI_WIDGET(view)->event_handler != RT_NULL) { RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event); } } } } break; case RTGUI_EVENT_KBD: { struct rtgui_event_kbd* kbd = (struct rtgui_event_kbd*)event; struct rtgui_toplevel* top = RTGUI_TOPLEVEL(kbd->wid); /* check the destination window */ if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL) { RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event); } else { if (RTGUI_WORKBENCH_IS_MODAL_MODE(workbench)) { /* let modal widget to handle it */ if (workbench->modal_widget != RT_NULL && workbench->modal_widget->event_handler != RT_NULL) { workbench->modal_widget->event_handler(workbench->modal_widget, event); } } else { if (RTGUI_CONTAINER(widget)->focused == widget) { /* set focused widget to the current view */ if (workbench->current_view != RT_NULL) rtgui_widget_focus(RTGUI_WIDGET(RTGUI_CONTAINER(workbench->current_view)->focused)); } return rtgui_toplevel_event_handler(widget, event); } } } break; case RTGUI_EVENT_PAINT: { struct rtgui_event_paint* epaint = (struct rtgui_event_paint*)event; struct rtgui_toplevel* top = RTGUI_TOPLEVEL(epaint->wid); /* check the destination window */ if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL) { RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event); } else { rtgui_view_t* view; /* un-hide workbench */ RTGUI_WIDGET_UNHIDE(widget); /* paint a view */ view = workbench->current_view; if (view != RT_NULL) { /* remake a paint event */ RTGUI_EVENT_PAINT_INIT(epaint); epaint->wid = RT_NULL; /* send this event to the view */ if (RTGUI_WIDGET(view)->event_handler != RT_NULL) { RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event); } } else { struct rtgui_dc* dc; struct rtgui_rect rect; dc = rtgui_dc_begin_drawing(widget); rtgui_widget_get_rect(widget, &rect); rtgui_dc_fill_rect(dc, &rect); rtgui_dc_end_drawing(dc); } } } break; case RTGUI_EVENT_CLIP_INFO: { struct rtgui_event_clip_info* eclip = (struct rtgui_event_clip_info*)event; struct rtgui_widget* dest_widget = RTGUI_WIDGET(eclip->wid); if (dest_widget != RT_NULL && dest_widget->event_handler != RT_NULL) { dest_widget->event_handler(dest_widget, event); } else { return rtgui_toplevel_event_handler(widget, event); } } break; case RTGUI_EVENT_WIN_CLOSE: case RTGUI_EVENT_WIN_ACTIVATE: case RTGUI_EVENT_WIN_DEACTIVATE: { struct rtgui_event_win* wevent = (struct rtgui_event_win*)event; struct rtgui_widget* dest_widget = RTGUI_WIDGET(wevent->wid); if (dest_widget != RT_NULL && dest_widget->event_handler != RT_NULL) { dest_widget->event_handler(dest_widget, event); } } break; case RTGUI_EVENT_WIN_MOVE: { struct rtgui_event_win_move* wevent = (struct rtgui_event_win_move*)event; struct rtgui_toplevel* top = RTGUI_TOPLEVEL(wevent->wid); if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL) { RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event); } } break; default: return rtgui_toplevel_event_handler(widget, event); } return RT_TRUE; }