mirror of https://github.com/RT-Thread/rt-thread
merge new RTGUI in to trunk
The full log is at https://github.com/RTGUI/RTGUI/commits/merge_1 and it's difficult to merge the new tree commit by commit. I also converted all the file into unix eol so there are many fake diff. Big changes are noted in rtgui/doc/road_map.txt and rtgui/doc/attention.txt. Keep an eye on them if you want to migrate your old code. Note that the work is still in progress and the bsp is not prepared in trunk so far. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2092 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
06d45f0c42
commit
db06460208
|
@ -34,9 +34,9 @@ common/pixel_driver.c
|
|||
""")
|
||||
|
||||
server_src = Split("""
|
||||
server/rtgui_application.c
|
||||
server/driver.c
|
||||
server/mouse.c
|
||||
server/panel.c
|
||||
server/server.c
|
||||
server/topwin.c
|
||||
""")
|
||||
|
@ -45,7 +45,6 @@ widgets_src = Split("""
|
|||
widgets/box.c
|
||||
widgets/button.c
|
||||
widgets/checkbox.c
|
||||
widgets/container.c
|
||||
widgets/combobox.c
|
||||
widgets/iconbox.c
|
||||
widgets/label.c
|
||||
|
@ -62,13 +61,12 @@ widgets/listbox.c
|
|||
widgets/title.c
|
||||
widgets/toplevel.c
|
||||
widgets/notebook.c
|
||||
widgets/view.c
|
||||
widgets/container.c
|
||||
widgets/list_view.c
|
||||
widgets/about_view.c
|
||||
widgets/filelist_view.c
|
||||
widgets/widget.c
|
||||
widgets/window.c
|
||||
widgets/workbench.c
|
||||
""")
|
||||
|
||||
# The set of source files associated with this SConscript file.
|
||||
|
|
|
@ -21,9 +21,10 @@
|
|||
|
||||
#include <rtgui/driver.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
#include <rtgui/rtgui_server.h>
|
||||
#include <rtgui/widgets/container.h>
|
||||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/widgets/workbench.h>
|
||||
#include <rtgui/widgets/title.h>
|
||||
|
||||
static void rtgui_dc_client_draw_point(struct rtgui_dc* dc, int x, int y);
|
||||
|
@ -50,12 +51,9 @@ struct rtgui_dc* rtgui_dc_begin_drawing(rtgui_widget_t* owner)
|
|||
|
||||
if ((rtgui_region_is_flat(&owner->clip) == RT_EOK) &&
|
||||
rtgui_rect_is_equal(&(owner->extent), &(owner->clip.extents)) == RT_EOK)
|
||||
{
|
||||
/* use hardware DC */
|
||||
return rtgui_dc_hw_create(owner);
|
||||
}
|
||||
|
||||
return rtgui_dc_client_create(owner);
|
||||
else
|
||||
return rtgui_dc_client_create(owner);
|
||||
}
|
||||
|
||||
void rtgui_dc_end_drawing(struct rtgui_dc* dc)
|
||||
|
@ -116,7 +114,7 @@ struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner)
|
|||
if (RTGUI_WIDGET_IS_HIDE(widget))
|
||||
{
|
||||
RTGUI_WIDGET_DC_SET_UNVISIBLE(owner);
|
||||
break;
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
widget = widget->parent;
|
||||
|
@ -130,7 +128,7 @@ struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner)
|
|||
if (top->drawing == 1)
|
||||
{
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
#ifdef __WIN32__
|
||||
#ifdef _WIN32
|
||||
rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
|
||||
rt_kprintf("hide cursor\n");
|
||||
rtgui_mouse_hide_cursor();
|
||||
|
@ -141,15 +139,18 @@ struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner)
|
|||
#endif
|
||||
}
|
||||
}
|
||||
else if (RTGUI_IS_WORKBENCH(owner->toplevel) ||
|
||||
RTGUI_IS_WIN(owner->toplevel))
|
||||
else if (RTGUI_IS_APPLICATION(owner->toplevel))
|
||||
{
|
||||
RT_ASSERT(0);
|
||||
}
|
||||
else if (RTGUI_IS_WIN(owner->toplevel))
|
||||
{
|
||||
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
|
||||
top->drawing ++;
|
||||
|
||||
if (top->drawing == 1)
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
#ifdef _WIN32
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
|
||||
rt_kprintf("hide cursor\n");
|
||||
|
@ -161,7 +162,7 @@ struct rtgui_dc* rtgui_dc_client_create(rtgui_widget_t* owner)
|
|||
RTGUI_EVENT_UPDATE_BEGIN_INIT(&(eupdate));
|
||||
eupdate.rect = RTGUI_WIDGET(top)->extent;
|
||||
|
||||
rtgui_thread_send(top->server, (struct rtgui_event*)&eupdate, sizeof(eupdate));
|
||||
rtgui_server_post_event((struct rtgui_event*)&eupdate, sizeof(eupdate));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -186,7 +187,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc)
|
|||
top->drawing --;
|
||||
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
#ifdef _WIN32
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
rt_mutex_release(&cursor_mutex);
|
||||
/* show cursor */
|
||||
|
@ -206,7 +207,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc)
|
|||
#endif
|
||||
}
|
||||
}
|
||||
else if (RTGUI_IS_WORKBENCH(owner->toplevel) ||
|
||||
else if (RTGUI_IS_APPLICATION(owner->toplevel) ||
|
||||
RTGUI_IS_WIN(owner->toplevel))
|
||||
{
|
||||
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
|
||||
|
@ -214,7 +215,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc)
|
|||
|
||||
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
#ifdef _WIN32
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
rt_mutex_release(&cursor_mutex);
|
||||
/* show cursor */
|
||||
|
@ -229,7 +230,7 @@ static rt_bool_t rtgui_dc_client_fini(struct rtgui_dc* dc)
|
|||
RTGUI_EVENT_UPDATE_END_INIT(&(eupdate));
|
||||
eupdate.rect = owner->extent;
|
||||
|
||||
rtgui_thread_send(top->server, (struct rtgui_event*)&eupdate, sizeof(eupdate));
|
||||
rtgui_server_post_event((struct rtgui_event*)&eupdate, sizeof(eupdate));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,11 @@
|
|||
#include <rtgui/dc_hw.h>
|
||||
#include <rtgui/driver.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
#include <rtgui/rtgui_server.h>
|
||||
|
||||
#include <rtgui/widgets/container.h>
|
||||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/widgets/workbench.h>
|
||||
#include <rtgui/widgets/title.h>
|
||||
|
||||
static void rtgui_dc_hw_draw_point(struct rtgui_dc* dc, int x, int y);
|
||||
|
@ -81,7 +83,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
|
|||
if (RTGUI_WIDGET_IS_HIDE(widget))
|
||||
{
|
||||
RTGUI_WIDGET_DC_SET_UNVISIBLE(owner);
|
||||
break;
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
widget = widget->parent;
|
||||
|
@ -104,7 +106,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
|
|||
if (top->drawing == 1)
|
||||
{
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
#ifdef __WIN32__
|
||||
#ifdef _WIN32
|
||||
rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
|
||||
rt_kprintf("hide cursor\n");
|
||||
rtgui_mouse_hide_cursor();
|
||||
|
@ -115,7 +117,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
|
|||
#endif
|
||||
}
|
||||
}
|
||||
else if (RTGUI_IS_WORKBENCH(owner->toplevel) ||
|
||||
else if (RTGUI_IS_APPLICATION(owner->toplevel) ||
|
||||
RTGUI_IS_WIN(owner->toplevel))
|
||||
{
|
||||
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
|
||||
|
@ -123,7 +125,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
|
|||
|
||||
if (top->drawing == 1)
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
#ifdef _WIN32
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
rt_mutex_take(&cursor_mutex, RT_WAITING_FOREVER);
|
||||
rt_kprintf("hide cursor\n");
|
||||
|
@ -135,7 +137,7 @@ struct rtgui_dc* rtgui_dc_hw_create(rtgui_widget_t* owner)
|
|||
RTGUI_EVENT_UPDATE_BEGIN_INIT(&(eupdate));
|
||||
eupdate.rect = RTGUI_WIDGET(top)->extent;
|
||||
|
||||
rtgui_thread_send(top->server, (struct rtgui_event*)&eupdate, sizeof(eupdate));
|
||||
rtgui_server_post_event((struct rtgui_event*)&eupdate, sizeof(eupdate));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +164,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
|
|||
top->drawing --;
|
||||
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
#ifdef _WIN32
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
rt_mutex_release(&cursor_mutex);
|
||||
/* show cursor */
|
||||
|
@ -182,7 +184,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
|
|||
#endif
|
||||
}
|
||||
}
|
||||
else if (RTGUI_IS_WORKBENCH(owner->toplevel) ||
|
||||
else if (RTGUI_IS_APPLICATION(owner->toplevel) ||
|
||||
RTGUI_IS_WIN(owner->toplevel))
|
||||
{
|
||||
rtgui_toplevel_t* top = RTGUI_TOPLEVEL(owner->toplevel);
|
||||
|
@ -190,7 +192,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
|
|||
|
||||
if ((top->drawing == 0) && RTGUI_WIDGET_IS_DC_VISIBLE(owner))
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
#ifdef _WIN32
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
rt_mutex_release(&cursor_mutex);
|
||||
/* show cursor */
|
||||
|
@ -205,7 +207,7 @@ static rt_bool_t rtgui_dc_hw_fini(struct rtgui_dc* dc)
|
|||
RTGUI_EVENT_UPDATE_END_INIT(&(eupdate));
|
||||
eupdate.rect = owner->extent;
|
||||
|
||||
rtgui_thread_send(top->server, (struct rtgui_event*)&eupdate, sizeof(eupdate));
|
||||
rtgui_server_post_event((struct rtgui_event*)&eupdate, sizeof(eupdate));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ static void rtgui_hz_bitmap_font_draw_text (struct rtgui_font* font, struct rtgu
|
|||
while (length > 0)
|
||||
{
|
||||
len = 0;
|
||||
while (((rt_uint8_t)*(text + len)) < 0x80 && *(text + len)) len ++;
|
||||
while (((rt_uint8_t)*(text + len)) < 0x80 && *(text + len) && len < length) len ++;
|
||||
/* draw text with English font */
|
||||
if (len > 0)
|
||||
{
|
||||
|
@ -97,7 +97,7 @@ static void rtgui_hz_bitmap_font_draw_text (struct rtgui_font* font, struct rtgu
|
|||
}
|
||||
|
||||
len = 0;
|
||||
while (((rt_uint8_t)*(text + len)) >= 0x80) len ++;
|
||||
while (((rt_uint8_t)*(text + len)) >= 0x80 && len < length) len ++;
|
||||
if (len > 0)
|
||||
{
|
||||
_rtgui_hz_bitmap_font_draw_text(bmp_font, dc, text, len, rect);
|
||||
|
|
|
@ -177,7 +177,7 @@ static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_d
|
|||
while (length > 0)
|
||||
{
|
||||
len = 0;
|
||||
while (((rt_uint8_t)*(text + len)) < 0x80 && *(text + len)) len ++;
|
||||
while (((rt_uint8_t)*(text + len)) < 0x80 && *(text + len) && len < length) len ++;
|
||||
/* draw text with English font */
|
||||
if (len > 0)
|
||||
{
|
||||
|
@ -188,7 +188,7 @@ static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_d
|
|||
}
|
||||
|
||||
len = 0;
|
||||
while (((rt_uint8_t)*(text + len)) >= 0x80) len ++;
|
||||
while (((rt_uint8_t)*(text + len)) >= 0x80 && len < length) len ++;
|
||||
if (len > 0)
|
||||
{
|
||||
_rtgui_hz_file_font_draw_text(hz_file_font, dc, text, len, rect);
|
||||
|
|
|
@ -64,23 +64,6 @@ void rtgui_system_image_init(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
static struct rtgui_image_engine* rtgui_image_get_engine(const char* type)
|
||||
{
|
||||
struct rtgui_list_node *node;
|
||||
struct rtgui_image_engine *engine;
|
||||
|
||||
rtgui_list_foreach(node, &_rtgui_system_image_list)
|
||||
{
|
||||
engine = rtgui_list_entry(node, struct rtgui_image_engine, list);
|
||||
|
||||
if (strncasecmp(engine->name, type, strlen(engine->name)) ==0)
|
||||
return engine;
|
||||
}
|
||||
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
|
||||
static struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn)
|
||||
{
|
||||
struct rtgui_list_node *node;
|
||||
|
@ -105,6 +88,23 @@ static struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char*
|
|||
return RT_NULL;
|
||||
}
|
||||
|
||||
static struct rtgui_image_engine* rtgui_image_get_engine(const char* type)
|
||||
{
|
||||
struct rtgui_list_node *node;
|
||||
struct rtgui_image_engine *engine;
|
||||
|
||||
rtgui_list_foreach(node, &_rtgui_system_image_list)
|
||||
{
|
||||
engine = rtgui_list_entry(node, struct rtgui_image_engine, list);
|
||||
|
||||
if (strncasecmp(engine->name, type, strlen(engine->name)) ==0)
|
||||
return engine;
|
||||
}
|
||||
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
|
||||
struct rtgui_image* rtgui_image_create_from_file(const char* type, const char* filename, rt_bool_t load)
|
||||
{
|
||||
struct rtgui_filerw* filerw;
|
||||
|
|
|
@ -17,9 +17,10 @@
|
|||
|
||||
static void _rtgui_object_constructor(rtgui_object_t *object)
|
||||
{
|
||||
if (!object) return;
|
||||
if (!object)
|
||||
return;
|
||||
|
||||
object->is_static = RT_FALSE;
|
||||
object->flag = RTGUI_OBJECT_FLAG_NONE;
|
||||
}
|
||||
|
||||
/* Destroys the object */
|
||||
|
@ -115,7 +116,6 @@ rtgui_object_t *rtgui_object_create(rtgui_type_t *object_type)
|
|||
#endif
|
||||
|
||||
new_object->type = object_type;
|
||||
new_object->is_static = RT_FALSE;
|
||||
|
||||
rtgui_type_object_construct(object_type, new_object);
|
||||
|
||||
|
@ -131,7 +131,8 @@ rtgui_object_t *rtgui_object_create(rtgui_type_t *object_type)
|
|||
*/
|
||||
void rtgui_object_destroy(rtgui_object_t *object)
|
||||
{
|
||||
if (!object || object->is_static == RT_TRUE) return;
|
||||
if (!object || object->flag & RTGUI_OBJECT_FLAG_STATIC)
|
||||
return;
|
||||
|
||||
#ifdef RTGUI_OBJECT_TRACE
|
||||
obj_info.objs_number --;
|
||||
|
@ -178,3 +179,15 @@ const rtgui_type_t *rtgui_object_object_type_get(rtgui_object_t *object)
|
|||
return object->type;
|
||||
}
|
||||
|
||||
void rtgui_object_set_event_handler(struct rtgui_object *object, rtgui_event_handler_ptr handler)
|
||||
{
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
|
||||
object->event_handler = handler;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_object_event_handler(struct rtgui_object *object, struct rtgui_event* event)
|
||||
{
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,15 +16,13 @@
|
|||
#include <rtgui/image.h>
|
||||
#include <rtgui/font.h>
|
||||
#include <rtgui/event.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
#include <rtgui/rtgui_server.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/rtgui_theme.h>
|
||||
|
||||
#define RTGUI_EVENT_DEBUG
|
||||
|
||||
#ifdef _WIN32
|
||||
#define RTGUI_EVENT_DEBUG
|
||||
#define RTGUI_MEM_TRACE
|
||||
#endif
|
||||
|
||||
|
@ -43,467 +41,6 @@ void rtgui_system_server_init()
|
|||
rtgui_system_theme_init();
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* RTGUI Thread Wrapper */
|
||||
/************************************************************************/
|
||||
#ifdef RTGUI_EVENT_DEBUG
|
||||
const char *event_string[] =
|
||||
{
|
||||
/* panel event */
|
||||
"PANEL_ATTACH", /* attach to a panel */
|
||||
"PANEL_DETACH", /* detach from a panel */
|
||||
"PANEL_SHOW", /* show in a panel */
|
||||
"PANEL_HIDE", /* hide from a panel */
|
||||
"PANEL_INFO", /* panel information */
|
||||
"PANEL_RESIZE", /* resize panel */
|
||||
"PANEL_FULLSCREEN", /* to full screen */
|
||||
"PANEL_NORMAL", /* to normal screen */
|
||||
|
||||
/* window event */
|
||||
"WIN_CREATE", /* create a window */
|
||||
"WIN_DESTROY", /* destroy a window */
|
||||
"WIN_SHOW", /* show a window */
|
||||
"WIN_HIDE", /* hide a window */
|
||||
"WIN_ACTIVATE", /* activate a window */
|
||||
"WIN_DEACTIVATE", /* deactivate a window */
|
||||
"WIN_CLOSE", /* close a window */
|
||||
"WIN_MOVE", /* move a window */
|
||||
"WIN_RESIZE", /* resize a window */
|
||||
|
||||
"SET_WM", /* set window manager */
|
||||
|
||||
"UPDATE_BEGIN", /* begin of update rect */
|
||||
"UPDATE_END", /* end of update rect */
|
||||
"MONITOR_ADD", /* add a monitor rect */
|
||||
"MONITOR_REMOVE", /* remove a monitor rect*/
|
||||
"PAINT", /* paint on screen */
|
||||
"TIMER", /* timer */
|
||||
|
||||
/* clip rect information */
|
||||
"CLIP_INFO", /* clip rect info */
|
||||
|
||||
/* mouse and keyboard event */
|
||||
"MOUSE_MOTION", /* mouse motion */
|
||||
"MOUSE_BUTTON", /* mouse button info */
|
||||
"KBD", /* keyboard info */
|
||||
|
||||
/* user command event */
|
||||
"COMMAND", /* user command */
|
||||
|
||||
/* request's status event */
|
||||
"STATUS", /* request result */
|
||||
"SCROLLED", /* scroll bar scrolled */
|
||||
"RESIZE", /* widget resize */
|
||||
};
|
||||
|
||||
#define DBG_MSG(x) rt_kprintf x
|
||||
|
||||
static void rtgui_event_dump(rt_thread_t tid, rtgui_event_t* event)
|
||||
{
|
||||
char* sender = "(unknown)";
|
||||
|
||||
if (event->sender != RT_NULL) sender = event->sender->name;
|
||||
|
||||
if ((event->type == RTGUI_EVENT_TIMER) ||
|
||||
(event->type == RTGUI_EVENT_UPDATE_BEGIN) ||
|
||||
(event->type == RTGUI_EVENT_UPDATE_END))
|
||||
{
|
||||
/* don't dump timer event */
|
||||
return ;
|
||||
}
|
||||
|
||||
rt_kprintf("%s -- %s --> %s ", sender, event_string[event->type], tid->name);
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
{
|
||||
struct rtgui_event_paint *paint = (struct rtgui_event_paint *)event;
|
||||
|
||||
if(paint->wid != RT_NULL)
|
||||
rt_kprintf("win: %s", paint->wid->title);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_KBD:
|
||||
{
|
||||
struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd*) event;
|
||||
if (ekbd->wid != RT_NULL)
|
||||
rt_kprintf("win: %s", ekbd->wid->title);
|
||||
if (RTGUI_KBD_IS_UP(ekbd)) rt_kprintf(", up");
|
||||
else rt_kprintf(", down");
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_CLIP_INFO:
|
||||
{
|
||||
struct rtgui_event_clip_info *info = (struct rtgui_event_clip_info *)event;
|
||||
|
||||
if(info->wid != RT_NULL)
|
||||
rt_kprintf("win: %s", info->wid->title);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_CREATE:
|
||||
{
|
||||
struct rtgui_event_win_create *create = (struct rtgui_event_win_create*)event;
|
||||
|
||||
rt_kprintf(" win: %s at (x1:%d, y1:%d, x2:%d, y2:%d)",
|
||||
#ifdef RTGUI_USING_SMALL_SIZE
|
||||
create->wid->title,
|
||||
RTGUI_WIDGET(create->wid)->extent.x1,
|
||||
RTGUI_WIDGET(create->wid)->extent.y1,
|
||||
RTGUI_WIDGET(create->wid)->extent.x2,
|
||||
RTGUI_WIDGET(create->wid)->extent.y2);
|
||||
#else
|
||||
create->title,
|
||||
create->extent.x1,
|
||||
create->extent.y1,
|
||||
create->extent.x2,
|
||||
create->extent.y2);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_UPDATE_END:
|
||||
{
|
||||
struct rtgui_event_update_end* update_end = (struct rtgui_event_update_end*)event;
|
||||
rt_kprintf("(x:%d, y1:%d, x2:%d, y2:%d)", update_end->rect.x1,
|
||||
update_end->rect.y1,
|
||||
update_end->rect.x2,
|
||||
update_end->rect.y2);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_ACTIVATE:
|
||||
case RTGUI_EVENT_WIN_DEACTIVATE:
|
||||
case RTGUI_EVENT_WIN_SHOW:
|
||||
{
|
||||
struct rtgui_event_win *win = (struct rtgui_event_win *)event;
|
||||
|
||||
if(win->wid != RT_NULL)
|
||||
rt_kprintf("win: %s", win->wid->title);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_MOVE:
|
||||
{
|
||||
struct rtgui_event_win_move *win = (struct rtgui_event_win_move *)event;
|
||||
|
||||
if(win->wid != RT_NULL)
|
||||
{
|
||||
rt_kprintf("win: %s", win->wid->title);
|
||||
rt_kprintf(" to (x:%d, y:%d)", win->x, win->y);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_RESIZE:
|
||||
{
|
||||
struct rtgui_event_win_resize* win = (struct rtgui_event_win_resize *)event;
|
||||
|
||||
if (win->wid != RT_NULL)
|
||||
{
|
||||
rt_kprintf("win: %s, rect(x1:%d, y1:%d, x2:%d, y2:%d)", win->wid->title,
|
||||
RTGUI_WIDGET(win->wid)->extent.x1,
|
||||
RTGUI_WIDGET(win->wid)->extent.y1,
|
||||
RTGUI_WIDGET(win->wid)->extent.x2,
|
||||
RTGUI_WIDGET(win->wid)->extent.y2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
case RTGUI_EVENT_MOUSE_MOTION:
|
||||
{
|
||||
struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse*)event;
|
||||
|
||||
if (mouse->button & RTGUI_MOUSE_BUTTON_LEFT) rt_kprintf("left ");
|
||||
else rt_kprintf("right ");
|
||||
|
||||
if (mouse->button & RTGUI_MOUSE_BUTTON_DOWN) rt_kprintf("down ");
|
||||
else rt_kprintf("up ");
|
||||
|
||||
if (mouse->wid != RT_NULL)
|
||||
rt_kprintf("win: %s at (%d, %d)", mouse->wid->title,
|
||||
mouse->x, mouse->y);
|
||||
else
|
||||
rt_kprintf("(%d, %d)", mouse->x, mouse->y);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MONITOR_ADD:
|
||||
{
|
||||
struct rtgui_event_monitor *monitor = (struct rtgui_event_monitor*)event;
|
||||
if (monitor->panel != RT_NULL)
|
||||
{
|
||||
rt_kprintf("the rect is:(%d, %d) - (%d, %d)",
|
||||
monitor->rect.x1, monitor->rect.y1,
|
||||
monitor->rect.x2, monitor->rect.y2);
|
||||
}
|
||||
else if (monitor->wid != RT_NULL)
|
||||
{
|
||||
rt_kprintf("win: %s, the rect is:(%d, %d) - (%d, %d)", monitor->wid->title,
|
||||
monitor->rect.x1, monitor->rect.y1,
|
||||
monitor->rect.x2, monitor->rect.y2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
rt_kprintf("\n");
|
||||
}
|
||||
#else
|
||||
#define DBG_MSG(x)
|
||||
#define rtgui_event_dump(tid, event)
|
||||
#endif
|
||||
|
||||
rtgui_thread_t* rtgui_thread_register(rt_thread_t tid, rt_mq_t mq)
|
||||
{
|
||||
rtgui_thread_t* thread = rtgui_malloc(sizeof(rtgui_thread_t));
|
||||
|
||||
if (thread != RT_NULL)
|
||||
{
|
||||
DBG_MSG(("register a rtgui thread: %s, tid: 0x%p\n", tid->name, tid));
|
||||
|
||||
/* set tid and mq */
|
||||
thread->tid = tid;
|
||||
thread->mq = mq;
|
||||
thread->widget = RT_NULL;
|
||||
thread->on_idle = RT_NULL;
|
||||
|
||||
/* set user thread */
|
||||
tid->user_data = (rt_uint32_t)thread;
|
||||
}
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
void rtgui_thread_deregister(rt_thread_t tid)
|
||||
{
|
||||
rtgui_thread_t* thread;
|
||||
|
||||
/* find rtgui_thread_t */
|
||||
thread = (rtgui_thread_t*) (tid->user_data);
|
||||
|
||||
if (thread != RT_NULL)
|
||||
{
|
||||
/* remove rtgui_thread_t */
|
||||
tid->user_data = 0;
|
||||
|
||||
/* free rtgui_thread_t */
|
||||
rtgui_free(thread);
|
||||
}
|
||||
}
|
||||
|
||||
/* get current gui thread */
|
||||
rtgui_thread_t* rtgui_thread_self()
|
||||
{
|
||||
rtgui_thread_t* thread;
|
||||
rt_thread_t self;
|
||||
|
||||
/* get current thread */
|
||||
self = rt_thread_self();
|
||||
thread = (rtgui_thread_t*)(self->user_data);
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
void rtgui_thread_set_onidle(rtgui_idle_func onidle)
|
||||
{
|
||||
rtgui_thread_t* thread;
|
||||
|
||||
thread = rtgui_thread_self();
|
||||
RT_ASSERT(thread != RT_NULL);
|
||||
|
||||
thread->on_idle = onidle;
|
||||
}
|
||||
|
||||
rtgui_idle_func rtgui_thread_get_onidle()
|
||||
{
|
||||
rtgui_thread_t* thread;
|
||||
|
||||
thread = rtgui_thread_self();
|
||||
RT_ASSERT(thread != RT_NULL);
|
||||
|
||||
return thread->on_idle;
|
||||
}
|
||||
|
||||
extern rt_thread_t rt_thread_find(char* name);
|
||||
rt_thread_t rtgui_thread_get_server()
|
||||
{
|
||||
return rt_thread_find("rtgui");
|
||||
}
|
||||
|
||||
void rtgui_thread_set_widget(rtgui_widget_t* widget)
|
||||
{
|
||||
rtgui_thread_t* thread;
|
||||
|
||||
/* get rtgui_thread */
|
||||
thread = (rtgui_thread_t*) (rt_thread_self()->user_data);
|
||||
|
||||
if (thread != RT_NULL) thread->widget = widget;
|
||||
}
|
||||
|
||||
rtgui_widget_t* rtgui_thread_get_widget()
|
||||
{
|
||||
rtgui_thread_t* thread;
|
||||
|
||||
/* get rtgui_thread_t */
|
||||
thread = (rtgui_thread_t*) (rt_thread_self()->user_data);
|
||||
|
||||
return thread == RT_NULL? RT_NULL : thread->widget;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_thread_send(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
|
||||
{
|
||||
rt_err_t result;
|
||||
rtgui_thread_t* thread;
|
||||
|
||||
rtgui_event_dump(tid, event);
|
||||
|
||||
/* find rtgui_thread_t */
|
||||
thread = (rtgui_thread_t*) (tid->user_data);
|
||||
if (thread == RT_NULL) return -RT_ERROR;
|
||||
|
||||
result = rt_mq_send(thread->mq, event, event_size);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
if (event->type != RTGUI_EVENT_TIMER)
|
||||
rt_kprintf("send event to %s failed\n", thread->tid->name);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_thread_send_urgent(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
|
||||
{
|
||||
rt_err_t result;
|
||||
rtgui_thread_t* thread;
|
||||
|
||||
rtgui_event_dump(tid, event);
|
||||
|
||||
/* find rtgui_thread_t */
|
||||
thread = (rtgui_thread_t*) (tid->user_data);
|
||||
if (thread == RT_NULL) return -RT_ERROR;
|
||||
|
||||
result = rt_mq_urgent(thread->mq, event, event_size);
|
||||
if (result != RT_EOK)
|
||||
rt_kprintf("send ergent event failed\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_thread_send_sync(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
|
||||
{
|
||||
rt_err_t r;
|
||||
rtgui_thread_t* thread;
|
||||
rt_int32_t ack_buffer, ack_status;
|
||||
struct rt_mailbox ack_mb;
|
||||
|
||||
rtgui_event_dump(tid, event);
|
||||
|
||||
/* init ack mailbox */
|
||||
r = rt_mb_init(&ack_mb, "ack", &ack_buffer, 1, 0);
|
||||
if (r!= RT_EOK) goto __return;
|
||||
|
||||
/* find rtgui_thread_t */
|
||||
thread = (rtgui_thread_t*) (tid->user_data);
|
||||
if (thread == RT_NULL)
|
||||
{
|
||||
r = -RT_ERROR;
|
||||
goto __return;
|
||||
}
|
||||
|
||||
event->ack = &ack_mb;
|
||||
r = rt_mq_send(thread->mq, event, event_size);
|
||||
if (r != RT_EOK)
|
||||
{
|
||||
rt_kprintf("send sync event failed\n");
|
||||
goto __return;
|
||||
}
|
||||
|
||||
r = rt_mb_recv(&ack_mb, (rt_uint32_t*)&ack_status, RT_WAITING_FOREVER);
|
||||
if (r!= RT_EOK) goto __return;
|
||||
|
||||
if (ack_status != RTGUI_STATUS_OK)
|
||||
r = -RT_ERROR;
|
||||
else
|
||||
r = RT_EOK;
|
||||
|
||||
__return:
|
||||
/* fini ack mailbox */
|
||||
rt_mb_detach(&ack_mb);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_thread_ack(rtgui_event_t* event, rt_int32_t status)
|
||||
{
|
||||
if (event != RT_NULL &&
|
||||
event->ack != RT_NULL)
|
||||
{
|
||||
rt_mb_send(event->ack, status);
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_thread_recv(rtgui_event_t* event, rt_size_t event_size)
|
||||
{
|
||||
rtgui_thread_t* thread;
|
||||
rt_err_t r;
|
||||
|
||||
/* find rtgui_thread_t */
|
||||
thread = (rtgui_thread_t*) (rt_thread_self()->user_data);
|
||||
if (thread == RT_NULL) return -RT_ERROR;
|
||||
|
||||
r = rt_mq_recv(thread->mq, event, event_size, RT_WAITING_FOREVER);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_thread_recv_nosuspend(rtgui_event_t* event, rt_size_t event_size)
|
||||
{
|
||||
rtgui_thread_t* thread;
|
||||
rt_err_t r;
|
||||
|
||||
/* find rtgui_thread */
|
||||
thread = (rtgui_thread_t*) (rt_thread_self()->user_data);
|
||||
if (thread == RT_NULL) return -RT_ERROR;
|
||||
|
||||
r = rt_mq_recv(thread->mq, event, event_size, 0);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_thread_recv_filter(rt_uint32_t type, rtgui_event_t* event, rt_size_t event_size)
|
||||
{
|
||||
rtgui_thread_t* thread;
|
||||
|
||||
/* find rtgui_thread_t */
|
||||
thread = (rtgui_thread_t*) (rt_thread_self()->user_data);
|
||||
if (thread == RT_NULL) return -RT_ERROR;
|
||||
|
||||
while (rt_mq_recv(thread->mq, event, event_size, RT_WAITING_FOREVER) == RT_EOK)
|
||||
{
|
||||
if (event->type == type)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* let widget to handle event */
|
||||
if (thread->widget != RT_NULL &&
|
||||
thread->widget->event_handler != RT_NULL)
|
||||
{
|
||||
thread->widget->event_handler(thread->widget, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
/* RTGUI Timer */
|
||||
/************************************************************************/
|
||||
|
@ -522,7 +59,7 @@ static void rtgui_time_out(void* parameter)
|
|||
|
||||
event.timer = timer;
|
||||
|
||||
rtgui_thread_send(timer->tid, &(event.parent), sizeof(rtgui_event_timer_t));
|
||||
rtgui_application_send(timer->tid, &(event.parent), sizeof(rtgui_event_timer_t));
|
||||
}
|
||||
|
||||
rtgui_timer_t* rtgui_timer_create(rt_int32_t time, rt_int32_t flag, rtgui_timeout_func timeout, void* parameter)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
1, 对同一 window 销毁两次会引起 segfault。同时,如果在创建时设置了
|
||||
RTGUI_WIN_STYLE_DESTROY_ON_CLOSE,close 窗口之后不要再去销毁窗口。
|
||||
|
||||
2, 所有的 window 由 topwin 进行管理,用户不要在指定创建具有父窗口的子窗口之后在
|
||||
把这个窗口加为父窗口的 child。这可能会导致子窗口无法显示。
|
||||
|
||||
3, command 事件添加了 wid 参数,用于指定此事件需要传递的目标窗口。
|
||||
|
||||
4, 在 widget 中添加了 on_show 和 on_hide 事件回调函数。他们会在控件显示/隐藏的
|
||||
时候被调用。
|
||||
|
||||
5, slider 控件改为左键减小数值,右键增加数值。横向的 slider 处理左右键,纵向的
|
||||
slider 处理上下键,上面的值小,下面的值大。
|
||||
|
||||
6, view 不再提供 show 方法。如果想单独显示控件,请用 window 包含之。
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
RTGUI for 1.1 路线图(排名不分先后)
|
||||
1, 把 rtgui_thread 给去掉,变成 rtgui_application ,消除原来的 rtgui_thread +
|
||||
mq 的模式。rtgui_application 记录当前依附的 panel,和 panel 的 extent。(Done)
|
||||
1.1, rtgui_application_run 运行主事件循环(Done)
|
||||
1.2, rtgui_application 作为事件的接收者_和_事件派发者。(Done)
|
||||
|
||||
2, workbench,window并成一个,其事件主循环并合并到rtgui_application中。
|
||||
2.1, window 作为有标题栏的 workbench(Done)
|
||||
2.2, 将其事件主循环移至 application 中。(Done)
|
||||
2.3, 将 window 的父类 toplevel 合并进 window 中。所有直接与服务器打交道的从
|
||||
window 继承。(或者将 toplevel 合并进 application 中,因为只有 application 才
|
||||
会和服务器打交道。)
|
||||
2.4 在创建 window 的时候需要指定 parent,如果为 RT_NULL,则此 window 为 root
|
||||
窗口,parent 为当前 rtgui_application。每一个 application 必须有且只有一个根
|
||||
窗口。(Done)
|
||||
2.5 添加一个 FULL_PANEL 的 STYLE。指定此 STYLE 之后会自动填满整个 panel。其
|
||||
与 NO_TITLE 之类的合用可以达到之前 workbench 的效果。(Deprecated)
|
||||
2.6 event_loop 可以设定顶层控件,只会把事件传递给顶层控件。这样可以方便的实
|
||||
现模态窗口。event_loop 靠 object 的一个标志位来判断是否要退出当前循环。(Done)
|
||||
|
||||
3, 将 view 合并进 container,所有容器类继承 container。[note1](Done)
|
||||
|
||||
4, 事件循环完成后不主动销毁控件,销毁任务交由用户完成。但是有些自动销毁是必要的
|
||||
,比如 container 自动销毁其包含的控件(Done)
|
||||
4.1 对于 window 的 onclose事件,保证在其回调函数中可以(但不是必须)安全销毁窗
|
||||
口。这个功能不保证能够实现。(onclose 是在将要关闭窗口的时候触发的,调用它之
|
||||
后 RTGUI 还要进行其他的设置和清理工作,所以不能在 onclose 里销毁窗口)(Cannot
|
||||
Implement)
|
||||
4.2 对 window 添加 RTGUI_WIN_STYLE_DESTROY_ON_CLOSE 。使得其在被关闭时自动销
|
||||
毁。注意:对同一 window 销毁两次会引起 segfault。同时,如果在创建时设置了
|
||||
RTGUI_WIN_STYLE_DESTROY_ON_CLOSE,close 窗口之后不要再去销毁窗口。
|
||||
|
||||
5, API 清理。更详细的文档。
|
||||
|
||||
6, 使 panel 退化为无窗口标题的 window,这样 server 就只记录 window 一种东西的位
|
||||
置。(Done, 删除了 panel,使得整体以 window 为主)
|
||||
|
||||
7, 指定名称的时候不再自己拷贝一份。(我觉得 90% 的情况下名称都是静态的字符串,这
|
||||
时用 strdup其实并没有必要。)(Deprecated)
|
||||
|
||||
8, 添加一些工业控制当中用到的波形、仪表之类的控件。
|
||||
|
||||
9, 在 window 中记录焦点控件,键盘事件由 window 直接投送。各个控件不记录焦点控件
|
||||
。(Done)
|
||||
|
||||
10, 在 widget 中添加 on_show 和 on_hide 事件回调函数。(Done)
|
||||
|
||||
11, 添加 EVENT_WIN_MODAL_ENTER 和 EVENT_WIN_MODAL_EXIT 事件,用来通知窗口管理器
|
||||
(topwin)一个窗口进入模态。窗口管理器根据这个进行相应的设置。
|
||||
|
||||
12, rtgui_filelist_view 不必继承自 container。
|
||||
|
||||
13, 添加 desktop window 支持。(Done)
|
||||
概念与名词:
|
||||
13.1 desktop window:最底层的桌面窗口。它会在所有窗口下面显示,并且不会被它
|
||||
上面的窗口模态掉。它的子窗口是 root window。(继承关系由 RTGUI 管理,不
|
||||
用用户管理)它只有在启用 RTGUI_USING_DESKTOP_WINDOW 时才有此特性。
|
||||
13.2 root window:创建时父窗口为 RT_NULL 的窗口。是用户空间窗口继承树的根。
|
||||
13.3 normal window:创建时父窗口不为 RT_NULL 的窗口。它始终会在父窗口之上显
|
||||
示(它会 clip 父窗口)。normal windows 和 root window 组成一个窗口树。
|
||||
13.4 模态:当一个 normal window 模态显示时会会模态自己所在树的同级窗口
|
||||
和所有父级窗口,但不会影响别的窗口树。被模态的窗口不会接受到用户事
|
||||
件(按键,触摸等)
|
||||
|
||||
----
|
||||
[note1] 我们至少需要一种容器控件来盛放其他的控件,并且能把上层事件传递给被包含
|
||||
的控件。实现这样的功能有一个就好,container 可以担当这个责任。其他需要放多个控
|
||||
件的控件则可以继承/包含这个控件。然后多个容器控件轮换的,notebook 可以来做。
|
||||
notebook可以是有标签和无标签的,有标签的对应一般的 tab 控件,无标签的对应 rtgui
|
||||
for RTT 1.0 的 workbench+view。
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* File : dlist.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2011, 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
|
||||
* 2006-03-16 Bernard the first version
|
||||
* 2006-09-07 Bernard move the kservice APIs to rtthread.h
|
||||
* 2007-06-27 Bernard fix the rt_list_remove bug
|
||||
* 2012-02-25 Grissiom move to rtgui/include/rtgui and some misc changes
|
||||
*/
|
||||
|
||||
#ifndef __RTGUI_DLIST_H__
|
||||
#define __RTGUI_DLIST_H__
|
||||
|
||||
/* This file is copied from kservice.h in RTT kernel. There are some differences:
|
||||
* 1, naming. Use rtgui_dlist_ prefix instead of rt_list.
|
||||
* 2, add rtgui_dlist_foreach for convenience.
|
||||
* 3, move the definition of list node into this file.
|
||||
*
|
||||
* Please keep both of the files synchronized when fixing bugs.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
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. */
|
||||
};
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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 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)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -17,61 +17,57 @@
|
|||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/kbddef.h>
|
||||
|
||||
/* NOTE: if you create a new event type, remember to add it into the union
|
||||
* rtgui_event_generic */
|
||||
enum _rtgui_event_type
|
||||
{
|
||||
/* panel event */
|
||||
RTGUI_EVENT_PANEL_ATTACH = 0, /* attach to a panel */
|
||||
RTGUI_EVENT_PANEL_DETACH, /* detach from a panel */
|
||||
RTGUI_EVENT_PANEL_SHOW, /* show in a panel */
|
||||
RTGUI_EVENT_PANEL_HIDE, /* hide from a panel */
|
||||
RTGUI_EVENT_PANEL_INFO, /* panel information */
|
||||
RTGUI_EVENT_PANEL_RESIZE, /* resize panel */
|
||||
RTGUI_EVENT_PANEL_FULLSCREEN, /* to full screen */
|
||||
RTGUI_EVENT_PANEL_NORMAL, /* to normal screen */
|
||||
|
||||
/* 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_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 */
|
||||
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_PAINT, /* paint on screen */
|
||||
RTGUI_EVENT_TIMER, /* timer */
|
||||
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_PAINT, /* paint on screen */
|
||||
RTGUI_EVENT_TIMER, /* timer */
|
||||
|
||||
/* clip rect information */
|
||||
RTGUI_EVENT_CLIP_INFO, /* clip rect info */
|
||||
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 */
|
||||
RTGUI_EVENT_MOUSE_MOTION, /* mouse motion */
|
||||
RTGUI_EVENT_MOUSE_BUTTON, /* mouse button info */
|
||||
RTGUI_EVENT_KBD, /* keyboard info */
|
||||
|
||||
/* user command event */
|
||||
RTGUI_EVENT_COMMAND, /* user command */
|
||||
RTGUI_EVENT_COMMAND, /* user command */
|
||||
|
||||
/* widget event */
|
||||
RTGUI_EVENT_FOCUSED, /* widget focused */
|
||||
RTGUI_EVENT_SCROLLED, /* scroll bar scrolled */
|
||||
RTGUI_EVENT_RESIZE, /* widget resize */
|
||||
RTGUI_EVENT_FOCUSED, /* widget focused */
|
||||
RTGUI_EVENT_SCROLLED, /* scroll bar scrolled */
|
||||
RTGUI_EVENT_RESIZE, /* widget resize */
|
||||
};
|
||||
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 */
|
||||
RTGUI_STATUS_OK = 0, /* status ok */
|
||||
RTGUI_STATUS_ERROR, /* generic error */
|
||||
RTGUI_STATUS_NRC, /* no resource */
|
||||
};
|
||||
|
||||
struct rtgui_event
|
||||
|
@ -98,144 +94,62 @@ typedef struct rtgui_event rtgui_event_t;
|
|||
(e)->ack = RT_NULL; \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* RTGUI Panel Event
|
||||
*/
|
||||
struct rtgui_event_panel_attach
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
/* the panel name to be attached */
|
||||
char panel_name[RTGUI_NAME_MAX];
|
||||
|
||||
/* workbench, wm field */
|
||||
rtgui_workbench_t* workbench;
|
||||
};
|
||||
|
||||
struct rtgui_event_panel_detach
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
/* the panel which thread belong to */
|
||||
rtgui_panel_t* panel;
|
||||
|
||||
/* workbench, wm field */
|
||||
rtgui_workbench_t* workbench;
|
||||
};
|
||||
|
||||
struct rtgui_event_panel_show
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
/* the panel which thread belong to */
|
||||
rtgui_panel_t* panel;
|
||||
|
||||
/* workbench, wm field */
|
||||
rtgui_workbench_t* workbench;
|
||||
};
|
||||
|
||||
struct rtgui_event_panel_hide
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
/* the panel which thread belong to */
|
||||
rtgui_panel_t* panel;
|
||||
|
||||
/* workbench, wm field */
|
||||
rtgui_workbench_t* workbench;
|
||||
};
|
||||
|
||||
struct rtgui_event_panel_info
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
/* panel info */
|
||||
rtgui_panel_t* panel;
|
||||
rtgui_rect_t extent;
|
||||
};
|
||||
|
||||
#define RTGUI_EVENT_PANEL_ATTACH_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PANEL_ATTACH)
|
||||
#define RTGUI_EVENT_PANEL_DETACH_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PANEL_DETACH)
|
||||
#define RTGUI_EVENT_PANEL_SHOW_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PANEL_SHOW)
|
||||
#define RTGUI_EVENT_PANEL_HIDE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PANEL_HIDE)
|
||||
#define RTGUI_EVENT_PANEL_INFO_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PANEL_INFO)
|
||||
#define _RTGUI_EVENT_WIN_ELEMENTS \
|
||||
struct rtgui_event parent; \
|
||||
struct rtgui_win *wid;
|
||||
|
||||
/*
|
||||
* RTGUI Window Event
|
||||
*/
|
||||
struct rtgui_event_win
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
/* the window id */
|
||||
rtgui_win_t* wid;
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
};
|
||||
|
||||
struct rtgui_event_win_create
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
_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;
|
||||
#endif
|
||||
|
||||
/* the window id */
|
||||
rtgui_win_t* wid;
|
||||
};
|
||||
|
||||
struct rtgui_event_win_move
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
/* the window id */
|
||||
rtgui_win_t* wid;
|
||||
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
rt_int16_t x, y;
|
||||
};
|
||||
|
||||
struct rtgui_event_win_resize
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
/* the window id */
|
||||
rtgui_win_t* wid;
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
rtgui_rect_t rect;
|
||||
};
|
||||
|
||||
#define rtgui_event_win_destroy rtgui_event_win
|
||||
#define rtgui_event_win_show rtgui_event_win
|
||||
#define rtgui_event_win_hide rtgui_event_win
|
||||
#define rtgui_event_win_activate rtgui_event_win
|
||||
#define rtgui_event_win_deactivate rtgui_event_win
|
||||
#define rtgui_event_win_close rtgui_event_win
|
||||
#define rtgui_event_win_destroy rtgui_event_win
|
||||
#define rtgui_event_win_show rtgui_event_win
|
||||
#define rtgui_event_win_hide rtgui_event_win
|
||||
#define rtgui_event_win_activate rtgui_event_win
|
||||
#define rtgui_event_win_deactivate rtgui_event_win
|
||||
#define rtgui_event_win_close rtgui_event_win
|
||||
#define rtgui_event_win_modal_enter rtgui_event_win
|
||||
|
||||
/* window event init */
|
||||
#define RTGUI_EVENT_WIN_CREATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CREATE)
|
||||
#define RTGUI_EVENT_WIN_DESTROY_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DESTROY)
|
||||
#define RTGUI_EVENT_WIN_SHOW_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_SHOW)
|
||||
#define RTGUI_EVENT_WIN_HIDE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_HIDE)
|
||||
#define RTGUI_EVENT_WIN_ACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_ACTIVATE)
|
||||
#define RTGUI_EVENT_WIN_DEACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DEACTIVATE)
|
||||
#define RTGUI_EVENT_WIN_CLOSE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CLOSE)
|
||||
#define RTGUI_EVENT_WIN_MOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MOVE)
|
||||
#define RTGUI_EVENT_WIN_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_RESIZE)
|
||||
|
||||
/*
|
||||
* RTGUI Workbench Manager Event
|
||||
*/
|
||||
struct rtgui_event_set_wm
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
/* the panel name to be managed */
|
||||
char panel_name[RTGUI_NAME_MAX];
|
||||
};
|
||||
/* window event init */
|
||||
#define RTGUI_EVENT_SET_WM_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SET_WM)
|
||||
#define RTGUI_EVENT_WIN_CREATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CREATE)
|
||||
#define RTGUI_EVENT_WIN_DESTROY_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DESTROY)
|
||||
#define RTGUI_EVENT_WIN_SHOW_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_SHOW)
|
||||
#define RTGUI_EVENT_WIN_HIDE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_HIDE)
|
||||
#define RTGUI_EVENT_WIN_ACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_ACTIVATE)
|
||||
#define RTGUI_EVENT_WIN_DEACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DEACTIVATE)
|
||||
#define RTGUI_EVENT_WIN_CLOSE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CLOSE)
|
||||
#define RTGUI_EVENT_WIN_MOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MOVE)
|
||||
#define RTGUI_EVENT_WIN_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_RESIZE)
|
||||
#define RTGUI_EVENT_WIN_MODAL_ENTER_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MODAL_ENTER)
|
||||
|
||||
/*
|
||||
* RTGUI Other Event
|
||||
|
@ -258,23 +172,16 @@ struct rtgui_event_update_end
|
|||
|
||||
struct rtgui_event_monitor
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
/* the monitor rect */
|
||||
rtgui_rect_t rect;
|
||||
|
||||
/* under panel */
|
||||
rtgui_panel_t* panel;
|
||||
|
||||
/* or under window */
|
||||
rtgui_win_t* wid;
|
||||
};
|
||||
|
||||
struct rtgui_event_paint
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
rtgui_win_t* wid; /* destination window */
|
||||
rtgui_rect_t rect; /* rect to be updated */
|
||||
};
|
||||
|
||||
|
@ -290,13 +197,10 @@ typedef struct rtgui_event_timer rtgui_event_timer_t;
|
|||
|
||||
struct rtgui_event_clip_info
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
/* destination window */
|
||||
rtgui_win_t* wid;
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
/* the number of rects */
|
||||
rt_uint32_t num_rect;
|
||||
//rt_uint32_t num_rect;
|
||||
|
||||
/* rtgui_rect_t *rects */
|
||||
};
|
||||
|
@ -315,9 +219,7 @@ struct rtgui_event_clip_info
|
|||
*/
|
||||
struct rtgui_event_mouse
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
rtgui_win_t* wid; /* destination window */
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
rt_uint16_t x, y;
|
||||
rt_uint16_t button;
|
||||
|
@ -333,9 +235,7 @@ struct rtgui_event_mouse
|
|||
|
||||
struct rtgui_event_kbd
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
|
||||
rtgui_win_t* wid; /* destination window */
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
rt_uint16_t type; /* key down or up */
|
||||
rt_uint16_t key; /* current key */
|
||||
|
@ -354,7 +254,7 @@ struct rtgui_event_kbd
|
|||
|
||||
struct rtgui_event_command
|
||||
{
|
||||
struct rtgui_event parent;
|
||||
_RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
/* command type */
|
||||
rt_int32_t type;
|
||||
|
@ -420,4 +320,33 @@ struct rtgui_event_resize
|
|||
};
|
||||
#define RTGUI_EVENT_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_RESIZE)
|
||||
|
||||
#undef _RTGUI_EVENT_WIN_ELEMENTS
|
||||
|
||||
union rtgui_event_generic
|
||||
{
|
||||
struct rtgui_event base;
|
||||
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_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;
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -21,17 +21,16 @@
|
|||
#define RT_INT16_MIN (-RT_INT16_MAX-1)
|
||||
#define RTGUI_NOT_FOUND (-1)
|
||||
|
||||
struct rtgui_panel;
|
||||
struct rtgui_event;
|
||||
|
||||
struct rtgui_object;
|
||||
struct rtgui_widget;
|
||||
struct rtgui_win;
|
||||
struct rtgui_font;
|
||||
|
||||
typedef struct rtgui_panel rtgui_panel_t;
|
||||
typedef struct rtgui_win rtgui_win_t;
|
||||
typedef struct rtgui_workbench rtgui_workbench_t;
|
||||
typedef rt_bool_t (*rtgui_event_handler_ptr)(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
typedef rt_bool_t (*rtgui_event_handler_ptr)(struct rtgui_object* widget, struct rtgui_event* event);
|
||||
typedef void (*rtgui_onbutton_func_t)(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
|
||||
struct rtgui_point
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* File : rtgui_application.h
|
||||
* This file is part of RTGUI in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2012-01-13 Grissiom first version
|
||||
*/
|
||||
#ifndef __RTGUI_APPLICATION_H__
|
||||
#define __RTGUI_APPLICATION_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/event.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
|
||||
DECLARE_CLASS_TYPE(application);
|
||||
|
||||
/** Gets the type of a application */
|
||||
#define RTGUI_APPLICATION_TYPE (RTGUI_TYPE(application))
|
||||
/** Casts the object to an rtgui_workbench */
|
||||
#define RTGUI_APPLICATION(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_APPLICATION_TYPE, struct rtgui_application))
|
||||
/** Checks if the object is an rtgui_workbench */
|
||||
#define RTGUI_IS_APPLICATION(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_APPLICATION_TYPE))
|
||||
|
||||
enum rtgui_application_flag
|
||||
{
|
||||
RTGUI_APPLICATION_FLAG_EXITED = 0x04,
|
||||
RTGUI_APPLICATION_FLAG_SHOWN = 0x08
|
||||
};
|
||||
|
||||
typedef void (*rtgui_idle_func)(struct rtgui_object* obj, struct rtgui_event *event);
|
||||
|
||||
struct rtgui_application
|
||||
{
|
||||
struct rtgui_object parent;
|
||||
|
||||
/* application name */
|
||||
unsigned char *name;
|
||||
|
||||
enum rtgui_application_flag state_flag;
|
||||
|
||||
rt_uint16_t ref_count;
|
||||
rt_uint16_t exit_code;
|
||||
|
||||
/* the thread id */
|
||||
rt_thread_t tid;
|
||||
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)];
|
||||
|
||||
/* if not RT_NULL, the application is modaled by modal_object. If is
|
||||
* RT_NULL, nothing modals. */
|
||||
struct rtgui_object *modal_object;
|
||||
|
||||
/* on idle event handler */
|
||||
rtgui_idle_func on_idle;
|
||||
};
|
||||
|
||||
/**
|
||||
* create an application named @myname on thread @param tid
|
||||
*/
|
||||
struct rtgui_application* rtgui_application_create(
|
||||
rt_thread_t tid,
|
||||
const char *myname);
|
||||
void rtgui_application_destroy(struct rtgui_application *app);
|
||||
rt_err_t rtgui_application_show(struct rtgui_application *app);
|
||||
rt_err_t rtgui_application_hide(struct rtgui_application *app);
|
||||
|
||||
rt_base_t rtgui_application_run(struct rtgui_application *app);
|
||||
void rtgui_application_exit(struct rtgui_application *app, rt_uint16_t code);
|
||||
|
||||
void rtgui_application_set_onidle(rtgui_idle_func onidle);
|
||||
rtgui_idle_func rtgui_application_get_onidle(void);
|
||||
struct rtgui_application* rtgui_application_self(void);
|
||||
|
||||
rt_thread_t rtgui_application_get_server(void);
|
||||
|
||||
void rtgui_application_set_root_object(struct rtgui_object* object);
|
||||
struct rtgui_object* rtgui_application_get_root_object(void);
|
||||
|
||||
struct rtgui_event;
|
||||
rt_err_t rtgui_application_send(rt_thread_t tid, struct rtgui_event* event, rt_size_t event_size);
|
||||
rt_err_t rtgui_application_send_urgent(rt_thread_t tid, struct rtgui_event* event, rt_size_t event_size);
|
||||
rt_err_t rtgui_application_send_sync(rt_thread_t tid, struct rtgui_event* event, rt_size_t event_size);
|
||||
rt_err_t rtgui_application_ack(struct rtgui_event* event, rt_int32_t status);
|
||||
rt_err_t rtgui_application_recv(struct rtgui_event* event, rt_size_t event_size);
|
||||
rt_err_t rtgui_application_recv_nosuspend(struct rtgui_event* event, rt_size_t event_size);
|
||||
rt_err_t rtgui_application_recv_filter(rt_uint32_t type, struct rtgui_event* event, rt_size_t event_size);
|
||||
|
||||
#endif /* end of include guard: RTGUI_APPLICATION_H */
|
|
@ -26,7 +26,7 @@
|
|||
/* support Chinese font */
|
||||
#define RTGUI_USING_FONTHZ
|
||||
/* support FreeType TTF font */
|
||||
// #define RTGUI_USING_TTF
|
||||
//#define RTGUI_USING_TTF
|
||||
/* use small size in RTGUI */
|
||||
#define RTGUI_USING_SMALL_SIZE
|
||||
/* use mouse cursor */
|
||||
|
@ -72,4 +72,10 @@
|
|||
#define RTGUI_APP_THREAD_STACK_SIZE 2048
|
||||
#endif
|
||||
|
||||
#define RTGUI_USING_CAST_CHECK
|
||||
|
||||
//#define RTGUI_USING_DESKTOP_WINDOW
|
||||
|
||||
#define RTGUI_EVENT_DEBUG
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtgui/rtgui.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -85,25 +86,47 @@ DECLARE_CLASS_TYPE(type);
|
|||
/** Gets the type of an object */
|
||||
#define RTGUI_OBJECT_TYPE RTGUI_TYPE(type)
|
||||
/** Casts the object to an rtgui_object_t */
|
||||
#define RTGUI_OBJECT(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_OBJECT_TYPE, 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 */
|
||||
#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
|
||||
};
|
||||
|
||||
/* rtgui base object */
|
||||
struct rtgui_object
|
||||
{
|
||||
/* object type */
|
||||
const rtgui_type_t* type;
|
||||
|
||||
rt_bool_t is_static;
|
||||
/* the event handler */
|
||||
rtgui_event_handler_ptr event_handler;
|
||||
|
||||
enum rtgui_object_flag flag;
|
||||
};
|
||||
rtgui_type_t *rtgui_object_type_get(void);
|
||||
|
||||
rtgui_object_t *rtgui_object_create(rtgui_type_t *object_type);
|
||||
void rtgui_object_destroy(rtgui_object_t *object);
|
||||
|
||||
void rtgui_object_name_set(rtgui_object_t *object, const char *name);
|
||||
const char *rtgui_object_name_get(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. */
|
||||
#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;
|
||||
|
||||
void rtgui_object_name_set(rtgui_object_t *object, const char *name);
|
||||
const char *rtgui_object_name_get(rtgui_object_t *object);
|
||||
|
||||
rtgui_object_t *rtgui_object_check_cast(rtgui_object_t *object, rtgui_type_t *type);
|
||||
rtgui_type_t *rtk_object_object_type_get(rtgui_object_t *object);
|
||||
|
|
|
@ -15,25 +15,32 @@
|
|||
#define __RTGUI_SERVER_H__
|
||||
|
||||
#include <rtgui/list.h>
|
||||
#include <rtgui/dlist.h>
|
||||
|
||||
/* RTGUI server definitions */
|
||||
|
||||
/* top window definitions in server */
|
||||
enum
|
||||
{
|
||||
WINTITLE_NO = 0x01,
|
||||
WINTITLE_BORDER = 0x02,
|
||||
WINTITLE_ACTIVATE = 0x04,
|
||||
WINTITLE_CLOSEBOX = 0x08,
|
||||
WINTITLE_MOVE = 0x0C,
|
||||
WINTITLE_CB_PRESSED = 0x10,
|
||||
WINTITLE_NOFOCUS = 0x20
|
||||
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
|
||||
};
|
||||
|
||||
#define WINTITLE_HEIGHT 20
|
||||
#define WINTITLE_CB_WIDTH 16
|
||||
#define WINTITLE_CB_HEIGHT 16
|
||||
#define WINTITLE_BORDER_SIZE 2
|
||||
#define WINTITLE_HEIGHT 20
|
||||
#define WINTITLE_CB_WIDTH 16
|
||||
#define WINTITLE_CB_HEIGHT 16
|
||||
#define WINTITLE_BORDER_SIZE 2
|
||||
|
||||
struct rtgui_topwin
|
||||
{
|
||||
|
@ -53,8 +60,12 @@ struct rtgui_topwin
|
|||
/* the extent information */
|
||||
rtgui_rect_t extent;
|
||||
|
||||
/* the top window list */
|
||||
rtgui_list_t list;
|
||||
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;
|
||||
|
||||
/* the monitor rect list */
|
||||
rtgui_list_t monitor_list;
|
||||
|
@ -67,13 +78,7 @@ void rtgui_server_init(void);
|
|||
|
||||
/* post an event to server */
|
||||
void rtgui_server_post_event(struct rtgui_event* event, rt_size_t size);
|
||||
|
||||
/* register or deregister panel in server */
|
||||
void rtgui_panel_register(char* name, rtgui_rect_t* extent);
|
||||
void rtgui_panel_deregister(char* name);
|
||||
|
||||
void rtgui_panel_set_default_focused(char* name);
|
||||
void rtgui_panel_set_nofocused(char* name);
|
||||
rt_err_t rtgui_server_post_event_sync(struct rtgui_event* event, rt_size_t size);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -21,32 +21,8 @@ struct rtgui_dc;
|
|||
struct rtgui_event;
|
||||
struct rtgui_widget;
|
||||
|
||||
#ifdef RTGUI_USING_SMALL_SIZE
|
||||
#define RTGUI_EVENT_BUFFER_SIZE 64
|
||||
#else
|
||||
#define RTGUI_EVENT_BUFFER_SIZE 256
|
||||
#endif
|
||||
|
||||
struct rtgui_thread
|
||||
{
|
||||
/* the thread id */
|
||||
rt_thread_t tid;
|
||||
|
||||
/* the message queue of thread */
|
||||
rt_mq_t mq;
|
||||
|
||||
/* the owner of thread */
|
||||
struct rtgui_widget* widget;
|
||||
/* event buffer */
|
||||
rt_uint8_t event_buffer[RTGUI_EVENT_BUFFER_SIZE];
|
||||
|
||||
/* on idle event handler */
|
||||
void (*on_idle)(struct rtgui_widget* widget, struct rtgui_event *event);
|
||||
};
|
||||
typedef struct rtgui_thread rtgui_thread_t;
|
||||
struct rtgui_timer;
|
||||
typedef void (*rtgui_timeout_func)(struct rtgui_timer* timer, void* parameter);
|
||||
typedef void (*rtgui_idle_func)(struct rtgui_widget* widget, struct rtgui_event *event);
|
||||
|
||||
struct rtgui_timer
|
||||
{
|
||||
|
@ -67,25 +43,6 @@ void rtgui_timer_destory(rtgui_timer_t* timer);
|
|||
void rtgui_timer_start(rtgui_timer_t* timer);
|
||||
void rtgui_timer_stop (rtgui_timer_t* timer);
|
||||
|
||||
rtgui_thread_t* rtgui_thread_register(rt_thread_t tid, rt_mq_t mq);
|
||||
void rtgui_thread_deregister(rt_thread_t tid);
|
||||
void rtgui_thread_set_onidle(rtgui_idle_func onidle);
|
||||
rtgui_idle_func rtgui_thread_get_onidle(void);
|
||||
rtgui_thread_t* rtgui_thread_self(void);
|
||||
|
||||
rt_thread_t rtgui_thread_get_server(void);
|
||||
|
||||
void rtgui_thread_set_widget(struct rtgui_widget* widget);
|
||||
struct rtgui_widget* rtgui_thread_get_widget(void);
|
||||
|
||||
rt_err_t rtgui_thread_send(rt_thread_t tid, struct rtgui_event* event, rt_size_t event_size);
|
||||
rt_err_t rtgui_thread_send_urgent(rt_thread_t tid, struct rtgui_event* event, rt_size_t event_size);
|
||||
rt_err_t rtgui_thread_send_sync(rt_thread_t tid, struct rtgui_event* event, rt_size_t event_size);
|
||||
rt_err_t rtgui_thread_recv(struct rtgui_event* event, rt_size_t event_size);
|
||||
rt_err_t rtgui_thread_recv_nosuspend(struct rtgui_event* event, rt_size_t event_size);
|
||||
rt_err_t rtgui_thread_recv_filter(rt_uint32_t type, struct rtgui_event* event, rt_size_t event_size);
|
||||
rt_err_t rtgui_thread_ack(struct rtgui_event* event, rt_int32_t status);
|
||||
|
||||
/* rtgui system initialization function */
|
||||
void rtgui_system_server_init(void);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/image.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/widgets/container.h>
|
||||
|
||||
DECLARE_CLASS_TYPE(aboutview);
|
||||
/** Gets the type of a about view */
|
||||
|
@ -30,7 +30,7 @@ DECLARE_CLASS_TYPE(aboutview);
|
|||
|
||||
struct rtgui_about_view
|
||||
{
|
||||
struct rtgui_view parent;
|
||||
struct rtgui_container parent;
|
||||
|
||||
/* widget private data */
|
||||
rtgui_image_t* logo;
|
||||
|
@ -38,9 +38,7 @@ struct rtgui_about_view
|
|||
};
|
||||
typedef struct rtgui_about_view rtgui_about_view_t;
|
||||
|
||||
rtgui_type_t *rtgui_about_view_type_get(void);
|
||||
|
||||
rtgui_about_view_t* rtgui_about_view_create(rtgui_image_t *logo, const char* description);
|
||||
rt_bool_t rtgui_about_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
rt_bool_t rtgui_about_view_event_handler(struct rtgui_object* widget, struct rtgui_event* event);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -70,7 +70,7 @@ 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);
|
||||
|
||||
rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
rt_bool_t rtgui_button_event_handler(struct rtgui_object* object, struct rtgui_event* event);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ DECLARE_CLASS_TYPE(checkbox);
|
|||
/** Gets the type of a checkbox */
|
||||
#define RTGUI_CHECKBOX_TYPE (RTGUI_TYPE(checkbox))
|
||||
/** Casts the object to an rtgui_button */
|
||||
#define RTGUI_CHECKBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_CHECKBOX_TYPE, rtgui_checkbox))
|
||||
#define RTGUI_CHECKBOX(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_CHECKBOX_TYPE, struct rtgui_checkbox))
|
||||
/** Checks if the object is an rtgui_button */
|
||||
#define RTGUI_IS_CHECKBOX(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_CHECKBOX_TYPE))
|
||||
|
||||
|
@ -38,6 +38,6 @@ 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);
|
||||
|
||||
rt_bool_t rtgui_checkbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
rt_bool_t rtgui_checkbox_event_handler(struct rtgui_object* object, struct rtgui_event* event);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -34,16 +34,16 @@ struct rtgui_combobox
|
|||
rt_uint16_t current_item;
|
||||
|
||||
/* call back */
|
||||
void (*on_selected) (struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
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);
|
||||
|
||||
rt_bool_t rtgui_combobox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
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_onitem_func_t func);
|
||||
void rtgui_combobox_set_onselected(struct rtgui_combobox* box, rtgui_event_handler_ptr func);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,32 +16,53 @@
|
|||
|
||||
#include <rtgui/widgets/widget.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DECLARE_CLASS_TYPE(container);
|
||||
/** Gets the type of a container */
|
||||
#define RTGUI_CONTAINER_TYPE (RTGUI_TYPE(container))
|
||||
/** Casts the object to a 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 a 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
|
||||
{
|
||||
/* inherit from widget */
|
||||
struct rtgui_widget parent;
|
||||
|
||||
struct rtgui_widget* focused;
|
||||
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);
|
||||
|
||||
rt_bool_t rtgui_container_event_handler(struct rtgui_object* widget, struct rtgui_event* event);
|
||||
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
struct rtgui_box;
|
||||
void rtgui_container_set_box(struct rtgui_container* container, struct rtgui_box* box);
|
||||
#endif
|
||||
|
||||
void rtgui_container_hide(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(rtgui_widget_t* 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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __RTGUI_FILELIST_VIEW_H__
|
||||
#define __RTGUI_FILELIST_VIEW_H__
|
||||
|
||||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/widgets/container.h>
|
||||
|
||||
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
|
||||
#define RTGUI_FITEM_FILE 0x0
|
||||
|
@ -24,7 +24,7 @@ DECLARE_CLASS_TYPE(filelist);
|
|||
|
||||
struct rtgui_filelist_view
|
||||
{
|
||||
struct rtgui_view parent;
|
||||
struct rtgui_container parent;
|
||||
|
||||
/* widget private data */
|
||||
|
||||
|
@ -44,8 +44,9 @@ struct rtgui_filelist_view
|
|||
};
|
||||
typedef struct rtgui_filelist_view rtgui_filelist_view_t;
|
||||
|
||||
rtgui_filelist_view_t* rtgui_filelist_view_create(rtgui_workbench_t* workbench,
|
||||
const char* directory, const char* pattern, const rtgui_rect_t* rect);
|
||||
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_widget* widget, struct rtgui_event* event);
|
||||
|
|
|
@ -48,7 +48,7 @@ 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);
|
||||
|
||||
rt_bool_t rtgui_iconbox_event_handler(struct rtgui_widget* widget, 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);
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ typedef struct rtgui_label rtgui_label_t;
|
|||
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_widget* widget, 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);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <rtgui/image.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
|
||||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/widgets/container.h>
|
||||
|
||||
typedef void (*item_action)(struct rtgui_widget* widget, void* parameter);
|
||||
struct rtgui_list_item
|
||||
|
@ -45,7 +45,7 @@ DECLARE_CLASS_TYPE(listview);
|
|||
|
||||
struct rtgui_list_view
|
||||
{
|
||||
struct rtgui_view parent;
|
||||
struct rtgui_container parent;
|
||||
|
||||
/* widget private data */
|
||||
/* list item */
|
||||
|
@ -59,20 +59,18 @@ struct rtgui_list_view
|
|||
/* the number of item in a page */
|
||||
rt_uint16_t page_items;
|
||||
/* current item */
|
||||
rt_int16_t current_item;
|
||||
rt_uint16_t current_item;
|
||||
|
||||
/* icon layout */
|
||||
rt_uint8_t row_items, col_items;
|
||||
};
|
||||
typedef struct rtgui_list_view rtgui_list_view_t;
|
||||
|
||||
rtgui_type_t *rtgui_list_view_type_get(void);
|
||||
|
||||
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_widget* widget, struct rtgui_event* event);
|
||||
rt_bool_t rtgui_list_view_event_handler(struct rtgui_object* widget, struct rtgui_event* event);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ struct rtgui_listbox
|
|||
const struct rtgui_listbox_item* items;
|
||||
|
||||
/* item event handler */
|
||||
void (*on_item)(rtgui_widget_t *widgets, struct rtgui_event* event);
|
||||
rtgui_event_handler_ptr on_item;
|
||||
|
||||
/* total number of items */
|
||||
rt_uint16_t items_count;
|
||||
|
@ -53,14 +53,13 @@ struct rtgui_listbox
|
|||
rt_int16_t current_item;
|
||||
};
|
||||
typedef struct rtgui_listbox rtgui_listbox_t;
|
||||
typedef void (*rtgui_onitem_func_t)(struct rtgui_widget* widget, rtgui_event_t *event);
|
||||
|
||||
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_widget* widget, struct rtgui_event* event);
|
||||
void rtgui_listbox_set_onitem(rtgui_listbox_t* box, rtgui_onitem_func_t func);
|
||||
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);
|
||||
|
||||
|
|
|
@ -44,22 +44,19 @@ struct rtgui_listctrl
|
|||
rt_int16_t current_item;
|
||||
|
||||
/* item event handler */
|
||||
void (*on_item)(rtgui_widget_t *widget, struct rtgui_event* event);
|
||||
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_func_t)(struct rtgui_widget* widget, rtgui_event_t *event);
|
||||
typedef void (*rtgui_onitem_draw_t)(struct rtgui_listctrl *list, struct rtgui_dc* dc, rtgui_rect_t* rect, rt_uint16_t index);
|
||||
|
||||
rtgui_type_t *rtgui_listctrl_type_get(void);
|
||||
|
||||
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);
|
||||
|
||||
rt_bool_t rtgui_listctrl_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
void rtgui_listctrl_set_onitem(rtgui_listctrl_t* ctrl, rtgui_onitem_func_t func);
|
||||
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);
|
||||
|
||||
|
|
|
@ -59,13 +59,11 @@ struct rtgui_menu
|
|||
struct rtgui_listctrl *items_list;
|
||||
|
||||
/* pop event handle */
|
||||
rt_bool_t (*on_menupop)(rtgui_widget_t* widget, rtgui_event_t* event);
|
||||
rt_bool_t (*on_menuhide)(rtgui_widget_t* widget, rtgui_event_t* event);
|
||||
rtgui_event_handler_ptr on_menupop;
|
||||
rtgui_event_handler_ptr on_menuhide;
|
||||
};
|
||||
typedef struct rtgui_menu rtgui_menu_t;
|
||||
|
||||
rtgui_type_t *rtgui_menu_type_get(void);
|
||||
|
||||
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);
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
#define __RTGUI_NOTEBOOK_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/widgets/container.h>
|
||||
#include <rtgui/widgets/widget.h>
|
||||
|
||||
DECLARE_CLASS_TYPE(notebook);
|
||||
/** Gets the type of a notebook */
|
||||
#define RTGUI_NOTEBOOK_TYPE (RTGUI_TYPE(notebook))
|
||||
/** Casts the object to a notebook control */
|
||||
#define RTGUI_NOTEBOOK(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_NOTEBOOK_TYPE, rtgui_notebook_t))
|
||||
#define RTGUI_NOTEBOOK(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_NOTEBOOK_TYPE, struct rtgui_notebook))
|
||||
/** Checks if the object is a notebook control */
|
||||
#define RTGUI_IS_NOTEBOOK(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_NOTEBOOK_TYPE))
|
||||
|
||||
|
@ -16,38 +16,34 @@ DECLARE_CLASS_TYPE(notebook);
|
|||
#define RTGUI_NOTEBOOK_BOTTOM 0x01
|
||||
#define RTGUI_NOTEBOOK_NOTAB 0x02
|
||||
|
||||
struct rtgui_notebook_tab
|
||||
{
|
||||
char* title;
|
||||
struct rtgui_widget* widget;
|
||||
};
|
||||
typedef struct rtgui_notebook_tab rtgui_notebook_tab_t;
|
||||
struct rtgui_notebook_tab;
|
||||
|
||||
struct rtgui_notebook
|
||||
{
|
||||
struct rtgui_container parent;
|
||||
struct rtgui_widget parent;
|
||||
|
||||
rt_uint8_t flag;
|
||||
|
||||
/* widget private data */
|
||||
rtgui_notebook_tab_t* childs;
|
||||
struct rtgui_notebook_tab *childs;
|
||||
rt_uint16_t count;
|
||||
rt_int16_t current;
|
||||
};
|
||||
typedef struct rtgui_notebook rtgui_notebook_t;
|
||||
|
||||
rtgui_type_t *rtgui_notebook_type_get(void);
|
||||
struct rtgui_notebook* rtgui_notebook_create(const rtgui_rect_t* rect, rt_uint8_t style);
|
||||
void rtgui_notebook_destroy(struct rtgui_notebook* notebook);
|
||||
|
||||
rtgui_notebook_t* rtgui_notebook_create(const rtgui_rect_t* rect, rt_uint8_t style);
|
||||
void rtgui_notebook_destroy(rtgui_notebook_t* notebook);
|
||||
void rtgui_notebook_add(struct rtgui_notebook* notebook, const char* label, struct rtgui_widget* child);
|
||||
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_add(rtgui_notebook_t* notebook, const char* label, rtgui_widget_t* child);
|
||||
int rtgui_notebook_get_count(rtgui_notebook_t* notebook);
|
||||
rtgui_widget_t* rtgui_notebook_get_current(rtgui_notebook_t* notebook);
|
||||
void rtgui_notebook_set_current(rtgui_notebook_t* notebook, rtgui_widget_t* widget);
|
||||
void rtgui_notebook_set_current_by_index(rtgui_notebook_t* notebook, rt_uint16_t index);
|
||||
rtgui_widget_t* rtgui_notebook_get_index(rtgui_notebook_t* notebook, rt_uint16_t index);
|
||||
int rtgui_notebook_get_count(struct rtgui_notebook* notebook);
|
||||
|
||||
rt_bool_t rtgui_notebook_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
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);
|
||||
|
||||
rt_bool_t rtgui_notebook_event_handler(struct rtgui_object* widget, struct rtgui_event* event);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,7 +29,7 @@ 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);
|
||||
|
||||
rt_bool_t rtgui_progressbar_event_handler(struct rtgui_widget* widget,
|
||||
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);
|
||||
|
|
|
@ -37,7 +37,7 @@ 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);
|
||||
|
||||
rt_bool_t rtgui_radiobox_event_handler(struct rtgui_widget* widget, 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);
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ struct rtgui_scrollbar
|
|||
/* position 1:1 width of scrollbar */
|
||||
rt_int16_t min_position, max_position;
|
||||
|
||||
rt_bool_t (*on_scroll) (struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
rtgui_event_handler_ptr on_scroll;
|
||||
};
|
||||
typedef struct rtgui_scrollbar rtgui_scrollbar_t;
|
||||
|
||||
|
@ -80,7 +80,7 @@ void rtgui_scrollbar_set_orientation(struct rtgui_scrollbar* bar, int orientatio
|
|||
void rtgui_scrollbar_set_page_step(struct rtgui_scrollbar* bar, int step);
|
||||
void rtgui_scrollbar_set_line_step(struct rtgui_scrollbar* bar, int step);
|
||||
|
||||
rt_bool_t rtgui_scrollbar_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
rt_bool_t rtgui_scrollbar_event_handler(struct rtgui_object* object, struct rtgui_event* event);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ 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);
|
||||
|
||||
rt_bool_t rtgui_slider_event_handler(struct rtgui_widget* widget, 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);
|
||||
|
|
|
@ -28,7 +28,7 @@ typedef struct rtgui_staticline rtgui_staticline_t;
|
|||
rtgui_staticline_t *rtgui_staticline_create(int orientation);
|
||||
void rtgui_staticline_destroy(rtgui_staticline_t* staticline);
|
||||
|
||||
rt_bool_t rtgui_staticline_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
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
|
||||
|
|
|
@ -65,7 +65,7 @@ typedef struct rtgui_textbox rtgui_textbox_t;
|
|||
struct rtgui_textbox* rtgui_textbox_create(const char* text, rt_uint8_t flag);
|
||||
void rtgui_textbox_destroy(struct rtgui_textbox* box);
|
||||
|
||||
rt_bool_t rtgui_textbox_event_handler(struct rtgui_widget* widget, 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);
|
||||
|
|
|
@ -55,7 +55,7 @@ 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);
|
||||
|
||||
rt_bool_t rtgui_textview_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
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);
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -24,12 +24,9 @@ DECLARE_CLASS_TYPE(toplevel);
|
|||
/** Checks if the object is an rtgui_toplevel */
|
||||
#define RTGUI_IS_TOPLEVEL(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_TOPLEVEL_TYPE))
|
||||
|
||||
/* last mouse event handled widget */
|
||||
#define RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(obj) (RTGUI_TOPLEVEL(obj)->last_mevent_widget)
|
||||
|
||||
struct rtgui_toplevel
|
||||
{
|
||||
/* inherit from container */
|
||||
/* inherit from view */
|
||||
rtgui_container_t parent;
|
||||
|
||||
/* drawing count */
|
||||
|
@ -38,16 +35,10 @@ struct rtgui_toplevel
|
|||
/* external clip info */
|
||||
rtgui_rect_t* external_clip_rect;
|
||||
rt_uint32_t external_clip_size;
|
||||
|
||||
/* server thread id */
|
||||
rt_thread_t server;
|
||||
|
||||
/* last mouse event handled widget */
|
||||
rtgui_widget_t* last_mevent_widget;
|
||||
};
|
||||
typedef struct rtgui_toplevel rtgui_toplevel_t;
|
||||
|
||||
rt_bool_t rtgui_toplevel_event_handler(rtgui_widget_t* widget, rtgui_event_t* event);
|
||||
rt_bool_t rtgui_toplevel_event_handler(struct rtgui_object* widget, struct rtgui_event* event);
|
||||
void rtgui_toplevel_update_clip(rtgui_toplevel_t* top);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* File : view.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_VIEW_H__
|
||||
#define __RTGUI_VIEW_H__
|
||||
|
||||
#include <rtgui/widgets/box.h>
|
||||
#include <rtgui/widgets/container.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DECLARE_CLASS_TYPE(view);
|
||||
/** Gets the type of a view */
|
||||
#define RTGUI_VIEW_TYPE (RTGUI_TYPE(view))
|
||||
/** Casts the object to an rtgui_view */
|
||||
#define RTGUI_VIEW(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_VIEW_TYPE, rtgui_view_t))
|
||||
/** Checks if the object is an rtgui_view */
|
||||
#define RTGUI_IS_VIEW(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_VIEW_TYPE))
|
||||
|
||||
/*
|
||||
* the view widget
|
||||
*/
|
||||
struct rtgui_view
|
||||
{
|
||||
/* inherit from container */
|
||||
struct rtgui_container parent;
|
||||
|
||||
/* private field */
|
||||
char* title;
|
||||
rt_bool_t modal_show;
|
||||
};
|
||||
typedef struct rtgui_view rtgui_view_t;
|
||||
|
||||
rtgui_view_t* rtgui_view_create(const char* title);
|
||||
void rtgui_view_destroy(rtgui_view_t* view);
|
||||
|
||||
rt_bool_t rtgui_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
void rtgui_view_set_box(rtgui_view_t* view, rtgui_box_t* box);
|
||||
#endif
|
||||
|
||||
rtgui_modal_code_t rtgui_view_show(rtgui_view_t* view, rt_bool_t is_modal);
|
||||
void rtgui_view_hide(rtgui_view_t* view);
|
||||
void rtgui_view_end_modal(rtgui_view_t* view, rtgui_modal_code_t modal_code);
|
||||
|
||||
char* rtgui_view_get_title(rtgui_view_t* view);
|
||||
void rtgui_view_set_title(rtgui_view_t* view, const char* title);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -76,8 +76,10 @@ struct rtgui_widget
|
|||
/* inherit from rtgui_object */
|
||||
struct rtgui_object object;
|
||||
|
||||
/* the parent and root widget */
|
||||
struct rtgui_widget *parent, *toplevel;
|
||||
/* 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;
|
||||
|
||||
|
@ -106,18 +108,25 @@ struct rtgui_widget
|
|||
/* the rect clip */
|
||||
rtgui_region_t clip;
|
||||
|
||||
/* the event handler */
|
||||
rt_bool_t (*event_handler) (struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
|
||||
/* call back */
|
||||
rt_bool_t (*on_focus_in) (struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
rt_bool_t (*on_focus_out) (struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
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);
|
||||
/* will be called just before the widget is shown. You can setup your
|
||||
* widget in this call back. It's return value is ignored. The @param event
|
||||
* will always be RT_NULL
|
||||
*/
|
||||
rt_bool_t (*on_show) (struct rtgui_object* widget, struct rtgui_event* event);
|
||||
/* will be called just before the widget is hiden. You can setup your
|
||||
* widget in this call back. It's return value is ignored. The @param event
|
||||
* will always be RT_NULL
|
||||
*/
|
||||
rt_bool_t (*on_hide) (struct rtgui_object* widget, struct rtgui_event* event);
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
rt_bool_t (*on_draw) (struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
rt_bool_t (*on_mouseclick) (struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
rt_bool_t (*on_key) (struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
rt_bool_t (*on_size) (struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
rt_bool_t (*on_command) (struct rtgui_widget* 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 */
|
||||
|
@ -125,14 +134,10 @@ struct rtgui_widget
|
|||
};
|
||||
typedef struct rtgui_widget rtgui_widget_t;
|
||||
|
||||
rtgui_type_t *rtgui_widget_type_get(void);
|
||||
rtgui_widget_t *rtgui_widget_create(rtgui_type_t *widget_type);
|
||||
void rtgui_widget_destroy(rtgui_widget_t* widget);
|
||||
|
||||
/* set the event handler of widget */
|
||||
void rtgui_widget_set_event_handler(rtgui_widget_t* widget, rtgui_event_handler_ptr handler);
|
||||
/* widget default event handler */
|
||||
rt_bool_t rtgui_widget_event_handler(rtgui_widget_t* widget, 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);
|
||||
|
@ -141,6 +146,8 @@ 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);
|
||||
void rtgui_widget_set_onshow(rtgui_widget_t* widget, rtgui_event_handler_ptr handler);
|
||||
void rtgui_widget_set_onhide(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);
|
||||
|
@ -179,7 +186,7 @@ void rtgui_widget_move_to_logic(rtgui_widget_t* widget, int dx, int dy);
|
|||
void rtgui_widget_update_clip(rtgui_widget_t* widget);
|
||||
|
||||
/* get the toplevel widget of widget */
|
||||
rtgui_widget_t* rtgui_widget_get_toplevel(rtgui_widget_t* widget);
|
||||
struct rtgui_win* rtgui_widget_get_toplevel(rtgui_widget_t* widget);
|
||||
|
||||
void rtgui_widget_show(rtgui_widget_t* widget);
|
||||
void rtgui_widget_hide(rtgui_widget_t* widget);
|
||||
|
|
|
@ -29,21 +29,47 @@ 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_MODAL 0x001 /* modal mode window */
|
||||
#define RTGUI_WIN_STYLE_CLOSED 0x002 /* window is closed */
|
||||
#define RTGUI_WIN_STYLE_ACTIVATE 0x004 /* window is activated */
|
||||
#define RTGUI_WIN_STYLE_NO_FOCUS 0x008 /* non-focused window */
|
||||
#define RTGUI_WIN_STYLE_NO_FOCUS 0x001 /* non-focused window */
|
||||
|
||||
#define RTGUI_WIN_STYLE_NO_TITLE 0x010 /* no title window */
|
||||
#define RTGUI_WIN_STYLE_NO_BORDER 0x020 /* no border window */
|
||||
#define RTGUI_WIN_STYLE_CLOSEBOX 0x040 /* window has the close button */
|
||||
#define RTGUI_WIN_STYLE_MINIBOX 0x080 /* window has the mini button */
|
||||
#define RTGUI_WIN_STYLE_NO_TITLE 0x002 /* no title window */
|
||||
#define RTGUI_WIN_STYLE_NO_BORDER 0x004 /* no border window */
|
||||
#define RTGUI_WIN_STYLE_CLOSEBOX 0x008 /* window has the close button */
|
||||
#define RTGUI_WIN_STYLE_MINIBOX 0x010 /* window has the mini button */
|
||||
|
||||
#define RTGUI_WIN_STYLE_UNDER_MODAL 0x100 /* window is under modal show (show
|
||||
* sub-win as modal window) */
|
||||
#define RTGUI_WIN_STYLE_DESTROY_ON_CLOSE 0x020 /* window is destroyed when closed */
|
||||
#ifdef RTGUI_USING_DESKTOP_WINDOW
|
||||
/* A desktop window is a full screen window which will beneath all other windows.
|
||||
* There will be only one desktop window in a system. And this window should be
|
||||
* created _before_ any other windows.
|
||||
*/
|
||||
#define RTGUI_WIN_STYLE_DESKTOP 0x8000
|
||||
#define RTGUI_WIN_STYLE_DESKTOP_DEFAULT RTGUI_WIN_STYLE_DESKTOP |\
|
||||
RTGUI_WIN_STYLE_NO_BORDER |\
|
||||
RTGUI_WIN_STYLE_NO_TITLE
|
||||
#endif
|
||||
|
||||
#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
|
||||
};
|
||||
|
||||
struct rtgui_win_title;
|
||||
struct rtgui_win_area;
|
||||
|
||||
|
@ -52,33 +78,59 @@ struct rtgui_win
|
|||
/* inherit from toplevel */
|
||||
struct rtgui_toplevel parent;
|
||||
|
||||
/* parent toplevel */
|
||||
rtgui_toplevel_t* parent_toplevel;
|
||||
/* parent window. RT_NULL if the window is a top level window */
|
||||
struct rtgui_win *parent_window;
|
||||
|
||||
/* the widget that will grab the focus in current window */
|
||||
struct rtgui_widget *focused_widget;
|
||||
|
||||
/* top window style */
|
||||
rt_uint16_t style;
|
||||
|
||||
/* window state flag */
|
||||
enum rtgui_win_flag flag;
|
||||
|
||||
rtgui_modal_code_t modal_code;
|
||||
rtgui_widget_t* modal_widget;
|
||||
|
||||
/* last mouse event handled widget */
|
||||
rtgui_widget_t* last_mevent_widget;
|
||||
|
||||
/* window title */
|
||||
char* title;
|
||||
|
||||
/* call back */
|
||||
rt_bool_t (*on_activate) (struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
rt_bool_t (*on_deactivate) (struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
rt_bool_t (*on_close) (struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
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(rtgui_toplevel_t* parent_toplevel, const char* title,
|
||||
rtgui_rect_t *rect, rt_uint8_t flag);
|
||||
rtgui_win_t* rtgui_win_create(struct rtgui_win *parent_window, const char* title,
|
||||
rtgui_rect_t *rect, rt_uint16_t style);
|
||||
void rtgui_win_destroy(rtgui_win_t* win);
|
||||
void rtgui_win_close(struct rtgui_win* win);
|
||||
|
||||
rtgui_modal_code_t rtgui_win_show(rtgui_win_t* win, rt_bool_t is_modal);
|
||||
/** Close window.
|
||||
*
|
||||
* @param win the window you want to close
|
||||
*
|
||||
* @return RT_TRUE if the window is closed. RT_FALSE if not. If the onclose
|
||||
* callback returns RT_FALSE, the window won't be closed.
|
||||
*
|
||||
* \sa rtgui_win_set_onclose .
|
||||
*/
|
||||
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);
|
||||
|
||||
|
@ -96,8 +148,9 @@ void rtgui_win_set_box(rtgui_win_t* win, rtgui_box_t* box);
|
|||
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(rtgui_widget_t* 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);
|
||||
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* File : workbench.h
|
||||
* This file is part of RTGUI in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-04 Bernard first version
|
||||
*/
|
||||
#ifndef __RTGUI_WORKBENCH_H__
|
||||
#define __RTGUI_WORKBENCH_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/list.h>
|
||||
#include <rtgui/region.h>
|
||||
#include <rtgui/dc.h>
|
||||
|
||||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/widgets/toplevel.h>
|
||||
|
||||
#define RTGUI_WORKBENCH_FLAG_VISIBLE 0x00 /* workbench is visible */
|
||||
#define RTGUI_WORKBENCH_FLAG_INVISIBLE 0x01 /* workbench is invisible */
|
||||
#define RTGUI_WORKBENCH_FLAG_FULLSCREEN 0x02 /* workbench is full screen */
|
||||
#define RTGUI_WORKBENCH_FLAG_MODAL_MODE 0x04 /* workbench is modal mode showing */
|
||||
|
||||
#define RTGUI_WORKBENCH_FLAG_CLOSEBLE 0x00
|
||||
#define RTGUI_WORKBENCH_FLAG_UNCLOSEBLE 0x10
|
||||
#define RTGUI_WORKBENCH_FLAG_CLOSED 0x20
|
||||
|
||||
#define RTGUI_WORKBENCH_FLAG_DEFAULT RTGUI_WORKBENCH_FLAG_VISIBLE | RTGUI_WORKBENCH_FLAG_CLOSEBLE
|
||||
|
||||
#define RTGUI_WORKBENCH_IS_MODAL_MODE(w) ((w)->flag & RTGUI_WORKBENCH_FLAG_MODAL_MODE)
|
||||
|
||||
DECLARE_CLASS_TYPE(workbench);
|
||||
|
||||
/** Gets the type of a workbench */
|
||||
#define RTGUI_WORKBENCH_TYPE (RTGUI_TYPE(workbench))
|
||||
/** Casts the object to an rtgui_workbench */
|
||||
#define RTGUI_WORKBENCH(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_WORKBENCH_TYPE, rtgui_workbench_t))
|
||||
/** Checks if the object is an rtgui_workbench */
|
||||
#define RTGUI_IS_WORKBENCH(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_WORKBENCH_TYPE))
|
||||
|
||||
struct rtgui_workbench
|
||||
{
|
||||
/* inherit from toplevel */
|
||||
struct rtgui_toplevel parent;
|
||||
|
||||
/* panel id */
|
||||
rtgui_panel_t* panel;
|
||||
|
||||
/* workbench flag */
|
||||
rt_uint8_t flag;
|
||||
rtgui_modal_code_t modal_code;
|
||||
rtgui_widget_t *modal_widget;
|
||||
|
||||
/* workbench title */
|
||||
unsigned char* title;
|
||||
rtgui_view_t* current_view;
|
||||
};
|
||||
|
||||
rtgui_type_t* rtgui_workbench_type_get(void);
|
||||
|
||||
rtgui_workbench_t *rtgui_workbench_create(const char* panel_name, const unsigned char* title);
|
||||
void rtgui_workbench_destroy(rtgui_workbench_t* workbench);
|
||||
void rtgui_workbench_close(rtgui_workbench_t* workbench);
|
||||
|
||||
rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* event);
|
||||
|
||||
void rtgui_workbench_set_flag(rtgui_workbench_t* workbench, rt_uint8_t flag);
|
||||
|
||||
rt_bool_t rtgui_workbench_event_loop(rtgui_workbench_t* workbench);
|
||||
|
||||
rt_err_t rtgui_workbench_show (rtgui_workbench_t* workbench);
|
||||
rt_err_t rtgui_workbench_hide (rtgui_workbench_t* workbench);
|
||||
|
||||
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_show_view(rtgui_workbench_t* workbench, rtgui_view_t* view);
|
||||
void rtgui_workbench_hide_view(rtgui_workbench_t* workbench, rtgui_view_t* view);
|
||||
|
||||
rtgui_view_t *rtgui_workbench_get_current_view(rtgui_workbench_t * workbench);
|
||||
|
||||
#endif
|
|
@ -432,7 +432,7 @@ static void rtgui_winrect_show()
|
|||
rt_uint16_t x, y;
|
||||
rtgui_color_t c;
|
||||
rtgui_rect_t screen_rect, win_rect, win_rect_inner;
|
||||
void (*set_pixel) (rtgui_color_t *c, rt_base_t x, rt_base_t y);
|
||||
void (*set_pixel) (rtgui_color_t *c, int x, int y);
|
||||
|
||||
c = black;
|
||||
set_pixel = rtgui_graphic_driver_get_default()->ops->set_pixel;
|
||||
|
|
|
@ -1,315 +0,0 @@
|
|||
/*
|
||||
* File : panel.c
|
||||
* This file is part of RTGUI in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-04 Bernard first version
|
||||
*/
|
||||
|
||||
#include "panel.h"
|
||||
#include "mouse.h"
|
||||
|
||||
#include <rtgui/rtgui_system.h>
|
||||
|
||||
/* the global parameter */
|
||||
struct rtgui_list_node _rtgui_panel_list = {RT_NULL};
|
||||
|
||||
void rtgui_panel_register(char* name, rtgui_rect_t* extent)
|
||||
{
|
||||
register rt_base_t temp;
|
||||
struct rtgui_panel* panel;
|
||||
|
||||
panel = rtgui_panel_find(name);
|
||||
if (panel != RT_NULL )
|
||||
{
|
||||
/* there are already a same named panel exist. */
|
||||
return;
|
||||
}
|
||||
|
||||
panel = rtgui_malloc(sizeof(struct rtgui_panel));
|
||||
if (panel == RT_NULL)
|
||||
{
|
||||
/* can't alloc memory */
|
||||
return;
|
||||
}
|
||||
|
||||
/* copy name */
|
||||
for (temp = 0; temp < RTGUI_NAME_MAX; temp ++)
|
||||
{
|
||||
panel->name[temp] = name[temp];
|
||||
}
|
||||
|
||||
/* copy extent */
|
||||
panel->extent = *extent;
|
||||
|
||||
panel->wm_thread = RT_NULL;
|
||||
panel->is_focusable = RT_TRUE;
|
||||
|
||||
/* init list */
|
||||
rtgui_list_init(&(panel->sibling));
|
||||
rtgui_list_init(&(panel->thread_list));
|
||||
|
||||
/* add panel to panel list */
|
||||
rtgui_list_insert(&_rtgui_panel_list, &(panel->sibling));
|
||||
}
|
||||
|
||||
void rtgui_panel_deregister(char* name)
|
||||
{
|
||||
struct rtgui_panel* panel;
|
||||
|
||||
panel = rtgui_panel_find(name);
|
||||
if (panel != RT_NULL)
|
||||
{
|
||||
rtgui_list_remove(&_rtgui_panel_list, &(panel->sibling));
|
||||
|
||||
/* free pane node */
|
||||
rtgui_free(panel);
|
||||
}
|
||||
}
|
||||
|
||||
/* set default focused panel, please use it after registered panel */
|
||||
void rtgui_panel_set_default_focused(char* name)
|
||||
{
|
||||
extern struct rtgui_panel* rtgui_server_focus_panel;
|
||||
struct rtgui_panel* panel;
|
||||
|
||||
panel = rtgui_panel_find(name);
|
||||
if (panel != RT_NULL)
|
||||
{
|
||||
rtgui_server_focus_panel = panel;
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_panel_set_nofocused(char* name)
|
||||
{
|
||||
extern struct rtgui_panel* rtgui_server_focus_panel;
|
||||
struct rtgui_panel* panel;
|
||||
|
||||
panel = rtgui_panel_find(name);
|
||||
if (panel != RT_NULL)
|
||||
{
|
||||
panel->is_focusable = RT_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
struct rtgui_panel* rtgui_panel_find(char* name)
|
||||
{
|
||||
struct rtgui_list_node* node;
|
||||
struct rtgui_panel* panel;
|
||||
|
||||
rtgui_list_foreach(node, &_rtgui_panel_list)
|
||||
{
|
||||
panel = rtgui_list_entry(node, struct rtgui_panel, sibling);
|
||||
|
||||
if (rt_strncmp(panel->name, name, RTGUI_NAME_MAX) == 0)
|
||||
{
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
struct rtgui_panel* rtgui_panel_thread_add(char* name, rt_thread_t tid)
|
||||
{
|
||||
struct rtgui_panel* panel;
|
||||
|
||||
panel = rtgui_panel_find(name);
|
||||
if (panel != RT_NULL )
|
||||
{
|
||||
struct rtgui_panel_thread* thread;
|
||||
|
||||
/* allocate panel thread node */
|
||||
thread = rtgui_malloc(sizeof(struct rtgui_panel_thread));
|
||||
if (thread == RT_NULL)
|
||||
{
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
/* construct panel thread node */
|
||||
thread->tid = tid;
|
||||
|
||||
/* init list */
|
||||
rtgui_list_init(&(thread->list));
|
||||
rtgui_list_init(&(thread->monitor_list));
|
||||
|
||||
/* append thread to the list */
|
||||
rtgui_list_append(&(panel->thread_list), &(thread->list));
|
||||
}
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
void rtgui_panel_thread_remove(rtgui_panel_t* panel, rt_thread_t tid)
|
||||
{
|
||||
if (panel != RT_NULL )
|
||||
{
|
||||
struct rtgui_list_node* node;
|
||||
struct rtgui_panel_thread* thread;
|
||||
|
||||
rtgui_list_foreach(node, &(panel->thread_list))
|
||||
{
|
||||
thread = rtgui_list_entry(node, struct rtgui_panel_thread, list);
|
||||
if (thread->tid == tid)
|
||||
{
|
||||
/* remove node from list */
|
||||
rtgui_list_remove(&(panel->thread_list), &(thread->list));
|
||||
|
||||
/* free the panel thread node */
|
||||
rtgui_free(thread);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rt_thread_t rtgui_panel_get_active_thread(rtgui_panel_t* panel)
|
||||
{
|
||||
if (panel != RT_NULL)
|
||||
{
|
||||
if (panel->thread_list.next != RT_NULL)
|
||||
{
|
||||
struct rtgui_panel_thread* thread;
|
||||
thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list);
|
||||
|
||||
return thread->tid;
|
||||
}
|
||||
}
|
||||
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
void rtgui_panel_set_active_thread(rtgui_panel_t* panel, rt_thread_t tid)
|
||||
{
|
||||
/* get old active thread */
|
||||
rt_thread_t prev_actived = rtgui_panel_get_active_thread(panel);
|
||||
if (prev_actived != tid)
|
||||
{
|
||||
/* de-active old active workbench */
|
||||
struct rtgui_event_panel_hide ehide;
|
||||
RTGUI_EVENT_PANEL_HIDE_INIT(&ehide);
|
||||
|
||||
ehide.panel = panel;
|
||||
ehide.workbench = RT_NULL;
|
||||
rtgui_thread_send_urgent(prev_actived, &(ehide.parent), sizeof (ehide));
|
||||
}
|
||||
|
||||
if (panel != RT_NULL )
|
||||
{
|
||||
struct rtgui_list_node* node;
|
||||
struct rtgui_panel_thread* thread;
|
||||
|
||||
rtgui_list_foreach(node, &(panel->thread_list))
|
||||
{
|
||||
thread = rtgui_list_entry(node, struct rtgui_panel_thread, list);
|
||||
if (thread->tid == tid)
|
||||
{
|
||||
/* remove node from list */
|
||||
rtgui_list_remove(&(panel->thread_list), &(thread->list));
|
||||
|
||||
/* insert node to the header */
|
||||
rtgui_list_insert(&(panel->thread_list), &(thread->list));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* deactivate current activated thread -- move it to the end of list */
|
||||
void rtgui_panel_deactive_thread(rtgui_panel_t* panel)
|
||||
{
|
||||
RT_ASSERT(panel == RT_NULL);
|
||||
|
||||
if (panel->thread_list.next != RT_NULL)
|
||||
{
|
||||
struct rtgui_panel_thread* thread;
|
||||
thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list);
|
||||
|
||||
/* remove it */
|
||||
panel->thread_list.next = thread->list.next;
|
||||
|
||||
/* append to the tail of thread list */
|
||||
rtgui_list_append(&(panel->thread_list), &(thread->list));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the panel which contains a point(x, y)
|
||||
*/
|
||||
rtgui_panel_t* rtgui_panel_get_contain(int x, int y)
|
||||
{
|
||||
struct rtgui_list_node* node;
|
||||
struct rtgui_panel* panel;
|
||||
|
||||
rtgui_list_foreach(node, &(_rtgui_panel_list))
|
||||
{
|
||||
panel = rtgui_list_entry(node, struct rtgui_panel, sibling);
|
||||
if (rtgui_rect_contains_point(&(panel->extent), x, y) == RT_EOK)
|
||||
{
|
||||
return panel;
|
||||
}
|
||||
}
|
||||
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* append a rect to panel mouse monitor rect list
|
||||
*/
|
||||
void rtgui_panel_append_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect)
|
||||
{
|
||||
if (panel != RT_NULL )
|
||||
{
|
||||
struct rtgui_list_node* node;
|
||||
struct rtgui_panel_thread* thread;
|
||||
|
||||
rtgui_list_foreach(node, &(panel->thread_list))
|
||||
{
|
||||
thread = rtgui_list_entry(node, struct rtgui_panel_thread, list);
|
||||
if (thread->tid == tid)
|
||||
{
|
||||
/* add the monitor rect to list */
|
||||
rtgui_mouse_monitor_append(&(thread->monitor_list), rect);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a rect from panel mouse monitor rect list
|
||||
*/
|
||||
void rtgui_panel_remove_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect)
|
||||
{
|
||||
if (panel != RT_NULL )
|
||||
{
|
||||
struct rtgui_list_node* node;
|
||||
struct rtgui_panel_thread* thread;
|
||||
|
||||
rtgui_list_foreach(node, &(panel->thread_list))
|
||||
{
|
||||
thread = rtgui_list_entry(node, struct rtgui_panel_thread, list);
|
||||
if (thread->tid == tid)
|
||||
{
|
||||
/* remove the monitor rect from list */
|
||||
rtgui_mouse_monitor_remove(&(thread->monitor_list), rect);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_panel_set_wm(rtgui_panel_t* panel, rt_thread_t wm)
|
||||
{
|
||||
RT_ASSERT(wm != RT_NULL);
|
||||
RT_ASSERT(panel != RT_NULL);
|
||||
|
||||
panel->wm_thread = wm;
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* File : panel.h
|
||||
* This file is part of RTGUI in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-04 Bernard first version
|
||||
*/
|
||||
|
||||
#ifndef __RT_PANEL_H__
|
||||
#define __RT_PANEL_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/list.h>
|
||||
#include <rtgui/region.h>
|
||||
|
||||
struct rtgui_panel_thread
|
||||
{
|
||||
/* thread id */
|
||||
rt_thread_t tid;
|
||||
|
||||
/* the list of thread */
|
||||
rtgui_list_t list;
|
||||
|
||||
/* monitor rect list */
|
||||
rtgui_list_t monitor_list;
|
||||
};
|
||||
typedef struct rtgui_panel_thread rtgui_panel_thread_list_t;
|
||||
|
||||
struct rtgui_panel
|
||||
{
|
||||
char name[RTGUI_NAME_MAX];
|
||||
|
||||
/* the extent of panel */
|
||||
rtgui_rect_t extent;
|
||||
|
||||
/* the list of panel */
|
||||
rtgui_list_t sibling;
|
||||
|
||||
/* the thread list in this panel */
|
||||
rtgui_list_t thread_list;
|
||||
|
||||
/* the workbench manager thread */
|
||||
rt_thread_t wm_thread;
|
||||
|
||||
/* is focusable */
|
||||
rt_bool_t is_focusable;
|
||||
};
|
||||
|
||||
/* find panel by name */
|
||||
struct rtgui_panel* rtgui_panel_find(char* name);
|
||||
|
||||
/* add or remove application thread from specified panel */
|
||||
rtgui_panel_t* rtgui_panel_thread_add(char* name, rt_thread_t tid);
|
||||
void rtgui_panel_thread_remove(rtgui_panel_t* panel, rt_thread_t tid);
|
||||
|
||||
rt_thread_t rtgui_panel_get_active_thread(rtgui_panel_t* panel);
|
||||
void rtgui_panel_set_active_thread(rtgui_panel_t* panel, rt_thread_t tid);
|
||||
|
||||
rtgui_panel_t* rtgui_panel_get_contain(int x, int y);
|
||||
void rtgui_panel_set_wm(rtgui_panel_t* panel, rt_thread_t wm);
|
||||
|
||||
void rtgui_panel_append_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect);
|
||||
void rtgui_panel_remove_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect);
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,673 @@
|
|||
/*
|
||||
* File : rtgui_application.c
|
||||
* This file is part of RTGUI in 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-01-13 Grissiom first version(just a prototype of application API)
|
||||
*/
|
||||
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
#include <rtgui/widgets/window.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define RTGUI_EVENT_DEBUG
|
||||
#endif
|
||||
|
||||
#ifdef RTGUI_EVENT_DEBUG
|
||||
const char *event_string[] =
|
||||
{
|
||||
/* window event */
|
||||
"WIN_CREATE", /* create a window */
|
||||
"WIN_DESTROY", /* destroy a window */
|
||||
"WIN_SHOW", /* show a window */
|
||||
"WIN_HIDE", /* hide a window */
|
||||
"WIN_ACTIVATE", /* activate a window */
|
||||
"WIN_DEACTIVATE", /* deactivate a window */
|
||||
"WIN_CLOSE", /* close a window */
|
||||
"WIN_MOVE", /* move a window */
|
||||
"WIN_RESIZE", /* resize a window */
|
||||
"WIN_MODAL_ENTER", /* a window modals */
|
||||
|
||||
"SET_WM", /* set window manager */
|
||||
|
||||
"UPDATE_BEGIN", /* begin of update rect */
|
||||
"UPDATE_END", /* end of update rect */
|
||||
"MONITOR_ADD", /* add a monitor rect */
|
||||
"MONITOR_REMOVE", /* remove a monitor rect*/
|
||||
"PAINT", /* paint on screen */
|
||||
"TIMER", /* timer */
|
||||
|
||||
/* clip rect information */
|
||||
"CLIP_INFO", /* clip rect info */
|
||||
|
||||
/* mouse and keyboard event */
|
||||
"MOUSE_MOTION", /* mouse motion */
|
||||
"MOUSE_BUTTON", /* mouse button info */
|
||||
"KBD", /* keyboard info */
|
||||
|
||||
/* user command event */
|
||||
"COMMAND", /* user command */
|
||||
|
||||
/* request's status event */
|
||||
"STATUS", /* request result */
|
||||
"SCROLLED", /* scroll bar scrolled */
|
||||
"RESIZE", /* widget resize */
|
||||
};
|
||||
|
||||
#define DBG_MSG(x) rt_kprintf x
|
||||
|
||||
static void rtgui_event_dump(rt_thread_t tid, rtgui_event_t* event)
|
||||
{
|
||||
char* sender = "(unknown)";
|
||||
|
||||
if ((event->type == RTGUI_EVENT_TIMER) ||
|
||||
(event->type == RTGUI_EVENT_UPDATE_BEGIN) ||
|
||||
(event->type == RTGUI_EVENT_MOUSE_MOTION) ||
|
||||
(event->type == RTGUI_EVENT_UPDATE_END))
|
||||
{
|
||||
/* don't dump timer event */
|
||||
return ;
|
||||
}
|
||||
|
||||
if (event->sender != RT_NULL)
|
||||
sender = event->sender->name;
|
||||
|
||||
rt_kprintf("%s -- %s --> %s ", sender, event_string[event->type], tid->name);
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
{
|
||||
struct rtgui_event_paint *paint = (struct rtgui_event_paint *)event;
|
||||
|
||||
if(paint->wid != RT_NULL)
|
||||
rt_kprintf("win: %s", paint->wid->title);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_KBD:
|
||||
{
|
||||
struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd*) event;
|
||||
if (ekbd->wid != RT_NULL)
|
||||
rt_kprintf("win: %s", ekbd->wid->title);
|
||||
if (RTGUI_KBD_IS_UP(ekbd)) rt_kprintf(", up");
|
||||
else rt_kprintf(", down");
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_CLIP_INFO:
|
||||
{
|
||||
struct rtgui_event_clip_info *info = (struct rtgui_event_clip_info *)event;
|
||||
|
||||
if(info->wid != RT_NULL)
|
||||
rt_kprintf("win: %s", info->wid->title);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_CREATE:
|
||||
{
|
||||
struct rtgui_event_win_create *create = (struct rtgui_event_win_create*)event;
|
||||
|
||||
rt_kprintf(" win: %s at (x1:%d, y1:%d, x2:%d, y2:%d), addr: %p",
|
||||
#ifdef RTGUI_USING_SMALL_SIZE
|
||||
create->wid->title,
|
||||
RTGUI_WIDGET(create->wid)->extent.x1,
|
||||
RTGUI_WIDGET(create->wid)->extent.y1,
|
||||
RTGUI_WIDGET(create->wid)->extent.x2,
|
||||
RTGUI_WIDGET(create->wid)->extent.y2,
|
||||
#else
|
||||
create->title,
|
||||
create->extent.x1,
|
||||
create->extent.y1,
|
||||
create->extent.x2,
|
||||
create->extent.y2,
|
||||
#endif
|
||||
create->wid
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_UPDATE_END:
|
||||
{
|
||||
struct rtgui_event_update_end* update_end = (struct rtgui_event_update_end*)event;
|
||||
rt_kprintf("(x:%d, y1:%d, x2:%d, y2:%d)", update_end->rect.x1,
|
||||
update_end->rect.y1,
|
||||
update_end->rect.x2,
|
||||
update_end->rect.y2);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_ACTIVATE:
|
||||
case RTGUI_EVENT_WIN_DEACTIVATE:
|
||||
case RTGUI_EVENT_WIN_SHOW:
|
||||
case RTGUI_EVENT_WIN_MODAL_ENTER:
|
||||
{
|
||||
struct rtgui_event_win *win = (struct rtgui_event_win *)event;
|
||||
|
||||
if(win->wid != RT_NULL)
|
||||
rt_kprintf("win: %s", win->wid->title);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_MOVE:
|
||||
{
|
||||
struct rtgui_event_win_move *win = (struct rtgui_event_win_move *)event;
|
||||
|
||||
if(win->wid != RT_NULL)
|
||||
{
|
||||
rt_kprintf("win: %s", win->wid->title);
|
||||
rt_kprintf(" to (x:%d, y:%d)", win->x, win->y);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_RESIZE:
|
||||
{
|
||||
struct rtgui_event_win_resize* win = (struct rtgui_event_win_resize *)event;
|
||||
|
||||
if (win->wid != RT_NULL)
|
||||
{
|
||||
rt_kprintf("win: %s, rect(x1:%d, y1:%d, x2:%d, y2:%d)", win->wid->title,
|
||||
RTGUI_WIDGET(win->wid)->extent.x1,
|
||||
RTGUI_WIDGET(win->wid)->extent.y1,
|
||||
RTGUI_WIDGET(win->wid)->extent.x2,
|
||||
RTGUI_WIDGET(win->wid)->extent.y2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
case RTGUI_EVENT_MOUSE_MOTION:
|
||||
{
|
||||
struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse*)event;
|
||||
|
||||
if (mouse->button & RTGUI_MOUSE_BUTTON_LEFT) rt_kprintf("left ");
|
||||
else rt_kprintf("right ");
|
||||
|
||||
if (mouse->button & RTGUI_MOUSE_BUTTON_DOWN) rt_kprintf("down ");
|
||||
else rt_kprintf("up ");
|
||||
|
||||
if (mouse->wid != RT_NULL)
|
||||
rt_kprintf("win: %s at (%d, %d)", mouse->wid->title,
|
||||
mouse->x, mouse->y);
|
||||
else
|
||||
rt_kprintf("(%d, %d)", mouse->x, mouse->y);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MONITOR_ADD:
|
||||
{
|
||||
struct rtgui_event_monitor *monitor = (struct rtgui_event_monitor*)event;
|
||||
if (monitor->wid != RT_NULL)
|
||||
{
|
||||
rt_kprintf("win: %s, the rect is:(%d, %d) - (%d, %d)", monitor->wid->title,
|
||||
monitor->rect.x1, monitor->rect.y1,
|
||||
monitor->rect.x2, monitor->rect.y2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
rt_kprintf("\n");
|
||||
}
|
||||
#else
|
||||
#define DBG_MSG(x)
|
||||
#define rtgui_event_dump(tid, event)
|
||||
#endif
|
||||
|
||||
rt_bool_t rtgui_application_event_handler(struct rtgui_object* obj, rtgui_event_t* event);
|
||||
|
||||
static void _rtgui_application_constructor(struct rtgui_application *app)
|
||||
{
|
||||
/* set event handler */
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(app),
|
||||
rtgui_application_event_handler);
|
||||
|
||||
app->name = RT_NULL;
|
||||
/* set EXITED so we can destroy an application that just created */
|
||||
app->state_flag = RTGUI_APPLICATION_FLAG_EXITED;
|
||||
app->ref_count = 0;
|
||||
app->exit_code = 0;
|
||||
app->tid = RT_NULL;
|
||||
app->server = RT_NULL;
|
||||
app->mq = RT_NULL;
|
||||
app->modal_object = RT_NULL;
|
||||
app->on_idle = RT_NULL;
|
||||
}
|
||||
|
||||
static void _rtgui_application_destructor(struct rtgui_application *app)
|
||||
{
|
||||
RT_ASSERT(app != RT_NULL);
|
||||
|
||||
rt_free(app->name);
|
||||
app->name = RT_NULL;
|
||||
}
|
||||
|
||||
DEFINE_CLASS_TYPE(application, "application",
|
||||
RTGUI_OBJECT_TYPE,
|
||||
_rtgui_application_constructor,
|
||||
_rtgui_application_destructor,
|
||||
sizeof(struct rtgui_application));
|
||||
|
||||
struct rtgui_application* rtgui_application_create(
|
||||
rt_thread_t tid,
|
||||
const char *myname)
|
||||
{
|
||||
struct rtgui_application *app;
|
||||
|
||||
RT_ASSERT(tid != RT_NULL);
|
||||
RT_ASSERT(myname != RT_NULL);
|
||||
|
||||
/* create application */
|
||||
app = RTGUI_APPLICATION(rtgui_object_create(RTGUI_APPLICATION_TYPE));
|
||||
if (app == RT_NULL)
|
||||
return RT_NULL;
|
||||
|
||||
DBG_MSG(("register a rtgui application(%s) on thread %s\n", myname, tid->name));
|
||||
|
||||
app->tid = tid;
|
||||
/* set user thread */
|
||||
tid->user_data = (rt_uint32_t)app;
|
||||
|
||||
app->mq = rt_mq_create("rtgui", sizeof(union rtgui_event_generic), 32, RT_IPC_FLAG_FIFO);
|
||||
if (app->mq == RT_NULL)
|
||||
{
|
||||
rt_kprintf("mq err\n");
|
||||
goto __mq_err;
|
||||
}
|
||||
|
||||
/* set application title */
|
||||
app->name = (unsigned char*)rt_strdup((char*)myname);
|
||||
if (app->name != RT_NULL)
|
||||
return app;
|
||||
|
||||
__mq_err:
|
||||
rtgui_object_destroy(RTGUI_OBJECT(app));
|
||||
tid->user_data = 0;
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
#define _rtgui_application_check(app) \
|
||||
do { \
|
||||
RT_ASSERT(app != RT_NULL); \
|
||||
RT_ASSERT(app->tid != RT_NULL); \
|
||||
RT_ASSERT(app->tid->user_data != 0); \
|
||||
RT_ASSERT(app->mq != RT_NULL); \
|
||||
} while (0)
|
||||
|
||||
void rtgui_application_destroy(struct rtgui_application *app)
|
||||
{
|
||||
_rtgui_application_check(app);
|
||||
|
||||
if (!(app->state_flag & RTGUI_APPLICATION_FLAG_EXITED))
|
||||
{
|
||||
rt_kprintf("cannot destroy a running application: %s.\n",
|
||||
app->name);
|
||||
return;
|
||||
}
|
||||
|
||||
app->tid->user_data = 0;
|
||||
rt_mq_delete(app->mq);
|
||||
rtgui_object_destroy(RTGUI_OBJECT(app));
|
||||
}
|
||||
|
||||
struct rtgui_application* rtgui_application_self(void)
|
||||
{
|
||||
struct rtgui_application *app;
|
||||
rt_thread_t self;
|
||||
|
||||
/* get current thread */
|
||||
self = rt_thread_self();
|
||||
app = (struct rtgui_application*)(self->user_data);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
void rtgui_application_set_onidle(rtgui_idle_func onidle)
|
||||
{
|
||||
struct rtgui_application *app;
|
||||
|
||||
app = rtgui_application_self();
|
||||
if (app != RT_NULL)
|
||||
app->on_idle = onidle;
|
||||
}
|
||||
|
||||
rtgui_idle_func rtgui_application_get_onidle(void)
|
||||
{
|
||||
struct rtgui_application *app;
|
||||
|
||||
app = rtgui_application_self();
|
||||
if (app != RT_NULL)
|
||||
return app->on_idle;
|
||||
else
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
extern rt_thread_t rt_thread_find(char* name);
|
||||
rt_thread_t rtgui_application_get_server(void)
|
||||
{
|
||||
return rt_thread_find("rtgui");
|
||||
}
|
||||
|
||||
rt_err_t rtgui_application_send(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
|
||||
{
|
||||
rt_err_t result;
|
||||
struct rtgui_application *app;
|
||||
|
||||
RT_ASSERT(tid != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
RT_ASSERT(event_size != 0);
|
||||
|
||||
rtgui_event_dump(tid, event);
|
||||
|
||||
/* find struct rtgui_application */
|
||||
app = (struct rtgui_application*) (tid->user_data);
|
||||
if (app == RT_NULL)
|
||||
return -RT_ERROR;
|
||||
|
||||
result = rt_mq_send(app->mq, event, event_size);
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
if (event->type != RTGUI_EVENT_TIMER)
|
||||
rt_kprintf("send event to %s failed\n", app->tid->name);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_application_send_urgent(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
|
||||
{
|
||||
rt_err_t result;
|
||||
struct rtgui_application *app;
|
||||
|
||||
RT_ASSERT(tid != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
RT_ASSERT(event_size != 0);
|
||||
|
||||
rtgui_event_dump(tid, event);
|
||||
|
||||
/* find rtgui_application */
|
||||
app = (struct rtgui_application*) (tid->user_data);
|
||||
if (app == RT_NULL)
|
||||
return -RT_ERROR;
|
||||
|
||||
result = rt_mq_urgent(app->mq, event, event_size);
|
||||
if (result != RT_EOK)
|
||||
rt_kprintf("send ergent event failed\n");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_application_send_sync(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
|
||||
{
|
||||
rt_err_t r;
|
||||
struct rtgui_application *app;
|
||||
rt_int32_t ack_buffer, ack_status;
|
||||
struct rt_mailbox ack_mb;
|
||||
|
||||
RT_ASSERT(tid != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
RT_ASSERT(event_size != 0);
|
||||
|
||||
rtgui_event_dump(tid, event);
|
||||
|
||||
/* init ack mailbox */
|
||||
r = rt_mb_init(&ack_mb, "ack", &ack_buffer, 1, 0);
|
||||
if (r!= RT_EOK)
|
||||
goto __return;
|
||||
|
||||
app = (struct rtgui_application*) (tid->user_data);
|
||||
if (app == RT_NULL)
|
||||
{
|
||||
r = -RT_ERROR;
|
||||
goto __return;
|
||||
}
|
||||
|
||||
event->ack = &ack_mb;
|
||||
r = rt_mq_send(app->mq, event, event_size);
|
||||
if (r != RT_EOK)
|
||||
{
|
||||
rt_kprintf("send sync event failed\n");
|
||||
goto __return;
|
||||
}
|
||||
|
||||
r = rt_mb_recv(&ack_mb, (rt_uint32_t*)&ack_status, RT_WAITING_FOREVER);
|
||||
if (r!= RT_EOK)
|
||||
goto __return;
|
||||
|
||||
if (ack_status != RTGUI_STATUS_OK)
|
||||
r = -RT_ERROR;
|
||||
else
|
||||
r = RT_EOK;
|
||||
|
||||
__return:
|
||||
/* fini ack mailbox */
|
||||
rt_mb_detach(&ack_mb);
|
||||
return r;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_application_ack(rtgui_event_t* event, rt_int32_t status)
|
||||
{
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
RT_ASSERT(event->ack != RT_NULL);
|
||||
|
||||
rt_mb_send(event->ack, status);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_application_recv(rtgui_event_t* event, rt_size_t event_size)
|
||||
{
|
||||
struct rtgui_application* app;
|
||||
rt_err_t r;
|
||||
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
RT_ASSERT(event_size != 0);
|
||||
|
||||
app = (struct rtgui_application*) (rt_thread_self()->user_data);
|
||||
if (app == RT_NULL)
|
||||
return -RT_ERROR;
|
||||
|
||||
r = rt_mq_recv(app->mq, event, event_size, RT_WAITING_FOREVER);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_application_recv_nosuspend(rtgui_event_t* event, rt_size_t event_size)
|
||||
{
|
||||
struct rtgui_application *app;
|
||||
rt_err_t r;
|
||||
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
RT_ASSERT(event != 0);
|
||||
|
||||
app = (struct rtgui_application*) (rt_thread_self()->user_data);
|
||||
if (app == RT_NULL)
|
||||
return -RT_ERROR;
|
||||
|
||||
r = rt_mq_recv(app->mq, event, event_size, 0);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_application_recv_filter(rt_uint32_t type, rtgui_event_t* event, rt_size_t event_size)
|
||||
{
|
||||
struct rtgui_application *app;
|
||||
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
RT_ASSERT(event_size != 0);
|
||||
|
||||
app = (struct rtgui_application*) (rt_thread_self()->user_data);
|
||||
if (app == RT_NULL)
|
||||
return -RT_ERROR;
|
||||
|
||||
while (rt_mq_recv(app->mq, event, event_size, RT_WAITING_FOREVER) == RT_EOK)
|
||||
{
|
||||
if (event->type == type)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (RTGUI_OBJECT(app)->event_handler != RT_NULL)
|
||||
{
|
||||
RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
rt_inline rt_bool_t _rtgui_application_dest_handle(
|
||||
struct rtgui_application *app,
|
||||
struct rtgui_event *event)
|
||||
{
|
||||
struct rtgui_event_win* wevent = (struct rtgui_event_win*)event;
|
||||
|
||||
struct rtgui_object* dest_object = RTGUI_OBJECT(wevent->wid);
|
||||
|
||||
if (dest_object != RT_NULL)
|
||||
{
|
||||
if (dest_object->event_handler != RT_NULL)
|
||||
return dest_object->event_handler(RTGUI_OBJECT(dest_object), event);
|
||||
else
|
||||
return RT_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("RTGUI ERROR:server sent a event(%d) without wid\n", event->type);
|
||||
return RT_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_application_event_handler(struct rtgui_object* object, rtgui_event_t* event)
|
||||
{
|
||||
struct rtgui_application* app;
|
||||
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
app = RTGUI_APPLICATION(object);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
case RTGUI_EVENT_CLIP_INFO:
|
||||
case RTGUI_EVENT_WIN_ACTIVATE:
|
||||
case RTGUI_EVENT_WIN_DEACTIVATE:
|
||||
case RTGUI_EVENT_WIN_CLOSE:
|
||||
case RTGUI_EVENT_WIN_MOVE:
|
||||
case RTGUI_EVENT_KBD:
|
||||
_rtgui_application_dest_handle(app, event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
case RTGUI_EVENT_MOUSE_MOTION:
|
||||
{
|
||||
struct rtgui_event_win* wevent = (struct rtgui_event_win*)event;
|
||||
struct rtgui_object* dest_object = RTGUI_OBJECT(wevent->wid);
|
||||
|
||||
// FIXME: let application determine the dest_wiget but not in sever
|
||||
// so we can combine this handler with above one
|
||||
if (app->modal_object != RT_NULL &&
|
||||
dest_object != app->modal_object)
|
||||
{
|
||||
// rt_kprintf("discard event %s that is not sent to modal object\n",
|
||||
// event_string[event->type]);
|
||||
}
|
||||
else
|
||||
{
|
||||
_rtgui_application_dest_handle(app, event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_TIMER:
|
||||
{
|
||||
struct rtgui_timer* timer;
|
||||
struct rtgui_event_timer* etimer = (struct rtgui_event_timer*) event;
|
||||
|
||||
timer = etimer->timer;
|
||||
if (timer->timeout != RT_NULL)
|
||||
{
|
||||
/* call timeout function */
|
||||
timer->timeout(timer, timer->user_data);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_COMMAND:
|
||||
{
|
||||
struct rtgui_event_command *ecmd = (struct rtgui_event_command*)event;
|
||||
|
||||
if (ecmd->wid != RT_NULL)
|
||||
return _rtgui_application_dest_handle(app, event);
|
||||
}
|
||||
|
||||
default:
|
||||
return rtgui_object_event_handler(object, event);
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
rt_inline void _rtgui_application_event_loop(struct rtgui_application *app)
|
||||
{
|
||||
rt_err_t result;
|
||||
rt_uint16_t current_ref;
|
||||
struct rtgui_event *event;
|
||||
|
||||
_rtgui_application_check(app);
|
||||
|
||||
/* point to event buffer */
|
||||
event = (struct rtgui_event*)app->event_buffer;
|
||||
|
||||
current_ref = ++app->ref_count;
|
||||
|
||||
while (current_ref <= app->ref_count)
|
||||
{
|
||||
RT_ASSERT(current_ref == app->ref_count);
|
||||
|
||||
if (app->on_idle != RT_NULL)
|
||||
{
|
||||
result = rtgui_application_recv_nosuspend(event, sizeof(union rtgui_event_generic));
|
||||
if (result == RT_EOK)
|
||||
RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), event);
|
||||
else if (result == -RT_ETIMEOUT)
|
||||
app->on_idle(RTGUI_OBJECT(app), RT_NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = rtgui_application_recv(event, sizeof(union rtgui_event_generic));
|
||||
if (result == RT_EOK)
|
||||
RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rt_base_t rtgui_application_run(struct rtgui_application *app)
|
||||
{
|
||||
_rtgui_application_check(app);
|
||||
|
||||
app->state_flag &= ~RTGUI_APPLICATION_FLAG_EXITED;
|
||||
|
||||
_rtgui_application_event_loop(app);
|
||||
|
||||
if (app->ref_count == 0)
|
||||
app->state_flag |= RTGUI_APPLICATION_FLAG_EXITED;
|
||||
|
||||
return app->exit_code;
|
||||
}
|
||||
|
||||
void rtgui_application_exit(struct rtgui_application* app, rt_uint16_t code)
|
||||
{
|
||||
--app->ref_count;
|
||||
app->exit_code = code;
|
||||
}
|
|
@ -15,176 +15,15 @@
|
|||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/event.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/rtgui_object.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
#include <rtgui/driver.h>
|
||||
|
||||
#include "mouse.h"
|
||||
#include "panel.h"
|
||||
#include "topwin.h"
|
||||
|
||||
static struct rt_thread *rtgui_server_tid;
|
||||
static struct rt_messagequeue *rtgui_server_mq;
|
||||
|
||||
extern struct rtgui_topwin* rtgui_server_focus_topwin;
|
||||
struct rtgui_panel* rtgui_server_focus_panel = RT_NULL;
|
||||
|
||||
void rtgui_server_create_application(struct rtgui_event_panel_attach* event)
|
||||
{
|
||||
struct rtgui_panel* panel = rtgui_panel_find(event->panel_name);
|
||||
|
||||
if (panel != RT_NULL)
|
||||
{
|
||||
struct rtgui_event_panel_info ep;
|
||||
RTGUI_EVENT_PANEL_INFO_INIT(&ep);
|
||||
|
||||
if (panel->wm_thread != RT_NULL)
|
||||
{
|
||||
/* notify to workbench */
|
||||
rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_attach));
|
||||
}
|
||||
|
||||
/* send the responses - ok */
|
||||
rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK);
|
||||
|
||||
/* send the panel info */
|
||||
ep.panel = panel;
|
||||
ep.extent = panel->extent;
|
||||
rtgui_thread_send(event->parent.sender, (struct rtgui_event*)&ep, sizeof(ep));
|
||||
|
||||
rtgui_panel_thread_add(event->panel_name, event->parent.sender);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* send the responses - failure */
|
||||
rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_NRC);
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_server_destroy_application(struct rtgui_event_panel_detach* event)
|
||||
{
|
||||
struct rtgui_panel* panel = event->panel;
|
||||
|
||||
if (panel != RT_NULL)
|
||||
{
|
||||
if (panel->wm_thread != RT_NULL)
|
||||
{
|
||||
/* notify to workbench */
|
||||
rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_detach));
|
||||
}
|
||||
|
||||
/* send the responses */
|
||||
rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK);
|
||||
|
||||
rtgui_panel_thread_remove(panel, event->parent.sender);
|
||||
|
||||
{
|
||||
/* get next thread and active it */
|
||||
rt_thread_t tid = rtgui_panel_get_active_thread(panel);
|
||||
if (tid != RT_NULL)
|
||||
{
|
||||
/* let this thread repaint */
|
||||
struct rtgui_event_paint epaint;
|
||||
RTGUI_EVENT_PAINT_INIT(&epaint);
|
||||
epaint.wid = RT_NULL;
|
||||
rtgui_thread_send(tid, (struct rtgui_event*)&epaint, sizeof(epaint));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* send the responses - failure */
|
||||
rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_NRC);
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_server_thread_panel_show(struct rtgui_event_panel_show* event)
|
||||
{
|
||||
struct rtgui_panel* panel = event->panel;
|
||||
|
||||
if (panel != RT_NULL)
|
||||
{
|
||||
struct rtgui_event_paint epaint;
|
||||
|
||||
/* send the responses */
|
||||
rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK);
|
||||
|
||||
if (panel->wm_thread != RT_NULL)
|
||||
{
|
||||
/* notify to workbench */
|
||||
rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_show));
|
||||
}
|
||||
|
||||
rtgui_panel_set_active_thread(panel, event->parent.sender);
|
||||
|
||||
/* send all topwin clip info */
|
||||
rtgui_topwin_update_clip_to_panel(panel);
|
||||
|
||||
/* send paint event */
|
||||
RTGUI_EVENT_PAINT_INIT(&epaint);
|
||||
epaint.wid = RT_NULL;
|
||||
rtgui_thread_send(event->parent.sender, (struct rtgui_event*)&epaint,
|
||||
sizeof(epaint));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* send failed */
|
||||
rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_server_thread_panel_hide(struct rtgui_event_panel_hide* event)
|
||||
{
|
||||
struct rtgui_panel* panel = event->panel;
|
||||
|
||||
if (panel != RT_NULL)
|
||||
{
|
||||
rt_thread_t tid;
|
||||
|
||||
/* send the responses */
|
||||
rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK);
|
||||
|
||||
if (panel->thread_list.next != RT_NULL)
|
||||
{
|
||||
struct rtgui_panel_thread* thread;
|
||||
thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list);
|
||||
|
||||
/* remove it */
|
||||
panel->thread_list.next = thread->list.next;
|
||||
|
||||
/* append to the tail of thread list */
|
||||
rtgui_list_append(&(panel->thread_list), &(thread->list));
|
||||
}
|
||||
|
||||
/* send all topwin clip info */
|
||||
rtgui_topwin_update_clip_to_panel(panel);
|
||||
|
||||
/* get new active thread */
|
||||
tid = rtgui_panel_get_active_thread(panel);
|
||||
if (tid != RT_NULL)
|
||||
{
|
||||
struct rtgui_event_paint epaint;
|
||||
|
||||
/* send paint event */
|
||||
RTGUI_EVENT_PAINT_INIT(&epaint);
|
||||
epaint.wid = RT_NULL;
|
||||
rtgui_thread_send(tid, (struct rtgui_event*)&epaint, sizeof(epaint));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* send failed */
|
||||
rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_server_handle_set_wm(struct rtgui_event_set_wm *event)
|
||||
{
|
||||
struct rtgui_panel* panel = rtgui_panel_find(event->panel_name);
|
||||
|
||||
if (panel != RT_NULL)
|
||||
{
|
||||
rtgui_panel_set_wm(panel, event->parent.sender);
|
||||
}
|
||||
}
|
||||
static struct rtgui_application *rtgui_server_application;
|
||||
|
||||
void rtgui_server_handle_update(struct rtgui_event_update_end* event)
|
||||
{
|
||||
|
@ -199,36 +38,19 @@ void rtgui_server_handle_update(struct rtgui_event_update_end* event)
|
|||
|
||||
void rtgui_server_handle_monitor_add(struct rtgui_event_monitor* event)
|
||||
{
|
||||
if (event->panel != RT_NULL)
|
||||
{
|
||||
/* append monitor rect to panel list */
|
||||
rtgui_panel_append_monitor_rect(event->panel, event->parent.sender, &(event->rect));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* add monitor rect to top window list */
|
||||
rtgui_topwin_append_monitor_rect(event->wid, &(event->rect));
|
||||
}
|
||||
/* add monitor rect to top window list */
|
||||
rtgui_topwin_append_monitor_rect(event->wid, &(event->rect));
|
||||
}
|
||||
|
||||
void rtgui_server_handle_monitor_remove(struct rtgui_event_monitor* event)
|
||||
{
|
||||
if (event->panel != RT_NULL)
|
||||
{
|
||||
/* add monitor rect to panel list */
|
||||
rtgui_panel_remove_monitor_rect(event->panel, event->parent.sender, &(event->rect));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* add monitor rect to top window list */
|
||||
rtgui_topwin_remove_monitor_rect(event->wid, &(event->rect));
|
||||
}
|
||||
/* add monitor rect to top window list */
|
||||
rtgui_topwin_remove_monitor_rect(event->wid, &(event->rect));
|
||||
}
|
||||
|
||||
void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event)
|
||||
{
|
||||
struct rtgui_topwin* wnd;
|
||||
struct rtgui_panel* panel;
|
||||
|
||||
/* re-init to server thread */
|
||||
RTGUI_EVENT_MOUSE_BUTTON_INIT(event);
|
||||
|
@ -263,7 +85,7 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event)
|
|||
}
|
||||
|
||||
/* send to client thread */
|
||||
rtgui_thread_send(topwin->tid, &(ewin.parent), sizeof(ewin));
|
||||
rtgui_application_send(topwin->tid, &(ewin.parent), sizeof(ewin));
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -271,16 +93,15 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event)
|
|||
#endif
|
||||
|
||||
/* get the wnd which contains the mouse */
|
||||
wnd = rtgui_topwin_get_wnd(event->x, event->y);
|
||||
wnd = rtgui_topwin_get_wnd_no_modaled(event->x, event->y);
|
||||
if (wnd != RT_NULL)
|
||||
{
|
||||
event->wid = wnd->wid;
|
||||
|
||||
if (rtgui_server_focus_topwin != wnd)
|
||||
if (rtgui_topwin_get_focus() != wnd)
|
||||
{
|
||||
/* raise this window */
|
||||
rtgui_topwin_activate_win(wnd);
|
||||
rtgui_server_focus_panel = RT_NULL;
|
||||
}
|
||||
|
||||
if (wnd->title != RT_NULL &&
|
||||
|
@ -291,137 +112,39 @@ void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event)
|
|||
else
|
||||
{
|
||||
/* send mouse event to thread */
|
||||
rtgui_thread_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_mouse));
|
||||
rtgui_application_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_mouse));
|
||||
}
|
||||
return ;
|
||||
}
|
||||
|
||||
/* get the panel which contains the mouse */
|
||||
panel = rtgui_panel_get_contain(event->x, event->y);
|
||||
if ((panel != RT_NULL) && (panel->is_focusable == RT_TRUE))
|
||||
{
|
||||
/* deactivate old window */
|
||||
if (rtgui_server_focus_topwin != RT_NULL)
|
||||
{
|
||||
rtgui_topwin_deactivate_win(rtgui_server_focus_topwin);
|
||||
}
|
||||
|
||||
rtgui_server_focus_panel = panel;
|
||||
rtgui_server_focus_topwin = RT_NULL;
|
||||
|
||||
/* set destination window to null */
|
||||
event->wid = RT_NULL;
|
||||
|
||||
/* send mouse event to thread */
|
||||
if (rtgui_panel_get_active_thread(panel) != RT_NULL)
|
||||
{
|
||||
rtgui_thread_send(rtgui_panel_get_active_thread(panel),
|
||||
(struct rtgui_event*)event,
|
||||
sizeof(struct rtgui_event_mouse));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static struct rtgui_panel* last_monitor_panel = RT_NULL;
|
||||
static struct rtgui_topwin* last_monitor_topwin = RT_NULL;
|
||||
|
||||
void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse* event)
|
||||
{
|
||||
/* the topwin contains current mouse */
|
||||
struct rtgui_topwin* win = RT_NULL;
|
||||
struct rtgui_panel* panel = RT_NULL;
|
||||
|
||||
/* re-init mouse event */
|
||||
RTGUI_EVENT_MOUSE_MOTION_INIT(event);
|
||||
|
||||
/* find the panel or topwin which monitor the mouse motion */
|
||||
win = rtgui_topwin_get_wnd(event->x, event->y);
|
||||
if (win == RT_NULL)
|
||||
{
|
||||
/* try to find monitor on the panel */
|
||||
panel = rtgui_panel_get_contain(event->x, event->y);
|
||||
|
||||
if (panel != RT_NULL)
|
||||
{
|
||||
struct rtgui_panel_thread* thread;
|
||||
|
||||
/* get active panel thread */
|
||||
if (panel->thread_list.next != RT_NULL)
|
||||
{
|
||||
thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list);
|
||||
if (!rtgui_mouse_monitor_contains_point(&(thread->monitor_list),
|
||||
event->x, event->y) == RT_TRUE)
|
||||
{
|
||||
/* no monitor in this panel */
|
||||
panel = RT_NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (win->monitor_list.next != RT_NULL)
|
||||
win = rtgui_topwin_get_wnd_no_modaled(event->x, event->y);
|
||||
if (win != RT_NULL && win->monitor_list.next != RT_NULL)
|
||||
{
|
||||
// FIXME:
|
||||
/* check whether the monitor exist */
|
||||
if (rtgui_mouse_monitor_contains_point(&(win->monitor_list), event->x, event->y) != RT_TRUE)
|
||||
if (rtgui_mouse_monitor_contains_point(&(win->monitor_list),
|
||||
event->x, event->y) != RT_TRUE)
|
||||
{
|
||||
win = RT_NULL;
|
||||
|
||||
/* try to find monitor on the panel */
|
||||
panel = rtgui_panel_get_contain(event->x, event->y);
|
||||
if (panel != RT_NULL)
|
||||
{
|
||||
struct rtgui_panel_thread* thread;
|
||||
|
||||
/* get active panel thread */
|
||||
if (panel->thread_list.next != RT_NULL)
|
||||
{
|
||||
thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list);
|
||||
if (!rtgui_mouse_monitor_contains_point(&(thread->monitor_list),
|
||||
event->x, event->y) == RT_TRUE)
|
||||
{
|
||||
/* no monitor in this panel */
|
||||
panel = RT_NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
win = RT_NULL;
|
||||
}
|
||||
|
||||
/* check old panel or window */
|
||||
if (last_monitor_panel != RT_NULL)
|
||||
{
|
||||
rt_thread_t tid = rtgui_panel_get_active_thread(last_monitor_panel);
|
||||
|
||||
/* send mouse motion event */
|
||||
if (tid != RT_NULL)
|
||||
{
|
||||
event->wid = RT_NULL;
|
||||
rtgui_thread_send(tid, &(event->parent), sizeof(struct rtgui_event_mouse));
|
||||
}
|
||||
}
|
||||
else if (last_monitor_topwin != RT_NULL)
|
||||
if (last_monitor_topwin != RT_NULL)
|
||||
{
|
||||
event->wid = last_monitor_topwin->wid;
|
||||
|
||||
/* send mouse motion event */
|
||||
rtgui_thread_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse));
|
||||
}
|
||||
|
||||
if (last_monitor_panel != panel)
|
||||
{
|
||||
last_monitor_panel = panel;
|
||||
if (last_monitor_panel != RT_NULL)
|
||||
{
|
||||
rt_thread_t tid = rtgui_panel_get_active_thread(last_monitor_panel);
|
||||
event->wid = RT_NULL;
|
||||
|
||||
/* send mouse motion event */
|
||||
if (tid != RT_NULL)
|
||||
rtgui_thread_send(tid, &(event->parent), sizeof(struct rtgui_event_mouse));
|
||||
}
|
||||
rtgui_application_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse));
|
||||
}
|
||||
|
||||
if (last_monitor_topwin != win)
|
||||
|
@ -432,7 +155,7 @@ void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse* event)
|
|||
event->wid = last_monitor_topwin->wid;
|
||||
|
||||
/* send mouse motion event */
|
||||
rtgui_thread_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse));
|
||||
rtgui_application_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -443,203 +166,191 @@ void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse* event)
|
|||
void rtgui_server_handle_kbd(struct rtgui_event_kbd* event)
|
||||
{
|
||||
struct rtgui_topwin* wnd;
|
||||
struct rtgui_panel* panel;
|
||||
|
||||
/* re-init to server thread */
|
||||
RTGUI_EVENT_KBD_INIT(event);
|
||||
|
||||
/* todo: handle input method and global shortcut */
|
||||
|
||||
/* send to focus window or focus panel */
|
||||
wnd = rtgui_server_focus_topwin;
|
||||
if (wnd != RT_NULL && wnd->flag & WINTITLE_ACTIVATE)
|
||||
wnd = rtgui_topwin_get_focus();
|
||||
if (wnd != RT_NULL)
|
||||
{
|
||||
RT_ASSERT(wnd->flag & WINTITLE_ACTIVATE)
|
||||
|
||||
/* send to focus window */
|
||||
event->wid = wnd->wid;
|
||||
|
||||
/* send keyboard event to thread */
|
||||
rtgui_thread_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd));
|
||||
rtgui_application_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
panel = rtgui_server_focus_panel;
|
||||
if (panel != RT_NULL)
|
||||
{
|
||||
rt_thread_t tid;
|
||||
|
||||
/* get active thread in this panel */
|
||||
tid = rtgui_panel_get_active_thread(panel);
|
||||
if (tid != RT_NULL)
|
||||
{
|
||||
/* send to focus panel */
|
||||
event->wid = RT_NULL;
|
||||
|
||||
/* send keyboard event to thread */
|
||||
rtgui_thread_send(tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __WIN32__
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
static rt_bool_t rtgui_server_event_handler(struct rtgui_object *object,
|
||||
struct rtgui_event *event)
|
||||
{
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
/* dispatch event */
|
||||
switch (event->type)
|
||||
{
|
||||
/* window event */
|
||||
case RTGUI_EVENT_WIN_CREATE:
|
||||
if (rtgui_topwin_add((struct rtgui_event_win_create*)event) == RT_EOK)
|
||||
rtgui_application_ack(event, RTGUI_STATUS_OK);
|
||||
else
|
||||
rtgui_application_ack(event, RTGUI_STATUS_ERROR);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_DESTROY:
|
||||
if (last_monitor_topwin != RT_NULL &&
|
||||
last_monitor_topwin->wid == ((struct rtgui_event_win*)event)->wid)
|
||||
last_monitor_topwin = RT_NULL;
|
||||
if (rtgui_topwin_remove(((struct rtgui_event_win*)event)->wid) == RT_EOK)
|
||||
rtgui_application_ack(event, RTGUI_STATUS_OK);
|
||||
else
|
||||
rtgui_application_ack(event, RTGUI_STATUS_ERROR);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_SHOW:
|
||||
if (rtgui_topwin_show((struct rtgui_event_win*)event) == RT_EOK)
|
||||
rtgui_application_ack(event, RTGUI_STATUS_OK);
|
||||
else
|
||||
rtgui_application_ack(event, RTGUI_STATUS_ERROR);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_HIDE:
|
||||
if (rtgui_topwin_hide((struct rtgui_event_win*)event) == RT_EOK)
|
||||
rtgui_application_ack(event, RTGUI_STATUS_OK);
|
||||
else
|
||||
rtgui_application_ack(event, RTGUI_STATUS_ERROR);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_MOVE:
|
||||
if (rtgui_topwin_move((struct rtgui_event_win_move*)event) == RT_EOK)
|
||||
rtgui_application_ack(event, RTGUI_STATUS_OK);
|
||||
else
|
||||
rtgui_application_ack(event, RTGUI_STATUS_ERROR);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_MODAL_ENTER:
|
||||
if (rtgui_topwin_modal_enter((struct rtgui_event_win_modal_enter*)event) == RT_EOK)
|
||||
rtgui_application_ack(event, RTGUI_STATUS_OK);
|
||||
else
|
||||
rtgui_application_ack(event, RTGUI_STATUS_ERROR);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_RESIZE:
|
||||
rtgui_topwin_resize(((struct rtgui_event_win_resize*)event)->wid,
|
||||
&(((struct rtgui_event_win_resize*)event)->rect));
|
||||
break;
|
||||
|
||||
/* other event */
|
||||
case RTGUI_EVENT_UPDATE_BEGIN:
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
/* hide cursor */
|
||||
rtgui_mouse_hide_cursor();
|
||||
#endif
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_UPDATE_END:
|
||||
/* handle screen update */
|
||||
rtgui_server_handle_update((struct rtgui_event_update_end*)event);
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
/* show cursor */
|
||||
rtgui_mouse_show_cursor();
|
||||
#endif
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MONITOR_ADD:
|
||||
/* handle mouse monitor */
|
||||
rtgui_server_handle_monitor_add((struct rtgui_event_monitor*)event);
|
||||
break;
|
||||
|
||||
/* mouse and keyboard event */
|
||||
case RTGUI_EVENT_MOUSE_MOTION:
|
||||
/* handle mouse motion event */
|
||||
rtgui_server_handle_mouse_motion((struct rtgui_event_mouse*)event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
/* handle mouse button */
|
||||
rtgui_server_handle_mouse_btn((struct rtgui_event_mouse*)event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_KBD:
|
||||
/* handle keyboard event */
|
||||
rtgui_server_handle_kbd((struct rtgui_event_kbd*)event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_COMMAND:
|
||||
break;
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* rtgui server thread's entry
|
||||
*/
|
||||
static void rtgui_server_entry(void* parameter)
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
#ifdef _WIN32
|
||||
/* set the server thread to highest */
|
||||
HANDLE hCurrentThread = GetCurrentThread();
|
||||
SetThreadPriority(hCurrentThread, THREAD_PRIORITY_HIGHEST);
|
||||
#endif
|
||||
|
||||
#ifdef RTGUI_USING_SMALL_SIZE
|
||||
/* create rtgui server msgq */
|
||||
rtgui_server_mq = rt_mq_create("rtgui",
|
||||
32, 16, RT_IPC_FLAG_FIFO);
|
||||
#else
|
||||
/* create rtgui server msgq */
|
||||
rtgui_server_mq = rt_mq_create("rtgui",
|
||||
256, 8, RT_IPC_FLAG_FIFO);
|
||||
#endif
|
||||
/* register rtgui server thread */
|
||||
rtgui_thread_register(rtgui_server_tid, rtgui_server_mq);
|
||||
rtgui_server_application = rtgui_application_create(rtgui_server_tid,
|
||||
"rtgui");
|
||||
if (rtgui_server_application == RT_NULL)
|
||||
return;
|
||||
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(rtgui_server_application),
|
||||
rtgui_server_event_handler);
|
||||
/* init mouse and show */
|
||||
rtgui_mouse_init();
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
rtgui_mouse_show_cursor();
|
||||
#endif
|
||||
|
||||
while (1)
|
||||
{
|
||||
/* the buffer uses to receive event */
|
||||
#ifdef RTGUI_USING_SMALL_SIZE
|
||||
char event_buf[64];
|
||||
#else
|
||||
char event_buf[256];
|
||||
#endif
|
||||
struct rtgui_event* event = (struct rtgui_event*)&(event_buf[0]);
|
||||
rtgui_application_run(rtgui_server_application);
|
||||
|
||||
if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK)
|
||||
{
|
||||
/* dispatch event */
|
||||
switch (event->type)
|
||||
{
|
||||
/* panel event */
|
||||
case RTGUI_EVENT_PANEL_ATTACH:
|
||||
/* register an application in panel */
|
||||
rtgui_server_create_application((struct rtgui_event_panel_attach*)event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_PANEL_DETACH:
|
||||
/* unregister an application */
|
||||
rtgui_server_destroy_application((struct rtgui_event_panel_detach*)event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_PANEL_SHOW:
|
||||
/* handle raise an application */
|
||||
rtgui_server_thread_panel_show((struct rtgui_event_panel_show*)event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_PANEL_HIDE:
|
||||
/* handle hide an application */
|
||||
rtgui_server_thread_panel_hide((struct rtgui_event_panel_hide*)event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_SET_WM:
|
||||
/* handle set workbench manager event */
|
||||
rtgui_server_handle_set_wm((struct rtgui_event_set_wm*)event);
|
||||
break;
|
||||
|
||||
/* window event */
|
||||
case RTGUI_EVENT_WIN_CREATE:
|
||||
rtgui_thread_ack(event, RTGUI_STATUS_OK);
|
||||
rtgui_topwin_add((struct rtgui_event_win_create*)event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_DESTROY:
|
||||
if (rtgui_topwin_remove(((struct rtgui_event_win*)event)->wid) == RT_EOK)
|
||||
rtgui_thread_ack(event, RTGUI_STATUS_OK);
|
||||
else
|
||||
rtgui_thread_ack(event, RTGUI_STATUS_ERROR);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_SHOW:
|
||||
rtgui_topwin_show((struct rtgui_event_win*)event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_HIDE:
|
||||
rtgui_topwin_hide((struct rtgui_event_win*)event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_MOVE:
|
||||
rtgui_topwin_move((struct rtgui_event_win_move*)event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_RESIZE:
|
||||
rtgui_topwin_resize(((struct rtgui_event_win_resize*)event)->wid,
|
||||
&(((struct rtgui_event_win_resize*)event)->rect));
|
||||
break;
|
||||
|
||||
/* other event */
|
||||
case RTGUI_EVENT_UPDATE_BEGIN:
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
/* hide cursor */
|
||||
rtgui_mouse_hide_cursor();
|
||||
#endif
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_UPDATE_END:
|
||||
/* handle screen update */
|
||||
rtgui_server_handle_update((struct rtgui_event_update_end*)event);
|
||||
#ifdef RTGUI_USING_MOUSE_CURSOR
|
||||
/* show cursor */
|
||||
rtgui_mouse_show_cursor();
|
||||
#endif
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MONITOR_ADD:
|
||||
/* handle mouse monitor */
|
||||
rtgui_server_handle_monitor_add((struct rtgui_event_monitor*)event);
|
||||
break;
|
||||
|
||||
/* mouse and keyboard event */
|
||||
case RTGUI_EVENT_MOUSE_MOTION:
|
||||
/* handle mouse motion event */
|
||||
rtgui_server_handle_mouse_motion((struct rtgui_event_mouse*)event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
/* handle mouse button */
|
||||
rtgui_server_handle_mouse_btn((struct rtgui_event_mouse*)event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_KBD:
|
||||
/* handle keyboard event */
|
||||
rtgui_server_handle_kbd((struct rtgui_event_kbd*)event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_COMMAND:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* unregister in rtgui thread */
|
||||
// rtgui_thread_deregister(rt_thread_self());
|
||||
rtgui_application_destroy(rtgui_server_application);
|
||||
rtgui_server_application = RT_NULL;
|
||||
}
|
||||
|
||||
void rtgui_server_post_event(struct rtgui_event* event, rt_size_t size)
|
||||
{
|
||||
rt_mq_send(rtgui_server_mq, event, size);
|
||||
if (rtgui_server_tid != RT_NULL)
|
||||
rtgui_application_send(rtgui_server_tid, event, size);
|
||||
else
|
||||
rt_kprintf("post when server is not running\n");
|
||||
}
|
||||
|
||||
void rtgui_server_init()
|
||||
rt_err_t rtgui_server_post_event_sync(struct rtgui_event* event, rt_size_t size)
|
||||
{
|
||||
if (rtgui_server_tid != RT_NULL)
|
||||
return rtgui_application_send_sync(rtgui_server_tid, event, size);
|
||||
else
|
||||
{
|
||||
rt_kprintf("post when server is not running\n");
|
||||
return -RT_ENOSYS;
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_server_init(void)
|
||||
{
|
||||
if (rtgui_server_tid != RT_NULL)
|
||||
return;
|
||||
|
||||
rtgui_server_tid = rt_thread_create("rtgui",
|
||||
rtgui_server_entry, RT_NULL,
|
||||
RTGUI_SVR_THREAD_STACK_SIZE,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -15,7 +15,6 @@
|
|||
#define __RTGUI_TOPWIN_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/list.h>
|
||||
#include <rtgui/region.h>
|
||||
#include <rtgui/event.h>
|
||||
#include <rtgui/widgets/title.h>
|
||||
|
@ -25,25 +24,24 @@
|
|||
rt_err_t rtgui_topwin_add(struct rtgui_event_win_create* event);
|
||||
rt_err_t rtgui_topwin_remove(struct rtgui_win* wid);
|
||||
|
||||
/* raise window to front */
|
||||
void rtgui_topwin_raise(struct rtgui_win* wid, rt_thread_t sender);
|
||||
/* update clip info to a panel */
|
||||
void rtgui_topwin_update_clip_to_panel(struct rtgui_panel* panel);
|
||||
void rtgui_topwin_activate_win(struct rtgui_topwin* win);
|
||||
|
||||
/* show a window */
|
||||
void rtgui_topwin_show(struct rtgui_event_win* event);
|
||||
rt_err_t rtgui_topwin_show(struct rtgui_event_win* event);
|
||||
/* hide a window */
|
||||
void rtgui_topwin_hide(struct rtgui_event_win* event);
|
||||
rt_err_t rtgui_topwin_hide(struct rtgui_event_win* event);
|
||||
/* move a window */
|
||||
void rtgui_topwin_move(struct rtgui_event_win_move* event);
|
||||
rt_err_t rtgui_topwin_move(struct rtgui_event_win_move* event);
|
||||
/* resize a window */
|
||||
void rtgui_topwin_resize(struct rtgui_win* wid, rtgui_rect_t* r);
|
||||
/* a window is entering modal mode */
|
||||
rt_err_t rtgui_topwin_modal_enter(struct rtgui_event_win_modal_enter* event);
|
||||
|
||||
/* get window at (x, y) */
|
||||
struct rtgui_topwin* rtgui_topwin_get_wnd(int x, int y);
|
||||
struct rtgui_topwin* rtgui_topwin_get_wnd_no_modaled(int x, int y);
|
||||
|
||||
void rtgui_topwin_activate_win(struct rtgui_topwin* win);
|
||||
void rtgui_topwin_deactivate_win(struct rtgui_topwin* win);
|
||||
//void rtgui_topwin_deactivate_win(struct rtgui_topwin* win);
|
||||
|
||||
/* window title */
|
||||
void rtgui_topwin_title_ondraw(struct rtgui_topwin* win);
|
||||
|
@ -53,7 +51,7 @@ void rtgui_topwin_title_onmouse(struct rtgui_topwin* win, struct rtgui_event_mou
|
|||
void rtgui_topwin_append_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect);
|
||||
void rtgui_topwin_remove_monitor_rect(struct rtgui_win* wid, rtgui_rect_t* rect);
|
||||
|
||||
void rtgui_topwin_do_clip(rtgui_widget_t* widget);
|
||||
|
||||
/* get the topwin that is currently focused */
|
||||
struct rtgui_topwin* rtgui_topwin_get_focus(void);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ static void _rtgui_about_view_constructor(struct rtgui_about_view *view)
|
|||
struct rtgui_rect rect = {0, 0, 200, 200};
|
||||
|
||||
/* set default widget rect and set event handler */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view),rtgui_about_view_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(view),rtgui_about_view_event_handler);
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
|
||||
|
||||
RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
|
@ -33,7 +33,7 @@ static void _rtgui_about_view_constructor(struct rtgui_about_view *view)
|
|||
}
|
||||
|
||||
DEFINE_CLASS_TYPE(aboutview, "aboutview",
|
||||
RTGUI_VIEW_TYPE,
|
||||
RTGUI_CONTAINER_TYPE,
|
||||
_rtgui_about_view_constructor,
|
||||
RT_NULL,
|
||||
sizeof(struct rtgui_about_view));
|
||||
|
@ -64,7 +64,7 @@ void rtgui_about_view_ondraw(struct rtgui_about_view* view)
|
|||
rtgui_dc_end_drawing(dc);
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_about_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_about_view_event_handler(struct rtgui_object* widget, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_about_view* view = RT_NULL;
|
||||
|
||||
|
@ -77,7 +77,7 @@ rt_bool_t rtgui_about_view_event_handler(struct rtgui_widget* widget, struct rtg
|
|||
}
|
||||
|
||||
/* use view event handler */
|
||||
return rtgui_view_event_handler(widget, event);
|
||||
return rtgui_container_event_handler(widget, event);
|
||||
}
|
||||
|
||||
rtgui_about_view_t* rtgui_about_view_create(rtgui_image_t *logo, const char* description)
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
static void _rtgui_box_constructor(rtgui_box_t *box)
|
||||
{
|
||||
/* init widget and set event handler */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_box_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_box_event_handler);
|
||||
|
||||
RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_TRANSPARENT;
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_box_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_box_event_handler);
|
||||
|
||||
/* set proper of control */
|
||||
box->orient = RTGUI_HORIZONTAL;
|
||||
|
@ -34,7 +34,7 @@ DEFINE_CLASS_TYPE(box, "box",
|
|||
RT_NULL,
|
||||
sizeof(struct rtgui_box));
|
||||
|
||||
rt_bool_t rtgui_box_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
|
||||
rt_bool_t rtgui_box_event_handler(struct rtgui_object *widget, rtgui_event_t *event)
|
||||
{
|
||||
struct rtgui_box* box = (struct rtgui_box*)widget;
|
||||
|
||||
|
@ -48,7 +48,7 @@ rt_bool_t rtgui_box_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
|
|||
break;
|
||||
|
||||
default:
|
||||
return rtgui_container_event_handler(RTGUI_WIDGET(box), event);
|
||||
return rtgui_container_event_handler(RTGUI_OBJECT(box), event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
|
@ -166,7 +166,8 @@ static void rtgui_box_layout_vertical(rtgui_box_t* box)
|
|||
size_event.y = rect->y1;
|
||||
size_event.w = rect->x2 - rect->x1;
|
||||
size_event.h = rect->y2 - rect->y1;
|
||||
widget->event_handler(widget, &size_event.parent);
|
||||
RTGUI_OBJECT(widget)->event_handler(RTGUI_OBJECT(widget),
|
||||
&size_event.parent);
|
||||
|
||||
/* point to next height */
|
||||
next_y = rect->y2;
|
||||
|
@ -258,7 +259,8 @@ static void rtgui_box_layout_horizontal(rtgui_box_t* box)
|
|||
size_event.y = rect->y1;
|
||||
size_event.w = rect->x2 - rect->x1;
|
||||
size_event.h = rect->y2 - rect->y1;
|
||||
widget->event_handler(widget, &size_event.parent);
|
||||
RTGUI_OBJECT(widget)->event_handler(RTGUI_OBJECT(widget),
|
||||
&size_event.parent);
|
||||
|
||||
/* point to next width */
|
||||
next_x = rect->x2;
|
||||
|
|
|
@ -14,13 +14,13 @@
|
|||
#include <rtgui/dc.h>
|
||||
#include <rtgui/rtgui_theme.h>
|
||||
#include <rtgui/widgets/button.h>
|
||||
#include <rtgui/widgets/toplevel.h>
|
||||
#include <rtgui/widgets/window.h>
|
||||
|
||||
static void _rtgui_button_constructor(rtgui_button_t *button)
|
||||
{
|
||||
/* init widget and set event handler */
|
||||
RTGUI_WIDGET(button)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(button), rtgui_button_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(button), rtgui_button_event_handler);
|
||||
|
||||
/* un-press button */
|
||||
button->flag = 0;
|
||||
|
@ -57,13 +57,16 @@ DEFINE_CLASS_TYPE(button, "button",
|
|||
_rtgui_button_destructor,
|
||||
sizeof(struct rtgui_button));
|
||||
|
||||
rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_button_event_handler(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_button* btn;
|
||||
struct rtgui_widget *widget;
|
||||
struct rtgui_button *btn;
|
||||
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
btn = (struct rtgui_button*) widget;
|
||||
widget = RTGUI_WIDGET(object);
|
||||
btn = RTGUI_BUTTON(widget);
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
|
@ -150,10 +153,10 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_e
|
|||
if (emouse->button & RTGUI_MOUSE_BUTTON_LEFT)
|
||||
{
|
||||
/* set the last mouse event handled widget */
|
||||
rtgui_toplevel_t* toplevel;
|
||||
struct rtgui_win* win;
|
||||
|
||||
toplevel = RTGUI_TOPLEVEL(RTGUI_WIDGET(btn)->toplevel);
|
||||
toplevel->last_mevent_widget = RTGUI_WIDGET(btn);
|
||||
win = RTGUI_WIN(RTGUI_WIDGET(btn)->toplevel);
|
||||
win->last_mevent_widget = RTGUI_WIDGET(btn);
|
||||
|
||||
/* it's a normal button */
|
||||
if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
|
||||
|
|
|
@ -6,7 +6,7 @@ static void _rtgui_checkbox_constructor(rtgui_checkbox_t *box)
|
|||
{
|
||||
/* init widget and set event handler */
|
||||
RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_checkbox_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_checkbox_event_handler);
|
||||
|
||||
/* set status */
|
||||
box->status_down = RTGUI_CHECKBOX_STATUS_UNCHECKED;
|
||||
|
@ -29,9 +29,16 @@ void rtgui_checkbox_set_onbutton(rtgui_checkbox_t* checkbox, rtgui_onbutton_func
|
|||
checkbox->on_button = func;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_checkbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_checkbox_event_handler(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_checkbox* box = (struct rtgui_checkbox*)widget;
|
||||
struct rtgui_widget *widget;
|
||||
struct rtgui_checkbox *box = (struct rtgui_checkbox*)widget;
|
||||
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
widget = RTGUI_WIDGET(object);
|
||||
box = RTGUI_CHECKBOX(object);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <rtgui/rtgui_theme.h>
|
||||
#include <rtgui/widgets/combobox.h>
|
||||
|
||||
static rt_bool_t rtgui_combobox_pulldown_hide(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
static rt_bool_t rtgui_combobox_pulldown_hide(struct rtgui_object* object, struct rtgui_event* event);
|
||||
const static rt_uint8_t down_arrow[] = {0xff, 0x7e, 0x3c, 0x18};
|
||||
|
||||
static void _rtgui_combobox_constructor(rtgui_combobox_t *box)
|
||||
|
@ -10,7 +10,7 @@ static void _rtgui_combobox_constructor(rtgui_combobox_t *box)
|
|||
rtgui_rect_t rect = {0, 0, RTGUI_COMBOBOX_WIDTH, RTGUI_COMBOBOX_HEIGHT};
|
||||
|
||||
/* init widget and set event handler */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_combobox_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_combobox_event_handler);
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect);
|
||||
|
||||
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(box)) = RTGUI_ALIGN_CENTER_VERTICAL;
|
||||
|
@ -30,29 +30,34 @@ static void _rtgui_combobox_destructor(rtgui_combobox_t *box)
|
|||
box->pd_win = RT_NULL;
|
||||
}
|
||||
|
||||
void rtgui_combobox_pdwin_onitem(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_combobox_pdwin_onitem(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_widget *widget;
|
||||
rtgui_win_t* pd_win;
|
||||
rtgui_combobox_t* combo;
|
||||
rtgui_listbox_t* list;
|
||||
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
widget = RTGUI_WIDGET(object);
|
||||
list = RTGUI_LISTBOX(widget);
|
||||
pd_win = RTGUI_WIN(rtgui_widget_get_toplevel(widget));
|
||||
combo = RTGUI_COMBOBOX(pd_win->user_data);
|
||||
combo->current_item = list->current_item;
|
||||
|
||||
if (combo->on_selected != RT_NULL)
|
||||
combo->on_selected(RTGUI_WIDGET(combo), RT_NULL);
|
||||
combo->on_selected(RTGUI_OBJECT(combo), RT_NULL);
|
||||
|
||||
rtgui_win_hiden(pd_win);
|
||||
rtgui_widget_update(RTGUI_WIDGET(combo));
|
||||
|
||||
return ;
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_combobox_pdwin_ondeactive(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_combobox_pdwin_ondeactive(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
rtgui_win_hiden(RTGUI_WIN(widget));
|
||||
rtgui_win_hiden(RTGUI_WIN(object));
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
|
@ -186,9 +191,14 @@ static rt_bool_t rtgui_combobox_onmouse_button(struct rtgui_combobox* box, struc
|
|||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_combobox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_combobox_event_handler(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_combobox* box = (struct rtgui_combobox*)widget;
|
||||
struct rtgui_combobox *box;
|
||||
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
box = RTGUI_COMBOBOX(object);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
|
@ -224,9 +234,16 @@ rt_bool_t rtgui_combobox_event_handler(struct rtgui_widget* widget, struct rtgui
|
|||
return RT_FALSE;
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_combobox_pulldown_hide(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
static rt_bool_t rtgui_combobox_pulldown_hide(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_combobox* box;
|
||||
struct rtgui_widget *widget;
|
||||
struct rtgui_combobox *box;
|
||||
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
widget = RTGUI_WIDGET(object);
|
||||
box = RTGUI_COMBOBOX(object);
|
||||
|
||||
if (widget == RT_NULL) return RT_TRUE;
|
||||
|
||||
|
@ -253,7 +270,7 @@ struct rtgui_listbox_item* rtgui_combox_get_select(struct rtgui_combobox* box)
|
|||
return RT_NULL;
|
||||
}
|
||||
|
||||
void rtgui_combobox_set_onselected(struct rtgui_combobox* box, rtgui_onitem_func_t func)
|
||||
void rtgui_combobox_set_onselected(struct rtgui_combobox* box, rtgui_event_handler_ptr func)
|
||||
{
|
||||
box->on_selected = func;
|
||||
}
|
||||
|
|
|
@ -10,37 +10,55 @@
|
|||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-16 Bernard first version
|
||||
* 2010-09-24 Bernard fix container destroy issue
|
||||
*/
|
||||
#include <rtgui/widgets/toplevel.h>
|
||||
#include <rtgui/dc.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
#include <rtgui/widgets/container.h>
|
||||
#include <rtgui/widgets/window.h>
|
||||
|
||||
static void _rtgui_container_constructor(rtgui_container_t *container)
|
||||
{
|
||||
/* set event handler and init field */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(container), rtgui_container_event_handler);
|
||||
/* init container */
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(container),
|
||||
rtgui_container_event_handler);
|
||||
|
||||
rtgui_list_init(&(container->children));
|
||||
|
||||
/* set focused widget to itself */
|
||||
container->focused = RTGUI_WIDGET(container);
|
||||
/* set container as focusable widget */
|
||||
RTGUI_WIDGET(container)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
/* container is used to 'contain'(show) widgets and dispatch events to
|
||||
* them, not interact with user. So no need to grab focus. If we did it,
|
||||
* some widget inherited from container(e.g. notebook) will grab the focus
|
||||
* annoyingly.
|
||||
*
|
||||
* For example, a focusable notebook N has a widget W. When the user press
|
||||
* W, N will gain the focus and W will lose it at first. Then N will set
|
||||
* focus to W because it is W that eventually interact with people. N will
|
||||
* yield focus and W will gain the focus again. This loop will make W
|
||||
* repaint twice every time user press it.
|
||||
*
|
||||
* Just eliminate it.
|
||||
*/
|
||||
RTGUI_WIDGET(container)->flag &= ~RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
}
|
||||
|
||||
static void _rtgui_container_destructor(rtgui_container_t *container)
|
||||
{
|
||||
/* destroy children of container */
|
||||
rtgui_container_destroy_children(container);
|
||||
}
|
||||
|
||||
static void _rtgui_container_update_toplevel(rtgui_container_t* container)
|
||||
{
|
||||
struct rtgui_win *window;
|
||||
struct rtgui_list_node* node;
|
||||
|
||||
window = rtgui_widget_get_toplevel(RTGUI_WIDGET(container));
|
||||
|
||||
rtgui_list_foreach(node, &(container->children))
|
||||
{
|
||||
rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling);
|
||||
/* set child toplevel */
|
||||
child->toplevel = rtgui_widget_get_toplevel(RTGUI_WIDGET(container));
|
||||
child->toplevel = window;
|
||||
|
||||
if (RTGUI_IS_CONTAINER(child))
|
||||
{
|
||||
|
@ -65,7 +83,8 @@ rt_bool_t rtgui_container_dispatch_event(rtgui_container_t *container, rtgui_eve
|
|||
struct rtgui_widget* w;
|
||||
w = rtgui_list_entry(node, struct rtgui_widget, sibling);
|
||||
|
||||
if (w->event_handler(w, event) == RT_TRUE) return RT_TRUE;
|
||||
if (RTGUI_OBJECT(w)->event_handler(RTGUI_OBJECT(w), event) == RT_TRUE)
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
|
@ -75,64 +94,106 @@ rt_bool_t rtgui_container_dispatch_mouse_event(rtgui_container_t *container, str
|
|||
{
|
||||
/* handle in child widget */
|
||||
struct rtgui_list_node* node;
|
||||
rtgui_widget_t *focus;
|
||||
struct rtgui_widget *old_focus;
|
||||
|
||||
old_focus = RTGUI_WIDGET(container)->toplevel->focused_widget;
|
||||
|
||||
/* get focus widget on toplevel */
|
||||
focus = RTGUI_CONTAINER(RTGUI_WIDGET(container)->toplevel)->focused;
|
||||
rtgui_list_foreach(node, &(container->children))
|
||||
{
|
||||
struct rtgui_widget* w;
|
||||
w = rtgui_list_entry(node, struct rtgui_widget, sibling);
|
||||
if (rtgui_rect_contains_point(&(w->extent), event->x, event->y) == RT_EOK)
|
||||
if (rtgui_rect_contains_point(&(w->extent),
|
||||
event->x, event->y) == RT_EOK)
|
||||
{
|
||||
if ((focus != w) && RTGUI_WIDGET_IS_FOCUSABLE(w))
|
||||
if ((old_focus != w) && RTGUI_WIDGET_IS_FOCUSABLE(w))
|
||||
rtgui_widget_focus(w);
|
||||
if (w->event_handler(w, (rtgui_event_t*)event) == RT_TRUE) return RT_TRUE;
|
||||
if (RTGUI_OBJECT(w)->event_handler(RTGUI_OBJECT(w),
|
||||
(rtgui_event_t*)event) == RT_TRUE)
|
||||
return RT_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_container_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
|
||||
rt_bool_t rtgui_container_event_handler(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
rtgui_container_t *container = RTGUI_CONTAINER(widget);
|
||||
struct rtgui_container *container;
|
||||
struct rtgui_widget *widget;
|
||||
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
container = RTGUI_CONTAINER(object);
|
||||
widget = RTGUI_WIDGET(object);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
{
|
||||
struct rtgui_dc* dc;
|
||||
struct rtgui_rect rect;
|
||||
|
||||
dc = rtgui_dc_begin_drawing(widget);
|
||||
if (dc == RT_NULL)
|
||||
return RT_FALSE;
|
||||
rtgui_widget_get_rect(widget, &rect);
|
||||
|
||||
/* fill container with background */
|
||||
rtgui_dc_fill_rect(dc, &rect);
|
||||
|
||||
/* paint on each child */
|
||||
rtgui_container_dispatch_event(container, event);
|
||||
|
||||
rtgui_dc_end_drawing(dc);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_KBD:
|
||||
/* let parent to handle keyboard event */
|
||||
if (widget->parent != RT_NULL &&
|
||||
widget->parent != RTGUI_WIDGET(widget->toplevel))
|
||||
{
|
||||
return RTGUI_OBJECT(widget->parent)->event_handler(
|
||||
RTGUI_OBJECT(widget->parent),
|
||||
event);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
case RTGUI_EVENT_MOUSE_MOTION:
|
||||
/* handle in child widget */
|
||||
return rtgui_container_dispatch_mouse_event(container,
|
||||
(struct rtgui_event_mouse*)event);
|
||||
|
||||
case RTGUI_EVENT_COMMAND:
|
||||
case RTGUI_EVENT_RESIZE:
|
||||
rtgui_container_dispatch_event(container, event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_KBD:
|
||||
{
|
||||
/* let parent to handle keyboard event */
|
||||
if (widget->parent != RT_NULL && widget->parent != widget->toplevel)
|
||||
{
|
||||
return widget->parent->event_handler(widget->parent, event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
/* handle in child widget */
|
||||
return rtgui_container_dispatch_mouse_event(container,
|
||||
(struct rtgui_event_mouse*)event);
|
||||
|
||||
case RTGUI_EVENT_MOUSE_MOTION:
|
||||
return rtgui_container_dispatch_mouse_event(container,
|
||||
(struct rtgui_event_mouse*)event);
|
||||
|
||||
default:
|
||||
/* call parent widget event handler */
|
||||
return rtgui_widget_event_handler(widget, event);
|
||||
return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rtgui_container_t* rtgui_container_create(void)
|
||||
{
|
||||
struct rtgui_container* container;
|
||||
|
||||
/* allocate container */
|
||||
container = (struct rtgui_container*) rtgui_widget_create (RTGUI_CONTAINER_TYPE);
|
||||
return container;
|
||||
}
|
||||
|
||||
void rtgui_container_destroy(rtgui_container_t* container)
|
||||
{
|
||||
rtgui_container_hide(container);
|
||||
rtgui_widget_destroy(RTGUI_WIDGET(container));
|
||||
}
|
||||
|
||||
/*
|
||||
* This function will add a child to a container widget
|
||||
* Note: this function will not change the widget layout
|
||||
|
@ -168,13 +229,7 @@ void rtgui_container_remove_child(rtgui_container_t *container, rtgui_widget_t*
|
|||
RT_ASSERT(container != RT_NULL);
|
||||
RT_ASSERT(child != RT_NULL);
|
||||
|
||||
if (child == container->focused)
|
||||
{
|
||||
/* set focused to itself */
|
||||
container->focused = RTGUI_WIDGET(container);
|
||||
|
||||
rtgui_widget_focus(RTGUI_WIDGET(container));
|
||||
}
|
||||
rtgui_widget_unfocus(child);
|
||||
|
||||
/* remove widget from parent's children list */
|
||||
rtgui_list_remove(&(container->children), &(child->sibling));
|
||||
|
@ -218,9 +273,6 @@ void rtgui_container_destroy_children(rtgui_container_t *container)
|
|||
}
|
||||
|
||||
container->children.next = RT_NULL;
|
||||
container->focused = RTGUI_WIDGET(container);
|
||||
if (RTGUI_WIDGET(container)->parent != RT_NULL)
|
||||
rtgui_widget_focus(RTGUI_WIDGET(container));
|
||||
|
||||
/* update widget clip */
|
||||
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(RTGUI_WIDGET(container)->toplevel));
|
||||
|
@ -237,3 +289,26 @@ rtgui_widget_t* rtgui_container_get_first_child(rtgui_container_t* container)
|
|||
|
||||
return child;
|
||||
}
|
||||
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
void rtgui_container_set_box(rtgui_container_t* container, struct rtgui_box* box)
|
||||
{
|
||||
if (container == RT_NULL || box == RT_NULL)
|
||||
return;
|
||||
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(container), RTGUI_WIDGET(box));
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(box), &(RTGUI_WIDGET(container)->extent));
|
||||
}
|
||||
#endif
|
||||
|
||||
void rtgui_container_hide(rtgui_container_t* container)
|
||||
{
|
||||
if (container == RT_NULL) return;
|
||||
|
||||
if (RTGUI_WIDGET(container)->parent == RT_NULL)
|
||||
{
|
||||
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(container));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
#include <rtgui/rtgui_object.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/rtgui_theme.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
|
||||
#include <rtgui/list.h>
|
||||
#include <rtgui/image.h>
|
||||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/widgets/workbench.h>
|
||||
#include <rtgui/widgets/container.h>
|
||||
#include <rtgui/widgets/filelist_view.h>
|
||||
#include <rtgui/widgets/listbox.h>
|
||||
#include <rtgui/widgets/window.h>
|
||||
|
@ -224,9 +224,9 @@ static rtgui_image_t *file_image, *folder_image;
|
|||
static struct rtgui_listbox_item items[] =
|
||||
{
|
||||
#ifdef RTGUI_USING_FONTHZ
|
||||
{"打开文件夹", RT_NULL},
|
||||
{"选择文件夹", RT_NULL},
|
||||
{"退出", RT_NULL}
|
||||
{"ºþôË<EFBFBD>`Á§˜Ë", RT_NULL},
|
||||
{"í¥Œv<EFBFBD>`Á§˜Ë", RT_NULL},
|
||||
{"ØXµÌ", RT_NULL}
|
||||
#else
|
||||
{"Open folder", RT_NULL},
|
||||
{"Select folder", RT_NULL},
|
||||
|
@ -266,10 +266,6 @@ static void rtgui_filelist_view_on_folder_item(rtgui_widget_t* widget, struct rt
|
|||
case 1:
|
||||
/* destroy menu window */
|
||||
rtgui_win_destroy(menu);
|
||||
if (RTGUI_VIEW(view)->modal_show == RT_TRUE)
|
||||
{
|
||||
rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_OK);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -300,7 +296,7 @@ static void rtgui_filelist_view_menu_pop(rtgui_widget_t *parent)
|
|||
rtgui_rect_moveto_align(&screen, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
|
||||
|
||||
menu = rtgui_win_create(RTGUI_TOPLEVEL(rtgui_widget_get_toplevel(parent)),
|
||||
"Folder Menu", &rect, RTGUI_WIN_STYLE_DEFAULT);
|
||||
"Folder Menu", &rect, RTGUI_WIN_STYLE_DEFAULT);
|
||||
if (menu != RT_NULL)
|
||||
{
|
||||
/* set user data on menu window */
|
||||
|
@ -323,7 +319,7 @@ static void _rtgui_filelist_view_constructor(struct rtgui_filelist_view *view)
|
|||
struct rtgui_rect rect = {0, 0, 200, 200};
|
||||
|
||||
/* set default widget rect and set event handler */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), rtgui_filelist_view_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_WIDGET(view), rtgui_filelist_view_event_handler);
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
|
||||
|
||||
RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
|
@ -357,7 +353,7 @@ static void _rtgui_filelist_view_destructor(struct rtgui_filelist_view *view)
|
|||
}
|
||||
|
||||
DEFINE_CLASS_TYPE(filelist, "filelist",
|
||||
RTGUI_VIEW_TYPE,
|
||||
RTGUI_CONTAINER_TYPE,
|
||||
_rtgui_filelist_view_constructor,
|
||||
_rtgui_filelist_view_destructor,
|
||||
sizeof(struct rtgui_filelist_view));
|
||||
|
@ -404,7 +400,6 @@ void rtgui_filelist_view_ondraw(struct rtgui_filelist_view* view)
|
|||
}
|
||||
|
||||
/* draw item */
|
||||
|
||||
if (item->type == RTGUI_FITEM_FILE)
|
||||
rtgui_image_blit(file_image, dc, &image_rect);
|
||||
else
|
||||
|
@ -519,19 +514,13 @@ static void rtgui_filelist_view_onenturn(struct rtgui_filelist_view* view)
|
|||
}
|
||||
else if (view->current_item == 0 &&
|
||||
#ifdef _WIN32
|
||||
(view->current_directory[1] == ':') && (view->current_directory[2] == '\\'))
|
||||
(view->current_directory[1] == ':') && (view->current_directory[2] == '\\')
|
||||
#else
|
||||
(view->current_directory[0] == '/') && (view->current_directory[1] == '\0'))
|
||||
(view->current_directory[0] == '/') && (view->current_directory[1] == '\0')
|
||||
#endif
|
||||
)
|
||||
{
|
||||
if (RTGUI_VIEW(view)->modal_show == RT_TRUE)
|
||||
{
|
||||
rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_CANCEL);
|
||||
}
|
||||
else
|
||||
{
|
||||
rtgui_filelist_view_destroy(view);
|
||||
}
|
||||
rtgui_filelist_view_destroy(view);
|
||||
|
||||
return ;
|
||||
}
|
||||
|
@ -542,13 +531,6 @@ static void rtgui_filelist_view_onenturn(struct rtgui_filelist_view* view)
|
|||
}
|
||||
rtgui_filelist_view_set_directory(view, new_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (RTGUI_VIEW(view)->modal_show == RT_TRUE)
|
||||
{
|
||||
rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_OK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
|
@ -668,11 +650,12 @@ rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_widget* widget, struct
|
|||
}
|
||||
|
||||
/* use view event handler */
|
||||
return rtgui_view_event_handler(widget, event);
|
||||
return rtgui_container_event_handler(widget, event);
|
||||
}
|
||||
|
||||
rtgui_filelist_view_t* rtgui_filelist_view_create(rtgui_workbench_t* workbench,
|
||||
const char* directory, const char* pattern, const rtgui_rect_t* rect)
|
||||
rtgui_filelist_view_t* rtgui_filelist_view_create(const char* directory,
|
||||
const char* pattern,
|
||||
const rtgui_rect_t* rect)
|
||||
{
|
||||
struct rtgui_filelist_view* view = RT_NULL;
|
||||
|
||||
|
@ -684,8 +667,6 @@ rtgui_filelist_view_t* rtgui_filelist_view_create(rtgui_workbench_t* workbench,
|
|||
view->pattern = rt_strdup(pattern);
|
||||
view->page_items = rtgui_rect_height(*rect) / (1 + rtgui_theme_get_selected_height());
|
||||
rtgui_filelist_view_set_directory(view, directory);
|
||||
|
||||
rtgui_workbench_add_view(workbench, RTGUI_VIEW(view));
|
||||
}
|
||||
|
||||
return view;
|
||||
|
@ -778,7 +759,7 @@ void rtgui_filelist_view_set_directory(rtgui_filelist_view_t* view, const char*
|
|||
item = &(view->items[0]);
|
||||
|
||||
/* add .. directory */
|
||||
item->name = rt_strdup("退出文件浏览");
|
||||
item->name = rt_strdup("ØXµÌ<EFBFBD>`Á§ãš”M");
|
||||
item->type = RTGUI_FITEM_DIR;
|
||||
item->size = 0;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ static void _rtgui_iconbox_constructor(rtgui_iconbox_t *iconbox)
|
|||
{
|
||||
/* init widget and set event handler */
|
||||
RTGUI_WIDGET(iconbox)->flag |= RTGUI_WIDGET_FLAG_TRANSPARENT;
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(iconbox), rtgui_iconbox_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(iconbox), rtgui_iconbox_event_handler);
|
||||
|
||||
/* set proper of control */
|
||||
iconbox->image = RT_NULL;
|
||||
|
@ -46,9 +46,14 @@ DEFINE_CLASS_TYPE(iconbox, "iconbox",
|
|||
_rtgui_iconbox_destructor,
|
||||
sizeof(struct rtgui_iconbox));
|
||||
|
||||
rt_bool_t rtgui_iconbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_iconbox_event_handler(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_iconbox* iconbox = (struct rtgui_iconbox*)widget;
|
||||
struct rtgui_iconbox* iconbox;
|
||||
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
iconbox = RTGUI_ICONBOX(object);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
static void _rtgui_label_constructor(rtgui_label_t *label)
|
||||
{
|
||||
/* init widget and set event handler */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(label), rtgui_label_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(label), rtgui_label_event_handler);
|
||||
|
||||
/* set field */
|
||||
label->text = RT_NULL;
|
||||
|
@ -38,13 +38,12 @@ DEFINE_CLASS_TYPE(label, "label",
|
|||
_rtgui_label_destructor,
|
||||
sizeof(struct rtgui_label));
|
||||
|
||||
rt_bool_t rtgui_label_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_label_event_handler(struct rtgui_object *object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_label* label;
|
||||
struct rtgui_label *label;
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
|
||||
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
|
||||
label = (struct rtgui_label*) widget;
|
||||
label = RTGUI_LABEL(object);
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
|
|
|
@ -23,7 +23,7 @@ static void _rtgui_list_view_constructor(struct rtgui_list_view *view)
|
|||
struct rtgui_rect rect = {0, 0, 200, 200};
|
||||
|
||||
/* set default widget rect and set event handler */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view),rtgui_list_view_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(view),rtgui_list_view_event_handler);
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
|
||||
|
||||
RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
|
@ -38,7 +38,7 @@ static void _rtgui_list_view_constructor(struct rtgui_list_view *view)
|
|||
}
|
||||
|
||||
DEFINE_CLASS_TYPE(listview, "listview",
|
||||
RTGUI_VIEW_TYPE,
|
||||
RTGUI_CONTAINER_TYPE,
|
||||
_rtgui_list_view_constructor,
|
||||
RT_NULL,
|
||||
sizeof(struct rtgui_list_view));
|
||||
|
@ -96,7 +96,7 @@ static void rtgui_list_view_onicondraw(struct rtgui_list_view* view, struct rtgu
|
|||
}
|
||||
}
|
||||
|
||||
static void rtgui_list_view_update_icon(struct rtgui_list_view* view, rt_int16_t old_item)
|
||||
static void rtgui_list_view_update_icon(struct rtgui_list_view* view, rt_uint16_t old_item)
|
||||
{
|
||||
struct rtgui_rect rect, item_rect, drawing_rect;
|
||||
rt_ubase_t c, r; /* col and row index */
|
||||
|
@ -230,7 +230,7 @@ static void rtgui_list_view_onlistdraw(struct rtgui_list_view* view, struct rtgu
|
|||
}
|
||||
}
|
||||
|
||||
void rtgui_list_view_update_list(struct rtgui_list_view* view, rt_int16_t old_item)
|
||||
void rtgui_list_view_update_list(struct rtgui_list_view* view, rt_uint16_t old_item)
|
||||
{
|
||||
struct rtgui_dc* dc;
|
||||
const struct rtgui_list_item* item;
|
||||
|
@ -419,7 +419,7 @@ static rt_bool_t rtgui_list_view_onmouse(struct rtgui_list_view* view, struct rt
|
|||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_list_view_event_handler(struct rtgui_object* widget, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_list_view* view = RT_NULL;
|
||||
|
||||
|
@ -562,7 +562,7 @@ rt_bool_t rtgui_list_view_event_handler(struct rtgui_widget* widget, struct rtgu
|
|||
}
|
||||
|
||||
/* use view event handler */
|
||||
return rtgui_view_event_handler(widget, event);
|
||||
return rtgui_container_event_handler(widget, event);
|
||||
}
|
||||
|
||||
static void rtgui_list_view_calc(struct rtgui_list_view* view)
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
static void _rtgui_listbox_constructor(struct rtgui_listbox *box)
|
||||
{
|
||||
/* set default widget rect and set event handler */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(box),rtgui_listbox_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_listbox_event_handler);
|
||||
|
||||
RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
|
||||
|
@ -172,11 +172,12 @@ static void rtgui_listbox_update_current(struct rtgui_listbox* box, rt_int16_t o
|
|||
rtgui_dc_end_drawing(dc);
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_listbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_listbox_event_handler(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_listbox* box = RT_NULL;
|
||||
struct rtgui_listbox* box;
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
|
||||
|
||||
box = RTGUI_LISTBOX(widget);
|
||||
box = RTGUI_LISTBOX(object);
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
|
@ -250,7 +251,7 @@ rt_bool_t rtgui_listbox_event_handler(struct rtgui_widget* widget, struct rtgui_
|
|||
/* up event */
|
||||
if (box->on_item != RT_NULL)
|
||||
{
|
||||
box->on_item(RTGUI_WIDGET(box), RT_NULL);
|
||||
box->on_item(RTGUI_OBJECT(box), RT_NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -309,7 +310,7 @@ rt_bool_t rtgui_listbox_event_handler(struct rtgui_widget* widget, struct rtgui_
|
|||
case RTGUIK_RETURN:
|
||||
if (box->on_item != RT_NULL)
|
||||
{
|
||||
box->on_item(RTGUI_WIDGET(box), RT_NULL);
|
||||
box->on_item(RTGUI_OBJECT(box), RT_NULL);
|
||||
}
|
||||
return RT_FALSE;
|
||||
|
||||
|
@ -322,7 +323,7 @@ rt_bool_t rtgui_listbox_event_handler(struct rtgui_widget* widget, struct rtgui_
|
|||
}
|
||||
|
||||
/* use box event handler */
|
||||
return rtgui_widget_event_handler(widget, event);
|
||||
return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
|
||||
}
|
||||
|
||||
rtgui_listbox_t* rtgui_listbox_create(const struct rtgui_listbox_item* items, rt_uint16_t count, rtgui_rect_t *rect)
|
||||
|
@ -349,7 +350,7 @@ void rtgui_listbox_destroy(rtgui_listbox_t* box)
|
|||
rtgui_widget_destroy(RTGUI_WIDGET(box));
|
||||
}
|
||||
|
||||
void rtgui_listbox_set_onitem(rtgui_listbox_t* box, rtgui_onitem_func_t func)
|
||||
void rtgui_listbox_set_onitem(rtgui_listbox_t* box, rtgui_event_handler_ptr func)
|
||||
{
|
||||
RT_ASSERT(box != RT_NULL);
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ static void rtgui_listctrl_update_current(struct rtgui_listctrl* ctrl, rt_uint16
|
|||
static void _rtgui_listctrl_constructor(struct rtgui_listctrl *ctrl)
|
||||
{
|
||||
/* set default widget rect and set event handler */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(ctrl),rtgui_listctrl_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(ctrl), rtgui_listctrl_event_handler);
|
||||
|
||||
RTGUI_WIDGET(ctrl)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
|
||||
|
@ -206,11 +206,12 @@ void rtgui_listctrl_update_current(struct rtgui_listctrl* ctrl, rt_uint16_t old_
|
|||
rtgui_dc_end_drawing(dc);
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_listctrl_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_listctrl* ctrl = RT_NULL;
|
||||
struct rtgui_listctrl* ctrl;
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
|
||||
|
||||
ctrl = RTGUI_LISTCTRL(widget);
|
||||
ctrl = RTGUI_LISTCTRL(object);
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
|
@ -292,7 +293,7 @@ rt_bool_t rtgui_listctrl_event_handler(struct rtgui_widget* widget, struct rtgui
|
|||
/* up event */
|
||||
if (ctrl->on_item != RT_NULL)
|
||||
{
|
||||
ctrl->on_item(RTGUI_WIDGET(ctrl), RT_NULL);
|
||||
ctrl->on_item(RTGUI_OBJECT(ctrl), RT_NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -343,7 +344,7 @@ rt_bool_t rtgui_listctrl_event_handler(struct rtgui_widget* widget, struct rtgui
|
|||
case RTGUIK_RETURN:
|
||||
if (ctrl->on_item != RT_NULL)
|
||||
{
|
||||
ctrl->on_item(RTGUI_WIDGET(ctrl), RT_NULL);
|
||||
ctrl->on_item(RTGUI_OBJECT(ctrl), RT_NULL);
|
||||
}
|
||||
return RT_FALSE;
|
||||
|
||||
|
@ -356,7 +357,7 @@ rt_bool_t rtgui_listctrl_event_handler(struct rtgui_widget* widget, struct rtgui
|
|||
}
|
||||
|
||||
/* use ctrl event handler */
|
||||
return rtgui_widget_event_handler(widget, event);
|
||||
return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
|
||||
}
|
||||
|
||||
rtgui_listctrl_t* rtgui_listctrl_create(rt_uint32_t items, rt_uint16_t count, rtgui_rect_t *rect,
|
||||
|
@ -384,7 +385,7 @@ void rtgui_listctrl_destroy(rtgui_listctrl_t* ctrl)
|
|||
rtgui_widget_destroy(RTGUI_WIDGET(ctrl));
|
||||
}
|
||||
|
||||
void rtgui_listctrl_set_onitem(rtgui_listctrl_t* ctrl, rtgui_onitem_func_t func)
|
||||
void rtgui_listctrl_set_onitem(rtgui_listctrl_t* ctrl, rtgui_event_handler_ptr func)
|
||||
{
|
||||
RT_ASSERT(ctrl != RT_NULL);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <rtgui/widgets/menu.h>
|
||||
#include <rtgui/rtgui_theme.h>
|
||||
|
||||
static rt_bool_t rtgui_menu_on_deactivate(rtgui_widget_t* widget, rtgui_event_t* event);
|
||||
static rt_bool_t rtgui_menu_on_deactivate(struct rtgui_object* object, rtgui_event_t* event);
|
||||
const static rt_uint8_t right_arrow[] = {0x80, 0xc0, 0xe0, 0xf0, 0xe0, 0xc0, 0x80};
|
||||
|
||||
static void _rtgui_menu_constructor(rtgui_menu_t *menu)
|
||||
|
@ -37,9 +37,10 @@ static void _rtgui_menu_destructor(rtgui_menu_t* menu)
|
|||
menu->items_list = RT_NULL;
|
||||
}
|
||||
|
||||
static void _rtgui_menu_onitem(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
static rt_bool_t _rtgui_menu_onitem(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_menu* menu;
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
|
||||
|
||||
/* get menu */
|
||||
menu = RTGUI_MENU(rtgui_widget_get_toplevel(widget));
|
||||
|
@ -59,13 +60,13 @@ static void _rtgui_menu_onitem(struct rtgui_widget* widget, struct rtgui_event*
|
|||
{
|
||||
/* hide this sub menu */
|
||||
rtgui_win_hiden(RTGUI_WIN(menu->sub_menu));
|
||||
return;
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
/* show this sub menu */
|
||||
rtgui_listctrl_get_item_rect(menu->items_list, menu->items_list->current_item, &item_rect);
|
||||
rtgui_menu_pop(menu->sub_menu, item_rect.x2, item_rect.y1);
|
||||
return;
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
/* delete sub menu */
|
||||
|
@ -92,9 +93,13 @@ static void _rtgui_menu_onitem(struct rtgui_widget* widget, struct rtgui_event*
|
|||
}
|
||||
rtgui_menu_hiden(menu);
|
||||
}
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
static void _rtgui_menu_item_ondraw(struct rtgui_listctrl *list, struct rtgui_dc* dc, rtgui_rect_t* rect, rt_uint16_t index)
|
||||
static void _rtgui_menu_item_ondraw(struct rtgui_listctrl *list,
|
||||
struct rtgui_dc* dc,
|
||||
rtgui_rect_t* rect,
|
||||
rt_uint16_t index)
|
||||
{
|
||||
rtgui_rect_t item_rect;
|
||||
struct rtgui_menu_item* item;
|
||||
|
@ -148,31 +153,37 @@ DEFINE_CLASS_TYPE(menu, "menu",
|
|||
_rtgui_menu_destructor,
|
||||
sizeof(struct rtgui_menu));
|
||||
|
||||
static rt_bool_t rtgui_menu_on_deactivate(rtgui_widget_t* widget, rtgui_event_t* event)
|
||||
static rt_bool_t rtgui_menu_on_deactivate(struct rtgui_object *object, rtgui_event_t* event)
|
||||
{
|
||||
rtgui_menu_t* menu = (rtgui_menu_t*) widget;
|
||||
rtgui_menu_t* menu;
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
|
||||
|
||||
menu = RTGUI_MENU(object);
|
||||
if (menu->parent_menu != RT_NULL)
|
||||
{
|
||||
/* whether click on parent menu */
|
||||
if (rtgui_win_is_activated(RTGUI_WIN(menu->parent_menu)) == RT_TRUE &&
|
||||
menu->parent_menu->items[menu->parent_menu->items_list->current_item].submenu == (struct rtgui_menu_item_t *)menu->items)
|
||||
menu->parent_menu->items[menu->parent_menu->items_list->current_item].submenu
|
||||
== (struct rtgui_menu_item_t *)menu->items)
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
/* submenu is activate */
|
||||
if (menu->items[menu->items_list->current_item].type == RTGUI_ITEM_SUBMENU)
|
||||
{
|
||||
/* if sub menu activated, not hide menu */
|
||||
/* if sub menu activated, not hide menu. But we cannot use the
|
||||
* activated flag as criteria since the old window is deactivated
|
||||
* before the new window got activated. But the window will be shown in
|
||||
* this context, so use 'is not hide'. */
|
||||
if (menu->sub_menu != RT_NULL &&
|
||||
rtgui_win_is_activated(RTGUI_WIN(menu->sub_menu)) == RT_TRUE)
|
||||
!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(menu->sub_menu)))
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
rtgui_win_hiden(RTGUI_WIN(menu));
|
||||
if (menu->on_menuhide != RT_NULL)
|
||||
{
|
||||
menu->on_menuhide(RTGUI_WIDGET(menu), RT_NULL);
|
||||
menu->on_menuhide(RTGUI_OBJECT(menu), RT_NULL);
|
||||
}
|
||||
|
||||
/* un-select item */
|
||||
|
@ -182,14 +193,14 @@ static rt_bool_t rtgui_menu_on_deactivate(rtgui_widget_t* widget, rtgui_event_t*
|
|||
if (menu->parent_menu != RT_NULL &&
|
||||
rtgui_win_is_activated(RTGUI_WIN(menu->parent_menu)) == RT_FALSE)
|
||||
{
|
||||
rtgui_menu_on_deactivate(RTGUI_WIDGET(menu->parent_menu), event);
|
||||
rtgui_menu_on_deactivate(RTGUI_OBJECT(menu->parent_menu), event);
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
struct rtgui_menu* rtgui_menu_create(const char* title, struct rtgui_menu* parent_menu,
|
||||
const struct rtgui_menu_item* items, rt_uint16_t count)
|
||||
const struct rtgui_menu_item* items, rt_uint16_t count)
|
||||
{
|
||||
rtgui_rect_t rect = {0, 0, 100, 100};
|
||||
struct rtgui_menu* menu;
|
||||
|
@ -238,7 +249,8 @@ void rtgui_menu_pop(struct rtgui_menu* menu, int x, int y)
|
|||
rtgui_rect_t rect;
|
||||
struct rtgui_event_resize eresize;
|
||||
|
||||
if (menu == RT_NULL) return;
|
||||
if (menu == RT_NULL)
|
||||
return;
|
||||
|
||||
/* set window extent */
|
||||
rect.x1 = 0; rect.y1 = 0;
|
||||
|
@ -251,12 +263,12 @@ void rtgui_menu_pop(struct rtgui_menu* menu, int x, int y)
|
|||
eresize.parent.type = RTGUI_EVENT_RESIZE;
|
||||
eresize.x = rect.x1; eresize.y = rect.y1;
|
||||
eresize.h = rect.y2 - rect.y1; eresize.w = rect.x2 - rect.x1;
|
||||
rtgui_listctrl_event_handler(RTGUI_WIDGET(menu->items_list), &(eresize.parent));
|
||||
rtgui_listctrl_event_handler(RTGUI_OBJECT(menu->items_list), &(eresize.parent));
|
||||
|
||||
/* on menu pop handler */
|
||||
if (menu->on_menupop != RT_NULL)
|
||||
{
|
||||
menu->on_menupop(RTGUI_WIDGET(menu), RT_NULL);
|
||||
menu->on_menupop(RTGUI_OBJECT(menu), RT_NULL);
|
||||
}
|
||||
|
||||
/* show menu window */
|
||||
|
|
|
@ -5,21 +5,27 @@
|
|||
|
||||
#define RTGUI_NOTEBOOK_TAB_WIDTH 80
|
||||
|
||||
static void _rtgui_notebook_get_bar_rect(rtgui_notebook_t *notebook, struct rtgui_rect* rect);
|
||||
static void _rtgui_notebook_get_page_rect(rtgui_notebook_t *notebook, struct rtgui_rect* rect);
|
||||
|
||||
static void _rtgui_notebook_constructor(rtgui_notebook_t *notebook)
|
||||
struct rtgui_notebook_tab
|
||||
{
|
||||
notebook->flag = 0;
|
||||
notebook->childs = RT_NULL;
|
||||
notebook->count = 0;
|
||||
notebook->current = RTGUI_NOT_FOUND;
|
||||
struct rtgui_widget *widget;
|
||||
char *title;
|
||||
};
|
||||
|
||||
static void _rtgui_notebook_get_bar_rect(struct rtgui_notebook *notebook, struct rtgui_rect* rect);
|
||||
static void _rtgui_notebook_get_page_rect(struct rtgui_notebook *notebook, struct rtgui_rect* rect);
|
||||
|
||||
static void _rtgui_notebook_constructor(struct rtgui_notebook *notebook)
|
||||
{
|
||||
notebook->flag = 0;
|
||||
notebook->childs = RT_NULL;
|
||||
notebook->count = 0;
|
||||
notebook->current = 0;
|
||||
|
||||
RTGUI_WIDGET(notebook)->gc.textalign = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(notebook), rtgui_notebook_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(notebook), rtgui_notebook_event_handler);
|
||||
}
|
||||
|
||||
static void _rtgui_notebook_destructor(rtgui_notebook_t *notebook)
|
||||
static void _rtgui_notebook_destructor(struct rtgui_notebook *notebook)
|
||||
{
|
||||
int index;
|
||||
|
||||
|
@ -35,6 +41,12 @@ static void _rtgui_notebook_destructor(rtgui_notebook_t *notebook)
|
|||
}
|
||||
}
|
||||
|
||||
DEFINE_CLASS_TYPE(notebook, "notebook",
|
||||
RTGUI_WIDGET_TYPE,
|
||||
_rtgui_notebook_constructor,
|
||||
_rtgui_notebook_destructor,
|
||||
sizeof(struct rtgui_notebook));
|
||||
|
||||
/* Draw tab bars of @param notebook. @param dc should be initialized and
|
||||
* finished outside this function. Don't pass @param notebook or @param dc as
|
||||
* RT_NULL, it should be checked outside.
|
||||
|
@ -47,6 +59,9 @@ static void _rtgui_notebook_draw_bar(struct rtgui_notebook *notebook,
|
|||
|
||||
RT_ASSERT((notebook != RT_NULL) && (dc != RT_NULL));
|
||||
|
||||
if (notebook->flag & RTGUI_NOTEBOOK_NOTAB)
|
||||
return;
|
||||
|
||||
_rtgui_notebook_get_bar_rect(notebook, &rect);
|
||||
rtgui_dc_fill_rect(dc, &rect);
|
||||
|
||||
|
@ -66,7 +81,7 @@ static void _rtgui_notebook_draw_bar(struct rtgui_notebook *notebook,
|
|||
|
||||
}
|
||||
|
||||
static void _rtgui_notebook_ondraw(rtgui_notebook_t *notebook)
|
||||
static void _rtgui_notebook_ondraw(struct rtgui_notebook *notebook)
|
||||
{
|
||||
struct rtgui_dc* dc;
|
||||
|
||||
|
@ -92,7 +107,7 @@ static void _rtgui_notebook_ondraw(rtgui_notebook_t *notebook)
|
|||
rtgui_dc_end_drawing(dc);
|
||||
}
|
||||
|
||||
static void _rtgui_notebook_onmouse(rtgui_notebook_t *notebook, struct rtgui_event_mouse* emouse)
|
||||
static void _rtgui_notebook_onmouse(struct rtgui_notebook *notebook, struct rtgui_event_mouse* emouse)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
|
||||
|
@ -120,92 +135,89 @@ static void _rtgui_notebook_onmouse(rtgui_notebook_t *notebook, struct rtgui_eve
|
|||
}
|
||||
else
|
||||
{
|
||||
/* handle on page */
|
||||
if (notebook->childs[notebook->current].widget->event_handler != RT_NULL)
|
||||
notebook->childs[notebook->current].widget->event_handler(
|
||||
notebook->childs[notebook->current].widget,
|
||||
/* handle on page */
|
||||
if (RTGUI_OBJECT(notebook->childs[notebook->current].widget)->event_handler != RT_NULL)
|
||||
RTGUI_OBJECT(notebook->childs[notebook->current].widget)->event_handler(
|
||||
RTGUI_OBJECT(notebook->childs[notebook->current].widget),
|
||||
&(emouse->parent));
|
||||
}
|
||||
}
|
||||
|
||||
static void _rtgui_notebook_get_page_rect(rtgui_notebook_t *notebook, struct rtgui_rect* rect)
|
||||
static void _rtgui_notebook_get_page_rect(struct rtgui_notebook *notebook, struct rtgui_rect* rect)
|
||||
{
|
||||
RT_ASSERT(notebook != RT_NULL);
|
||||
RT_ASSERT(rect != RT_NULL);
|
||||
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(notebook), rect);
|
||||
|
||||
if (notebook->flag == RTGUI_NOTEBOOK_NOTAB) return;
|
||||
if (notebook->flag == RTGUI_NOTEBOOK_NOTAB)
|
||||
return;
|
||||
else if (notebook->flag == RTGUI_NOTEBOOK_TOP)
|
||||
rect->y1 = rect->y1 + 25;
|
||||
else if (notebook->flag == RTGUI_NOTEBOOK_BOTTOM)
|
||||
rect->y2 = rect->y2 - 25;
|
||||
}
|
||||
|
||||
static void _rtgui_notebook_get_bar_rect(rtgui_notebook_t *notebook, struct rtgui_rect* rect)
|
||||
static void _rtgui_notebook_get_bar_rect(struct rtgui_notebook *notebook, struct rtgui_rect* rect)
|
||||
{
|
||||
RT_ASSERT(notebook != RT_NULL);
|
||||
RT_ASSERT(rect != RT_NULL);
|
||||
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(notebook), rect);
|
||||
if (notebook->flag == RTGUI_NOTEBOOK_NOTAB) return;
|
||||
if (notebook->flag == RTGUI_NOTEBOOK_NOTAB)
|
||||
{
|
||||
rect->x1 = rect->y1 = rect->x2 = rect->y2 = 0;
|
||||
}
|
||||
else if (notebook->flag == RTGUI_NOTEBOOK_TOP)
|
||||
rect->y2 = rect->y1 + 25;
|
||||
else if (notebook->flag == RTGUI_NOTEBOOK_BOTTOM)
|
||||
rect->y1 = rect->y2 - 25;
|
||||
}
|
||||
|
||||
DEFINE_CLASS_TYPE(notebook, "notebook",
|
||||
RTGUI_CONTAINER_TYPE,
|
||||
_rtgui_notebook_constructor,
|
||||
_rtgui_notebook_destructor,
|
||||
sizeof(struct rtgui_notebook));
|
||||
|
||||
rtgui_notebook_tab_t *tabs;
|
||||
struct rtgui_notebook *_notebook;
|
||||
rtgui_notebook_t* rtgui_notebook_create(const rtgui_rect_t* rect, rt_uint8_t style)
|
||||
struct rtgui_notebook* rtgui_notebook_create(const rtgui_rect_t* rect, rt_uint8_t style)
|
||||
{
|
||||
struct rtgui_notebook* notebook;
|
||||
|
||||
notebook = (struct rtgui_notebook*) rtgui_widget_create (RTGUI_NOTEBOOK_TYPE);
|
||||
notebook = (struct rtgui_notebook*) rtgui_widget_create(RTGUI_NOTEBOOK_TYPE);
|
||||
if (notebook != RT_NULL)
|
||||
{
|
||||
notebook->flag = style;
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(notebook), rect);
|
||||
}
|
||||
|
||||
_notebook = notebook;
|
||||
return notebook;
|
||||
}
|
||||
|
||||
void rtgui_notebook_destroy(rtgui_notebook_t* notebook)
|
||||
void rtgui_notebook_destroy(struct rtgui_notebook* notebook)
|
||||
{
|
||||
rtgui_widget_destroy(RTGUI_WIDGET(notebook));
|
||||
}
|
||||
|
||||
void rtgui_notebook_add(rtgui_notebook_t* notebook, const char* label, rtgui_widget_t* child)
|
||||
void rtgui_notebook_add(struct rtgui_notebook* notebook, const char* label, struct rtgui_widget* child)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
RT_ASSERT(notebook != RT_NULL);
|
||||
|
||||
notebook->count += 1;
|
||||
notebook->childs = (struct rtgui_notebook_tab*) rtgui_realloc(notebook->childs,
|
||||
sizeof(struct rtgui_notebook_tab) * notebook->count);
|
||||
notebook->childs = (struct rtgui_notebook_tab*)
|
||||
rtgui_realloc(notebook->childs,
|
||||
sizeof(struct rtgui_notebook_tab) * notebook->count);
|
||||
|
||||
notebook->childs[notebook->count - 1].title = rt_strdup(label);
|
||||
notebook->childs[notebook->count - 1].widget = child;
|
||||
|
||||
tabs = notebook->childs;
|
||||
|
||||
/* set parent */
|
||||
rtgui_widget_set_parent(child, RTGUI_WIDGET(notebook));
|
||||
|
||||
_rtgui_notebook_get_page_rect(notebook, &rect);
|
||||
rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
|
||||
rtgui_widget_set_rect(child, &rect);
|
||||
|
||||
if (notebook->count - 1 != notebook->current)
|
||||
rtgui_widget_hide(child);
|
||||
}
|
||||
|
||||
void rtgui_notebook_remove(rtgui_notebook_t* notebook, rt_uint16_t index)
|
||||
void rtgui_notebook_remove(struct rtgui_notebook* notebook, rt_uint16_t index)
|
||||
{
|
||||
struct rtgui_notebook_tab tab;
|
||||
RT_ASSERT(notebook != RT_NULL);
|
||||
|
@ -232,6 +244,7 @@ void rtgui_notebook_remove(rtgui_notebook_t* notebook, rt_uint16_t index)
|
|||
sizeof(struct rtgui_notebook_tab) * notebook->count);
|
||||
}
|
||||
|
||||
// FIXME: do we really want to destroy it?
|
||||
rtgui_widget_destroy(tab.widget);
|
||||
rtgui_free(tab.title);
|
||||
|
||||
|
@ -245,12 +258,13 @@ void rtgui_notebook_remove(rtgui_notebook_t* notebook, rt_uint16_t index)
|
|||
}
|
||||
}
|
||||
|
||||
int rtgui_notebook_get_count(rtgui_notebook_t* notebook)
|
||||
int rtgui_notebook_get_count(struct rtgui_notebook* notebook)
|
||||
{
|
||||
RT_ASSERT(notebook != RT_NULL);
|
||||
return notebook->count;
|
||||
}
|
||||
|
||||
rtgui_widget_t* rtgui_notebook_get_current(rtgui_notebook_t* notebook)
|
||||
struct rtgui_widget* rtgui_notebook_get_current(struct rtgui_notebook* notebook)
|
||||
{
|
||||
RT_ASSERT(notebook != RT_NULL);
|
||||
if (notebook->current != RTGUI_NOT_FOUND)
|
||||
|
@ -258,7 +272,14 @@ rtgui_widget_t* rtgui_notebook_get_current(rtgui_notebook_t* notebook)
|
|||
|
||||
return RT_NULL;
|
||||
}
|
||||
void rtgui_notebook_set_current(rtgui_notebook_t* notebook, rtgui_widget_t* widget)
|
||||
|
||||
rt_int16_t rtgui_notebook_get_current_index(struct rtgui_notebook* notebook)
|
||||
{
|
||||
RT_ASSERT(notebook != RT_NULL);
|
||||
return notebook->current;
|
||||
}
|
||||
|
||||
void rtgui_notebook_set_current(struct rtgui_notebook* notebook, struct rtgui_widget* widget)
|
||||
{
|
||||
rt_int16_t index;
|
||||
|
||||
|
@ -274,7 +295,7 @@ void rtgui_notebook_set_current(rtgui_notebook_t* notebook, rtgui_widget_t* widg
|
|||
}
|
||||
}
|
||||
|
||||
void rtgui_notebook_set_current_by_index(rtgui_notebook_t* notebook, rt_uint16_t index)
|
||||
void rtgui_notebook_set_current_by_index(struct rtgui_notebook* notebook, rt_uint16_t index)
|
||||
{
|
||||
RT_ASSERT(notebook != RT_NULL);
|
||||
|
||||
|
@ -289,7 +310,7 @@ void rtgui_notebook_set_current_by_index(rtgui_notebook_t* notebook, rt_uint16_t
|
|||
}
|
||||
}
|
||||
|
||||
rtgui_widget_t* rtgui_notebook_get_index(rtgui_notebook_t* notebook, rt_uint16_t index)
|
||||
struct rtgui_widget* rtgui_notebook_get_widget_at(struct rtgui_notebook* notebook, rt_uint16_t index)
|
||||
{
|
||||
RT_ASSERT(notebook != RT_NULL);
|
||||
if (index < notebook->count)
|
||||
|
@ -298,32 +319,37 @@ rtgui_widget_t* rtgui_notebook_get_index(rtgui_notebook_t* notebook, rt_uint16_t
|
|||
return RT_NULL;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_notebook_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_notebook_event_handler(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_notebook* notebook;
|
||||
|
||||
notebook = RTGUI_NOTEBOOK(widget);
|
||||
if (event->type == RTGUI_EVENT_PAINT)
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
notebook = RTGUI_NOTEBOOK(object);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
_rtgui_notebook_ondraw(notebook);
|
||||
}
|
||||
else if (event->type == RTGUI_EVENT_MOUSE_BUTTON)
|
||||
{
|
||||
break;
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
_rtgui_notebook_onmouse(notebook, (struct rtgui_event_mouse*)event);
|
||||
}
|
||||
else if (event->type == RTGUI_EVENT_KBD)
|
||||
{
|
||||
break;
|
||||
case RTGUI_EVENT_KBD:
|
||||
if (notebook->current != RTGUI_NOT_FOUND)
|
||||
{
|
||||
if (notebook->childs[notebook->current].widget->event_handler != RT_NULL)
|
||||
return notebook->childs[notebook->current].widget->event_handler(notebook->childs[notebook->current].widget,
|
||||
event);
|
||||
if (RTGUI_OBJECT(notebook->childs[notebook->current].widget
|
||||
)->event_handler != RT_NULL)
|
||||
return RTGUI_OBJECT(notebook->childs[notebook->current].widget
|
||||
)->event_handler(
|
||||
RTGUI_OBJECT(notebook->childs[notebook->current].widget),
|
||||
event);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
default:
|
||||
/* use parent event handler */
|
||||
return rtgui_widget_event_handler(widget, event);
|
||||
return rtgui_widget_event_handler(object, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
|
|
|
@ -8,7 +8,7 @@ static void _rtgui_progressbar_constructor(rtgui_progressbar_t *bar)
|
|||
{
|
||||
rtgui_rect_t rect = {0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT};
|
||||
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(bar), rtgui_progressbar_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(bar), rtgui_progressbar_event_handler);
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(bar), &rect);
|
||||
|
||||
bar->orient = RTGUI_HORIZONTAL;
|
||||
|
@ -25,10 +25,13 @@ DEFINE_CLASS_TYPE(progressbar, "progressbar",
|
|||
RT_NULL,
|
||||
sizeof(struct rtgui_progressbar));
|
||||
|
||||
rt_bool_t rtgui_progressbar_event_handler(struct rtgui_widget* widget,
|
||||
rt_bool_t rtgui_progressbar_event_handler(struct rtgui_object* object,
|
||||
struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_progressbar* bar = (struct rtgui_progressbar*)widget;
|
||||
struct rtgui_progressbar* bar;
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
|
||||
|
||||
bar = RTGUI_PROGRESSBAR(object);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ static void _rtgui_radiobox_constructor(rtgui_radiobox_t *radiobox)
|
|||
RTGUI_WIDGET(radiobox)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(radiobox)) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(radiobox), rtgui_radiobox_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(radiobox), rtgui_radiobox_event_handler);
|
||||
|
||||
/* set proper of control */
|
||||
radiobox->items = RT_NULL;
|
||||
|
@ -76,10 +76,12 @@ static void rtgui_radiobox_onmouse(struct rtgui_radiobox* radiobox, struct rtgui
|
|||
}
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_radiobox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_radiobox_event_handler(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_radiobox* radiobox = (struct rtgui_radiobox*)widget;
|
||||
struct rtgui_radiobox* radiobox;
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
|
||||
|
||||
radiobox = RTGUI_RADIOBOX(object);
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
|
|
|
@ -20,7 +20,7 @@ static void _rtgui_scrollbar_constructor(rtgui_scrollbar_t *bar)
|
|||
struct rtgui_rect rect = {0, 0, RTGUI_DEFAULT_SB_WIDTH, RTGUI_DEFAULT_SB_HEIGHT};
|
||||
|
||||
/* set event handler */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(bar), rtgui_scrollbar_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(bar), rtgui_scrollbar_event_handler);
|
||||
|
||||
rtgui_scrollbar_set_range(bar, 0, 100);
|
||||
rtgui_scrollbar_set_page_step(bar, 20);
|
||||
|
@ -257,14 +257,18 @@ __exit:
|
|||
if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
|
||||
(RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
|
||||
{
|
||||
if (bar->on_scroll != RT_NULL) bar->on_scroll(widget, RT_NULL);
|
||||
if (bar->on_scroll != RT_NULL)
|
||||
bar->on_scroll(RTGUI_OBJECT(widget), RT_NULL);
|
||||
}
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_scrollbar_event_handler(struct rtgui_widget * widget,
|
||||
struct rtgui_event * event)
|
||||
rt_bool_t rtgui_scrollbar_event_handler(struct rtgui_object *object,
|
||||
struct rtgui_event *event)
|
||||
{
|
||||
struct rtgui_scrollbar* bar = (struct rtgui_scrollbar*)widget;
|
||||
struct rtgui_scrollbar* bar;
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
|
||||
|
||||
bar = RTGUI_SCROLLBAR(object);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@ static void _rtgui_slider_constructor(rtgui_slider_t *slider)
|
|||
/* init widget and set event handler */
|
||||
RTGUI_WIDGET(slider)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect);
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(slider), rtgui_slider_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(slider), rtgui_slider_event_handler);
|
||||
|
||||
/* set proper of control */
|
||||
slider->min = RTGUI_SLIDER_DEFAULT_MIN;
|
||||
|
@ -95,34 +95,59 @@ static void rtgui_slider_onmouse(struct rtgui_slider* slider, struct rtgui_event
|
|||
}
|
||||
}
|
||||
|
||||
static void rtgui_slider_onkey(struct rtgui_slider* slider, struct rtgui_event_kbd *event)
|
||||
static rt_bool_t rtgui_slider_onkey(struct rtgui_slider* slider, struct rtgui_event_kbd *event)
|
||||
{
|
||||
RT_ASSERT(slider != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
if (!(RTGUI_KBD_IS_UP(event))) return;
|
||||
if (!(RTGUI_KBD_IS_UP(event)))
|
||||
return RT_TRUE;
|
||||
|
||||
if (event->key == RTGUIK_LEFT)
|
||||
if (slider->orient == RTGUI_HORIZONTAL)
|
||||
{
|
||||
if (slider->value > slider->min)
|
||||
slider->value ++;
|
||||
if (event->key == RTGUIK_RIGHT)
|
||||
{
|
||||
if (slider->value > slider->min)
|
||||
slider->value++;
|
||||
}
|
||||
else if (event->key == RTGUIK_LEFT)
|
||||
{
|
||||
if (slider->value < slider->max)
|
||||
slider->value--;
|
||||
}
|
||||
}
|
||||
|
||||
if (event->key == RTGUIK_RIGHT)
|
||||
else
|
||||
{
|
||||
if (slider->value < slider->max)
|
||||
slider->value --;
|
||||
if (event->key == RTGUIK_UP)
|
||||
{
|
||||
if (slider->value > slider->min)
|
||||
slider->value--;
|
||||
}
|
||||
else if (event->key == RTGUIK_DOWN)
|
||||
{
|
||||
if (slider->value < slider->max)
|
||||
slider->value++;
|
||||
}
|
||||
}
|
||||
|
||||
/* update widget */
|
||||
rtgui_widget_update(RTGUI_WIDGET(slider));
|
||||
if (slider->on_changed != RT_NULL) /* invoke callback function */
|
||||
slider->on_changed(RTGUI_WIDGET(slider), RT_NULL);
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_slider_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_slider_event_handler(struct rtgui_object *object, struct rtgui_event *event)
|
||||
{
|
||||
struct rtgui_slider* slider = (struct rtgui_slider*)widget;
|
||||
struct rtgui_widget *widget;
|
||||
struct rtgui_slider* slider;
|
||||
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
widget = RTGUI_WIDGET(object);
|
||||
slider = RTGUI_SLIDER(object);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
|
@ -145,7 +170,7 @@ rt_bool_t rtgui_slider_event_handler(struct rtgui_widget* widget, struct rtgui_e
|
|||
else
|
||||
#endif
|
||||
{
|
||||
rtgui_slider_onkey(slider, (struct rtgui_event_kbd *)event);
|
||||
return rtgui_slider_onkey(slider, (struct rtgui_event_kbd *)event);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ static void _rtgui_staticline_constructor(rtgui_staticline_t *staticline)
|
|||
rtgui_widget_set_rect(RTGUI_WIDGET(staticline), &rect);
|
||||
staticline->orient= RTGUI_HORIZONTAL;
|
||||
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(staticline), rtgui_staticline_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(staticline), rtgui_staticline_event_handler);
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,12 +20,12 @@ DEFINE_CLASS_TYPE(staticline, "staticline",
|
|||
RT_NULL,
|
||||
sizeof(struct rtgui_staticline));
|
||||
|
||||
rt_bool_t rtgui_staticline_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_staticline_event_handler(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_staticline* staticline;
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
|
||||
|
||||
staticline = (struct rtgui_staticline*) widget;
|
||||
staticline = RTGUI_STATICLINE(object);
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
#define RTGUI_TEXTBOX_MARGIN 3
|
||||
|
||||
static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kbd* event);
|
||||
static rt_bool_t rtgui_textbox_onfocus(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_widget* widget, struct rtgui_event* event);
|
||||
static rt_bool_t rtgui_textbox_onfocus(struct rtgui_object* object, struct rtgui_event* event);
|
||||
static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_object* object, struct rtgui_event* event);
|
||||
|
||||
static void _rtgui_textbox_caret_timeout(struct rtgui_timer* timer, void* parameter)
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ static void _rtgui_textbox_constructor(rtgui_textbox_t *box)
|
|||
rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect);
|
||||
|
||||
RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_textbox_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_textbox_event_handler);
|
||||
rtgui_widget_set_onfocus(RTGUI_WIDGET(box), rtgui_textbox_onfocus);
|
||||
rtgui_widget_set_onunfocus(RTGUI_WIDGET(box), rtgui_textbox_onunfocus);
|
||||
|
||||
|
@ -226,10 +226,12 @@ static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kb
|
|||
rtgui_theme_draw_textbox(box);
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_textbox_onfocus(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
static rt_bool_t rtgui_textbox_onfocus(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_textbox* box = (struct rtgui_textbox*)widget;
|
||||
struct rtgui_textbox* box;
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
|
||||
|
||||
box = RTGUI_TEXTBOX(object);
|
||||
/* set caret to show */
|
||||
box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
|
||||
/* start caret timer */
|
||||
|
@ -238,10 +240,12 @@ static rt_bool_t rtgui_textbox_onfocus(struct rtgui_widget* widget, struct rtgui
|
|||
return RT_TRUE;
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_textbox* box = (struct rtgui_textbox*)widget;
|
||||
struct rtgui_textbox* box;
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
|
||||
|
||||
box = RTGUI_TEXTBOX(object);
|
||||
/* stop caret timer */
|
||||
rtgui_timer_stop(box->caret_timer);
|
||||
/* set caret to hide */
|
||||
|
@ -250,10 +254,12 @@ static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_widget* widget, struct rtg
|
|||
return RT_TRUE;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_textbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_textbox_event_handler(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_textbox* box = (struct rtgui_textbox*)widget;
|
||||
struct rtgui_textbox* box;
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
|
||||
|
||||
box = RTGUI_TEXTBOX(object);
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
|
|
|
@ -222,7 +222,7 @@ static void _draw_textview(rtgui_textview_t *textview)
|
|||
static void _rtgui_textview_constructor(rtgui_textview_t *textview)
|
||||
{
|
||||
/* init widget and set event handler */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(textview), rtgui_textview_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(textview), rtgui_textview_event_handler);
|
||||
RTGUI_WIDGET(textview)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
|
||||
/* set field */
|
||||
|
@ -246,13 +246,12 @@ DEFINE_CLASS_TYPE(textview, "textview",
|
|||
_rtgui_textview_destructor,
|
||||
sizeof(struct rtgui_textview));
|
||||
|
||||
rt_bool_t rtgui_textview_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_textview_event_handler(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_textview* textview;
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE
|
||||
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
|
||||
textview = (struct rtgui_textview*) widget;
|
||||
textview = RTGUI_TEXTVIEW(object);
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
|
|
|
@ -13,26 +13,25 @@
|
|||
*/
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/widgets/toplevel.h>
|
||||
extern void rtgui_topwin_do_clip(rtgui_widget_t* widget);
|
||||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/widgets/title.h>
|
||||
|
||||
static void _rtgui_toplevel_constructor(rtgui_toplevel_t *toplevel)
|
||||
{
|
||||
/* set event handler */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(toplevel), rtgui_toplevel_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(toplevel), rtgui_toplevel_event_handler);
|
||||
|
||||
/* set toplevel to self */
|
||||
RTGUI_WIDGET(toplevel)->toplevel = RTGUI_WIDGET(toplevel);
|
||||
if (RTGUI_IS_WINTITLE(toplevel))
|
||||
RTGUI_WIDGET(toplevel)->toplevel = (struct rtgui_win*)toplevel;
|
||||
else
|
||||
RTGUI_WIDGET(toplevel)->toplevel = RTGUI_WIN(toplevel);
|
||||
|
||||
/* init toplevel property */
|
||||
toplevel->drawing = 0;
|
||||
|
||||
/* hide toplevel default */
|
||||
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(toplevel));
|
||||
|
||||
/* set server as RT_NULL (no connected) */
|
||||
toplevel->server = RT_NULL;
|
||||
/* initialize last mouse event handled widget */
|
||||
toplevel->last_mevent_widget = RT_NULL;
|
||||
}
|
||||
|
||||
static void _rtgui_toplevel_destructor(rtgui_toplevel_t* toplevel)
|
||||
|
@ -47,45 +46,29 @@ DEFINE_CLASS_TYPE(toplevel, "toplevel",
|
|||
_rtgui_toplevel_destructor,
|
||||
sizeof(struct rtgui_toplevel));
|
||||
|
||||
rt_bool_t rtgui_toplevel_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
|
||||
rt_bool_t rtgui_toplevel_event_handler(struct rtgui_object* object, rtgui_event_t* event)
|
||||
{
|
||||
rtgui_toplevel_t* toplevel = (rtgui_toplevel_t*)widget;
|
||||
struct rtgui_toplevel* toplevel;
|
||||
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
toplevel = RTGUI_TOPLEVEL(object);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_KBD:
|
||||
if (RTGUI_CONTAINER(toplevel)->focused != RT_NULL)
|
||||
{
|
||||
RTGUI_CONTAINER(toplevel)->focused->event_handler(RTGUI_CONTAINER(toplevel)->focused, event);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_CLIP_INFO:
|
||||
/* update toplevel clip */
|
||||
rtgui_toplevel_update_clip(toplevel);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_TIMER:
|
||||
{
|
||||
struct rtgui_timer* timer;
|
||||
struct rtgui_event_timer* etimer = (struct rtgui_event_timer*) event;
|
||||
|
||||
timer = etimer->timer;
|
||||
if (timer->timeout != RT_NULL)
|
||||
{
|
||||
/* call timeout function */
|
||||
timer->timeout(timer, timer->user_data);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_COMMAND:
|
||||
if (rtgui_container_dispatch_event(RTGUI_CONTAINER(widget), event) != RT_TRUE)
|
||||
if (rtgui_container_dispatch_event(RTGUI_CONTAINER(object), event) != RT_TRUE)
|
||||
{
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
if (widget->on_command != RT_NULL)
|
||||
if (RTGUI_WIDGET(object)->on_command != RT_NULL)
|
||||
{
|
||||
widget->on_command(widget, event);
|
||||
RTGUI_WIDGET(object)->on_command(object, event);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -93,38 +76,23 @@ rt_bool_t rtgui_toplevel_event_handler(rtgui_widget_t* widget, rtgui_event_t* ev
|
|||
break;
|
||||
|
||||
default :
|
||||
return rtgui_container_event_handler(widget, event);
|
||||
return rtgui_container_event_handler(object, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
#include <rtgui/driver.h> /* to get screen rect */
|
||||
|
||||
void rtgui_toplevel_update_clip(rtgui_toplevel_t* top)
|
||||
{
|
||||
rtgui_container_t* container;
|
||||
rtgui_container_t* view;
|
||||
struct rtgui_list_node* node;
|
||||
rtgui_rect_t screen_rect;
|
||||
|
||||
if (top == RT_NULL) return;
|
||||
|
||||
/* reset toplevel widget clip to extent */
|
||||
rtgui_region_reset(&(RTGUI_WIDGET(top)->clip), &(RTGUI_WIDGET(top)->extent));
|
||||
|
||||
/* subtract the screen rect */
|
||||
screen_rect.x1 = screen_rect.y1 = 0;
|
||||
screen_rect.x2 = rtgui_graphic_driver_get_default()->width;
|
||||
screen_rect.y2 = rtgui_graphic_driver_get_default()->height;
|
||||
rtgui_region_intersect_rect(&(RTGUI_WIDGET(top)->clip), &(RTGUI_WIDGET(top)->clip),
|
||||
&screen_rect);
|
||||
|
||||
/* subtract the external rect */
|
||||
rtgui_topwin_do_clip(RTGUI_WIDGET(top));
|
||||
if (top == RT_NULL)
|
||||
return;
|
||||
|
||||
/* update the clip info of each child */
|
||||
container = RTGUI_CONTAINER(top);
|
||||
rtgui_list_foreach(node, &(container->children))
|
||||
view = RTGUI_CONTAINER(top);
|
||||
rtgui_list_foreach(node, &(view->children))
|
||||
{
|
||||
rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling);
|
||||
|
||||
|
|
|
@ -1,214 +0,0 @@
|
|||
/*
|
||||
* File : view.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-16 Bernard first version
|
||||
* 2010-09-24 Bernard fix view destroy issue
|
||||
*/
|
||||
#include <rtgui/dc.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/widgets/workbench.h>
|
||||
|
||||
static void _rtgui_view_constructor(rtgui_view_t *view)
|
||||
{
|
||||
/* init view */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view),
|
||||
rtgui_view_event_handler);
|
||||
|
||||
view->modal_show = RT_FALSE;
|
||||
view->title = RT_NULL;
|
||||
}
|
||||
|
||||
static void _rtgui_view_destructor(rtgui_view_t *view)
|
||||
{
|
||||
/* remove view from workbench */
|
||||
if (RTGUI_WIDGET(view)->parent != RT_NULL)
|
||||
{
|
||||
rtgui_workbench_t *workbench;
|
||||
|
||||
if (view->modal_show == RT_TRUE)
|
||||
rtgui_view_end_modal(view, RTGUI_MODAL_CANCEL);
|
||||
|
||||
workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent);
|
||||
rtgui_workbench_remove_view(workbench, view);
|
||||
}
|
||||
|
||||
if (view->title != RT_NULL)
|
||||
{
|
||||
rt_free(view->title);
|
||||
view->title = RT_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
DEFINE_CLASS_TYPE(view, "view",
|
||||
RTGUI_CONTAINER_TYPE,
|
||||
_rtgui_view_constructor,
|
||||
_rtgui_view_destructor,
|
||||
sizeof(struct rtgui_view));
|
||||
|
||||
rt_bool_t rtgui_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_view* view = (struct rtgui_view*) widget;
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
{
|
||||
struct rtgui_dc* dc;
|
||||
struct rtgui_rect rect;
|
||||
|
||||
dc = rtgui_dc_begin_drawing(widget);
|
||||
if (dc == RT_NULL) return RT_FALSE;
|
||||
rtgui_widget_get_rect(widget, &rect);
|
||||
|
||||
/* fill view with background */
|
||||
rtgui_dc_fill_rect(dc, &rect);
|
||||
|
||||
/* paint on each child */
|
||||
rtgui_container_dispatch_event(RTGUI_CONTAINER(view), event);
|
||||
|
||||
rtgui_dc_end_drawing(dc);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return rtgui_container_event_handler(widget, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rtgui_view_t* rtgui_view_create(const char* title)
|
||||
{
|
||||
struct rtgui_view* view;
|
||||
|
||||
/* allocate view */
|
||||
view = (struct rtgui_view*) rtgui_widget_create (RTGUI_VIEW_TYPE);
|
||||
if (view != RT_NULL)
|
||||
{
|
||||
if (title != RT_NULL)
|
||||
view->title = rt_strdup(title);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
void rtgui_view_destroy(rtgui_view_t* view)
|
||||
{
|
||||
if (view->modal_show == RT_TRUE)
|
||||
rtgui_view_end_modal(view, RTGUI_MODAL_CANCEL);
|
||||
else
|
||||
{
|
||||
rtgui_view_hide(view);
|
||||
rtgui_widget_destroy(RTGUI_WIDGET(view));
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
void rtgui_view_set_box(rtgui_view_t* view, rtgui_box_t* box)
|
||||
{
|
||||
if (view == RT_NULL ||
|
||||
box == RT_NULL) return;
|
||||
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(box));
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(box), &(RTGUI_WIDGET(view)->extent));
|
||||
}
|
||||
#endif
|
||||
|
||||
rtgui_modal_code_t rtgui_view_show(rtgui_view_t* view, rt_bool_t is_modal)
|
||||
{
|
||||
rtgui_workbench_t* workbench;
|
||||
|
||||
/* parameter check */
|
||||
if (view == RT_NULL) return RTGUI_MODAL_CANCEL;
|
||||
|
||||
if (RTGUI_WIDGET(view)->parent == RT_NULL)
|
||||
{
|
||||
RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(view));
|
||||
return RTGUI_MODAL_CANCEL;
|
||||
}
|
||||
|
||||
workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent);
|
||||
rtgui_workbench_show_view(workbench, view);
|
||||
if (RTGUI_CONTAINER(view)->focused != RT_NULL)
|
||||
rtgui_widget_focus(RTGUI_CONTAINER(view)->focused);
|
||||
else
|
||||
{
|
||||
if (RTGUI_WIDGET_IS_FOCUSABLE(RTGUI_WIDGET(view)))
|
||||
rtgui_widget_focus(RTGUI_WIDGET(view));
|
||||
}
|
||||
|
||||
view->modal_show = is_modal;
|
||||
if (is_modal == RT_TRUE)
|
||||
{
|
||||
/* set modal mode */
|
||||
workbench->flag |= RTGUI_WORKBENCH_FLAG_MODAL_MODE;
|
||||
workbench->modal_widget = RTGUI_WIDGET(view);
|
||||
|
||||
/* perform workbench event loop */
|
||||
rtgui_workbench_event_loop(workbench);
|
||||
|
||||
workbench->modal_widget = RT_NULL;
|
||||
return workbench->modal_code;
|
||||
}
|
||||
|
||||
/* no modal mode, always return modal_ok */
|
||||
return RTGUI_MODAL_OK;
|
||||
}
|
||||
|
||||
void rtgui_view_end_modal(rtgui_view_t* view, rtgui_modal_code_t modal_code)
|
||||
{
|
||||
rtgui_workbench_t* workbench;
|
||||
|
||||
/* parameter check */
|
||||
if ((view == RT_NULL) || (RTGUI_WIDGET(view)->parent == RT_NULL))return ;
|
||||
|
||||
workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent);
|
||||
workbench->modal_code = modal_code;
|
||||
workbench->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE;
|
||||
|
||||
/* remove modal mode */
|
||||
view->modal_show = RT_FALSE;
|
||||
}
|
||||
|
||||
void rtgui_view_hide(rtgui_view_t* view)
|
||||
{
|
||||
if (view == RT_NULL) return;
|
||||
|
||||
if (RTGUI_WIDGET(view)->parent == RT_NULL)
|
||||
{
|
||||
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view));
|
||||
return;
|
||||
}
|
||||
|
||||
rtgui_workbench_hide_view((rtgui_workbench_t*)(RTGUI_WIDGET(view)->parent), view);
|
||||
}
|
||||
|
||||
char* rtgui_view_get_title(rtgui_view_t* view)
|
||||
{
|
||||
RT_ASSERT(view != RT_NULL);
|
||||
|
||||
return view->title;
|
||||
}
|
||||
|
||||
void rtgui_view_set_title(rtgui_view_t* view, const char *title)
|
||||
{
|
||||
RT_ASSERT(view != RT_NULL);
|
||||
|
||||
if (view->title != RT_NULL)
|
||||
{
|
||||
rtgui_free(view->title);
|
||||
|
||||
if (title != RT_NULL) view->title = rt_strdup(title);
|
||||
else view->title = RT_NULL;
|
||||
}
|
||||
}
|
|
@ -14,10 +14,11 @@
|
|||
*/
|
||||
|
||||
#include <rtgui/dc_client.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
#include <rtgui/widgets/widget.h>
|
||||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/widgets/view.h>
|
||||
extern void rtgui_topwin_do_clip(rtgui_widget_t* widget);
|
||||
#include <rtgui/widgets/container.h>
|
||||
#include <rtgui/widgets/notebook.h>
|
||||
|
||||
static void _rtgui_widget_constructor(rtgui_widget_t *widget)
|
||||
{
|
||||
|
@ -40,23 +41,25 @@ static void _rtgui_widget_constructor(rtgui_widget_t *widget)
|
|||
#endif
|
||||
|
||||
/* set parent and toplevel root */
|
||||
widget->parent = RT_NULL;
|
||||
widget->toplevel = RT_NULL;
|
||||
widget->parent = RT_NULL;
|
||||
widget->toplevel = RT_NULL;
|
||||
|
||||
/* some common event handler */
|
||||
widget->on_focus_in = RT_NULL;
|
||||
widget->on_focus_out = RT_NULL;
|
||||
widget->on_focus_in = RT_NULL;
|
||||
widget->on_focus_out = RT_NULL;
|
||||
widget->on_show = RT_NULL;
|
||||
widget->on_hide = RT_NULL;
|
||||
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
widget->on_draw = RT_NULL;
|
||||
widget->on_mouseclick = RT_NULL;
|
||||
widget->on_key = RT_NULL;
|
||||
widget->on_size = RT_NULL;
|
||||
widget->on_command = RT_NULL;
|
||||
widget->on_draw = RT_NULL;
|
||||
widget->on_mouseclick = RT_NULL;
|
||||
widget->on_key = RT_NULL;
|
||||
widget->on_size = RT_NULL;
|
||||
widget->on_command = RT_NULL;
|
||||
#endif
|
||||
|
||||
/* set default event handler */
|
||||
rtgui_widget_set_event_handler(widget,rtgui_widget_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(widget), rtgui_widget_event_handler);
|
||||
|
||||
/* init user data private to 0 */
|
||||
widget->user_data = 0;
|
||||
|
@ -203,13 +206,6 @@ void rtgui_widget_move_to_logic(rtgui_widget_t* widget, int dx, int dy)
|
|||
}
|
||||
}
|
||||
|
||||
void rtgui_widget_set_event_handler(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
|
||||
{
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
|
||||
widget->event_handler = handler;
|
||||
}
|
||||
|
||||
void rtgui_widget_get_rect(rtgui_widget_t* widget, rtgui_rect_t *rect)
|
||||
{
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
|
@ -236,6 +232,20 @@ void rtgui_widget_set_onunfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr
|
|||
widget->on_focus_out = handler;
|
||||
}
|
||||
|
||||
void rtgui_widget_set_onshow(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
|
||||
{
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
|
||||
widget->on_show = handler;
|
||||
}
|
||||
|
||||
void rtgui_widget_set_onhide(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
|
||||
{
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
|
||||
widget->on_hide = handler;
|
||||
}
|
||||
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
void rtgui_widget_set_ondraw(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
|
||||
{
|
||||
|
@ -280,35 +290,28 @@ void rtgui_widget_set_oncommand(rtgui_widget_t* widget, rtgui_event_handler_ptr
|
|||
*/
|
||||
void rtgui_widget_focus(rtgui_widget_t *widget)
|
||||
{
|
||||
rtgui_container_t *parent;
|
||||
struct rtgui_widget *old_focus;
|
||||
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
|
||||
if (!widget->parent || !widget->toplevel) return;
|
||||
if (!RTGUI_WIDGET_IS_FOCUSABLE(widget) || !RTGUI_WIDGET_IS_ENABLE(widget))
|
||||
return;
|
||||
|
||||
/* set widget as focused */
|
||||
widget->flag |= RTGUI_WIDGET_FLAG_FOCUS;
|
||||
|
||||
/* get root parent container and old focused widget */
|
||||
parent = RTGUI_CONTAINER(widget->toplevel);
|
||||
if (parent->focused == widget) return ; /* it's the same focused widget */
|
||||
old_focus = RTGUI_WIN(widget->toplevel)->focused_widget;
|
||||
if (old_focus == widget)
|
||||
return; /* it's the same focused widget */
|
||||
|
||||
/* unfocused the old widget */
|
||||
if (parent->focused != RT_NULL) rtgui_widget_unfocus(parent->focused);
|
||||
if (old_focus != RT_NULL)
|
||||
rtgui_widget_unfocus(old_focus);
|
||||
|
||||
/* set widget as focused widget in parent link */
|
||||
parent = RTGUI_CONTAINER(widget->parent);
|
||||
do
|
||||
{
|
||||
parent->focused = widget;
|
||||
parent = RTGUI_CONTAINER(RTGUI_WIDGET(parent)->parent);
|
||||
} while ((parent != RT_NULL) && !RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(parent)));
|
||||
/* set widget as focused */
|
||||
widget->flag |= RTGUI_WIDGET_FLAG_FOCUS;
|
||||
RTGUI_WIN(widget->toplevel)->focused_widget = widget;
|
||||
|
||||
/* invoke on focus in call back */
|
||||
if (widget->on_focus_in != RT_NULL)
|
||||
widget->on_focus_in(widget, RT_NULL);
|
||||
widget->on_focus_in(RTGUI_OBJECT(widget), RT_NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -317,6 +320,7 @@ void rtgui_widget_focus(rtgui_widget_t *widget)
|
|||
*/
|
||||
void rtgui_widget_unfocus(rtgui_widget_t *widget)
|
||||
{
|
||||
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
|
||||
if (!widget->toplevel || !RTGUI_WIDGET_IS_FOCUSED(widget))
|
||||
|
@ -325,7 +329,9 @@ void rtgui_widget_unfocus(rtgui_widget_t *widget)
|
|||
widget->flag &= ~RTGUI_WIDGET_FLAG_FOCUS;
|
||||
|
||||
if (widget->on_focus_out != RT_NULL)
|
||||
widget->on_focus_out(widget, RT_NULL);
|
||||
widget->on_focus_out(RTGUI_OBJECT(widget), RT_NULL);
|
||||
|
||||
RTGUI_WIN(widget->toplevel)->focused_widget = RT_NULL;
|
||||
|
||||
/* refresh widget */
|
||||
rtgui_widget_update(widget);
|
||||
|
@ -381,47 +387,62 @@ void rtgui_widget_rect_to_logic(rtgui_widget_t* widget, rtgui_rect_t* rect)
|
|||
}
|
||||
}
|
||||
|
||||
rtgui_widget_t* rtgui_widget_get_toplevel(rtgui_widget_t* widget)
|
||||
struct rtgui_win* rtgui_widget_get_toplevel(rtgui_widget_t* widget)
|
||||
{
|
||||
rtgui_widget_t* r;
|
||||
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
|
||||
if (widget->toplevel) return widget->toplevel;
|
||||
if (widget->toplevel)
|
||||
return widget->toplevel;
|
||||
|
||||
rt_kprintf("widget->toplevel not properly set\n");
|
||||
r = widget;
|
||||
/* get the toplevel widget */
|
||||
while (r->parent != RT_NULL) r = r->parent;
|
||||
while (r->parent != RT_NULL)
|
||||
r = r->parent;
|
||||
|
||||
/* set toplevel */
|
||||
widget->toplevel = r;
|
||||
widget->toplevel = RTGUI_WIN(r);
|
||||
|
||||
return r;
|
||||
return RTGUI_WIN(r);
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_widget_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
|
||||
rt_bool_t rtgui_widget_event_handler(struct rtgui_object* object, rtgui_event_t* event)
|
||||
{
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
struct rtgui_widget *widget;
|
||||
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
widget = RTGUI_WIDGET(object);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PAINT:
|
||||
if (widget->on_draw != RT_NULL) return widget->on_draw(widget, event);
|
||||
if (widget->on_draw != RT_NULL)
|
||||
return widget->on_draw(RTGUI_OBJECT(widget), event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_KBD:
|
||||
if (widget->on_key != RT_NULL) return widget->on_key(widget, event);
|
||||
if (widget->on_key != RT_NULL)
|
||||
return widget->on_key(RTGUI_OBJECT(widget), event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
if (widget->on_mouseclick != RT_NULL) return widget->on_mouseclick(widget, event);
|
||||
if (widget->on_mouseclick != RT_NULL)
|
||||
return widget->on_mouseclick(RTGUI_OBJECT(widget), event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_COMMAND:
|
||||
if (widget->on_command != RT_NULL) return widget->on_command(widget, event);
|
||||
if (widget->on_command != RT_NULL)
|
||||
return widget->on_command(RTGUI_OBJECT(widget), event);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_RESIZE:
|
||||
if (widget->on_size != RT_NULL) return widget->on_size(widget, event);
|
||||
if (widget->on_size != RT_NULL)
|
||||
return widget->on_size(RTGUI_OBJECT(widget), event);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
@ -441,14 +462,9 @@ void rtgui_widget_update_clip(rtgui_widget_t* widget)
|
|||
if (widget == RT_NULL || RTGUI_WIDGET_IS_HIDE(widget)) return;
|
||||
|
||||
parent = widget->parent;
|
||||
/* if there is no parent, do not update clip (please use toplevel widget API) */
|
||||
/* if there is no parent, there is no clip to update. */
|
||||
if (parent == RT_NULL)
|
||||
{
|
||||
if (RTGUI_IS_TOPLEVEL(widget))
|
||||
{
|
||||
/* if it's toplevel widget, update it by toplevel function */
|
||||
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(widget));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -479,7 +495,7 @@ void rtgui_widget_update_clip(rtgui_widget_t* widget)
|
|||
* intersect.
|
||||
*/
|
||||
|
||||
/* if it's a container object, update the clip info of children */
|
||||
/* if it's a view object, update the clip info of children */
|
||||
if (RTGUI_IS_CONTAINER(widget))
|
||||
{
|
||||
rtgui_widget_t* child;
|
||||
|
@ -490,17 +506,25 @@ void rtgui_widget_update_clip(rtgui_widget_t* widget)
|
|||
rtgui_widget_update_clip(child);
|
||||
}
|
||||
}
|
||||
else if (RTGUI_IS_NOTEBOOK(widget))
|
||||
{
|
||||
rtgui_widget_update_clip(rtgui_notebook_get_current(RTGUI_NOTEBOOK(widget)));
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_widget_show(rtgui_widget_t* widget)
|
||||
{
|
||||
/* there is no parent or the parent is hide, no show at all */
|
||||
if (widget->parent == RT_NULL ||
|
||||
RTGUI_WIDGET_IS_HIDE(widget->parent)) return;
|
||||
RTGUI_WIDGET_IS_HIDE(widget->parent))
|
||||
return;
|
||||
|
||||
/* update the clip info of widget */
|
||||
RTGUI_WIDGET_UNHIDE(widget);
|
||||
rtgui_widget_update_clip(widget);
|
||||
|
||||
if (widget->on_show != RT_NULL)
|
||||
widget->on_show(RTGUI_OBJECT(widget), RT_NULL);
|
||||
}
|
||||
|
||||
void rtgui_widget_hide(rtgui_widget_t* widget)
|
||||
|
@ -521,10 +545,10 @@ void rtgui_widget_hide(rtgui_widget_t* widget)
|
|||
|
||||
/* union widget rect */
|
||||
rtgui_region_union_rect(&(parent->clip), &(parent->clip), &(widget->extent));
|
||||
|
||||
/* subtract the external rect */
|
||||
rtgui_topwin_do_clip(RTGUI_WIDGET(parent));
|
||||
}
|
||||
|
||||
if (widget->on_hide != RT_NULL)
|
||||
widget->on_hide(RTGUI_OBJECT(widget), RT_NULL);
|
||||
}
|
||||
|
||||
rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t* widget)
|
||||
|
@ -567,9 +591,11 @@ void rtgui_widget_update(rtgui_widget_t* widget)
|
|||
|
||||
RT_ASSERT(widget != RT_NULL);
|
||||
|
||||
if (widget->event_handler != RT_NULL)
|
||||
if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
|
||||
{
|
||||
widget->event_handler(widget, &paint.parent);
|
||||
RTGUI_OBJECT(widget)->event_handler(
|
||||
RTGUI_OBJECT(widget),
|
||||
&paint.parent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -617,11 +643,9 @@ void rtgui_widget_dump(rtgui_widget_t* widget)
|
|||
obj = RTGUI_OBJECT(widget);
|
||||
rt_kprintf("widget type: %s ", obj->type->name);
|
||||
|
||||
if (RTGUI_IS_VIEW(widget) == RT_TRUE)
|
||||
rt_kprintf(":%s ", RTGUI_VIEW(widget)->title);
|
||||
if (RTGUI_IS_WIN(widget) == RT_TRUE)
|
||||
rt_kprintf(":%s ", RTGUI_WIN(widget)->title);
|
||||
if ((RTGUI_IS_LABEL(widget) == RT_TRUE) || (RTGUI_IS_BUTTON(widget) == RT_TRUE))
|
||||
else if ((RTGUI_IS_LABEL(widget) == RT_TRUE) || (RTGUI_IS_BUTTON(widget) == RT_TRUE))
|
||||
rt_kprintf(":%s ", RTGUI_LABEL(widget)->text);
|
||||
|
||||
rt_kprintf("extent(%d, %d) - (%d, %d)\n", widget->extent.x1,
|
||||
|
|
|
@ -15,27 +15,37 @@
|
|||
#include <rtgui/color.h>
|
||||
#include <rtgui/image.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/rtgui_server.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
|
||||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/widgets/button.h>
|
||||
#include <rtgui/widgets/workbench.h>
|
||||
|
||||
static void _rtgui_win_constructor(rtgui_win_t *win)
|
||||
{
|
||||
RTGUI_WIDGET(win)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
|
||||
win->parent_window = RT_NULL;
|
||||
/* init window attribute */
|
||||
win->on_activate = RT_NULL;
|
||||
win->on_deactivate = RT_NULL;
|
||||
win->on_close = RT_NULL;
|
||||
win->title = RT_NULL;
|
||||
win->modal_code = RTGUI_MODAL_OK;
|
||||
win->modal_widget = RT_NULL;
|
||||
win->on_activate = RT_NULL;
|
||||
win->on_deactivate = RT_NULL;
|
||||
win->on_close = RT_NULL;
|
||||
win->on_key = RT_NULL;
|
||||
win->title = RT_NULL;
|
||||
win->modal_code = RTGUI_MODAL_OK;
|
||||
|
||||
/* initialize last mouse event handled widget */
|
||||
win->last_mevent_widget = RT_NULL;
|
||||
win->focused_widget = RT_NULL;
|
||||
|
||||
/* set window hide */
|
||||
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));
|
||||
|
||||
/* set window style */
|
||||
win->style = RTGUI_WIN_STYLE_DEFAULT;
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(win), rtgui_win_event_handler);
|
||||
|
||||
win->flag = RTGUI_WIN_FLAG_INIT;
|
||||
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(win), rtgui_win_event_handler);
|
||||
|
||||
/* init user data */
|
||||
win->user_data = 0;
|
||||
|
@ -45,12 +55,12 @@ static void _rtgui_win_destructor(rtgui_win_t* win)
|
|||
{
|
||||
struct rtgui_event_win_destroy edestroy;
|
||||
|
||||
if (RTGUI_TOPLEVEL(win)->server != RT_NULL)
|
||||
if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
|
||||
{
|
||||
/* destroy in server */
|
||||
RTGUI_EVENT_WIN_DESTROY_INIT(&edestroy);
|
||||
edestroy.wid = win;
|
||||
if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&edestroy),
|
||||
if (rtgui_server_post_event_sync(RTGUI_EVENT(&edestroy),
|
||||
sizeof(struct rtgui_event_win_destroy)) != RT_EOK)
|
||||
{
|
||||
/* destroy in server failed */
|
||||
|
@ -62,39 +72,31 @@ static void _rtgui_win_destructor(rtgui_win_t* win)
|
|||
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(struct rtgui_win *win)
|
||||
{
|
||||
if (RTGUI_TOPLEVEL(win)->server == RT_NULL)
|
||||
if (!(win->flag & RTGUI_WIN_FLAG_CONNECTED))
|
||||
{
|
||||
rt_thread_t server;
|
||||
struct rtgui_event_win_create ecreate;
|
||||
RTGUI_EVENT_WIN_CREATE_INIT(&ecreate);
|
||||
|
||||
/* get server thread id */
|
||||
server = rtgui_thread_get_server();
|
||||
if (server == RT_NULL)
|
||||
{
|
||||
rt_kprintf("RTGUI server is not running...\n");
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
/* send win create event to server */
|
||||
ecreate.wid = win;
|
||||
ecreate.parent.user = win->style;
|
||||
ecreate.parent_window = win->parent_window;
|
||||
ecreate.wid = win;
|
||||
ecreate.parent.user = win->style;
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
ecreate.extent = RTGUI_WIDGET(win)->extent;
|
||||
ecreate.extent = RTGUI_WIDGET(win)->extent;
|
||||
rt_strncpy((char*)ecreate.title, (char*)win->title, RTGUI_NAME_MAX);
|
||||
#endif
|
||||
|
||||
if (rtgui_thread_send_sync(server, RTGUI_EVENT(&ecreate),
|
||||
sizeof(struct rtgui_event_win_create)) != RT_EOK)
|
||||
if (rtgui_server_post_event_sync(RTGUI_EVENT(&ecreate),
|
||||
sizeof(struct rtgui_event_win_create)
|
||||
) != RT_EOK)
|
||||
{
|
||||
rt_kprintf("create win: %s failed\n", win->title);
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
/* set server */
|
||||
RTGUI_TOPLEVEL(win)->server = server;
|
||||
win->flag |= RTGUI_WIN_FLAG_CONNECTED;
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
|
@ -106,181 +108,202 @@ DEFINE_CLASS_TYPE(win, "win",
|
|||
_rtgui_win_destructor,
|
||||
sizeof(struct rtgui_win));
|
||||
|
||||
rtgui_win_t* rtgui_win_create(rtgui_toplevel_t* parent_toplevel, const char* title, rtgui_rect_t *rect, rt_uint8_t style)
|
||||
#ifdef RTGUI_USING_DESKTOP_WINDOW
|
||||
static struct rtgui_win *the_desktop_window;
|
||||
#endif
|
||||
|
||||
rtgui_win_t* rtgui_win_create(struct rtgui_win* parent_window,
|
||||
const char* title,
|
||||
rtgui_rect_t *rect,
|
||||
rt_uint16_t style)
|
||||
{
|
||||
struct rtgui_win* win;
|
||||
|
||||
/* allocate win memory */
|
||||
win = (struct rtgui_win*) rtgui_widget_create (RTGUI_WIN_TYPE);
|
||||
if (win != RT_NULL)
|
||||
win = RTGUI_WIN(rtgui_widget_create(RTGUI_WIN_TYPE));
|
||||
if (win == RT_NULL)
|
||||
return RT_NULL;
|
||||
|
||||
/* set parent toplevel */
|
||||
#ifdef RTGUI_USING_DESKTOP_WINDOW
|
||||
if (style & RTGUI_WIN_STYLE_DESKTOP)
|
||||
{
|
||||
/* set parent toplevel */
|
||||
win->parent_toplevel = parent_toplevel;
|
||||
|
||||
/* set title, rect and style */
|
||||
if (title != RT_NULL) win->title = rt_strdup(title);
|
||||
else win->title = RT_NULL;
|
||||
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(win), rect);
|
||||
win->style = style;
|
||||
|
||||
if (_rtgui_win_create_in_server(win) == RT_FALSE)
|
||||
{
|
||||
rtgui_widget_destroy(RTGUI_WIDGET(win));
|
||||
return RT_NULL;
|
||||
}
|
||||
RT_ASSERT(the_desktop_window == RT_NULL);
|
||||
win->parent_window = RT_NULL;
|
||||
the_desktop_window = win;
|
||||
}
|
||||
else if (parent_window == RT_NULL)
|
||||
{
|
||||
RT_ASSERT(the_desktop_window != RT_NULL);
|
||||
win->parent_window = the_desktop_window;
|
||||
}
|
||||
else
|
||||
win->parent_window = parent_window;
|
||||
#else
|
||||
win->parent_window = parent_window;
|
||||
#endif
|
||||
|
||||
/* set title, rect and style */
|
||||
if (title != RT_NULL)
|
||||
win->title = rt_strdup(title);
|
||||
else
|
||||
win->title = RT_NULL;
|
||||
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(win), rect);
|
||||
win->style = style;
|
||||
|
||||
if (_rtgui_win_create_in_server(win) == RT_FALSE)
|
||||
{
|
||||
goto __on_err;
|
||||
}
|
||||
return win;
|
||||
|
||||
__on_err:
|
||||
rtgui_widget_destroy(RTGUI_WIDGET(win));
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
void rtgui_win_destroy(struct rtgui_win* win)
|
||||
{
|
||||
if (win->style & RTGUI_WIN_STYLE_MODAL)
|
||||
if (win->flag & RTGUI_WIN_FLAG_MODAL)
|
||||
{
|
||||
/* end modal */
|
||||
/* set the RTGUI_WIN_STYLE_DESTROY_ON_CLOSE flag so the window will be
|
||||
* destroyed after the event_loop */
|
||||
win->style |= RTGUI_WIN_STYLE_DESTROY_ON_CLOSE;
|
||||
rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
|
||||
}
|
||||
else
|
||||
{
|
||||
rtgui_widget_destroy(RTGUI_WIDGET(win));
|
||||
}
|
||||
|
||||
static rt_bool_t _rtgui_win_deal_close(struct rtgui_win *win,
|
||||
struct rtgui_event *event)
|
||||
{
|
||||
if (win->on_close != RT_NULL)
|
||||
{
|
||||
if (win->on_close(RTGUI_OBJECT(win), event) == RT_FALSE)
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rtgui_win_hiden(win);
|
||||
|
||||
win->flag |= RTGUI_WIN_FLAG_CLOSED;
|
||||
|
||||
if (win->flag & RTGUI_WIN_FLAG_MODAL)
|
||||
{
|
||||
rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
|
||||
}
|
||||
else if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE)
|
||||
{
|
||||
rtgui_win_destroy(win);
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
void rtgui_win_close(struct rtgui_win* win)
|
||||
/* send a close event to myself to get a consistent behavior */
|
||||
rt_bool_t rtgui_win_close(struct rtgui_win* win)
|
||||
{
|
||||
win->style |= RTGUI_WIN_STYLE_CLOSED;
|
||||
struct rtgui_event_win_close eclose;
|
||||
|
||||
RTGUI_EVENT_WIN_CLOSE_INIT(&eclose);
|
||||
eclose.wid = win;
|
||||
return _rtgui_win_deal_close(win,
|
||||
(struct rtgui_event*)&eclose);
|
||||
}
|
||||
|
||||
rtgui_modal_code_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal)
|
||||
rt_base_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal)
|
||||
{
|
||||
rtgui_modal_code_t result;
|
||||
struct rtgui_event_win_show eshow;
|
||||
rt_base_t exit_code = -1;
|
||||
|
||||
RT_ASSERT(win != RT_NULL);
|
||||
result = RTGUI_MODAL_CANCEL;
|
||||
RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
|
||||
eshow.wid = win;
|
||||
|
||||
if (win == RT_NULL)
|
||||
return exit_code;
|
||||
|
||||
/* if it does not register into server, create it in server */
|
||||
if (RTGUI_TOPLEVEL(win)->server == RT_NULL)
|
||||
if (!(win->flag & RTGUI_WIN_FLAG_CONNECTED))
|
||||
{
|
||||
if (_rtgui_win_create_in_server(win) == RT_FALSE)
|
||||
return result;
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)))
|
||||
if (rtgui_server_post_event_sync(RTGUI_EVENT(&eshow),
|
||||
sizeof(struct rtgui_event_win_show)
|
||||
) != RT_EOK)
|
||||
{
|
||||
/* send show message to server */
|
||||
struct rtgui_event_win_show eshow;
|
||||
RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
|
||||
eshow.wid = win;
|
||||
|
||||
if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&eshow),
|
||||
sizeof(struct rtgui_event_win_show)) != RT_EOK)
|
||||
{
|
||||
/* hide window failed */
|
||||
return result;
|
||||
}
|
||||
|
||||
/* set window unhidden */
|
||||
RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win));
|
||||
}
|
||||
else rtgui_widget_update(RTGUI_WIDGET(win));
|
||||
|
||||
if (is_modal == RT_TRUE)
|
||||
{
|
||||
if (win->parent_toplevel != RT_NULL)
|
||||
{
|
||||
rtgui_widget_t *parent_widget;
|
||||
|
||||
/* set style */
|
||||
win->style |= RTGUI_WIN_STYLE_MODAL;
|
||||
|
||||
/* get root toplevel */
|
||||
parent_widget = RTGUI_WIDGET(win->parent_toplevel);
|
||||
if (RTGUI_IS_WORKBENCH(parent_widget))
|
||||
{
|
||||
rtgui_workbench_t* workbench;
|
||||
workbench = RTGUI_WORKBENCH(win->parent_toplevel);
|
||||
workbench->flag |= RTGUI_WORKBENCH_FLAG_MODAL_MODE;
|
||||
workbench->modal_widget = RTGUI_WIDGET(win);
|
||||
|
||||
rtgui_workbench_event_loop(workbench);
|
||||
result = workbench->modal_code;
|
||||
workbench->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE;
|
||||
workbench->modal_widget = RT_NULL;
|
||||
}
|
||||
else if (RTGUI_IS_WIN(parent_widget))
|
||||
{
|
||||
rtgui_win_t* parent_win;
|
||||
parent_win = RTGUI_WIN(win->parent_toplevel);
|
||||
parent_win->style |= RTGUI_WIN_STYLE_UNDER_MODAL;
|
||||
parent_win->modal_widget = RTGUI_WIDGET(win);
|
||||
|
||||
rtgui_win_event_loop(parent_win);
|
||||
result = parent_win->modal_code;
|
||||
parent_win->style &= ~RTGUI_WIN_STYLE_UNDER_MODAL;
|
||||
parent_win->modal_widget = RT_NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* which is a root window */
|
||||
win->style |= RTGUI_WIN_STYLE_MODAL;
|
||||
rtgui_win_event_loop(win);
|
||||
|
||||
result = win->modal_code;
|
||||
win->style &= ~RTGUI_WIN_STYLE_MODAL;
|
||||
}
|
||||
rt_kprintf("show win failed\n");
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
return result;
|
||||
/* set window unhidden */
|
||||
RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win));
|
||||
|
||||
if (win->focused_widget == RT_NULL)
|
||||
rtgui_widget_focus(RTGUI_WIDGET(win));
|
||||
|
||||
if (is_modal == RT_TRUE)
|
||||
{
|
||||
struct rtgui_application *app;
|
||||
struct rtgui_event_win_modal_enter emodal;
|
||||
|
||||
RTGUI_EVENT_WIN_MODAL_ENTER_INIT(&emodal);
|
||||
emodal.wid = win;
|
||||
|
||||
app = rtgui_application_self();
|
||||
RT_ASSERT(app != RT_NULL);
|
||||
|
||||
win->flag |= RTGUI_WIN_FLAG_MODAL;
|
||||
|
||||
if (rtgui_server_post_event_sync((struct rtgui_event*)&emodal,
|
||||
sizeof(emodal)) != RT_EOK)
|
||||
return exit_code;
|
||||
|
||||
app->modal_object = RTGUI_OBJECT(win);
|
||||
|
||||
exit_code = rtgui_application_run(app);
|
||||
|
||||
app->modal_object = RT_NULL;
|
||||
win->flag &= ~RTGUI_WIN_FLAG_MODAL;
|
||||
|
||||
if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE)
|
||||
{
|
||||
rtgui_win_destroy(win);
|
||||
}
|
||||
}
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
void rtgui_win_end_modal(struct rtgui_win* win, rtgui_modal_code_t modal_code)
|
||||
{
|
||||
if (win->parent_toplevel != RT_NULL)
|
||||
{
|
||||
if (RTGUI_IS_WORKBENCH(win->parent_toplevel))
|
||||
{
|
||||
rtgui_workbench_t* workbench;
|
||||
if (win == RT_NULL || !(win->flag & RTGUI_WIN_FLAG_MODAL))
|
||||
return;
|
||||
|
||||
/* which is shown under workbench */
|
||||
workbench = RTGUI_WORKBENCH(win->parent_toplevel);
|
||||
workbench->modal_code = modal_code;
|
||||
workbench->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE;
|
||||
}
|
||||
else if (RTGUI_IS_WIN(win->parent_toplevel))
|
||||
{
|
||||
rtgui_win_t* parent_win;
|
||||
|
||||
/* which is shown under win */
|
||||
parent_win = RTGUI_WIN(win->parent_toplevel);
|
||||
parent_win->modal_code = modal_code;
|
||||
parent_win->style &= ~RTGUI_WIN_STYLE_UNDER_MODAL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* which is a stand alone window */
|
||||
win->modal_code = modal_code;
|
||||
}
|
||||
rtgui_application_exit(rtgui_application_self(), modal_code);
|
||||
|
||||
/* remove modal mode */
|
||||
win->style &= ~RTGUI_WIN_STYLE_MODAL;
|
||||
win->flag &= ~RTGUI_WIN_FLAG_MODAL;
|
||||
}
|
||||
|
||||
void rtgui_win_hiden(struct rtgui_win* win)
|
||||
{
|
||||
RT_ASSERT(win != RT_NULL);
|
||||
#ifdef RTGUI_USING_DESKTOP_WINDOW
|
||||
RT_ASSERT(win != the_desktop_window);
|
||||
#endif
|
||||
|
||||
if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)) &&
|
||||
RTGUI_TOPLEVEL(win)->server != RT_NULL)
|
||||
win->flag & RTGUI_WIN_FLAG_CONNECTED)
|
||||
{
|
||||
/* send hidden message to server */
|
||||
struct rtgui_event_win_hide ehide;
|
||||
RTGUI_EVENT_WIN_HIDE_INIT(&ehide);
|
||||
ehide.wid = win;
|
||||
|
||||
if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&ehide),
|
||||
if (rtgui_server_post_event_sync(RTGUI_EVENT(&ehide),
|
||||
sizeof(struct rtgui_event_win_hide)) != RT_EOK)
|
||||
{
|
||||
rt_kprintf("hide win: %s failed\n", win->title);
|
||||
|
@ -289,7 +312,7 @@ void rtgui_win_hiden(struct rtgui_win* win)
|
|||
|
||||
/* set window hide and deactivated */
|
||||
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));
|
||||
win->style &= ~RTGUI_WIN_STYLE_ACTIVATE;
|
||||
win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -297,7 +320,7 @@ rt_bool_t rtgui_win_is_activated(struct rtgui_win* win)
|
|||
{
|
||||
RT_ASSERT(win != RT_NULL);
|
||||
|
||||
if (win->style & RTGUI_WIN_STYLE_ACTIVATE) return RT_TRUE;
|
||||
if (win->flag & RTGUI_WIN_FLAG_ACTIVATE) return RT_TRUE;
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
@ -307,28 +330,29 @@ void rtgui_win_move(struct rtgui_win* win, int x, int y)
|
|||
struct rtgui_event_win_move emove;
|
||||
RTGUI_EVENT_WIN_MOVE_INIT(&emove);
|
||||
|
||||
if (win == RT_NULL) return;
|
||||
|
||||
if (RTGUI_TOPLEVEL(win)->server != RT_NULL)
|
||||
{
|
||||
/* set win hide firstly */
|
||||
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));
|
||||
|
||||
emove.wid = win;
|
||||
emove.x = x;
|
||||
emove.y = y;
|
||||
if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&emove),
|
||||
sizeof(struct rtgui_event_win_move)) != RT_EOK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (win == RT_NULL)
|
||||
return;
|
||||
|
||||
/* move window to logic position */
|
||||
rtgui_widget_move_to_logic(RTGUI_WIDGET(win),
|
||||
x - RTGUI_WIDGET(win)->extent.x1,
|
||||
y - RTGUI_WIDGET(win)->extent.y1);
|
||||
|
||||
if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
|
||||
{
|
||||
/* set win hide firstly */
|
||||
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));
|
||||
|
||||
emove.wid = win;
|
||||
emove.x = x;
|
||||
emove.y = y;
|
||||
if (rtgui_server_post_event_sync(RTGUI_EVENT(&emove),
|
||||
sizeof(struct rtgui_event_win_move)) != RT_EOK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* set window visible */
|
||||
RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win));
|
||||
return;
|
||||
|
@ -342,7 +366,8 @@ static rt_bool_t rtgui_win_ondraw(struct rtgui_win* win)
|
|||
|
||||
/* begin drawing */
|
||||
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(win));
|
||||
if (dc == RT_NULL) return RT_FALSE;
|
||||
if (dc == RT_NULL)
|
||||
return RT_FALSE;
|
||||
|
||||
/* get window rect */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(win), &rect);
|
||||
|
@ -352,18 +377,22 @@ static rt_bool_t rtgui_win_ondraw(struct rtgui_win* win)
|
|||
/* paint each widget */
|
||||
RTGUI_EVENT_PAINT_INIT(&event);
|
||||
event.wid = RT_NULL;
|
||||
rtgui_container_dispatch_event(RTGUI_CONTAINER(win), (rtgui_event_t*)&event);
|
||||
rtgui_container_dispatch_event(RTGUI_CONTAINER(win),
|
||||
(rtgui_event_t*)&event);
|
||||
|
||||
rtgui_dc_end_drawing(dc);
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
rt_bool_t rtgui_win_event_handler(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_win* win = (struct rtgui_win*)widget;
|
||||
struct rtgui_win* win;
|
||||
|
||||
RT_ASSERT((win != RT_NULL) && (event != RT_NULL));
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
|
||||
win = RTGUI_WIN(object);
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
|
@ -376,22 +405,8 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_even
|
|||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_CLOSE:
|
||||
if (win->on_close != RT_NULL)
|
||||
{
|
||||
if (win->on_close(widget, event) == RT_FALSE) return RT_TRUE;
|
||||
}
|
||||
|
||||
if (win->style & RTGUI_WIN_STYLE_MODAL)
|
||||
{
|
||||
rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* destroy window */
|
||||
rtgui_win_destroy(win);
|
||||
}
|
||||
|
||||
/* exit event loop */
|
||||
_rtgui_win_deal_close(win, event);
|
||||
/* don't broadcast WIN_CLOSE event to others */
|
||||
return RT_TRUE;
|
||||
|
||||
case RTGUI_EVENT_WIN_MOVE:
|
||||
|
@ -410,49 +425,54 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_even
|
|||
return RT_TRUE;
|
||||
}
|
||||
|
||||
win->style |= RTGUI_WIN_STYLE_ACTIVATE;
|
||||
win->flag |= RTGUI_WIN_FLAG_ACTIVATE;
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
|
||||
if (RTGUI_WIDGET(object)->on_draw != RT_NULL)
|
||||
RTGUI_WIDGET(object)->on_draw(object, event);
|
||||
else
|
||||
#endif
|
||||
rtgui_widget_update(RTGUI_WIDGET(win));
|
||||
|
||||
if (win->on_activate != RT_NULL)
|
||||
{
|
||||
win->on_activate(widget, event);
|
||||
win->on_activate(RTGUI_OBJECT(object), event);
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_DEACTIVATE:
|
||||
if (win->style & RTGUI_WIN_STYLE_MODAL)
|
||||
if (win->flag & RTGUI_WIN_FLAG_MODAL)
|
||||
{
|
||||
/* do not deactivate a modal win, re-send win-show event */
|
||||
struct rtgui_event_win_show eshow;
|
||||
RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
|
||||
eshow.wid = win;
|
||||
|
||||
rtgui_thread_send(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&eshow),
|
||||
sizeof(struct rtgui_event_win_show));
|
||||
/* FIXME: make modal concept clear and easy. See the comment of
|
||||
* rtgui_topwin_modal_enter. */
|
||||
/* There are various reason that a modal window got deactivated:
|
||||
* 1, it has child windows and the user activate one of them.
|
||||
* 2, the application has more than one root window and the
|
||||
* user switched to one of the others.
|
||||
*
|
||||
* In any of the cases, we have nothing to do here.
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
win->style &= ~RTGUI_WIN_STYLE_ACTIVATE;
|
||||
win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
|
||||
if (RTGUI_WIDGET(object)->on_draw != RT_NULL)
|
||||
RTGUI_WIDGET(object)->on_draw(object, event);
|
||||
else
|
||||
#endif
|
||||
rtgui_win_ondraw(win);
|
||||
rtgui_widget_update(RTGUI_WIDGET(win));
|
||||
|
||||
if (win->on_deactivate != RT_NULL)
|
||||
{
|
||||
win->on_deactivate(widget, event);
|
||||
win->on_deactivate(RTGUI_OBJECT(object), event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_PAINT:
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
|
||||
if (RTGUI_WIDGET(object)->on_draw != RT_NULL)
|
||||
RTGUI_WIDGET(object)->on_draw(object, event);
|
||||
else
|
||||
#endif
|
||||
rtgui_win_ondraw(win);
|
||||
|
@ -460,36 +480,22 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_even
|
|||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
/* check whether has widget which handled mouse event before */
|
||||
if (RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(win) != RT_NULL)
|
||||
if (win->last_mevent_widget != RT_NULL)
|
||||
{
|
||||
struct rtgui_event_mouse* emouse;
|
||||
|
||||
emouse = (struct rtgui_event_mouse*)event;
|
||||
|
||||
RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(win)->event_handler(RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(win), event);
|
||||
if (rtgui_rect_contains_point(&(RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(win)->extent),
|
||||
emouse->x, emouse->y) == RT_EOK)
|
||||
{
|
||||
RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(win) = RT_NULL;
|
||||
break; /* mouse event is inside of widget, do not handle it anymore */
|
||||
}
|
||||
RTGUI_OBJECT(win->last_mevent_widget)->event_handler(
|
||||
RTGUI_OBJECT(win->last_mevent_widget),
|
||||
event);
|
||||
|
||||
/* clean last mouse event handled widget */
|
||||
RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(win) = RT_NULL;
|
||||
win->last_mevent_widget = RT_NULL;
|
||||
}
|
||||
|
||||
if (win->style & RTGUI_WIN_STYLE_UNDER_MODAL)
|
||||
{
|
||||
if (win->modal_widget != RT_NULL)
|
||||
return win->modal_widget->event_handler(win->modal_widget, event);
|
||||
}
|
||||
else if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win),
|
||||
else if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win),
|
||||
(struct rtgui_event_mouse*)event) == RT_FALSE)
|
||||
{
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
if (widget->on_mouseclick != RT_NULL)
|
||||
if (RTGUI_WIDGET(object)->on_mouseclick != RT_NULL)
|
||||
{
|
||||
return widget->on_mouseclick(widget, event);
|
||||
return RTGUI_WIDGET(object)->on_mouseclick(object, event);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -512,101 +518,45 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_even
|
|||
#endif
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_KBD:
|
||||
if (win->style & RTGUI_WIN_STYLE_UNDER_MODAL)
|
||||
case RTGUI_EVENT_KBD:
|
||||
/* we should dispatch key event firstly */
|
||||
if (!(win->flag & RTGUI_WIN_FLAG_HANDLE_KEY))
|
||||
{
|
||||
if (win->modal_widget != RT_NULL)
|
||||
return win->modal_widget->event_handler(win->modal_widget, event);
|
||||
rt_bool_t res = RT_FALSE;
|
||||
/* we should dispatch the key event just once. Once entered the
|
||||
* dispatch mode, we should swtich to key handling mode. */
|
||||
win->flag |= RTGUI_WIN_FLAG_HANDLE_KEY;
|
||||
|
||||
/* dispatch the key event */
|
||||
if (win->focused_widget != RT_NULL &&
|
||||
RTGUI_OBJECT(win->focused_widget)->event_handler != RT_NULL)
|
||||
res = RTGUI_OBJECT(win->focused_widget)->event_handler(
|
||||
RTGUI_OBJECT(win->focused_widget), event);
|
||||
|
||||
/* if the focused widget doesn't handle it, I will handle it. */
|
||||
if (res != RT_TRUE && win->on_key != RT_NULL)
|
||||
res = win->on_key(RTGUI_OBJECT(win), event);
|
||||
|
||||
win->flag &= ~RTGUI_WIN_FLAG_HANDLE_KEY;
|
||||
return res;
|
||||
}
|
||||
else if (RTGUI_CONTAINER(win)->focused != widget &&
|
||||
RTGUI_CONTAINER(win)->focused != RT_NULL)
|
||||
else
|
||||
{
|
||||
RTGUI_CONTAINER(win)->focused->event_handler(RTGUI_CONTAINER(win)->focused, event);
|
||||
/* in key handling mode(it may reach here in
|
||||
* win->focused_widget->event_handler call) */
|
||||
if (win->on_key != RT_NULL)
|
||||
return win->on_key(RTGUI_OBJECT(win), event);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* call parent event handler */
|
||||
return rtgui_toplevel_event_handler(widget, event);
|
||||
return rtgui_toplevel_event_handler(object, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
/* windows event loop */
|
||||
void rtgui_win_event_loop(rtgui_win_t* wnd)
|
||||
{
|
||||
rt_err_t result;
|
||||
rtgui_thread_t* tid;
|
||||
struct rtgui_event* event;
|
||||
|
||||
tid = rtgui_thread_self();
|
||||
RT_ASSERT(tid != RT_NULL);
|
||||
|
||||
/* point to event buffer */
|
||||
event = (struct rtgui_event*)tid->event_buffer;
|
||||
|
||||
if (wnd->style & RTGUI_WIN_STYLE_UNDER_MODAL)
|
||||
{
|
||||
while (wnd->style & RTGUI_WIN_STYLE_UNDER_MODAL)
|
||||
{
|
||||
if (tid->on_idle != RT_NULL)
|
||||
{
|
||||
result = rtgui_thread_recv_nosuspend(event, RTGUI_EVENT_BUFFER_SIZE);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
/* perform event handler */
|
||||
RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event);
|
||||
}
|
||||
else if (result == -RT_ETIMEOUT)
|
||||
{
|
||||
tid->on_idle(RTGUI_WIDGET(wnd), RT_NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = rtgui_thread_recv(event, RTGUI_EVENT_BUFFER_SIZE);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
/* perform event handler */
|
||||
RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (!(wnd->style & RTGUI_WIN_STYLE_CLOSED))
|
||||
{
|
||||
if (tid->on_idle != RT_NULL)
|
||||
{
|
||||
result = rtgui_thread_recv_nosuspend(event, RTGUI_EVENT_BUFFER_SIZE);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
/* perform event handler */
|
||||
RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event);
|
||||
}
|
||||
else if (result == -RT_ETIMEOUT)
|
||||
{
|
||||
tid->on_idle(RTGUI_WIDGET(wnd), RT_NULL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = rtgui_thread_recv(event, RTGUI_EVENT_BUFFER_SIZE);
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
/* perform event handler */
|
||||
RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* destroy window */
|
||||
rtgui_widget_destroy(RTGUI_WIDGET(wnd));
|
||||
}
|
||||
|
||||
void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect)
|
||||
{
|
||||
struct rtgui_event_win_resize event;
|
||||
|
@ -615,14 +565,14 @@ void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect)
|
|||
|
||||
RTGUI_WIDGET(win)->extent = *rect;
|
||||
|
||||
if (RTGUI_TOPLEVEL(win)->server != RT_NULL)
|
||||
if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
|
||||
{
|
||||
/* set window resize event to server */
|
||||
RTGUI_EVENT_WIN_RESIZE_INIT(&event);
|
||||
event.wid = win;
|
||||
event.rect = *rect;
|
||||
|
||||
rtgui_thread_send(RTGUI_TOPLEVEL(win)->server, &(event.parent), sizeof(struct rtgui_event_win_resize));
|
||||
rtgui_server_post_event(&(event.parent), sizeof(struct rtgui_event_win_resize));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -660,10 +610,18 @@ 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)
|
||||
{
|
||||
if (win != RT_NULL)
|
||||
{
|
||||
win->on_key = handler;
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_win_set_title(rtgui_win_t* win, const char *title)
|
||||
{
|
||||
/* send title to server */
|
||||
if (RTGUI_TOPLEVEL(win)->server != RT_NULL)
|
||||
if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -1,581 +0,0 @@
|
|||
/*
|
||||
* File : workbench.c
|
||||
* This file is part of RTGUI in RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2009-10-04 Bernard first version
|
||||
* 2010-09-24 Bernard fix workbench destroy issue
|
||||
*/
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/widgets/workbench.h>
|
||||
|
||||
static void _rtgui_workbench_constructor(rtgui_workbench_t *workbench)
|
||||
{
|
||||
/* set event handler */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(workbench), rtgui_workbench_event_handler);
|
||||
|
||||
/* set attributes */
|
||||
workbench->flag = RTGUI_WORKBENCH_FLAG_DEFAULT;
|
||||
workbench->panel = RT_NULL;
|
||||
workbench->title = RT_NULL;
|
||||
workbench->current_view = RT_NULL;
|
||||
workbench->modal_code = RTGUI_MODAL_OK;
|
||||
workbench->modal_widget = RT_NULL;
|
||||
}
|
||||
|
||||
static void _rtgui_workbench_destructor(rtgui_workbench_t *workbench)
|
||||
{
|
||||
RT_ASSERT(workbench != RT_NULL);
|
||||
|
||||
if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL)
|
||||
{
|
||||
struct rtgui_event_panel_detach edetach;
|
||||
RTGUI_EVENT_PANEL_DETACH_INIT(&edetach);
|
||||
|
||||
/* detach from panel */
|
||||
edetach.panel = workbench->panel;
|
||||
|
||||
/* send PANEL DETACH to server */
|
||||
if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(workbench)->server,
|
||||
RTGUI_EVENT(&edetach), sizeof(struct rtgui_event_panel_detach)) != RT_EOK)
|
||||
return;
|
||||
|
||||
RTGUI_TOPLEVEL(workbench)->server = RT_NULL;
|
||||
}
|
||||
|
||||
/* release title */
|
||||
rt_free(workbench->title);
|
||||
workbench->title = RT_NULL;
|
||||
}
|
||||
|
||||
DEFINE_CLASS_TYPE(workbench, "workbench",
|
||||
RTGUI_TOPLEVEL_TYPE,
|
||||
_rtgui_workbench_constructor,
|
||||
_rtgui_workbench_destructor,
|
||||
sizeof(struct rtgui_workbench));
|
||||
|
||||
rtgui_workbench_t *rtgui_workbench_create(const char* panel_name, const unsigned char* title)
|
||||
{
|
||||
struct rtgui_workbench* workbench;
|
||||
|
||||
/* the server thread id */
|
||||
rt_thread_t server = rtgui_thread_get_server();
|
||||
if (server == RT_NULL)
|
||||
{
|
||||
rt_kprintf("can't find rtgui server\n");
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
/* create workbench */
|
||||
workbench = (rtgui_workbench_t*) rtgui_widget_create (RTGUI_WORKBENCH_TYPE);
|
||||
if (workbench != RT_NULL)
|
||||
{
|
||||
/* the buffer uses to receive event */
|
||||
union
|
||||
{
|
||||
struct rtgui_event_panel_attach ecreate;
|
||||
struct rtgui_event_panel_info epanel;
|
||||
|
||||
char buffer[256]; /* use to recv other information */
|
||||
} event;
|
||||
|
||||
/* set workbench title */
|
||||
workbench->title = (unsigned char*)rt_strdup((char*)title);
|
||||
|
||||
/* create application in server */
|
||||
RTGUI_EVENT_PANEL_ATTACH_INIT(&(event.ecreate));
|
||||
|
||||
/* set the panel name and workbench */
|
||||
rt_strncpy(event.ecreate.panel_name, panel_name, RTGUI_NAME_MAX);
|
||||
event.ecreate.workbench = workbench;
|
||||
|
||||
/* send PANEL ATTACH to server */
|
||||
if (rtgui_thread_send_sync(server,
|
||||
&(event.ecreate.parent), sizeof(struct rtgui_event_panel_attach)) != RTGUI_STATUS_OK)
|
||||
{
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
/* get PANEL INFO */
|
||||
rtgui_thread_recv_filter(RTGUI_EVENT_PANEL_INFO, &(event.epanel.parent), sizeof(event));
|
||||
|
||||
/* set panel */
|
||||
workbench->panel = (struct rtgui_panel*)event.epanel.panel;
|
||||
|
||||
/* connected */
|
||||
RTGUI_TOPLEVEL(workbench)->server = server;
|
||||
|
||||
/* set extent of workbench */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(workbench), &(event.epanel.extent));
|
||||
|
||||
/* set workbench in thread */
|
||||
rtgui_thread_set_widget(RTGUI_WIDGET(workbench));
|
||||
}
|
||||
|
||||
return workbench;
|
||||
}
|
||||
|
||||
void rtgui_workbench_destroy(rtgui_workbench_t* workbench)
|
||||
{
|
||||
RT_ASSERT(workbench != RT_NULL);
|
||||
|
||||
if (workbench->flag & RTGUI_WORKBENCH_FLAG_CLOSED)
|
||||
{
|
||||
rtgui_widget_destroy(RTGUI_WIDGET(workbench));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* just close workbench */
|
||||
rtgui_workbench_close(workbench);
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_workbench_close(rtgui_workbench_t* workbench)
|
||||
{
|
||||
/* detach workbench in server */
|
||||
if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL)
|
||||
{
|
||||
struct rtgui_event_panel_detach edetach;
|
||||
RTGUI_EVENT_PANEL_DETACH_INIT(&edetach);
|
||||
|
||||
/* detach from panel */
|
||||
edetach.panel = workbench->panel;
|
||||
edetach.workbench = workbench;
|
||||
|
||||
/* send PANEL DETACH to server */
|
||||
if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(workbench)->server,
|
||||
RTGUI_EVENT(&edetach), sizeof(struct rtgui_event_panel_detach)) != RT_EOK)
|
||||
return;
|
||||
|
||||
RTGUI_TOPLEVEL(workbench)->server = RT_NULL;
|
||||
}
|
||||
|
||||
/* set status to close */
|
||||
workbench->flag |= RTGUI_WORKBENCH_FLAG_CLOSED;
|
||||
}
|
||||
|
||||
void rtgui_workbench_set_flag(rtgui_workbench_t* workbench, rt_uint8_t flag)
|
||||
{
|
||||
RT_ASSERT(workbench != RT_NULL);
|
||||
|
||||
workbench->flag = flag;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_workbench_event_loop(rtgui_workbench_t* workbench)
|
||||
{
|
||||
rt_err_t result;
|
||||
rtgui_thread_t* tid;
|
||||
struct rtgui_event* event;
|
||||
|
||||
tid = rtgui_thread_self();
|
||||
RT_ASSERT(tid != RT_NULL);
|
||||
|
||||
/* point to event buffer */
|
||||
event = (struct rtgui_event*)tid->event_buffer;
|
||||
|
||||
if (workbench->flag & RTGUI_WORKBENCH_FLAG_MODAL_MODE)
|
||||
{
|
||||
/* event loop for modal mode shown view */
|
||||
while (workbench->flag & RTGUI_WORKBENCH_FLAG_MODAL_MODE)
|
||||
{
|
||||
if (tid->on_idle != RT_NULL)
|
||||
{
|
||||
result = rtgui_thread_recv_nosuspend(event, RTGUI_EVENT_BUFFER_SIZE);
|
||||
if (result == RT_EOK)
|
||||
RTGUI_WIDGET(workbench)->event_handler(RTGUI_WIDGET(workbench), event);
|
||||
else if (result == -RT_ETIMEOUT)
|
||||
tid->on_idle(RTGUI_WIDGET(workbench), RT_NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = rtgui_thread_recv(event, RTGUI_EVENT_BUFFER_SIZE);
|
||||
if (result == RT_EOK)
|
||||
RTGUI_WIDGET(workbench)->event_handler(RTGUI_WIDGET(workbench), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* show workbench firstly */
|
||||
rtgui_workbench_show(workbench);
|
||||
|
||||
while (!(workbench->flag & RTGUI_WORKBENCH_FLAG_CLOSED))
|
||||
{
|
||||
if (tid->on_idle != RT_NULL)
|
||||
{
|
||||
result = rtgui_thread_recv_nosuspend(event, RTGUI_EVENT_BUFFER_SIZE);
|
||||
if (result == RT_EOK)
|
||||
RTGUI_WIDGET(workbench)->event_handler(RTGUI_WIDGET(workbench), event);
|
||||
else if (result == -RT_ETIMEOUT)
|
||||
tid->on_idle(RTGUI_WIDGET(workbench), RT_NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = rtgui_thread_recv(event, RTGUI_EVENT_BUFFER_SIZE);
|
||||
if (result == RT_EOK)
|
||||
RTGUI_WIDGET(workbench)->event_handler(RTGUI_WIDGET(workbench), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_workbench_show(rtgui_workbench_t* workbench)
|
||||
{
|
||||
RT_ASSERT(workbench != RT_NULL);
|
||||
|
||||
if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL)
|
||||
{
|
||||
struct rtgui_event_panel_show eraise;
|
||||
RTGUI_EVENT_PANEL_SHOW_INIT(&eraise);
|
||||
eraise.workbench = workbench;
|
||||
|
||||
eraise.panel = workbench->panel;
|
||||
if (rtgui_thread_send_sync(workbench->parent.server, RTGUI_EVENT(&eraise),
|
||||
sizeof(struct rtgui_event_panel_show)) != RT_EOK)
|
||||
return -RT_ERROR;
|
||||
|
||||
RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(workbench));
|
||||
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
|
||||
}
|
||||
else return -RT_ERROR;
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_err_t rtgui_workbench_hide(rtgui_workbench_t* workbench)
|
||||
{
|
||||
if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL)
|
||||
{
|
||||
struct rtgui_event_panel_hide ehide;
|
||||
RTGUI_EVENT_PANEL_HIDE_INIT(&ehide);
|
||||
|
||||
RT_ASSERT(workbench != RT_NULL);
|
||||
if (workbench->parent.server == RT_NULL) return -RT_ERROR;
|
||||
|
||||
ehide.panel = workbench->panel;
|
||||
if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(workbench)->server, RTGUI_EVENT(&ehide),
|
||||
sizeof(struct rtgui_event_panel_hide)) != RT_EOK)
|
||||
return -RT_ERROR;
|
||||
|
||||
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench));
|
||||
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
|
||||
{
|
||||
struct rtgui_workbench* workbench = (struct rtgui_workbench*)widget;
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case RTGUI_EVENT_PANEL_DETACH:
|
||||
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench));
|
||||
RTGUI_TOPLEVEL(workbench)->server = RT_NULL;
|
||||
return RT_TRUE;
|
||||
|
||||
case RTGUI_EVENT_PANEL_SHOW:
|
||||
/* show workbench in server */
|
||||
rtgui_workbench_show(workbench);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_PANEL_HIDE:
|
||||
/* hide widget */
|
||||
RTGUI_WIDGET_HIDE(widget);
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_MOTION:
|
||||
{
|
||||
struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
|
||||
struct rtgui_toplevel* top = RTGUI_TOPLEVEL(emouse->wid);
|
||||
|
||||
/* check the destination window */
|
||||
if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
|
||||
{
|
||||
RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* let viewer to handle it */
|
||||
rtgui_view_t* view = workbench->current_view;
|
||||
if (view != RT_NULL &&
|
||||
RTGUI_WIDGET(view)->event_handler != RT_NULL)
|
||||
{
|
||||
RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_MOUSE_BUTTON:
|
||||
{
|
||||
struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
|
||||
struct rtgui_toplevel* top = RTGUI_TOPLEVEL(emouse->wid);
|
||||
|
||||
/* check whether has widget which handled mouse event before */
|
||||
if (RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(workbench) != RT_NULL)
|
||||
{
|
||||
struct rtgui_event_mouse* emouse;
|
||||
|
||||
emouse = (struct rtgui_event_mouse*)event;
|
||||
|
||||
RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(workbench)->event_handler(RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(workbench), event);
|
||||
if (rtgui_rect_contains_point(&(RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(workbench)->extent),
|
||||
emouse->x, emouse->y) == RT_EOK)
|
||||
{
|
||||
RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(workbench) = RT_NULL;
|
||||
break; /* mouse event is inside of widget, do not handle it anymore */
|
||||
}
|
||||
|
||||
/* clean last mouse event handled widget */
|
||||
RTGUI_TOPLEVEL_LAST_MEVENT_WIDGET(workbench) = RT_NULL;
|
||||
}
|
||||
|
||||
/* check the destination window */
|
||||
if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
|
||||
{
|
||||
RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (RTGUI_WORKBENCH_IS_MODAL_MODE(workbench))
|
||||
{
|
||||
/* let modal widget to handle it */
|
||||
if (workbench->modal_widget != RT_NULL &&
|
||||
workbench->modal_widget->event_handler != RT_NULL)
|
||||
{
|
||||
workbench->modal_widget->event_handler(workbench->modal_widget, event);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* let viewer to handle it */
|
||||
rtgui_view_t* view = workbench->current_view;
|
||||
if (view != RT_NULL &&
|
||||
RTGUI_WIDGET(view)->event_handler != RT_NULL)
|
||||
{
|
||||
RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_KBD:
|
||||
{
|
||||
struct rtgui_event_kbd* kbd = (struct rtgui_event_kbd*)event;
|
||||
struct rtgui_toplevel* top = RTGUI_TOPLEVEL(kbd->wid);
|
||||
|
||||
/* check the destination window */
|
||||
if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
|
||||
{
|
||||
RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (RTGUI_WORKBENCH_IS_MODAL_MODE(workbench))
|
||||
{
|
||||
/* let modal widget to handle it */
|
||||
if (workbench->modal_widget != RT_NULL &&
|
||||
workbench->modal_widget->event_handler != RT_NULL)
|
||||
{
|
||||
workbench->modal_widget->event_handler(workbench->modal_widget, event);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (RTGUI_CONTAINER(widget)->focused == widget)
|
||||
{
|
||||
/* set focused widget to the current view */
|
||||
if (workbench->current_view != RT_NULL)
|
||||
rtgui_widget_focus(RTGUI_WIDGET(RTGUI_CONTAINER(workbench->current_view)->focused));
|
||||
}
|
||||
|
||||
return rtgui_toplevel_event_handler(widget, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_PAINT:
|
||||
{
|
||||
struct rtgui_event_paint* epaint = (struct rtgui_event_paint*)event;
|
||||
struct rtgui_toplevel* top = RTGUI_TOPLEVEL(epaint->wid);
|
||||
|
||||
/* check the destination window */
|
||||
if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
|
||||
{
|
||||
RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
|
||||
}
|
||||
else
|
||||
{
|
||||
rtgui_view_t* view;
|
||||
|
||||
/* un-hide workbench */
|
||||
RTGUI_WIDGET_UNHIDE(widget);
|
||||
|
||||
/* paint a view */
|
||||
view = workbench->current_view;
|
||||
if (view != RT_NULL)
|
||||
{
|
||||
/* remake a paint event */
|
||||
RTGUI_EVENT_PAINT_INIT(epaint);
|
||||
epaint->wid = RT_NULL;
|
||||
|
||||
/* send this event to the view */
|
||||
if (RTGUI_WIDGET(view)->event_handler != RT_NULL)
|
||||
{
|
||||
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;
|
||||
|
||||
case RTGUI_EVENT_CLIP_INFO:
|
||||
{
|
||||
struct rtgui_event_clip_info* eclip = (struct rtgui_event_clip_info*)event;
|
||||
struct rtgui_widget* dest_widget = RTGUI_WIDGET(eclip->wid);
|
||||
|
||||
if (dest_widget != RT_NULL && dest_widget->event_handler != RT_NULL)
|
||||
{
|
||||
dest_widget->event_handler(dest_widget, event);
|
||||
}
|
||||
else
|
||||
{
|
||||
return rtgui_toplevel_event_handler(widget, event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_CLOSE:
|
||||
case RTGUI_EVENT_WIN_ACTIVATE:
|
||||
case RTGUI_EVENT_WIN_DEACTIVATE:
|
||||
{
|
||||
struct rtgui_event_win* wevent = (struct rtgui_event_win*)event;
|
||||
struct rtgui_widget* dest_widget = RTGUI_WIDGET(wevent->wid);
|
||||
if (dest_widget != RT_NULL && dest_widget->event_handler != RT_NULL)
|
||||
{
|
||||
dest_widget->event_handler(dest_widget, event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RTGUI_EVENT_WIN_MOVE:
|
||||
{
|
||||
struct rtgui_event_win_move* wevent = (struct rtgui_event_win_move*)event;
|
||||
struct rtgui_toplevel* top = RTGUI_TOPLEVEL(wevent->wid);
|
||||
if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
|
||||
{
|
||||
RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return rtgui_toplevel_event_handler(widget, event);
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* view on workbench
|
||||
*
|
||||
*/
|
||||
|
||||
void rtgui_workbench_add_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
|
||||
{
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(workbench), RTGUI_WIDGET(view));
|
||||
/* hide view in default */
|
||||
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view));
|
||||
|
||||
/* reset view extent */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(view), &(RTGUI_WIDGET(workbench)->extent));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
void rtgui_workbench_show_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
|
||||
{
|
||||
RT_ASSERT(workbench != RT_NULL);
|
||||
RT_ASSERT(view != RT_NULL);
|
||||
|
||||
/* already shown */
|
||||
if (workbench->current_view == view) return;
|
||||
|
||||
if (workbench->current_view != RT_NULL)
|
||||
{
|
||||
/* hide old view */
|
||||
RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench->current_view));
|
||||
}
|
||||
|
||||
/* show view */
|
||||
RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(view));
|
||||
workbench->current_view = view;
|
||||
|
||||
/* update workbench clip */
|
||||
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
|
||||
|
||||
if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(workbench)))
|
||||
{
|
||||
rtgui_widget_update(RTGUI_WIDGET(view));
|
||||
}
|
||||
}
|
||||
|
||||
void rtgui_workbench_hide_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
|
||||
{
|
||||
RT_ASSERT(workbench != RT_NULL);
|
||||
RT_ASSERT(view != RT_NULL);
|
||||
|
||||
/* hide 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, RT_FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* update workbench clip */
|
||||
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,40 +1,46 @@
|
|||
from building import *
|
||||
|
||||
src = Split("""
|
||||
'''
|
||||
demo_view_dc_buffer.c
|
||||
demo_view_instrument_panel.c
|
||||
demo_fnview.c
|
||||
demo_listview.c
|
||||
demo_listview_icon.c
|
||||
demo_panel_single.c
|
||||
demo_view.c
|
||||
demo_view_animation.c
|
||||
demo_view_buffer_animation.c
|
||||
demo_view_box.c
|
||||
demo_view_button.c
|
||||
demo_view_checkbox.c
|
||||
demo_view_dc.c
|
||||
demo_view_image.c
|
||||
demo_view_module.c
|
||||
'''
|
||||
|
||||
src = Split("""
|
||||
demo_application.c
|
||||
demo_view.c
|
||||
demo_view_benchmark.c
|
||||
demo_view_dc.c
|
||||
demo_view_ttf.c
|
||||
demo_view_dc_buffer.c
|
||||
demo_view_animation.c
|
||||
demo_view_buffer_animation.c
|
||||
demo_view_instrument_panel.c
|
||||
demo_view_window.c
|
||||
demo_view_label.c
|
||||
demo_view_mywidget.c
|
||||
demo_view_button.c
|
||||
demo_view_checkbox.c
|
||||
demo_view_progressbar.c
|
||||
demo_view_scrollbar.c
|
||||
demo_view_radiobox.c
|
||||
demo_view_textbox.c
|
||||
demo_view_listbox.c
|
||||
demo_view_menu.c
|
||||
demo_view_listctrl.c
|
||||
demo_view_combobox.c
|
||||
demo_view_slider.c
|
||||
demo_view_notebook.c
|
||||
demo_view_combobox.c
|
||||
demo_view_listctrl.c
|
||||
demo_view_menu.c
|
||||
demo_view_scrollbar.c
|
||||
demo_view_textbox.c
|
||||
demo_view_window.c
|
||||
demo_view_benchmark.c
|
||||
demo_workbench.c
|
||||
gui_init.c
|
||||
demo_view_mywidget.c
|
||||
mywidget.c
|
||||
""")
|
||||
|
||||
|
||||
|
||||
group = DefineGroup('gui_examples', src, depend = ['RT_USING_RTGUI'])
|
||||
|
||||
Return('group')
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
|
||||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/widgets/notebook.h>
|
||||
|
||||
struct rtgui_notebook *the_notebook;
|
||||
|
||||
static rt_bool_t demo_handle_key(struct rtgui_object* object, struct rtgui_event* event)
|
||||
{
|
||||
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
|
||||
|
||||
if (ekbd->type == RTGUI_KEYDOWN)
|
||||
{
|
||||
if (ekbd->key == RTGUIK_RIGHT)
|
||||
{
|
||||
demo_view_next(RT_NULL, RT_NULL);
|
||||
return RT_TRUE;
|
||||
}
|
||||
else if (ekbd->key == RTGUIK_LEFT)
|
||||
{
|
||||
demo_view_prev(RT_NULL, RT_NULL);
|
||||
return RT_TRUE;
|
||||
}
|
||||
}
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
struct rtgui_win *main_win;
|
||||
static void application_entry(void* parameter)
|
||||
{
|
||||
struct rtgui_application *app;
|
||||
struct rtgui_rect rect;
|
||||
|
||||
app = rtgui_application_create(rt_thread_self(), "gui_demo");
|
||||
if (app == RT_NULL)
|
||||
return;
|
||||
|
||||
/* create a full screen window */
|
||||
rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect);
|
||||
|
||||
main_win = rtgui_win_create(RT_NULL, "demo_win", &rect,
|
||||
/*RTGUI_WIN_STYLE_DESKTOP_DEFAULT);*/
|
||||
RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE);
|
||||
if (main_win == RT_NULL)
|
||||
{
|
||||
rtgui_application_destroy(app);
|
||||
return;
|
||||
}
|
||||
|
||||
rtgui_win_set_onkey(main_win, demo_handle_key);
|
||||
|
||||
/* create a no title notebook that we can switch demo on it easily. */
|
||||
the_notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_NOTAB);
|
||||
if (the_notebook == RT_NULL)
|
||||
{
|
||||
rtgui_win_destroy(main_win);
|
||||
rtgui_application_destroy(app);
|
||||
return;
|
||||
}
|
||||
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(main_win), RTGUI_WIDGET(the_notebook));
|
||||
|
||||
/* 初始化各个例子的视图 */
|
||||
demo_view_benchmark();
|
||||
|
||||
demo_view_dc();
|
||||
#ifdef RTGUI_USING_TTF
|
||||
demo_view_ttf();
|
||||
#endif
|
||||
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
demo_view_dc_buffer();
|
||||
#endif
|
||||
demo_view_animation();
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
demo_view_buffer_animation();
|
||||
demo_view_instrument_panel();
|
||||
#endif
|
||||
demo_view_window();
|
||||
demo_view_label();
|
||||
demo_view_button();
|
||||
demo_view_checkbox();
|
||||
demo_view_progressbar();
|
||||
demo_view_scrollbar();
|
||||
demo_view_radiobox();
|
||||
demo_view_textbox();
|
||||
demo_view_listbox();
|
||||
demo_view_menu();
|
||||
demo_view_listctrl();
|
||||
demo_view_combobox();
|
||||
demo_view_slider();
|
||||
demo_view_notebook();
|
||||
demo_view_mywidget();
|
||||
#if 0
|
||||
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
|
||||
demo_view_image();
|
||||
#endif
|
||||
#ifdef RT_USING_MODULE
|
||||
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
|
||||
demo_view_module();
|
||||
#endif
|
||||
#endif
|
||||
demo_listview_view();
|
||||
demo_listview_icon_view();
|
||||
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
|
||||
demo_fn_view();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
rtgui_win_show(main_win, RT_FALSE);
|
||||
|
||||
/* 执行工作台事件循环 */
|
||||
rtgui_application_run(app);
|
||||
|
||||
rtgui_application_destroy(app);
|
||||
}
|
||||
|
||||
void application_init()
|
||||
{
|
||||
static rt_bool_t inited = RT_FALSE;
|
||||
|
||||
if (inited == RT_FALSE) /* 避免重复初始化而做的保护 */
|
||||
{
|
||||
rt_thread_t tid;
|
||||
|
||||
tid = rt_thread_create("wb",
|
||||
application_entry, RT_NULL,
|
||||
2048 * 2, 25, 10);
|
||||
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
|
||||
inited = RT_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef RT_USING_FINSH
|
||||
#include <finsh.h>
|
||||
void application()
|
||||
{
|
||||
application_init();
|
||||
}
|
||||
/* finsh的命令输出,可以直接执行application()函数以执行上面的函数 */
|
||||
FINSH_FUNCTION_EXPORT(application, application demo)
|
||||
#endif
|
|
@ -20,7 +20,7 @@ static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
|||
rtgui_rect_t rect;
|
||||
|
||||
/* 获得顶层的workbench对象 */
|
||||
workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
|
||||
workbench = RTGUI_APPLICATION(rtgui_widget_get_toplevel(widget));
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
|
||||
|
||||
/* 针对Win32平台和其他平台做的不同的其实目录位置 */
|
||||
|
@ -31,7 +31,7 @@ static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
|||
#endif
|
||||
|
||||
/* 采用模式形式显示文件列表视图 */
|
||||
if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
|
||||
if (rtgui_container_show(RTGUI_CONTAINER(view), RT_TRUE) == RTGUI_MODAL_OK)
|
||||
{
|
||||
char path[32];
|
||||
|
||||
|
@ -43,14 +43,14 @@ static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
|||
}
|
||||
|
||||
/* 删除 文件列表 视图 */
|
||||
rtgui_view_destroy(RTGUI_VIEW(view));
|
||||
rtgui_container_destroy(RTGUI_CONTAINER(view));
|
||||
}
|
||||
|
||||
/* 创建用于演示文件列表视图的视图 */
|
||||
rtgui_view_t* demo_fn_view(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t* demo_fn_view(rtgui_workbench_t* workbench)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_container_t* view;
|
||||
rtgui_button_t* open_btn;
|
||||
rtgui_font_t* font;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* 程序清单:列表视图演示
|
||||
*
|
||||
* 这个例子会先创建出一个演示用的view,当点击上面的按钮时会按照模式显示的形式显示
|
||||
* 这个例子会先创建出一个演示用的container,当点击上面的按钮时会按照模式显示的形式显示
|
||||
* 新的列表视图
|
||||
*/
|
||||
#include "demo_view.h"
|
||||
|
@ -10,16 +10,12 @@
|
|||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/widgets/list_view.h>
|
||||
|
||||
static rtgui_workbench_t* workbench = RT_NULL;
|
||||
static struct rtgui_application *application = RT_NULL;
|
||||
static rtgui_list_view_t* _view = RT_NULL;
|
||||
// static rtgui_image_t* return_image = RT_NULL;
|
||||
|
||||
/* 列表项的动作函数 */
|
||||
#if RTTHREAD_VERSION >= 10000
|
||||
static void listitem_action(rtgui_widget_t *widget, void* parameter)
|
||||
#else
|
||||
static void listitem_action(void* parameter)
|
||||
#endif
|
||||
{
|
||||
char label_text[32];
|
||||
rtgui_win_t *win;
|
||||
|
@ -30,7 +26,7 @@ static void listitem_action(void* parameter)
|
|||
rtgui_rect_moveto(&rect, 20, 50);
|
||||
|
||||
/* 显示消息窗口 */
|
||||
win = rtgui_win_create(RTGUI_TOPLEVEL(workbench),
|
||||
win = rtgui_win_create(RTGUI_TOPLEVEL(application),
|
||||
"窗口", &rect, RTGUI_WIN_STYLE_DEFAULT);
|
||||
|
||||
rect.x1 += 20;
|
||||
|
@ -43,20 +39,16 @@ static void listitem_action(void* parameter)
|
|||
label = rtgui_label_create(label_text);
|
||||
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));
|
||||
rtgui_container_add_child(win, RTGUI_WIDGET(label));
|
||||
|
||||
/* 非模态显示窗口 */
|
||||
rtgui_win_show(win, RT_FALSE);
|
||||
}
|
||||
|
||||
/* 返回功能的动作函数 */
|
||||
#if RTTHREAD_VERSION >= 10000
|
||||
static void return_action(rtgui_widget_t* widget, void* parameter)
|
||||
#else
|
||||
static void return_action(void* parameter)
|
||||
#endif
|
||||
{
|
||||
rtgui_view_end_modal(RTGUI_VIEW(_view), RTGUI_MODAL_OK);
|
||||
rtgui_container_end_modal(RTGUI_CONTAINER(_view), RTGUI_MODAL_OK);
|
||||
}
|
||||
|
||||
/* 各个列表项定义 */
|
||||
|
@ -75,41 +67,41 @@ static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
|||
{
|
||||
rtgui_rect_t rect;
|
||||
|
||||
/* 获得顶层的workbench */
|
||||
workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
|
||||
/* 获得顶层的application */
|
||||
application = RTGUI_APPLICATION(rtgui_widget_get_toplevel(widget));
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(application), &rect);
|
||||
|
||||
/* 创建一个列表视图, 项指定为items */
|
||||
_view = rtgui_list_view_create(items, sizeof(items)/sizeof(struct rtgui_list_item),
|
||||
&rect, RTGUI_LIST_VIEW_LIST);
|
||||
/* 在workbench中添加相应的视图 */
|
||||
rtgui_workbench_add_view(workbench, RTGUI_VIEW(_view));
|
||||
|
||||
rtgui_application_add_container(application, RTGUI_CONTAINER(_view));
|
||||
|
||||
/* 模式显示视图 */
|
||||
rtgui_view_show(RTGUI_VIEW(_view), RT_TRUE);
|
||||
rtgui_view_destroy(RTGUI_VIEW(_view));
|
||||
rtgui_container_show(RTGUI_CONTAINER(_view), RT_TRUE);
|
||||
rtgui_container_destroy(RTGUI_CONTAINER(_view));
|
||||
_view = RT_NULL;
|
||||
}
|
||||
|
||||
/* 创建用于演示列表视图的视图 */
|
||||
rtgui_view_t* demo_listview_view(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t* demo_listview_view(void)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t *view;
|
||||
rtgui_container_t *container;
|
||||
rtgui_button_t* open_btn;
|
||||
|
||||
view = demo_view(workbench, "列表视图演示");
|
||||
container = demo_view("列表视图演示");
|
||||
|
||||
/* 添加动作按钮 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 80;
|
||||
rect.y1 += 30;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
open_btn = rtgui_button_create("打开列表");
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn));
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(open_btn));
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
|
||||
rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
|
||||
|
||||
return view;
|
||||
return container;
|
||||
}
|
||||
|
|
|
@ -10,15 +10,11 @@
|
|||
#include <rtgui/widgets/window.h>
|
||||
#include <rtgui/widgets/list_view.h>
|
||||
|
||||
static rtgui_workbench_t* workbench = RT_NULL;
|
||||
static struct rtgui_application *application = RT_NULL;
|
||||
static rtgui_list_view_t* _view = RT_NULL;
|
||||
|
||||
/* 列表项的动作函数 */
|
||||
#if RTTHREAD_VERSION >= 10000
|
||||
static void listitem_action(rtgui_widget_t* widget, void* parameter)
|
||||
#else
|
||||
static void listitem_action(void* parameter)
|
||||
#endif
|
||||
{
|
||||
char label_text[32];
|
||||
rtgui_win_t *win;
|
||||
|
@ -29,7 +25,7 @@ static void listitem_action(void* parameter)
|
|||
rtgui_rect_moveto(&rect, 20, 50);
|
||||
|
||||
/* 显示消息窗口 */
|
||||
win = rtgui_win_create(RTGUI_TOPLEVEL(workbench),
|
||||
win = rtgui_win_create(RTGUI_TOPLEVEL(application),
|
||||
"窗口", &rect, RTGUI_WIN_STYLE_DEFAULT);
|
||||
|
||||
rect.x1 += 20;
|
||||
|
@ -49,14 +45,14 @@ static void listitem_action(void* parameter)
|
|||
}
|
||||
|
||||
/* 返回功能的动作函数 */
|
||||
#if RTTHREAD_VERSION >= 10000
|
||||
#if RT_VERSION == 4
|
||||
static void return_action(rtgui_widget_t* widget, void* parameter)
|
||||
#else
|
||||
static void return_action(void* parameter)
|
||||
#endif
|
||||
{
|
||||
/* 退出模态显示 */
|
||||
rtgui_view_end_modal(RTGUI_VIEW(_view), RTGUI_MODAL_OK);
|
||||
rtgui_container_end_modal(RTGUI_CONTAINER(_view), RTGUI_MODAL_OK);
|
||||
}
|
||||
|
||||
/* 列表项 */
|
||||
|
@ -286,9 +282,9 @@ static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
|||
rtgui_rect_t rect;
|
||||
rt_uint32_t index;
|
||||
|
||||
/* 获得顶层的workbench */
|
||||
workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
|
||||
/* 获得顶层的application */
|
||||
application = RTGUI_APPLICATION(rtgui_widget_get_toplevel(widget));
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(application), &rect);
|
||||
|
||||
/* 初始化图标列表 */
|
||||
if (items == RT_NULL)
|
||||
|
@ -313,24 +309,24 @@ static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
|||
|
||||
/* 创建一个列表视图, 项指定为items */
|
||||
_view = rtgui_list_view_create(items, ITEM_MAX + 1, &rect, RTGUI_LIST_VIEW_ICON);
|
||||
/* 在workbench中添加相应的视图 */
|
||||
rtgui_workbench_add_view(workbench, RTGUI_VIEW(_view));
|
||||
/* 在application中添加相应的视图 */
|
||||
rtgui_application_add_container(application, RTGUI_CONTAINER(_view));
|
||||
|
||||
/* 模式显示视图 */
|
||||
rtgui_view_show(RTGUI_VIEW(_view), RT_TRUE);
|
||||
rtgui_view_destroy(RTGUI_VIEW(_view));
|
||||
rtgui_container_show(RTGUI_CONTAINER(_view), RT_TRUE);
|
||||
rtgui_container_destroy(RTGUI_CONTAINER(_view));
|
||||
|
||||
_view = RT_NULL;
|
||||
}
|
||||
|
||||
/* 创建用于演示列表视图的视图 */
|
||||
rtgui_view_t* demo_listview_icon_view(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t* demo_listview_icon_view(struct rtgui_application *app)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t *view;
|
||||
rtgui_container_t *view;
|
||||
rtgui_button_t* open_btn;
|
||||
|
||||
view = demo_view(workbench, "图标视图演示");
|
||||
view = demo_view(app, "图标视图演示");
|
||||
|
||||
if (item_icon == RT_NULL)
|
||||
item_icon = rtgui_image_create_from_mem("xpm",
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
static void workbench_entry(void* parameter)
|
||||
{
|
||||
rt_mq_t mq;
|
||||
rtgui_view_t* view;
|
||||
rtgui_container_t* view;
|
||||
rtgui_label_t* label;
|
||||
struct rtgui_workbench* workbench;
|
||||
rtgui_rect_t rect;
|
||||
|
@ -22,7 +22,7 @@ static void workbench_entry(void* parameter)
|
|||
workbench = rtgui_workbench_create("main", "workbench #1");
|
||||
if (workbench == RT_NULL) return;
|
||||
|
||||
view = rtgui_view_create("view");
|
||||
view = rtgui_container_create("view");
|
||||
if (view == RT_NULL) return;
|
||||
/* 指定视图的背景色 */
|
||||
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
|
||||
|
@ -38,7 +38,7 @@ static void workbench_entry(void* parameter)
|
|||
/* 添加到父workbench中 */
|
||||
rtgui_workbench_add_view(workbench, view);
|
||||
/* 非模式方式显示视图 */
|
||||
rtgui_view_show(view, RT_FALSE);
|
||||
rtgui_container_show(view, RT_FALSE);
|
||||
|
||||
/* 执行工作台事件循环 */
|
||||
rtgui_workbench_event_loop(workbench);
|
||||
|
|
|
@ -1,141 +1,128 @@
|
|||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
|
||||
#include <rtgui/widgets/container.h>
|
||||
#include <rtgui/widgets/notebook.h>
|
||||
#include <rtgui/widgets/button.h>
|
||||
#include <rtgui/widgets/workbench.h>
|
||||
#include <rtgui/widgets/staticline.h>
|
||||
|
||||
/* 用于存放演示视图的数组,最多可创建32个演示视图 */
|
||||
static rtgui_view_t* demo_view_list[32];
|
||||
/* 当前演示视图索引 */
|
||||
static rt_uint16_t demo_view_current = 0;
|
||||
/* 总共包括的演示视图数目 */
|
||||
static rt_uint16_t demo_view_number = 0;
|
||||
extern struct rtgui_notebook *the_notebook;
|
||||
|
||||
/* 显示下一个演示视图 */
|
||||
void demo_view_next(struct rtgui_widget* widget, rtgui_event_t *event)
|
||||
void demo_view_next(struct rtgui_object *object, struct rtgui_event *event)
|
||||
{
|
||||
if (demo_view_current + 1< demo_view_number)
|
||||
{
|
||||
demo_view_current ++;
|
||||
rtgui_view_show(demo_view_list[demo_view_current], RT_FALSE);
|
||||
}
|
||||
rtgui_notebook_set_current_by_index(the_notebook,
|
||||
(rtgui_notebook_get_current_index(the_notebook) + 1) %
|
||||
rtgui_notebook_get_count(the_notebook));
|
||||
}
|
||||
|
||||
/* 显示前一个演示视图 */
|
||||
void demo_view_prev(struct rtgui_widget* widget, rtgui_event_t *event)
|
||||
void demo_view_prev(struct rtgui_object *object, struct rtgui_event *event)
|
||||
{
|
||||
if (demo_view_current != 0)
|
||||
{
|
||||
demo_view_current --;
|
||||
rtgui_view_show(demo_view_list[demo_view_current], RT_FALSE);
|
||||
}
|
||||
rt_int16_t cur_idx = rtgui_notebook_get_current_index(the_notebook);
|
||||
|
||||
if (cur_idx == 0)
|
||||
rtgui_notebook_set_current_by_index(the_notebook,
|
||||
rtgui_notebook_get_count(the_notebook) - 1);
|
||||
else
|
||||
rtgui_notebook_set_current_by_index(the_notebook,
|
||||
--cur_idx);
|
||||
}
|
||||
|
||||
/* 创建一个演示视图,需提供父workbench和演示用的标题 */
|
||||
rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title)
|
||||
rtgui_container_t* demo_view(const char *title)
|
||||
{
|
||||
struct rtgui_view* view;
|
||||
struct rtgui_container *container;
|
||||
struct rtgui_label *label;
|
||||
struct rtgui_staticline *line;
|
||||
struct rtgui_button *next_btn, *prev_btn;
|
||||
struct rtgui_rect rect;
|
||||
|
||||
/* 设置视图的名称 */
|
||||
view = rtgui_view_create(title);
|
||||
if (view == RT_NULL) return RT_NULL;
|
||||
container = rtgui_container_create();
|
||||
if (container == RT_NULL)
|
||||
return RT_NULL;
|
||||
|
||||
/* 创建成功后,添加到数组中 */
|
||||
demo_view_list[demo_view_number] = view;
|
||||
demo_view_number ++;
|
||||
rtgui_notebook_add(the_notebook, title, RTGUI_WIDGET(container));
|
||||
|
||||
/* 添加到父workbench中 */
|
||||
rtgui_workbench_add_view(workbench, view);
|
||||
/* 获得视图的位置信息(在加入到 notebook 中时,notebook 会自动调整 container
|
||||
* 的大小) */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
|
||||
rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
|
||||
rect.x1 += 5;
|
||||
rect.y1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
|
||||
/* 添加下一个视图和前一个视图按钮 */
|
||||
{
|
||||
struct rtgui_rect rect;
|
||||
struct rtgui_button *next_btn, *prev_btn;
|
||||
struct rtgui_label *label;
|
||||
struct rtgui_staticline *line;
|
||||
/* 创建标题用的标签 */
|
||||
label = rtgui_label_create(title);
|
||||
/* 设置标签位置信息 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
/* 添加标签到视图中 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(label));
|
||||
|
||||
/* 获得视图的位置信息(在加入到workbench中时,workbench会自动调整视图的大小) */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
||||
rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
|
||||
rect.x1 += 5;
|
||||
rect.y1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
rect.y1 += 20;
|
||||
rect.y2 += 20;
|
||||
/* 创建一个水平的 staticline 线 */
|
||||
line = rtgui_staticline_create(RTGUI_HORIZONTAL);
|
||||
/* 设置静态线的位置信息 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(line), &rect);
|
||||
/* 添加静态线到视图中 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(line));
|
||||
|
||||
/* 创建标题用的标签 */
|
||||
label = rtgui_label_create(title);
|
||||
/* 设置标签位置信息 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
/* 添加标签到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
/* 获得视图的位置信息 */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
|
||||
rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
|
||||
rect.x2 -= 5;
|
||||
rect.y2 -= 5;
|
||||
rect.x1 = rect.x2 - 100;
|
||||
rect.y1 = rect.y2 - 25;
|
||||
|
||||
rect.y1 += 20;
|
||||
rect.y2 += 20;
|
||||
/* 创建一个水平的staticline线 */
|
||||
line = rtgui_staticline_create(RTGUI_HORIZONTAL);
|
||||
/* 设置静态线的位置信息 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(line), &rect);
|
||||
/* 添加静态线到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(line));
|
||||
/* 创建"下一个"按钮 */
|
||||
next_btn = rtgui_button_create("下一个");
|
||||
/* 设置onbutton动作到demo_view_next函数 */
|
||||
rtgui_button_set_onbutton(next_btn, demo_view_next);
|
||||
/* 设置按钮的位置信息 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(next_btn), &rect);
|
||||
/* 添加按钮到视图中 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(next_btn));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
||||
rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
|
||||
rect.x2 -= 5;
|
||||
rect.y2 -= 5;
|
||||
rect.x1 = rect.x2 - 100;
|
||||
rect.y1 = rect.y2 - 25;
|
||||
/* 获得视图的位置信息 */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
|
||||
rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
|
||||
rect.x1 += 5;
|
||||
rect.y2 -= 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 = rect.y2 - 25;
|
||||
|
||||
/* 创建"下一个"按钮 */
|
||||
next_btn = rtgui_button_create("下一个");
|
||||
/* 设置onbutton动作到demo_view_next函数 */
|
||||
rtgui_button_set_onbutton(next_btn, demo_view_next);
|
||||
/* 设置按钮的位置信息 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(next_btn), &rect);
|
||||
/* 添加按钮到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(next_btn));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
||||
rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
|
||||
rect.x1 += 5;
|
||||
rect.y2 -= 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 = rect.y2 - 25;
|
||||
|
||||
/* 创建"上一个"按钮 */
|
||||
prev_btn = rtgui_button_create("上一个");
|
||||
/* 设置onbutton动作到demo_view_prev函数 */
|
||||
rtgui_button_set_onbutton(prev_btn, demo_view_prev);
|
||||
/* 设置按钮的位置信息 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(prev_btn), &rect);
|
||||
/* 添加按钮到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(prev_btn));
|
||||
}
|
||||
/* 创建"上一个"按钮 */
|
||||
prev_btn = rtgui_button_create("上一个");
|
||||
/* 设置onbutton动作到demo_view_prev函数 */
|
||||
rtgui_button_set_onbutton(prev_btn, demo_view_prev);
|
||||
/* 设置按钮的位置信息 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(prev_btn), &rect);
|
||||
/* 添加按钮到视图中 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(prev_btn));
|
||||
|
||||
/* 返回创建的视图 */
|
||||
return view;
|
||||
return container;
|
||||
}
|
||||
|
||||
/* 这个函数用于返回演示视图的对外可用区域 */
|
||||
void demo_view_get_rect(rtgui_view_t* view, rtgui_rect_t *rect)
|
||||
void demo_view_get_rect(rtgui_container_t* container, rtgui_rect_t *rect)
|
||||
{
|
||||
RT_ASSERT(view != RT_NULL);
|
||||
RT_ASSERT(container != RT_NULL);
|
||||
RT_ASSERT(rect != RT_NULL);
|
||||
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), rect);
|
||||
rtgui_widget_rect_to_device(RTGUI_WIDGET(view), rect);
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(container), rect);
|
||||
rtgui_widget_rect_to_device(RTGUI_WIDGET(container), rect);
|
||||
/* 去除演示标题和下方按钮的区域 */
|
||||
rect->y1 += 45;
|
||||
rect->y2 -= 35;
|
||||
}
|
||||
|
||||
void demo_view_get_logic_rect(rtgui_view_t* view, rtgui_rect_t *rect)
|
||||
void demo_view_get_logic_rect(rtgui_container_t* container, rtgui_rect_t *rect)
|
||||
{
|
||||
RT_ASSERT(view != RT_NULL);
|
||||
RT_ASSERT(container != RT_NULL);
|
||||
RT_ASSERT(rect != RT_NULL);
|
||||
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), rect);
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(container), rect);
|
||||
/* 去除演示标题和下方按钮的区域 */
|
||||
rect->y1 += 45;
|
||||
rect->y2 -= 35;
|
||||
|
@ -143,30 +130,21 @@ void demo_view_get_logic_rect(rtgui_view_t* view, rtgui_rect_t *rect)
|
|||
|
||||
/* 当是标准版本时,这个函数用于返回自动布局引擎box控件 */
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
rtgui_box_t* demo_view_create_box(rtgui_view_t* view, int orient)
|
||||
struct rtgui_box* demo_view_create_box(struct rtgui_container *container, int orient)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_box_t* box;
|
||||
struct rtgui_box* box;
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
|
||||
rect.y1 += 45;
|
||||
rect.y2 -= 25;
|
||||
|
||||
/* 创建一个自动布局引擎 */
|
||||
box = rtgui_box_create(orient, &rect);
|
||||
/* 添加box控件到视图中 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(box));
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(box));
|
||||
|
||||
return box;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* 这个函数用于显示当前的视图 */
|
||||
void demo_view_show()
|
||||
{
|
||||
if (demo_view_number != 0)
|
||||
{
|
||||
rtgui_view_show(demo_view_list[demo_view_current], RT_FALSE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,24 +15,24 @@
|
|||
#define __DEMO_VIEW_H__
|
||||
|
||||
#include <rtgui/rtgui.h>
|
||||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/widgets/workbench.h>
|
||||
#include <rtgui/rtgui_application.h>
|
||||
#include <rtgui/widgets/container.h>
|
||||
|
||||
/* 如果是标准版本,可以启用box自动布局引擎 */
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
#include <rtgui/widgets/box.h>
|
||||
#endif
|
||||
|
||||
/* 创建一个演示视图,需要给出这个视图所在的workbench和演示标题 */
|
||||
rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title);
|
||||
/* 创建一个演示视图,需要给出这个视图的演示标题 */
|
||||
rtgui_container_t* demo_view(const char* title);
|
||||
/* 获得演示视图提供给演示控件用的区域信息 */
|
||||
void demo_view_get_rect(rtgui_view_t* view, rtgui_rect_t *rect);
|
||||
void demo_view_get_logic_rect(rtgui_view_t* view, rtgui_rect_t *rect);
|
||||
void demo_view_get_rect(rtgui_container_t* view, rtgui_rect_t *rect);
|
||||
void demo_view_get_logic_rect(rtgui_container_t* view, rtgui_rect_t *rect);
|
||||
void demo_view_show(void);
|
||||
|
||||
/* 如果是标准版,可以调用这个函数获得一个自动布局引擎 */
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
rtgui_box_t* demo_view_create_box(rtgui_view_t* view, int orient);
|
||||
rtgui_box_t* demo_view_create_box(rtgui_container_t* view, int orient);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <rtgui/dc.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/widgets/container.h>
|
||||
#include "demo_view.h"
|
||||
|
||||
/*
|
||||
|
@ -16,19 +16,19 @@ static rtgui_timer_t *timer;
|
|||
void timeout(struct rtgui_timer* timer, void* parameter)
|
||||
{
|
||||
struct rtgui_dc* dc;
|
||||
rtgui_rect_t rect;
|
||||
rtgui_widget_t *widget;
|
||||
struct rtgui_rect rect;
|
||||
struct rtgui_widget *widget;
|
||||
|
||||
/* 控件(view)通过parameter参数传递给定时器 */
|
||||
widget = (rtgui_widget_t*)parameter;
|
||||
/* 控件(container)通过parameter参数传递给定时器 */
|
||||
widget = RTGUI_WIDGET(parameter);
|
||||
|
||||
/* 获得控件所属的DC */
|
||||
dc = rtgui_dc_begin_drawing(widget);
|
||||
if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
|
||||
return ;
|
||||
|
||||
/* 获得demo view允许绘图的区域,主要用于判断边界 */
|
||||
demo_view_get_rect(RTGUI_VIEW(widget), &rect);
|
||||
/* 获得demo container允许绘图的区域,主要用于判断边界 */
|
||||
demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
|
||||
rect.y2 -= 5;
|
||||
|
||||
/* 判断是否是第一次绘图 */
|
||||
|
@ -59,23 +59,25 @@ void timeout(struct rtgui_timer* timer, void* parameter)
|
|||
rtgui_dc_end_drawing(dc);
|
||||
}
|
||||
|
||||
rt_bool_t animation_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
||||
rt_bool_t animation_event_handler(struct rtgui_object* object, rtgui_event_t *event)
|
||||
{
|
||||
struct rtgui_widget *widget = RTGUI_WIDGET(object);
|
||||
|
||||
if (event->type == RTGUI_EVENT_PAINT)
|
||||
{
|
||||
struct rtgui_dc* dc;
|
||||
rtgui_rect_t rect;
|
||||
|
||||
/* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view先绘图 */
|
||||
rtgui_view_event_handler(widget, event);
|
||||
/* 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container先绘图 */
|
||||
rtgui_container_event_handler(object, event);
|
||||
|
||||
/* 获得控件所属的DC */
|
||||
dc = rtgui_dc_begin_drawing(widget);
|
||||
if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
|
||||
return RT_FALSE;
|
||||
|
||||
/* 获得demo view允许绘图的区域 */
|
||||
demo_view_get_rect(RTGUI_VIEW(widget), &rect);
|
||||
/* 获得demo container允许绘图的区域 */
|
||||
demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
|
||||
|
||||
/* 擦除所有 */
|
||||
rtgui_dc_fill_rect(dc, &rect);
|
||||
|
@ -89,25 +91,42 @@ rt_bool_t animation_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
|||
else
|
||||
{
|
||||
/* 调用默认的事件处理函数 */
|
||||
return rtgui_view_event_handler(widget, event);
|
||||
return rtgui_container_event_handler(object, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rtgui_view_t *demo_view_animation(rtgui_workbench_t* workbench)
|
||||
static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event)
|
||||
{
|
||||
rtgui_view_t *view;
|
||||
|
||||
view = demo_view(workbench, "DC 动画");
|
||||
if (view != RT_NULL)
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), animation_event_handler);
|
||||
|
||||
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), "飞线乱飞", &text_rect);
|
||||
rtgui_rect_moveto(&text_rect, 0, 45);
|
||||
/* 启动定时器以触发动画 */
|
||||
timer = rtgui_timer_create(2, RT_TIMER_FLAG_PERIODIC, timeout, (void*)view);
|
||||
rtgui_timer_start(timer);
|
||||
|
||||
return view;
|
||||
rt_kprintf("animation on show\n");
|
||||
if (timer != RT_NULL)
|
||||
rtgui_timer_start(timer);
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event)
|
||||
{
|
||||
rt_kprintf("animation on hide\n");
|
||||
if (timer != RT_NULL)
|
||||
rtgui_timer_stop(timer);
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
rtgui_container_t *demo_view_animation()
|
||||
{
|
||||
rtgui_container_t *container;
|
||||
|
||||
container = demo_view("DC 动画");
|
||||
if (container != RT_NULL)
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(container), animation_event_handler);
|
||||
|
||||
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(container)), "飞线乱飞", &text_rect);
|
||||
rtgui_rect_moveto(&text_rect, 0, 45);
|
||||
timer = rtgui_timer_create(2, RT_TIMER_FLAG_PERIODIC, timeout, (void*)container);
|
||||
|
||||
rtgui_widget_set_onshow(RTGUI_WIDGET(container), animation_on_show);
|
||||
rtgui_widget_set_onhide(RTGUI_WIDGET(container), animation_on_hide);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
#include <rtgui/dc.h>
|
||||
#include <rtgui/dc_hw.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/widgets/container.h>
|
||||
#include "demo_view.h"
|
||||
|
||||
#if RTTHREAD_VERSION >= 10000
|
||||
#define RAND(x1, x2) ((rand() % (x2 - x1)) + x1)
|
||||
|
||||
static rtgui_view_t* view = RT_NULL;
|
||||
static struct rtgui_container *container = RT_NULL;
|
||||
static int running = 0;
|
||||
|
||||
void _onidle(rtgui_widget_t* widget, rtgui_event_t *event)
|
||||
void _onidle(struct rtgui_object *object, rtgui_event_t *event)
|
||||
{
|
||||
rtgui_color_t color;
|
||||
rtgui_rect_t rect, draw_rect;
|
||||
struct rtgui_dc *dc;
|
||||
|
||||
/* 获得控件所属的DC */
|
||||
// dc = rtgui_dc_hw_create(RTGUI_WIDGET(view));
|
||||
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
|
||||
if (dc == RT_NULL) return ;
|
||||
// dc = rtgui_dc_hw_create(RTGUI_WIDGET(container));
|
||||
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(container));
|
||||
if (dc == RT_NULL)
|
||||
return;
|
||||
|
||||
demo_view_get_logic_rect(RTGUI_VIEW(view), &rect);
|
||||
demo_view_get_logic_rect(RTGUI_CONTAINER(container), &rect);
|
||||
draw_rect.x1 = RAND(rect.x1, rect.x2);
|
||||
draw_rect.y1 = RAND(rect.y1, rect.y2);
|
||||
draw_rect.x2 = RAND(draw_rect.x1, rect.x2);
|
||||
draw_rect.y2 = RAND(draw_rect.y1, rect.y2);
|
||||
|
||||
color = RTGUI_RGB(rand() % 255, rand() % 255, rand() % 255);
|
||||
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = color;
|
||||
RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(container)) = color;
|
||||
|
||||
rtgui_dc_fill_rect(dc, &draw_rect);
|
||||
|
||||
|
@ -36,21 +36,22 @@ void _onidle(rtgui_widget_t* widget, rtgui_event_t *event)
|
|||
rtgui_dc_end_drawing(dc);
|
||||
}
|
||||
|
||||
void _draw_default(rtgui_widget_t* widget, rtgui_event_t* event)
|
||||
void _draw_default(struct rtgui_object *object, rtgui_event_t* event)
|
||||
{
|
||||
struct rtgui_widget *widget = RTGUI_WIDGET(object);
|
||||
struct rtgui_dc* dc;
|
||||
rtgui_rect_t rect;
|
||||
|
||||
/* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view先绘图 */
|
||||
rtgui_view_event_handler(widget, event);
|
||||
/* 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container先绘图 */
|
||||
rtgui_container_event_handler(object, event);
|
||||
|
||||
/* 获得控件所属的DC */
|
||||
dc = rtgui_dc_begin_drawing(widget);
|
||||
if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
|
||||
return ;
|
||||
return;
|
||||
|
||||
/* 获得demo view允许绘图的区域 */
|
||||
demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect);
|
||||
/* 获得demo container允许绘图的区域 */
|
||||
demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
|
||||
|
||||
/* 擦除所有 */
|
||||
RTGUI_WIDGET_BACKGROUND(widget) = default_background;
|
||||
|
@ -63,11 +64,11 @@ void _draw_default(rtgui_widget_t* widget, rtgui_event_t* event)
|
|||
rtgui_dc_end_drawing(dc);
|
||||
}
|
||||
|
||||
rt_bool_t benchmark_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
||||
rt_bool_t benchmark_event_handler(struct rtgui_object *object, rtgui_event_t *event)
|
||||
{
|
||||
if (event->type == RTGUI_EVENT_PAINT)
|
||||
{
|
||||
_draw_default(widget, event);
|
||||
_draw_default(object, event);
|
||||
}
|
||||
else if (event->type == RTGUI_EVENT_KBD)
|
||||
{
|
||||
|
@ -78,13 +79,13 @@ rt_bool_t benchmark_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
|||
if (running)
|
||||
{
|
||||
/* stop */
|
||||
rtgui_thread_set_onidle(RT_NULL);
|
||||
_draw_default(widget, event);
|
||||
rtgui_application_set_onidle(RT_NULL);
|
||||
_draw_default(object, event);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* run */
|
||||
rtgui_thread_set_onidle(_onidle);
|
||||
rtgui_application_set_onidle(_onidle);
|
||||
}
|
||||
|
||||
running = !running;
|
||||
|
@ -94,18 +95,17 @@ rt_bool_t benchmark_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
|||
else
|
||||
{
|
||||
/* 调用默认的事件处理函数 */
|
||||
return rtgui_view_event_handler(widget, event);
|
||||
return rtgui_container_event_handler(object, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rtgui_view_t *demo_view_benchmark(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t *demo_view_benchmark(void)
|
||||
{
|
||||
srand(100);
|
||||
view = demo_view(workbench, "绘图测试");
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), benchmark_event_handler);
|
||||
container = demo_view("绘图测试");
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(container), benchmark_event_handler);
|
||||
|
||||
return view;
|
||||
return container;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
#include <rtgui/widgets/box.h>
|
||||
|
||||
rtgui_view_t* demo_view_box(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t* demo_view_box(rtgui_workbench_t* workbench)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_container_t* view;
|
||||
|
||||
view = demo_view(workbench, "Box View");
|
||||
demo_view_get_rect(view, &rect);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <rtgui/dc.h>
|
||||
#include <rtgui/rtgui_system.h>
|
||||
#include <rtgui/widgets/view.h>
|
||||
#include <rtgui/widgets/container.h>
|
||||
#include "demo_view.h"
|
||||
|
||||
/*
|
||||
|
@ -28,7 +28,7 @@ static void timeout(struct rtgui_timer* timer, void* parameter)
|
|||
return ;
|
||||
|
||||
/* 获得demo view允许绘图的区域,主要用于判断边界 */
|
||||
demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect);
|
||||
demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
|
||||
rect.y2 -= 5;
|
||||
|
||||
/* 判断是否是第一次绘图 */
|
||||
|
@ -56,15 +56,17 @@ static void timeout(struct rtgui_timer* timer, void* parameter)
|
|||
rtgui_dc_end_drawing(dc);
|
||||
}
|
||||
|
||||
static rt_bool_t animation_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
||||
static rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *event)
|
||||
{
|
||||
struct rtgui_widget *widget = RTGUI_WIDGET(object);
|
||||
|
||||
if (event->type == RTGUI_EVENT_PAINT)
|
||||
{
|
||||
struct rtgui_dc* dc;
|
||||
rtgui_rect_t rect;
|
||||
|
||||
/* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view先绘图 */
|
||||
rtgui_view_event_handler(widget, event);
|
||||
rtgui_container_event_handler(object, event);
|
||||
|
||||
/* 获得控件所属的DC */
|
||||
dc = rtgui_dc_begin_drawing(widget);
|
||||
|
@ -72,7 +74,7 @@ static rt_bool_t animation_event_handler(rtgui_widget_t* widget, rtgui_event_t *
|
|||
return RT_FALSE;
|
||||
|
||||
/* 获得demo view允许绘图的区域 */
|
||||
demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect);
|
||||
demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
|
||||
|
||||
/* 绘图 */
|
||||
rect = text_rect;
|
||||
|
@ -85,21 +87,37 @@ static rt_bool_t animation_event_handler(rtgui_widget_t* widget, rtgui_event_t *
|
|||
else
|
||||
{
|
||||
/* 调用默认的事件处理函数 */
|
||||
return rtgui_view_event_handler(widget, event);
|
||||
return rtgui_container_event_handler(object, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
rtgui_view_t *demo_view_buffer_animation(rtgui_workbench_t* workbench)
|
||||
static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event)
|
||||
{
|
||||
rtgui_view_t *view;
|
||||
rt_kprintf("buffer animation on show\n");
|
||||
rtgui_timer_start(timer);
|
||||
|
||||
view = demo_view(workbench, "DC »º³åÇø¶¯»");
|
||||
if (view != RT_NULL)
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), animation_event_handler);
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(view)), "»º³å¶¯»", &text_rect);
|
||||
static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event)
|
||||
{
|
||||
rt_kprintf("buffer animation on hide\n");
|
||||
rtgui_timer_stop(timer);
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
struct rtgui_container *demo_view_buffer_animation(void)
|
||||
{
|
||||
struct rtgui_container *container;
|
||||
|
||||
container= demo_view("DC »º³åÇø¶¯»");
|
||||
if (container!= RT_NULL)
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(container), animation_event_handler);
|
||||
|
||||
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(container)), "»º³å¶¯»", &text_rect);
|
||||
if (dc_buffer == RT_NULL)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
|
@ -109,7 +127,7 @@ rtgui_view_t *demo_view_buffer_animation(rtgui_workbench_t* workbench)
|
|||
|
||||
/* 创建 DC Buffer,长 50,宽 50 */
|
||||
dc_buffer = rtgui_dc_buffer_create(rtgui_rect_width(rect), rtgui_rect_height(rect));
|
||||
RTGUI_DC_FC(dc_buffer) = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view));
|
||||
RTGUI_DC_FC(dc_buffer) = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(container));
|
||||
rtgui_dc_fill_rect(dc_buffer, &rect);
|
||||
RTGUI_DC_FC(dc_buffer) = black;
|
||||
rect.x1 = 1; rect.y1 = 1;
|
||||
|
@ -117,8 +135,10 @@ rtgui_view_t *demo_view_buffer_animation(rtgui_workbench_t* workbench)
|
|||
}
|
||||
|
||||
/* 启动定时器以触发动画 */
|
||||
timer = rtgui_timer_create(1, RT_TIMER_FLAG_PERIODIC, timeout, (void*)view);
|
||||
rtgui_timer_start(timer);
|
||||
timer = rtgui_timer_create(1, RT_TIMER_FLAG_PERIODIC, timeout, (void*)container);
|
||||
|
||||
return view;
|
||||
rtgui_widget_set_onshow(RTGUI_WIDGET(container), animation_on_show);
|
||||
rtgui_widget_set_onhide(RTGUI_WIDGET(container), animation_on_hide);
|
||||
|
||||
return container;
|
||||
}
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
/*
|
||||
* 程序清单:button控件演示
|
||||
*
|
||||
* 这个例子会在创建出的view上添加几个不同类型的button控件
|
||||
* 这个例子会在创建出的container上添加几个不同类型的button控件
|
||||
*/
|
||||
|
||||
#include "demo_view.h"
|
||||
#include <rtgui/widgets/button.h>
|
||||
|
||||
/* 创建用于演示button控件的视图 */
|
||||
rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t* demo_view_button(void)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_container_t* container;
|
||||
rtgui_button_t* button;
|
||||
rtgui_font_t* font;
|
||||
|
||||
/* 先创建一个演示用的视图 */
|
||||
view = demo_view(workbench, "Button View");
|
||||
container = demo_view("Button View");
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5;
|
||||
|
@ -30,11 +30,10 @@ rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench)
|
|||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(button)) = red;
|
||||
/* 设置button的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个button控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(button));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25;
|
||||
|
@ -45,11 +44,10 @@ rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench)
|
|||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(button)) = blue;
|
||||
/* 设置button的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个button控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(button));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25;
|
||||
|
@ -61,11 +59,10 @@ rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench)
|
|||
RTGUI_WIDGET_FONT(RTGUI_WIDGET(button)) = font;
|
||||
/* 设置button的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个button控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(button));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25 + 25;
|
||||
|
@ -77,8 +74,7 @@ rtgui_view_t* demo_view_button(rtgui_workbench_t* workbench)
|
|||
RTGUI_WIDGET_FONT(RTGUI_WIDGET(button)) = font;
|
||||
/* 设置button的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个button控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(button));
|
||||
|
||||
return view;
|
||||
return container;
|
||||
}
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
/*
|
||||
* 程序清单:checkbox控件演示
|
||||
*
|
||||
* 这个例子会在创建出的view上添加几个checkbox控件
|
||||
* 这个例子会在创建出的container上添加几个checkbox控件
|
||||
*/
|
||||
|
||||
#include "demo_view.h"
|
||||
#include <rtgui/widgets/checkbox.h>
|
||||
|
||||
/* 创建用于演示checkbox控件的视图 */
|
||||
rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t* demo_view_checkbox(void)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_container_t* container;
|
||||
rtgui_checkbox_t* checkbox;
|
||||
rtgui_font_t* font;
|
||||
|
||||
/* 先创建一个演示用的视图 */
|
||||
view = demo_view(workbench, "CheckBox View");
|
||||
container = demo_view("CheckBox View");
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5;
|
||||
|
@ -30,11 +30,10 @@ rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench)
|
|||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = red;
|
||||
/* 设置checkbox的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个checkbox控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25;
|
||||
|
@ -45,11 +44,10 @@ rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench)
|
|||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = blue;
|
||||
/* 设置checkbox的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个checkbox控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25;
|
||||
|
@ -61,11 +59,10 @@ rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench)
|
|||
RTGUI_WIDGET_FONT(RTGUI_WIDGET(checkbox)) = font;
|
||||
/* 设置checkbox的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个checkbox控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5 + 25 + 25 + 25;
|
||||
|
@ -77,8 +74,7 @@ rtgui_view_t* demo_view_checkbox(rtgui_workbench_t* workbench)
|
|||
RTGUI_WIDGET_FONT(RTGUI_WIDGET(checkbox)) = font;
|
||||
/* 设置checkbox的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个checkbox控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(checkbox));
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
|
||||
|
||||
return view;
|
||||
return container;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* 程序清单:label控件演示
|
||||
*
|
||||
* 这个例子会在创建出的view上添加几个不同类型的label控件
|
||||
* 这个例子会在创建出的container上添加几个不同类型的label控件
|
||||
*/
|
||||
#include "demo_view.h"
|
||||
#include <rtgui/widgets/combobox.h>
|
||||
|
@ -16,25 +16,25 @@ struct rtgui_listbox_item items[] =
|
|||
};
|
||||
|
||||
/* 创建用于演示combobox控件的视图 */
|
||||
rtgui_view_t* demo_view_combobox(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t* demo_view_combobox(void)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_container_t* container;
|
||||
rtgui_combobox_t* box;
|
||||
|
||||
/* 先创建一个演示用的视图 */
|
||||
view = demo_view(workbench, "ComboBox View");
|
||||
container = demo_view("ComboBox View");
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
/* 创建一个label控件 */
|
||||
box = rtgui_combobox_create(items, sizeof(items)/sizeof(items[0]), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个box控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(box));
|
||||
/* container是一个container控件,调用add_child方法添加这个box控件 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(box));
|
||||
|
||||
return view;
|
||||
return container;
|
||||
}
|
||||
|
|
|
@ -19,21 +19,23 @@ struct rtgui_image_hdcmm stop_image = RTGUI_IMAGE_HDC_DEF(2, 0x1c, 0x16, stop_hd
|
|||
/*
|
||||
* view的事件处理函数
|
||||
*/
|
||||
rt_bool_t dc_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
||||
rt_bool_t dc_event_handler(struct rtgui_object* object, rtgui_event_t *event)
|
||||
{
|
||||
struct rtgui_widget *widget = RTGUI_WIDGET(object);
|
||||
|
||||
/* 仅对PAINT事件进行处理 */
|
||||
if (event->type == RTGUI_EVENT_PAINT)
|
||||
{
|
||||
struct rtgui_dc* dc;
|
||||
rtgui_rect_t rect;
|
||||
// const int vx[] = {20, 50, 60, 45, 60, 20};
|
||||
// const int vy[] = {150, 50, 90, 60, 45, 50};
|
||||
const int vx[] = {20, 50, 60, 45, 60, 20};
|
||||
const int vy[] = {150, 50, 90, 60, 45, 50};
|
||||
|
||||
/*
|
||||
* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view
|
||||
* 先绘图
|
||||
*/
|
||||
rtgui_view_event_handler(widget, event);
|
||||
rtgui_container_event_handler(RTGUI_OBJECT(widget), event);
|
||||
|
||||
/************************************************************************/
|
||||
/* 下面的是DC的操作 */
|
||||
|
@ -46,7 +48,7 @@ rt_bool_t dc_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
|||
return RT_FALSE;
|
||||
|
||||
/* 获得demo view允许绘图的区域 */
|
||||
demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect);
|
||||
demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
|
||||
|
||||
RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL;
|
||||
/* 显示GUI的版本信息 */
|
||||
|
@ -170,21 +172,21 @@ rt_bool_t dc_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
|||
else
|
||||
{
|
||||
/* 其他事件,调用默认的事件处理函数 */
|
||||
return rtgui_view_event_handler(widget, event);
|
||||
return rtgui_container_event_handler(object, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
/* 创建用于DC操作演示用的视图 */
|
||||
rtgui_view_t *demo_view_dc(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t *demo_view_dc(void)
|
||||
{
|
||||
rtgui_view_t *view;
|
||||
rtgui_container_t *view;
|
||||
|
||||
view = demo_view(workbench, "DC Demo");
|
||||
view = demo_view("DC Demo");
|
||||
if (view != RT_NULL)
|
||||
/* 设置成自己的事件处理函数 */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), dc_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(view), dc_event_handler);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
|
@ -10,14 +10,15 @@
|
|||
#include <rtgui/widgets/slider.h>
|
||||
#include <rtgui/image.h>
|
||||
|
||||
// static rtgui_image_t *background;
|
||||
static rtgui_image_t *background;
|
||||
static struct rtgui_dc *dc_buffer;
|
||||
|
||||
/*
|
||||
* view的事件处理函数
|
||||
*/
|
||||
static rt_bool_t dc_buffer_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
||||
static rt_bool_t dc_buffer_event_handler(struct rtgui_object* object, rtgui_event_t *event)
|
||||
{
|
||||
struct rtgui_widget *widget = RTGUI_WIDGET(object);
|
||||
|
||||
/* 仅对PAINT事件进行处理 */
|
||||
if (event->type == RTGUI_EVENT_PAINT)
|
||||
|
@ -29,7 +30,7 @@ static rt_bool_t dc_buffer_event_handler(rtgui_widget_t* widget, rtgui_event_t *
|
|||
* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view
|
||||
* 先绘图
|
||||
*/
|
||||
rtgui_view_event_handler(widget, event);
|
||||
rtgui_container_event_handler(object, event);
|
||||
|
||||
/* 获得控件所属的DC */
|
||||
dc = rtgui_dc_begin_drawing(widget);
|
||||
|
@ -38,7 +39,7 @@ static rt_bool_t dc_buffer_event_handler(rtgui_widget_t* widget, rtgui_event_t *
|
|||
return RT_FALSE;
|
||||
|
||||
/* 获得demo view允许绘图的区域 */
|
||||
demo_view_get_logic_rect(RTGUI_VIEW(widget), &rect);
|
||||
demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
|
||||
|
||||
rect.x1 += 10;
|
||||
rect.y1 += 10;
|
||||
|
@ -50,16 +51,16 @@ static rt_bool_t dc_buffer_event_handler(rtgui_widget_t* widget, rtgui_event_t *
|
|||
else
|
||||
{
|
||||
/* 其他事件,调用默认的事件处理函数 */
|
||||
return rtgui_view_event_handler(widget, event);
|
||||
return rtgui_container_event_handler(object, event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
/* 创建用于DC Buffer操作演示用的视图 */
|
||||
rtgui_view_t *demo_view_dc_buffer(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t *demo_view_dc_buffer()
|
||||
{
|
||||
rtgui_view_t *view;
|
||||
rtgui_container_t *view;
|
||||
|
||||
if (dc_buffer == RT_NULL)
|
||||
{
|
||||
|
@ -74,10 +75,10 @@ rtgui_view_t *demo_view_dc_buffer(rtgui_workbench_t* workbench)
|
|||
rtgui_dc_draw_circle(dc_buffer, 25, 25, 10);
|
||||
}
|
||||
|
||||
view = demo_view(workbench, "»º³åDCÑÝʾ");
|
||||
view = demo_view("»º³åDCÑÝʾ");
|
||||
if (view != RT_NULL)
|
||||
/* 设置成自己的事件处理函数 */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), dc_buffer_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(view), dc_buffer_event_handler);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* 程序清单:DC上显示图像演示
|
||||
*
|
||||
* 这个例子会在创建出的view上显示图像
|
||||
* 这个例子会在创建出的container上显示图像
|
||||
*/
|
||||
|
||||
#include "demo_view.h"
|
||||
|
@ -9,34 +9,29 @@
|
|||
#include <rtgui/widgets/filelist_view.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
|
||||
static rtgui_image_t* image = RT_NULL;
|
||||
static rtgui_view_t* _view = RT_NULL;
|
||||
static rtgui_container_t* _container = RT_NULL;
|
||||
|
||||
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
|
||||
/* 打开按钮的回调函数 */
|
||||
static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
||||
{
|
||||
rtgui_filelist_view_t *view;
|
||||
rtgui_workbench_t *workbench;
|
||||
rtgui_rect_t rect;
|
||||
|
||||
/* 获得顶层的workbench */
|
||||
workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
|
||||
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
|
||||
rtgui_filelist_view_t *filelist;
|
||||
struct rtgui_rect rect = {0, 100, 240, 280};
|
||||
|
||||
/* WIN32平台上和真实设备上的初始路径处理 */
|
||||
#ifdef _WIN32
|
||||
view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect);
|
||||
filelist = rtgui_filelist_view_create("e:\\", "*.*", &rect);
|
||||
#else
|
||||
view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
|
||||
filelist = rtgui_filelist_view_create("/", "*.*", &rect);
|
||||
#endif
|
||||
/* 模态显示一个文件列表视图,以提供给用户选择图像文件 */
|
||||
if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
|
||||
if (rtgui_container_show(RTGUI_CONTAINER(filelist), RT_TRUE) == RTGUI_MODAL_OK)
|
||||
{
|
||||
char path[32], image_type[8];
|
||||
|
||||
/* 设置文件路径的标签 */
|
||||
rtgui_filelist_view_get_fullpath(view, path, sizeof(path));
|
||||
rtgui_filelist_view_get_fullpath(filelist, path, sizeof(path));
|
||||
if (image != RT_NULL)
|
||||
{
|
||||
rtgui_image_destroy(image);
|
||||
|
@ -65,8 +60,8 @@ static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
|||
}
|
||||
|
||||
/* 删除 文件列表 视图 */
|
||||
rtgui_view_destroy(RTGUI_VIEW(view));
|
||||
rtgui_view_show(_view, RT_FALSE);
|
||||
rtgui_container_destroy(RTGUI_CONTAINER(filelist));
|
||||
rtgui_container_show(_container, RT_FALSE);
|
||||
}
|
||||
|
||||
/* 演示视图的事件处理函数 */
|
||||
|
@ -75,7 +70,7 @@ static rt_bool_t demo_view_event_handler(rtgui_widget_t* widget, rtgui_event_t *
|
|||
rt_bool_t result;
|
||||
|
||||
/* 先调用默认的事件处理函数(这里只关心PAINT事件,但演示视图还有本身的一些控件) */
|
||||
result = rtgui_view_event_handler(widget, event);
|
||||
result = rtgui_container_event_handler(widget, event);
|
||||
|
||||
if (event->type == RTGUI_EVENT_PAINT)
|
||||
{
|
||||
|
@ -88,8 +83,8 @@ static rt_bool_t demo_view_event_handler(rtgui_widget_t* widget, rtgui_event_t *
|
|||
/* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
|
||||
return RT_FALSE;
|
||||
|
||||
/* 获得demo view允许绘图的区域 */
|
||||
demo_view_get_rect(RTGUI_VIEW(widget), &rect);
|
||||
/* 获得demo container允许绘图的区域 */
|
||||
demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
|
||||
|
||||
/* 获得图像显示区域 */
|
||||
rect.x1 += 5; rect.x2 -= 5;
|
||||
|
@ -106,26 +101,26 @@ static rt_bool_t demo_view_event_handler(rtgui_widget_t* widget, rtgui_event_t *
|
|||
}
|
||||
|
||||
/* 创建用于显示图像的演示视图 */
|
||||
rtgui_view_t* demo_view_image(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t* demo_view_image(void)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_button_t* open_btn;
|
||||
|
||||
/* 先创建一个演示视图 */
|
||||
_view = demo_view(workbench, "图像演示");
|
||||
if (_view != RT_NULL)
|
||||
_container = demo_view("图像演示");
|
||||
if (_container != RT_NULL)
|
||||
/* 设置默认的事件处理函数到demo_view_event_handler函数 */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(_view), demo_view_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_WIDGET(_container), demo_view_event_handler);
|
||||
|
||||
/* 添加一个按钮 */
|
||||
demo_view_get_rect(_view, &rect);
|
||||
demo_view_get_rect(_container, &rect);
|
||||
rect.x1 += 5; rect.x2 = rect.x1 + 120;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
open_btn = rtgui_button_create("打开图像文件");
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(_view), RTGUI_WIDGET(open_btn));
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(_container), RTGUI_WIDGET(open_btn));
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
|
||||
rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
|
||||
|
||||
return _view;
|
||||
return _container;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* 程序清单:DC操作演示
|
||||
*
|
||||
* 这个例子会在创建出的view上进行DC操作的演示
|
||||
* 这个例子会在创建出的container上进行DC操作的演示
|
||||
*/
|
||||
|
||||
#include "demo_view.h"
|
||||
|
@ -13,10 +13,11 @@
|
|||
#include <math.h>
|
||||
|
||||
/*
|
||||
* view的事件处理函数
|
||||
* container的事件处理函数
|
||||
*/
|
||||
rt_bool_t instrument_panel_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
|
||||
rt_bool_t instrument_panel_event_handler(struct rtgui_object *object, rtgui_event_t *event)
|
||||
{
|
||||
struct rtgui_widget *widget = RTGUI_WIDGET(object);
|
||||
char ac[4];
|
||||
int i;
|
||||
int x0 = 120;
|
||||
|
@ -33,10 +34,10 @@ rt_bool_t instrument_panel_event_handler(rtgui_widget_t* widget, rtgui_event_t *
|
|||
const int arrowy[] = {170-5, 170+5, 170};
|
||||
|
||||
/*
|
||||
* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view
|
||||
* 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container
|
||||
* 先绘图
|
||||
*/
|
||||
rtgui_view_event_handler(widget, event);
|
||||
rtgui_container_event_handler(RTGUI_OBJECT(widget), event);
|
||||
|
||||
/************************************************************************/
|
||||
/* 下面的是DC的操作 */
|
||||
|
@ -48,8 +49,8 @@ rt_bool_t instrument_panel_event_handler(rtgui_widget_t* widget, rtgui_event_t *
|
|||
if (dc == RT_NULL)
|
||||
return RT_FALSE;
|
||||
|
||||
/* 获得demo view允许绘图的区域 */
|
||||
demo_view_get_rect(RTGUI_VIEW(widget), &rect);
|
||||
/* 获得demo container允许绘图的区域 */
|
||||
demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
|
||||
|
||||
RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL;
|
||||
/* 显示GUI的版本信息 */
|
||||
|
@ -128,21 +129,21 @@ rt_bool_t instrument_panel_event_handler(rtgui_widget_t* widget, rtgui_event_t *
|
|||
else
|
||||
{
|
||||
/* 其他事件,调用默认的事件处理函数 */
|
||||
return rtgui_view_event_handler(widget, event);
|
||||
return rtgui_container_event_handler(RTGUI_OBJECT(widget), event);
|
||||
}
|
||||
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
/* 创建用于DC操作演示用的视图 */
|
||||
rtgui_view_t *demo_view_instrument_panel(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t *demo_view_instrument_panel(void)
|
||||
{
|
||||
rtgui_view_t *view;
|
||||
rtgui_container_t *container;
|
||||
|
||||
view = demo_view(workbench, "instrument panel Demo");
|
||||
if (view != RT_NULL)
|
||||
container = demo_view("instrument panel Demo");
|
||||
if (container != RT_NULL)
|
||||
/* 设置成自己的事件处理函数 */
|
||||
rtgui_widget_set_event_handler(RTGUI_WIDGET(view), instrument_panel_event_handler);
|
||||
rtgui_object_set_event_handler(RTGUI_OBJECT(container), instrument_panel_event_handler);
|
||||
|
||||
return view;
|
||||
return container;
|
||||
}
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
/*
|
||||
* 程序清单:label控件演示
|
||||
*
|
||||
* 这个例子会在创建出的view上添加几个不同类型的label控件
|
||||
* 这个例子会在创建出的container上添加几个不同类型的label控件
|
||||
*/
|
||||
#include "demo_view.h"
|
||||
#include <rtgui/widgets/label.h>
|
||||
|
||||
/* 创建用于演示label控件的视图 */
|
||||
rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t* demo_view_label(void)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_container_t* container;
|
||||
rtgui_label_t* label;
|
||||
rtgui_font_t* font;
|
||||
|
||||
/* 先创建一个演示用的视图 */
|
||||
view = demo_view(workbench, "Label View");
|
||||
container = demo_view("Label View");
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5;
|
||||
|
@ -31,11 +31,11 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
|
|||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = red;
|
||||
/* 设置label的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
/* container是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(label));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5 + 25;
|
||||
|
@ -48,11 +48,11 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
|
|||
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = blue;
|
||||
/* 设置label的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
/* container是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(label));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5 + 25 + 25;
|
||||
|
@ -65,11 +65,11 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
|
|||
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_CENTER_HORIZONTAL;
|
||||
/* 设置label的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
/* container是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(label));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5 + 25 + 25 + 25;
|
||||
|
@ -81,11 +81,11 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
|
|||
RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
|
||||
/* 设置label的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
/* container是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(label));
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.y1 += 5 + 25 + 25 + 25 + 25;
|
||||
rect.y2 = rect.y1 + 20;
|
||||
|
@ -96,9 +96,9 @@ rtgui_view_t* demo_view_label(rtgui_workbench_t* workbench)
|
|||
RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
|
||||
/* 设置label的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
/* container是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(label));
|
||||
|
||||
return view;
|
||||
return container;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* 程序清单:label控件演示
|
||||
*
|
||||
* 这个例子会在创建出的view上添加几个不同类型的label控件
|
||||
* 这个例子会在创建出的container上添加几个不同类型的label控件
|
||||
*/
|
||||
#include "demo_view.h"
|
||||
#include <rtgui/widgets/label.h>
|
||||
|
@ -152,15 +152,15 @@ static void on_items(rtgui_widget_t* widget, struct rtgui_event* event)
|
|||
}
|
||||
|
||||
/* 创建用于演示label控件的视图 */
|
||||
rtgui_view_t* demo_view_listbox(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t* demo_view_listbox(void)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_container_t* container;
|
||||
rtgui_label_t* label;
|
||||
rtgui_listbox_t* box;
|
||||
|
||||
/* 先创建一个演示用的视图 */
|
||||
view = demo_view(workbench, "ListBox Demo");
|
||||
container = demo_view("ListBox Demo");
|
||||
|
||||
if (item_icon == RT_NULL)
|
||||
item_icon = rtgui_image_create_from_mem("xpm",
|
||||
|
@ -168,7 +168,7 @@ rtgui_view_t* demo_view_listbox(rtgui_workbench_t* workbench)
|
|||
items[1].image = item_icon;
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5;
|
||||
|
@ -177,15 +177,15 @@ rtgui_view_t* demo_view_listbox(rtgui_workbench_t* workbench)
|
|||
label = rtgui_label_create("listbox: ");
|
||||
/* 设置label的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
/* container是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(label));
|
||||
|
||||
rect.y1 = rect.y2 + 3;
|
||||
rect.y2 = 250;
|
||||
box = rtgui_listbox_create(items, sizeof(items)/sizeof(struct rtgui_listbox_item), &rect);
|
||||
rtgui_listbox_set_onitem(box, on_items);
|
||||
/* view是一个container控件,调用add_child方法添加这个listbox控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(box));
|
||||
/* container是一个container控件,调用add_child方法添加这个listbox控件 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(box));
|
||||
|
||||
return view;
|
||||
return container;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* 程序清单:label控件演示
|
||||
*
|
||||
* 这个例子会在创建出的view上添加几个不同类型的label控件
|
||||
* 这个例子会在创建出的container上添加几个不同类型的label控件
|
||||
*/
|
||||
#include "demo_view.h"
|
||||
#include <rtgui/widgets/label.h>
|
||||
|
@ -163,7 +163,10 @@ static struct list_item
|
|||
{"index19", "m19", 30, RT_NULL},
|
||||
};
|
||||
|
||||
void _rtgui_listctrl_item_draw(struct rtgui_listctrl *list, struct rtgui_dc* dc, rtgui_rect_t* rect, rt_uint16_t index)
|
||||
void _rtgui_listctrl_item_draw(struct rtgui_listctrl *list,
|
||||
struct rtgui_dc* dc,
|
||||
rtgui_rect_t* rect,
|
||||
rt_uint16_t index)
|
||||
{
|
||||
char age_str[8];
|
||||
rtgui_rect_t item_rect;
|
||||
|
@ -212,15 +215,15 @@ static void on_items(rtgui_widget_t* widget, struct rtgui_event* event)
|
|||
}
|
||||
|
||||
/* 创建用于演示label控件的视图 */
|
||||
rtgui_view_t* demo_view_listctrl(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t* demo_view_listctrl(void)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_container_t* container;
|
||||
rtgui_label_t* label;
|
||||
rtgui_listctrl_t* box;
|
||||
|
||||
/* 先创建一个演示用的视图 */
|
||||
view = demo_view(workbench, "List Control Demo");
|
||||
container = demo_view("List Control Demo");
|
||||
|
||||
if (item_icon == RT_NULL)
|
||||
item_icon = rtgui_image_create_from_mem("xpm",
|
||||
|
@ -228,7 +231,7 @@ rtgui_view_t* demo_view_listctrl(rtgui_workbench_t* workbench)
|
|||
items[1].image = item_icon;
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 -= 5;
|
||||
rect.y1 += 5;
|
||||
|
@ -237,16 +240,16 @@ rtgui_view_t* demo_view_listctrl(rtgui_workbench_t* workbench)
|
|||
label = rtgui_label_create("List Control: ");
|
||||
/* 设置label的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
|
||||
/* container是一个container控件,调用add_child方法添加这个label控件 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(label));
|
||||
|
||||
rect.y1 = rect.y2 + 3;
|
||||
rect.y2 = 250;
|
||||
box = rtgui_listctrl_create((rt_uint32_t)items, sizeof(items)/sizeof(items[0]), &rect,
|
||||
_rtgui_listctrl_item_draw);
|
||||
rtgui_listctrl_set_onitem(box, on_items);
|
||||
/* view是一个container控件,调用add_child方法添加这个listctrl控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(box));
|
||||
/* container是一个container控件,调用add_child方法添加这个listctrl控件 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(box));
|
||||
|
||||
return view;
|
||||
return container;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* 程序清单:menu控件演示
|
||||
*
|
||||
* 这个例子会在创建出的view上添加几个不同类型的label控件
|
||||
* 这个例子会在创建出的container上添加几个不同类型的label控件
|
||||
*/
|
||||
#include "demo_view.h"
|
||||
#include <rtgui/widgets/menu.h>
|
||||
|
@ -25,11 +25,13 @@ static const rtgui_menu_item_t items[] =
|
|||
{RTGUI_ITEM_NORMAL, "item #1", RT_NULL, RT_NULL, 0, RT_NULL},
|
||||
{RTGUI_ITEM_NORMAL, "item #2", RT_NULL, RT_NULL, 0, RT_NULL},
|
||||
{RTGUI_ITEM_SEPARATOR, RT_NULL, RT_NULL, RT_NULL, 0, RT_NULL},
|
||||
{RTGUI_ITEM_SUBMENU, "item #3", RT_NULL, (struct rtgui_menu_item_t *)sub_items, sizeof(sub_items)/sizeof(sub_items[0]), RT_NULL},
|
||||
{RTGUI_ITEM_SUBMENU, "item #3", RT_NULL,
|
||||
(struct rtgui_menu_item_t *)sub_items,
|
||||
sizeof(sub_items)/sizeof(sub_items[0]), RT_NULL},
|
||||
};
|
||||
static rtgui_menu_t* menu;
|
||||
|
||||
static void _onmenu(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
static _onmenu(struct rtgui_widget* widget, struct rtgui_event* event)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
|
||||
|
@ -41,17 +43,17 @@ static void _onmenu(struct rtgui_widget* widget, struct rtgui_event* event)
|
|||
}
|
||||
|
||||
/* 创建用于演示menu控件的视图 */
|
||||
rtgui_view_t* demo_view_menu(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t* demo_view_menu(void)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_view_t* view;
|
||||
rtgui_container_t* container;
|
||||
rtgui_button_t* button;
|
||||
|
||||
/* 先创建一个演示用的视图 */
|
||||
view = demo_view(workbench, "MENU View");
|
||||
container = demo_view("MENU View");
|
||||
|
||||
/* 获得视图的位置信息 */
|
||||
demo_view_get_rect(view, &rect);
|
||||
demo_view_get_rect(container, &rect);
|
||||
rect.x1 += 5;
|
||||
rect.x2 = rect.x1 + 100;
|
||||
rect.y1 += 5;
|
||||
|
@ -60,11 +62,11 @@ rtgui_view_t* demo_view_menu(rtgui_workbench_t* workbench)
|
|||
button = rtgui_button_create("Pop Menu");
|
||||
/* 设置button的位置 */
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
|
||||
/* view是一个container控件,调用add_child方法添加这个button控件 */
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(button));
|
||||
/* container是一个container控件,调用add_child方法添加这个button控件 */
|
||||
rtgui_container_add_child(container, RTGUI_WIDGET(button));
|
||||
rtgui_button_set_onbutton(button, _onmenu);
|
||||
|
||||
menu = rtgui_menu_create("Menu Test", RT_NULL, items, sizeof(items)/sizeof(items[0]));
|
||||
|
||||
return view;
|
||||
return container;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#ifdef RT_USING_MODULE
|
||||
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
|
||||
static rtgui_view_t* _view = RT_NULL;
|
||||
static rtgui_container_t* _view = RT_NULL;
|
||||
|
||||
/* 打开按钮的回调函数 */
|
||||
static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
||||
|
@ -31,7 +31,7 @@ static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
|||
view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
|
||||
#endif
|
||||
/* 模态显示一个文件列表视图,以提供给用户选择图像文件 */
|
||||
if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
|
||||
if (rtgui_container_show(RTGUI_CONTAINER(view), RT_TRUE) == RTGUI_MODAL_OK)
|
||||
{
|
||||
char path[32], name[8];
|
||||
|
||||
|
@ -48,12 +48,12 @@ static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
|
|||
}
|
||||
|
||||
/* 删除 文件列表 视图 */
|
||||
rtgui_view_destroy(RTGUI_VIEW(view));
|
||||
rtgui_view_show(_view, RT_FALSE);
|
||||
rtgui_container_destroy(RTGUI_CONTAINER(view));
|
||||
rtgui_container_show(_view, RT_FALSE);
|
||||
}
|
||||
|
||||
/* 创建用于显示应用模块的演示视图 */
|
||||
rtgui_view_t* demo_view_module(rtgui_workbench_t* workbench)
|
||||
rtgui_container_t* demo_view_module(rtgui_workbench_t* workbench)
|
||||
{
|
||||
rtgui_rect_t rect;
|
||||
rtgui_button_t* open_btn;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue