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:
chaos.proton@gmail.com
2012-04-18 15:06:12 +00:00
parent 06d45f0c42
commit db06460208
140 changed files with 17246 additions and 17942 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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