add leaked destructor in widgets
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@157 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
c8d02426c7
commit
774c4d961a
|
@ -36,6 +36,7 @@ void rtgui_system_image_init(void)
|
||||||
{
|
{
|
||||||
/* always support XPM image */
|
/* always support XPM image */
|
||||||
rtgui_image_xpm_init();
|
rtgui_image_xpm_init();
|
||||||
|
rtgui_image_hdc_init();
|
||||||
|
|
||||||
#ifdef RTGUI_IMAGE_BMP
|
#ifdef RTGUI_IMAGE_BMP
|
||||||
rtgui_image_bmp_init();
|
rtgui_image_bmp_init();
|
||||||
|
|
|
@ -129,15 +129,18 @@ static void rtgui_image_hdc_unload(struct rtgui_image* image)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* rect)
|
static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* dst_rect)
|
||||||
{
|
{
|
||||||
rt_uint16_t y, w, h;
|
rt_uint16_t y, w, h;
|
||||||
rtgui_color_t foreground;
|
rtgui_color_t foreground;
|
||||||
struct rtgui_image_hdc* hdc;
|
struct rtgui_image_hdc* hdc;
|
||||||
rt_uint16_t rect_pitch, hw_pitch;
|
rt_uint16_t rect_pitch, hw_pitch;
|
||||||
rtgui_rect_t dc_rect;
|
rtgui_rect_t dc_rect, _rect, *rect;
|
||||||
|
|
||||||
RT_ASSERT(image != RT_NULL && dc != RT_NULL && rect != RT_NULL);
|
RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL);
|
||||||
|
|
||||||
|
_rect = *dst_rect;
|
||||||
|
rect = &_rect;
|
||||||
|
|
||||||
/* this dc is not visible */
|
/* this dc is not visible */
|
||||||
if (dc->get_visible(dc) != RT_TRUE) return;
|
if (dc->get_visible(dc) != RT_TRUE) return;
|
||||||
|
@ -148,8 +151,7 @@ static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc,
|
||||||
/* transfer logic coordinate to physical coordinate */
|
/* transfer logic coordinate to physical coordinate */
|
||||||
if (dc->type == RTGUI_DC_HW)
|
if (dc->type == RTGUI_DC_HW)
|
||||||
{
|
{
|
||||||
struct rtgui_dc_hw *hw_dc = (struct rtgui_dc_hw*)dc;
|
dc_rect = ((struct rtgui_dc_hw*)dc)->owner->extent;
|
||||||
dc_rect = hw_dc->owner->extent;
|
|
||||||
}
|
}
|
||||||
else rtgui_dc_get_rect(dc, &dc_rect);
|
else rtgui_dc_get_rect(dc, &dc_rect);
|
||||||
rtgui_rect_moveto(rect, dc_rect.x1, dc_rect.y1);
|
rtgui_rect_moveto(rect, dc_rect.x1, dc_rect.y1);
|
||||||
|
@ -197,15 +199,15 @@ static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc,
|
||||||
|
|
||||||
for (y = 0; y < h; y ++)
|
for (y = 0; y < h; y ++)
|
||||||
{
|
{
|
||||||
hdc->hw_driver->draw_raw_hline(rect_ptr, rect->x1, rect->x2, rect->y1 + y);
|
hdc->hw_driver->draw_raw_hline(rect_ptr, rect->x1, rect->x1 + w, rect->y1 + y);
|
||||||
rect_ptr += rect_pitch;
|
rect_ptr += hdc->pitch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rt_uint8_t* rect_ptr;
|
rt_uint8_t* rect_ptr;
|
||||||
rect_ptr = rtgui_malloc(rect_pitch);
|
rect_ptr = rtgui_malloc(hdc->pitch);
|
||||||
if (rect_ptr == RT_NULL) return; /* no memory */
|
if (rect_ptr == RT_NULL) return; /* no memory */
|
||||||
|
|
||||||
/* seek to the begin of pixel data */
|
/* seek to the begin of pixel data */
|
||||||
|
@ -223,7 +225,7 @@ static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc,
|
||||||
for (y = 0; y < h; y ++)
|
for (y = 0; y < h; y ++)
|
||||||
{
|
{
|
||||||
/* read pixel data */
|
/* read pixel data */
|
||||||
if (rtgui_filerw_read(hdc->filerw, rect_ptr, 1, rect_pitch) != rect_pitch)
|
if (rtgui_filerw_read(hdc->filerw, rect_ptr, 1, hdc->pitch) != hdc->pitch)
|
||||||
break; /* read data failed */
|
break; /* read data failed */
|
||||||
|
|
||||||
rt_memcpy(hw_ptr, rect_ptr, rect_pitch);
|
rt_memcpy(hw_ptr, rect_ptr, rect_pitch);
|
||||||
|
@ -235,10 +237,10 @@ static void rtgui_image_hdc_blit(struct rtgui_image* image, struct rtgui_dc* dc,
|
||||||
for (y = 0; y < h; y ++)
|
for (y = 0; y < h; y ++)
|
||||||
{
|
{
|
||||||
/* read pixel data */
|
/* read pixel data */
|
||||||
if (rtgui_filerw_read(hdc->filerw, rect_ptr, 1, rect_pitch) != rect_pitch)
|
if (rtgui_filerw_read(hdc->filerw, rect_ptr, 1, hdc->pitch) != hdc->pitch)
|
||||||
break; /* read data failed */
|
break; /* read data failed */
|
||||||
|
|
||||||
hdc->hw_driver->draw_raw_hline(rect_ptr, rect->x1, rect->x2, rect->y1 + y);
|
hdc->hw_driver->draw_raw_hline(rect_ptr, rect->x1, rect->x1 + w, rect->y1 + y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,9 @@ struct rtgui_graphic_driver
|
||||||
void (*draw_hline)(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y);
|
void (*draw_hline)(rtgui_color_t *c, rt_base_t x1, rt_base_t x2, rt_base_t y);
|
||||||
void (*draw_vline)(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2);
|
void (*draw_vline)(rtgui_color_t *c, rt_base_t x , rt_base_t y1, rt_base_t y2);
|
||||||
|
|
||||||
|
/* draw raw hline */
|
||||||
|
void (*draw_raw_hline)(rt_uint8_t *pixels, rt_base_t x1, rt_base_t x2, rt_base_t y);
|
||||||
|
|
||||||
/* the driver list */
|
/* the driver list */
|
||||||
rtgui_list_t list;
|
rtgui_list_t list;
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
// #define RT_USING_STDIO_FILERW
|
// #define RT_USING_STDIO_FILERW
|
||||||
#define RT_USING_DFS_FILERW
|
#define RT_USING_DFS_FILERW
|
||||||
#define RTGUI_IMAGE_PNG
|
// #define RTGUI_IMAGE_PNG
|
||||||
|
|
||||||
#define RTGUI_SVR_THREAD_PRIORITY 15
|
#define RTGUI_SVR_THREAD_PRIORITY 15
|
||||||
#define RTGUI_SVR_THREAD_TIMESLICE 5
|
#define RTGUI_SVR_THREAD_TIMESLICE 5
|
||||||
|
|
|
@ -70,6 +70,7 @@ void rtgui_server_post_event(struct rtgui_event* event, rt_size_t size);
|
||||||
/* register or deregister panel in server */
|
/* register or deregister panel in server */
|
||||||
void rtgui_panel_register(char* name, rtgui_rect_t* extent);
|
void rtgui_panel_register(char* name, rtgui_rect_t* extent);
|
||||||
void rtgui_panel_deregister(char* name);
|
void rtgui_panel_deregister(char* name);
|
||||||
|
void rtgui_panel_set_default_focused(char* name);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ struct rtgui_workbench
|
||||||
|
|
||||||
/* workbench title */
|
/* workbench title */
|
||||||
unsigned char* title;
|
unsigned char* title;
|
||||||
|
rtgui_view_t* current_view;
|
||||||
};
|
};
|
||||||
|
|
||||||
rtgui_workbench_t *rtgui_workbench_create(const char* panel_name, const unsigned char* title);
|
rtgui_workbench_t *rtgui_workbench_create(const char* panel_name, const unsigned char* title);
|
||||||
|
@ -67,6 +68,7 @@ void rtgui_workbench_event_loop(rtgui_workbench_t* workbench);
|
||||||
rt_err_t rtgui_workbench_show (rtgui_workbench_t* workbench);
|
rt_err_t rtgui_workbench_show (rtgui_workbench_t* workbench);
|
||||||
rt_err_t rtgui_workbench_hide (rtgui_workbench_t* workbench);
|
rt_err_t rtgui_workbench_hide (rtgui_workbench_t* workbench);
|
||||||
|
|
||||||
|
rtgui_view_t *rtgui_workbench_get_current_view(rtgui_workbench_t * workbench);
|
||||||
void rtgui_workbench_add_view(rtgui_workbench_t* workbench, rtgui_view_t* view);
|
void rtgui_workbench_add_view(rtgui_workbench_t* workbench, rtgui_view_t* view);
|
||||||
void rtgui_workbench_remove_view(rtgui_workbench_t* workbench, rtgui_view_t* view);
|
void rtgui_workbench_remove_view(rtgui_workbench_t* workbench, rtgui_view_t* view);
|
||||||
void rtgui_workbench_show_view(rtgui_workbench_t* workbench, rtgui_view_t* view);
|
void rtgui_workbench_show_view(rtgui_workbench_t* workbench, rtgui_view_t* view);
|
||||||
|
|
|
@ -77,6 +77,19 @@ void rtgui_panel_deregister(char* name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* set default focused panel, please use it after registered panel */
|
||||||
|
void rtgui_panel_set_default_focused(char* name)
|
||||||
|
{
|
||||||
|
extern struct rtgui_panel* rtgui_server_focus_panel;
|
||||||
|
struct rtgui_panel* panel;
|
||||||
|
|
||||||
|
panel = rtgui_panel_find(name);
|
||||||
|
if (panel != RT_NULL)
|
||||||
|
{
|
||||||
|
rtgui_server_focus_panel = panel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct rtgui_panel* rtgui_panel_find(char* name)
|
struct rtgui_panel* rtgui_panel_find(char* name)
|
||||||
{
|
{
|
||||||
struct rtgui_list_node* node;
|
struct rtgui_list_node* node;
|
||||||
|
|
|
@ -28,7 +28,7 @@ static struct rt_messagequeue rtgui_server_mq;
|
||||||
static char rtgui_server_msg_pool[2048];
|
static char rtgui_server_msg_pool[2048];
|
||||||
|
|
||||||
extern struct rtgui_topwin* rtgui_server_focus_topwin;
|
extern struct rtgui_topwin* rtgui_server_focus_topwin;
|
||||||
static struct rtgui_panel* rtgui_server_focus_panel = RT_NULL;
|
struct rtgui_panel* rtgui_server_focus_panel = RT_NULL;
|
||||||
|
|
||||||
void rtgui_server_create_application(struct rtgui_event_panel_attach* event)
|
void rtgui_server_create_application(struct rtgui_event_panel_attach* event)
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,6 +35,21 @@ static void _rtgui_button_constructor(rtgui_button_t *button)
|
||||||
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(button)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
|
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(button)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _rtgui_button_destructor(rtgui_button_t *button)
|
||||||
|
{
|
||||||
|
if (button->pressed_image != RT_NULL)
|
||||||
|
{
|
||||||
|
rtgui_image_destroy(button->pressed_image);
|
||||||
|
button->pressed_image = RT_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button->unpressed_image != RT_NULL)
|
||||||
|
{
|
||||||
|
rtgui_image_destroy(button->unpressed_image);
|
||||||
|
button->unpressed_image = RT_NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rtgui_type_t *rtgui_button_type_get(void)
|
rtgui_type_t *rtgui_button_type_get(void)
|
||||||
{
|
{
|
||||||
static rtgui_type_t *button_type = RT_NULL;
|
static rtgui_type_t *button_type = RT_NULL;
|
||||||
|
@ -42,7 +57,9 @@ rtgui_type_t *rtgui_button_type_get(void)
|
||||||
if (!button_type)
|
if (!button_type)
|
||||||
{
|
{
|
||||||
button_type = rtgui_type_create("button", RTGUI_LABEL_TYPE,
|
button_type = rtgui_type_create("button", RTGUI_LABEL_TYPE,
|
||||||
sizeof(rtgui_button_t), RTGUI_CONSTRUCTOR(_rtgui_button_constructor), RT_NULL);
|
sizeof(rtgui_button_t),
|
||||||
|
RTGUI_CONSTRUCTOR(_rtgui_button_constructor),
|
||||||
|
RTGUI_DESTRUCTOR(_rtgui_button_destructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
return button_type;
|
return button_type;
|
||||||
|
|
|
@ -28,6 +28,18 @@ static void _rtgui_iconbox_constructor(rtgui_iconbox_t *iconbox)
|
||||||
iconbox->text_position = RTGUI_ICONBOX_TEXT_BELOW;
|
iconbox->text_position = RTGUI_ICONBOX_TEXT_BELOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _rtgui_iconbox_destructor(rtgui_iconbox_t *iconbox)
|
||||||
|
{
|
||||||
|
if (iconbox->image != RT_NULL)
|
||||||
|
{
|
||||||
|
rtgui_image_destroy(iconbox->image);
|
||||||
|
iconbox->image = RT_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
rt_free(iconbox->text);
|
||||||
|
iconbox->text = RT_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
rtgui_type_t *rtgui_iconbox_type_get(void)
|
rtgui_type_t *rtgui_iconbox_type_get(void)
|
||||||
{
|
{
|
||||||
static rtgui_type_t *iconbox_type = RT_NULL;
|
static rtgui_type_t *iconbox_type = RT_NULL;
|
||||||
|
@ -35,7 +47,8 @@ rtgui_type_t *rtgui_iconbox_type_get(void)
|
||||||
if (!iconbox_type)
|
if (!iconbox_type)
|
||||||
{
|
{
|
||||||
iconbox_type = rtgui_type_create("iconbox", RTGUI_WIDGET_TYPE,
|
iconbox_type = rtgui_type_create("iconbox", RTGUI_WIDGET_TYPE,
|
||||||
sizeof(rtgui_iconbox_t), RTGUI_CONSTRUCTOR(_rtgui_iconbox_constructor), RT_NULL);
|
sizeof(rtgui_iconbox_t), RTGUI_CONSTRUCTOR(_rtgui_iconbox_constructor),
|
||||||
|
RTGUI_DESTRUCTOR(_rtgui_iconbox_destructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
return iconbox_type;
|
return iconbox_type;
|
||||||
|
|
|
@ -28,7 +28,7 @@ static void _rtgui_label_constructor(rtgui_label_t *label)
|
||||||
static void _rtgui_label_destructor(rtgui_label_t *label)
|
static void _rtgui_label_destructor(rtgui_label_t *label)
|
||||||
{
|
{
|
||||||
/* release text memory */
|
/* release text memory */
|
||||||
rtgui_free(label->text);
|
rt_free(label->text);
|
||||||
label->text = RT_NULL;
|
label->text = RT_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ void rtgui_label_set_text(rtgui_label_t* label, const unsigned char* text)
|
||||||
if (label->text != RT_NULL)
|
if (label->text != RT_NULL)
|
||||||
{
|
{
|
||||||
/* release old text memory */
|
/* release old text memory */
|
||||||
rtgui_free(label->text);
|
rt_free(label->text);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (text != RT_NULL) label->text = (unsigned char*)rt_strdup((const char*)text);
|
if (text != RT_NULL) label->text = (unsigned char*)rt_strdup((const char*)text);
|
||||||
|
|
|
@ -53,7 +53,7 @@ static void _rtgui_textbox_deconstructor(rtgui_textbox_t *box)
|
||||||
{
|
{
|
||||||
if (box->text != RT_NULL)
|
if (box->text != RT_NULL)
|
||||||
{
|
{
|
||||||
rtgui_free(box->text);
|
rt_free(box->text);
|
||||||
box->text = RT_NULL;
|
box->text = RT_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,12 @@ static void _rtgui_wintitle_constructor(rtgui_wintitle_t* wintitle)
|
||||||
RTGUI_WIDGET(wintitle)->flag = RTGUI_WIDGET_FLAG_DEFAULT;
|
RTGUI_WIDGET(wintitle)->flag = RTGUI_WIDGET_FLAG_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _rtgui_wintitle_deconstructor(rtgui_wintitle_t* wintitle)
|
||||||
|
{
|
||||||
|
rt_free(wintitle->title);
|
||||||
|
wintitle->title = RT_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
rtgui_type_t* rtgui_wintitle_type_get()
|
rtgui_type_t* rtgui_wintitle_type_get()
|
||||||
{
|
{
|
||||||
static rtgui_type_t *wintitle_type = RT_NULL;
|
static rtgui_type_t *wintitle_type = RT_NULL;
|
||||||
|
@ -28,7 +34,9 @@ rtgui_type_t* rtgui_wintitle_type_get()
|
||||||
if (!wintitle_type)
|
if (!wintitle_type)
|
||||||
{
|
{
|
||||||
wintitle_type = rtgui_type_create("wintitle", RTGUI_TOPLEVEL_TYPE,
|
wintitle_type = rtgui_type_create("wintitle", RTGUI_TOPLEVEL_TYPE,
|
||||||
sizeof(rtgui_wintitle_t), RTGUI_CONSTRUCTOR(_rtgui_wintitle_constructor), RT_NULL);
|
sizeof(rtgui_wintitle_t),
|
||||||
|
RTGUI_CONSTRUCTOR(_rtgui_wintitle_constructor),
|
||||||
|
RTGUI_DESTRUCTOR(_rtgui_wintitle_deconstructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
return wintitle_type;
|
return wintitle_type;
|
||||||
|
|
|
@ -41,6 +41,7 @@ static void _rtgui_toplevel_destructor(rtgui_toplevel_t* toplevel)
|
||||||
rtgui_free(toplevel->external_clip_rect);
|
rtgui_free(toplevel->external_clip_rect);
|
||||||
|
|
||||||
toplevel->drawing = 0;
|
toplevel->drawing = 0;
|
||||||
|
rtgui_free(toplevel->external_clip_rect);
|
||||||
toplevel->external_clip_rect = RT_NULL;
|
toplevel->external_clip_rect = RT_NULL;
|
||||||
toplevel->external_clip_size = 0;
|
toplevel->external_clip_size = 0;
|
||||||
toplevel->focus = RT_NULL;
|
toplevel->focus = RT_NULL;
|
||||||
|
|
|
@ -25,6 +25,15 @@ static void _rtgui_view_constructor(rtgui_view_t *view)
|
||||||
view->title = RT_NULL;
|
view->title = RT_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _rtgui_view_destructor(rtgui_view_t *view)
|
||||||
|
{
|
||||||
|
if (view->title != RT_NULL)
|
||||||
|
{
|
||||||
|
rt_free(view->title);
|
||||||
|
view->title = RT_NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rtgui_type_t *rtgui_view_type_get(void)
|
rtgui_type_t *rtgui_view_type_get(void)
|
||||||
{
|
{
|
||||||
static rtgui_type_t *view_type = RT_NULL;
|
static rtgui_type_t *view_type = RT_NULL;
|
||||||
|
@ -32,7 +41,9 @@ rtgui_type_t *rtgui_view_type_get(void)
|
||||||
if (!view_type)
|
if (!view_type)
|
||||||
{
|
{
|
||||||
view_type = rtgui_type_create("view", RTGUI_CONTAINER_TYPE,
|
view_type = rtgui_type_create("view", RTGUI_CONTAINER_TYPE,
|
||||||
sizeof(rtgui_view_t), RTGUI_CONSTRUCTOR(_rtgui_view_constructor), RT_NULL);
|
sizeof(rtgui_view_t),
|
||||||
|
RTGUI_CONSTRUCTOR(_rtgui_view_constructor),
|
||||||
|
RTGUI_DESTRUCTOR(_rtgui_view_destructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
return view_type;
|
return view_type;
|
||||||
|
@ -113,6 +124,8 @@ void rtgui_view_show(rtgui_view_t* view)
|
||||||
}
|
}
|
||||||
|
|
||||||
rtgui_workbench_show_view((rtgui_workbench_t*)(RTGUI_WIDGET(view)->parent), view);
|
rtgui_workbench_show_view((rtgui_workbench_t*)(RTGUI_WIDGET(view)->parent), view);
|
||||||
|
if (RTGUI_WIDGET_IS_FOCUSABLE(RTGUI_WIDGET(view)))
|
||||||
|
rtgui_widget_focus(RTGUI_WIDGET(view));
|
||||||
}
|
}
|
||||||
|
|
||||||
void rtgui_view_hide(rtgui_view_t* view)
|
void rtgui_view_hide(rtgui_view_t* view)
|
||||||
|
|
|
@ -50,12 +50,13 @@ static void _rtgui_win_destructor(rtgui_win_t* win)
|
||||||
if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&edestroy),
|
if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&edestroy),
|
||||||
sizeof(struct rtgui_event_win_destroy)) != RT_EOK)
|
sizeof(struct rtgui_event_win_destroy)) != RT_EOK)
|
||||||
{
|
{
|
||||||
|
/* destroy in server failed */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* release field */
|
/* release field */
|
||||||
rtgui_free(win->title);
|
rt_free(win->title);
|
||||||
}
|
}
|
||||||
|
|
||||||
static rt_bool_t _rtgui_win_create_in_server(rtgui_win_t* win)
|
static rt_bool_t _rtgui_win_create_in_server(rtgui_win_t* win)
|
||||||
|
|
|
@ -23,6 +23,7 @@ static void _rtgui_workbench_constructor(rtgui_workbench_t *workbench)
|
||||||
/* set attributes */
|
/* set attributes */
|
||||||
workbench->panel = RT_NULL;
|
workbench->panel = RT_NULL;
|
||||||
workbench->flag = RTGUI_WORKBENCH_FLAG_DEFAULT;
|
workbench->flag = RTGUI_WORKBENCH_FLAG_DEFAULT;
|
||||||
|
workbench->current_view = RT_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _rtgui_workbench_destructor(rtgui_workbench_t *workbench)
|
static void _rtgui_workbench_destructor(rtgui_workbench_t *workbench)
|
||||||
|
@ -46,10 +47,8 @@ static void _rtgui_workbench_destructor(rtgui_workbench_t *workbench)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* release title */
|
/* release title */
|
||||||
if (workbench->title != RT_NULL)
|
rt_free(workbench->title);
|
||||||
{
|
workbench->title = RT_NULL;
|
||||||
rtgui_free(workbench->title);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rtgui_type_t *rtgui_workbench_type_get(void)
|
rtgui_type_t *rtgui_workbench_type_get(void)
|
||||||
|
@ -158,28 +157,6 @@ void rtgui_workbench_set_flag(rtgui_workbench_t* workbench, rt_uint8_t flag)
|
||||||
workbench->flag = flag;
|
workbench->flag = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
rtgui_view_t *rtgui_workbench_get_current_view(rtgui_workbench_t * workbench)
|
|
||||||
{
|
|
||||||
struct rtgui_list_node* node;
|
|
||||||
struct rtgui_widget* view;
|
|
||||||
|
|
||||||
RT_ASSERT(workbench != RT_NULL);
|
|
||||||
|
|
||||||
/* find the first shown view */
|
|
||||||
rtgui_list_foreach(node, &(RTGUI_CONTAINER(workbench)->children))
|
|
||||||
{
|
|
||||||
view = rtgui_list_entry(node, struct rtgui_widget, sibling);
|
|
||||||
|
|
||||||
/* is it a shown view? */
|
|
||||||
if (!RTGUI_WIDGET_IS_HIDE(view))
|
|
||||||
{
|
|
||||||
return (rtgui_view_t*)view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return RT_NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void rtgui_workbench_event_loop(rtgui_workbench_t* workbench)
|
void rtgui_workbench_event_loop(rtgui_workbench_t* workbench)
|
||||||
{
|
{
|
||||||
int quit = 0;
|
int quit = 0;
|
||||||
|
@ -279,7 +256,7 @@ rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* e
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* let viewer to handle it */
|
/* let viewer to handle it */
|
||||||
rtgui_view_t* view = rtgui_workbench_get_current_view(workbench);
|
rtgui_view_t* view = workbench->current_view;
|
||||||
if (view != RT_NULL &&
|
if (view != RT_NULL &&
|
||||||
RTGUI_WIDGET(view)->event_handler != RT_NULL)
|
RTGUI_WIDGET(view)->event_handler != RT_NULL)
|
||||||
{
|
{
|
||||||
|
@ -302,7 +279,7 @@ rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* e
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* let viewer to handle it */
|
/* let viewer to handle it */
|
||||||
rtgui_view_t* view = rtgui_workbench_get_current_view(workbench);
|
rtgui_view_t* view = workbench->current_view;
|
||||||
if (view != RT_NULL &&
|
if (view != RT_NULL &&
|
||||||
RTGUI_WIDGET(view)->event_handler != RT_NULL)
|
RTGUI_WIDGET(view)->event_handler != RT_NULL)
|
||||||
{
|
{
|
||||||
|
@ -344,7 +321,7 @@ rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* e
|
||||||
rtgui_view_t* view;
|
rtgui_view_t* view;
|
||||||
|
|
||||||
/* paint a view */
|
/* paint a view */
|
||||||
view = rtgui_workbench_get_current_view(workbench);
|
view = workbench->current_view;
|
||||||
if (view != RT_NULL)
|
if (view != RT_NULL)
|
||||||
{
|
{
|
||||||
/* remake a paint event */
|
/* remake a paint event */
|
||||||
|
@ -357,6 +334,16 @@ rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* e
|
||||||
RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
|
RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
struct rtgui_dc* dc;
|
||||||
|
struct rtgui_rect rect;
|
||||||
|
|
||||||
|
dc = rtgui_dc_begin_drawing(widget);
|
||||||
|
rtgui_widget_get_rect(widget, &rect);
|
||||||
|
rtgui_dc_fill_rect(dc, &rect);
|
||||||
|
rtgui_dc_end_drawing(dc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -408,9 +395,17 @@ rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* e
|
||||||
return RT_TRUE;
|
return RT_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* view on workbench
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
void rtgui_workbench_add_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
|
void rtgui_workbench_add_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
|
||||||
{
|
{
|
||||||
rtgui_container_add_child(RTGUI_CONTAINER(workbench), RTGUI_WIDGET(view));
|
rtgui_container_add_child(RTGUI_CONTAINER(workbench), RTGUI_WIDGET(view));
|
||||||
|
/* hide view in default */
|
||||||
|
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view));
|
||||||
|
|
||||||
/* reset view extent */
|
/* reset view extent */
|
||||||
rtgui_widget_set_rect(RTGUI_WIDGET(view), &(RTGUI_WIDGET(workbench)->extent));
|
rtgui_widget_set_rect(RTGUI_WIDGET(view), &(RTGUI_WIDGET(workbench)->extent));
|
||||||
|
@ -418,6 +413,9 @@ void rtgui_workbench_add_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
|
||||||
|
|
||||||
void rtgui_workbench_remove_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
|
void rtgui_workbench_remove_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
|
||||||
{
|
{
|
||||||
|
if (view == workbench->current_view)
|
||||||
|
rtgui_workbench_hide_view(workbench, view);
|
||||||
|
|
||||||
rtgui_container_remove_child(RTGUI_CONTAINER(workbench), RTGUI_WIDGET(view));
|
rtgui_container_remove_child(RTGUI_CONTAINER(workbench), RTGUI_WIDGET(view));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,17 +424,18 @@ void rtgui_workbench_show_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
|
||||||
RT_ASSERT(workbench != RT_NULL);
|
RT_ASSERT(workbench != RT_NULL);
|
||||||
RT_ASSERT(view != RT_NULL);
|
RT_ASSERT(view != RT_NULL);
|
||||||
|
|
||||||
if (rtgui_workbench_get_current_view(workbench) == view &&
|
/* already shown */
|
||||||
!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(view))) return;
|
if (workbench->current_view == view) return;
|
||||||
|
|
||||||
/* remove from child list */
|
if (workbench->current_view != RT_NULL)
|
||||||
rtgui_list_remove(&(RTGUI_CONTAINER(workbench)->children), &(RTGUI_WIDGET(view)->sibling));
|
{
|
||||||
|
/* hide old view */
|
||||||
/* insert to the head of child list */
|
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench->current_view));
|
||||||
rtgui_list_insert(&(RTGUI_CONTAINER(workbench)->children), &(RTGUI_WIDGET(view)->sibling));
|
}
|
||||||
|
|
||||||
/* show view */
|
/* show view */
|
||||||
RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(view));
|
RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(view));
|
||||||
|
workbench->current_view = view;
|
||||||
|
|
||||||
/* update workbench clip */
|
/* update workbench clip */
|
||||||
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
|
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
|
||||||
|
@ -452,21 +451,27 @@ void rtgui_workbench_hide_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
|
||||||
RT_ASSERT(workbench != RT_NULL);
|
RT_ASSERT(workbench != RT_NULL);
|
||||||
RT_ASSERT(view != RT_NULL);
|
RT_ASSERT(view != RT_NULL);
|
||||||
|
|
||||||
/* remove from child list */
|
|
||||||
rtgui_list_remove(&(RTGUI_CONTAINER(workbench)->children), &(RTGUI_WIDGET(view)->sibling));
|
|
||||||
|
|
||||||
/* append to the end of child list */
|
|
||||||
rtgui_list_append(&(RTGUI_CONTAINER(workbench)->children), &(RTGUI_WIDGET(view)->sibling));
|
|
||||||
|
|
||||||
/* hide view */
|
/* hide view */
|
||||||
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view));
|
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view));
|
||||||
|
|
||||||
|
if (view == workbench->current_view)
|
||||||
|
{
|
||||||
|
rtgui_view_t *next_view;
|
||||||
|
|
||||||
|
workbench->current_view = RT_NULL;
|
||||||
|
|
||||||
|
next_view = RTGUI_VIEW(rtgui_widget_get_next_sibling(RTGUI_WIDGET(view)));
|
||||||
|
if (next_view == RT_NULL)
|
||||||
|
next_view = RTGUI_VIEW(rtgui_widget_get_prev_sibling(RTGUI_WIDGET(view)));
|
||||||
|
|
||||||
|
if (next_view != RT_NULL)
|
||||||
|
{
|
||||||
|
rtgui_view_show(next_view);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* update workbench clip */
|
/* update workbench clip */
|
||||||
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
|
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
|
||||||
|
}
|
||||||
if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(workbench)))
|
|
||||||
{
|
|
||||||
view = rtgui_workbench_get_current_view(workbench);
|
|
||||||
rtgui_widget_update(RTGUI_WIDGET(view));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue