diff options
| author | bernard.xiong <[email protected]> | 2010-04-18 15:05:20 +0000 |
|---|---|---|
| committer | bernard.xiong <[email protected]> | 2010-04-18 15:05:20 +0000 |
| commit | f908d62a40b49ee0c03527e63a153acf6822e79b (patch) | |
| tree | 39d74a8d2b6698171eee392412b69da94f95f05f /rtgui/server | |
| parent | 1df014578a7fab20f6b5ed00b3ea530ba7509d04 (diff) | |
move to components directory
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@638 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'rtgui/server')
| -rw-r--r-- | rtgui/server/driver.c | 67 | ||||
| -rw-r--r-- | rtgui/server/mouse.c | 629 | ||||
| -rw-r--r-- | rtgui/server/mouse.h | 51 | ||||
| -rw-r--r-- | rtgui/server/panel.c | 306 | ||||
| -rw-r--r-- | rtgui/server/panel.h | 68 | ||||
| -rw-r--r-- | rtgui/server/server.c | 636 | ||||
| -rw-r--r-- | rtgui/server/topwin.c | 1044 | ||||
| -rw-r--r-- | rtgui/server/topwin.h | 59 |
8 files changed, 0 insertions, 2860 deletions
diff --git a/rtgui/server/driver.c b/rtgui/server/driver.c deleted file mode 100644 index 6793ea1360..0000000000 --- a/rtgui/server/driver.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * File : driver.c - * This file is part of RTGUI in RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, 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 - * 2009-10-04 Bernard first version - */ -#include <rtgui/driver.h> - -struct rtgui_list_node _rtgui_graphic_driver_list = {RT_NULL}; - -void rtgui_graphic_driver_add(struct rtgui_graphic_driver* driver) -{ - rtgui_list_insert(&_rtgui_graphic_driver_list, &(driver->list)); -} - -void rtgui_graphic_driver_remove(struct rtgui_graphic_driver* driver) -{ - rtgui_list_remove(&_rtgui_graphic_driver_list, &(driver->list)); -} - -struct rtgui_graphic_driver* rtgui_graphic_driver_find(char* name) -{ - struct rtgui_list_node* node; - struct rtgui_graphic_driver* driver; - - /* search in list */ - rtgui_list_foreach(node, &(_rtgui_graphic_driver_list)) - { - driver = rtgui_list_entry(node, struct rtgui_graphic_driver, list); - - /* find it */ - if (rt_strncmp(driver->name, name, RTGUI_NAME_MAX) == 0) - { - return driver; - } - } - - return RT_NULL; -} - -struct rtgui_graphic_driver* rtgui_graphic_driver_get_default() -{ - return rtgui_list_entry(_rtgui_graphic_driver_list.next, - struct rtgui_graphic_driver, list); -} - -void rtgui_graphic_driver_get_rect(struct rtgui_graphic_driver *driver, rtgui_rect_t *rect) -{ - if (rect == RT_NULL || driver == RT_NULL) return; - - rect->x1 = rect->y1 = 0; - rect->x2 = driver->width; - rect->y2 = driver->height; -} - -void rtgui_graphic_driver_get_default_rect(rtgui_rect_t *rect) -{ - /* return default the extent of default driver */ - rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), rect); -} diff --git a/rtgui/server/mouse.c b/rtgui/server/mouse.c deleted file mode 100644 index 2432073a3e..0000000000 --- a/rtgui/server/mouse.c +++ /dev/null @@ -1,629 +0,0 @@ -/* - * File : mouse.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, 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 - * 2009-10-16 Bernard first version - */ - -#include "mouse.h" -#include <rtgui/region.h> -#include <rtgui/driver.h> -#include <rtgui/rtgui_system.h> - -struct rtgui_cursor -{ - /* screen byte per pixel */ - rt_uint16_t bpp; - - /* screen pitch */ - rt_uint16_t screen_pitch; - - /* current cursor x and y */ - rt_uint16_t cx, cy; - -#ifdef RTGUI_USING_MOUSE_CURSOR - /* cursor pitch */ - rt_uint16_t cursor_pitch; - - /* show cursor and show cursor count */ - rt_bool_t show_cursor; - rt_base_t show_cursor_count; - - /* cursor rect info */ - rtgui_rect_t rect; - - /* cursor image and saved cursor */ - rtgui_image_t *cursor_image; - rt_uint8_t *cursor_saved; -#endif - - /* move window rect and border */ - struct rtgui_topwin *topwin; - rtgui_rect_t win_rect; - rt_uint8_t *win_left, *win_right; - rt_uint8_t *win_top, *win_bottom; - rt_bool_t win_rect_show, win_rect_has_saved; - - /* screen framebuffer */ - rt_uint8_t* framebuffer; -}; - -struct rtgui_cursor* _rtgui_cursor; - -#ifdef RTGUI_USING_MOUSE_CURSOR -struct rt_mutex cursor_mutex; -static const rt_uint8_t * cursor_xpm[] = { - "16 16 35 1", - " c None", - ". c #A0B8D0", - "+ c #F0F0F0", - "@ c #FFFFFF", - "# c #F0F8F0", - "$ c #A0B0D0", - "% c #90A8C0", - "& c #A0B0C0", - "* c #E0E8F0", - "= c #8090B0", - "- c #D0D8E0", - "; c #7080A0", - "> c #90A0B0", - ", c #FFF8FF", - "' c #F0F8FF", - ") c #607090", - "! c #8098B0", - "~ c #405060", - "{ c #405070", - "] c #506070", - "^ c #607080", - "/ c #708090", - "( c #7088A0", - "_ c #D0D0E0", - ": c #607890", - "< c #C0D0E0", - "[ c #C0C8D0", - "} c #506880", - "| c #5F778F", - "1 c #D0D8F0", - "2 c #506080", - "3 c #C0C8E0", - "4 c #A0A8C0", - "5 c #405870", - "6 c #5F6F8F", - " . ", - " .. ", - " .+. ", - " .@#$ ", - " $@@+% ", - " &@@@*= ", - " %@@@@-; ", - " >@@,''-) ", - " !,''+)~{] ", - " ='-^*/ ", - " (_{:<[^ ", - " ;} |:12 ", - " / )345 ", - " 6}${ ", - " 5{ ", - " "}; - -static void rtgui_cursor_restore (void); -static void rtgui_cursor_save (void); -static void rtgui_cursor_show (void); -#endif - -static void rtgui_winrect_restore (void); -static void rtgui_winrect_save (void); -static void rtgui_winrect_show (void); - -#define WIN_MOVE_BORDER 4 -void rtgui_mouse_init() -{ - struct rtgui_graphic_driver* gd = rtgui_graphic_driver_get_default(); - - _rtgui_cursor = (struct rtgui_cursor*) rtgui_malloc(sizeof(struct rtgui_cursor)); - rt_memset(_rtgui_cursor, 0, sizeof(struct rtgui_cursor)); - -#ifdef RTGUI_USING_MOUSE_CURSOR - rt_mutex_init(&cursor_mutex, "cursor", RT_IPC_FLAG_FIFO); -#endif - - /* init cursor */ - _rtgui_cursor->bpp = gd->byte_per_pixel; - _rtgui_cursor->framebuffer = gd->get_framebuffer(); - _rtgui_cursor->screen_pitch = _rtgui_cursor->bpp * gd->width; - -#ifdef RTGUI_USING_MOUSE_CURSOR - /* init cursor image */ - _rtgui_cursor->cursor_image = rtgui_image_create_from_mem("xpm", cursor_xpm, sizeof(cursor_xpm)); - if (_rtgui_cursor->cursor_image == RT_NULL) - { - rtgui_free(_rtgui_cursor); - _rtgui_cursor = RT_NULL; - - return; - } - - /* init rect */ - _rtgui_cursor->rect.x1 = _rtgui_cursor->rect.y1 = 0; - _rtgui_cursor->rect.x2 = _rtgui_cursor->cursor_image->w; - _rtgui_cursor->rect.y2 = _rtgui_cursor->cursor_image->h; - - _rtgui_cursor->cursor_pitch = _rtgui_cursor->cursor_image->w * _rtgui_cursor->bpp; - - _rtgui_cursor->show_cursor = RT_TRUE; - _rtgui_cursor->show_cursor_count = 0; - _rtgui_cursor->cursor_saved = rtgui_malloc(_rtgui_cursor->cursor_image->w * - _rtgui_cursor->cursor_image->h * _rtgui_cursor->bpp); -#endif - - /* init window move save image */ - _rtgui_cursor->win_rect_has_saved = RT_FALSE; - _rtgui_cursor->win_rect_show = RT_FALSE; - - _rtgui_cursor->win_left = rtgui_malloc(_rtgui_cursor->bpp * gd->height * WIN_MOVE_BORDER); - _rtgui_cursor->win_right = rtgui_malloc(_rtgui_cursor->bpp * gd->height * WIN_MOVE_BORDER); - _rtgui_cursor->win_top = rtgui_malloc(_rtgui_cursor->bpp * gd->width * WIN_MOVE_BORDER); - _rtgui_cursor->win_bottom = rtgui_malloc(_rtgui_cursor->bpp * gd->width * WIN_MOVE_BORDER); -} - -void rtgui_mouse_moveto(int x, int y) -{ -#ifdef RTGUI_USING_MOUSE_CURSOR - rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER); -#endif - - if (x != _rtgui_cursor->cx || - y != _rtgui_cursor->cy) - { - if (_rtgui_cursor->win_rect_show) - { - if (_rtgui_cursor->win_rect_has_saved == RT_TRUE) - { - rtgui_winrect_restore(); - } - -#ifdef RTGUI_USING_MOUSE_CURSOR - rtgui_mouse_hide_cursor(); -#endif - - /* move winrect */ - rtgui_rect_moveto(&(_rtgui_cursor->win_rect), x - _rtgui_cursor->cx, - y - _rtgui_cursor->cy); - rtgui_winrect_save(); - - /* move current cursor */ - _rtgui_cursor->cx = x; - _rtgui_cursor->cy = y; - -#ifdef RTGUI_USING_MOUSE_CURSOR - /* show cursor */ - rtgui_mouse_show_cursor(); -#endif - /* show winrect */ - rtgui_winrect_show(); - } - else - { -#ifdef RTGUI_USING_MOUSE_CURSOR - rtgui_mouse_hide_cursor(); -#endif - /* move current cursor */ - _rtgui_cursor->cx = x; - _rtgui_cursor->cy = y; - -#ifdef RTGUI_USING_MOUSE_CURSOR - /* show cursor */ - rtgui_mouse_show_cursor(); -#endif - } - } - -#ifdef RTGUI_USING_MOUSE_CURSOR - rt_mutex_release(&cursor_mutex); -#endif -} - -#ifdef RTGUI_USING_MOUSE_CURSOR -void rtgui_mouse_set_cursor_enable(rt_bool_t enable) -{ - _rtgui_cursor->show_cursor = enable; -} - -/* set current cursor image */ -void rtgui_mouse_set_cursor(rtgui_image_t* cursor) -{ -} - -void rtgui_mouse_get_cursor_rect(rtgui_rect_t* rect) -{ - if (rect != RT_NULL) - { - *rect = _rtgui_cursor->rect; - } -} - -void rtgui_mouse_show_cursor() -{ - if (_rtgui_cursor->show_cursor == RT_FALSE) - return; - - _rtgui_cursor->show_cursor_count ++; - if (_rtgui_cursor->show_cursor_count == 1) - { - /* save show mouse area */ - rtgui_cursor_save(); - - /* show mouse cursor */ - rtgui_cursor_show(); - } -} - -void rtgui_mouse_hide_cursor() -{ - if (_rtgui_cursor->show_cursor == RT_FALSE) - return; - - if (_rtgui_cursor->show_cursor_count == 1) - { - /* display the cursor coverage area */ - rtgui_cursor_restore(); - } - _rtgui_cursor->show_cursor_count --; -} - -rt_bool_t rtgui_mouse_is_intersect(rtgui_rect_t* r) -{ - return rtgui_rect_is_intersect(&(_rtgui_cursor->rect), r) == RT_EOK? RT_TRUE : RT_FALSE; -} - -/* display the saved cursor area to screen */ -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 - + _rtgui_cursor->cx * _rtgui_cursor->bpp; - cursor_ptr = _rtgui_cursor->cursor_saved; - - height = (_rtgui_cursor->cy + _rtgui_cursor->cursor_image->h < - rtgui_graphic_driver_get_default()->height)? _rtgui_cursor->cursor_image->h : - rtgui_graphic_driver_get_default()->height - _rtgui_cursor->cy; - - cursor_pitch = (_rtgui_cursor->cx + _rtgui_cursor->cursor_image->w < - rtgui_graphic_driver_get_default()->width)? _rtgui_cursor->cursor_pitch : - (rtgui_graphic_driver_get_default()->width - _rtgui_cursor->cx) * _rtgui_cursor->bpp; - - for (idx = 0; idx < height; idx ++) - { - rt_memcpy(fb_ptr, cursor_ptr, cursor_pitch); - - fb_ptr += _rtgui_cursor->screen_pitch; - cursor_ptr += _rtgui_cursor->cursor_pitch; - } -} - -/* save the cursor coverage area from screen */ -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 + - _rtgui_cursor->cx * _rtgui_cursor->bpp; - cursor_ptr = _rtgui_cursor->cursor_saved; - - height = (_rtgui_cursor->cy + _rtgui_cursor->cursor_image->h < - rtgui_graphic_driver_get_default()->height)? _rtgui_cursor->cursor_image->h : - rtgui_graphic_driver_get_default()->height - _rtgui_cursor->cy; - - cursor_pitch = (_rtgui_cursor->cx + _rtgui_cursor->cursor_image->w < - rtgui_graphic_driver_get_default()->width)? _rtgui_cursor->cursor_pitch : - (rtgui_graphic_driver_get_default()->width - _rtgui_cursor->cx) * _rtgui_cursor->bpp; - - for (idx = 0; idx < height; idx ++) - { - rt_memcpy(cursor_ptr, fb_ptr, cursor_pitch); - - fb_ptr += _rtgui_cursor->screen_pitch; - cursor_ptr += _rtgui_cursor->cursor_pitch; - } -} - -static void rtgui_cursor_show() -{ - rt_uint16_t x, y; - rtgui_color_t* ptr; - rtgui_rect_t rect; - void (*set_pixel) (rtgui_color_t *c, rt_uint16_t x, rt_uint16_t y); - - ptr = (rtgui_color_t*) _rtgui_cursor->cursor_image->data; - set_pixel = rtgui_graphic_driver_get_default()->set_pixel; - - rtgui_mouse_get_cursor_rect(&rect); - rtgui_rect_moveto(&rect, _rtgui_cursor->cx, _rtgui_cursor->cy); - - /* draw each point */ - for (y = rect.y1; y < rect.y2; y ++) - { - for (x = rect.x1; x < rect.x2; x++) - { - /* not alpha */ - if ((*ptr >> 24) != 255) - { - set_pixel(ptr, x, y); - } - - /* move to next color buffer */ - ptr ++; - } - } - - /* update rect */ - rtgui_graphic_driver_get_default()->screen_update(&rect); -} -#endif - -void rtgui_winrect_set(struct rtgui_topwin* topwin) -{ - /* set win rect show */ - _rtgui_cursor->win_rect_show = RT_TRUE; - - /* set win rect */ - _rtgui_cursor->win_rect = topwin->title == RT_NULL? topwin->extent : RTGUI_WIDGET(topwin->title)->extent; - _rtgui_cursor->topwin = topwin; -} - -rt_bool_t rtgui_winrect_moved_done(rtgui_rect_t* winrect, struct rtgui_topwin** topwin) -{ - rt_bool_t moved = RT_FALSE; - - /* no win rect */ - if (winrect == RT_NULL) return RT_FALSE; - - /* restore winrect */ - if (_rtgui_cursor->win_rect_has_saved) - { - rtgui_winrect_restore(); - - moved = RT_TRUE; - } - - /* clear win rect show */ - _rtgui_cursor->win_rect_show = RT_FALSE; - _rtgui_cursor->win_rect_has_saved = RT_FALSE; - - /* return win rect */ - *winrect = _rtgui_cursor->win_rect; - *topwin = _rtgui_cursor->topwin; - - return moved; -} - -rt_bool_t rtgui_winrect_is_moved() -{ - return _rtgui_cursor->win_rect_show; -} - -/* show winrect */ -static void rtgui_winrect_show() -{ - rt_uint16_t x, y; - rtgui_color_t c; - rtgui_rect_t screen_rect, win_rect, win_rect_inner; - void (*set_pixel) (rtgui_color_t *c, rt_base_t x, rt_base_t y); - - c = black; - set_pixel = rtgui_graphic_driver_get_default()->set_pixel; - - win_rect = _rtgui_cursor->win_rect; - win_rect_inner = win_rect; - rtgui_rect_inflate(&win_rect_inner, -WIN_MOVE_BORDER); - - rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), - &screen_rect); - rtgui_rect_intersect(&screen_rect, &win_rect); - rtgui_rect_intersect(&screen_rect, &win_rect_inner); - - /* draw left */ - for (y = win_rect.y1; y < win_rect.y2; y ++) - { - for (x = win_rect.x1; x < win_rect_inner.x1; x++) - if ((x + y) & 0x01) set_pixel(&c, x, y); - } - - /* draw right */ - for (y = win_rect.y1; y < win_rect.y2; y ++) - { - for (x = win_rect_inner.x2; x < win_rect.x2; x++) - if ((x + y) & 0x01) set_pixel(&c, x, y); - } - - /* draw top border */ - for (y = win_rect.y1; y < win_rect_inner.y1; y ++) - { - for (x = win_rect_inner.x1; x < win_rect_inner.x2; x++) - if ((x + y) & 0x01) set_pixel(&c, x, y); - } - - /* draw bottom border */ - for (y = win_rect_inner.y2; y < win_rect.y2; y ++) - { - for (x = win_rect_inner.x1; x < win_rect_inner.x2; x++) - if ((x + y) & 0x01) set_pixel(&c, x, y); - } - - /* update rect */ - rtgui_graphic_driver_get_default()->screen_update(&win_rect); -} - -#define display_direct_memcpy(src, dest, src_pitch, dest_pitch, height, len) \ - for (idx = 0; idx < height; idx ++) \ - { \ - rt_memcpy(dest, src, len); \ - src += src_pitch; \ - dest += dest_pitch; \ - } - -static void rtgui_winrect_restore() -{ - rt_uint8_t *winrect_ptr, *fb_ptr; - int winrect_pitch, idx; - rtgui_rect_t screen_rect, win_rect; - - win_rect = _rtgui_cursor->win_rect; - - rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), - &screen_rect); - rtgui_rect_intersect(&screen_rect, &win_rect); - - /* restore winrect left */ - fb_ptr = _rtgui_cursor->framebuffer + 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; - display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch, - (win_rect.y2 - win_rect.y1), winrect_pitch); - - /* restore winrect right */ - fb_ptr = _rtgui_cursor->framebuffer + 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; - display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch, - (win_rect.y2 - win_rect.y1), winrect_pitch); - - /* restore winrect top */ - fb_ptr = _rtgui_cursor->framebuffer + 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; - display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch, - WIN_MOVE_BORDER, winrect_pitch); - - /* restore winrect bottom */ - fb_ptr = _rtgui_cursor->framebuffer + (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, - WIN_MOVE_BORDER, winrect_pitch); -} - -static void rtgui_winrect_save() -{ - rt_uint8_t *winrect_ptr, *fb_ptr; - int winrect_pitch, idx; - rtgui_rect_t screen_rect, win_rect; - - win_rect = _rtgui_cursor->win_rect; - - rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), - &screen_rect); - rtgui_rect_intersect(&screen_rect, &win_rect); - - /* set winrect has saved */ - _rtgui_cursor->win_rect_has_saved = RT_TRUE; - - /* save winrect left */ - fb_ptr = _rtgui_cursor->framebuffer + 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; - display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch, - (win_rect.y2 - win_rect.y1), winrect_pitch); - - /* save winrect right */ - fb_ptr = _rtgui_cursor->framebuffer + 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; - display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch, - (win_rect.y2 - win_rect.y1), winrect_pitch); - - /* save winrect top */ - fb_ptr = _rtgui_cursor->framebuffer + 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; - display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch, - WIN_MOVE_BORDER, winrect_pitch); - - /* save winrect bottom */ - fb_ptr = _rtgui_cursor->framebuffer + (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, - WIN_MOVE_BORDER, winrect_pitch); -} - -void rtgui_mouse_monitor_append(rtgui_list_t* head, rtgui_rect_t* rect) -{ - struct rtgui_mouse_monitor* mmonitor; - - /* check parameters */ - if (head == RT_NULL || rect == RT_NULL) return; - - /* create a mouse monitor node */ - mmonitor = (struct rtgui_mouse_monitor*) rtgui_malloc (sizeof(struct rtgui_mouse_monitor)); - if (mmonitor == RT_NULL) return; /* no memory */ - - /* set mouse monitor node */ - mmonitor->rect = *rect; - rtgui_list_init(&(mmonitor->list)); - - /* append to list */ - rtgui_list_append(head, &(mmonitor->list)); -} - -void rtgui_mouse_monitor_remove(rtgui_list_t* head, rtgui_rect_t* rect) -{ - struct rtgui_list_node* node; - struct rtgui_mouse_monitor* mmonitor; - - /* check parameters */ - if (head == RT_NULL || rect == RT_NULL) return; - - for (node = head->next; node != RT_NULL; node = node->next) - { - mmonitor = rtgui_list_entry(node, struct rtgui_mouse_monitor, list); - if (mmonitor->rect.x1 == rect->x1 && - mmonitor->rect.x2 == rect->x2 && - mmonitor->rect.y1 == rect->y1 && - mmonitor->rect.y2 == rect->y2) - { - /* found node */ - rtgui_list_remove(head, node); - rtgui_free(mmonitor); - - return ; - } - } -} - -rt_bool_t rtgui_mouse_monitor_contains_point(rtgui_list_t* head, int x, int y) -{ - struct rtgui_list_node* node; - - /* check parameter */ - if (head == RT_NULL) return RT_FALSE; - - rtgui_list_foreach(node, head) - { - struct rtgui_mouse_monitor* monitor = rtgui_list_entry(node, - struct rtgui_mouse_monitor, list); - - if (rtgui_rect_contains_point(&(monitor->rect), x, y) == RT_EOK) - { - return RT_TRUE; - } - } - - return RT_FALSE; -} diff --git a/rtgui/server/mouse.h b/rtgui/server/mouse.h deleted file mode 100644 index da6c16485e..0000000000 --- a/rtgui/server/mouse.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * File : mouse.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, 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 - * 2009-10-16 Bernard first version - */ -#ifndef __RTGUI_MOUSE_H__ -#define __RTGUI_MOUSE_H__ - -#include <rtgui/rtgui.h> -#include <rtgui/image.h> -#include "topwin.h" - -struct rtgui_mouse_monitor -{ - /* event rect */ - rtgui_rect_t rect; - - /* node list */ - rtgui_list_t list; -}; -typedef struct rtgui_mouse_monitor rtgui_mouse_monitor_t; - -void rtgui_mouse_init(void); -void rtgui_mouse_moveto(int x, int y); - -void rtgui_mouse_set_cursor_enable(rt_bool_t enable); -void rtgui_mouse_set_cursor(rtgui_image_t* cursor); -void rtgui_mouse_get_cursor_rect(rtgui_rect_t* rect); - -void rtgui_mouse_show_cursor(void); -void rtgui_mouse_hide_cursor(void); - -rt_bool_t rtgui_mouse_is_intersect(rtgui_rect_t* r); - -rt_bool_t rtgui_winrect_is_moved(void); -void rtgui_winrect_set(struct rtgui_topwin* topwin); -rt_bool_t rtgui_winrect_moved_done(rtgui_rect_t* winrect, struct rtgui_topwin** topwin); - -void rtgui_mouse_monitor_append(rtgui_list_t* head, rtgui_rect_t* rect); -void rtgui_mouse_monitor_remove(rtgui_list_t* head, rtgui_rect_t* rect); -rt_bool_t rtgui_mouse_monitor_contains_point(rtgui_list_t* head, int x, int y); - -#endif diff --git a/rtgui/server/panel.c b/rtgui/server/panel.c deleted file mode 100644 index 0d767a3f3d..0000000000 --- a/rtgui/server/panel.c +++ /dev/null @@ -1,306 +0,0 @@ -/* - * File : panel.c - * This file is part of RTGUI in RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, 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 - * 2009-10-04 Bernard first version - */ - -#include "panel.h" -#include "mouse.h" - -#include <rtgui/rtgui_system.h> - -/* the global parameter */ -struct rtgui_list_node _rtgui_panel_list; - -void rtgui_panel_init() -{ - rtgui_list_init(&_rtgui_panel_list); -} - -void rtgui_panel_register(char* name, rtgui_rect_t* extent) -{ - register rt_base_t temp; - struct rtgui_panel* panel; - - panel = rtgui_panel_find(name); - if (panel != RT_NULL ) - { - /* there are already a same named panel exist. */ - return; - } - - panel = rtgui_malloc(sizeof(struct rtgui_panel)); - if (panel == RT_NULL) - { - /* can't alloc memory */ - return; - } - - /* copy name */ - for (temp = 0; temp < RTGUI_NAME_MAX; temp ++) - { - panel->name[temp] = name[temp]; - } - - /* copy extent */ - panel->extent = *extent; - - panel->wm_thread = RT_NULL; - - /* init list */ - rtgui_list_init(&(panel->sibling)); - rtgui_list_init(&(panel->thread_list)); - - /* add panel to panel list */ - rtgui_list_insert(&_rtgui_panel_list, &(panel->sibling)); -} - -void rtgui_panel_deregister(char* name) -{ - struct rtgui_panel* panel; - - panel = rtgui_panel_find(name); - if (panel != RT_NULL) - { - rtgui_list_remove(&_rtgui_panel_list, &(panel->sibling)); - - /* free pane node */ - rtgui_free(panel); - } -} - -/* set default focused panel, please use it after registered panel */ -void rtgui_panel_set_default_focused(char* name) -{ - extern struct rtgui_panel* rtgui_server_focus_panel; - struct rtgui_panel* panel; - - panel = rtgui_panel_find(name); - if (panel != RT_NULL) - { - rtgui_server_focus_panel = panel; - } -} - -struct rtgui_panel* rtgui_panel_find(char* name) -{ - struct rtgui_list_node* node; - struct rtgui_panel* panel; - - rtgui_list_foreach(node, &_rtgui_panel_list) - { - panel = rtgui_list_entry(node, struct rtgui_panel, sibling); - - if (rt_strncmp(panel->name, name, RTGUI_NAME_MAX) == 0) - { - return panel; - } - } - - return RT_NULL; -} - -struct rtgui_panel* rtgui_panel_thread_add(char* name, rt_thread_t tid) -{ - struct rtgui_panel* panel; - - panel = rtgui_panel_find(name); - if (panel != RT_NULL ) - { - struct rtgui_panel_thread* thread; - - /* allocate panel thread node */ - thread = rtgui_malloc(sizeof(struct rtgui_panel_thread)); - if (thread == RT_NULL) - { - return RT_NULL; - } - - /* construct panel thread node */ - thread->tid = tid; - - /* init list */ - rtgui_list_init(&(thread->list)); - rtgui_list_init(&(thread->monitor_list)); - - /* append thread to the list */ - rtgui_list_append(&(panel->thread_list), &(thread->list)); - } - - return panel; -} - -void rtgui_panel_thread_remove(rtgui_panel_t* panel, rt_thread_t tid) -{ - if (panel != RT_NULL ) - { - struct rtgui_list_node* node; - struct rtgui_panel_thread* thread; - - rtgui_list_foreach(node, &(panel->thread_list)) - { - thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); - if (thread->tid == tid) - { - /* remove node from list */ - rtgui_list_remove(&(panel->thread_list), &(thread->list)); - - /* free the panel thread node */ - rtgui_free(thread); - return; - } - } - } -} - -rt_thread_t rtgui_panel_get_active_thread(rtgui_panel_t* panel) -{ - if (panel != RT_NULL) - { - if (panel->thread_list.next != RT_NULL) - { - struct rtgui_panel_thread* thread; - thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); - - return thread->tid; - } - } - - return RT_NULL; -} - -void rtgui_panel_set_active_thread(rtgui_panel_t* panel, rt_thread_t tid) -{ - /* get old active thread */ - rt_thread_t prev_actived = rtgui_panel_get_active_thread(panel); - if (prev_actived != tid) - { - /* de-active old active workbench */ - struct rtgui_event_panel_hide ehide; - RTGUI_EVENT_PANEL_HIDE_INIT(&ehide); - - ehide.panel = panel; - ehide.workbench = RT_NULL; - rtgui_thread_send_urgent(prev_actived, &(ehide.parent), sizeof (ehide)); - } - - if (panel != RT_NULL ) - { - struct rtgui_list_node* node; - struct rtgui_panel_thread* thread; - - rtgui_list_foreach(node, &(panel->thread_list)) - { - thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); - if (thread->tid == tid) - { - /* remove node from list */ - rtgui_list_remove(&(panel->thread_list), &(thread->list)); - - /* insert node to the header */ - rtgui_list_insert(&(panel->thread_list), &(thread->list)); - return; - } - } - } -} - -/* deactivate current activated thread -- move it to the end of list */ -void rtgui_panel_deactive_thread(rtgui_panel_t* panel) -{ - RT_ASSERT(panel == RT_NULL); - - if (panel->thread_list.next != RT_NULL) - { - struct rtgui_panel_thread* thread; - thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); - - /* remove it */ - panel->thread_list.next = thread->list.next; - - /* append to the tail of thread list */ - rtgui_list_append(&(panel->thread_list), &(thread->list)); - } -} - -/** - * get the panel which contains a point(x, y) - */ -rtgui_panel_t* rtgui_panel_get_contain(int x, int y) -{ - struct rtgui_list_node* node; - struct rtgui_panel* panel; - - rtgui_list_foreach(node, &(_rtgui_panel_list)) - { - panel = rtgui_list_entry(node, struct rtgui_panel, sibling); - if (rtgui_rect_contains_point(&(panel->extent), x, y) == RT_EOK) - { - return panel; - } - } - - return RT_NULL; -} - -/** - * append a rect to panel mouse monitor rect list - */ -void rtgui_panel_append_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect) -{ - if (panel != RT_NULL ) - { - struct rtgui_list_node* node; - struct rtgui_panel_thread* thread; - - rtgui_list_foreach(node, &(panel->thread_list)) - { - thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); - if (thread->tid == tid) - { - /* add the monitor rect to list */ - rtgui_mouse_monitor_append(&(thread->monitor_list), rect); - return; - } - } - } -} - -/** - * remove a rect from panel mouse monitor rect list - */ -void rtgui_panel_remove_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect) -{ - if (panel != RT_NULL ) - { - struct rtgui_list_node* node; - struct rtgui_panel_thread* thread; - - rtgui_list_foreach(node, &(panel->thread_list)) - { - thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); - if (thread->tid == tid) - { - /* remove the monitor rect from list */ - rtgui_mouse_monitor_remove(&(thread->monitor_list), rect); - return; - } - } - } -} - -void rtgui_panel_set_wm(rtgui_panel_t* panel, rt_thread_t wm) -{ - RT_ASSERT(wm != RT_NULL); - RT_ASSERT(panel != RT_NULL); - - panel->wm_thread = wm; -} diff --git a/rtgui/server/panel.h b/rtgui/server/panel.h deleted file mode 100644 index fffaa35dc0..0000000000 --- a/rtgui/server/panel.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * File : panel.h - * This file is part of RTGUI in RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, 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 - * 2009-10-04 Bernard first version - */ - -#ifndef __RT_PANEL_H__ -#define __RT_PANEL_H__ - -#include <rtgui/rtgui.h> -#include <rtgui/list.h> -#include <rtgui/region.h> - -struct rtgui_panel_thread -{ - /* thread id */ - rt_thread_t tid; - - /* the list of thread */ - rtgui_list_t list; - - /* monitor rect list */ - rtgui_list_t monitor_list; -}; -typedef struct rtgui_panel_thread rtgui_panel_thread_list_t; - -struct rtgui_panel -{ - char name[RTGUI_NAME_MAX]; - - /* the extent of panel */ - rtgui_rect_t extent; - - /* the list of panel */ - rtgui_list_t sibling; - - /* the thread list in this panel */ - rtgui_list_t thread_list; - - /* the workbench manager thread */ - rt_thread_t wm_thread; -}; - -/* find panel by name */ -struct rtgui_panel* rtgui_panel_find(char* name); - -/* add or remove application thread from specified panel */ -rtgui_panel_t* rtgui_panel_thread_add(char* name, rt_thread_t tid); -void rtgui_panel_thread_remove(rtgui_panel_t* panel, rt_thread_t tid); - -rt_thread_t rtgui_panel_get_active_thread(rtgui_panel_t* panel); -void rtgui_panel_set_active_thread(rtgui_panel_t* panel, rt_thread_t tid); - -rtgui_panel_t* rtgui_panel_get_contain(int x, int y); -void rtgui_panel_set_wm(rtgui_panel_t* panel, rt_thread_t wm); - -void rtgui_panel_append_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect); -void rtgui_panel_remove_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect); - -#endif diff --git a/rtgui/server/server.c b/rtgui/server/server.c deleted file mode 100644 index 2d4b5c317b..0000000000 --- a/rtgui/server/server.c +++ /dev/null @@ -1,636 +0,0 @@ -/* - * File : server.c - * This file is part of RTGUI in RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, 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 - * 2009-10-04 Bernard first version - */ - -#include <rtgui/rtgui.h> -#include <rtgui/event.h> -#include <rtgui/rtgui_system.h> -#include <rtgui/driver.h> - -#include "mouse.h" -#include "panel.h" -#include "topwin.h" - -static struct rt_thread *rtgui_server_tid; -static struct rt_messagequeue *rtgui_server_mq; - -extern struct rtgui_topwin* rtgui_server_focus_topwin; -struct rtgui_panel* rtgui_server_focus_panel = RT_NULL; - -void rtgui_server_create_application(struct rtgui_event_panel_attach* event) -{ - struct rtgui_panel* panel = rtgui_panel_find(event->panel_name); - - if (panel != RT_NULL) - { - struct rtgui_event_panel_info ep; - RTGUI_EVENT_PANEL_INFO_INIT(&ep); - - if (panel->wm_thread != RT_NULL) - { - /* notify to workbench */ - rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_attach)); - } - - /* send the responses - ok */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); - - /* send the panel info */ - ep.panel = panel; - ep.extent = panel->extent; - rtgui_thread_send(event->parent.sender, (struct rtgui_event*)&ep, sizeof(ep)); - - rtgui_panel_thread_add(event->panel_name, event->parent.sender); - } - else - { - /* send the responses - failure */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_NRC); - } -} - -void rtgui_server_destroy_application(struct rtgui_event_panel_detach* event) -{ - struct rtgui_panel* panel = event->panel; - - if (panel != RT_NULL) - { - if (panel->wm_thread != RT_NULL) - { - /* notify to workbench */ - rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_detach)); - } - - /* send the responses */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); - - rtgui_panel_thread_remove(panel, event->parent.sender); - - { - /* get next thread and active it */ - rt_thread_t tid = rtgui_panel_get_active_thread(panel); - - /* let this thread repaint */ - struct rtgui_event_paint epaint; - RTGUI_EVENT_PAINT_INIT(&epaint); - epaint.wid = RT_NULL; - rtgui_thread_send(tid, (struct rtgui_event*)&epaint, sizeof(epaint)); - } - } - else - { - /* send the responses - failure */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_NRC); - } -} - -void rtgui_server_thread_panel_show(struct rtgui_event_panel_show* event) -{ - struct rtgui_panel* panel = event->panel; - - if (panel != RT_NULL) - { - struct rtgui_event_paint epaint; - - /* send the responses */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); - - if (panel->wm_thread != RT_NULL) - { - /* notify to workbench */ - rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_show)); - } - - rtgui_panel_set_active_thread(panel, event->parent.sender); - - /* send all topwin clip info */ - rtgui_topwin_update_clip_to_panel(panel); - - /* send paint event */ - RTGUI_EVENT_PAINT_INIT(&epaint); - epaint.wid = RT_NULL; - rtgui_thread_send(event->parent.sender, (struct rtgui_event*)&epaint, - sizeof(epaint)); - } - else - { - /* send failed */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); - } -} - -void rtgui_server_thread_panel_hide(struct rtgui_event_panel_hide* event) -{ - struct rtgui_panel* panel = event->panel; - - if (panel != RT_NULL) - { - rt_thread_t tid; - struct rtgui_event_paint epaint; - - /* send the responses */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); - - if (panel->thread_list.next != RT_NULL) - { - struct rtgui_panel_thread* thread; - thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); - - /* remove it */ - panel->thread_list.next = thread->list.next; - - /* append to the tail of thread list */ - rtgui_list_append(&(panel->thread_list), &(thread->list)); - } - - /* get new active thread */ - tid = rtgui_panel_get_active_thread(panel); - /* send all topwin clip info */ - rtgui_topwin_update_clip_to_panel(panel); - - /* send paint event */ - RTGUI_EVENT_PAINT_INIT(&epaint); - epaint.wid = RT_NULL; - rtgui_thread_send(tid, (struct rtgui_event*)&epaint, sizeof(epaint)); - } - else - { - /* send failed */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); - } -} - -void rtgui_server_handle_set_wm(struct rtgui_event_set_wm *event) -{ - struct rtgui_panel* panel = rtgui_panel_find(event->panel_name); - - if (panel != RT_NULL) - { - rtgui_panel_set_wm(panel, event->parent.sender); - } -} - -void rtgui_server_handle_update(struct rtgui_event_update_end* event) -{ - struct rtgui_graphic_driver* driver = rtgui_graphic_driver_get_default(); - if (driver != RT_NULL) - { - driver->screen_update(&(event->rect)); - } -} - -void rtgui_server_handle_monitor_add(struct rtgui_event_monitor* event) -{ - if (event->panel != RT_NULL) - { - /* append monitor rect to panel list */ - rtgui_panel_append_monitor_rect(event->panel, event->parent.sender, &(event->rect)); - } - else - { - /* add monitor rect to top window list */ - rtgui_topwin_append_monitor_rect(event->wid, &(event->rect)); - } -} - -void rtgui_server_handle_monitor_remove(struct rtgui_event_monitor* event) -{ - if (event->panel != RT_NULL) - { - /* add monitor rect to panel list */ - rtgui_panel_remove_monitor_rect(event->panel, event->parent.sender, &(event->rect)); - } - else - { - /* add monitor rect to top window list */ - rtgui_topwin_remove_monitor_rect(event->wid, &(event->rect)); - } -} - -void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event) -{ - struct rtgui_topwin* wnd; - struct rtgui_panel* panel; - - /* re-init to server thread */ - RTGUI_EVENT_MOUSE_BUTTON_INIT(event); - - if (rtgui_winrect_is_moved() && - event->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP)) - { - struct rtgui_topwin* topwin; - rtgui_rect_t rect; - - if (rtgui_winrect_moved_done(&rect, &topwin) == RT_TRUE) - { - struct rtgui_event_win_move ewin; - - /* move window */ - RTGUI_EVENT_WIN_MOVE_INIT(&ewin); - ewin.wid = topwin->wid; - if (topwin->title != RT_NULL) - { - if (topwin->flag & WINTITLE_BORDER) - { - ewin.x = rect.x1 + WINTITLE_BORDER_SIZE; - ewin.y = rect.y1 + WINTITLE_BORDER_SIZE; - } - if (!(topwin->flag & WINTITLE_NO)) ewin.y += WINTITLE_HEIGHT; - } - else - { - ewin.x = rect.x1; - ewin.y = rect.y1; - } - - /* send to client thread */ - rtgui_thread_send(topwin->tid, &(ewin.parent), sizeof(ewin)); - - return; - } - } - - /* get the wnd which contains the mouse */ - wnd = rtgui_topwin_get_wnd(event->x, event->y); - if (wnd != RT_NULL) - { - event->wid = wnd->wid; - - if (rtgui_server_focus_topwin != wnd) - { - /* raise this window */ - rtgui_topwin_raise(wnd->wid, wnd->tid); - rtgui_server_focus_panel = RT_NULL; - } - - if (wnd->title != RT_NULL && - rtgui_rect_contains_point(&(RTGUI_WIDGET(wnd->title)->extent), event->x, event->y) == RT_EOK) - { - rtgui_topwin_title_onmouse(wnd, event); - } - else - { - /* send mouse event to thread */ - rtgui_thread_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_mouse)); - } - return ; - } - - /* get the panel which contains the mouse */ - panel = rtgui_panel_get_contain(event->x, event->y); - if (panel != RT_NULL) - { - /* deactivate old window */ - if (rtgui_server_focus_topwin != RT_NULL) - { - rtgui_topwin_deactivate_win(rtgui_server_focus_topwin); - } - - rtgui_server_focus_panel = panel; - rtgui_server_focus_topwin = RT_NULL; - - /* set destination window to null */ - event->wid = RT_NULL; - - /* send mouse event to thread */ - if (rtgui_panel_get_active_thread(panel) != RT_NULL) - { - rtgui_thread_send(rtgui_panel_get_active_thread(panel), - (struct rtgui_event*)event, - sizeof(struct rtgui_event_mouse)); - } - } -} - -static struct rtgui_panel* last_monitor_panel = RT_NULL; -static struct rtgui_topwin* last_monitor_topwin = RT_NULL; - -void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse* event) -{ - /* the topwin contains current mouse */ - struct rtgui_topwin* win = RT_NULL; - struct rtgui_panel* panel = RT_NULL; - - /* re-init mouse event */ - RTGUI_EVENT_MOUSE_MOTION_INIT(event); - - /* find the panel or topwin which monitor the mouse motion */ - win = rtgui_topwin_get_wnd(event->x, event->y); - if (win == RT_NULL) - { - /* try to find monitor on the panel */ - panel = rtgui_panel_get_contain(event->x, event->y); - - if (panel != RT_NULL) - { - struct rtgui_panel_thread* thread; - - /* get active panel thread */ - if (panel->thread_list.next != RT_NULL) - { - thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); - if (!rtgui_mouse_monitor_contains_point(&(thread->monitor_list), - event->x, event->y) == RT_TRUE) - { - /* no monitor in this panel */ - panel = RT_NULL; - } - } - } - } - else if (win->monitor_list.next != RT_NULL) - { - /* check whether the monitor exist */ - if (rtgui_mouse_monitor_contains_point(&(win->monitor_list), event->x, event->y) != RT_TRUE) - { - win = RT_NULL; - - /* try to find monitor on the panel */ - panel = rtgui_panel_get_contain(event->x, event->y); - if (panel != RT_NULL) - { - struct rtgui_panel_thread* thread; - - /* get active panel thread */ - if (panel->thread_list.next != RT_NULL) - { - thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); - if (!rtgui_mouse_monitor_contains_point(&(thread->monitor_list), - event->x, event->y) == RT_TRUE) - { - /* no monitor in this panel */ - panel = RT_NULL; - } - } - } - } - } - else - { - win = RT_NULL; - } - - /* check old panel or window */ - if (last_monitor_panel != RT_NULL) - { - rt_thread_t tid = rtgui_panel_get_active_thread(last_monitor_panel); - - /* send mouse motion event */ - if (tid != RT_NULL) - { - event->wid = RT_NULL; - rtgui_thread_send(tid, &(event->parent), sizeof(struct rtgui_event_mouse)); - } - } - else if (last_monitor_topwin != RT_NULL) - { - event->wid = last_monitor_topwin->wid; - - /* send mouse motion event */ - rtgui_thread_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); - } - - if (last_monitor_panel != panel) - { - last_monitor_panel = panel; - if (last_monitor_panel != RT_NULL) - { - rt_thread_t tid = rtgui_panel_get_active_thread(last_monitor_panel); - event->wid = RT_NULL; - - /* send mouse motion event */ - if (tid != RT_NULL) - rtgui_thread_send(tid, &(event->parent), sizeof(struct rtgui_event_mouse)); - } - } - - if (last_monitor_topwin != win) - { - last_monitor_topwin = win; - if (last_monitor_topwin != RT_NULL) - { - event->wid = last_monitor_topwin->wid; - - /* send mouse motion event */ - rtgui_thread_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); - } - } - - /* move mouse to (x, y) */ - rtgui_mouse_moveto(event->x, event->y); -} - -void rtgui_server_handle_kbd(struct rtgui_event_kbd* event) -{ - struct rtgui_topwin* wnd; - struct rtgui_panel* panel; - - /* re-init to server thread */ - RTGUI_EVENT_KBD_INIT(event); - - /* todo: handle input method and global shortcut */ - - /* send to focus window or focus panel */ - wnd = rtgui_server_focus_topwin; - if (wnd != RT_NULL && wnd->flag & WINTITLE_ACTIVATE) - { - /* send to focus window */ - event->wid = wnd->wid; - - /* send keyboard event to thread */ - rtgui_thread_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd)); - - return; - } - - panel = rtgui_server_focus_panel; - if (panel != RT_NULL) - { - /* send to focus panel */ - event->wid = RT_NULL; - - /* send keyboard event to thread */ - rtgui_thread_send(rtgui_panel_get_active_thread(panel), - (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd)); - } -} - -#ifdef __WIN32__ -#include <windows.h> -#endif - -/** - * rtgui server thread's entry - */ -static void rtgui_server_entry(void* parameter) -{ -#ifdef __WIN32__ - /* set the server thread to highest */ - HANDLE hCurrentThread = GetCurrentThread(); - SetThreadPriority(hCurrentThread, THREAD_PRIORITY_HIGHEST); -#endif - -#ifdef RTGUI_USING_SMALL_SIZE - /* create rtgui server msgq */ - rtgui_server_mq = rt_mq_create("rtgui", - 32, 16, RT_IPC_FLAG_FIFO); -#else - /* create rtgui server msgq */ - rtgui_server_mq = rt_mq_create("rtgui", - 256, 8, RT_IPC_FLAG_FIFO); -#endif - /* register rtgui server thread */ - rtgui_thread_register(rtgui_server_tid, rtgui_server_mq); - - /* init mouse and show */ - rtgui_mouse_init(); -#ifdef RTGUI_USING_MOUSE_CURSOR - rtgui_mouse_show_cursor(); -#endif - - while (1) - { - /* the buffer uses to receive event */ -#ifdef RTGUI_USING_SMALL_SIZE - char event_buf[64]; -#else - char event_buf[256]; -#endif - struct rtgui_event* event = (struct rtgui_event*)&(event_buf[0]); - - if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK) - { - /* dispatch event */ - switch (event->type) - { - /* panel event */ - case RTGUI_EVENT_PANEL_ATTACH: - /* register an application in panel */ - rtgui_server_create_application((struct rtgui_event_panel_attach*)event); - break; - - case RTGUI_EVENT_PANEL_DETACH: - /* unregister an application */ - rtgui_server_destroy_application((struct rtgui_event_panel_detach*)event); - break; - - case RTGUI_EVENT_PANEL_SHOW: - /* handle raise an application */ - rtgui_server_thread_panel_show((struct rtgui_event_panel_show*)event); - break; - - case RTGUI_EVENT_PANEL_HIDE: - /* handle hide an application */ - rtgui_server_thread_panel_hide((struct rtgui_event_panel_hide*)event); - break; - - case RTGUI_EVENT_SET_WM: - /* handle set workbench manager event */ - rtgui_server_handle_set_wm((struct rtgui_event_set_wm*)event); - break; - - /* window event */ - case RTGUI_EVENT_WIN_CREATE: - rtgui_thread_ack(event, RTGUI_STATUS_OK); - rtgui_topwin_add((struct rtgui_event_win_create*)event); - break; - - case RTGUI_EVENT_WIN_DESTROY: - if (rtgui_topwin_remove(((struct rtgui_event_win*)event)->wid) == RT_EOK) - rtgui_thread_ack(event, RTGUI_STATUS_OK); - else - rtgui_thread_ack(event, RTGUI_STATUS_ERROR); - break; - - case RTGUI_EVENT_WIN_SHOW: - rtgui_topwin_show((struct rtgui_event_win*)event); - break; - - case RTGUI_EVENT_WIN_HIDE: - rtgui_topwin_hide((struct rtgui_event_win*)event); - break; - - case RTGUI_EVENT_WIN_MOVE: - rtgui_topwin_move((struct rtgui_event_win_move*)event); - break; - - case RTGUI_EVENT_WIN_RESIZE: - rtgui_topwin_resize(((struct rtgui_event_win_resize*)event)->wid, - &(((struct rtgui_event_win_resize*)event)->rect)); - break; - - /* other event */ - 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; - - /* 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; - } - } - } - - /* unregister in rtgui thread */ - // rtgui_thread_deregister(rt_thread_self()); -} - -void rtgui_server_post_event(struct rtgui_event* event, rt_size_t size) -{ - rt_mq_send(rtgui_server_mq, event, size); -} - -void rtgui_server_init() -{ - rtgui_server_tid = rt_thread_create("rtgui", - rtgui_server_entry, RT_NULL, - RTGUI_SVR_THREAD_STACK_SIZE, - RTGUI_SVR_THREAD_PRIORITY, - RTGUI_SVR_THREAD_TIMESLICE); - - /* start rtgui server thread */ - if (rtgui_server_tid != RT_NULL) - rt_thread_startup(rtgui_server_tid); -} diff --git a/rtgui/server/topwin.c b/rtgui/server/topwin.c deleted file mode 100644 index ac807e26bc..0000000000 --- a/rtgui/server/topwin.c +++ /dev/null @@ -1,1044 +0,0 @@ -/* - * File : topwin.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, 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 - * 2009-10-16 Bernard first version - */ -#include "panel.h" -#include "topwin.h" -#include "mouse.h" - -#include <rtgui/event.h> -#include <rtgui/image.h> -#include <rtgui/rtgui_theme.h> -#include <rtgui/rtgui_system.h> -#include <rtgui/widgets/window.h> - -struct rtgui_topwin* rtgui_server_focus_topwin = RT_NULL; - -static struct rtgui_list_node _rtgui_topwin_show_list; -static struct rtgui_list_node _rtgui_topwin_hide_list; -static struct rt_semaphore _rtgui_topwin_lock; - -static void rtgui_topwin_update_clip(void); -static void rtgui_topwin_redraw(struct rtgui_rect* rect); - -void rtgui_topwin_init() -{ - /* init window list */ - rtgui_list_init(&_rtgui_topwin_show_list); - rtgui_list_init(&_rtgui_topwin_hide_list); - - rt_sem_init(&_rtgui_topwin_lock, - "topwin", 1, RT_IPC_FLAG_FIFO); -} - -static struct rtgui_topwin* -rtgui_topwin_search_in_list(struct rtgui_win* wid, struct rtgui_list_node* list) -{ - struct rtgui_list_node* node; - struct rtgui_topwin* topwin; - - /* search in list */ - rtgui_list_foreach(node, list) - { - topwin = rtgui_list_entry(node, struct rtgui_topwin, list); - - /* is this node? */ - if (topwin->wid == wid) - { - return topwin; - } - } - - return RT_NULL; -} - -/* add a window to window list[hide] */ -rt_err_t rtgui_topwin_add(struct rtgui_event_win_create* event) -{ - struct rtgui_topwin* topwin; - - topwin = rtgui_malloc(sizeof(struct rtgui_topwin)); - if (topwin == RT_NULL) return -RT_ERROR; - - topwin->wid = event->wid; -#ifdef RTGUI_USING_SMALL_SIZE - topwin->extent = RTGUI_WIDGET(event->wid)->extent; -#else - topwin->extent = event->extent; -#endif - topwin->tid = event->parent.sender; - - topwin->flag = 0; - if (event->parent.user & RTGUI_WIN_STYLE_NO_TITLE) topwin->flag |= WINTITLE_NO; - 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(!(topwin->flag & WINTITLE_NO) || (topwin->flag & WINTITLE_BORDER)) - { - /* get win extent */ - rtgui_rect_t rect = topwin->extent; - - /* add border rect */ - if (topwin->flag & WINTITLE_BORDER) - { - rtgui_rect_inflate(&rect, WINTITLE_BORDER_SIZE); - } - - /* add title rect */ - if (!(topwin->flag & WINTITLE_NO)) rect.y1 -= WINTITLE_HEIGHT; - -#ifdef RTGUI_USING_SMALL_SIZE - topwin->title = rtgui_wintitle_create(event->wid->title); -#else - topwin->title = rtgui_wintitle_create(event->title); -#endif - rtgui_widget_set_rect(RTGUI_WIDGET(topwin->title), &rect); - - /* update clip info */ - rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(topwin->title)); - rtgui_region_subtract_rect(&(RTGUI_WIDGET(topwin->title)->clip), - &(RTGUI_WIDGET(topwin->title)->clip), - &(topwin->extent)); - } - else topwin->title = RT_NULL; - - rtgui_list_init(&topwin->list); - rtgui_list_init(&topwin->monitor_list); - - /* add topwin node to the hidden window list */ - rtgui_list_insert(&(_rtgui_topwin_hide_list), &(topwin->list)); - - return RT_EOK; -} - -rt_err_t rtgui_topwin_remove(struct rtgui_win* wid) -{ - struct rtgui_topwin* topwin; - - /* find the topwin node */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); - - if (topwin) - { - /* remove node from list */ - rtgui_list_remove(&_rtgui_topwin_show_list, &(topwin->list)); - - rtgui_topwin_update_clip(); - - /* redraw the old rect */ - rtgui_topwin_redraw(&(topwin->extent)); - - if (rtgui_server_focus_topwin == topwin) - { - /* activate the next window */ - if (_rtgui_topwin_show_list.next != RT_NULL) - { - struct rtgui_event_win wevent; - struct rtgui_topwin* wnd; - - /* get the topwin */ - wnd = rtgui_list_entry(_rtgui_topwin_show_list.next, - struct rtgui_topwin, list); - - /* activate the window */ - RTGUI_EVENT_WIN_ACTIVATE_INIT(&wevent); - wevent.wid = wnd->wid; - rtgui_thread_send(wnd->tid, &(wevent.parent), sizeof(struct rtgui_event_win)); - - /* set new focus topwin */ - rtgui_server_focus_topwin = wnd; - } - else - { - /* there is no shown window right now */ - rtgui_server_focus_topwin = RT_NULL; - } - } - - /* free the monitor rect list, topwin node and title */ - while (topwin->monitor_list.next != RT_NULL) - { - struct rtgui_mouse_monitor* monitor = rtgui_list_entry(topwin->monitor_list.next, - struct rtgui_mouse_monitor, list); - - topwin->monitor_list.next = topwin->monitor_list.next->next; - rtgui_free(monitor); - } - - /* destroy win title */ - rtgui_wintitle_destroy(topwin->title); - topwin->title = RT_NULL; - - rtgui_free(topwin); - - return RT_EOK; - } - - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); - if (topwin) - { - /* remove node from list */ - rtgui_list_remove(&_rtgui_topwin_hide_list, &(topwin->list)); - - /* free the topwin node and title */ - rtgui_wintitle_destroy(topwin->title); - topwin->title = RT_NULL; - - rtgui_free(topwin); - - return RT_EOK; - } - - return -RT_ERROR; -} - -/* activate a win - * - deactivate the old focus win - * - activate a win - * - set the focus win to activate win - * - draw win title - */ -void rtgui_topwin_activate_win(struct rtgui_topwin* win) -{ - struct rtgui_event_win event; - - /* activate the raised window */ - RTGUI_EVENT_WIN_ACTIVATE_INIT(&event); - event.wid = win->wid; - rtgui_thread_send(win->tid, &(event.parent), sizeof(struct rtgui_event_win)); - - /* redraw title */ - if (win->title != RT_NULL) - { - win->flag |= WINTITLE_ACTIVATE; - rtgui_theme_draw_win(win); - } - - if ((rtgui_server_focus_topwin != RT_NULL) && (rtgui_server_focus_topwin != win)) - { - /* deactivate the old focus win */ - RTGUI_EVENT_WIN_DEACTIVATE_INIT(&event); - event.wid = rtgui_server_focus_topwin->wid; - rtgui_thread_send(rtgui_server_focus_topwin->tid, - &event.parent, sizeof(struct rtgui_event_win)); - - /* redraw title */ - if (rtgui_server_focus_topwin->title != RT_NULL) - { - rtgui_server_focus_topwin->flag &= ~WINTITLE_ACTIVATE; - rtgui_theme_draw_win(rtgui_server_focus_topwin); - } - } - - rtgui_server_focus_topwin = win; -} - -/* - * deactivate a win - * - deactivate the win - * - redraw win title - * - set rtgui_server_focus_topwin - */ -void rtgui_topwin_deactivate_win(struct rtgui_topwin* win) -{ - /* deactivate win */ - struct rtgui_event_win event; - RTGUI_EVENT_WIN_DEACTIVATE_INIT(&event); - event.wid = win->wid; - rtgui_thread_send(win->tid, - &event.parent, sizeof(struct rtgui_event_win)); - - win->flag &= ~WINTITLE_ACTIVATE; - rtgui_theme_draw_win(win); - - if (rtgui_server_focus_topwin == win) - { - rtgui_server_focus_topwin = RT_NULL; - } -} - -/* raise window to front */ -#ifdef RTGUI_USING_SMALL_SIZE -void rtgui_topwin_raise(struct rtgui_win* wid, rt_thread_t sender) -{ - struct rtgui_topwin* topwin; - - /* find the topwin node */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); - if (topwin) - { - rt_int32_t count; - struct rtgui_list_node* node; - struct rtgui_event_clip_info eclip; - RTGUI_EVENT_CLIP_INFO_INIT(&eclip); - - /* the window is already placed in front */ - if (&(topwin->list) == _rtgui_topwin_show_list.next) - { - rtgui_server_focus_topwin = RT_NULL; - rtgui_topwin_activate_win(topwin); - return ; - } - - /* remove node from list */ - rtgui_list_remove(&_rtgui_topwin_show_list, &(topwin->list)); - /* add to front */ - rtgui_list_insert(&_rtgui_topwin_show_list, &(topwin->list)); - - /* send clip info event */ - count = 0; - for (node = _rtgui_topwin_show_list.next; node != RT_NULL; node = node->next) - { - struct rtgui_topwin* wnd = rtgui_list_entry(node, struct rtgui_topwin, list); - - eclip.num_rect = count; - eclip.wid = wnd->wid; - - count ++; - - /* send to destination window */ - rtgui_thread_send(wnd->tid, &(eclip.parent), sizeof(struct rtgui_event_clip_info)); - - /* reset clip info in title */ - if (wnd->title != RT_NULL) - { - rtgui_toplevel_handle_clip(RTGUI_TOPLEVEL(wnd->title), &eclip); - rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(wnd->title)); - rtgui_region_subtract_rect(&(RTGUI_WIDGET(wnd->title)->clip), - &(RTGUI_WIDGET(wnd->title)->clip), - &(wnd->extent)); - } - } - - rtgui_topwin_activate_win(topwin); - } -} -#else -void rtgui_topwin_raise(struct rtgui_win* wid, rt_thread_t sender) -{ - struct rtgui_topwin* topwin; - - /* find the topwin node */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); - if (topwin) - { - rt_int32_t count; - struct rtgui_list_node* node; - struct rtgui_event_clip_info* eclip; - struct rtgui_rect* rect; - - /* the window is already placed in front */ - if (&(topwin->list) == _rtgui_topwin_show_list.next) - { - rtgui_server_focus_topwin = RT_NULL; - rtgui_topwin_activate_win(topwin); - return ; - } - - /* update clip info */ - count = 0; - node = _rtgui_topwin_show_list.next; - while (node != &(topwin->list)) - { - count ++; - node = node->next; - } - - eclip = (struct rtgui_event_clip_info*)rtgui_malloc(sizeof(struct rtgui_event_clip_info) - + (count + 1)* sizeof(struct rtgui_rect)); - - /* reset clip info to top window */ - RTGUI_EVENT_CLIP_INFO_INIT(eclip); - eclip->num_rect = 0; - eclip->wid = topwin->wid; - /* send to destination window */ - rtgui_thread_send(topwin->tid, &(eclip->parent), sizeof(struct rtgui_event_clip_info)); - - /* reset clip info in title */ - if (topwin->title != RT_NULL) - { - rtgui_toplevel_handle_clip(RTGUI_TOPLEVEL(topwin->title), eclip); - rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(topwin->title)); - rtgui_region_subtract_rect(&(RTGUI_WIDGET(topwin->title)->clip), - &(RTGUI_WIDGET(topwin->title)->clip), - &(topwin->extent)); - } - - rect = RTGUI_EVENT_GET_RECT(eclip, 0); - *rect = (topwin->title != RT_NULL)? RTGUI_WIDGET(topwin->title)->extent : topwin->extent; - - count = 1; - for (node = _rtgui_topwin_show_list.next; - node != &(topwin->list); - node = node->next) - { - struct rtgui_topwin* wnd; - wnd = rtgui_list_entry(node, struct rtgui_topwin, list); - - eclip->num_rect = count; - eclip->wid = wnd->wid; - - /* send to destination window */ - rtgui_thread_send(wnd->tid, &(eclip->parent), - sizeof(struct rtgui_event_clip_info) + count * sizeof(struct rtgui_rect)); - - /* reset clip info in title */ - if (wnd->title != RT_NULL) - { - rtgui_toplevel_handle_clip(RTGUI_TOPLEVEL(wnd->title), eclip); - rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(wnd->title)); - rtgui_region_subtract_rect(&(RTGUI_WIDGET(wnd->title)->clip), - &(RTGUI_WIDGET(wnd->title)->clip), - &(wnd->extent)); - } - - rect = RTGUI_EVENT_GET_RECT(eclip, count++); - *rect = (wnd->title != RT_NULL)? RTGUI_WIDGET(wnd->title)->extent : wnd->extent; - } - - /* release clip info event */ - rtgui_free(eclip); - - /* remove node from list */ - rtgui_list_remove(&_rtgui_topwin_show_list, &(topwin->list)); - /* add to front */ - rtgui_list_insert(&_rtgui_topwin_show_list, &(topwin->list)); - - rtgui_topwin_activate_win(topwin); - } -} -#endif - -/* show a window */ -void rtgui_topwin_show(struct rtgui_event_win* event) -{ - struct rtgui_topwin* topwin; - struct rtgui_win* wid = event->wid; - rt_thread_t sender = RTGUI_EVENT(event)->sender; - - /* find in hide list */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); - - /* find it */ - if (topwin != RT_NULL) - { - /* remove node from hidden list */ - rtgui_list_remove(&_rtgui_topwin_hide_list, &(topwin->list)); - - /* add node to show list */ - rtgui_list_insert(&_rtgui_topwin_show_list, &(topwin->list)); - - /* show window title */ - if (topwin->title != RT_NULL) - { - RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(topwin->title)); - } - - /* update clip info */ - rtgui_topwin_update_clip(); - - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); - - /* activate this window */ - rtgui_topwin_activate_win(topwin); - } - else - { - /* the wnd is located in show list, raise wnd to front */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); - if (topwin != RT_NULL) - { - if (_rtgui_topwin_show_list.next != &(topwin->list)) - { - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); - - /* not the front window, raise it */ - rtgui_topwin_raise(wid, sender); - } - else - { - /* just raise it */ - rtgui_topwin_raise(wid, sender); - } - } - else - { - /* there is no wnd in wnd list */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); - } - } -} - -/* send clip info to panel */ -#ifdef RTGUI_USING_SMALL_SIZE -void rtgui_topwin_update_clip_to_panel(struct rtgui_panel* panel) -{ - rt_uint32_t count; - rt_thread_t tid; - struct rtgui_list_node* node; - struct rtgui_event_clip_info eclip; - - /* get topwin count */ - count = 0; - node = _rtgui_topwin_show_list.next; - while (node != RT_NULL) - { - count ++; - node = node->next; - } - - /* send clip info event to panel */ - RTGUI_EVENT_CLIP_INFO_INIT(&eclip); - eclip.num_rect = count; eclip.wid = RT_NULL; - - /* send to the activated thread of panel */ - tid = rtgui_panel_get_active_thread(panel); - rtgui_thread_send(tid, &eclip.parent, sizeof(struct rtgui_event_clip_info)); -} -#else -void rtgui_topwin_update_clip_to_panel(struct rtgui_panel* panel) -{ - rt_uint32_t count; - rt_thread_t tid; - struct rtgui_list_node* node; - struct rtgui_event_clip_info* eclip; - - /* get topwin count */ - count = 0; - node = _rtgui_topwin_show_list.next; - while (node != RT_NULL) - { - count ++; - node = node->next; - } - - eclip = (struct rtgui_event_clip_info*)rtgui_malloc(sizeof(struct rtgui_event_clip_info) - + (count + 1)* sizeof(struct rtgui_rect)); - if (eclip == RT_NULL) - { - /* no memory */ - return ; - } - - /* reset clip info to top window */ - RTGUI_EVENT_CLIP_INFO_INIT(eclip); - eclip->num_rect = count; eclip->wid = RT_NULL; - - count = 0; - for (node = _rtgui_topwin_show_list.next; node != RT_NULL; node = node->next) - { - struct rtgui_topwin* wnd; - struct rtgui_rect* rect; - - wnd = rtgui_list_entry(node, struct rtgui_topwin, list); - - rect = RTGUI_EVENT_GET_RECT(eclip, count++); - *rect = (wnd->title != RT_NULL)? RTGUI_WIDGET(wnd->title)->extent : wnd->extent; - } - - /* send to the activated thread of panel */ - tid = rtgui_panel_get_active_thread(panel); - rtgui_thread_send(tid, (struct rtgui_event*)eclip, sizeof(struct rtgui_event_clip_info) - + count* sizeof(struct rtgui_rect)); - - /* release clip info event */ - rtgui_free(eclip); -} -#endif - -/* hide a window */ -void rtgui_topwin_hide(struct rtgui_event_win* event) -{ - struct rtgui_topwin* topwin; - struct rtgui_win* wid = event->wid; - - /* find in show list */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); - - /* found it */ - if (topwin) - { - /* remove node from show list */ - rtgui_list_remove(&_rtgui_topwin_show_list, &(topwin->list)); - - /* add node to hidden list */ - rtgui_list_insert(&_rtgui_topwin_hide_list, &(topwin->list)); - - /* show window title */ - if (topwin->title != RT_NULL) - { - RTGUI_WIDGET_HIDE(RTGUI_WIDGET(topwin->title)); - } - - /* update clip info */ - rtgui_topwin_update_clip(); - - /* redraw the old rect */ - rtgui_topwin_redraw(&(topwin->extent)); - - if (rtgui_server_focus_topwin == topwin) - { - /* activate the next window */ - if (_rtgui_topwin_show_list.next != RT_NULL) - { - /* get the topwin */ - topwin = rtgui_list_entry(_rtgui_topwin_show_list.next, - struct rtgui_topwin, list); - - rtgui_server_focus_topwin = RT_NULL; - rtgui_topwin_activate_win(topwin); - } - else - { - /* there is no shown window right now */ - rtgui_server_focus_topwin = RT_NULL; - } - } - } - else - { - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); - return; - } - - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); -} - -/* move top window */ -void rtgui_topwin_move(struct rtgui_event_win_move* event) -{ - struct rtgui_topwin* topwin; - - /* find in show list */ - topwin = rtgui_topwin_search_in_list(event->wid, &_rtgui_topwin_show_list); - if (topwin != RT_NULL) - { - int dx, dy; - rtgui_rect_t rect; /* the old topwin coverage area */ - struct rtgui_list_node* node; - - /* send status ok */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); - - /* get the delta move x, y */ - dx = event->x - topwin->extent.x1; - dy = event->y - topwin->extent.y1; - - rect = topwin->extent; - /* move window rect */ - rtgui_rect_moveto(&(topwin->extent), dx, dy); - - /* move window title */ - if (topwin->title != RT_NULL) - { - rect = RTGUI_WIDGET(topwin->title)->extent; - rtgui_widget_move_to_logic(RTGUI_WIDGET(topwin->title), dx, dy); - } - - /* move the monitor rect list */ - rtgui_list_foreach(node, &(topwin->monitor_list)) - { - struct rtgui_mouse_monitor* monitor = rtgui_list_entry(node, - struct rtgui_mouse_monitor, - list); - rtgui_rect_moveto(&(monitor->rect), dx, dy); - } - - /* update windows clip info */ - rtgui_topwin_update_clip(); - - /* update top window title */ - if (topwin->title != RT_NULL) rtgui_theme_draw_win(topwin); - if (rtgui_rect_is_intersect(&rect, &(topwin->extent)) != RT_EOK) - { - /* - * the old rect is not intersect with moved rect, - * re-paint window - */ - struct rtgui_event_paint epaint; - RTGUI_EVENT_PAINT_INIT(&epaint); - epaint.wid = topwin->wid; - rtgui_thread_send(topwin->tid, &(epaint.parent), sizeof(epaint)); - } - - /* update old window coverage area */ - rtgui_topwin_redraw(&rect); - } - else - { - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); - } -} - -/* - * resize a top win - * Note: currently, only support resize hidden window - */ -void rtgui_topwin_resize(struct rtgui_win* wid, rtgui_rect_t* r) -{ - struct rtgui_topwin* topwin; - - /* find in show list */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); - if (topwin) - { - topwin->extent = *r; - - if (topwin->title != RT_NULL) - { - /* get win extent */ - rtgui_rect_t rect = topwin->extent; - - /* add border rect */ - if (topwin->flag & WINTITLE_BORDER) - { - rtgui_rect_inflate(&rect, WINTITLE_BORDER_SIZE); - } - - /* add title rect */ - if (!(topwin->flag & WINTITLE_NO)) rect.y1 -= WINTITLE_HEIGHT; - - RTGUI_WIDGET(topwin->title)->extent = rect; - - /* update title & border clip info */ - rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(topwin->title)); - rtgui_region_subtract_rect(&(RTGUI_WIDGET(topwin->title)->clip), - &(RTGUI_WIDGET(topwin->title)->clip), - &(topwin->extent)); - } - } -} - -struct rtgui_topwin* rtgui_topwin_get_wnd(int x, int y) -{ - struct rtgui_list_node* node; - struct rtgui_topwin* topwin; - - /* search in list */ - rtgui_list_foreach(node, &(_rtgui_topwin_show_list)) - { - topwin = rtgui_list_entry(node, struct rtgui_topwin, list); - - /* is this window? */ - if ((topwin->title != RT_NULL) && - rtgui_rect_contains_point(&(RTGUI_WIDGET(topwin->title)->extent), x, y) == RT_EOK) - { - return topwin; - } - else if (rtgui_rect_contains_point(&(topwin->extent), x, y) == RT_EOK) - { - return topwin; - } - } - - return RT_NULL; -} - -extern struct rtgui_list_node _rtgui_panel_list; -#ifdef RTGUI_USING_SMALL_SIZE -static void rtgui_topwin_update_clip() -{ - rt_int32_t count = 0; - struct rtgui_event_clip_info eclip; - struct rtgui_list_node* node = _rtgui_topwin_show_list.next; - - RTGUI_EVENT_CLIP_INFO_INIT(&eclip); - - rtgui_list_foreach(node, &_rtgui_topwin_show_list) - { - struct rtgui_topwin* wnd; - wnd = rtgui_list_entry(node, struct rtgui_topwin, list); - - eclip.num_rect = count; - eclip.wid = wnd->wid; - - count ++; - - /* send to destination window */ - rtgui_thread_send(wnd->tid, &(eclip.parent), sizeof(struct rtgui_event_clip_info)); - - /* update clip in win title */ - if (wnd->title != RT_NULL) - { - /* reset clip info */ - rtgui_toplevel_handle_clip(RTGUI_TOPLEVEL(wnd->title), &eclip); - rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(wnd->title)); - rtgui_region_subtract_rect(&(RTGUI_WIDGET(wnd->title)->clip), - &(RTGUI_WIDGET(wnd->title)->clip), - &(wnd->extent)); - } - } - - /* send clip info to each panel */ - eclip.wid = RT_NULL; - eclip.num_rect = count; - - rtgui_list_foreach(node, &(_rtgui_panel_list)) - { - struct rtgui_panel* panel; - struct rtgui_list_node* panel_node; - - panel = rtgui_list_entry(node, struct rtgui_panel, sibling); - - rtgui_list_foreach(panel_node, &(panel->thread_list)) - { - struct rtgui_panel_thread* thread; - thread = rtgui_list_entry(panel_node, struct rtgui_panel_thread, list); - - /* send clip info to panel */ - rtgui_thread_send(thread->tid, &(eclip.parent), sizeof(struct rtgui_event_clip_info)); - } - } -} -#else -static void rtgui_topwin_update_clip() -{ - rt_int32_t count = 0; - struct rtgui_event_clip_info* eclip; - struct rtgui_list_node* node = _rtgui_topwin_show_list.next; - - /* calculate count */ - while (node != RT_NULL) - { - count ++; - node = node->next; - } - - eclip = (struct rtgui_event_clip_info*)rtgui_malloc(sizeof(struct rtgui_event_clip_info) - + count * sizeof(struct rtgui_rect)); - RTGUI_EVENT_CLIP_INFO_INIT(eclip); - - count = 0; - rtgui_list_foreach(node, &_rtgui_topwin_show_list) - { - struct rtgui_rect* rect; - struct rtgui_topwin* wnd; - wnd = rtgui_list_entry(node, struct rtgui_topwin, list); - - eclip->num_rect = count; - eclip->wid = wnd->wid; - - /* send to destination window */ - rtgui_thread_send(wnd->tid, &(eclip->parent), - sizeof(struct rtgui_event_clip_info) + count * sizeof(struct rtgui_rect)); - - /* update clip in win title */ - if (wnd->title != RT_NULL) - { - /* reset clip info */ - rtgui_toplevel_handle_clip(RTGUI_TOPLEVEL(wnd->title), eclip); - rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(wnd->title)); - rtgui_region_subtract_rect(&(RTGUI_WIDGET(wnd->title)->clip), - &(RTGUI_WIDGET(wnd->title)->clip), - &(wnd->extent)); - } - - rect = RTGUI_EVENT_GET_RECT(eclip, count++); - *rect = (wnd->title != RT_NULL)? RTGUI_WIDGET(wnd->title)->extent : wnd->extent; - } - - /* send clip info to each panel */ - eclip->wid = RT_NULL; - eclip->num_rect = count; - - rtgui_list_foreach(node, &(_rtgui_panel_list)) - { - struct rtgui_panel* panel; - struct rtgui_list_node* panel_node; - - panel = rtgui_list_entry(node, struct rtgui_panel, sibling); - - rtgui_list_foreach(panel_node, &(panel->thread_list)) - { - struct rtgui_panel_thread* thread; - thread = rtgui_list_entry(panel_node, struct rtgui_panel_thread, list); - - /* send clip info to panel */ - rtgui_thread_send(thread->tid, &(eclip->parent), - sizeof(struct rtgui_event_clip_info) + count * sizeof(struct rtgui_rect)); - } - } - - /* release clip info event */ - rtgui_free(eclip); -} -#endif - -static void rtgui_topwin_redraw(struct rtgui_rect* rect) -{ - struct rtgui_list_node* node; - struct rtgui_event_paint epaint; - RTGUI_EVENT_PAINT_INIT(&epaint); - - rtgui_list_foreach(node, &_rtgui_topwin_show_list) - { - struct rtgui_topwin* wnd = rtgui_list_entry(node, struct rtgui_topwin, list); - - if (rtgui_rect_is_intersect(rect, &(wnd->extent)) == RT_EOK) - { - /* draw window */ - epaint.wid = wnd->wid; - rtgui_thread_send(wnd->tid, &(epaint.parent), sizeof(epaint)); - - /* draw title */ - if (wnd->title != RT_NULL) - { - rtgui_theme_draw_win(wnd); - } - } - } - - /* redraw the panel */ - rtgui_list_foreach(node, &(_rtgui_panel_list)) - { - struct rtgui_panel* panel; - panel = rtgui_list_entry(node, struct rtgui_panel, sibling); - - if (rtgui_rect_is_intersect(rect, &(panel->extent)) == RT_EOK) - { - rt_thread_t tid; - - tid = rtgui_panel_get_active_thread(panel); - if (tid != RT_NULL) - { - /* draw panel */ - epaint.wid = RT_NULL; - rtgui_thread_send(tid, &(epaint.parent), sizeof(epaint)); - } - } - } -} - -void rtgui_topwin_title_onmouse(struct rtgui_topwin* win, struct rtgui_event_mouse* event) -{ - rtgui_rect_t rect; - - /* let window to process this mouse event */ - if (rtgui_rect_contains_point(&win->extent, event->x, event->y) == RT_EOK) - { - /* send mouse event to thread */ - rtgui_thread_send(win->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); - return; - } - - /* get close button rect (device value) */ - rect.x1 = RTGUI_WIDGET(win->title)->extent.x2 - WINTITLE_BORDER_SIZE - WINTITLE_CB_WIDTH - 3; - rect.y1 = RTGUI_WIDGET(win->title)->extent.y1 + WINTITLE_BORDER_SIZE + 3; - rect.x2 = rect.x1 + WINTITLE_CB_WIDTH; - rect.y2 = rect.y1 + WINTITLE_CB_HEIGHT; - - if (event->button & RTGUI_MOUSE_BUTTON_LEFT) - { - if (event->button & RTGUI_MOUSE_BUTTON_DOWN) - { - if (rtgui_rect_contains_point(&rect, event->x, event->y) == RT_EOK) - { - win->flag |= WINTITLE_CB_PRESSED; - rtgui_theme_draw_win(win); - } - else - { - /* maybe move window */ - rtgui_winrect_set(win); - } - } - else if (event->button & RTGUI_MOUSE_BUTTON_UP) - { - if (rtgui_rect_contains_point(&rect, event->x, event->y) == RT_EOK) - { - struct rtgui_event_win event; - - win->flag &= ~WINTITLE_CB_PRESSED; - rtgui_theme_draw_win(win); - - /* send close event to window */ - RTGUI_EVENT_WIN_CLOSE_INIT(&event); - event.wid = win->wid; - rtgui_thread_send(win->tid, &(event.parent), sizeof(struct rtgui_event_win)); - } - } - } -} - -void rtgui_topwin_append_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect) -{ - struct rtgui_topwin* win; - - /* parameters check */ - if (wid == RT_NULL || rect == RT_NULL) return; - - /* find topwin */ - win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); - if (win == RT_NULL) - win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); - - if (win == RT_NULL) return; - - /* append rect to top window monitor rect list */ - rtgui_mouse_monitor_append(&(win->monitor_list), rect); -} - -void rtgui_topwin_remove_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect) -{ - struct rtgui_topwin* win; - - /* parameters check */ - if (wid == RT_NULL || rect == RT_NULL) return; - - /* find topwin */ - win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); - if (win == RT_NULL) - win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); - - if (win == RT_NULL) return; - - /* remove rect from top window monitor rect list */ - rtgui_mouse_monitor_remove(&(win->monitor_list), rect); -} - -#ifdef RTGUI_USING_SMALL_SIZE -/** - * get clip information for topwin - * wid, the self window id. If wid = NULL, get whole topwin clip information. - * - * @return the clip rect information - */ -void rtgui_topwin_get_clipinfo(struct rtgui_rect* rect_list, rt_int32_t count) -{ - struct rtgui_rect* rect; - struct rtgui_topwin* topwin; - struct rtgui_list_node* node; - - if ((rect_list == RT_NULL) || (count == 0)) return ; - - /* set to the header of list */ - rect = rect_list; - - rt_sem_take(&_rtgui_topwin_lock, RT_WAITING_FOREVER); - /* get all of topwin rect list */ - rtgui_list_foreach(node, &_rtgui_topwin_show_list) - { - topwin = rtgui_list_entry(node, struct rtgui_topwin, list); - - if (topwin->title != RT_NULL) - *rect = RTGUI_WIDGET(topwin->title)->extent; - else - *rect = topwin->extent; - - rect ++; - count --; - if (count <= 0) break; - } - rt_sem_release(&_rtgui_topwin_lock); -} -#endif diff --git a/rtgui/server/topwin.h b/rtgui/server/topwin.h deleted file mode 100644 index 8bfe394235..0000000000 --- a/rtgui/server/topwin.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * File : topwin.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, 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 - * 2009-10-16 Bernard first version - */ -#ifndef __RTGUI_TOPWIN_H__ -#define __RTGUI_TOPWIN_H__ - -#include <rtgui/rtgui.h> -#include <rtgui/list.h> -#include <rtgui/region.h> -#include <rtgui/event.h> -#include <rtgui/widgets/title.h> -#include <rtgui/rtgui_server.h> - -/* 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); - -/* raise window to front */ -void rtgui_topwin_raise(struct rtgui_win* wid, rt_thread_t sender); -/* update clip info to a panel */ -void rtgui_topwin_update_clip_to_panel(struct rtgui_panel* panel); - -/* show a window */ -void rtgui_topwin_show(struct rtgui_event_win* event); -/* hide a window */ -void rtgui_topwin_hide(struct rtgui_event_win* event); -/* move a window */ -void rtgui_topwin_move(struct rtgui_event_win_move* event); -/* resize a window */ -void rtgui_topwin_resize(struct rtgui_win* wid, rtgui_rect_t* r); - -/* get window at (x, y) */ -struct rtgui_topwin* rtgui_topwin_get_wnd(int x, int y); - -void rtgui_topwin_activate_win(struct rtgui_topwin* win); -void rtgui_topwin_deactivate_win(struct rtgui_topwin* win); - -/* window title */ -void rtgui_topwin_title_ondraw(struct rtgui_topwin* win); -void rtgui_topwin_title_onmouse(struct rtgui_topwin* win, struct rtgui_event_mouse* event); - -/* monitor rect */ -void rtgui_topwin_append_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect); -void rtgui_topwin_remove_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect); - -void rtgui_topwin_get_clipinfo(struct rtgui_rect* rect_list, rt_int32_t count); - -#endif - |
