diff options
Diffstat (limited to 'components/rtgui/include')
57 files changed, 2674 insertions, 2539 deletions
diff --git a/components/rtgui/include/rtgui/blit.h b/components/rtgui/include/rtgui/blit.h index 0203af72f5..7d1559d517 100644 --- a/components/rtgui/include/rtgui/blit.h +++ b/components/rtgui/include/rtgui/blit.h @@ -3,7 +3,7 @@ #include <rtgui/rtgui.h> -typedef void (*rtgui_blit_line_func)(rt_uint8_t* dst, rt_uint8_t* src, int line); +typedef void (*rtgui_blit_line_func)(rt_uint8_t *dst, rt_uint8_t *src, int line); rtgui_blit_line_func rtgui_blit_line_get(int dst_bpp, int src_bpp); rtgui_blit_line_func rtgui_blit_line_get_inv(int dst_bpp, int src_bpp); diff --git a/components/rtgui/include/rtgui/color.h b/components/rtgui/include/rtgui/color.h index 22d9017a9b..e45db77f9f 100644 --- a/components/rtgui/include/rtgui/color.h +++ b/components/rtgui/include/rtgui/color.h @@ -17,17 +17,17 @@ #include <rtgui/rtgui.h> -#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)|\ - (((unsigned long)(rt_uint8_t)(a))<<24))) -#define RTGUI_RGB(r, g, b) RTGUI_ARGB(255, (r), (g), (b)) +#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)|\ + (((unsigned long)(rt_uint8_t)(a))<<24))) +#define RTGUI_RGB(r, g, b) RTGUI_ARGB(255, (r), (g), (b)) -#define RTGUI_RGB_R(c) ((c) & 0xff) -#define RTGUI_RGB_G(c) (((c) >> 8) & 0xff) -#define RTGUI_RGB_B(c) (((c) >> 16) & 0xff) -#define RTGUI_RGB_A(c) (((c) >> 24) & 0xff) +#define RTGUI_RGB_R(c) ((c) & 0xff) +#define RTGUI_RGB_G(c) (((c) >> 8) & 0xff) +#define RTGUI_RGB_B(c) (((c) >> 16) & 0xff) +#define RTGUI_RGB_A(c) (((c) >> 24) & 0xff) extern const rtgui_color_t default_foreground; extern const rtgui_color_t default_background; @@ -49,90 +49,90 @@ extern const rtgui_color_t light_grey; /* convert rtgui color to mono */ rt_inline rt_uint8_t rtgui_color_to_mono(rtgui_color_t c) { - rt_uint8_t pixel; + rt_uint8_t pixel; - pixel = (RTGUI_RGB_R(c) | RTGUI_RGB_G(c) | RTGUI_RGB_B(c)) ? 0x01 : 0x00; - return pixel; + pixel = (RTGUI_RGB_R(c) | RTGUI_RGB_G(c) | RTGUI_RGB_B(c)) ? 0x01 : 0x00; + return pixel; } rt_inline rtgui_color_t rtgui_color_from_mono(rt_uint8_t pixel) { - rtgui_color_t color; + rtgui_color_t color; - if (pixel) - { - color = white; - } + if (pixel) + { + color = white; + } else { color = black; } - return color; + return color; } /* convert rtgui color to BBBBBGGGGGGRRRRR */ rt_inline rt_uint16_t rtgui_color_to_565(rtgui_color_t c) { - rt_uint16_t pixel; + rt_uint16_t pixel; - pixel = (rt_uint16_t)(((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; + return pixel; } rt_inline rtgui_color_t rtgui_color_from_565(rt_uint16_t pixel) { - rt_uint16_t r, g, b; - rtgui_color_t color; + rt_uint16_t r, g, b; + rtgui_color_t color; - r = pixel & 0x1f; - g = (pixel >> 5) & 0x3f; - b = (pixel >> 11) & 0x1f; + r = pixel & 0x1f; + g = (pixel >> 5) & 0x3f; + b = (pixel >> 11) & 0x1f; - color = r * 255 / 31 + ((g * 255 / 63) << 8) + ((b * 255 / 31) << 16); + color = r * 255 / 31 + ((g * 255 / 63) << 8) + ((b * 255 / 31) << 16); - return color; + return color; } /* convert rtgui color to RRRRRGGGGGGBBBBB */ rt_inline rt_uint16_t rtgui_color_to_565p(rtgui_color_t c) { - rt_uint16_t pixel; + rt_uint16_t pixel; - pixel = (rt_uint16_t)(((RTGUI_RGB_R(c) >> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_B(c)>> 3)); - return pixel; + pixel = (rt_uint16_t)(((RTGUI_RGB_R(c) >> 3) << 11) | ((RTGUI_RGB_G(c) >> 2) << 5) | (RTGUI_RGB_B(c) >> 3)); + return pixel; } rt_inline rtgui_color_t rtgui_color_from_565p(rt_uint16_t pixel) { - rt_uint8_t r, g, b; - rtgui_color_t color; + rt_uint8_t r, g, b; + rtgui_color_t color; - r = (pixel >> 11) & 0x1f; - g = (pixel >> 5) & 0x3f; - b = pixel & 0x1f; + r = (pixel >> 11) & 0x1f; + g = (pixel >> 5) & 0x3f; + b = pixel & 0x1f; - color = r * 255 / 31 + ((g * 255 / 63) << 8) + ((b * 255 / 31) << 16); + color = r * 255 / 31 + ((g * 255 / 63) << 8) + ((b * 255 / 31) << 16); - return color; + return color; } /* convert rtgui color to RGB */ rt_inline rt_uint32_t rtgui_color_to_888(rtgui_color_t c) { - rt_uint32_t pixel; + rt_uint32_t pixel; - pixel = RTGUI_RGB_R(c) << 16 | RTGUI_RGB_G(c) << 8 | RTGUI_RGB_B(c); - return pixel; + pixel = RTGUI_RGB_R(c) << 16 | RTGUI_RGB_G(c) << 8 | RTGUI_RGB_B(c); + return pixel; } rt_inline rtgui_color_t rtgui_color_from_888(rt_uint32_t pixel) { - rtgui_color_t color; + rtgui_color_t color; - color = RTGUI_RGB(((pixel >> 16) & 0xff), ((pixel >> 8) & 0xff), pixel & 0xff); + color = RTGUI_RGB(((pixel >> 16) & 0xff), ((pixel >> 8) & 0xff), pixel & 0xff); - return color; + return color; } #endif diff --git a/components/rtgui/include/rtgui/dc.h b/components/rtgui/include/rtgui/dc.h index 07bf096725..7ee7f6dd93 100644 --- a/components/rtgui/include/rtgui/dc.h +++ b/components/rtgui/include/rtgui/dc.h @@ -21,91 +21,91 @@ enum rtgui_dc_type { - RTGUI_DC_HW, - RTGUI_DC_CLIENT, - RTGUI_DC_BUFFER, + RTGUI_DC_HW, + RTGUI_DC_CLIENT, + RTGUI_DC_BUFFER, }; struct rtgui_dc_engine { - /* interface */ - void (*draw_point)(struct rtgui_dc* dc, int x, int y); - void (*draw_color_point)(struct rtgui_dc* dc, int x, int y, rtgui_color_t color); - void (*draw_vline)(struct rtgui_dc* dc, int x, int y1, int y2); - void (*draw_hline)(struct rtgui_dc* dc, int x1, int x2, int y); - void (*fill_rect )(struct rtgui_dc* dc, rtgui_rect_t* rect); - void (*blit_line) (struct rtgui_dc* dc, int x1, int x2, int y, rt_uint8_t* line_data); - void (*blit )(struct rtgui_dc* dc, struct rtgui_point* dc_point, struct rtgui_dc* dest, rtgui_rect_t* rect); + /* interface */ + void (*draw_point)(struct rtgui_dc *dc, int x, int y); + void (*draw_color_point)(struct rtgui_dc *dc, int x, int y, rtgui_color_t color); + void (*draw_vline)(struct rtgui_dc *dc, int x, int y1, int y2); + void (*draw_hline)(struct rtgui_dc *dc, int x1, int x2, int y); + void (*fill_rect)(struct rtgui_dc *dc, rtgui_rect_t *rect); + void (*blit_line)(struct rtgui_dc *dc, int x1, int x2, int y, rt_uint8_t *line_data); + void (*blit)(struct rtgui_dc *dc, struct rtgui_point *dc_point, struct rtgui_dc *dest, rtgui_rect_t *rect); - /* set and get graphic context */ - void (*set_gc)(struct rtgui_dc* dc, struct rtgui_gc *gc); - struct rtgui_gc* (*get_gc)(struct rtgui_dc* dc); + /* set and get graphic context */ + void (*set_gc)(struct rtgui_dc *dc, struct rtgui_gc *gc); + struct rtgui_gc *(*get_gc)(struct rtgui_dc *dc); - /* get dc visible */ - rt_bool_t (*get_visible)(struct rtgui_dc* dc); + /* get dc visible */ + rt_bool_t (*get_visible)(struct rtgui_dc *dc); - /* get dc rect */ - void (*get_rect )(struct rtgui_dc* dc, rtgui_rect_t* rect); + /* get dc rect */ + void (*get_rect)(struct rtgui_dc *dc, rtgui_rect_t *rect); - rt_bool_t (*fini )(struct rtgui_dc* dc); + rt_bool_t (*fini)(struct rtgui_dc *dc); }; /* the abstract device context */ struct rtgui_dc { - /* type of device context */ - rt_uint32_t type; + /* type of device context */ + rt_uint32_t type; - /* dc engine */ - const struct rtgui_dc_engine* engine; + /* dc engine */ + const struct rtgui_dc_engine *engine; }; -#define RTGUI_DC_FC(dc) (rtgui_dc_get_gc(dc)->foreground) -#define RTGUI_DC_BC(dc) (rtgui_dc_get_gc(dc)->background) -#define RTGUI_DC_FONT(dc) (rtgui_dc_get_gc(dc)->font) -#define RTGUI_DC_TEXTALIGN(dc) (rtgui_dc_get_gc(dc)->textalign) +#define RTGUI_DC_FC(dc) (rtgui_dc_get_gc(dc)->foreground) +#define RTGUI_DC_BC(dc) (rtgui_dc_get_gc(dc)->background) +#define RTGUI_DC_FONT(dc) (rtgui_dc_get_gc(dc)->font) +#define RTGUI_DC_TEXTALIGN(dc) (rtgui_dc_get_gc(dc)->textalign) /* create a buffer dc */ -struct rtgui_dc* rtgui_dc_buffer_create(int width, int height); -rt_uint8_t* rtgui_dc_buffer_get_pixel(struct rtgui_dc* dc); +struct rtgui_dc *rtgui_dc_buffer_create(int width, int height); +rt_uint8_t *rtgui_dc_buffer_get_pixel(struct rtgui_dc *dc); /* begin and end a drawing */ -struct rtgui_dc* rtgui_dc_begin_drawing(rtgui_widget_t* owner); -void rtgui_dc_end_drawing(struct rtgui_dc* dc); +struct rtgui_dc *rtgui_dc_begin_drawing(rtgui_widget_t *owner); +void rtgui_dc_end_drawing(struct rtgui_dc *dc); /* destroy a dc */ -void rtgui_dc_destory(struct rtgui_dc* dc); +void rtgui_dc_destory(struct rtgui_dc *dc); -void rtgui_dc_draw_line (struct rtgui_dc* dc, int x1, int y1, int x2, int y2); -void rtgui_dc_draw_rect (struct rtgui_dc* dc, struct rtgui_rect* rect); -void rtgui_dc_fill_rect_forecolor(struct rtgui_dc* dc, struct rtgui_rect* rect); -void rtgui_dc_draw_round_rect(struct rtgui_dc* dc, struct rtgui_rect* rect, int r); -void rtgui_dc_fill_round_rect(struct rtgui_dc* dc, struct rtgui_rect* rect, int r); +void rtgui_dc_draw_line(struct rtgui_dc *dc, int x1, int y1, int x2, int y2); +void rtgui_dc_draw_rect(struct rtgui_dc *dc, struct rtgui_rect *rect); +void rtgui_dc_fill_rect_forecolor(struct rtgui_dc *dc, struct rtgui_rect *rect); +void rtgui_dc_draw_round_rect(struct rtgui_dc *dc, struct rtgui_rect *rect, int r); +void rtgui_dc_fill_round_rect(struct rtgui_dc *dc, struct rtgui_rect *rect, int r); void rtgui_dc_draw_annulus(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r1, rt_int16_t r2, rt_int16_t start, rt_int16_t end); void rtgui_dc_draw_sector(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end); void rtgui_dc_fill_sector(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end); -void rtgui_dc_draw_text (struct rtgui_dc* dc, const char* text, struct rtgui_rect* rect); -void rtgui_dc_draw_text_stroke (struct rtgui_dc* dc, const char* text, struct rtgui_rect* rect, - rtgui_color_t color_stroke, rtgui_color_t color_core); +void rtgui_dc_draw_text(struct rtgui_dc *dc, const char *text, struct rtgui_rect *rect); +void rtgui_dc_draw_text_stroke(struct rtgui_dc *dc, const char *text, struct rtgui_rect *rect, + rtgui_color_t color_stroke, rtgui_color_t color_core); -void rtgui_dc_draw_mono_bmp(struct rtgui_dc* dc, int x, int y, int w, int h, const rt_uint8_t* data); -void rtgui_dc_draw_byte(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data); -void rtgui_dc_draw_word(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data); +void rtgui_dc_draw_mono_bmp(struct rtgui_dc *dc, int x, int y, int w, int h, const rt_uint8_t *data); +void rtgui_dc_draw_byte(struct rtgui_dc *dc, int x, int y, int h, const rt_uint8_t *data); +void rtgui_dc_draw_word(struct rtgui_dc *dc, int x, int y, int h, const rt_uint8_t *data); -void rtgui_dc_draw_border(struct rtgui_dc* dc, rtgui_rect_t* rect, int flag); -void rtgui_dc_draw_horizontal_line(struct rtgui_dc* dc, int x1, int x2, int y); -void rtgui_dc_draw_vertical_line(struct rtgui_dc* dc, int x, int y1, int y2); -void rtgui_dc_draw_focus_rect(struct rtgui_dc* dc, rtgui_rect_t* rect); +void rtgui_dc_draw_border(struct rtgui_dc *dc, rtgui_rect_t *rect, int flag); +void rtgui_dc_draw_horizontal_line(struct rtgui_dc *dc, int x1, int x2, int y); +void rtgui_dc_draw_vertical_line(struct rtgui_dc *dc, int x, int y1, int y2); +void rtgui_dc_draw_focus_rect(struct rtgui_dc *dc, rtgui_rect_t *rect); -void rtgui_dc_draw_polygon(struct rtgui_dc* dc, const int *vx, const int *vy, int count); -void rtgui_dc_fill_polygon(struct rtgui_dc* dc, const int* vx, const int* vy, int count); +void rtgui_dc_draw_polygon(struct rtgui_dc *dc, const int *vx, const int *vy, int count); +void rtgui_dc_fill_polygon(struct rtgui_dc *dc, const int *vx, const int *vy, int count); -void rtgui_dc_draw_circle(struct rtgui_dc* dc, int x, int y, int r); -void rtgui_dc_fill_circle(struct rtgui_dc* dc, rt_int16_t x, rt_int16_t y, rt_int16_t r); +void rtgui_dc_draw_circle(struct rtgui_dc *dc, int x, int y, int r); +void rtgui_dc_fill_circle(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r); void rtgui_dc_draw_arc(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end); -void rtgui_dc_draw_ellipse(struct rtgui_dc* dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry); +void rtgui_dc_draw_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry); void rtgui_dc_fill_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry); /* @@ -118,81 +118,81 @@ void rtgui_dc_fill_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_i /* * draw a point on dc */ -rt_inline void rtgui_dc_draw_point(struct rtgui_dc* dc, int x, int y) +rt_inline void rtgui_dc_draw_point(struct rtgui_dc *dc, int x, int y) { - dc->engine->draw_point(dc, x, y); + dc->engine->draw_point(dc, x, y); } /* * draw a color point on dc */ -rt_inline void rtgui_dc_draw_color_point(struct rtgui_dc* dc, int x, int y, rtgui_color_t color) +rt_inline void rtgui_dc_draw_color_point(struct rtgui_dc *dc, int x, int y, rtgui_color_t color) { - dc->engine->draw_color_point(dc, x, y, color); + dc->engine->draw_color_point(dc, x, y, color); } /* * draw a vertical line on dc */ -rt_inline void rtgui_dc_draw_vline(struct rtgui_dc* dc, int x, int y1, int y2) +rt_inline void rtgui_dc_draw_vline(struct rtgui_dc *dc, int x, int y1, int y2) { - dc->engine->draw_vline(dc, x, y1, y2); + dc->engine->draw_vline(dc, x, y1, y2); } /* * draw a horizontal line on dc */ -rt_inline void rtgui_dc_draw_hline(struct rtgui_dc* dc, int x1, int x2, int y) +rt_inline void rtgui_dc_draw_hline(struct rtgui_dc *dc, int x1, int x2, int y) { - dc->engine->draw_hline(dc, x1, x2, y); + dc->engine->draw_hline(dc, x1, x2, y); } /* - * fill a rect with background color + * fill a rect with background color */ -rt_inline void rtgui_dc_fill_rect (struct rtgui_dc* dc, struct rtgui_rect* rect) +rt_inline void rtgui_dc_fill_rect(struct rtgui_dc *dc, struct rtgui_rect *rect) { - dc->engine->fill_rect(dc, rect); + dc->engine->fill_rect(dc, rect); } /* * blit a dc on hardware dc */ -rt_inline void rtgui_dc_blit(struct rtgui_dc* dc, struct rtgui_point* dc_point, struct rtgui_dc* dest, rtgui_rect_t* rect) +rt_inline void rtgui_dc_blit(struct rtgui_dc *dc, struct rtgui_point *dc_point, struct rtgui_dc *dest, rtgui_rect_t *rect) { - dc->engine->blit(dc, dc_point, dest, rect); + dc->engine->blit(dc, dc_point, dest, rect); } /* * set gc of dc */ -rt_inline void rtgui_dc_set_gc(struct rtgui_dc* dc, rtgui_gc_t* gc) +rt_inline void rtgui_dc_set_gc(struct rtgui_dc *dc, rtgui_gc_t *gc) { - dc->engine->set_gc(dc, gc); + dc->engine->set_gc(dc, gc); } /* * get gc of dc */ -rt_inline rtgui_gc_t *rtgui_dc_get_gc(struct rtgui_dc* dc) +rt_inline rtgui_gc_t *rtgui_dc_get_gc(struct rtgui_dc *dc) { - return dc->engine->get_gc(dc); + return dc->engine->get_gc(dc); } /* - * get visible status of dc + * get visible status of dc */ -rt_inline rt_bool_t rtgui_dc_get_visible(struct rtgui_dc* dc) +rt_inline rt_bool_t rtgui_dc_get_visible(struct rtgui_dc *dc) { - return dc->engine->get_visible(dc); + return dc->engine->get_visible(dc); } /* * get rect of dc */ -rt_inline void rtgui_dc_get_rect(struct rtgui_dc*dc, rtgui_rect_t* rect) +rt_inline void rtgui_dc_get_rect(struct rtgui_dc *dc, rtgui_rect_t *rect) { - dc->engine->get_rect(dc, rect); + dc->engine->get_rect(dc, rect); } #endif diff --git a/components/rtgui/include/rtgui/dc_client.h b/components/rtgui/include/rtgui/dc_client.h index 1a1de04851..e277654f04 100644 --- a/components/rtgui/include/rtgui/dc_client.h +++ b/components/rtgui/include/rtgui/dc_client.h @@ -20,8 +20,8 @@ #include <rtgui/dc.h> /* create a hardware dc */ -struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner); -void rtgui_dc_client_init(rtgui_widget_t* owner); +struct rtgui_dc *rtgui_dc_client_create(rtgui_widget_t *owner); +void rtgui_dc_client_init(rtgui_widget_t *owner); #endif diff --git a/components/rtgui/include/rtgui/dc_hw.h b/components/rtgui/include/rtgui/dc_hw.h index a9eca07aa1..0dadd7686e 100644 --- a/components/rtgui/include/rtgui/dc_hw.h +++ b/components/rtgui/include/rtgui/dc_hw.h @@ -18,7 +18,7 @@ #include <rtgui/dc.h> /* create a hardware dc */ -struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner); +struct rtgui_dc *rtgui_dc_hw_create(rtgui_widget_t *owner); #endif diff --git a/components/rtgui/include/rtgui/dlist.h b/components/rtgui/include/rtgui/dlist.h index 5491daca0c..0b8f490bea 100644 --- a/components/rtgui/include/rtgui/dlist.h +++ b/components/rtgui/include/rtgui/dlist.h @@ -30,87 +30,87 @@ extern "C" { #endif -struct rtgui_dlist_node -{ - struct rtgui_dlist_node *next; /* point to next node. */ - struct rtgui_dlist_node *prev; /* point to prev node. */ -}; + struct rtgui_dlist_node + { + struct rtgui_dlist_node *next; /* point to next node. */ + struct rtgui_dlist_node *prev; /* point to prev node. */ + }; -/** - * @brief initialize a list - * - * @param l list to be initialized - */ -rt_inline void rtgui_dlist_init(struct rtgui_dlist_node *l) -{ - l->next = l->prev = l; -} + /** + * @brief initialize a list + * + * @param l list to be initialized + */ + rt_inline void rtgui_dlist_init(struct rtgui_dlist_node *l) + { + l->next = l->prev = l; + } -/** - * @brief insert a node after a list - * - * @param l list to insert it - * @param n new node to be inserted - */ -rt_inline void rtgui_dlist_insert_after(struct rtgui_dlist_node *l, struct rtgui_dlist_node *n) -{ - l->next->prev = n; - n->next = l->next; + /** + * @brief insert a node after a list + * + * @param l list to insert it + * @param n new node to be inserted + */ + rt_inline void rtgui_dlist_insert_after(struct rtgui_dlist_node *l, struct rtgui_dlist_node *n) + { + l->next->prev = n; + n->next = l->next; - l->next = n; - n->prev = l; -} + l->next = n; + n->prev = l; + } -/** - * @brief insert a node before a list - * - * @param n new node to be inserted - * @param l list to insert it - */ -rt_inline void rtgui_dlist_insert_before(struct rtgui_dlist_node *l, struct rtgui_dlist_node *n) -{ - l->prev->next = n; - n->prev = l->prev; + /** + * @brief insert a node before a list + * + * @param n new node to be inserted + * @param l list to insert it + */ + rt_inline void rtgui_dlist_insert_before(struct rtgui_dlist_node *l, struct rtgui_dlist_node *n) + { + l->prev->next = n; + n->prev = l->prev; - l->prev = n; - n->next = l; -} + l->prev = n; + n->next = l; + } -/** - * @brief remove node from list. - * @param n the node to remove from the list. - */ -rt_inline void rtgui_dlist_remove(struct rtgui_dlist_node *n) -{ - n->next->prev = n->prev; - n->prev->next = n->next; + /** + * @brief remove node from list. + * @param n the node to remove from the list. + */ + rt_inline void rtgui_dlist_remove(struct rtgui_dlist_node *n) + { + n->next->prev = n->prev; + n->prev->next = n->next; - rtgui_dlist_init(n); -} + rtgui_dlist_init(n); + } -/** - * @brief tests whether a list is empty - * @param l the list to test. - */ -rt_inline int rtgui_dlist_isempty(const struct rtgui_dlist_node *l) -{ - return l->next == l; -} + /** + * @brief tests whether a list is empty + * @param l the list to test. + */ + rt_inline int rtgui_dlist_isempty(const struct rtgui_dlist_node *l) + { + return l->next == l; + } -/** - * @brief get the struct for this entry - * @param node the entry point - * @param type the type of structure - * @param member the name of list in structure - */ + /** + * @brief get the struct for this entry + * @param node the entry point + * @param type the type of structure + * @param member the name of list in structure + */ #define rtgui_dlist_entry(node, type, member) \ ((type *)((char *)(node) - (unsigned long)(&((type *)0)->member))) -/* the direction can only be next or prev. If you want to iterate the list in - * normal order, use next. If you want to iterate the list with reverse order, - * use prev.*/ -#define rtgui_dlist_foreach(node, list, direction) \ - for ((node) = (list)->direction; (node) != list; (node) = (node)->direction) + /* the direction can only be next or prev. If you want to iterate the list in + * normal order, use next. If you want to iterate the list with reverse order, + * use prev.*/ +#define rtgui_dlist_foreach(node, list, direction) \ + for ((node) = (list)->direction; (node) != list; (node) = (node)->direction) #ifdef __cplusplus } diff --git a/components/rtgui/include/rtgui/driver.h b/components/rtgui/include/rtgui/driver.h index b341661dfd..6b77aa804f 100644 --- a/components/rtgui/include/rtgui/driver.h +++ b/components/rtgui/include/rtgui/driver.h @@ -19,49 +19,49 @@ struct rtgui_graphic_driver_ops { - /* set and get pixel in (x, y) */ - void (*set_pixel) (rtgui_color_t *c, int x, int y); - void (*get_pixel) (rtgui_color_t *c, int x, int y); + /* set and get pixel in (x, y) */ + void (*set_pixel)(rtgui_color_t *c, int x, int y); + void (*get_pixel)(rtgui_color_t *c, int x, int y); - void (*draw_hline)(rtgui_color_t *c, int x1, int x2, int y); - void (*draw_vline)(rtgui_color_t *c, int x , int y1, int y2); + void (*draw_hline)(rtgui_color_t *c, int x1, int x2, int y); + void (*draw_vline)(rtgui_color_t *c, int x , int y1, int y2); - /* draw raw hline */ - void (*draw_raw_hline)(rt_uint8_t *pixels, int x1, int x2, int y); + /* draw raw hline */ + void (*draw_raw_hline)(rt_uint8_t *pixels, int x1, int x2, int y); }; struct rtgui_graphic_driver { - /* pixel format and byte per pixel */ - rt_uint8_t pixel_format; - rt_uint8_t bits_per_pixel; - rt_uint16_t pitch; + /* pixel format and byte per pixel */ + rt_uint8_t pixel_format; + rt_uint8_t bits_per_pixel; + rt_uint16_t pitch; - /* screen width and height */ - rt_uint16_t width; - rt_uint16_t height; + /* screen width and height */ + rt_uint16_t width; + rt_uint16_t height; - /* framebuffer address and ops */ - volatile rt_uint8_t *framebuffer; - rt_device_t device; - const struct rtgui_graphic_driver_ops *ops; + /* framebuffer address and ops */ + volatile rt_uint8_t *framebuffer; + rt_device_t device; + const struct rtgui_graphic_driver_ops *ops; }; -void rtgui_graphic_driver_add(const struct rtgui_graphic_driver* driver); +void rtgui_graphic_driver_add(const struct rtgui_graphic_driver *driver); -struct rtgui_graphic_driver* rtgui_graphic_driver_get_default(void); +struct rtgui_graphic_driver *rtgui_graphic_driver_get_default(void); void rtgui_graphic_driver_get_rect(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect); -void rtgui_graphic_driver_screen_update(const struct rtgui_graphic_driver* driver, rtgui_rect_t *rect); -rt_uint8_t* rtgui_graphic_driver_get_framebuffer(const struct rtgui_graphic_driver* driver); -rt_uint8_t* rtgui_graphic_driver_get_default_framebuffer(void); +void rtgui_graphic_driver_screen_update(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect); +rt_uint8_t *rtgui_graphic_driver_get_framebuffer(const struct rtgui_graphic_driver *driver); +rt_uint8_t *rtgui_graphic_driver_get_default_framebuffer(void); rt_err_t rtgui_graphic_set_device(rt_device_t device); -rt_inline struct rtgui_graphic_driver* rtgui_graphic_get_device() +rt_inline struct rtgui_graphic_driver *rtgui_graphic_get_device() { - extern struct rtgui_graphic_driver _driver; - return &_driver; + extern struct rtgui_graphic_driver _driver; + return &_driver; } #endif diff --git a/components/rtgui/include/rtgui/event.h b/components/rtgui/include/rtgui/event.h index e43390e06e..c0f4e5b7bf 100644 --- a/components/rtgui/include/rtgui/event.h +++ b/components/rtgui/include/rtgui/event.h @@ -21,87 +21,89 @@ * rtgui_event_generic */ enum _rtgui_event_type { - /* applications event */ - RTGUI_EVENT_APP_CREATE, /* create an application */ - RTGUI_EVENT_APP_DESTROY, /* destroy an application */ - RTGUI_EVENT_APP_ACTIVATE, /* activate an application */ + /* applications event */ + RTGUI_EVENT_APP_CREATE, /* create an application */ + RTGUI_EVENT_APP_DESTROY, /* destroy an application */ + RTGUI_EVENT_APP_ACTIVATE, /* activate an application */ - /* window event */ - RTGUI_EVENT_WIN_CREATE, /* create a window */ - RTGUI_EVENT_WIN_DESTROY, /* destroy a window */ - RTGUI_EVENT_WIN_SHOW, /* show a window */ - RTGUI_EVENT_WIN_HIDE, /* hide a window */ - RTGUI_EVENT_WIN_ACTIVATE, /* activate a window */ - RTGUI_EVENT_WIN_DEACTIVATE, /* deactivate a window */ - RTGUI_EVENT_WIN_CLOSE, /* close a window */ - RTGUI_EVENT_WIN_MOVE, /* move a window */ - RTGUI_EVENT_WIN_RESIZE, /* resize a window */ - RTGUI_EVENT_WIN_MODAL_ENTER, /* the window is entering modal mode. - This event should be sent after the - window got setup and before the - application got setup. */ + /* window event */ + RTGUI_EVENT_WIN_CREATE, /* create a window */ + RTGUI_EVENT_WIN_DESTROY, /* destroy a window */ + RTGUI_EVENT_WIN_SHOW, /* show a window */ + RTGUI_EVENT_WIN_HIDE, /* hide a window */ + RTGUI_EVENT_WIN_ACTIVATE, /* activate a window */ + RTGUI_EVENT_WIN_DEACTIVATE, /* deactivate a window */ + RTGUI_EVENT_WIN_CLOSE, /* close a window */ + RTGUI_EVENT_WIN_MOVE, /* move a window */ + RTGUI_EVENT_WIN_RESIZE, /* resize a window */ + RTGUI_EVENT_WIN_MODAL_ENTER, /* the window is entering modal mode. + This event should be sent after the + window got setup and before the + application got setup. */ - /* WM event */ - RTGUI_EVENT_SET_WM, /* set window manager */ + /* WM event */ + RTGUI_EVENT_SET_WM, /* set window manager */ - RTGUI_EVENT_UPDATE_BEGIN, /* update a rect */ - RTGUI_EVENT_UPDATE_END, /* update a rect */ - RTGUI_EVENT_MONITOR_ADD, /* add a monitor rect */ - RTGUI_EVENT_MONITOR_REMOVE, /* remove a monitor rect */ - RTGUI_EVENT_SHOW, /* the widget is going to be shown */ - RTGUI_EVENT_HIDE, /* the widget is going to be hidden */ - RTGUI_EVENT_PAINT, /* paint on screen */ - RTGUI_EVENT_TIMER, /* timer */ - RTGUI_EVENT_UPDATE_TOPLVL, /* update the toplevel */ + RTGUI_EVENT_UPDATE_BEGIN, /* update a rect */ + RTGUI_EVENT_UPDATE_END, /* update a rect */ + RTGUI_EVENT_MONITOR_ADD, /* add a monitor rect */ + RTGUI_EVENT_MONITOR_REMOVE, /* remove a monitor rect */ + RTGUI_EVENT_SHOW, /* the widget is going to be shown */ + RTGUI_EVENT_HIDE, /* the widget is going to be hidden */ + RTGUI_EVENT_PAINT, /* paint on screen */ + RTGUI_EVENT_TIMER, /* timer */ + RTGUI_EVENT_UPDATE_TOPLVL, /* update the toplevel */ - /* clip rect information */ - RTGUI_EVENT_CLIP_INFO, /* clip rect info */ + /* clip rect information */ + RTGUI_EVENT_CLIP_INFO, /* clip rect info */ - /* mouse and keyboard event */ - RTGUI_EVENT_MOUSE_MOTION, /* mouse motion */ - RTGUI_EVENT_MOUSE_BUTTON, /* mouse button info */ - RTGUI_EVENT_KBD, /* keyboard info */ + /* mouse and keyboard event */ + RTGUI_EVENT_MOUSE_MOTION, /* mouse motion */ + RTGUI_EVENT_MOUSE_BUTTON, /* mouse button info */ + RTGUI_EVENT_KBD, /* keyboard info */ - /* user command event */ - RTGUI_EVENT_COMMAND=0x0100, /* user command */ + /* widget event */ + RTGUI_EVENT_FOCUSED, /* widget focused */ + RTGUI_EVENT_SCROLLED, /* scroll bar scrolled */ + RTGUI_EVENT_RESIZE, /* widget resize */ + RTGUI_EVENT_SELECTED, /* widget selected */ + RTGUI_EVENT_UNSELECTED, /* widget un-selected */ + RTGUI_EVENT_MV_MODEL, /* data of a model has been changed */ - /* widget event */ - RTGUI_EVENT_FOCUSED, /* widget focused */ - RTGUI_EVENT_SCROLLED, /* scroll bar scrolled */ - RTGUI_EVENT_RESIZE, /* widget resize */ - RTGUI_EVENT_SELECTED, /* widget selected */ - RTGUI_EVENT_UNSELECTED, /* widget un-selected */ + /* user command event. It should always be the last command type. */ + RTGUI_EVENT_COMMAND = 0x0100, /* user command */ }; typedef enum _rtgui_event_type rtgui_event_type; -enum { - RTGUI_STATUS_OK = 0, /* status ok */ - RTGUI_STATUS_ERROR, /* generic error */ - RTGUI_STATUS_NRC, /* no resource */ +enum +{ + RTGUI_STATUS_OK = 0, /* status ok */ + RTGUI_STATUS_ERROR, /* generic error */ + RTGUI_STATUS_NRC, /* no resource */ }; struct rtgui_event { - /* the event type */ - rt_uint16_t type; - /* user field of event */ - rt_uint16_t user; + /* the event type */ + enum _rtgui_event_type type; + /* user field of event */ + rt_uint16_t user; - /* the event sender */ - rt_thread_t sender; + /* the event sender */ + rt_thread_t sender; - /* mailbox to acknowledge request */ - rt_mailbox_t ack; + /* mailbox to acknowledge request */ + rt_mailbox_t ack; }; typedef struct rtgui_event rtgui_event_t; -#define RTGUI_EVENT(e) ((struct rtgui_event*)(e)) +#define RTGUI_EVENT(e) ((struct rtgui_event*)(e)) -#define RTGUI_EVENT_INIT(e, t) do \ -{ \ - (e)->type = (t); \ - (e)->user = 0; \ - (e)->sender = rt_thread_self(); \ - (e)->ack = RT_NULL; \ +#define RTGUI_EVENT_INIT(e, t) do \ +{ \ + (e)->type = (t); \ + (e)->user = 0; \ + (e)->sender = rt_thread_self(); \ + (e)->ack = RT_NULL; \ } while (0) /* @@ -109,9 +111,9 @@ typedef struct rtgui_event rtgui_event_t; */ struct rtgui_event_application { - struct rtgui_event parent; + struct rtgui_event parent; - struct rtgui_app* app; + struct rtgui_app *app; }; /* gui application init */ @@ -123,40 +125,40 @@ struct rtgui_event_application * RTGUI Window Event */ #define _RTGUI_EVENT_WIN_ELEMENTS \ - struct rtgui_event parent; \ - struct rtgui_win *wid; + struct rtgui_event parent; \ + struct rtgui_win *wid; /* * RTGUI Window Event */ struct rtgui_event_win { - _RTGUI_EVENT_WIN_ELEMENTS + _RTGUI_EVENT_WIN_ELEMENTS }; struct rtgui_event_win_create { - _RTGUI_EVENT_WIN_ELEMENTS - struct rtgui_win *parent_window; + _RTGUI_EVENT_WIN_ELEMENTS + struct rtgui_win *parent_window; #ifndef RTGUI_USING_SMALL_SIZE - /* the window title */ - rt_uint8_t title[RTGUI_NAME_MAX]; - /* the window extent */ - struct rtgui_rect extent; + /* the window title */ + rt_uint8_t title[RTGUI_NAME_MAX]; + /* the window extent */ + struct rtgui_rect extent; #endif }; struct rtgui_event_win_move { - _RTGUI_EVENT_WIN_ELEMENTS - rt_int16_t x, y; + _RTGUI_EVENT_WIN_ELEMENTS + rt_int16_t x, y; }; struct rtgui_event_win_resize { - _RTGUI_EVENT_WIN_ELEMENTS + _RTGUI_EVENT_WIN_ELEMENTS - rtgui_rect_t rect; + rtgui_rect_t rect; }; #define rtgui_event_win_destroy rtgui_event_win @@ -184,159 +186,159 @@ struct rtgui_event_win_resize */ struct rtgui_event_set_wm { - struct rtgui_event parent; - struct rtgui_app *app; + struct rtgui_event parent; + struct rtgui_app *app; }; -#define RTGUI_EVENT_SET_WM_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SET_WM); +#define RTGUI_EVENT_SET_WM_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SET_WM); /* * RTGUI Other Event */ struct rtgui_event_update_begin { - struct rtgui_event parent; + struct rtgui_event parent; - /* the update rect */ - rtgui_rect_t rect; + /* the update rect */ + rtgui_rect_t rect; }; struct rtgui_event_update_end { - struct rtgui_event parent; + struct rtgui_event parent; - /* the update rect */ - rtgui_rect_t rect; + /* the update rect */ + rtgui_rect_t rect; }; struct rtgui_event_monitor { - _RTGUI_EVENT_WIN_ELEMENTS + _RTGUI_EVENT_WIN_ELEMENTS - /* the monitor rect */ - rtgui_rect_t rect; + /* the monitor rect */ + rtgui_rect_t rect; }; struct rtgui_event_paint { - _RTGUI_EVENT_WIN_ELEMENTS + _RTGUI_EVENT_WIN_ELEMENTS - rtgui_rect_t rect; /* rect to be updated */ + rtgui_rect_t rect; /* rect to be updated */ }; struct rtgui_timer; struct rtgui_event_timer { - struct rtgui_event parent; + struct rtgui_event parent; - struct rtgui_timer *timer; + struct rtgui_timer *timer; }; typedef struct rtgui_event_timer rtgui_event_timer_t; struct rtgui_event_clip_info { - _RTGUI_EVENT_WIN_ELEMENTS + _RTGUI_EVENT_WIN_ELEMENTS - /* the number of rects */ - //rt_uint32_t num_rect; + /* the number of rects */ + //rt_uint32_t num_rect; - /* rtgui_rect_t *rects */ + /* rtgui_rect_t *rects */ }; -#define RTGUI_EVENT_GET_RECT(e, i) &(((rtgui_rect_t*)(e + 1))[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) -#define RTGUI_EVENT_MONITOR_ADD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MONITOR_ADD) -#define RTGUI_EVENT_MONITOR_REMOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MONITOR_REMOVE) -#define RTGUI_EVENT_CLIP_INFO_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_CLIP_INFO) -#define RTGUI_EVENT_PAINT_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PAINT) -#define RTGUI_EVENT_TIMER_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_TIMER) +#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) +#define RTGUI_EVENT_MONITOR_ADD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MONITOR_ADD) +#define RTGUI_EVENT_MONITOR_REMOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MONITOR_REMOVE) +#define RTGUI_EVENT_CLIP_INFO_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_CLIP_INFO) +#define RTGUI_EVENT_PAINT_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PAINT) +#define RTGUI_EVENT_TIMER_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_TIMER) #define rtgui_event_show rtgui_event #define rtgui_event_hide rtgui_event -#define RTGUI_EVENT_SHOW_INIT(e) RTGUI_EVENT_INIT((e), RTGUI_EVENT_SHOW) -#define RTGUI_EVENT_HIDE_INIT(e) RTGUI_EVENT_INIT((e), RTGUI_EVENT_HIDE) +#define RTGUI_EVENT_SHOW_INIT(e) RTGUI_EVENT_INIT((e), RTGUI_EVENT_SHOW) +#define RTGUI_EVENT_HIDE_INIT(e) RTGUI_EVENT_INIT((e), RTGUI_EVENT_HIDE) struct rtgui_event_update_toplvl { - struct rtgui_event parent; - struct rtgui_win *toplvl; + struct rtgui_event parent; + struct rtgui_win *toplvl; }; -#define RTGUI_EVENT_UPDATE_TOPLVL_INIT(e) \ - do { \ - RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_TOPLVL); \ - (e)->toplvl = RT_NULL; \ - } while (0) +#define RTGUI_EVENT_UPDATE_TOPLVL_INIT(e) \ + do { \ + RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_TOPLVL); \ + (e)->toplvl = RT_NULL; \ + } while (0) /* * RTGUI Mouse and Keyboard Event */ struct rtgui_event_mouse { - _RTGUI_EVENT_WIN_ELEMENTS + _RTGUI_EVENT_WIN_ELEMENTS - rt_uint16_t x, y; - rt_uint16_t button; + rt_uint16_t x, y; + rt_uint16_t button; }; -#define RTGUI_MOUSE_BUTTON_LEFT 0x01 -#define RTGUI_MOUSE_BUTTON_RIGHT 0x02 -#define RTGUI_MOUSE_BUTTON_MIDDLE 0x03 -#define RTGUI_MOUSE_BUTTON_WHEELUP 0x04 -#define RTGUI_MOUSE_BUTTON_WHEELDOWN 0x08 +#define RTGUI_MOUSE_BUTTON_LEFT 0x01 +#define RTGUI_MOUSE_BUTTON_RIGHT 0x02 +#define RTGUI_MOUSE_BUTTON_MIDDLE 0x03 +#define RTGUI_MOUSE_BUTTON_WHEELUP 0x04 +#define RTGUI_MOUSE_BUTTON_WHEELDOWN 0x08 -#define RTGUI_MOUSE_BUTTON_DOWN 0x10 -#define RTGUI_MOUSE_BUTTON_UP 0x20 +#define RTGUI_MOUSE_BUTTON_DOWN 0x10 +#define RTGUI_MOUSE_BUTTON_UP 0x20 struct rtgui_event_kbd { - _RTGUI_EVENT_WIN_ELEMENTS + _RTGUI_EVENT_WIN_ELEMENTS - rt_uint16_t type; /* key down or up */ - rt_uint16_t key; /* current key */ - rt_uint16_t mod; /* current key modifiers */ - rt_uint16_t unicode; /* translated character */ + rt_uint16_t type; /* key down or up */ + rt_uint16_t key; /* current key */ + rt_uint16_t mod; /* current key modifiers */ + rt_uint16_t unicode; /* translated character */ }; -#define RTGUI_KBD_IS_SET_CTRL(e) ((e)->mod & (RTGUI_KMOD_LCTRL | RTGUI_KMOD_RCTRL))) -#define RTGUI_KBD_IS_SET_ALT(e) ((e)->mod & (RTGUI_KMOD_LALT | RTGUI_KMOD_RALT)) -#define RTGUI_KBD_IS_SET_SHIFT(e) ((e)->mod & (RTGUI_KMOD_LSHIFT| RTGUI_KMOD_RSHIFT)) -#define RTGUI_KBD_IS_UP(e) ((e)->type == RTGUI_KEYUP) -#define RTGUI_KBD_IS_DOWN(e) ((e)->type == RTGUI_KEYDOWN) +#define RTGUI_KBD_IS_SET_CTRL(e) ((e)->mod & (RTGUI_KMOD_LCTRL | RTGUI_KMOD_RCTRL))) +#define RTGUI_KBD_IS_SET_ALT(e) ((e)->mod & (RTGUI_KMOD_LALT | RTGUI_KMOD_RALT)) +#define RTGUI_KBD_IS_SET_SHIFT(e) ((e)->mod & (RTGUI_KMOD_LSHIFT| RTGUI_KMOD_RSHIFT)) +#define RTGUI_KBD_IS_UP(e) ((e)->type == RTGUI_KEYUP) +#define RTGUI_KBD_IS_DOWN(e) ((e)->type == RTGUI_KEYDOWN) -#define RTGUI_EVENT_MOUSE_MOTION_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_MOTION) -#define RTGUI_EVENT_MOUSE_BUTTON_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_BUTTON) -#define RTGUI_EVENT_KBD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_KBD) +#define RTGUI_EVENT_MOUSE_MOTION_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_MOTION) +#define RTGUI_EVENT_MOUSE_BUTTON_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_BUTTON) +#define RTGUI_EVENT_KBD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_KBD) struct rtgui_event_command { - _RTGUI_EVENT_WIN_ELEMENTS + _RTGUI_EVENT_WIN_ELEMENTS - /* command type */ - rt_int32_t type; + /* command type */ + rt_int32_t type; - /* command id */ - rt_int32_t command_id; + /* command id */ + rt_int32_t command_id; - /* command string */ - char command_string[RTGUI_NAME_MAX]; + /* command string */ + char command_string[RTGUI_NAME_MAX]; }; -#define RTGUI_EVENT_COMMAND_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_COMMAND) +#define RTGUI_EVENT_COMMAND_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_COMMAND) -#define RTGUI_CMD_UNKNOWN 0x00 -#define RTGUI_CMD_WM_CLOSE 0x10 +#define RTGUI_CMD_UNKNOWN 0x00 +#define RTGUI_CMD_WM_CLOSE 0x10 -#define RTGUI_CMD_USER_INT 0x20 -#define RTGUI_CMD_USER_STRING 0x21 +#define RTGUI_CMD_USER_INT 0x20 +#define RTGUI_CMD_USER_STRING 0x21 /************************************************************************/ /* Widget Event */ /************************************************************************/ -#define RTGUI_WIDGET_EVENT_INIT(e, t) do \ -{ \ - (e)->type = (t); \ - (e)->sender = RT_NULL; \ - (e)->ack = RT_NULL; \ +#define RTGUI_WIDGET_EVENT_INIT(e, t) do \ +{ \ + (e)->type = (t); \ + (e)->sender = RT_NULL; \ + (e)->ack = RT_NULL; \ } while (0) /* @@ -352,7 +354,7 @@ struct rtgui_event_scrollbar #define RTGUI_SCROLL_LINEDOWN 0x02 #define RTGUI_SCROLL_PAGEUP 0x03 #define RTGUI_SCROLL_PAGEDOWN 0x04 -#define RTGUI_EVENT_SCROLLED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SCROLLED) +#define RTGUI_EVENT_SCROLLED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SCROLLED) /* * RTGUI Widget Focused Event @@ -361,55 +363,102 @@ struct rtgui_event_focused { struct rtgui_event parent; - struct rtgui_widget* widget; + struct rtgui_widget *widget; }; -#define RTGUI_EVENT_FOCUSED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_FOCUSED) +#define RTGUI_EVENT_FOCUSED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_FOCUSED) /* * RTGUI Widget Resize Event */ struct rtgui_event_resize { - struct rtgui_event parent; - rt_int16_t x, y; - rt_int16_t w, h; + struct rtgui_event parent; + rt_int16_t x, y; + rt_int16_t w, h; }; #define RTGUI_EVENT_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_RESIZE) +/* + * RTGUI Model/View Event + */ +enum rtgui_event_model_mode +{ + RTGUI_MV_DATA_ADDED, + RTGUI_MV_DATA_CHANGED, + RTGUI_MV_DATA_DELETED, +}; + +struct rtgui_event_mv_model +{ + struct rtgui_event parent; + struct rtgui_mv_model *model; + struct rtgui_mv_view *view; + rt_size_t first_data_changed_idx; + rt_size_t last_data_changed_idx; +}; + +#define _RTGUI_EVENT_MV_INIT_TYPE(T) \ +rt_inline void RTGUI_EVENT_MV_MODEL_##T##_INIT(struct rtgui_event_mv_model *e) \ +{ \ + RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MV_MODEL); \ + (e)->parent.user = RTGUI_MV_DATA_##T; \ +} \ +/* useless struct to allow trailing semicolon */ \ +struct dummy + +_RTGUI_EVENT_MV_INIT_TYPE(ADDED); +_RTGUI_EVENT_MV_INIT_TYPE(CHANGED); +_RTGUI_EVENT_MV_INIT_TYPE(DELETED); +#undef _RTGUI_EVENT_MV_INIT_TYPE + +#define _RTGUI_EVENT_MV_IS_TYPE(T) \ +rt_inline rt_bool_t RTGUI_EVENT_MV_MODEL_IS_##T(struct rtgui_event_mv_model *e) \ +{ \ + return e->parent.user == RTGUI_MV_DATA_##T; \ +} \ +/* useless struct to allow trailing semicolon */ \ +struct dummy + +_RTGUI_EVENT_MV_IS_TYPE(ADDED); +_RTGUI_EVENT_MV_IS_TYPE(CHANGED); +_RTGUI_EVENT_MV_IS_TYPE(DELETED); +#undef _RTGUI_EVENT_MV_IS_TYPE + #undef _RTGUI_EVENT_WIN_ELEMENTS union rtgui_event_generic { - struct rtgui_event base; + struct rtgui_event base; - struct rtgui_event_application app_create; - struct rtgui_event_application app_destroy; - struct rtgui_event_application app_activate; + struct rtgui_event_application app_create; + struct rtgui_event_application app_destroy; + struct rtgui_event_application app_activate; - struct rtgui_event_set_wm set_wm; - struct rtgui_event_win win_base; - struct rtgui_event_win_create win_create; - struct rtgui_event_win_move win_move; - struct rtgui_event_win_resize win_resize; - struct rtgui_event_win_destroy win_destroy; - struct rtgui_event_win_show win_show; - struct rtgui_event_win_hide win_hide; - struct rtgui_event_win_activate win_activate; - struct rtgui_event_win_deactivate win_deactivate; - struct rtgui_event_win_close win_close; - struct rtgui_event_win_modal_enter win_modal_enter; - struct rtgui_event_update_begin update_begin; - struct rtgui_event_update_end update_end; - struct rtgui_event_monitor monitor; - struct rtgui_event_paint paint; - struct rtgui_event_timer timer; - struct rtgui_event_update_toplvl update_toplvl; - struct rtgui_event_clip_info clip_info; - struct rtgui_event_mouse mouse; - struct rtgui_event_kbd kbd; - struct rtgui_event_command command; - struct rtgui_event_scrollbar scrollbar; - struct rtgui_event_focused focused; - struct rtgui_event_resize resize; + struct rtgui_event_set_wm set_wm; + struct rtgui_event_win win_base; + struct rtgui_event_win_create win_create; + struct rtgui_event_win_move win_move; + struct rtgui_event_win_resize win_resize; + struct rtgui_event_win_destroy win_destroy; + struct rtgui_event_win_show win_show; + struct rtgui_event_win_hide win_hide; + struct rtgui_event_win_activate win_activate; + struct rtgui_event_win_deactivate win_deactivate; + struct rtgui_event_win_close win_close; + struct rtgui_event_win_modal_enter win_modal_enter; + struct rtgui_event_update_begin update_begin; + struct rtgui_event_update_end update_end; + struct rtgui_event_monitor monitor; + struct rtgui_event_paint paint; + struct rtgui_event_timer timer; + struct rtgui_event_update_toplvl update_toplvl; + struct rtgui_event_clip_info clip_info; + struct rtgui_event_mouse mouse; + struct rtgui_event_kbd kbd; + struct rtgui_event_scrollbar scrollbar; + struct rtgui_event_focused focused; + struct rtgui_event_resize resize; + struct rtgui_event_mv_model model; + struct rtgui_event_command command; }; #endif diff --git a/components/rtgui/include/rtgui/filerw.h b/components/rtgui/include/rtgui/filerw.h index eb1f5d3885..e32f40d22f 100644 --- a/components/rtgui/include/rtgui/filerw.h +++ b/components/rtgui/include/rtgui/filerw.h @@ -14,8 +14,8 @@ #ifndef __RTGUI_FILERW_H__ #define __RTGUI_FILERW_H__ -#ifdef RTGUI_USING_DFS_FILERW -#ifdef _WIN32 +#ifdef RTGUI_USING_DFS_FILERW +#ifdef _WIN32_NATIVE #pragma warning(disable: 4996) #include <fcntl.h> #include <sys/types.h> @@ -28,33 +28,33 @@ #include <rtgui/rtgui.h> -#define RTGUI_FILE_SEEK_SET 0 -#define RTGUI_FILE_SEEK_CUR 1 -#define RTGUI_FILE_SEEK_END 2 +#define RTGUI_FILE_SEEK_SET 0 +#define RTGUI_FILE_SEEK_CUR 1 +#define RTGUI_FILE_SEEK_END 2 struct rtgui_filerw { - int (*seek) (struct rtgui_filerw *context, rt_off_t offset, int whence); - int (*read) (struct rtgui_filerw *context, void *buffer, rt_size_t size, rt_size_t count); - int (*write)(struct rtgui_filerw *context, const void *buffer, rt_size_t size, rt_size_t count); - int (*tell) (struct rtgui_filerw *context); - int (*eof) (struct rtgui_filerw *context); - int (*close)(struct rtgui_filerw *context); + int (*seek)(struct rtgui_filerw *context, rt_off_t offset, int whence); + int (*read)(struct rtgui_filerw *context, void *buffer, rt_size_t size, rt_size_t count); + int (*write)(struct rtgui_filerw *context, const void *buffer, rt_size_t size, rt_size_t count); + int (*tell)(struct rtgui_filerw *context); + int (*eof)(struct rtgui_filerw *context); + int (*close)(struct rtgui_filerw *context); }; typedef struct rtgui_filerw rtgui_filerw_t; -struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode); -struct rtgui_filerw* rtgui_filerw_create_mem(const rt_uint8_t* mem, rt_size_t size); +struct rtgui_filerw *rtgui_filerw_create_file(const char *filename, const char *mode); +struct rtgui_filerw *rtgui_filerw_create_mem(const rt_uint8_t *mem, rt_size_t size); -int rtgui_filerw_seek (struct rtgui_filerw* context, rt_off_t offset, int whence); -int rtgui_filerw_read (struct rtgui_filerw* context, void* buffer, rt_size_t size, rt_size_t count); -int rtgui_filerw_write(struct rtgui_filerw* context, const void* buffer, rt_size_t size, rt_size_t count); -int rtgui_filerw_tell (struct rtgui_filerw* context); -int rtgui_filerw_eof (struct rtgui_filerw* context); -int rtgui_filerw_close(struct rtgui_filerw* context); +int rtgui_filerw_seek(struct rtgui_filerw *context, rt_off_t offset, int whence); +int rtgui_filerw_read(struct rtgui_filerw *context, void *buffer, rt_size_t size, rt_size_t count); +int rtgui_filerw_write(struct rtgui_filerw *context, const void *buffer, rt_size_t size, rt_size_t count); +int rtgui_filerw_tell(struct rtgui_filerw *context); +int rtgui_filerw_eof(struct rtgui_filerw *context); +int rtgui_filerw_close(struct rtgui_filerw *context); int rtgui_filerw_unlink(const char *filename); /* get memory data from filerw memory object */ -const rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context); +const rt_uint8_t *rtgui_filerw_mem_getdata(struct rtgui_filerw *context); #endif diff --git a/components/rtgui/include/rtgui/font.h b/components/rtgui/include/rtgui/font.h index f3bf5ef464..d24165203b 100644 --- a/components/rtgui/include/rtgui/font.h +++ b/components/rtgui/include/rtgui/font.h @@ -23,13 +23,13 @@ struct rtgui_rect; struct rtgui_font_engine { - /* font engine function */ - void (*font_init)(struct rtgui_font* font); - void (*font_load)(struct rtgui_font* font); + /* font engine function */ + void (*font_init)(struct rtgui_font *font); + void (*font_load)(struct rtgui_font *font); - void (*font_draw_text)(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, - rt_ubase_t len, struct rtgui_rect* rect); - void (*font_get_metrics)(struct rtgui_font* font, const char* text, struct rtgui_rect* rect); + void (*font_draw_text)(struct rtgui_font *font, struct rtgui_dc *dc, const char *text, + rt_ubase_t len, struct rtgui_rect *rect); + void (*font_get_metrics)(struct rtgui_font *font, const char *text, struct rtgui_rect *rect); }; /* @@ -37,15 +37,15 @@ struct rtgui_font_engine */ struct rtgui_font_bitmap { - const rt_uint8_t* bmp; /* bitmap font data */ - const rt_uint8_t* char_width; /* each character width, NULL for fixed font */ - const rt_uint32_t* offset; /* offset for each character */ + const rt_uint8_t *bmp; /* bitmap font data */ + const rt_uint8_t *char_width; /* each character width, NULL for fixed font */ + const rt_uint32_t *offset; /* offset for each character */ - rt_uint16_t width; /* font width */ - rt_uint16_t height; /* font height */ + rt_uint16_t width; /* font width */ + rt_uint16_t height; /* font height */ - rt_uint8_t first_char; - rt_uint8_t last_char; + rt_uint8_t first_char; + rt_uint8_t last_char; }; extern const struct rtgui_font_engine bmp_font_engine; @@ -65,50 +65,54 @@ struct rtgui_hz_file_font /* font size */ rt_uint16_t font_size; - rt_uint16_t font_data_size; + rt_uint16_t font_data_size; /* file descriptor */ int fd; /* font file name */ - const char* font_fn; + const char *font_fn; }; extern const struct rtgui_font_engine rtgui_hz_file_font_engine; struct rtgui_font { - /* font name */ - char* family; + /* font name */ + char *family; - /* font height */ - rt_uint16_t height; + /* font height */ + rt_uint16_t height; - /* refer count */ - rt_uint32_t refer_count; + /* refer count */ + rt_uint32_t refer_count; - /* font engine */ - const struct rtgui_font_engine* engine; + /* font engine */ + const struct rtgui_font_engine *engine; - /* font private data */ - void* data; + /* font private data */ + void *data; - /* the font list */ - rtgui_list_t list; + /* the font list */ + rtgui_list_t list; }; typedef struct rtgui_font rtgui_font_t; void rtgui_font_system_init(void); -void rtgui_font_system_add_font(struct rtgui_font* font); -void rtgui_font_system_remove_font(struct rtgui_font* font); -struct rtgui_font* rtgui_font_default(void); -void rtgui_font_set_defaut(struct rtgui_font* font); +void rtgui_font_system_add_font(struct rtgui_font *font); +void rtgui_font_system_remove_font(struct rtgui_font *font); +struct rtgui_font *rtgui_font_default(void); +void rtgui_font_set_defaut(struct rtgui_font *font); -struct rtgui_font* rtgui_font_refer(const rt_uint8_t* family, rt_uint16_t height); -void rtgui_font_derefer(struct rtgui_font* font); +struct rtgui_font *rtgui_font_refer(const char *family, rt_uint16_t height); +void rtgui_font_derefer(struct rtgui_font *font); /* draw a text */ -void rtgui_font_draw(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect); -int rtgui_font_get_string_width(struct rtgui_font* font, const char* text); -void rtgui_font_get_metrics(struct rtgui_font* font, const char* text, struct rtgui_rect* rect); +void rtgui_font_draw(struct rtgui_font *font, struct rtgui_dc *dc, const char *text, rt_ubase_t len, struct rtgui_rect *rect); +int rtgui_font_get_string_width(struct rtgui_font *font, const char *text); +void rtgui_font_get_metrics(struct rtgui_font *font, const char *text, struct rtgui_rect *rect); + +/* used by stract font */ +#define FONT_BMP_DATA_BEGIN +#define FONT_BMP_DATA_END #endif diff --git a/components/rtgui/include/rtgui/font_freetype.h b/components/rtgui/include/rtgui/font_freetype.h index b99108e7c4..bd54d308f1 100644 --- a/components/rtgui/include/rtgui/font_freetype.h +++ b/components/rtgui/include/rtgui/font_freetype.h @@ -4,7 +4,7 @@ #include <rtgui/dc.h> #include <rtgui/font.h> -rtgui_font_t* rtgui_freetype_font_create(const char* filename, int bold, int italic, rt_size_t size); -void rtgui_freetype_font_destroy(rtgui_font_t* font); +rtgui_font_t *rtgui_freetype_font_create(const char *filename, int bold, int italic, rt_size_t size); +void rtgui_freetype_font_destroy(rtgui_font_t *font); #endif diff --git a/components/rtgui/include/rtgui/image.h b/components/rtgui/include/rtgui/image.h index 3c1383656e..b664833a6d 100644 --- a/components/rtgui/include/rtgui/image.h +++ b/components/rtgui/include/rtgui/image.h @@ -19,48 +19,48 @@ #include <rtgui/region.h> enum rtgui_img_zoom -{ - RTGUI_IMG_ZOOM_NEAREST, - RTGUI_IMG_ZOOM_BILINEAR +{ + RTGUI_IMG_ZOOM_NEAREST, + RTGUI_IMG_ZOOM_BILINEAR }; struct rtgui_image; struct rtgui_image_engine { - const char* name; - struct rtgui_list_node list; + const char *name; + struct rtgui_list_node list; - /* image engine function */ - rt_bool_t (*image_check)(struct rtgui_filerw* file); + /* image engine function */ + rt_bool_t (*image_check)(struct rtgui_filerw *file); - rt_bool_t (*image_load)(struct rtgui_image* image, struct rtgui_filerw* file, rt_bool_t load); - void (*image_unload)(struct rtgui_image* image); + rt_bool_t (*image_load)(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load); + void (*image_unload)(struct rtgui_image *image); - void (*image_blit)(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* rect); - struct rtgui_image* (*image_zoom)(struct rtgui_image* image, float scalew, float scaleh, rt_uint32_t mode); - struct rtgui_image* (*image_rotate)(struct rtgui_image* image, float angle); + void (*image_blit)(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect); + struct rtgui_image *(*image_zoom)(struct rtgui_image *image, float scalew, float scaleh, rt_uint32_t mode); + struct rtgui_image *(*image_rotate)(struct rtgui_image *image, float angle); }; struct rtgui_image_palette { - rtgui_color_t* colors; - rt_uint32_t ncolors; + rtgui_color_t *colors; + rt_uint32_t ncolors; }; typedef struct rtgui_image_palette rtgui_image_palette_t; struct rtgui_image { - /* image metrics */ - rt_uint16_t w, h; + /* image metrics */ + rt_uint16_t w, h; - /* image engine */ - const struct rtgui_image_engine* engine; + /* image engine */ + const struct rtgui_image_engine *engine; - /* image palette */ - rtgui_image_palette_t* palette; + /* image palette */ + rtgui_image_palette_t *palette; - /* image private data */ - void* data; + /* image private data */ + void *data; }; typedef struct rtgui_image rtgui_image_t; @@ -68,24 +68,24 @@ typedef struct rtgui_image rtgui_image_t; void rtgui_system_image_init(void); #if defined(RTGUI_USING_DFS_FILERW) -struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn); -struct rtgui_image* rtgui_image_create_from_file(const char* type, const char* filename, rt_bool_t load); -struct rtgui_image* rtgui_image_create(const char* filename, rt_bool_t load); +struct rtgui_image_engine *rtgui_image_get_engine_by_filename(const char *fn); +struct rtgui_image *rtgui_image_create_from_file(const char *type, const char *filename, rt_bool_t load); +struct rtgui_image *rtgui_image_create(const char *filename, rt_bool_t load); #endif -struct rtgui_image* rtgui_image_create_from_mem(const char* type, const rt_uint8_t* data, rt_size_t length, rt_bool_t load); -void rtgui_image_destroy(struct rtgui_image* image); +struct rtgui_image *rtgui_image_create_from_mem(const char *type, const rt_uint8_t *data, rt_size_t length, rt_bool_t load); +void rtgui_image_destroy(struct rtgui_image *image); /* get image's rect */ -void rtgui_image_get_rect(struct rtgui_image* image, struct rtgui_rect* rect); +void rtgui_image_get_rect(struct rtgui_image *image, struct rtgui_rect *rect); /* register an image engine */ -void rtgui_image_register_engine(struct rtgui_image_engine* engine); +void rtgui_image_register_engine(struct rtgui_image_engine *engine); /* blit an image on DC */ -void rtgui_image_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* rect); -struct rtgui_image_palette* rtgui_image_palette_create(rt_uint32_t ncolors); -rtgui_image_t* rtgui_image_zoom(rtgui_image_t* image, float scalew, float scaleh, rt_uint32_t mode); -rtgui_image_t* rtgui_image_rotate(rtgui_image_t* image, float angle); +void rtgui_image_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect); +struct rtgui_image_palette *rtgui_image_palette_create(rt_uint32_t ncolors); +rtgui_image_t *rtgui_image_zoom(rtgui_image_t *image, float scalew, float scaleh, rt_uint32_t mode); +rtgui_image_t *rtgui_image_rotate(rtgui_image_t *image, float angle); #endif diff --git a/components/rtgui/include/rtgui/image_bmp.h b/components/rtgui/include/rtgui/image_bmp.h index a282e23984..7e5fbdc58c 100644 --- a/components/rtgui/include/rtgui/image_bmp.h +++ b/components/rtgui/include/rtgui/image_bmp.h @@ -18,27 +18,27 @@ struct rtgui_image_bmp_header { - /* The Win32 BMP file header (14 bytes) */ - rt_uint16_t bfType; - rt_uint32_t bfSize; - rt_uint16_t bfReserved1; - rt_uint16_t bfReserved2; - rt_uint32_t bfOffBits; + /* The Win32 BMP file header (14 bytes) */ + rt_uint16_t bfType; + rt_uint32_t bfSize; + rt_uint16_t bfReserved1; + rt_uint16_t bfReserved2; + rt_uint32_t bfOffBits; - /* The Win32 BITMAPINFOHEADER struct (40 bytes) */ - rt_uint32_t biSize; - rt_int32_t biWidth; - rt_int32_t biHeight; - rt_uint16_t biPlanes; - rt_uint16_t biBitCount; - rt_uint32_t biCompression; - rt_uint32_t biSizeImage; - rt_int32_t biXPelsPerMeter; - rt_int32_t biYPelsPerMeter; - rt_uint32_t biClrUsed; - rt_uint32_t biClrImportant; + /* The Win32 BITMAPINFOHEADER struct (40 bytes) */ + rt_uint32_t biSize; + rt_int32_t biWidth; + rt_int32_t biHeight; + rt_uint16_t biPlanes; + rt_uint16_t biBitCount; + rt_uint32_t biCompression; + rt_uint32_t biSizeImage; + rt_int32_t biXPelsPerMeter; + rt_int32_t biYPelsPerMeter; + rt_uint32_t biClrUsed; + rt_uint32_t biClrImportant; }; -#ifdef _WIN32 +#ifdef _WIN32_NATIVE #pragma warning(disable : 4103) #endif void rtgui_image_bmp_init(void); diff --git a/components/rtgui/include/rtgui/image_container.h b/components/rtgui/include/rtgui/image_container.h index fe7367abb7..4fb3616cea 100644 --- a/components/rtgui/include/rtgui/image_container.h +++ b/components/rtgui/include/rtgui/image_container.h @@ -8,20 +8,20 @@ /* image item in image container */ struct rtgui_image_item { - rtgui_image_t *image; - char *filename; + rtgui_image_t *image; + char *filename; - rt_uint32_t refcount; + rt_uint32_t refcount; }; typedef struct rtgui_image_item rtgui_image_item_t; void rtgui_system_image_container_init(rt_bool_t load); -#ifdef RTGUI_USING_DFS_FILERW -rtgui_image_item_t* rtgui_image_container_get(const char* filename); +#ifdef RTGUI_USING_DFS_FILERW +rtgui_image_item_t *rtgui_image_container_get(const char *filename); #endif -rtgui_image_item_t* rtgui_image_container_get_from_mem(const rt_uint8_t* mem, const char* type, rt_uint32_t len); +rtgui_image_item_t *rtgui_image_container_get_from_mem(const rt_uint8_t *mem, const char *type, rt_uint32_t len); -void rtgui_image_container_put(rtgui_image_item_t* item); +void rtgui_image_container_put(rtgui_image_item_t *item); #endif #endif diff --git a/components/rtgui/include/rtgui/image_hdc.h b/components/rtgui/include/rtgui/image_hdc.h index 122a6a3313..3ec1e7b1ef 100644 --- a/components/rtgui/include/rtgui/image_hdc.h +++ b/components/rtgui/include/rtgui/image_hdc.h @@ -18,20 +18,20 @@ struct rtgui_image_hdcmm { - struct rtgui_image parent; + struct rtgui_image parent; - /* hdc image information */ - rt_uint16_t byte_per_pixel; + /* hdc image information */ + rt_uint16_t byte_per_pixel; rt_uint16_t pitch; - rt_uint8_t *pixels; + rt_uint8_t *pixels; }; void rtgui_image_hdc_init(void); extern const struct rtgui_image_engine rtgui_image_hdcmm_engine; -#define HDC_HEADER_SIZE (5 * 4) -#define RTGUI_IMAGE_HDC_DEF(bpp, w, h, pixels) \ - {{w, h, &rtgui_image_hdcmm_engine, RT_NULL}, bpp, (bpp * w), ((rt_uint8_t*)pixels + HDC_HEADER_SIZE)} +#define HDC_HEADER_SIZE (5 * 4) +#define RTGUI_IMAGE_HDC_DEF(bpp, w, h, pixels) \ + {{w, h, &rtgui_image_hdcmm_engine, RT_NULL}, bpp, (bpp * w), ((rt_uint8_t*)pixels + HDC_HEADER_SIZE)} #endif diff --git a/components/rtgui/include/rtgui/kbddef.h b/components/rtgui/include/rtgui/kbddef.h index 7a97e7f990..d510445f0a 100644 --- a/components/rtgui/include/rtgui/kbddef.h +++ b/components/rtgui/include/rtgui/kbddef.h @@ -17,277 +17,279 @@ /* The keyboard key have been cleverly chosen to map to ASCII */ typedef enum { - RTGUIK_UNKNOWN = 0, - RTGUIK_FIRST = 0, - RTGUIK_BACKSPACE = 8, - RTGUIK_TAB = 9, - RTGUIK_CLEAR = 12, - RTGUIK_RETURN = 13, - RTGUIK_PAUSE = 19, - RTGUIK_ESCAPE = 27, - RTGUIK_SPACE = 32, - RTGUIK_EXCLAIM = 33, - RTGUIK_QUOTEDBL = 34, - RTGUIK_HASH = 35, - RTGUIK_DOLLAR = 36, - RTGUIK_AMPERSAND = 38, - RTGUIK_QUOTE = 39, - RTGUIK_LEFTPAREN = 40, - RTGUIK_RIGHTPAREN = 41, - RTGUIK_ASTERISK = 42, - RTGUIK_PLUS = 43, - RTGUIK_COMMA = 44, - RTGUIK_MINUS = 45, - RTGUIK_PERIOD = 46, - RTGUIK_SLASH = 47, - RTGUIK_0 = 48, - RTGUIK_1 = 49, - RTGUIK_2 = 50, - RTGUIK_3 = 51, - RTGUIK_4 = 52, - RTGUIK_5 = 53, - RTGUIK_6 = 54, - RTGUIK_7 = 55, - RTGUIK_8 = 56, - RTGUIK_9 = 57, - RTGUIK_COLON = 58, - RTGUIK_SEMICOLON = 59, - RTGUIK_LESS = 60, - RTGUIK_EQUALS = 61, - RTGUIK_GREATER = 62, - RTGUIK_QUESTION = 63, - RTGUIK_AT = 64, + RTGUIK_UNKNOWN = 0, + RTGUIK_FIRST = 0, + RTGUIK_BACKSPACE = 8, + RTGUIK_TAB = 9, + RTGUIK_CLEAR = 12, + RTGUIK_RETURN = 13, + RTGUIK_PAUSE = 19, + RTGUIK_ESCAPE = 27, + RTGUIK_SPACE = 32, + RTGUIK_EXCLAIM = 33, + RTGUIK_QUOTEDBL = 34, + RTGUIK_HASH = 35, + RTGUIK_DOLLAR = 36, + RTGUIK_AMPERSAND = 38, + RTGUIK_QUOTE = 39, + RTGUIK_LEFTPAREN = 40, + RTGUIK_RIGHTPAREN = 41, + RTGUIK_ASTERISK = 42, + RTGUIK_PLUS = 43, + RTGUIK_COMMA = 44, + RTGUIK_MINUS = 45, + RTGUIK_PERIOD = 46, + RTGUIK_SLASH = 47, + RTGUIK_0 = 48, + RTGUIK_1 = 49, + RTGUIK_2 = 50, + RTGUIK_3 = 51, + RTGUIK_4 = 52, + RTGUIK_5 = 53, + RTGUIK_6 = 54, + RTGUIK_7 = 55, + RTGUIK_8 = 56, + RTGUIK_9 = 57, + RTGUIK_COLON = 58, + RTGUIK_SEMICOLON = 59, + RTGUIK_LESS = 60, + RTGUIK_EQUALS = 61, + RTGUIK_GREATER = 62, + RTGUIK_QUESTION = 63, + RTGUIK_AT = 64, - /* - Skip uppercase letters - */ - RTGUIK_LEFTBRACKET = 91, - RTGUIK_BACKSLASH = 92, - RTGUIK_RIGHTBRACKET = 93, - RTGUIK_CARET = 94, - RTGUIK_UNDERSCORE = 95, - RTGUIK_BACKQUOTE = 96, - RTGUIK_a = 97, - RTGUIK_b = 98, - RTGUIK_c = 99, - RTGUIK_d = 100, - RTGUIK_e = 101, - RTGUIK_f = 102, - RTGUIK_g = 103, - RTGUIK_h = 104, - RTGUIK_i = 105, - RTGUIK_j = 106, - RTGUIK_k = 107, - RTGUIK_l = 108, - RTGUIK_m = 109, - RTGUIK_n = 110, - RTGUIK_o = 111, - RTGUIK_p = 112, - RTGUIK_q = 113, - RTGUIK_r = 114, - RTGUIK_s = 115, - RTGUIK_t = 116, - RTGUIK_u = 117, - RTGUIK_v = 118, - RTGUIK_w = 119, - RTGUIK_x = 120, - RTGUIK_y = 121, - RTGUIK_z = 122, - RTGUIK_DELETE = 127, + /* + Skip uppercase letters + */ + RTGUIK_LEFTBRACKET = 91, + RTGUIK_BACKSLASH = 92, + RTGUIK_RIGHTBRACKET = 93, + RTGUIK_CARET = 94, + RTGUIK_UNDERSCORE = 95, + RTGUIK_BACKQUOTE = 96, + RTGUIK_a = 97, + RTGUIK_b = 98, + RTGUIK_c = 99, + RTGUIK_d = 100, + RTGUIK_e = 101, + RTGUIK_f = 102, + RTGUIK_g = 103, + RTGUIK_h = 104, + RTGUIK_i = 105, + RTGUIK_j = 106, + RTGUIK_k = 107, + RTGUIK_l = 108, + RTGUIK_m = 109, + RTGUIK_n = 110, + RTGUIK_o = 111, + RTGUIK_p = 112, + RTGUIK_q = 113, + RTGUIK_r = 114, + RTGUIK_s = 115, + RTGUIK_t = 116, + RTGUIK_u = 117, + RTGUIK_v = 118, + RTGUIK_w = 119, + RTGUIK_x = 120, + RTGUIK_y = 121, + RTGUIK_z = 122, + RTGUIK_DELETE = 127, - /* International keyboard */ - RTGUIK_WORLD_0 = 160, /* 0xA0 */ - RTGUIK_WORLD_1 = 161, - RTGUIK_WORLD_2 = 162, - RTGUIK_WORLD_3 = 163, - RTGUIK_WORLD_4 = 164, - RTGUIK_WORLD_5 = 165, - RTGUIK_WORLD_6 = 166, - RTGUIK_WORLD_7 = 167, - RTGUIK_WORLD_8 = 168, - RTGUIK_WORLD_9 = 169, - RTGUIK_WORLD_10 = 170, - RTGUIK_WORLD_11 = 171, - RTGUIK_WORLD_12 = 172, - RTGUIK_WORLD_13 = 173, - RTGUIK_WORLD_14 = 174, - RTGUIK_WORLD_15 = 175, - RTGUIK_WORLD_16 = 176, - RTGUIK_WORLD_17 = 177, - RTGUIK_WORLD_18 = 178, - RTGUIK_WORLD_19 = 179, - RTGUIK_WORLD_20 = 180, - RTGUIK_WORLD_21 = 181, - RTGUIK_WORLD_22 = 182, - RTGUIK_WORLD_23 = 183, - RTGUIK_WORLD_24 = 184, - RTGUIK_WORLD_25 = 185, - RTGUIK_WORLD_26 = 186, - RTGUIK_WORLD_27 = 187, - RTGUIK_WORLD_28 = 188, - RTGUIK_WORLD_29 = 189, - RTGUIK_WORLD_30 = 190, - RTGUIK_WORLD_31 = 191, - RTGUIK_WORLD_32 = 192, - RTGUIK_WORLD_33 = 193, - RTGUIK_WORLD_34 = 194, - RTGUIK_WORLD_35 = 195, - RTGUIK_WORLD_36 = 196, - RTGUIK_WORLD_37 = 197, - RTGUIK_WORLD_38 = 198, - RTGUIK_WORLD_39 = 199, - RTGUIK_WORLD_40 = 200, - RTGUIK_WORLD_41 = 201, - RTGUIK_WORLD_42 = 202, - RTGUIK_WORLD_43 = 203, - RTGUIK_WORLD_44 = 204, - RTGUIK_WORLD_45 = 205, - RTGUIK_WORLD_46 = 206, - RTGUIK_WORLD_47 = 207, - RTGUIK_WORLD_48 = 208, - RTGUIK_WORLD_49 = 209, - RTGUIK_WORLD_50 = 210, - RTGUIK_WORLD_51 = 211, - RTGUIK_WORLD_52 = 212, - RTGUIK_WORLD_53 = 213, - RTGUIK_WORLD_54 = 214, - RTGUIK_WORLD_55 = 215, - RTGUIK_WORLD_56 = 216, - RTGUIK_WORLD_57 = 217, - RTGUIK_WORLD_58 = 218, - RTGUIK_WORLD_59 = 219, - RTGUIK_WORLD_60 = 220, - RTGUIK_WORLD_61 = 221, - RTGUIK_WORLD_62 = 222, - RTGUIK_WORLD_63 = 223, - RTGUIK_WORLD_64 = 224, - RTGUIK_WORLD_65 = 225, - RTGUIK_WORLD_66 = 226, - RTGUIK_WORLD_67 = 227, - RTGUIK_WORLD_68 = 228, - RTGUIK_WORLD_69 = 229, - RTGUIK_WORLD_70 = 230, - RTGUIK_WORLD_71 = 231, - RTGUIK_WORLD_72 = 232, - RTGUIK_WORLD_73 = 233, - RTGUIK_WORLD_74 = 234, - RTGUIK_WORLD_75 = 235, - RTGUIK_WORLD_76 = 236, - RTGUIK_WORLD_77 = 237, - RTGUIK_WORLD_78 = 238, - RTGUIK_WORLD_79 = 239, - RTGUIK_WORLD_80 = 240, - RTGUIK_WORLD_81 = 241, - RTGUIK_WORLD_82 = 242, - RTGUIK_WORLD_83 = 243, - RTGUIK_WORLD_84 = 244, - RTGUIK_WORLD_85 = 245, - RTGUIK_WORLD_86 = 246, - RTGUIK_WORLD_87 = 247, - RTGUIK_WORLD_88 = 248, - RTGUIK_WORLD_89 = 249, - RTGUIK_WORLD_90 = 250, - RTGUIK_WORLD_91 = 251, - RTGUIK_WORLD_92 = 252, - RTGUIK_WORLD_93 = 253, - RTGUIK_WORLD_94 = 254, - RTGUIK_WORLD_95 = 255, /* 0xFF */ + /* International keyboard */ + RTGUIK_WORLD_0 = 160, /* 0xA0 */ + RTGUIK_WORLD_1 = 161, + RTGUIK_WORLD_2 = 162, + RTGUIK_WORLD_3 = 163, + RTGUIK_WORLD_4 = 164, + RTGUIK_WORLD_5 = 165, + RTGUIK_WORLD_6 = 166, + RTGUIK_WORLD_7 = 167, + RTGUIK_WORLD_8 = 168, + RTGUIK_WORLD_9 = 169, + RTGUIK_WORLD_10 = 170, + RTGUIK_WORLD_11 = 171, + RTGUIK_WORLD_12 = 172, + RTGUIK_WORLD_13 = 173, + RTGUIK_WORLD_14 = 174, + RTGUIK_WORLD_15 = 175, + RTGUIK_WORLD_16 = 176, + RTGUIK_WORLD_17 = 177, + RTGUIK_WORLD_18 = 178, + RTGUIK_WORLD_19 = 179, + RTGUIK_WORLD_20 = 180, + RTGUIK_WORLD_21 = 181, + RTGUIK_WORLD_22 = 182, + RTGUIK_WORLD_23 = 183, + RTGUIK_WORLD_24 = 184, + RTGUIK_WORLD_25 = 185, + RTGUIK_WORLD_26 = 186, + RTGUIK_WORLD_27 = 187, + RTGUIK_WORLD_28 = 188, + RTGUIK_WORLD_29 = 189, + RTGUIK_WORLD_30 = 190, + RTGUIK_WORLD_31 = 191, + RTGUIK_WORLD_32 = 192, + RTGUIK_WORLD_33 = 193, + RTGUIK_WORLD_34 = 194, + RTGUIK_WORLD_35 = 195, + RTGUIK_WORLD_36 = 196, + RTGUIK_WORLD_37 = 197, + RTGUIK_WORLD_38 = 198, + RTGUIK_WORLD_39 = 199, + RTGUIK_WORLD_40 = 200, + RTGUIK_WORLD_41 = 201, + RTGUIK_WORLD_42 = 202, + RTGUIK_WORLD_43 = 203, + RTGUIK_WORLD_44 = 204, + RTGUIK_WORLD_45 = 205, + RTGUIK_WORLD_46 = 206, + RTGUIK_WORLD_47 = 207, + RTGUIK_WORLD_48 = 208, + RTGUIK_WORLD_49 = 209, + RTGUIK_WORLD_50 = 210, + RTGUIK_WORLD_51 = 211, + RTGUIK_WORLD_52 = 212, + RTGUIK_WORLD_53 = 213, + RTGUIK_WORLD_54 = 214, + RTGUIK_WORLD_55 = 215, + RTGUIK_WORLD_56 = 216, + RTGUIK_WORLD_57 = 217, + RTGUIK_WORLD_58 = 218, + RTGUIK_WORLD_59 = 219, + RTGUIK_WORLD_60 = 220, + RTGUIK_WORLD_61 = 221, + RTGUIK_WORLD_62 = 222, + RTGUIK_WORLD_63 = 223, + RTGUIK_WORLD_64 = 224, + RTGUIK_WORLD_65 = 225, + RTGUIK_WORLD_66 = 226, + RTGUIK_WORLD_67 = 227, + RTGUIK_WORLD_68 = 228, + RTGUIK_WORLD_69 = 229, + RTGUIK_WORLD_70 = 230, + RTGUIK_WORLD_71 = 231, + RTGUIK_WORLD_72 = 232, + RTGUIK_WORLD_73 = 233, + RTGUIK_WORLD_74 = 234, + RTGUIK_WORLD_75 = 235, + RTGUIK_WORLD_76 = 236, + RTGUIK_WORLD_77 = 237, + RTGUIK_WORLD_78 = 238, + RTGUIK_WORLD_79 = 239, + RTGUIK_WORLD_80 = 240, + RTGUIK_WORLD_81 = 241, + RTGUIK_WORLD_82 = 242, + RTGUIK_WORLD_83 = 243, + RTGUIK_WORLD_84 = 244, + RTGUIK_WORLD_85 = 245, + RTGUIK_WORLD_86 = 246, + RTGUIK_WORLD_87 = 247, + RTGUIK_WORLD_88 = 248, + RTGUIK_WORLD_89 = 249, + RTGUIK_WORLD_90 = 250, + RTGUIK_WORLD_91 = 251, + RTGUIK_WORLD_92 = 252, + RTGUIK_WORLD_93 = 253, + RTGUIK_WORLD_94 = 254, + RTGUIK_WORLD_95 = 255, /* 0xFF */ - /* Numeric keypad */ - RTGUIK_KP0 = 256, - RTGUIK_KP1 = 257, - RTGUIK_KP2 = 258, - RTGUIK_KP3 = 259, - RTGUIK_KP4 = 260, - RTGUIK_KP5 = 261, - RTGUIK_KP6 = 262, - RTGUIK_KP7 = 263, - RTGUIK_KP8 = 264, - RTGUIK_KP9 = 265, - RTGUIK_KP_PERIOD = 266, - RTGUIK_KP_DIVIDE = 267, - RTGUIK_KP_MULTIPLY = 268, - RTGUIK_KP_MINUS = 269, - RTGUIK_KP_PLUS = 270, - RTGUIK_KP_ENTER = 271, - RTGUIK_KP_EQUALS = 272, + /* Numeric keypad */ + RTGUIK_KP0 = 256, + RTGUIK_KP1 = 257, + RTGUIK_KP2 = 258, + RTGUIK_KP3 = 259, + RTGUIK_KP4 = 260, + RTGUIK_KP5 = 261, + RTGUIK_KP6 = 262, + RTGUIK_KP7 = 263, + RTGUIK_KP8 = 264, + RTGUIK_KP9 = 265, + RTGUIK_KP_PERIOD = 266, + RTGUIK_KP_DIVIDE = 267, + RTGUIK_KP_MULTIPLY = 268, + RTGUIK_KP_MINUS = 269, + RTGUIK_KP_PLUS = 270, + RTGUIK_KP_ENTER = 271, + RTGUIK_KP_EQUALS = 272, - /* Arrows + Home/End pad */ - RTGUIK_UP = 273, - RTGUIK_DOWN = 274, - RTGUIK_RIGHT = 275, - RTGUIK_LEFT = 276, - RTGUIK_INSERT = 277, - RTGUIK_HOME = 278, - RTGUIK_END = 279, - RTGUIK_PAGEUP = 280, - RTGUIK_PAGEDOWN = 281, + /* Arrows + Home/End pad */ + RTGUIK_UP = 273, + RTGUIK_DOWN = 274, + RTGUIK_RIGHT = 275, + RTGUIK_LEFT = 276, + RTGUIK_INSERT = 277, + RTGUIK_HOME = 278, + RTGUIK_END = 279, + RTGUIK_PAGEUP = 280, + RTGUIK_PAGEDOWN = 281, - /* Function keys */ - RTGUIK_F1 = 282, - RTGUIK_F2 = 283, - RTGUIK_F3 = 284, - RTGUIK_F4 = 285, - RTGUIK_F5 = 286, - RTGUIK_F6 = 287, - RTGUIK_F7 = 288, - RTGUIK_F8 = 289, - RTGUIK_F9 = 290, - RTGUIK_F10 = 291, - RTGUIK_F11 = 292, - RTGUIK_F12 = 293, - RTGUIK_F13 = 294, - RTGUIK_F14 = 295, - RTGUIK_F15 = 296, + /* Function keys */ + RTGUIK_F1 = 282, + RTGUIK_F2 = 283, + RTGUIK_F3 = 284, + RTGUIK_F4 = 285, + RTGUIK_F5 = 286, + RTGUIK_F6 = 287, + RTGUIK_F7 = 288, + RTGUIK_F8 = 289, + RTGUIK_F9 = 290, + RTGUIK_F10 = 291, + RTGUIK_F11 = 292, + RTGUIK_F12 = 293, + RTGUIK_F13 = 294, + RTGUIK_F14 = 295, + RTGUIK_F15 = 296, - /* Key state modifier keys */ - RTGUIK_NUMLOCK = 300, - RTGUIK_CAPSLOCK = 301, - RTGUIK_SCROLLOCK = 302, - RTGUIK_RSHIFT = 303, - RTGUIK_LSHIFT = 304, - RTGUIK_RCTRL = 305, - RTGUIK_LCTRL = 306, - RTGUIK_RALT = 307, - RTGUIK_LALT = 308, - RTGUIK_RMETA = 309, - RTGUIK_LMETA = 310, - RTGUIK_LSUPER = 311, /* Left "Windows" key */ - RTGUIK_RSUPER = 312, /* Right "Windows" key */ - RTGUIK_MODE = 313, /* "Alt Gr" key */ - RTGUIK_COMPOSE = 314, /* Multi-key compose key */ + /* Key state modifier keys */ + RTGUIK_NUMLOCK = 300, + RTGUIK_CAPSLOCK = 301, + RTGUIK_SCROLLOCK = 302, + RTGUIK_RSHIFT = 303, + RTGUIK_LSHIFT = 304, + RTGUIK_RCTRL = 305, + RTGUIK_LCTRL = 306, + RTGUIK_RALT = 307, + RTGUIK_LALT = 308, + RTGUIK_RMETA = 309, + RTGUIK_LMETA = 310, + RTGUIK_LSUPER = 311, /* Left "Windows" key */ + RTGUIK_RSUPER = 312, /* Right "Windows" key */ + RTGUIK_MODE = 313, /* "Alt Gr" key */ + RTGUIK_COMPOSE = 314, /* Multi-key compose key */ - /* Miscellaneous function keys */ - RTGUIK_HELP = 315, - RTGUIK_PRINT = 316, - RTGUIK_SYSREQ = 317, - RTGUIK_BREAK = 318, - RTGUIK_MENU = 319, - RTGUIK_POWER = 320, /* Power key */ + /* Miscellaneous function keys */ + RTGUIK_HELP = 315, + RTGUIK_PRINT = 316, + RTGUIK_SYSREQ = 317, + RTGUIK_BREAK = 318, + RTGUIK_MENU = 319, + RTGUIK_POWER = 320, /* Power key */ - RTGUIK_LAST + RTGUIK_LAST } RTGUI_KBD_KEY; /* Enumeration of valid key mods (possibly OR'd together) */ -typedef enum { - RTGUI_KMOD_NONE = 0x0000, - RTGUI_KMOD_LSHIFT = 0x0001, - RTGUI_KMOD_RSHIFT = 0x0002, - RTGUI_KMOD_LCTRL = 0x0040, - RTGUI_KMOD_RCTRL = 0x0080, - RTGUI_KMOD_LALT = 0x0100, - RTGUI_KMOD_RALT = 0x0200, - RTGUI_KMOD_LMETA = 0x0400, - RTGUI_KMOD_RMETA = 0x0800, - RTGUI_KMOD_NUM = 0x1000, - RTGUI_KMOD_CAPS = 0x2000, - RTGUI_KMOD_MODE = 0x4000, - RTGUI_KMOD_RESERVED = 0x8000 +typedef enum +{ + RTGUI_KMOD_NONE = 0x0000, + RTGUI_KMOD_LSHIFT = 0x0001, + RTGUI_KMOD_RSHIFT = 0x0002, + RTGUI_KMOD_LCTRL = 0x0040, + RTGUI_KMOD_RCTRL = 0x0080, + RTGUI_KMOD_LALT = 0x0100, + RTGUI_KMOD_RALT = 0x0200, + RTGUI_KMOD_LMETA = 0x0400, + RTGUI_KMOD_RMETA = 0x0800, + RTGUI_KMOD_NUM = 0x1000, + RTGUI_KMOD_CAPS = 0x2000, + RTGUI_KMOD_MODE = 0x4000, + RTGUI_KMOD_RESERVED = 0x8000 } RTGUI_KBD_MOD; -typedef enum { - RTGUI_KEYDOWN, /* Keys pressed */ - RTGUI_KEYUP, /* Keys released */ +typedef enum +{ + RTGUI_KEYDOWN, /* Keys pressed */ + RTGUI_KEYUP, /* Keys released */ } RTGUI_KBD_TYPE; #endif diff --git a/components/rtgui/include/rtgui/list.h b/components/rtgui/include/rtgui/list.h index bead36be39..20b3957181 100644 --- a/components/rtgui/include/rtgui/list.h +++ b/components/rtgui/include/rtgui/list.h @@ -18,49 +18,49 @@ struct rtgui_list_node { - struct rtgui_list_node* next; + struct rtgui_list_node *next; }; typedef struct rtgui_list_node rtgui_list_t; rt_inline void rtgui_list_init(rtgui_list_t *l) { - l->next = (struct rtgui_list_node *)0; + l->next = (struct rtgui_list_node *)0; } rt_inline void rtgui_list_append(rtgui_list_t *l, rtgui_list_t *n) { - struct rtgui_list_node* node; + struct rtgui_list_node *node; - node = l; - while (node->next) node = node->next; + node = l; + while (node->next) node = node->next; - /* append the node to the tail */ - node->next = n; - n->next = (struct rtgui_list_node*) 0; + /* append the node to the tail */ + node->next = n; + n->next = (struct rtgui_list_node *) 0; } rt_inline void rtgui_list_insert(rtgui_list_t *l, rtgui_list_t *n) { - n->next = l->next; - l->next = n; + n->next = l->next; + l->next = n; } -rt_inline rtgui_list_t* rtgui_list_remove(rtgui_list_t *l, rtgui_list_t *n) +rt_inline rtgui_list_t *rtgui_list_remove(rtgui_list_t *l, rtgui_list_t *n) { - /* remove slist head */ - struct rtgui_list_node* node = l; - while (node->next && node->next != n) node = node->next; + /* remove slist head */ + struct rtgui_list_node *node = l; + while (node->next && node->next != n) node = node->next; - /* remove node */ - if (node->next != (rtgui_list_t *)0) node->next = node->next->next; + /* remove node */ + if (node->next != (rtgui_list_t *)0) node->next = node->next->next; - return l; + return l; } -#define rtgui_list_entry(node, type, member) \ - ((type *)((char*)(node)-(unsigned long)(&((type *)0)->member))) +#define rtgui_list_entry(node, type, member) \ + ((type *)((char*)(node)-(unsigned long)(&((type *)0)->member))) -#define rtgui_list_foreach(node, list) \ - for ((node) = (list)->next; (node) != RT_NULL; (node) = (node)->next) +#define rtgui_list_foreach(node, list) \ + for ((node) = (list)->next; (node) != RT_NULL; (node) = (node)->next) #endif diff --git a/components/rtgui/include/rtgui/region.h b/components/rtgui/include/rtgui/region.h index 70041e526c..42a78b8da4 100644 --- a/components/rtgui/include/rtgui/region.h +++ b/components/rtgui/include/rtgui/region.h @@ -20,81 +20,81 @@ extern "C" { #endif -typedef struct rtgui_region_data rtgui_region_data_t; + typedef struct rtgui_region_data rtgui_region_data_t; -struct rtgui_region_data -{ - rt_uint32_t size; - rt_uint32_t numRects; - /* XXX: And why, exactly, do we have this bogus struct definition? */ - /* rtgui_rect_t rects[size]; in memory but not explicitly declared */ -}; + struct rtgui_region_data + { + rt_uint32_t size; + rt_uint32_t numRects; + /* XXX: And why, exactly, do we have this bogus struct definition? */ + /* rtgui_rect_t rects[size]; in memory but not explicitly declared */ + }; -typedef struct rtgui_region -{ - rtgui_rect_t extents; - rtgui_region_data_t *data; -}rtgui_region_t; + typedef struct rtgui_region + { + rtgui_rect_t extents; + rtgui_region_data_t *data; + } rtgui_region_t; -typedef enum -{ - RTGUI_REGION_STATUS_FAILURE, - RTGUI_REGION_STATUS_SUCCESS -}rtgui_region_status_t; + typedef enum + { + RTGUI_REGION_STATUS_FAILURE, + RTGUI_REGION_STATUS_SUCCESS + } rtgui_region_status_t; -/* creation/destruction */ + /* creation/destruction */ -void rtgui_region_init(rtgui_region_t *region); -void rtgui_region_init_rect(rtgui_region_t *region, - int x, int y, unsigned int width, unsigned int height); -void rtgui_region_init_with_extents(rtgui_region_t *region, const rtgui_rect_t *extents); -void rtgui_region_fini (rtgui_region_t *region); + void rtgui_region_init(rtgui_region_t *region); + void rtgui_region_init_rect(rtgui_region_t *region, + int x, int y, unsigned int width, unsigned int height); + void rtgui_region_init_with_extents(rtgui_region_t *region, const rtgui_rect_t *extents); + void rtgui_region_fini(rtgui_region_t *region); -void rtgui_region_translate (rtgui_region_t *region, int x, int y); + void rtgui_region_translate(rtgui_region_t *region, int x, int y); -rtgui_region_status_t rtgui_region_copy (rtgui_region_t *dest, rtgui_region_t *source); + rtgui_region_status_t rtgui_region_copy(rtgui_region_t *dest, rtgui_region_t *source); -rtgui_region_status_t rtgui_region_intersect (rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_region_t *reg2); -rtgui_region_status_t rtgui_region_intersect_rect (rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_rect_t *rect); -rtgui_region_status_t rtgui_region_union (rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_region_t *reg2); -rtgui_region_status_t rtgui_region_union_rect(rtgui_region_t *dest, rtgui_region_t *source, rtgui_rect_t* rect); -rtgui_region_status_t rtgui_region_subtract (rtgui_region_t *regD, rtgui_region_t *regM, rtgui_region_t *regS); -rtgui_region_status_t rtgui_region_subtract_rect (rtgui_region_t *regD, rtgui_region_t *regM, rtgui_rect_t* rect); -rtgui_region_status_t rtgui_region_inverse (rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_rect_t *invRect); + rtgui_region_status_t rtgui_region_intersect(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_region_t *reg2); + rtgui_region_status_t rtgui_region_intersect_rect(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_rect_t *rect); + rtgui_region_status_t rtgui_region_union(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_region_t *reg2); + rtgui_region_status_t rtgui_region_union_rect(rtgui_region_t *dest, rtgui_region_t *source, rtgui_rect_t *rect); + rtgui_region_status_t rtgui_region_subtract(rtgui_region_t *regD, rtgui_region_t *regM, rtgui_region_t *regS); + rtgui_region_status_t rtgui_region_subtract_rect(rtgui_region_t *regD, rtgui_region_t *regM, rtgui_rect_t *rect); + rtgui_region_status_t rtgui_region_inverse(rtgui_region_t *newReg, rtgui_region_t *reg1, rtgui_rect_t *invRect); -int rtgui_region_num_rects (rtgui_region_t *region); + int rtgui_region_num_rects(rtgui_region_t *region); -rtgui_rect_t* rtgui_region_rects (rtgui_region_t *region); + rtgui_rect_t *rtgui_region_rects(rtgui_region_t *region); -#define RTGUI_REGION_OUT 0 -#define RTGUI_REGION_IN 1 -#define RTGUI_REGION_PART 2 +#define RTGUI_REGION_OUT 0 +#define RTGUI_REGION_IN 1 +#define RTGUI_REGION_PART 2 -int rtgui_region_contains_point (rtgui_region_t *region, int x, int y, rtgui_rect_t *box); -int rtgui_region_contains_rectangle (rtgui_region_t *rtgui_region_t, rtgui_rect_t *prect); + int rtgui_region_contains_point(rtgui_region_t *region, int x, int y, rtgui_rect_t *box); + int rtgui_region_contains_rectangle(rtgui_region_t *rtgui_region_t, rtgui_rect_t *prect); -int rtgui_region_not_empty (rtgui_region_t *region); -rtgui_rect_t *rtgui_region_extents (rtgui_region_t *region); + int rtgui_region_not_empty(rtgui_region_t *region); + rtgui_rect_t *rtgui_region_extents(rtgui_region_t *region); -rtgui_region_status_t rtgui_region_append (rtgui_region_t *dest, rtgui_region_t *region); -rtgui_region_status_t rtgui_region_validate (rtgui_region_t *badreg, int *pOverlap); + rtgui_region_status_t rtgui_region_append(rtgui_region_t *dest, rtgui_region_t *region); + rtgui_region_status_t rtgui_region_validate(rtgui_region_t *badreg, int *pOverlap); -void rtgui_region_reset(rtgui_region_t *region, rtgui_rect_t* rect); -void rtgui_region_empty (rtgui_region_t *region); -void rtgui_region_dump(rtgui_region_t* region); -int rtgui_region_is_flat(rtgui_region_t* region); + void rtgui_region_reset(rtgui_region_t *region, rtgui_rect_t *rect); + void rtgui_region_empty(rtgui_region_t *region); + void rtgui_region_dump(rtgui_region_t *region); + int rtgui_region_is_flat(rtgui_region_t *region); -/* rect functions */ -extern rtgui_rect_t rtgui_empty_rect; + /* rect functions */ + extern rtgui_rect_t rtgui_empty_rect; -void rtgui_rect_moveto(rtgui_rect_t *rect, int x, int y); -void rtgui_rect_moveto_align(rtgui_rect_t *rect, rtgui_rect_t *to, int align); -void rtgui_rect_inflate(rtgui_rect_t *rect, int d); -void rtgui_rect_intersect(rtgui_rect_t *src, rtgui_rect_t *dest); -int rtgui_rect_contains_point(const rtgui_rect_t *rect, int x, int y); -int rtgui_rect_is_intersect(const rtgui_rect_t *rect1, const rtgui_rect_t *rect2); -int rtgui_rect_is_equal(const rtgui_rect_t *rect1, const rtgui_rect_t *rect2); -rt_bool_t rtgui_rect_is_empty(const rtgui_rect_t *rect); + void rtgui_rect_moveto(rtgui_rect_t *rect, int x, int y); + void rtgui_rect_moveto_align(rtgui_rect_t *rect, rtgui_rect_t *to, int align); + void rtgui_rect_inflate(rtgui_rect_t *rect, int d); + void rtgui_rect_intersect(rtgui_rect_t *src, rtgui_rect_t *dest); + int rtgui_rect_contains_point(const rtgui_rect_t *rect, int x, int y); + int rtgui_rect_is_intersect(const rtgui_rect_t *rect1, const rtgui_rect_t *rect2); + int rtgui_rect_is_equal(const rtgui_rect_t *rect1, const rtgui_rect_t *rect2); + rt_bool_t rtgui_rect_is_empty(const rtgui_rect_t *rect); #if defined(__cplusplus) || defined(c_plusplus) } diff --git a/components/rtgui/include/rtgui/rtgui.h b/components/rtgui/include/rtgui/rtgui.h index f03a94c916..066262d34c 100644 --- a/components/rtgui/include/rtgui/rtgui.h +++ b/components/rtgui/include/rtgui/rtgui.h @@ -17,9 +17,9 @@ #include <rtthread.h> #include <rtgui/rtgui_config.h> -#define RT_INT16_MAX 32767 -#define RT_INT16_MIN (-RT_INT16_MAX-1) -#define RTGUI_NOT_FOUND (-1) +#define RT_INT16_MAX 32767 +#define RT_INT16_MIN (-RT_INT16_MAX-1) +#define RTGUI_NOT_FOUND (-1) struct rtgui_event; @@ -29,15 +29,15 @@ struct rtgui_win; struct rtgui_font; typedef struct rtgui_win rtgui_win_t; -typedef rt_bool_t (*rtgui_event_handler_ptr)(struct rtgui_object* object, struct rtgui_event* event); -typedef void (*rtgui_onbutton_func_t)(struct rtgui_object* object, struct rtgui_event* event); +typedef rt_bool_t (*rtgui_event_handler_ptr)(struct rtgui_object *object, struct rtgui_event *event); +typedef void (*rtgui_onbutton_func_t)(struct rtgui_object *object, struct rtgui_event *event); /** * Coordinate point */ struct rtgui_point { - rt_int16_t x, y; + rt_int16_t x, y; }; typedef struct rtgui_point rtgui_point_t; extern rtgui_point_t rtgui_empty_point; @@ -47,11 +47,11 @@ extern rtgui_point_t rtgui_empty_point; */ struct rtgui_rect { - rt_int16_t x1, y1, x2, y2; + rt_int16_t x1, y1, x2, y2; }; typedef struct rtgui_rect rtgui_rect_t; -#define rtgui_rect_width(r) ((r).x2 - (r).x1) -#define rtgui_rect_height(r) ((r).y2 - (r).y1) +#define rtgui_rect_width(r) ((r).x2 - (r).x1) +#define rtgui_rect_height(r) ((r).y2 - (r).y1) typedef unsigned long rtgui_color_t; @@ -60,82 +60,82 @@ typedef unsigned long rtgui_color_t; */ struct rtgui_gc { - /* foreground and background color */ - rtgui_color_t foreground, background; + /* foreground and background color */ + rtgui_color_t foreground, background; - /* text style */ - rt_uint16_t textstyle; - /* text align */ - rt_uint16_t textalign; + /* text style */ + rt_uint16_t textstyle; + /* text align */ + rt_uint16_t textalign; - /* font */ - struct rtgui_font* font; + /* font */ + struct rtgui_font *font; }; typedef struct rtgui_gc rtgui_gc_t; enum RTGUI_MARGIN_STYLE { - RTGUI_MARGIN_LEFT = 0x01, - RTGUI_MARGIN_RIGHT = 0x02, - RTGUI_MARGIN_TOP = 0x04, - RTGUI_MARGIN_BOTTOM = 0x08, - RTGUI_MARGIN_ALL = RTGUI_MARGIN_LEFT | RTGUI_MARGIN_RIGHT | RTGUI_MARGIN_TOP | RTGUI_MARGIN_BOTTOM + RTGUI_MARGIN_LEFT = 0x01, + RTGUI_MARGIN_RIGHT = 0x02, + RTGUI_MARGIN_TOP = 0x04, + RTGUI_MARGIN_BOTTOM = 0x08, + RTGUI_MARGIN_ALL = RTGUI_MARGIN_LEFT | RTGUI_MARGIN_RIGHT | RTGUI_MARGIN_TOP | RTGUI_MARGIN_BOTTOM }; /** - * Border style + * Border style */ enum RTGUI_BORDER_STYLE { - RTGUI_BORDER_NONE = 0, - RTGUI_BORDER_SIMPLE, - RTGUI_BORDER_RAISE, - RTGUI_BORDER_SUNKEN, - RTGUI_BORDER_BOX, - RTGUI_BORDER_STATIC, - RTGUI_BORDER_EXTRA, - RTGUI_BORDER_UP, - RTGUI_BORDER_DOWN + RTGUI_BORDER_NONE = 0, + RTGUI_BORDER_SIMPLE, + RTGUI_BORDER_RAISE, + RTGUI_BORDER_SUNKEN, + RTGUI_BORDER_BOX, + RTGUI_BORDER_STATIC, + RTGUI_BORDER_EXTRA, + RTGUI_BORDER_UP, + RTGUI_BORDER_DOWN }; -#define RTGUI_BORDER_DEFAULT_WIDTH 2 -#define RTGUI_WIDGET_DEFAULT_MARGIN 3 +#define RTGUI_BORDER_DEFAULT_WIDTH 2 +#define RTGUI_WIDGET_DEFAULT_MARGIN 3 /** * Orientation */ enum RTGUI_ORIENTATION { - RTGUI_HORIZONTAL = 0x01, - RTGUI_VERTICAL = 0x02, - RTGUI_ORIENTATION_BOTH = RTGUI_HORIZONTAL | RTGUI_VERTICAL + RTGUI_HORIZONTAL = 0x01, + RTGUI_VERTICAL = 0x02, + RTGUI_ORIENTATION_BOTH = RTGUI_HORIZONTAL | RTGUI_VERTICAL }; enum RTGUI_ALIGN { - RTGUI_ALIGN_NOT = 0x00, - RTGUI_ALIGN_CENTER_HORIZONTAL = 0x01, - RTGUI_ALIGN_LEFT = RTGUI_ALIGN_NOT, - RTGUI_ALIGN_TOP = RTGUI_ALIGN_NOT, - RTGUI_ALIGN_RIGHT = 0x02, - RTGUI_ALIGN_BOTTOM = 0x04, - RTGUI_ALIGN_CENTER_VERTICAL = 0x08, - RTGUI_ALIGN_CENTER = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL, - RTGUI_ALIGN_EXPAND = 0x10, - RTGUI_ALIGN_STRETCH = 0x20, + RTGUI_ALIGN_NOT = 0x00, + RTGUI_ALIGN_CENTER_HORIZONTAL = 0x01, + RTGUI_ALIGN_LEFT = RTGUI_ALIGN_NOT, + RTGUI_ALIGN_TOP = RTGUI_ALIGN_NOT, + RTGUI_ALIGN_RIGHT = 0x02, + RTGUI_ALIGN_BOTTOM = 0x04, + RTGUI_ALIGN_CENTER_VERTICAL = 0x08, + RTGUI_ALIGN_CENTER = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL, + RTGUI_ALIGN_EXPAND = 0x10, + RTGUI_ALIGN_STRETCH = 0x20, }; enum RTGUI_TEXTSTYLE { - RTGUI_TEXTSTYLE_NORMAL = 0x00, - RTGUI_TEXTSTYLE_DRAW_BACKGROUND = 0x01, - RTGUI_TEXTSTYLE_SHADOW = 0x02, - RTGUI_TEXTSTYLE_OUTLINE = 0x04, + RTGUI_TEXTSTYLE_NORMAL = 0x00, + RTGUI_TEXTSTYLE_DRAW_BACKGROUND = 0x01, + RTGUI_TEXTSTYLE_SHADOW = 0x02, + RTGUI_TEXTSTYLE_OUTLINE = 0x04, }; enum RTGUI_MODAL_CODE { - RTGUI_MODAL_OK, - RTGUI_MODAL_CANCEL + RTGUI_MODAL_OK, + RTGUI_MODAL_CANCEL }; typedef enum RTGUI_MODAL_CODE rtgui_modal_code_t; diff --git a/components/rtgui/include/rtgui/rtgui_app.h b/components/rtgui/include/rtgui/rtgui_app.h index 6d973198c0..50087e07a2 100644 --- a/components/rtgui/include/rtgui/rtgui_app.h +++ b/components/rtgui/include/rtgui/rtgui_app.h @@ -31,42 +31,42 @@ DECLARE_CLASS_TYPE(application); enum rtgui_app_flag { - RTGUI_APP_FLAG_EXITED = 0x04, - RTGUI_APP_FLAG_SHOWN = 0x08 + RTGUI_APP_FLAG_EXITED = 0x04, + RTGUI_APP_FLAG_SHOWN = 0x08 }; typedef void (*rtgui_idle_func_t)(struct rtgui_object *obj, struct rtgui_event *event); struct rtgui_app { - struct rtgui_object parent; + struct rtgui_object parent; - /* application name */ - unsigned char *name; - struct rtgui_image* icon; + /* application name */ + unsigned char *name; + struct rtgui_image *icon; - enum rtgui_app_flag state_flag; + enum rtgui_app_flag state_flag; - rt_uint16_t ref_count; - rt_uint16_t exit_code; + rt_uint16_t ref_count; + rt_uint16_t exit_code; - /* the thread id */ - rt_thread_t tid; - /* the RTGUI server id */ - rt_thread_t server; + /* the thread id */ + rt_thread_t tid; + /* the RTGUI server id */ + rt_thread_t server; - /* the message queue of thread */ - rt_mq_t mq; - /* event buffer */ - rt_uint8_t event_buffer[sizeof(union rtgui_event_generic)]; + /* the message queue of thread */ + rt_mq_t mq; + /* event buffer */ + rt_uint8_t event_buffer[sizeof(union rtgui_event_generic)]; - /* if not RT_NULL, the application is in modal state by modal_object. If is - * RT_NULL, nothing modal windows. */ - struct rtgui_object *modal_object; - struct rtgui_object *main_object; + /* if not RT_NULL, the application is in modal state by modal_object. If is + * RT_NULL, nothing modal windows. */ + struct rtgui_object *modal_object; + struct rtgui_object *main_object; - /* on idle event handler */ - rtgui_idle_func_t on_idle; + /* on idle event handler */ + rtgui_idle_func_t on_idle; }; /** diff --git a/components/rtgui/include/rtgui/rtgui_config.h b/components/rtgui/include/rtgui/rtgui_config.h index 98160339f1..514e94b04c 100644 --- a/components/rtgui/include/rtgui/rtgui_config.h +++ b/components/rtgui/include/rtgui/rtgui_config.h @@ -18,67 +18,34 @@ /* RTGUI options */ -#ifdef _WIN32 - /* name length of RTGUI object */ - #define RTGUI_NAME_MAX 12 - /* support 16 weight font */ - #define RTGUI_USING_FONT16 - /* support Chinese font */ - #define RTGUI_USING_FONTHZ - /* support FreeType TTF font */ - //#define RTGUI_USING_TTF - /* use small size in RTGUI */ - #define RTGUI_USING_SMALL_SIZE - /* use mouse cursor */ - /* #define RTGUI_USING_MOUSE_CURSOR */ - /* default font size in RTGUI */ - #define RTGUI_DEFAULT_FONT_SIZE 12 - - #define RTGUI_USING_STDIO_FILERW - #define RTGUI_USING_DFS_FILERW - #define RTGUI_IMAGE_CONTAINER - #define RTGUI_IMAGE_XPM - #define RTGUI_IMAGE_BMP - #define RTGUI_IMAGE_PNG - // #define RTGUI_IMAGE_JPEG - // #define RTGUI_IMAGE_TJPGD - #define RTGUI_USING_FONT12 - #define RTGUI_USING_HZ_BMP - #define RTGUI_MEM_TRACE - #define RTGUI_USING_WINMOVE - #define RTGUI_USING_NOTEBOOK_IMAGE - // #define RTGUI_USING_HZ_FILE -#else - /* native running under RT-Thread */ - #ifndef RT_USING_DFS - #undef RTGUI_USING_DFS_FILERW - #undef RTGUI_USING_HZ_FILE - #endif +#ifndef RT_USING_DFS +#undef RTGUI_USING_DFS_FILERW +#undef RTGUI_USING_HZ_FILE #endif #if RTGUI_DEFAULT_FONT_SIZE == 0 #define RTGUI_DEFAULT_FONT_SIZE 12 #endif -#define RTGUI_SVR_THREAD_PRIORITY 15 -#define RTGUI_SVR_THREAD_TIMESLICE 5 +#define RTGUI_SVR_THREAD_PRIORITY 15 +#define RTGUI_SVR_THREAD_TIMESLICE 5 #ifdef RTGUI_USING_SMALL_SIZE -#define RTGUI_SVR_THREAD_STACK_SIZE 1024 +#define RTGUI_SVR_THREAD_STACK_SIZE 1024 #else -#define RTGUI_SVR_THREAD_STACK_SIZE 2048 +#define RTGUI_SVR_THREAD_STACK_SIZE 2048 #endif -#define RTGUI_APP_THREAD_PRIORITY 25 -#define RTGUI_APP_THREAD_TIMESLICE 5 +#define RTGUI_APP_THREAD_PRIORITY 25 +#define RTGUI_APP_THREAD_TIMESLICE 5 #ifdef RTGUI_USING_SMALL_SIZE -#define RTGUI_APP_THREAD_STACK_SIZE 1024 +#define RTGUI_APP_THREAD_STACK_SIZE 1024 #else -#define RTGUI_APP_THREAD_STACK_SIZE 2048 +#define RTGUI_APP_THREAD_STACK_SIZE 2048 #endif #define RTGUI_USING_CAST_CHECK //#define RTGUI_USING_DESKTOP_WINDOW -#undef RTGUI_USING_SMALL_SIZE +//#undef RTGUI_USING_SMALL_SIZE #endif diff --git a/components/rtgui/include/rtgui/rtgui_mv_model.h b/components/rtgui/include/rtgui/rtgui_mv_model.h new file mode 100644 index 0000000000..072fad7c12 --- /dev/null +++ b/components/rtgui/include/rtgui/rtgui_mv_model.h @@ -0,0 +1,58 @@ +/* + * File : rtgui_mv_model.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2012, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2012-09-15 Grissiom first version + */ +#ifndef __RTGUI_MV_MODEL_H__ +#define __RTGUI_MV_MODEL_H__ + +#include <rtgui/rtgui.h> +#include <rtgui/widgets/mv_view.h> + +DECLARE_CLASS_TYPE(mv_model); + +/** Gets the type of a mv_model */ +#define RTGUI_MV_MODEL_TYPE (RTGUI_TYPE(mv_model)) +/** Casts the object to an mv_model */ +#define RTGUI_MV_MODEL(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_MV_MODEL_TYPE, struct rtgui_mv_model)) +/** Checks if the object is an mv_model */ +#define RTGUI_IS_MV_MODEL(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_MV_MODEL_TYPE)) + +struct rtgui_mv_model +{ + struct rtgui_object parent; + + rt_uint16_t dimension; + rt_uint16_t view_number; + /* the length of data */ + rt_uint16_t length; + /* if the dimension is 1, the data is the pointer to the data. If the + * dimension is more than 1, data is a pointer to a array of pointers to + * data. */ + void *data; + /* the content of view is like the content of data. If a model has more + * then one view, view is pointed to an array of pointers to views. */ + void *view; +}; + +struct rtgui_mv_model *rtgui_mv_model_create(rt_uint16_t dimension); +void rtgui_mv_model_destroy(struct rtgui_mv_model *model); + +rt_err_t rtgui_mv_model_set_dimension(struct rtgui_mv_model *model, rt_uint16_t dimension); +rt_err_t rtgui_mv_model_add_view(struct rtgui_mv_model *, struct rtgui_mv_view *); +void rtgui_mv_model_remove_view(struct rtgui_mv_model *, struct rtgui_mv_view *); + +rt_bool_t rtgui_mv_model_has_view(struct rtgui_mv_model *model, struct rtgui_mv_view *view); +void rtgui_mv_model_set_data(struct rtgui_mv_model *model, rt_uint16_t dim, void *p); +void *rtgui_mv_model_get_data(struct rtgui_mv_model *model, rt_uint16_t dim); +void rtgui_mv_model_notify(struct rtgui_mv_model *model, struct rtgui_event_mv_model *em); + +#endif /* end of include guard: __RTGUI_MV_MODEL_H__ */ diff --git a/components/rtgui/include/rtgui/rtgui_object.h b/components/rtgui/include/rtgui/rtgui_object.h index aa2f9a3306..57fd47f0eb 100644 --- a/components/rtgui/include/rtgui/rtgui_object.h +++ b/components/rtgui/include/rtgui/rtgui_object.h @@ -22,124 +22,124 @@ extern "C" { #endif -/* rtgui object type */ -#define RTGUI_CONTAINER_OF(obj, type, member) \ - ((type *)((char *)(obj) - (unsigned long)(&((type *)0)->member))) + /* rtgui object type */ +#define RTGUI_CONTAINER_OF(obj, type, member) \ + ((type *)((char *)(obj) - (unsigned long)(&((type *)0)->member))) -/** Casts the function pointer to an rtgui_constructor */ + /** Casts the function pointer to an rtgui_constructor */ #define RTGUI_CONSTRUCTOR(constructor) ((rtgui_constructor_t)(constructor)) -/** Casts the function pointer to an rtgui_constructor */ + /** Casts the function pointer to an rtgui_constructor */ #define RTGUI_DESTRUCTOR(destructor) ((rtgui_destructor_t)(destructor)) -/* pre-definition */ -struct rtgui_object; -typedef struct rtgui_object rtgui_object_t; -typedef void (*rtgui_constructor_t)(rtgui_object_t *object); -typedef void (*rtgui_destructor_t)(rtgui_object_t *object); + /* pre-definition */ + struct rtgui_object; + typedef struct rtgui_object rtgui_object_t; + typedef void (*rtgui_constructor_t)(rtgui_object_t *object); + typedef void (*rtgui_destructor_t)(rtgui_object_t *object); -/* rtgui type structure */ -struct rtgui_type -{ - /* type name */ - char* name; + /* rtgui type structure */ + struct rtgui_type + { + /* type name */ + char *name; - /* parent type link */ - struct rtgui_type *parent; + /* parent type link */ + struct rtgui_type *parent; - /* constructor and destructor */ - rtgui_constructor_t constructor; - rtgui_destructor_t destructor; + /* constructor and destructor */ + rtgui_constructor_t constructor; + rtgui_destructor_t destructor; - /* size of type */ - int size; -}; -typedef struct rtgui_type rtgui_type_t; -#define RTGUI_TYPE(type) (struct rtgui_type*)&(_rtgui_##type) + /* size of type */ + int size; + }; + typedef struct rtgui_type rtgui_type_t; +#define RTGUI_TYPE(type) (struct rtgui_type*)&(_rtgui_##type) -#define DECLARE_CLASS_TYPE(type) extern const struct rtgui_type _rtgui_##type +#define DECLARE_CLASS_TYPE(type) extern const struct rtgui_type _rtgui_##type #define DEFINE_CLASS_TYPE(type, name, parent, constructor, destructor, size) \ - const struct rtgui_type _rtgui_##type = { \ - name, \ - parent, \ - RTGUI_CONSTRUCTOR(constructor), \ - RTGUI_DESTRUCTOR(destructor), \ - size } + const struct rtgui_type _rtgui_##type = { \ + name, \ + parent, \ + RTGUI_CONSTRUCTOR(constructor), \ + RTGUI_DESTRUCTOR(destructor), \ + size } -void rtgui_type_object_construct(const rtgui_type_t *type, rtgui_object_t *object); -void rtgui_type_destructors_call(const rtgui_type_t *type, rtgui_object_t *object); -rt_bool_t rtgui_type_inherits_from(const rtgui_type_t *type, const rtgui_type_t *parent); -const rtgui_type_t *rtgui_type_parent_type_get(const rtgui_type_t *type); -const char *rtgui_type_name_get(const rtgui_type_t *type); -const rtgui_type_t *rtgui_object_object_type_get(rtgui_object_t *object); + void rtgui_type_object_construct(const rtgui_type_t *type, rtgui_object_t *object); + void rtgui_type_destructors_call(const rtgui_type_t *type, rtgui_object_t *object); + rt_bool_t rtgui_type_inherits_from(const rtgui_type_t *type, const rtgui_type_t *parent); + const rtgui_type_t *rtgui_type_parent_type_get(const rtgui_type_t *type); + const char *rtgui_type_name_get(const rtgui_type_t *type); + const rtgui_type_t *rtgui_object_object_type_get(rtgui_object_t *object); #ifdef RTGUI_USING_CAST_CHECK - #define RTGUI_OBJECT_CAST(obj, obj_type, c_type) \ - ((c_type *)rtgui_object_check_cast((rtgui_object_t *)(obj), (obj_type), __FUNCTION__, __LINE__)) +#define RTGUI_OBJECT_CAST(obj, obj_type, c_type) \ + ((c_type *)rtgui_object_check_cast((rtgui_object_t *)(obj), (obj_type), __FUNCTION__, __LINE__)) #else - #define RTGUI_OBJECT_CAST(obj, obj_type, c_type) ((c_type *)(obj)) +#define RTGUI_OBJECT_CAST(obj, obj_type, c_type) ((c_type *)(obj)) #endif #define RTGUI_OBJECT_CHECK_TYPE(_obj, _type) \ - (rtgui_type_inherits_from(((rtgui_object_t *)(_obj))->type, (_type))) + (rtgui_type_inherits_from(((rtgui_object_t *)(_obj))->type, (_type))) -DECLARE_CLASS_TYPE(object); -/** Gets the type of an object */ + DECLARE_CLASS_TYPE(object); + /** Gets the type of an object */ #define RTGUI_OBJECT_TYPE RTGUI_TYPE(object) -/** Casts the object to an rtgui_object_t */ + /** Casts the object to an rtgui_object_t */ #define RTGUI_OBJECT(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_OBJECT_TYPE, struct rtgui_object)) -/** Checks if the object is an rtgui_Object */ + /** Checks if the object is an rtgui_Object */ #define RTGUI_IS_OBJECT(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_OBJECT_TYPE)) -enum rtgui_object_flag -{ - RTGUI_OBJECT_FLAG_NONE = 0x00, - RTGUI_OBJECT_FLAG_STATIC = 0x01, - RTGUI_OBJECT_FLAG_DISABLED = 0x02 -}; + enum rtgui_object_flag + { + RTGUI_OBJECT_FLAG_NONE = 0x00, + RTGUI_OBJECT_FLAG_STATIC = 0x01, + RTGUI_OBJECT_FLAG_DISABLED = 0x02 + }; -/* rtgui base object */ -struct rtgui_object -{ - /* object type */ - const rtgui_type_t* type; + /* rtgui base object */ + struct rtgui_object + { + /* object type */ + const rtgui_type_t *type; - /* the event handler */ - rtgui_event_handler_ptr event_handler; + /* the event handler */ + rtgui_event_handler_ptr event_handler; - enum rtgui_object_flag flag; -}; + enum rtgui_object_flag flag; + }; -rtgui_object_t *rtgui_object_create(rtgui_type_t *object_type); -void rtgui_object_destroy(rtgui_object_t *object); + rtgui_object_t *rtgui_object_create(rtgui_type_t *object_type); + void rtgui_object_destroy(rtgui_object_t *object); -/* set the event handler of object */ -void rtgui_object_set_event_handler(struct rtgui_object *object, rtgui_event_handler_ptr handler); -/* object default event handler */ -rt_bool_t rtgui_object_event_handler(struct rtgui_object *object, struct rtgui_event* event); -/* helper micro. widget event handlers could use this. */ + /* set the event handler of object */ + void rtgui_object_set_event_handler(struct rtgui_object *object, rtgui_event_handler_ptr handler); + /* object default event handler */ + rt_bool_t rtgui_object_event_handler(struct rtgui_object *object, struct rtgui_event *event); + /* helper micro. widget event handlers could use this. */ #define RTGUI_WIDGET_EVENT_HANDLER_PREPARE \ - struct rtgui_widget *widget; \ - RT_ASSERT(object != RT_NULL); \ - RT_ASSERT(event != RT_NULL); \ - widget = RTGUI_WIDGET(object); \ - /* supress compiler warning */ \ - widget = widget; + struct rtgui_widget *widget; \ + RT_ASSERT(object != RT_NULL); \ + RT_ASSERT(event != RT_NULL); \ + widget = RTGUI_WIDGET(object); \ + /* supress compiler warning */ \ + widget = widget; -/** handle @param event on @param object's own event handler - * - * If the @param object does not have an event handler, which means the object - * does not interested in any event, it will return RT_FALSE. Otherwise, the - * return code of that handler is returned. - */ -rt_inline rt_bool_t rtgui_object_handle(struct rtgui_object *object, struct rtgui_event *event) -{ - if (object->event_handler) - return object->event_handler(object, event); - return RT_FALSE; -} + /** handle @param event on @param object's own event handler + * + * If the @param object does not have an event handler, which means the object + * does not interested in any event, it will return RT_FALSE. Otherwise, the + * return code of that handler is returned. + */ + rt_inline rt_bool_t rtgui_object_handle(struct rtgui_object *object, struct rtgui_event *event) + { + if (object->event_handler) + return object->event_handler(object, event); + return RT_FALSE; + } -rtgui_object_t *rtgui_object_check_cast(rtgui_object_t *object, rtgui_type_t *type, const char* func, int line); -rtgui_type_t *rtk_object_object_type_get(rtgui_object_t *object); + rtgui_object_t *rtgui_object_check_cast(rtgui_object_t *object, rtgui_type_t *type, const char *func, int line); + rtgui_type_t *rtk_object_object_type_get(rtgui_object_t *object); #ifdef __cplusplus } diff --git a/components/rtgui/include/rtgui/rtgui_server.h b/components/rtgui/include/rtgui/rtgui_server.h index f109f7297a..9914a5b8ef 100644 --- a/components/rtgui/include/rtgui/rtgui_server.h +++ b/components/rtgui/include/rtgui/rtgui_server.h @@ -22,21 +22,21 @@ /* top window definitions in server */ enum rtgui_topwin_flag { - WINTITLE_NO = 0x01, - WINTITLE_BORDER = 0x02, - WINTITLE_ACTIVATE = 0x04, - WINTITLE_CLOSEBOX = 0x08, - WINTITLE_MOVE = 0x0C, - WINTITLE_CB_PRESSED = 0x10, - WINTITLE_NOFOCUS = 0x20, - /* window is hidden by default */ - WINTITLE_SHOWN = 0x40, - /* window is modaled by other window */ - WINTITLE_MODALED = 0x80, - /* window is modaling other window */ - WINTITLE_MODALING = 0x100, - WINTITLE_ONTOP = 0x200, - WINTITLE_ONBTM = 0x400, + WINTITLE_NO = 0x01, + WINTITLE_BORDER = 0x02, + WINTITLE_ACTIVATE = 0x04, + WINTITLE_CLOSEBOX = 0x08, + WINTITLE_MOVE = 0x0C, + WINTITLE_CB_PRESSED = 0x10, + WINTITLE_NOFOCUS = 0x20, + /* window is hidden by default */ + WINTITLE_SHOWN = 0x40, + /* window is modaled by other window */ + WINTITLE_MODALED = 0x80, + /* window is modaling other window */ + WINTITLE_MODALING = 0x100, + WINTITLE_ONTOP = 0x200, + WINTITLE_ONBTM = 0x400, }; #define WINTITLE_HEIGHT 20 @@ -46,31 +46,31 @@ enum rtgui_topwin_flag struct rtgui_topwin { - /* the window flag */ - enum rtgui_topwin_flag flag; - /* event mask */ - rt_uint32_t mask; + /* the window flag */ + enum rtgui_topwin_flag flag; + /* event mask */ + rt_uint32_t mask; - struct rtgui_wintitle* title; + struct rtgui_wintitle *title; - /* the window id */ - struct rtgui_win* wid; + /* the window id */ + struct rtgui_win *wid; - /* the thread id */ - rt_thread_t tid; + /* the thread id */ + rt_thread_t tid; - /* the extent information */ - rtgui_rect_t extent; + /* the extent information */ + rtgui_rect_t extent; - struct rtgui_topwin *parent; + struct rtgui_topwin *parent; - /* we need to iterate the topwin list with usual order(get target window) - * or reversely(painting). So it's better to use a double linked list */ - struct rtgui_dlist_node list; - struct rtgui_dlist_node child_list; + /* we need to iterate the topwin list with usual order(get target window) + * or reversely(painting). So it's better to use a double linked list */ + struct rtgui_dlist_node list; + struct rtgui_dlist_node child_list; - /* the monitor rect list */ - rtgui_list_t monitor_list; + /* the monitor rect list */ + rtgui_list_t monitor_list; }; typedef struct rtgui_topwin rtgui_topwin_t; @@ -79,8 +79,8 @@ void rtgui_topwin_init(void); void rtgui_server_init(void); /* post an event to server */ -void rtgui_server_post_event(struct rtgui_event* event, rt_size_t size); -rt_err_t rtgui_server_post_event_sync(struct rtgui_event* event, rt_size_t size); +void rtgui_server_post_event(struct rtgui_event *event, rt_size_t size); +rt_err_t rtgui_server_post_event_sync(struct rtgui_event *event, rt_size_t size); #endif diff --git a/components/rtgui/include/rtgui/rtgui_system.h b/components/rtgui/include/rtgui/rtgui_system.h index 31030fa2ae..975b1e0be5 100644 --- a/components/rtgui/include/rtgui/rtgui_system.h +++ b/components/rtgui/include/rtgui/rtgui_system.h @@ -22,40 +22,40 @@ struct rtgui_event; struct rtgui_widget; struct rtgui_timer; -typedef void (*rtgui_timeout_func)(struct rtgui_timer* timer, void* parameter); +typedef void (*rtgui_timeout_func)(struct rtgui_timer *timer, void *parameter); struct rtgui_timer { - /* context thread id */ - rt_thread_t tid; - /* rt timer */ - struct rt_timer timer; + /* context thread id */ + rt_thread_t tid; + /* rt timer */ + struct rt_timer timer; - /* timeout function and user data */ - rtgui_timeout_func timeout; - void* user_data; + /* timeout function and user data */ + rtgui_timeout_func timeout; + void *user_data; }; typedef struct rtgui_timer rtgui_timer_t; -rtgui_timer_t* rtgui_timer_create(rt_int32_t time, rt_base_t flag, rtgui_timeout_func timeout, void* parameter); -void rtgui_timer_destory(rtgui_timer_t* timer); +rtgui_timer_t *rtgui_timer_create(rt_int32_t time, rt_base_t flag, rtgui_timeout_func timeout, void *parameter); +void rtgui_timer_destory(rtgui_timer_t *timer); -void rtgui_timer_start(rtgui_timer_t* timer); -void rtgui_timer_stop (rtgui_timer_t* timer); +void rtgui_timer_start(rtgui_timer_t *timer); +void rtgui_timer_stop(rtgui_timer_t *timer); /* rtgui system initialization function */ void rtgui_system_server_init(void); -void* rtgui_malloc(rt_size_t size); -void rtgui_free(void* ptr); -void* rtgui_realloc(void* ptr, rt_size_t size); +void *rtgui_malloc(rt_size_t size); +void rtgui_free(void *ptr); +void *rtgui_realloc(void *ptr, rt_size_t size); -#ifdef _WIN32 -#define rtgui_enter_critical() -#define rtgui_exit_critical() +#ifdef _WIN32_NATIVE +#define rtgui_enter_critical() +#define rtgui_exit_critical() #else -#define rtgui_enter_critical rt_enter_critical -#define rtgui_exit_critical rt_exit_critical +#define rtgui_enter_critical rt_enter_critical +#define rtgui_exit_critical rt_exit_critical #endif rt_thread_t rtgui_get_server(void); @@ -67,12 +67,12 @@ void rtgui_screen_lock(rt_int32_t timeout); void rtgui_screen_unlock(void); struct rtgui_event; -rt_err_t rtgui_send(rt_thread_t tid, struct rtgui_event* event, rt_size_t event_size); -rt_err_t rtgui_send_urgent(rt_thread_t tid, struct rtgui_event* event, rt_size_t event_size); -rt_err_t rtgui_send_sync(rt_thread_t tid, struct rtgui_event* event, rt_size_t event_size); -rt_err_t rtgui_ack(struct rtgui_event* event, rt_int32_t status); -rt_err_t rtgui_recv(struct rtgui_event* event, rt_size_t event_size); -rt_err_t rtgui_recv_nosuspend(struct rtgui_event* event, rt_size_t event_size); -rt_err_t rtgui_recv_filter(rt_uint32_t type, struct rtgui_event* event, rt_size_t event_size); +rt_err_t rtgui_send(rt_thread_t tid, struct rtgui_event *event, rt_size_t event_size); +rt_err_t rtgui_send_urgent(rt_thread_t tid, struct rtgui_event *event, rt_size_t event_size); +rt_err_t rtgui_send_sync(rt_thread_t tid, struct rtgui_event *event, rt_size_t event_size); +rt_err_t rtgui_ack(struct rtgui_event *event, rt_int32_t status); +rt_err_t rtgui_recv(struct rtgui_event *event, rt_size_t event_size); +rt_err_t rtgui_recv_nosuspend(struct rtgui_event *event, rt_size_t event_size); +rt_err_t rtgui_recv_filter(rt_uint32_t type, struct rtgui_event *event, rt_size_t event_size); #endif diff --git a/components/rtgui/include/rtgui/rtgui_theme.h b/components/rtgui/include/rtgui/rtgui_theme.h index 27f09d0079..8f70277ec9 100644 --- a/components/rtgui/include/rtgui/rtgui_theme.h +++ b/components/rtgui/include/rtgui/rtgui_theme.h @@ -17,11 +17,11 @@ #include <rtgui/rtgui.h> #include <rtgui/rtgui_server.h> -#define CHECK_BOX_W 13 -#define CHECK_BOX_H 13 +#define CHECK_BOX_W 13 +#define CHECK_BOX_H 13 -#define RADIO_BOX_W 12 -#define RADIO_BOX_H 12 +#define RADIO_BOX_W 12 +#define RADIO_BOX_H 12 #include <rtgui/widgets/label.h> #include <rtgui/widgets/button.h> @@ -38,27 +38,26 @@ extern "C" { #endif -void rtgui_system_theme_init(void); + 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); -void rtgui_theme_draw_checkbox(rtgui_checkbox_t* checkbox); -void rtgui_theme_draw_radiobutton(struct rtgui_radiobox* radiobox, rt_uint16_t item); + 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); + void rtgui_theme_draw_checkbox(rtgui_checkbox_t *checkbox); + void rtgui_theme_draw_radiobutton(struct rtgui_radiobox *radiobox, rt_uint16_t item); -void rtgui_theme_draw_radiobox(struct rtgui_radiobox* radiobox); -void rtgui_theme_draw_slider(struct rtgui_slider* slider); -void rtgui_theme_draw_scrollbar(struct rtgui_scrollbar* bar); -void rtgui_theme_draw_progressbar(struct rtgui_progressbar* bar); -void rtgui_theme_draw_staticline(struct rtgui_staticline* staticline); + void rtgui_theme_draw_radiobox(struct rtgui_radiobox *radiobox); + void rtgui_theme_draw_slider(struct rtgui_slider *slider); + void rtgui_theme_draw_progressbar(struct rtgui_progressbar *bar); + void rtgui_theme_draw_staticline(struct rtgui_staticline *staticline); -rt_uint16_t rtgui_theme_get_selected_height(void); -void rtgui_theme_draw_selected(struct rtgui_dc* dc, rtgui_rect_t *rect); + 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); + rtgui_color_t rtgui_theme_default_bc(void); + rtgui_color_t rtgui_theme_default_fc(void); #ifdef __cplusplus } diff --git a/components/rtgui/include/rtgui/rtgui_xml.h b/components/rtgui/include/rtgui/rtgui_xml.h index 18bd1177ac..977f7967d1 100644 --- a/components/rtgui/include/rtgui/rtgui_xml.h +++ b/components/rtgui/include/rtgui/rtgui_xml.h @@ -5,30 +5,31 @@ /* Types of events: start element, end element, text, attr name, attr val and start/end document. Other events can be ignored! */ -enum { - EVENT_START = 0, /* Start tag */ - EVENT_END, /* End tag */ - EVENT_TEXT, /* Text */ - EVENT_NAME, /* Attribute name */ - EVENT_VAL, /* Attribute value */ - EVENT_END_DOC, /* End of document */ - EVENT_COPY, /* Internal only; copies to internal buffer */ - EVENT_NONE /* Internal only; should never see this event */ +enum +{ + EVENT_START = 0, /* Start tag */ + EVENT_END, /* End tag */ + EVENT_TEXT, /* Text */ + EVENT_NAME, /* Attribute name */ + EVENT_VAL, /* Attribute value */ + EVENT_END_DOC, /* End of document */ + EVENT_COPY, /* Internal only; copies to internal buffer */ + EVENT_NONE /* Internal only; should never see this event */ }; /* xml structure typedef */ typedef struct rtgui_xml rtgui_xml_t; -typedef int (*rtgui_xml_event_handler_t)(rt_uint8_t event, const char* text, rt_size_t len, void* user); +typedef int (*rtgui_xml_event_handler_t)(rt_uint8_t event, const char *text, rt_size_t len, void *user); /* create a xml parser context */ -rtgui_xml_t* rtgui_xml_create(rt_size_t buffer_size, rtgui_xml_event_handler_t handler, void* user); +rtgui_xml_t *rtgui_xml_create(rt_size_t buffer_size, rtgui_xml_event_handler_t handler, void *user); /* destroy a xml parser context */ -void rtgui_xml_destroy(rtgui_xml_t* rtgui_xml); +void rtgui_xml_destroy(rtgui_xml_t *rtgui_xml); /* parse xml buffer */ -int rtgui_xml_parse(rtgui_xml_t* rtgui_xml, const char* buf, rt_size_t len); +int rtgui_xml_parse(rtgui_xml_t *rtgui_xml, const char *buf, rt_size_t len); /* event string */ -const char* rtgui_xml_event_str(rt_uint8_t event); +const char *rtgui_xml_event_str(rt_uint8_t event); #endif diff --git a/components/rtgui/include/rtgui/tree.h b/components/rtgui/include/rtgui/tree.h index b45668c562..58653fb00d 100644 --- a/components/rtgui/include/rtgui/tree.h +++ b/components/rtgui/include/rtgui/tree.h @@ -1,5 +1,5 @@ -/* $NetBSD: tree.h,v 1.8 2004/03/28 19:38:30 provos Exp $ */ -/* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */ +/* $NetBSD: tree.h,v 1.8 2004/03/28 19:38:30 provos Exp $ */ +/* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */ /* $FreeBSD$ */ /*- @@ -27,8 +27,8 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _SYS_TREE_H_ -#define _SYS_TREE_H_ +#ifndef _SYS_TREE_H_ +#define _SYS_TREE_H_ #ifndef NULL #define NULL RT_NULL @@ -53,696 +53,696 @@ * * A red-black tree is a binary search tree with the node color as an * extra attribute. It fulfills a set of conditions: - * - every search path from the root to a leaf consists of the - * same number of black nodes, - * - each red node (except for the root) has a black parent, - * - each leaf node is black. + * - every search path from the root to a leaf consists of the + * same number of black nodes, + * - each red node (except for the root) has a black parent, + * - each leaf node is black. * * Every operation on a red-black tree is bounded as O(lg n). * The maximum height of a red-black tree is 2lg (n+1). */ -#define SPLAY_HEAD(name, type) \ -struct name { \ - struct type *sph_root; /* root of the tree */ \ +#define SPLAY_HEAD(name, type) \ +struct name { \ + struct type *sph_root; /* root of the tree */ \ } -#define SPLAY_INITIALIZER(root) \ - { NULL } +#define SPLAY_INITIALIZER(root) \ + { NULL } -#define SPLAY_INIT(root) do { \ - (root)->sph_root = NULL; \ +#define SPLAY_INIT(root) do { \ + (root)->sph_root = NULL; \ } while (/*CONSTCOND*/ 0) -#define SPLAY_ENTRY(type) \ -struct { \ - struct type *spe_left; /* left element */ \ - struct type *spe_right; /* right element */ \ +#define SPLAY_ENTRY(type) \ +struct { \ + struct type *spe_left; /* left element */ \ + struct type *spe_right; /* right element */ \ } -#define SPLAY_LEFT(elm, field) (elm)->field.spe_left -#define SPLAY_RIGHT(elm, field) (elm)->field.spe_right -#define SPLAY_ROOT(head) (head)->sph_root -#define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL) +#define SPLAY_LEFT(elm, field) (elm)->field.spe_left +#define SPLAY_RIGHT(elm, field) (elm)->field.spe_right +#define SPLAY_ROOT(head) (head)->sph_root +#define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL) /* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */ -#define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \ - SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \ - SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ - (head)->sph_root = tmp; \ +#define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ } while (/*CONSTCOND*/ 0) - -#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \ - SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ - SPLAY_LEFT(tmp, field) = (head)->sph_root; \ - (head)->sph_root = tmp; \ + +#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ } while (/*CONSTCOND*/ 0) -#define SPLAY_LINKLEFT(head, tmp, field) do { \ - SPLAY_LEFT(tmp, field) = (head)->sph_root; \ - tmp = (head)->sph_root; \ - (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ +#define SPLAY_LINKLEFT(head, tmp, field) do { \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ } while (/*CONSTCOND*/ 0) -#define SPLAY_LINKRIGHT(head, tmp, field) do { \ - SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ - tmp = (head)->sph_root; \ - (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ +#define SPLAY_LINKRIGHT(head, tmp, field) do { \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ } while (/*CONSTCOND*/ 0) -#define SPLAY_ASSEMBLE(head, node, left, right, field) do { \ - SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \ - SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\ - SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \ - SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \ +#define SPLAY_ASSEMBLE(head, node, left, right, field) do { \ + SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \ + SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \ } while (/*CONSTCOND*/ 0) /* Generates prototypes and inline functions */ -#define SPLAY_PROTOTYPE(name, type, field, cmp) \ -void name##_SPLAY(struct name *, struct type *); \ -void name##_SPLAY_MINMAX(struct name *, int); \ -struct type *name##_SPLAY_INSERT(struct name *, struct type *); \ -struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \ - \ -/* Finds the node with the same key as elm */ \ -rt_inline struct type * \ -name##_SPLAY_FIND(struct name *head, struct type *elm) \ -{ \ - if (SPLAY_EMPTY(head)) \ - return(NULL); \ - name##_SPLAY(head, elm); \ - if ((cmp)(elm, (head)->sph_root) == 0) \ - return (head->sph_root); \ - return (NULL); \ -} \ - \ -rt_inline struct type * \ -name##_SPLAY_NEXT(struct name *head, struct type *elm) \ -{ \ - name##_SPLAY(head, elm); \ - if (SPLAY_RIGHT(elm, field) != NULL) { \ - elm = SPLAY_RIGHT(elm, field); \ - while (SPLAY_LEFT(elm, field) != NULL) { \ - elm = SPLAY_LEFT(elm, field); \ - } \ - } else \ - elm = NULL; \ - return (elm); \ -} \ - \ -rt_inline struct type * \ -name##_SPLAY_MIN_MAX(struct name *head, int val) \ -{ \ - name##_SPLAY_MINMAX(head, val); \ - return (SPLAY_ROOT(head)); \ +#define SPLAY_PROTOTYPE(name, type, field, cmp) \ +void name##_SPLAY(struct name *, struct type *); \ +void name##_SPLAY_MINMAX(struct name *, int); \ +struct type *name##_SPLAY_INSERT(struct name *, struct type *); \ +struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \ + \ +/* Finds the node with the same key as elm */ \ +rt_inline struct type * \ +name##_SPLAY_FIND(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) \ + return(NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) \ + return (head->sph_root); \ + return (NULL); \ +} \ + \ +rt_inline struct type * \ +name##_SPLAY_NEXT(struct name *head, struct type *elm) \ +{ \ + name##_SPLAY(head, elm); \ + if (SPLAY_RIGHT(elm, field) != NULL) { \ + elm = SPLAY_RIGHT(elm, field); \ + while (SPLAY_LEFT(elm, field) != NULL) { \ + elm = SPLAY_LEFT(elm, field); \ + } \ + } else \ + elm = NULL; \ + return (elm); \ +} \ + \ +rt_inline struct type * \ +name##_SPLAY_MIN_MAX(struct name *head, int val) \ +{ \ + name##_SPLAY_MINMAX(head, val); \ + return (SPLAY_ROOT(head)); \ } /* Main splay operation. * Moves node close to the key of elm to top */ -#define SPLAY_GENERATE(name, type, field, cmp) \ -struct type * \ -name##_SPLAY_INSERT(struct name *head, struct type *elm) \ -{ \ - if (SPLAY_EMPTY(head)) { \ - SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \ - } else { \ - int __comp; \ - name##_SPLAY(head, elm); \ - __comp = (cmp)(elm, (head)->sph_root); \ - if(__comp < 0) { \ - SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\ - SPLAY_RIGHT(elm, field) = (head)->sph_root; \ - SPLAY_LEFT((head)->sph_root, field) = NULL; \ - } else if (__comp > 0) { \ - SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\ - SPLAY_LEFT(elm, field) = (head)->sph_root; \ - SPLAY_RIGHT((head)->sph_root, field) = NULL; \ - } else \ - return ((head)->sph_root); \ - } \ - (head)->sph_root = (elm); \ - return (NULL); \ -} \ - \ -struct type * \ -name##_SPLAY_REMOVE(struct name *head, struct type *elm) \ -{ \ - struct type *__tmp; \ - if (SPLAY_EMPTY(head)) \ - return (NULL); \ - name##_SPLAY(head, elm); \ - if ((cmp)(elm, (head)->sph_root) == 0) { \ - if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \ - (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\ - } else { \ - __tmp = SPLAY_RIGHT((head)->sph_root, field); \ - (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\ - name##_SPLAY(head, elm); \ - SPLAY_RIGHT((head)->sph_root, field) = __tmp; \ - } \ - return (elm); \ - } \ - return (NULL); \ -} \ - \ -void \ -name##_SPLAY(struct name *head, struct type *elm) \ -{ \ - struct type __node, *__left, *__right, *__tmp; \ - int __comp; \ +#define SPLAY_GENERATE(name, type, field, cmp) \ +struct type * \ +name##_SPLAY_INSERT(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) { \ + SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \ + } else { \ + int __comp; \ + name##_SPLAY(head, elm); \ + __comp = (cmp)(elm, (head)->sph_root); \ + if(__comp < 0) { \ + SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\ + SPLAY_RIGHT(elm, field) = (head)->sph_root; \ + SPLAY_LEFT((head)->sph_root, field) = NULL; \ + } else if (__comp > 0) { \ + SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT(elm, field) = (head)->sph_root; \ + SPLAY_RIGHT((head)->sph_root, field) = NULL; \ + } else \ + return ((head)->sph_root); \ + } \ + (head)->sph_root = (elm); \ + return (NULL); \ +} \ + \ +struct type * \ +name##_SPLAY_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *__tmp; \ + if (SPLAY_EMPTY(head)) \ + return (NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) { \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\ + } else { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\ + name##_SPLAY(head, elm); \ + SPLAY_RIGHT((head)->sph_root, field) = __tmp; \ + } \ + return (elm); \ + } \ + return (NULL); \ +} \ + \ +void \ +name##_SPLAY(struct name *head, struct type *elm) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ + int __comp; \ \ - SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ - __left = __right = &__node; \ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ \ - while ((__comp = (cmp)(elm, (head)->sph_root)) != 0) { \ - if (__comp < 0) { \ - __tmp = SPLAY_LEFT((head)->sph_root, field); \ - if (__tmp == NULL) \ - break; \ - if ((cmp)(elm, __tmp) < 0){ \ - SPLAY_ROTATE_RIGHT(head, __tmp, field); \ - if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ - break; \ - } \ - SPLAY_LINKLEFT(head, __right, field); \ - } else if (__comp > 0) { \ - __tmp = SPLAY_RIGHT((head)->sph_root, field); \ - if (__tmp == NULL) \ - break; \ - if ((cmp)(elm, __tmp) > 0){ \ - SPLAY_ROTATE_LEFT(head, __tmp, field); \ - if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ - break; \ - } \ - SPLAY_LINKRIGHT(head, __left, field); \ - } \ - } \ - SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ -} \ - \ -/* Splay with either the minimum or the maximum element \ - * Used to find minimum or maximum element in tree. \ - */ \ + while ((__comp = (cmp)(elm, (head)->sph_root)) != 0) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) > 0){ \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} \ + \ +/* Splay with either the minimum or the maximum element \ + * Used to find minimum or maximum element in tree. \ + */ \ void name##_SPLAY_MINMAX(struct name *head, int __comp) \ -{ \ - struct type __node, *__left, *__right, *__tmp; \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ \ - SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ - __left = __right = &__node; \ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ \ - while (1) { \ - if (__comp < 0) { \ - __tmp = SPLAY_LEFT((head)->sph_root, field); \ - if (__tmp == NULL) \ - break; \ - if (__comp < 0){ \ - SPLAY_ROTATE_RIGHT(head, __tmp, field); \ - if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ - break; \ - } \ - SPLAY_LINKLEFT(head, __right, field); \ - } else if (__comp > 0) { \ - __tmp = SPLAY_RIGHT((head)->sph_root, field); \ - if (__tmp == NULL) \ - break; \ - if (__comp > 0) { \ - SPLAY_ROTATE_LEFT(head, __tmp, field); \ - if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ - break; \ - } \ - SPLAY_LINKRIGHT(head, __left, field); \ - } \ - } \ - SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ + while (1) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp > 0) { \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ } -#define SPLAY_NEGINF -1 -#define SPLAY_INF 1 +#define SPLAY_NEGINF -1 +#define SPLAY_INF 1 -#define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y) -#define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y) -#define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y) -#define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y) -#define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \ - : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF)) -#define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \ - : name##_SPLAY_MIN_MAX(x, SPLAY_INF)) +#define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y) +#define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y) +#define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y) +#define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y) +#define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF)) +#define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_INF)) -#define SPLAY_FOREACH(x, name, head) \ - for ((x) = SPLAY_MIN(name, head); \ - (x) != NULL; \ - (x) = SPLAY_NEXT(name, head, x)) +#define SPLAY_FOREACH(x, name, head) \ + for ((x) = SPLAY_MIN(name, head); \ + (x) != NULL; \ + (x) = SPLAY_NEXT(name, head, x)) /* Macros that define a red-black tree */ -#define RB_HEAD(name, type) \ -struct name { \ - struct type *rbh_root; /* root of the tree */ \ +#define RB_HEAD(name, type) \ +struct name { \ + struct type *rbh_root; /* root of the tree */ \ } -#define RB_INITIALIZER(root) \ - { NULL } +#define RB_INITIALIZER(root) \ + { NULL } -#define RB_INIT(root) do { \ - (root)->rbh_root = NULL; \ +#define RB_INIT(root) do { \ + (root)->rbh_root = NULL; \ } while (/*CONSTCOND*/ 0) -#define RB_BLACK 0 -#define RB_RED 1 -#define RB_ENTRY(type) \ -struct { \ - struct type *rbe_left; /* left element */ \ - struct type *rbe_right; /* right element */ \ - struct type *rbe_parent; /* parent element */ \ - int rbe_color; /* node color */ \ +#define RB_BLACK 0 +#define RB_RED 1 +#define RB_ENTRY(type) \ +struct { \ + struct type *rbe_left; /* left element */ \ + struct type *rbe_right; /* right element */ \ + struct type *rbe_parent; /* parent element */ \ + int rbe_color; /* node color */ \ } -#define RB_LEFT(elm, field) (elm)->field.rbe_left -#define RB_RIGHT(elm, field) (elm)->field.rbe_right -#define RB_PARENT(elm, field) (elm)->field.rbe_parent -#define RB_COLOR(elm, field) (elm)->field.rbe_color -#define RB_ROOT(head) (head)->rbh_root -#define RB_EMPTY(head) (RB_ROOT(head) == NULL) +#define RB_LEFT(elm, field) (elm)->field.rbe_left +#define RB_RIGHT(elm, field) (elm)->field.rbe_right +#define RB_PARENT(elm, field) (elm)->field.rbe_parent +#define RB_COLOR(elm, field) (elm)->field.rbe_color +#define RB_ROOT(head) (head)->rbh_root +#define RB_EMPTY(head) (RB_ROOT(head) == NULL) -#define RB_SET(elm, parent, field) do { \ - RB_PARENT(elm, field) = parent; \ - RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \ - RB_COLOR(elm, field) = RB_RED; \ +#define RB_SET(elm, parent, field) do { \ + RB_PARENT(elm, field) = parent; \ + RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \ + RB_COLOR(elm, field) = RB_RED; \ } while (/*CONSTCOND*/ 0) -#define RB_SET_BLACKRED(black, red, field) do { \ - RB_COLOR(black, field) = RB_BLACK; \ - RB_COLOR(red, field) = RB_RED; \ +#define RB_SET_BLACKRED(black, red, field) do { \ + RB_COLOR(black, field) = RB_BLACK; \ + RB_COLOR(red, field) = RB_RED; \ } while (/*CONSTCOND*/ 0) #ifndef RB_AUGMENT -#define RB_AUGMENT(x) do {} while (0) +#define RB_AUGMENT(x) do {} while (0) #endif -#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ - (tmp) = RB_RIGHT(elm, field); \ - if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field)) != NULL) { \ - RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \ - } \ - RB_AUGMENT(elm); \ - if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \ - if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ - RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ - else \ - RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ - } else \ - (head)->rbh_root = (tmp); \ - RB_LEFT(tmp, field) = (elm); \ - RB_PARENT(elm, field) = (tmp); \ - RB_AUGMENT(tmp); \ - if ((RB_PARENT(tmp, field))) \ - RB_AUGMENT(RB_PARENT(tmp, field)); \ +#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \ + (tmp) = RB_RIGHT(elm, field); \ + if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field)) != NULL) { \ + RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_LEFT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ } while (/*CONSTCOND*/ 0) -#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ - (tmp) = RB_LEFT(elm, field); \ - if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field)) != NULL) { \ - RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \ - } \ - RB_AUGMENT(elm); \ - if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \ - if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ - RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ - else \ - RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ - } else \ - (head)->rbh_root = (tmp); \ - RB_RIGHT(tmp, field) = (elm); \ - RB_PARENT(elm, field) = (tmp); \ - RB_AUGMENT(tmp); \ - if ((RB_PARENT(tmp, field))) \ - RB_AUGMENT(RB_PARENT(tmp, field)); \ +#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \ + (tmp) = RB_LEFT(elm, field); \ + if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field)) != NULL) { \ + RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \ + } \ + RB_AUGMENT(elm); \ + if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field)) != NULL) { \ + if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \ + RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \ + else \ + RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + RB_RIGHT(tmp, field) = (elm); \ + RB_PARENT(elm, field) = (tmp); \ + RB_AUGMENT(tmp); \ + if ((RB_PARENT(tmp, field))) \ + RB_AUGMENT(RB_PARENT(tmp, field)); \ } while (/*CONSTCOND*/ 0) /* Generates prototypes and inline functions */ -#define RB_PROTOTYPE(name, type, field, cmp) \ - RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) -#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ - RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __unused static) -#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \ -attr void name##_RB_INSERT_COLOR(struct name *, struct type *); \ +#define RB_PROTOTYPE(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) +#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \ + RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __unused static) +#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \ +attr void name##_RB_INSERT_COLOR(struct name *, struct type *); \ attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\ -attr struct type *name##_RB_REMOVE(struct name *, struct type *); \ -attr struct type *name##_RB_INSERT(struct name *, struct type *); \ -attr struct type *name##_RB_FIND(struct name *, struct type *); \ -attr struct type *name##_RB_NFIND(struct name *, struct type *); \ -attr struct type *name##_RB_NEXT(struct type *); \ -attr struct type *name##_RB_PREV(struct type *); \ -attr struct type *name##_RB_MINMAX(struct name *, int); \ - \ - +attr struct type *name##_RB_REMOVE(struct name *, struct type *); \ +attr struct type *name##_RB_INSERT(struct name *, struct type *); \ +attr struct type *name##_RB_FIND(struct name *, struct type *); \ +attr struct type *name##_RB_NFIND(struct name *, struct type *); \ +attr struct type *name##_RB_NEXT(struct type *); \ +attr struct type *name##_RB_PREV(struct type *); \ +attr struct type *name##_RB_MINMAX(struct name *, int); \ + \ + /* Main rb operation. * Moves node close to the key of elm to top */ -#define RB_GENERATE(name, type, field, cmp) \ - RB_GENERATE_INTERNAL(name, type, field, cmp,) -#define RB_GENERATE_STATIC(name, type, field, cmp) \ - RB_GENERATE_INTERNAL(name, type, field, cmp, __unused static) -#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \ -attr void \ -name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ -{ \ - struct type *parent, *gparent, *tmp; \ - while ((parent = RB_PARENT(elm, field)) != NULL && \ - RB_COLOR(parent, field) == RB_RED) { \ - gparent = RB_PARENT(parent, field); \ - if (parent == RB_LEFT(gparent, field)) { \ - tmp = RB_RIGHT(gparent, field); \ - if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ - RB_COLOR(tmp, field) = RB_BLACK; \ - RB_SET_BLACKRED(parent, gparent, field);\ - elm = gparent; \ - continue; \ - } \ - if (RB_RIGHT(parent, field) == elm) { \ - RB_ROTATE_LEFT(head, parent, tmp, field);\ - tmp = parent; \ - parent = elm; \ - elm = tmp; \ - } \ - RB_SET_BLACKRED(parent, gparent, field); \ - RB_ROTATE_RIGHT(head, gparent, tmp, field); \ - } else { \ - tmp = RB_LEFT(gparent, field); \ - if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ - RB_COLOR(tmp, field) = RB_BLACK; \ - RB_SET_BLACKRED(parent, gparent, field);\ - elm = gparent; \ - continue; \ - } \ - if (RB_LEFT(parent, field) == elm) { \ - RB_ROTATE_RIGHT(head, parent, tmp, field);\ - tmp = parent; \ - parent = elm; \ - elm = tmp; \ - } \ - RB_SET_BLACKRED(parent, gparent, field); \ - RB_ROTATE_LEFT(head, gparent, tmp, field); \ - } \ - } \ - RB_COLOR(head->rbh_root, field) = RB_BLACK; \ -} \ - \ -attr void \ +#define RB_GENERATE(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp,) +#define RB_GENERATE_STATIC(name, type, field, cmp) \ + RB_GENERATE_INTERNAL(name, type, field, cmp, __unused static) +#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \ +attr void \ +name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \ +{ \ + struct type *parent, *gparent, *tmp; \ + while ((parent = RB_PARENT(elm, field)) != NULL && \ + RB_COLOR(parent, field) == RB_RED) { \ + gparent = RB_PARENT(parent, field); \ + if (parent == RB_LEFT(gparent, field)) { \ + tmp = RB_RIGHT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_RIGHT(parent, field) == elm) { \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_RIGHT(head, gparent, tmp, field); \ + } else { \ + tmp = RB_LEFT(gparent, field); \ + if (tmp && RB_COLOR(tmp, field) == RB_RED) { \ + RB_COLOR(tmp, field) = RB_BLACK; \ + RB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (RB_LEFT(parent, field) == elm) { \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + RB_SET_BLACKRED(parent, gparent, field); \ + RB_ROTATE_LEFT(head, gparent, tmp, field); \ + } \ + } \ + RB_COLOR(head->rbh_root, field) = RB_BLACK; \ +} \ + \ +attr void \ name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \ -{ \ - struct type *tmp; \ - while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) && \ - elm != RB_ROOT(head)) { \ - if (RB_LEFT(parent, field) == elm) { \ - tmp = RB_RIGHT(parent, field); \ - if (RB_COLOR(tmp, field) == RB_RED) { \ - RB_SET_BLACKRED(tmp, parent, field); \ - RB_ROTATE_LEFT(head, parent, tmp, field);\ - tmp = RB_RIGHT(parent, field); \ - } \ - if ((RB_LEFT(tmp, field) == NULL || \ - RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ - (RB_RIGHT(tmp, field) == NULL || \ - RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ - RB_COLOR(tmp, field) = RB_RED; \ - elm = parent; \ - parent = RB_PARENT(elm, field); \ - } else { \ - if (RB_RIGHT(tmp, field) == NULL || \ - RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\ - struct type *oleft; \ - if ((oleft = RB_LEFT(tmp, field)) \ - != NULL) \ - RB_COLOR(oleft, field) = RB_BLACK;\ - RB_COLOR(tmp, field) = RB_RED; \ - RB_ROTATE_RIGHT(head, tmp, oleft, field);\ - tmp = RB_RIGHT(parent, field); \ - } \ - RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ - RB_COLOR(parent, field) = RB_BLACK; \ - if (RB_RIGHT(tmp, field)) \ - RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\ - RB_ROTATE_LEFT(head, parent, tmp, field);\ - elm = RB_ROOT(head); \ - break; \ - } \ - } else { \ - tmp = RB_LEFT(parent, field); \ - if (RB_COLOR(tmp, field) == RB_RED) { \ - RB_SET_BLACKRED(tmp, parent, field); \ - RB_ROTATE_RIGHT(head, parent, tmp, field);\ - tmp = RB_LEFT(parent, field); \ - } \ - if ((RB_LEFT(tmp, field) == NULL || \ - RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ - (RB_RIGHT(tmp, field) == NULL || \ - RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ - RB_COLOR(tmp, field) = RB_RED; \ - elm = parent; \ - parent = RB_PARENT(elm, field); \ - } else { \ - if (RB_LEFT(tmp, field) == NULL || \ - RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\ - struct type *oright; \ - if ((oright = RB_RIGHT(tmp, field)) \ - != NULL) \ - RB_COLOR(oright, field) = RB_BLACK;\ - RB_COLOR(tmp, field) = RB_RED; \ - RB_ROTATE_LEFT(head, tmp, oright, field);\ - tmp = RB_LEFT(parent, field); \ - } \ - RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ - RB_COLOR(parent, field) = RB_BLACK; \ - if (RB_LEFT(tmp, field)) \ - RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\ - RB_ROTATE_RIGHT(head, parent, tmp, field);\ - elm = RB_ROOT(head); \ - break; \ - } \ - } \ - } \ - if (elm) \ - RB_COLOR(elm, field) = RB_BLACK; \ -} \ - \ -attr struct type * \ -name##_RB_REMOVE(struct name *head, struct type *elm) \ -{ \ - struct type *child, *parent, *old = elm; \ - int color; \ - if (RB_LEFT(elm, field) == NULL) \ - child = RB_RIGHT(elm, field); \ - else if (RB_RIGHT(elm, field) == NULL) \ - child = RB_LEFT(elm, field); \ - else { \ - struct type *left; \ - elm = RB_RIGHT(elm, field); \ - while ((left = RB_LEFT(elm, field)) != NULL) \ - elm = left; \ - child = RB_RIGHT(elm, field); \ - parent = RB_PARENT(elm, field); \ - color = RB_COLOR(elm, field); \ - if (child) \ - RB_PARENT(child, field) = parent; \ - if (parent) { \ - if (RB_LEFT(parent, field) == elm) \ - RB_LEFT(parent, field) = child; \ - else \ - RB_RIGHT(parent, field) = child; \ - RB_AUGMENT(parent); \ - } else \ - RB_ROOT(head) = child; \ - if (RB_PARENT(elm, field) == old) \ - parent = elm; \ - (elm)->field = (old)->field; \ - if (RB_PARENT(old, field)) { \ - if (RB_LEFT(RB_PARENT(old, field), field) == old)\ - RB_LEFT(RB_PARENT(old, field), field) = elm;\ - else \ - RB_RIGHT(RB_PARENT(old, field), field) = elm;\ - RB_AUGMENT(RB_PARENT(old, field)); \ - } else \ - RB_ROOT(head) = elm; \ - RB_PARENT(RB_LEFT(old, field), field) = elm; \ - if (RB_RIGHT(old, field)) \ - RB_PARENT(RB_RIGHT(old, field), field) = elm; \ - if (parent) { \ - left = parent; \ - do { \ - RB_AUGMENT(left); \ - } while ((left = RB_PARENT(left, field)) != NULL); \ - } \ - goto color; \ - } \ - parent = RB_PARENT(elm, field); \ - color = RB_COLOR(elm, field); \ - if (child) \ - RB_PARENT(child, field) = parent; \ - if (parent) { \ - if (RB_LEFT(parent, field) == elm) \ - RB_LEFT(parent, field) = child; \ - else \ - RB_RIGHT(parent, field) = child; \ - RB_AUGMENT(parent); \ - } else \ - RB_ROOT(head) = child; \ -color: \ - if (color == RB_BLACK) \ - name##_RB_REMOVE_COLOR(head, parent, child); \ - return (old); \ -} \ - \ -/* Inserts a node into the RB tree */ \ -attr struct type * \ -name##_RB_INSERT(struct name *head, struct type *elm) \ -{ \ - struct type *tmp; \ - struct type *parent = NULL; \ - int comp = 0; \ - tmp = RB_ROOT(head); \ - while (tmp) { \ - parent = tmp; \ - comp = (cmp)(elm, parent); \ - if (comp < 0) \ - tmp = RB_LEFT(tmp, field); \ - else if (comp > 0) \ - tmp = RB_RIGHT(tmp, field); \ - else \ - return (tmp); \ - } \ - RB_SET(elm, parent, field); \ - if (parent != NULL) { \ - if (comp < 0) \ - RB_LEFT(parent, field) = elm; \ - else \ - RB_RIGHT(parent, field) = elm; \ - RB_AUGMENT(parent); \ - } else \ - RB_ROOT(head) = elm; \ - name##_RB_INSERT_COLOR(head, elm); \ - return (NULL); \ -} \ - \ -/* Finds the node with the same key as elm */ \ -attr struct type * \ -name##_RB_FIND(struct name *head, struct type *elm) \ -{ \ - struct type *tmp = RB_ROOT(head); \ - int comp; \ - while (tmp) { \ - comp = cmp(elm, tmp); \ - if (comp < 0) \ - tmp = RB_LEFT(tmp, field); \ - else if (comp > 0) \ - tmp = RB_RIGHT(tmp, field); \ - else \ - return (tmp); \ - } \ - return (NULL); \ -} \ - \ -/* Finds the first node greater than or equal to the search key */ \ -attr struct type * \ -name##_RB_NFIND(struct name *head, struct type *elm) \ -{ \ - struct type *tmp = RB_ROOT(head); \ - struct type *res = NULL; \ - int comp; \ - while (tmp) { \ - comp = cmp(elm, tmp); \ - if (comp < 0) { \ - res = tmp; \ - tmp = RB_LEFT(tmp, field); \ - } \ - else if (comp > 0) \ - tmp = RB_RIGHT(tmp, field); \ - else \ - return (tmp); \ - } \ - return (res); \ -} \ - \ -/* ARGSUSED */ \ -attr struct type * \ -name##_RB_NEXT(struct type *elm) \ -{ \ - if (RB_RIGHT(elm, field)) { \ - elm = RB_RIGHT(elm, field); \ - while (RB_LEFT(elm, field)) \ - elm = RB_LEFT(elm, field); \ - } else { \ - if (RB_PARENT(elm, field) && \ - (elm == RB_LEFT(RB_PARENT(elm, field), field))) \ - elm = RB_PARENT(elm, field); \ - else { \ - while (RB_PARENT(elm, field) && \ - (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\ - elm = RB_PARENT(elm, field); \ - elm = RB_PARENT(elm, field); \ - } \ - } \ - return (elm); \ -} \ - \ -/* ARGSUSED */ \ -attr struct type * \ -name##_RB_PREV(struct type *elm) \ -{ \ - if (RB_LEFT(elm, field)) { \ - elm = RB_LEFT(elm, field); \ - while (RB_RIGHT(elm, field)) \ - elm = RB_RIGHT(elm, field); \ - } else { \ - if (RB_PARENT(elm, field) && \ - (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \ - elm = RB_PARENT(elm, field); \ - else { \ - while (RB_PARENT(elm, field) && \ - (elm == RB_LEFT(RB_PARENT(elm, field), field)))\ - elm = RB_PARENT(elm, field); \ - elm = RB_PARENT(elm, field); \ - } \ - } \ - return (elm); \ -} \ - \ -attr struct type * \ -name##_RB_MINMAX(struct name *head, int val) \ -{ \ - struct type *tmp = RB_ROOT(head); \ - struct type *parent = NULL; \ - while (tmp) { \ - parent = tmp; \ - if (val < 0) \ - tmp = RB_LEFT(tmp, field); \ - else \ - tmp = RB_RIGHT(tmp, field); \ - } \ - return (parent); \ +{ \ + struct type *tmp; \ + while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) && \ + elm != RB_ROOT(head)) { \ + if (RB_LEFT(parent, field) == elm) { \ + tmp = RB_RIGHT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\ + struct type *oleft; \ + if ((oleft = RB_LEFT(tmp, field)) \ + != NULL) \ + RB_COLOR(oleft, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_RIGHT(head, tmp, oleft, field);\ + tmp = RB_RIGHT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_RIGHT(tmp, field)) \ + RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_LEFT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } else { \ + tmp = RB_LEFT(parent, field); \ + if (RB_COLOR(tmp, field) == RB_RED) { \ + RB_SET_BLACKRED(tmp, parent, field); \ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + if ((RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\ + (RB_RIGHT(tmp, field) == NULL || \ + RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\ + RB_COLOR(tmp, field) = RB_RED; \ + elm = parent; \ + parent = RB_PARENT(elm, field); \ + } else { \ + if (RB_LEFT(tmp, field) == NULL || \ + RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\ + struct type *oright; \ + if ((oright = RB_RIGHT(tmp, field)) \ + != NULL) \ + RB_COLOR(oright, field) = RB_BLACK;\ + RB_COLOR(tmp, field) = RB_RED; \ + RB_ROTATE_LEFT(head, tmp, oright, field);\ + tmp = RB_LEFT(parent, field); \ + } \ + RB_COLOR(tmp, field) = RB_COLOR(parent, field);\ + RB_COLOR(parent, field) = RB_BLACK; \ + if (RB_LEFT(tmp, field)) \ + RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\ + RB_ROTATE_RIGHT(head, parent, tmp, field);\ + elm = RB_ROOT(head); \ + break; \ + } \ + } \ + } \ + if (elm) \ + RB_COLOR(elm, field) = RB_BLACK; \ +} \ + \ +attr struct type * \ +name##_RB_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *child, *parent, *old = elm; \ + int color; \ + if (RB_LEFT(elm, field) == NULL) \ + child = RB_RIGHT(elm, field); \ + else if (RB_RIGHT(elm, field) == NULL) \ + child = RB_LEFT(elm, field); \ + else { \ + struct type *left; \ + elm = RB_RIGHT(elm, field); \ + while ((left = RB_LEFT(elm, field)) != NULL) \ + elm = left; \ + child = RB_RIGHT(elm, field); \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ + if (RB_PARENT(elm, field) == old) \ + parent = elm; \ + (elm)->field = (old)->field; \ + if (RB_PARENT(old, field)) { \ + if (RB_LEFT(RB_PARENT(old, field), field) == old)\ + RB_LEFT(RB_PARENT(old, field), field) = elm;\ + else \ + RB_RIGHT(RB_PARENT(old, field), field) = elm;\ + RB_AUGMENT(RB_PARENT(old, field)); \ + } else \ + RB_ROOT(head) = elm; \ + RB_PARENT(RB_LEFT(old, field), field) = elm; \ + if (RB_RIGHT(old, field)) \ + RB_PARENT(RB_RIGHT(old, field), field) = elm; \ + if (parent) { \ + left = parent; \ + do { \ + RB_AUGMENT(left); \ + } while ((left = RB_PARENT(left, field)) != NULL); \ + } \ + goto color; \ + } \ + parent = RB_PARENT(elm, field); \ + color = RB_COLOR(elm, field); \ + if (child) \ + RB_PARENT(child, field) = parent; \ + if (parent) { \ + if (RB_LEFT(parent, field) == elm) \ + RB_LEFT(parent, field) = child; \ + else \ + RB_RIGHT(parent, field) = child; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = child; \ +color: \ + if (color == RB_BLACK) \ + name##_RB_REMOVE_COLOR(head, parent, child); \ + return (old); \ +} \ + \ +/* Inserts a node into the RB tree */ \ +attr struct type * \ +name##_RB_INSERT(struct name *head, struct type *elm) \ +{ \ + struct type *tmp; \ + struct type *parent = NULL; \ + int comp = 0; \ + tmp = RB_ROOT(head); \ + while (tmp) { \ + parent = tmp; \ + comp = (cmp)(elm, parent); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + RB_SET(elm, parent, field); \ + if (parent != NULL) { \ + if (comp < 0) \ + RB_LEFT(parent, field) = elm; \ + else \ + RB_RIGHT(parent, field) = elm; \ + RB_AUGMENT(parent); \ + } else \ + RB_ROOT(head) = elm; \ + name##_RB_INSERT_COLOR(head, elm); \ + return (NULL); \ +} \ + \ +/* Finds the node with the same key as elm */ \ +attr struct type * \ +name##_RB_FIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) \ + tmp = RB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (NULL); \ +} \ + \ +/* Finds the first node greater than or equal to the search key */ \ +attr struct type * \ +name##_RB_NFIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *res = NULL; \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) { \ + res = tmp; \ + tmp = RB_LEFT(tmp, field); \ + } \ + else if (comp > 0) \ + tmp = RB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (res); \ +} \ + \ +/* ARGSUSED */ \ +attr struct type * \ +name##_RB_NEXT(struct type *elm) \ +{ \ + if (RB_RIGHT(elm, field)) { \ + elm = RB_RIGHT(elm, field); \ + while (RB_LEFT(elm, field)) \ + elm = RB_LEFT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +/* ARGSUSED */ \ +attr struct type * \ +name##_RB_PREV(struct type *elm) \ +{ \ + if (RB_LEFT(elm, field)) { \ + elm = RB_LEFT(elm, field); \ + while (RB_RIGHT(elm, field)) \ + elm = RB_RIGHT(elm, field); \ + } else { \ + if (RB_PARENT(elm, field) && \ + (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \ + elm = RB_PARENT(elm, field); \ + else { \ + while (RB_PARENT(elm, field) && \ + (elm == RB_LEFT(RB_PARENT(elm, field), field)))\ + elm = RB_PARENT(elm, field); \ + elm = RB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +attr struct type * \ +name##_RB_MINMAX(struct name *head, int val) \ +{ \ + struct type *tmp = RB_ROOT(head); \ + struct type *parent = NULL; \ + while (tmp) { \ + parent = tmp; \ + if (val < 0) \ + tmp = RB_LEFT(tmp, field); \ + else \ + tmp = RB_RIGHT(tmp, field); \ + } \ + return (parent); \ } -#define RB_NEGINF -1 -#define RB_INF 1 +#define RB_NEGINF -1 +#define RB_INF 1 -#define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) -#define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) -#define RB_FIND(name, x, y) name##_RB_FIND(x, y) -#define RB_NFIND(name, x, y) name##_RB_NFIND(x, y) -#define RB_NEXT(name, x, y) name##_RB_NEXT(y) -#define RB_PREV(name, x, y) name##_RB_PREV(y) -#define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) -#define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) +#define RB_INSERT(name, x, y) name##_RB_INSERT(x, y) +#define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y) +#define RB_FIND(name, x, y) name##_RB_FIND(x, y) +#define RB_NFIND(name, x, y) name##_RB_NFIND(x, y) +#define RB_NEXT(name, x, y) name##_RB_NEXT(y) +#define RB_PREV(name, x, y) name##_RB_PREV(y) +#define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF) +#define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF) -#define RB_FOREACH(x, name, head) \ - for ((x) = RB_MIN(name, head); \ - (x) != NULL; \ - (x) = name##_RB_NEXT(x)) +#define RB_FOREACH(x, name, head) \ + for ((x) = RB_MIN(name, head); \ + (x) != NULL; \ + (x) = name##_RB_NEXT(x)) -#define RB_FOREACH_REVERSE(x, name, head) \ - for ((x) = RB_MAX(name, head); \ - (x) != NULL; \ - (x) = name##_RB_PREV(x)) +#define RB_FOREACH_REVERSE(x, name, head) \ + for ((x) = RB_MAX(name, head); \ + (x) != NULL; \ + (x) = name##_RB_PREV(x)) -#endif /* _SYS_TREE_H_ */ +#endif /* _SYS_TREE_H_ */ diff --git a/components/rtgui/include/rtgui/widgets/box.h b/components/rtgui/include/rtgui/widgets/box.h index 621a64991d..efe13c5f38 100644 --- a/components/rtgui/include/rtgui/widgets/box.h +++ b/components/rtgui/include/rtgui/widgets/box.h @@ -22,31 +22,31 @@ extern "C" { #endif -DECLARE_CLASS_TYPE(box); + DECLARE_CLASS_TYPE(box); -/** Gets the type of a box */ + /** Gets the type of a box */ #define RTGUI_BOX_TYPE (RTGUI_TYPE(box)) -/** Casts the object to an rtgui_box */ + /** Casts the object to an rtgui_box */ #define RTGUI_BOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_BOX_TYPE, rtgui_box_t)) -/** Checks if the object is an rtgui_box */ + /** Checks if the object is an rtgui_box */ #define RTGUI_IS_BOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_BOX_TYPE)) -struct rtgui_box -{ - struct rtgui_object parent; + struct rtgui_box + { + struct rtgui_object parent; - rt_uint16_t orient; - rt_uint16_t border_size; + rt_uint16_t orient; + rt_uint16_t border_size; - struct rtgui_container* container; -}; -typedef struct rtgui_box rtgui_box_t; + struct rtgui_container *container; + }; + typedef struct rtgui_box rtgui_box_t; -struct rtgui_box* rtgui_box_create(int orientation, int border_size); -void rtgui_box_destroy(struct rtgui_box* box); + struct rtgui_box *rtgui_box_create(int orientation, int border_size); + void rtgui_box_destroy(struct rtgui_box *box); -void rtgui_box_layout(rtgui_box_t* box); -void rtgui_box_layout_rect(rtgui_box_t* box, struct rtgui_rect* rect); + void rtgui_box_layout(rtgui_box_t *box); + void rtgui_box_layout_rect(rtgui_box_t *box, struct rtgui_rect *rect); #ifdef __cplusplus } diff --git a/components/rtgui/include/rtgui/widgets/button.h b/components/rtgui/include/rtgui/widgets/button.h index b149c5a2a2..c414b17961 100644 --- a/components/rtgui/include/rtgui/widgets/button.h +++ b/components/rtgui/include/rtgui/widgets/button.h @@ -22,57 +22,57 @@ extern "C" { #endif -/** - * @defgroup rtgui_button - * @{ - */ + /** + * @defgroup rtgui_button + * @{ + */ -DECLARE_CLASS_TYPE(button); + DECLARE_CLASS_TYPE(button); -/** Gets the type of a button */ + /** Gets the type of a button */ #define RTGUI_BUTTON_TYPE (RTGUI_TYPE(button)) -/** Casts the object to an rtgui_button */ + /** Casts the object to an rtgui_button */ #define RTGUI_BUTTON(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_BUTTON_TYPE, rtgui_button_t)) -/** Checks if the object is an rtgui_button */ + /** Checks if the object is an rtgui_button */ #define RTGUI_IS_BUTTON(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_BUTTON_TYPE)) -#define RTGUI_BUTTON_FLAG_PRESS 0x01 -#define RTGUI_BUTTON_FLAG_DEFAULT 0x02 +#define RTGUI_BUTTON_FLAG_PRESS 0x01 +#define RTGUI_BUTTON_FLAG_DEFAULT 0x02 -#define RTGUI_BUTTON_TYPE_NORMAL 0x00 -#define RTGUI_BUTTON_TYPE_PUSH 0x10 +#define RTGUI_BUTTON_TYPE_NORMAL 0x00 +#define RTGUI_BUTTON_TYPE_PUSH 0x10 -/* - * the button widget - */ -struct rtgui_button -{ - /* inherit from label */ - struct rtgui_label parent; + /* + * the button widget + */ + struct rtgui_button + { + /* inherit from label */ + struct rtgui_label parent; - /* button flag */ - rt_base_t flag; + /* button flag */ + rt_base_t flag; - /* pressed and unpressed image */ - rtgui_image_t *pressed_image, *unpressed_image; + /* pressed and unpressed image */ + rtgui_image_t *pressed_image, *unpressed_image; - /* click button event handler */ - rtgui_onbutton_func_t on_button; -}; -typedef struct rtgui_button rtgui_button_t; + /* click button event handler */ + rtgui_onbutton_func_t on_button; + }; + typedef struct rtgui_button rtgui_button_t; -rtgui_button_t* rtgui_button_create(const char* text); -rtgui_button_t* rtgui_pushbutton_create(const char* text); -void rtgui_button_destroy(rtgui_button_t* btn); + rtgui_button_t *rtgui_button_create(const char *text); + rtgui_button_t *rtgui_pushbutton_create(const char *text); + void rtgui_button_destroy(rtgui_button_t *btn); -void rtgui_button_set_pressed_image(rtgui_button_t* btn, rtgui_image_t* image); -void rtgui_button_set_unpressed_image(rtgui_button_t* btn, rtgui_image_t* image); + void rtgui_button_set_pressed_image(rtgui_button_t *btn, rtgui_image_t *image); + void rtgui_button_set_unpressed_image(rtgui_button_t *btn, rtgui_image_t *image); -void rtgui_button_set_onbutton(rtgui_button_t* btn, rtgui_onbutton_func_t func); + void rtgui_button_set_onbutton(rtgui_button_t *btn, rtgui_onbutton_func_t func); -rt_bool_t rtgui_button_event_handler(struct rtgui_object* object, struct rtgui_event* event); + rt_bool_t rtgui_button_event_handler(struct rtgui_object *object, struct rtgui_event *event); -/** @} */ + /** @} */ #ifdef __cplusplus } diff --git a/components/rtgui/include/rtgui/widgets/checkbox.h b/components/rtgui/include/rtgui/widgets/checkbox.h index c23b5d79a1..d526d23d2f 100644 --- a/components/rtgui/include/rtgui/widgets/checkbox.h +++ b/components/rtgui/include/rtgui/widgets/checkbox.h @@ -14,30 +14,30 @@ DECLARE_CLASS_TYPE(checkbox); /** Checks if the object is an rtgui_button */ #define RTGUI_IS_CHECKBOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_CHECKBOX_TYPE)) -#define RTGUI_CHECKBOX_STATUS_CHECKED 0 -#define RTGUI_CHECKBOX_STATUS_UNCHECKED 1 +#define RTGUI_CHECKBOX_STATUS_CHECKED 0 +#define RTGUI_CHECKBOX_STATUS_UNCHECKED 1 struct rtgui_checkbox { - /* inherit from label */ - struct rtgui_label parent; + /* inherit from label */ + struct rtgui_label parent; - /* check box status */ - rt_uint8_t status_down; + /* check box status */ + rt_uint8_t status_down; - /* click button event handler */ - rtgui_onbutton_func_t on_button; + /* click button event handler */ + rtgui_onbutton_func_t on_button; }; typedef struct rtgui_checkbox rtgui_checkbox_t; -rtgui_checkbox_t* rtgui_checkbox_create(const char* text, rt_bool_t checked); -void rtgui_checkbox_destroy(rtgui_checkbox_t* checkbox); +rtgui_checkbox_t *rtgui_checkbox_create(const char *text, rt_bool_t checked); +void rtgui_checkbox_destroy(rtgui_checkbox_t *checkbox); -void rtgui_checkbox_set_checked(rtgui_checkbox_t* checkbox, rt_bool_t checked); -rt_bool_t rtgui_checkbox_get_checked(rtgui_checkbox_t* checkbox); +void rtgui_checkbox_set_checked(rtgui_checkbox_t *checkbox, rt_bool_t checked); +rt_bool_t rtgui_checkbox_get_checked(rtgui_checkbox_t *checkbox); -void rtgui_checkbox_set_onbutton(rtgui_checkbox_t* checkbox, rtgui_onbutton_func_t func); +void rtgui_checkbox_set_onbutton(rtgui_checkbox_t *checkbox, rtgui_onbutton_func_t func); -rt_bool_t rtgui_checkbox_event_handler(struct rtgui_object* object, struct rtgui_event* event); +rt_bool_t rtgui_checkbox_event_handler(struct rtgui_object *object, struct rtgui_event *event); #endif diff --git a/components/rtgui/include/rtgui/widgets/combobox.h b/components/rtgui/include/rtgui/widgets/combobox.h index 6be860b76b..b10a3e93eb 100644 --- a/components/rtgui/include/rtgui/widgets/combobox.h +++ b/components/rtgui/include/rtgui/widgets/combobox.h @@ -14,36 +14,36 @@ DECLARE_CLASS_TYPE(combobox); /** Checks if the object is a rtgui_combobox */ #define RTGUI_IS_COMBOBOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_COMBOBOX_TYPE)) -#define RTGUI_COMBOBOX_WIDTH 75 -#define RTGUI_COMBOBOX_HEIGHT 20 -#define RTGUI_COMBOBOX_BUTTON_WIDTH 18 +#define RTGUI_COMBOBOX_WIDTH 75 +#define RTGUI_COMBOBOX_HEIGHT 20 +#define RTGUI_COMBOBOX_BUTTON_WIDTH 18 struct rtgui_combobox { - struct rtgui_widget parent; + struct rtgui_widget parent; - /* widget private data */ + /* widget private data */ - /* pull down window */ - struct rtgui_win* pd_win; - rt_bool_t pd_pressed; + /* pull down window */ + struct rtgui_win *pd_win; + rt_bool_t pd_pressed; - /* combobox items */ - struct rtgui_listbox_item* items; - rt_uint16_t items_count; - rt_uint16_t current_item; + /* combobox items */ + struct rtgui_listbox_item *items; + rt_uint16_t items_count; + rt_uint16_t current_item; - /* call back */ - rtgui_event_handler_ptr on_selected; + /* call back */ + rtgui_event_handler_ptr on_selected; }; typedef struct rtgui_combobox rtgui_combobox_t; -rtgui_combobox_t *rtgui_combobox_create(struct rtgui_listbox_item* items, rt_uint16_t counter, struct rtgui_rect* rect); -void rtgui_combobox_destroy(rtgui_combobox_t* box); +rtgui_combobox_t *rtgui_combobox_create(struct rtgui_listbox_item *items, rt_uint16_t counter, struct rtgui_rect *rect); +void rtgui_combobox_destroy(rtgui_combobox_t *box); -rt_bool_t rtgui_combobox_event_handler(struct rtgui_object* object, struct rtgui_event* event); -struct rtgui_listbox_item* rtgui_combox_get_select(struct rtgui_combobox* box); +rt_bool_t rtgui_combobox_event_handler(struct rtgui_object *object, struct rtgui_event *event); +struct rtgui_listbox_item *rtgui_combox_get_select(struct rtgui_combobox *box); -void rtgui_combobox_set_onselected(struct rtgui_combobox* box, rtgui_event_handler_ptr func); +void rtgui_combobox_set_onselected(struct rtgui_combobox *box, rtgui_event_handler_ptr func); #endif diff --git a/components/rtgui/include/rtgui/widgets/container.h b/components/rtgui/include/rtgui/widgets/container.h index 990876992b..d7798b1b11 100644 --- a/components/rtgui/include/rtgui/widgets/container.h +++ b/components/rtgui/include/rtgui/widgets/container.h @@ -21,46 +21,46 @@ extern "C" { #endif -DECLARE_CLASS_TYPE(container); -/** Gets the type of a container */ + DECLARE_CLASS_TYPE(container); + /** Gets the type of a container */ #define RTGUI_CONTAINER_TYPE (RTGUI_TYPE(container)) -/** Casts the object to an rtgui_container */ + /** Casts the object to an rtgui_container */ #define RTGUI_CONTAINER(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_CONTAINER_TYPE, rtgui_container_t)) -/** Checks if the object is an rtgui_container */ + /** Checks if the object is an rtgui_container */ #define RTGUI_IS_CONTAINER(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_CONTAINER_TYPE)) -/* - * the container widget - */ -struct rtgui_container -{ - struct rtgui_widget parent; + /* + * the container widget + */ + struct rtgui_container + { + struct rtgui_widget parent; - /* layout box */ - struct rtgui_box* layout_box; + /* layout box */ + struct rtgui_box *layout_box; - rtgui_list_t children; -}; -typedef struct rtgui_container rtgui_container_t; + rtgui_list_t children; + }; + typedef struct rtgui_container rtgui_container_t; -rtgui_container_t* rtgui_container_create(void); -void rtgui_container_destroy(rtgui_container_t* container); + rtgui_container_t *rtgui_container_create(void); + void rtgui_container_destroy(rtgui_container_t *container); -rt_bool_t rtgui_container_event_handler(struct rtgui_object* widget, struct rtgui_event* event); + rt_bool_t rtgui_container_event_handler(struct rtgui_object *widget, struct rtgui_event *event); -/* set layout box */ -void rtgui_container_set_box(struct rtgui_container* container, struct rtgui_box* box); -void rtgui_container_layout(struct rtgui_container* container); + /* set layout box */ + void rtgui_container_set_box(struct rtgui_container *container, struct rtgui_box *box); + void rtgui_container_layout(struct rtgui_container *container); -void rtgui_container_add_child(rtgui_container_t *container, rtgui_widget_t* child); -void rtgui_container_remove_child(rtgui_container_t *container, rtgui_widget_t* child); -void rtgui_container_destroy_children(rtgui_container_t *container); -rtgui_widget_t* rtgui_container_get_first_child(rtgui_container_t* container); + void rtgui_container_add_child(rtgui_container_t *container, rtgui_widget_t *child); + void rtgui_container_remove_child(rtgui_container_t *container, rtgui_widget_t *child); + void rtgui_container_destroy_children(rtgui_container_t *container); + rtgui_widget_t *rtgui_container_get_first_child(rtgui_container_t *container); -rt_bool_t rtgui_container_event_handler(struct rtgui_object* widget, rtgui_event_t* event); + rt_bool_t rtgui_container_event_handler(struct rtgui_object *widget, rtgui_event_t *event); -rt_bool_t rtgui_container_dispatch_event(rtgui_container_t *container, rtgui_event_t* event); -rt_bool_t rtgui_container_dispatch_mouse_event(rtgui_container_t *container, struct rtgui_event_mouse* event); + rt_bool_t rtgui_container_dispatch_event(rtgui_container_t *container, rtgui_event_t *event); + rt_bool_t rtgui_container_dispatch_mouse_event(rtgui_container_t *container, struct rtgui_event_mouse *event); #ifdef __cplusplus } diff --git a/components/rtgui/include/rtgui/widgets/edit.h b/components/rtgui/include/rtgui/widgets/edit.h index 75cbdd319a..ca2eb65295 100644 --- a/components/rtgui/include/rtgui/widgets/edit.h +++ b/components/rtgui/include/rtgui/widgets/edit.h @@ -21,91 +21,91 @@ extern "C" { #endif -DECLARE_CLASS_TYPE(edit); + DECLARE_CLASS_TYPE(edit); -/** Gets the type of a edit */ + /** Gets the type of a edit */ #define RTGUI_EDIT_TYPE (RTGUI_TYPE(edit)) -/** Casts the object to a rtgui_edit */ + /** Casts the object to a rtgui_edit */ #define RTGUI_EDIT(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_EDIT_TYPE, struct rtgui_edit)) -/** Checks if the object is a rtgui_edit */ + /** Checks if the object is a rtgui_edit */ #define RTGUI_IS_EDIT(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_EDIT_TYPE)) -#define RTGUI_EDIT_NONE 0x00 -#define RTGUI_EDIT_CARET 0x01 -#define RTGUI_EDIT_VSCROLL 0x02 -#define RTGUI_EDIT_HSCROLL 0x04 -#define RTGUI_EDIT_SHIFT 0x10 -#define RTGUI_EDIT_CTRL 0x20 -#define RTGUI_EDIT_ALT 0x40 -#define RTGUI_EDIT_CAPSLOCK 0x80 -#define RTGUI_EDIT_NUMLOCK 0x100 +#define RTGUI_EDIT_NONE 0x00 +#define RTGUI_EDIT_CARET 0x01 +#define RTGUI_EDIT_VSCROLL 0x02 +#define RTGUI_EDIT_HSCROLL 0x04 +#define RTGUI_EDIT_SHIFT 0x10 +#define RTGUI_EDIT_CTRL 0x20 +#define RTGUI_EDIT_ALT 0x40 +#define RTGUI_EDIT_CAPSLOCK 0x80 +#define RTGUI_EDIT_NUMLOCK 0x100 -struct edit_update -{ - /* rt_uint32_t type; */ /* update type */ - rtgui_point_t start, end; /* update area */ -}; + struct edit_update + { + /* rt_uint32_t type; */ /* update type */ + rtgui_point_t start, end; /* update area */ + }; -struct edit_line -{ - rt_int16_t zsize; /* zone size */ - rt_int16_t len; - struct edit_line *prev; - struct edit_line *next; - char *text; -}; + struct edit_line + { + rt_int16_t zsize; /* zone size */ + rt_int16_t len; + struct edit_line *prev; + struct edit_line *next; + char *text; + }; -struct rtgui_edit -{ - /* inherit from container */ - rtgui_container_t parent; + struct rtgui_edit + { + /* inherit from container */ + rtgui_container_t parent; - /* edit flag */ - rt_uint32_t flag; - rt_int16_t max_rows, max_cols; - rt_int16_t row_per_page, col_per_page; - rtgui_point_t upleft; - rtgui_point_t visual; - rt_uint8_t tabsize; - rt_uint8_t item_height; - rt_uint8_t font_width,font_height; - rt_uint8_t margin; - rt_int16_t bzsize; /* base zone size */ - - struct rtgui_timer *caret_timer; - rtgui_color_t *caret; - rtgui_rect_t caret_rect; - struct edit_update update; - char *update_buf; /* speed up renewal process */ - struct rtgui_dc *dbl_buf; - - struct edit_line *head; - struct edit_line *tail; - struct edit_line *first_line; + /* edit flag */ + rt_uint32_t flag; + rt_int16_t max_rows, max_cols; + rt_int16_t row_per_page, col_per_page; + rtgui_point_t upleft; + rtgui_point_t visual; + rt_uint8_t tabsize; + rt_uint8_t item_height; + rt_uint8_t font_width, font_height; + rt_uint8_t margin; + rt_int16_t bzsize; /* base zone size */ + + struct rtgui_timer *caret_timer; + rtgui_color_t *caret; + rtgui_rect_t caret_rect; + struct edit_update update; + char *update_buf; /* speed up renewal process */ + struct rtgui_dc *dbl_buf; + + struct edit_line *head; + struct edit_line *tail; + struct edit_line *first_line; #ifdef RTGUI_EDIT_USING_SCROLL - struct rtgui_scrollbar *hscroll; - struct rtgui_scrollbar *vscroll; + struct rtgui_scrollbar *hscroll; + struct rtgui_scrollbar *vscroll; #endif -}; + }; -rt_bool_t rtgui_edit_append_line(struct rtgui_edit *edit, const char *text); -rt_bool_t rtgui_edit_insert_line(struct rtgui_edit *edit, struct edit_line *p, char *text); -rt_bool_t rtgui_edit_delete_line(struct rtgui_edit *edit, struct edit_line *line); -rt_bool_t rtgui_edit_connect_line(struct rtgui_edit *edit, struct edit_line *line, struct edit_line *connect); + rt_bool_t rtgui_edit_append_line(struct rtgui_edit *edit, const char *text); + rt_bool_t rtgui_edit_insert_line(struct rtgui_edit *edit, struct edit_line *p, char *text); + rt_bool_t rtgui_edit_delete_line(struct rtgui_edit *edit, struct edit_line *line); + rt_bool_t rtgui_edit_connect_line(struct rtgui_edit *edit, struct edit_line *line, struct edit_line *connect); -void _rtgui_edit_constructor(struct rtgui_edit *box); -void _rtgui_edit_deconstructor(struct rtgui_edit *textbox); + void _rtgui_edit_constructor(struct rtgui_edit *box); + void _rtgui_edit_deconstructor(struct rtgui_edit *textbox); -struct rtgui_edit* rtgui_edit_create(struct rtgui_container* container, int left, int top, int w, int h); -void rtgui_edit_destroy(struct rtgui_edit *edit); -void rtgui_edit_update(struct rtgui_edit *edit); -void rtgui_edit_ondraw(struct rtgui_edit *edit); -rt_bool_t rtgui_edit_event_handler(struct rtgui_object* object, rtgui_event_t* event); -void rtgui_edit_set_text(struct rtgui_edit *edit, const char* text); -rtgui_point_t rtgui_edit_get_current_point(struct rtgui_edit *edit); -rt_uint32_t rtgui_edit_get_mem_consume(struct rtgui_edit *edit); -rt_bool_t rtgui_edit_readin_file(struct rtgui_edit *edit, const char *filename); -rt_bool_t rtgui_edit_saveas_file(struct rtgui_edit *edit, const char *filename); + struct rtgui_edit *rtgui_edit_create(struct rtgui_container *container, int left, int top, int w, int h); + void rtgui_edit_destroy(struct rtgui_edit *edit); + void rtgui_edit_update(struct rtgui_edit *edit); + void rtgui_edit_ondraw(struct rtgui_edit *edit); + rt_bool_t rtgui_edit_event_handler(struct rtgui_object *object, rtgui_event_t *event); + void rtgui_edit_set_text(struct rtgui_edit *edit, const char *text); + rtgui_point_t rtgui_edit_get_current_point(struct rtgui_edit *edit); + rt_uint32_t rtgui_edit_get_mem_consume(struct rtgui_edit *edit); + rt_bool_t rtgui_edit_readin_file(struct rtgui_edit *edit, const char *filename); + rt_bool_t rtgui_edit_saveas_file(struct rtgui_edit *edit, const char *filename); #ifdef __cplusplus } diff --git a/components/rtgui/include/rtgui/widgets/filelist_view.h b/components/rtgui/include/rtgui/widgets/filelist_view.h index 78a38a2835..dcaa11de1d 100644 --- a/components/rtgui/include/rtgui/widgets/filelist_view.h +++ b/components/rtgui/include/rtgui/widgets/filelist_view.h @@ -8,10 +8,10 @@ #define RTGUI_FITEM_DIR 0x1 struct rtgui_file_item { - char* name; + char *name; - rt_uint32_t type; - rt_uint32_t size; + rt_uint32_t type; + rt_uint32_t size; }; DECLARE_CLASS_TYPE(filelist); @@ -24,35 +24,35 @@ DECLARE_CLASS_TYPE(filelist); struct rtgui_filelist_view { - struct rtgui_container parent; + struct rtgui_container parent; - /* widget private data */ + /* widget private data */ /* current directory */ - char* current_directory; - char* pattern; + char *current_directory; + char *pattern; /* the number of item in a page */ rt_uint16_t page_items; - rt_uint16_t items_count; + rt_uint16_t items_count; - /* the selected item */ - rt_uint16_t current_item; + /* the selected item */ + rt_uint16_t current_item; - /* items array */ - struct rtgui_file_item *items; + /* items array */ + struct rtgui_file_item *items; }; typedef struct rtgui_filelist_view rtgui_filelist_view_t; -rtgui_filelist_view_t* rtgui_filelist_view_create(const char* directory, - const char* pattern, - const rtgui_rect_t* rect); -void rtgui_filelist_view_destroy(rtgui_filelist_view_t* view); +rtgui_filelist_view_t *rtgui_filelist_view_create(const char *directory, + const char *pattern, + const rtgui_rect_t *rect); +void rtgui_filelist_view_destroy(rtgui_filelist_view_t *view); -rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_object* object, struct rtgui_event* event); -void rtgui_filelist_view_set_directory(rtgui_filelist_view_t* view, const char* directory); +rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_object *object, struct rtgui_event *event); +void rtgui_filelist_view_set_directory(rtgui_filelist_view_t *view, const char *directory); -void rtgui_filelist_view_get_fullpath(rtgui_filelist_view_t* view, char* path, rt_size_t len); +void rtgui_filelist_view_get_fullpath(rtgui_filelist_view_t *view, char *path, rt_size_t len); #endif #endif diff --git a/components/rtgui/include/rtgui/widgets/groupbox.h b/components/rtgui/include/rtgui/widgets/groupbox.h index 8cc06d4613..157424728d 100644 --- a/components/rtgui/include/rtgui/widgets/groupbox.h +++ b/components/rtgui/include/rtgui/widgets/groupbox.h @@ -28,45 +28,45 @@ DECLARE_CLASS_TYPE(groupbox); /** Checks if the object is an rtgui_groupbox */ #define RTGUI_IS_GROUPBOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_GROUPBOX_TYPE)) -typedef void (*widget_select_t)(struct rtgui_widget* widget, rt_bool_t selected); +typedef void (*widget_select_t)(struct rtgui_widget *widget, rt_bool_t selected); /* * the groupbox widget * - * The Group Box is a container widget, in which user can place some other widget into it. + * The Group Box is a container widget, in which user can place some other widget into it. * However, the current selected in group box must be notified by user: * - invoke rtgui_groupbox_select_widget to notify group box the current selected widget; - * - when a widget has been selected, group box invokes groupbox->select_func to change - * the status of widget, for example un-select this widget. + * - when a widget has been selected, group box invokes groupbox->select_func to change + * the status of widget, for example un-select this widget. */ struct rtgui_groupbox { - struct rtgui_panel parent; + struct rtgui_panel parent; - char* label; - struct rtgui_box *box; - struct rtgui_widget *selected; + char *label; + struct rtgui_box *box; + struct rtgui_widget *selected; - widget_select_t select_func; - rtgui_event_handler_ptr on_selected; + widget_select_t select_func; + rtgui_event_handler_ptr on_selected; }; typedef struct rtgui_groupbox rtgui_groupbox_t; -rtgui_groupbox_t* rtgui_groupbox_create(const char* label, struct rtgui_rect *rect, int style, widget_select_t select_func); -void rtgui_groupbox_destroy(rtgui_groupbox_t* groupbox); +rtgui_groupbox_t *rtgui_groupbox_create(const char *label, struct rtgui_rect *rect, int style, widget_select_t select_func); +void rtgui_groupbox_destroy(rtgui_groupbox_t *groupbox); void rtgui_groupbox_layout(struct rtgui_groupbox *box); void rtgui_groupbox_add_widget(struct rtgui_groupbox *box, struct rtgui_widget *widget); void rtgui_groupbox_select_widget(struct rtgui_groupbox *box, struct rtgui_widget *widget); -struct rtgui_widget* rtgui_groupbox_get_selected(struct rtgui_groupbox *box); +struct rtgui_widget *rtgui_groupbox_get_selected(struct rtgui_groupbox *box); -rt_bool_t rtgui_groupbox_event_handler(struct rtgui_object* object, struct rtgui_event* event); +rt_bool_t rtgui_groupbox_event_handler(struct rtgui_object *object, struct rtgui_event *event); -rt_inline void rtgui_groupbox_set_onselected(struct rtgui_groupbox* box, rtgui_event_handler_ptr on_selected) +rt_inline void rtgui_groupbox_set_onselected(struct rtgui_groupbox *box, rtgui_event_handler_ptr on_selected) { - RT_ASSERT(box != RT_NULL); - box->on_selected = on_selected; + RT_ASSERT(box != RT_NULL); + box->on_selected = on_selected; } #endif diff --git a/components/rtgui/include/rtgui/widgets/iconbox.h b/components/rtgui/include/rtgui/widgets/iconbox.h index 5c46f97342..f3f9b45e49 100644 --- a/components/rtgui/include/rtgui/widgets/iconbox.h +++ b/components/rtgui/include/rtgui/widgets/iconbox.h @@ -26,31 +26,31 @@ DECLARE_CLASS_TYPE(iconbox); /** Checks if the object is a rtgui_iconbox */ #define RTGUI_IS_ICONBOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_ICONBOX_TYPE)) -#define RTGUI_ICONBOX_NOTEXT 0x00 -#define RTGUI_ICONBOX_TEXT_RIGHT 0x01 -#define RTGUI_ICONBOX_TEXT_BELOW 0x02 +#define RTGUI_ICONBOX_NOTEXT 0x00 +#define RTGUI_ICONBOX_TEXT_RIGHT 0x01 +#define RTGUI_ICONBOX_TEXT_BELOW 0x02 struct rtgui_iconbox { - /* inherit from widget */ - struct rtgui_widget parent; + /* inherit from widget */ + struct rtgui_widget parent; - /* widget private data */ - struct rtgui_image* image; + /* widget private data */ + struct rtgui_image *image; - char *text; - rt_ubase_t text_position; + char *text; + rt_ubase_t text_position; - rt_bool_t selected; + rt_bool_t selected; }; typedef struct rtgui_iconbox rtgui_iconbox_t; -struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image, const char* text, int position); -void rtgui_iconbox_destroy(struct rtgui_iconbox* iconbox); +struct rtgui_iconbox *rtgui_iconbox_create(struct rtgui_image *image, const char *text, int position); +void rtgui_iconbox_destroy(struct rtgui_iconbox *iconbox); -rt_bool_t rtgui_iconbox_event_handler(struct rtgui_object* object, struct rtgui_event* event); +rt_bool_t rtgui_iconbox_event_handler(struct rtgui_object *object, struct rtgui_event *event); -void rtgui_iconbox_set_text_position(struct rtgui_iconbox* iconbox, int position); -void rtgui_iconbox_set_selected(struct rtgui_iconbox* iconbox, rt_bool_t selected); +void rtgui_iconbox_set_text_position(struct rtgui_iconbox *iconbox, int position); +void rtgui_iconbox_set_selected(struct rtgui_iconbox *iconbox, rt_bool_t selected); #endif diff --git a/components/rtgui/include/rtgui/widgets/label.h b/components/rtgui/include/rtgui/widgets/label.h index be75e3957d..8dfece1701 100644 --- a/components/rtgui/include/rtgui/widgets/label.h +++ b/components/rtgui/include/rtgui/widgets/label.h @@ -31,19 +31,19 @@ DECLARE_CLASS_TYPE(label); */ struct rtgui_label { - struct rtgui_widget parent; + struct rtgui_widget parent; - /* label */ - char* text; + /* label */ + char *text; }; typedef struct rtgui_label rtgui_label_t; -rtgui_label_t* rtgui_label_create(const char* text); -void rtgui_label_destroy(rtgui_label_t* label); +rtgui_label_t *rtgui_label_create(const char *text); +void rtgui_label_destroy(rtgui_label_t *label); -rt_bool_t rtgui_label_event_handler(struct rtgui_object* object, struct rtgui_event* event); +rt_bool_t rtgui_label_event_handler(struct rtgui_object *object, struct rtgui_event *event); -void rtgui_label_set_text(rtgui_label_t* label, const char* text); -char* rtgui_label_get_text(rtgui_label_t* label); +void rtgui_label_set_text(rtgui_label_t *label, const char *text); +char *rtgui_label_get_text(rtgui_label_t *label); #endif diff --git a/components/rtgui/include/rtgui/widgets/list_view.h b/components/rtgui/include/rtgui/widgets/list_view.h index 1ab062d263..b58210425b 100644 --- a/components/rtgui/include/rtgui/widgets/list_view.h +++ b/components/rtgui/include/rtgui/widgets/list_view.h @@ -21,11 +21,11 @@ #include <rtgui/widgets/container.h> -typedef void (*item_action)(struct rtgui_widget* widget, void* parameter); +typedef void (*item_action)(struct rtgui_widget *widget, void *parameter); struct rtgui_list_item { - char* name; - rtgui_image_t *image; + char *name; + rtgui_image_t *image; item_action action; void *parameter; @@ -39,38 +39,38 @@ DECLARE_CLASS_TYPE(listview); /** Checks if the object is a filelist view */ #define RTGUI_IS_LIST_VIEW(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_LIST_VIEW_TYPE)) -#define RTGUI_LIST_VIEW_LIST 0x00 -#define RTGUI_LIST_VIEW_ICON 0x01 -#define RTGUI_LIST_VIEW_REPORT 0x02 +#define RTGUI_LIST_VIEW_LIST 0x00 +#define RTGUI_LIST_VIEW_ICON 0x01 +#define RTGUI_LIST_VIEW_REPORT 0x02 struct rtgui_list_view { - struct rtgui_container parent; + struct rtgui_container parent; - /* widget private data */ - /* list item */ - const struct rtgui_list_item* items; + /* widget private data */ + /* list item */ + const struct rtgui_list_item *items; - /* layout flag */ - rt_uint16_t flag; + /* layout flag */ + rt_uint16_t flag; - /* total number of items */ - rt_uint16_t items_count; + /* total number of items */ + rt_uint16_t items_count; /* the number of item in a page */ rt_uint16_t page_items; - /* current item */ + /* current item */ rt_int16_t current_item; - /* icon layout */ - rt_uint8_t row_items, col_items; + /* icon layout */ + rt_uint8_t row_items, col_items; }; typedef struct rtgui_list_view rtgui_list_view_t; -rtgui_list_view_t* rtgui_list_view_create(const struct rtgui_list_item* items, rt_uint16_t count, - rtgui_rect_t *rect, rt_uint16_t flag); -void rtgui_list_view_destroy(rtgui_list_view_t* view); +rtgui_list_view_t *rtgui_list_view_create(const struct rtgui_list_item *items, rt_uint16_t count, + rtgui_rect_t *rect, rt_uint16_t flag); +void rtgui_list_view_destroy(rtgui_list_view_t *view); -rt_bool_t rtgui_list_view_event_handler(struct rtgui_object* widget, struct rtgui_event* event); +rt_bool_t rtgui_list_view_event_handler(struct rtgui_object *widget, struct rtgui_event *event); #endif diff --git a/components/rtgui/include/rtgui/widgets/listbox.h b/components/rtgui/include/rtgui/widgets/listbox.h index cb38802d53..a2fb035128 100644 --- a/components/rtgui/include/rtgui/widgets/listbox.h +++ b/components/rtgui/include/rtgui/widgets/listbox.h @@ -22,31 +22,31 @@ struct rtgui_listbox_item { - char* name; - rtgui_image_t *image; + char *name; + rtgui_image_t *image; }; DECLARE_CLASS_TYPE(listbox); /** Gets the type of a list box */ -#define RTGUI_LISTBOX_TYPE (RTGUI_TYPE(listbox)) +#define RTGUI_LISTBOX_TYPE (RTGUI_TYPE(listbox)) /** Casts the object to a filelist */ -#define RTGUI_LISTBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_LISTBOX_TYPE, rtgui_listbox_t)) +#define RTGUI_LISTBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_LISTBOX_TYPE, rtgui_listbox_t)) /** Checks if the object is a filelist box */ -#define RTGUI_IS_LISTBOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_LISTBOX_TYPE)) +#define RTGUI_IS_LISTBOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_LISTBOX_TYPE)) struct rtgui_listbox { - struct rtgui_widget parent; + struct rtgui_widget parent; - /* widget private data */ - /* listbox item */ - const struct rtgui_listbox_item* items; + /* widget private data */ + /* listbox item */ + const struct rtgui_listbox_item *items; - /* item event handler */ - rtgui_event_handler_ptr on_item; + /* item event handler */ + rtgui_event_handler_ptr on_item; - /* total number of items */ - rt_uint16_t items_count; + /* total number of items */ + rt_uint16_t items_count; /* the number of item in a page */ rt_uint16_t page_items; /* current item */ @@ -54,14 +54,14 @@ struct rtgui_listbox }; typedef struct rtgui_listbox rtgui_listbox_t; -rtgui_listbox_t* rtgui_listbox_create(const struct rtgui_listbox_item* items, rt_uint16_t count, - rtgui_rect_t *rect); -void rtgui_listbox_destroy(rtgui_listbox_t* box); +rtgui_listbox_t *rtgui_listbox_create(const struct rtgui_listbox_item *items, rt_uint16_t count, + rtgui_rect_t *rect); +void rtgui_listbox_destroy(rtgui_listbox_t *box); -rt_bool_t rtgui_listbox_event_handler(struct rtgui_object* object, struct rtgui_event* event); -void rtgui_listbox_set_onitem(rtgui_listbox_t* box, rtgui_event_handler_ptr func); -void rtgui_listbox_set_items(rtgui_listbox_t* box, struct rtgui_listbox_item* items, rt_uint16_t count); -void rtgui_listbox_set_current_item(rtgui_listbox_t* box, int index); +rt_bool_t rtgui_listbox_event_handler(struct rtgui_object *object, struct rtgui_event *event); +void rtgui_listbox_set_onitem(rtgui_listbox_t *box, rtgui_event_handler_ptr func); +void rtgui_listbox_set_items(rtgui_listbox_t *box, struct rtgui_listbox_item *items, rt_uint16_t count); +void rtgui_listbox_set_current_item(rtgui_listbox_t *box, int index); #endif diff --git a/components/rtgui/include/rtgui/widgets/listctrl.h b/components/rtgui/include/rtgui/widgets/listctrl.h index 51905f5942..79b123c3db 100644 --- a/components/rtgui/include/rtgui/widgets/listctrl.h +++ b/components/rtgui/include/rtgui/widgets/listctrl.h @@ -22,44 +22,45 @@ DECLARE_CLASS_TYPE(listctrl); /** Gets the type of a listctrl */ -#define RTGUI_LISTCTRL_TYPE (RTGUI_TYPE(listctrl)) +#define RTGUI_LISTCTRL_TYPE (RTGUI_TYPE(listctrl)) /** Casts the object to a listctrl */ -#define RTGUI_LISTCTRL(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_LISTCTRL_TYPE, rtgui_listctrl_t)) +#define RTGUI_LISTCTRL(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_LISTCTRL_TYPE, rtgui_listctrl_t)) /** Checks if the object is a listctrl */ -#define RTGUI_IS_LISTCTRL(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_LISTCTRL_TYPE)) +#define RTGUI_IS_LISTCTRL(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_LISTCTRL_TYPE)) struct rtgui_listctrl { - struct rtgui_widget parent; + struct rtgui_widget parent; - /* widget private data */ - /* listctrl items */ - rt_uint32_t items; + /* widget private data */ + /* listctrl items */ + void *items; - /* total number of items */ - rt_uint16_t items_count; + /* total number of items */ + rt_uint16_t items_count; /* the number of item in a page */ rt_uint16_t page_items; /* current item */ rt_int16_t current_item; - rt_uint16_t item_height; + rt_uint16_t item_height; - /* item event handler */ - rtgui_event_handler_ptr on_item; - void (*on_item_draw)(struct rtgui_listctrl *list, struct rtgui_dc* dc, rtgui_rect_t* rect, rt_uint16_t index); + /* item event handler */ + rtgui_event_handler_ptr on_item; + void (*on_item_draw)(struct rtgui_listctrl *list, struct rtgui_dc *dc, rtgui_rect_t *rect, rt_uint16_t index); }; typedef struct rtgui_listctrl rtgui_listctrl_t; -typedef void (*rtgui_onitem_draw_t)(struct rtgui_listctrl *list, struct rtgui_dc* dc, rtgui_rect_t* rect, rt_uint16_t index); +typedef void (*rtgui_onitem_draw_t)(struct rtgui_listctrl *list, struct rtgui_dc *dc, rtgui_rect_t *rect, rt_uint16_t index); -rtgui_listctrl_t* rtgui_listctrl_create(rt_uint32_t items, rt_uint16_t count, - rtgui_rect_t *rect, rtgui_onitem_draw_t ondraw); -void rtgui_listctrl_destroy(rtgui_listctrl_t* ctrl); +rtgui_listctrl_t *rtgui_listctrl_create(void *items, rt_uint16_t count, + rtgui_rect_t *rect, rtgui_onitem_draw_t ondraw); +void rtgui_listctrl_destroy(rtgui_listctrl_t *ctrl); -rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object* object, struct rtgui_event* event); -void rtgui_listctrl_set_onitem(rtgui_listctrl_t* ctrl, rtgui_event_handler_ptr func); -void rtgui_listctrl_set_items(rtgui_listctrl_t* ctrl, rt_uint32_t items, rt_uint16_t count); -rt_bool_t rtgui_listctrl_get_item_rect(rtgui_listctrl_t* ctrl, rt_uint16_t item, rtgui_rect_t* item_rect); -void rtgui_listctrl_set_itemheight(struct rtgui_listctrl* ctrl, int height); +rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object *object, struct rtgui_event *event); +void rtgui_listctrl_set_onitem(rtgui_listctrl_t *ctrl, rtgui_event_handler_ptr func); +void rtgui_listctrl_set_items(rtgui_listctrl_t *ctrl, void *items, rt_uint16_t count); +void rtgui_listctrl_set_current_item(struct rtgui_listctrl *ctrl, rt_uint16_t index); +rt_bool_t rtgui_listctrl_get_item_rect(rtgui_listctrl_t *ctrl, rt_uint16_t item, rtgui_rect_t *item_rect); +void rtgui_listctrl_set_itemheight(struct rtgui_listctrl *ctrl, int height); #endif diff --git a/components/rtgui/include/rtgui/widgets/menu.h b/components/rtgui/include/rtgui/widgets/menu.h index 2a137d7009..0a40890b0f 100644 --- a/components/rtgui/include/rtgui/widgets/menu.h +++ b/components/rtgui/include/rtgui/widgets/menu.h @@ -8,28 +8,28 @@ /* rtgui menu item */ enum rtgui_menu_item_type { - RTGUI_ITEM_NORMAL, - RTGUI_ITEM_CHECK, - RTGUI_ITEM_SUBMENU, - RTGUI_ITEM_SEPARATOR + RTGUI_ITEM_NORMAL, + RTGUI_ITEM_CHECK, + RTGUI_ITEM_SUBMENU, + RTGUI_ITEM_SEPARATOR }; typedef enum rtgui_menu_item_type rtgui_menu_item_type_t; struct rtgui_menu_item { - rtgui_menu_item_type_t type; + rtgui_menu_item_type_t type; - /* menu text label */ - const char* label; - /* menu image */ - rtgui_image_t *image; + /* menu text label */ + const char *label; + /* menu image */ + rtgui_image_t *image; - /* sub-menu item */ - const struct rtgui_menu_item_t *submenu; - rt_uint16_t submenu_count; + /* sub-menu item */ + const struct rtgui_menu_item_t *submenu; + rt_uint16_t submenu_count; - /* menu action */ - rt_bool_t (*on_menuaction)(struct rtgui_object* object, struct rtgui_event* event); + /* menu action */ + rt_bool_t (*on_menuaction)(struct rtgui_object *object, struct rtgui_event *event); }; typedef struct rtgui_menu_item rtgui_menu_item_t; @@ -41,38 +41,38 @@ DECLARE_CLASS_TYPE(menu); /** Checks if the object is an rtgui_menu */ #define RTGUI_IS_MENU(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_MENU_TYPE)) -#define RTGUI_MENU_DEFAULT_WIDTH 100 +#define RTGUI_MENU_DEFAULT_WIDTH 100 struct rtgui_menu { - /* inherited from window */ - struct rtgui_win parent; + /* inherited from window */ + struct rtgui_win parent; - /* menu items */ - const struct rtgui_menu_item *items; - rt_uint16_t items_count; + /* menu items */ + const struct rtgui_menu_item *items; + rt_uint16_t items_count; - /* parent menu */ - struct rtgui_menu *parent_menu; - struct rtgui_menu *sub_menu; + /* parent menu */ + struct rtgui_menu *parent_menu; + struct rtgui_menu *sub_menu; - /* menu item list control */ - struct rtgui_listctrl *items_list; + /* menu item list control */ + struct rtgui_listctrl *items_list; - /* pop event handle */ - rtgui_event_handler_ptr on_menupop; - rtgui_event_handler_ptr on_menuhide; + /* pop event handle */ + rtgui_event_handler_ptr on_menupop; + rtgui_event_handler_ptr on_menuhide; }; typedef struct rtgui_menu rtgui_menu_t; -struct rtgui_menu* rtgui_menu_create(const char* title, struct rtgui_menu* parent_menu, - const struct rtgui_menu_item* items, rt_uint16_t count); -void rtgui_menu_destroy(struct rtgui_menu* menu); +struct rtgui_menu *rtgui_menu_create(const char *title, struct rtgui_menu *parent_menu, + const struct rtgui_menu_item *items, rt_uint16_t count); +void rtgui_menu_destroy(struct rtgui_menu *menu); -void rtgui_menu_set_onmenupop(struct rtgui_menu* menu, rtgui_event_handler_ptr handler); -void rtgui_menu_set_onmenuhide(struct rtgui_menu* menu, rtgui_event_handler_ptr handler); +void rtgui_menu_set_onmenupop(struct rtgui_menu *menu, rtgui_event_handler_ptr handler); +void rtgui_menu_set_onmenuhide(struct rtgui_menu *menu, rtgui_event_handler_ptr handler); -void rtgui_menu_pop(struct rtgui_menu* menu, int x, int y); -void rtgui_menu_hiden(struct rtgui_menu* menu); +void rtgui_menu_pop(struct rtgui_menu *menu, int x, int y); +void rtgui_menu_hiden(struct rtgui_menu *menu); #endif diff --git a/components/rtgui/include/rtgui/widgets/mv_view.h b/components/rtgui/include/rtgui/widgets/mv_view.h new file mode 100644 index 0000000000..290f4d0dbb --- /dev/null +++ b/components/rtgui/include/rtgui/widgets/mv_view.h @@ -0,0 +1,44 @@ +/* + * File : mv_view.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2012, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2012-09-15 Grissiom first version + */ +#ifndef __MV_VIEW_H__ +#define __MV_VIEW_H__ + +#include <rtgui/rtgui.h> +#include <rtgui/widgets/widget.h> + +DECLARE_CLASS_TYPE(mv_view); + +/** Gets the type of a mv_view */ +#define RTGUI_MV_VIEW_TYPE (RTGUI_TYPE(mv_view)) +/** Casts the object to an mv_view */ +#define RTGUI_MV_VIEW(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_MV_VIEW_TYPE, struct rtgui_mv_view)) +/** Checks if the object is an mv_view */ +#define RTGUI_IS_MV_VIEW(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_MV_VIEW_TYPE)) + +struct rtgui_mv_view +{ + struct rtgui_widget parent; + rt_uint16_t model_number; + /* if the model_number is 1, the model is the pointer to the model. If the + * model_number is more than 1, model is a pointer to a array of pointers + * to model. */ + void *model; +}; + +struct rtgui_mv_view *rtgui_mv_view_create(void); +void rtgui_mv_view_destroy(struct rtgui_mv_view *view); + +struct rtgui_mv_model *rtgui_mv_view_foreach_in_model(struct rtgui_mv_view *view, rt_uint32_t *iter); + +#endif /* end of include guard: __MV_VIEW_H__ */ diff --git a/components/rtgui/include/rtgui/widgets/notebook.h b/components/rtgui/include/rtgui/widgets/notebook.h index 9d8cfa8ade..60d209e538 100644 --- a/components/rtgui/include/rtgui/widgets/notebook.h +++ b/components/rtgui/include/rtgui/widgets/notebook.h @@ -13,60 +13,60 @@ DECLARE_CLASS_TYPE(notebook); /** Checks if the object is a notebook control */ #define RTGUI_IS_NOTEBOOK(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_NOTEBOOK_TYPE)) -#define RTGUI_NOTEBOOK_TOP 0x00 -#define RTGUI_NOTEBOOK_BOTTOM 0x01 -#define RTGUI_NOTEBOOK_NOTAB 0x02 -#define RTGUI_NOTEBOOK_LEFT 0x03 -#define RTGUI_NOTEBOOK_RIGHT 0x04 +#define RTGUI_NOTEBOOK_TOP 0x00 +#define RTGUI_NOTEBOOK_BOTTOM 0x01 +#define RTGUI_NOTEBOOK_NOTAB 0x02 +#define RTGUI_NOTEBOOK_LEFT 0x03 +#define RTGUI_NOTEBOOK_RIGHT 0x04 struct rtgui_notebook_tab; struct rtgui_notebook { - struct rtgui_widget parent; + struct rtgui_widget parent; - rt_uint8_t flag; + rt_uint8_t flag; - /* widget private data */ - struct rtgui_notebook_tab *childs; - rt_uint16_t count; - rt_int16_t current; + /* widget private data */ + struct rtgui_notebook_tab *childs; + rt_uint16_t count; + rt_int16_t current; - rt_uint16_t tab_w, tab_h; + rt_uint16_t tab_w, tab_h; }; -struct rtgui_notebook* rtgui_notebook_create(const rtgui_rect_t* rect, rt_uint8_t style); -void rtgui_notebook_destroy(struct rtgui_notebook* notebook); +struct rtgui_notebook *rtgui_notebook_create(const rtgui_rect_t *rect, rt_uint8_t style); +void rtgui_notebook_destroy(struct rtgui_notebook *notebook); rt_inline void rtgui_notebook_set_tab_height(struct rtgui_notebook *notebook, rt_uint16_t height) { - RT_ASSERT(notebook != RT_NULL); - notebook->tab_h = height; + RT_ASSERT(notebook != RT_NULL); + notebook->tab_h = height; } rt_inline void rtgui_notebook_set_tab_width(struct rtgui_notebook *notebook, rt_uint16_t width) { - RT_ASSERT(notebook != RT_NULL); - notebook->tab_w = width; + RT_ASSERT(notebook != RT_NULL); + notebook->tab_w = width; } -void rtgui_notebook_add(struct rtgui_notebook* notebook, const char* label, struct rtgui_widget* child); +void rtgui_notebook_add(struct rtgui_notebook *notebook, const char *label, struct rtgui_widget *child); #ifdef RTGUI_USING_NOTEBOOK_IMAGE -void rtgui_notebook_add_image(struct rtgui_notebook* notebook, const char* label, struct rtgui_widget* child, - struct rtgui_image *pressed_image, struct rtgui_image *unpressed_image); +void rtgui_notebook_add_image(struct rtgui_notebook *notebook, const char *label, struct rtgui_widget *child, + struct rtgui_image *pressed_image, struct rtgui_image *unpressed_image); #endif -void rtgui_notebook_remove(struct rtgui_notebook* notebook, rt_uint16_t index); -struct rtgui_widget* rtgui_notebook_get_current(struct rtgui_notebook* notebook); -rt_int16_t rtgui_notebook_get_current_index(struct rtgui_notebook* notebook); +void rtgui_notebook_remove(struct rtgui_notebook *notebook, rt_uint16_t index); +struct rtgui_widget *rtgui_notebook_get_current(struct rtgui_notebook *notebook); +rt_int16_t rtgui_notebook_get_current_index(struct rtgui_notebook *notebook); -int rtgui_notebook_get_count(struct rtgui_notebook* notebook); -void rtgui_notebook_get_client_rect(struct rtgui_notebook* notebook, struct rtgui_rect *rect); +int rtgui_notebook_get_count(struct rtgui_notebook *notebook); +void rtgui_notebook_get_client_rect(struct rtgui_notebook *notebook, struct rtgui_rect *rect); -void rtgui_notebook_set_current(struct rtgui_notebook* notebook, struct rtgui_widget* child); -void rtgui_notebook_set_current_by_index(struct rtgui_notebook* notebook, rt_uint16_t index); +void rtgui_notebook_set_current(struct rtgui_notebook *notebook, struct rtgui_widget *child); +void rtgui_notebook_set_current_by_index(struct rtgui_notebook *notebook, rt_uint16_t index); -struct rtgui_widget* rtgui_notebook_get_widget_at(struct rtgui_notebook* notebook, rt_uint16_t index); +struct rtgui_widget *rtgui_notebook_get_widget_at(struct rtgui_notebook *notebook, rt_uint16_t index); -rt_bool_t rtgui_notebook_event_handler(struct rtgui_object* widget, struct rtgui_event* event); +rt_bool_t rtgui_notebook_event_handler(struct rtgui_object *widget, struct rtgui_event *event); #endif diff --git a/components/rtgui/include/rtgui/widgets/panel.h b/components/rtgui/include/rtgui/widgets/panel.h index 3343e4e9f8..ec332e4eef 100644 --- a/components/rtgui/include/rtgui/widgets/panel.h +++ b/components/rtgui/include/rtgui/widgets/panel.h @@ -31,21 +31,21 @@ DECLARE_CLASS_TYPE(panel); */ struct rtgui_panel { - struct rtgui_container parent; + struct rtgui_container parent; - int border_style; + int border_style; }; typedef struct rtgui_panel rtgui_panel_t; -rtgui_panel_t* rtgui_panel_create(int border_style); -void rtgui_panel_destroy(rtgui_panel_t* panel); +rtgui_panel_t *rtgui_panel_create(int border_style); +void rtgui_panel_destroy(rtgui_panel_t *panel); -rt_inline void rtgui_panel_set_border(struct rtgui_panel* panel, int border_style) +rt_inline void rtgui_panel_set_border(struct rtgui_panel *panel, int border_style) { - RT_ASSERT(panel != RT_NULL); - panel->border_style = border_style; + RT_ASSERT(panel != RT_NULL); + panel->border_style = border_style; } -rt_bool_t rtgui_panel_event_handler(struct rtgui_object* object, struct rtgui_event* event); +rt_bool_t rtgui_panel_event_handler(struct rtgui_object *object, struct rtgui_event *event); #endif diff --git a/components/rtgui/include/rtgui/widgets/plot.h b/components/rtgui/include/rtgui/widgets/plot.h index 28a1c84791..db063f2004 100644 --- a/components/rtgui/include/rtgui/widgets/plot.h +++ b/components/rtgui/include/rtgui/widgets/plot.h @@ -16,6 +16,7 @@ #include <rtgui/rtgui.h> #include <rtgui/widgets/widget.h> +#include <rtgui/widgets/mv_view.h> #include <rtgui/widgets/plot_curve.h> DECLARE_CLASS_TYPE(plot); @@ -27,17 +28,10 @@ DECLARE_CLASS_TYPE(plot); /** Checks if the object is an rtgui_plot */ #define RTGUI_IS_PLOT(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_PLOT_TYPE)) -struct rtgui_plot_curve_container +enum rtgui_plot_type { - struct rtgui_plot_curve *curve; - struct rtgui_plot_curve_container *next; -}; - -enum rtgui_plot_flag -{ - RTGUI_PLOT_INCREMENTAL, - RTGUI_PLOT_MOVING_WINDOW, - RTGUI_PLOT_SCAN, + RTGUI_PLOT_TYPE_SCAN, + RTGUI_PLOT_TYPE_INCREMENTAL, }; /* @@ -45,20 +39,21 @@ enum rtgui_plot_flag */ struct rtgui_plot { - struct rtgui_widget parent; + struct rtgui_mv_view parent; - enum rtgui_plot_flag pflag; + enum rtgui_plot_type ptype; + rt_uint16_t scale_x; + rt_uint16_t scale_y; - struct rtgui_point base_point; - struct rtgui_plot_curve_container curve_container; + rtgui_plot_curve_dtype base_x; + rtgui_plot_curve_dtype base_y; }; -struct rtgui_plot *rtgui_plot_create(struct rtgui_plot_curve*); +struct rtgui_plot *rtgui_plot_create(void); void rtgui_plot_destroy(struct rtgui_plot *plot); -void rtgui_plot_set_base_point(struct rtgui_plot *plot, rt_uint16_t x, rt_uint16_t y); -void rtgui_plot_append_curve(struct rtgui_plot *plot, struct rtgui_plot_curve *curve); -void rtgui_plot_remove_curve(struct rtgui_plot *plot, struct rtgui_plot_curve *curve); +void rtgui_plot_set_base(struct rtgui_plot *plot, + rtgui_plot_curve_dtype x, rtgui_plot_curve_dtype y); rt_bool_t rtgui_plot_event_handler(struct rtgui_object *object, struct rtgui_event *event); diff --git a/components/rtgui/include/rtgui/widgets/plot_curve.h b/components/rtgui/include/rtgui/widgets/plot_curve.h index a868e6ebe5..d3c3053301 100644 --- a/components/rtgui/include/rtgui/widgets/plot_curve.h +++ b/components/rtgui/include/rtgui/widgets/plot_curve.h @@ -15,6 +15,7 @@ #define __RTGUI_PLOT_CURVE_H__ #include <rtgui/rtgui.h> +#include <rtgui/rtgui_mv_model.h> DECLARE_CLASS_TYPE(plot_curve); @@ -31,15 +32,20 @@ DECLARE_CLASS_TYPE(plot_curve); struct rtgui_plot_curve { - struct rtgui_object parent; + struct rtgui_mv_model parent; rtgui_color_t color; - rt_size_t length; - rtgui_plot_curve_dtype *x_data; - rtgui_plot_curve_dtype *y_data; + rtgui_plot_curve_dtype min_x, max_x; + rtgui_plot_curve_dtype min_y, max_y; }; struct rtgui_plot_curve *rtgui_plot_curve_create(void); void rtgui_plot_curve_destroy(struct rtgui_plot_curve *curve); + +void rtgui_plot_curve_set_x(struct rtgui_plot_curve *curve, void *p); +void *rtgui_plot_curve_get_x(struct rtgui_plot_curve *curve); +void rtgui_plot_curve_set_y(struct rtgui_plot_curve *curve, void *p); +void *rtgui_plot_curve_get_y(struct rtgui_plot_curve *curve); + #endif diff --git a/components/rtgui/include/rtgui/widgets/progressbar.h b/components/rtgui/include/rtgui/widgets/progressbar.h index 08733c3496..9c19ad724d 100644 --- a/components/rtgui/include/rtgui/widgets/progressbar.h +++ b/components/rtgui/include/rtgui/widgets/progressbar.h @@ -17,20 +17,20 @@ DECLARE_CLASS_TYPE(progressbar); struct rtgui_progressbar { - struct rtgui_widget parent; + struct rtgui_widget parent; - int orient; + int orient; int range; int position; }; typedef struct rtgui_progressbar rtgui_progressbar_t; -struct rtgui_progressbar* rtgui_progressbar_create(int orientation, int range, rtgui_rect_t* r); -void rtgui_progressbar_destroy(struct rtgui_progressbar* p_bar); +struct rtgui_progressbar *rtgui_progressbar_create(int orientation, int range, rtgui_rect_t *r); +void rtgui_progressbar_destroy(struct rtgui_progressbar *p_bar); -rt_bool_t rtgui_progressbar_event_handler(struct rtgui_object* object, - struct rtgui_event* event); +rt_bool_t rtgui_progressbar_event_handler(struct rtgui_object *object, + struct rtgui_event *event); void rtgui_progressbar_set_value(struct rtgui_progressbar *p_bar, int value); int rtgui_progressbar_get_value(struct rtgui_progressbar *p_bar); diff --git a/components/rtgui/include/rtgui/widgets/radiobox.h b/components/rtgui/include/rtgui/widgets/radiobox.h index 2a53daa477..94dbb54b3e 100644 --- a/components/rtgui/include/rtgui/widgets/radiobox.h +++ b/components/rtgui/include/rtgui/widgets/radiobox.h @@ -14,32 +14,32 @@ DECLARE_CLASS_TYPE(radiobox); struct rtgui_radiobox { - struct rtgui_widget parent; + struct rtgui_widget parent; - /* widget private data */ - char* text; /* radio box label */ + /* widget private data */ + char *text; /* radio box label */ - /* box orient */ - rt_uint8_t orient; + /* box orient */ + rt_uint8_t orient; - /* item size */ - rt_uint8_t item_size; + /* item size */ + rt_uint8_t item_size; - char** items; - rt_uint16_t item_count; - rt_int16_t item_selection; + char **items; + rt_uint16_t item_count; + rt_int16_t item_selection; }; typedef struct rtgui_radiobox rtgui_radiobox_t; -struct rtgui_radiobox* rtgui_radiobox_create(const char* label, int orient, char** radio_items, int number); -void rtgui_radiobox_destroy(struct rtgui_radiobox* radiobox); +struct rtgui_radiobox *rtgui_radiobox_create(const char *label, int orient, char **radio_items, int number); +void rtgui_radiobox_destroy(struct rtgui_radiobox *radiobox); -void rtgui_radiobox_set_selection(struct rtgui_radiobox* radiobox, int selection); -int rtgui_radiobox_get_selection(struct rtgui_radiobox* radiobox); +void rtgui_radiobox_set_selection(struct rtgui_radiobox *radiobox, int selection); +int rtgui_radiobox_get_selection(struct rtgui_radiobox *radiobox); -rt_bool_t rtgui_radiobox_event_handler(struct rtgui_object* object, struct rtgui_event* event); +rt_bool_t rtgui_radiobox_event_handler(struct rtgui_object *object, struct rtgui_event *event); -void rtgui_radiobox_set_orientation(struct rtgui_radiobox* radiobox, int orientation); +void rtgui_radiobox_set_orientation(struct rtgui_radiobox *radiobox, int orientation); #endif diff --git a/components/rtgui/include/rtgui/widgets/scrollbar.h b/components/rtgui/include/rtgui/widgets/scrollbar.h index a4e57b7204..24f1691267 100644 --- a/components/rtgui/include/rtgui/widgets/scrollbar.h +++ b/components/rtgui/include/rtgui/widgets/scrollbar.h @@ -14,14 +14,15 @@ #ifndef __RTGUI_SCROLLBAR_H__ #define __RTGUI_SCROLLBAR_H__ -#include <rtgui/rtgui.h> #include <rtgui/widgets/widget.h> +#include <rtgui/widgets/container.h> #ifdef __cplusplus extern "C" { #endif DECLARE_CLASS_TYPE(scrollbar); + /** Gets the type of a scrollbar */ #define RTGUI_SCROLLBAR_TYPE (RTGUI_TYPE(scrollbar)) /** Casts the object to an rtgui_scrollbar */ @@ -29,58 +30,60 @@ DECLARE_CLASS_TYPE(scrollbar); /** Checks if the object is an rtgui_scrollbar */ #define RTGUI_IS_SCROLLBAR(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_SCROLLBAR_TYPE)) -#define RTGUI_DEFAULT_SB_WIDTH 100 -#define RTGUI_DEFAULT_SB_HEIGHT 16 +#define RTGUI_DEFAULT_SB_WIDTH 16 /* scrollbar status/positions*/ #define SBS_UNKNOWN 0x0000 #define SBS_LEFTARROW 0x0001 #define SBS_RIGHTARROW 0x0002 -#define SBS_LEFTSPACE 0x0004 -#define SBS_RIGHTSPACE 0x0008 -#define SBS_HORZTHUMB 0x0010 +#define SBS_LEFTSPACE 0x0004 /* Need mouse_motion event */ +#define SBS_RIGHTSPACE 0x0008 /* Need mouse_motion event */ +#define SBS_HORZTHUMB 0x0010 /* Need mouse_motion event */ #define SBS_UPARROW 0x0020 #define SBS_DOWNARROW 0x0040 -#define SBS_UPSPACE 0x0080 -#define SBS_DOWNSPACE 0x0100 -#define SBS_VERTTHUMB 0x0200 +#define SBS_UPSPACE 0x0080 /* Need mouse_motion event */ +#define SBS_DOWNSPACE 0x0100 /* Need mouse_motion event */ +#define SBS_VERTTHUMB 0x0200 /* Need mouse_motion event */ +#define SBS_UPTHUMB 0x0400 /* Need mouse_motion event */ +#define SBS_DOWNTHUMB 0x0800 /* Need mouse_motion event */ +#define SBS_LEFTTHUMB 0x1000 /* Need mouse_motion event */ +#define SBS_RIGHTTHUMB 0x2000 /* Need mouse_motion event */ struct rtgui_scrollbar { /* inherit from widget */ - struct rtgui_widget parent; + rtgui_widget_t parent; - rt_uint8_t orient; - rt_uint8_t status; + rt_uint8_t orient; + rt_uint32_t status; - /* page_step = width of scrollbar */ - /* thumb size = line_step * page_step / (page_step - (button width * 2)) */ + /* page_step = display lines of scrollbar */ + /* thumb_len = line_step * page_step / (page_step - (button width * 2)) */ rt_int16_t line_step, page_step; - - rt_int16_t thumb_position, thumb_size; - + rt_int16_t value, thumb_len,thumb_w; /* position 1:1 width of scrollbar */ - rt_int16_t min_position, max_position; + rt_int16_t count; - rtgui_event_handler_ptr on_scroll; + rtgui_widget_t *widget_link;/* be connected widget */ + rt_bool_t (*on_scroll) (rtgui_object_t *obj, rtgui_event_t* event); }; typedef struct rtgui_scrollbar rtgui_scrollbar_t; -struct rtgui_scrollbar* rtgui_scrollbar_create(int orient, rtgui_rect_t* r); -void rtgui_scrollbar_destroy(struct rtgui_scrollbar* bar); - -void rtgui_scrollbar_get_thumb_rect(rtgui_scrollbar_t *bar, rtgui_rect_t *rect); +rtgui_scrollbar_t* rtgui_scrollbar_create(rtgui_container_t *container,int left,int top,int w,int len,int orient); +void rtgui_scrollbar_destroy(rtgui_scrollbar_t* bar); +void rtgui_scrollbar_ondraw(rtgui_scrollbar_t* bar); +void rtgui_scrollbar_get_thumb_rect(rtgui_scrollbar_t *bar, rtgui_rect_t *erect); -void rtgui_scrollbar_set_range(struct rtgui_scrollbar* bar, int min, int max); -rt_int16_t rtgui_scrollbar_get_value(struct rtgui_scrollbar* bar); -void rtgui_scrollbar_set_value(struct rtgui_scrollbar* bar, rt_int16_t position); +void rtgui_scrollbar_set_range(rtgui_scrollbar_t* bar, int count); +void rtgui_scrollbar_set_value(rtgui_scrollbar_t* bar, rt_int16_t value); -void rtgui_scrollbar_set_onscroll(struct rtgui_scrollbar* bar, rtgui_event_handler_ptr handler); -void rtgui_scrollbar_set_orientation(struct rtgui_scrollbar* bar, int orientation); -void rtgui_scrollbar_set_page_step(struct rtgui_scrollbar* bar, int step); -void rtgui_scrollbar_set_line_step(struct rtgui_scrollbar* bar, int step); +void rtgui_scrollbar_set_onscroll(rtgui_scrollbar_t* bar, rtgui_event_handler_ptr handler); +void rtgui_scrollbar_set_orientation(rtgui_scrollbar_t* bar, int orient); +void rtgui_scrollbar_set_page_step(rtgui_scrollbar_t* bar, int step); +void rtgui_scrollbar_set_line_step(rtgui_scrollbar_t* bar, int step); -rt_bool_t rtgui_scrollbar_event_handler(struct rtgui_object* object, struct rtgui_event* event); +rt_bool_t rtgui_scrollbar_event_handler(rtgui_object_t *obj, rtgui_event_t* event); +void rtgui_scrollbar_hide(rtgui_scrollbar_t* bar); #ifdef __cplusplus } diff --git a/components/rtgui/include/rtgui/widgets/slider.h b/components/rtgui/include/rtgui/widgets/slider.h index 2273177acc..ea99fb736e 100644 --- a/components/rtgui/include/rtgui/widgets/slider.h +++ b/components/rtgui/include/rtgui/widgets/slider.h @@ -27,27 +27,27 @@ DECLARE_CLASS_TYPE(slider); struct rtgui_slider { - struct rtgui_widget parent; + struct rtgui_widget parent; - /* widget private data */ - rt_size_t min, max, value, ticks; - rt_size_t thumb_width; + /* widget private data */ + rt_size_t min, max, value, ticks; + rt_size_t thumb_width; - int orient; + int orient; - void (*on_changed)(struct rtgui_widget* widget, struct rtgui_event *event); + void (*on_changed)(struct rtgui_widget *widget, struct rtgui_event *event); }; typedef struct rtgui_slider rtgui_slider_t; -struct rtgui_slider* rtgui_slider_create(rt_size_t min, rt_size_t max, int orient); -void rtgui_slider_destroy(struct rtgui_slider* slider); +struct rtgui_slider *rtgui_slider_create(rt_size_t min, rt_size_t max, int orient); +void rtgui_slider_destroy(struct rtgui_slider *slider); -rt_bool_t rtgui_slider_event_handler(struct rtgui_object* object, struct rtgui_event* event); +rt_bool_t rtgui_slider_event_handler(struct rtgui_object *object, struct rtgui_event *event); -void rtgui_slider_set_range(struct rtgui_slider* slider, rt_size_t min, rt_size_t max); -void rtgui_slider_set_value(struct rtgui_slider* slider, rt_size_t value); -void rtgui_slider_set_orientation(struct rtgui_slider* slider, int orientation); +void rtgui_slider_set_range(struct rtgui_slider *slider, rt_size_t min, rt_size_t max); +void rtgui_slider_set_value(struct rtgui_slider *slider, rt_size_t value); +void rtgui_slider_set_orientation(struct rtgui_slider *slider, int orientation); -rt_size_t rtgui_slider_get_value(struct rtgui_slider* slider); +rt_size_t rtgui_slider_get_value(struct rtgui_slider *slider); #endif diff --git a/components/rtgui/include/rtgui/widgets/staticline.h b/components/rtgui/include/rtgui/widgets/staticline.h index 67ccfa4dec..6ba8799816 100644 --- a/components/rtgui/include/rtgui/widgets/staticline.h +++ b/components/rtgui/include/rtgui/widgets/staticline.h @@ -18,18 +18,18 @@ DECLARE_CLASS_TYPE(staticline); struct rtgui_staticline { - /* inherit from widget */ - struct rtgui_widget parent; + /* inherit from widget */ + struct rtgui_widget parent; - int orient; + int orient; }; typedef struct rtgui_staticline rtgui_staticline_t; rtgui_staticline_t *rtgui_staticline_create(int orientation); -void rtgui_staticline_destroy(rtgui_staticline_t* staticline); +void rtgui_staticline_destroy(rtgui_staticline_t *staticline); -rt_bool_t rtgui_staticline_event_handler(struct rtgui_object* object, struct rtgui_event* event); -void rtgui_staticline_set_orientation(rtgui_staticline_t* staticline, int orientation); +rt_bool_t rtgui_staticline_event_handler(struct rtgui_object *object, struct rtgui_event *event); +void rtgui_staticline_set_orientation(rtgui_staticline_t *staticline, int orientation); #endif diff --git a/components/rtgui/include/rtgui/widgets/textbox.h b/components/rtgui/include/rtgui/widgets/textbox.h index 55d74bf109..918e98d162 100644 --- a/components/rtgui/include/rtgui/widgets/textbox.h +++ b/components/rtgui/include/rtgui/widgets/textbox.h @@ -1,16 +1,16 @@ /* - * File : textbox.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 - */ +* File : textbox.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_TEXTBOX_H__ #define __RTGUI_TEXTBOX_H__ @@ -31,17 +31,17 @@ DECLARE_CLASS_TYPE(textbox); /** Checks if the object is a rtgui_textbox_t */ #define RTGUI_IS_TEXTBOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_TEXTBOX_TYPE)) -#define RTGUI_TEXTBOX_DEFAULT_WIDTH 80 -#define RTGUI_TEXTBOX_DEFAULT_HEIGHT 20 +#define RTGUI_TEXTBOX_DEFAULT_WIDTH 80 +#define RTGUI_TEXTBOX_DEFAULT_HEIGHT 20 #define RTGUI_TEXTBOX_SINGLE 0x00 -#define RTGUI_TEXTBOX_MULTI 0x01 /* multiline */ -#define RTGUI_TEXTBOX_MASK 0x02 /* ciphertext */ +#define RTGUI_TEXTBOX_MULTI 0x01 /* multiline */ +#define RTGUI_TEXTBOX_MASK 0x02 /* ciphertext */ #define RTGUI_TEXTBOX_DIGIT 0x04 /* digit */ -#define RTGUI_TEXTBOX_CARET_SHOW 0x10 -#define RTGUI_TEXTBOX_CARET_STAT 0x20 /* unused */ +#define RTGUI_TEXTBOX_CARET_SHOW 0x10 +#define RTGUI_TEXTBOX_CARET_STAT 0x20 /* unused */ -#define RTGUI_TEXTBOX_LINE_MAX 128 /* text line cache */ +#define RTGUI_TEXTBOX_LINE_MAX 128 /* text line cache */ struct rtgui_textbox { @@ -53,8 +53,10 @@ struct rtgui_textbox /* current line and position */ rt_uint16_t line, line_begin, position, line_length; - rt_uint16_t dis_length; /*may be display length.*/ - char* text; + rt_uint16_t dis_length; /*may be display length.*/ + rt_uint16_t first_pos; + char mask_char; + char *text; rt_size_t font_width; rtgui_timer_t *caret_timer; @@ -62,23 +64,24 @@ struct rtgui_textbox rtgui_rect_t caret_rect; /* textbox private data */ - rt_bool_t (*on_enter) (struct rtgui_textbox *box, rtgui_event_t* event); + rt_bool_t (*on_enter)(struct rtgui_textbox *box, rtgui_event_t *event); }; typedef struct rtgui_textbox rtgui_textbox_t; -struct rtgui_textbox* rtgui_textbox_create(const char* text, rt_uint32_t flag); -void rtgui_textbox_destroy(struct rtgui_textbox* box); +rtgui_textbox_t *rtgui_textbox_create(const char *text, rt_uint32_t flag); +void rtgui_textbox_destroy(struct rtgui_textbox *box); -rt_bool_t rtgui_textbox_event_handler(struct rtgui_object* object, struct rtgui_event* event); +rt_bool_t rtgui_textbox_event_handler(struct rtgui_object *object, struct rtgui_event *event); -void rtgui_textbox_set_value(struct rtgui_textbox* box, const char* text); -const char* rtgui_textbox_get_value(struct rtgui_textbox* box); +void rtgui_textbox_set_value(struct rtgui_textbox *box, const char *text); +const char *rtgui_textbox_get_value(struct rtgui_textbox *box); +void rtgui_textbox_set_mask_char(rtgui_textbox_t *box, const char ch); +const char rtgui_textbox_get_mask_char(rtgui_textbox_t *box); +void rtgui_textbox_set_line_length(struct rtgui_textbox *box, rt_size_t length); -void rtgui_textbox_set_line_length(struct rtgui_textbox* box, rt_size_t length); +void rtgui_textbox_get_edit_rect(struct rtgui_textbox *box, rtgui_rect_t *rect); -void rtgui_textbox_get_edit_rect(struct rtgui_textbox *box,rtgui_rect_t *rect); - -void rtgui_textbox_ondraw(rtgui_textbox_t* box); +void rtgui_textbox_ondraw(rtgui_textbox_t *box); #ifdef __cplusplus } #endif diff --git a/components/rtgui/include/rtgui/widgets/textview.h b/components/rtgui/include/rtgui/widgets/textview.h index 49024207cf..14ff51821a 100644 --- a/components/rtgui/include/rtgui/widgets/textview.h +++ b/components/rtgui/include/rtgui/widgets/textview.h @@ -20,45 +20,45 @@ extern "C" { #endif -/** - * @defgroup rtgui_textview - * @{ - */ + /** + * @defgroup rtgui_textview + * @{ + */ -DECLARE_CLASS_TYPE(textview); + DECLARE_CLASS_TYPE(textview); -/** Gets the type of a textview */ + /** Gets the type of a textview */ #define RTGUI_TEXTVIEW_TYPE (RTGUI_TYPE(textview)) -/** Casts the object to an rtgui_textview */ + /** Casts the object to an rtgui_textview */ #define RTGUI_TEXTVIEW(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_TEXTVIEW_TYPE, rtgui_textview_t)) -/** Checks if the object is an rtgui_textview */ + /** Checks if the object is an rtgui_textview */ #define RTGUI_IS_TEXTVIEW(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_TEXTVIEW_TYPE)) -/* - * the textview widget - */ -struct rtgui_textview -{ - /* inherit from widget */ - struct rtgui_widget parent; + /* + * the textview widget + */ + struct rtgui_textview + { + /* inherit from widget */ + struct rtgui_widget parent; - rt_uint16_t line_width; - rt_uint16_t line_count; + rt_uint16_t line_width; + rt_uint16_t line_count; - char* lines; + char *lines; - rt_int16_t line_current; - rt_uint16_t line_page_count; -}; -typedef struct rtgui_textview rtgui_textview_t; + rt_int16_t line_current; + rt_uint16_t line_page_count; + }; + typedef struct rtgui_textview rtgui_textview_t; -rtgui_textview_t* rtgui_textview_create(const char* text, const rtgui_rect_t *rect); -void rtgui_textview_destroy(rtgui_textview_t* textview); + rtgui_textview_t *rtgui_textview_create(const char *text, const rtgui_rect_t *rect); + void rtgui_textview_destroy(rtgui_textview_t *textview); -rt_bool_t rtgui_textview_event_handler(struct rtgui_object* object, struct rtgui_event* event); -void rtgui_textview_set_text(rtgui_textview_t* textview, const char* text); + rt_bool_t rtgui_textview_event_handler(struct rtgui_object *object, struct rtgui_event *event); + void rtgui_textview_set_text(rtgui_textview_t *textview, const char *text); -/** @} */ + /** @} */ #ifdef __cplusplus } diff --git a/components/rtgui/include/rtgui/widgets/title.h b/components/rtgui/include/rtgui/widgets/title.h index 974a90711b..7684f56df1 100644 --- a/components/rtgui/include/rtgui/widgets/title.h +++ b/components/rtgui/include/rtgui/widgets/title.h @@ -26,19 +26,19 @@ DECLARE_CLASS_TYPE(wintitle); struct rtgui_wintitle { - struct rtgui_widget parent; + struct rtgui_widget parent; - /* title */ - char* title; + /* title */ + char *title; }; typedef struct rtgui_wintitle rtgui_wintitle_t; -rtgui_wintitle_t* rtgui_wintitle_create(struct rtgui_win *window, const char* title); -void rtgui_wintitle_destroy(rtgui_wintitle_t* wintitle); +rtgui_wintitle_t *rtgui_wintitle_create(struct rtgui_win *window, const char *title); +void rtgui_wintitle_destroy(rtgui_wintitle_t *wintitle); -rt_bool_t rtgui_wintile_event_handler(rtgui_widget_t* widget, rtgui_event_t* event); +rt_bool_t rtgui_wintile_event_handler(rtgui_widget_t *widget, rtgui_event_t *event); -void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const char* title); -char *rtgui_wintitle_get_title(rtgui_wintitle_t* wintitle); +void rtgui_wintitle_set_title(rtgui_wintitle_t *wintitle, const char *title); +char *rtgui_wintitle_get_title(rtgui_wintitle_t *wintitle); #endif diff --git a/components/rtgui/include/rtgui/widgets/widget.h b/components/rtgui/include/rtgui/widgets/widget.h index 6e4926a312..7dd65898c4 100644 --- a/components/rtgui/include/rtgui/widgets/widget.h +++ b/components/rtgui/include/rtgui/widgets/widget.h @@ -25,176 +25,176 @@ extern "C" { #endif -#define RTGUI_WIDGET_FLAG_DEFAULT 0x0000 -#define RTGUI_WIDGET_FLAG_SHOWN 0x0001 -#define RTGUI_WIDGET_FLAG_DISABLE 0x0002 -#define RTGUI_WIDGET_FLAG_FOCUS 0x0004 -#define RTGUI_WIDGET_FLAG_TRANSPARENT 0x0008 -#define RTGUI_WIDGET_FLAG_FOCUSABLE 0x0010 -#define RTGUI_WIDGET_FLAG_DC_VISIBLE 0x0100 +#define RTGUI_WIDGET_FLAG_DEFAULT 0x0000 +#define RTGUI_WIDGET_FLAG_SHOWN 0x0001 +#define RTGUI_WIDGET_FLAG_DISABLE 0x0002 +#define RTGUI_WIDGET_FLAG_FOCUS 0x0004 +#define RTGUI_WIDGET_FLAG_TRANSPARENT 0x0008 +#define RTGUI_WIDGET_FLAG_FOCUSABLE 0x0010 +#define RTGUI_WIDGET_FLAG_DC_VISIBLE 0x0100 -/* rtgui widget attribute */ -#define RTGUI_WIDGET_FOREGROUND(w) (RTGUI_WIDGET(w)->gc.foreground) -#define RTGUI_WIDGET_BACKGROUND(w) (RTGUI_WIDGET(w)->gc.background) -#define RTGUI_WIDGET_TEXTALIGN(w) (RTGUI_WIDGET(w)->gc.textalign) -#define RTGUI_WIDGET_FONT(w) (RTGUI_WIDGET(w)->gc.font) -#define RTGUI_WIDGET_FLAG(w) (RTGUI_WIDGET(w)->flag) -#define RTGUI_WIDGET_ALIGN(w) (RTGUI_WIDGET(w)->align) -#define RTGUI_WIDGET_BORDER(w) (RTGUI_WIDGET(w)->border) -#define RTGUI_WIDGET_BORDER_STYLE(w) (RTGUI_WIDGET(w)->border_style) + /* rtgui widget attribute */ +#define RTGUI_WIDGET_FOREGROUND(w) (RTGUI_WIDGET(w)->gc.foreground) +#define RTGUI_WIDGET_BACKGROUND(w) (RTGUI_WIDGET(w)->gc.background) +#define RTGUI_WIDGET_TEXTALIGN(w) (RTGUI_WIDGET(w)->gc.textalign) +#define RTGUI_WIDGET_FONT(w) (RTGUI_WIDGET(w)->gc.font) +#define RTGUI_WIDGET_FLAG(w) (RTGUI_WIDGET(w)->flag) +#define RTGUI_WIDGET_ALIGN(w) (RTGUI_WIDGET(w)->align) +#define RTGUI_WIDGET_BORDER(w) (RTGUI_WIDGET(w)->border) +#define RTGUI_WIDGET_BORDER_STYLE(w) (RTGUI_WIDGET(w)->border_style) -#define RTGUI_WIDGET_UNHIDE(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_SHOWN -#define RTGUI_WIDGET_HIDE(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_SHOWN -#define RTGUI_WIDGET_IS_HIDE(w) (!(RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_SHOWN)) +#define RTGUI_WIDGET_UNHIDE(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_SHOWN +#define RTGUI_WIDGET_HIDE(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_SHOWN +#define RTGUI_WIDGET_IS_HIDE(w) (!(RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_SHOWN)) -#define RTGUI_WIDGET_ENABLE(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_DISABLE -#define RTGUI_WIDGET_DISABLE(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_DISABLE -#define RTGUI_WIDGET_IS_ENABLE(w) (!((RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_DISABLE))) +#define RTGUI_WIDGET_ENABLE(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_DISABLE +#define RTGUI_WIDGET_DISABLE(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_DISABLE +#define RTGUI_WIDGET_IS_ENABLE(w) (!((RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_DISABLE))) -#define RTGUI_WIDGET_UNFOCUS(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_FOCUS -#define RTGUI_WIDGET_FOCUS(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_FOCUS -#define RTGUI_WIDGET_IS_FOCUSED(w) (RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_FOCUS) +#define RTGUI_WIDGET_UNFOCUS(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_FOCUS +#define RTGUI_WIDGET_FOCUS(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_FOCUS +#define RTGUI_WIDGET_IS_FOCUSED(w) (RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_FOCUS) -#define RTGUI_WIDGET_IS_FOCUSABLE(w) (RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_FOCUSABLE) +#define RTGUI_WIDGET_IS_FOCUSABLE(w) (RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_FOCUSABLE) -#define RTGUI_WIDGET_IS_DC_VISIBLE(w) (RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_DC_VISIBLE) -#define RTGUI_WIDGET_DC_SET_VISIBLE(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_DC_VISIBLE +#define RTGUI_WIDGET_IS_DC_VISIBLE(w) (RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_DC_VISIBLE) +#define RTGUI_WIDGET_DC_SET_VISIBLE(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_DC_VISIBLE #define RTGUI_WIDGET_DC_SET_UNVISIBLE(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_DC_VISIBLE -#define RTGUI_WIDGET_DC(w) ((struct rtgui_dc*)&((w)->dc_type)) +#define RTGUI_WIDGET_DC(w) ((struct rtgui_dc*)&((w)->dc_type)) -DECLARE_CLASS_TYPE(widget); + DECLARE_CLASS_TYPE(widget); -/** Gets the type of a widget */ + /** Gets the type of a widget */ #define RTGUI_WIDGET_TYPE (RTGUI_TYPE(widget)) -/** Casts the object to a rtgui_widget */ + /** Casts the object to a rtgui_widget */ #define RTGUI_WIDGET(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_WIDGET_TYPE, rtgui_widget_t)) -/** Check if the object is a rtgui_widget */ + /** Check if the object is a rtgui_widget */ #define RTGUI_IS_WIDGET(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_WIDGET_TYPE)) -/* - * the base widget object - */ -struct rtgui_widget -{ - /* inherit from rtgui_object */ - struct rtgui_object object; + /* + * the base widget object + */ + struct rtgui_widget + { + /* inherit from rtgui_object */ + struct rtgui_object object; - /* the widget that contains this widget */ - struct rtgui_widget *parent; - /* the window that contains this widget */ - struct rtgui_win *toplevel; - /* the widget children and sibling */ - rtgui_list_t sibling; + /* the widget that contains this widget */ + struct rtgui_widget *parent; + /* the window that contains this widget */ + struct rtgui_win *toplevel; + /* the widget children and sibling */ + rtgui_list_t sibling; - /* widget flag */ - rt_int32_t flag; + /* widget flag */ + rt_int32_t flag; - /* hardware device context */ - rt_uint32_t dc_type; - const struct rtgui_dc_engine* dc_engine; + /* hardware device context */ + rt_uint32_t dc_type; + const struct rtgui_dc_engine *dc_engine; - /* the graphic context of widget */ - rtgui_gc_t gc; + /* the graphic context of widget */ + rtgui_gc_t gc; - /* the widget extent */ - rtgui_rect_t extent; + /* the widget extent */ + rtgui_rect_t extent; - /* minimal width and height of widget */ - rt_int16_t mini_width, mini_height; - /* widget align */ - rt_int32_t align; - rt_uint16_t border; - rt_uint16_t border_style; - /* the rect clip */ - rtgui_region_t clip; + /* minimal width and height of widget */ + rt_int16_t mini_width, mini_height; + /* widget align */ + rt_int32_t align; + rt_uint16_t border; + rt_uint16_t border_style; + /* the rect clip */ + rtgui_region_t clip; - /* call back */ - rt_bool_t (*on_focus_in) (struct rtgui_object* widget, struct rtgui_event* event); - rt_bool_t (*on_focus_out) (struct rtgui_object* widget, struct rtgui_event* event); + /* call back */ + rt_bool_t (*on_focus_in)(struct rtgui_object *widget, struct rtgui_event *event); + rt_bool_t (*on_focus_out)(struct rtgui_object *widget, struct rtgui_event *event); #ifndef RTGUI_USING_SMALL_SIZE - rt_bool_t (*on_draw) (struct rtgui_object* widget, struct rtgui_event* event); - rt_bool_t (*on_mouseclick) (struct rtgui_object* widget, struct rtgui_event* event); - rt_bool_t (*on_key) (struct rtgui_object* widget, struct rtgui_event* event); - rt_bool_t (*on_size) (struct rtgui_object* widget, struct rtgui_event* event); - rt_bool_t (*on_command) (struct rtgui_object* widget, struct rtgui_event* event); + rt_bool_t (*on_draw)(struct rtgui_object *widget, struct rtgui_event *event); + rt_bool_t (*on_mouseclick)(struct rtgui_object *widget, struct rtgui_event *event); + rt_bool_t (*on_key)(struct rtgui_object *widget, struct rtgui_event *event); + rt_bool_t (*on_size)(struct rtgui_object *widget, struct rtgui_event *event); + rt_bool_t (*on_command)(struct rtgui_object *widget, struct rtgui_event *event); #endif - /* user private data */ - rt_uint32_t user_data; -}; -typedef struct rtgui_widget rtgui_widget_t; + /* user private data */ + rt_uint32_t user_data; + }; + typedef struct rtgui_widget rtgui_widget_t; -rtgui_widget_t *rtgui_widget_create(rtgui_type_t *widget_type); -void rtgui_widget_destroy(rtgui_widget_t* widget); + rtgui_widget_t *rtgui_widget_create(rtgui_type_t *widget_type); + void rtgui_widget_destroy(rtgui_widget_t *widget); -rt_bool_t rtgui_widget_event_handler(struct rtgui_object* object, rtgui_event_t* event); + rt_bool_t rtgui_widget_event_handler(struct rtgui_object *object, rtgui_event_t *event); -/* focus and unfocus */ -void rtgui_widget_focus(rtgui_widget_t * widget); -void rtgui_widget_unfocus(rtgui_widget_t *widget); + /* focus and unfocus */ + void rtgui_widget_focus(rtgui_widget_t *widget); + void rtgui_widget_unfocus(rtgui_widget_t *widget); -/* event handler for each command */ -void rtgui_widget_set_onfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler); -void rtgui_widget_set_onunfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler); + /* event handler for each command */ + void rtgui_widget_set_onfocus(rtgui_widget_t *widget, rtgui_event_handler_ptr handler); + void rtgui_widget_set_onunfocus(rtgui_widget_t *widget, rtgui_event_handler_ptr handler); #ifndef RTGUI_USING_SMALL_SIZE -void rtgui_widget_set_ondraw(rtgui_widget_t* widget, rtgui_event_handler_ptr handler); -void rtgui_widget_set_onmouseclick(rtgui_widget_t* widget, rtgui_event_handler_ptr handler); -void rtgui_widget_set_onkey(rtgui_widget_t* widget, rtgui_event_handler_ptr handler); -void rtgui_widget_set_onsize(rtgui_widget_t* widget, rtgui_event_handler_ptr handler); -void rtgui_widget_set_oncommand(rtgui_widget_t* widget, rtgui_event_handler_ptr handler); + void rtgui_widget_set_ondraw(rtgui_widget_t *widget, rtgui_event_handler_ptr handler); + void rtgui_widget_set_onmouseclick(rtgui_widget_t *widget, rtgui_event_handler_ptr handler); + void rtgui_widget_set_onkey(rtgui_widget_t *widget, rtgui_event_handler_ptr handler); + void rtgui_widget_set_onsize(rtgui_widget_t *widget, rtgui_event_handler_ptr handler); + void rtgui_widget_set_oncommand(rtgui_widget_t *widget, rtgui_event_handler_ptr handler); #endif -/* get and set rect of widget */ -void rtgui_widget_get_rect(rtgui_widget_t* widget, rtgui_rect_t *rect); -void rtgui_widget_set_border(rtgui_widget_t* widget, rt_uint32_t style); -void rtgui_widget_set_rect(rtgui_widget_t* widget, const rtgui_rect_t* rect); -void rtgui_widget_set_rectangle(rtgui_widget_t* widget, int x, int y, int width, int height); -void rtgui_widget_get_extent(rtgui_widget_t* widget, rtgui_rect_t *rect); + /* get and set rect of widget */ + void rtgui_widget_get_rect(rtgui_widget_t *widget, rtgui_rect_t *rect); + void rtgui_widget_set_border(rtgui_widget_t *widget, rt_uint32_t style); + void rtgui_widget_set_rect(rtgui_widget_t *widget, const rtgui_rect_t *rect); + void rtgui_widget_set_rectangle(rtgui_widget_t *widget, int x, int y, int width, int height); + void rtgui_widget_get_extent(rtgui_widget_t *widget, rtgui_rect_t *rect); #ifndef RTGUI_USING_SMALL_SIZE -void rtgui_widget_set_miniwidth(rtgui_widget_t* widget, int width); -void rtgui_widget_set_miniheight(rtgui_widget_t* widget, int height); + void rtgui_widget_set_miniwidth(rtgui_widget_t *widget, int width); + void rtgui_widget_set_miniheight(rtgui_widget_t *widget, int height); #endif -void rtgui_widget_set_parent(rtgui_widget_t* widget, rtgui_widget_t* parent); + void rtgui_widget_set_parent(rtgui_widget_t *widget, rtgui_widget_t *parent); -/* get the physical position of a logic point on widget */ -void rtgui_widget_point_to_device(rtgui_widget_t * widget, rtgui_point_t * point); -/* get the physical position of a logic rect on widget */ -void rtgui_widget_rect_to_device(rtgui_widget_t * widget, rtgui_rect_t * rect); + /* get the physical position of a logic point on widget */ + void rtgui_widget_point_to_device(rtgui_widget_t *widget, rtgui_point_t *point); + /* get the physical position of a logic rect on widget */ + void rtgui_widget_rect_to_device(rtgui_widget_t *widget, rtgui_rect_t *rect); -/* get the logic position of a physical point on widget */ -void rtgui_widget_point_to_logic(rtgui_widget_t* widget, rtgui_point_t * point); -/* get the logic position of a physical rect on widget */ -void rtgui_widget_rect_to_logic(rtgui_widget_t* widget, rtgui_rect_t* rect); + /* get the logic position of a physical point on widget */ + void rtgui_widget_point_to_logic(rtgui_widget_t *widget, rtgui_point_t *point); + /* get the logic position of a physical rect on widget */ + void rtgui_widget_rect_to_logic(rtgui_widget_t *widget, rtgui_rect_t *rect); -/* move widget and its children to a logic point */ -void rtgui_widget_move_to_logic(rtgui_widget_t* widget, int dx, int dy); + /* move widget and its children to a logic point */ + void rtgui_widget_move_to_logic(rtgui_widget_t *widget, int dx, int dy); -/* update the clip info of widget */ -void rtgui_widget_update_clip(rtgui_widget_t* widget); + /* update the clip info of widget */ + void rtgui_widget_update_clip(rtgui_widget_t *widget); -/* get the toplevel widget of widget */ -struct rtgui_win* rtgui_widget_get_toplevel(rtgui_widget_t* widget); -rt_bool_t rtgui_widget_onupdate_toplvl(struct rtgui_object *object, struct rtgui_event *event); + /* get the toplevel widget of widget */ + struct rtgui_win *rtgui_widget_get_toplevel(rtgui_widget_t *widget); + rt_bool_t rtgui_widget_onupdate_toplvl(struct rtgui_object *object, struct rtgui_event *event); -void rtgui_widget_show(rtgui_widget_t* widget); -rt_bool_t rtgui_widget_onshow(struct rtgui_object *object, struct rtgui_event *event); -void rtgui_widget_hide(rtgui_widget_t* widget); -rt_bool_t rtgui_widget_onhide(struct rtgui_object *object, struct rtgui_event *event); -void rtgui_widget_update(rtgui_widget_t* widget); + void rtgui_widget_show(rtgui_widget_t *widget); + rt_bool_t rtgui_widget_onshow(struct rtgui_object *object, struct rtgui_event *event); + void rtgui_widget_hide(rtgui_widget_t *widget); + rt_bool_t rtgui_widget_onhide(struct rtgui_object *object, struct rtgui_event *event); + void rtgui_widget_update(rtgui_widget_t *widget); -/* get parent color */ -rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t* widget); -rtgui_color_t rtgui_widget_get_parent_background(rtgui_widget_t* widget); + /* get parent color */ + rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t *widget); + rtgui_color_t rtgui_widget_get_parent_background(rtgui_widget_t *widget); -/* get the next sibling of widget */ -rtgui_widget_t* rtgui_widget_get_next_sibling(rtgui_widget_t* widget); -/* get the prev sibling of widget */ -rtgui_widget_t* rtgui_widget_get_prev_sibling(rtgui_widget_t* widget); + /* get the next sibling of widget */ + rtgui_widget_t *rtgui_widget_get_next_sibling(rtgui_widget_t *widget); + /* get the prev sibling of widget */ + rtgui_widget_t *rtgui_widget_get_prev_sibling(rtgui_widget_t *widget); -/* dump widget information */ -void rtgui_widget_dump(rtgui_widget_t* widget); + /* dump widget information */ + void rtgui_widget_dump(rtgui_widget_t *widget); #ifdef __cplusplus } diff --git a/components/rtgui/include/rtgui/widgets/window.h b/components/rtgui/include/rtgui/widgets/window.h index cc502cdbdb..6c8a37cf7f 100644 --- a/components/rtgui/include/rtgui/widgets/window.h +++ b/components/rtgui/include/rtgui/widgets/window.h @@ -28,37 +28,37 @@ DECLARE_CLASS_TYPE(win); /** 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_NO_FOCUS 0x0001 /* non-focused window */ -#define RTGUI_WIN_STYLE_NO_TITLE 0x0002 /* no title window */ -#define RTGUI_WIN_STYLE_NO_BORDER 0x0004 /* no border window */ -#define RTGUI_WIN_STYLE_CLOSEBOX 0x0008 /* window has the close button */ -#define RTGUI_WIN_STYLE_MINIBOX 0x0010 /* window has the mini button */ +#define RTGUI_WIN_STYLE_NO_FOCUS 0x0001 /* non-focused window */ +#define RTGUI_WIN_STYLE_NO_TITLE 0x0002 /* no title window */ +#define RTGUI_WIN_STYLE_NO_BORDER 0x0004 /* no border window */ +#define RTGUI_WIN_STYLE_CLOSEBOX 0x0008 /* window has the close button */ +#define RTGUI_WIN_STYLE_MINIBOX 0x0010 /* window has the mini button */ -#define RTGUI_WIN_STYLE_DESTROY_ON_CLOSE 0x0020 /* window is destroyed when closed */ -#define RTGUI_WIN_STYLE_ONTOP 0x0040 /* window is in the top layer */ -#define RTGUI_WIN_STYLE_ONBTM 0x0080 /* window is in the bottom layer */ -#define RTGUI_WIN_STYLE_MAINWIN 0x0106 /* window is a main window */ +#define RTGUI_WIN_STYLE_DESTROY_ON_CLOSE 0x0020 /* window is destroyed when closed */ +#define RTGUI_WIN_STYLE_ONTOP 0x0040 /* window is in the top layer */ +#define RTGUI_WIN_STYLE_ONBTM 0x0080 /* window is in the bottom layer */ +#define RTGUI_WIN_STYLE_MAINWIN 0x0106 /* window is a main window */ -#define RTGUI_WIN_STYLE_DEFAULT (RTGUI_WIN_STYLE_CLOSEBOX | RTGUI_WIN_STYLE_MINIBOX) +#define RTGUI_WIN_STYLE_DEFAULT (RTGUI_WIN_STYLE_CLOSEBOX | RTGUI_WIN_STYLE_MINIBOX) enum rtgui_win_flag { - RTGUI_WIN_FLAG_INIT = 0x00, /* init state */ - RTGUI_WIN_FLAG_MODAL = 0x01, /* modal mode window */ - RTGUI_WIN_FLAG_CLOSED = 0x02, /* window is closed */ - RTGUI_WIN_FLAG_ACTIVATE = 0x04, /* window is activated */ - RTGUI_WIN_FLAG_UNDER_MODAL = 0x08, /* window is under modal - show(modaled by other) */ - RTGUI_WIN_FLAG_CONNECTED = 0x10, /* connected to server */ - /* window is event_key dispatcher(dispatch it to the focused widget in - * current window) _and_ a key handler(it should be able to handle keys - * such as ESC). Both of dispatching and handling are in the same - * function(rtgui_win_event_handler). So we have to distinguish between the - * two modes. - * - * If this flag is set, we are in key-handling mode. - */ - RTGUI_WIN_FLAG_HANDLE_KEY = 0x20 + RTGUI_WIN_FLAG_INIT = 0x00, /* init state */ + RTGUI_WIN_FLAG_MODAL = 0x01, /* modal mode window */ + RTGUI_WIN_FLAG_CLOSED = 0x02, /* window is closed */ + RTGUI_WIN_FLAG_ACTIVATE = 0x04, /* window is activated */ + RTGUI_WIN_FLAG_UNDER_MODAL = 0x08, /* window is under modal + show(modaled by other) */ + RTGUI_WIN_FLAG_CONNECTED = 0x10, /* connected to server */ + /* window is event_key dispatcher(dispatch it to the focused widget in + * current window) _and_ a key handler(it should be able to handle keys + * such as ESC). Both of dispatching and handling are in the same + * function(rtgui_win_event_handler). So we have to distinguish between the + * two modes. + * + * If this flag is set, we are in key-handling mode. + */ + RTGUI_WIN_FLAG_HANDLE_KEY = 0x20 }; struct rtgui_win_title; @@ -66,54 +66,57 @@ struct rtgui_win_area; struct rtgui_win { - /* inherit from container */ - rtgui_container_t parent; + /* inherit from container */ + rtgui_container_t parent; - /* drawing count */ - rt_base_t drawing; + /* drawing count */ + rt_base_t drawing; /* parent window. RT_NULL if the window is a top level window */ - struct rtgui_win *parent_window; + struct rtgui_win *parent_window; - /* the widget that will grab the focus in current window */ - struct rtgui_widget *focused_widget; + /* the widget that will grab the focus in current window */ + struct rtgui_widget *focused_widget; - /* window style */ - rt_uint16_t style; + /* which app I belong */ + struct rtgui_app *app; - /* window state flag */ - enum rtgui_win_flag flag; + /* window style */ + rt_uint16_t style; - rtgui_modal_code_t modal_code; + /* window state flag */ + enum rtgui_win_flag flag; - /* last mouse event handled widget */ - rtgui_widget_t* last_mevent_widget; + rtgui_modal_code_t modal_code; - /* window title */ - char* title; + /* last mouse event handled widget */ + rtgui_widget_t *last_mevent_widget; - /* call back */ - rt_bool_t (*on_activate) (struct rtgui_object* widget, struct rtgui_event* event); - rt_bool_t (*on_deactivate) (struct rtgui_object* widget, struct rtgui_event* event); - rt_bool_t (*on_close) (struct rtgui_object* widget, struct rtgui_event* event); - /* the key is sent to the focused widget by default. If the focused widget - * and all of it's parents didn't handle the key event, it will be handled - * by @func on_key - * - * If you want to handle key event on your own, it's better to overload - * this function other than handle EVENT_KBD in event_handler. - */ - rt_bool_t (*on_key) (struct rtgui_object* widget, struct rtgui_event* event); + /* window title */ + char *title; - /* reserved user data */ - rt_uint32_t user_data; + /* call back */ + rt_bool_t (*on_activate)(struct rtgui_object *widget, struct rtgui_event *event); + rt_bool_t (*on_deactivate)(struct rtgui_object *widget, struct rtgui_event *event); + rt_bool_t (*on_close)(struct rtgui_object *widget, struct rtgui_event *event); + /* the key is sent to the focused widget by default. If the focused widget + * and all of it's parents didn't handle the key event, it will be handled + * by @func on_key + * + * If you want to handle key event on your own, it's better to overload + * this function other than handle EVENT_KBD in event_handler. + */ + rt_bool_t (*on_key)(struct rtgui_object *widget, struct rtgui_event *event); + + /* reserved user data */ + rt_uint32_t user_data; }; -rtgui_win_t* rtgui_win_create(struct rtgui_win *parent_window, const char* title, - rtgui_rect_t *rect, rt_uint16_t style); -rtgui_win_t* rtgui_mainwin_create(struct rtgui_win *parent_window, const char* title, rt_uint16_t style); +rtgui_win_t *rtgui_win_create(struct rtgui_win *parent_window, const char *title, + rtgui_rect_t *rect, rt_uint16_t style); +rtgui_win_t *rtgui_mainwin_create(struct rtgui_win *parent_window, const char *title, rt_uint16_t style); -void rtgui_win_destroy(rtgui_win_t* win); +void rtgui_win_destroy(rtgui_win_t *win); /** Close window. * @@ -124,30 +127,30 @@ void rtgui_win_destroy(rtgui_win_t* win); * * \sa rtgui_win_set_onclose . */ -rt_bool_t rtgui_win_close(struct rtgui_win* win); +rt_bool_t rtgui_win_close(struct rtgui_win *win); rt_base_t rtgui_win_show(struct rtgui_win *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); +void rtgui_win_hiden(rtgui_win_t *win); +void rtgui_win_end_modal(rtgui_win_t *win, rtgui_modal_code_t modal_code); rt_err_t rtgui_win_activate(struct rtgui_win *win); -rt_bool_t rtgui_win_is_activated(struct rtgui_win* win); +rt_bool_t rtgui_win_is_activated(struct rtgui_win *win); -void rtgui_win_move(struct rtgui_win* win, int x, int y); +void rtgui_win_move(struct rtgui_win *win, int x, int y); /* reset extent of window */ -void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect); -void rtgui_win_update_clip(struct rtgui_win* win); +void rtgui_win_set_rect(rtgui_win_t *win, rtgui_rect_t *rect); +void rtgui_win_update_clip(struct rtgui_win *win); -void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler); -void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler); -void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler); -void rtgui_win_set_onkey(rtgui_win_t* win, rtgui_event_handler_ptr handler); +void rtgui_win_set_onactivate(rtgui_win_t *win, rtgui_event_handler_ptr handler); +void rtgui_win_set_ondeactivate(rtgui_win_t *win, rtgui_event_handler_ptr handler); +void rtgui_win_set_onclose(rtgui_win_t *win, rtgui_event_handler_ptr handler); +void rtgui_win_set_onkey(rtgui_win_t *win, rtgui_event_handler_ptr handler); -rt_bool_t rtgui_win_event_handler(struct rtgui_object* win, struct rtgui_event* event); +rt_bool_t rtgui_win_event_handler(struct rtgui_object *win, struct rtgui_event *event); -void rtgui_win_event_loop(rtgui_win_t* wnd); +void rtgui_win_event_loop(rtgui_win_t *wnd); -void rtgui_win_set_title(rtgui_win_t* win, const char *title); -char* rtgui_win_get_title(rtgui_win_t* win); +void rtgui_win_set_title(rtgui_win_t *win, const char *title); +char *rtgui_win_get_title(rtgui_win_t *win); #endif |
