diff options
| author | [email protected] <[email protected]> | 2012-07-20 12:37:56 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-07-20 12:37:56 +0000 |
| commit | 92a50c838d8ca2ae4027fd77b71db12fb52d86e3 (patch) | |
| tree | 08cb5a9273c78c36df97f48eea17eb2e1034a497 /components/rtgui/server | |
| parent | c2868be90d0f1f43ee13bacdb1c0f55a9fe34276 (diff) | |
sync with RTGUI c074ff2898b9e
Full log is in GitHub.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2222 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/rtgui/server')
| -rw-r--r-- | components/rtgui/server/driver.c | 4 | ||||
| -rw-r--r-- | components/rtgui/server/mouse.c | 30 | ||||
| -rw-r--r-- | components/rtgui/server/rtgui_application.c | 677 | ||||
| -rw-r--r-- | components/rtgui/server/server.c | 144 | ||||
| -rw-r--r-- | components/rtgui/server/topwin.c | 303 | ||||
| -rw-r--r-- | components/rtgui/server/topwin.h | 4 |
6 files changed, 294 insertions, 868 deletions
diff --git a/components/rtgui/server/driver.c b/components/rtgui/server/driver.c index 67e4aee909..1b35e4f6fc 100644 --- a/components/rtgui/server/driver.c +++ b/components/rtgui/server/driver.c @@ -88,3 +88,7 @@ rt_uint8_t* rtgui_graphic_driver_get_framebuffer(const struct rtgui_graphic_driv return (rt_uint8_t*)driver->framebuffer; } +rt_uint8_t* rtgui_graphic_driver_get_default_framebuffer(void) +{ + return rtgui_graphic_driver_get_framebuffer(&_driver); +} diff --git a/components/rtgui/server/mouse.c b/components/rtgui/server/mouse.c index c7a05aac4b..9acc989617 100644 --- a/components/rtgui/server/mouse.c +++ b/components/rtgui/server/mouse.c @@ -52,9 +52,6 @@ struct rtgui_cursor rt_uint8_t *win_top, *win_bottom; rt_bool_t win_rect_show, win_rect_has_saved; #endif - - /* screen framebuffer */ - rt_uint8_t* framebuffer; }; struct rtgui_cursor* _rtgui_cursor; @@ -140,7 +137,6 @@ void rtgui_mouse_init() /* init cursor */ _rtgui_cursor->bpp = gd->bits_per_pixel/8; - _rtgui_cursor->framebuffer = rtgui_graphic_driver_get_framebuffer(gd); _rtgui_cursor->screen_pitch = _rtgui_cursor->bpp * gd->width; #ifdef RTGUI_USING_MOUSE_CURSOR @@ -300,7 +296,7 @@ static void rtgui_cursor_restore() rt_base_t idx, height, cursor_pitch; rt_uint8_t *cursor_ptr, *fb_ptr; - fb_ptr = _rtgui_cursor->framebuffer + _rtgui_cursor->cy * _rtgui_cursor->screen_pitch + fb_ptr = rtgui_graphic_driver_get_default_framebuffer() + _rtgui_cursor->cy * _rtgui_cursor->screen_pitch + _rtgui_cursor->cx * _rtgui_cursor->bpp; cursor_ptr = _rtgui_cursor->cursor_saved; @@ -327,7 +323,7 @@ static void rtgui_cursor_save() rt_base_t idx, height, cursor_pitch; rt_uint8_t *cursor_ptr, *fb_ptr; - fb_ptr = _rtgui_cursor->framebuffer + _rtgui_cursor->cy * _rtgui_cursor->screen_pitch + + fb_ptr = _driver_get_default_framebuffer() + _rtgui_cursor->cy * _rtgui_cursor->screen_pitch + _rtgui_cursor->cx * _rtgui_cursor->bpp; cursor_ptr = _rtgui_cursor->cursor_saved; @@ -488,10 +484,11 @@ static void rtgui_winrect_show() static void rtgui_winrect_restore() { - rt_uint8_t *winrect_ptr, *fb_ptr; + rt_uint8_t *winrect_ptr, *fb_ptr, *driver_fb; int winrect_pitch, idx; rtgui_rect_t screen_rect, win_rect; + driver_fb = rtgui_graphic_driver_get_default_framebuffer(); win_rect = _rtgui_cursor->win_rect; rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), @@ -499,7 +496,7 @@ static void rtgui_winrect_restore() rtgui_rect_intersect(&screen_rect, &win_rect); /* restore winrect left */ - fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch + + fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch + win_rect.x1 * _rtgui_cursor->bpp; winrect_ptr = _rtgui_cursor->win_left; winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp; @@ -507,7 +504,7 @@ static void rtgui_winrect_restore() (win_rect.y2 - win_rect.y1), winrect_pitch); /* restore winrect right */ - fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch + + fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch + (win_rect.x2 - WIN_MOVE_BORDER) * _rtgui_cursor->bpp; winrect_ptr = _rtgui_cursor->win_right; winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp; @@ -515,7 +512,7 @@ static void rtgui_winrect_restore() (win_rect.y2 - win_rect.y1), winrect_pitch); /* restore winrect top */ - fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch + + fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch + (win_rect.x1 + WIN_MOVE_BORDER)* _rtgui_cursor->bpp; winrect_ptr = _rtgui_cursor->win_top; winrect_pitch = (win_rect.x2 - win_rect.x1 - 2 * WIN_MOVE_BORDER) * _rtgui_cursor->bpp; @@ -523,7 +520,7 @@ static void rtgui_winrect_restore() WIN_MOVE_BORDER, winrect_pitch); /* restore winrect bottom */ - fb_ptr = _rtgui_cursor->framebuffer + (win_rect.y2 - WIN_MOVE_BORDER) * _rtgui_cursor->screen_pitch + + fb_ptr = driver_fb + (win_rect.y2 - WIN_MOVE_BORDER) * _rtgui_cursor->screen_pitch + (win_rect.x1 + WIN_MOVE_BORDER) * _rtgui_cursor->bpp; winrect_ptr = _rtgui_cursor->win_bottom; display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch, @@ -532,10 +529,11 @@ static void rtgui_winrect_restore() static void rtgui_winrect_save() { - rt_uint8_t *winrect_ptr, *fb_ptr; + rt_uint8_t *winrect_ptr, *fb_ptr, *driver_fb; int winrect_pitch, idx; rtgui_rect_t screen_rect, win_rect; + driver_fb = rtgui_graphic_driver_get_default_framebuffer(); win_rect = _rtgui_cursor->win_rect; rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), @@ -546,7 +544,7 @@ static void rtgui_winrect_save() _rtgui_cursor->win_rect_has_saved = RT_TRUE; /* save winrect left */ - fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch + + fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch + win_rect.x1 * _rtgui_cursor->bpp; winrect_ptr = _rtgui_cursor->win_left; winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp; @@ -554,7 +552,7 @@ static void rtgui_winrect_save() (win_rect.y2 - win_rect.y1), winrect_pitch); /* save winrect right */ - fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch + + fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch + (win_rect.x2 - WIN_MOVE_BORDER) * _rtgui_cursor->bpp; winrect_ptr = _rtgui_cursor->win_right; winrect_pitch = WIN_MOVE_BORDER * _rtgui_cursor->bpp; @@ -562,7 +560,7 @@ static void rtgui_winrect_save() (win_rect.y2 - win_rect.y1), winrect_pitch); /* save winrect top */ - fb_ptr = _rtgui_cursor->framebuffer + win_rect.y1 * _rtgui_cursor->screen_pitch + + fb_ptr = driver_fb + win_rect.y1 * _rtgui_cursor->screen_pitch + (win_rect.x1 + WIN_MOVE_BORDER)* _rtgui_cursor->bpp; winrect_ptr = _rtgui_cursor->win_top; winrect_pitch = (win_rect.x2 - win_rect.x1 - 2 * WIN_MOVE_BORDER) * _rtgui_cursor->bpp; @@ -570,7 +568,7 @@ static void rtgui_winrect_save() WIN_MOVE_BORDER, winrect_pitch); /* save winrect bottom */ - fb_ptr = _rtgui_cursor->framebuffer + (win_rect.y2 - WIN_MOVE_BORDER) * _rtgui_cursor->screen_pitch + + fb_ptr = driver_fb + (win_rect.y2 - WIN_MOVE_BORDER) * _rtgui_cursor->screen_pitch + (win_rect.x1 + WIN_MOVE_BORDER) * _rtgui_cursor->bpp; winrect_ptr = _rtgui_cursor->win_bottom; display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch, diff --git a/components/rtgui/server/rtgui_application.c b/components/rtgui/server/rtgui_application.c deleted file mode 100644 index 5aa32433af..0000000000 --- a/components/rtgui/server/rtgui_application.c +++ /dev/null @@ -1,677 +0,0 @@ -/* - * File : rtgui_application.c - * This file is part of RTGUI in RT-Thread RTOS - * COPYRIGHT (C) 2012, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2012-01-13 Grissiom first version(just a prototype of application API) - */ - -#include <rtgui/rtgui_system.h> -#include <rtgui/rtgui_application.h> -#include <rtgui/widgets/window.h> - -#ifdef _WIN32 -#define RTGUI_EVENT_DEBUG -#endif - -#ifdef RTGUI_EVENT_DEBUG -const char *event_string[] = -{ - /* window event */ - "WIN_CREATE", /* create a window */ - "WIN_DESTROY", /* destroy a window */ - "WIN_SHOW", /* show a window */ - "WIN_HIDE", /* hide a window */ - "WIN_ACTIVATE", /* activate a window */ - "WIN_DEACTIVATE", /* deactivate a window */ - "WIN_CLOSE", /* close a window */ - "WIN_MOVE", /* move a window */ - "WIN_RESIZE", /* resize a window */ - "WIN_MODAL_ENTER", /* a window modals */ - - "SET_WM", /* set window manager */ - - "UPDATE_BEGIN", /* begin of update rect */ - "UPDATE_END", /* end of update rect */ - "MONITOR_ADD", /* add a monitor rect */ - "MONITOR_REMOVE", /* remove a monitor rect*/ - "PAINT", /* paint on screen */ - "TIMER", /* timer */ - - /* clip rect information */ - "CLIP_INFO", /* clip rect info */ - - /* mouse and keyboard event */ - "MOUSE_MOTION", /* mouse motion */ - "MOUSE_BUTTON", /* mouse button info */ - "KBD", /* keyboard info */ - - /* user command event */ - "COMMAND", /* user command */ - - /* request's status event */ - "STATUS", /* request result */ - "SCROLLED", /* scroll bar scrolled */ - "RESIZE", /* widget resize */ -}; - -#define DBG_MSG(x) rt_kprintf x - -static void rtgui_event_dump(rt_thread_t tid, rtgui_event_t* event) -{ - char* sender = "(unknown)"; - - if ((event->type == RTGUI_EVENT_TIMER) || - (event->type == RTGUI_EVENT_UPDATE_BEGIN) || - (event->type == RTGUI_EVENT_MOUSE_MOTION) || - (event->type == RTGUI_EVENT_UPDATE_END)) - { - /* don't dump timer event */ - return ; - } - - if (event->sender != RT_NULL) - sender = event->sender->name; - - rt_kprintf("%s -- %s --> %s ", sender, event_string[event->type], tid->name); - switch (event->type) - { - case RTGUI_EVENT_PAINT: - { - struct rtgui_event_paint *paint = (struct rtgui_event_paint *)event; - - if(paint->wid != RT_NULL) - rt_kprintf("win: %s", paint->wid->title); - } - break; - - case RTGUI_EVENT_KBD: - { - struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd*) event; - if (ekbd->wid != RT_NULL) - rt_kprintf("win: %s", ekbd->wid->title); - if (RTGUI_KBD_IS_UP(ekbd)) rt_kprintf(", up"); - else rt_kprintf(", down"); - } - break; - - case RTGUI_EVENT_CLIP_INFO: - { - struct rtgui_event_clip_info *info = (struct rtgui_event_clip_info *)event; - - if(info->wid != RT_NULL) - rt_kprintf("win: %s", info->wid->title); - } - break; - - case RTGUI_EVENT_WIN_CREATE: - { - struct rtgui_event_win_create *create = (struct rtgui_event_win_create*)event; - - rt_kprintf(" win: %s at (x1:%d, y1:%d, x2:%d, y2:%d), addr: %p", -#ifdef RTGUI_USING_SMALL_SIZE - create->wid->title, - RTGUI_WIDGET(create->wid)->extent.x1, - RTGUI_WIDGET(create->wid)->extent.y1, - RTGUI_WIDGET(create->wid)->extent.x2, - RTGUI_WIDGET(create->wid)->extent.y2, -#else - create->title, - create->extent.x1, - create->extent.y1, - create->extent.x2, - create->extent.y2, -#endif - create->wid - ); - } - break; - - case RTGUI_EVENT_UPDATE_END: - { - struct rtgui_event_update_end* update_end = (struct rtgui_event_update_end*)event; - rt_kprintf("(x:%d, y1:%d, x2:%d, y2:%d)", update_end->rect.x1, - update_end->rect.y1, - update_end->rect.x2, - update_end->rect.y2); - } - break; - - case RTGUI_EVENT_WIN_ACTIVATE: - case RTGUI_EVENT_WIN_DEACTIVATE: - case RTGUI_EVENT_WIN_SHOW: - case RTGUI_EVENT_WIN_MODAL_ENTER: - case RTGUI_EVENT_WIN_HIDE: - { - struct rtgui_event_win *win = (struct rtgui_event_win *)event; - - if(win->wid != RT_NULL) - rt_kprintf("win: %s", win->wid->title); - } - break; - - case RTGUI_EVENT_WIN_MOVE: - { - struct rtgui_event_win_move *win = (struct rtgui_event_win_move *)event; - - if(win->wid != RT_NULL) - { - rt_kprintf("win: %s", win->wid->title); - rt_kprintf(" to (x:%d, y:%d)", win->x, win->y); - } - } - break; - - case RTGUI_EVENT_WIN_RESIZE: - { - struct rtgui_event_win_resize* win = (struct rtgui_event_win_resize *)event; - - if (win->wid != RT_NULL) - { - rt_kprintf("win: %s, rect(x1:%d, y1:%d, x2:%d, y2:%d)", win->wid->title, - RTGUI_WIDGET(win->wid)->extent.x1, - RTGUI_WIDGET(win->wid)->extent.y1, - RTGUI_WIDGET(win->wid)->extent.x2, - RTGUI_WIDGET(win->wid)->extent.y2); - } - } - break; - - case RTGUI_EVENT_MOUSE_BUTTON: - case RTGUI_EVENT_MOUSE_MOTION: - { - struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse*)event; - - if (mouse->button & RTGUI_MOUSE_BUTTON_LEFT) rt_kprintf("left "); - else rt_kprintf("right "); - - if (mouse->button & RTGUI_MOUSE_BUTTON_DOWN) rt_kprintf("down "); - else rt_kprintf("up "); - - if (mouse->wid != RT_NULL) - rt_kprintf("win: %s at (%d, %d)", mouse->wid->title, - mouse->x, mouse->y); - else - rt_kprintf("(%d, %d)", mouse->x, mouse->y); - } - break; - - case RTGUI_EVENT_MONITOR_ADD: - { - struct rtgui_event_monitor *monitor = (struct rtgui_event_monitor*)event; - if (monitor->wid != RT_NULL) - { - rt_kprintf("win: %s, the rect is:(%d, %d) - (%d, %d)", monitor->wid->title, - monitor->rect.x1, monitor->rect.y1, - monitor->rect.x2, monitor->rect.y2); - } - } - break; - - default: - break; - } - - rt_kprintf("\n"); -} -#else -#define DBG_MSG(x) -#define rtgui_event_dump(tid, event) -#endif - -rt_bool_t rtgui_application_event_handler(struct rtgui_object* obj, rtgui_event_t* event); - -static void _rtgui_application_constructor(struct rtgui_application *app) -{ - /* set event handler */ - rtgui_object_set_event_handler(RTGUI_OBJECT(app), - rtgui_application_event_handler); - - app->name = RT_NULL; - /* set EXITED so we can destroy an application that just created */ - app->state_flag = RTGUI_APPLICATION_FLAG_EXITED; - app->ref_count = 0; - app->exit_code = 0; - app->tid = RT_NULL; - app->server = RT_NULL; - app->mq = RT_NULL; - app->modal_object = RT_NULL; - app->on_idle = RT_NULL; -} - -static void _rtgui_application_destructor(struct rtgui_application *app) -{ - RT_ASSERT(app != RT_NULL); - - rt_free(app->name); - app->name = RT_NULL; -} - -DEFINE_CLASS_TYPE(application, "application", - RTGUI_OBJECT_TYPE, - _rtgui_application_constructor, - _rtgui_application_destructor, - sizeof(struct rtgui_application)); - -struct rtgui_application* rtgui_application_create( - rt_thread_t tid, - const char *myname) -{ - struct rtgui_application *app; - - RT_ASSERT(tid != RT_NULL); - RT_ASSERT(myname != RT_NULL); - - /* create application */ - app = RTGUI_APPLICATION(rtgui_object_create(RTGUI_APPLICATION_TYPE)); - if (app == RT_NULL) - return RT_NULL; - - DBG_MSG(("register a rtgui application(%s) on thread %s\n", myname, tid->name)); - - app->tid = tid; - /* set user thread */ - tid->user_data = (rt_uint32_t)app; - - app->mq = rt_mq_create("rtgui", sizeof(union rtgui_event_generic), 32, RT_IPC_FLAG_FIFO); - if (app->mq == RT_NULL) - { - rt_kprintf("mq err\n"); - goto __mq_err; - } - - /* set application title */ - app->name = (unsigned char*)rt_strdup((char*)myname); - if (app->name != RT_NULL) - return app; - -__mq_err: - rtgui_object_destroy(RTGUI_OBJECT(app)); - tid->user_data = 0; - return RT_NULL; -} - -#define _rtgui_application_check(app) \ -do { \ - RT_ASSERT(app != RT_NULL); \ - RT_ASSERT(app->tid != RT_NULL); \ - RT_ASSERT(app->tid->user_data != 0); \ - RT_ASSERT(app->mq != RT_NULL); \ -} while (0) - -void rtgui_application_destroy(struct rtgui_application *app) -{ - _rtgui_application_check(app); - - if (!(app->state_flag & RTGUI_APPLICATION_FLAG_EXITED)) - { - rt_kprintf("cannot destroy a running application: %s.\n", - app->name); - return; - } - - app->tid->user_data = 0; - rt_mq_delete(app->mq); - rtgui_object_destroy(RTGUI_OBJECT(app)); -} - -struct rtgui_application* rtgui_application_self(void) -{ - struct rtgui_application *app; - rt_thread_t self; - - /* get current thread */ - self = rt_thread_self(); - app = (struct rtgui_application*)(self->user_data); - - return app; -} - -void rtgui_application_set_onidle(rtgui_idle_func onidle) -{ - struct rtgui_application *app; - - app = rtgui_application_self(); - if (app != RT_NULL) - app->on_idle = onidle; -} - -rtgui_idle_func rtgui_application_get_onidle(void) -{ - struct rtgui_application *app; - - app = rtgui_application_self(); - if (app != RT_NULL) - return app->on_idle; - else - return RT_NULL; -} - -extern rt_thread_t rt_thread_find(char* name); -rt_thread_t rtgui_application_get_server(void) -{ - return rt_thread_find("rtgui"); -} - -rt_err_t rtgui_application_send(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size) -{ - rt_err_t result; - struct rtgui_application *app; - - RT_ASSERT(tid != RT_NULL); - RT_ASSERT(event != RT_NULL); - RT_ASSERT(event_size != 0); - - rtgui_event_dump(tid, event); - - /* find struct rtgui_application */ - app = (struct rtgui_application*) (tid->user_data); - if (app == RT_NULL) - return -RT_ERROR; - - result = rt_mq_send(app->mq, event, event_size); - if (result != RT_EOK) - { - if (event->type != RTGUI_EVENT_TIMER) - rt_kprintf("send event to %s failed\n", app->tid->name); - } - - return result; -} - -rt_err_t rtgui_application_send_urgent(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size) -{ - rt_err_t result; - struct rtgui_application *app; - - RT_ASSERT(tid != RT_NULL); - RT_ASSERT(event != RT_NULL); - RT_ASSERT(event_size != 0); - - rtgui_event_dump(tid, event); - - /* find rtgui_application */ - app = (struct rtgui_application*) (tid->user_data); - if (app == RT_NULL) - return -RT_ERROR; - - result = rt_mq_urgent(app->mq, event, event_size); - if (result != RT_EOK) - rt_kprintf("send ergent event failed\n"); - - return result; -} - -rt_err_t rtgui_application_send_sync(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size) -{ - rt_err_t r; - struct rtgui_application *app; - rt_int32_t ack_buffer, ack_status; - struct rt_mailbox ack_mb; - - RT_ASSERT(tid != RT_NULL); - RT_ASSERT(event != RT_NULL); - RT_ASSERT(event_size != 0); - - rtgui_event_dump(tid, event); - - /* init ack mailbox */ - r = rt_mb_init(&ack_mb, "ack", &ack_buffer, 1, 0); - if (r!= RT_EOK) - goto __return; - - app = (struct rtgui_application*) (tid->user_data); - if (app == RT_NULL) - { - r = -RT_ERROR; - goto __return; - } - - event->ack = &ack_mb; - r = rt_mq_send(app->mq, event, event_size); - if (r != RT_EOK) - { - rt_kprintf("send sync event failed\n"); - goto __return; - } - - r = rt_mb_recv(&ack_mb, (rt_uint32_t*)&ack_status, RT_WAITING_FOREVER); - if (r!= RT_EOK) - goto __return; - - if (ack_status != RTGUI_STATUS_OK) - r = -RT_ERROR; - else - r = RT_EOK; - -__return: - /* fini ack mailbox */ - rt_mb_detach(&ack_mb); - return r; -} - -rt_err_t rtgui_application_ack(rtgui_event_t* event, rt_int32_t status) -{ - RT_ASSERT(event != RT_NULL); - RT_ASSERT(event->ack != RT_NULL); - - rt_mb_send(event->ack, status); - - return RT_EOK; -} - -rt_err_t rtgui_application_recv(rtgui_event_t* event, rt_size_t event_size) -{ - struct rtgui_application* app; - rt_err_t r; - - RT_ASSERT(event != RT_NULL); - RT_ASSERT(event_size != 0); - - app = (struct rtgui_application*) (rt_thread_self()->user_data); - if (app == RT_NULL) - return -RT_ERROR; - - r = rt_mq_recv(app->mq, event, event_size, RT_WAITING_FOREVER); - - return r; -} - -rt_err_t rtgui_application_recv_nosuspend(rtgui_event_t* event, rt_size_t event_size) -{ - struct rtgui_application *app; - rt_err_t r; - - RT_ASSERT(event != RT_NULL); - RT_ASSERT(event != 0); - - app = (struct rtgui_application*) (rt_thread_self()->user_data); - if (app == RT_NULL) - return -RT_ERROR; - - r = rt_mq_recv(app->mq, event, event_size, 0); - - return r; -} - -rt_err_t rtgui_application_recv_filter(rt_uint32_t type, rtgui_event_t* event, rt_size_t event_size) -{ - struct rtgui_application *app; - - RT_ASSERT(event != RT_NULL); - RT_ASSERT(event_size != 0); - - app = (struct rtgui_application*) (rt_thread_self()->user_data); - if (app == RT_NULL) - return -RT_ERROR; - - while (rt_mq_recv(app->mq, event, event_size, RT_WAITING_FOREVER) == RT_EOK) - { - if (event->type == type) - { - return RT_EOK; - } - else - { - if (RTGUI_OBJECT(app)->event_handler != RT_NULL) - { - RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), event); - } - } - } - - return -RT_ERROR; -} - -rt_inline rt_bool_t _rtgui_application_dest_handle( - struct rtgui_application *app, - struct rtgui_event *event) -{ - struct rtgui_event_win* wevent = (struct rtgui_event_win*)event; - - struct rtgui_object* dest_object = RTGUI_OBJECT(wevent->wid); - - if (dest_object != RT_NULL) - { - if (dest_object->event_handler != RT_NULL) - return dest_object->event_handler(RTGUI_OBJECT(dest_object), event); - else - return RT_FALSE; - } - else - { - rt_kprintf("RTGUI ERROR:server sent a event(%d) without wid\n", event->type); - return RT_FALSE; - } -} - -rt_bool_t rtgui_application_event_handler(struct rtgui_object* object, rtgui_event_t* event) -{ - struct rtgui_application* app; - - RT_ASSERT(object != RT_NULL); - RT_ASSERT(event != RT_NULL); - - app = RTGUI_APPLICATION(object); - - switch (event->type) - { - case RTGUI_EVENT_PAINT: - case RTGUI_EVENT_CLIP_INFO: - case RTGUI_EVENT_WIN_ACTIVATE: - case RTGUI_EVENT_WIN_DEACTIVATE: - case RTGUI_EVENT_WIN_CLOSE: - case RTGUI_EVENT_WIN_MOVE: - case RTGUI_EVENT_KBD: - _rtgui_application_dest_handle(app, event); - break; - - case RTGUI_EVENT_MOUSE_BUTTON: - case RTGUI_EVENT_MOUSE_MOTION: - { - struct rtgui_event_win* wevent = (struct rtgui_event_win*)event; - struct rtgui_object* dest_object = RTGUI_OBJECT(wevent->wid); - - // FIXME: let application determine the dest_wiget but not in sever - // so we can combine this handler with above one - if (app->modal_object != RT_NULL && - dest_object != app->modal_object) - { -// rt_kprintf("discard event %s that is not sent to modal object\n", -// event_string[event->type]); - } - else - { - _rtgui_application_dest_handle(app, event); - } - } - break; - - case RTGUI_EVENT_TIMER: - { - struct rtgui_timer* timer; - struct rtgui_event_timer* etimer = (struct rtgui_event_timer*) event; - - timer = etimer->timer; - if (timer->timeout != RT_NULL) - { - /* call timeout function */ - timer->timeout(timer, timer->user_data); - } - } - break; - - case RTGUI_EVENT_COMMAND: - { - struct rtgui_event_command *ecmd = (struct rtgui_event_command *)event; - - if (ecmd->wid != RT_NULL) - return _rtgui_application_dest_handle(app, event); - } - - default: - return rtgui_object_event_handler(object, event); - } - - return RT_TRUE; -} - -rt_inline void _rtgui_application_event_loop(struct rtgui_application *app) -{ - rt_err_t result; - rt_uint16_t current_ref; - struct rtgui_event *event; - - _rtgui_application_check(app); - - /* point to event buffer */ - event = (struct rtgui_event*)app->event_buffer; - - current_ref = ++app->ref_count; - - while (current_ref <= app->ref_count) - { - RT_ASSERT(current_ref == app->ref_count); - - if (app->on_idle != RT_NULL) - { - result = rtgui_application_recv_nosuspend(event, sizeof(union rtgui_event_generic)); - if (result == RT_EOK) - RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), event); - else if (result == -RT_ETIMEOUT) - app->on_idle(RTGUI_OBJECT(app), RT_NULL); - } - else - { - result = rtgui_application_recv(event, sizeof(union rtgui_event_generic)); - if (result == RT_EOK) - RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), event); - } - } -} - -rt_base_t rtgui_application_run(struct rtgui_application *app) -{ - _rtgui_application_check(app); - - app->state_flag &= ~RTGUI_APPLICATION_FLAG_EXITED; - - _rtgui_application_event_loop(app); - - if (app->ref_count == 0) - app->state_flag |= RTGUI_APPLICATION_FLAG_EXITED; - - return app->exit_code; -} - -void rtgui_application_exit(struct rtgui_application* app, rt_uint16_t code) -{ - --app->ref_count; - app->exit_code = code; -} diff --git a/components/rtgui/server/server.c b/components/rtgui/server/server.c index 10ddfbf77a..28f0fb771f 100644 --- a/components/rtgui/server/server.c +++ b/components/rtgui/server/server.c @@ -16,14 +16,16 @@ #include <rtgui/event.h> #include <rtgui/rtgui_system.h> #include <rtgui/rtgui_object.h> -#include <rtgui/rtgui_application.h> +#include <rtgui/rtgui_app.h> #include <rtgui/driver.h> #include "mouse.h" #include "topwin.h" static struct rt_thread *rtgui_server_tid; -static struct rtgui_application *rtgui_server_application; + +static struct rtgui_app *rtgui_server_application = RT_NULL; +static struct rtgui_app *rtgui_wm_application = RT_NULL; void rtgui_server_handle_update(struct rtgui_event_update_end* event) { @@ -85,7 +87,7 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event) } /* send to client thread */ - rtgui_application_send(topwin->tid, &(ewin.parent), sizeof(ewin)); + rtgui_send(topwin->tid, &(ewin.parent), sizeof(ewin)); return; } @@ -101,7 +103,7 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event) if (rtgui_topwin_get_focus() != wnd) { /* raise this window */ - rtgui_topwin_activate_win(wnd); + rtgui_topwin_activate_topwin(wnd); } if (wnd->title != RT_NULL && @@ -112,7 +114,7 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event) else { /* send mouse event to thread */ - rtgui_application_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_mouse)); + rtgui_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_mouse)); } return ; } @@ -144,7 +146,7 @@ void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse* event) { event->wid = last_monitor_topwin->wid; /* send mouse motion event */ - rtgui_application_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); + rtgui_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); } if (last_monitor_topwin != win) @@ -155,7 +157,7 @@ void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse* event) event->wid = last_monitor_topwin->wid; /* send mouse motion event */ - rtgui_application_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); + rtgui_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); } } @@ -181,7 +183,7 @@ void rtgui_server_handle_kbd(struct rtgui_event_kbd* event) event->wid = wnd->wid; /* send keyboard event to thread */ - rtgui_application_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd)); + rtgui_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd)); return; } @@ -200,58 +202,113 @@ static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object, /* 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_application_ack(event, RTGUI_STATUS_OK); + rtgui_ack(event, RTGUI_STATUS_OK); else - rtgui_application_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_application_ack(event, RTGUI_STATUS_OK); - else - rtgui_application_ack(event, RTGUI_STATUS_ERROR); + rtgui_ack(event, RTGUI_STATUS_ERROR); break; case RTGUI_EVENT_WIN_SHOW: if (rtgui_topwin_show((struct rtgui_event_win*)event) == RT_EOK) - rtgui_application_ack(event, RTGUI_STATUS_OK); + rtgui_ack(event, RTGUI_STATUS_OK); else - rtgui_application_ack(event, RTGUI_STATUS_ERROR); + rtgui_ack(event, RTGUI_STATUS_ERROR); break; case RTGUI_EVENT_WIN_HIDE: if (rtgui_topwin_hide((struct rtgui_event_win*)event) == RT_EOK) - rtgui_application_ack(event, RTGUI_STATUS_OK); + rtgui_ack(event, RTGUI_STATUS_OK); else - rtgui_application_ack(event, RTGUI_STATUS_ERROR); + 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_application_ack(event, RTGUI_STATUS_OK); + rtgui_ack(event, RTGUI_STATUS_OK); else - rtgui_application_ack(event, RTGUI_STATUS_ERROR); + 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_application_ack(event, RTGUI_STATUS_OK); + rtgui_ack(event, RTGUI_STATUS_OK); else - rtgui_application_ack(event, RTGUI_STATUS_ERROR); + 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 */ @@ -272,25 +329,6 @@ static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object, /* handle mouse monitor */ rtgui_server_handle_monitor_add((struct rtgui_event_monitor*)event); 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; - - case RTGUI_EVENT_COMMAND: - break; } return RT_TRUE; @@ -307,8 +345,8 @@ static void rtgui_server_entry(void* parameter) SetThreadPriority(hCurrentThread, THREAD_PRIORITY_HIGHEST); #endif - /* register rtgui server thread */ - rtgui_server_application = rtgui_application_create(rtgui_server_tid, + /* create rtgui server application */ + rtgui_server_application = rtgui_app_create(rtgui_server_tid, "rtgui"); if (rtgui_server_application == RT_NULL) return; @@ -321,16 +359,16 @@ static void rtgui_server_entry(void* parameter) rtgui_mouse_show_cursor(); #endif - rtgui_application_run(rtgui_server_application); + rtgui_app_run(rtgui_server_application); - rtgui_application_destroy(rtgui_server_application); + rtgui_app_destroy(rtgui_server_application); rtgui_server_application = RT_NULL; } void rtgui_server_post_event(struct rtgui_event* event, rt_size_t size) { if (rtgui_server_tid != RT_NULL) - rtgui_application_send(rtgui_server_tid, event, size); + rtgui_send(rtgui_server_tid, event, size); else rt_kprintf("post when server is not running\n"); } @@ -338,7 +376,7 @@ void rtgui_server_post_event(struct rtgui_event* event, rt_size_t size) rt_err_t rtgui_server_post_event_sync(struct rtgui_event* event, rt_size_t size) { if (rtgui_server_tid != RT_NULL) - return rtgui_application_send_sync(rtgui_server_tid, event, size); + return rtgui_send_sync(rtgui_server_tid, event, size); else { rt_kprintf("post when server is not running\n"); diff --git a/components/rtgui/server/topwin.c b/components/rtgui/server/topwin.c index 14c9432b18..4c75cc1159 100644 --- a/components/rtgui/server/topwin.c +++ b/components/rtgui/server/topwin.c @@ -19,41 +19,36 @@ #include <rtgui/image.h> #include <rtgui/rtgui_theme.h> #include <rtgui/rtgui_system.h> -#include <rtgui/rtgui_application.h> +#include <rtgui/rtgui_app.h> #include <rtgui/widgets/window.h> /* This list is divided into two parts. The first part is the shown list, in * which all the windows have the WINTITLE_SHOWN flag set. Second part is the - * hidden list, in which all the windows don't have WINTITLE_SHOWN flag. + * hidden items, in which all the windows don't have WINTITLE_SHOWN flag. * * The active window is the one that would receive kbd events. It should always - * in the first tree. The order of this list is the order of the windows. - * Thus, the first item is the top most window and the last item is the bottom - * window. Top window can always clip the window beneath it when the two + * be in the first tree. The order of this list is the order of the windows. + * Top window can always clip the window beneath it when the two * overlapping. Child window can always clip it's parent. Slibing windows can - * clip each other with the same rule as this list. Thus, each child list is - * the same as _rtgui_topwin_list. This forms the hierarchy tree structure of - * all windows. + * clip each other with the same rule as this list. Each child list is the same + * as _rtgui_topwin_list. This forms the hierarchy tree structure of all + * windows. * - * The hidden list have no specific order. + * Thus, the left most leaf of the tree is the top most window and the right + * most root node is the bottom window. The hidden part have no specific + * order. */ static struct rtgui_dlist_node _rtgui_topwin_list; #define get_topwin_from_list(list_entry) \ (rtgui_dlist_entry((list_entry), struct rtgui_topwin, list)) -#ifdef RTGUI_USING_DESKTOP_WINDOW -static struct rtgui_topwin *the_desktop_topwin; - -#define IS_ROOT_WIN(topwin) ((topwin)->parent == the_desktop_topwin) -#else #define IS_ROOT_WIN(topwin) ((topwin)->parent == RT_NULL) -#endif static struct rt_semaphore _rtgui_topwin_lock; static void rtgui_topwin_update_clip(void); static void rtgui_topwin_redraw(struct rtgui_rect* rect); -static void _rtgui_topwin_activate_next(void); +static void _rtgui_topwin_activate_next(enum rtgui_topwin_flag); void rtgui_topwin_init(void) { @@ -113,11 +108,6 @@ rt_err_t rtgui_topwin_add(struct rtgui_event_win_create* event) { topwin->parent = RT_NULL; rtgui_dlist_insert_before(&_rtgui_topwin_list, &topwin->list); -#ifdef RTGUI_USING_DESKTOP_WINDOW - RT_ASSERT(the_desktop_topwin == RT_NULL); - RT_ASSERT(event->parent.user & RTGUI_WIN_STYLE_DESKTOP); - the_desktop_topwin = topwin; -#endif } else { @@ -138,6 +128,8 @@ rt_err_t rtgui_topwin_add(struct rtgui_event_win_create* event) if (event->parent.user & RTGUI_WIN_STYLE_CLOSEBOX) topwin->flag |= WINTITLE_CLOSEBOX; if (!(event->parent.user & RTGUI_WIN_STYLE_NO_BORDER)) topwin->flag |= WINTITLE_BORDER; if (event->parent.user & RTGUI_WIN_STYLE_NO_FOCUS) topwin->flag |= WINTITLE_NOFOCUS; + if (event->parent.user & RTGUI_WIN_STYLE_ONTOP) topwin->flag |= WINTITLE_ONTOP; + if (event->parent.user & RTGUI_WIN_STYLE_ONBTM) topwin->flag |= WINTITLE_ONBTM; if(!(topwin->flag & WINTITLE_NO) || (topwin->flag & WINTITLE_BORDER)) { @@ -195,12 +187,31 @@ static struct rtgui_topwin* _rtgui_topwin_get_topmost_child_shown(struct rtgui_t return topwin; } -static struct rtgui_topwin* _rtgui_topwin_get_topmost_window_shown(void) +static rt_bool_t _rtgui_topwin_in_layer(struct rtgui_topwin *topwin, enum rtgui_topwin_flag flag) { - if (!(get_topwin_from_list(_rtgui_topwin_list.next)->flag & WINTITLE_SHOWN)) - return RT_NULL; - else - return _rtgui_topwin_get_topmost_child_shown(get_topwin_from_list(_rtgui_topwin_list.next)); + return (topwin->flag & (WINTITLE_ONTOP|WINTITLE_ONBTM)) + == (flag & (WINTITLE_ONTOP|WINTITLE_ONBTM)); +} + +/* find the topmost window shown in the layer set by flag. The flag has many + * other infomations but we only use the ONTOP/ONBTM */ +static struct rtgui_topwin* _rtgui_topwin_get_topmost_window_shown(enum rtgui_topwin_flag flag) +{ + struct rtgui_dlist_node *node; + + rtgui_dlist_foreach(node, &_rtgui_topwin_list, next) + { + struct rtgui_topwin *topwin = get_topwin_from_list(node); + + /* reach the hidden region no window shown in current layer */ + if (!(topwin->flag & WINTITLE_SHOWN)) + return RT_NULL; + + if (_rtgui_topwin_in_layer(topwin, flag)) + return _rtgui_topwin_get_topmost_child_shown(topwin); + } + /* no window in current layer is shown */ + return RT_NULL; } /* a hidden parent will hide it's children. Top level window can be shown at @@ -286,23 +297,22 @@ rt_err_t rtgui_topwin_remove(struct rtgui_win* wid) old_focus = rtgui_topwin_get_focus(); - // TODO: if the window is hidden, there is no need to update the window - // region - _rtgui_topwin_union_region_tree(topwin, ®ion); - if (topwin->flag & WINTITLE_SHOWN) - rtgui_topwin_update_clip(); + /* remove the root from _rtgui_topwin_list will remove the whole tree from + * _rtgui_topwin_list. */ + rtgui_dlist_remove(&topwin->list); if (old_focus == topwin) { - _rtgui_topwin_activate_next(); + _rtgui_topwin_activate_next(topwin->flag); } - /* redraw the old rect */ - rtgui_topwin_redraw(rtgui_region_extents(®ion)); - - /* remove the root from _rtgui_topwin_list will remove the whole tree from - * _rtgui_topwin_list. */ - rtgui_dlist_remove(&topwin->list); + if (topwin->flag & WINTITLE_SHOWN) + { + rtgui_topwin_update_clip(); + /* redraw the old rect */ + _rtgui_topwin_union_region_tree(topwin, ®ion); + rtgui_topwin_redraw(rtgui_region_extents(®ion)); + } _rtgui_topwin_free_tree(topwin); @@ -327,7 +337,7 @@ static void _rtgui_topwin_only_activate(struct rtgui_topwin *topwin) topwin->flag |= WINTITLE_ACTIVATE; event.wid = topwin->wid; - rtgui_application_send(topwin->tid, &(event.parent), sizeof(struct rtgui_event_win)); + rtgui_send(topwin->tid, &(event.parent), sizeof(struct rtgui_event_win)); /* redraw title */ if (topwin->title != RT_NULL) @@ -336,11 +346,13 @@ static void _rtgui_topwin_only_activate(struct rtgui_topwin *topwin) } } -static void _rtgui_topwin_activate_next(void) +/* activate next window in the same layer as flag. The flag has many other + * infomations but we only use the ONTOP/ONBTM */ +static void _rtgui_topwin_activate_next(enum rtgui_topwin_flag flag) { struct rtgui_topwin *topwin; - topwin = _rtgui_topwin_get_topmost_window_shown(); + topwin = _rtgui_topwin_get_topmost_window_shown(flag); if (topwin == RT_NULL) return; @@ -358,7 +370,7 @@ static void _rtgui_topwin_deactivate(struct rtgui_topwin *topwin) RTGUI_EVENT_WIN_DEACTIVATE_INIT(&event); event.wid = topwin->wid; - rtgui_application_send(topwin->tid, + rtgui_send(topwin->tid, &event.parent, sizeof(struct rtgui_event_win)); topwin->flag &= ~WINTITLE_ACTIVATE; @@ -376,17 +388,6 @@ static void _rtgui_topwin_move_whole_tree2top(struct rtgui_topwin *topwin) RT_ASSERT(topwin != RT_NULL); -#ifdef RTGUI_USING_DESKTOP_WINDOW - /* handle desktop window separately, avoid calling - * _rtgui_topwin_get_root_win */ - if (topwin == the_desktop_topwin) - { - rtgui_dlist_remove(&the_desktop_topwin->list); - rtgui_dlist_insert_after(&_rtgui_topwin_list, &the_desktop_topwin->list); - return; - } -#endif - /* move the whole tree */ topparent = _rtgui_topwin_get_root_win(topwin); RT_ASSERT(topparent != RT_NULL); @@ -394,20 +395,58 @@ static void _rtgui_topwin_move_whole_tree2top(struct rtgui_topwin *topwin) /* remove node from hidden list */ rtgui_dlist_remove(&topparent->list); /* add node to show list */ -#ifdef RTGUI_USING_DESKTOP_WINDOW - rtgui_dlist_insert_after(&the_desktop_topwin->child_list, &(topparent->list)); -#else - rtgui_dlist_insert_after(&_rtgui_topwin_list, &(topparent->list)); -#endif + if (topwin->flag & WINTITLE_ONTOP) + { + rtgui_dlist_insert_after(&_rtgui_topwin_list, &(topparent->list)); + } + else if (topwin->flag & WINTITLE_ONBTM) + { + /* botton layer window, before the fisrt bottom window or hidden window. */ + struct rtgui_topwin *ntopwin = get_topwin_from_list(&_rtgui_topwin_list); + struct rtgui_dlist_node *node; + + rtgui_dlist_foreach(node, &_rtgui_topwin_list, next) + { + ntopwin = get_topwin_from_list(node); + if ((ntopwin->flag & WINTITLE_ONBTM) + || !(ntopwin->flag & WINTITLE_SHOWN)) + break; + } + /* all other windows are shown top/normal layer windows. Insert it as + * the last window. */ + if (node == &_rtgui_topwin_list) + rtgui_dlist_insert_before(&_rtgui_topwin_list, &(topparent->list)); + else + rtgui_dlist_insert_before(&ntopwin->list, &(topparent->list)); + } + else + { + /* normal layer window, before the fisrt shown normal layer window. */ + struct rtgui_topwin *ntopwin = get_topwin_from_list(&_rtgui_topwin_list); + struct rtgui_dlist_node *node; + + rtgui_dlist_foreach(node, &_rtgui_topwin_list, next) + { + ntopwin = get_topwin_from_list(node); + if (!((ntopwin->flag & WINTITLE_ONTOP) + && (ntopwin->flag & WINTITLE_SHOWN))) + break; + } + /* all other windows are shown top layer windows. Insert it as + * the last window. */ + if (node == &_rtgui_topwin_list) + rtgui_dlist_insert_before(&_rtgui_topwin_list, &(topparent->list)); + else + rtgui_dlist_insert_before(&ntopwin->list, &(topparent->list)); + } } -static void _rtgui_topwin_raise_topwin_in_tree(struct rtgui_topwin *topwin) +static void _rtgui_topwin_raise_in_sibling(struct rtgui_topwin *topwin) { struct rtgui_dlist_node *win_level; RT_ASSERT(topwin != RT_NULL); - _rtgui_topwin_move_whole_tree2top(topwin); if (topwin->parent == RT_NULL) win_level = &_rtgui_topwin_list; else @@ -416,33 +455,64 @@ static void _rtgui_topwin_raise_topwin_in_tree(struct rtgui_topwin *topwin) rtgui_dlist_insert_after(win_level, &topwin->list); } +/* it will do 2 things. One is moving the whole tree(the root of the tree) to + * the front and the other is moving topwin to the front of it's siblings. */ +static void _rtgui_topwin_raise_tree_from_root(struct rtgui_topwin *topwin) +{ + RT_ASSERT(topwin != RT_NULL); + + _rtgui_topwin_move_whole_tree2top(topwin); + /* root win is aleady moved by _rtgui_topwin_move_whole_tree2top */ + if (!IS_ROOT_WIN(topwin)) + _rtgui_topwin_raise_in_sibling(topwin); +} + /* activate a win means: * - deactivate the old focus win if any * - raise the window to the front of it's siblings * - activate a win */ -void rtgui_topwin_activate_win(struct rtgui_topwin* topwin) +rt_err_t rtgui_topwin_activate(struct rtgui_event_win_activate* event) +{ + struct rtgui_topwin *topwin; + + RT_ASSERT(event); + + topwin = rtgui_topwin_search_in_list(event->wid, &_rtgui_topwin_list); + if (topwin == RT_NULL) + return -RT_ERROR; + + return rtgui_topwin_activate_topwin(topwin); +} + +rt_err_t rtgui_topwin_activate_topwin(struct rtgui_topwin* topwin) { struct rtgui_topwin *old_focus_topwin; RT_ASSERT(topwin != RT_NULL); + if (!(topwin->flag & WINTITLE_SHOWN)) + return -RT_ERROR; + if (topwin->flag & WINTITLE_NOFOCUS) { /* just raise it, not affect others. */ - _rtgui_topwin_raise_topwin_in_tree(topwin); + _rtgui_topwin_raise_tree_from_root(topwin); /* update clip info */ rtgui_topwin_update_clip(); - return; + return RT_EOK; } - old_focus_topwin = rtgui_topwin_get_focus(); + if (topwin->flag & WINTITLE_ACTIVATE) + return RT_EOK; - if (old_focus_topwin == topwin) - return; + old_focus_topwin = rtgui_topwin_get_focus(); + /* if topwin has the focus, it shoule have WINTITLE_ACTIVATE set and + * returned above. */ + RT_ASSERT(old_focus_topwin != topwin); - _rtgui_topwin_raise_topwin_in_tree(topwin); + _rtgui_topwin_raise_tree_from_root(topwin); /* update clip info */ rtgui_topwin_update_clip(); @@ -454,6 +524,8 @@ void rtgui_topwin_activate_win(struct rtgui_topwin* topwin) } _rtgui_topwin_only_activate(topwin); + + return RT_EOK; } /* map func to the topwin tree in preorder. @@ -486,6 +558,10 @@ rt_inline void _rtgui_topwin_mark_hidden(struct rtgui_topwin *topwin) rt_inline void _rtgui_topwin_mark_shown(struct rtgui_topwin *topwin) { + if (!(topwin->flag & WINTITLE_SHOWN) + && RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(topwin->wid))) + return; + topwin->flag |= WINTITLE_SHOWN; if (topwin->title != RT_NULL) { @@ -504,10 +580,12 @@ static void _rtgui_topwin_draw_tree(struct rtgui_topwin *topwin, struct rtgui_ev } epaint->wid = topwin->wid; - rtgui_application_send(topwin->tid, &(epaint->parent), sizeof(struct rtgui_event_paint)); + rtgui_send(topwin->tid, &(epaint->parent), sizeof(struct rtgui_event_paint)); rtgui_dlist_foreach(node, &topwin->child_list, prev) { + if (!(get_topwin_from_list(node)->flag & WINTITLE_SHOWN)) + return; _rtgui_topwin_draw_tree(get_topwin_from_list(node), epaint); } } @@ -519,7 +597,7 @@ static void _rtgui_topwin_show_tree(struct rtgui_topwin *topwin, struct rtgui_ev RT_ASSERT(topwin != RT_NULL); RT_ASSERT(epaint != RT_NULL); - _rtgui_topwin_raise_topwin_in_tree(topwin); + _rtgui_topwin_raise_tree_from_root(topwin); /* we have to mark the _all_ tree before update_clip because update_clip * will stop as hidden windows */ _rtgui_topwin_preorder_map(topwin, _rtgui_topwin_mark_shown); @@ -532,14 +610,6 @@ static void _rtgui_topwin_show_tree(struct rtgui_topwin *topwin, struct rtgui_ev _rtgui_topwin_draw_tree(topwin, epaint); } -/** show a window - * - * If any parent window in the hierarchy tree is hidden, this window won't be - * shown. If this window could be shown, all the child windows will be shown as - * well. The topmost child will be active. - * - * Top level window(parent == RT_NULL) can always be shown. - */ rt_err_t rtgui_topwin_show(struct rtgui_event_win* event) { struct rtgui_topwin *topwin, *old_focus; @@ -548,25 +618,30 @@ rt_err_t rtgui_topwin_show(struct rtgui_event_win* event) RTGUI_EVENT_PAINT_INIT(&epaint); - /* find in hide list */ topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_list); - if (topwin == RT_NULL || - !_rtgui_topwin_could_show(topwin)) + /* no such a window recorded */ + if (topwin == RT_NULL) return -RT_ERROR; + /* if the parent is hidden, just mark it as shown. It will be shown when + * the parent is shown. */ + if (!_rtgui_topwin_could_show(topwin)) + { + topwin->flag |= WINTITLE_SHOWN; + _rtgui_topwin_raise_in_sibling(topwin); + + return -RT_ERROR; + } + old_focus = rtgui_topwin_get_focus(); _rtgui_topwin_show_tree(topwin, &epaint); /* we don't want double clipping(bare rtgui_topwin_activate_win will clip), * so we have to do deactivate/activate manually. */ - if (old_focus == RT_NULL) - _rtgui_topwin_only_activate(topwin); - else if (old_focus != topwin) - { + if (old_focus && old_focus != topwin) _rtgui_topwin_deactivate(old_focus); - _rtgui_topwin_only_activate(topwin); - } + _rtgui_topwin_only_activate(topwin); return RT_EOK; } @@ -633,7 +708,7 @@ rt_err_t rtgui_topwin_hide(struct rtgui_event_win* event) if (old_focus_topwin == topwin) { - _rtgui_topwin_activate_next(); + _rtgui_topwin_activate_next(topwin->flag); } return RT_EOK; @@ -697,7 +772,7 @@ rt_err_t rtgui_topwin_move(struct rtgui_event_win_move* event) struct rtgui_event_paint epaint; RTGUI_EVENT_PAINT_INIT(&epaint); epaint.wid = topwin->wid; - rtgui_application_send(topwin->tid, &(epaint.parent), sizeof(epaint)); + rtgui_send(topwin->tid, &(epaint.parent), sizeof(epaint)); } return RT_EOK; @@ -772,24 +847,7 @@ static struct rtgui_topwin* _rtgui_topwin_get_focus_from_list(struct rtgui_dlist struct rtgui_topwin* rtgui_topwin_get_focus(void) { -#if 1 - // debug code - struct rtgui_topwin *topwin = _rtgui_topwin_get_focus_from_list(&_rtgui_topwin_list); - - if (topwin != RT_NULL) -#ifdef RTGUI_USING_DESKTOP_WINDOW - RT_ASSERT(topwin == the_desktop_topwin ||\ - get_topwin_from_list(the_desktop_topwin->child_list.next) == - _rtgui_topwin_get_root_win(topwin)); -#else - RT_ASSERT(get_topwin_from_list(_rtgui_topwin_list.next) == - _rtgui_topwin_get_root_win(topwin)); -#endif - - return topwin; -#else return _rtgui_topwin_get_focus_from_list(&_rtgui_topwin_list); -#endif } static struct rtgui_topwin* _rtgui_topwin_get_wnd_from_tree(struct rtgui_dlist_node *list, @@ -885,7 +943,12 @@ static void rtgui_topwin_update_clip(void) rtgui_graphic_driver_get_default()->height); /* from top to bottom. */ - top = _rtgui_topwin_get_topmost_window_shown(); + top = _rtgui_topwin_get_topmost_window_shown(WINTITLE_ONTOP); + /* 0 is normal layer */ + if (top == RT_NULL) + top = _rtgui_topwin_get_topmost_window_shown(0); + if (top == RT_NULL) + top = _rtgui_topwin_get_topmost_window_shown(WINTITLE_ONBTM); while (top != RT_NULL) { @@ -906,7 +969,7 @@ static void rtgui_topwin_update_clip(void) /* send clip event to destination window */ eclip.wid = top->wid; - rtgui_application_send(top->tid, &(eclip.parent), sizeof(struct rtgui_event_clip_info)); + rtgui_send(top->tid, &(eclip.parent), sizeof(struct rtgui_event_clip_info)); /* move to next sibling tree */ if (top->parent == RT_NULL) @@ -915,6 +978,7 @@ static void rtgui_topwin_update_clip(void) top = _rtgui_topwin_get_topmost_child_shown(get_topwin_from_list(top->list.next)); else break; + /* move to next slibing topwin */ else if (top->list.next != &top->parent->child_list && get_topwin_from_list(top->list.next)->flag & WINTITLE_SHOWN) top = _rtgui_topwin_get_topmost_child_shown(get_topwin_from_list(top->list.next)); @@ -951,7 +1015,7 @@ static void _rtgui_topwin_redraw_tree(struct rtgui_dlist_node *list, if (rtgui_rect_is_intersect(rect, &(topwin->extent)) == RT_EOK) { epaint->wid = topwin->wid; - rtgui_application_send(topwin->tid, &(epaint->parent), sizeof(*epaint)); + rtgui_send(topwin->tid, &(epaint->parent), sizeof(*epaint)); /* draw title */ if (topwin->title != RT_NULL) @@ -1019,7 +1083,7 @@ void rtgui_topwin_title_onmouse(struct rtgui_topwin* win, struct rtgui_event_mou if (rtgui_rect_contains_point(&win->extent, event->x, event->y) == RT_EOK) { /* send mouse event to thread */ - rtgui_application_send(win->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); + rtgui_send(win->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); return; } @@ -1058,7 +1122,7 @@ void rtgui_topwin_title_onmouse(struct rtgui_topwin* win, struct rtgui_event_mou /* send close event to window */ RTGUI_EVENT_WIN_CLOSE_INIT(&event); event.wid = win->wid; - rtgui_application_send(win->tid, &(event.parent), sizeof(struct rtgui_event_win)); + rtgui_send(win->tid, &(event.parent), sizeof(struct rtgui_event_win)); } } } @@ -1120,19 +1184,18 @@ void rtgui_topwin_dump_tree(void) { struct rtgui_dlist_node *node; -#ifdef RTGUI_USING_DESKTOP_WINDOW - _rtgui_topwin_dump(the_desktop_topwin); - rt_kprintf("\n"); - rtgui_dlist_foreach(node, &the_desktop_topwin->child_list, next) - { - _rtgui_topwin_dump_tree(get_topwin_from_list(node)); - rt_kprintf("\n"); - } -#else rtgui_dlist_foreach(node, &_rtgui_topwin_list, next) { _rtgui_topwin_dump_tree(get_topwin_from_list(node)); rt_kprintf("\n"); } -#endif } + +#ifdef RT_USING_FINSH +#include <finsh.h> +void dump_tree() +{ + rtgui_topwin_dump_tree(); +} +FINSH_FUNCTION_EXPORT(dump_tree, dump rtgui topwin tree) +#endif diff --git a/components/rtgui/server/topwin.h b/components/rtgui/server/topwin.h index bc9db9d284..59b8f30e79 100644 --- a/components/rtgui/server/topwin.h +++ b/components/rtgui/server/topwin.h @@ -23,8 +23,8 @@ /* add or remove a top win */ rt_err_t rtgui_topwin_add(struct rtgui_event_win_create* event); rt_err_t rtgui_topwin_remove(struct rtgui_win* wid); - -void rtgui_topwin_activate_win(struct rtgui_topwin* win); +rt_err_t rtgui_topwin_activate(struct rtgui_event_win_activate* event); +rt_err_t rtgui_topwin_activate_topwin(struct rtgui_topwin* win); /* show a window */ rt_err_t rtgui_topwin_show(struct rtgui_event_win* event); |
