diff options
| author | bernard.xiong <[email protected]> | 2009-10-04 02:56:38 +0000 |
|---|---|---|
| committer | bernard.xiong <[email protected]> | 2009-10-04 02:56:38 +0000 |
| commit | 90f9d0a2ab733f3930907693fceadba1d01c0df4 (patch) | |
| tree | 2fa88428f28ba4fb071afcd98c585d30176ef674 /rtgui/server | |
| parent | e3248a5045bd59b32c0b97a05c771928316f3aff (diff) | |
add basic files of RTGUI
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@69 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'rtgui/server')
| -rw-r--r-- | rtgui/server/driver.c | 67 | ||||
| -rw-r--r-- | rtgui/server/panel.c | 293 | ||||
| -rw-r--r-- | rtgui/server/panel.h | 72 | ||||
| -rw-r--r-- | rtgui/server/server.c | 633 |
4 files changed, 1065 insertions, 0 deletions
diff --git a/rtgui/server/driver.c b/rtgui/server/driver.c new file mode 100644 index 0000000000..2805ad1e56 --- /dev/null +++ b/rtgui/server/driver.c @@ -0,0 +1,67 @@ +/*
+ * File : driver.c
+ * This file is part of RTGUI in RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2009-10-04 Bernard first version
+ */
+#include <rtgui/driver.h>
+
+struct rtgui_list_node _rtgui_graphic_driver_list = {RT_NULL};
+
+void rtgui_graphic_driver_add(struct rtgui_graphic_driver* driver)
+{
+ rtgui_list_insert(&_rtgui_graphic_driver_list, &(driver->list));
+}
+
+void rtgui_graphic_driver_remove(struct rtgui_graphic_driver* driver)
+{
+ rtgui_list_remove(&_rtgui_graphic_driver_list, &(driver->list));
+}
+
+struct rtgui_graphic_driver* rtgui_graphic_driver_find(char* name)
+{
+ struct rtgui_list_node* node;
+ struct rtgui_graphic_driver* driver;
+
+ /* search in list */
+ rtgui_list_foreach(node, &(_rtgui_graphic_driver_list))
+ {
+ driver = rtgui_list_entry(node, struct rtgui_graphic_driver, list);
+
+ /* find it */
+ if (rt_strncmp(driver->name, name, RTGUI_NAME_MAX) == 0)
+ {
+ return driver;
+ }
+ }
+
+ return RT_NULL;
+}
+
+struct rtgui_graphic_driver* rtgui_graphic_driver_get_default()
+{
+ return rtgui_list_entry(_rtgui_graphic_driver_list.next,
+ struct rtgui_graphic_driver, list);
+}
+
+void rtgui_graphic_driver_get_rect(struct rtgui_graphic_driver *driver, rtgui_rect_t *rect)
+{
+ if (rect == RT_NULL || driver == RT_NULL) return;
+
+ rect->x1 = rect->y1 = 0;
+ rect->x2 = driver->width;
+ rect->y2 = driver->height;
+}
+
+void rtgui_graphic_driver_get_default_rect(rtgui_rect_t *rect)
+{
+ /* return default the extent of default driver */
+ rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), rect);
+}
diff --git a/rtgui/server/panel.c b/rtgui/server/panel.c new file mode 100644 index 0000000000..744fa5b3f7 --- /dev/null +++ b/rtgui/server/panel.c @@ -0,0 +1,293 @@ +/*
+ * 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;
+
+void rtgui_panel_init()
+{
+ rtgui_list_init(&_rtgui_panel_list);
+}
+
+void rtgui_panel_register(char* name, rtgui_rect_t* extent)
+{
+ register rt_base_t temp;
+ struct rtgui_panel* panel;
+
+ panel = rtgui_panel_find(name);
+ if (panel != RT_NULL )
+ {
+ /* there are already a same named panel exist. */
+ return;
+ }
+
+ panel = rtgui_malloc(sizeof(struct rtgui_panel));
+ if (panel == RT_NULL)
+ {
+ /* can't alloc memory */
+ return;
+ }
+
+ /* copy name */
+ for (temp = 0; temp < RTGUI_NAME_MAX; temp ++)
+ {
+ panel->name[temp] = name[temp];
+ }
+
+ /* copy extent */
+ panel->extent = *extent;
+
+ panel->wm_thread = RT_NULL;
+
+ /* init list */
+ rtgui_list_init(&(panel->sibling));
+ rtgui_list_init(&(panel->thread_list));
+
+ /* add panel to panel list */
+ rtgui_list_insert(&_rtgui_panel_list, &(panel->sibling));
+}
+
+void rtgui_panel_deregister(char* name)
+{
+ struct rtgui_panel* panel;
+
+ panel = rtgui_panel_find(name);
+ if (panel != RT_NULL)
+ {
+ rtgui_list_remove(&_rtgui_panel_list, &(panel->sibling));
+
+ /* free pane node */
+ rtgui_free(panel);
+ }
+}
+
+struct rtgui_panel* rtgui_panel_find(char* name)
+{
+ struct rtgui_list_node* node;
+ struct rtgui_panel* panel;
+
+ rtgui_list_foreach(node, &_rtgui_panel_list)
+ {
+ panel = rtgui_list_entry(node, struct rtgui_panel, sibling);
+
+ if (rt_strncmp(panel->name, name, RTGUI_NAME_MAX) == 0)
+ {
+ return panel;
+ }
+ }
+
+ return RT_NULL;
+}
+
+struct rtgui_panel* rtgui_panel_thread_add(char* name, rt_thread_t tid)
+{
+ struct rtgui_panel* panel;
+
+ panel = rtgui_panel_find(name);
+ if (panel != RT_NULL )
+ {
+ struct rtgui_panel_thread* thread;
+
+ /* allocate panel thread node */
+ thread = rtgui_malloc(sizeof(struct rtgui_panel_thread));
+ if (thread == RT_NULL)
+ {
+ return RT_NULL;
+ }
+
+ /* construct panel thread node */
+ thread->tid = tid;
+
+ /* init list */
+ rtgui_list_init(&(thread->list));
+ rtgui_list_init(&(thread->monitor_list));
+
+ /* append thread to the list */
+ rtgui_list_append(&(panel->thread_list), &(thread->list));
+ }
+
+ return panel;
+}
+
+void rtgui_panel_thread_remove(rtgui_panel_t* panel, rt_thread_t tid)
+{
+ if (panel != RT_NULL )
+ {
+ struct rtgui_list_node* node;
+ struct rtgui_panel_thread* thread;
+
+ rtgui_list_foreach(node, &(panel->thread_list))
+ {
+ thread = rtgui_list_entry(node, struct rtgui_panel_thread, list);
+ if (thread->tid == tid)
+ {
+ /* remove node from list */
+ rtgui_list_remove(&(panel->thread_list), &(thread->list));
+
+ /* free the panel thread node */
+ rtgui_free(thread);
+ return;
+ }
+ }
+ }
+}
+
+rt_thread_t rtgui_panel_get_active_thread(rtgui_panel_t* panel)
+{
+ if (panel != RT_NULL)
+ {
+ if (panel->thread_list.next != RT_NULL)
+ {
+ struct rtgui_panel_thread* thread;
+ thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list);
+
+ return thread->tid;
+ }
+ }
+
+ return RT_NULL;
+}
+
+void rtgui_panel_set_active_thread(rtgui_panel_t* panel, rt_thread_t tid)
+{
+ /* get old active thread */
+ rt_thread_t prev_actived = rtgui_panel_get_active_thread(panel);
+ if (prev_actived != tid)
+ {
+ /* de-active old active workbench */
+ struct rtgui_event_panel_hide ehide;
+ RTGUI_EVENT_PANEL_HIDE_INIT(&ehide);
+
+ ehide.panel = panel;
+ ehide.workbench = RT_NULL;
+ rtgui_thread_send_urgent(prev_actived, &(ehide.parent), sizeof (ehide));
+ }
+
+ if (panel != RT_NULL )
+ {
+ struct rtgui_list_node* node;
+ struct rtgui_panel_thread* thread;
+
+ rtgui_list_foreach(node, &(panel->thread_list))
+ {
+ thread = rtgui_list_entry(node, struct rtgui_panel_thread, list);
+ if (thread->tid == tid)
+ {
+ /* remove node from list */
+ rtgui_list_remove(&(panel->thread_list), &(thread->list));
+
+ /* insert node to the header */
+ rtgui_list_insert(&(panel->thread_list), &(thread->list));
+ return;
+ }
+ }
+ }
+}
+
+/* deactivate current activated thread -- move it to the end of list */
+void rtgui_panel_deactive_thread(rtgui_panel_t* panel)
+{
+ RT_ASSERT(panel == RT_NULL);
+
+ if (panel->thread_list.next != RT_NULL)
+ {
+ struct rtgui_panel_thread* thread;
+ thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list);
+
+ /* remove it */
+ panel->thread_list.next = thread->list.next;
+
+ /* append to the tail of thread list */
+ rtgui_list_append(&(panel->thread_list), &(thread->list));
+ }
+}
+
+/**
+ * get the panel which contains a point(x, y)
+ */
+rtgui_panel_t* rtgui_panel_get_contain(int x, int y)
+{
+ struct rtgui_list_node* node;
+ struct rtgui_panel* panel;
+
+ rtgui_list_foreach(node, &(_rtgui_panel_list))
+ {
+ panel = rtgui_list_entry(node, struct rtgui_panel, sibling);
+ if (rtgui_rect_contains_point(&(panel->extent), x, y) == RT_EOK)
+ {
+ return panel;
+ }
+ }
+
+ return RT_NULL;
+}
+
+/**
+ * append a rect to panel mouse monitor rect list
+ */
+void rtgui_panel_append_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect)
+{
+ if (panel != RT_NULL )
+ {
+ struct rtgui_list_node* node;
+ struct rtgui_panel_thread* thread;
+
+ rtgui_list_foreach(node, &(panel->thread_list))
+ {
+ thread = rtgui_list_entry(node, struct rtgui_panel_thread, list);
+ if (thread->tid == tid)
+ {
+ /* add the monitor rect to list */
+ rtgui_mouse_monitor_append(&(thread->monitor_list), rect);
+ return;
+ }
+ }
+ }
+}
+
+/**
+ * remove a rect from panel mouse monitor rect list
+ */
+void rtgui_panel_remove_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect)
+{
+ if (panel != RT_NULL )
+ {
+ struct rtgui_list_node* node;
+ struct rtgui_panel_thread* thread;
+
+ rtgui_list_foreach(node, &(panel->thread_list))
+ {
+ thread = rtgui_list_entry(node, struct rtgui_panel_thread, list);
+ if (thread->tid == tid)
+ {
+ /* remove the monitor rect from list */
+ rtgui_mouse_monitor_remove(&(thread->monitor_list), rect);
+ return;
+ }
+ }
+ }
+}
+
+void rtgui_panel_set_wm(rtgui_panel_t* panel, rt_thread_t wm)
+{
+ RT_ASSERT(wm != RT_NULL);
+ RT_ASSERT(panel != RT_NULL);
+
+ panel->wm_thread = wm;
+}
diff --git a/rtgui/server/panel.h b/rtgui/server/panel.h new file mode 100644 index 0000000000..a524ede6a4 --- /dev/null +++ b/rtgui/server/panel.h @@ -0,0 +1,72 @@ +/*
+ * 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;
+};
+
+/* register or deregister panel in server */
+void rtgui_panel_register(char* name, rtgui_rect_t* extent);
+void rtgui_panel_deregister(char* name);
+
+/* find panel by name */
+struct rtgui_panel* rtgui_panel_find(char* name);
+
+/* add or remove application thread from specified panel */
+rtgui_panel_t* rtgui_panel_thread_add(char* name, rt_thread_t tid);
+void rtgui_panel_thread_remove(rtgui_panel_t* panel, rt_thread_t tid);
+
+rt_thread_t rtgui_panel_get_active_thread(rtgui_panel_t* panel);
+void rtgui_panel_set_active_thread(rtgui_panel_t* panel, rt_thread_t tid);
+
+rtgui_panel_t* rtgui_panel_get_contain(int x, int y);
+void rtgui_panel_set_wm(rtgui_panel_t* panel, rt_thread_t wm);
+
+void rtgui_panel_append_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect);
+void rtgui_panel_remove_monitor_rect(rtgui_panel_t* panel, rt_thread_t tid, rtgui_rect_t* rect);
+
+#endif
diff --git a/rtgui/server/server.c b/rtgui/server/server.c new file mode 100644 index 0000000000..78040ab344 --- /dev/null +++ b/rtgui/server/server.c @@ -0,0 +1,633 @@ +/*
+ * File : server.c
+ * This file is part of RTGUI in RT-Thread RTOS
+ * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rt-thread.org/license/LICENSE
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2009-10-04 Bernard first version
+ */
+
+#include <rtgui/rtgui.h>
+#include <rtgui/event.h>
+#include <rtgui/rtgui_system.h> +#include <rtgui/driver.h>
+
+#include "mouse.h"
+#include "panel.h"
+#include "topwin.h"
+
+#define RTGUI_SVR_THREAD_PRIORITY 96
+#define RTGUI_SVR_THREAD_TIMESLICE 20
+
+#define RTGUI_APP_THREAD_PRIORITY 220
+#define RTGUI_APP_THREAD_TIMESLICE 20
+
+static char rtgui_server_stack[2048];
+static struct rt_thread rtgui_server_thread;
+
+static struct rt_messagequeue rtgui_server_mq;
+static char rtgui_server_msg_pool[2048];
+
+extern struct rtgui_topwin* rtgui_server_focus_topwin;
+static struct rtgui_panel* rtgui_server_focus_panel = RT_NULL;
+
+void rtgui_server_create_application(struct rtgui_event_panel_attach* event)
+{
+ struct rtgui_panel* panel = rtgui_panel_find(event->panel_name);
+
+ if (panel != RT_NULL)
+ {
+ struct rtgui_event_panel_info ep;
+ RTGUI_EVENT_PANEL_INFO_INIT(&ep);
+
+ if (panel->wm_thread != RT_NULL)
+ {
+ /* notify to workbench */
+ rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_attach));
+ }
+
+ /* send the responses - ok */
+ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK);
+
+ /* send the panel info */
+ ep.panel = panel;
+ ep.extent = panel->extent;
+ rtgui_thread_send(event->parent.sender, (struct rtgui_event*)&ep, sizeof(ep));
+
+ rtgui_panel_thread_add(event->panel_name, event->parent.sender);
+ }
+ else
+ {
+ /* send the responses - failure */
+ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_NRC);
+ }
+}
+
+void rtgui_server_destroy_application(struct rtgui_event_panel_detach* event)
+{
+ struct rtgui_panel* panel = event->panel;
+
+ if (panel != RT_NULL)
+ {
+ if (panel->wm_thread != RT_NULL)
+ {
+ /* notify to workbench */
+ rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_detach));
+ }
+
+ /* send the responses */
+ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK);
+
+ rtgui_panel_thread_remove(panel, event->parent.sender);
+
+ {
+ /* get next thread and active it */
+ rt_thread_t tid = rtgui_panel_get_active_thread(panel);
+
+ /* let this thread repaint */
+ struct rtgui_event_paint epaint;
+ RTGUI_EVENT_PAINT_INIT(&epaint);
+ epaint.wid = RT_NULL;
+ rtgui_thread_send(tid, (struct rtgui_event*)&epaint, sizeof(epaint));
+ }
+ }
+ else
+ {
+ /* send the responses - failure */
+ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_NRC);
+ }
+}
+
+void rtgui_server_thread_panel_show(struct rtgui_event_panel_show* event)
+{
+ struct rtgui_panel* panel = event->panel;
+
+ if (panel != RT_NULL)
+ {
+ struct rtgui_event_paint epaint;
+
+ /* send the responses */
+ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK);
+
+ if (panel->wm_thread != RT_NULL)
+ {
+ /* notify to workbench */
+ rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_show));
+ }
+
+ rtgui_panel_set_active_thread(panel, event->parent.sender);
+
+ /* send all topwin clip info */
+ rtgui_topwin_update_clip_to_panel(panel);
+
+ /* send paint event */
+ RTGUI_EVENT_PAINT_INIT(&epaint);
+ epaint.wid = RT_NULL;
+ rtgui_thread_send(event->parent.sender, (struct rtgui_event*)&epaint,
+ sizeof(epaint));
+ }
+ else
+ {
+ /* send failed */
+ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR);
+ }
+}
+
+void rtgui_server_thread_panel_hide(struct rtgui_event_panel_hide* event)
+{
+ struct rtgui_panel* panel = event->panel;
+
+ if (panel != RT_NULL)
+ {
+ rt_thread_t tid;
+ struct rtgui_event_paint epaint;
+
+ /* send the responses */
+ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK);
+
+ if (panel->thread_list.next != RT_NULL)
+ {
+ struct rtgui_panel_thread* thread;
+ thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list);
+
+ /* remove it */
+ panel->thread_list.next = thread->list.next;
+
+ /* append to the tail of thread list */
+ rtgui_list_append(&(panel->thread_list), &(thread->list));
+ }
+
+ /* get new active thread */
+ tid = rtgui_panel_get_active_thread(panel);
+ /* send all topwin clip info */
+ rtgui_topwin_update_clip_to_panel(panel);
+
+ /* send paint event */
+ RTGUI_EVENT_PAINT_INIT(&epaint);
+ epaint.wid = RT_NULL;
+ rtgui_thread_send(tid, (struct rtgui_event*)&epaint, sizeof(epaint));
+ }
+ else
+ {
+ /* send failed */
+ rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR);
+ }
+}
+
+void rtgui_server_handle_set_wm(struct rtgui_event_set_wm *event)
+{
+ struct rtgui_panel* panel = rtgui_panel_find(event->panel_name);
+
+ if (panel != RT_NULL)
+ {
+ rtgui_panel_set_wm(panel, event->parent.sender);
+ }
+}
+
+void rtgui_server_handle_update(struct rtgui_event_update_end* event)
+{
+ struct rtgui_graphic_driver* driver = rtgui_graphic_driver_get_default();
+ if (driver != RT_NULL)
+ {
+ driver->screen_update(&(event->rect));
+ }
+}
+
+void rtgui_server_handle_monitor_add(struct rtgui_event_monitor* event)
+{
+ if (event->panel != RT_NULL)
+ {
+ /* append monitor rect to panel list */
+ rtgui_panel_append_monitor_rect(event->panel, event->parent.sender, &(event->rect));
+ }
+ else
+ {
+ /* add monitor rect to top window list */
+ rtgui_topwin_append_monitor_rect(event->wid, &(event->rect));
+ }
+}
+
+void rtgui_server_handle_monitor_remove(struct rtgui_event_monitor* event)
+{
+ if (event->panel != RT_NULL)
+ {
+ /* add monitor rect to panel list */
+ rtgui_panel_remove_monitor_rect(event->panel, event->parent.sender, &(event->rect));
+ }
+ else
+ {
+ /* add monitor rect to top window list */
+ rtgui_topwin_remove_monitor_rect(event->wid, &(event->rect));
+ }
+}
+
+void rtgui_server_handle_mouse_btn(struct rtgui_event_mouse* event)
+{
+ struct rtgui_topwin* wnd;
+ struct rtgui_panel* panel;
+
+ /* re-init to server thread */
+ RTGUI_EVENT_MOUSE_BUTTON_INIT(event);
+
+ if (rtgui_winrect_is_moved() &&
+ event->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_UP))
+ {
+ struct rtgui_topwin* topwin;
+ rtgui_rect_t rect;
+
+ if (rtgui_winrect_moved_done(&rect, &topwin) == RT_TRUE)
+ {
+ struct rtgui_event_win_move ewin;
+
+ /* move window */
+ RTGUI_EVENT_WIN_MOVE_INIT(&ewin);
+ ewin.wid = topwin->wid;
+ if (topwin->title != RT_NULL)
+ {
+ if (topwin->flag & WINTITLE_BORDER)
+ {
+ ewin.x = rect.x1 + WINTITLE_BORDER_SIZE;
+ ewin.y = rect.y1 + WINTITLE_BORDER_SIZE;
+ }
+ if (!(topwin->flag & WINTITLE_NO)) ewin.y += WINTITLE_HEIGHT;
+ }
+ else
+ {
+ ewin.x = rect.x1;
+ ewin.y = rect.y1;
+ }
+
+ /* send to client thread */
+ rtgui_thread_send(topwin->tid, &(ewin.parent), sizeof(ewin));
+
+ return;
+ }
+ }
+
+ /* get the wnd which contains the mouse */
+ wnd = rtgui_topwin_get_wnd(event->x, event->y);
+ if (wnd != RT_NULL)
+ {
+ event->wid = wnd->wid;
+
+ if (rtgui_server_focus_topwin != wnd)
+ {
+ /* raise this window */
+ rtgui_topwin_raise(wnd->wid, wnd->tid);
+ rtgui_server_focus_panel = RT_NULL;
+ }
+
+ if (wnd->title != RT_NULL &&
+ rtgui_rect_contains_point(&(RTGUI_WIDGET(wnd->title)->extent), event->x, event->y) == RT_EOK)
+ {
+ rtgui_topwin_title_onmouse(wnd, event);
+ }
+ else
+ {
+ /* send mouse event to thread */
+ rtgui_thread_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_mouse));
+ }
+ return ;
+ }
+
+ /* get the panel which contains the mouse */
+ panel = rtgui_panel_get_contain(event->x, event->y);
+ if (panel != RT_NULL)
+ {
+ /* deactivate old window */
+ if (rtgui_server_focus_topwin != RT_NULL)
+ {
+ rtgui_topwin_deactivate_win(rtgui_server_focus_topwin);
+ }
+
+ rtgui_server_focus_panel = panel;
+ rtgui_server_focus_topwin = RT_NULL;
+
+ /* set destination window to null */
+ event->wid = RT_NULL;
+
+ /* send mouse event to thread */
+ rtgui_thread_send(rtgui_panel_get_active_thread(panel),
+ (struct rtgui_event*)event,
+ sizeof(struct rtgui_event_mouse));
+ }
+}
+
+static struct rtgui_panel* last_monitor_panel = RT_NULL;
+static struct rtgui_topwin* last_monitor_topwin = RT_NULL;
+
+void rtgui_server_handle_mouse_motion(struct rtgui_event_mouse* event)
+{
+ /* the topwin contains current mouse */
+ struct rtgui_topwin* win = RT_NULL;
+ struct rtgui_panel* panel = RT_NULL;
+
+ /* re-init mouse event */
+ RTGUI_EVENT_MOUSE_MOTION_INIT(event);
+
+ /* find the panel or topwin which monitor the mouse motion */
+ win = rtgui_topwin_get_wnd(event->x, event->y);
+ if (win == RT_NULL)
+ {
+ /* try to find monitor on the panel */
+ panel = rtgui_panel_get_contain(event->x, event->y);
+
+ if (panel != RT_NULL)
+ {
+ struct rtgui_panel_thread* thread;
+
+ /* get active panel thread */
+ if (panel->thread_list.next != RT_NULL)
+ {
+ thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list);
+ if (!rtgui_mouse_monitor_contains_point(&(thread->monitor_list),
+ event->x, event->y) == RT_TRUE)
+ {
+ /* no monitor in this panel */
+ panel = RT_NULL;
+ }
+ }
+ }
+ }
+ else if (win->monitor_list.next != RT_NULL)
+ {
+ /* check whether the monitor exist */
+ if (rtgui_mouse_monitor_contains_point(&(win->monitor_list), event->x, event->y) != RT_TRUE)
+ {
+ win = RT_NULL;
+
+ /* try to find monitor on the panel */
+ panel = rtgui_panel_get_contain(event->x, event->y);
+ if (panel != RT_NULL)
+ {
+ struct rtgui_panel_thread* thread;
+
+ /* get active panel thread */
+ if (panel->thread_list.next != RT_NULL)
+ {
+ thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list);
+ if (!rtgui_mouse_monitor_contains_point(&(thread->monitor_list),
+ event->x, event->y) == RT_TRUE)
+ {
+ /* no monitor in this panel */
+ panel = RT_NULL;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ win = RT_NULL;
+ }
+
+ /* check old panel or window */
+ if (last_monitor_panel != RT_NULL)
+ {
+ rt_thread_t tid = rtgui_panel_get_active_thread(last_monitor_panel);
+ event->wid = RT_NULL;
+
+ /* send mouse motion event */
+ rtgui_thread_send(tid, &(event->parent), sizeof(struct rtgui_event_mouse));
+ }
+ else if (last_monitor_topwin != RT_NULL)
+ {
+ event->wid = last_monitor_topwin->wid;
+
+ /* send mouse motion event */
+ rtgui_thread_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse));
+ }
+
+ if (last_monitor_panel != panel)
+ {
+ last_monitor_panel = panel;
+ if (last_monitor_panel != RT_NULL)
+ {
+ rt_thread_t tid = rtgui_panel_get_active_thread(last_monitor_panel);
+ event->wid = RT_NULL;
+
+ /* send mouse motion event */
+ rtgui_thread_send(tid, &(event->parent), sizeof(struct rtgui_event_mouse));
+ }
+ }
+
+ if (last_monitor_topwin != win)
+ {
+ last_monitor_topwin = win;
+ if (last_monitor_topwin != RT_NULL)
+ {
+ event->wid = last_monitor_topwin->wid;
+
+ /* send mouse motion event */
+ rtgui_thread_send(last_monitor_topwin->tid, &(event->parent), sizeof(struct rtgui_event_mouse));
+ }
+ }
+
+ /* move mouse to (x, y) */
+ rtgui_mouse_moveto(event->x, event->y);
+}
+
+void rtgui_server_handle_kbd(struct rtgui_event_kbd* event)
+{
+ struct rtgui_topwin* wnd;
+ struct rtgui_panel* panel;
+
+ /* re-init to server thread */
+ RTGUI_EVENT_KBD_INIT(event);
+
+ /* todo: handle input method and global shortcut */
+
+ /* send to focus window or focus panel */
+ wnd = rtgui_server_focus_topwin;
+ if (wnd != RT_NULL && wnd->flag & WINTITLE_ACTIVATE)
+ {
+ /* send to focus window */
+ event->wid = wnd->wid;
+
+ /* send keyboard event to thread */
+ rtgui_thread_send(wnd->tid, (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd));
+
+ return;
+ }
+
+ panel = rtgui_server_focus_panel;
+ if (panel != RT_NULL)
+ {
+ /* send to focus panel */
+ event->wid = RT_NULL;
+
+ /* send keyboard event to thread */
+ rtgui_thread_send(rtgui_panel_get_active_thread(panel),
+ (struct rtgui_event*)event, sizeof(struct rtgui_event_kbd));
+ }
+}
+
+#ifdef __WIN32__
+#include <windows.h>
+#endif
+
+/**
+ * rtgui server thread's entry
+ */
+static void rtgui_server_entry(void* parameter)
+{
+#ifdef __WIN32__
+ /* set the server thread to highest */
+ HANDLE hCurrentThread = GetCurrentThread();
+ SetThreadPriority(hCurrentThread, THREAD_PRIORITY_HIGHEST);
+#endif
+
+ /* init rtgui server msgq */
+ rt_mq_init(&rtgui_server_mq,
+ "rtgui",
+ &rtgui_server_msg_pool[0],
+ 256,
+ sizeof(rtgui_server_msg_pool),
+ RT_IPC_FLAG_FIFO);
+
+ /* register rtgui server thread */
+ rtgui_thread_register(&rtgui_server_thread, &rtgui_server_mq);
+
+ /* init mouse and show */
+ rtgui_mouse_init();
+#ifdef RTGUI_USING_MOUSE_CURSOR
+ rtgui_mouse_show_cursor();
+#endif
+
+ while (1)
+ {
+ /* the buffer uses to receive event */
+ char event_buf[256];
+ struct rtgui_event* event = (struct rtgui_event*)&(event_buf[0]);
+
+ if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK)
+ {
+ /* dispatch event */
+ switch (event->type)
+ {
+ /* panel event */
+ case RTGUI_EVENT_PANEL_ATTACH:
+ /* register an application in panel */
+ rtgui_server_create_application((struct rtgui_event_panel_attach*)event);
+ break;
+
+ case RTGUI_EVENT_PANEL_DETACH:
+ /* unregister an application */
+ rtgui_server_destroy_application((struct rtgui_event_panel_detach*)event);
+ break;
+
+ case RTGUI_EVENT_PANEL_SHOW:
+ /* handle raise an application */
+ rtgui_server_thread_panel_show((struct rtgui_event_panel_show*)event);
+ break;
+
+ case RTGUI_EVENT_PANEL_HIDE:
+ /* handle hide an application */
+ rtgui_server_thread_panel_hide((struct rtgui_event_panel_hide*)event);
+ break;
+
+ case RTGUI_EVENT_SET_WM:
+ /* handle set workbench manager event */
+ rtgui_server_handle_set_wm((struct rtgui_event_set_wm*)event);
+ break;
+
+ /* window event */
+ case RTGUI_EVENT_WIN_CREATE:
+ rtgui_thread_ack(event, RTGUI_STATUS_OK);
+ rtgui_topwin_add((struct rtgui_event_win_create*)event);
+ break;
+
+ case RTGUI_EVENT_WIN_DESTROY:
+ if (rtgui_topwin_remove(((struct rtgui_event_win*)event)->wid) == RT_EOK)
+ rtgui_thread_ack(event, RTGUI_STATUS_OK);
+ else
+ rtgui_thread_ack(event, RTGUI_STATUS_ERROR);
+ break;
+
+ case RTGUI_EVENT_WIN_SHOW:
+ rtgui_topwin_show((struct rtgui_event_win*)event);
+ break;
+
+ case RTGUI_EVENT_WIN_HIDE:
+ rtgui_topwin_hide((struct rtgui_event_win*)event);
+ break;
+
+ case RTGUI_EVENT_WIN_MOVE:
+ rtgui_topwin_move((struct rtgui_event_win_move*)event);
+ break;
+
+ case RTGUI_EVENT_WIN_RESIZE:
+ rtgui_topwin_resize(((struct rtgui_event_win_resize*)event)->wid,
+ &(((struct rtgui_event_win_resize*)event)->rect));
+ break;
+
+ /* other event */
+ case RTGUI_EVENT_UPDATE_BEGIN:
+#ifdef RTGUI_USING_MOUSE_CURSOR
+ /* hide cursor */
+ rtgui_mouse_hide_cursor();
+#endif
+ break;
+
+ case RTGUI_EVENT_UPDATE_END:
+ /* handle screen update */
+ rtgui_server_handle_update((struct rtgui_event_update_end*)event);
+#ifdef RTGUI_USING_MOUSE_CURSOR
+ /* show cursor */
+ rtgui_mouse_show_cursor();
+#endif
+ break;
+
+ case RTGUI_EVENT_MONITOR_ADD:
+ /* handle mouse monitor */
+ rtgui_server_handle_monitor_add((struct rtgui_event_monitor*)event);
+ break;
+
+ /* mouse and keyboard event */
+ case RTGUI_EVENT_MOUSE_MOTION:
+ /* handle mouse motion event */
+ rtgui_server_handle_mouse_motion((struct rtgui_event_mouse*)event);
+ break;
+
+ case RTGUI_EVENT_MOUSE_BUTTON:
+ /* handle mouse button */
+ rtgui_server_handle_mouse_btn((struct rtgui_event_mouse*)event);
+ break;
+
+ case RTGUI_EVENT_KBD:
+ /* handle keyboard event */
+ rtgui_server_handle_kbd((struct rtgui_event_kbd*)event);
+ break;
+
+ case RTGUI_EVENT_COMMAND:
+ break;
+ }
+ }
+ }
+
+ /* unregister in rtgui thread */
+ // rtgui_thread_deregister(rt_thread_self());
+}
+
+void rtgui_server_post_event(struct rtgui_event* event, rt_size_t size)
+{
+ rt_mq_send(&rtgui_server_mq, event, size);
+}
+
+void rtgui_server_init()
+{
+ rt_thread_init(&rtgui_server_thread,
+ "rtgui",
+ rtgui_server_entry, RT_NULL,
+ &rtgui_server_stack[0], sizeof(rtgui_server_stack),
+ RTGUI_SVR_THREAD_PRIORITY,
+ RTGUI_SVR_THREAD_TIMESLICE);
+
+ /* start rtgui server thread */
+ rt_thread_startup(&rtgui_server_thread);
+}
|
