diff options
| author | [email protected] <[email protected]> | 2012-11-26 02:42:52 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-11-26 02:42:52 +0000 |
| commit | 62447b2cd84b529f7dbf6712c29d7ac4ff0c1e12 (patch) | |
| tree | 399aa1bbc0d4c632d7dc2804ed76e5c62b5cec27 /components/rtgui/server | |
| parent | 9789907ca1b4c43ee34fac6e94e5a48f76aaca3c (diff) | |
sync RTGUI with github(https://github.com/RT-Thread/RTGUI) 9ae08379da5b698d6facc40bd0415de2e254ae9c
As always, full log is in GitHub.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2449 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/rtgui/server')
| -rw-r--r-- | components/rtgui/server/driver.c | 93 | ||||
| -rw-r--r-- | components/rtgui/server/mouse.c | 878 | ||||
| -rw-r--r-- | components/rtgui/server/mouse.h | 24 | ||||
| -rw-r--r-- | components/rtgui/server/server.c | 425 | ||||
| -rw-r--r-- | components/rtgui/server/topwin.c | 1474 | ||||
| -rw-r--r-- | components/rtgui/server/topwin.h | 32 |
6 files changed, 1466 insertions, 1460 deletions
diff --git a/components/rtgui/server/driver.c b/components/rtgui/server/driver.c index 48a29ab5ff..2fe19347b5 100644 --- a/components/rtgui/server/driver.c +++ b/components/rtgui/server/driver.c @@ -20,82 +20,83 @@ extern const struct rtgui_graphic_driver_ops *rtgui_pixel_device_get_ops(int pix extern const struct rtgui_graphic_driver_ops *rtgui_framebuffer_get_ops(int pixel_format); /* get default driver */ -struct rtgui_graphic_driver* rtgui_graphic_driver_get_default() +struct rtgui_graphic_driver *rtgui_graphic_driver_get_default() { - return &_driver; + return &_driver; } RTM_EXPORT(rtgui_graphic_driver_get_default); void rtgui_graphic_driver_get_rect(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect) { - RT_ASSERT(rect != RT_NULL); - RT_ASSERT(driver != RT_NULL); + RT_ASSERT(rect != RT_NULL); + RT_ASSERT(driver != RT_NULL); - rect->x1 = rect->y1 = 0; - rect->x2 = driver->width; - rect->y2 = driver->height; + rect->x1 = rect->y1 = 0; + rect->x2 = driver->width; + rect->y2 = driver->height; } RTM_EXPORT(rtgui_graphic_driver_get_rect); rt_err_t rtgui_graphic_set_device(rt_device_t device) { - rt_err_t result; - struct rt_device_graphic_info info; + rt_err_t result; + struct rt_device_graphic_info info; - /* get framebuffer address */ - result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info); - if (result != RT_EOK) - { - /* get device information failed */ - return -RT_ERROR; - } + /* get framebuffer address */ + result = rt_device_control(device, RTGRAPHIC_CTRL_GET_INFO, &info); + if (result != RT_EOK) + { + /* get device information failed */ + return -RT_ERROR; + } - /* initialize framebuffer driver */ - _driver.device = device; - _driver.pixel_format = info.pixel_format; - _driver.bits_per_pixel = info.bits_per_pixel; - _driver.width = info.width; - _driver.height = info.height; - _driver.pitch = _driver.width * _driver.bits_per_pixel/8; - _driver.framebuffer = info.framebuffer; + /* initialize framebuffer driver */ + _driver.device = device; + _driver.pixel_format = info.pixel_format; + _driver.bits_per_pixel = info.bits_per_pixel; + _driver.width = info.width; + _driver.height = info.height; + _driver.pitch = _driver.width * _driver.bits_per_pixel / 8; + _driver.framebuffer = info.framebuffer; - if (info.framebuffer != RT_NULL) - { - /* is a frame buffer device */ - _driver.ops = rtgui_framebuffer_get_ops(_driver.pixel_format); - } - else - { - /* is a pixel device */ - _driver.ops = rtgui_pixel_device_get_ops(_driver.pixel_format); - } - - return RT_EOK; + if (info.framebuffer != RT_NULL) + { + /* is a frame buffer device */ + _driver.ops = rtgui_framebuffer_get_ops(_driver.pixel_format); + } + else + { + /* is a pixel device */ + _driver.ops = rtgui_pixel_device_get_ops(_driver.pixel_format); + } + + return RT_EOK; } RTM_EXPORT(rtgui_graphic_set_device); /* screen update */ -void rtgui_graphic_driver_screen_update(const struct rtgui_graphic_driver* driver, rtgui_rect_t *rect) +void rtgui_graphic_driver_screen_update(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect) { - struct rt_device_rect_info rect_info; + struct rt_device_rect_info rect_info; - rect_info.x = rect->x1; rect_info.y = rect->y1; - rect_info.width = rect->x2 - rect->x1; - rect_info.height = rect->y2 - rect->y1; - rt_device_control(driver->device, RTGRAPHIC_CTRL_RECT_UPDATE, &rect_info); + rect_info.x = rect->x1; + rect_info.y = rect->y1; + rect_info.width = rect->x2 - rect->x1; + rect_info.height = rect->y2 - rect->y1; + rt_device_control(driver->device, RTGRAPHIC_CTRL_RECT_UPDATE, &rect_info); } RTM_EXPORT(rtgui_graphic_driver_screen_update); /* get video frame buffer */ -rt_uint8_t* rtgui_graphic_driver_get_framebuffer(const struct rtgui_graphic_driver* driver) +rt_uint8_t *rtgui_graphic_driver_get_framebuffer(const struct rtgui_graphic_driver *driver) { - return (rt_uint8_t*)driver->framebuffer; + return (rt_uint8_t *)driver->framebuffer; } RTM_EXPORT(rtgui_graphic_driver_get_framebuffer); -rt_uint8_t* rtgui_graphic_driver_get_default_framebuffer(void) +rt_uint8_t *rtgui_graphic_driver_get_default_framebuffer(void) { - return rtgui_graphic_driver_get_framebuffer(&_driver); + return rtgui_graphic_driver_get_framebuffer(&_driver); } RTM_EXPORT(rtgui_graphic_driver_get_default_framebuffer); diff --git a/components/rtgui/server/mouse.c b/components/rtgui/server/mouse.c index a6c71ed7ef..27972af2b2 100644 --- a/components/rtgui/server/mouse.c +++ b/components/rtgui/server/mouse.c @@ -19,647 +19,649 @@ struct rtgui_cursor { - /* screen byte per pixel */ - rt_uint16_t bpp; + /* screen byte per pixel */ + rt_uint16_t bpp; - /* screen pitch */ - rt_uint16_t screen_pitch; + /* screen pitch */ + rt_uint16_t screen_pitch; - /* current cursor x and y */ - rt_uint16_t cx, cy; + /* current cursor x and y */ + rt_uint16_t cx, cy; #ifdef RTGUI_USING_MOUSE_CURSOR - /* cursor pitch */ - rt_uint16_t cursor_pitch; + /* cursor pitch */ + rt_uint16_t cursor_pitch; - /* show cursor and show cursor count */ - rt_bool_t show_cursor; - rt_base_t show_cursor_count; + /* 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 rect info */ + rtgui_rect_t rect; - /* cursor image and saved cursor */ - rtgui_image_t *cursor_image; - rt_uint8_t *cursor_saved; + /* cursor image and saved cursor */ + rtgui_image_t *cursor_image; + rt_uint8_t *cursor_saved; #endif #ifdef RTGUI_USING_WINMOVE - /* 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; + /* 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; #endif }; -struct rtgui_cursor* _rtgui_cursor; +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 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); +static void rtgui_cursor_restore(void); +static void rtgui_cursor_save(void); +static void rtgui_cursor_show(void); #endif #ifdef RTGUI_USING_WINMOVE -static void rtgui_winrect_restore (void); -static void rtgui_winrect_save (void); -static void rtgui_winrect_show (void); +static void rtgui_winrect_restore(void); +static void rtgui_winrect_save(void); +static void rtgui_winrect_show(void); #endif -#define WIN_MOVE_BORDER 4 +#define WIN_MOVE_BORDER 4 void rtgui_mouse_init(void) { - const struct rtgui_graphic_driver* gd = rtgui_graphic_driver_get_default(); + const struct rtgui_graphic_driver *gd = rtgui_graphic_driver_get_default(); - if (_rtgui_cursor != RT_NULL) rtgui_mouse_fini(); + if (_rtgui_cursor != RT_NULL) rtgui_mouse_fini(); - _rtgui_cursor = (struct rtgui_cursor*) rtgui_malloc(sizeof(struct rtgui_cursor)); - rt_memset(_rtgui_cursor, 0, sizeof(struct rtgui_cursor)); + _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); + rt_mutex_init(&cursor_mutex, "cursor", RT_IPC_FLAG_FIFO); #endif - /* init cursor */ - _rtgui_cursor->bpp = gd->bits_per_pixel/8; - _rtgui_cursor->screen_pitch = _rtgui_cursor->bpp * gd->width; + /* init cursor */ + _rtgui_cursor->bpp = gd->bits_per_pixel / 8; + _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", - (rt_uint8_t*)cursor_xpm, - sizeof(cursor_xpm), - RT_TRUE); - if (_rtgui_cursor->cursor_image == RT_NULL) - { - rtgui_free(_rtgui_cursor); - _rtgui_cursor = RT_NULL; + /* init cursor image */ + _rtgui_cursor->cursor_image = rtgui_image_create_from_mem("xpm", + (rt_uint8_t *)cursor_xpm, + sizeof(cursor_xpm), + RT_TRUE); + if (_rtgui_cursor->cursor_image == RT_NULL) + { + rtgui_free(_rtgui_cursor); + _rtgui_cursor = RT_NULL; - return; - } + 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; + /* 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->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); + _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 #ifdef RTGUI_USING_WINMOVE - /* init window move save image */ - _rtgui_cursor->win_rect_has_saved = RT_FALSE; - _rtgui_cursor->win_rect_show = RT_FALSE; + /* 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); + _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); #endif } void rtgui_mouse_fini(void) { - if (_rtgui_cursor != RT_NULL) - { + if (_rtgui_cursor != RT_NULL) + { #ifdef RTGUI_USING_WINMOVE - rtgui_free(_rtgui_cursor->win_left); - rtgui_free(_rtgui_cursor->win_right); - rtgui_free(_rtgui_cursor->win_top); - rtgui_free(_rtgui_cursor->win_bottom); + rtgui_free(_rtgui_cursor->win_left); + rtgui_free(_rtgui_cursor->win_right); + rtgui_free(_rtgui_cursor->win_top); + rtgui_free(_rtgui_cursor->win_bottom); #endif #ifdef RTGUI_USING_MOUSE_CURSOR - rt_mutex_detach(&cursor_mutex); - rtgui_image_destroy(_rtgui_cursor->cursor_image); - rtgui_free(_rtgui_cursor->cursor_saved); + rt_mutex_detach(&cursor_mutex); + rtgui_image_destroy(_rtgui_cursor->cursor_image); + rtgui_free(_rtgui_cursor->cursor_saved); #endif - rtgui_free(_rtgui_cursor); + rtgui_free(_rtgui_cursor); - _rtgui_cursor = RT_NULL; - } + _rtgui_cursor = RT_NULL; + } } void rtgui_mouse_moveto(int x, int y) { #ifdef RTGUI_USING_MOUSE_CURSOR - rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER); + rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER); #endif - if (x != _rtgui_cursor->cx || - y != _rtgui_cursor->cy) - { + if (x != _rtgui_cursor->cx || + y != _rtgui_cursor->cy) + { #ifdef RTGUI_USING_WINMOVE - if (_rtgui_cursor->win_rect_show) - { - if (_rtgui_cursor->win_rect_has_saved == RT_TRUE) - { - rtgui_winrect_restore(); - } + 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(); + 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 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; + /* move current cursor */ + _rtgui_cursor->cx = x; + _rtgui_cursor->cy = y; #ifdef RTGUI_USING_MOUSE_CURSOR - /* show cursor */ - rtgui_mouse_show_cursor(); + /* show cursor */ + rtgui_mouse_show_cursor(); #endif - /* show winrect */ - rtgui_winrect_show(); - } - else + /* show winrect */ + rtgui_winrect_show(); + } + else #endif - { + { #ifdef RTGUI_USING_MOUSE_CURSOR - rtgui_mouse_hide_cursor(); + rtgui_mouse_hide_cursor(); #endif - /* move current cursor */ - _rtgui_cursor->cx = x; - _rtgui_cursor->cy = y; + /* move current cursor */ + _rtgui_cursor->cx = x; + _rtgui_cursor->cy = y; #ifdef RTGUI_USING_MOUSE_CURSOR - /* show cursor */ - rtgui_mouse_show_cursor(); + /* show cursor */ + rtgui_mouse_show_cursor(); #endif - } - } + } + } #ifdef RTGUI_USING_MOUSE_CURSOR - rt_mutex_release(&cursor_mutex); + 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; + _rtgui_cursor->show_cursor = enable; } /* set current cursor image */ -void rtgui_mouse_set_cursor(rtgui_image_t* cursor) +void rtgui_mouse_set_cursor(rtgui_image_t *cursor) { } -void rtgui_mouse_get_cursor_rect(rtgui_rect_t* rect) +void rtgui_mouse_get_cursor_rect(rtgui_rect_t *rect) { - if (rect != RT_NULL) - { - *rect = _rtgui_cursor->rect; - } + if (rect != RT_NULL) + { + *rect = _rtgui_cursor->rect; + } } void rtgui_mouse_show_cursor() { - if (_rtgui_cursor->show_cursor == RT_FALSE) - return; + 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(); + _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(); - } + /* show mouse cursor */ + rtgui_cursor_show(); + } } void rtgui_mouse_hide_cursor() { - if (_rtgui_cursor->show_cursor == RT_FALSE) - return; + 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 --; + 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) +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; + 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; + rt_base_t idx, height, cursor_pitch; + rt_uint8_t *cursor_ptr, *fb_ptr; - 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; + 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; - 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; + 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; + 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); + 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; - } + 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; + rt_base_t idx, height, cursor_pitch; + rt_uint8_t *cursor_ptr, *fb_ptr; - 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; + 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; - 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; + 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; + 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); + 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; - } + fb_ptr += _rtgui_cursor->screen_pitch; + cursor_ptr += _rtgui_cursor->cursor_pitch; + } } static void rtgui_cursor_show() { - // FIXME: the prototype of set_pixel is using int so we have to use int - // as well. Might be uniformed with others in the future - int x, y; - rtgui_color_t* ptr; - rtgui_rect_t rect; - void (*set_pixel) (rtgui_color_t *c, int x, int y); + // FIXME: the prototype of set_pixel is using int so we have to use int + // as well. Might be uniformed with others in the future + int x, y; + rtgui_color_t *ptr; + rtgui_rect_t rect; + void (*set_pixel)(rtgui_color_t * c, int x, int y); - ptr = (rtgui_color_t*) _rtgui_cursor->cursor_image->data; - set_pixel = rtgui_graphic_driver_get_default()->ops->set_pixel; + ptr = (rtgui_color_t *) _rtgui_cursor->cursor_image->data; + set_pixel = rtgui_graphic_driver_get_default()->ops->set_pixel; - rtgui_mouse_get_cursor_rect(&rect); - rtgui_rect_moveto(&rect, _rtgui_cursor->cx, _rtgui_cursor->cy); + 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); - } + /* 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 ++; - } - } + /* move to next color buffer */ + ptr ++; + } + } - /* update rect */ - rtgui_graphic_driver_screen_update(rtgui_graphic_driver_get_default(), &rect); + /* update rect */ + rtgui_graphic_driver_screen_update(rtgui_graphic_driver_get_default(), &rect); } #endif #ifdef RTGUI_USING_WINMOVE -void rtgui_winrect_set(struct rtgui_topwin* topwin) +void rtgui_winrect_set(struct rtgui_topwin *topwin) { - /* set win rect show */ - _rtgui_cursor->win_rect_show = RT_TRUE; + /* 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; + /* 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 rtgui_winrect_moved_done(rtgui_rect_t *winrect, struct rtgui_topwin **topwin) { - rt_bool_t moved = RT_FALSE; + rt_bool_t moved = RT_FALSE; - /* no win rect */ - if (winrect == RT_NULL) return RT_FALSE; + /* no win rect */ + if (winrect == RT_NULL) return RT_FALSE; - /* restore winrect */ - if (_rtgui_cursor->win_rect_has_saved) - { - rtgui_winrect_restore(); + /* restore winrect */ + if (_rtgui_cursor->win_rect_has_saved) + { + rtgui_winrect_restore(); - moved = RT_TRUE; - } + moved = RT_TRUE; + } - /* clear win rect show */ - _rtgui_cursor->win_rect_show = RT_FALSE; - _rtgui_cursor->win_rect_has_saved = RT_FALSE; + /* 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 win rect */ + *winrect = _rtgui_cursor->win_rect; + *topwin = _rtgui_cursor->topwin; - return moved; + return moved; } rt_bool_t rtgui_winrect_is_moved() { - return _rtgui_cursor->win_rect_show; + 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, int x, int y); + 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, int x, int y); - c = black; - set_pixel = rtgui_graphic_driver_get_default()->ops->set_pixel; + c = black; + set_pixel = rtgui_graphic_driver_get_default()->ops->set_pixel; - win_rect = _rtgui_cursor->win_rect; - win_rect_inner = win_rect; - rtgui_rect_inflate(&win_rect_inner, -WIN_MOVE_BORDER); + 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); + 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 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 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 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); - } + /* 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_screen_update(rtgui_graphic_driver_get_default(), &win_rect); + /* update rect */ + rtgui_graphic_driver_screen_update(rtgui_graphic_driver_get_default(), &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; \ - } +#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, *driver_fb; - int winrect_pitch, idx; - rtgui_rect_t screen_rect, win_rect; + 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; + driver_fb = rtgui_graphic_driver_get_default_framebuffer(); + 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); + rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), + &screen_rect); + rtgui_rect_intersect(&screen_rect, &win_rect); - /* restore winrect left */ - 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; - display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch, - (win_rect.y2 - win_rect.y1), winrect_pitch); + /* restore winrect left */ + 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; + 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 = 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; - 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 = 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; + 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 = 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; - display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch, - WIN_MOVE_BORDER, winrect_pitch); + /* restore winrect top */ + 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; + display_direct_memcpy(winrect_ptr, fb_ptr, winrect_pitch, _rtgui_cursor->screen_pitch, + WIN_MOVE_BORDER, winrect_pitch); - /* restore winrect bottom */ - 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, - WIN_MOVE_BORDER, winrect_pitch); + /* restore winrect bottom */ + 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, + WIN_MOVE_BORDER, winrect_pitch); } static void rtgui_winrect_save() { - rt_uint8_t *winrect_ptr, *fb_ptr, *driver_fb; - int winrect_pitch, idx; - rtgui_rect_t screen_rect, win_rect; + 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; + driver_fb = rtgui_graphic_driver_get_default_framebuffer(); + 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); + 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; + /* set winrect has saved */ + _rtgui_cursor->win_rect_has_saved = RT_TRUE; - /* save winrect left */ - 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; - display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch, - (win_rect.y2 - win_rect.y1), winrect_pitch); + /* save winrect left */ + 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; + 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 = 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; - 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 = 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; + 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 = 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; - display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch, - WIN_MOVE_BORDER, winrect_pitch); + /* save winrect top */ + 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; + display_direct_memcpy(fb_ptr, winrect_ptr, _rtgui_cursor->screen_pitch, winrect_pitch, + WIN_MOVE_BORDER, winrect_pitch); - /* save winrect bottom */ - 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, - WIN_MOVE_BORDER, winrect_pitch); + /* save winrect bottom */ + 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, + WIN_MOVE_BORDER, winrect_pitch); } #endif -void rtgui_mouse_monitor_append(rtgui_list_t* head, rtgui_rect_t* rect) +void rtgui_mouse_monitor_append(rtgui_list_t *head, rtgui_rect_t *rect) { - struct rtgui_mouse_monitor* mmonitor; + struct rtgui_mouse_monitor *mmonitor; - /* check parameters */ - if (head == RT_NULL || rect == RT_NULL) return; + /* 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 */ + /* 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)); + /* set mouse monitor node */ + mmonitor->rect = *rect; + rtgui_list_init(&(mmonitor->list)); - /* append to list */ - rtgui_list_append(head, &(mmonitor->list)); + /* append to list */ + rtgui_list_append(head, &(mmonitor->list)); } -void rtgui_mouse_monitor_remove(rtgui_list_t* head, rtgui_rect_t* rect) +void rtgui_mouse_monitor_remove(rtgui_list_t *head, rtgui_rect_t *rect) { - struct rtgui_list_node* node; - struct rtgui_mouse_monitor* mmonitor; + struct rtgui_list_node *node; + struct rtgui_mouse_monitor *mmonitor; - /* check parameters */ - if (head == RT_NULL || rect == RT_NULL) return; + /* 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); + 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 ; - } - } + return ; + } + } } -rt_bool_t rtgui_mouse_monitor_contains_point(rtgui_list_t* head, int x, int y) +rt_bool_t rtgui_mouse_monitor_contains_point(rtgui_list_t *head, int x, int y) { - struct rtgui_list_node* node; + struct rtgui_list_node *node; - /* check parameter */ - if (head == RT_NULL) return RT_FALSE; + /* 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); + 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; - } - } + if (rtgui_rect_contains_point(&(monitor->rect), x, y) == RT_EOK) + { + return RT_TRUE; + } + } - return RT_FALSE; + return RT_FALSE; } diff --git a/components/rtgui/server/mouse.h b/components/rtgui/server/mouse.h index 01c8fc47ce..7b8c4f5990 100644 --- a/components/rtgui/server/mouse.h +++ b/components/rtgui/server/mouse.h @@ -20,11 +20,11 @@ struct rtgui_mouse_monitor { - /* event rect */ - rtgui_rect_t rect; + /* event rect */ + rtgui_rect_t rect; - /* node list */ - rtgui_list_t list; + /* node list */ + rtgui_list_t list; }; typedef struct rtgui_mouse_monitor rtgui_mouse_monitor_t; @@ -33,22 +33,22 @@ void rtgui_mouse_fini(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_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_mouse_is_intersect(rtgui_rect_t *r); #ifdef RTGUI_USING_WINMOVE 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_winrect_set(struct rtgui_topwin *topwin); +rt_bool_t rtgui_winrect_moved_done(rtgui_rect_t *winrect, struct rtgui_topwin **topwin); #endif -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); +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/components/rtgui/server/server.c b/components/rtgui/server/server.c index 28f0fb771f..ea0fbc44c8 100644 --- a/components/rtgui/server/server.c +++ b/components/rtgui/server/server.c @@ -27,174 +27,174 @@ static struct rt_thread *rtgui_server_tid; 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) +void rtgui_server_handle_update(struct rtgui_event_update_end *event) { - struct rtgui_graphic_driver* driver; + struct rtgui_graphic_driver *driver; - driver = rtgui_graphic_driver_get_default(); - if (driver != RT_NULL) - { - rtgui_graphic_driver_screen_update(driver, &(event->rect)); - } + driver = rtgui_graphic_driver_get_default(); + if (driver != RT_NULL) + { + rtgui_graphic_driver_screen_update(driver, &(event->rect)); + } } -void rtgui_server_handle_monitor_add(struct rtgui_event_monitor* event) +void rtgui_server_handle_monitor_add(struct rtgui_event_monitor *event) { - /* add monitor rect to top window list */ - rtgui_topwin_append_monitor_rect(event->wid, &(event->rect)); + /* 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) +void rtgui_server_handle_monitor_remove(struct rtgui_event_monitor *event) { - /* add monitor rect to top window list */ - rtgui_topwin_remove_monitor_rect(event->wid, &(event->rect)); + /* 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) +void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse *event) { - struct rtgui_topwin* wnd; + struct rtgui_topwin *wnd; - /* re-init to server thread */ - RTGUI_EVENT_MOUSE_BUTTON_INIT(event); + /* re-init to server thread */ + RTGUI_EVENT_MOUSE_BUTTON_INIT(event); #ifdef RTGUI_USING_WINMOVE - 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_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; + 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; - } + /* 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_send(topwin->tid, &(ewin.parent), sizeof(ewin)); + /* send to client thread */ + rtgui_send(topwin->tid, &(ewin.parent), sizeof(ewin)); - return; - } - } + return; + } + } #endif - /* get the wnd which contains the mouse */ - wnd = rtgui_topwin_get_wnd_no_modaled(event->x, event->y); - if (wnd != RT_NULL) - { - event->wid = wnd->wid; + /* get the wnd which contains the mouse */ + wnd = rtgui_topwin_get_wnd_no_modaled(event->x, event->y); + if (wnd != RT_NULL) + { + event->wid = wnd->wid; - if (rtgui_topwin_get_focus() != wnd) - { - /* raise this window */ - rtgui_topwin_activate_topwin(wnd); - } + if (rtgui_topwin_get_focus() != wnd) + { + /* raise this window */ + rtgui_topwin_activate_topwin(wnd); + } - 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_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_mouse)); - } - return ; - } + 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_send(wnd->tid, (struct rtgui_event *)event, sizeof(struct rtgui_event_mouse)); + } + return ; + } } -static struct rtgui_topwin* last_monitor_topwin = RT_NULL; +static struct rtgui_topwin *last_monitor_topwin = RT_NULL; -void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse* event) +void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse *event) { - /* the topwin contains current mouse */ - struct rtgui_topwin* win = RT_NULL; + /* the topwin contains current mouse */ + struct rtgui_topwin *win = RT_NULL; - /* re-init mouse event */ - RTGUI_EVENT_MOUSE_MOTION_INIT(event); + /* re-init mouse event */ + RTGUI_EVENT_MOUSE_MOTION_INIT(event); - win = rtgui_topwin_get_wnd_no_modaled(event->x, event->y); - if (win != RT_NULL && win->monitor_list.next != RT_NULL) - { - // FIXME: - /* check whether the monitor exist */ - if (rtgui_mouse_monitor_contains_point(&(win->monitor_list), - event->x, event->y) != RT_TRUE) - { - win = RT_NULL; - } - } + win = rtgui_topwin_get_wnd_no_modaled(event->x, event->y); + if (win != RT_NULL && win->monitor_list.next != RT_NULL) + { + // FIXME: + /* check whether the monitor exist */ + if (rtgui_mouse_monitor_contains_point(&(win->monitor_list), + event->x, event->y) != RT_TRUE) + { + win = RT_NULL; + } + } - if (last_monitor_topwin != RT_NULL) - { - event->wid = last_monitor_topwin->wid; - /* send mouse motion event */ - rtgui_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); - } + if (last_monitor_topwin != RT_NULL) + { + event->wid = last_monitor_topwin->wid; + /* send mouse motion event */ + rtgui_send(last_monitor_topwin->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; + 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_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); - } - } + /* send mouse motion event */ + rtgui_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); + } + } - /* move mouse to (x, y) */ - rtgui_mouse_moveto(event->x, event->y); + /* move mouse to (x, y) */ + rtgui_mouse_moveto(event->x, event->y); } -void rtgui_server_handle_kbd(struct rtgui_event_kbd* event) +void rtgui_server_handle_kbd(struct rtgui_event_kbd *event) { - struct rtgui_topwin* wnd; + struct rtgui_topwin *wnd; - /* re-init to server thread */ - RTGUI_EVENT_KBD_INIT(event); + /* re-init to server thread */ + RTGUI_EVENT_KBD_INIT(event); - /* todo: handle input method and global shortcut */ + /* todo: handle input method and global shortcut */ - wnd = rtgui_topwin_get_focus(); - if (wnd != RT_NULL) - { - RT_ASSERT(wnd->flag & WINTITLE_ACTIVATE) + wnd = rtgui_topwin_get_focus(); + if (wnd != RT_NULL) + { + RT_ASSERT(wnd->flag & WINTITLE_ACTIVATE) - /* send to focus window */ - event->wid = wnd->wid; + /* send to focus window */ + event->wid = wnd->wid; - /* send keyboard event to thread */ - rtgui_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd)); + /* send keyboard event to thread */ + rtgui_send(wnd->tid, (struct rtgui_event *)event, sizeof(struct rtgui_event_kbd)); - return; - } + return; + } } -#ifdef _WIN32 +#ifdef _WIN32_NATIVE #include <windows.h> #endif static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object, - struct rtgui_event *event) + struct rtgui_event *event) { RT_ASSERT(object != RT_NULL); RT_ASSERT(event != RT_NULL); @@ -203,107 +203,107 @@ static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object, 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; + 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 */ + /* mouse and keyboard event */ case RTGUI_EVENT_MOUSE_MOTION: /* handle mouse motion event */ - rtgui_server_handle_mouse_motion((struct rtgui_event_mouse*)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); + 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); + rtgui_server_handle_kbd((struct rtgui_event_kbd *)event); break; - /* window event */ + /* window event */ case RTGUI_EVENT_WIN_CREATE: - if (rtgui_topwin_add((struct rtgui_event_win_create*)event) == RT_EOK) - rtgui_ack(event, RTGUI_STATUS_OK); - else - rtgui_ack(event, RTGUI_STATUS_ERROR); + if (rtgui_topwin_add((struct rtgui_event_win_create *)event) == RT_EOK) + rtgui_ack(event, RTGUI_STATUS_OK); + else + rtgui_ack(event, RTGUI_STATUS_ERROR); break; case RTGUI_EVENT_WIN_SHOW: - if (rtgui_topwin_show((struct rtgui_event_win*)event) == RT_EOK) + if (rtgui_topwin_show((struct rtgui_event_win *)event) == RT_EOK) rtgui_ack(event, RTGUI_STATUS_OK); else rtgui_ack(event, RTGUI_STATUS_ERROR); break; case RTGUI_EVENT_WIN_HIDE: - if (rtgui_topwin_hide((struct rtgui_event_win*)event) == RT_EOK) + if (rtgui_topwin_hide((struct rtgui_event_win *)event) == RT_EOK) rtgui_ack(event, RTGUI_STATUS_OK); else rtgui_ack(event, RTGUI_STATUS_ERROR); break; case RTGUI_EVENT_WIN_MOVE: - if (rtgui_topwin_move((struct rtgui_event_win_move*)event) == RT_EOK) + if (rtgui_topwin_move((struct rtgui_event_win_move *)event) == RT_EOK) rtgui_ack(event, RTGUI_STATUS_OK); else rtgui_ack(event, RTGUI_STATUS_ERROR); break; - case RTGUI_EVENT_WIN_MODAL_ENTER: - if (rtgui_topwin_modal_enter((struct rtgui_event_win_modal_enter*)event) == RT_EOK) - rtgui_ack(event, RTGUI_STATUS_OK); - else - rtgui_ack(event, RTGUI_STATUS_ERROR); - break; + case RTGUI_EVENT_WIN_MODAL_ENTER: + if (rtgui_topwin_modal_enter((struct rtgui_event_win_modal_enter *)event) == RT_EOK) + rtgui_ack(event, RTGUI_STATUS_OK); + else + rtgui_ack(event, RTGUI_STATUS_ERROR); + break; - case RTGUI_EVENT_WIN_ACTIVATE: - if (rtgui_topwin_activate((struct rtgui_event_win_activate*)event) == RT_EOK) - rtgui_ack(event, RTGUI_STATUS_OK); - else - rtgui_ack(event, RTGUI_STATUS_ERROR); - break; + case RTGUI_EVENT_WIN_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) + 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)); + 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; + 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; + 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: @@ -318,7 +318,7 @@ static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object, case RTGUI_EVENT_UPDATE_END: /* handle screen update */ - rtgui_server_handle_update((struct rtgui_event_update_end*)event); + rtgui_server_handle_update((struct rtgui_event_update_end *)event); #ifdef RTGUI_USING_MOUSE_CURSOR /* show cursor */ rtgui_mouse_show_cursor(); @@ -327,36 +327,39 @@ static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object, case RTGUI_EVENT_MONITOR_ADD: /* handle mouse monitor */ - rtgui_server_handle_monitor_add((struct rtgui_event_monitor*)event); + rtgui_server_handle_monitor_add((struct rtgui_event_monitor *)event); break; + default: + rt_kprintf("RTGUI: wrong event sent to server: %d", event->type); + return RT_FALSE; } - return RT_TRUE; + return RT_TRUE; } /** * rtgui server thread's entry */ -static void rtgui_server_entry(void* parameter) +static void rtgui_server_entry(void *parameter) { -#ifdef _WIN32 - /* set the server thread to highest */ - HANDLE hCurrentThread = GetCurrentThread(); - SetThreadPriority(hCurrentThread, THREAD_PRIORITY_HIGHEST); +#ifdef _WIN32_NATIVE + /* set the server thread to highest */ + HANDLE hCurrentThread = GetCurrentThread(); + SetThreadPriority(hCurrentThread, THREAD_PRIORITY_HIGHEST); #endif - /* create rtgui server application */ - rtgui_server_application = rtgui_app_create(rtgui_server_tid, - "rtgui"); + /* create rtgui server application */ + rtgui_server_application = rtgui_app_create(rtgui_server_tid, + "rtgui"); if (rtgui_server_application == RT_NULL) return; rtgui_object_set_event_handler(RTGUI_OBJECT(rtgui_server_application), rtgui_server_event_handler); - /* init mouse and show */ - rtgui_mouse_init(); + /* init mouse and show */ + rtgui_mouse_init(); #ifdef RTGUI_USING_MOUSE_CURSOR - rtgui_mouse_show_cursor(); + rtgui_mouse_show_cursor(); #endif rtgui_app_run(rtgui_server_application); @@ -365,23 +368,23 @@ static void rtgui_server_entry(void* parameter) rtgui_server_application = RT_NULL; } -void rtgui_server_post_event(struct rtgui_event* event, rt_size_t size) +void rtgui_server_post_event(struct rtgui_event *event, rt_size_t size) { - if (rtgui_server_tid != RT_NULL) - rtgui_send(rtgui_server_tid, event, size); - else - rt_kprintf("post when server is not running\n"); + if (rtgui_server_tid != RT_NULL) + rtgui_send(rtgui_server_tid, event, size); + else + rt_kprintf("post when server is not running\n"); } -rt_err_t rtgui_server_post_event_sync(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_send_sync(rtgui_server_tid, event, size); - else - { - rt_kprintf("post when server is not running\n"); - return -RT_ENOSYS; - } + if (rtgui_server_tid != RT_NULL) + return rtgui_send_sync(rtgui_server_tid, event, size); + else + { + rt_kprintf("post when server is not running\n"); + return -RT_ENOSYS; + } } void rtgui_server_init(void) @@ -389,13 +392,13 @@ void rtgui_server_init(void) if (rtgui_server_tid != RT_NULL) return; - 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); + 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); + /* start rtgui server thread */ + if (rtgui_server_tid != RT_NULL) + rt_thread_startup(rtgui_server_tid); } diff --git a/components/rtgui/server/topwin.c b/components/rtgui/server/topwin.c index 31a61e8dc1..abb69d717d 100644 --- a/components/rtgui/server/topwin.c +++ b/components/rtgui/server/topwin.c @@ -40,210 +40,210 @@ */ static struct rtgui_dlist_node _rtgui_topwin_list; #define get_topwin_from_list(list_entry) \ - (rtgui_dlist_entry((list_entry), struct rtgui_topwin, list)) + (rtgui_dlist_entry((list_entry), struct rtgui_topwin, list)) #define IS_ROOT_WIN(topwin) ((topwin)->parent == RT_NULL) 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_redraw(struct rtgui_rect *rect); static void _rtgui_topwin_activate_next(enum rtgui_topwin_flag); void rtgui_topwin_init(void) { - /* init window list */ - rtgui_dlist_init(&_rtgui_topwin_list); + /* init window list */ + rtgui_dlist_init(&_rtgui_topwin_list); - rt_sem_init(&_rtgui_topwin_lock, - "topwin", 1, RT_IPC_FLAG_FIFO); + rt_sem_init(&_rtgui_topwin_lock, + "topwin", 1, RT_IPC_FLAG_FIFO); } -static struct rtgui_topwin* rtgui_topwin_search_in_list(struct rtgui_win* window, - struct rtgui_dlist_node* list) +static struct rtgui_topwin *rtgui_topwin_search_in_list(struct rtgui_win *window, + struct rtgui_dlist_node *list) { - /* TODO: use a cache to speed up the search. */ - struct rtgui_dlist_node* node; - struct rtgui_topwin* topwin; + /* TODO: use a cache to speed up the search. */ + struct rtgui_dlist_node *node; + struct rtgui_topwin *topwin; - /* the action is tend to operate on the top most window. So we search in a - * depth first order. - */ - rtgui_dlist_foreach(node, list, next) - { - topwin = rtgui_dlist_entry(node, struct rtgui_topwin, list); + /* the action is tend to operate on the top most window. So we search in a + * depth first order. + */ + rtgui_dlist_foreach(node, list, next) + { + topwin = rtgui_dlist_entry(node, struct rtgui_topwin, list); - /* is this node? */ - if (topwin->wid == window) - { - return topwin; - } + /* is this node? */ + if (topwin->wid == window) + { + return topwin; + } - topwin = rtgui_topwin_search_in_list(window, &topwin->child_list); - if (topwin != RT_NULL) - return topwin; - } + topwin = rtgui_topwin_search_in_list(window, &topwin->child_list); + if (topwin != RT_NULL) + return topwin; + } - return RT_NULL; + return RT_NULL; } /* add a window to window list[hide] */ -rt_err_t rtgui_topwin_add(struct rtgui_event_win_create* event) +rt_err_t rtgui_topwin_add(struct rtgui_event_win_create *event) { - struct rtgui_topwin* topwin; + struct rtgui_topwin *topwin; - topwin = rtgui_malloc(sizeof(struct rtgui_topwin)); - if (topwin == RT_NULL) - return -RT_ERROR; + topwin = rtgui_malloc(sizeof(struct rtgui_topwin)); + if (topwin == RT_NULL) + return -RT_ERROR; - topwin->wid = event->wid; + topwin->wid = event->wid; #ifdef RTGUI_USING_SMALL_SIZE - topwin->extent = RTGUI_WIDGET(event->wid)->extent; + topwin->extent = RTGUI_WIDGET(event->wid)->extent; #else - topwin->extent = event->extent; + topwin->extent = event->extent; #endif - topwin->tid = event->parent.sender; + topwin->tid = event->parent.sender; - if (event->parent_window == RT_NULL) - { - topwin->parent = RT_NULL; - rtgui_dlist_insert_before(&_rtgui_topwin_list, &topwin->list); - } - else - { - topwin->parent = rtgui_topwin_search_in_list(event->parent_window, &_rtgui_topwin_list); - if (topwin->parent == RT_NULL) - { - /* parent does not exist. Orphan window? */ - rtgui_free(topwin); - return -RT_ERROR; - } - rtgui_dlist_insert_before(&topwin->parent->child_list, &topwin->list); - } + if (event->parent_window == RT_NULL) + { + topwin->parent = RT_NULL; + rtgui_dlist_insert_before(&_rtgui_topwin_list, &topwin->list); + } + else + { + topwin->parent = rtgui_topwin_search_in_list(event->parent_window, &_rtgui_topwin_list); + if (topwin->parent == RT_NULL) + { + /* parent does not exist. Orphan window? */ + rtgui_free(topwin); + return -RT_ERROR; + } + rtgui_dlist_insert_before(&topwin->parent->child_list, &topwin->list); + } - rtgui_dlist_init(&topwin->child_list); + rtgui_dlist_init(&topwin->child_list); - 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 (event->parent.user & RTGUI_WIN_STYLE_ONTOP) topwin->flag |= WINTITLE_ONTOP; - if (event->parent.user & RTGUI_WIN_STYLE_ONBTM) topwin->flag |= WINTITLE_ONBTM; + 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 (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)) - { - /* get win extent */ - rtgui_rect_t rect = topwin->extent; + 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 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; + /* add title rect */ + if (!(topwin->flag & WINTITLE_NO)) rect.y1 -= WINTITLE_HEIGHT; #ifdef RTGUI_USING_SMALL_SIZE - topwin->title = rtgui_wintitle_create(topwin->wid, event->wid->title); + topwin->title = rtgui_wintitle_create(topwin->wid, event->wid->title); #else - topwin->title = rtgui_wintitle_create(topwin->wid, (const char*)event->title); + topwin->title = rtgui_wintitle_create(topwin->wid, (const char *)event->title); #endif - rtgui_widget_set_rect(RTGUI_WIDGET(topwin->title), &rect); + rtgui_widget_set_rect(RTGUI_WIDGET(topwin->title), &rect); - /* update clip info */ - rtgui_region_subtract_rect(&(RTGUI_WIDGET(topwin->title)->clip), - &(RTGUI_WIDGET(topwin->title)->clip), - &(topwin->extent)); - } - else - topwin->title = RT_NULL; + /* update clip info */ + 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->monitor_list); + rtgui_list_init(&topwin->monitor_list); - return RT_EOK; + return RT_EOK; } -static struct rtgui_topwin* _rtgui_topwin_get_root_win(struct rtgui_topwin *topwin) +static struct rtgui_topwin *_rtgui_topwin_get_root_win(struct rtgui_topwin *topwin) { - struct rtgui_topwin *topparent; + struct rtgui_topwin *topparent; - RT_ASSERT(topwin != RT_NULL); + RT_ASSERT(topwin != RT_NULL); - topparent = topwin; - while (topparent && !IS_ROOT_WIN(topparent)) - topparent = topparent->parent; - return topparent; + topparent = topwin; + while (topparent && !IS_ROOT_WIN(topparent)) + topparent = topparent->parent; + return topparent; } -static struct rtgui_topwin* _rtgui_topwin_get_topmost_child_shown(struct rtgui_topwin *topwin) +static struct rtgui_topwin *_rtgui_topwin_get_topmost_child_shown(struct rtgui_topwin *topwin) { - RT_ASSERT(topwin != RT_NULL); + RT_ASSERT(topwin != RT_NULL); - while (!(rtgui_dlist_isempty(&topwin->child_list)) && - get_topwin_from_list(topwin->child_list.next)->flag & WINTITLE_SHOWN) - topwin = get_topwin_from_list(topwin->child_list.next); - return topwin; + while (!(rtgui_dlist_isempty(&topwin->child_list)) && + get_topwin_from_list(topwin->child_list.next)->flag &WINTITLE_SHOWN) + topwin = get_topwin_from_list(topwin->child_list.next); + return topwin; } static rt_bool_t _rtgui_topwin_in_layer(struct rtgui_topwin *topwin, enum rtgui_topwin_flag flag) { - return (topwin->flag & (WINTITLE_ONTOP|WINTITLE_ONBTM)) - == (flag & (WINTITLE_ONTOP|WINTITLE_ONBTM)); + 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) +static struct rtgui_topwin *_rtgui_topwin_get_topmost_window_shown(enum rtgui_topwin_flag flag) { - struct rtgui_dlist_node *node; + struct rtgui_dlist_node *node; - rtgui_dlist_foreach(node, &_rtgui_topwin_list, next) - { - struct rtgui_topwin *topwin = get_topwin_from_list(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; + /* 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; + 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 * any time. */ static rt_bool_t _rtgui_topwin_could_show(struct rtgui_topwin *topwin) { - struct rtgui_topwin *parent; + struct rtgui_topwin *parent; - RT_ASSERT(topwin != RT_NULL); + RT_ASSERT(topwin != RT_NULL); - for (parent = topwin->parent; parent != RT_NULL; parent = parent->parent) - { - if (!(parent->flag & WINTITLE_SHOWN)) - return RT_FALSE; - } - return RT_TRUE; + for (parent = topwin->parent; parent != RT_NULL; parent = parent->parent) + { + if (!(parent->flag & WINTITLE_SHOWN)) + return RT_FALSE; + } + return RT_TRUE; } static void _rtgui_topwin_union_region_tree(struct rtgui_topwin *topwin, - struct rtgui_region *region) + struct rtgui_region *region) { - struct rtgui_dlist_node *node; + struct rtgui_dlist_node *node; - RT_ASSERT(topwin != RT_NULL); + RT_ASSERT(topwin != RT_NULL); - rtgui_dlist_foreach(node, &topwin->child_list, next) - _rtgui_topwin_union_region_tree(get_topwin_from_list(node), region); + rtgui_dlist_foreach(node, &topwin->child_list, next) + _rtgui_topwin_union_region_tree(get_topwin_from_list(node), region); - if (topwin->title != RT_NULL) - rtgui_region_union_rect(region, region, &RTGUI_WIDGET(topwin->title)->extent); - else - rtgui_region_union_rect(region, region, &topwin->extent); + if (topwin->title != RT_NULL) + rtgui_region_union_rect(region, region, &RTGUI_WIDGET(topwin->title)->extent); + else + rtgui_region_union_rect(region, region, &topwin->extent); } /* The return value of this function is the next node in tree. @@ -251,72 +251,72 @@ static void _rtgui_topwin_union_region_tree(struct rtgui_topwin *topwin, * As we freed the node in this function, it would be a null reference error of * the caller iterate the tree normally. */ -static struct rtgui_dlist_node* _rtgui_topwin_free_tree(struct rtgui_topwin *topwin) +static struct rtgui_dlist_node *_rtgui_topwin_free_tree(struct rtgui_topwin *topwin) { - struct rtgui_dlist_node *node, *next_node; + struct rtgui_dlist_node *node, *next_node; - RT_ASSERT(topwin != RT_NULL); + RT_ASSERT(topwin != RT_NULL); - node = topwin->child_list.next; - while (node != &topwin->child_list) - node = _rtgui_topwin_free_tree(get_topwin_from_list(node)); + node = topwin->child_list.next; + while (node != &topwin->child_list) + node = _rtgui_topwin_free_tree(get_topwin_from_list(node)); - next_node = topwin->list.next; - rtgui_dlist_remove(&topwin->list); + next_node = topwin->list.next; + rtgui_dlist_remove(&topwin->list); - /* 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); + /* 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); - } + topwin->monitor_list.next = topwin->monitor_list.next->next; + rtgui_free(monitor); + } - /* destroy win title */ - rtgui_wintitle_destroy(topwin->title); - topwin->title = RT_NULL; + /* destroy win title */ + rtgui_wintitle_destroy(topwin->title); + topwin->title = RT_NULL; - rtgui_free(topwin); - return next_node; + rtgui_free(topwin); + return next_node; } -rt_err_t rtgui_topwin_remove(struct rtgui_win* wid) +rt_err_t rtgui_topwin_remove(struct rtgui_win *wid) { - struct rtgui_topwin *topwin, *old_focus; - struct rtgui_region region; + struct rtgui_topwin *topwin, *old_focus; + struct rtgui_region region; - /* find the topwin node */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_list); + /* find the topwin node */ + topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_list); - if (topwin == RT_NULL) - return -RT_ERROR; + if (topwin == RT_NULL) + return -RT_ERROR; - rtgui_region_init(®ion); + rtgui_region_init(®ion); - old_focus = rtgui_topwin_get_focus(); + old_focus = rtgui_topwin_get_focus(); - /* remove the root from _rtgui_topwin_list will remove the whole tree from - * _rtgui_topwin_list. */ - rtgui_dlist_remove(&topwin->list); + /* 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(topwin->flag); - } + if (old_focus == topwin) + { + _rtgui_topwin_activate_next(topwin->flag); + } - 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)); - } + 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); + _rtgui_topwin_free_tree(topwin); - return RT_EOK; + return RT_EOK; } /* neither deactivate the old focus nor change _rtgui_topwin_list. @@ -324,147 +324,147 @@ rt_err_t rtgui_topwin_remove(struct rtgui_win* wid) * already. */ static void _rtgui_topwin_only_activate(struct rtgui_topwin *topwin) { - struct rtgui_event_win event; + struct rtgui_event_win event; - RT_ASSERT(topwin != RT_NULL); + RT_ASSERT(topwin != RT_NULL); - if (topwin->flag & WINTITLE_NOFOCUS) - return; + if (topwin->flag & WINTITLE_NOFOCUS) + return; - /* activate the raised window */ - RTGUI_EVENT_WIN_ACTIVATE_INIT(&event); + /* activate the raised window */ + RTGUI_EVENT_WIN_ACTIVATE_INIT(&event); - topwin->flag |= WINTITLE_ACTIVATE; + topwin->flag |= WINTITLE_ACTIVATE; - event.wid = topwin->wid; - rtgui_send(topwin->tid, &(event.parent), sizeof(struct rtgui_event_win)); + event.wid = topwin->wid; + rtgui_send(topwin->tid, &(event.parent), sizeof(struct rtgui_event_win)); - /* redraw title */ - if (topwin->title != RT_NULL) - { - rtgui_theme_draw_win(topwin); - } + /* redraw title */ + if (topwin->title != RT_NULL) + { + rtgui_theme_draw_win(topwin); + } } /* 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; + struct rtgui_topwin *topwin; - topwin = _rtgui_topwin_get_topmost_window_shown(flag); - if (topwin == RT_NULL) - return; + topwin = _rtgui_topwin_get_topmost_window_shown(flag); + if (topwin == RT_NULL) + return; - _rtgui_topwin_only_activate(topwin); + _rtgui_topwin_only_activate(topwin); } /* this function does not update the clip(to avoid doubel clipping). So if the * tree has changed, make sure it has already updated outside. */ static void _rtgui_topwin_deactivate(struct rtgui_topwin *topwin) { - struct rtgui_event_win event; + struct rtgui_event_win event; - RT_ASSERT(topwin != RT_NULL); - RT_ASSERT(topwin->tid != RT_NULL); + RT_ASSERT(topwin != RT_NULL); + RT_ASSERT(topwin->tid != RT_NULL); - RTGUI_EVENT_WIN_DEACTIVATE_INIT(&event); - event.wid = topwin->wid; - rtgui_send(topwin->tid, - &event.parent, sizeof(struct rtgui_event_win)); + RTGUI_EVENT_WIN_DEACTIVATE_INIT(&event); + event.wid = topwin->wid; + rtgui_send(topwin->tid, + &event.parent, sizeof(struct rtgui_event_win)); - topwin->flag &= ~WINTITLE_ACTIVATE; + topwin->flag &= ~WINTITLE_ACTIVATE; - /* redraw title */ - if (topwin->title != RT_NULL) - { - rtgui_theme_draw_win(topwin); - } + /* redraw title */ + if (topwin->title != RT_NULL) + { + rtgui_theme_draw_win(topwin); + } } static void _rtgui_topwin_move_whole_tree2top(struct rtgui_topwin *topwin) { - struct rtgui_topwin *topparent; + struct rtgui_topwin *topparent; - RT_ASSERT(topwin != RT_NULL); + RT_ASSERT(topwin != RT_NULL); - /* move the whole tree */ - topparent = _rtgui_topwin_get_root_win(topwin); - RT_ASSERT(topparent != RT_NULL); + /* move the whole tree */ + topparent = _rtgui_topwin_get_root_win(topwin); + RT_ASSERT(topparent != RT_NULL); - /* remove node from hidden list */ - rtgui_dlist_remove(&topparent->list); - /* add node to show list */ - 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; + /* remove node from hidden list */ + rtgui_dlist_remove(&topparent->list); + /* add node to show list */ + 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_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)); - } + 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_in_sibling(struct rtgui_topwin *topwin) { - struct rtgui_dlist_node *win_level; + struct rtgui_dlist_node *win_level; - RT_ASSERT(topwin != RT_NULL); + RT_ASSERT(topwin != RT_NULL); - if (topwin->parent == RT_NULL) - win_level = &_rtgui_topwin_list; - else - win_level = &topwin->parent->child_list; - rtgui_dlist_remove(&topwin->list); - rtgui_dlist_insert_after(win_level, &topwin->list); + if (topwin->parent == RT_NULL) + win_level = &_rtgui_topwin_list; + else + win_level = &topwin->parent->child_list; + rtgui_dlist_remove(&topwin->list); + 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); + 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); + _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: @@ -472,84 +472,84 @@ static void _rtgui_topwin_raise_tree_from_root(struct rtgui_topwin *topwin) * - raise the window to the front of it's siblings * - activate a win */ -rt_err_t rtgui_topwin_activate(struct rtgui_event_win_activate* event) +rt_err_t rtgui_topwin_activate(struct rtgui_event_win_activate *event) { - struct rtgui_topwin *topwin; + struct rtgui_topwin *topwin; - RT_ASSERT(event); + RT_ASSERT(event); - topwin = rtgui_topwin_search_in_list(event->wid, &_rtgui_topwin_list); - if (topwin == RT_NULL) - return -RT_ERROR; + topwin = rtgui_topwin_search_in_list(event->wid, &_rtgui_topwin_list); + if (topwin == RT_NULL) + return -RT_ERROR; - return rtgui_topwin_activate_topwin(topwin); + return rtgui_topwin_activate_topwin(topwin); } static void _rtgui_topwin_draw_tree(struct rtgui_topwin *topwin, struct rtgui_event_paint *epaint) { - struct rtgui_dlist_node *node; + struct rtgui_dlist_node *node; - if (topwin->title != RT_NULL) - { - rtgui_theme_draw_win(topwin); - } + if (topwin->title != RT_NULL) + { + rtgui_theme_draw_win(topwin); + } - epaint->wid = topwin->wid; - rtgui_send(topwin->tid, &(epaint->parent), sizeof(struct rtgui_event_paint)); + epaint->wid = topwin->wid; + 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); - } + 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); + } } -rt_err_t rtgui_topwin_activate_topwin(struct rtgui_topwin* topwin) +rt_err_t rtgui_topwin_activate_topwin(struct rtgui_topwin *topwin) { - struct rtgui_topwin *old_focus_topwin; + struct rtgui_topwin *old_focus_topwin; struct rtgui_event_paint epaint; - RT_ASSERT(topwin != RT_NULL); + RT_ASSERT(topwin != RT_NULL); RTGUI_EVENT_PAINT_INIT(&epaint); - if (!(topwin->flag & WINTITLE_SHOWN)) - return -RT_ERROR; + if (!(topwin->flag & WINTITLE_SHOWN)) + return -RT_ERROR; - if (topwin->flag & WINTITLE_NOFOCUS) - { - /* just raise and show, not affect others. */ + if (topwin->flag & WINTITLE_NOFOCUS) + { + /* just raise and show, not affect others. */ _rtgui_topwin_raise_tree_from_root(topwin); rtgui_topwin_update_clip(); _rtgui_topwin_draw_tree(topwin, &epaint); - return RT_EOK; - } + return RT_EOK; + } - if (topwin->flag & WINTITLE_ACTIVATE) - return RT_EOK; + if (topwin->flag & WINTITLE_ACTIVATE) + return RT_EOK; - 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); + 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_tree_from_root(topwin); + _rtgui_topwin_raise_tree_from_root(topwin); /* clip before active the window, so we could get right boarder region. */ - rtgui_topwin_update_clip(); + rtgui_topwin_update_clip(); - if (old_focus_topwin != RT_NULL) - { - /* deactivate the old focus window firstly, otherwise it will make the new - * window invisible. */ - _rtgui_topwin_deactivate(old_focus_topwin); - } + if (old_focus_topwin != RT_NULL) + { + /* deactivate the old focus window firstly, otherwise it will make the new + * window invisible. */ + _rtgui_topwin_deactivate(old_focus_topwin); + } - _rtgui_topwin_only_activate(topwin); + _rtgui_topwin_only_activate(topwin); _rtgui_topwin_draw_tree(topwin, &epaint); - return RT_EOK; + return RT_EOK; } /* map func to the topwin tree in preorder. @@ -557,621 +557,621 @@ rt_err_t rtgui_topwin_activate_topwin(struct rtgui_topwin* topwin) * Remember that we are in a embedded system so write the @param func memory * efficiently. */ -rt_inline void _rtgui_topwin_preorder_map(struct rtgui_topwin *topwin, void (*func)(struct rtgui_topwin*)) +rt_inline void _rtgui_topwin_preorder_map(struct rtgui_topwin *topwin, void (*func)(struct rtgui_topwin *)) { - struct rtgui_dlist_node *child; + struct rtgui_dlist_node *child; - RT_ASSERT(topwin != RT_NULL); - RT_ASSERT(func != RT_NULL); + RT_ASSERT(topwin != RT_NULL); + RT_ASSERT(func != RT_NULL); - func(topwin); + func(topwin); - rtgui_dlist_foreach(child, &topwin->child_list, next) - _rtgui_topwin_preorder_map(get_topwin_from_list(child), func); + rtgui_dlist_foreach(child, &topwin->child_list, next) + _rtgui_topwin_preorder_map(get_topwin_from_list(child), func); } rt_inline void _rtgui_topwin_mark_hidden(struct rtgui_topwin *topwin) { - topwin->flag &= ~WINTITLE_SHOWN; - if (topwin->title != RT_NULL) - { - RTGUI_WIDGET_HIDE(topwin->title); - } - RTGUI_WIDGET_HIDE(topwin->wid); + topwin->flag &= ~WINTITLE_SHOWN; + if (topwin->title != RT_NULL) + { + RTGUI_WIDGET_HIDE(topwin->title); + } + RTGUI_WIDGET_HIDE(topwin->wid); } rt_inline void _rtgui_topwin_mark_shown(struct rtgui_topwin *topwin) { - if (!(topwin->flag & WINTITLE_SHOWN) - && RTGUI_WIDGET_IS_HIDE(topwin->wid)) - return; + if (!(topwin->flag & WINTITLE_SHOWN) + && RTGUI_WIDGET_IS_HIDE(topwin->wid)) + return; - topwin->flag |= WINTITLE_SHOWN; - if (topwin->title != RT_NULL) - { - RTGUI_WIDGET_UNHIDE(topwin->title); - } - RTGUI_WIDGET_UNHIDE(topwin->wid); + topwin->flag |= WINTITLE_SHOWN; + if (topwin->title != RT_NULL) + { + RTGUI_WIDGET_UNHIDE(topwin->title); + } + RTGUI_WIDGET_UNHIDE(topwin->wid); } -rt_err_t rtgui_topwin_show(struct rtgui_event_win* event) +rt_err_t rtgui_topwin_show(struct rtgui_event_win *event) { - struct rtgui_topwin *topwin; - struct rtgui_win* wid = event->wid; + struct rtgui_topwin *topwin; + struct rtgui_win *wid = event->wid; - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_list); - /* no such a window recorded */ - if (topwin == RT_NULL) - return -RT_ERROR; + topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_list); + /* 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); + /* 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; - } + return -RT_ERROR; + } _rtgui_topwin_preorder_map(topwin, _rtgui_topwin_mark_shown); rtgui_topwin_activate_topwin(topwin); - return RT_EOK; + return RT_EOK; } static void _rtgui_topwin_clear_modal_tree(struct rtgui_topwin *topwin) { - struct rtgui_dlist_node *node; + struct rtgui_dlist_node *node; - RT_ASSERT(topwin != RT_NULL); - RT_ASSERT(topwin->parent != RT_NULL); + RT_ASSERT(topwin != RT_NULL); + RT_ASSERT(topwin->parent != RT_NULL); - while (!IS_ROOT_WIN(topwin)) - { - rtgui_dlist_foreach(node, &topwin->parent->child_list, next) - get_topwin_from_list(node)->flag &= ~WINTITLE_MODALED; - topwin = topwin->parent; - } - /* clear the modal flag of the root window */ - topwin->flag &= ~WINTITLE_MODALED; + while (!IS_ROOT_WIN(topwin)) + { + rtgui_dlist_foreach(node, &topwin->parent->child_list, next) + get_topwin_from_list(node)->flag &= ~WINTITLE_MODALED; + topwin = topwin->parent; + } + /* clear the modal flag of the root window */ + topwin->flag &= ~WINTITLE_MODALED; } /* hide a window */ -rt_err_t rtgui_topwin_hide(struct rtgui_event_win* event) +rt_err_t rtgui_topwin_hide(struct rtgui_event_win *event) { - struct rtgui_topwin *topwin; - struct rtgui_topwin *old_focus_topwin = rtgui_topwin_get_focus(); - struct rtgui_win *wid = event->wid; - struct rtgui_dlist_node *containing_list; + struct rtgui_topwin *topwin; + struct rtgui_topwin *old_focus_topwin = rtgui_topwin_get_focus(); + struct rtgui_win *wid = event->wid; + struct rtgui_dlist_node *containing_list; - /* find in show list */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_list); - if (topwin == RT_NULL) - { - return -RT_ERROR; - } - if (!(topwin->flag & WINTITLE_SHOWN)) - { - return RT_EOK; - } + /* find in show list */ + topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_list); + if (topwin == RT_NULL) + { + return -RT_ERROR; + } + if (!(topwin->flag & WINTITLE_SHOWN)) + { + return RT_EOK; + } - old_focus_topwin = rtgui_topwin_get_focus(); + old_focus_topwin = rtgui_topwin_get_focus(); - _rtgui_topwin_preorder_map(topwin, _rtgui_topwin_mark_hidden); + _rtgui_topwin_preorder_map(topwin, _rtgui_topwin_mark_hidden); - if (topwin->parent == RT_NULL) - containing_list = &_rtgui_topwin_list; - else - containing_list = &topwin->parent->child_list; + if (topwin->parent == RT_NULL) + containing_list = &_rtgui_topwin_list; + else + containing_list = &topwin->parent->child_list; - rtgui_dlist_remove(&topwin->list); - rtgui_dlist_insert_before(containing_list, &topwin->list); + rtgui_dlist_remove(&topwin->list); + rtgui_dlist_insert_before(containing_list, &topwin->list); - /* update clip info */ - rtgui_topwin_update_clip(); + /* update clip info */ + rtgui_topwin_update_clip(); - /* redraw the old rect */ - rtgui_topwin_redraw(&(topwin->extent)); + /* redraw the old rect */ + rtgui_topwin_redraw(&(topwin->extent)); - if (topwin->flag & WINTITLE_MODALING) - { - _rtgui_topwin_clear_modal_tree(topwin); - topwin->flag &= ~WINTITLE_MODALING; - } + if (topwin->flag & WINTITLE_MODALING) + { + _rtgui_topwin_clear_modal_tree(topwin); + topwin->flag &= ~WINTITLE_MODALING; + } - if (old_focus_topwin == topwin) - { - _rtgui_topwin_activate_next(topwin->flag); - } + if (old_focus_topwin == topwin) + { + _rtgui_topwin_activate_next(topwin->flag); + } topwin->flag &= ~WINTITLE_ACTIVATE; - return RT_EOK; + return RT_EOK; } /* move top window */ -rt_err_t rtgui_topwin_move(struct rtgui_event_win_move* event) +rt_err_t rtgui_topwin_move(struct rtgui_event_win_move *event) { - struct rtgui_topwin* topwin; - int dx, dy; - rtgui_rect_t old_rect; /* the old topwin coverage area */ - struct rtgui_list_node* node; + struct rtgui_topwin *topwin; + int dx, dy; + rtgui_rect_t old_rect; /* the old topwin coverage area */ + struct rtgui_list_node *node; - /* find in show list */ - topwin = rtgui_topwin_search_in_list(event->wid, &_rtgui_topwin_list); - if (topwin == RT_NULL || - !(topwin->flag & WINTITLE_SHOWN)) - { - return -RT_ERROR; - } + /* find in show list */ + topwin = rtgui_topwin_search_in_list(event->wid, &_rtgui_topwin_list); + if (topwin == RT_NULL || + !(topwin->flag & WINTITLE_SHOWN)) + { + return -RT_ERROR; + } - /* get the delta move x, y */ - dx = event->x - topwin->extent.x1; - dy = event->y - topwin->extent.y1; + /* get the delta move x, y */ + dx = event->x - topwin->extent.x1; + dy = event->y - topwin->extent.y1; - old_rect = topwin->extent; - /* move window rect */ - rtgui_rect_moveto(&(topwin->extent), dx, dy); + old_rect = topwin->extent; + /* move window rect */ + rtgui_rect_moveto(&(topwin->extent), dx, dy); - /* move window title */ - if (topwin->title != RT_NULL) - { - old_rect = RTGUI_WIDGET(topwin->title)->extent; - rtgui_widget_move_to_logic(RTGUI_WIDGET(topwin->title), dx, dy); - } + /* move window title */ + if (topwin->title != RT_NULL) + { + old_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); - } + /* 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 windows clip info */ + rtgui_topwin_update_clip(); - /* update old window coverage area */ - rtgui_topwin_redraw(&old_rect); + /* update old window coverage area */ + rtgui_topwin_redraw(&old_rect); - /* update top window title */ - if (topwin->title != RT_NULL) - rtgui_theme_draw_win(topwin); - if (rtgui_rect_is_intersect(&old_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_send(topwin->tid, &(epaint.parent), sizeof(epaint)); - } + /* update top window title */ + if (topwin->title != RT_NULL) + rtgui_theme_draw_win(topwin); + if (rtgui_rect_is_intersect(&old_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_send(topwin->tid, &(epaint.parent), sizeof(epaint)); + } - return RT_EOK; + return RT_EOK; } /* * resize a top win * Note: currently, only support resize hidden window */ -void rtgui_topwin_resize(struct rtgui_win* wid, rtgui_rect_t* rect) +void rtgui_topwin_resize(struct rtgui_win *wid, rtgui_rect_t *rect) { - struct rtgui_topwin* topwin; - struct rtgui_region region; + struct rtgui_topwin *topwin; + struct rtgui_region region; - /* find in show list */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_list); - if (topwin == RT_NULL || - !(topwin->flag & WINTITLE_SHOWN)) - return; + /* find in show list */ + topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_list); + if (topwin == RT_NULL || + !(topwin->flag & WINTITLE_SHOWN)) + return; - /* record the old rect */ - rtgui_region_init_with_extents(®ion, &topwin->extent); - /* union the new rect so this is the region we should redraw */ - rtgui_region_union_rect(®ion, ®ion, rect); + /* record the old rect */ + rtgui_region_init_with_extents(®ion, &topwin->extent); + /* union the new rect so this is the region we should redraw */ + rtgui_region_union_rect(®ion, ®ion, rect); - topwin->extent = *rect; + topwin->extent = *rect; - if (topwin->title != RT_NULL) - { - /* get win extent */ - rtgui_rect_t rect = topwin->extent; + 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 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; + /* add title rect */ + if (!(topwin->flag & WINTITLE_NO)) + rect.y1 -= WINTITLE_HEIGHT; - RTGUI_WIDGET(topwin->title)->extent = rect; - } + RTGUI_WIDGET(topwin->title)->extent = rect; + } - /* update windows clip info */ - rtgui_topwin_update_clip(); + /* update windows clip info */ + rtgui_topwin_update_clip(); - /* update old window coverage area */ - rtgui_topwin_redraw(rtgui_region_extents(®ion)); + /* update old window coverage area */ + rtgui_topwin_redraw(rtgui_region_extents(®ion)); } -static struct rtgui_topwin* _rtgui_topwin_get_focus_from_list(struct rtgui_dlist_node *list) +static struct rtgui_topwin *_rtgui_topwin_get_focus_from_list(struct rtgui_dlist_node *list) { - struct rtgui_dlist_node *node; + struct rtgui_dlist_node *node; - RT_ASSERT(list != RT_NULL); + RT_ASSERT(list != RT_NULL); - rtgui_dlist_foreach(node, list, next) - { - struct rtgui_topwin *child = get_topwin_from_list(node); - if (child->flag & WINTITLE_ACTIVATE) - return child; + rtgui_dlist_foreach(node, list, next) + { + struct rtgui_topwin *child = get_topwin_from_list(node); + if (child->flag & WINTITLE_ACTIVATE) + return child; - child = _rtgui_topwin_get_focus_from_list(&child->child_list); - if (child != RT_NULL) - return child; - } + child = _rtgui_topwin_get_focus_from_list(&child->child_list); + if (child != RT_NULL) + return child; + } - return RT_NULL; + return RT_NULL; } -struct rtgui_topwin* rtgui_topwin_get_focus(void) +struct rtgui_topwin *rtgui_topwin_get_focus(void) { - return _rtgui_topwin_get_focus_from_list(&_rtgui_topwin_list); + return _rtgui_topwin_get_focus_from_list(&_rtgui_topwin_list); } -static struct rtgui_topwin* _rtgui_topwin_get_wnd_from_tree(struct rtgui_dlist_node *list, - int x, int y, - rt_bool_t exclude_modaled) +static struct rtgui_topwin *_rtgui_topwin_get_wnd_from_tree(struct rtgui_dlist_node *list, + int x, int y, + rt_bool_t exclude_modaled) { - struct rtgui_dlist_node *node; - struct rtgui_topwin *topwin, *target; + struct rtgui_dlist_node *node; + struct rtgui_topwin *topwin, *target; - RT_ASSERT(list != RT_NULL); + RT_ASSERT(list != RT_NULL); - rtgui_dlist_foreach(node, list, next) - { - topwin = get_topwin_from_list(node); - if (!(topwin->flag & WINTITLE_SHOWN)) - break; + rtgui_dlist_foreach(node, list, next) + { + topwin = get_topwin_from_list(node); + if (!(topwin->flag & WINTITLE_SHOWN)) + break; - /* if higher window have this point, return it */ - target = _rtgui_topwin_get_wnd_from_tree(&topwin->child_list, x, y, exclude_modaled); - if (target != RT_NULL) - return target; + /* if higher window have this point, return it */ + target = _rtgui_topwin_get_wnd_from_tree(&topwin->child_list, x, y, exclude_modaled); + if (target != RT_NULL) + return target; - if (exclude_modaled && (topwin->flag & WINTITLE_MODALED)) - break; + if (exclude_modaled && (topwin->flag & WINTITLE_MODALED)) + break; - 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; - } - } + 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; + return RT_NULL; } -struct rtgui_topwin* rtgui_topwin_get_wnd(int x, int y) +struct rtgui_topwin *rtgui_topwin_get_wnd(int x, int y) { - return _rtgui_topwin_get_wnd_from_tree(&_rtgui_topwin_list, x, y, RT_FALSE); + return _rtgui_topwin_get_wnd_from_tree(&_rtgui_topwin_list, x, y, RT_FALSE); } -struct rtgui_topwin* rtgui_topwin_get_wnd_no_modaled(int x, int y) +struct rtgui_topwin *rtgui_topwin_get_wnd_no_modaled(int x, int y) { - return _rtgui_topwin_get_wnd_from_tree(&_rtgui_topwin_list, x, y, RT_TRUE); + return _rtgui_topwin_get_wnd_from_tree(&_rtgui_topwin_list, x, y, RT_TRUE); } /* clip region from topwin, and the windows beneath it. */ rt_inline void _rtgui_topwin_clip_to_region(struct rtgui_region *region, - struct rtgui_topwin *topwin) + struct rtgui_topwin *topwin) { - RT_ASSERT(region != RT_NULL); - RT_ASSERT(topwin != RT_NULL); + RT_ASSERT(region != RT_NULL); + RT_ASSERT(topwin != RT_NULL); - if (topwin->title != RT_NULL) - { - rtgui_region_reset(&(RTGUI_WIDGET(topwin->title)->clip), - &(RTGUI_WIDGET(topwin->title)->extent)); - rtgui_region_intersect(&(RTGUI_WIDGET(topwin->title)->clip), - &(RTGUI_WIDGET(topwin->title)->clip), - region); - rtgui_region_subtract_rect(&(RTGUI_WIDGET(topwin->title)->clip), - &(RTGUI_WIDGET(topwin->title)->clip), - &topwin->extent); - } + if (topwin->title != RT_NULL) + { + rtgui_region_reset(&(RTGUI_WIDGET(topwin->title)->clip), + &(RTGUI_WIDGET(topwin->title)->extent)); + rtgui_region_intersect(&(RTGUI_WIDGET(topwin->title)->clip), + &(RTGUI_WIDGET(topwin->title)->clip), + region); + rtgui_region_subtract_rect(&(RTGUI_WIDGET(topwin->title)->clip), + &(RTGUI_WIDGET(topwin->title)->clip), + &topwin->extent); + } - rtgui_region_reset(&RTGUI_WIDGET(topwin->wid)->clip, - &RTGUI_WIDGET(topwin->wid)->extent); - rtgui_region_intersect(&RTGUI_WIDGET(topwin->wid)->clip, - &RTGUI_WIDGET(topwin->wid)->clip, - region); + rtgui_region_reset(&RTGUI_WIDGET(topwin->wid)->clip, + &RTGUI_WIDGET(topwin->wid)->extent); + rtgui_region_intersect(&RTGUI_WIDGET(topwin->wid)->clip, + &RTGUI_WIDGET(topwin->wid)->clip, + region); } static void rtgui_topwin_update_clip(void) { - struct rtgui_topwin *top; - struct rtgui_event_clip_info eclip; - /* Note that the region is a "female die", that means it's the region you - * can paint to, not the region covered by others. - */ - struct rtgui_region region_available; + struct rtgui_topwin *top; + struct rtgui_event_clip_info eclip; + /* Note that the region is a "female die", that means it's the region you + * can paint to, not the region covered by others. + */ + struct rtgui_region region_available; - if (rtgui_dlist_isempty(&_rtgui_topwin_list) || - !(get_topwin_from_list(_rtgui_topwin_list.next)->flag & WINTITLE_SHOWN)) - return; + if (rtgui_dlist_isempty(&_rtgui_topwin_list) || + !(get_topwin_from_list(_rtgui_topwin_list.next)->flag & WINTITLE_SHOWN)) + return; - RTGUI_EVENT_CLIP_INFO_INIT(&eclip); + RTGUI_EVENT_CLIP_INFO_INIT(&eclip); - rtgui_region_init_rect(®ion_available, 0, 0, - rtgui_graphic_driver_get_default()->width, - rtgui_graphic_driver_get_default()->height); + rtgui_region_init_rect(®ion_available, 0, 0, + rtgui_graphic_driver_get_default()->width, + rtgui_graphic_driver_get_default()->height); - /* from top to bottom. */ - 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); + /* from top to bottom. */ + 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) - { - /* clip the topwin */ - _rtgui_topwin_clip_to_region(®ion_available, top); + while (top != RT_NULL) + { + /* clip the topwin */ + _rtgui_topwin_clip_to_region(®ion_available, top); #if 0 - /* debug window clipping */ - rt_kprintf("clip %s ", top->wid->title); - rtgui_region_dump(®ion_available); - rt_kprintf("\n"); + /* debug window clipping */ + rt_kprintf("clip %s ", top->wid->title); + rtgui_region_dump(®ion_available); + rt_kprintf("\n"); #endif - /* update available region */ - if (top->title != RT_NULL) - rtgui_region_subtract_rect(®ion_available, ®ion_available, &RTGUI_WIDGET(top->title)->extent); - else - rtgui_region_subtract_rect(®ion_available, ®ion_available, &top->extent); + /* update available region */ + if (top->title != RT_NULL) + rtgui_region_subtract_rect(®ion_available, ®ion_available, &RTGUI_WIDGET(top->title)->extent); + else + rtgui_region_subtract_rect(®ion_available, ®ion_available, &top->extent); - /* send clip event to destination window */ - eclip.wid = top->wid; - rtgui_send(top->tid, &(eclip.parent), sizeof(struct rtgui_event_clip_info)); + /* send clip event to destination window */ + eclip.wid = top->wid; + rtgui_send(top->tid, &(eclip.parent), sizeof(struct rtgui_event_clip_info)); - /* move to next sibling tree */ - if (top->parent == RT_NULL) - if (top->list.next != &_rtgui_topwin_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)); - 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)); - /* level up */ - else - top = top->parent; - } + /* move to next sibling tree */ + if (top->parent == RT_NULL) + if (top->list.next != &_rtgui_topwin_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)); + 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)); + /* level up */ + else + top = top->parent; + } } static void _rtgui_topwin_redraw_tree(struct rtgui_dlist_node *list, - struct rtgui_rect* rect, - struct rtgui_event_paint *epaint) + struct rtgui_rect *rect, + struct rtgui_event_paint *epaint) { - struct rtgui_dlist_node *node; + struct rtgui_dlist_node *node; - RT_ASSERT(list != RT_NULL); - RT_ASSERT(rect != RT_NULL); - RT_ASSERT(epaint != RT_NULL); + RT_ASSERT(list != RT_NULL); + RT_ASSERT(rect != RT_NULL); + RT_ASSERT(epaint != RT_NULL); - /* skip the hidden windows */ - rtgui_dlist_foreach(node, list, prev) - { - if (get_topwin_from_list(node)->flag & WINTITLE_SHOWN) - break; - } + /* skip the hidden windows */ + rtgui_dlist_foreach(node, list, prev) + { + if (get_topwin_from_list(node)->flag & WINTITLE_SHOWN) + break; + } - for (; node != list; node = node->prev) - { - struct rtgui_topwin *topwin; + for (; node != list; node = node->prev) + { + struct rtgui_topwin *topwin; - topwin = get_topwin_from_list(node); + topwin = get_topwin_from_list(node); - //FIXME: intersect with clip? - if (rtgui_rect_is_intersect(rect, &(topwin->extent)) == RT_EOK) - { - epaint->wid = topwin->wid; - rtgui_send(topwin->tid, &(epaint->parent), sizeof(*epaint)); + //FIXME: intersect with clip? + if (rtgui_rect_is_intersect(rect, &(topwin->extent)) == RT_EOK) + { + epaint->wid = topwin->wid; + rtgui_send(topwin->tid, &(epaint->parent), sizeof(*epaint)); - /* draw title */ - if (topwin->title != RT_NULL) - { - rtgui_theme_draw_win(topwin); - } - } + /* draw title */ + if (topwin->title != RT_NULL) + { + rtgui_theme_draw_win(topwin); + } + } - _rtgui_topwin_redraw_tree(&topwin->child_list, rect, epaint); - } + _rtgui_topwin_redraw_tree(&topwin->child_list, rect, epaint); + } } -static void rtgui_topwin_redraw(struct rtgui_rect* rect) +static void rtgui_topwin_redraw(struct rtgui_rect *rect) { - struct rtgui_event_paint epaint; - RTGUI_EVENT_PAINT_INIT(&epaint); - epaint.wid = RT_NULL; + struct rtgui_event_paint epaint; + RTGUI_EVENT_PAINT_INIT(&epaint); + epaint.wid = RT_NULL; - _rtgui_topwin_redraw_tree(&_rtgui_topwin_list, rect, &epaint); + _rtgui_topwin_redraw_tree(&_rtgui_topwin_list, rect, &epaint); } /* a window enter modal mode will modal all the sibling window and parent * window all along to the root window(which parent is RT_NULL or the desktop * window if there is). If a root window modals, there is nothing to do here.*/ -rt_err_t rtgui_topwin_modal_enter(struct rtgui_event_win_modal_enter* event) +rt_err_t rtgui_topwin_modal_enter(struct rtgui_event_win_modal_enter *event) { - struct rtgui_topwin *topwin, *parent_top; - struct rtgui_dlist_node *node; + struct rtgui_topwin *topwin, *parent_top; + struct rtgui_dlist_node *node; - topwin = rtgui_topwin_search_in_list(event->wid, &_rtgui_topwin_list); + topwin = rtgui_topwin_search_in_list(event->wid, &_rtgui_topwin_list); - if (topwin == RT_NULL) - return -RT_ERROR; + if (topwin == RT_NULL) + return -RT_ERROR; - if (IS_ROOT_WIN(topwin)) - return RT_EOK; + if (IS_ROOT_WIN(topwin)) + return RT_EOK; - parent_top = topwin->parent; + parent_top = topwin->parent; - /* modal window should be on top already */ - RT_ASSERT(get_topwin_from_list(parent_top->child_list.next) == topwin); + /* modal window should be on top already */ + RT_ASSERT(get_topwin_from_list(parent_top->child_list.next) == topwin); - while (!IS_ROOT_WIN(parent_top)) - { - rtgui_dlist_foreach(node, &parent_top->child_list, next) - get_topwin_from_list(node)->flag |= WINTITLE_MODALED; - parent_top->flag |= WINTITLE_MODALED; + while (!IS_ROOT_WIN(parent_top)) + { + rtgui_dlist_foreach(node, &parent_top->child_list, next) + get_topwin_from_list(node)->flag |= WINTITLE_MODALED; + parent_top->flag |= WINTITLE_MODALED; - parent_top = parent_top->parent; - } - /* mark root window as modaled */ - parent_top->flag |= WINTITLE_MODALED; + parent_top = parent_top->parent; + } + /* mark root window as modaled */ + parent_top->flag |= WINTITLE_MODALED; - topwin->flag &= ~WINTITLE_MODALED; - topwin->flag |= WINTITLE_MODALING; + topwin->flag &= ~WINTITLE_MODALED; + topwin->flag |= WINTITLE_MODALING; - return RT_EOK; + return RT_EOK; } -void rtgui_topwin_title_onmouse(struct rtgui_topwin* win, struct rtgui_event_mouse* event) +void rtgui_topwin_title_onmouse(struct rtgui_topwin *win, struct rtgui_event_mouse *event) { - rtgui_rect_t rect; + 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_send(win->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); - return; - } + /* 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_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; + /* 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); - } + 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); + } #ifdef RTGUI_USING_WINMOVE - else - { - /* maybe move window */ - rtgui_winrect_set(win); - } + else + { + /* maybe move window */ + rtgui_winrect_set(win); + } #endif - } - else if (win->flag & WINTITLE_CB_PRESSED && event->button & RTGUI_MOUSE_BUTTON_UP) - { - if (rtgui_rect_contains_point(&rect, event->x, event->y) == RT_EOK) - { - struct rtgui_event_win event; + } + else if (win->flag & WINTITLE_CB_PRESSED && 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); + 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_send(win->tid, &(event.parent), sizeof(struct rtgui_event_win)); - } - } - } + /* send close event to window */ + RTGUI_EVENT_WIN_CLOSE_INIT(&event); + event.wid = win->wid; + rtgui_send(win->tid, &(event.parent), sizeof(struct rtgui_event_win)); + } + } + } } -void rtgui_topwin_append_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect) +void rtgui_topwin_append_monitor_rect(struct rtgui_win *wid, rtgui_rect_t *rect) { - struct rtgui_topwin* win; + struct rtgui_topwin *win; - /* parameters check */ - if (wid == RT_NULL || rect == RT_NULL) return; + /* parameters check */ + if (wid == RT_NULL || rect == RT_NULL) return; - /* find topwin */ - win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_list); - if (win == RT_NULL) - return; + /* find topwin */ + win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_list); + if (win == RT_NULL) + return; - /* append rect to top window monitor rect list */ - rtgui_mouse_monitor_append(&(win->monitor_list), rect); + /* 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) +void rtgui_topwin_remove_monitor_rect(struct rtgui_win *wid, rtgui_rect_t *rect) { - struct rtgui_topwin* win; + struct rtgui_topwin *win; - /* parameters check */ - if (wid == RT_NULL || rect == RT_NULL) - return; + /* parameters check */ + if (wid == RT_NULL || rect == RT_NULL) + return; - /* find topwin */ - win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_list); - if (win == RT_NULL) - return; + /* find topwin */ + win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_list); + if (win == RT_NULL) + return; - /* remove rect from top window monitor rect list */ - rtgui_mouse_monitor_remove(&(win->monitor_list), rect); + /* remove rect from top window monitor rect list */ + rtgui_mouse_monitor_remove(&(win->monitor_list), rect); } static void _rtgui_topwin_dump(struct rtgui_topwin *topwin) { - rt_kprintf("0x%p:%s,0x%x", topwin, topwin->wid->title, topwin->flag); + rt_kprintf("0x%p:%s,0x%x", topwin, topwin->wid->title, topwin->flag); } static void _rtgui_topwin_dump_tree(struct rtgui_topwin *topwin) { - struct rtgui_dlist_node *node; + struct rtgui_dlist_node *node; - _rtgui_topwin_dump(topwin); + _rtgui_topwin_dump(topwin); - rt_kprintf("("); - rtgui_dlist_foreach(node, &topwin->child_list, next) - { - _rtgui_topwin_dump_tree(get_topwin_from_list(node)); - } - rt_kprintf(")"); + rt_kprintf("("); + rtgui_dlist_foreach(node, &topwin->child_list, next) + { + _rtgui_topwin_dump_tree(get_topwin_from_list(node)); + } + rt_kprintf(")"); } void rtgui_topwin_dump_tree(void) { - struct rtgui_dlist_node *node; + struct rtgui_dlist_node *node; - rtgui_dlist_foreach(node, &_rtgui_topwin_list, next) - { - _rtgui_topwin_dump_tree(get_topwin_from_list(node)); - rt_kprintf("\n"); - } + rtgui_dlist_foreach(node, &_rtgui_topwin_list, next) + { + _rtgui_topwin_dump_tree(get_topwin_from_list(node)); + rt_kprintf("\n"); + } } #ifdef RT_USING_FINSH #include <finsh.h> void dump_tree() { - rtgui_topwin_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 59b8f30e79..45f41f34e9 100644 --- a/components/rtgui/server/topwin.h +++ b/components/rtgui/server/topwin.h @@ -21,37 +21,37 @@ #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); -rt_err_t rtgui_topwin_activate(struct rtgui_event_win_activate* event); -rt_err_t rtgui_topwin_activate_topwin(struct rtgui_topwin* win); +rt_err_t rtgui_topwin_add(struct rtgui_event_win_create *event); +rt_err_t rtgui_topwin_remove(struct rtgui_win *wid); +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); +rt_err_t rtgui_topwin_show(struct rtgui_event_win *event); /* hide a window */ -rt_err_t rtgui_topwin_hide(struct rtgui_event_win* event); +rt_err_t rtgui_topwin_hide(struct rtgui_event_win *event); /* move a window */ -rt_err_t rtgui_topwin_move(struct rtgui_event_win_move* event); +rt_err_t rtgui_topwin_move(struct rtgui_event_win_move *event); /* resize a window */ -void rtgui_topwin_resize(struct rtgui_win* wid, rtgui_rect_t* r); +void rtgui_topwin_resize(struct rtgui_win *wid, rtgui_rect_t *r); /* a window is entering modal mode */ -rt_err_t rtgui_topwin_modal_enter(struct rtgui_event_win_modal_enter* event); +rt_err_t rtgui_topwin_modal_enter(struct rtgui_event_win_modal_enter *event); /* get window at (x, y) */ -struct rtgui_topwin* rtgui_topwin_get_wnd(int x, int y); -struct rtgui_topwin* rtgui_topwin_get_wnd_no_modaled(int x, int y); +struct rtgui_topwin *rtgui_topwin_get_wnd(int x, int y); +struct rtgui_topwin *rtgui_topwin_get_wnd_no_modaled(int x, int y); //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); +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_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); /* get the topwin that is currently focused */ -struct rtgui_topwin* rtgui_topwin_get_focus(void); +struct rtgui_topwin *rtgui_topwin_get_focus(void); #endif |
