static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object, struct rtgui_event *event) { RT_ASSERT(object != RT_NULL); RT_ASSERT(event != RT_NULL); /* dispatch event */ switch (event->type) { case RTGUI_EVENT_APP_CREATE: case RTGUI_EVENT_APP_DESTROY: if (rtgui_wm_application != RT_NULL) { /* forward event to wm application */ rtgui_send(rtgui_wm_application->tid, event, sizeof(struct rtgui_event_application)); } else { /* always ack with OK */ rtgui_ack(event, RTGUI_STATUS_OK); } break; /* mouse and keyboard event */ case RTGUI_EVENT_MOUSE_MOTION: /* handle mouse motion event */ rtgui_server_handle_mouse_motion((struct rtgui_event_mouse *)event); break; case RTGUI_EVENT_MOUSE_BUTTON: /* handle mouse button */ rtgui_server_handle_mouse_btn((struct rtgui_event_mouse *)event); break; case RTGUI_EVENT_KBD: /* handle keyboard event */ rtgui_server_handle_kbd((struct rtgui_event_kbd *)event); break; /* window event */ case RTGUI_EVENT_WIN_CREATE: if (rtgui_topwin_add((struct rtgui_event_win_create *)event) == RT_EOK) rtgui_ack(event, RTGUI_STATUS_OK); else rtgui_ack(event, RTGUI_STATUS_ERROR); break; case RTGUI_EVENT_WIN_SHOW: if (rtgui_topwin_show((struct rtgui_event_win *)event) == RT_EOK) rtgui_ack(event, RTGUI_STATUS_OK); else rtgui_ack(event, RTGUI_STATUS_ERROR); break; case RTGUI_EVENT_WIN_HIDE: if (rtgui_topwin_hide((struct rtgui_event_win *)event) == RT_EOK) rtgui_ack(event, RTGUI_STATUS_OK); else rtgui_ack(event, RTGUI_STATUS_ERROR); break; case RTGUI_EVENT_WIN_MOVE: if (rtgui_topwin_move((struct rtgui_event_win_move *)event) == RT_EOK) rtgui_ack(event, RTGUI_STATUS_OK); else rtgui_ack(event, RTGUI_STATUS_ERROR); break; case RTGUI_EVENT_WIN_MODAL_ENTER: if (rtgui_topwin_modal_enter((struct rtgui_event_win_modal_enter *)event) == RT_EOK) rtgui_ack(event, RTGUI_STATUS_OK); else rtgui_ack(event, RTGUI_STATUS_ERROR); break; case RTGUI_EVENT_WIN_ACTIVATE: if (rtgui_topwin_activate((struct rtgui_event_win_activate *)event) == RT_EOK) rtgui_ack(event, RTGUI_STATUS_OK); else rtgui_ack(event, RTGUI_STATUS_ERROR); break; case RTGUI_EVENT_WIN_DESTROY: if (last_monitor_topwin != RT_NULL && last_monitor_topwin->wid == ((struct rtgui_event_win *)event)->wid) last_monitor_topwin = RT_NULL; if (rtgui_topwin_remove(((struct rtgui_event_win *)event)->wid) == RT_EOK) rtgui_ack(event, RTGUI_STATUS_OK); else rtgui_ack(event, RTGUI_STATUS_ERROR); break; case RTGUI_EVENT_WIN_RESIZE: rtgui_topwin_resize(((struct rtgui_event_win_resize *)event)->wid, &(((struct rtgui_event_win_resize *)event)->rect)); break; case RTGUI_EVENT_SET_WM: if (rtgui_wm_application != RT_NULL) { rtgui_ack(event, RTGUI_STATUS_ERROR); } else { struct rtgui_event_set_wm *set_wm; set_wm = (struct rtgui_event_set_wm *) event; rtgui_wm_application = set_wm->app; rtgui_ack(event, RTGUI_STATUS_OK); } break; /* other event */ case RTGUI_EVENT_COMMAND: break; case RTGUI_EVENT_UPDATE_BEGIN: #ifdef RTGUI_USING_MOUSE_CURSOR /* hide cursor */ rtgui_mouse_hide_cursor(); #endif break; case RTGUI_EVENT_UPDATE_END: /* handle screen update */ rtgui_server_handle_update((struct rtgui_event_update_end *)event); #ifdef RTGUI_USING_MOUSE_CURSOR /* show cursor */ rtgui_mouse_show_cursor(); #endif break; case RTGUI_EVENT_MONITOR_ADD: /* handle mouse monitor */ rtgui_server_handle_monitor_add((struct rtgui_event_monitor *)event); break; default: rt_kprintf("RTGUI: wrong event sent to server: %d", event->type); return RT_FALSE; } return RT_TRUE; }
struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner) { struct rtgui_dc* dc; rtgui_widget_t* widget; /* adjudge owner */ if (owner == RT_NULL || owner->toplevel == RT_NULL) return RT_NULL; if (!RTGUI_IS_TOPLEVEL(owner->toplevel)) return RT_NULL; dc = RTGUI_WIDGET_DC(owner); /* set init visible as true */ RTGUI_WIDGET_DC_SET_VISIBLE(owner); /* check widget visible */ widget = owner; while (widget != RT_NULL) { if (RTGUI_WIDGET_IS_HIDE(widget)) { RTGUI_WIDGET_DC_SET_UNVISIBLE(owner); break; } widget = widget->parent; } if (RTGUI_IS_WINTITLE(owner->toplevel)) { rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel); top->drawing ++; if (top->drawing == 1) { #ifdef RTGUI_USING_MOUSE_CURSOR #ifdef __WIN32__ rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER); rt_kprintf("hide cursor\n"); rtgui_mouse_hide_cursor(); #else /* hide cursor */ rtgui_mouse_hide_cursor(); #endif #endif } } else if (RTGUI_IS_WORKBENCH(owner->toplevel) || RTGUI_IS_WIN(owner->toplevel)) { rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel); top->drawing ++; if (top->drawing == 1) { #ifdef __WIN32__ #ifdef RTGUI_USING_MOUSE_CURSOR rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER); rt_kprintf("hide cursor\n"); rtgui_mouse_hide_cursor(); #endif #else /* send draw begin to server */ struct rtgui_event_update_begin eupdate; RTGUI_EVENT_UPDATE_BEGIN_INIT(&(eupdate)); eupdate.rect = RTGUI_WIDGET(top)->extent; rtgui_thread_send(top->server, (struct rtgui_event*)&eupdate, sizeof(eupdate)); #endif } } return dc; }
struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner) { struct rtgui_dc_hw* dc; rtgui_widget_t* widget; /* adjudge owner */ if (owner == RT_NULL || owner->toplevel == RT_NULL) return RT_NULL; if (!RTGUI_IS_TOPLEVEL(owner->toplevel)) return RT_NULL; /* set init visible as true */ RTGUI_WIDGET_DC_SET_VISIBLE(owner); /* check widget visible */ widget = owner; while (widget != RT_NULL) { if (RTGUI_WIDGET_IS_HIDE(widget)) { RTGUI_WIDGET_DC_SET_UNVISIBLE(owner); return RT_NULL; } widget = widget->parent; } if (!RTGUI_WIDGET_IS_DC_VISIBLE(owner)) return RT_NULL; /* create DC */ dc = (struct rtgui_dc_hw*) rtgui_malloc(sizeof(struct rtgui_dc_hw)); dc->parent.type = RTGUI_DC_HW; dc->parent.engine = &dc_hw_engine; dc->owner = owner; dc->hw_driver = rtgui_graphic_driver_get_default(); if (RTGUI_IS_WINTITLE(owner->toplevel)) { rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel); top->drawing ++; if (top->drawing == 1) { #ifdef RTGUI_USING_MOUSE_CURSOR #ifdef _WIN32 rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER); rt_kprintf("hide cursor\n"); rtgui_mouse_hide_cursor(); #else /* hide cursor */ rtgui_mouse_hide_cursor(); #endif #endif } } else if (RTGUI_IS_APPLICATION(owner->toplevel) || RTGUI_IS_WIN(owner->toplevel)) { rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel); top->drawing ++; if (top->drawing == 1) { #ifdef _WIN32 #ifdef RTGUI_USING_MOUSE_CURSOR rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER); rt_kprintf("hide cursor\n"); rtgui_mouse_hide_cursor(); #endif #else /* send draw begin to server */ struct rtgui_event_update_begin eupdate; RTGUI_EVENT_UPDATE_BEGIN_INIT(&(eupdate)); eupdate.rect = RTGUI_WIDGET(top)->extent; rtgui_server_post_event((struct rtgui_event*)&eupdate, sizeof(eupdate)); #endif } } return &(dc->parent); }