From 010cec20096bfdc77538071f5e1a14a5fb1c422c Mon Sep 17 00:00:00 2001 From: "bernard.xiong" Date: Mon, 23 Nov 2009 23:34:58 +0000 Subject: [PATCH] add radio player UI git-svn-id: https://rt-thread.googlecode.com/svn/trunk@171 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- bsp/stm32_radio/application.c | 77 +- bsp/stm32_radio/device_info.c | 239 ++++ bsp/stm32_radio/dm9000.c | 2 +- bsp/stm32_radio/filelist.c | 630 +++++++- bsp/stm32_radio/filelist.h | 33 +- bsp/stm32_radio/fnmatch.c | 139 -- bsp/stm32_radio/fnmatch.h | 21 - bsp/stm32_radio/info.c | 17 +- bsp/stm32_radio/key.c | 23 +- bsp/stm32_radio/lcd.c | 57 +- bsp/stm32_radio/listview.c | 245 ++++ bsp/stm32_radio/listview.h | 53 + bsp/stm32_radio/player.c | 185 +++ bsp/stm32_radio/project.Opt | 347 ++--- bsp/stm32_radio/project.Uv2 | 99 +- bsp/stm32_radio/rtconfig.h | 7 +- bsp/stm32_radio/sdcard.c | 2 +- bsp/stm32_radio/startup.c | 7 - bsp/stm32_radio/wav.c | 1 + net/lwip/src/arch/sys_arch_init.c | 11 +- rtgui/common/asc16font.c | 4 +- rtgui/common/dc.c | 6 +- rtgui/common/dc_buffer.c | 2 +- rtgui/common/dc_hw.c | 2 +- rtgui/common/filerw.c | 46 +- rtgui/common/font_hz_file.c | 6 +- rtgui/common/hz12font.c | 18 +- rtgui/common/hz16font.c | 8 +- rtgui/common/image.c | 8 +- rtgui/common/image_hdc.c | 166 +-- rtgui/common/image_png.c | 4 +- rtgui/common/image_xpm.c | 2 +- rtgui/common/rtgui_object.c | 2 +- rtgui/common/rtgui_system.c | 5 +- rtgui/common/rtgui_theme.c | 950 ++++++------ rtgui/include/rtgui/color.h | 10 +- rtgui/include/rtgui/event.h | 8 +- rtgui/include/rtgui/image_png.h | 2 + rtgui/include/rtgui/rtgui.h | 9 +- rtgui/include/rtgui/rtgui_config.h | 15 +- rtgui/include/rtgui/rtgui_object.h | 1 - rtgui/include/rtgui/rtgui_system.h | 3 - rtgui/include/rtgui/rtgui_theme.h | 5 + rtgui/include/rtgui/widgets/container.h | 1 + rtgui/include/rtgui/widgets/toplevel.h | 6 - rtgui/include/rtgui/widgets/view.h | 3 +- rtgui/include/rtgui/widgets/window.h | 31 +- rtgui/include/rtgui/widgets/workbench.h | 11 +- rtgui/server/driver.c | 134 +- rtgui/server/panel.c | 612 ++++---- rtgui/server/panel.h | 136 +- rtgui/server/server.c | 1244 ++++++++-------- rtgui/server/topwin.c | 1746 +++++++++++------------ rtgui/server/topwin.h | 112 +- rtgui/widgets/box.c | 680 ++++----- rtgui/widgets/button.c | 374 ++--- rtgui/widgets/container.c | 570 ++++---- rtgui/widgets/iconbox.c | 334 ++--- rtgui/widgets/label.c | 226 +-- rtgui/widgets/textbox.c | 698 ++++----- rtgui/widgets/title.c | 162 +-- rtgui/widgets/toplevel.c | 372 +++-- rtgui/widgets/view.c | 353 ++--- rtgui/widgets/widget.c | 66 +- rtgui/widgets/window.c | 1026 +++++++------ rtgui/widgets/workbench.c | 38 +- 66 files changed, 6838 insertions(+), 5574 deletions(-) create mode 100644 bsp/stm32_radio/device_info.c delete mode 100644 bsp/stm32_radio/fnmatch.c delete mode 100644 bsp/stm32_radio/fnmatch.h create mode 100644 bsp/stm32_radio/listview.c create mode 100644 bsp/stm32_radio/listview.h create mode 100644 bsp/stm32_radio/player.c diff --git a/bsp/stm32_radio/application.c b/bsp/stm32_radio/application.c index d5735e4ac..5d6b4a735 100644 --- a/bsp/stm32_radio/application.c +++ b/bsp/stm32_radio/application.c @@ -42,10 +42,31 @@ #endif #ifdef RT_USING_RTGUI -#include -#include +extern void radio_rtgui_init(void); #endif +void sram_test_entry(void* parameter) +{ + rt_uint32_t *ptr; + rt_uint32_t index; + + ptr = (rt_uint32_t*)STM32_EXT_SRAM_BEGIN; + index = 0; + while (1) + { + *ptr = index; + ptr ++; index ++; + + if (ptr == (rt_uint32_t*)STM32_EXT_SRAM_END) + { + ptr = (rt_uint32_t*)STM32_EXT_SRAM_BEGIN; + rt_kprintf("test passed\n"); + + rt_thread_delay(50); + } + } +} + /* thread phase init */ void rt_init_thread_entry(void *parameter) { @@ -76,11 +97,27 @@ void rt_init_thread_entry(void *parameter) } #endif + /* RTGUI Initialization */ +#ifdef RT_USING_RTGUI + { + radio_rtgui_init(); + rt_hw_key_init(); + } +#endif + /* LwIP Initialization */ #ifdef RT_USING_LWIP { extern void lwip_sys_init(void); - +#ifdef RT_USING_LWIP + eth_system_device_init(); + + /* register ethernetif device */ + rt_hw_dm9000_init(); + /* init all device */ + rt_device_init_all(); +#endif + /* init lwip system */ lwip_sys_init(); rt_kprintf("TCP/IP initialized!\n"); @@ -92,32 +129,14 @@ void rt_init_thread_entry(void *parameter) net_buf_init(320 * 1024); #endif - /* RTGUI Initialization */ -#ifdef RT_USING_RTGUI +#if 0 { - rtgui_rect_t rect; - - rtgui_system_server_init(); - - /* register dock panel */ - rect.x1 = 0; - rect.y1 = 0; - rect.x2 = 240; - rect.y2 = 25; - - rtgui_panel_register("info", &rect); - - /* register main panel */ - rect.x1 = 0; - rect.y1 = 25; - rect.x2 = 240; - rect.y2 = 320; - rtgui_panel_register("main", &rect); - - rt_hw_lcd_init(); - - info_init(); - today_init(); + rt_thread_t tid; + + tid = rt_thread_create("sram", + sram_test_entry, RT_NULL, + 512, 30, 5); + if (tid != RT_NULL) rt_thread_startup(tid); } #endif } @@ -139,8 +158,6 @@ int rt_application_init() #endif if (init_thread != RT_NULL) rt_thread_startup(init_thread); - rt_hw_key_init(); - return 0; } diff --git a/bsp/stm32_radio/device_info.c b/bsp/stm32_radio/device_info.c new file mode 100644 index 000000000..c32d59430 --- /dev/null +++ b/bsp/stm32_radio/device_info.c @@ -0,0 +1,239 @@ +#include +#include +#include +#include + +#include +#include + +#include + +#ifdef RT_USING_LWIP +#include +#include +#include +#endif + +static struct rtgui_view* device_view = RT_NULL; + +int get_thread_cnt() +{ + int cnt = 0; + struct rt_list_node *list, *node; + extern struct rt_object_information rt_object_container[]; + + list = &rt_object_container[RT_Object_Class_Thread].object_list; + + for (node = list->next; node != list; node = node->next) + { + cnt ++; + } + + return cnt; +} + +const static char *stm32_devname[] = +{ + "STM32 MD", /* 0x410 */ + "STM32 LD", /* 0x412 */ + "STM32 HD", /* 0x414 */ + "Unknown" , /* 0x416 */ + "STM32 CL", /* 0x418 */ +}; + +const static char *stm32_revname[] = +{ + "Rev A", + "Rev B", + "Rev Z", + "Rev Y", + "Rev Unknown" +}; + +/* + * Device Information View + * Device: Win32 or Cortex-M3 etc + * Memory: + * Thread: + * IP Address: + * Gateway: + * DNS: + */ +static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) +{ + switch (event->type) + { + case RTGUI_EVENT_PAINT: + { + struct rtgui_dc* dc; + struct rtgui_rect rect; + char* line; + rt_uint32_t total, used, max_used; + + line = rtgui_malloc(256); + if (line == RT_NULL) return RT_FALSE; + + dc = rtgui_dc_begin_drawing(widget); + if (dc == RT_NULL) + { + rtgui_free(line); + return RT_FALSE; + } + rtgui_widget_get_rect(widget, &rect); + + /* fill background */ + rtgui_dc_fill_rect(dc, &rect); + + rect.y2 = rect.y1 + 18; + + { + rt_uint32_t dev_index, rev_index; + + dev_index = DBGMCU_GetDEVID(); + dev_index = (dev_index - 0x410)/2; + rev_index = DBGMCU_GetREVID(); + switch (rev_index) + { + case 0x1000: + case 0x0000: + rev_index = 0; /* Revision A */ + break; + + case 0x1001: + case 0x2001: + rev_index = 3; /* Revision Z */ + break; + + case 0x2000: + rev_index = 1; /* Revision B */ + break; + case 0x2002: + rev_index = 2; /* Revision Y */ + break; + + default: + rev_index = 4; /* Unknown */ + break; + }; + + /* check device index */ + if (dev_index < 0 || dev_index > 4) dev_index = 3; + + /* draw each information */ + sprintf(line, "设备: %s %s", + stm32_devname[dev_index], + stm32_revname[rev_index]); + rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; + } + + rt_memory_info(&total, &used, &max_used); + sprintf(line, "内存: 当前使用 %d 字节", used); + rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; + { + rt_uint16_t rect_width; + rtgui_color_t saved; + + rtgui_rect_t mem_rect = rect; + rtgui_rect_inflate(&mem_rect, -2); + rtgui_dc_draw_rect(dc, &mem_rect); + + rtgui_rect_inflate(&mem_rect, -1); + rect_width = rtgui_rect_width(mem_rect); + + saved = RTGUI_WIDGET_BACKGROUND(widget); + + RTGUI_WIDGET_BACKGROUND(widget) = light_grey; + mem_rect.x2 = mem_rect.x1 + (max_used * rect_width / total); + rtgui_dc_fill_rect(dc, &mem_rect); + + RTGUI_WIDGET_BACKGROUND(widget) = blue; + mem_rect.x2 = mem_rect.x1 + (used * rect_width / total); + rtgui_dc_fill_rect(dc, &mem_rect); + + /* restore color */ + RTGUI_WIDGET_BACKGROUND(widget) = saved; + } + rect.y1 += 18; rect.y2 += 18; + + sprintf(line, "线程数: %d", get_thread_cnt()); + rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; + +#ifdef RT_USING_LWIP + { + struct ip_addr ip_addr; + struct _ip_addr + { + rt_uint8_t addr0, addr1, addr2, addr3; + } *addr; + + addr = (struct _ip_addr*)&netif_default->ip_addr.addr; + + sprintf(line, "IP地址 : %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); + rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; + + addr = (struct _ip_addr*)&netif_default->gw.addr; + sprintf(line, "网关地址: %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); + rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; + + addr = (struct _ip_addr*)&netif_default->netmask.addr; + sprintf(line, "网络掩码: %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); + rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; + +#if LWIP_DNS + ip_addr = dns_getserver(0); + addr = (struct _ip_addr*)&ip_addr; + sprintf(line, "DNS地址 : %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); + rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; +#endif + } +#endif + + rtgui_dc_end_drawing(dc); + rtgui_free(line); + return RT_FALSE; + } + + case RTGUI_EVENT_KBD: + { + struct rtgui_event_kbd* ekbd; + + ekbd = (struct rtgui_event_kbd*)event; + if (ekbd->type == RTGUI_KEYDOWN && ekbd->key == RTGUIK_RETURN) + { + rtgui_workbench_t* workbench; + + workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(device_view)->parent); + rtgui_workbench_remove_view(workbench, device_view); + + rtgui_view_destroy(device_view); + device_view = RT_NULL; + } + } + return RT_FALSE; + } + + /* use parent event handler */ + return rtgui_view_event_handler(widget, event); +} + +rtgui_view_t *device_view_create(rtgui_workbench_t* workbench) +{ + if (device_view != RT_NULL) + { + rtgui_view_show(device_view, RT_FALSE); + } + else + { + /* create a view */ + device_view = rtgui_view_create("Device Info"); + /* set view event handler */ + rtgui_widget_set_event_handler(RTGUI_WIDGET(device_view), view_event_handler); + /* this view can be focused */ + RTGUI_WIDGET(device_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; + + /* add view to workbench */ + rtgui_workbench_add_view(workbench, device_view); + } + + return device_view; +} diff --git a/bsp/stm32_radio/dm9000.c b/bsp/stm32_radio/dm9000.c index 44ddfb5e5..598e44b35 100644 --- a/bsp/stm32_radio/dm9000.c +++ b/bsp/stm32_radio/dm9000.c @@ -276,7 +276,7 @@ static rt_err_t rt_dm9000_init(rt_device_t dev) while (!(phy_read(1) & 0x20)) { /* autonegation complete bit */ - delay_ms(10); + rt_thread_delay(10); i++; if (i == 10000) { diff --git a/bsp/stm32_radio/filelist.c b/bsp/stm32_radio/filelist.c index 4e39fe48a..6836475b7 100644 --- a/bsp/stm32_radio/filelist.c +++ b/bsp/stm32_radio/filelist.c @@ -1,13 +1,209 @@ #include #include +#include #include +#include #include +#include + +#include "filelist.h" +#include +#include + +#define FILELIST_MARGIN 5 +#ifdef _WIN32 +#define PATH_SEPARATOR '\\' +#define stat _stat +#else +#define PATH_SEPARATOR '/' +#endif + +const static char * file_xpm[] = { +"16 16 21 1", +" c None", +". c #999999", +"+ c #818181", +"@ c #FFFFFF", +"# c #ECECEC", +"$ c #EAEAEA", +"% c #EBEBEB", +"& c #EDEDED", +"* c #F0F0F0", +"= c #C4C4C4", +"- c #C5C5C5", +"; c #C6C6C6", +"> c #C7C7C7", +", c #EEEEEE", +"' c #EDEDE5", +") c #EDEDE6", +"! c #EFEFEF", +"~ c #C8C8C8", +"{ c #F1F1F1", +"] c #F2F2F2", +"^ c #959595", +".++++++++++++ ", +"+@@@@@@@@@@@@+ ", +"+@#$$%%%##&*@+ ", +"+@$=--;;;;>*@+ ", +"+@$%%###&&,*@+ ", +"+@%-;;;;;;>*@+ ", +"+@%%##&&'#,*@+ ", +"+@%;;;;,,),*@+ ", +"+@##&&,,!!!*@+ ", +"+@#;;;>>~~~*@+ ", +"+@#&,,!!*{{{@+ ", +"+@&;>>~~~{{]@+ ", +"+@&&,!!**{]]@+ ", +"+@@@@@@@@@@@@+ ", +"^++++++++++++^ ", +" "}; + +const static char * folder_xpm[] = { +"16 16 121 2", +" c None", +". c #D9B434", +"+ c #E1C25E", +"@ c #E2C360", +"# c #E2C35F", +"$ c #DBB63C", +"% c #DAB336", +"& c #FEFEFD", +"* c #FFFFFE", +"= c #FFFEFE", +"- c #FFFEFD", +"; c #FBF7EA", +"> c #E4C76B", +", c #E3C76B", +"' c #E6CD79", +") c #E5CA74", +"! c #DAAF35", +"~ c #FEFCF7", +"{ c #F8E48E", +"] c #F5DE91", +"^ c #F5E09F", +"/ c #F6E1AC", +"( c #FEFBEF", +"_ c #FEFDF4", +": c #FEFCF3", +"< c #FEFCF1", +"[ c #FEFBEE", +"} c #FFFDFA", +"| c #DAAF36", +"1 c #DAAA36", +"2 c #FDFAF1", +"3 c #F5DE94", +"4 c #F4DC93", +"5 c #F2D581", +"6 c #EDCA6A", +"7 c #EACB6C", +"8 c #EFD385", +"9 c #EFD280", +"0 c #EFD07A", +"a c #EECF76", +"b c #EECF72", +"c c #FBF7E9", +"d c #DAAE34", +"e c #DAAB35", +"f c #FBF6E8", +"g c #EFD494", +"h c #EECE88", +"i c #E9C173", +"j c #F6E9C9", +"k c #FEFCF2", +"l c #FEFCF0", +"m c #DAAB36", +"n c #DAA637", +"o c #FFFDF8", +"p c #FFFDF6", +"q c #FFFCF5", +"r c #FCF6D8", +"s c #F8E694", +"t c #F7E385", +"u c #F6DF76", +"v c #F5DB68", +"w c #F4D85C", +"x c #FCF4D7", +"y c #DAA435", +"z c #DAA136", +"A c #FEFCF6", +"B c #FCF2C8", +"C c #FBEFB9", +"D c #FAECAC", +"E c #F9E89C", +"F c #F7E38B", +"G c #F6E07C", +"H c #F6DC6C", +"I c #F5D95D", +"J c #F4D64F", +"K c #F3D344", +"L c #FCF3D0", +"M c #DA9F35", +"N c #DA9A36", +"O c #FDFAF2", +"P c #FAEDB3", +"Q c #F9E9A4", +"R c #F8E695", +"S c #F7E285", +"T c #F6DE76", +"U c #F5DB65", +"V c #F4D757", +"W c #F3D449", +"X c #F2D13B", +"Y c #F1CE30", +"Z c #FBF2CC", +"` c #DA9835", +" . c #DA9435", +".. c #FEFAEF", +"+. c #F9E9A1", +"@. c #F8E591", +"#. c #F7E181", +"$. c #F6DE72", +"%. c #F5DA63", +"&. c #F4D754", +"*. c #F3D347", +"=. c #F2D039", +"-. c #F1CD2E", +";. c #F0CB26", +">. c #FBF2CA", +",. c #D98E33", +"'. c #FAF0DC", +"). c #F4DDA7", +"!. c #F4DB9E", +"~. c #F3DA96", +"{. c #F3D88E", +"]. c #F3D786", +"^. c #F2D47F", +"/. c #F2D379", +"(. c #F1D272", +"_. c #F1D06C", +":. c #F1CF69", +"<. c #F8EAC2", +"[. c #D8882D", +"}. c #D8872D", +"|. c #D8862C", +" ", +" ", +" ", +" . + @ @ @ # $ ", +" % & * = - * ; > , , , ' ) ", +" ! ~ { ] ^ / ( _ : < ( [ } | ", +" 1 2 3 4 5 6 7 8 9 0 a b c d ", +" e f g h i j k : k l ( [ * m ", +" n * o p q : r s t u v w x y ", +" z A B C D E F G H I J K L M ", +" N O P Q R S T U V W X Y Z ` ", +" ...+.@.#.$.%.&.*.=.-.;.>. . ", +" ,.'.).!.~.{.].^./.(._.:.<.,. ", +" [.}.[.[.[.[.[.[.[.[.}.[.|. ", +" ", +" "}; /* image for file and folder */ -rtgui_image_t *file_image, *folder_image; +static rtgui_image_t *file_image, *folder_image; +static struct filelist_view *filelist_view = RT_NULL; /* only one view in global */ -static void _filelist_view_constructor(filelist_view *view) +static void _filelist_view_constructor(struct filelist_view *view) { /* default rect */ struct rtgui_rect rect = {0, 0, 200, 200}; @@ -16,12 +212,21 @@ static void _filelist_view_constructor(filelist_view *view) rtgui_widget_set_event_handler(RTGUI_WIDGET(view),filelist_view_event_handler); rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect); - RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(list)) = RTGUI_RGB(212, 208, 200); + RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; + + view->current_item = 0; + view->items_count = 0; + view->page_items = 0; - view->count = 0; view->current_directory = RT_NULL; view->pattern = RT_NULL; - rtgui_list_init(&view->list); + RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white; + RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(view)) = RTGUI_ALIGN_CENTER_VERTICAL; + + file_image = rtgui_image_create_from_mem("xpm", + (rt_uint8_t*)file_xpm, sizeof(file_xpm)); + folder_image = rtgui_image_create_from_mem("xpm", + (rt_uint8_t*)folder_xpm, sizeof(folder_xpm)); } rtgui_type_t *filelist_view_type_get(void) @@ -37,19 +242,158 @@ rtgui_type_t *filelist_view_type_get(void) return filelist_view_type; } +void filelist_view_ondraw(struct filelist_view* view) +{ + struct rtgui_rect rect, item_rect, image_rect; + struct rtgui_dc* dc; + rt_uint16_t page_index, index; + struct file_item* item; + + dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view)); + if (dc == RT_NULL) return; + + rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); + rtgui_dc_fill_rect(dc, &rect); + + /* get item base rect */ + item_rect = rect; + item_rect.y1 += 1; + item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height()); + + /* get image base rect */ + image_rect.x1 = FILELIST_MARGIN; image_rect.y1 = 0; + image_rect.x2 = FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h; + rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL); + + /* get current page */ + page_index = (view->current_item / view->page_items) * view->page_items; + for (index = 0; index < view->page_items; index ++) + { + if (page_index + index >= view->items_count) break; + + item = &(view->items[page_index + index]); + + if (page_index + index == view->current_item) + { + rtgui_theme_draw_selected(dc, &item_rect); + } + else + { + /* draw background */ + rtgui_dc_fill_rect(dc, &item_rect); + } + + /* draw item */ + + if (item->type == FITEM_FILE) + rtgui_image_blit(file_image, dc, &image_rect); + else + rtgui_image_blit(folder_image, dc, &image_rect); + + /* draw text */ + item_rect.x1 += FILELIST_MARGIN + file_image->w + 2; + rtgui_dc_draw_text(dc, item->name, &item_rect); + item_rect.x1 -= FILELIST_MARGIN + file_image->w + 2; + + /* move to next item position */ + item_rect.y1 += (rtgui_theme_get_selected_height() + 1); + item_rect.y2 += (rtgui_theme_get_selected_height() + 1); + + image_rect.y1 += (rtgui_theme_get_selected_height() + 1); + image_rect.y2 += (rtgui_theme_get_selected_height() + 1); + } + + rtgui_dc_end_drawing(dc); +} + +void filelist_view_update_current(struct filelist_view* view, rt_uint16_t old_item) +{ + struct rtgui_dc* dc; + struct file_item* item; + rtgui_rect_t rect, item_rect, image_rect; + + if (old_item/view->page_items != view->current_item/view->page_items) + { + /* it's not a same page, update all */ + rtgui_widget_update(RTGUI_WIDGET(view)); + return; + } + + dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view)); + if (dc == RT_NULL) return; + + rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); + + /* get old item rect */ + item_rect = rect; + item_rect.y1 += 1; + item_rect.y1 += (old_item % view->page_items) * (1 + rtgui_theme_get_selected_height()); + item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height()); + + /* get image rect */ + image_rect.x1 = FILELIST_MARGIN; image_rect.y1 = 0; + image_rect.x2 = FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h; + rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL); + + /* draw old item */ + rtgui_dc_fill_rect(dc, &item_rect); + + item = &(view->items[old_item]); + if (item->type == FITEM_FILE) /* draw item image */ + rtgui_image_blit(file_image, dc, &image_rect); + else + rtgui_image_blit(folder_image, dc, &image_rect); + + item_rect.x1 += FILELIST_MARGIN + file_image->w + 2; + rtgui_dc_draw_text(dc, item->name, &item_rect); + + /* draw current item */ + item_rect = rect; + item_rect.y1 += 1; + item_rect.y1 += (view->current_item % view->page_items) * (1 + rtgui_theme_get_selected_height()); + item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height()); + + rtgui_theme_draw_selected(dc, &item_rect); + + /* get image base rect */ + image_rect.x1 = FILELIST_MARGIN; image_rect.y1 = 0; + image_rect.x2 = FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h; + rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL); + + item = &(view->items[view->current_item]); + if (item->type == FITEM_FILE) /* draw item image */ + rtgui_image_blit(file_image, dc, &image_rect); + else + rtgui_image_blit(folder_image, dc, &image_rect); + + item_rect.x1 += FILELIST_MARGIN + file_image->w + 2; + rtgui_dc_draw_text(dc, item->name, &item_rect); + + rtgui_dc_end_drawing(dc); +} + rt_bool_t filelist_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { struct filelist_view* view = RT_NULL; view = FILELIST_VIEW(widget); - switch (event.type) + switch (event->type) { case RTGUI_EVENT_PAINT: - break; + filelist_view_ondraw(view); + return RT_FALSE; case RTGUI_EVENT_RESIZE: { + struct rtgui_event_resize* resize; + + resize = (struct rtgui_event_resize*)event; + /* recalculate page items */ + if (file_image != RT_NULL) + view->page_items = resize->h / (1 + rtgui_theme_get_selected_height()); + else + view->page_items = resize->h / (2 + 14); } break; @@ -58,44 +402,154 @@ rt_bool_t filelist_view_event_handler(struct rtgui_widget* widget, struct rtgui_ struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event; if (ekbd->type == RTGUI_KEYDOWN) { + rt_uint16_t old_item; + + old_item = view->current_item; switch (ekbd->key) { case RTGUIK_UP: - break; + if (view->current_item > 0) + view->current_item --; + filelist_view_update_current(view, old_item); + return RT_FALSE; case RTGUIK_DOWN: - break; + if (view->current_item < view->items_count - 1) + view->current_item ++; + filelist_view_update_current(view, old_item); + return RT_FALSE; + + case RTGUIK_LEFT: + if (view->current_item - view->page_items >= 0) + view->current_item -= view->page_items; + filelist_view_update_current(view, old_item); + return RT_FALSE; + + case RTGUIK_RIGHT: + if (view->current_item + view->page_items < view->items_count - 1) + view->current_item += view->page_items; + filelist_view_update_current(view, old_item); + return RT_FALSE; + + case RTGUIK_RETURN: + if (view->items[view->current_item].type == FITEM_DIR) + { + char new_path[64]; + + if (strcmp(view->items[view->current_item].name, ".") == 0) return RT_FALSE; + if (strcmp(view->items[view->current_item].name, "..") == 0) + { + char *ptr; + ptr = strrchr(view->current_directory, PATH_SEPARATOR); + + if (ptr == RT_NULL) return RT_FALSE; + if (ptr == &(view->current_directory[0])) + { + /* it's root directory */ + new_path[0] = PATH_SEPARATOR; + new_path[1] = '\0'; + } + else + { + strncpy(new_path, view->current_directory, ptr - view->current_directory + 1); + new_path[ptr - view->current_directory] = '\0'; + } + rt_kprintf("new path: %s\n", new_path); + } + else if (view->current_item == 0 && + (view->current_directory[0] == '/') && (view->current_directory[1] == '\0')) + { + /* exit, close this view */ + rtgui_workbench_t* workbench; + + workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent); + rtgui_workbench_remove_view(workbench, RTGUI_VIEW(view)); + filelist_view_destroy(view); + + filelist_view = RT_NULL; + return RT_FALSE; + } + else + { + if (view->current_directory[strlen(view->current_directory) - 1] != PATH_SEPARATOR) + sprintf(new_path, "%s%c%s",view->current_directory, PATH_SEPARATOR, + view->items[view->current_item].name); + else + sprintf(new_path, "%s%s",view->current_directory, + view->items[view->current_item].name); + } + filelist_view_set_directory(view, new_path); + } + else + { + if (strstr(view->items[view->current_item].name, ".HDC") != RT_NULL || + strstr(view->items[view->current_item].name, ".hdc") != RT_NULL) + { + char new_path[64]; + rtgui_workbench_t* workbench; + + workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent); + + if (view->current_directory[strlen(view->current_directory) - 1] != PATH_SEPARATOR) + sprintf(new_path, "%s%c%s",view->current_directory, PATH_SEPARATOR, + view->items[view->current_item].name); + else + sprintf(new_path, "%s%s",view->current_directory, + view->items[view->current_item].name); + } + } + return RT_FALSE; default: break; } } } - break; + return RT_FALSE; } /* use view event handler */ return rtgui_view_event_handler(widget, event); } -filelist_view_t* filelist_view_create(const char* directory, const char* pattern) +filelist_view_t* filelist_view_create(rtgui_workbench_t* workbench, const char* directory, const char* pattern, const rtgui_rect_t* rect) { struct filelist_view* view = RT_NULL; - view = (struct filelist_view*) rtgui_widget_create(FILELIST_VIEW_TYPE); - if (view != RT_NULL) + if (filelist_view != RT_NULL) { - view->pattern = rt_strdup(pattern); - filelist_view_set_directory(view, directory); + rtgui_view_show(RTGUI_VIEW(filelist_view), RT_FALSE); + } + else + { + /* create a new view */ + view = (struct filelist_view*) rtgui_widget_create(FILELIST_VIEW_TYPE); + if (view != RT_NULL) + { + view->items = RT_NULL; + view->pattern = rt_strdup(pattern); + view->page_items = rtgui_rect_height(*rect) / (1 + rtgui_theme_get_selected_height()); + filelist_view_set_directory(view, directory); + + rtgui_workbench_add_view(workbench, RTGUI_VIEW(view)); + } + filelist_view = view; } - return list; + return view; } void filelist_view_destroy(filelist_view_t* view) { /* delete all file items */ filelist_view_clear(view); + /* delete current directory and pattern */ + rtgui_free(view->current_directory); view->current_directory = RT_NULL; + rtgui_free(view->pattern); view->pattern = RT_NULL; + + /* delete image */ + rtgui_image_destroy(file_image); + rtgui_image_destroy(folder_image); /* destroy view */ rtgui_widget_destroy(RTGUI_WIDGET(view)); @@ -104,18 +558,24 @@ void filelist_view_destroy(filelist_view_t* view) /* clear all file items */ void filelist_view_clear(filelist_view_t* view) { - struct rtgui_list_node* node; + rt_uint32_t index; struct file_item* item; - while (view->list.next != RT_NULL) - { - node = view->list.next; - rtgui_list_remove(&view->list, node); + for (index = 0; index < view->items_count; index ++) + { + item = &(view->items[index]); - item = rtgui_list_entry(node, struct file_item, list); - rtgui_free(item->name); - rtgui_free(item); - } + /* release item name */ + rt_free(item->name); + item->name = RT_NULL; + } + + /* release items */ + rtgui_free(view->items); + view->items = RT_NULL; + + view->items_count = 0; + view->current_item = 0; } void filelist_view_set_directory(filelist_view_t* view, const char* directory) @@ -129,57 +589,97 @@ void filelist_view_set_directory(filelist_view_t* view, const char* directory) filelist_view_clear(view); if (directory != RT_NULL) { - DIR* dir; + DIR* dir; + struct stat s; + rt_uint32_t index; + struct dirent* dirent; + + view->items_count = 0; dir = opendir(directory); - if (dir != RT_NULL) - { - struct dfs_dirent* dirent; - struct dfs_stat s; + if (dir == RT_NULL) goto __return; - do - { - dirent = readdir(dir); - if (dirent == RT_NULL) break; - if (fnmatch(dirent->d_name, view->pattern, FNM_FILE_NAME) != 0) continue; + /* current directory exists, set it */ + if (view->current_directory != RT_NULL) rt_free(view->current_directory); + view->current_directory = rt_strdup(directory); - item = (struct file_item*) rt_malloc (sizeof(struct file_item)); - if (item == RT_NULL) break; + do + { + dirent = readdir(dir); + if (dirent == RT_NULL) break; - rt_memset(&s, 0, sizeof(struct dfs_stat)); + if (strcmp(dirent->d_name, ".") == 0) continue; + if (strcmp(dirent->d_name, "..") == 0) continue; + + view->items_count ++; + } while (dirent != RT_NULL); + closedir(dir); - /* build full path for the file */ - rt_sprintf(fullpath, "%s/%s", directory, dirent->d_name); + view->items_count ++; /* root directory for [x] exit, others for .. */ - item->name = strdup(direct->d_name); - rtgui_list_init(&item->list); - stat(fullpath, &s); - if ( s.st_mode & DFS_S_IFDIR ) - { - item->type = FITEM_DIR; - item->size = 0; - } - else - { - item->type = FITEM_FILE; - item->size = s.st_size; - } + view->items = (struct file_item*) rtgui_malloc(sizeof(struct file_item) * view->items_count); + if (view->items == RT_NULL) return; /* no memory */ - rtgui_list_append(&view->list, &item->list); - view->count ++; - } while (dirent != RT_NULL); + index = 0; + if (directory[0] == '/' && directory[1] != '\0') + { + item = &(view->items[0]); - closedir(dir); - } + /* add .. directory */ + item->name = rt_strdup(".."); + item->type = FITEM_DIR; + item->size = 0; + + index ++; + } + else + { + item = &(view->items[0]); + + /* add .. directory */ + item->name = rt_strdup("退出文件浏览"); + item->type = FITEM_DIR; + item->size = 0; + + index ++; + } + + /* reopen directory */ + dir = opendir(directory); + for (; index < view->items_count; index ++) + { + dirent = readdir(dir); + if (dirent == RT_NULL) break; + + item = &(view->items[index]); + item->name = rt_strdup(dirent->d_name); + + rt_memset(&s, 0, sizeof(struct stat)); + + /* build full path for the file */ + if (directory[strlen(directory) - 1] != PATH_SEPARATOR) + sprintf(fullpath, "%s%c%s", directory, PATH_SEPARATOR, dirent->d_name); + else + sprintf(fullpath, "%s%s", directory, dirent->d_name); + + stat(fullpath, &s); + if ( s.st_mode & S_IFDIR ) + { + item->type = FITEM_DIR; + item->size = 0; + } + else + { + item->type = FITEM_FILE; + item->size = s.st_size; + } + } + + closedir(dir); } - if (view->count > 0) - { - /* select first one */ - view->selected = rtgui_list_entry(view->list.next, - struct file_item, list); - } - else view->selected = RT_NULL; + view->current_item = 0; +__return: /* update view */ rtgui_widget_update(RTGUI_WIDGET(view)); } diff --git a/bsp/stm32_radio/filelist.h b/bsp/stm32_radio/filelist.h index 098657edb..35cee0f78 100644 --- a/bsp/stm32_radio/filelist.h +++ b/bsp/stm32_radio/filelist.h @@ -1,17 +1,16 @@ #ifndef __FILE_LIST_VIEW_H__ #define __FILE_LIST_VIEW_H__ +#include + #define FITEM_FILE 0x0 #define FITEM_DIR 0x1 struct file_item { - char* name; + rt_uint8_t* name; rt_uint32_t type; rt_uint32_t size; - - /* files under same directory */ - rtgui_list_t list; }; /** Gets the type of a filelist view */ @@ -27,22 +26,30 @@ struct filelist_view /* widget private data */ - /* total number of items */ - rt_uint32_t count; - - /* the selected item */ - struct file_item* selected; - /* current directory */ rt_uint8_t* current_directory; rt_uint8_t* pattern; /* the number of item in a page */ rt_uint16_t page_items; + rt_uint16_t items_count; - /* item_list */ - rtgui_list_t item_list; + /* the selected item */ + rt_uint16_t current_item; + + /* items array */ + struct file_item *items; }; typedef struct filelist_view filelist_view_t; -#endif \ No newline at end of file +rtgui_type_t *filelist_view_type_get(void); + +filelist_view_t* filelist_view_create(rtgui_workbench_t* workbench, const char* directory, const char* pattern, const rtgui_rect_t* rect); +void filelist_view_destroy(filelist_view_t* view); + +void filelist_view_clear(filelist_view_t* view); + +rt_bool_t filelist_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event); +void filelist_view_set_directory(filelist_view_t* view, const char* directory); + +#endif diff --git a/bsp/stm32_radio/fnmatch.c b/bsp/stm32_radio/fnmatch.c deleted file mode 100644 index 0eeaa0206..000000000 --- a/bsp/stm32_radio/fnmatch.c +++ /dev/null @@ -1,139 +0,0 @@ -#include -#include -#include - -#define NOTFIRST 128 - -#define STRUCT_CHARCLASS(c) { #c , is##c } - -static struct charclass { - char * class; - int (*istype)(int); -} allclasses[] = { - STRUCT_CHARCLASS(alnum), - STRUCT_CHARCLASS(alpha), - STRUCT_CHARCLASS(blank), - STRUCT_CHARCLASS(cntrl), - STRUCT_CHARCLASS(digit), - STRUCT_CHARCLASS(graph), - STRUCT_CHARCLASS(lower), - STRUCT_CHARCLASS(print), - STRUCT_CHARCLASS(punct), - STRUCT_CHARCLASS(space), - STRUCT_CHARCLASS(upper), - STRUCT_CHARCLASS(xdigit), -}; - -/* look for "class:]" in pattern */ -static struct charclass *charclass_lookup(const char *pattern) { - unsigned int i; - - for (i = 0; i< sizeof(allclasses)/sizeof(*allclasses); i++) { - int len = strlen(allclasses[i].class); - if (!strncmp(pattern, allclasses[i].class, len)) { - pattern += len; - if (strncmp(pattern, ":]", 2)) goto noclass; - return &allclasses[i]; - } - } -noclass: - return NULL; -} - -static int match(char c,char d,int flags) { - if (flags&FNM_CASEFOLD) - return (tolower(c)==tolower(d)); - else - return (c==d); -} - -int fnmatch(const char *pattern, const char *string, int flags) { - if (*string==0) { - while (*pattern=='*') ++pattern; - return (!!*pattern); - } - if (*string=='.' && *pattern!='.' && (flags&FNM_PERIOD)) { - /* don't match if FNM_PERIOD and this is the first char */ - if (!(flags&NOTFIRST)) - return FNM_NOMATCH; - /* don't match if FNM_PERIOD and FNM_PATHNAME and previous was '/' */ - if ((flags&(FNM_PATHNAME)) && string[-1]=='/') - return FNM_NOMATCH; - } - flags|=NOTFIRST; - switch (*pattern) { - case '[': - { - int neg=0; - const char* start; /* first member of character class */ - - ++pattern; - if (*string=='/' && flags&FNM_PATHNAME) return FNM_NOMATCH; - if (*pattern=='!') { neg=1; ++pattern; } - start=pattern; - while (*pattern) { - int res=0; - - if (*pattern==']' && pattern!=start) break; - if (*pattern=='[' && pattern[1]==':') { - /* MEMBER - stupid POSIX char classes */ - const struct charclass *cc; - - if (!(cc = charclass_lookup(pattern+2))) goto invalidclass; - pattern += strlen(cc->class) + 4; - if (flags&FNM_CASEFOLD - && (cc->istype == isupper || cc->istype == islower)) { - res = islower(tolower(*string)); - } else { - res = ((*(cc->istype))(*string)); - } - } else { -invalidclass: - if (pattern[1]=='-' && pattern[2]!=']') { - /* MEMBER - character range */ - if (*string>=*pattern && *string<=pattern[2]) res=1; - if (flags&FNM_CASEFOLD) { - if (tolower(*string)>=tolower(*pattern) && tolower(*string)<=tolower(pattern[2])) res=1; - } - pattern+=3; - } else { - /* MEMBER - literal character match */ - res=match(*pattern,*string,flags); - ++pattern; - } - } - if ((res&&!neg) || ((neg&&!res) && *pattern==']')) { - while (*pattern && *pattern!=']') ++pattern; - return fnmatch(pattern+!!*pattern,string+1,flags); - } else if (res && neg) - return FNM_NOMATCH; - } - } - break; - case '\\': - if (flags&FNM_NOESCAPE) { - if (*string=='\\') - return fnmatch(pattern+1,string+1,flags); - } else { - if (*string==pattern[1]) - return fnmatch(pattern+2,string+1,flags); - } - break; - case '*': - if ((*string=='/' && flags&FNM_PATHNAME) || fnmatch(pattern,string+1,flags)) - return fnmatch(pattern+1,string,flags); - return 0; - case 0: - if (*string==0 || (*string=='/' && (flags&FNM_LEADING_DIR))) - return 0; - break; - case '?': - if (*string=='/' && flags&FNM_PATHNAME) break; - return fnmatch(pattern+1,string+1,flags); - default: - if (match(*pattern,*string,flags)) - return fnmatch(pattern+1,string+1,flags); - break; - } - return FNM_NOMATCH; -} diff --git a/bsp/stm32_radio/fnmatch.h b/bsp/stm32_radio/fnmatch.h deleted file mode 100644 index a3336cad5..000000000 --- a/bsp/stm32_radio/fnmatch.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _FNMATCH_H -#define _FNMATCH_H - -#include - -__BEGIN_DECLS - -int fnmatch(const char *pattern, const char *string, int flags) __THROW; - -#define FNM_NOESCAPE 1 -#define FNM_PATHNAME 2 -#define FNM_FILE_NAME 2 -#define FNM_PERIOD 4 -#define FNM_LEADING_DIR 8 -#define FNM_CASEFOLD 16 - -#define FNM_NOMATCH 1 - -__END_DECLS - -#endif diff --git a/bsp/stm32_radio/info.c b/bsp/stm32_radio/info.c index 77ef4416b..a32f65615 100644 --- a/bsp/stm32_radio/info.c +++ b/bsp/stm32_radio/info.c @@ -7,6 +7,7 @@ #include "network.xpm" +static rtgui_image_t *rtt_image = RT_NULL; static rtgui_image_t *network_image = RT_NULL; static rtgui_image_t *usb_image = RT_NULL; static rtgui_image_t *power_image = RT_NULL; @@ -23,7 +24,19 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev rtgui_widget_get_rect(widget, &rect); rtgui_dc_fill_rect(dc, &rect); + rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y2 - 1); + /* draw RT-Thread logo */ + rtt_image = rtgui_image_create_from_file("hdc", + "/resource/RTT.hdc", RT_FALSE); + if (rtt_image != RT_NULL) + { + rtgui_image_blit(rtt_image, dc, &rect); + rtgui_image_destroy(rtt_image); + + rtt_image = RT_NULL; + } + if (network_image != RT_NULL) { rect.x1 = rect.x2 - (network_image->w + 2); @@ -48,7 +61,7 @@ static void info_entry(void* parameter) rtgui_thread_register(rt_thread_self(), mq); network_image = rtgui_image_create_from_mem("xpm", - network_xpm, sizeof(network_xpm)); + (rt_uint8_t*)network_xpm, sizeof(network_xpm)); workbench = rtgui_workbench_create("info", "workbench"); if (workbench == RT_NULL) return; @@ -57,7 +70,7 @@ static void info_entry(void* parameter) rtgui_workbench_add_view(workbench, view); - rtgui_view_show(view); + rtgui_view_show(view, RT_FALSE); rtgui_workbench_event_loop(workbench); diff --git a/bsp/stm32_radio/key.c b/bsp/stm32_radio/key.c index 4c769d41e..e49c51fa2 100644 --- a/bsp/stm32_radio/key.c +++ b/bsp/stm32_radio/key.c @@ -42,6 +42,8 @@ static void key_thread_entry(void *parameter) while (1) { next_delay = 20; + kbd_event.key = RTGUIK_UNKNOWN; + kbd_event.type = RTGUI_KEYDOWN; if ( key_enter_GETVALUE() == 0 ) { @@ -58,6 +60,7 @@ static void key_thread_entry(void *parameter) kbd_event.key = RTGUIK_RETURN; } } + if ( key_down_GETVALUE() == 0 ) { rt_kprintf("key_down\n"); @@ -81,15 +84,23 @@ static void key_thread_entry(void *parameter) rt_kprintf("key_left\n"); kbd_event.key = RTGUIK_LEFT; } - /* post down event */ - rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event)); + + if (kbd_event.key != RTGUIK_UNKNOWN) + { + /* post down event */ + rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event)); + + next_delay = 10; + /* delay to post up event */ + rt_thread_delay(next_delay); + + /* post up event */ + kbd_event.type = RTGUI_KEYUP; + rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event)); + } /* wait next key press */ rt_thread_delay(next_delay); - - /* post up event */ - kbd_event.type = RTGUI_KEYUP; - rtgui_server_post_event(&(kbd_event.parent), sizeof(kbd_event)); } } diff --git a/bsp/stm32_radio/lcd.c b/bsp/stm32_radio/lcd.c index fd46a902c..4ae7b1a27 100644 --- a/bsp/stm32_radio/lcd.c +++ b/bsp/stm32_radio/lcd.c @@ -3,6 +3,8 @@ #include "fmt0371/FMT0371.h" #include #include +#include +#include void rt_hw_lcd_update(rtgui_rect_t *rect); rt_uint8_t * rt_hw_lcd_get_framebuffer(void); @@ -10,6 +12,7 @@ void rt_hw_lcd_set_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y); void rt_hw_lcd_get_pixel(rtgui_color_t *c, rt_base_t x, rt_base_t y); void rt_hw_lcd_draw_hline(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y); void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t y2); +void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y); struct rtgui_graphic_driver _rtgui_lcd_driver = { @@ -22,7 +25,8 @@ struct rtgui_graphic_driver _rtgui_lcd_driver = rt_hw_lcd_set_pixel, rt_hw_lcd_get_pixel, rt_hw_lcd_draw_hline, - rt_hw_lcd_draw_vline + rt_hw_lcd_draw_vline, + rt_hw_lcd_draw_raw_hline }; void rt_hw_lcd_update(rtgui_rect_t *rect) @@ -123,6 +127,30 @@ void rt_hw_lcd_draw_vline(rtgui_color_t *c, rt_base_t x, rt_base_t y1, rt_base_t } } +void rt_hw_lcd_draw_raw_hline(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y) +{ + rt_uint16_t *ptr; + + /* get pixel */ + ptr = (rt_uint16_t*) pixels; + + /* set X point */ + LCD_ADDR = 0x02; + LCD_DATA = x1; + + /* set Y point */ + LCD_ADDR = 0x03; + LCD_DATA16( y ); + + /* write pixel */ + LCD_ADDR = 0x0E; + while (x1 < x2) + { + LCD_DATA16(*ptr); + x1 ++; ptr ++; + } +} + rt_err_t rt_hw_lcd_init(void) { GPIO_InitTypeDef GPIO_InitStructure; @@ -145,6 +173,33 @@ rt_err_t rt_hw_lcd_init(void) return RT_EOK; } +void radio_rtgui_init() +{ + rtgui_rect_t rect; + + rtgui_system_server_init(); + + /* register dock panel */ + rect.x1 = 0; + rect.y1 = 0; + rect.x2 = 240; + rect.y2 = 25; + rtgui_panel_register("info", &rect); + + /* register main panel */ + rect.x1 = 0; + rect.y1 = 25; + rect.x2 = 320; + rect.y2 = 320; + rtgui_panel_register("main", &rect); + rtgui_panel_set_default_focused("main"); + + rt_hw_lcd_init(); + + info_init(); + player_init(); +} + #include void hline(rt_base_t x1, rt_base_t x2, rt_base_t y, rt_uint32_t pixel) diff --git a/bsp/stm32_radio/listview.c b/bsp/stm32_radio/listview.c new file mode 100644 index 000000000..6a8a0b93d --- /dev/null +++ b/bsp/stm32_radio/listview.c @@ -0,0 +1,245 @@ +#include "listview.h" +#include + +#define LIST_MARGIN 5 + +static void _list_view_constructor(struct list_view *view) +{ + /* default rect */ + struct rtgui_rect rect = {0, 0, 200, 200}; + + /* set default widget rect and set event handler */ + rtgui_widget_set_event_handler(RTGUI_WIDGET(view),list_view_event_handler); + rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect); + + RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; + + view->current_item = 0; + view->items_count = 0; + view->page_items = 0; + + RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white; + RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(view)) = RTGUI_ALIGN_CENTER_VERTICAL; +} + +rtgui_type_t *list_view_type_get(void) +{ + static rtgui_type_t *list_view_type = RT_NULL; + + if (!list_view_type) + { + list_view_type = rtgui_type_create("listview", RTGUI_VIEW_TYPE, + sizeof(list_view_t), RTGUI_CONSTRUCTOR(_list_view_constructor), RT_NULL); + } + + return list_view_type; +} + +void list_view_ondraw(struct list_view* view) +{ + struct rtgui_rect rect, item_rect; + struct rtgui_dc* dc; + rt_uint16_t page_index, index; + struct list_item* item; + + dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view)); + if (dc == RT_NULL) return; + + rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); + rtgui_dc_fill_rect(dc, &rect); + + /* get item base rect */ + item_rect = rect; + item_rect.y1 += 2; + item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height()); + + /* get current page */ + page_index = (view->current_item / view->page_items) * view->page_items; + for (index = 0; index < view->page_items; index ++) + { + if (page_index + index >= view->items_count) break; + + item = &(view->items[page_index + index]); + + if (page_index + index == view->current_item) + { + rtgui_theme_draw_selected(dc, &item_rect); + } + item_rect.x1 += LIST_MARGIN; + + if (item->image != RT_NULL) + { + rtgui_image_blit(item->image, dc, &item_rect); + item_rect.x1 += item->image->w + 2; + } + /* draw text */ + rtgui_dc_draw_text(dc, item->name, &item_rect); + + if (item->image != RT_NULL) + item_rect.x1 -= (item->image->w + 2); + item_rect.x1 -= LIST_MARGIN; + + /* move to next item position */ + item_rect.y1 += (rtgui_theme_get_selected_height() + 2); + item_rect.y2 += (rtgui_theme_get_selected_height() + 2); + } + rtgui_dc_end_drawing(dc); +} + +void list_view_update_current(struct list_view* view, rt_uint16_t old_item) +{ + struct rtgui_dc* dc; + struct list_item* item; + rtgui_rect_t rect, item_rect; + + if (old_item/view->page_items != view->current_item/view->page_items) + { + /* it's not a same page, update all */ + rtgui_widget_update(RTGUI_WIDGET(view)); + return; + } + + dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view)); + if (dc == RT_NULL) return; + + rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect); + + item_rect = rect; + /* get old item's rect */ + item_rect.y1 += 2; + item_rect.y1 += (old_item % view->page_items) * (2 + rtgui_theme_get_selected_height()); + item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height()); + + /* draw old item */ + rtgui_dc_fill_rect(dc, &item_rect); + + item_rect.x1 += LIST_MARGIN; + + item = &(view->items[old_item]); + if (item->image != RT_NULL) + { + rtgui_image_blit(item->image, dc, &item_rect); + item_rect.x1 += item->image->w + 2; + } + rtgui_dc_draw_text(dc, item->name, &item_rect); + + /* draw current item */ + item_rect = rect; + /* get current item's rect */ + item_rect.y1 += 2; + item_rect.y1 += (view->current_item % view->page_items) * (2 + rtgui_theme_get_selected_height()); + item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height()); + + /* draw current item */ + rtgui_theme_draw_selected(dc, &item_rect); + + item_rect.x1 += LIST_MARGIN; + + item = &(view->items[view->current_item]); + if (item->image != RT_NULL) + { + rtgui_image_blit(item->image, dc, &item_rect); + item_rect.x1 += (item->image->w + 2); + } + rtgui_dc_draw_text(dc, item->name, &item_rect); + + rtgui_dc_end_drawing(dc); +} + +rt_bool_t list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) +{ + struct list_view* view = RT_NULL; + + view = LIST_VIEW(widget); + switch (event->type) + { + case RTGUI_EVENT_PAINT: + list_view_ondraw(view); + return RT_FALSE; + + case RTGUI_EVENT_RESIZE: + { + struct rtgui_event_resize* resize; + + resize = (struct rtgui_event_resize*)event; + + /* recalculate page items */ + view->page_items = resize->h / (2 + rtgui_theme_get_selected_height()); + } + break; + + case RTGUI_EVENT_KBD: + { + struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event; + if (ekbd->type == RTGUI_KEYDOWN) + { + rt_uint16_t old_item; + + old_item = view->current_item; + switch (ekbd->key) + { + case RTGUIK_LEFT: + if (view->current_item - view->page_items >= 0) + view->current_item -= view->page_items; + list_view_update_current(view, old_item); + return RT_FALSE; + + case RTGUIK_UP: + if (view->current_item > 0) + view->current_item --; + list_view_update_current(view, old_item); + return RT_FALSE; + + case RTGUIK_RIGHT: + if (view->current_item + view->page_items < view->items_count - 1) + view->current_item += view->page_items; + list_view_update_current(view, old_item); + return RT_FALSE; + + case RTGUIK_DOWN: + if (view->current_item < view->items_count - 1) + view->current_item ++; + list_view_update_current(view, old_item); + return RT_FALSE; + + case RTGUIK_RETURN: + if (view->items[view->current_item].action != RT_NULL) + { + view->items[view->current_item].action(view->items[view->current_item].parameter); + } + return RT_FALSE; + + default: + break; + } + } + } + return RT_FALSE; + } + + /* use view event handler */ + return rtgui_view_event_handler(widget, event); +} + +list_view_t* list_view_create(struct list_item* items, rt_uint16_t count, rtgui_rect_t *rect) +{ + struct list_view* view = RT_NULL; + + view = (struct list_view*) rtgui_widget_create(LIST_VIEW_TYPE); + if (view != RT_NULL) + { + view->items = items; + view->items_count = count; + + view->page_items = rtgui_rect_height(*rect) / (2 + rtgui_theme_get_selected_height()); + } + + return view; +} + +void list_view_destroy(list_view_t* view) +{ + /* destroy view */ + rtgui_widget_destroy(RTGUI_WIDGET(view)); +} + diff --git a/bsp/stm32_radio/listview.h b/bsp/stm32_radio/listview.h new file mode 100644 index 000000000..b5b7ce744 --- /dev/null +++ b/bsp/stm32_radio/listview.h @@ -0,0 +1,53 @@ +#ifndef __RTGUI_LIST_VIEW_H__ +#define __RTGUI_LIST_VIEW_H__ + +#include +#include +#include + +#include + +typedef void (*item_action)(void* parameter); +struct list_item +{ + char* name; + rtgui_image_t *image; + + item_action action; + void *parameter; +}; + +/** Gets the type of a list view */ +#define LIST_VIEW_TYPE (list_view_type_get()) +/** Casts the object to a filelist */ +#define LIST_VIEW(obj) (RTGUI_OBJECT_CAST((obj), LIST_VIEW_TYPE, list_view_t)) +/** Checks if the object is a filelist view */ +#define IS_LIST_VIEW(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), LIST_VIEW_TYPE)) + +struct list_view +{ + struct rtgui_view parent; + + /* widget private data */ + /* list item */ + struct list_item* items; + + /* total number of items */ + rt_uint16_t items_count; + /* the number of item in a page */ + rt_uint16_t page_items; + /* current item */ + rt_uint16_t current_item; +}; +typedef struct list_view list_view_t; + +rtgui_type_t *list_view_type_get(void); + +list_view_t* list_view_create(struct list_item* items, rt_uint16_t count, + rtgui_rect_t *rect); +void list_view_clear(list_view_t* view); + +rt_bool_t list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event); + +#endif + diff --git a/bsp/stm32_radio/player.c b/bsp/stm32_radio/player.c new file mode 100644 index 000000000..edd3c4904 --- /dev/null +++ b/bsp/stm32_radio/player.c @@ -0,0 +1,185 @@ +#include +#include +#include + +#include +#include +#include + +#include "listview.h" + +static rtgui_image_t *background = RT_NULL; + +static struct rtgui_view* function_view; +static struct rtgui_view* home_view; +static struct rtgui_workbench* workbench; + +void function_filelist(void* parameter) +{ + rtgui_rect_t rect; + rtgui_view_t *view; + extern rtgui_view_t* filelist_view_create(rtgui_workbench_t* workbench, + const char* directory, const char* pattern, rtgui_rect_t* rect); + + rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect); + view = (rtgui_view_t*)filelist_view_create(workbench, "/", "*.*", &rect); + if (view != RT_NULL) + { + rtgui_view_show(view, RT_FALSE); + } + + return; +} + +void function_device(void* parameter) +{ + rtgui_view_t *view; + extern rtgui_view_t* device_view_create(rtgui_workbench_t* workbench); + + view = device_view_create(workbench); + if (view != RT_NULL) + { + rtgui_view_show(view, RT_FALSE); + } + + return; +} + +void function_player(void* parameter) +{ + rtgui_view_show(home_view, RT_FALSE); + return; +} + +void function_action(void* parameter) +{ + rt_kprintf("item action!\n"); + return; +} + +struct list_item function_list[] = +{ + {"选择电台", RT_NULL, function_action, RT_NULL}, + {"更新电台", RT_NULL, function_action, RT_NULL}, + {"播放文件", RT_NULL, function_filelist, RT_NULL}, + {"设备信息", RT_NULL, function_device, RT_NULL}, + {"返回播放器", RT_NULL, function_player, RT_NULL}, +}; + +static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) +{ + if (event->type == RTGUI_EVENT_PAINT) + { + struct rtgui_dc* dc; + struct rtgui_rect rect; + + dc = rtgui_dc_begin_drawing(widget); + if (dc == RT_NULL) return RT_FALSE; + rtgui_widget_get_rect(widget, &rect); + + /* draw background */ + background = rtgui_image_create_from_file("hdc", + "/resource/bg.hdc", RT_FALSE); + if (background != RT_NULL) + { + rtgui_image_blit(background, dc, &rect); + rtgui_image_destroy(background); + + background = RT_NULL; + } + else + { + rtgui_dc_fill_rect(dc, &rect); + } + rtgui_dc_end_drawing(dc); + + return RT_FALSE; + } + else if (event->type == RTGUI_EVENT_KBD) + { + struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event; + if (ekbd->type == RTGUI_KEYDOWN) + { + switch (ekbd->key) + { + case RTGUIK_RIGHT: + case RTGUIK_LEFT: + break; + + case RTGUIK_DOWN: + rtgui_view_show(function_view, RT_FALSE); + break; + } + } + return RT_FALSE; + } + + return rtgui_view_event_handler(widget, event); +} + +rt_bool_t today_workbench_event_handler(rtgui_widget_t *widget, rtgui_event_t *event) +{ + if (event->type == RTGUI_EVENT_KBD) + { + struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event; + if ((ekbd->type == RTGUI_KEYUP) && ekbd->key == RTGUIK_HOME) + { + /* active home view */ + if (workbench->current_view != home_view) + { + rtgui_view_show(home_view, RT_FALSE); + return RT_FALSE; + } + } + } + + return rtgui_workbench_event_handler(widget, event); +} + +static void player_entry(void* parameter) +{ + rt_mq_t mq; + rtgui_rect_t rect; + + mq = rt_mq_create("qPlayer", 256, 4, RT_IPC_FLAG_FIFO); + rtgui_thread_register(rt_thread_self(), mq); + + workbench = rtgui_workbench_create("main", "workbench"); + if (workbench == RT_NULL) return; + rtgui_widget_set_event_handler(RTGUI_WIDGET(workbench), today_workbench_event_handler); + + /* add home view */ + home_view = rtgui_view_create("Home"); + rtgui_widget_set_event_handler(RTGUI_WIDGET(home_view), home_view_event_handler); + + rtgui_workbench_add_view(workbench, home_view); + /* this view can be focused */ + RTGUI_WIDGET(home_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; + /* set widget focus */ + rtgui_widget_focus(RTGUI_WIDGET(home_view)); + + rtgui_view_show(home_view, RT_FALSE); + + /* add function view */ + rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect); + function_view = (struct rtgui_view*)list_view_create(function_list, + sizeof(function_list)/sizeof(struct list_item), + &rect); + rtgui_workbench_add_view(workbench, function_view); + + rtgui_workbench_event_loop(workbench); + + rtgui_thread_deregister(rt_thread_self()); + rt_mq_delete(mq); +} + +void player_init() +{ + rt_thread_t tid; + + tid = rt_thread_create("player", + player_entry, RT_NULL, + 2048, 25, 10); + + if (tid != RT_NULL) rt_thread_startup(tid); +} diff --git a/bsp/stm32_radio/project.Opt b/bsp/stm32_radio/project.Opt index a1de9e085..79329c24e 100644 --- a/bsp/stm32_radio/project.Opt +++ b/bsp/stm32_radio/project.Opt @@ -20,13 +20,13 @@ GRPOPT 6,(finsh),0,0,0 GRPOPT 7,(Filesystem),0,0,0 GRPOPT 8,(LwIP),0,0,0 GRPOPT 9,(mp3),0,0,0 -GRPOPT 10,(RTGUI),1,0,0 +GRPOPT 10,(RTGUI),0,0,0 OPTFFF 1,1,5,0,0,0,0,0,<.\rtconfig.h> OPTFFF 1,2,5,0,0,0,0,0,<.\board.h> OPTFFF 1,3,5,0,0,0,0,0,<.\stm32f10x_conf.h> OPTFFF 1,4,1,0,0,0,0,0,<.\application.c> -OPTFFF 1,5,1,83886080,0,0,0,0,<.\board.c> +OPTFFF 1,5,1,0,0,0,0,0,<.\board.c> OPTFFF 1,6,1,335544320,0,0,0,0,<.\startup.c> OPTFFF 1,7,1,0,0,0,0,0,<.\stm32f10x_it.c> OPTFFF 1,8,1,0,0,0,0,0,<.\usart.c> @@ -34,7 +34,7 @@ OPTFFF 1,9,1,0,0,0,0,0,<.\sdcard.c> OPTFFF 1,10,1,0,0,0,0,0,<.\rtc.c> OPTFFF 1,11,1,0,0,0,0,0,<.\wm8753.c> OPTFFF 1,12,1,0,0,0,0,0,<.\dm9000.c> -OPTFFF 1,13,1,0,0,0,0,0,<.\fsmc_nand.c> +OPTFFF 1,13,1,889192448,0,0,0,0,<.\fsmc_nand.c> OPTFFF 1,14,1,0,0,0,0,0,<.\fsmc_sram.c> OPTFFF 1,15,1,0,0,0,0,0,<.\fmt0371\fmt0371.c> OPTFFF 1,16,1,0,0,0,0,0,<.\http.c> @@ -42,170 +42,175 @@ OPTFFF 1,17,1,0,0,0,0,0,<.\lcd.c> OPTFFF 1,18,1,620756992,0,0,0,0,<.\mp3.c> OPTFFF 1,19,1,369098752,0,0,0,0,<.\wav.c> OPTFFF 1,20,1,620756992,0,0,0,0,<.\netbuffer.c> -OPTFFF 1,21,1,33554432,0,0,0,0,<.\gui.c> -OPTFFF 1,22,1,0,0,0,0,0,<.\key.c> -OPTFFF 1,23,1,0,0,0,0,0,<.\info.c> -OPTFFF 1,24,1,0,0,0,0,0,<.\today.c> -OPTFFF 2,25,1,0,0,0,0,0,<..\..\src\clock.c> -OPTFFF 2,26,1,0,0,0,0,0,<..\..\src\idle.c> -OPTFFF 2,27,1,671088640,0,0,0,0,<..\..\src\ipc.c> -OPTFFF 2,28,1,0,0,0,0,0,<..\..\src\mempool.c> -OPTFFF 2,29,1,0,0,0,0,0,<..\..\src\mem.c> -OPTFFF 2,30,1,0,0,0,0,0,<..\..\src\object.c> -OPTFFF 2,31,1,0,0,0,0,0,<..\..\src\scheduler.c> -OPTFFF 2,32,1,285212672,0,0,0,0,<..\..\src\thread.c> -OPTFFF 2,33,1,0,0,0,0,0,<..\..\src\timer.c> -OPTFFF 2,34,1,0,0,0,0,0,<..\..\src\irq.c> -OPTFFF 2,35,1,0,0,0,0,0,<..\..\src\kservice.c> -OPTFFF 2,36,1,0,0,0,0,0,<..\..\src\device.c> -OPTFFF 2,37,1,0,0,0,0,0,<..\..\src\slab.c> -OPTFFF 3,38,1,0,0,0,0,0,<..\..\libcpu\arm\stm32\stack.c> -OPTFFF 3,39,1,0,0,0,0,0,<..\..\libcpu\arm\stm32\interrupt.c> -OPTFFF 3,40,1,0,0,0,0,0,<..\..\libcpu\arm\stm32\cpu.c> -OPTFFF 3,41,1,0,0,0,0,0,<..\..\libcpu\arm\stm32\serial.c> -OPTFFF 3,42,2,0,0,0,0,0,<..\..\libcpu\arm\stm32\context_rvds.S> -OPTFFF 3,43,2,0,0,0,0,0,<..\..\libcpu\arm\stm32\start_rvds.s> -OPTFFF 3,44,1,0,0,0,0,0,<..\..\libcpu\arm\stm32\fault.c> -OPTFFF 3,45,2,0,0,0,0,0,<..\..\libcpu\arm\stm32\fault_rvds.S> -OPTFFF 4,46,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\misc.c> -OPTFFF 4,47,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_adc.c> -OPTFFF 4,48,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_bkp.c> -OPTFFF 4,49,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_can.c> -OPTFFF 4,50,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_crc.c> -OPTFFF 4,51,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_dac.c> -OPTFFF 4,52,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_dbgmcu.c> -OPTFFF 4,53,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_dma.c> -OPTFFF 4,54,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_exti.c> -OPTFFF 4,55,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_flash.c> -OPTFFF 4,56,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_fsmc.c> -OPTFFF 4,57,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_gpio.c> -OPTFFF 4,58,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_i2c.c> -OPTFFF 4,59,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_iwdg.c> -OPTFFF 4,60,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_pwr.c> -OPTFFF 4,61,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_rcc.c> -OPTFFF 4,62,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_rtc.c> -OPTFFF 4,63,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_sdio.c> -OPTFFF 4,64,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_spi.c> -OPTFFF 4,65,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_tim.c> -OPTFFF 4,66,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_usart.c> -OPTFFF 4,67,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_wwdg.c> -OPTFFF 5,68,1,0,0,0,0,0,<.\Libraries\CMSIS\Core\CM3\core_cm3.c> -OPTFFF 5,69,1,0,0,0,0,0,<.\Libraries\CMSIS\Core\CM3\system_stm32f10x.c> -OPTFFF 6,70,1,0,0,0,0,0,<..\..\finsh\finsh_compiler.c> -OPTFFF 6,71,1,0,0,0,0,0,<..\..\finsh\finsh_error.c> -OPTFFF 6,72,1,0,0,0,0,0,<..\..\finsh\finsh_heap.c> -OPTFFF 6,73,1,0,0,0,0,0,<..\..\finsh\finsh_init.c> -OPTFFF 6,74,1,0,0,0,0,0,<..\..\finsh\finsh_node.c> -OPTFFF 6,75,1,0,0,0,0,0,<..\..\finsh\finsh_ops.c> -OPTFFF 6,76,1,0,0,0,0,0,<..\..\finsh\finsh_parser.c> -OPTFFF 6,77,1,0,0,0,0,0,<..\..\finsh\finsh_token.c> -OPTFFF 6,78,1,0,0,0,0,0,<..\..\finsh\finsh_var.c> -OPTFFF 6,79,1,0,0,0,0,0,<..\..\finsh\finsh_vm.c> -OPTFFF 6,80,1,0,0,0,0,0,<..\..\finsh\shell.c> -OPTFFF 6,81,1,0,0,0,0,0,<..\..\finsh\symbol.c> -OPTFFF 6,82,1,285212672,0,0,0,0,<..\..\finsh\cmd.c> -OPTFFF 7,83,1,0,0,0,0,0,<..\..\filesystem\dfs\src\dfs_init.c> -OPTFFF 7,84,1,503316480,0,0,0,0,<..\..\filesystem\dfs\src\dfs_fs.c> -OPTFFF 7,85,1,0,0,0,0,0,<..\..\filesystem\dfs\src\dfs_raw.c> -OPTFFF 7,86,1,0,0,0,0,0,<..\..\filesystem\dfs\src\dfs_util.c> -OPTFFF 7,87,1,0,0,0,0,0,<..\..\filesystem\dfs\src\dfs_posix.c> -OPTFFF 7,88,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\dir.c> -OPTFFF 7,89,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\fat.c> -OPTFFF 7,90,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\file.c> -OPTFFF 7,91,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\fs.c> -OPTFFF 7,92,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\ls.c> -OPTFFF 7,93,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\time.c> -OPTFFF 7,94,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\ui.c> -OPTFFF 7,95,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\base\plibc.c> -OPTFFF 7,96,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\base\efs.c> -OPTFFF 7,97,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\base\extract.c> -OPTFFF 7,98,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\base\partition.c> -OPTFFF 7,99,1,0,0,0,0,0,<..\..\filesystem\dfs\src\dfs_cache.c> -OPTFFF 8,100,1,0,0,0,0,0,<..\..\net\lwip\src\core\dhcp.c> -OPTFFF 8,101,1,0,0,0,0,0,<..\..\net\lwip\src\core\dns.c> -OPTFFF 8,102,1,0,0,0,0,0,<..\..\net\lwip\src\core\init.c> -OPTFFF 8,103,1,0,0,0,0,0,<..\..\net\lwip\src\core\netif.c> -OPTFFF 8,104,1,0,0,0,0,0,<..\..\net\lwip\src\core\pbuf.c> -OPTFFF 8,105,1,0,0,0,0,0,<..\..\net\lwip\src\core\raw.c> -OPTFFF 8,106,1,0,0,0,0,0,<..\..\net\lwip\src\core\stats.c> -OPTFFF 8,107,1,0,0,0,0,0,<..\..\net\lwip\src\core\sys.c> -OPTFFF 8,108,1,0,0,0,0,0,<..\..\net\lwip\src\core\tcp.c> -OPTFFF 8,109,1,0,0,0,0,0,<..\..\net\lwip\src\core\tcp_in.c> -OPTFFF 8,110,1,0,0,0,0,0,<..\..\net\lwip\src\core\tcp_out.c> -OPTFFF 8,111,1,0,0,0,0,0,<..\..\net\lwip\src\core\udp.c> -OPTFFF 8,112,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\autoip.c> -OPTFFF 8,113,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\icmp.c> -OPTFFF 8,114,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\igmp.c> -OPTFFF 8,115,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\inet.c> -OPTFFF 8,116,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\inet_chksum.c> -OPTFFF 8,117,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\ip.c> -OPTFFF 8,118,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\ip_addr.c> -OPTFFF 8,119,1,285212672,0,0,0,0,<..\..\net\lwip\src\core\ipv4\ip_frag.c> -OPTFFF 8,120,1,0,0,0,0,0,<..\..\net\lwip\src\core\snmp\msg_in.c> -OPTFFF 8,121,1,0,0,0,0,0,<..\..\net\lwip\src\core\snmp\msg_out.c> -OPTFFF 8,122,1,0,0,0,0,0,<..\..\net\lwip\src\api\api_lib.c> -OPTFFF 8,123,1,50331648,0,0,0,0,<..\..\net\lwip\src\api\api_msg.c> -OPTFFF 8,124,1,0,0,0,0,0,<..\..\net\lwip\src\api\err.c> -OPTFFF 8,125,1,0,0,0,0,0,<..\..\net\lwip\src\api\netbuf.c> -OPTFFF 8,126,1,0,0,0,0,0,<..\..\net\lwip\src\api\netdb.c> -OPTFFF 8,127,1,0,0,0,0,0,<..\..\net\lwip\src\api\netifapi.c> -OPTFFF 8,128,1,0,0,0,0,0,<..\..\net\lwip\src\api\tcpip.c> -OPTFFF 8,129,1,0,0,0,0,0,<..\..\net\lwip\src\netif\etharp.c> -OPTFFF 8,130,1,150994944,0,0,0,0,<..\..\net\lwip\src\netif\ethernetif.c> -OPTFFF 8,131,1,0,0,0,0,0,<..\..\net\lwip\src\netif\loopif.c> -OPTFFF 8,132,1,0,0,0,0,0,<..\..\net\lwip\src\arch\sys_arch_init.c> -OPTFFF 8,133,1,0,0,0,0,0,<..\..\net\lwip\src\arch\sys_arch.c> -OPTFFF 8,134,1,0,0,0,0,0,<..\..\net\lwip\src\api\sockets.c> -OPTFFF 8,135,1,0,0,0,0,0,<..\..\net\lwip\src\core\memp_tiny.c> -OPTFFF 9,136,1,268435456,0,0,0,0,<.\mp3\mp3dec.c> -OPTFFF 9,137,1,0,0,0,0,0,<.\mp3\mp3tabs.c> -OPTFFF 9,138,1,0,0,0,0,0,<.\mp3\real\bitstream.c> -OPTFFF 9,139,1,83886080,0,0,0,0,<.\mp3\real\buffers.c> -OPTFFF 9,140,1,0,0,0,0,0,<.\mp3\real\dct32.c> -OPTFFF 9,141,1,0,0,0,0,0,<.\mp3\real\dequant.c> -OPTFFF 9,142,1,0,0,0,0,0,<.\mp3\real\dqchan.c> -OPTFFF 9,143,1,0,0,0,0,0,<.\mp3\real\huffman.c> -OPTFFF 9,144,1,0,0,0,0,0,<.\mp3\real\hufftabs.c> -OPTFFF 9,145,1,0,0,0,0,0,<.\mp3\real\imdct.c> -OPTFFF 9,146,1,0,0,0,0,0,<.\mp3\real\scalfact.c> -OPTFFF 9,147,1,0,0,0,0,0,<.\mp3\real\stproc.c> -OPTFFF 9,148,1,0,0,0,0,0,<.\mp3\real\subband.c> -OPTFFF 9,149,1,0,0,0,0,0,<.\mp3\real\trigtabs.c> -OPTFFF 9,150,2,0,0,0,0,0,<.\mp3\real\arm\asmpoly_thumb2.s> -OPTFFF 9,151,2,0,0,0,0,0,<.\mp3\real\arm\asmmisc.s> -OPTFFF 10,152,1,0,0,0,0,0,<..\..\rtgui\common\rtgui_object.c> -OPTFFF 10,153,1,385875968,0,0,0,0,<..\..\rtgui\common\rtgui_system.c> -OPTFFF 10,154,1,0,0,0,0,0,<..\..\rtgui\common\rtgui_theme.c> -OPTFFF 10,155,1,0,0,0,0,0,<..\..\rtgui\common\asc12font.c> -OPTFFF 10,156,1,402653184,0,0,0,0,<..\..\rtgui\common\asc16font.c> -OPTFFF 10,157,1,0,0,0,0,0,<..\..\rtgui\common\color.c> -OPTFFF 10,158,1,0,0,0,0,0,<..\..\rtgui\common\dc.c> -OPTFFF 10,159,1,0,0,0,0,0,<..\..\rtgui\common\dc_buffer.c> -OPTFFF 10,160,1,0,0,0,0,0,<..\..\rtgui\common\dc_hw.c> -OPTFFF 10,161,1,16777216,0,0,0,0,<..\..\rtgui\common\filerw.c> -OPTFFF 10,162,1,83886080,0,0,0,0,<..\..\rtgui\common\font.c> -OPTFFF 10,163,1,469762048,0,0,0,0,<..\..\rtgui\common\image.c> -OPTFFF 10,164,1,0,0,0,0,0,<..\..\rtgui\common\image_xpm.c> -OPTFFF 10,165,1,0,0,0,0,0,<..\..\rtgui\common\image_hdc.c> -OPTFFF 10,166,1,0,0,0,0,0,<..\..\rtgui\common\region.c> -OPTFFF 10,167,1,0,0,0,0,0,<..\..\rtgui\server\server.c> -OPTFFF 10,168,1,0,0,0,0,0,<..\..\rtgui\server\driver.c> -OPTFFF 10,169,1,335544320,0,0,0,0,<..\..\rtgui\server\panel.c> -OPTFFF 10,170,1,0,0,0,0,0,<..\..\rtgui\widgets\widget.c> -OPTFFF 10,171,1,0,0,0,0,0,<..\..\rtgui\widgets\window.c> -OPTFFF 10,172,1,0,0,0,0,0,<..\..\rtgui\widgets\workbench.c> -OPTFFF 10,173,1,0,0,0,0,0,<..\..\rtgui\widgets\view.c> -OPTFFF 10,174,1,0,0,0,0,0,<..\..\rtgui\widgets\box.c> -OPTFFF 10,175,1,0,0,0,0,0,<..\..\rtgui\widgets\button.c> -OPTFFF 10,176,1,0,0,0,0,0,<..\..\rtgui\widgets\container.c> -OPTFFF 10,177,1,0,0,0,0,0,<..\..\rtgui\widgets\iconbox.c> -OPTFFF 10,178,1,0,0,0,0,0,<..\..\rtgui\widgets\label.c> -OPTFFF 10,179,1,0,0,0,0,0,<..\..\rtgui\widgets\textbox.c> -OPTFFF 10,180,1,0,0,0,0,0,<..\..\rtgui\widgets\title.c> -OPTFFF 10,181,1,67108864,0,0,0,0,<..\..\rtgui\widgets\toplevel.c> -OPTFFF 10,182,1,0,0,0,0,0,<..\..\rtgui\server\mouse.c> -OPTFFF 10,183,1,0,0,0,0,0,<..\..\rtgui\server\topwin.c> -OPTFFF 10,184,1,0,0,0,0,0,<..\..\rtgui\common\caret.c> +OPTFFF 1,21,1,0,0,0,0,0,<.\key.c> +OPTFFF 1,22,1,0,0,0,0,0,<.\info.c> +OPTFFF 1,23,1,0,0,0,0,0, +OPTFFF 1,24,1,0,0,0,0,0,<.\filelist.c> +OPTFFF 1,25,1,0,0,0,0,0,<.\device_info.c> +OPTFFF 1,26,1,0,0,0,0,0,<.\listview.c> +OPTFFF 2,27,1,0,0,0,0,0,<..\..\src\clock.c> +OPTFFF 2,28,1,0,0,0,0,0,<..\..\src\idle.c> +OPTFFF 2,29,1,671088640,0,0,0,0,<..\..\src\ipc.c> +OPTFFF 2,30,1,0,0,0,0,0,<..\..\src\mempool.c> +OPTFFF 2,31,1,0,0,0,0,0,<..\..\src\mem.c> +OPTFFF 2,32,1,0,0,0,0,0,<..\..\src\object.c> +OPTFFF 2,33,1,0,0,0,0,0,<..\..\src\scheduler.c> +OPTFFF 2,34,1,285212672,0,0,0,0,<..\..\src\thread.c> +OPTFFF 2,35,1,0,0,0,0,0,<..\..\src\timer.c> +OPTFFF 2,36,1,0,0,0,0,0,<..\..\src\irq.c> +OPTFFF 2,37,1,0,0,0,0,0,<..\..\src\kservice.c> +OPTFFF 2,38,1,0,0,0,0,0,<..\..\src\device.c> +OPTFFF 2,39,1,0,0,0,0,0,<..\..\src\slab.c> +OPTFFF 3,40,1,0,0,0,0,0,<..\..\libcpu\arm\stm32\stack.c> +OPTFFF 3,41,1,0,0,0,0,0,<..\..\libcpu\arm\stm32\interrupt.c> +OPTFFF 3,42,1,0,0,0,0,0,<..\..\libcpu\arm\stm32\cpu.c> +OPTFFF 3,43,1,0,0,0,0,0,<..\..\libcpu\arm\stm32\serial.c> +OPTFFF 3,44,2,0,0,0,0,0,<..\..\libcpu\arm\stm32\context_rvds.S> +OPTFFF 3,45,2,570425344,0,0,0,0,<..\..\libcpu\arm\stm32\start_rvds.s> +OPTFFF 3,46,1,0,0,0,0,0,<..\..\libcpu\arm\stm32\fault.c> +OPTFFF 3,47,2,0,0,0,0,0,<..\..\libcpu\arm\stm32\fault_rvds.S> +OPTFFF 4,48,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\misc.c> +OPTFFF 4,49,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_adc.c> +OPTFFF 4,50,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_bkp.c> +OPTFFF 4,51,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_can.c> +OPTFFF 4,52,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_crc.c> +OPTFFF 4,53,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_dac.c> +OPTFFF 4,54,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_dbgmcu.c> +OPTFFF 4,55,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_dma.c> +OPTFFF 4,56,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_exti.c> +OPTFFF 4,57,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_flash.c> +OPTFFF 4,58,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_fsmc.c> +OPTFFF 4,59,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_gpio.c> +OPTFFF 4,60,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_i2c.c> +OPTFFF 4,61,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_iwdg.c> +OPTFFF 4,62,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_pwr.c> +OPTFFF 4,63,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_rcc.c> +OPTFFF 4,64,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_rtc.c> +OPTFFF 4,65,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_sdio.c> +OPTFFF 4,66,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_spi.c> +OPTFFF 4,67,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_tim.c> +OPTFFF 4,68,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_usart.c> +OPTFFF 4,69,1,0,0,0,0,0,<.\Libraries\STM32F10x_StdPeriph_Driver\src\stm32f10x_wwdg.c> +OPTFFF 5,70,1,0,0,0,0,0,<.\Libraries\CMSIS\Core\CM3\core_cm3.c> +OPTFFF 5,71,1,0,0,0,0,0,<.\Libraries\CMSIS\Core\CM3\system_stm32f10x.c> +OPTFFF 6,72,1,0,0,0,0,0,<..\..\finsh\finsh_compiler.c> +OPTFFF 6,73,1,0,0,0,0,0,<..\..\finsh\finsh_error.c> +OPTFFF 6,74,1,0,0,0,0,0,<..\..\finsh\finsh_heap.c> +OPTFFF 6,75,1,0,0,0,0,0,<..\..\finsh\finsh_init.c> +OPTFFF 6,76,1,0,0,0,0,0,<..\..\finsh\finsh_node.c> +OPTFFF 6,77,1,0,0,0,0,0,<..\..\finsh\finsh_ops.c> +OPTFFF 6,78,1,0,0,0,0,0,<..\..\finsh\finsh_parser.c> +OPTFFF 6,79,1,0,0,0,0,0,<..\..\finsh\finsh_token.c> +OPTFFF 6,80,1,0,0,0,0,0,<..\..\finsh\finsh_var.c> +OPTFFF 6,81,1,0,0,0,0,0,<..\..\finsh\finsh_vm.c> +OPTFFF 6,82,1,0,0,0,0,0,<..\..\finsh\shell.c> +OPTFFF 6,83,1,0,0,0,0,0,<..\..\finsh\symbol.c> +OPTFFF 6,84,1,285212672,0,0,0,0,<..\..\finsh\cmd.c> +OPTFFF 7,85,1,0,0,0,0,0,<..\..\filesystem\dfs\src\dfs_init.c> +OPTFFF 7,86,1,503316480,0,0,0,0,<..\..\filesystem\dfs\src\dfs_fs.c> +OPTFFF 7,87,1,0,0,0,0,0,<..\..\filesystem\dfs\src\dfs_raw.c> +OPTFFF 7,88,1,0,0,0,0,0,<..\..\filesystem\dfs\src\dfs_util.c> +OPTFFF 7,89,1,0,0,0,0,0,<..\..\filesystem\dfs\src\dfs_posix.c> +OPTFFF 7,90,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\dir.c> +OPTFFF 7,91,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\fat.c> +OPTFFF 7,92,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\file.c> +OPTFFF 7,93,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\fs.c> +OPTFFF 7,94,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\ls.c> +OPTFFF 7,95,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\time.c> +OPTFFF 7,96,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\ui.c> +OPTFFF 7,97,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\base\plibc.c> +OPTFFF 7,98,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\base\efs.c> +OPTFFF 7,99,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\base\extract.c> +OPTFFF 7,100,1,0,0,0,0,0,<..\..\filesystem\dfs\filesystems\efsl\src\base\partition.c> +OPTFFF 7,101,1,0,0,0,0,0,<..\..\filesystem\dfs\src\dfs_cache.c> +OPTFFF 8,102,1,0,0,0,0,0,<..\..\net\lwip\src\core\dhcp.c> +OPTFFF 8,103,1,0,0,0,0,0,<..\..\net\lwip\src\core\dns.c> +OPTFFF 8,104,1,0,0,0,0,0,<..\..\net\lwip\src\core\init.c> +OPTFFF 8,105,1,0,0,0,0,0,<..\..\net\lwip\src\core\netif.c> +OPTFFF 8,106,1,0,0,0,0,0,<..\..\net\lwip\src\core\pbuf.c> +OPTFFF 8,107,1,0,0,0,0,0,<..\..\net\lwip\src\core\raw.c> +OPTFFF 8,108,1,0,0,0,0,0,<..\..\net\lwip\src\core\stats.c> +OPTFFF 8,109,1,0,0,0,0,0,<..\..\net\lwip\src\core\sys.c> +OPTFFF 8,110,1,0,0,0,0,0,<..\..\net\lwip\src\core\tcp.c> +OPTFFF 8,111,1,0,0,0,0,0,<..\..\net\lwip\src\core\tcp_in.c> +OPTFFF 8,112,1,0,0,0,0,0,<..\..\net\lwip\src\core\tcp_out.c> +OPTFFF 8,113,1,0,0,0,0,0,<..\..\net\lwip\src\core\udp.c> +OPTFFF 8,114,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\autoip.c> +OPTFFF 8,115,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\icmp.c> +OPTFFF 8,116,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\igmp.c> +OPTFFF 8,117,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\inet.c> +OPTFFF 8,118,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\inet_chksum.c> +OPTFFF 8,119,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\ip.c> +OPTFFF 8,120,1,0,0,0,0,0,<..\..\net\lwip\src\core\ipv4\ip_addr.c> +OPTFFF 8,121,1,285212672,0,0,0,0,<..\..\net\lwip\src\core\ipv4\ip_frag.c> +OPTFFF 8,122,1,0,0,0,0,0,<..\..\net\lwip\src\core\snmp\msg_in.c> +OPTFFF 8,123,1,0,0,0,0,0,<..\..\net\lwip\src\core\snmp\msg_out.c> +OPTFFF 8,124,1,0,0,0,0,0,<..\..\net\lwip\src\api\api_lib.c> +OPTFFF 8,125,1,50331648,0,0,0,0,<..\..\net\lwip\src\api\api_msg.c> +OPTFFF 8,126,1,0,0,0,0,0,<..\..\net\lwip\src\api\err.c> +OPTFFF 8,127,1,0,0,0,0,0,<..\..\net\lwip\src\api\netbuf.c> +OPTFFF 8,128,1,0,0,0,0,0,<..\..\net\lwip\src\api\netdb.c> +OPTFFF 8,129,1,0,0,0,0,0,<..\..\net\lwip\src\api\netifapi.c> +OPTFFF 8,130,1,0,0,0,0,0,<..\..\net\lwip\src\api\tcpip.c> +OPTFFF 8,131,1,0,0,0,0,0,<..\..\net\lwip\src\netif\etharp.c> +OPTFFF 8,132,1,150994944,0,0,0,0,<..\..\net\lwip\src\netif\ethernetif.c> +OPTFFF 8,133,1,0,0,0,0,0,<..\..\net\lwip\src\netif\loopif.c> +OPTFFF 8,134,1,285212672,0,0,0,0,<..\..\net\lwip\src\arch\sys_arch_init.c> +OPTFFF 8,135,1,0,0,0,0,0,<..\..\net\lwip\src\arch\sys_arch.c> +OPTFFF 8,136,1,0,0,0,0,0,<..\..\net\lwip\src\api\sockets.c> +OPTFFF 8,137,1,0,0,0,0,0,<..\..\net\lwip\src\core\memp_tiny.c> +OPTFFF 9,138,1,268435456,0,0,0,0,<.\mp3\mp3dec.c> +OPTFFF 9,139,1,0,0,0,0,0,<.\mp3\mp3tabs.c> +OPTFFF 9,140,1,0,0,0,0,0,<.\mp3\real\bitstream.c> +OPTFFF 9,141,1,83886080,0,0,0,0,<.\mp3\real\buffers.c> +OPTFFF 9,142,1,0,0,0,0,0,<.\mp3\real\dct32.c> +OPTFFF 9,143,1,0,0,0,0,0,<.\mp3\real\dequant.c> +OPTFFF 9,144,1,0,0,0,0,0,<.\mp3\real\dqchan.c> +OPTFFF 9,145,1,0,0,0,0,0,<.\mp3\real\huffman.c> +OPTFFF 9,146,1,0,0,0,0,0,<.\mp3\real\hufftabs.c> +OPTFFF 9,147,1,0,0,0,0,0,<.\mp3\real\imdct.c> +OPTFFF 9,148,1,0,0,0,0,0,<.\mp3\real\scalfact.c> +OPTFFF 9,149,1,0,0,0,0,0,<.\mp3\real\stproc.c> +OPTFFF 9,150,1,0,0,0,0,0,<.\mp3\real\subband.c> +OPTFFF 9,151,1,0,0,0,0,0,<.\mp3\real\trigtabs.c> +OPTFFF 9,152,2,0,0,0,0,0,<.\mp3\real\arm\asmpoly_thumb2.s> +OPTFFF 9,153,2,0,0,0,0,0,<.\mp3\real\arm\asmmisc.s> +OPTFFF 10,154,1,0,0,0,0,0,<..\..\rtgui\common\rtgui_object.c> +OPTFFF 10,155,1,0,0,0,0,0,<..\..\rtgui\common\rtgui_system.c> +OPTFFF 10,156,1,620756992,0,0,0,0,<..\..\rtgui\common\rtgui_theme.c> +OPTFFF 10,157,1,0,0,0,0,0,<..\..\rtgui\common\asc12font.c> +OPTFFF 10,158,1,402653184,0,0,0,0,<..\..\rtgui\common\asc16font.c> +OPTFFF 10,159,1,0,0,0,0,0,<..\..\rtgui\common\color.c> +OPTFFF 10,160,1,0,0,0,0,0,<..\..\rtgui\common\dc.c> +OPTFFF 10,161,1,0,0,0,0,0,<..\..\rtgui\common\dc_buffer.c> +OPTFFF 10,162,1,0,0,0,0,0,<..\..\rtgui\common\dc_hw.c> +OPTFFF 10,163,1,16777216,0,0,0,0,<..\..\rtgui\common\filerw.c> +OPTFFF 10,164,1,0,0,0,0,0,<..\..\rtgui\common\font.c> +OPTFFF 10,165,1,469762048,0,0,0,0,<..\..\rtgui\common\image.c> +OPTFFF 10,166,1,0,0,0,0,0,<..\..\rtgui\common\image_xpm.c> +OPTFFF 10,167,1,0,0,0,0,0,<..\..\rtgui\common\image_hdc.c> +OPTFFF 10,168,1,0,0,0,0,0,<..\..\rtgui\common\region.c> +OPTFFF 10,169,1,100663296,0,0,0,0,<..\..\rtgui\server\server.c> +OPTFFF 10,170,1,0,0,0,0,0,<..\..\rtgui\server\driver.c> +OPTFFF 10,171,1,335544320,0,0,0,0,<..\..\rtgui\server\panel.c> +OPTFFF 10,172,1,0,0,0,0,0,<..\..\rtgui\widgets\widget.c> +OPTFFF 10,173,1,16777216,0,0,0,0,<..\..\rtgui\widgets\window.c> +OPTFFF 10,174,1,0,0,0,0,0,<..\..\rtgui\widgets\workbench.c> +OPTFFF 10,175,1,16777216,0,0,0,0,<..\..\rtgui\widgets\view.c> +OPTFFF 10,176,1,0,0,0,0,0,<..\..\rtgui\widgets\box.c> +OPTFFF 10,177,1,0,0,0,0,0,<..\..\rtgui\widgets\button.c> +OPTFFF 10,178,1,0,0,0,0,0,<..\..\rtgui\widgets\container.c> +OPTFFF 10,179,1,0,0,0,0,0,<..\..\rtgui\widgets\iconbox.c> +OPTFFF 10,180,1,0,0,0,0,0,<..\..\rtgui\widgets\label.c> +OPTFFF 10,181,1,0,0,0,0,0,<..\..\rtgui\widgets\textbox.c> +OPTFFF 10,182,1,0,0,0,0,0,<..\..\rtgui\widgets\title.c> +OPTFFF 10,183,1,67108864,0,0,0,0,<..\..\rtgui\widgets\toplevel.c> +OPTFFF 10,184,1,0,0,0,0,0,<..\..\rtgui\server\mouse.c> +OPTFFF 10,185,1,0,0,0,0,0,<..\..\rtgui\server\topwin.c> +OPTFFF 10,186,1,0,0,0,0,0,<..\..\rtgui\common\caret.c> +OPTFFF 10,187,1,0,0,0,0,0,<..\..\rtgui\common\font_hz_file.c> +OPTFFF 10,188,1,0,0,0,0,0,<..\..\rtgui\common\hz16font.c> +OPTFFF 10,189,1,0,0,0,0,0,<..\..\rtgui\common\hz12font.c> TARGOPT 1, (RT-Thread STM32 Radio) @@ -224,11 +229,13 @@ TARGOPT 1, (RT-Thread STM32 Radio) OPTKEY 0,(ARMDBGFLAGS)() OPTKEY 0,(DLGUARM)((105=-1,-1,-1,-1,0)(106=-1,-1,-1,-1,0)(107=-1,-1,-1,-1,0)) OPTKEY 0,(JL2CM3)(-U20090110 -O718 -S8 -C0 -JU1 -JI127.0.0.1 -JP0 -N00("ARM CoreSight SW-DP") -D00(00000000) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO27 -FD20000000 -FC800 -FN1 -FF0STM32F10x_512 -FS08000000 -FL080000) - OPTBB 0,0,590,1,134251230,0,0,0,0,1,()() - OPTBB 1,0,331,1,134431418,0,0,0,0,1,()() + OPTBB 0,0,590,1,134245962,0,0,0,0,1,()() + OPTBB 1,0,129,1,134325656,0,0,0,0,1,()() + OPTBB 2,0,41,1,134354810,0,0,0,0,1,()() + OPTBB 3,0,66,1,134343178,0,0,0,0,1,()() OPTMM 1,8,(0x20005f34) OPTMM 2,8,(mimeBuffer) - OPTDF 0x86 + OPTDF 0x82 OPTLE <> OPTLC <> EndOpt diff --git a/bsp/stm32_radio/project.Uv2 b/bsp/stm32_radio/project.Uv2 index c858269c8..30c624c7a 100644 --- a/bsp/stm32_radio/project.Uv2 +++ b/bsp/stm32_radio/project.Uv2 @@ -34,10 +34,12 @@ File 1,1,<.\lcd.c> File 1,1,<.\mp3.c> File 1,1,<.\wav.c> File 1,1,<.\netbuffer.c> -File 1,1,<.\gui.c> File 1,1,<.\key.c> File 1,1,<.\info.c> -File 1,1,<.\today.c> +File 1,1, +File 1,1,<.\filelist.c> +File 1,1,<.\device_info.c> +File 1,1,<.\listview.c> File 2,1,<..\..\src\clock.c> File 2,1,<..\..\src\idle.c> File 2,1,<..\..\src\ipc.c> @@ -198,6 +200,9 @@ File 10,1,<..\..\rtgui\widgets\toplevel.c> File 10,1,<..\..\rtgui\server\mouse.c> File 10,1,<..\..\rtgui\server\topwin.c> File 10,1,<..\..\rtgui\common\caret.c> +File 10,1,<..\..\rtgui\common\font_hz_file.c> +File 10,1,<..\..\rtgui\common\hz16font.c> +File 10,1,<..\..\rtgui\common\hz12font.c> Options 1,0,0 // Target 'RT-Thread STM32 Radio' @@ -312,93 +317,3 @@ Options 1,9,0 // Group 'mp3' ADSAINCD () EndOpt -Options 1,10,0 // Group 'RTGUI' - PropFld { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } - IncBld=2 - AlwaysBuild=2 - GenAsm=2 - AsmAsm=2 - PublicsOnly=2 - StopCode=11 - CustArgs () - LibMods () - ADSCCFLG { 2,84,85,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } - ADSCMISC (--gnu) - ADSCDEFN () - ADSCUDEF () - ADSCINCD () - ADSASFLG { 170,42,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } - ADSAMISC () - ADSADEFN () - ADSAUDEF () - ADSAINCD () -EndOpt - -Options 1,1,21 // File 'gui.c' - PropFld { 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } - IncBld=2 - AlwaysBuild=2 - GenAsm=2 - AsmAsm=2 - PublicsOnly=2 - StopCode=11 - CustArgs () - LibMods () - ADSCCFLG { 2,84,85,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } - ADSCMISC (--gnu) - ADSCDEFN () - ADSCUDEF () - ADSCINCD () -EndOpt - -Options 1,1,22 // File 'key.c' - PropFld { 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } - IncBld=2 - AlwaysBuild=2 - GenAsm=2 - AsmAsm=2 - PublicsOnly=2 - StopCode=11 - CustArgs () - LibMods () - ADSCCFLG { 2,84,85,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } - ADSCMISC (--gnu) - ADSCDEFN () - ADSCUDEF () - ADSCINCD () -EndOpt - -Options 1,1,23 // File 'info.c' - PropFld { 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } - IncBld=2 - AlwaysBuild=2 - GenAsm=2 - AsmAsm=2 - PublicsOnly=2 - StopCode=11 - CustArgs () - LibMods () - ADSCCFLG { 2,84,85,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } - ADSCMISC (--gnu) - ADSCDEFN () - ADSCUDEF () - ADSCINCD () -EndOpt - -Options 1,1,24 // File 'today.c' - PropFld { 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } - IncBld=2 - AlwaysBuild=2 - GenAsm=2 - AsmAsm=2 - PublicsOnly=2 - StopCode=11 - CustArgs () - LibMods () - ADSCCFLG { 2,84,85,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } - ADSCMISC (--gnu) - ADSCDEFN () - ADSCUDEF () - ADSCINCD () -EndOpt - diff --git a/bsp/stm32_radio/rtconfig.h b/bsp/stm32_radio/rtconfig.h index b47ea2f73..d4d2ee94c 100644 --- a/bsp/stm32_radio/rtconfig.h +++ b/bsp/stm32_radio/rtconfig.h @@ -80,12 +80,13 @@ #define RT_USING_DFS #define RT_USING_DFS_EFSL -// #define RT_USING_DFS_ELMFAT +// #define RT_USING_DFS_ELMFAT +#define DFS_EFLS_USING_STATIC_CACHE /* SECTION: DFS options */ /* the max number of mounted filesystem */ #define DFS_FILESYSTEMS_MAX 1 /* the max number of opened files */ -#define DFS_FD_MAX 2 +#define DFS_FD_MAX 8 /* the max number of cached sector */ #define DFS_CACHE_MAX_NUM 4 @@ -118,7 +119,7 @@ /* #define RT_LWIP_SNMP */ /* Using DHCP */ -/* #define RT_LWIP_DHCP */ +#define RT_LWIP_DHCP /* Using DNS */ #define RT_LWIP_DNS diff --git a/bsp/stm32_radio/sdcard.c b/bsp/stm32_radio/sdcard.c index c60c30ae4..c9e94c244 100644 --- a/bsp/stm32_radio/sdcard.c +++ b/bsp/stm32_radio/sdcard.c @@ -3061,7 +3061,7 @@ void rt_hw_sdcard_init() SD_Error status; rt_uint8_t *sector; - SD_EnableWideBusOperation(SDIO_BusWide_4b); + SD_EnableWideBusOperation(SDIO_BusWide_1b); status = SD_GetCardInfo(&SDCardInfo); if (status != SD_OK) goto __return; diff --git a/bsp/stm32_radio/startup.c b/bsp/stm32_radio/startup.c index 34e466628..af917f4a4 100644 --- a/bsp/stm32_radio/startup.c +++ b/bsp/stm32_radio/startup.c @@ -103,13 +103,6 @@ void rtthread_startup(void) /* init scheduler system */ rt_system_scheduler_init(); -#ifdef RT_USING_LWIP - eth_system_device_init(); - - /* register ethernetif device */ - rt_hw_dm9000_init(); -#endif - wm8753_hw_init(); /* init hardware serial device */ diff --git a/bsp/stm32_radio/wav.c b/bsp/stm32_radio/wav.c index 7ff1af5a1..18105834e 100644 --- a/bsp/stm32_radio/wav.c +++ b/bsp/stm32_radio/wav.c @@ -36,6 +36,7 @@ void wav(char* filename) buf = sbuf_alloc(); len = read(fd, (char*)buf, block_size); if (len > 0) rt_device_write(device, 0, buf, len); + else sbuf_release(buf); } while (len != 0); /* close device and file */ diff --git a/net/lwip/src/arch/sys_arch_init.c b/net/lwip/src/arch/sys_arch_init.c index febab3c3f..04d47e35c 100644 --- a/net/lwip/src/arch/sys_arch_init.c +++ b/net/lwip/src/arch/sys_arch_init.c @@ -42,7 +42,8 @@ void lwip_sys_init() /* use DHCP client */ dhcp_start(netif_default); - while (1) { + while (netif_default->ip_addr.addr == 0) + { rt_thread_delay(DHCP_FINE_TIMER_MSECS); dhcp_fine_tmr(); @@ -52,7 +53,13 @@ void lwip_sys_init() dhcp_coarse_tmr(); mscnt = 0; } - } + } + + rt_kprintf("Acquired IP address from DHCP server:"); + rt_kprintf("%d.%d.%d.%d\n", netif_default->ip_addr.addr & 0xff, + (netif_default->ip_addr.addr>>8) & 0xff, + (netif_default->ip_addr.addr>>16) & 0xff, + (netif_default->ip_addr.addr>>24) & 0xff); #endif #if defined(RT_USING_FINSH) && (LWIP_STATS_DISPLAY) diff --git a/rtgui/common/asc16font.c b/rtgui/common/asc16font.c index a2998099d..4af71da2d 100644 --- a/rtgui/common/asc16font.c +++ b/rtgui/common/asc16font.c @@ -12,7 +12,7 @@ * 2009-10-16 Bernard first version */ #include - + #ifdef RTGUI_USING_FONT16 const unsigned char asc16_font[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -292,4 +292,4 @@ struct rtgui_font rtgui_font_asc16 = }; /* size = 4096 bytes */ -#endif +#endif diff --git a/rtgui/common/dc.c b/rtgui/common/dc.c index 1987d08bd..b8e06bf17 100644 --- a/rtgui/common/dc.c +++ b/rtgui/common/dc.c @@ -12,10 +12,10 @@ * 2009-10-16 Bernard first version */ #include -#include +#include -#include /* for strlen */ -#include /* fir qsort */ +#include /* for strlen */ +#include /* fir qsort */ /* for sin/cos etc */ #include diff --git a/rtgui/common/dc_buffer.c b/rtgui/common/dc_buffer.c index a04fcb9c7..ebb182c81 100644 --- a/rtgui/common/dc_buffer.c +++ b/rtgui/common/dc_buffer.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include struct rtgui_dc_buffer { diff --git a/rtgui/common/dc_hw.c b/rtgui/common/dc_hw.c index b5d8be3b6..ab1b88519 100644 --- a/rtgui/common/dc_hw.c +++ b/rtgui/common/dc_hw.c @@ -13,7 +13,7 @@ */ #include #include -#include +#include #include #include #include diff --git a/rtgui/common/filerw.c b/rtgui/common/filerw.c index a7656d853..1e03dda76 100644 --- a/rtgui/common/filerw.c +++ b/rtgui/common/filerw.c @@ -15,7 +15,7 @@ #include #include -#ifdef RT_USING_DFS_FILERW +#ifdef RTGUI_USING_DFS_FILERW #include /* standard file read/write */ @@ -95,7 +95,7 @@ static int stdio_close(struct rtgui_filerw *context) return -1; } -#elif RT_USING_STDIO_FILERW +#elif defined(RTGUI_USING_STDIO_FILERW) #include /* standard file read/write */ @@ -302,26 +302,26 @@ rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context) } /* file read/write public interface */ -#ifdef RT_USING_DFS_FILERW -static int parse_mode(const char *mode) -{ - int f=0; - - for (;;) - { - switch (*mode) - { - case 0: return f; - case 'b': break; - case 'r': f=O_RDONLY; break; - case 'w': f=O_WRONLY|O_CREAT|O_TRUNC; break; - case 'a': f=O_WRONLY|O_CREAT|O_APPEND; break; - case '+': f=(f&(~O_WRONLY))|O_RDWR; break; - } - - ++mode; - } -} +#ifdef RTGUI_USING_DFS_FILERW +static int parse_mode(const char *mode) +{ + int f=0; + + for (;;) + { + switch (*mode) + { + case 0: return f; + case 'b': break; + case 'r': f=O_RDONLY; break; + case 'w': f=O_WRONLY|O_CREAT|O_TRUNC; break; + case 'a': f=O_WRONLY|O_CREAT|O_APPEND; break; + case '+': f=(f&(~O_WRONLY))|O_RDWR; break; + } + + ++mode; + } +} struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode) { @@ -352,7 +352,7 @@ struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* return &(rw->parent); } -#elif RT_USING_STDIO_FILERW +#elif defined(RTGUI_USING_STDIO_FILERW) struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode) { FILE *fp; diff --git a/rtgui/common/font_hz_file.c b/rtgui/common/font_hz_file.c index 6c2967317..11ee300f8 100644 --- a/rtgui/common/font_hz_file.c +++ b/rtgui/common/font_hz_file.c @@ -5,6 +5,7 @@ #include #include #include +#ifdef RTGUI_USING_HZ_FILE #include #define HZ_CACHE_MAX 64 @@ -64,7 +65,7 @@ static rt_uint8_t* _font_cache_get(struct rtgui_hz_file_font* font, rt_uint16_t } /* insert to cache */ - SPLAY_INSERT(cache_tree, &(font->cache_root), cache); + SPLAY_INSERT(cache_tree, &(font->cache_root), cache); font->cache_size ++; if (font->cache_size > HZ_CACHE_MAX) @@ -75,7 +76,7 @@ static rt_uint8_t* _font_cache_get(struct rtgui_hz_file_font* font, rt_uint16_t while (SPLAY_LEFT(left, hz_node) != RT_NULL) left = SPLAY_LEFT(left, hz_node); /* remove the left node */ - SPLAY_REMOVE(cache_tree, &(font->cache_root), left); + SPLAY_REMOVE(cache_tree, &(font->cache_root), left); font->cache_size --; } @@ -142,3 +143,4 @@ static void rtgui_hz_file_font_get_metrics(struct rtgui_font* font, const rt_uin rect->x2 = (rt_int16_t)(hz_file_font->font_size/2 * rt_strlen((const char*)text)); rect->y2 = hz_file_font->font_size; } +#endif diff --git a/rtgui/common/hz12font.c b/rtgui/common/hz12font.c index e51ed16e4..5ea8bf57a 100644 --- a/rtgui/common/hz12font.c +++ b/rtgui/common/hz12font.c @@ -1,5 +1,5 @@ #include - + #ifdef RTGUI_USING_FONT12 #ifndef RTGUI_USING_HZ_FILE const unsigned char hz12_font[] = { @@ -12295,21 +12295,21 @@ struct rtgui_font rtgui_font_hz12 = #else const struct rtgui_hz_file_font hz12 = { - {RT_NULL}, /* cache root */ - 0, /* cache_size */ - 12, /* font_size */ - -1, /* fd */ - "/resource/hz12" /* font_fn */ + {RT_NULL}, /* cache root */ + 0, /* cache size */ + 12, /* font size */ + 32, /* font data size */ + -1, /* fd */ + "/resource/hzk12.fnt" /* font_fn */ }; -extern struct rtgui_hz_file_font_engine hz_file_font_engine; struct rtgui_font rtgui_font_hz12 = { "hz", /* family */ 12, /* height */ 1, /* refer count */ - &hz_file_font_engine,/* font engine */ + &rtgui_hz_file_font_engine,/* font engine */ (void*)&hz12, /* font private data */ }; #endif -#endif +#endif diff --git a/rtgui/common/hz16font.c b/rtgui/common/hz16font.c index 8f316f13f..07c8e3f88 100644 --- a/rtgui/common/hz16font.c +++ b/rtgui/common/hz16font.c @@ -1,4 +1,4 @@ -#include +#include #ifdef RTGUI_USING_FONT16 #ifndef RTGUI_USING_HZ_FILE @@ -16740,7 +16740,7 @@ const struct rtgui_font_bitmap hz16 = }; extern struct rtgui_font_engine hz_bmp_font_engine; -const struct rtgui_font rtgui_font_hz16 = +struct rtgui_font rtgui_font_hz16 = { "hz", /* family */ 16, /* height */ @@ -16755,7 +16755,7 @@ struct rtgui_hz_file_font hz16 = { {RT_NULL}, /* cache root */ 0, /* cache size */ - 16, /* font size */ + 16, /* font size */ 32, /* font data size */ -1, /* fd */ "/resource/hzk16.fnt" /* font_fn */ @@ -16770,4 +16770,4 @@ struct rtgui_font rtgui_font_hz16 = (void*)&hz16, /* font private data */ }; #endif -#endif +#endif diff --git a/rtgui/common/image.c b/rtgui/common/image.c index 817120d7d..64e2c992e 100644 --- a/rtgui/common/image.c +++ b/rtgui/common/image.c @@ -12,11 +12,11 @@ * 2009-10-16 Bernard first version */ #include -#include +#include -#include +#include #include -#include +#include #include @@ -37,7 +37,7 @@ void rtgui_system_image_init(void) { /* always support XPM image */ rtgui_image_xpm_init(); - rtgui_image_hdc_init(); + rtgui_image_hdc_init(); #ifdef RTGUI_IMAGE_BMP rtgui_image_bmp_init(); diff --git a/rtgui/common/image_hdc.c b/rtgui/common/image_hdc.c index 310725db4..db5ad6b2d 100644 --- a/rtgui/common/image_hdc.c +++ b/rtgui/common/image_hdc.c @@ -77,7 +77,7 @@ static rt_bool_t rtgui_image_hdc_load(struct rtgui_image* image, struct rtgui_fi rtgui_filerw_read(file, (char*)&header, 1, sizeof(header)); /* set image information */ - image->w = header[1]; image->h = header[2]; + image->w = (rt_uint16_t)header[1]; image->h = (rt_uint16_t)header[2]; image->engine = &rtgui_image_hdc_engine; image->data = hdc; hdc->filerw = file; @@ -104,8 +104,8 @@ static rt_bool_t rtgui_image_hdc_load(struct rtgui_image* image, struct rtgui_fi else { hdc->pixels = RT_NULL; - } - + } + return RT_TRUE; } @@ -129,18 +129,60 @@ static void rtgui_image_hdc_unload(struct rtgui_image* image) } } +static void rtgui_image_hdc_raw_hline(struct rtgui_dc_hw* dc, rt_uint8_t* raw_ptr, int x1, int x2, int y) +{ + register rt_base_t index; + register rt_base_t bpp; + + /* convert logic to device */ + x1 = x1 + dc->owner->extent.x1; + x2 = x2 + dc->owner->extent.x1; + y = y + dc->owner->extent.y1; + + bpp = dc->device->byte_per_pixel; + if (dc->owner->clip.data == RT_NULL) + { + rtgui_rect_t* prect; + + prect = &(dc->owner->clip.extents); + + /* calculate hline intersect */ + if (prect->y1 > y || prect->y2 <= y ) return; + if (prect->x2 <= x1 || prect->x1 > x2) return; + + if (prect->x1 > x1) x1 = prect->x1; + if (prect->x2 < x2) x2 = prect->x2; + + /* draw raw hline */ + dc->device->draw_raw_hline(raw_ptr, x1, x2, y); + } + else for (index = 0; index < rtgui_region_num_rects(&(dc->owner->clip)); index ++) + { + rtgui_rect_t* prect; + register rt_base_t draw_x1, draw_x2; + + prect = ((rtgui_rect_t *)(dc->owner->clip.data + index + 1)); + draw_x1 = x1; + draw_x2 = x2; + + /* calculate hline clip */ + if (prect->y1 > y || prect->y2 <= y ) continue; + if (prect->x2 <= x1 || prect->x1 > x2) continue; + + if (prect->x1 > x1) draw_x1 = prect->x1; + if (prect->x2 < x2) draw_x2 = prect->x2; + + /* draw raw hline */ + dc->device->draw_raw_hline(raw_ptr + (draw_x1 - x1) * bpp, draw_x1, draw_x2, y); + } +} + static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* dst_rect) { rt_uint16_t y, w, h; - rtgui_color_t foreground; struct rtgui_image_hdc* hdc; - rt_uint16_t rect_pitch, hw_pitch; - rtgui_rect_t dc_rect, _rect, *rect; - RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL); - - _rect = *dst_rect; - rect = &_rect; + RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL); /* this dc is not visible */ if (dc->get_visible(dc) != RT_TRUE) return; @@ -148,107 +190,47 @@ static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc, hdc = (struct rtgui_image_hdc*) image->data; RT_ASSERT(hdc != RT_NULL); - /* transfer logic coordinate to physical coordinate */ - if (dc->type == RTGUI_DC_HW) - { - dc_rect = ((struct rtgui_dc_hw*)dc)->owner->extent; - } - else rtgui_dc_get_rect(dc, &dc_rect); - rtgui_rect_moveto(rect, dc_rect.x1, dc_rect.y1); + if (dc->type != RTGUI_DC_HW) return; /* the minimum rect */ - if (image->w < rtgui_rect_width(*rect)) w = image->w; - else w = rtgui_rect_width(*rect); - if (image->h < rtgui_rect_height(*rect)) h = image->h; - else h = rtgui_rect_height(*rect); - - /* get rect pitch */ - rect_pitch = w * hdc->byte_per_pixel; - hw_pitch = hdc->hw_driver->width * hdc->hw_driver->byte_per_pixel; - - /* save foreground color */ - foreground = rtgui_dc_get_color(dc); + if (image->w < rtgui_rect_width(*dst_rect)) w = image->w; + else w = rtgui_rect_width(*dst_rect); + if (image->h < rtgui_rect_height(*dst_rect)) h = image->h; + else h = rtgui_rect_height(*dst_rect); if (hdc->pixels != RT_NULL) { - if (hdc->hw_driver->get_framebuffer() != RT_NULL) + rt_uint8_t* ptr; + + /* get pixel pointer */ + ptr = hdc->pixels; + + for (y = 0; y < h; y ++) { - rt_uint8_t* rect_ptr; - rt_uint8_t* hw_ptr; - - /* get pixel pointer */ - hw_ptr = hdc->hw_driver->get_framebuffer(); - rect_ptr = hdc->pixels; - - /* move hardware pixel pointer */ - hw_ptr += rect->y1 * hdc->pitch + rect->x1 * hdc->byte_per_pixel; - - for (y = 0; y < h; y ++) - { - rt_memcpy(hw_ptr, rect_ptr, rect_pitch); - hw_ptr += hw_pitch; - rect_ptr += rect_pitch; - } - } - else - { - rt_uint8_t* rect_ptr; - - /* get pixel pointer */ - rect_ptr = hdc->pixels; - - for (y = 0; y < h; y ++) - { - hdc->hw_driver->draw_raw_hline(rect_ptr, rect->x1, rect->x1 + w, rect->y1 + y); - rect_ptr += hdc->pitch; - } + rtgui_image_hdc_raw_hline((struct rtgui_dc_hw*)dc, ptr, dst_rect->x1, dst_rect->x2, dst_rect->y1 + y); + ptr += hdc->pitch; } } else { - rt_uint8_t* rect_ptr; - rect_ptr = rtgui_malloc(hdc->pitch); - if (rect_ptr == RT_NULL) return; /* no memory */ + rt_uint8_t* ptr; + ptr = rtgui_malloc(hdc->pitch); + if (ptr == RT_NULL) return; /* no memory */ /* seek to the begin of pixel data */ rtgui_filerw_seek(hdc->filerw, hdc->pixel_offset, RTGUI_FILE_SEEK_SET); - if (hdc->hw_driver->get_framebuffer() != RT_NULL) + for (y = 0; y < h; y ++) { - rt_uint8_t* hw_ptr; + /* read pixel data */ + if (rtgui_filerw_read(hdc->filerw, ptr, 1, hdc->pitch) != hdc->pitch) + break; /* read data failed */ - /* get pixel pointer */ - hw_ptr = hdc->hw_driver->get_framebuffer(); - /* move hardware pixel pointer */ - hw_ptr += rect->y1 * hdc->pitch + rect->x1 * hdc->byte_per_pixel; - - for (y = 0; y < h; y ++) - { - /* read pixel data */ - if (rtgui_filerw_read(hdc->filerw, rect_ptr, 1, hdc->pitch) != hdc->pitch) - break; /* read data failed */ - - rt_memcpy(hw_ptr, rect_ptr, rect_pitch); - hw_ptr += hw_pitch; - } - } - else - { - for (y = 0; y < h; y ++) - { - /* read pixel data */ - if (rtgui_filerw_read(hdc->filerw, rect_ptr, 1, hdc->pitch) != hdc->pitch) - break; /* read data failed */ - - hdc->hw_driver->draw_raw_hline(rect_ptr, rect->x1, rect->x1 + w, rect->y1 + y); - } + rtgui_image_hdc_raw_hline((struct rtgui_dc_hw*)dc, ptr, dst_rect->x1, dst_rect->x1 + w, dst_rect->y1 + y); } - rtgui_free(rect_ptr); + rtgui_free(ptr); } - - /* restore foreground */ - rtgui_dc_set_color(dc, foreground); } void rtgui_image_hdc_init() diff --git a/rtgui/common/image_png.c b/rtgui/common/image_png.c index 95dc81750..ae9135c9f 100644 --- a/rtgui/common/image_png.c +++ b/rtgui/common/image_png.c @@ -199,8 +199,8 @@ static rt_bool_t rtgui_image_png_load(struct rtgui_image* image, struct rtgui_fi else { png->pixels = RT_NULL; - } - + } + return RT_TRUE; } diff --git a/rtgui/common/image_xpm.c b/rtgui/common/image_xpm.c index 4b171fd67..620002399 100644 --- a/rtgui/common/image_xpm.c +++ b/rtgui/common/image_xpm.c @@ -565,7 +565,7 @@ color_none: } } - free_colorhash(colors_table); + free_colorhash(colors_table); rtgui_filerw_close(file); return RT_TRUE; diff --git a/rtgui/common/rtgui_object.c b/rtgui/common/rtgui_object.c index a0f0d71fb..4bbc221c1 100644 --- a/rtgui/common/rtgui_object.c +++ b/rtgui/common/rtgui_object.c @@ -13,7 +13,7 @@ */ #include -#include +#include static void _rtgui_object_constructor(rtgui_object_t *object) { diff --git a/rtgui/common/rtgui_system.c b/rtgui/common/rtgui_system.c index 60808da44..3ee1e8ff1 100644 --- a/rtgui/common/rtgui_system.c +++ b/rtgui/common/rtgui_system.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,9 @@ void rtgui_system_server_init() /* init rtgui_thread */ rtgui_thread_system_init(); + /* init theme */ + rtgui_system_theme_init(); + /* init image */ rtgui_system_image_init(); /* init font */ @@ -257,7 +261,6 @@ rtgui_thread_t* rtgui_thread_register(rt_thread_t tid, rt_mq_t mq) thread->tid = tid; thread->mq = mq; thread->widget = RT_NULL; - thread->is_quit = RT_FALSE; /* take semaphore */ rt_sem_take(&_rtgui_thread_hash_semaphore, RT_WAITING_FOREVER); diff --git a/rtgui/common/rtgui_theme.c b/rtgui/common/rtgui_theme.c index a99030219..b7d34966c 100644 --- a/rtgui/common/rtgui_theme.c +++ b/rtgui/common/rtgui_theme.c @@ -1,454 +1,496 @@ -/* - * File : rtgui_theme.c - * This file is part of RTGUI in RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-04 Bernard first version - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define WINTITLE_CB_WIDTH 14 -#define WINTITLE_CB_HEIGHT 14 - -static const rt_uint8_t *close_unpressed_xpm[] = { - "14 14 55 1", - " c None", - ". c #DCDFEA", - "+ c #A4ADD3", - "@ c #8F9ACA", - "# c #98A2CD", - "$ c #D2D6E6", - "% c #F7F7F7", - "& c #F6F6F6", - "* c #B9C1D0", - "= c #7A8AAA", - "- c #D6DAE2", - "; c #D8DCE3", - "> c #7485A5", - ", c #455C89", - "' c #516690", - ") c #D3D8E0", - "! c #536891", - "~ c #6D7FA1", - "{ c #F5F5F5", - "] c #D1D6DF", - "^ c #D2D7DF", - "/ c #D5D9E1", - "( c #4E648E", - "_ c #CFD4DE", - ": c #F4F4F4", - "< c #D0D5DE", - "[ c #CED3DD", - "} c #F3F3F3", - "| c #CFD4DD", - "1 c #CDD2DC", - "2 c #F2F2F2", - "3 c #D3D7DF", - "4 c #526790", - "5 c #D0D5DD", - "6 c #F1F1F1", - "7 c #D2D6DE", - "8 c #CFD4DC", - "9 c #F0F0F0", - "0 c #D1D5DD", - "a c #C9CED8", - "b c #CDD2DB", - "c c #50658F", - "d c #CED3DB", - "e c #7283A3", - "f c #6E80A2", - "g c #EFEFEF", - "h c #B2BACA", - "i c #7081A2", - "j c #C8CDD7", - "k c #CCD1DA", - "l c #ACB5C7", - "m c #D0D4E2", - "n c #EEEEEE", - "o c #D2D5E3", - "p c #97A1CC", - ".+@@@@@@@@@@+.", - "#$%%%%%%%%%%$#", - "@&*=-&&&&;=*&@", - "@&>,')&&-!,~&@", - "@{]','^/!,(_{@", - "@::<','!,([::@", - "@}}}|',,(1}}}@", - "@22234,,'5222@", - "@6674,(','866@", - "@904,(abc,cd9@", - "@9e,(a99bc,f9@", - "@ghijggggkelg@", - "#mnnnnnnnnnnm#", - "op@@@@@@@@@@po"}; - -static const rt_uint8_t *close_pressed_xpm[] = { - "14 14 66 1", - " c None", - ". c #CED4EE", - "+ c #7E90DD", - "@ c #6076D7", - "# c #6C80D9", - "$ c #BFC8EA", - "% c #F2F3F5", - "& c #F0F2F3", - "* c #A5B6D7", - "= c #587ABB", - "- c #C9D3E4", - "; c #CBD5E4", - "> c #EEF0F2", - ", c #5073B7", - "' c #1746A3", - ") c #2551A8", - "! c #C5CFE2", - "~ c #C8D1E3", - "{ c #2853A8", - "] c #496DB4", - "^ c #ECEEF1", - "/ c #C0CCE0", - "( c #C3CEE1", - "_ c #C6D0E2", - ": c #224FA7", - "< c #BEC9DF", - "[ c #EAECF0", - "} c #BFCAE0", - "| c #2551A7", - "1 c #224EA7", - "2 c #BCC8DF", - "3 c #E8EBEE", - "4 c #BDCADE", - "5 c #BAC7DD", - "6 c #E6E9ED", - "7 c #C1CBDF", - "8 c #2753A8", - "9 c #BECADE", - "0 c #E4E7EB", - "a c #BFCADD", - "b c #224EA6", - "c c #BDC8DC", - "d c #E1E5EA", - "e c #2752A8", - "f c #B3C0D9", - "g c #B8C5DB", - "h c #2451A7", - "i c #BAC6DB", - "j c #DFE2E8", - "k c #4C70B4", - "l c #B2BED8", - "m c #B6C2D9", - "n c #2450A7", - "o c #486BB3", - "p c #DCE0E7", - "q c #96A8CE", - "r c #496CB3", - "s c #AFBCD7", - "t c #B4C1D8", - "u c #4B6FB4", - "v c #8EA4CC", - "w c #6C80D8", - "x c #B4BEDF", - "y c #DADEE5", - "z c #B5BEDE", - "A c #6A7ED7", - ".+@@@@@@@@@@+.", - "#$%%%%%%%%%%$#", - "@&*=-&&&&;=*&@", - "@>,')!>>~{']>@", - "@^/)')(_{':<^@", - "@[[}|'|{'12[[@", - "@3334|''15333@", - "@66678''|9666@", - "@00a8'b|'|c00@", - "@dce'bfgh'hid@", - "@jk'bljjmn'oj@", - "@pqrspppptuvp@", - "wxyyyyyyyyyyxw", - "zA@@@@@@@@@@Az"}; - -static rtgui_image_t* close_pressed = RT_NULL; -static rtgui_image_t* close_unpressed = RT_NULL; - -/* window drawing */ -void rtgui_theme_draw_win(struct rtgui_topwin* win) -{ - struct rtgui_dc* dc; - rtgui_rect_t rect; - - /* init close box image */ - if (close_pressed == RT_NULL) - close_pressed = rtgui_image_create_from_mem("xpm", - (const rt_uint8_t*)close_pressed_xpm, sizeof(close_pressed_xpm)); - if (close_unpressed == RT_NULL) - close_unpressed = rtgui_image_create_from_mem("xpm", - (const rt_uint8_t*)close_unpressed_xpm, sizeof(close_unpressed_xpm)); - - /* begin drawing */ - dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(win->title)); - - /* get rect */ - rtgui_widget_get_rect(RTGUI_WIDGET(win->title), &rect); - - /* draw border */ - if (win->flag & WINTITLE_BORDER) - { - RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(219, 210, 243); - rtgui_dc_draw_rect(dc, &rect); - - /* shrink border */ - rect.x1 += WINTITLE_BORDER_SIZE; - rect.y1 += WINTITLE_BORDER_SIZE; - rect.x2 -= WINTITLE_BORDER_SIZE; - rect.y2 -= WINTITLE_BORDER_SIZE; - } - - /* draw title */ - if (!(win->flag & WINTITLE_NO)) - { - if (win->flag & WINTITLE_ACTIVATE) - { - RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(229, 236, 249); - RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB( 51, 102, 204); - } - else - { - RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(242, 245, 252); - RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(153, 178, 229); - } - rtgui_dc_fill_rect(dc, &rect); - - rect.x1 += 4; - rect.y1 += 2; - rtgui_dc_draw_text(dc, rtgui_wintitle_get_title(win->title), &rect); - - if (win->flag & WINTITLE_CLOSEBOX) - { - /* get close button rect */ - rect.x1 = rtgui_rect_width(RTGUI_WIDGET(win->title)->extent) - - WINTITLE_BORDER_SIZE - WINTITLE_CB_WIDTH - 3; - rect.y1 = 3; - rect.x2 = rect.x1 + WINTITLE_CB_WIDTH; - rect.y2 = rect.y1 + WINTITLE_CB_HEIGHT; - - /* draw close box */ - if(win->flag & WINTITLE_CB_PRESSED) rtgui_image_blit(close_pressed, dc, &rect); - else rtgui_image_blit(close_unpressed, dc, &rect); - } - } - - rtgui_dc_end_drawing(dc); -} - -/* widget drawing */ -void rtgui_theme_draw_button(rtgui_button_t* btn) -{ - /* draw button */ - struct rtgui_dc* dc; - struct rtgui_rect rect; - - /* begin drawing */ - dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(btn)); - if (dc == RT_NULL) return; - - rtgui_widget_get_rect(RTGUI_WIDGET(btn), &rect); - - /* fill button rect with background color */ - // RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(212, 208, 200); - rtgui_dc_fill_rect(dc, &rect); - - if (btn->flag & RTGUI_BUTTON_TYPE_PUSH && btn->flag & RTGUI_BUTTON_FLAG_PRESS) - { - /* draw border */ - RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(64, 64, 64); - rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1); - rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2); - - RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(128, 128, 128); - rtgui_dc_draw_hline(dc, rect.x1, rect.x2 - 1, rect.y1 + 1); - rtgui_dc_draw_vline(dc, rect.x1 + 1, rect.y1 + 1, rect.y2 - 2); - - RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(255, 255, 255); - rtgui_dc_draw_hline(dc, rect.x1, rect.x2 + 1, rect.y2 - 1); - rtgui_dc_draw_vline(dc, rect.x2 - 1, rect.y1, rect.y2); - - if (btn->pressed_image != RT_NULL) - { - rtgui_rect_t image_rect = {0, 0, btn->unpressed_image->w, btn->unpressed_image->h}; - rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); - - rtgui_image_blit(btn->pressed_image, dc, &image_rect); - } - } - else if (btn->flag & RTGUI_BUTTON_FLAG_PRESS) - { - if (btn->pressed_image != RT_NULL) - { - rtgui_rect_t image_rect = {0, 0, btn->unpressed_image->w, btn->unpressed_image->h}; - rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); - - rtgui_image_blit(btn->pressed_image, dc, &image_rect); - } - else - { - /* draw border */ - RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(0, 0, 0); - rtgui_dc_draw_rect(dc, &rect); - - RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(128, 128, 128); - rect.x1 += 1; rect.y1 += 1; rect.x2 -= 1; rect.y2 -= 1; - rtgui_dc_draw_rect(dc, &rect); - } - } - else - { - if (btn->unpressed_image != RT_NULL) - { - rtgui_rect_t image_rect = {0, 0, btn->unpressed_image->w, btn->unpressed_image->h}; - rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); - - rtgui_image_blit(btn->unpressed_image, dc, &image_rect); - } - else - { - /* draw border */ - RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(255, 255, 255); - rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1); - rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2); - - RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(0, 0, 0); - rtgui_dc_draw_hline(dc, rect.x1, rect.x2 + 1, rect.y2); - rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2); - - RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(128, 128, 128); - rtgui_dc_draw_hline(dc, rect.x1 + 1, rect.x2, rect.y2 - 1); - rtgui_dc_draw_vline(dc, rect.x2 - 1, rect.y1 + 1, rect.y2 - 1); - } - } - - if (btn->pressed_image == RT_NULL) - { - /* re-set foreground and get default rect */ - RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(0, 0, 0); - rtgui_widget_get_rect(RTGUI_WIDGET(btn), &rect); - - /* remove border */ - rtgui_rect_inflate(&rect, -2); - - /* draw text */ - rtgui_dc_draw_text(dc, rtgui_label_get_text(RTGUI_LABEL(btn)), &rect); - } - - /* end drawing */ - rtgui_dc_end_drawing(dc); -} - -void rtgui_theme_draw_label(rtgui_label_t* label) -{ - /* draw label */ - struct rtgui_dc* dc; - struct rtgui_rect rect; - - /* begin drawing */ - dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(label)); - if (dc == RT_NULL) return; - - rtgui_widget_get_rect(RTGUI_WIDGET(label), &rect); - rtgui_dc_fill_rect(dc, &rect); - - /* default left and center draw */ - rect.y1 = rect.y1 + (rtgui_rect_height(rect) - 8)/2; - rtgui_dc_draw_text(dc, rtgui_label_get_text(label), &rect); - - /* end drawing */ - rtgui_dc_end_drawing(dc); -} - -#define RTGUI_TEXTBOX_MARGIN 3 -void rtgui_theme_draw_textbox(rtgui_textbox_t* box) -{ - /* draw button */ - struct rtgui_dc* dc; - struct rtgui_rect rect; - - /* begin drawing */ - dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box)); - if (dc == RT_NULL) return; - - /* get widget rect */ - rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect); - - /* fill widget rect with background color */ - rtgui_dc_fill_rect(dc, &rect); - - /* draw border */ - rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_STATIC); - - /* draw text */ - if (box->text != RT_NULL) - { - rect.x1 += RTGUI_TEXTBOX_MARGIN; - - rtgui_dc_draw_text(dc, box->text, &rect); - } - - /* end drawing */ - rtgui_dc_end_drawing(dc); -} - -void rtgui_theme_draw_iconbox(rtgui_iconbox_t* iconbox) -{ - struct rtgui_dc* dc; - struct rtgui_rect rect; - - /* begin drawing */ - dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(iconbox)); - if (dc == RT_NULL) return; - - /* get widget rect */ - rtgui_widget_get_rect(RTGUI_WIDGET(iconbox), &rect); - - /* draw icon */ - rtgui_image_blit(iconbox->image, dc, &rect); - - /* draw text */ - if (iconbox->text_position == RTGUI_ICONBOX_TEXT_BELOW && iconbox->text != RT_NULL) - { - rect.y1 = iconbox->image->h + RTGUI_WIDGET_DEFAULT_MARGIN; - rtgui_dc_draw_text(dc, iconbox->text, &rect); - } - else if (iconbox->text_position == RTGUI_ICONBOX_TEXT_RIGHT && iconbox->text != RT_NULL) - { - rect.x1 = iconbox->image->w + RTGUI_WIDGET_DEFAULT_MARGIN; - rtgui_dc_draw_text(dc, iconbox->text, &rect); - } - - /* end drawing */ - rtgui_dc_end_drawing(dc); -} - -/* get default background color */ -rtgui_color_t rtgui_theme_default_bc() -{ - return default_background; -} - -/* get default foreground color */ -rtgui_color_t rtgui_theme_default_fc() -{ - return default_foreground; -} +/* + * File : rtgui_theme.c + * This file is part of RTGUI in RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-04 Bernard first version + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define WINTITLE_CB_WIDTH 14 +#define WINTITLE_CB_HEIGHT 14 +#define SELECTED_HEIGHT 25 + +static const rt_uint8_t *close_unpressed_xpm[] = { + "14 14 55 1", + " c None", + ". c #DCDFEA", + "+ c #A4ADD3", + "@ c #8F9ACA", + "# c #98A2CD", + "$ c #D2D6E6", + "% c #F7F7F7", + "& c #F6F6F6", + "* c #B9C1D0", + "= c #7A8AAA", + "- c #D6DAE2", + "; c #D8DCE3", + "> c #7485A5", + ", c #455C89", + "' c #516690", + ") c #D3D8E0", + "! c #536891", + "~ c #6D7FA1", + "{ c #F5F5F5", + "] c #D1D6DF", + "^ c #D2D7DF", + "/ c #D5D9E1", + "( c #4E648E", + "_ c #CFD4DE", + ": c #F4F4F4", + "< c #D0D5DE", + "[ c #CED3DD", + "} c #F3F3F3", + "| c #CFD4DD", + "1 c #CDD2DC", + "2 c #F2F2F2", + "3 c #D3D7DF", + "4 c #526790", + "5 c #D0D5DD", + "6 c #F1F1F1", + "7 c #D2D6DE", + "8 c #CFD4DC", + "9 c #F0F0F0", + "0 c #D1D5DD", + "a c #C9CED8", + "b c #CDD2DB", + "c c #50658F", + "d c #CED3DB", + "e c #7283A3", + "f c #6E80A2", + "g c #EFEFEF", + "h c #B2BACA", + "i c #7081A2", + "j c #C8CDD7", + "k c #CCD1DA", + "l c #ACB5C7", + "m c #D0D4E2", + "n c #EEEEEE", + "o c #D2D5E3", + "p c #97A1CC", + ".+@@@@@@@@@@+.", + "#$%%%%%%%%%%$#", + "@&*=-&&&&;=*&@", + "@&>,')&&-!,~&@", + "@{]','^/!,(_{@", + "@::<','!,([::@", + "@}}}|',,(1}}}@", + "@22234,,'5222@", + "@6674,(','866@", + "@904,(abc,cd9@", + "@9e,(a99bc,f9@", + "@ghijggggkelg@", + "#mnnnnnnnnnnm#", + "op@@@@@@@@@@po"}; + +static const rt_uint8_t *close_pressed_xpm[] = { + "14 14 66 1", + " c None", + ". c #CED4EE", + "+ c #7E90DD", + "@ c #6076D7", + "# c #6C80D9", + "$ c #BFC8EA", + "% c #F2F3F5", + "& c #F0F2F3", + "* c #A5B6D7", + "= c #587ABB", + "- c #C9D3E4", + "; c #CBD5E4", + "> c #EEF0F2", + ", c #5073B7", + "' c #1746A3", + ") c #2551A8", + "! c #C5CFE2", + "~ c #C8D1E3", + "{ c #2853A8", + "] c #496DB4", + "^ c #ECEEF1", + "/ c #C0CCE0", + "( c #C3CEE1", + "_ c #C6D0E2", + ": c #224FA7", + "< c #BEC9DF", + "[ c #EAECF0", + "} c #BFCAE0", + "| c #2551A7", + "1 c #224EA7", + "2 c #BCC8DF", + "3 c #E8EBEE", + "4 c #BDCADE", + "5 c #BAC7DD", + "6 c #E6E9ED", + "7 c #C1CBDF", + "8 c #2753A8", + "9 c #BECADE", + "0 c #E4E7EB", + "a c #BFCADD", + "b c #224EA6", + "c c #BDC8DC", + "d c #E1E5EA", + "e c #2752A8", + "f c #B3C0D9", + "g c #B8C5DB", + "h c #2451A7", + "i c #BAC6DB", + "j c #DFE2E8", + "k c #4C70B4", + "l c #B2BED8", + "m c #B6C2D9", + "n c #2450A7", + "o c #486BB3", + "p c #DCE0E7", + "q c #96A8CE", + "r c #496CB3", + "s c #AFBCD7", + "t c #B4C1D8", + "u c #4B6FB4", + "v c #8EA4CC", + "w c #6C80D8", + "x c #B4BEDF", + "y c #DADEE5", + "z c #B5BEDE", + "A c #6A7ED7", + ".+@@@@@@@@@@+.", + "#$%%%%%%%%%%$#", + "@&*=-&&&&;=*&@", + "@>,')!>>~{']>@", + "@^/)')(_{':<^@", + "@[[}|'|{'12[[@", + "@3334|''15333@", + "@66678''|9666@", + "@00a8'b|'|c00@", + "@dce'bfgh'hid@", + "@jk'bljjmn'oj@", + "@pqrspppptuvp@", + "wxyyyyyyyyyyxw", + "zA@@@@@@@@@@Az"}; + +static rtgui_image_t* close_pressed = RT_NULL; +static rtgui_image_t* close_unpressed = RT_NULL; + +/* init theme */ +void rtgui_system_theme_init() +{ + close_pressed = rtgui_image_create_from_mem("xpm", + (const rt_uint8_t*)close_pressed_xpm, sizeof(close_pressed_xpm)); + close_unpressed = rtgui_image_create_from_mem("xpm", + (const rt_uint8_t*)close_unpressed_xpm, sizeof(close_unpressed_xpm)); +} + +/* window drawing */ +void rtgui_theme_draw_win(struct rtgui_topwin* win) +{ + struct rtgui_dc* dc; + rtgui_rect_t rect; + + /* init close box image */ + if (close_pressed == RT_NULL) + close_pressed = rtgui_image_create_from_mem("xpm", + (const rt_uint8_t*)close_pressed_xpm, sizeof(close_pressed_xpm)); + if (close_unpressed == RT_NULL) + close_unpressed = rtgui_image_create_from_mem("xpm", + (const rt_uint8_t*)close_unpressed_xpm, sizeof(close_unpressed_xpm)); + + /* begin drawing */ + dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(win->title)); + + /* get rect */ + rtgui_widget_get_rect(RTGUI_WIDGET(win->title), &rect); + + /* draw border */ + if (win->flag & WINTITLE_BORDER) + { + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(219, 210, 243); + rtgui_dc_draw_rect(dc, &rect); + + /* shrink border */ + rect.x1 += WINTITLE_BORDER_SIZE; + rect.y1 += WINTITLE_BORDER_SIZE; + rect.x2 -= WINTITLE_BORDER_SIZE; + rect.y2 -= WINTITLE_BORDER_SIZE; + } + + /* draw title */ + if (!(win->flag & WINTITLE_NO)) + { + if (win->flag & WINTITLE_ACTIVATE) + { + RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(229, 236, 249); + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB( 51, 102, 204); + } + else + { + RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(242, 245, 252); + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(win->title)) = RTGUI_RGB(153, 178, 229); + } + rtgui_dc_fill_rect(dc, &rect); + + rect.x1 += 4; + rect.y1 += 2; + rtgui_dc_draw_text(dc, rtgui_wintitle_get_title(win->title), &rect); + + if (win->flag & WINTITLE_CLOSEBOX) + { + /* get close button rect */ + rect.x1 = rtgui_rect_width(RTGUI_WIDGET(win->title)->extent) - + WINTITLE_BORDER_SIZE - WINTITLE_CB_WIDTH - 3; + rect.y1 = 3; + rect.x2 = rect.x1 + WINTITLE_CB_WIDTH; + rect.y2 = rect.y1 + WINTITLE_CB_HEIGHT; + + /* draw close box */ + if(win->flag & WINTITLE_CB_PRESSED) rtgui_image_blit(close_pressed, dc, &rect); + else rtgui_image_blit(close_unpressed, dc, &rect); + } + } + + rtgui_dc_end_drawing(dc); +} + +/* widget drawing */ +void rtgui_theme_draw_button(rtgui_button_t* btn) +{ + /* draw button */ + struct rtgui_dc* dc; + struct rtgui_rect rect; + + /* begin drawing */ + dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(btn)); + if (dc == RT_NULL) return; + + rtgui_widget_get_rect(RTGUI_WIDGET(btn), &rect); + + /* fill button rect with background color */ + // RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(212, 208, 200); + rtgui_dc_fill_rect(dc, &rect); + + if (btn->flag & RTGUI_BUTTON_TYPE_PUSH && btn->flag & RTGUI_BUTTON_FLAG_PRESS) + { + /* draw border */ + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(64, 64, 64); + rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1); + rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2); + + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(128, 128, 128); + rtgui_dc_draw_hline(dc, rect.x1, rect.x2 - 1, rect.y1 + 1); + rtgui_dc_draw_vline(dc, rect.x1 + 1, rect.y1 + 1, rect.y2 - 2); + + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(btn)) = RTGUI_RGB(255, 255, 255); + rtgui_dc_draw_hline(dc, rect.x1, rect.x2 + 1, rect.y2 - 1); + rtgui_dc_draw_vline(dc, rect.x2 - 1, rect.y1, rect.y2); + + if (btn->pressed_image != RT_NULL) + { + rtgui_rect_t image_rect; + image_rect.x1 = 0; image_rect.y1 = 0; + image_rect.x2 = btn->unpressed_image->w; + image_rect.y2 = btn->unpressed_image->h; + rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); + + rtgui_image_blit(btn->pressed_image, dc, &image_rect); + } + } + else if (btn->flag & RTGUI_BUTTON_FLAG_PRESS) + { + if (btn->pressed_image != RT_NULL) + { + rtgui_rect_t image_rect; + image_rect.x1 = 0; image_rect.y1 = 0; + image_rect.x2 = btn->unpressed_image->w; + image_rect.y2 = btn->unpressed_image->h; + rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); + + rtgui_image_blit(btn->pressed_image, dc, &image_rect); + } + else + { + /* draw border */ + RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(0, 0, 0); + rtgui_dc_draw_rect(dc, &rect); + + RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(128, 128, 128); + rect.x1 += 1; rect.y1 += 1; rect.x2 -= 1; rect.y2 -= 1; + rtgui_dc_draw_rect(dc, &rect); + } + } + else + { + if (btn->unpressed_image != RT_NULL) + { + rtgui_rect_t image_rect; + image_rect.x1 = 0; image_rect.y1 = 0; + image_rect.x2 = btn->unpressed_image->w; + image_rect.y2 = btn->unpressed_image->h; + rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); + + rtgui_image_blit(btn->unpressed_image, dc, &image_rect); + } + else + { + /* draw border */ + RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(255, 255, 255); + rtgui_dc_draw_hline(dc, rect.x1, rect.x2, rect.y1); + rtgui_dc_draw_vline(dc, rect.x1, rect.y1, rect.y2); + + RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(0, 0, 0); + rtgui_dc_draw_hline(dc, rect.x1, rect.x2 + 1, rect.y2); + rtgui_dc_draw_vline(dc, rect.x2, rect.y1, rect.y2); + + RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(128, 128, 128); + rtgui_dc_draw_hline(dc, rect.x1 + 1, rect.x2, rect.y2 - 1); + rtgui_dc_draw_vline(dc, rect.x2 - 1, rect.y1 + 1, rect.y2 - 1); + } + } + + if (btn->pressed_image == RT_NULL) + { + /* re-set foreground and get default rect */ + RTGUI_WIDGET(btn)->gc.foreground = RTGUI_RGB(0, 0, 0); + rtgui_widget_get_rect(RTGUI_WIDGET(btn), &rect); + + /* remove border */ + rtgui_rect_inflate(&rect, -2); + + /* draw text */ + rtgui_dc_draw_text(dc, rtgui_label_get_text(RTGUI_LABEL(btn)), &rect); + } + + /* end drawing */ + rtgui_dc_end_drawing(dc); +} + +void rtgui_theme_draw_label(rtgui_label_t* label) +{ + /* draw label */ + struct rtgui_dc* dc; + struct rtgui_rect rect; + + /* begin drawing */ + dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(label)); + if (dc == RT_NULL) return; + + rtgui_widget_get_rect(RTGUI_WIDGET(label), &rect); + rtgui_dc_fill_rect(dc, &rect); + + /* default left and center draw */ + rect.y1 = rect.y1 + (rtgui_rect_height(rect) - 8)/2; + rtgui_dc_draw_text(dc, rtgui_label_get_text(label), &rect); + + /* end drawing */ + rtgui_dc_end_drawing(dc); +} + +#define RTGUI_TEXTBOX_MARGIN 3 +void rtgui_theme_draw_textbox(rtgui_textbox_t* box) +{ + /* draw button */ + struct rtgui_dc* dc; + struct rtgui_rect rect; + + /* begin drawing */ + dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box)); + if (dc == RT_NULL) return; + + /* get widget rect */ + rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect); + + /* fill widget rect with background color */ + rtgui_dc_fill_rect(dc, &rect); + + /* draw border */ + rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_STATIC); + + /* draw text */ + if (box->text != RT_NULL) + { + rect.x1 += RTGUI_TEXTBOX_MARGIN; + + rtgui_dc_draw_text(dc, box->text, &rect); + } + + /* end drawing */ + rtgui_dc_end_drawing(dc); +} + +void rtgui_theme_draw_iconbox(rtgui_iconbox_t* iconbox) +{ + struct rtgui_dc* dc; + struct rtgui_rect rect; + + /* begin drawing */ + dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(iconbox)); + if (dc == RT_NULL) return; + + /* get widget rect */ + rtgui_widget_get_rect(RTGUI_WIDGET(iconbox), &rect); + + /* draw icon */ + rtgui_image_blit(iconbox->image, dc, &rect); + + /* draw text */ + if (iconbox->text_position == RTGUI_ICONBOX_TEXT_BELOW && iconbox->text != RT_NULL) + { + rect.y1 = iconbox->image->h + RTGUI_WIDGET_DEFAULT_MARGIN; + rtgui_dc_draw_text(dc, iconbox->text, &rect); + } + else if (iconbox->text_position == RTGUI_ICONBOX_TEXT_RIGHT && iconbox->text != RT_NULL) + { + rect.x1 = iconbox->image->w + RTGUI_WIDGET_DEFAULT_MARGIN; + rtgui_dc_draw_text(dc, iconbox->text, &rect); + } + + /* end drawing */ + rtgui_dc_end_drawing(dc); +} + +rt_uint16_t rtgui_theme_get_selected_height() +{ + return SELECTED_HEIGHT; +} + +void rtgui_theme_draw_selected(struct rtgui_dc* dc, rtgui_rect_t *rect) +{ + rtgui_color_t saved; + rtgui_rect_t focus_rect; + + focus_rect = *rect; + saved = rtgui_dc_get_color(dc); + rtgui_dc_set_color(dc, blue); + + rtgui_rect_inflate(&focus_rect, -1); + rtgui_dc_draw_focus_rect(dc, &focus_rect); + rtgui_rect_inflate(&focus_rect, -1); + rtgui_dc_draw_focus_rect(dc, &focus_rect); + + rtgui_dc_set_color(dc, saved); +} + +/* get default background color */ +rtgui_color_t rtgui_theme_default_bc() +{ + return default_background; +} + +/* get default foreground color */ +rtgui_color_t rtgui_theme_default_fc() +{ + return default_foreground; +} + diff --git a/rtgui/include/rtgui/color.h b/rtgui/include/rtgui/color.h index af45664a1..6150b9903 100644 --- a/rtgui/include/rtgui/color.h +++ b/rtgui/include/rtgui/color.h @@ -18,9 +18,9 @@ typedef unsigned long rtgui_color_t; #define RTGUI_ARGB(a, r, g, b) \ - ((rtgui_color_t)(((rt_uint8_t)(r)|\ - (((unsigned)(rt_uint8_t)(g))<<8))|\ - (((unsigned long)(rt_uint8_t)(b))<<16)|\ + ((rtgui_color_t)(((rt_uint8_t)(r)|\ + (((unsigned)(rt_uint8_t)(g))<<8))|\ + (((unsigned long)(rt_uint8_t)(b))<<16)|\ (((unsigned long)(rt_uint8_t)(a))<<24))) #define RTGUI_RGB(r, g, b) RTGUI_ARGB(255, (r), (g), (b)) @@ -51,7 +51,7 @@ rt_inline rt_uint16_t rtgui_color_to_565(rtgui_color_t c) { rt_uint16_t pixel; - pixel = ((RTGUI_RGB_B(c)>> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_R(c) >> 3); + pixel = (rt_uint16_t)(((RTGUI_RGB_B(c)>> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_R(c) >> 3)); return pixel; } @@ -75,7 +75,7 @@ rt_inline rt_uint16_t rtgui_color_to_565p(rtgui_color_t c) { rt_uint16_t pixel; - pixel = ((RTGUI_RGB_R(c) >> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_B(c)>> 3); + pixel = (rt_uint16_t)(((RTGUI_RGB_R(c) >> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_B(c)>> 3)); return pixel; } diff --git a/rtgui/include/rtgui/event.h b/rtgui/include/rtgui/event.h index 0ff94117c..e1179d8df 100644 --- a/rtgui/include/rtgui/event.h +++ b/rtgui/include/rtgui/event.h @@ -213,7 +213,7 @@ struct rtgui_event_win_resize #define rtgui_event_win_activate rtgui_event_win #define rtgui_event_win_deactivate rtgui_event_win #define rtgui_event_win_close rtgui_event_win - + /* window event init */ #define RTGUI_EVENT_WIN_CREATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CREATE) #define RTGUI_EVENT_WIN_DESTROY_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DESTROY) @@ -296,9 +296,9 @@ struct rtgui_event_clip_info /* the number of rects */ rt_uint32_t num_rect; - struct rtgui_rect rects[0]; + /* rtgui_rect_t *rects */ }; -#define RTGUI_EVENT_GET_RECT(e, i) (&(e->rects[0]) + i) +#define RTGUI_EVENT_GET_RECT(e, i) &(((rtgui_rect_t*)(e + 1))[i]) #define RTGUI_EVENT_UPDATE_BEGIN_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_BEGIN) #define RTGUI_EVENT_UPDATE_END_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_END) @@ -420,5 +420,5 @@ struct rtgui_event_resize rt_int16_t w, h; }; #define RTGUI_EVENT_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_RESIZE) - + #endif diff --git a/rtgui/include/rtgui/image_png.h b/rtgui/include/rtgui/image_png.h index 13aff657f..09454d6a7 100644 --- a/rtgui/include/rtgui/image_png.h +++ b/rtgui/include/rtgui/image_png.h @@ -16,4 +16,6 @@ #include +void rtgui_image_png_init(void); + #endif diff --git a/rtgui/include/rtgui/rtgui.h b/rtgui/include/rtgui/rtgui.h index dcc0741db..50e3b5b59 100644 --- a/rtgui/include/rtgui/rtgui.h +++ b/rtgui/include/rtgui/rtgui.h @@ -28,7 +28,7 @@ struct rtgui_widget; struct rtgui_win; typedef struct rtgui_panel rtgui_panel_t; -typedef struct rtgui_win rtgui_win_t; +typedef struct rtgui_win rtgui_win_t; typedef struct rtgui_workbench rtgui_workbench_t; typedef rt_bool_t (*rtgui_event_handler_ptr)(struct rtgui_widget* widget, struct rtgui_event* event); @@ -95,6 +95,13 @@ enum RTGUI_ARRAW RTGUI_ARRAW_RIGHT }; +enum RTGUI_MODAL_CODE +{ + RTGUI_MODAL_OK, + RTGUI_MODAL_CANCEL +}; +typedef enum RTGUI_MODAL_CODE rtgui_modal_code_t; + #include #endif diff --git a/rtgui/include/rtgui/rtgui_config.h b/rtgui/include/rtgui/rtgui_config.h index 4cce06fab..bc97b028b 100644 --- a/rtgui/include/rtgui/rtgui_config.h +++ b/rtgui/include/rtgui/rtgui_config.h @@ -22,18 +22,23 @@ /* #define RTGUI_USING_MOUSE_CURSOR */ +/* #define RTGUI_USING_FONT12 */ + #define RTGUI_USING_FONT16 #define RTGUI_USING_FONTHZ +#ifdef _WIN32 +#define RTGUI_USING_STDIO_FILERW +#define RTGUI_IMAGE_PNG +#define RTGUI_IMAGE_JPG +#else +#define RTGUI_USING_DFS_FILERW #define RTGUI_USING_HZ_FILE - -// #define RT_USING_STDIO_FILERW -#define RT_USING_DFS_FILERW -// #define RTGUI_IMAGE_PNG -// #define RTGUI_IMAGE_JPG +#endif #define RTGUI_SVR_THREAD_PRIORITY 15 #define RTGUI_SVR_THREAD_TIMESLICE 5 +#define RTGUI_SVR_THREAD_STACK_SIZE 2048 #define RTGUI_APP_THREAD_PRIORITY 25 #define RTGUI_APP_THREAD_TIMESLICE 8 diff --git a/rtgui/include/rtgui/rtgui_object.h b/rtgui/include/rtgui/rtgui_object.h index 9c0613770..bab31f15c 100644 --- a/rtgui/include/rtgui/rtgui_object.h +++ b/rtgui/include/rtgui/rtgui_object.h @@ -88,7 +88,6 @@ struct rtgui_object /* object type */ rtgui_type_t* type; - char *name; rt_bool_t is_static; }; rtgui_type_t *rtgui_object_type_get(void); diff --git a/rtgui/include/rtgui/rtgui_system.h b/rtgui/include/rtgui/rtgui_system.h index 9fd76b39c..e0ceae6f2 100644 --- a/rtgui/include/rtgui/rtgui_system.h +++ b/rtgui/include/rtgui/rtgui_system.h @@ -31,9 +31,6 @@ struct rtgui_thread /* the owner of thread */ struct rtgui_widget* widget; - - /* quit of thread */ - rt_bool_t is_quit; }; typedef struct rtgui_thread rtgui_thread_t; struct rtgui_timer; diff --git a/rtgui/include/rtgui/rtgui_theme.h b/rtgui/include/rtgui/rtgui_theme.h index 28edac0e6..0efde47ca 100644 --- a/rtgui/include/rtgui/rtgui_theme.h +++ b/rtgui/include/rtgui/rtgui_theme.h @@ -26,12 +26,17 @@ extern "C" { #endif +void rtgui_system_theme_init(void); + void rtgui_theme_draw_win(struct rtgui_topwin* win); void rtgui_theme_draw_button(rtgui_button_t* btn); void rtgui_theme_draw_label(rtgui_label_t* label); void rtgui_theme_draw_textbox(rtgui_textbox_t* box); void rtgui_theme_draw_iconbox(rtgui_iconbox_t* iconbox); +rt_uint16_t rtgui_theme_get_selected_height(void); +void rtgui_theme_draw_selected(struct rtgui_dc* dc, rtgui_rect_t *rect); + rtgui_color_t rtgui_theme_default_bc(void); rtgui_color_t rtgui_theme_default_fc(void); diff --git a/rtgui/include/rtgui/widgets/container.h b/rtgui/include/rtgui/widgets/container.h index 7f1af7d3d..4cd1bb0a3 100644 --- a/rtgui/include/rtgui/widgets/container.h +++ b/rtgui/include/rtgui/widgets/container.h @@ -28,6 +28,7 @@ struct rtgui_container /* inherit from widget */ struct rtgui_widget parent; + struct rtgui_widget* focused; rtgui_list_t children; }; typedef struct rtgui_container rtgui_container_t; diff --git a/rtgui/include/rtgui/widgets/toplevel.h b/rtgui/include/rtgui/widgets/toplevel.h index 044edf405..463b7e76d 100644 --- a/rtgui/include/rtgui/widgets/toplevel.h +++ b/rtgui/include/rtgui/widgets/toplevel.h @@ -37,9 +37,6 @@ struct rtgui_toplevel /* server thread id */ rt_thread_t server; - - /* current focus widget */ - rtgui_widget_t* focus; }; typedef struct rtgui_toplevel rtgui_toplevel_t; @@ -51,7 +48,4 @@ void rtgui_toplevel_handle_clip(struct rtgui_toplevel* top, struct rtgui_event_clip_info* info); void rtgui_toplevel_update_clip(rtgui_toplevel_t* top); -void rtgui_toplevel_set_focus(struct rtgui_toplevel* top, rtgui_widget_t* focus); -rtgui_widget_t* rtgui_toplevel_get_focus(struct rtgui_toplevel* top); - #endif diff --git a/rtgui/include/rtgui/widgets/view.h b/rtgui/include/rtgui/widgets/view.h index c4033c603..c1ebfa691 100644 --- a/rtgui/include/rtgui/widgets/view.h +++ b/rtgui/include/rtgui/widgets/view.h @@ -50,8 +50,9 @@ rt_bool_t rtgui_view_event_handler(struct rtgui_widget* widget, struct rtgui_eve void rtgui_view_set_box(rtgui_view_t* view, rtgui_box_t* box); -void rtgui_view_show(rtgui_view_t* view); +rtgui_modal_code_t rtgui_view_show(rtgui_view_t* view, rt_bool_t is_modal); void rtgui_view_hide(rtgui_view_t* view); +void rtgui_view_end_modal(rtgui_view_t* view, rtgui_modal_code_t modal_code); char* rtgui_view_get_title(rtgui_view_t* view); void rtgui_view_set_title(rtgui_view_t* view, const char* title); diff --git a/rtgui/include/rtgui/widgets/window.h b/rtgui/include/rtgui/widgets/window.h index 243ab75d2..ea730580a 100644 --- a/rtgui/include/rtgui/widgets/window.h +++ b/rtgui/include/rtgui/widgets/window.h @@ -27,18 +27,18 @@ /** Checks if the object is an rtgui_win */ #define RTGUI_IS_WIN(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_WIN_TYPE)) -#define RTGUI_WIN_STYLE_MODAL 0x00 -#define RTGUI_WIN_STYLE_MODAL_LESS 0x01 -#define RTGUI_WIN_STYLE_NO_TITLE 0x02 -#define RTGUI_WIN_STYLE_NO_BORDER 0x04 -#define RTGUI_WIN_STYLE_SHOW 0x08 -#define RTGUI_WIN_STYLE_CLOSEBOX 0x10 -#define RTGUI_WIN_STYLE_MINIBOX 0x20 -#define RTGUI_WIN_STYLE_ACTIVATE 0x40 -#define RTGUI_WIN_STYLE_NO_FOCUS 0x80 +#define RTGUI_WIN_STYLE_MODAL 0x01 /* modal mode window */ +#define RTGUI_WIN_STYLE_CLOSED 0x02 /* window is closed */ +#define RTGUI_WIN_STYLE_ACTIVATE 0x04 /* window is activated */ +#define RTGUI_WIN_STYLE_NO_FOCUS 0x08 /* non-focused window */ + +#define RTGUI_WIN_STYLE_NO_TITLE 0x10 /* no title window */ +#define RTGUI_WIN_STYLE_NO_BORDER 0x20 /* no border window */ +#define RTGUI_WIN_STYLE_CLOSEBOX 0x40 /* window has the close button */ +#define RTGUI_WIN_STYLE_MINIBOX 0x80 /* window has the mini button */ #define RTGUI_WIN_STYLE_DEFAULT (RTGUI_WIN_STYLE_CLOSEBOX | RTGUI_WIN_STYLE_MINIBOX) - + struct rtgui_win_title; struct rtgui_win_area; @@ -51,18 +51,19 @@ struct rtgui_win rtgui_toplevel_t* parent_toplevel; /* top window style */ - rt_uint32_t style; + rt_uint8_t style; + rtgui_modal_code_t modal_code; /* window title */ char* title; /* call back */ - rt_bool_t (*on_activate) (struct rtgui_widget* widget, struct rtgui_event* event); + rt_bool_t (*on_activate) (struct rtgui_widget* widget, struct rtgui_event* event); rt_bool_t (*on_deactivate) (struct rtgui_widget* widget, struct rtgui_event* event); rt_bool_t (*on_close) (struct rtgui_widget* widget, struct rtgui_event* event); /* reserved user data */ - rt_uint32_t user_data; + rt_uint32_t user_data; }; rtgui_type_t *rtgui_win_type_get(void); @@ -71,8 +72,10 @@ rtgui_win_t* rtgui_win_create(rtgui_toplevel_t* parent_toplevel, const char* tit rtgui_rect_t *rect, rt_uint32_t flag); void rtgui_win_destroy(rtgui_win_t* win); -void rtgui_win_show(rtgui_win_t* win); +rtgui_modal_code_t rtgui_win_show(rtgui_win_t* win, rt_bool_t is_modal); void rtgui_win_hiden(rtgui_win_t* win); +void rtgui_win_end_modal(rtgui_win_t* win, rtgui_modal_code_t modal_code); + rt_bool_t rtgui_win_is_activated(struct rtgui_win* win); void rtgui_win_move(struct rtgui_win* win, int x, int y); diff --git a/rtgui/include/rtgui/widgets/workbench.h b/rtgui/include/rtgui/widgets/workbench.h index dd132757c..3d8668083 100644 --- a/rtgui/include/rtgui/widgets/workbench.h +++ b/rtgui/include/rtgui/widgets/workbench.h @@ -22,12 +22,14 @@ #include #include -#define RTGUI_WORKBENCH_FLAG_VISIBLE 0x00 -#define RTGUI_WORKBENCH_FLAG_INVISIBLE 0x01 -#define RTGUI_WORKBENCH_FLAG_FULLSCREEN 0x02 +#define RTGUI_WORKBENCH_FLAG_VISIBLE 0x00 /* workbench is visible */ +#define RTGUI_WORKBENCH_FLAG_INVISIBLE 0x01 /* workbench is invisible */ +#define RTGUI_WORKBENCH_FLAG_FULLSCREEN 0x02 /* workbench is full screen */ +#define RTGUI_WORKBENCH_FLAG_MODAL_MODE 0x04 /* workbench is modal mode showing */ #define RTGUI_WORKBENCH_FLAG_CLOSEBLE 0x00 #define RTGUI_WORKBENCH_FLAG_UNCLOSEBLE 0x10 +#define RTGUI_WORKBENCH_FLAG_CLOSED 0x20 #define RTGUI_WORKBENCH_FLAG_DEFAULT RTGUI_WORKBENCH_FLAG_VISIBLE | RTGUI_WORKBENCH_FLAG_CLOSEBLE @@ -48,6 +50,7 @@ struct rtgui_workbench /* workbench flag */ rt_uint8_t flag; + rtgui_modal_code_t modal_code; /* workbench title */ unsigned char* title; @@ -63,7 +66,7 @@ rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* e void rtgui_workbench_set_flag(rtgui_workbench_t* workbench, rt_uint8_t flag); -void rtgui_workbench_event_loop(rtgui_workbench_t* workbench); +rt_bool_t rtgui_workbench_event_loop(rtgui_workbench_t* workbench); rt_err_t rtgui_workbench_show (rtgui_workbench_t* workbench); rt_err_t rtgui_workbench_hide (rtgui_workbench_t* workbench); diff --git a/rtgui/server/driver.c b/rtgui/server/driver.c index 2805ad1e5..6793ea136 100644 --- a/rtgui/server/driver.c +++ b/rtgui/server/driver.c @@ -1,67 +1,67 @@ -/* - * File : driver.c - * This file is part of RTGUI in RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-04 Bernard first version - */ -#include - -struct rtgui_list_node _rtgui_graphic_driver_list = {RT_NULL}; - -void rtgui_graphic_driver_add(struct rtgui_graphic_driver* driver) -{ - rtgui_list_insert(&_rtgui_graphic_driver_list, &(driver->list)); -} - -void rtgui_graphic_driver_remove(struct rtgui_graphic_driver* driver) -{ - rtgui_list_remove(&_rtgui_graphic_driver_list, &(driver->list)); -} - -struct rtgui_graphic_driver* rtgui_graphic_driver_find(char* name) -{ - struct rtgui_list_node* node; - struct rtgui_graphic_driver* driver; - - /* search in list */ - rtgui_list_foreach(node, &(_rtgui_graphic_driver_list)) - { - driver = rtgui_list_entry(node, struct rtgui_graphic_driver, list); - - /* find it */ - if (rt_strncmp(driver->name, name, RTGUI_NAME_MAX) == 0) - { - return driver; - } - } - - return RT_NULL; -} - -struct rtgui_graphic_driver* rtgui_graphic_driver_get_default() -{ - return rtgui_list_entry(_rtgui_graphic_driver_list.next, - struct rtgui_graphic_driver, list); -} - -void rtgui_graphic_driver_get_rect(struct rtgui_graphic_driver *driver, rtgui_rect_t *rect) -{ - if (rect == RT_NULL || driver == RT_NULL) return; - - rect->x1 = rect->y1 = 0; - rect->x2 = driver->width; - rect->y2 = driver->height; -} - -void rtgui_graphic_driver_get_default_rect(rtgui_rect_t *rect) -{ - /* return default the extent of default driver */ - rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), rect); -} +/* + * File : driver.c + * This file is part of RTGUI in RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-04 Bernard first version + */ +#include + +struct rtgui_list_node _rtgui_graphic_driver_list = {RT_NULL}; + +void rtgui_graphic_driver_add(struct rtgui_graphic_driver* driver) +{ + rtgui_list_insert(&_rtgui_graphic_driver_list, &(driver->list)); +} + +void rtgui_graphic_driver_remove(struct rtgui_graphic_driver* driver) +{ + rtgui_list_remove(&_rtgui_graphic_driver_list, &(driver->list)); +} + +struct rtgui_graphic_driver* rtgui_graphic_driver_find(char* name) +{ + struct rtgui_list_node* node; + struct rtgui_graphic_driver* driver; + + /* search in list */ + rtgui_list_foreach(node, &(_rtgui_graphic_driver_list)) + { + driver = rtgui_list_entry(node, struct rtgui_graphic_driver, list); + + /* find it */ + if (rt_strncmp(driver->name, name, RTGUI_NAME_MAX) == 0) + { + return driver; + } + } + + return RT_NULL; +} + +struct rtgui_graphic_driver* rtgui_graphic_driver_get_default() +{ + return rtgui_list_entry(_rtgui_graphic_driver_list.next, + struct rtgui_graphic_driver, list); +} + +void rtgui_graphic_driver_get_rect(struct rtgui_graphic_driver *driver, rtgui_rect_t *rect) +{ + if (rect == RT_NULL || driver == RT_NULL) return; + + rect->x1 = rect->y1 = 0; + rect->x2 = driver->width; + rect->y2 = driver->height; +} + +void rtgui_graphic_driver_get_default_rect(rtgui_rect_t *rect) +{ + /* return default the extent of default driver */ + rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), rect); +} diff --git a/rtgui/server/panel.c b/rtgui/server/panel.c index e52858a91..0d767a3f3 100644 --- a/rtgui/server/panel.c +++ b/rtgui/server/panel.c @@ -1,306 +1,306 @@ -/* - * File : panel.c - * This file is part of RTGUI in RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-04 Bernard first version - */ - -#include "panel.h" -#include "mouse.h" - -#include - -/* the global parameter */ -struct rtgui_list_node _rtgui_panel_list; - -void rtgui_panel_init() -{ - rtgui_list_init(&_rtgui_panel_list); -} - -void rtgui_panel_register(char* name, rtgui_rect_t* extent) -{ - register rt_base_t temp; - struct rtgui_panel* panel; - - panel = rtgui_panel_find(name); - if (panel != RT_NULL ) - { - /* there are already a same named panel exist. */ - return; - } - - panel = rtgui_malloc(sizeof(struct rtgui_panel)); - if (panel == RT_NULL) - { - /* can't alloc memory */ - return; - } - - /* copy name */ - for (temp = 0; temp < RTGUI_NAME_MAX; temp ++) - { - panel->name[temp] = name[temp]; - } - - /* copy extent */ - panel->extent = *extent; - - panel->wm_thread = RT_NULL; - - /* init list */ - rtgui_list_init(&(panel->sibling)); - rtgui_list_init(&(panel->thread_list)); - - /* add panel to panel list */ - rtgui_list_insert(&_rtgui_panel_list, &(panel->sibling)); -} - -void rtgui_panel_deregister(char* name) -{ - struct rtgui_panel* panel; - - panel = rtgui_panel_find(name); - if (panel != RT_NULL) - { - rtgui_list_remove(&_rtgui_panel_list, &(panel->sibling)); - - /* free pane node */ - rtgui_free(panel); - } -} - -/* set default focused panel, please use it after registered panel */ -void rtgui_panel_set_default_focused(char* name) -{ - extern struct rtgui_panel* rtgui_server_focus_panel; - struct rtgui_panel* panel; - - panel = rtgui_panel_find(name); - if (panel != RT_NULL) - { - rtgui_server_focus_panel = panel; - } -} - -struct rtgui_panel* rtgui_panel_find(char* name) -{ - struct rtgui_list_node* node; - struct rtgui_panel* panel; - - rtgui_list_foreach(node, &_rtgui_panel_list) - { - panel = rtgui_list_entry(node, struct rtgui_panel, sibling); - - if (rt_strncmp(panel->name, name, RTGUI_NAME_MAX) == 0) - { - return panel; - } - } - - return RT_NULL; -} - -struct rtgui_panel* rtgui_panel_thread_add(char* name, rt_thread_t tid) -{ - struct rtgui_panel* panel; - - panel = rtgui_panel_find(name); - if (panel != RT_NULL ) - { - struct rtgui_panel_thread* thread; - - /* allocate panel thread node */ - thread = rtgui_malloc(sizeof(struct rtgui_panel_thread)); - if (thread == RT_NULL) - { - return RT_NULL; - } - - /* construct panel thread node */ - thread->tid = tid; - - /* init list */ - rtgui_list_init(&(thread->list)); - rtgui_list_init(&(thread->monitor_list)); - - /* append thread to the list */ - rtgui_list_append(&(panel->thread_list), &(thread->list)); - } - - return panel; -} - -void rtgui_panel_thread_remove(rtgui_panel_t* panel, rt_thread_t tid) -{ - if (panel != RT_NULL ) - { - struct rtgui_list_node* node; - struct rtgui_panel_thread* thread; - - rtgui_list_foreach(node, &(panel->thread_list)) - { - thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); - if (thread->tid == tid) - { - /* remove node from list */ - rtgui_list_remove(&(panel->thread_list), &(thread->list)); - - /* free the panel thread node */ - rtgui_free(thread); - return; - } - } - } -} - -rt_thread_t rtgui_panel_get_active_thread(rtgui_panel_t* panel) -{ - if (panel != RT_NULL) - { - if (panel->thread_list.next != RT_NULL) - { - struct rtgui_panel_thread* thread; - thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); - - return thread->tid; - } - } - - return RT_NULL; -} - -void rtgui_panel_set_active_thread(rtgui_panel_t* panel, rt_thread_t tid) -{ - /* get old active thread */ - rt_thread_t prev_actived = rtgui_panel_get_active_thread(panel); - if (prev_actived != tid) - { - /* de-active old active workbench */ - struct rtgui_event_panel_hide ehide; - RTGUI_EVENT_PANEL_HIDE_INIT(&ehide); - - ehide.panel = panel; - ehide.workbench = RT_NULL; - rtgui_thread_send_urgent(prev_actived, &(ehide.parent), sizeof (ehide)); - } - - if (panel != RT_NULL ) - { - struct rtgui_list_node* node; - struct rtgui_panel_thread* thread; - - rtgui_list_foreach(node, &(panel->thread_list)) - { - thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); - if (thread->tid == tid) - { - /* remove node from list */ - rtgui_list_remove(&(panel->thread_list), &(thread->list)); - - /* insert node to the header */ - rtgui_list_insert(&(panel->thread_list), &(thread->list)); - return; - } - } - } -} - -/* deactivate current activated thread -- move it to the end of list */ -void rtgui_panel_deactive_thread(rtgui_panel_t* panel) -{ - RT_ASSERT(panel == RT_NULL); - - if (panel->thread_list.next != RT_NULL) - { - struct rtgui_panel_thread* thread; - thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); - - /* remove it */ - panel->thread_list.next = thread->list.next; - - /* append to the tail of thread list */ - rtgui_list_append(&(panel->thread_list), &(thread->list)); - } -} - -/** - * get the panel which contains a point(x, y) - */ -rtgui_panel_t* rtgui_panel_get_contain(int x, int y) -{ - struct rtgui_list_node* node; - struct rtgui_panel* panel; - - rtgui_list_foreach(node, &(_rtgui_panel_list)) - { - panel = rtgui_list_entry(node, struct rtgui_panel, sibling); - if (rtgui_rect_contains_point(&(panel->extent), x, y) == RT_EOK) - { - return panel; - } - } - - return RT_NULL; -} - -/** - * append a rect to panel mouse monitor rect list - */ -void rtgui_panel_append_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect) -{ - if (panel != RT_NULL ) - { - struct rtgui_list_node* node; - struct rtgui_panel_thread* thread; - - rtgui_list_foreach(node, &(panel->thread_list)) - { - thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); - if (thread->tid == tid) - { - /* add the monitor rect to list */ - rtgui_mouse_monitor_append(&(thread->monitor_list), rect); - return; - } - } - } -} - -/** - * remove a rect from panel mouse monitor rect list - */ -void rtgui_panel_remove_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect) -{ - if (panel != RT_NULL ) - { - struct rtgui_list_node* node; - struct rtgui_panel_thread* thread; - - rtgui_list_foreach(node, &(panel->thread_list)) - { - thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); - if (thread->tid == tid) - { - /* remove the monitor rect from list */ - rtgui_mouse_monitor_remove(&(thread->monitor_list), rect); - return; - } - } - } -} - -void rtgui_panel_set_wm(rtgui_panel_t* panel, rt_thread_t wm) -{ - RT_ASSERT(wm != RT_NULL); - RT_ASSERT(panel != RT_NULL); - - panel->wm_thread = wm; -} +/* + * File : panel.c + * This file is part of RTGUI in RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-04 Bernard first version + */ + +#include "panel.h" +#include "mouse.h" + +#include + +/* the global parameter */ +struct rtgui_list_node _rtgui_panel_list; + +void rtgui_panel_init() +{ + rtgui_list_init(&_rtgui_panel_list); +} + +void rtgui_panel_register(char* name, rtgui_rect_t* extent) +{ + register rt_base_t temp; + struct rtgui_panel* panel; + + panel = rtgui_panel_find(name); + if (panel != RT_NULL ) + { + /* there are already a same named panel exist. */ + return; + } + + panel = rtgui_malloc(sizeof(struct rtgui_panel)); + if (panel == RT_NULL) + { + /* can't alloc memory */ + return; + } + + /* copy name */ + for (temp = 0; temp < RTGUI_NAME_MAX; temp ++) + { + panel->name[temp] = name[temp]; + } + + /* copy extent */ + panel->extent = *extent; + + panel->wm_thread = RT_NULL; + + /* init list */ + rtgui_list_init(&(panel->sibling)); + rtgui_list_init(&(panel->thread_list)); + + /* add panel to panel list */ + rtgui_list_insert(&_rtgui_panel_list, &(panel->sibling)); +} + +void rtgui_panel_deregister(char* name) +{ + struct rtgui_panel* panel; + + panel = rtgui_panel_find(name); + if (panel != RT_NULL) + { + rtgui_list_remove(&_rtgui_panel_list, &(panel->sibling)); + + /* free pane node */ + rtgui_free(panel); + } +} + +/* set default focused panel, please use it after registered panel */ +void rtgui_panel_set_default_focused(char* name) +{ + extern struct rtgui_panel* rtgui_server_focus_panel; + struct rtgui_panel* panel; + + panel = rtgui_panel_find(name); + if (panel != RT_NULL) + { + rtgui_server_focus_panel = panel; + } +} + +struct rtgui_panel* rtgui_panel_find(char* name) +{ + struct rtgui_list_node* node; + struct rtgui_panel* panel; + + rtgui_list_foreach(node, &_rtgui_panel_list) + { + panel = rtgui_list_entry(node, struct rtgui_panel, sibling); + + if (rt_strncmp(panel->name, name, RTGUI_NAME_MAX) == 0) + { + return panel; + } + } + + return RT_NULL; +} + +struct rtgui_panel* rtgui_panel_thread_add(char* name, rt_thread_t tid) +{ + struct rtgui_panel* panel; + + panel = rtgui_panel_find(name); + if (panel != RT_NULL ) + { + struct rtgui_panel_thread* thread; + + /* allocate panel thread node */ + thread = rtgui_malloc(sizeof(struct rtgui_panel_thread)); + if (thread == RT_NULL) + { + return RT_NULL; + } + + /* construct panel thread node */ + thread->tid = tid; + + /* init list */ + rtgui_list_init(&(thread->list)); + rtgui_list_init(&(thread->monitor_list)); + + /* append thread to the list */ + rtgui_list_append(&(panel->thread_list), &(thread->list)); + } + + return panel; +} + +void rtgui_panel_thread_remove(rtgui_panel_t* panel, rt_thread_t tid) +{ + if (panel != RT_NULL ) + { + struct rtgui_list_node* node; + struct rtgui_panel_thread* thread; + + rtgui_list_foreach(node, &(panel->thread_list)) + { + thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); + if (thread->tid == tid) + { + /* remove node from list */ + rtgui_list_remove(&(panel->thread_list), &(thread->list)); + + /* free the panel thread node */ + rtgui_free(thread); + return; + } + } + } +} + +rt_thread_t rtgui_panel_get_active_thread(rtgui_panel_t* panel) +{ + if (panel != RT_NULL) + { + if (panel->thread_list.next != RT_NULL) + { + struct rtgui_panel_thread* thread; + thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); + + return thread->tid; + } + } + + return RT_NULL; +} + +void rtgui_panel_set_active_thread(rtgui_panel_t* panel, rt_thread_t tid) +{ + /* get old active thread */ + rt_thread_t prev_actived = rtgui_panel_get_active_thread(panel); + if (prev_actived != tid) + { + /* de-active old active workbench */ + struct rtgui_event_panel_hide ehide; + RTGUI_EVENT_PANEL_HIDE_INIT(&ehide); + + ehide.panel = panel; + ehide.workbench = RT_NULL; + rtgui_thread_send_urgent(prev_actived, &(ehide.parent), sizeof (ehide)); + } + + if (panel != RT_NULL ) + { + struct rtgui_list_node* node; + struct rtgui_panel_thread* thread; + + rtgui_list_foreach(node, &(panel->thread_list)) + { + thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); + if (thread->tid == tid) + { + /* remove node from list */ + rtgui_list_remove(&(panel->thread_list), &(thread->list)); + + /* insert node to the header */ + rtgui_list_insert(&(panel->thread_list), &(thread->list)); + return; + } + } + } +} + +/* deactivate current activated thread -- move it to the end of list */ +void rtgui_panel_deactive_thread(rtgui_panel_t* panel) +{ + RT_ASSERT(panel == RT_NULL); + + if (panel->thread_list.next != RT_NULL) + { + struct rtgui_panel_thread* thread; + thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); + + /* remove it */ + panel->thread_list.next = thread->list.next; + + /* append to the tail of thread list */ + rtgui_list_append(&(panel->thread_list), &(thread->list)); + } +} + +/** + * get the panel which contains a point(x, y) + */ +rtgui_panel_t* rtgui_panel_get_contain(int x, int y) +{ + struct rtgui_list_node* node; + struct rtgui_panel* panel; + + rtgui_list_foreach(node, &(_rtgui_panel_list)) + { + panel = rtgui_list_entry(node, struct rtgui_panel, sibling); + if (rtgui_rect_contains_point(&(panel->extent), x, y) == RT_EOK) + { + return panel; + } + } + + return RT_NULL; +} + +/** + * append a rect to panel mouse monitor rect list + */ +void rtgui_panel_append_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect) +{ + if (panel != RT_NULL ) + { + struct rtgui_list_node* node; + struct rtgui_panel_thread* thread; + + rtgui_list_foreach(node, &(panel->thread_list)) + { + thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); + if (thread->tid == tid) + { + /* add the monitor rect to list */ + rtgui_mouse_monitor_append(&(thread->monitor_list), rect); + return; + } + } + } +} + +/** + * remove a rect from panel mouse monitor rect list + */ +void rtgui_panel_remove_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect) +{ + if (panel != RT_NULL ) + { + struct rtgui_list_node* node; + struct rtgui_panel_thread* thread; + + rtgui_list_foreach(node, &(panel->thread_list)) + { + thread = rtgui_list_entry(node, struct rtgui_panel_thread, list); + if (thread->tid == tid) + { + /* remove the monitor rect from list */ + rtgui_mouse_monitor_remove(&(thread->monitor_list), rect); + return; + } + } + } +} + +void rtgui_panel_set_wm(rtgui_panel_t* panel, rt_thread_t wm) +{ + RT_ASSERT(wm != RT_NULL); + RT_ASSERT(panel != RT_NULL); + + panel->wm_thread = wm; +} diff --git a/rtgui/server/panel.h b/rtgui/server/panel.h index c40f57a5f..fffaa35dc 100644 --- a/rtgui/server/panel.h +++ b/rtgui/server/panel.h @@ -1,68 +1,68 @@ -/* - * File : panel.h - * This file is part of RTGUI in RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-04 Bernard first version - */ - -#ifndef __RT_PANEL_H__ -#define __RT_PANEL_H__ - -#include -#include -#include - -struct rtgui_panel_thread -{ - /* thread id */ - rt_thread_t tid; - - /* the list of thread */ - rtgui_list_t list; - - /* monitor rect list */ - rtgui_list_t monitor_list; -}; -typedef struct rtgui_panel_thread rtgui_panel_thread_list_t; - -struct rtgui_panel -{ - char name[RTGUI_NAME_MAX]; - - /* the extent of panel */ - rtgui_rect_t extent; - - /* the list of panel */ - rtgui_list_t sibling; - - /* the thread list in this panel */ - rtgui_list_t thread_list; - - /* the workbench manager thread */ - rt_thread_t wm_thread; -}; - -/* find panel by name */ -struct rtgui_panel* rtgui_panel_find(char* name); - -/* add or remove application thread from specified panel */ -rtgui_panel_t* rtgui_panel_thread_add(char* name, rt_thread_t tid); -void rtgui_panel_thread_remove(rtgui_panel_t* panel, rt_thread_t tid); - -rt_thread_t rtgui_panel_get_active_thread(rtgui_panel_t* panel); -void rtgui_panel_set_active_thread(rtgui_panel_t* panel, rt_thread_t tid); - -rtgui_panel_t* rtgui_panel_get_contain(int x, int y); -void rtgui_panel_set_wm(rtgui_panel_t* panel, rt_thread_t wm); - -void rtgui_panel_append_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect); -void rtgui_panel_remove_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect); - -#endif +/* + * File : panel.h + * This file is part of RTGUI in RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-04 Bernard first version + */ + +#ifndef __RT_PANEL_H__ +#define __RT_PANEL_H__ + +#include +#include +#include + +struct rtgui_panel_thread +{ + /* thread id */ + rt_thread_t tid; + + /* the list of thread */ + rtgui_list_t list; + + /* monitor rect list */ + rtgui_list_t monitor_list; +}; +typedef struct rtgui_panel_thread rtgui_panel_thread_list_t; + +struct rtgui_panel +{ + char name[RTGUI_NAME_MAX]; + + /* the extent of panel */ + rtgui_rect_t extent; + + /* the list of panel */ + rtgui_list_t sibling; + + /* the thread list in this panel */ + rtgui_list_t thread_list; + + /* the workbench manager thread */ + rt_thread_t wm_thread; +}; + +/* find panel by name */ +struct rtgui_panel* rtgui_panel_find(char* name); + +/* add or remove application thread from specified panel */ +rtgui_panel_t* rtgui_panel_thread_add(char* name, rt_thread_t tid); +void rtgui_panel_thread_remove(rtgui_panel_t* panel, rt_thread_t tid); + +rt_thread_t rtgui_panel_get_active_thread(rtgui_panel_t* panel); +void rtgui_panel_set_active_thread(rtgui_panel_t* panel, rt_thread_t tid); + +rtgui_panel_t* rtgui_panel_get_contain(int x, int y); +void rtgui_panel_set_wm(rtgui_panel_t* panel, rt_thread_t wm); + +void rtgui_panel_append_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect); +void rtgui_panel_remove_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect); + +#endif diff --git a/rtgui/server/server.c b/rtgui/server/server.c index c782e0e13..5a7fe08a5 100644 --- a/rtgui/server/server.c +++ b/rtgui/server/server.c @@ -1,627 +1,619 @@ -/* - * File : server.c - * This file is part of RTGUI in RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-04 Bernard first version - */ - -#include -#include +/* + * File : server.c + * This file is part of RTGUI in RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-04 Bernard first version + */ + +#include +#include #include -#include - -#include "mouse.h" -#include "panel.h" -#include "topwin.h" - -static char rtgui_server_stack[2048]; -static struct rt_thread rtgui_server_thread; - -static struct rt_messagequeue rtgui_server_mq; -static char rtgui_server_msg_pool[2048]; - -extern struct rtgui_topwin* rtgui_server_focus_topwin; -struct rtgui_panel* rtgui_server_focus_panel = RT_NULL; - -void rtgui_server_create_application(struct rtgui_event_panel_attach* event) -{ - struct rtgui_panel* panel = rtgui_panel_find(event->panel_name); - - if (panel != RT_NULL) - { - struct rtgui_event_panel_info ep; - RTGUI_EVENT_PANEL_INFO_INIT(&ep); - - if (panel->wm_thread != RT_NULL) - { - /* notify to workbench */ - rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_attach)); - } - - /* send the responses - ok */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); - - /* send the panel info */ - ep.panel = panel; - ep.extent = panel->extent; - rtgui_thread_send(event->parent.sender, (struct rtgui_event*)&ep, sizeof(ep)); - - rtgui_panel_thread_add(event->panel_name, event->parent.sender); - } - else - { - /* send the responses - failure */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_NRC); - } -} - -void rtgui_server_destroy_application(struct rtgui_event_panel_detach* event) -{ - struct rtgui_panel* panel = event->panel; - - if (panel != RT_NULL) - { - if (panel->wm_thread != RT_NULL) - { - /* notify to workbench */ - rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_detach)); - } - - /* send the responses */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); - - rtgui_panel_thread_remove(panel, event->parent.sender); - - { - /* get next thread and active it */ - rt_thread_t tid = rtgui_panel_get_active_thread(panel); - - /* let this thread repaint */ - struct rtgui_event_paint epaint; - RTGUI_EVENT_PAINT_INIT(&epaint); - epaint.wid = RT_NULL; - rtgui_thread_send(tid, (struct rtgui_event*)&epaint, sizeof(epaint)); - } - } - else - { - /* send the responses - failure */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_NRC); - } -} - -void rtgui_server_thread_panel_show(struct rtgui_event_panel_show* event) -{ - struct rtgui_panel* panel = event->panel; - - if (panel != RT_NULL) - { - struct rtgui_event_paint epaint; - - /* send the responses */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); - - if (panel->wm_thread != RT_NULL) - { - /* notify to workbench */ - rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_show)); - } - - rtgui_panel_set_active_thread(panel, event->parent.sender); - - /* send all topwin clip info */ - rtgui_topwin_update_clip_to_panel(panel); - - /* send paint event */ - RTGUI_EVENT_PAINT_INIT(&epaint); - epaint.wid = RT_NULL; - rtgui_thread_send(event->parent.sender, (struct rtgui_event*)&epaint, - sizeof(epaint)); - } - else - { - /* send failed */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); - } -} - -void rtgui_server_thread_panel_hide(struct rtgui_event_panel_hide* event) -{ - struct rtgui_panel* panel = event->panel; - - if (panel != RT_NULL) - { - rt_thread_t tid; - struct rtgui_event_paint epaint; - - /* send the responses */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); - - if (panel->thread_list.next != RT_NULL) - { - struct rtgui_panel_thread* thread; - thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); - - /* remove it */ - panel->thread_list.next = thread->list.next; - - /* append to the tail of thread list */ - rtgui_list_append(&(panel->thread_list), &(thread->list)); - } - - /* get new active thread */ - tid = rtgui_panel_get_active_thread(panel); - /* send all topwin clip info */ - rtgui_topwin_update_clip_to_panel(panel); - - /* send paint event */ - RTGUI_EVENT_PAINT_INIT(&epaint); - epaint.wid = RT_NULL; - rtgui_thread_send(tid, (struct rtgui_event*)&epaint, sizeof(epaint)); - } - else - { - /* send failed */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); - } -} - -void rtgui_server_handle_set_wm(struct rtgui_event_set_wm *event) -{ - struct rtgui_panel* panel = rtgui_panel_find(event->panel_name); - - if (panel != RT_NULL) - { - rtgui_panel_set_wm(panel, event->parent.sender); - } -} - -void rtgui_server_handle_update(struct rtgui_event_update_end* event) -{ - struct rtgui_graphic_driver* driver = rtgui_graphic_driver_get_default(); - if (driver != RT_NULL) - { - driver->screen_update(&(event->rect)); - } -} - -void rtgui_server_handle_monitor_add(struct rtgui_event_monitor* event) -{ - if (event->panel != RT_NULL) - { - /* append monitor rect to panel list */ - rtgui_panel_append_monitor_rect(event->panel, event->parent.sender, &(event->rect)); - } - else - { - /* add monitor rect to top window list */ - rtgui_topwin_append_monitor_rect(event->wid, &(event->rect)); - } -} - -void rtgui_server_handle_monitor_remove(struct rtgui_event_monitor* event) -{ - if (event->panel != RT_NULL) - { - /* add monitor rect to panel list */ - rtgui_panel_remove_monitor_rect(event->panel, event->parent.sender, &(event->rect)); - } - else - { - /* add monitor rect to top window list */ - rtgui_topwin_remove_monitor_rect(event->wid, &(event->rect)); - } -} - -void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event) -{ - struct rtgui_topwin* wnd; - struct rtgui_panel* panel; - - /* re-init to server thread */ - RTGUI_EVENT_MOUSE_BUTTON_INIT(event); - - if (rtgui_winrect_is_moved() && - event->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP)) - { - struct rtgui_topwin* topwin; - rtgui_rect_t rect; - - if (rtgui_winrect_moved_done(&rect, &topwin) == RT_TRUE) - { - struct rtgui_event_win_move ewin; - - /* move window */ - RTGUI_EVENT_WIN_MOVE_INIT(&ewin); - ewin.wid = topwin->wid; - if (topwin->title != RT_NULL) - { - if (topwin->flag & WINTITLE_BORDER) - { - ewin.x = rect.x1 + WINTITLE_BORDER_SIZE; - ewin.y = rect.y1 + WINTITLE_BORDER_SIZE; - } - if (!(topwin->flag & WINTITLE_NO)) ewin.y += WINTITLE_HEIGHT; - } - else - { - ewin.x = rect.x1; - ewin.y = rect.y1; - } - - /* send to client thread */ - rtgui_thread_send(topwin->tid, &(ewin.parent), sizeof(ewin)); - - return; - } - } - - /* get the wnd which contains the mouse */ - wnd = rtgui_topwin_get_wnd(event->x, event->y); - if (wnd != RT_NULL) - { - event->wid = wnd->wid; - - if (rtgui_server_focus_topwin != wnd) - { - /* raise this window */ - rtgui_topwin_raise(wnd->wid, wnd->tid); - rtgui_server_focus_panel = RT_NULL; - } - - if (wnd->title != RT_NULL && - rtgui_rect_contains_point(&(RTGUI_WIDGET(wnd->title)->extent), event->x, event->y) == RT_EOK) - { - rtgui_topwin_title_onmouse(wnd, event); - } - else - { - /* send mouse event to thread */ - rtgui_thread_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_mouse)); - } - return ; - } - - /* get the panel which contains the mouse */ - panel = rtgui_panel_get_contain(event->x, event->y); - if (panel != RT_NULL) - { - /* deactivate old window */ - if (rtgui_server_focus_topwin != RT_NULL) - { - rtgui_topwin_deactivate_win(rtgui_server_focus_topwin); - } - - rtgui_server_focus_panel = panel; - rtgui_server_focus_topwin = RT_NULL; - - /* set destination window to null */ - event->wid = RT_NULL; - - /* send mouse event to thread */ - rtgui_thread_send(rtgui_panel_get_active_thread(panel), - (struct rtgui_event*)event, - sizeof(struct rtgui_event_mouse)); - } -} - -static struct rtgui_panel* last_monitor_panel = RT_NULL; -static struct rtgui_topwin* last_monitor_topwin = RT_NULL; - -void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse* event) -{ - /* the topwin contains current mouse */ - struct rtgui_topwin* win = RT_NULL; - struct rtgui_panel* panel = RT_NULL; - - /* re-init mouse event */ - RTGUI_EVENT_MOUSE_MOTION_INIT(event); - - /* find the panel or topwin which monitor the mouse motion */ - win = rtgui_topwin_get_wnd(event->x, event->y); - if (win == RT_NULL) - { - /* try to find monitor on the panel */ - panel = rtgui_panel_get_contain(event->x, event->y); - - if (panel != RT_NULL) - { - struct rtgui_panel_thread* thread; - - /* get active panel thread */ - if (panel->thread_list.next != RT_NULL) - { - thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); - if (!rtgui_mouse_monitor_contains_point(&(thread->monitor_list), - event->x, event->y) == RT_TRUE) - { - /* no monitor in this panel */ - panel = RT_NULL; - } - } - } - } - else if (win->monitor_list.next != RT_NULL) - { - /* check whether the monitor exist */ - if (rtgui_mouse_monitor_contains_point(&(win->monitor_list), event->x, event->y) != RT_TRUE) - { - win = RT_NULL; - - /* try to find monitor on the panel */ - panel = rtgui_panel_get_contain(event->x, event->y); - if (panel != RT_NULL) - { - struct rtgui_panel_thread* thread; - - /* get active panel thread */ - if (panel->thread_list.next != RT_NULL) - { - thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); - if (!rtgui_mouse_monitor_contains_point(&(thread->monitor_list), - event->x, event->y) == RT_TRUE) - { - /* no monitor in this panel */ - panel = RT_NULL; - } - } - } - } - } - else - { - win = RT_NULL; - } - - /* check old panel or window */ - if (last_monitor_panel != RT_NULL) - { - rt_thread_t tid = rtgui_panel_get_active_thread(last_monitor_panel); - event->wid = RT_NULL; - - /* send mouse motion event */ - rtgui_thread_send(tid, &(event->parent), sizeof(struct rtgui_event_mouse)); - } - else if (last_monitor_topwin != RT_NULL) - { - event->wid = last_monitor_topwin->wid; - - /* send mouse motion event */ - rtgui_thread_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); - } - - if (last_monitor_panel != panel) - { - last_monitor_panel = panel; - if (last_monitor_panel != RT_NULL) - { - rt_thread_t tid = rtgui_panel_get_active_thread(last_monitor_panel); - event->wid = RT_NULL; - - /* send mouse motion event */ - rtgui_thread_send(tid, &(event->parent), sizeof(struct rtgui_event_mouse)); - } - } - - if (last_monitor_topwin != win) - { - last_monitor_topwin = win; - if (last_monitor_topwin != RT_NULL) - { - event->wid = last_monitor_topwin->wid; - - /* send mouse motion event */ - rtgui_thread_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); - } - } - - /* move mouse to (x, y) */ - rtgui_mouse_moveto(event->x, event->y); -} - -void rtgui_server_handle_kbd(struct rtgui_event_kbd* event) -{ - struct rtgui_topwin* wnd; - struct rtgui_panel* panel; - - /* re-init to server thread */ - RTGUI_EVENT_KBD_INIT(event); - - /* todo: handle input method and global shortcut */ - - /* send to focus window or focus panel */ - wnd = rtgui_server_focus_topwin; - if (wnd != RT_NULL && wnd->flag & WINTITLE_ACTIVATE) - { - /* send to focus window */ - event->wid = wnd->wid; - - /* send keyboard event to thread */ - rtgui_thread_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd)); - - return; - } - - panel = rtgui_server_focus_panel; - if (panel != RT_NULL) - { - /* send to focus panel */ - event->wid = RT_NULL; - - /* send keyboard event to thread */ - rtgui_thread_send(rtgui_panel_get_active_thread(panel), - (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd)); - } -} - -#ifdef __WIN32__ -#include -#endif - -/** - * rtgui server thread's entry - */ -static void rtgui_server_entry(void* parameter) -{ -#ifdef __WIN32__ - /* set the server thread to highest */ - HANDLE hCurrentThread = GetCurrentThread(); - SetThreadPriority(hCurrentThread, THREAD_PRIORITY_HIGHEST); -#endif - - /* init rtgui server msgq */ - rt_mq_init(&rtgui_server_mq, - "rtgui", - &rtgui_server_msg_pool[0], - 256, - sizeof(rtgui_server_msg_pool), - RT_IPC_FLAG_FIFO); - - /* register rtgui server thread */ - rtgui_thread_register(&rtgui_server_thread, &rtgui_server_mq); - - /* init mouse and show */ - rtgui_mouse_init(); -#ifdef RTGUI_USING_MOUSE_CURSOR - rtgui_mouse_show_cursor(); -#endif - - while (1) - { - /* the buffer uses to receive event */ - char event_buf[256]; - struct rtgui_event* event = (struct rtgui_event*)&(event_buf[0]); - - if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK) - { - /* dispatch event */ - switch (event->type) - { - /* panel event */ - case RTGUI_EVENT_PANEL_ATTACH: - /* register an application in panel */ - rtgui_server_create_application((struct rtgui_event_panel_attach*)event); - break; - - case RTGUI_EVENT_PANEL_DETACH: - /* unregister an application */ - rtgui_server_destroy_application((struct rtgui_event_panel_detach*)event); - break; - - case RTGUI_EVENT_PANEL_SHOW: - /* handle raise an application */ - rtgui_server_thread_panel_show((struct rtgui_event_panel_show*)event); - break; - - case RTGUI_EVENT_PANEL_HIDE: - /* handle hide an application */ - rtgui_server_thread_panel_hide((struct rtgui_event_panel_hide*)event); - break; - - case RTGUI_EVENT_SET_WM: - /* handle set workbench manager event */ - rtgui_server_handle_set_wm((struct rtgui_event_set_wm*)event); - break; - - /* window event */ - case RTGUI_EVENT_WIN_CREATE: - rtgui_thread_ack(event, RTGUI_STATUS_OK); - rtgui_topwin_add((struct rtgui_event_win_create*)event); - break; - - case RTGUI_EVENT_WIN_DESTROY: - if (rtgui_topwin_remove(((struct rtgui_event_win*)event)->wid) == RT_EOK) - rtgui_thread_ack(event, RTGUI_STATUS_OK); - else - rtgui_thread_ack(event, RTGUI_STATUS_ERROR); - break; - - case RTGUI_EVENT_WIN_SHOW: - rtgui_topwin_show((struct rtgui_event_win*)event); - break; - - case RTGUI_EVENT_WIN_HIDE: - rtgui_topwin_hide((struct rtgui_event_win*)event); - break; - - case RTGUI_EVENT_WIN_MOVE: - rtgui_topwin_move((struct rtgui_event_win_move*)event); - break; - - case RTGUI_EVENT_WIN_RESIZE: - rtgui_topwin_resize(((struct rtgui_event_win_resize*)event)->wid, - &(((struct rtgui_event_win_resize*)event)->rect)); - break; - - /* other event */ - case RTGUI_EVENT_UPDATE_BEGIN: -#ifdef RTGUI_USING_MOUSE_CURSOR - /* hide cursor */ - rtgui_mouse_hide_cursor(); -#endif - break; - - case RTGUI_EVENT_UPDATE_END: - /* handle screen update */ - rtgui_server_handle_update((struct rtgui_event_update_end*)event); -#ifdef RTGUI_USING_MOUSE_CURSOR - /* show cursor */ - rtgui_mouse_show_cursor(); -#endif - break; - - case RTGUI_EVENT_MONITOR_ADD: - /* handle mouse monitor */ - rtgui_server_handle_monitor_add((struct rtgui_event_monitor*)event); - break; - - /* mouse and keyboard event */ - case RTGUI_EVENT_MOUSE_MOTION: - /* handle mouse motion event */ - rtgui_server_handle_mouse_motion((struct rtgui_event_mouse*)event); - break; - - case RTGUI_EVENT_MOUSE_BUTTON: - /* handle mouse button */ - rtgui_server_handle_mouse_btn((struct rtgui_event_mouse*)event); - break; - - case RTGUI_EVENT_KBD: - /* handle keyboard event */ - rtgui_server_handle_kbd((struct rtgui_event_kbd*)event); - break; - - case RTGUI_EVENT_COMMAND: - break; - } - } - } - - /* unregister in rtgui thread */ - // rtgui_thread_deregister(rt_thread_self()); -} - -void rtgui_server_post_event(struct rtgui_event* event, rt_size_t size) -{ - rt_mq_send(&rtgui_server_mq, event, size); -} - -void rtgui_server_init() -{ - rt_thread_init(&rtgui_server_thread, - "rtgui", - rtgui_server_entry, RT_NULL, - &rtgui_server_stack[0], sizeof(rtgui_server_stack), - RTGUI_SVR_THREAD_PRIORITY, - RTGUI_SVR_THREAD_TIMESLICE); - - /* start rtgui server thread */ - rt_thread_startup(&rtgui_server_thread); -} +#include + +#include "mouse.h" +#include "panel.h" +#include "topwin.h" + +static struct rt_thread *rtgui_server_tid; +static struct rt_messagequeue *rtgui_server_mq; + +extern struct rtgui_topwin* rtgui_server_focus_topwin; +struct rtgui_panel* rtgui_server_focus_panel = RT_NULL; + +void rtgui_server_create_application(struct rtgui_event_panel_attach* event) +{ + struct rtgui_panel* panel = rtgui_panel_find(event->panel_name); + + if (panel != RT_NULL) + { + struct rtgui_event_panel_info ep; + RTGUI_EVENT_PANEL_INFO_INIT(&ep); + + if (panel->wm_thread != RT_NULL) + { + /* notify to workbench */ + rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_attach)); + } + + /* send the responses - ok */ + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); + + /* send the panel info */ + ep.panel = panel; + ep.extent = panel->extent; + rtgui_thread_send(event->parent.sender, (struct rtgui_event*)&ep, sizeof(ep)); + + rtgui_panel_thread_add(event->panel_name, event->parent.sender); + } + else + { + /* send the responses - failure */ + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_NRC); + } +} + +void rtgui_server_destroy_application(struct rtgui_event_panel_detach* event) +{ + struct rtgui_panel* panel = event->panel; + + if (panel != RT_NULL) + { + if (panel->wm_thread != RT_NULL) + { + /* notify to workbench */ + rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_detach)); + } + + /* send the responses */ + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); + + rtgui_panel_thread_remove(panel, event->parent.sender); + + { + /* get next thread and active it */ + rt_thread_t tid = rtgui_panel_get_active_thread(panel); + + /* let this thread repaint */ + struct rtgui_event_paint epaint; + RTGUI_EVENT_PAINT_INIT(&epaint); + epaint.wid = RT_NULL; + rtgui_thread_send(tid, (struct rtgui_event*)&epaint, sizeof(epaint)); + } + } + else + { + /* send the responses - failure */ + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_NRC); + } +} + +void rtgui_server_thread_panel_show(struct rtgui_event_panel_show* event) +{ + struct rtgui_panel* panel = event->panel; + + if (panel != RT_NULL) + { + struct rtgui_event_paint epaint; + + /* send the responses */ + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); + + if (panel->wm_thread != RT_NULL) + { + /* notify to workbench */ + rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_show)); + } + + rtgui_panel_set_active_thread(panel, event->parent.sender); + + /* send all topwin clip info */ + rtgui_topwin_update_clip_to_panel(panel); + + /* send paint event */ + RTGUI_EVENT_PAINT_INIT(&epaint); + epaint.wid = RT_NULL; + rtgui_thread_send(event->parent.sender, (struct rtgui_event*)&epaint, + sizeof(epaint)); + } + else + { + /* send failed */ + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); + } +} + +void rtgui_server_thread_panel_hide(struct rtgui_event_panel_hide* event) +{ + struct rtgui_panel* panel = event->panel; + + if (panel != RT_NULL) + { + rt_thread_t tid; + struct rtgui_event_paint epaint; + + /* send the responses */ + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); + + if (panel->thread_list.next != RT_NULL) + { + struct rtgui_panel_thread* thread; + thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); + + /* remove it */ + panel->thread_list.next = thread->list.next; + + /* append to the tail of thread list */ + rtgui_list_append(&(panel->thread_list), &(thread->list)); + } + + /* get new active thread */ + tid = rtgui_panel_get_active_thread(panel); + /* send all topwin clip info */ + rtgui_topwin_update_clip_to_panel(panel); + + /* send paint event */ + RTGUI_EVENT_PAINT_INIT(&epaint); + epaint.wid = RT_NULL; + rtgui_thread_send(tid, (struct rtgui_event*)&epaint, sizeof(epaint)); + } + else + { + /* send failed */ + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); + } +} + +void rtgui_server_handle_set_wm(struct rtgui_event_set_wm *event) +{ + struct rtgui_panel* panel = rtgui_panel_find(event->panel_name); + + if (panel != RT_NULL) + { + rtgui_panel_set_wm(panel, event->parent.sender); + } +} + +void rtgui_server_handle_update(struct rtgui_event_update_end* event) +{ + struct rtgui_graphic_driver* driver = rtgui_graphic_driver_get_default(); + if (driver != RT_NULL) + { + driver->screen_update(&(event->rect)); + } +} + +void rtgui_server_handle_monitor_add(struct rtgui_event_monitor* event) +{ + if (event->panel != RT_NULL) + { + /* append monitor rect to panel list */ + rtgui_panel_append_monitor_rect(event->panel, event->parent.sender, &(event->rect)); + } + else + { + /* add monitor rect to top window list */ + rtgui_topwin_append_monitor_rect(event->wid, &(event->rect)); + } +} + +void rtgui_server_handle_monitor_remove(struct rtgui_event_monitor* event) +{ + if (event->panel != RT_NULL) + { + /* add monitor rect to panel list */ + rtgui_panel_remove_monitor_rect(event->panel, event->parent.sender, &(event->rect)); + } + else + { + /* add monitor rect to top window list */ + rtgui_topwin_remove_monitor_rect(event->wid, &(event->rect)); + } +} + +void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event) +{ + struct rtgui_topwin* wnd; + struct rtgui_panel* panel; + + /* re-init to server thread */ + RTGUI_EVENT_MOUSE_BUTTON_INIT(event); + + if (rtgui_winrect_is_moved() && + event->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP)) + { + struct rtgui_topwin* topwin; + rtgui_rect_t rect; + + if (rtgui_winrect_moved_done(&rect, &topwin) == RT_TRUE) + { + struct rtgui_event_win_move ewin; + + /* move window */ + RTGUI_EVENT_WIN_MOVE_INIT(&ewin); + ewin.wid = topwin->wid; + if (topwin->title != RT_NULL) + { + if (topwin->flag & WINTITLE_BORDER) + { + ewin.x = rect.x1 + WINTITLE_BORDER_SIZE; + ewin.y = rect.y1 + WINTITLE_BORDER_SIZE; + } + if (!(topwin->flag & WINTITLE_NO)) ewin.y += WINTITLE_HEIGHT; + } + else + { + ewin.x = rect.x1; + ewin.y = rect.y1; + } + + /* send to client thread */ + rtgui_thread_send(topwin->tid, &(ewin.parent), sizeof(ewin)); + + return; + } + } + + /* get the wnd which contains the mouse */ + wnd = rtgui_topwin_get_wnd(event->x, event->y); + if (wnd != RT_NULL) + { + event->wid = wnd->wid; + + if (rtgui_server_focus_topwin != wnd) + { + /* raise this window */ + rtgui_topwin_raise(wnd->wid, wnd->tid); + rtgui_server_focus_panel = RT_NULL; + } + + if (wnd->title != RT_NULL && + rtgui_rect_contains_point(&(RTGUI_WIDGET(wnd->title)->extent), event->x, event->y) == RT_EOK) + { + rtgui_topwin_title_onmouse(wnd, event); + } + else + { + /* send mouse event to thread */ + rtgui_thread_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_mouse)); + } + return ; + } + + /* get the panel which contains the mouse */ + panel = rtgui_panel_get_contain(event->x, event->y); + if (panel != RT_NULL) + { + /* deactivate old window */ + if (rtgui_server_focus_topwin != RT_NULL) + { + rtgui_topwin_deactivate_win(rtgui_server_focus_topwin); + } + + rtgui_server_focus_panel = panel; + rtgui_server_focus_topwin = RT_NULL; + + /* set destination window to null */ + event->wid = RT_NULL; + + /* send mouse event to thread */ + rtgui_thread_send(rtgui_panel_get_active_thread(panel), + (struct rtgui_event*)event, + sizeof(struct rtgui_event_mouse)); + } +} + +static struct rtgui_panel* last_monitor_panel = RT_NULL; +static struct rtgui_topwin* last_monitor_topwin = RT_NULL; + +void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse* event) +{ + /* the topwin contains current mouse */ + struct rtgui_topwin* win = RT_NULL; + struct rtgui_panel* panel = RT_NULL; + + /* re-init mouse event */ + RTGUI_EVENT_MOUSE_MOTION_INIT(event); + + /* find the panel or topwin which monitor the mouse motion */ + win = rtgui_topwin_get_wnd(event->x, event->y); + if (win == RT_NULL) + { + /* try to find monitor on the panel */ + panel = rtgui_panel_get_contain(event->x, event->y); + + if (panel != RT_NULL) + { + struct rtgui_panel_thread* thread; + + /* get active panel thread */ + if (panel->thread_list.next != RT_NULL) + { + thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); + if (!rtgui_mouse_monitor_contains_point(&(thread->monitor_list), + event->x, event->y) == RT_TRUE) + { + /* no monitor in this panel */ + panel = RT_NULL; + } + } + } + } + else if (win->monitor_list.next != RT_NULL) + { + /* check whether the monitor exist */ + if (rtgui_mouse_monitor_contains_point(&(win->monitor_list), event->x, event->y) != RT_TRUE) + { + win = RT_NULL; + + /* try to find monitor on the panel */ + panel = rtgui_panel_get_contain(event->x, event->y); + if (panel != RT_NULL) + { + struct rtgui_panel_thread* thread; + + /* get active panel thread */ + if (panel->thread_list.next != RT_NULL) + { + thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list); + if (!rtgui_mouse_monitor_contains_point(&(thread->monitor_list), + event->x, event->y) == RT_TRUE) + { + /* no monitor in this panel */ + panel = RT_NULL; + } + } + } + } + } + else + { + win = RT_NULL; + } + + /* check old panel or window */ + if (last_monitor_panel != RT_NULL) + { + rt_thread_t tid = rtgui_panel_get_active_thread(last_monitor_panel); + event->wid = RT_NULL; + + /* send mouse motion event */ + rtgui_thread_send(tid, &(event->parent), sizeof(struct rtgui_event_mouse)); + } + else if (last_monitor_topwin != RT_NULL) + { + event->wid = last_monitor_topwin->wid; + + /* send mouse motion event */ + rtgui_thread_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); + } + + if (last_monitor_panel != panel) + { + last_monitor_panel = panel; + if (last_monitor_panel != RT_NULL) + { + rt_thread_t tid = rtgui_panel_get_active_thread(last_monitor_panel); + event->wid = RT_NULL; + + /* send mouse motion event */ + rtgui_thread_send(tid, &(event->parent), sizeof(struct rtgui_event_mouse)); + } + } + + if (last_monitor_topwin != win) + { + last_monitor_topwin = win; + if (last_monitor_topwin != RT_NULL) + { + event->wid = last_monitor_topwin->wid; + + /* send mouse motion event */ + rtgui_thread_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); + } + } + + /* move mouse to (x, y) */ + rtgui_mouse_moveto(event->x, event->y); +} + +void rtgui_server_handle_kbd(struct rtgui_event_kbd* event) +{ + struct rtgui_topwin* wnd; + struct rtgui_panel* panel; + + /* re-init to server thread */ + RTGUI_EVENT_KBD_INIT(event); + + /* todo: handle input method and global shortcut */ + + /* send to focus window or focus panel */ + wnd = rtgui_server_focus_topwin; + if (wnd != RT_NULL && wnd->flag & WINTITLE_ACTIVATE) + { + /* send to focus window */ + event->wid = wnd->wid; + + /* send keyboard event to thread */ + rtgui_thread_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd)); + + return; + } + + panel = rtgui_server_focus_panel; + if (panel != RT_NULL) + { + /* send to focus panel */ + event->wid = RT_NULL; + + /* send keyboard event to thread */ + rtgui_thread_send(rtgui_panel_get_active_thread(panel), + (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd)); + } +} + +#ifdef __WIN32__ +#include +#endif + +/** + * rtgui server thread's entry + */ +static void rtgui_server_entry(void* parameter) +{ +#ifdef __WIN32__ + /* set the server thread to highest */ + HANDLE hCurrentThread = GetCurrentThread(); + SetThreadPriority(hCurrentThread, THREAD_PRIORITY_HIGHEST); +#endif + + /* create rtgui server msgq */ + rtgui_server_mq = rt_mq_create("rtgui", + 256, 8, RT_IPC_FLAG_FIFO); + /* register rtgui server thread */ + rtgui_thread_register(rtgui_server_tid, rtgui_server_mq); + + /* init mouse and show */ + rtgui_mouse_init(); +#ifdef RTGUI_USING_MOUSE_CURSOR + rtgui_mouse_show_cursor(); +#endif + + while (1) + { + /* the buffer uses to receive event */ + char event_buf[256]; + struct rtgui_event* event = (struct rtgui_event*)&(event_buf[0]); + + if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK) + { + /* dispatch event */ + switch (event->type) + { + /* panel event */ + case RTGUI_EVENT_PANEL_ATTACH: + /* register an application in panel */ + rtgui_server_create_application((struct rtgui_event_panel_attach*)event); + break; + + case RTGUI_EVENT_PANEL_DETACH: + /* unregister an application */ + rtgui_server_destroy_application((struct rtgui_event_panel_detach*)event); + break; + + case RTGUI_EVENT_PANEL_SHOW: + /* handle raise an application */ + rtgui_server_thread_panel_show((struct rtgui_event_panel_show*)event); + break; + + case RTGUI_EVENT_PANEL_HIDE: + /* handle hide an application */ + rtgui_server_thread_panel_hide((struct rtgui_event_panel_hide*)event); + break; + + case RTGUI_EVENT_SET_WM: + /* handle set workbench manager event */ + rtgui_server_handle_set_wm((struct rtgui_event_set_wm*)event); + break; + + /* window event */ + case RTGUI_EVENT_WIN_CREATE: + rtgui_thread_ack(event, RTGUI_STATUS_OK); + rtgui_topwin_add((struct rtgui_event_win_create*)event); + break; + + case RTGUI_EVENT_WIN_DESTROY: + if (rtgui_topwin_remove(((struct rtgui_event_win*)event)->wid) == RT_EOK) + rtgui_thread_ack(event, RTGUI_STATUS_OK); + else + rtgui_thread_ack(event, RTGUI_STATUS_ERROR); + break; + + case RTGUI_EVENT_WIN_SHOW: + rtgui_topwin_show((struct rtgui_event_win*)event); + break; + + case RTGUI_EVENT_WIN_HIDE: + rtgui_topwin_hide((struct rtgui_event_win*)event); + break; + + case RTGUI_EVENT_WIN_MOVE: + rtgui_topwin_move((struct rtgui_event_win_move*)event); + break; + + case RTGUI_EVENT_WIN_RESIZE: + rtgui_topwin_resize(((struct rtgui_event_win_resize*)event)->wid, + &(((struct rtgui_event_win_resize*)event)->rect)); + break; + + /* other event */ + case RTGUI_EVENT_UPDATE_BEGIN: +#ifdef RTGUI_USING_MOUSE_CURSOR + /* hide cursor */ + rtgui_mouse_hide_cursor(); +#endif + break; + + case RTGUI_EVENT_UPDATE_END: + /* handle screen update */ + rtgui_server_handle_update((struct rtgui_event_update_end*)event); +#ifdef RTGUI_USING_MOUSE_CURSOR + /* show cursor */ + rtgui_mouse_show_cursor(); +#endif + break; + + case RTGUI_EVENT_MONITOR_ADD: + /* handle mouse monitor */ + rtgui_server_handle_monitor_add((struct rtgui_event_monitor*)event); + break; + + /* mouse and keyboard event */ + case RTGUI_EVENT_MOUSE_MOTION: + /* handle mouse motion event */ + rtgui_server_handle_mouse_motion((struct rtgui_event_mouse*)event); + break; + + case RTGUI_EVENT_MOUSE_BUTTON: + /* handle mouse button */ + rtgui_server_handle_mouse_btn((struct rtgui_event_mouse*)event); + break; + + case RTGUI_EVENT_KBD: + /* handle keyboard event */ + rtgui_server_handle_kbd((struct rtgui_event_kbd*)event); + break; + + case RTGUI_EVENT_COMMAND: + break; + } + } + } + + /* unregister in rtgui thread */ + // rtgui_thread_deregister(rt_thread_self()); +} + +void rtgui_server_post_event(struct rtgui_event* event, rt_size_t size) +{ + rt_mq_send(rtgui_server_mq, event, size); +} + +void rtgui_server_init() +{ + rtgui_server_tid = rt_thread_create("rtgui", + rtgui_server_entry, RT_NULL, + RTGUI_SVR_THREAD_STACK_SIZE, + RTGUI_SVR_THREAD_PRIORITY, + RTGUI_SVR_THREAD_TIMESLICE); + + /* start rtgui server thread */ + if (rtgui_server_tid != RT_NULL) + rt_thread_startup(rtgui_server_tid); +} diff --git a/rtgui/server/topwin.c b/rtgui/server/topwin.c index caf374b41..6f2c72301 100644 --- a/rtgui/server/topwin.c +++ b/rtgui/server/topwin.c @@ -1,873 +1,873 @@ -/* - * File : topwin.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-16 Bernard first version - */ -#include "panel.h" -#include "topwin.h" -#include "mouse.h" - -#include -#include -#include -#include -#include - -struct rtgui_topwin* rtgui_server_focus_topwin = RT_NULL; - -static struct rtgui_list_node _rtgui_topwin_show_list; -static struct rtgui_list_node _rtgui_topwin_hide_list; - -static void rtgui_topwin_update_clip(void); -static void rtgui_topwin_redraw(struct rtgui_rect* rect); - -#define WINTITLE_CB_WIDTH 14 -#define WINTITLE_CB_HEIGHT 14 - -void rtgui_topwin_init() -{ - /* init window list */ - rtgui_list_init(&_rtgui_topwin_show_list); - rtgui_list_init(&_rtgui_topwin_hide_list); -} - -static struct rtgui_topwin* -rtgui_topwin_search_in_list(struct rtgui_win* wid, struct rtgui_list_node* list) -{ - struct rtgui_list_node* node; - struct rtgui_topwin* topwin; - - /* search in list */ - rtgui_list_foreach(node, list) - { - topwin = rtgui_list_entry(node, struct rtgui_topwin, list); - - /* is this node? */ - if (topwin->wid == wid) - { - return topwin; - } - } - - return RT_NULL; -} - -/* add a window to window list[hide] */ -rt_err_t rtgui_topwin_add(struct rtgui_event_win_create* event) -{ - struct rtgui_topwin* topwin; - - topwin = rtgui_malloc(sizeof(struct rtgui_topwin)); - if (topwin == RT_NULL) return -RT_ERROR; - - topwin->wid = event->wid; - topwin->extent = event->extent; - topwin->tid = event->parent.sender; - topwin->mask = event->mask; - - topwin->flag = 0; - if (event->flag & RTGUI_WIN_STYLE_NO_TITLE) topwin->flag |= WINTITLE_NO; - if (event->flag & RTGUI_WIN_STYLE_CLOSEBOX) topwin->flag |= WINTITLE_CLOSEBOX; - if (!(event->flag & RTGUI_WIN_STYLE_NO_BORDER)) topwin->flag |= WINTITLE_BORDER; - if (event->flag & RTGUI_WIN_STYLE_NO_FOCUS) topwin->flag |= WINTITLE_NOFOCUS; - - if(!(topwin->flag & WINTITLE_NO) || (topwin->flag & WINTITLE_BORDER)) - { - /* get win extent */ - rtgui_rect_t rect = topwin->extent; - - /* add border rect */ - if (topwin->flag & WINTITLE_BORDER) - { - rect.x1 -= WINTITLE_BORDER_SIZE; - rect.y1 -= WINTITLE_BORDER_SIZE; - rect.x2 += WINTITLE_BORDER_SIZE; - rect.y2 += WINTITLE_BORDER_SIZE; - } - - /* add title rect */ - if (!(topwin->flag & WINTITLE_NO)) rect.y1 -= WINTITLE_HEIGHT; - - topwin->title = rtgui_wintitle_create(event->title); - rtgui_widget_set_rect(RTGUI_WIDGET(topwin->title), &rect); - - /* update clip info */ - rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(topwin->title)); - rtgui_region_subtract_rect(&(RTGUI_WIDGET(topwin->title)->clip), - &(RTGUI_WIDGET(topwin->title)->clip), - &(topwin->extent)); - } - else topwin->title = RT_NULL; - - rtgui_list_init(&topwin->list); - rtgui_list_init(&topwin->monitor_list); - - /* add topwin node to the hidden window list */ - rtgui_list_insert(&(_rtgui_topwin_hide_list), &(topwin->list)); - - return RT_EOK; -} - -rt_err_t rtgui_topwin_remove(struct rtgui_win* wid) -{ - struct rtgui_topwin* topwin; - - /* find the topwin node */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); - - if (topwin) - { - /* remove node from list */ - rtgui_list_remove(&_rtgui_topwin_show_list, &(topwin->list)); - - rtgui_topwin_update_clip(); - - /* redraw the old rect */ - rtgui_topwin_redraw(&(topwin->extent)); - - if (rtgui_server_focus_topwin == topwin) - { - /* activate the next window */ - if (_rtgui_topwin_show_list.next != RT_NULL) - { - struct rtgui_event_win wevent; - struct rtgui_topwin* wnd; - - /* get the topwin */ - wnd = rtgui_list_entry(_rtgui_topwin_show_list.next, - struct rtgui_topwin, list); - - /* activate the window */ - RTGUI_EVENT_WIN_ACTIVATE_INIT(&wevent); - wevent.wid = wnd->wid; - rtgui_thread_send(wnd->tid, &(wevent.parent), sizeof(struct rtgui_event_win)); - - /* set new focus topwin */ - rtgui_server_focus_topwin = wnd; - } - else - { - /* there is no shown window right now */ - rtgui_server_focus_topwin = RT_NULL; - } - } - - /* free the monitor rect list, topwin node and title */ - while (topwin->monitor_list.next != RT_NULL) - { - struct rtgui_mouse_monitor* monitor = rtgui_list_entry(topwin->monitor_list.next, - struct rtgui_mouse_monitor, list); - - topwin->monitor_list.next = topwin->monitor_list.next->next; - rtgui_free(monitor); - } - - /* destroy win title */ - rtgui_wintitle_destroy(topwin->title); - topwin->title = RT_NULL; - - rtgui_free(topwin); - - return RT_EOK; - } - - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); - if (topwin) - { - /* remove node from list */ - rtgui_list_remove(&_rtgui_topwin_hide_list, &(topwin->list)); - - /* free the topwin node and title */ - rtgui_wintitle_destroy(topwin->title); - topwin->title = RT_NULL; - - rtgui_free(topwin); - - return RT_EOK; - } - - return -RT_ERROR; -} - -/* activate a win - * - deactivate the old focus win - * - activate a win - * - set the focus win to activate win - * - draw win title - */ -void rtgui_topwin_activate_win(struct rtgui_topwin* win) -{ - struct rtgui_event_win event; - - /* activate the raised window */ - RTGUI_EVENT_WIN_ACTIVATE_INIT(&event); - event.wid = win->wid; - rtgui_thread_send(win->tid, &(event.parent), sizeof(struct rtgui_event_win)); - - /* redraw title */ - if (win->title != RT_NULL) - { - win->flag |= WINTITLE_ACTIVATE; - rtgui_theme_draw_win(win); - } - - if (rtgui_server_focus_topwin != RT_NULL) - { - /* deactivate the old focus win */ - RTGUI_EVENT_WIN_DEACTIVATE_INIT(&event); - event.wid = rtgui_server_focus_topwin->wid; - rtgui_thread_send(rtgui_server_focus_topwin->tid, - &event.parent, sizeof(struct rtgui_event_win)); - - /* redraw title */ - if (rtgui_server_focus_topwin->title != RT_NULL) - { - rtgui_server_focus_topwin->flag &= ~WINTITLE_ACTIVATE; - rtgui_theme_draw_win(rtgui_server_focus_topwin); - } - } - - rtgui_server_focus_topwin = win; -} - -/* - * deactivate a win - * - deactivate the win - * - redraw win title - * - set rtgui_server_focus_topwin - */ -void rtgui_topwin_deactivate_win(struct rtgui_topwin* win) -{ - /* deactivate win */ - struct rtgui_event_win event; - RTGUI_EVENT_WIN_DEACTIVATE_INIT(&event); - event.wid = win->wid; - rtgui_thread_send(win->tid, - &event.parent, sizeof(struct rtgui_event_win)); - - win->flag &= ~WINTITLE_ACTIVATE; - rtgui_theme_draw_win(win); - - if (rtgui_server_focus_topwin == win) - { - rtgui_server_focus_topwin = RT_NULL; - } -} - -/* raise window to front */ -void rtgui_topwin_raise(struct rtgui_win* wid, rt_thread_t sender) -{ - struct rtgui_topwin* topwin; - - /* find the topwin node */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); - if (topwin) - { - rt_int32_t count; - struct rtgui_list_node* node; - struct rtgui_event_clip_info* eclip; - struct rtgui_rect* rect; - - /* the window is already placed in front */ - if (&(topwin->list) == _rtgui_topwin_show_list.next) - { - rtgui_server_focus_topwin = RT_NULL; - rtgui_topwin_activate_win(topwin); - return ; - } - - /* update clip info */ - count = 0; - node = _rtgui_topwin_show_list.next; - while (node != &(topwin->list)) - { - count ++; - node = node->next; - } - - eclip = (struct rtgui_event_clip_info*)rtgui_malloc(sizeof(struct rtgui_event_clip_info) - + (count + 1)* sizeof(struct rtgui_rect)); - - /* reset clip info to top window */ - RTGUI_EVENT_CLIP_INFO_INIT(eclip); - eclip->num_rect = 0; - eclip->wid = topwin->wid; - /* send to destination window */ - rtgui_thread_send(topwin->tid, &(eclip->parent), sizeof(struct rtgui_event_clip_info)); - - /* reset clip info in title */ - rtgui_toplevel_handle_clip(RTGUI_TOPLEVEL(topwin->title), eclip); - rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(topwin->title)); - rtgui_region_subtract_rect(&(RTGUI_WIDGET(topwin->title)->clip), - &(RTGUI_WIDGET(topwin->title)->clip), - &(topwin->extent)); - - rect = RTGUI_EVENT_GET_RECT(eclip, 0); - *rect = (topwin->title != RT_NULL)? RTGUI_WIDGET(topwin->title)->extent : topwin->extent; - - count = 1; - for (node = _rtgui_topwin_show_list.next; - node != &(topwin->list); - node = node->next) - { - struct rtgui_topwin* wnd; - wnd = rtgui_list_entry(node, struct rtgui_topwin, list); - - eclip->num_rect = count; - eclip->wid = wnd->wid; - - /* send to destination window */ - rtgui_thread_send(wnd->tid, &(eclip->parent), - sizeof(struct rtgui_event_clip_info) + count * sizeof(struct rtgui_rect)); - - /* reset clip info in title */ - rtgui_toplevel_handle_clip(RTGUI_TOPLEVEL(wnd->title), eclip); - rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(wnd->title)); - rtgui_region_subtract_rect(&(RTGUI_WIDGET(wnd->title)->clip), - &(RTGUI_WIDGET(wnd->title)->clip), - &(wnd->extent)); - - rect = RTGUI_EVENT_GET_RECT(eclip, count++); - *rect = (wnd->title != RT_NULL)? RTGUI_WIDGET(wnd->title)->extent : wnd->extent; - } - - /* release clip info event */ - rtgui_free(eclip); - - /* remove node from list */ - rtgui_list_remove(&_rtgui_topwin_show_list, &(topwin->list)); - /* add to front */ - rtgui_list_insert(&_rtgui_topwin_show_list, &(topwin->list)); - - rtgui_topwin_activate_win(topwin); - } -} - -/* show a window */ -void rtgui_topwin_show(struct rtgui_event_win* event) -{ - struct rtgui_topwin* topwin; - struct rtgui_win* wid = event->wid; - rt_thread_t sender = RTGUI_EVENT(event)->sender; - - /* find in hide list */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); - - /* find it */ - if (topwin != RT_NULL) - { - /* remove node from hidden list */ - rtgui_list_remove(&_rtgui_topwin_hide_list, &(topwin->list)); - - /* add node to show list */ - rtgui_list_insert(&_rtgui_topwin_show_list, &(topwin->list)); - - /* show window title */ - if (topwin->title != RT_NULL) - { - RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(topwin->title)); - } - - /* update clip info */ - rtgui_topwin_update_clip(); - - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); - - /* activate this window */ - rtgui_topwin_activate_win(topwin); - } - else - { - /* the wnd is located in show list, raise wnd to front */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); - if (topwin != RT_NULL) - { - if (_rtgui_topwin_show_list.next != &(topwin->list)) - { - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); - - /* not the front window, raise it */ - rtgui_topwin_raise(wid, sender); - } - } - else - { - /* there is no wnd in wnd list */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); - } - } -} - -/* send clip info to panel */ -void rtgui_topwin_update_clip_to_panel(struct rtgui_panel* panel) -{ - rt_uint32_t count; - rt_thread_t tid; - struct rtgui_list_node* node; - struct rtgui_event_clip_info* eclip; - - /* get topwin count */ - count = 0; - node = _rtgui_topwin_show_list.next; - while (node != RT_NULL) - { - count ++; - node = node->next; - } - - eclip = (struct rtgui_event_clip_info*)rtgui_malloc(sizeof(struct rtgui_event_clip_info) - + (count + 1)* sizeof(struct rtgui_rect)); - if (eclip == RT_NULL) - { - /* no memory */ - return ; - } - - /* reset clip info to top window */ - RTGUI_EVENT_CLIP_INFO_INIT(eclip); - eclip->num_rect = count; eclip->wid = RT_NULL; - - count = 0; - for (node = _rtgui_topwin_show_list.next; node != RT_NULL; node = node->next) - { - struct rtgui_topwin* wnd; - struct rtgui_rect* rect; - - wnd = rtgui_list_entry(node, struct rtgui_topwin, list); - - rect = RTGUI_EVENT_GET_RECT(eclip, count++); - *rect = (wnd->title != RT_NULL)? RTGUI_WIDGET(wnd->title)->extent : wnd->extent; - } - - /* send to the activated thread of panel */ - tid = rtgui_panel_get_active_thread(panel); - rtgui_thread_send(tid, (struct rtgui_event*)eclip, sizeof(struct rtgui_event_clip_info) - + count* sizeof(struct rtgui_rect)); - - /* release clip info event */ - rtgui_free(eclip); -} - -/* hide a window */ -void rtgui_topwin_hide(struct rtgui_event_win* event) -{ - struct rtgui_topwin* topwin; - struct rtgui_win* wid = event->wid; - - /* find in show list */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); - - /* found it */ - if (topwin) - { - /* remove node from show list */ - rtgui_list_remove(&_rtgui_topwin_show_list, &(topwin->list)); - - /* add node to hidden list */ - rtgui_list_insert(&_rtgui_topwin_hide_list, &(topwin->list)); - - /* show window title */ - if (topwin->title != RT_NULL) - { - RTGUI_WIDGET_HIDE(RTGUI_WIDGET(topwin->title)); - } - - /* update clip info */ - rtgui_topwin_update_clip(); - - /* redraw the old rect */ - rtgui_topwin_redraw(&(topwin->extent)); - - if (rtgui_server_focus_topwin == topwin) - { - /* activate the next window */ - if (_rtgui_topwin_show_list.next != RT_NULL) - { - /* get the topwin */ - topwin = rtgui_list_entry(_rtgui_topwin_show_list.next, - struct rtgui_topwin, list); - - rtgui_server_focus_topwin = RT_NULL; - rtgui_topwin_activate_win(topwin); - } - else - { - /* there is no shown window right now */ - rtgui_server_focus_topwin = RT_NULL; - } - } - } - else - { - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); - return; - } - - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); -} - -/* move top window */ -void rtgui_topwin_move(struct rtgui_event_win_move* event) -{ - struct rtgui_topwin* topwin; - - /* find in show list */ - topwin = rtgui_topwin_search_in_list(event->wid, &_rtgui_topwin_show_list); - if (topwin != RT_NULL) - { - int dx, dy; - rtgui_rect_t rect; /* the old topwin coverage area */ - struct rtgui_list_node* node; - - /* send status ok */ - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); - - /* get the delta move x, y */ - dx = event->x - topwin->extent.x1; - dy = event->y - topwin->extent.y1; - - rect = topwin->extent; - /* move window rect */ - rtgui_rect_moveto(&(topwin->extent), dx, dy); - - /* move window title */ - if (topwin->title != RT_NULL) - { - rect = RTGUI_WIDGET(topwin->title)->extent; - rtgui_widget_move_to_logic(RTGUI_WIDGET(topwin->title), dx, dy); - } - - /* move the monitor rect list */ - rtgui_list_foreach(node, &(topwin->monitor_list)) - { - struct rtgui_mouse_monitor* monitor = rtgui_list_entry(node, - struct rtgui_mouse_monitor, - list); - rtgui_rect_moveto(&(monitor->rect), dx, dy); - } - - /* update windows clip info */ - rtgui_topwin_update_clip(); - - /* update top window title */ - if (topwin->title != RT_NULL) rtgui_theme_draw_win(topwin); - if (rtgui_rect_is_intersect(&rect, &(topwin->extent)) != RT_EOK) - { - /* - * the old rect is not intersect with moved rect, - * re-paint window - */ - struct rtgui_event_paint epaint; - RTGUI_EVENT_PAINT_INIT(&epaint); - epaint.wid = topwin->wid; - rtgui_thread_send(topwin->tid, &(epaint.parent), sizeof(epaint)); - } - - /* update old window coverage area */ - rtgui_topwin_redraw(&rect); - } - else - { - rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); - } -} - -/* - * resize a top win - * Note: currently, only support resize hidden window - */ -void rtgui_topwin_resize(struct rtgui_win* wid, rtgui_rect_t* r) -{ - struct rtgui_topwin* topwin; - - /* find in show list */ - topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); - if (topwin) - { - topwin->extent = *r; - - if (topwin->title != RT_NULL) - { - /* get win extent */ - rtgui_rect_t rect = topwin->extent; - - /* add border rect */ - if (topwin->flag & WINTITLE_BORDER) - { - rect.x1 -= WINTITLE_BORDER_SIZE; - rect.y1 -= WINTITLE_BORDER_SIZE; - rect.x2 += WINTITLE_BORDER_SIZE; - rect.y2 += WINTITLE_BORDER_SIZE; - } - - /* add title rect */ - if (!(topwin->flag & WINTITLE_NO)) rect.y1 -= WINTITLE_HEIGHT; - - RTGUI_WIDGET(topwin->title)->extent = rect; - - /* update title & border clip info */ - rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(topwin->title)); - rtgui_region_subtract_rect(&(RTGUI_WIDGET(topwin->title)->clip), - &(RTGUI_WIDGET(topwin->title)->clip), - &(topwin->extent)); - } - } -} - -struct rtgui_topwin* rtgui_topwin_get_wnd(int x, int y) -{ - struct rtgui_list_node* node; - struct rtgui_topwin* topwin; - - /* search in list */ - rtgui_list_foreach(node, &(_rtgui_topwin_show_list)) - { - topwin = rtgui_list_entry(node, struct rtgui_topwin, list); - - /* is this window? */ - if ((topwin->title != RT_NULL) && - rtgui_rect_contains_point(&(RTGUI_WIDGET(topwin->title)->extent), x, y) == RT_EOK) - { - return topwin; - } - else if (rtgui_rect_contains_point(&(topwin->extent), x, y) == RT_EOK) - { - return topwin; - } - } - - return RT_NULL; -} - -extern struct rtgui_list_node _rtgui_panel_list; -static void rtgui_topwin_update_clip() -{ - rt_int32_t count = 0; - struct rtgui_event_clip_info* eclip; - struct rtgui_list_node* node = _rtgui_topwin_show_list.next; - - /* calculate count */ - while (node != RT_NULL) - { - count ++; - node = node->next; - } - - eclip = (struct rtgui_event_clip_info*)rtgui_malloc(sizeof(struct rtgui_event_clip_info) - + count * sizeof(struct rtgui_rect)); - RTGUI_EVENT_CLIP_INFO_INIT(eclip); - - count = 0; - rtgui_list_foreach(node, &_rtgui_topwin_show_list) - { - struct rtgui_rect* rect; - struct rtgui_topwin* wnd; - wnd = rtgui_list_entry(node, struct rtgui_topwin, list); - - eclip->num_rect = count; - eclip->wid = wnd->wid; - - /* send to destination window */ - rtgui_thread_send(wnd->tid, &(eclip->parent), - sizeof(struct rtgui_event_clip_info) + count * sizeof(struct rtgui_rect)); - - /* update clip in win title */ - if (wnd->title != RT_NULL) - { - /* reset clip info */ - rtgui_toplevel_handle_clip(RTGUI_TOPLEVEL(wnd->title), eclip); - rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(wnd->title)); - rtgui_region_subtract_rect(&(RTGUI_WIDGET(wnd->title)->clip), - &(RTGUI_WIDGET(wnd->title)->clip), - &(wnd->extent)); - } - - rect = RTGUI_EVENT_GET_RECT(eclip, count++); - *rect = (wnd->title != RT_NULL)? RTGUI_WIDGET(wnd->title)->extent : wnd->extent; - } - - /* send clip info to each panel */ - eclip->wid = RT_NULL; - eclip->num_rect = count; - - rtgui_list_foreach(node, &(_rtgui_panel_list)) - { - struct rtgui_panel* panel; - struct rtgui_list_node* panel_node; - - panel = rtgui_list_entry(node, struct rtgui_panel, sibling); - - rtgui_list_foreach(panel_node, &(panel->thread_list)) - { - struct rtgui_panel_thread* thread; - thread = rtgui_list_entry(panel_node, struct rtgui_panel_thread, list); - - /* send clip info to panel */ - rtgui_thread_send(thread->tid, &(eclip->parent), - sizeof(struct rtgui_event_clip_info) + count * sizeof(struct rtgui_rect)); - } - } - - /* release clip info event */ - rtgui_free(eclip); -} - -static void rtgui_topwin_redraw(struct rtgui_rect* rect) -{ - struct rtgui_list_node* node; - struct rtgui_event_paint epaint; - RTGUI_EVENT_PAINT_INIT(&epaint); - - rtgui_list_foreach(node, &_rtgui_topwin_show_list) - { - struct rtgui_topwin* wnd = rtgui_list_entry(node, struct rtgui_topwin, list); - - if (rtgui_rect_is_intersect(rect, &(wnd->extent)) == RT_EOK) - { - /* draw window */ - epaint.wid = wnd->wid; - rtgui_thread_send(wnd->tid, &(epaint.parent), sizeof(epaint)); - - /* draw title */ - if (wnd->title != RT_NULL) - { - rtgui_theme_draw_win(wnd); - } - } - } - - /* redraw the panel */ - rtgui_list_foreach(node, &(_rtgui_panel_list)) - { - struct rtgui_panel* panel; - panel = rtgui_list_entry(node, struct rtgui_panel, sibling); - - if (rtgui_rect_is_intersect(rect, &(panel->extent)) == RT_EOK) - { - rt_thread_t tid; - - tid = rtgui_panel_get_active_thread(panel); - if (tid != RT_NULL) - { - /* draw panel */ - epaint.wid = RT_NULL; - rtgui_thread_send(tid, &(epaint.parent), sizeof(epaint)); - } - } - } -} - -void rtgui_topwin_title_onmouse(struct rtgui_topwin* win, struct rtgui_event_mouse* event) -{ - rtgui_rect_t rect; - - /* let window to process this mouse event */ - if (rtgui_rect_contains_point(&win->extent, event->x, event->y) == RT_EOK) - { - /* send mouse event to thread */ - rtgui_thread_send(win->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); - return; - } - - /* get close button rect (device value) */ - rect.x1 = RTGUI_WIDGET(win->title)->extent.x2 - WINTITLE_BORDER_SIZE - WINTITLE_CB_WIDTH - 3; - rect.y1 = RTGUI_WIDGET(win->title)->extent.y1 + WINTITLE_BORDER_SIZE + 3; - rect.x2 = rect.x1 + WINTITLE_CB_WIDTH; - rect.y2 = rect.y1 + WINTITLE_CB_HEIGHT; - - if (event->button & RTGUI_MOUSE_BUTTON_LEFT) - { - if (event->button & RTGUI_MOUSE_BUTTON_DOWN) - { - if (rtgui_rect_contains_point(&rect, event->x, event->y) == RT_EOK) - { - win->flag |= WINTITLE_CB_PRESSED; - rtgui_theme_draw_win(win); - } - else - { - /* maybe move window */ - rtgui_winrect_set(win); - } - } - else if (event->button & RTGUI_MOUSE_BUTTON_UP) - { - if (rtgui_rect_contains_point(&rect, event->x, event->y) == RT_EOK) - { - struct rtgui_event_win event; - - win->flag &= ~WINTITLE_CB_PRESSED; - rtgui_theme_draw_win(win); - - /* send close event to window */ - RTGUI_EVENT_WIN_CLOSE_INIT(&event); - event.wid = win->wid; - rtgui_thread_send(win->tid, &(event.parent), sizeof(struct rtgui_event_win)); - } - } - } -} - -void rtgui_topwin_append_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect) -{ - struct rtgui_topwin* win; - - /* parameters check */ - if (wid == RT_NULL || rect == RT_NULL) return; - - /* find topwin */ - win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); - if (win == RT_NULL) - win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); - - if (win == RT_NULL) return; - - /* append rect to top window monitor rect list */ - rtgui_mouse_monitor_append(&(win->monitor_list), rect); -} - -void rtgui_topwin_remove_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect) -{ - struct rtgui_topwin* win; - - /* parameters check */ - if (wid == RT_NULL || rect == RT_NULL) return; - - /* find topwin */ - win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); - if (win == RT_NULL) - win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); - - if (win == RT_NULL) return; - - /* remove rect from top window monitor rect list */ - rtgui_mouse_monitor_remove(&(win->monitor_list), rect); -} - -void rtgui_topwin_dump() -{ - struct rtgui_list_node* node; - - rtgui_list_foreach(node, &_rtgui_topwin_show_list) - { - struct rtgui_topwin* wnd = rtgui_list_entry(node, struct rtgui_topwin, list); - - rt_kprintf("wnd at (%d, %d) - (%d, %d)\n", - wnd->extent.x1, wnd->extent.y1, wnd->extent.x2, wnd->extent.y2); - - if (wnd->title != RT_NULL) - { - rt_kprintf("title[%s] border (%d, %d) - (%d, %d)\n", wnd->title->title, - RTGUI_WIDGET(wnd->title)->extent.x1, RTGUI_WIDGET(wnd->title)->extent.y1, - RTGUI_WIDGET(wnd->title)->extent.x2, RTGUI_WIDGET(wnd->title)->extent.y2); - } - } -} +/* + * File : topwin.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-16 Bernard first version + */ +#include "panel.h" +#include "topwin.h" +#include "mouse.h" + +#include +#include +#include +#include +#include + +struct rtgui_topwin* rtgui_server_focus_topwin = RT_NULL; + +static struct rtgui_list_node _rtgui_topwin_show_list; +static struct rtgui_list_node _rtgui_topwin_hide_list; + +static void rtgui_topwin_update_clip(void); +static void rtgui_topwin_redraw(struct rtgui_rect* rect); + +#define WINTITLE_CB_WIDTH 14 +#define WINTITLE_CB_HEIGHT 14 + +void rtgui_topwin_init() +{ + /* init window list */ + rtgui_list_init(&_rtgui_topwin_show_list); + rtgui_list_init(&_rtgui_topwin_hide_list); +} + +static struct rtgui_topwin* +rtgui_topwin_search_in_list(struct rtgui_win* wid, struct rtgui_list_node* list) +{ + struct rtgui_list_node* node; + struct rtgui_topwin* topwin; + + /* search in list */ + rtgui_list_foreach(node, list) + { + topwin = rtgui_list_entry(node, struct rtgui_topwin, list); + + /* is this node? */ + if (topwin->wid == wid) + { + return topwin; + } + } + + return RT_NULL; +} + +/* add a window to window list[hide] */ +rt_err_t rtgui_topwin_add(struct rtgui_event_win_create* event) +{ + struct rtgui_topwin* topwin; + + topwin = rtgui_malloc(sizeof(struct rtgui_topwin)); + if (topwin == RT_NULL) return -RT_ERROR; + + topwin->wid = event->wid; + topwin->extent = event->extent; + topwin->tid = event->parent.sender; + topwin->mask = event->mask; + + topwin->flag = 0; + if (event->flag & RTGUI_WIN_STYLE_NO_TITLE) topwin->flag |= WINTITLE_NO; + if (event->flag & RTGUI_WIN_STYLE_CLOSEBOX) topwin->flag |= WINTITLE_CLOSEBOX; + if (!(event->flag & RTGUI_WIN_STYLE_NO_BORDER)) topwin->flag |= WINTITLE_BORDER; + if (event->flag & RTGUI_WIN_STYLE_NO_FOCUS) topwin->flag |= WINTITLE_NOFOCUS; + + if(!(topwin->flag & WINTITLE_NO) || (topwin->flag & WINTITLE_BORDER)) + { + /* get win extent */ + rtgui_rect_t rect = topwin->extent; + + /* add border rect */ + if (topwin->flag & WINTITLE_BORDER) + { + rect.x1 -= WINTITLE_BORDER_SIZE; + rect.y1 -= WINTITLE_BORDER_SIZE; + rect.x2 += WINTITLE_BORDER_SIZE; + rect.y2 += WINTITLE_BORDER_SIZE; + } + + /* add title rect */ + if (!(topwin->flag & WINTITLE_NO)) rect.y1 -= WINTITLE_HEIGHT; + + topwin->title = rtgui_wintitle_create(event->title); + rtgui_widget_set_rect(RTGUI_WIDGET(topwin->title), &rect); + + /* update clip info */ + rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(topwin->title)); + rtgui_region_subtract_rect(&(RTGUI_WIDGET(topwin->title)->clip), + &(RTGUI_WIDGET(topwin->title)->clip), + &(topwin->extent)); + } + else topwin->title = RT_NULL; + + rtgui_list_init(&topwin->list); + rtgui_list_init(&topwin->monitor_list); + + /* add topwin node to the hidden window list */ + rtgui_list_insert(&(_rtgui_topwin_hide_list), &(topwin->list)); + + return RT_EOK; +} + +rt_err_t rtgui_topwin_remove(struct rtgui_win* wid) +{ + struct rtgui_topwin* topwin; + + /* find the topwin node */ + topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); + + if (topwin) + { + /* remove node from list */ + rtgui_list_remove(&_rtgui_topwin_show_list, &(topwin->list)); + + rtgui_topwin_update_clip(); + + /* redraw the old rect */ + rtgui_topwin_redraw(&(topwin->extent)); + + if (rtgui_server_focus_topwin == topwin) + { + /* activate the next window */ + if (_rtgui_topwin_show_list.next != RT_NULL) + { + struct rtgui_event_win wevent; + struct rtgui_topwin* wnd; + + /* get the topwin */ + wnd = rtgui_list_entry(_rtgui_topwin_show_list.next, + struct rtgui_topwin, list); + + /* activate the window */ + RTGUI_EVENT_WIN_ACTIVATE_INIT(&wevent); + wevent.wid = wnd->wid; + rtgui_thread_send(wnd->tid, &(wevent.parent), sizeof(struct rtgui_event_win)); + + /* set new focus topwin */ + rtgui_server_focus_topwin = wnd; + } + else + { + /* there is no shown window right now */ + rtgui_server_focus_topwin = RT_NULL; + } + } + + /* free the monitor rect list, topwin node and title */ + while (topwin->monitor_list.next != RT_NULL) + { + struct rtgui_mouse_monitor* monitor = rtgui_list_entry(topwin->monitor_list.next, + struct rtgui_mouse_monitor, list); + + topwin->monitor_list.next = topwin->monitor_list.next->next; + rtgui_free(monitor); + } + + /* destroy win title */ + rtgui_wintitle_destroy(topwin->title); + topwin->title = RT_NULL; + + rtgui_free(topwin); + + return RT_EOK; + } + + topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); + if (topwin) + { + /* remove node from list */ + rtgui_list_remove(&_rtgui_topwin_hide_list, &(topwin->list)); + + /* free the topwin node and title */ + rtgui_wintitle_destroy(topwin->title); + topwin->title = RT_NULL; + + rtgui_free(topwin); + + return RT_EOK; + } + + return -RT_ERROR; +} + +/* activate a win + * - deactivate the old focus win + * - activate a win + * - set the focus win to activate win + * - draw win title + */ +void rtgui_topwin_activate_win(struct rtgui_topwin* win) +{ + struct rtgui_event_win event; + + /* activate the raised window */ + RTGUI_EVENT_WIN_ACTIVATE_INIT(&event); + event.wid = win->wid; + rtgui_thread_send(win->tid, &(event.parent), sizeof(struct rtgui_event_win)); + + /* redraw title */ + if (win->title != RT_NULL) + { + win->flag |= WINTITLE_ACTIVATE; + rtgui_theme_draw_win(win); + } + + if (rtgui_server_focus_topwin != RT_NULL) + { + /* deactivate the old focus win */ + RTGUI_EVENT_WIN_DEACTIVATE_INIT(&event); + event.wid = rtgui_server_focus_topwin->wid; + rtgui_thread_send(rtgui_server_focus_topwin->tid, + &event.parent, sizeof(struct rtgui_event_win)); + + /* redraw title */ + if (rtgui_server_focus_topwin->title != RT_NULL) + { + rtgui_server_focus_topwin->flag &= ~WINTITLE_ACTIVATE; + rtgui_theme_draw_win(rtgui_server_focus_topwin); + } + } + + rtgui_server_focus_topwin = win; +} + +/* + * deactivate a win + * - deactivate the win + * - redraw win title + * - set rtgui_server_focus_topwin + */ +void rtgui_topwin_deactivate_win(struct rtgui_topwin* win) +{ + /* deactivate win */ + struct rtgui_event_win event; + RTGUI_EVENT_WIN_DEACTIVATE_INIT(&event); + event.wid = win->wid; + rtgui_thread_send(win->tid, + &event.parent, sizeof(struct rtgui_event_win)); + + win->flag &= ~WINTITLE_ACTIVATE; + rtgui_theme_draw_win(win); + + if (rtgui_server_focus_topwin == win) + { + rtgui_server_focus_topwin = RT_NULL; + } +} + +/* raise window to front */ +void rtgui_topwin_raise(struct rtgui_win* wid, rt_thread_t sender) +{ + struct rtgui_topwin* topwin; + + /* find the topwin node */ + topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); + if (topwin) + { + rt_int32_t count; + struct rtgui_list_node* node; + struct rtgui_event_clip_info* eclip; + struct rtgui_rect* rect; + + /* the window is already placed in front */ + if (&(topwin->list) == _rtgui_topwin_show_list.next) + { + rtgui_server_focus_topwin = RT_NULL; + rtgui_topwin_activate_win(topwin); + return ; + } + + /* update clip info */ + count = 0; + node = _rtgui_topwin_show_list.next; + while (node != &(topwin->list)) + { + count ++; + node = node->next; + } + + eclip = (struct rtgui_event_clip_info*)rtgui_malloc(sizeof(struct rtgui_event_clip_info) + + (count + 1)* sizeof(struct rtgui_rect)); + + /* reset clip info to top window */ + RTGUI_EVENT_CLIP_INFO_INIT(eclip); + eclip->num_rect = 0; + eclip->wid = topwin->wid; + /* send to destination window */ + rtgui_thread_send(topwin->tid, &(eclip->parent), sizeof(struct rtgui_event_clip_info)); + + /* reset clip info in title */ + rtgui_toplevel_handle_clip(RTGUI_TOPLEVEL(topwin->title), eclip); + rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(topwin->title)); + rtgui_region_subtract_rect(&(RTGUI_WIDGET(topwin->title)->clip), + &(RTGUI_WIDGET(topwin->title)->clip), + &(topwin->extent)); + + rect = RTGUI_EVENT_GET_RECT(eclip, 0); + *rect = (topwin->title != RT_NULL)? RTGUI_WIDGET(topwin->title)->extent : topwin->extent; + + count = 1; + for (node = _rtgui_topwin_show_list.next; + node != &(topwin->list); + node = node->next) + { + struct rtgui_topwin* wnd; + wnd = rtgui_list_entry(node, struct rtgui_topwin, list); + + eclip->num_rect = count; + eclip->wid = wnd->wid; + + /* send to destination window */ + rtgui_thread_send(wnd->tid, &(eclip->parent), + sizeof(struct rtgui_event_clip_info) + count * sizeof(struct rtgui_rect)); + + /* reset clip info in title */ + rtgui_toplevel_handle_clip(RTGUI_TOPLEVEL(wnd->title), eclip); + rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(wnd->title)); + rtgui_region_subtract_rect(&(RTGUI_WIDGET(wnd->title)->clip), + &(RTGUI_WIDGET(wnd->title)->clip), + &(wnd->extent)); + + rect = RTGUI_EVENT_GET_RECT(eclip, count++); + *rect = (wnd->title != RT_NULL)? RTGUI_WIDGET(wnd->title)->extent : wnd->extent; + } + + /* release clip info event */ + rtgui_free(eclip); + + /* remove node from list */ + rtgui_list_remove(&_rtgui_topwin_show_list, &(topwin->list)); + /* add to front */ + rtgui_list_insert(&_rtgui_topwin_show_list, &(topwin->list)); + + rtgui_topwin_activate_win(topwin); + } +} + +/* show a window */ +void rtgui_topwin_show(struct rtgui_event_win* event) +{ + struct rtgui_topwin* topwin; + struct rtgui_win* wid = event->wid; + rt_thread_t sender = RTGUI_EVENT(event)->sender; + + /* find in hide list */ + topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); + + /* find it */ + if (topwin != RT_NULL) + { + /* remove node from hidden list */ + rtgui_list_remove(&_rtgui_topwin_hide_list, &(topwin->list)); + + /* add node to show list */ + rtgui_list_insert(&_rtgui_topwin_show_list, &(topwin->list)); + + /* show window title */ + if (topwin->title != RT_NULL) + { + RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(topwin->title)); + } + + /* update clip info */ + rtgui_topwin_update_clip(); + + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); + + /* activate this window */ + rtgui_topwin_activate_win(topwin); + } + else + { + /* the wnd is located in show list, raise wnd to front */ + topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); + if (topwin != RT_NULL) + { + if (_rtgui_topwin_show_list.next != &(topwin->list)) + { + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); + + /* not the front window, raise it */ + rtgui_topwin_raise(wid, sender); + } + } + else + { + /* there is no wnd in wnd list */ + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); + } + } +} + +/* send clip info to panel */ +void rtgui_topwin_update_clip_to_panel(struct rtgui_panel* panel) +{ + rt_uint32_t count; + rt_thread_t tid; + struct rtgui_list_node* node; + struct rtgui_event_clip_info* eclip; + + /* get topwin count */ + count = 0; + node = _rtgui_topwin_show_list.next; + while (node != RT_NULL) + { + count ++; + node = node->next; + } + + eclip = (struct rtgui_event_clip_info*)rtgui_malloc(sizeof(struct rtgui_event_clip_info) + + (count + 1)* sizeof(struct rtgui_rect)); + if (eclip == RT_NULL) + { + /* no memory */ + return ; + } + + /* reset clip info to top window */ + RTGUI_EVENT_CLIP_INFO_INIT(eclip); + eclip->num_rect = count; eclip->wid = RT_NULL; + + count = 0; + for (node = _rtgui_topwin_show_list.next; node != RT_NULL; node = node->next) + { + struct rtgui_topwin* wnd; + struct rtgui_rect* rect; + + wnd = rtgui_list_entry(node, struct rtgui_topwin, list); + + rect = RTGUI_EVENT_GET_RECT(eclip, count++); + *rect = (wnd->title != RT_NULL)? RTGUI_WIDGET(wnd->title)->extent : wnd->extent; + } + + /* send to the activated thread of panel */ + tid = rtgui_panel_get_active_thread(panel); + rtgui_thread_send(tid, (struct rtgui_event*)eclip, sizeof(struct rtgui_event_clip_info) + + count* sizeof(struct rtgui_rect)); + + /* release clip info event */ + rtgui_free(eclip); +} + +/* hide a window */ +void rtgui_topwin_hide(struct rtgui_event_win* event) +{ + struct rtgui_topwin* topwin; + struct rtgui_win* wid = event->wid; + + /* find in show list */ + topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); + + /* found it */ + if (topwin) + { + /* remove node from show list */ + rtgui_list_remove(&_rtgui_topwin_show_list, &(topwin->list)); + + /* add node to hidden list */ + rtgui_list_insert(&_rtgui_topwin_hide_list, &(topwin->list)); + + /* show window title */ + if (topwin->title != RT_NULL) + { + RTGUI_WIDGET_HIDE(RTGUI_WIDGET(topwin->title)); + } + + /* update clip info */ + rtgui_topwin_update_clip(); + + /* redraw the old rect */ + rtgui_topwin_redraw(&(topwin->extent)); + + if (rtgui_server_focus_topwin == topwin) + { + /* activate the next window */ + if (_rtgui_topwin_show_list.next != RT_NULL) + { + /* get the topwin */ + topwin = rtgui_list_entry(_rtgui_topwin_show_list.next, + struct rtgui_topwin, list); + + rtgui_server_focus_topwin = RT_NULL; + rtgui_topwin_activate_win(topwin); + } + else + { + /* there is no shown window right now */ + rtgui_server_focus_topwin = RT_NULL; + } + } + } + else + { + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); + return; + } + + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); +} + +/* move top window */ +void rtgui_topwin_move(struct rtgui_event_win_move* event) +{ + struct rtgui_topwin* topwin; + + /* find in show list */ + topwin = rtgui_topwin_search_in_list(event->wid, &_rtgui_topwin_show_list); + if (topwin != RT_NULL) + { + int dx, dy; + rtgui_rect_t rect; /* the old topwin coverage area */ + struct rtgui_list_node* node; + + /* send status ok */ + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK); + + /* get the delta move x, y */ + dx = event->x - topwin->extent.x1; + dy = event->y - topwin->extent.y1; + + rect = topwin->extent; + /* move window rect */ + rtgui_rect_moveto(&(topwin->extent), dx, dy); + + /* move window title */ + if (topwin->title != RT_NULL) + { + rect = RTGUI_WIDGET(topwin->title)->extent; + rtgui_widget_move_to_logic(RTGUI_WIDGET(topwin->title), dx, dy); + } + + /* move the monitor rect list */ + rtgui_list_foreach(node, &(topwin->monitor_list)) + { + struct rtgui_mouse_monitor* monitor = rtgui_list_entry(node, + struct rtgui_mouse_monitor, + list); + rtgui_rect_moveto(&(monitor->rect), dx, dy); + } + + /* update windows clip info */ + rtgui_topwin_update_clip(); + + /* update top window title */ + if (topwin->title != RT_NULL) rtgui_theme_draw_win(topwin); + if (rtgui_rect_is_intersect(&rect, &(topwin->extent)) != RT_EOK) + { + /* + * the old rect is not intersect with moved rect, + * re-paint window + */ + struct rtgui_event_paint epaint; + RTGUI_EVENT_PAINT_INIT(&epaint); + epaint.wid = topwin->wid; + rtgui_thread_send(topwin->tid, &(epaint.parent), sizeof(epaint)); + } + + /* update old window coverage area */ + rtgui_topwin_redraw(&rect); + } + else + { + rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR); + } +} + +/* + * resize a top win + * Note: currently, only support resize hidden window + */ +void rtgui_topwin_resize(struct rtgui_win* wid, rtgui_rect_t* r) +{ + struct rtgui_topwin* topwin; + + /* find in show list */ + topwin = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); + if (topwin) + { + topwin->extent = *r; + + if (topwin->title != RT_NULL) + { + /* get win extent */ + rtgui_rect_t rect = topwin->extent; + + /* add border rect */ + if (topwin->flag & WINTITLE_BORDER) + { + rect.x1 -= WINTITLE_BORDER_SIZE; + rect.y1 -= WINTITLE_BORDER_SIZE; + rect.x2 += WINTITLE_BORDER_SIZE; + rect.y2 += WINTITLE_BORDER_SIZE; + } + + /* add title rect */ + if (!(topwin->flag & WINTITLE_NO)) rect.y1 -= WINTITLE_HEIGHT; + + RTGUI_WIDGET(topwin->title)->extent = rect; + + /* update title & border clip info */ + rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(topwin->title)); + rtgui_region_subtract_rect(&(RTGUI_WIDGET(topwin->title)->clip), + &(RTGUI_WIDGET(topwin->title)->clip), + &(topwin->extent)); + } + } +} + +struct rtgui_topwin* rtgui_topwin_get_wnd(int x, int y) +{ + struct rtgui_list_node* node; + struct rtgui_topwin* topwin; + + /* search in list */ + rtgui_list_foreach(node, &(_rtgui_topwin_show_list)) + { + topwin = rtgui_list_entry(node, struct rtgui_topwin, list); + + /* is this window? */ + if ((topwin->title != RT_NULL) && + rtgui_rect_contains_point(&(RTGUI_WIDGET(topwin->title)->extent), x, y) == RT_EOK) + { + return topwin; + } + else if (rtgui_rect_contains_point(&(topwin->extent), x, y) == RT_EOK) + { + return topwin; + } + } + + return RT_NULL; +} + +extern struct rtgui_list_node _rtgui_panel_list; +static void rtgui_topwin_update_clip() +{ + rt_int32_t count = 0; + struct rtgui_event_clip_info* eclip; + struct rtgui_list_node* node = _rtgui_topwin_show_list.next; + + /* calculate count */ + while (node != RT_NULL) + { + count ++; + node = node->next; + } + + eclip = (struct rtgui_event_clip_info*)rtgui_malloc(sizeof(struct rtgui_event_clip_info) + + count * sizeof(struct rtgui_rect)); + RTGUI_EVENT_CLIP_INFO_INIT(eclip); + + count = 0; + rtgui_list_foreach(node, &_rtgui_topwin_show_list) + { + struct rtgui_rect* rect; + struct rtgui_topwin* wnd; + wnd = rtgui_list_entry(node, struct rtgui_topwin, list); + + eclip->num_rect = count; + eclip->wid = wnd->wid; + + /* send to destination window */ + rtgui_thread_send(wnd->tid, &(eclip->parent), + sizeof(struct rtgui_event_clip_info) + count * sizeof(struct rtgui_rect)); + + /* update clip in win title */ + if (wnd->title != RT_NULL) + { + /* reset clip info */ + rtgui_toplevel_handle_clip(RTGUI_TOPLEVEL(wnd->title), eclip); + rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(wnd->title)); + rtgui_region_subtract_rect(&(RTGUI_WIDGET(wnd->title)->clip), + &(RTGUI_WIDGET(wnd->title)->clip), + &(wnd->extent)); + } + + rect = RTGUI_EVENT_GET_RECT(eclip, count++); + *rect = (wnd->title != RT_NULL)? RTGUI_WIDGET(wnd->title)->extent : wnd->extent; + } + + /* send clip info to each panel */ + eclip->wid = RT_NULL; + eclip->num_rect = count; + + rtgui_list_foreach(node, &(_rtgui_panel_list)) + { + struct rtgui_panel* panel; + struct rtgui_list_node* panel_node; + + panel = rtgui_list_entry(node, struct rtgui_panel, sibling); + + rtgui_list_foreach(panel_node, &(panel->thread_list)) + { + struct rtgui_panel_thread* thread; + thread = rtgui_list_entry(panel_node, struct rtgui_panel_thread, list); + + /* send clip info to panel */ + rtgui_thread_send(thread->tid, &(eclip->parent), + sizeof(struct rtgui_event_clip_info) + count * sizeof(struct rtgui_rect)); + } + } + + /* release clip info event */ + rtgui_free(eclip); +} + +static void rtgui_topwin_redraw(struct rtgui_rect* rect) +{ + struct rtgui_list_node* node; + struct rtgui_event_paint epaint; + RTGUI_EVENT_PAINT_INIT(&epaint); + + rtgui_list_foreach(node, &_rtgui_topwin_show_list) + { + struct rtgui_topwin* wnd = rtgui_list_entry(node, struct rtgui_topwin, list); + + if (rtgui_rect_is_intersect(rect, &(wnd->extent)) == RT_EOK) + { + /* draw window */ + epaint.wid = wnd->wid; + rtgui_thread_send(wnd->tid, &(epaint.parent), sizeof(epaint)); + + /* draw title */ + if (wnd->title != RT_NULL) + { + rtgui_theme_draw_win(wnd); + } + } + } + + /* redraw the panel */ + rtgui_list_foreach(node, &(_rtgui_panel_list)) + { + struct rtgui_panel* panel; + panel = rtgui_list_entry(node, struct rtgui_panel, sibling); + + if (rtgui_rect_is_intersect(rect, &(panel->extent)) == RT_EOK) + { + rt_thread_t tid; + + tid = rtgui_panel_get_active_thread(panel); + if (tid != RT_NULL) + { + /* draw panel */ + epaint.wid = RT_NULL; + rtgui_thread_send(tid, &(epaint.parent), sizeof(epaint)); + } + } + } +} + +void rtgui_topwin_title_onmouse(struct rtgui_topwin* win, struct rtgui_event_mouse* event) +{ + rtgui_rect_t rect; + + /* let window to process this mouse event */ + if (rtgui_rect_contains_point(&win->extent, event->x, event->y) == RT_EOK) + { + /* send mouse event to thread */ + rtgui_thread_send(win->tid, &(event->parent), sizeof(struct rtgui_event_mouse)); + return; + } + + /* get close button rect (device value) */ + rect.x1 = RTGUI_WIDGET(win->title)->extent.x2 - WINTITLE_BORDER_SIZE - WINTITLE_CB_WIDTH - 3; + rect.y1 = RTGUI_WIDGET(win->title)->extent.y1 + WINTITLE_BORDER_SIZE + 3; + rect.x2 = rect.x1 + WINTITLE_CB_WIDTH; + rect.y2 = rect.y1 + WINTITLE_CB_HEIGHT; + + if (event->button & RTGUI_MOUSE_BUTTON_LEFT) + { + if (event->button & RTGUI_MOUSE_BUTTON_DOWN) + { + if (rtgui_rect_contains_point(&rect, event->x, event->y) == RT_EOK) + { + win->flag |= WINTITLE_CB_PRESSED; + rtgui_theme_draw_win(win); + } + else + { + /* maybe move window */ + rtgui_winrect_set(win); + } + } + else if (event->button & RTGUI_MOUSE_BUTTON_UP) + { + if (rtgui_rect_contains_point(&rect, event->x, event->y) == RT_EOK) + { + struct rtgui_event_win event; + + win->flag &= ~WINTITLE_CB_PRESSED; + rtgui_theme_draw_win(win); + + /* send close event to window */ + RTGUI_EVENT_WIN_CLOSE_INIT(&event); + event.wid = win->wid; + rtgui_thread_send(win->tid, &(event.parent), sizeof(struct rtgui_event_win)); + } + } + } +} + +void rtgui_topwin_append_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect) +{ + struct rtgui_topwin* win; + + /* parameters check */ + if (wid == RT_NULL || rect == RT_NULL) return; + + /* find topwin */ + win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); + if (win == RT_NULL) + win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); + + if (win == RT_NULL) return; + + /* append rect to top window monitor rect list */ + rtgui_mouse_monitor_append(&(win->monitor_list), rect); +} + +void rtgui_topwin_remove_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect) +{ + struct rtgui_topwin* win; + + /* parameters check */ + if (wid == RT_NULL || rect == RT_NULL) return; + + /* find topwin */ + win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_show_list); + if (win == RT_NULL) + win = rtgui_topwin_search_in_list(wid, &_rtgui_topwin_hide_list); + + if (win == RT_NULL) return; + + /* remove rect from top window monitor rect list */ + rtgui_mouse_monitor_remove(&(win->monitor_list), rect); +} + +void rtgui_topwin_dump() +{ + struct rtgui_list_node* node; + + rtgui_list_foreach(node, &_rtgui_topwin_show_list) + { + struct rtgui_topwin* wnd = rtgui_list_entry(node, struct rtgui_topwin, list); + + rt_kprintf("wnd at (%d, %d) - (%d, %d)\n", + wnd->extent.x1, wnd->extent.y1, wnd->extent.x2, wnd->extent.y2); + + if (wnd->title != RT_NULL) + { + rt_kprintf("title[%s] border (%d, %d) - (%d, %d)\n", wnd->title->title, + RTGUI_WIDGET(wnd->title)->extent.x1, RTGUI_WIDGET(wnd->title)->extent.y1, + RTGUI_WIDGET(wnd->title)->extent.x2, RTGUI_WIDGET(wnd->title)->extent.y2); + } + } +} diff --git a/rtgui/server/topwin.h b/rtgui/server/topwin.h index 64d0a8a76..af5d72b3b 100644 --- a/rtgui/server/topwin.h +++ b/rtgui/server/topwin.h @@ -1,56 +1,56 @@ -/* - * File : topwin.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-16 Bernard first version - */ -#ifndef __RTGUI_TOPWIN_H__ -#define __RTGUI_TOPWIN_H__ - -#include -#include -#include -#include -#include -#include - -/* add or remove a top win */ -rt_err_t rtgui_topwin_add(struct rtgui_event_win_create* event); -rt_err_t rtgui_topwin_remove(struct rtgui_win* wid); - -/* raise window to front */ -void rtgui_topwin_raise(struct rtgui_win* wid, rt_thread_t sender); -/* update clip info to a panel */ -void rtgui_topwin_update_clip_to_panel(struct rtgui_panel* panel); - -/* show a window */ -void rtgui_topwin_show(struct rtgui_event_win* event); -/* hide a window */ -void rtgui_topwin_hide(struct rtgui_event_win* event); -/* move a window */ -void rtgui_topwin_move(struct rtgui_event_win_move* event); -/* resize a window */ -void rtgui_topwin_resize(struct rtgui_win* wid, rtgui_rect_t* r); - -/* get window at (x, y) */ -struct rtgui_topwin* rtgui_topwin_get_wnd(int x, int y); - -void rtgui_topwin_activate_win(struct rtgui_topwin* win); -void rtgui_topwin_deactivate_win(struct rtgui_topwin* win); - -/* window title */ -void rtgui_topwin_title_ondraw(struct rtgui_topwin* win); -void rtgui_topwin_title_onmouse(struct rtgui_topwin* win, struct rtgui_event_mouse* event); - -/* monitor rect */ -void rtgui_topwin_append_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect); -void rtgui_topwin_remove_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect); - -#endif +/* + * File : topwin.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-16 Bernard first version + */ +#ifndef __RTGUI_TOPWIN_H__ +#define __RTGUI_TOPWIN_H__ + +#include +#include +#include +#include +#include +#include + +/* add or remove a top win */ +rt_err_t rtgui_topwin_add(struct rtgui_event_win_create* event); +rt_err_t rtgui_topwin_remove(struct rtgui_win* wid); + +/* raise window to front */ +void rtgui_topwin_raise(struct rtgui_win* wid, rt_thread_t sender); +/* update clip info to a panel */ +void rtgui_topwin_update_clip_to_panel(struct rtgui_panel* panel); + +/* show a window */ +void rtgui_topwin_show(struct rtgui_event_win* event); +/* hide a window */ +void rtgui_topwin_hide(struct rtgui_event_win* event); +/* move a window */ +void rtgui_topwin_move(struct rtgui_event_win_move* event); +/* resize a window */ +void rtgui_topwin_resize(struct rtgui_win* wid, rtgui_rect_t* r); + +/* get window at (x, y) */ +struct rtgui_topwin* rtgui_topwin_get_wnd(int x, int y); + +void rtgui_topwin_activate_win(struct rtgui_topwin* win); +void rtgui_topwin_deactivate_win(struct rtgui_topwin* win); + +/* window title */ +void rtgui_topwin_title_ondraw(struct rtgui_topwin* win); +void rtgui_topwin_title_onmouse(struct rtgui_topwin* win, struct rtgui_event_mouse* event); + +/* monitor rect */ +void rtgui_topwin_append_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect); +void rtgui_topwin_remove_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect); + +#endif diff --git a/rtgui/widgets/box.c b/rtgui/widgets/box.c index a9d16311c..798f6b817 100644 --- a/rtgui/widgets/box.c +++ b/rtgui/widgets/box.c @@ -1,340 +1,340 @@ -/* - * File : box.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-16 Bernard first version - */ -#include -#include - -static void _rtgui_box_constructor(rtgui_box_t *box) -{ - /* init widget and set event handler */ - rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_box_event_handler); - - RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_TRANSPARENT; - rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_box_event_handler); - - /* set proper of control */ - box->orientation = RTGUI_HORIZONTAL; - box->border_size = RTGUI_BORDER_DEFAULT_WIDTH; -} - -rtgui_type_t *rtgui_box_type_get(void) -{ - static rtgui_type_t *box_type = RT_NULL; - - if (!box_type) - { - box_type = rtgui_type_create("box", RTGUI_CONTAINER_TYPE, - sizeof(rtgui_box_t), RTGUI_CONSTRUCTOR(_rtgui_box_constructor), RT_NULL); - } - - return box_type; -} - -rt_bool_t rtgui_box_event_handler(rtgui_widget_t* widget, rtgui_event_t* event) -{ - struct rtgui_box* box = (struct rtgui_box*)widget; - - RT_ASSERT(box != RT_NULL); - - switch (event->type) - { - case RTGUI_EVENT_RESIZE: - /* re-layout */ - rtgui_box_layout(box); - break; - - default: - return rtgui_container_event_handler(RTGUI_WIDGET(box), event); - } - - return RT_FALSE; -} - -struct rtgui_box* rtgui_box_create(int orientation, rtgui_rect_t* rect) -{ - struct rtgui_box* box; - - box = (struct rtgui_box*) rtgui_widget_create (RTGUI_BOX_TYPE); - if (box != RT_NULL) - { - /* set proper of control */ - rtgui_widget_set_rect(RTGUI_WIDGET(box), rect); - box->orientation = orientation; - } - - return box; -} - -void rtgui_box_append(struct rtgui_box* box, rtgui_widget_t* widget) -{ - /* put to box's children list */ - rtgui_container_add_child(RTGUI_CONTAINER(box), widget); -} - -static void rtgui_box_layout_vertical(rtgui_box_t* box) -{ - rtgui_list_t *node; - rt_int32_t box_width; - rt_int32_t space_count; - rt_int32_t next_x, next_y; - rt_int32_t total_height, space_height; - struct rtgui_event_resize size_event; - - /* prepare the resize event */ - RTGUI_EVENT_RESIZE_INIT(&size_event); - - /* find spaces */ - space_count = 0; - total_height = 0; - space_height = 0; - - rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) - { - rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); - if (widget->align & RTGUI_ALIGN_STRETCH) space_count ++; - else total_height += widget->mini_height; - } - - /* calculate the height for each spaces */ - if (space_count != 0) - { - space_height = (rtgui_rect_height(RTGUI_WIDGET(box)->extent) - total_height - (box->border_size << 1)) / space_count; - } - - /* init (x, y) and box width */ - next_x = RTGUI_WIDGET(box)->extent.x1 + box->border_size; - next_y = RTGUI_WIDGET(box)->extent.y1 + box->border_size; - box_width = rtgui_rect_width(RTGUI_WIDGET(box)->extent) - (box->border_size << 1); - - /* layout each widget */ - rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) - { - rtgui_rect_t *rect; - rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); - - /* get extent of widget */ - rect = &(widget->extent); - - /* reset rect */ - rtgui_rect_moveto(rect, -rect->x1, -rect->y1); - rect->x2 = widget->mini_width; - rect->y2 = widget->mini_height; - - /* left in default */ - rtgui_rect_moveto(rect, next_x, next_y); - - if (widget->align & RTGUI_ALIGN_EXPAND) - { - /* expand on horizontal */ - rect->x2 = rect->x1 + (rt_int16_t)box_width; - } - if (widget->align & RTGUI_ALIGN_CENTER_VERTICAL) - { - /* center */ - rt_uint32_t mid; - - mid = box_width - rtgui_rect_width(*rect); - mid = mid /2; - - rect->x1 = next_x + mid; - rect->x2 = next_x + box_width - mid; - } - else if (widget->align & RTGUI_ALIGN_RIGHT) - { - /* right */ - rect->x1 = next_x + box_width - rtgui_rect_width(*rect); - rect->x2 = next_x + box_width; - } - - if (widget->align & RTGUI_ALIGN_STRETCH) - { - rect->y2 = rect->y1 + space_height; - } - - /* process resize event */ - size_event.x = rect->x1; - size_event.y = rect->y1; - size_event.w = rect->x2 - rect->x1; - size_event.h = rect->y2 - rect->y1; - widget->event_handler(widget, &size_event.parent); - - /* point to next height */ - next_y = rect->y2; - } -} - -static void rtgui_box_layout_horizontal(rtgui_box_t* box) -{ - rtgui_list_t *node; - rt_int32_t box_height; - rt_int32_t space_count; - rt_int32_t next_x, next_y; - rt_int32_t total_width, space_width; - struct rtgui_event_resize size_event; - - /* prepare the resize event */ - RTGUI_EVENT_RESIZE_INIT(&size_event); - - /* find spaces */ - space_count = 0; - total_width = 0; - space_width = 0; - - rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) - { - rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); - if (widget->align & RTGUI_ALIGN_STRETCH) space_count ++; - else total_width += widget->mini_width; - } - - if (space_count != 0) - { - /* calculate the height for each spaces */ - space_width = (rtgui_rect_width(RTGUI_WIDGET(box)->extent) - total_width) / space_count; - } - - /* init (x, y) and box height */ - next_x = RTGUI_WIDGET(box)->extent.x1 + box->border_size; - next_y = RTGUI_WIDGET(box)->extent.y1 + box->border_size; - box_height = rtgui_rect_height(RTGUI_WIDGET(box)->extent) - (box->border_size << 1); - - /* layout each widget */ - rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) - { - rtgui_rect_t *rect; - rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); - - /* get extent of widget */ - rect = &(widget->extent); - - /* reset rect */ - rtgui_rect_moveto(rect, -rect->x1, -rect->y1); - rect->x2 = widget->mini_width; - rect->y2 = widget->mini_height; - - /* top in default */ - rtgui_rect_moveto(rect, next_x, next_y); - - if (widget->align & RTGUI_ALIGN_EXPAND) - { - /* expand on vertical */ - rect->y2 = rect->y1 + box_height; - } - if (widget->align & RTGUI_ALIGN_CENTER_HORIZONTAL) - { - /* center */ - rt_uint32_t mid; - - mid = box_height - rtgui_rect_height(*rect); - mid = mid /2; - - rect->y1 = next_y + mid; - rect->y2 = next_y + box_height - mid; - } - else if (widget->align & RTGUI_ALIGN_RIGHT) - { - /* right */ - rect->y1 = next_y + box_height - rtgui_rect_height(*rect); - rect->y2 = next_y + box_height; - } - - if (widget->align & RTGUI_ALIGN_STRETCH) - { - rect->x2 = rect->x1 + space_width; - } - - /* process resize event */ - size_event.x = rect->x1; - size_event.y = rect->y1; - size_event.w = rect->x2 - rect->x1; - size_event.h = rect->y2 - rect->y1; - widget->event_handler(widget, &size_event.parent); - - /* point to next width */ - next_x = rect->x2; - } -} - -void rtgui_box_layout(rtgui_box_t* box) -{ - RT_ASSERT(box != RT_NULL); - - if (box->orientation & RTGUI_VERTICAL) - { - rtgui_box_layout_vertical(box); - } - else - { - rtgui_box_layout_horizontal(box); - } - - /* update box and its children clip */ - if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(box))) - { - rtgui_widget_update_clip(RTGUI_WIDGET(box)); - } -} - -rt_uint32_t rtgui_box_get_width(rtgui_box_t* box) -{ - rtgui_list_t *node; - rt_uint32_t width; - - width = 0; - rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) - { - rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); - rt_uint32_t widget_width; - - widget_width = rtgui_rect_width(widget->extent); - if (box->orientation & RTGUI_VERTICAL) - { - /* get the max width */ - if (width < widget_width) width = widget_width; - } - else - { - /* get the total width */ - width += widget_width; - } - } - - return width; -} - -rt_uint32_t rtgui_box_get_height(rtgui_box_t* box) -{ - rtgui_list_t *node; - rt_uint32_t height; - - height = 0; - rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) - { - rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); - rt_uint32_t widget_height; - - widget_height = rtgui_rect_height(widget->extent); - if (box->orientation & RTGUI_HORIZONTAL) - { - /* get the max height */ - if (height < widget_height) height = widget_height; - } - else - { - /* get the total height */ - height += widget_height; - } - } - - return height; -} +/* + * File : box.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-16 Bernard first version + */ +#include +#include + +static void _rtgui_box_constructor(rtgui_box_t *box) +{ + /* init widget and set event handler */ + rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_box_event_handler); + + RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_TRANSPARENT; + rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_box_event_handler); + + /* set proper of control */ + box->orientation = RTGUI_HORIZONTAL; + box->border_size = RTGUI_BORDER_DEFAULT_WIDTH; +} + +rtgui_type_t *rtgui_box_type_get(void) +{ + static rtgui_type_t *box_type = RT_NULL; + + if (!box_type) + { + box_type = rtgui_type_create("box", RTGUI_CONTAINER_TYPE, + sizeof(rtgui_box_t), RTGUI_CONSTRUCTOR(_rtgui_box_constructor), RT_NULL); + } + + return box_type; +} + +rt_bool_t rtgui_box_event_handler(rtgui_widget_t* widget, rtgui_event_t* event) +{ + struct rtgui_box* box = (struct rtgui_box*)widget; + + RT_ASSERT(box != RT_NULL); + + switch (event->type) + { + case RTGUI_EVENT_RESIZE: + /* re-layout */ + rtgui_box_layout(box); + break; + + default: + return rtgui_container_event_handler(RTGUI_WIDGET(box), event); + } + + return RT_FALSE; +} + +struct rtgui_box* rtgui_box_create(int orientation, rtgui_rect_t* rect) +{ + struct rtgui_box* box; + + box = (struct rtgui_box*) rtgui_widget_create (RTGUI_BOX_TYPE); + if (box != RT_NULL) + { + /* set proper of control */ + rtgui_widget_set_rect(RTGUI_WIDGET(box), rect); + box->orientation = orientation; + } + + return box; +} + +void rtgui_box_append(struct rtgui_box* box, rtgui_widget_t* widget) +{ + /* put to box's children list */ + rtgui_container_add_child(RTGUI_CONTAINER(box), widget); +} + +static void rtgui_box_layout_vertical(rtgui_box_t* box) +{ + rtgui_list_t *node; + rt_int32_t box_width; + rt_int32_t space_count; + rt_int32_t next_x, next_y; + rt_int32_t total_height, space_height; + struct rtgui_event_resize size_event; + + /* prepare the resize event */ + RTGUI_EVENT_RESIZE_INIT(&size_event); + + /* find spaces */ + space_count = 0; + total_height = 0; + space_height = 0; + + rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) + { + rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); + if (widget->align & RTGUI_ALIGN_STRETCH) space_count ++; + else total_height += widget->mini_height; + } + + /* calculate the height for each spaces */ + if (space_count != 0) + { + space_height = (rtgui_rect_height(RTGUI_WIDGET(box)->extent) - total_height - (box->border_size << 1)) / space_count; + } + + /* init (x, y) and box width */ + next_x = RTGUI_WIDGET(box)->extent.x1 + box->border_size; + next_y = RTGUI_WIDGET(box)->extent.y1 + box->border_size; + box_width = rtgui_rect_width(RTGUI_WIDGET(box)->extent) - (box->border_size << 1); + + /* layout each widget */ + rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) + { + rtgui_rect_t *rect; + rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); + + /* get extent of widget */ + rect = &(widget->extent); + + /* reset rect */ + rtgui_rect_moveto(rect, -rect->x1, -rect->y1); + rect->x2 = widget->mini_width; + rect->y2 = widget->mini_height; + + /* left in default */ + rtgui_rect_moveto(rect, next_x, next_y); + + if (widget->align & RTGUI_ALIGN_EXPAND) + { + /* expand on horizontal */ + rect->x2 = rect->x1 + (rt_int16_t)box_width; + } + if (widget->align & RTGUI_ALIGN_CENTER_VERTICAL) + { + /* center */ + rt_uint32_t mid; + + mid = box_width - rtgui_rect_width(*rect); + mid = mid /2; + + rect->x1 = next_x + mid; + rect->x2 = next_x + box_width - mid; + } + else if (widget->align & RTGUI_ALIGN_RIGHT) + { + /* right */ + rect->x1 = next_x + box_width - rtgui_rect_width(*rect); + rect->x2 = next_x + box_width; + } + + if (widget->align & RTGUI_ALIGN_STRETCH) + { + rect->y2 = rect->y1 + space_height; + } + + /* process resize event */ + size_event.x = rect->x1; + size_event.y = rect->y1; + size_event.w = rect->x2 - rect->x1; + size_event.h = rect->y2 - rect->y1; + widget->event_handler(widget, &size_event.parent); + + /* point to next height */ + next_y = rect->y2; + } +} + +static void rtgui_box_layout_horizontal(rtgui_box_t* box) +{ + rtgui_list_t *node; + rt_int32_t box_height; + rt_int32_t space_count; + rt_int32_t next_x, next_y; + rt_int32_t total_width, space_width; + struct rtgui_event_resize size_event; + + /* prepare the resize event */ + RTGUI_EVENT_RESIZE_INIT(&size_event); + + /* find spaces */ + space_count = 0; + total_width = 0; + space_width = 0; + + rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) + { + rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); + if (widget->align & RTGUI_ALIGN_STRETCH) space_count ++; + else total_width += widget->mini_width; + } + + if (space_count != 0) + { + /* calculate the height for each spaces */ + space_width = (rtgui_rect_width(RTGUI_WIDGET(box)->extent) - total_width) / space_count; + } + + /* init (x, y) and box height */ + next_x = RTGUI_WIDGET(box)->extent.x1 + box->border_size; + next_y = RTGUI_WIDGET(box)->extent.y1 + box->border_size; + box_height = rtgui_rect_height(RTGUI_WIDGET(box)->extent) - (box->border_size << 1); + + /* layout each widget */ + rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) + { + rtgui_rect_t *rect; + rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); + + /* get extent of widget */ + rect = &(widget->extent); + + /* reset rect */ + rtgui_rect_moveto(rect, -rect->x1, -rect->y1); + rect->x2 = widget->mini_width; + rect->y2 = widget->mini_height; + + /* top in default */ + rtgui_rect_moveto(rect, next_x, next_y); + + if (widget->align & RTGUI_ALIGN_EXPAND) + { + /* expand on vertical */ + rect->y2 = rect->y1 + box_height; + } + if (widget->align & RTGUI_ALIGN_CENTER_HORIZONTAL) + { + /* center */ + rt_uint32_t mid; + + mid = box_height - rtgui_rect_height(*rect); + mid = mid /2; + + rect->y1 = next_y + mid; + rect->y2 = next_y + box_height - mid; + } + else if (widget->align & RTGUI_ALIGN_RIGHT) + { + /* right */ + rect->y1 = next_y + box_height - rtgui_rect_height(*rect); + rect->y2 = next_y + box_height; + } + + if (widget->align & RTGUI_ALIGN_STRETCH) + { + rect->x2 = rect->x1 + space_width; + } + + /* process resize event */ + size_event.x = rect->x1; + size_event.y = rect->y1; + size_event.w = rect->x2 - rect->x1; + size_event.h = rect->y2 - rect->y1; + widget->event_handler(widget, &size_event.parent); + + /* point to next width */ + next_x = rect->x2; + } +} + +void rtgui_box_layout(rtgui_box_t* box) +{ + RT_ASSERT(box != RT_NULL); + + if (box->orientation & RTGUI_VERTICAL) + { + rtgui_box_layout_vertical(box); + } + else + { + rtgui_box_layout_horizontal(box); + } + + /* update box and its children clip */ + if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(box))) + { + rtgui_widget_update_clip(RTGUI_WIDGET(box)); + } +} + +rt_uint32_t rtgui_box_get_width(rtgui_box_t* box) +{ + rtgui_list_t *node; + rt_uint32_t width; + + width = 0; + rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) + { + rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); + rt_uint32_t widget_width; + + widget_width = rtgui_rect_width(widget->extent); + if (box->orientation & RTGUI_VERTICAL) + { + /* get the max width */ + if (width < widget_width) width = widget_width; + } + else + { + /* get the total width */ + width += widget_width; + } + } + + return width; +} + +rt_uint32_t rtgui_box_get_height(rtgui_box_t* box) +{ + rtgui_list_t *node; + rt_uint32_t height; + + height = 0; + rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) + { + rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); + rt_uint32_t widget_height; + + widget_height = rtgui_rect_height(widget->extent); + if (box->orientation & RTGUI_HORIZONTAL) + { + /* get the max height */ + if (height < widget_height) height = widget_height; + } + else + { + /* get the total height */ + height += widget_height; + } + } + + return height; +} diff --git a/rtgui/widgets/button.c b/rtgui/widgets/button.c index f5bd8877d..1a563f0db 100644 --- a/rtgui/widgets/button.c +++ b/rtgui/widgets/button.c @@ -1,187 +1,187 @@ -/* - * File : button.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-16 Bernard first version - */ -#include -#include -#include - -static void _rtgui_button_constructor(rtgui_button_t *button) -{ - /* init widget and set event handler */ - RTGUI_WIDGET(button)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; - rtgui_widget_set_event_handler(RTGUI_WIDGET(button), rtgui_button_event_handler); - - /* un-press button */ - button->flag &= ~RTGUI_BUTTON_FLAG_PRESS; - - /* set flag and on_button event handler */ - button->pressed_image = RT_NULL; - button->unpressed_image = RT_NULL; - button->on_button = RT_NULL; - - /* set gc */ - RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(button)) = default_foreground; - RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(button)) = RTGUI_RGB(212, 208, 200); - RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(button)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; -} - -static void _rtgui_button_destructor(rtgui_button_t *button) -{ - if (button->pressed_image != RT_NULL) - { - rtgui_image_destroy(button->pressed_image); - button->pressed_image = RT_NULL; - } - - if (button->unpressed_image != RT_NULL) - { - rtgui_image_destroy(button->unpressed_image); - button->unpressed_image = RT_NULL; - } -} - -rtgui_type_t *rtgui_button_type_get(void) -{ - static rtgui_type_t *button_type = RT_NULL; - - if (!button_type) - { - button_type = rtgui_type_create("button", RTGUI_LABEL_TYPE, - sizeof(rtgui_button_t), - RTGUI_CONSTRUCTOR(_rtgui_button_constructor), - RTGUI_DESTRUCTOR(_rtgui_button_destructor)); - } - - return button_type; -} - -rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) -{ - struct rtgui_button* btn; - - RT_ASSERT(widget != RT_NULL); - - btn = (struct rtgui_button*) widget; - switch (event->type) - { - case RTGUI_EVENT_PAINT: - if (widget->on_draw != RT_NULL ) widget->on_draw(widget, event); - else rtgui_theme_draw_button(btn); - break; - - case RTGUI_EVENT_MOUSE_BUTTON: - { - struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event; - - if (btn->flag & RTGUI_BUTTON_TYPE_PUSH) - { - /* it's a push button */ - if (emouse->button & RTGUI_MOUSE_BUTTON_UP) - { - if (btn->flag & RTGUI_BUTTON_FLAG_PRESS) - btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS; - else - btn->flag |= RTGUI_BUTTON_FLAG_PRESS; - - /* draw button */ - if (widget->on_draw != RT_NULL ) widget->on_draw(widget, event); - else rtgui_theme_draw_button(btn); - - /* invokes call back */ - if (widget->on_mouseclick != RT_NULL && - emouse->button & RTGUI_MOUSE_BUTTON_UP) - return widget->on_mouseclick(widget, event); - } - } - else - { - if (emouse->button & RTGUI_MOUSE_BUTTON_LEFT) - { - /* it's a normal button */ - if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN) - { - btn->flag |= RTGUI_BUTTON_FLAG_PRESS; - } - else - { - btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS; - } - - /* draw button */ - if (widget->on_draw != RT_NULL ) widget->on_draw(widget, event); - else rtgui_theme_draw_button(btn); - - /* invokes call back */ - if (widget->on_mouseclick != RT_NULL && - emouse->button & RTGUI_MOUSE_BUTTON_UP) - return widget->on_mouseclick(widget, event); - } - - } - - return RT_TRUE; - } - } - - return RT_FALSE; -} - -rtgui_button_t* rtgui_button_create(unsigned char* text) -{ - struct rtgui_button* btn; - - btn = (struct rtgui_button*) rtgui_widget_create (RTGUI_BUTTON_TYPE); - if (btn != RT_NULL) - { - rtgui_rect_t rect; - - /* set default rect */ - rtgui_font_get_metrics(rtgui_font_default(), text, &rect); - rect.x2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1); - rect.y2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1); - rtgui_widget_set_rect(RTGUI_WIDGET(btn), &rect); - rtgui_label_set_text(RTGUI_LABEL(btn), text); - } - - return btn; -} - -rtgui_button_t* rtgui_pushbutton_create(unsigned char* text) -{ - rtgui_button_t* btn; - - btn = rtgui_button_create(text); - if (btn != RT_NULL) btn->flag |= RTGUI_BUTTON_TYPE_PUSH; - - return btn; -} - -void rtgui_button_destroy(rtgui_button_t* btn) -{ - rtgui_widget_destroy(RTGUI_WIDGET(btn)); -} - -void rtgui_button_set_pressed_image(rtgui_button_t* btn, rtgui_image_t* image) -{ - RT_ASSERT(btn != RT_NULL); - - btn->pressed_image = image; -} - -void rtgui_button_set_unpressed_image(rtgui_button_t* btn, rtgui_image_t* image) -{ - RT_ASSERT(btn != RT_NULL); - - btn->unpressed_image = image; -} - +/* + * File : button.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-16 Bernard first version + */ +#include +#include +#include + +static void _rtgui_button_constructor(rtgui_button_t *button) +{ + /* init widget and set event handler */ + RTGUI_WIDGET(button)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; + rtgui_widget_set_event_handler(RTGUI_WIDGET(button), rtgui_button_event_handler); + + /* un-press button */ + button->flag &= ~RTGUI_BUTTON_FLAG_PRESS; + + /* set flag and on_button event handler */ + button->pressed_image = RT_NULL; + button->unpressed_image = RT_NULL; + button->on_button = RT_NULL; + + /* set gc */ + RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(button)) = default_foreground; + RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(button)) = RTGUI_RGB(212, 208, 200); + RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(button)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL; +} + +static void _rtgui_button_destructor(rtgui_button_t *button) +{ + if (button->pressed_image != RT_NULL) + { + rtgui_image_destroy(button->pressed_image); + button->pressed_image = RT_NULL; + } + + if (button->unpressed_image != RT_NULL) + { + rtgui_image_destroy(button->unpressed_image); + button->unpressed_image = RT_NULL; + } +} + +rtgui_type_t *rtgui_button_type_get(void) +{ + static rtgui_type_t *button_type = RT_NULL; + + if (!button_type) + { + button_type = rtgui_type_create("button", RTGUI_LABEL_TYPE, + sizeof(rtgui_button_t), + RTGUI_CONSTRUCTOR(_rtgui_button_constructor), + RTGUI_DESTRUCTOR(_rtgui_button_destructor)); + } + + return button_type; +} + +rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) +{ + struct rtgui_button* btn; + + RT_ASSERT(widget != RT_NULL); + + btn = (struct rtgui_button*) widget; + switch (event->type) + { + case RTGUI_EVENT_PAINT: + if (widget->on_draw != RT_NULL ) widget->on_draw(widget, event); + else rtgui_theme_draw_button(btn); + break; + + case RTGUI_EVENT_MOUSE_BUTTON: + { + struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event; + + if (btn->flag & RTGUI_BUTTON_TYPE_PUSH) + { + /* it's a push button */ + if (emouse->button & RTGUI_MOUSE_BUTTON_UP) + { + if (btn->flag & RTGUI_BUTTON_FLAG_PRESS) + btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS; + else + btn->flag |= RTGUI_BUTTON_FLAG_PRESS; + + /* draw button */ + if (widget->on_draw != RT_NULL ) widget->on_draw(widget, event); + else rtgui_theme_draw_button(btn); + + /* invokes call back */ + if (widget->on_mouseclick != RT_NULL && + emouse->button & RTGUI_MOUSE_BUTTON_UP) + return widget->on_mouseclick(widget, event); + } + } + else + { + if (emouse->button & RTGUI_MOUSE_BUTTON_LEFT) + { + /* it's a normal button */ + if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN) + { + btn->flag |= RTGUI_BUTTON_FLAG_PRESS; + } + else + { + btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS; + } + + /* draw button */ + if (widget->on_draw != RT_NULL ) widget->on_draw(widget, event); + else rtgui_theme_draw_button(btn); + + /* invokes call back */ + if (widget->on_mouseclick != RT_NULL && + emouse->button & RTGUI_MOUSE_BUTTON_UP) + return widget->on_mouseclick(widget, event); + } + + } + + return RT_TRUE; + } + } + + return RT_FALSE; +} + +rtgui_button_t* rtgui_button_create(unsigned char* text) +{ + struct rtgui_button* btn; + + btn = (struct rtgui_button*) rtgui_widget_create (RTGUI_BUTTON_TYPE); + if (btn != RT_NULL) + { + rtgui_rect_t rect; + + /* set default rect */ + rtgui_font_get_metrics(rtgui_font_default(), text, &rect); + rect.x2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1); + rect.y2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1); + rtgui_widget_set_rect(RTGUI_WIDGET(btn), &rect); + rtgui_label_set_text(RTGUI_LABEL(btn), text); + } + + return btn; +} + +rtgui_button_t* rtgui_pushbutton_create(unsigned char* text) +{ + rtgui_button_t* btn; + + btn = rtgui_button_create(text); + if (btn != RT_NULL) btn->flag |= RTGUI_BUTTON_TYPE_PUSH; + + return btn; +} + +void rtgui_button_destroy(rtgui_button_t* btn) +{ + rtgui_widget_destroy(RTGUI_WIDGET(btn)); +} + +void rtgui_button_set_pressed_image(rtgui_button_t* btn, rtgui_image_t* image) +{ + RT_ASSERT(btn != RT_NULL); + + btn->pressed_image = image; +} + +void rtgui_button_set_unpressed_image(rtgui_button_t* btn, rtgui_image_t* image) +{ + RT_ASSERT(btn != RT_NULL); + + btn->unpressed_image = image; +} + diff --git a/rtgui/widgets/container.c b/rtgui/widgets/container.c index 1a233807c..8771f70b7 100644 --- a/rtgui/widgets/container.c +++ b/rtgui/widgets/container.c @@ -1,279 +1,291 @@ -/* - * File : container.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-16 Bernard first version - */ -#include -#include - -static void _rtgui_container_constructor(rtgui_container_t *container) -{ - /* set event handler and init field */ - rtgui_widget_set_event_handler(RTGUI_WIDGET(container), rtgui_container_event_handler); - rtgui_list_init(&(container->children)); -} - -static void _rtgui_container_destructor(rtgui_container_t *container) -{ - /* destroy children of container */ - rtgui_container_destroy_children(container); -} - -static void _rtgui_container_update_toplevel(rtgui_container_t* container) -{ - struct rtgui_list_node* node; - - rtgui_list_foreach(node, &(container->children)) - { - rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling); - /* set child toplevel */ - child->toplevel = rtgui_widget_get_toplevel(RTGUI_WIDGET(container)); - - if (RTGUI_IS_CONTAINER(child)) - { - _rtgui_container_update_toplevel(RTGUI_CONTAINER(child)); - } - } -} - -rtgui_type_t *rtgui_container_type_get(void) -{ - static rtgui_type_t *container_type = RT_NULL; - - if (!container_type) - { - container_type = rtgui_type_create("container", RTGUI_WIDGET_TYPE, - sizeof(rtgui_container_t), - RTGUI_CONSTRUCTOR(_rtgui_container_constructor), - RTGUI_DESTRUCTOR(_rtgui_container_destructor)); - } - - return container_type; -} - -rt_bool_t rtgui_container_dispatch_event(rtgui_container_t *container, rtgui_event_t* event) -{ - /* handle in child widget */ - struct rtgui_list_node* node; - - rtgui_list_foreach(node, &(container->children)) - { - struct rtgui_widget* w; - w = rtgui_list_entry(node, struct rtgui_widget, sibling); - - if (w->event_handler(w, event) == RT_TRUE) return RT_TRUE; - } - - return RT_FALSE; -} - -rt_bool_t rtgui_container_dispatch_mouse_event(rtgui_container_t *container, struct rtgui_event_mouse* event) -{ - /* handle in child widget */ - struct rtgui_list_node* node; - - rtgui_list_foreach(node, &(container->children)) - { - struct rtgui_widget* w; - w = rtgui_list_entry(node, struct rtgui_widget, sibling); - if (rtgui_rect_contains_point(&(w->extent), event->x, event->y) == RT_EOK) - { - if (w->event_handler(w, (rtgui_event_t*)event) == RT_TRUE) return RT_TRUE; - } - } - - return RT_FALSE; -} - -rt_bool_t rtgui_container_event_handler(rtgui_widget_t* widget, rtgui_event_t* event) -{ - rtgui_container_t *container = RTGUI_CONTAINER(widget); - - switch (event->type) - { - case RTGUI_EVENT_PAINT: - if (widget->on_draw != RT_NULL) - { - return widget->on_draw(widget, event); - } - - rtgui_container_dispatch_event(container, event); - break; - - case RTGUI_EVENT_KBD: - if (widget->on_key != RT_NULL) - { - return widget->on_key(widget, event); - } - else - { - /* let parent to handle keyboard event */ - if (widget->parent != RT_NULL && widget->parent != widget->toplevel) - { - return widget->parent->event_handler(widget->parent, event); - } - } - break; - - case RTGUI_EVENT_MOUSE_BUTTON: - /* handle in child widget */ - if (rtgui_container_dispatch_mouse_event(container, - (struct rtgui_event_mouse*)event) == RT_FALSE) - { - /* handle event in current widget */ - if (widget->on_mouseclick != RT_NULL) - { - return widget->on_mouseclick(widget, event); - } - } - else return RT_TRUE; - break; - - case RTGUI_EVENT_MOUSE_MOTION: -#if 0 - if (rtgui_container_dispatch_mouse_event(container, - (struct rtgui_event_mouse*)event) == RT_FALSE) - { - /* handle event in current widget */ - if (widget->on_mousemotion != RT_NULL) - { - return widget->on_mousemotion(widget, event); - } - } - else return RT_TRUE; -#endif - break; - - case RTGUI_EVENT_COMMAND: - if (rtgui_container_dispatch_event(container, event) == RT_FALSE) - { - if (widget->on_command != RT_NULL) - { - return widget->on_command(widget, event); - } - } - else return RT_TRUE; - break; - - case RTGUI_EVENT_RESIZE: - if (rtgui_container_dispatch_event(container, event) == RT_FALSE) - { - if (widget->on_size != RT_NULL) - return widget->on_size(widget, event); - } - else return RT_TRUE; - break; - - default: - /* call parent widget event handler */ - return rtgui_widget_event_handler(widget, event); - } - - return RT_FALSE; -} - -/* - * This function will add a child to a container widget - * Note: this function will not change the widget layout - * the layout is the responsibility of layout widget, such as box. - */ -void rtgui_container_add_child(rtgui_container_t *container, rtgui_widget_t* child) -{ - RT_ASSERT(container != RT_NULL); - RT_ASSERT(child != RT_NULL); - - /* set parent and toplevel widget */ - child->parent = RTGUI_WIDGET(container); - /* put widget to parent's children list */ - rtgui_list_append(&(container->children), &(child->sibling)); - - /* update children toplevel */ - if (RTGUI_WIDGET(container)->toplevel != RT_NULL && - RTGUI_IS_TOPLEVEL(RTGUI_WIDGET(container)->toplevel)) - { - child->toplevel = rtgui_widget_get_toplevel(RTGUI_WIDGET(container)); - - /* update all child toplevel */ - if (RTGUI_IS_CONTAINER(child)) - { - _rtgui_container_update_toplevel(RTGUI_CONTAINER(child)); - } - } -} - -/* remove a child to widget */ -void rtgui_container_remove_child(rtgui_container_t *container, rtgui_widget_t* child) -{ - RT_ASSERT(container != RT_NULL); - RT_ASSERT(child != RT_NULL); - - /* remove widget from parent's children list */ - rtgui_list_remove(&(container->children), &(child->sibling)); - - /* set parent and toplevel widget */ - child->parent = RT_NULL; - child->toplevel = RT_NULL; -} - -/* destroy all children of container */ -void rtgui_container_destroy_children(rtgui_container_t *container) -{ - struct rtgui_list_node* node; - - if (container == RT_NULL) return; - - node = container->children.next; - while (node != RT_NULL) - { - rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling); - - if (RTGUI_IS_CONTAINER(child)) - { - /* destroy children of child */ - rtgui_container_destroy_children(RTGUI_CONTAINER(child)); - } - - /* destroy object and remove from parent */ - rtgui_object_destroy(RTGUI_OBJECT(child)); - - node = container->children.next; - } - - container->children.next = RT_NULL; - - /* update widget clip */ -#if 0 - rtgui_widget_update_clip(RTGUI_WIDGET(container)); -#else - /* update toplevel widget clip */ -#if 0 - { - rtgui_toplevel_t* top; - - top = RTGUI_TOPLEVEL(RTGUI_WIDGET(container)->toplevel); - if (RTGUI_IS_VIEW(top)) - } -#endif - rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(RTGUI_WIDGET(container)->toplevel)); -#endif -} - -rtgui_widget_t* rtgui_container_get_first_child(rtgui_container_t* container) -{ - rtgui_widget_t* child = RT_NULL; - - if (container->children.next != RT_NULL) - { - child = rtgui_list_entry(container->children.next, rtgui_widget_t, sibling); - } - - return child; -} +/* + * File : container.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-16 Bernard first version + */ +#include +#include + +static void _rtgui_container_constructor(rtgui_container_t *container) +{ + /* set event handler and init field */ + rtgui_widget_set_event_handler(RTGUI_WIDGET(container), rtgui_container_event_handler); + rtgui_list_init(&(container->children)); + + /* set focused widget to itself */ + container->focused = RTGUI_WIDGET(container); + /* set container as focusable widget */ + RTGUI_WIDGET(container)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; +} + +static void _rtgui_container_destructor(rtgui_container_t *container) +{ + /* destroy children of container */ + rtgui_container_destroy_children(container); +} + +static void _rtgui_container_update_toplevel(rtgui_container_t* container) +{ + struct rtgui_list_node* node; + + rtgui_list_foreach(node, &(container->children)) + { + rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling); + /* set child toplevel */ + child->toplevel = rtgui_widget_get_toplevel(RTGUI_WIDGET(container)); + + if (RTGUI_IS_CONTAINER(child)) + { + _rtgui_container_update_toplevel(RTGUI_CONTAINER(child)); + } + } +} + +rtgui_type_t *rtgui_container_type_get(void) +{ + static rtgui_type_t *container_type = RT_NULL; + + if (!container_type) + { + container_type = rtgui_type_create("container", RTGUI_WIDGET_TYPE, + sizeof(rtgui_container_t), + RTGUI_CONSTRUCTOR(_rtgui_container_constructor), + RTGUI_DESTRUCTOR(_rtgui_container_destructor)); + } + + return container_type; +} + +rt_bool_t rtgui_container_dispatch_event(rtgui_container_t *container, rtgui_event_t* event) +{ + /* handle in child widget */ + struct rtgui_list_node* node; + + rtgui_list_foreach(node, &(container->children)) + { + struct rtgui_widget* w; + w = rtgui_list_entry(node, struct rtgui_widget, sibling); + + if (w->event_handler(w, event) == RT_TRUE) return RT_TRUE; + } + + return RT_FALSE; +} + +rt_bool_t rtgui_container_dispatch_mouse_event(rtgui_container_t *container, struct rtgui_event_mouse* event) +{ + /* handle in child widget */ + struct rtgui_list_node* node; + + rtgui_list_foreach(node, &(container->children)) + { + struct rtgui_widget* w; + w = rtgui_list_entry(node, struct rtgui_widget, sibling); + if (rtgui_rect_contains_point(&(w->extent), event->x, event->y) == RT_EOK) + { + if (w->event_handler(w, (rtgui_event_t*)event) == RT_TRUE) return RT_TRUE; + } + } + + return RT_FALSE; +} + +rt_bool_t rtgui_container_event_handler(rtgui_widget_t* widget, rtgui_event_t* event) +{ + rtgui_container_t *container = RTGUI_CONTAINER(widget); + + switch (event->type) + { + case RTGUI_EVENT_PAINT: + if (widget->on_draw != RT_NULL) + { + return widget->on_draw(widget, event); + } + + rtgui_container_dispatch_event(container, event); + break; + + case RTGUI_EVENT_KBD: + if (widget->on_key != RT_NULL) + { + return widget->on_key(widget, event); + } + else + { + /* let parent to handle keyboard event */ + if (widget->parent != RT_NULL && widget->parent != widget->toplevel) + { + return widget->parent->event_handler(widget->parent, event); + } + } + break; + + case RTGUI_EVENT_MOUSE_BUTTON: + /* handle in child widget */ + if (rtgui_container_dispatch_mouse_event(container, + (struct rtgui_event_mouse*)event) == RT_FALSE) + { + /* handle event in current widget */ + if (widget->on_mouseclick != RT_NULL) + { + return widget->on_mouseclick(widget, event); + } + } + else return RT_TRUE; + break; + + case RTGUI_EVENT_MOUSE_MOTION: + if (rtgui_container_dispatch_mouse_event(container, + (struct rtgui_event_mouse*)event) == RT_FALSE) + { +#if 0 + /* handle event in current widget */ + if (widget->on_mousemotion != RT_NULL) + { + return widget->on_mousemotion(widget, event); + } +#endif + } + else return RT_TRUE; + break; + + case RTGUI_EVENT_COMMAND: + if (rtgui_container_dispatch_event(container, event) == RT_FALSE) + { + if (widget->on_command != RT_NULL) + { + return widget->on_command(widget, event); + } + } + else return RT_TRUE; + break; + + case RTGUI_EVENT_RESIZE: + if (rtgui_container_dispatch_event(container, event) == RT_FALSE) + { + if (widget->on_size != RT_NULL) + return widget->on_size(widget, event); + } + else return RT_TRUE; + break; + + default: + /* call parent widget event handler */ + return rtgui_widget_event_handler(widget, event); + } + + return RT_FALSE; +} + +/* + * This function will add a child to a container widget + * Note: this function will not change the widget layout + * the layout is the responsibility of layout widget, such as box. + */ +void rtgui_container_add_child(rtgui_container_t *container, rtgui_widget_t* child) +{ + RT_ASSERT(container != RT_NULL); + RT_ASSERT(child != RT_NULL); + + /* set parent and toplevel widget */ + child->parent = RTGUI_WIDGET(container); + /* put widget to parent's children list */ + rtgui_list_append(&(container->children), &(child->sibling)); + + /* update children toplevel */ + if (RTGUI_WIDGET(container)->toplevel != RT_NULL && + RTGUI_IS_TOPLEVEL(RTGUI_WIDGET(container)->toplevel)) + { + child->toplevel = rtgui_widget_get_toplevel(RTGUI_WIDGET(container)); + + /* update all child toplevel */ + if (RTGUI_IS_CONTAINER(child)) + { + _rtgui_container_update_toplevel(RTGUI_CONTAINER(child)); + } + } +} + +/* remove a child to widget */ +void rtgui_container_remove_child(rtgui_container_t *container, rtgui_widget_t* child) +{ + RT_ASSERT(container != RT_NULL); + RT_ASSERT(child != RT_NULL); + + if (child == container->focused) + { + /* set focused to itself */ + container->focused = RTGUI_WIDGET(container); + + rtgui_widget_focus(RTGUI_WIDGET(container)); + } + + /* remove widget from parent's children list */ + rtgui_list_remove(&(container->children), &(child->sibling)); + + /* set parent and toplevel widget */ + child->parent = RT_NULL; + child->toplevel = RT_NULL; +} + +/* destroy all children of container */ +void rtgui_container_destroy_children(rtgui_container_t *container) +{ + struct rtgui_list_node* node; + + if (container == RT_NULL) return; + + node = container->children.next; + while (node != RT_NULL) + { + rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling); + + if (RTGUI_IS_CONTAINER(child)) + { + /* break parent firstly */ + child->parent = RT_NULL; + + /* destroy children of child */ + rtgui_container_destroy_children(RTGUI_CONTAINER(child)); + } + + /* remove widget from parent's children list */ + rtgui_list_remove(&(container->children), &(child->sibling)); + + /* set parent and toplevel widget */ + child->parent = RT_NULL; + + /* destroy object and remove from parent */ + rtgui_object_destroy(RTGUI_OBJECT(child)); + + node = container->children.next; + } + + container->children.next = RT_NULL; + container->focused = RTGUI_WIDGET(container); + if (RTGUI_WIDGET(container)->parent != RT_NULL) + rtgui_widget_focus(RTGUI_WIDGET(container)); + + /* update widget clip */ + rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(RTGUI_WIDGET(container)->toplevel)); +} + +rtgui_widget_t* rtgui_container_get_first_child(rtgui_container_t* container) +{ + rtgui_widget_t* child = RT_NULL; + + if (container->children.next != RT_NULL) + { + child = rtgui_list_entry(container->children.next, rtgui_widget_t, sibling); + } + + return child; +} diff --git a/rtgui/widgets/iconbox.c b/rtgui/widgets/iconbox.c index b44cab1e7..c141e8198 100644 --- a/rtgui/widgets/iconbox.c +++ b/rtgui/widgets/iconbox.c @@ -1,167 +1,167 @@ -/* - * File : iconbox.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-16 Bernard first version - */ -#include -#include -#include - -static void _rtgui_iconbox_constructor(rtgui_iconbox_t *iconbox) -{ - /* init widget and set event handler */ - RTGUI_WIDGET(iconbox)->flag |= RTGUI_WIDGET_FLAG_TRANSPARENT; - rtgui_widget_set_event_handler(RTGUI_WIDGET(iconbox), rtgui_iconbox_event_handler); - - /* set proper of control */ - iconbox->image = RT_NULL; - iconbox->selected = RT_FALSE; - iconbox->text = RT_NULL; - iconbox->text_position = RTGUI_ICONBOX_TEXT_BELOW; -} - -static void _rtgui_iconbox_destructor(rtgui_iconbox_t *iconbox) -{ - if (iconbox->image != RT_NULL) - { - rtgui_image_destroy(iconbox->image); - iconbox->image = RT_NULL; - } - - rt_free(iconbox->text); - iconbox->text = RT_NULL; -} - -rtgui_type_t *rtgui_iconbox_type_get(void) -{ - static rtgui_type_t *iconbox_type = RT_NULL; - - if (!iconbox_type) - { - iconbox_type = rtgui_type_create("iconbox", RTGUI_WIDGET_TYPE, - sizeof(rtgui_iconbox_t), RTGUI_CONSTRUCTOR(_rtgui_iconbox_constructor), - RTGUI_DESTRUCTOR(_rtgui_iconbox_destructor)); - } - - return iconbox_type; -} - -rt_bool_t rtgui_iconbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) -{ - struct rtgui_iconbox* iconbox = (struct rtgui_iconbox*)widget; - - switch (event->type) - { - case RTGUI_EVENT_PAINT: - if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); - else - { - rtgui_theme_draw_iconbox(iconbox); - } - - break; - } - - return RT_FALSE; -} - -struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image, - const unsigned char* text, - int position) -{ - struct rtgui_iconbox* iconbox; - - iconbox = (struct rtgui_iconbox*)rtgui_widget_create(RTGUI_ICONBOX_TYPE); - if (iconbox != RT_NULL) - { - rtgui_rect_t rect = {0, 0, 0, 0}, text_rect; - - rect.x2 = image->w; - rect.y2 = image->h; - - /* get text rect */ - rtgui_font_get_metrics(rtgui_font_default(), text, &text_rect); - if (position == RTGUI_ICONBOX_TEXT_BELOW) - { - rect.y2 += RTGUI_WIDGET_DEFAULT_MARGIN; - if (text_rect.x2 > rect.x2) - { - rect.x2 = text_rect.x2; - } - rect.y2 += text_rect.y2; - } - else if (position == RTGUI_ICONBOX_TEXT_RIGHT) - { - rect.x2 += RTGUI_WIDGET_DEFAULT_MARGIN; - if (text_rect.y2 > rect.y2) - { - rect.y2 = text_rect.y2; - } - rect.x2 += text_rect.x2; - } - - /* set widget rect */ - rtgui_widget_set_rect(RTGUI_WIDGET(iconbox), &rect); - - /* set image and text position */ - iconbox->image = image; - iconbox->text = (unsigned char*)rt_strdup((const char*)text); - iconbox->text_position = position; - } - - return iconbox; -} - -void rtgui_iconbox_destroy(struct rtgui_iconbox* iconbox) -{ - rtgui_widget_destroy(RTGUI_WIDGET(iconbox)); -} - -void rtgui_iconbox_set_text_position(struct rtgui_iconbox* iconbox, int position) -{ - rtgui_rect_t rect = {0, 0, 0, 0}, text_rect; - - RT_ASSERT(iconbox != RT_NULL); - - iconbox->text_position = position; - - /* set mini width and height */ - rect.x2 = iconbox->image->w; - rect.y2 = iconbox->image->h; - - /* get text rect */ - if (iconbox->text != RT_NULL) - { - rtgui_font_get_metrics(rtgui_font_default(), - iconbox->text, &text_rect); - if (position == RTGUI_ICONBOX_TEXT_BELOW) - { - rect.y2 += RTGUI_WIDGET_DEFAULT_MARGIN; - if (text_rect.x2 > rect.x2) - { - rect.x2 = text_rect.x2; - } - rect.y2 += text_rect.y2; - } - else if (position == RTGUI_ICONBOX_TEXT_RIGHT) - { - rect.x2 += RTGUI_WIDGET_DEFAULT_MARGIN; - if (text_rect.y2 > rect.y2) - { - rect.y2 = text_rect.y2; - } - rect.x2 += text_rect.x2; - } - } - - rtgui_widget_set_miniwidth(RTGUI_WIDGET(iconbox), rect.x2); - rtgui_widget_set_miniheight(RTGUI_WIDGET(iconbox), rect.y2); -} +/* + * File : iconbox.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-16 Bernard first version + */ +#include +#include +#include + +static void _rtgui_iconbox_constructor(rtgui_iconbox_t *iconbox) +{ + /* init widget and set event handler */ + RTGUI_WIDGET(iconbox)->flag |= RTGUI_WIDGET_FLAG_TRANSPARENT; + rtgui_widget_set_event_handler(RTGUI_WIDGET(iconbox), rtgui_iconbox_event_handler); + + /* set proper of control */ + iconbox->image = RT_NULL; + iconbox->selected = RT_FALSE; + iconbox->text = RT_NULL; + iconbox->text_position = RTGUI_ICONBOX_TEXT_BELOW; +} + +static void _rtgui_iconbox_destructor(rtgui_iconbox_t *iconbox) +{ + if (iconbox->image != RT_NULL) + { + rtgui_image_destroy(iconbox->image); + iconbox->image = RT_NULL; + } + + rt_free(iconbox->text); + iconbox->text = RT_NULL; +} + +rtgui_type_t *rtgui_iconbox_type_get(void) +{ + static rtgui_type_t *iconbox_type = RT_NULL; + + if (!iconbox_type) + { + iconbox_type = rtgui_type_create("iconbox", RTGUI_WIDGET_TYPE, + sizeof(rtgui_iconbox_t), RTGUI_CONSTRUCTOR(_rtgui_iconbox_constructor), + RTGUI_DESTRUCTOR(_rtgui_iconbox_destructor)); + } + + return iconbox_type; +} + +rt_bool_t rtgui_iconbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) +{ + struct rtgui_iconbox* iconbox = (struct rtgui_iconbox*)widget; + + switch (event->type) + { + case RTGUI_EVENT_PAINT: + if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); + else + { + rtgui_theme_draw_iconbox(iconbox); + } + + break; + } + + return RT_FALSE; +} + +struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image, + const unsigned char* text, + int position) +{ + struct rtgui_iconbox* iconbox; + + iconbox = (struct rtgui_iconbox*)rtgui_widget_create(RTGUI_ICONBOX_TYPE); + if (iconbox != RT_NULL) + { + rtgui_rect_t rect = {0, 0, 0, 0}, text_rect; + + rect.x2 = image->w; + rect.y2 = image->h; + + /* get text rect */ + rtgui_font_get_metrics(rtgui_font_default(), text, &text_rect); + if (position == RTGUI_ICONBOX_TEXT_BELOW) + { + rect.y2 += RTGUI_WIDGET_DEFAULT_MARGIN; + if (text_rect.x2 > rect.x2) + { + rect.x2 = text_rect.x2; + } + rect.y2 += text_rect.y2; + } + else if (position == RTGUI_ICONBOX_TEXT_RIGHT) + { + rect.x2 += RTGUI_WIDGET_DEFAULT_MARGIN; + if (text_rect.y2 > rect.y2) + { + rect.y2 = text_rect.y2; + } + rect.x2 += text_rect.x2; + } + + /* set widget rect */ + rtgui_widget_set_rect(RTGUI_WIDGET(iconbox), &rect); + + /* set image and text position */ + iconbox->image = image; + iconbox->text = (unsigned char*)rt_strdup((const char*)text); + iconbox->text_position = position; + } + + return iconbox; +} + +void rtgui_iconbox_destroy(struct rtgui_iconbox* iconbox) +{ + rtgui_widget_destroy(RTGUI_WIDGET(iconbox)); +} + +void rtgui_iconbox_set_text_position(struct rtgui_iconbox* iconbox, int position) +{ + rtgui_rect_t rect = {0, 0, 0, 0}, text_rect; + + RT_ASSERT(iconbox != RT_NULL); + + iconbox->text_position = position; + + /* set mini width and height */ + rect.x2 = iconbox->image->w; + rect.y2 = iconbox->image->h; + + /* get text rect */ + if (iconbox->text != RT_NULL) + { + rtgui_font_get_metrics(rtgui_font_default(), + iconbox->text, &text_rect); + if (position == RTGUI_ICONBOX_TEXT_BELOW) + { + rect.y2 += RTGUI_WIDGET_DEFAULT_MARGIN; + if (text_rect.x2 > rect.x2) + { + rect.x2 = text_rect.x2; + } + rect.y2 += text_rect.y2; + } + else if (position == RTGUI_ICONBOX_TEXT_RIGHT) + { + rect.x2 += RTGUI_WIDGET_DEFAULT_MARGIN; + if (text_rect.y2 > rect.y2) + { + rect.y2 = text_rect.y2; + } + rect.x2 += text_rect.x2; + } + } + + rtgui_widget_set_miniwidth(RTGUI_WIDGET(iconbox), rect.x2); + rtgui_widget_set_miniheight(RTGUI_WIDGET(iconbox), rect.y2); +} diff --git a/rtgui/widgets/label.c b/rtgui/widgets/label.c index 992142472..68e41d074 100644 --- a/rtgui/widgets/label.c +++ b/rtgui/widgets/label.c @@ -1,113 +1,113 @@ -/* - * File : label.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-16 Bernard first version - */ -#include -#include -#include -#include - -static void _rtgui_label_constructor(rtgui_label_t *label) -{ - /* init widget and set event handler */ - rtgui_widget_set_event_handler(RTGUI_WIDGET(label), rtgui_label_event_handler); - - /* set field */ - label->text = RT_NULL; -} - -static void _rtgui_label_destructor(rtgui_label_t *label) -{ - /* release text memory */ - rt_free(label->text); - label->text = RT_NULL; -} - -rtgui_type_t *rtgui_label_type_get(void) -{ - static rtgui_type_t *label_type = RT_NULL; - - if (!label_type) - { - label_type = rtgui_type_create("label", RTGUI_WIDGET_TYPE, - sizeof(rtgui_label_t), - RTGUI_CONSTRUCTOR(_rtgui_label_constructor), - RTGUI_DESTRUCTOR(_rtgui_label_destructor)); - } - - return label_type; -} - -rt_bool_t rtgui_label_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) -{ - struct rtgui_label* label; - - RT_ASSERT(widget != RT_NULL); - - label = (struct rtgui_label*) widget; - switch (event->type) - { - case RTGUI_EVENT_PAINT: - rtgui_theme_draw_label(label); - break; - } - - return RT_FALSE; -} - -rtgui_label_t* rtgui_label_create(const unsigned char* text) -{ - struct rtgui_label* label; - - label = (struct rtgui_label*) rtgui_widget_create(RTGUI_LABEL_TYPE); - if (label != RT_NULL) - { - rtgui_rect_t rect; - - /* set default rect */ - rtgui_font_get_metrics(rtgui_font_default(), text, &rect); - rect.x2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1); - rect.y2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1); - rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); - - /* set text */ - label->text = (unsigned char*)rt_strdup((const char*)text); - } - - return label; -} - -void rtgui_label_destroy(rtgui_label_t* label) -{ - rtgui_widget_destroy(RTGUI_WIDGET(label)); -} - -unsigned char* rtgui_label_get_text(rtgui_label_t* label) -{ - RT_ASSERT(label != RT_NULL); - - return label->text; -} - -void rtgui_label_set_text(rtgui_label_t* label, const unsigned char* text) -{ - RT_ASSERT(label != RT_NULL); - - if (label->text != RT_NULL) - { - /* release old text memory */ - rt_free(label->text); - } - - if (text != RT_NULL) label->text = (unsigned char*)rt_strdup((const char*)text); - else label->text = RT_NULL; -} +/* + * File : label.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-16 Bernard first version + */ +#include +#include +#include +#include + +static void _rtgui_label_constructor(rtgui_label_t *label) +{ + /* init widget and set event handler */ + rtgui_widget_set_event_handler(RTGUI_WIDGET(label), rtgui_label_event_handler); + + /* set field */ + label->text = RT_NULL; +} + +static void _rtgui_label_destructor(rtgui_label_t *label) +{ + /* release text memory */ + rt_free(label->text); + label->text = RT_NULL; +} + +rtgui_type_t *rtgui_label_type_get(void) +{ + static rtgui_type_t *label_type = RT_NULL; + + if (!label_type) + { + label_type = rtgui_type_create("label", RTGUI_WIDGET_TYPE, + sizeof(rtgui_label_t), + RTGUI_CONSTRUCTOR(_rtgui_label_constructor), + RTGUI_DESTRUCTOR(_rtgui_label_destructor)); + } + + return label_type; +} + +rt_bool_t rtgui_label_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) +{ + struct rtgui_label* label; + + RT_ASSERT(widget != RT_NULL); + + label = (struct rtgui_label*) widget; + switch (event->type) + { + case RTGUI_EVENT_PAINT: + rtgui_theme_draw_label(label); + break; + } + + return RT_FALSE; +} + +rtgui_label_t* rtgui_label_create(const unsigned char* text) +{ + struct rtgui_label* label; + + label = (struct rtgui_label*) rtgui_widget_create(RTGUI_LABEL_TYPE); + if (label != RT_NULL) + { + rtgui_rect_t rect; + + /* set default rect */ + rtgui_font_get_metrics(rtgui_font_default(), text, &rect); + rect.x2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1); + rect.y2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1); + rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); + + /* set text */ + label->text = (unsigned char*)rt_strdup((const char*)text); + } + + return label; +} + +void rtgui_label_destroy(rtgui_label_t* label) +{ + rtgui_widget_destroy(RTGUI_WIDGET(label)); +} + +unsigned char* rtgui_label_get_text(rtgui_label_t* label) +{ + RT_ASSERT(label != RT_NULL); + + return label->text; +} + +void rtgui_label_set_text(rtgui_label_t* label, const unsigned char* text) +{ + RT_ASSERT(label != RT_NULL); + + if (label->text != RT_NULL) + { + /* release old text memory */ + rt_free(label->text); + } + + if (text != RT_NULL) label->text = (unsigned char*)rt_strdup((const char*)text); + else label->text = RT_NULL; +} diff --git a/rtgui/widgets/textbox.c b/rtgui/widgets/textbox.c index 560ffb914..2f1e79227 100644 --- a/rtgui/widgets/textbox.c +++ b/rtgui/widgets/textbox.c @@ -1,348 +1,350 @@ -/* - * File : textbox.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-16 Bernard first version - */ -#include -#include -#include - -#include - -#define RTGUI_TEXTBOX_LINE_MAX 64 -#define RTGUI_TEXTBOX_MARGIN 3 - -static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kbd* event); -static rt_bool_t rtgui_textbox_onfocus(struct rtgui_widget* widget, struct rtgui_event* event); -static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_widget* widget, struct rtgui_event* event); - -static void _rtgui_textbox_constructor(rtgui_textbox_t *box) -{ - rtgui_rect_t rect = {0, 0, RTGUI_TEXTBOX_DEFAULT_WIDTH, RTGUI_TEXTBOX_DEFAULT_HEIGHT}; - rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect); - - RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; - rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_textbox_event_handler); - rtgui_widget_set_onfocus(RTGUI_WIDGET(box), rtgui_textbox_onfocus); - rtgui_widget_set_onunfocus(RTGUI_WIDGET(box), rtgui_textbox_onunfocus); - - /* set default text align */ - RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(box)) = RTGUI_ALIGN_CENTER_VERTICAL; - - /* set proper of control */ - box->caret_x = box->caret_y = 0; - box->caret = rtgui_caret_create(RTGUI_WIDGET(box)); - - box->line = box->line_begin = box->position = 0; - box->type = RTGUI_TEXTBOX_SINGLE; - - /* allocate default line buffer */ - box->text = RT_NULL; - - rtgui_font_get_metrics(RTGUI_WIDGET(box)->gc.font, "h", &rect); - box->font_width = rtgui_rect_width(rect); -} - -static void _rtgui_textbox_deconstructor(rtgui_textbox_t *box) -{ - if (box->text != RT_NULL) - { - rt_free(box->text); - box->text = RT_NULL; - } - - if (box->caret != RT_NULL) - { - rtgui_caret_destroy(box->caret); - box->caret = RT_NULL; - } -} - -rtgui_type_t *rtgui_textbox_type_get(void) -{ - static rtgui_type_t *textbox_type = RT_NULL; - - if (!textbox_type) - { - textbox_type = rtgui_type_create("textbox", RTGUI_WIDGET_TYPE, - sizeof(rtgui_textbox_t), - RTGUI_CONSTRUCTOR(_rtgui_textbox_constructor), - RTGUI_DESTRUCTOR(_rtgui_textbox_deconstructor)); - } - - return textbox_type; -} - -static void rtgui_textbox_onmouse(struct rtgui_textbox* box, struct rtgui_event_mouse* event) -{ - rt_size_t length; - - RT_ASSERT(box != RT_NULL); - RT_ASSERT(event != RT_NULL); - - length = rt_strlen((const char*)box->text); - - if (event->button & RTGUI_MOUSE_BUTTON_LEFT && - event->button & RTGUI_MOUSE_BUTTON_DOWN) - { - rt_int32_t x; - - /* set caret position */ - x = event->x - RTGUI_WIDGET(box)->extent.x1; - if (x < 0) - { - box->position = 0; - } - else if (x > length * box->font_width) - { - box->position = length; - } - else - { - box->position = x / box->font_width; - } - - rtgui_caret_set_point(box->caret, RTGUI_TEXTBOX_MARGIN + box->position * box->font_width, 2); - rtgui_caret_set_box(box->caret, 2, rtgui_rect_height(RTGUI_WIDGET(box)->extent) - 4); - - /* set widget focus */ - rtgui_widget_focus(RTGUI_WIDGET(box)); - } -} - -static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kbd* event) -{ - rt_size_t length; - - RT_ASSERT(box != RT_NULL); - RT_ASSERT(event != RT_NULL); - - if (event->type != RTGUI_KEYDOWN) - return ; - - length = rt_strlen((const char*)box->text); - if (event->key == RTGUIK_DELETE) - { - if (box->position == length - 1) - { - box->text[box->position] = '\0'; - } - else - { - unsigned char *c; - - /* remove character */ - for (c = &box->text[box->position]; c[1] != '\0'; c++) - *c = c[1]; - *c = '\0'; - } - } - else if (event->key == RTGUIK_BACKSPACE) - { - if (box->position == length - 1) - { - box->text[box->position] = '\0'; - box->position --; - } - else if (box->position != 0) - { - /* remove current character */ - if (box->position != 0) - { - unsigned char *c; - - /* remove character */ - for (c = &box->text[box->position - 1]; c[1] != '\0'; c++) - *c = c[1]; - *c = '\0'; - } - box->position --; - } - } - else if (event->key == RTGUIK_LEFT) - { - if (box->position > 0) box->position --; - } - else if (event->key == RTGUIK_RIGHT) - { - if (box->position < length) box->position ++; - } - else if (event->key == RTGUIK_HOME) - { - box->position = 0; - } - else if (event->key == RTGUIK_END) - { - box->position = length; - } - else if (event->key == RTGUIK_RETURN) - { - if (box->on_enter != RT_NULL) - { - box->on_enter(RTGUI_WIDGET(box), RT_NULL); - } - } - else - { - if (isprint(event->key) || isdigit(event->key)) - { - /* no buffer on this line */ - if (length + 1 > box->line_length) return; - - if (box->position < length - 1) - { - unsigned char* c; - - for (c = &box->text[length]; c != &box->text[box->position]; c--) - *c = *(c-1); - box->text[length + 1] = '\0'; - } - - box->text[box->position] = event->key; - box->position ++; - } - } - - /* re-draw text box */ - rtgui_theme_draw_textbox(box); - rtgui_caret_set_point(box->caret, - RTGUI_TEXTBOX_MARGIN + box->position * box->font_width , 2); - rtgui_caret_set_box(box->caret, 2, rtgui_rect_height(RTGUI_WIDGET(box)->extent) - 4); -} - -static rt_bool_t rtgui_textbox_onfocus(struct rtgui_widget* widget, struct rtgui_event* event) -{ - struct rtgui_textbox* box = (struct rtgui_textbox*)widget; - - /* show caret */ - rtgui_caret_show(box->caret, box->caret_x, box->caret_y); - - return RT_TRUE; -} - -static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_widget* widget, struct rtgui_event* event) -{ - struct rtgui_textbox* box = (struct rtgui_textbox*)widget; - - /* hide caret */ - rtgui_caret_hide(box->caret); - - return RT_TRUE; -} - -rt_bool_t rtgui_textbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) -{ - struct rtgui_textbox* box = (struct rtgui_textbox*)widget; - - switch (event->type) - { - case RTGUI_EVENT_PAINT: - if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); - else rtgui_theme_draw_textbox(box); - break; - - case RTGUI_EVENT_MOUSE_BUTTON: - if (widget->on_mouseclick != RT_NULL) widget->on_mouseclick(widget, event); - else rtgui_textbox_onmouse(box, (struct rtgui_event_mouse*)event); - return RT_TRUE; - - case RTGUI_EVENT_KBD: - if (widget->on_key != RT_NULL) widget->on_key(widget, event); - else rtgui_textbox_onkey(box, (struct rtgui_event_kbd*)event); - return RT_TRUE; - } - - return RT_FALSE; -} - -struct rtgui_textbox* rtgui_textbox_create(const char* text) -{ - struct rtgui_textbox* box; - - box = (struct rtgui_textbox*) rtgui_widget_create (RTGUI_TEXTBOX_TYPE); - if (box != RT_NULL) - { - rtgui_rect_t rect = {0, 0, RTGUI_TEXTBOX_DEFAULT_WIDTH, RTGUI_TEXTBOX_DEFAULT_HEIGHT}; - - /* allocate default line buffer */ - rtgui_textbox_set_value(box, text); - - rtgui_font_get_metrics(RTGUI_WIDGET(box)->gc.font, "h", &rect); - box->font_width = rtgui_rect_width(rect); - } - - return box; -} - -void rtgui_textbox_destroy(struct rtgui_textbox* box) -{ - rtgui_widget_destroy(RTGUI_WIDGET(box)); -} - -void rtgui_textbox_set_value(struct rtgui_textbox* box, const char* text) -{ - if (box->text != RT_NULL) - { - if (box->line_length > rt_strlen(text) + 1) - { - rt_memcpy(box->text, text, rt_strlen(text) + 1); - return; - } - else - { - /* free the old text */ - rtgui_free(box->text); - box->text = RT_NULL; - } - } - - box->line_length = RTGUI_TEXTBOX_LINE_MAX > rt_strlen(text) + 1 ? - RTGUI_TEXTBOX_LINE_MAX : rt_strlen(text) + 1; - - /* allocate line buffer */ - box->text = rtgui_malloc(box->line_length); - rt_memset(box->text, 0, box->line_length); - - /* copy text */ - rt_memcpy(box->text, text, rt_strlen(text) + 1); - - /* set current position */ - box->position = 0; -} - -const char* rtgui_textbox_get_value(struct rtgui_textbox* box) -{ - return (const char*)box->text; -} - -void rtgui_widget_set_line_length(struct rtgui_textbox* box, rt_size_t length) -{ - rt_uint8_t* new_line; - - RT_ASSERT(box != RT_NULL); - - /* invalid length */ - if (length <= 0) return; - - new_line = rtgui_malloc(length); - if (length < box->line_length) - { - rt_memcpy(new_line, box->text, length - 1); - new_line[length] = '\0'; - } - else - { - rt_memcpy(new_line, (const char*)box->text, rt_strlen((const char*)box->text)); - } - - /* set line length */ - box->line_length = length; -} +/* + * File : textbox.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-16 Bernard first version + */ +#include +#include +#include + +#ifndef _WIN32 +#include +#endif + +#define RTGUI_TEXTBOX_LINE_MAX 64 +#define RTGUI_TEXTBOX_MARGIN 3 + +static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kbd* event); +static rt_bool_t rtgui_textbox_onfocus(struct rtgui_widget* widget, struct rtgui_event* event); +static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_widget* widget, struct rtgui_event* event); + +static void _rtgui_textbox_constructor(rtgui_textbox_t *box) +{ + rtgui_rect_t rect = {0, 0, RTGUI_TEXTBOX_DEFAULT_WIDTH, RTGUI_TEXTBOX_DEFAULT_HEIGHT}; + rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect); + + RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; + rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_textbox_event_handler); + rtgui_widget_set_onfocus(RTGUI_WIDGET(box), rtgui_textbox_onfocus); + rtgui_widget_set_onunfocus(RTGUI_WIDGET(box), rtgui_textbox_onunfocus); + + /* set default text align */ + RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(box)) = RTGUI_ALIGN_CENTER_VERTICAL; + + /* set proper of control */ + box->caret_x = box->caret_y = 0; + box->caret = rtgui_caret_create(RTGUI_WIDGET(box)); + + box->line = box->line_begin = box->position = 0; + box->type = RTGUI_TEXTBOX_SINGLE; + + /* allocate default line buffer */ + box->text = RT_NULL; + + rtgui_font_get_metrics(RTGUI_WIDGET(box)->gc.font, "h", &rect); + box->font_width = rtgui_rect_width(rect); +} + +static void _rtgui_textbox_deconstructor(rtgui_textbox_t *box) +{ + if (box->text != RT_NULL) + { + rt_free(box->text); + box->text = RT_NULL; + } + + if (box->caret != RT_NULL) + { + rtgui_caret_destroy(box->caret); + box->caret = RT_NULL; + } +} + +rtgui_type_t *rtgui_textbox_type_get(void) +{ + static rtgui_type_t *textbox_type = RT_NULL; + + if (!textbox_type) + { + textbox_type = rtgui_type_create("textbox", RTGUI_WIDGET_TYPE, + sizeof(rtgui_textbox_t), + RTGUI_CONSTRUCTOR(_rtgui_textbox_constructor), + RTGUI_DESTRUCTOR(_rtgui_textbox_deconstructor)); + } + + return textbox_type; +} + +static void rtgui_textbox_onmouse(struct rtgui_textbox* box, struct rtgui_event_mouse* event) +{ + rt_size_t length; + + RT_ASSERT(box != RT_NULL); + RT_ASSERT(event != RT_NULL); + + length = rt_strlen((const char*)box->text); + + if (event->button & RTGUI_MOUSE_BUTTON_LEFT && + event->button & RTGUI_MOUSE_BUTTON_DOWN) + { + rt_int32_t x; + + /* set caret position */ + x = event->x - RTGUI_WIDGET(box)->extent.x1; + if (x < 0) + { + box->position = 0; + } + else if (x > length * box->font_width) + { + box->position = length; + } + else + { + box->position = x / box->font_width; + } + + rtgui_caret_set_point(box->caret, RTGUI_TEXTBOX_MARGIN + box->position * box->font_width, 2); + rtgui_caret_set_box(box->caret, 2, rtgui_rect_height(RTGUI_WIDGET(box)->extent) - 4); + + /* set widget focus */ + rtgui_widget_focus(RTGUI_WIDGET(box)); + } +} + +static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kbd* event) +{ + rt_size_t length; + + RT_ASSERT(box != RT_NULL); + RT_ASSERT(event != RT_NULL); + + if (event->type != RTGUI_KEYDOWN) + return ; + + length = rt_strlen((const char*)box->text); + if (event->key == RTGUIK_DELETE) + { + if (box->position == length - 1) + { + box->text[box->position] = '\0'; + } + else + { + unsigned char *c; + + /* remove character */ + for (c = &box->text[box->position]; c[1] != '\0'; c++) + *c = c[1]; + *c = '\0'; + } + } + else if (event->key == RTGUIK_BACKSPACE) + { + if (box->position == length - 1) + { + box->text[box->position] = '\0'; + box->position --; + } + else if (box->position != 0) + { + /* remove current character */ + if (box->position != 0) + { + unsigned char *c; + + /* remove character */ + for (c = &box->text[box->position - 1]; c[1] != '\0'; c++) + *c = c[1]; + *c = '\0'; + } + box->position --; + } + } + else if (event->key == RTGUIK_LEFT) + { + if (box->position > 0) box->position --; + } + else if (event->key == RTGUIK_RIGHT) + { + if (box->position < length) box->position ++; + } + else if (event->key == RTGUIK_HOME) + { + box->position = 0; + } + else if (event->key == RTGUIK_END) + { + box->position = length; + } + else if (event->key == RTGUIK_RETURN) + { + if (box->on_enter != RT_NULL) + { + box->on_enter(RTGUI_WIDGET(box), RT_NULL); + } + } + else + { + if (isprint(event->key) || isdigit(event->key)) + { + /* no buffer on this line */ + if (length + 1 > box->line_length) return; + + if (box->position < length - 1) + { + unsigned char* c; + + for (c = &box->text[length]; c != &box->text[box->position]; c--) + *c = *(c-1); + box->text[length + 1] = '\0'; + } + + box->text[box->position] = event->key; + box->position ++; + } + } + + /* re-draw text box */ + rtgui_theme_draw_textbox(box); + rtgui_caret_set_point(box->caret, + RTGUI_TEXTBOX_MARGIN + box->position * box->font_width , 2); + rtgui_caret_set_box(box->caret, 2, rtgui_rect_height(RTGUI_WIDGET(box)->extent) - 4); +} + +static rt_bool_t rtgui_textbox_onfocus(struct rtgui_widget* widget, struct rtgui_event* event) +{ + struct rtgui_textbox* box = (struct rtgui_textbox*)widget; + + /* show caret */ + rtgui_caret_show(box->caret, box->caret_x, box->caret_y); + + return RT_TRUE; +} + +static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_widget* widget, struct rtgui_event* event) +{ + struct rtgui_textbox* box = (struct rtgui_textbox*)widget; + + /* hide caret */ + rtgui_caret_hide(box->caret); + + return RT_TRUE; +} + +rt_bool_t rtgui_textbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) +{ + struct rtgui_textbox* box = (struct rtgui_textbox*)widget; + + switch (event->type) + { + case RTGUI_EVENT_PAINT: + if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); + else rtgui_theme_draw_textbox(box); + break; + + case RTGUI_EVENT_MOUSE_BUTTON: + if (widget->on_mouseclick != RT_NULL) widget->on_mouseclick(widget, event); + else rtgui_textbox_onmouse(box, (struct rtgui_event_mouse*)event); + return RT_TRUE; + + case RTGUI_EVENT_KBD: + if (widget->on_key != RT_NULL) widget->on_key(widget, event); + else rtgui_textbox_onkey(box, (struct rtgui_event_kbd*)event); + return RT_TRUE; + } + + return RT_FALSE; +} + +struct rtgui_textbox* rtgui_textbox_create(const char* text) +{ + struct rtgui_textbox* box; + + box = (struct rtgui_textbox*) rtgui_widget_create (RTGUI_TEXTBOX_TYPE); + if (box != RT_NULL) + { + rtgui_rect_t rect = {0, 0, RTGUI_TEXTBOX_DEFAULT_WIDTH, RTGUI_TEXTBOX_DEFAULT_HEIGHT}; + + /* allocate default line buffer */ + rtgui_textbox_set_value(box, text); + + rtgui_font_get_metrics(RTGUI_WIDGET(box)->gc.font, "h", &rect); + box->font_width = rtgui_rect_width(rect); + } + + return box; +} + +void rtgui_textbox_destroy(struct rtgui_textbox* box) +{ + rtgui_widget_destroy(RTGUI_WIDGET(box)); +} + +void rtgui_textbox_set_value(struct rtgui_textbox* box, const char* text) +{ + if (box->text != RT_NULL) + { + if (box->line_length > rt_strlen(text) + 1) + { + rt_memcpy(box->text, text, rt_strlen(text) + 1); + return; + } + else + { + /* free the old text */ + rtgui_free(box->text); + box->text = RT_NULL; + } + } + + box->line_length = RTGUI_TEXTBOX_LINE_MAX > rt_strlen(text) + 1 ? + RTGUI_TEXTBOX_LINE_MAX : rt_strlen(text) + 1; + + /* allocate line buffer */ + box->text = rtgui_malloc(box->line_length); + rt_memset(box->text, 0, box->line_length); + + /* copy text */ + rt_memcpy(box->text, text, rt_strlen(text) + 1); + + /* set current position */ + box->position = 0; +} + +const char* rtgui_textbox_get_value(struct rtgui_textbox* box) +{ + return (const char*)box->text; +} + +void rtgui_widget_set_line_length(struct rtgui_textbox* box, rt_size_t length) +{ + rt_uint8_t* new_line; + + RT_ASSERT(box != RT_NULL); + + /* invalid length */ + if (length <= 0) return; + + new_line = rtgui_malloc(length); + if (length < box->line_length) + { + rt_memcpy(new_line, box->text, length - 1); + new_line[length] = '\0'; + } + else + { + rt_memcpy(new_line, (const char*)box->text, rt_strlen((const char*)box->text)); + } + + /* set line length */ + box->line_length = length; +} diff --git a/rtgui/widgets/title.c b/rtgui/widgets/title.c index 41b8924cb..2a38c703a 100644 --- a/rtgui/widgets/title.c +++ b/rtgui/widgets/title.c @@ -1,81 +1,81 @@ -/* - * File : title.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-16 Bernard first version - */ -#include -#include - -/* there is no event handler in wintitle but handle the event on topwin of server */ -static void _rtgui_wintitle_constructor(rtgui_wintitle_t* wintitle) -{ - wintitle->title = RT_NULL; - RTGUI_WIDGET(wintitle)->flag = RTGUI_WIDGET_FLAG_DEFAULT; -} - -static void _rtgui_wintitle_deconstructor(rtgui_wintitle_t* wintitle) -{ - rt_free(wintitle->title); - wintitle->title = RT_NULL; -} - -rtgui_type_t* rtgui_wintitle_type_get() -{ - static rtgui_type_t *wintitle_type = RT_NULL; - - if (!wintitle_type) - { - wintitle_type = rtgui_type_create("wintitle", RTGUI_TOPLEVEL_TYPE, - sizeof(rtgui_wintitle_t), - RTGUI_CONSTRUCTOR(_rtgui_wintitle_constructor), - RTGUI_DESTRUCTOR(_rtgui_wintitle_deconstructor)); - } - - return wintitle_type; -} - -rtgui_wintitle_t* rtgui_wintitle_create(const rt_uint8_t* title) -{ - rtgui_wintitle_t* wintitle; - - wintitle = (rtgui_wintitle_t*)rtgui_widget_create(RTGUI_WINTITLE_TYPE); - if (wintitle != RT_NULL) - { - rtgui_wintitle_set_title(wintitle, title); - } - - return wintitle; -} - -void rtgui_wintitle_destroy(rtgui_wintitle_t* wintitle) -{ - rtgui_widget_destroy(RTGUI_WIDGET(wintitle)); -} - -void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const rt_uint8_t* title) -{ - RT_ASSERT(wintitle != RT_NULL); - - if (wintitle->title != RT_NULL) - { - rtgui_free(wintitle->title); - } - - if (title != RT_NULL) wintitle->title = (unsigned char*)rt_strdup((const char*)title); - else wintitle->title = RT_NULL; -} - -rt_uint8_t *rtgui_wintitle_get_title(rtgui_wintitle_t* wintitle) -{ - RT_ASSERT(wintitle != RT_NULL); - - return wintitle->title; -} +/* + * File : title.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-16 Bernard first version + */ +#include +#include + +/* there is no event handler in wintitle but handle the event on topwin of server */ +static void _rtgui_wintitle_constructor(rtgui_wintitle_t* wintitle) +{ + wintitle->title = RT_NULL; + RTGUI_WIDGET(wintitle)->flag = RTGUI_WIDGET_FLAG_DEFAULT; +} + +static void _rtgui_wintitle_deconstructor(rtgui_wintitle_t* wintitle) +{ + rt_free(wintitle->title); + wintitle->title = RT_NULL; +} + +rtgui_type_t* rtgui_wintitle_type_get() +{ + static rtgui_type_t *wintitle_type = RT_NULL; + + if (!wintitle_type) + { + wintitle_type = rtgui_type_create("wintitle", RTGUI_TOPLEVEL_TYPE, + sizeof(rtgui_wintitle_t), + RTGUI_CONSTRUCTOR(_rtgui_wintitle_constructor), + RTGUI_DESTRUCTOR(_rtgui_wintitle_deconstructor)); + } + + return wintitle_type; +} + +rtgui_wintitle_t* rtgui_wintitle_create(const rt_uint8_t* title) +{ + rtgui_wintitle_t* wintitle; + + wintitle = (rtgui_wintitle_t*)rtgui_widget_create(RTGUI_WINTITLE_TYPE); + if (wintitle != RT_NULL) + { + rtgui_wintitle_set_title(wintitle, title); + } + + return wintitle; +} + +void rtgui_wintitle_destroy(rtgui_wintitle_t* wintitle) +{ + rtgui_widget_destroy(RTGUI_WIDGET(wintitle)); +} + +void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const rt_uint8_t* title) +{ + RT_ASSERT(wintitle != RT_NULL); + + if (wintitle->title != RT_NULL) + { + rtgui_free(wintitle->title); + } + + if (title != RT_NULL) wintitle->title = (unsigned char*)rt_strdup((const char*)title); + else wintitle->title = RT_NULL; +} + +rt_uint8_t *rtgui_wintitle_get_title(rtgui_wintitle_t* wintitle) +{ + RT_ASSERT(wintitle != RT_NULL); + + return wintitle->title; +} diff --git a/rtgui/widgets/toplevel.c b/rtgui/widgets/toplevel.c index b2089449f..1c7da7851 100644 --- a/rtgui/widgets/toplevel.c +++ b/rtgui/widgets/toplevel.c @@ -1,194 +1,178 @@ -/* - * File : toplevel.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-16 Bernard first version - */ -#include -#include - -static void _rtgui_toplevel_constructor(rtgui_toplevel_t *toplevel) -{ - /* set event handler */ - rtgui_widget_set_event_handler(RTGUI_WIDGET(toplevel), rtgui_toplevel_event_handler); - - /* set toplevel to self */ - RTGUI_WIDGET(toplevel)->toplevel = RTGUI_WIDGET(toplevel); - - /* init toplevel property */ - toplevel->drawing = 0; - toplevel->external_clip_rect = RT_NULL; - toplevel->external_clip_size = 0; - toplevel->focus = RT_NULL; - - /* hide toplevel default */ - RTGUI_WIDGET_HIDE(RTGUI_WIDGET(toplevel)); - - /* set server as RT_NULL (no connected) */ - toplevel->server = RT_NULL; -} - -static void _rtgui_toplevel_destructor(rtgui_toplevel_t* toplevel) -{ - /* release external clip info */ - rtgui_free(toplevel->external_clip_rect); - - toplevel->drawing = 0; - rtgui_free(toplevel->external_clip_rect); - toplevel->external_clip_rect = RT_NULL; - toplevel->external_clip_size = 0; - toplevel->focus = RT_NULL; -} - -rtgui_type_t *rtgui_toplevel_type_get(void) -{ - static rtgui_type_t *toplevel_type = RT_NULL; - - if (!toplevel_type) - { - toplevel_type = rtgui_type_create("toplevel", RTGUI_CONTAINER_TYPE, - sizeof(rtgui_toplevel_t), - RTGUI_CONSTRUCTOR(_rtgui_toplevel_constructor), - RTGUI_DESTRUCTOR(_rtgui_toplevel_destructor)); - } - - return toplevel_type; -} - -rt_bool_t rtgui_toplevel_event_handler(rtgui_widget_t* widget, rtgui_event_t* event) -{ - rtgui_toplevel_t* toplevel = (rtgui_toplevel_t*)widget; - - switch (event->type) - { - case RTGUI_EVENT_KBD: - if (toplevel->focus != RT_NULL) - { - toplevel->focus->event_handler(toplevel->focus, event); - } - break; - - case RTGUI_EVENT_CLIP_INFO: - /* set toplevel external clip info */ - rtgui_toplevel_handle_clip(toplevel, (struct rtgui_event_clip_info*)event); - - /* update toplevel clip */ - rtgui_toplevel_update_clip(toplevel); - break; - - case RTGUI_EVENT_TIMER: - { - struct rtgui_timer* timer; - struct rtgui_event_timer* etimer = (struct rtgui_event_timer*) event; - - timer = etimer->timer; - if (timer->timeout != RT_NULL) - { - /* call timeout function */ - timer->timeout(timer, timer->user_data); - } - } - break; - - case RTGUI_EVENT_COMMAND: - if (rtgui_container_dispatch_event(RTGUI_CONTAINER(widget), event) != RT_TRUE) - { - if (widget->on_command != RT_NULL) - { - widget->on_command(widget, event); - } - } - break; - - default : - return rtgui_container_event_handler(widget, event); - } - - return RT_FALSE; -} - -void rtgui_toplevel_handle_clip(struct rtgui_toplevel* top, - struct rtgui_event_clip_info* info) -{ - RT_ASSERT(top != RT_NULL); - RT_ASSERT(info != RT_NULL); - - /* release old rect array */ - if (top->external_clip_size != 0) - { - rtgui_free(top->external_clip_rect); - top->external_clip_rect = RT_NULL; - top->external_clip_size = 0; - } - - /* no rect info */ - if (info->num_rect == 0) return; - - top->external_clip_rect = (rtgui_rect_t*) rtgui_malloc(sizeof(rtgui_rect_t) * - info->num_rect); - top->external_clip_size = info->num_rect; - - /* copy rect array */ - rt_memcpy(top->external_clip_rect, info->rects, sizeof(rtgui_rect_t) * info->num_rect); -} - -#include /* to get screen rect */ - -void rtgui_toplevel_update_clip(rtgui_toplevel_t* top) -{ - rt_uint32_t idx; - rtgui_container_t* container; - struct rtgui_list_node* node; - rtgui_rect_t screen_rect; - - if (top == RT_NULL) return; - - /* reset toplevel widget clip to extent */ - rtgui_region_reset(&(RTGUI_WIDGET(top)->clip), &(RTGUI_WIDGET(top)->extent)); - RTGUI_WIDGET(top)->clip_sync ++; - - /* subtract the screen rect */ - screen_rect.x1 = screen_rect.y1 = 0; - screen_rect.x2 = rtgui_graphic_driver_get_default()->width; - screen_rect.y2 = rtgui_graphic_driver_get_default()->height; - rtgui_region_intersect_rect(&(RTGUI_WIDGET(top)->clip), &(RTGUI_WIDGET(top)->clip), - &screen_rect); - - /* subtract the external rect */ - for (idx = 0; idx < top->external_clip_size; idx ++) - { - rtgui_region_subtract_rect(&(RTGUI_WIDGET(top)->clip), &(RTGUI_WIDGET(top)->clip), - &(top->external_clip_rect[idx])); - } - - /* update the clip info of each child */ - container = RTGUI_CONTAINER(top); - rtgui_list_foreach(node, &(container->children)) - { - rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling); - - rtgui_widget_update_clip(child); - } -} - -void rtgui_toplevel_set_focus(struct rtgui_toplevel* top, rtgui_widget_t* focus) -{ - RT_ASSERT(top != RT_NULL); - - top->focus = focus; -} - -rtgui_widget_t* rtgui_toplevel_get_focus(struct rtgui_toplevel* top) -{ - RT_ASSERT(top != RT_NULL); - - return top->focus; -} - +/* + * File : toplevel.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-16 Bernard first version + */ +#include +#include + +static void _rtgui_toplevel_constructor(rtgui_toplevel_t *toplevel) +{ + /* set event handler */ + rtgui_widget_set_event_handler(RTGUI_WIDGET(toplevel), rtgui_toplevel_event_handler); + + /* set toplevel to self */ + RTGUI_WIDGET(toplevel)->toplevel = RTGUI_WIDGET(toplevel); + + /* init toplevel property */ + toplevel->drawing = 0; + toplevel->external_clip_rect = RT_NULL; + toplevel->external_clip_size = 0; + + /* hide toplevel default */ + RTGUI_WIDGET_HIDE(RTGUI_WIDGET(toplevel)); + + /* set server as RT_NULL (no connected) */ + toplevel->server = RT_NULL; +} + +static void _rtgui_toplevel_destructor(rtgui_toplevel_t* toplevel) +{ + /* release external clip info */ + rtgui_free(toplevel->external_clip_rect); + + toplevel->drawing = 0; + rtgui_free(toplevel->external_clip_rect); + toplevel->external_clip_rect = RT_NULL; + toplevel->external_clip_size = 0; +} + +rtgui_type_t *rtgui_toplevel_type_get(void) +{ + static rtgui_type_t *toplevel_type = RT_NULL; + + if (!toplevel_type) + { + toplevel_type = rtgui_type_create("toplevel", RTGUI_CONTAINER_TYPE, + sizeof(rtgui_toplevel_t), + RTGUI_CONSTRUCTOR(_rtgui_toplevel_constructor), + RTGUI_DESTRUCTOR(_rtgui_toplevel_destructor)); + } + + return toplevel_type; +} + +rt_bool_t rtgui_toplevel_event_handler(rtgui_widget_t* widget, rtgui_event_t* event) +{ + rtgui_toplevel_t* toplevel = (rtgui_toplevel_t*)widget; + + switch (event->type) + { + case RTGUI_EVENT_KBD: + if (RTGUI_CONTAINER(toplevel)->focused != RT_NULL) + { + RTGUI_CONTAINER(toplevel)->focused->event_handler(RTGUI_CONTAINER(toplevel)->focused, event); + } + break; + + case RTGUI_EVENT_CLIP_INFO: + /* set toplevel external clip info */ + rtgui_toplevel_handle_clip(toplevel, (struct rtgui_event_clip_info*)event); + + /* update toplevel clip */ + rtgui_toplevel_update_clip(toplevel); + break; + + case RTGUI_EVENT_TIMER: + { + struct rtgui_timer* timer; + struct rtgui_event_timer* etimer = (struct rtgui_event_timer*) event; + + timer = etimer->timer; + if (timer->timeout != RT_NULL) + { + /* call timeout function */ + timer->timeout(timer, timer->user_data); + } + } + break; + + case RTGUI_EVENT_COMMAND: + if (rtgui_container_dispatch_event(RTGUI_CONTAINER(widget), event) != RT_TRUE) + { + if (widget->on_command != RT_NULL) + { + widget->on_command(widget, event); + } + } + else return RT_TRUE; + break; + + default : + return rtgui_container_event_handler(widget, event); + } + + return RT_FALSE; +} + +void rtgui_toplevel_handle_clip(struct rtgui_toplevel* top, + struct rtgui_event_clip_info* info) +{ + RT_ASSERT(top != RT_NULL); + RT_ASSERT(info != RT_NULL); + + /* release old rect array */ + if (top->external_clip_size != 0) + { + rtgui_free(top->external_clip_rect); + top->external_clip_rect = RT_NULL; + top->external_clip_size = 0; + } + + /* no rect info */ + if (info->num_rect == 0) return; + + top->external_clip_rect = (rtgui_rect_t*) rtgui_malloc(sizeof(rtgui_rect_t) * + info->num_rect); + top->external_clip_size = info->num_rect; + + /* copy rect array */ + rt_memcpy(top->external_clip_rect, (void*)(info + 1), sizeof(rtgui_rect_t) * info->num_rect); +} + +#include /* to get screen rect */ + +void rtgui_toplevel_update_clip(rtgui_toplevel_t* top) +{ + rt_uint32_t idx; + rtgui_container_t* container; + struct rtgui_list_node* node; + rtgui_rect_t screen_rect; + + if (top == RT_NULL) return; + + /* reset toplevel widget clip to extent */ + rtgui_region_reset(&(RTGUI_WIDGET(top)->clip), &(RTGUI_WIDGET(top)->extent)); + RTGUI_WIDGET(top)->clip_sync ++; + + /* subtract the screen rect */ + screen_rect.x1 = screen_rect.y1 = 0; + screen_rect.x2 = rtgui_graphic_driver_get_default()->width; + screen_rect.y2 = rtgui_graphic_driver_get_default()->height; + rtgui_region_intersect_rect(&(RTGUI_WIDGET(top)->clip), &(RTGUI_WIDGET(top)->clip), + &screen_rect); + + /* subtract the external rect */ + for (idx = 0; idx < top->external_clip_size; idx ++) + { + rtgui_region_subtract_rect(&(RTGUI_WIDGET(top)->clip), &(RTGUI_WIDGET(top)->clip), + &(top->external_clip_rect[idx])); + } + + /* update the clip info of each child */ + container = RTGUI_CONTAINER(top); + rtgui_list_foreach(node, &(container->children)) + { + rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling); + + rtgui_widget_update_clip(child); + } +} diff --git a/rtgui/widgets/view.c b/rtgui/widgets/view.c index 41b433c7a..59e1b3043 100644 --- a/rtgui/widgets/view.c +++ b/rtgui/widgets/view.c @@ -1,162 +1,191 @@ -/* - * File : view.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-16 Bernard first version - */ -#include -#include -#include -#include - -static void _rtgui_view_constructor(rtgui_view_t *view) -{ - /* init view */ - rtgui_widget_set_event_handler(RTGUI_WIDGET(view), - rtgui_view_event_handler); - - view->title = RT_NULL; -} - -static void _rtgui_view_destructor(rtgui_view_t *view) -{ - if (view->title != RT_NULL) - { - rt_free(view->title); - view->title = RT_NULL; - } -} - -rtgui_type_t *rtgui_view_type_get(void) -{ - static rtgui_type_t *view_type = RT_NULL; - - if (!view_type) - { - view_type = rtgui_type_create("view", RTGUI_CONTAINER_TYPE, - sizeof(rtgui_view_t), - RTGUI_CONSTRUCTOR(_rtgui_view_constructor), - RTGUI_DESTRUCTOR(_rtgui_view_destructor)); - } - - return view_type; -} - -rt_bool_t rtgui_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) -{ - struct rtgui_view* view = (struct rtgui_view*) widget; - RT_ASSERT(widget != RT_NULL); - - switch (event->type) - { - case RTGUI_EVENT_PAINT: - if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); - else - { - struct rtgui_dc* dc; - struct rtgui_rect rect; - - dc = rtgui_dc_begin_drawing(widget); - if (dc == RT_NULL) return RT_FALSE; - rtgui_widget_get_rect(widget, &rect); - - /* fill view with background */ - rtgui_dc_fill_rect(dc, &rect); - - /* paint on each child */ - rtgui_container_dispatch_event(RTGUI_CONTAINER(view), event); - - rtgui_dc_end_drawing(dc); - } - break; - - default: - return rtgui_container_event_handler(widget, event); - } - - return RT_FALSE; -} - -rtgui_view_t* rtgui_view_create(const char* title) -{ - struct rtgui_view* view; - - /* allocate view */ - view = (struct rtgui_view*) rtgui_widget_create (RTGUI_VIEW_TYPE); - if (view != RT_NULL) - { - if (title != RT_NULL) - view->title = rt_strdup(title); - } - - return view; -} - -void rtgui_view_destroy(rtgui_view_t* view) -{ - rtgui_widget_destroy(RTGUI_WIDGET(view)); -} - -void rtgui_view_set_box(rtgui_view_t* view, rtgui_box_t* box) -{ - if (view == RT_NULL || - box == RT_NULL) return; - - rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(box)); - rtgui_widget_set_rect(RTGUI_WIDGET(box), &(RTGUI_WIDGET(view)->extent)); -} - -void rtgui_view_show(rtgui_view_t* view) -{ - if (view == RT_NULL) return; - - if (RTGUI_WIDGET(view)->parent == RT_NULL) - { - RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(view)); - return; - } - - rtgui_workbench_show_view((rtgui_workbench_t*)(RTGUI_WIDGET(view)->parent), view); - if (RTGUI_WIDGET_IS_FOCUSABLE(RTGUI_WIDGET(view))) - rtgui_widget_focus(RTGUI_WIDGET(view)); -} - -void rtgui_view_hide(rtgui_view_t* view) -{ - if (view == RT_NULL) return; - - if (RTGUI_WIDGET(view)->parent == RT_NULL) - { - RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view)); - return; - } - - rtgui_workbench_hide_view((rtgui_workbench_t*)(RTGUI_WIDGET(view)->parent), view); -} - -char* rtgui_view_get_title(rtgui_view_t* view) -{ - RT_ASSERT(view != RT_NULL); - - return view->title; -} - -void rtgui_view_set_title(rtgui_view_t* view, const char *title) -{ - RT_ASSERT(view != RT_NULL); - - if (view->title != RT_NULL) - { - rtgui_free(view->title); - - if (title != RT_NULL) view->title = rt_strdup(title); - else view->title = RT_NULL; - } -} +/* + * File : view.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-16 Bernard first version + */ +#include +#include +#include +#include + +static void _rtgui_view_constructor(rtgui_view_t *view) +{ + /* init view */ + rtgui_widget_set_event_handler(RTGUI_WIDGET(view), + rtgui_view_event_handler); + + view->title = RT_NULL; +} + +static void _rtgui_view_destructor(rtgui_view_t *view) +{ + if (view->title != RT_NULL) + { + rt_free(view->title); + view->title = RT_NULL; + } +} + +rtgui_type_t *rtgui_view_type_get(void) +{ + static rtgui_type_t *view_type = RT_NULL; + + if (!view_type) + { + view_type = rtgui_type_create("view", RTGUI_CONTAINER_TYPE, + sizeof(rtgui_view_t), + RTGUI_CONSTRUCTOR(_rtgui_view_constructor), + RTGUI_DESTRUCTOR(_rtgui_view_destructor)); + } + + return view_type; +} + +rt_bool_t rtgui_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) +{ + struct rtgui_view* view = (struct rtgui_view*) widget; + RT_ASSERT(widget != RT_NULL); + + switch (event->type) + { + case RTGUI_EVENT_PAINT: + if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); + else + { + struct rtgui_dc* dc; + struct rtgui_rect rect; + + dc = rtgui_dc_begin_drawing(widget); + if (dc == RT_NULL) return RT_FALSE; + rtgui_widget_get_rect(widget, &rect); + + /* fill view with background */ + rtgui_dc_fill_rect(dc, &rect); + + /* paint on each child */ + rtgui_container_dispatch_event(RTGUI_CONTAINER(view), event); + + rtgui_dc_end_drawing(dc); + } + break; + + default: + return rtgui_container_event_handler(widget, event); + } + + return RT_FALSE; +} + +rtgui_view_t* rtgui_view_create(const char* title) +{ + struct rtgui_view* view; + + /* allocate view */ + view = (struct rtgui_view*) rtgui_widget_create (RTGUI_VIEW_TYPE); + if (view != RT_NULL) + { + if (title != RT_NULL) + view->title = rt_strdup(title); + } + + return view; +} + +void rtgui_view_destroy(rtgui_view_t* view) +{ + rtgui_widget_destroy(RTGUI_WIDGET(view)); +} + +void rtgui_view_set_box(rtgui_view_t* view, rtgui_box_t* box) +{ + if (view == RT_NULL || + box == RT_NULL) return; + + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(box)); + rtgui_widget_set_rect(RTGUI_WIDGET(box), &(RTGUI_WIDGET(view)->extent)); +} + +rtgui_modal_code_t rtgui_view_show(rtgui_view_t* view, rt_bool_t is_modal) +{ + rtgui_workbench_t* workbench; + + /* parameter check */ + if (view == RT_NULL) return RTGUI_MODAL_CANCEL; + + if (RTGUI_WIDGET(view)->parent == RT_NULL) + { + RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(view)); + return RTGUI_MODAL_CANCEL; + } + + workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent); + rtgui_workbench_show_view(workbench, view); + if (RTGUI_WIDGET_IS_FOCUSABLE(RTGUI_WIDGET(view))) + rtgui_widget_focus(RTGUI_WIDGET(view)); + + if (is_modal == RT_TRUE) + { + /* set modal mode */ + workbench->flag |= RTGUI_WORKBENCH_FLAG_MODAL_MODE; + + /* perform workbench event loop */ + rtgui_workbench_event_loop(workbench); + return workbench->modal_code; + } + + /* no modal mode, always return modal_ok */ + return RTGUI_MODAL_OK; +} + +void rtgui_view_end_modal(rtgui_view_t* view, rtgui_modal_code_t modal_code) +{ + rtgui_workbench_t* workbench; + + /* parameter check */ + if ((view == RT_NULL) || (RTGUI_WIDGET(view)->parent == RT_NULL))return ; + + workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent); + workbench->modal_code = modal_code; + workbench->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE; +} + +void rtgui_view_hide(rtgui_view_t* view) +{ + if (view == RT_NULL) return; + + if (RTGUI_WIDGET(view)->parent == RT_NULL) + { + RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view)); + return; + } + + rtgui_workbench_hide_view((rtgui_workbench_t*)(RTGUI_WIDGET(view)->parent), view); +} + +char* rtgui_view_get_title(rtgui_view_t* view) +{ + RT_ASSERT(view != RT_NULL); + + return view->title; +} + +void rtgui_view_set_title(rtgui_view_t* view, const char *title) +{ + RT_ASSERT(view != RT_NULL); + + if (view->title != RT_NULL) + { + rtgui_free(view->title); + + if (title != RT_NULL) view->title = rt_strdup(title); + else view->title = RT_NULL; + } +} diff --git a/rtgui/widgets/widget.c b/rtgui/widgets/widget.c index 4363baf1c..f3c876b29 100644 --- a/rtgui/widgets/widget.c +++ b/rtgui/widgets/widget.c @@ -103,10 +103,10 @@ void rtgui_widget_set_rect(rtgui_widget_t* widget, rtgui_rect_t* rect) { if (widget == RT_NULL || rect == RT_NULL) return; - widget->extent = *rect; - - /* reset mini width and height */ - widget->mini_width = rtgui_rect_width(widget->extent); + widget->extent = *rect; + + /* reset mini width and height */ + widget->mini_width = rtgui_rect_width(widget->extent); widget->mini_height = rtgui_rect_height(widget->extent); /* it's not empty, fini it */ @@ -226,30 +226,45 @@ void rtgui_widget_set_oncommand(rtgui_widget_t* widget, rtgui_event_handler_ptr } /** - * @brief Focuses the widget. The focused widget is the one which receives the keyboard events + * @brief Focuses the widget. The focused widget is the widget which can receive the keyboard events * @param widget a widget * @note The widget has to be attached to a toplevel widget, otherwise it will have no effect */ void rtgui_widget_focus(rtgui_widget_t *widget) { - rtgui_widget_t *focused; + rtgui_widget_t *focused; + rtgui_container_t *parent; - if (!widget || !widget->toplevel || !RTGUI_WIDGET_IS_FOCUSABLE(widget) || !RTGUI_WIDGET_IS_ENABLE(widget)) + RT_ASSERT(widget != RT_NULL); + + if (!widget->parent || !RTGUI_WIDGET_IS_FOCUSABLE(widget) || !RTGUI_WIDGET_IS_ENABLE(widget)) return; - focused = rtgui_toplevel_get_focus(RTGUI_TOPLEVEL(widget->toplevel)); - - if ( focused != RT_NULL && widget == focused) - return; - - if (focused != RT_NULL) - { - rtgui_widget_unfocus(focused); - } - - rtgui_toplevel_set_focus(RTGUI_TOPLEVEL(widget->toplevel), widget); + /* set widget as focused */ widget->flag |= RTGUI_WIDGET_FLAG_FOCUS; + /* get parent container */ + parent = RTGUI_CONTAINER(widget->parent); + + /* get old focused widget */ + focused = parent->focused; + if (focused == widget) return ; /* it's the same focused widget */ + + if (focused != RT_NULL) + rtgui_widget_unfocus(focused); + + /* set widget as focused widget in parent link */ + parent->focused = widget; + while (RTGUI_WIDGET(parent)->parent != RT_NULL) + { + parent = RTGUI_CONTAINER(RTGUI_WIDGET(parent)->parent); + parent->focused = widget; + + /* if the parent is hide, break it */ + if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(parent))) break; + } + + /* invoke on focus in call back */ if (widget->on_focus_in) widget->on_focus_in(widget, RT_NULL); } @@ -260,16 +275,13 @@ void rtgui_widget_focus(rtgui_widget_t *widget) */ void rtgui_widget_unfocus(rtgui_widget_t *widget) { - if (!widget || !widget->toplevel || !RTGUI_WIDGET_IS_FOCUS(widget)) - return; - - if (rtgui_toplevel_get_focus(RTGUI_TOPLEVEL(widget->toplevel)) == widget) - { - rtgui_toplevel_set_focus(RTGUI_TOPLEVEL(widget->toplevel), RT_NULL); - } + RT_ASSERT(widget != RT_NULL); widget->flag &= ~RTGUI_WIDGET_FLAG_FOCUS; + if (!widget->toplevel || !RTGUI_WIDGET_IS_FOCUS(widget)) + return; + if (widget->on_focus_out) widget->on_focus_out(widget, RT_NULL); } @@ -477,7 +489,7 @@ rtgui_widget_t* rtgui_widget_get_next_sibling(rtgui_widget_t* widget) rtgui_widget_t* rtgui_widget_get_prev_sibling(rtgui_widget_t* widget) { struct rtgui_list_node* node; - rtgui_widget_t *sibling, *parent; + rtgui_widget_t *sibling, *parent; node = RT_NULL; sibling = RT_NULL; parent = widget->parent; @@ -494,4 +506,4 @@ rtgui_widget_t* rtgui_widget_get_prev_sibling(rtgui_widget_t* widget) sibling = rtgui_list_entry(node, rtgui_widget_t, sibling); return sibling; -} +} diff --git a/rtgui/widgets/window.c b/rtgui/widgets/window.c index 01d4bd605..ae0c708b3 100644 --- a/rtgui/widgets/window.c +++ b/rtgui/widgets/window.c @@ -1,476 +1,552 @@ -/* - * File : window.c - * This file is part of RTGUI in RT-Thread RTOS - * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-10-04 Bernard first version - */ -#include -#include -#include -#include +/* + * File : window.c + * This file is part of RTGUI in RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2009-10-04 Bernard first version + */ +#include +#include +#include +#include -#include -#include - -static void _rtgui_win_constructor(rtgui_win_t *win) -{ - /* init window attribute */ - win->on_activate = RT_NULL; - win->on_deactivate = RT_NULL; - win->on_close = RT_NULL; - win->title = RT_NULL; - - /* set window hide */ - RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win)); - - /* set window style */ - win->style = RTGUI_WIN_STYLE_DEFAULT; - rtgui_widget_set_event_handler(RTGUI_WIDGET(win), rtgui_win_event_handler); - - /* init user data */ - win->user_data = 0; -} - -static void _rtgui_win_destructor(rtgui_win_t* win) -{ - struct rtgui_event_win_destroy edestroy; - - if (RTGUI_TOPLEVEL(win)->server != RT_NULL) - { - /* destroy in server */ - RTGUI_EVENT_WIN_DESTROY_INIT(&edestroy); - edestroy.wid = win; - if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&edestroy), - sizeof(struct rtgui_event_win_destroy)) != RT_EOK) - { - /* destroy in server failed */ - return; - } - } - - /* release field */ - rt_free(win->title); -} - -static rt_bool_t _rtgui_win_create_in_server(rtgui_win_t* win) -{ - if (RTGUI_TOPLEVEL(win)->server == RT_NULL) - { - rt_thread_t server; - struct rtgui_event_win_create ecreate; - RTGUI_EVENT_WIN_CREATE_INIT(&ecreate); - - /* get server thread id */ - server = rtgui_thread_get_server(); - if (server == RT_NULL) - { - rt_kprintf("RTGUI server is not running...\n"); - return RT_FALSE; - } - - /* send win create event to server */ - ecreate.wid = win; - ecreate.extent = RTGUI_WIDGET(win)->extent; - ecreate.flag = win->style; - ecreate.mask = 0; - rt_strncpy((char*)ecreate.title, (char*)win->title, RTGUI_NAME_MAX); - - if (rtgui_thread_send_sync(server, RTGUI_EVENT(&ecreate), - sizeof(struct rtgui_event_win_create)) != RT_EOK) - { - rt_kprintf("create win: %s failed\n", win->title); - return RT_FALSE; - } - - /* set server */ - RTGUI_TOPLEVEL(win)->server = server; - } - - return RT_TRUE; -} - -rtgui_type_t *rtgui_win_type_get(void) -{ - static rtgui_type_t *win_type = RT_NULL; - - if (!win_type) - { - win_type = rtgui_type_create("win", RTGUI_TOPLEVEL_TYPE, - sizeof(rtgui_win_t), - RTGUI_CONSTRUCTOR(_rtgui_win_constructor), - RTGUI_DESTRUCTOR(_rtgui_win_destructor)); - } - - return win_type; -} - -rtgui_win_t* rtgui_win_create(rtgui_toplevel_t* parent_toplevel, const char* title, rtgui_rect_t *rect, rt_uint32_t style) -{ - struct rtgui_win* win; - - /* allocate win memory */ - win = (struct rtgui_win*) rtgui_widget_create (RTGUI_WIN_TYPE); - if (win != RT_NULL) - { - /* set parent toplevel */ - win->parent_toplevel = parent_toplevel; - - /* set title, rect and style */ - if (title != RT_NULL) win->title = rt_strdup(title); - else win->title = RT_NULL; - - rtgui_widget_set_rect(RTGUI_WIDGET(win), rect); - win->style = style; - - if (_rtgui_win_create_in_server(win) == RT_FALSE) - { - rtgui_widget_destroy(RTGUI_WIDGET(win)); - return RT_NULL; - } - } - - return win; -} - -void rtgui_win_destroy(struct rtgui_win* win) -{ - if (win->parent_toplevel == RT_NULL) - { - rtgui_thread_t *rtgui_tid; - - rtgui_tid = (rtgui_thread_t*) rt_thread_self()->user_data; - rtgui_tid->is_quit = RT_TRUE; - } - - rtgui_widget_destroy(RTGUI_WIDGET(win)); -} - -void rtgui_win_show(struct rtgui_win* win) -{ - RT_ASSERT(win != RT_NULL); - - /* if it does not register into server, create it in server */ - if (RTGUI_TOPLEVEL(win)->server == RT_NULL) - { - if (_rtgui_win_create_in_server(win) == RT_FALSE) - return; - } - - if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win))) - { - /* send show message to server */ - struct rtgui_event_win_show eshow; - RTGUI_EVENT_WIN_SHOW_INIT(&eshow); - eshow.wid = win; - - if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&eshow), - sizeof(struct rtgui_event_win_show)) != RT_EOK) - { - /* hide window failed */ - return; - } - - /* set window unhidden */ - RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win)); - } - else rtgui_widget_update(RTGUI_WIDGET(win)); -} - -void rtgui_win_hiden(struct rtgui_win* win) -{ - RT_ASSERT(win != RT_NULL); - - if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)) && - RTGUI_TOPLEVEL(win)->server != RT_NULL) - { - /* send hidden message to server */ - struct rtgui_event_win_hide ehide; - RTGUI_EVENT_WIN_HIDE_INIT(&ehide); - ehide.wid = win; - - if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&ehide), - sizeof(struct rtgui_event_win_hide)) != RT_EOK) - { - rt_kprintf("hide win: %s failed\n", win->title); - return; - } - - /* set window hide and deactivated */ - RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win)); - win->style &= ~RTGUI_WIN_STYLE_ACTIVATE; - } -} - -rt_bool_t rtgui_win_is_activated(struct rtgui_win* win) -{ - RT_ASSERT(win != RT_NULL); - - return win->style & RTGUI_WIN_STYLE_ACTIVATE; -} - -void rtgui_win_move(struct rtgui_win* win, int x, int y) -{ - struct rtgui_event_win_move emove; - RTGUI_EVENT_WIN_MOVE_INIT(&emove); - - if (win == RT_NULL) return; - - if (RTGUI_TOPLEVEL(win)->server != RT_NULL) - { - /* set win hide firstly */ - RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win)); - - emove.wid = win; - emove.x = x; - emove.y = y; - if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&emove), - sizeof(struct rtgui_event_win_move)) != RT_EOK) - { - return; - } - } - - /* move window to logic position */ - rtgui_widget_move_to_logic(RTGUI_WIDGET(win), - x - RTGUI_WIDGET(win)->extent.x1, - y - RTGUI_WIDGET(win)->extent.y1); - - /* set window visible */ - RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win)); - - /* update window */ - // rtgui_widget_update(RTGUI_WIDGET(win)); - return; -} - -static rt_bool_t rtgui_win_ondraw(struct rtgui_win* win) -{ - struct rtgui_dc* dc; - struct rtgui_rect rect; - struct rtgui_event_paint event; - - /* begin drawing */ - dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(win)); - if (dc == RT_NULL) return RT_FALSE; - - /* get window rect */ - rtgui_widget_get_rect(RTGUI_WIDGET(win), &rect); - /* fill area */ - rtgui_dc_fill_rect(dc, &rect); - - /* paint each widget */ - RTGUI_EVENT_PAINT_INIT(&event); - event.wid = RT_NULL; - rtgui_container_dispatch_event(RTGUI_CONTAINER(win), (rtgui_event_t*)&event); - - rtgui_dc_end_drawing(dc); - - return RT_FALSE; -} - -rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) -{ - struct rtgui_win* win = (struct rtgui_win*)widget; - - RT_ASSERT((win != RT_NULL) && (event != RT_NULL)); - - switch (event->type) - { - case RTGUI_EVENT_WIN_SHOW: - rtgui_win_show(win); - break; - - case RTGUI_EVENT_WIN_HIDE: - rtgui_win_hiden(win); - break; - - case RTGUI_EVENT_WIN_CLOSE: - if (win->on_close != RT_NULL) - { - if (win->on_close(widget, event) == RT_FALSE) return RT_TRUE; - } - - /* destroy window */ - rtgui_win_destroy(win); - - /* exit event loop */ - return RT_TRUE; - - case RTGUI_EVENT_WIN_MOVE: - { - struct rtgui_event_win_move* emove = (struct rtgui_event_win_move*)event; - - /* move window */ - rtgui_win_move(win, emove->x, emove->y); - } - break; - - case RTGUI_EVENT_WIN_ACTIVATE: - if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win))) - { - rt_kprintf("activate window, but window is hide!\n"); - } - - win->style |= RTGUI_WIN_STYLE_ACTIVATE; - if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); - else rtgui_win_ondraw(win); - - if (win->on_activate != RT_NULL) - { - win->on_activate(widget, event); - } - break; - - case RTGUI_EVENT_WIN_DEACTIVATE: - win->style &= ~RTGUI_WIN_STYLE_ACTIVATE; - if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); - else rtgui_win_ondraw(win); - - if (win->on_deactivate != RT_NULL) - { - win->on_deactivate(widget, event); - } - break; - - case RTGUI_EVENT_PAINT: - if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); - else rtgui_win_ondraw(win); - break; - - case RTGUI_EVENT_MOUSE_BUTTON: - if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win), (struct rtgui_event_mouse*)event) == RT_FALSE) - { - if (widget->on_mouseclick != RT_NULL) - { - return widget->on_mouseclick(widget, event); - } - } - break; - - case RTGUI_EVENT_MOUSE_MOTION: -#if 0 - if (rtgui_widget_dispatch_mouse_event(widget, - (struct rtgui_event_mouse*)event) == RT_FALSE) - { - /* handle event in current widget */ - if (widget->on_mousemotion != RT_NULL) - { - return widget->on_mousemotion(widget, event); - } - } - else return RT_TRUE; -#endif - break; - - default: - /* call parent event handler */ - return rtgui_toplevel_event_handler(widget, event); - } - - return RT_FALSE; -} - -/* windows event loop */ -void rtgui_win_event_loop(rtgui_win_t* wnd) -{ - rtgui_thread_t *rtgui_tid; - /* the buffer uses to receive event */ - char event_buf[256]; - - struct rtgui_event* event = (struct rtgui_event*)&event_buf[0]; - rtgui_tid = (rtgui_thread_t*) rt_thread_self()->user_data; - - while (rtgui_tid->is_quit == RT_FALSE) - { - if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK) - { - if (RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event) == RT_TRUE) - rtgui_tid->is_quit = RT_TRUE; - } - } -} - -void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect) -{ - struct rtgui_event_win_resize event; - - if (win == RT_NULL || rect == RT_NULL) return; - - RTGUI_WIDGET(win)->extent = *rect; - - if (RTGUI_TOPLEVEL(win)->server != RT_NULL) - { - /* set window resize event to server */ - RTGUI_EVENT_WIN_RESIZE_INIT(&event); - event.wid = win; - event.rect = *rect; - - rtgui_thread_send(RTGUI_TOPLEVEL(win)->server, &(event.parent), sizeof(struct rtgui_event_win_resize)); - } -} - -void rtgui_win_set_box(rtgui_win_t* win, rtgui_box_t* box) -{ - if (win == RT_NULL || box == RT_NULL) return; - - rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(box)); - rtgui_widget_set_rect(RTGUI_WIDGET(box), &(RTGUI_WIDGET(win)->extent)); -} - -void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler) -{ - if (win != RT_NULL) - { - win->on_activate = handler; - } -} - -void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler) -{ - if (win != RT_NULL) - { - win->on_deactivate = handler; - } -} - -void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler) -{ - if (win != RT_NULL) - { - win->on_close = handler; - } -} - -void rtgui_win_set_title(rtgui_win_t* win, const char *title) -{ - /* send title to server */ - if (RTGUI_TOPLEVEL(win)->server != RT_NULL) - { - } - - /* modify in local side */ - if (win->title != RT_NULL) - { - rtgui_free(win->title); - win->title = RT_NULL; - } - - if (title != RT_NULL) - { - win->title = rt_strdup(title); - } -} - -char* rtgui_win_get_title(rtgui_win_t* win) -{ - RT_ASSERT(win != RT_NULL); - - return win->title; -} +#include +#include +#include + +static void _rtgui_win_constructor(rtgui_win_t *win) +{ + /* init window attribute */ + win->on_activate = RT_NULL; + win->on_deactivate = RT_NULL; + win->on_close = RT_NULL; + win->title = RT_NULL; + + /* set window hide */ + RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win)); + + /* set window style */ + win->style = RTGUI_WIN_STYLE_DEFAULT; + rtgui_widget_set_event_handler(RTGUI_WIDGET(win), rtgui_win_event_handler); + + /* init user data */ + win->user_data = 0; +} + +static void _rtgui_win_destructor(rtgui_win_t* win) +{ + struct rtgui_event_win_destroy edestroy; + + if (RTGUI_TOPLEVEL(win)->server != RT_NULL) + { + /* destroy in server */ + RTGUI_EVENT_WIN_DESTROY_INIT(&edestroy); + edestroy.wid = win; + if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&edestroy), + sizeof(struct rtgui_event_win_destroy)) != RT_EOK) + { + /* destroy in server failed */ + return; + } + } + + /* release field */ + rt_free(win->title); +} + +static rt_bool_t _rtgui_win_create_in_server(rtgui_win_t* win) +{ + if (RTGUI_TOPLEVEL(win)->server == RT_NULL) + { + rt_thread_t server; + struct rtgui_event_win_create ecreate; + RTGUI_EVENT_WIN_CREATE_INIT(&ecreate); + + /* get server thread id */ + server = rtgui_thread_get_server(); + if (server == RT_NULL) + { + rt_kprintf("RTGUI server is not running...\n"); + return RT_FALSE; + } + + /* send win create event to server */ + ecreate.wid = win; + ecreate.extent = RTGUI_WIDGET(win)->extent; + ecreate.flag = win->style; + ecreate.mask = 0; + rt_strncpy((char*)ecreate.title, (char*)win->title, RTGUI_NAME_MAX); + + if (rtgui_thread_send_sync(server, RTGUI_EVENT(&ecreate), + sizeof(struct rtgui_event_win_create)) != RT_EOK) + { + rt_kprintf("create win: %s failed\n", win->title); + return RT_FALSE; + } + + /* set server */ + RTGUI_TOPLEVEL(win)->server = server; + } + + return RT_TRUE; +} + +rtgui_type_t *rtgui_win_type_get(void) +{ + static rtgui_type_t *win_type = RT_NULL; + + if (!win_type) + { + win_type = rtgui_type_create("win", RTGUI_TOPLEVEL_TYPE, + sizeof(rtgui_win_t), + RTGUI_CONSTRUCTOR(_rtgui_win_constructor), + RTGUI_DESTRUCTOR(_rtgui_win_destructor)); + } + + return win_type; +} + +rtgui_win_t* rtgui_win_create(rtgui_toplevel_t* parent_toplevel, const char* title, rtgui_rect_t *rect, rt_uint32_t style) +{ + struct rtgui_win* win; + + /* allocate win memory */ + win = (struct rtgui_win*) rtgui_widget_create (RTGUI_WIN_TYPE); + if (win != RT_NULL) + { + /* set parent toplevel */ + win->parent_toplevel = parent_toplevel; + + /* set title, rect and style */ + if (title != RT_NULL) win->title = rt_strdup(title); + else win->title = RT_NULL; + + rtgui_widget_set_rect(RTGUI_WIDGET(win), rect); + win->style = style; + + if (_rtgui_win_create_in_server(win) == RT_FALSE) + { + rtgui_widget_destroy(RTGUI_WIDGET(win)); + return RT_NULL; + } + } + + return win; +} + +void rtgui_win_destroy(struct rtgui_win* win) +{ + if (win->parent_toplevel != RT_NULL) + { + if (win->style & RTGUI_WIN_STYLE_MODAL) + { + /* exit modal mode */ + win->style &= ~RTGUI_WIN_STYLE_MODAL; + /* set style to closed */ + win->style |= RTGUI_WIN_STYLE_CLOSED; + } + else rtgui_widget_destroy(RTGUI_WIDGET(win)); + + } + else if (win->style & RTGUI_WIN_STYLE_CLOSED) + { + rtgui_widget_destroy(RTGUI_WIDGET(win)); + } + else + { + /* exit modal mode */ + win->style &= ~RTGUI_WIN_STYLE_MODAL; + /* set style to closed */ + win->style |= RTGUI_WIN_STYLE_CLOSED; + } +} + +rtgui_modal_code_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal) +{ + rtgui_modal_code_t result; + + RT_ASSERT(win != RT_NULL); + result = RTGUI_MODAL_CANCEL; + + /* if it does not register into server, create it in server */ + if (RTGUI_TOPLEVEL(win)->server == RT_NULL) + { + if (_rtgui_win_create_in_server(win) == RT_FALSE) + return result; + } + + if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win))) + { + /* send show message to server */ + struct rtgui_event_win_show eshow; + RTGUI_EVENT_WIN_SHOW_INIT(&eshow); + eshow.wid = win; + + if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&eshow), + sizeof(struct rtgui_event_win_show)) != RT_EOK) + { + /* hide window failed */ + return result; + } + + /* set window unhidden */ + RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win)); + } + else rtgui_widget_update(RTGUI_WIDGET(win)); + + if (is_modal == RT_TRUE) + { + if (win->parent_toplevel != RT_NULL) + { + rtgui_workbench_t* workbench; + + /* get root toplevel */ + workbench = RTGUI_WORKBENCH(win->parent_toplevel); + workbench->flag |= RTGUI_WORKBENCH_FLAG_MODAL_MODE; + + rtgui_workbench_event_loop(workbench); + result = workbench->modal_code; + workbench->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE; + } + else + { + /* which is a root window */ + win->style |= RTGUI_WIN_STYLE_MODAL; + rtgui_win_event_loop(win); + + result = win->modal_code; + win->style &= ~RTGUI_WIN_STYLE_MODAL; + } + } + + return result; +} + +void rtgui_win_end_modal(struct rtgui_win* win, rtgui_modal_code_t modal_code) +{ + if (win->parent_toplevel != RT_NULL) + { + rtgui_workbench_t* workbench; + + /* which is shown under workbench */ + workbench = RTGUI_WORKBENCH(win->parent_toplevel); + workbench->modal_code = modal_code; + workbench->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE; + } + else + { + /* which is a stand alone window */ + win->modal_code = modal_code; + win->style &= ~RTGUI_WIN_STYLE_MODAL; + } +} + +void rtgui_win_hiden(struct rtgui_win* win) +{ + RT_ASSERT(win != RT_NULL); + + if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)) && + RTGUI_TOPLEVEL(win)->server != RT_NULL) + { + /* send hidden message to server */ + struct rtgui_event_win_hide ehide; + RTGUI_EVENT_WIN_HIDE_INIT(&ehide); + ehide.wid = win; + + if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&ehide), + sizeof(struct rtgui_event_win_hide)) != RT_EOK) + { + rt_kprintf("hide win: %s failed\n", win->title); + return; + } + + /* set window hide and deactivated */ + RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win)); + win->style &= ~RTGUI_WIN_STYLE_ACTIVATE; + } +} + +rt_bool_t rtgui_win_is_activated(struct rtgui_win* win) +{ + RT_ASSERT(win != RT_NULL); + + return win->style & RTGUI_WIN_STYLE_ACTIVATE; +} + +void rtgui_win_move(struct rtgui_win* win, int x, int y) +{ + struct rtgui_event_win_move emove; + RTGUI_EVENT_WIN_MOVE_INIT(&emove); + + if (win == RT_NULL) return; + + if (RTGUI_TOPLEVEL(win)->server != RT_NULL) + { + /* set win hide firstly */ + RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win)); + + emove.wid = win; + emove.x = x; + emove.y = y; + if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&emove), + sizeof(struct rtgui_event_win_move)) != RT_EOK) + { + return; + } + } + + /* move window to logic position */ + rtgui_widget_move_to_logic(RTGUI_WIDGET(win), + x - RTGUI_WIDGET(win)->extent.x1, + y - RTGUI_WIDGET(win)->extent.y1); + + /* set window visible */ + RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win)); + return; +} + +static rt_bool_t rtgui_win_ondraw(struct rtgui_win* win) +{ + struct rtgui_dc* dc; + struct rtgui_rect rect; + struct rtgui_event_paint event; + + /* begin drawing */ + dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(win)); + if (dc == RT_NULL) return RT_FALSE; + + /* get window rect */ + rtgui_widget_get_rect(RTGUI_WIDGET(win), &rect); + /* fill area */ + rtgui_dc_fill_rect(dc, &rect); + + /* paint each widget */ + RTGUI_EVENT_PAINT_INIT(&event); + event.wid = RT_NULL; + rtgui_container_dispatch_event(RTGUI_CONTAINER(win), (rtgui_event_t*)&event); + + rtgui_dc_end_drawing(dc); + + return RT_FALSE; +} + +rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) +{ + struct rtgui_win* win = (struct rtgui_win*)widget; + + RT_ASSERT((win != RT_NULL) && (event != RT_NULL)); + + switch (event->type) + { + case RTGUI_EVENT_WIN_SHOW: + rtgui_win_show(win, RT_FALSE); + break; + + case RTGUI_EVENT_WIN_HIDE: + rtgui_win_hiden(win); + break; + + case RTGUI_EVENT_WIN_CLOSE: + if (win->on_close != RT_NULL) + { + if (win->on_close(widget, event) == RT_FALSE) return RT_TRUE; + } + + /* destroy window */ + rtgui_win_destroy(win); + + /* exit event loop */ + return RT_TRUE; + + case RTGUI_EVENT_WIN_MOVE: + { + struct rtgui_event_win_move* emove = (struct rtgui_event_win_move*)event; + + /* move window */ + rtgui_win_move(win, emove->x, emove->y); + } + break; + + case RTGUI_EVENT_WIN_ACTIVATE: + if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win))) + { + rt_kprintf("activate window, but window is hide!\n"); + } + + win->style |= RTGUI_WIN_STYLE_ACTIVATE; + if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); + else rtgui_win_ondraw(win); + + if (win->on_activate != RT_NULL) + { + win->on_activate(widget, event); + } + break; + + case RTGUI_EVENT_WIN_DEACTIVATE: + win->style &= ~RTGUI_WIN_STYLE_ACTIVATE; + if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); + else rtgui_win_ondraw(win); + + if (win->on_deactivate != RT_NULL) + { + win->on_deactivate(widget, event); + } + break; + + case RTGUI_EVENT_PAINT: + if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); + else rtgui_win_ondraw(win); + break; + + case RTGUI_EVENT_MOUSE_BUTTON: + if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win), (struct rtgui_event_mouse*)event) == RT_FALSE) + { + if (widget->on_mouseclick != RT_NULL) + { + return widget->on_mouseclick(widget, event); + } + } + break; + + case RTGUI_EVENT_MOUSE_MOTION: +#if 0 + if (rtgui_widget_dispatch_mouse_event(widget, + (struct rtgui_event_mouse*)event) == RT_FALSE) + { + /* handle event in current widget */ + if (widget->on_mousemotion != RT_NULL) + { + return widget->on_mousemotion(widget, event); + } + } + else return RT_TRUE; +#endif + break; + + default: + /* call parent event handler */ + return rtgui_toplevel_event_handler(widget, event); + } + + return RT_FALSE; +} + +/* windows event loop */ +void rtgui_win_event_loop(rtgui_win_t* wnd) +{ + /* the buffer uses to receive event */ + char event_buf[256]; + + struct rtgui_event* event = (struct rtgui_event*)&event_buf[0]; + + if (wnd->style & RTGUI_WIN_STYLE_MODAL) + { + while (wnd->style & RTGUI_WIN_STYLE_MODAL) + { + if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK) + { + /* perform event handler */ + RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event); + } + } + } + else + { + while (!(wnd->style & RTGUI_WIN_STYLE_CLOSED)) + { + if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK) + { + /* perform event handler */ + RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event); + } + } + } + + /* destroy window */ + rtgui_widget_destroy(RTGUI_WIDGET(wnd)); +} + +void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect) +{ + struct rtgui_event_win_resize event; + + if (win == RT_NULL || rect == RT_NULL) return; + + RTGUI_WIDGET(win)->extent = *rect; + + if (RTGUI_TOPLEVEL(win)->server != RT_NULL) + { + /* set window resize event to server */ + RTGUI_EVENT_WIN_RESIZE_INIT(&event); + event.wid = win; + event.rect = *rect; + + rtgui_thread_send(RTGUI_TOPLEVEL(win)->server, &(event.parent), sizeof(struct rtgui_event_win_resize)); + } +} + +void rtgui_win_set_box(rtgui_win_t* win, rtgui_box_t* box) +{ + if (win == RT_NULL || box == RT_NULL) return; + + rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(box)); + rtgui_widget_set_rect(RTGUI_WIDGET(box), &(RTGUI_WIDGET(win)->extent)); +} + +void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler) +{ + if (win != RT_NULL) + { + win->on_activate = handler; + } +} + +void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler) +{ + if (win != RT_NULL) + { + win->on_deactivate = handler; + } +} + +void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler) +{ + if (win != RT_NULL) + { + win->on_close = handler; + } +} + +void rtgui_win_set_title(rtgui_win_t* win, const char *title) +{ + /* send title to server */ + if (RTGUI_TOPLEVEL(win)->server != RT_NULL) + { + } + + /* modify in local side */ + if (win->title != RT_NULL) + { + rtgui_free(win->title); + win->title = RT_NULL; + } + + if (title != RT_NULL) + { + win->title = rt_strdup(title); + } +} + +char* rtgui_win_get_title(rtgui_win_t* win) +{ + RT_ASSERT(win != RT_NULL); + + return win->title; +} diff --git a/rtgui/widgets/workbench.c b/rtgui/widgets/workbench.c index cdeb93232..239237bb3 100644 --- a/rtgui/widgets/workbench.c +++ b/rtgui/widgets/workbench.c @@ -23,6 +23,7 @@ static void _rtgui_workbench_constructor(rtgui_workbench_t *workbench) /* set attributes */ workbench->panel = RT_NULL; workbench->flag = RTGUI_WORKBENCH_FLAG_DEFAULT; + workbench->modal_code = RTGUI_MODAL_OK; workbench->current_view = RT_NULL; } @@ -157,10 +158,8 @@ void rtgui_workbench_set_flag(rtgui_workbench_t* workbench, rt_uint8_t flag) workbench->flag = flag; } -void rtgui_workbench_event_loop(rtgui_workbench_t* workbench) +rt_bool_t rtgui_workbench_event_loop(rtgui_workbench_t* workbench) { - int quit = 0; - /* the buffer uses to receive event */ char event_buf[256]; struct rtgui_event* event = (struct rtgui_event*)&event_buf[0]; @@ -168,13 +167,29 @@ void rtgui_workbench_event_loop(rtgui_workbench_t* workbench) /* show workbench firstly */ rtgui_workbench_show(workbench); - while (!quit) + if (workbench->flag & RTGUI_WORKBENCH_FLAG_MODAL_MODE) { - if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK) + /* event loop for modal mode shown view */ + while (workbench->flag & RTGUI_WORKBENCH_FLAG_MODAL_MODE) { - RTGUI_WIDGET(workbench)->event_handler(RTGUI_WIDGET(workbench), event); + if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK) + { + RTGUI_WIDGET(workbench)->event_handler(RTGUI_WIDGET(workbench), event); + } } } + else + { + while (!(workbench->flag & RTGUI_WORKBENCH_FLAG_CLOSED)) + { + if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK) + { + RTGUI_WIDGET(workbench)->event_handler(RTGUI_WIDGET(workbench), event); + } + } + } + + return RT_TRUE; } rt_err_t rtgui_workbench_show(rtgui_workbench_t* workbench) @@ -301,6 +316,13 @@ rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* e } else { + if (RTGUI_CONTAINER(widget)->focused == widget) + { + /* set focused widget to the current view */ + if (workbench->current_view != RT_NULL) + rtgui_widget_focus(RTGUI_WIDGET(RTGUI_CONTAINER(workbench->current_view)->focused)); + } + return rtgui_toplevel_event_handler(widget, event); } } @@ -465,8 +487,8 @@ void rtgui_workbench_hide_view(rtgui_workbench_t* workbench, rtgui_view_t* view) next_view = RTGUI_VIEW(rtgui_widget_get_prev_sibling(RTGUI_WIDGET(view))); if (next_view != RT_NULL) - { - rtgui_view_show(next_view); + { + rtgui_view_show(next_view, RT_FALSE); } else {