summaryrefslogtreecommitdiff
path: root/rtgui
diff options
context:
space:
mode:
authorbernard.xiong <[email protected]>2009-10-20 23:55:50 +0000
committerbernard.xiong <[email protected]>2009-10-20 23:55:50 +0000
commita65a0c70ac8c82b5eb7f8b6bf258270585a4e001 (patch)
tree4e4244a2b59ab111f518d087fe6e3041ae70d3da /rtgui
parent9a7ae650851ee482a21062f1dfff08caf619bcc2 (diff)
update filerw ops with dfs filesystem interface; update window event loop handler.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@114 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'rtgui')
-rw-r--r--rtgui/common/filerw.c118
-rw-r--r--rtgui/common/libpng/pngconf.h4
-rw-r--r--rtgui/common/rtgui_system.c6
-rw-r--r--rtgui/include/rtgui/event.h3
-rw-r--r--rtgui/include/rtgui/rtgui_config.h3
-rw-r--r--rtgui/include/rtgui/rtgui_system.h3
-rw-r--r--rtgui/include/rtgui/widgets/window.h6
-rw-r--r--rtgui/server/topwin.c13
-rw-r--r--rtgui/widgets/toplevel.c6
-rw-r--r--rtgui/widgets/window.c26
10 files changed, 162 insertions, 26 deletions
diff --git a/rtgui/common/filerw.c b/rtgui/common/filerw.c
index 7f390d3f1d..09905f33b3 100644
--- a/rtgui/common/filerw.c
+++ b/rtgui/common/filerw.c
@@ -15,7 +15,87 @@
#include <rtgui/filerw.h>
#include <rtgui/rtgui_system.h>
-#ifdef RT_USING_STDIO_FILERW
+#ifdef RT_USING_DFS_FILERW
+#include <dfs_posix.h>
+
+/* standard file read/write */
+struct rtgui_filerw_stdio
+{
+ /* inherit from rtgui_filerw */
+ struct rtgui_filerw parent;
+
+ int fd;
+ rt_bool_t eof;
+};
+
+static int stdio_seek(struct rtgui_filerw *context, rt_off_t offset, int whence)
+{
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+ int stdio_whence[3] = {SEEK_SET, SEEK_CUR, SEEK_END};
+
+ if (whence < RTGUI_FILE_SEEK_SET || whence > RTGUI_FILE_SEEK_END)
+ {
+ return -1;
+ }
+
+ return lseek(stdio_filerw->fd, offset, stdio_whence[whence]);
+}
+
+static int stdio_read(struct rtgui_filerw *context, void *ptr, rt_size_t size, rt_size_t maxnum)
+{
+ int result;
+
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ /* end of file */
+ if (stdio_filerw->eof == RT_TRUE) return -1;
+
+ result = read(stdio_filerw->fd, ptr, size * maxnum);
+ if (result == 0) stdio_filerw->eof = RT_TRUE;
+
+ return result;
+}
+
+static int stdio_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num)
+{
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ return write(stdio_filerw->fd, (char*)ptr, size * num);
+}
+
+static int stdio_tell(struct rtgui_filerw* context)
+{
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ return lseek(stdio_filerw->fd, 0, SEEK_CUR);
+}
+
+static int stdio_eof(struct rtgui_filerw* context)
+{
+ int result;
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ if (stdio_filerw->eof == RT_TRUE) result = 1;
+ else result = -1;
+
+ return result;
+}
+
+static int stdio_close(struct rtgui_filerw *context)
+{
+ struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
+
+ if (stdio_filerw)
+ {
+ close(stdio_filerw->fd);
+ rtgui_free(stdio_filerw);
+
+ return 0;
+ }
+
+ return -1;
+}
+#elif RT_USING_STDIO_FILERW
#include <stdio.h>
/* standard file read/write */
@@ -74,14 +154,14 @@ static int stdio_write(struct rtgui_filerw *context, const void *ptr, rt_size_t
return nwrote;
}
-int stdio_tell(struct rtgui_filerw* context)
+static int stdio_tell(struct rtgui_filerw* context)
{
struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
return ftell(stdio_filerw->fp);
}
-int stdio_eof(struct rtgui_filerw* context)
+static int stdio_eof(struct rtgui_filerw* context)
{
struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
@@ -222,7 +302,37 @@ rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context)
}
/* file read/write public interface */
-#ifdef RT_USING_STDIO_FILERW
+#ifdef RT_USING_DFS_FILERW
+struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode)
+{
+ int fd;
+ struct rtgui_filerw_stdio *rw;
+
+ RT_ASSERT(filename != RT_NULL);
+
+ rw = RT_NULL;
+ fd = open(filename, mode, 0);
+
+ if ( fd >= 0 )
+ {
+ rw = (struct rtgui_filerw_stdio*) rtgui_malloc(sizeof(struct rtgui_filerw_stdio));
+ if (rw != RT_NULL)
+ {
+ rw->parent.seek = stdio_seek;
+ rw->parent.read = stdio_read;
+ rw->parent.write = stdio_write;
+ rw->parent.tell = stdio_tell;
+ rw->parent.close = stdio_close;
+ rw->parent.eof = stdio_eof;
+
+ rw->fd = fd;
+ rw->eof = RT_FALSE;
+ }
+ }
+
+ return &(rw->parent);
+}
+#elif RT_USING_STDIO_FILERW
struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode)
{
FILE *fp;
diff --git a/rtgui/common/libpng/pngconf.h b/rtgui/common/libpng/pngconf.h
index b61c7aedc0..10a6b3f0ad 100644
--- a/rtgui/common/libpng/pngconf.h
+++ b/rtgui/common/libpng/pngconf.h
@@ -22,7 +22,9 @@
#ifdef __RT_THREAD__
#define PNG_NO_WRITE_SUPPORTED
#define PNG_NO_STDIO
-#define PNG_MAX_MALLOC_64K
+#define PNG_MAX_MALLOC_64K
+#define malloc rtgui_malloc
+#define free rtgui_free
#endif
#define PNG_1_2_X
diff --git a/rtgui/common/rtgui_system.c b/rtgui/common/rtgui_system.c
index 7288c83f55..60808da44d 100644
--- a/rtgui/common/rtgui_system.c
+++ b/rtgui/common/rtgui_system.c
@@ -19,6 +19,8 @@
#include <rtgui/rtgui_server.h>
#include <rtgui/widgets/window.h>
+#define RTGUI_EVENT_DEBUG
+
#ifdef __WIN32__
#define RTGUI_EVENT_DEBUG
#define RTGUI_MEM_TRACE
@@ -255,6 +257,7 @@ rtgui_thread_t* rtgui_thread_register(rt_thread_t tid, rt_mq_t mq)
thread->tid = tid;
thread->mq = mq;
thread->widget = RT_NULL;
+ thread->is_quit = RT_FALSE;
/* take semaphore */
rt_sem_take(&_rtgui_thread_hash_semaphore, RT_WAITING_FOREVER);
@@ -443,8 +446,7 @@ static void rtgui_time_out(void* parameter)
event.parent.type = RTGUI_EVENT_TIMER;
event.parent.sender = RT_NULL;
- event.callback = timer->timeout;
- event.parameter = timer->user_data;
+ event.timer = timer;
rtgui_thread_send(timer->tid, &(event.parent), sizeof(struct rtgui_event_timer));
}
diff --git a/rtgui/include/rtgui/event.h b/rtgui/include/rtgui/event.h
index 5a94107ee9..0ff94117ce 100644
--- a/rtgui/include/rtgui/event.h
+++ b/rtgui/include/rtgui/event.h
@@ -283,8 +283,7 @@ struct rtgui_event_timer
{
struct rtgui_event parent;
- void (*callback)(struct rtgui_timer* timer, void* parameter);
- void *parameter;
+ struct rtgui_timer *timer;
};
struct rtgui_event_clip_info
diff --git a/rtgui/include/rtgui/rtgui_config.h b/rtgui/include/rtgui/rtgui_config.h
index 11e77c2091..fc63f17d6c 100644
--- a/rtgui/include/rtgui/rtgui_config.h
+++ b/rtgui/include/rtgui/rtgui_config.h
@@ -24,7 +24,8 @@
/* #define RTGUI_USING_FONT16 */
-#define RT_USING_STDIO_FILERW
+// #define RT_USING_STDIO_FILERW
+#define RT_USING_DFS_FILERW
#define RTGUI_IMAGE_PNG
#define RTGUI_SVR_THREAD_PRIORITY 15
diff --git a/rtgui/include/rtgui/rtgui_system.h b/rtgui/include/rtgui/rtgui_system.h
index e0ceae6f2b..9fd76b39c0 100644
--- a/rtgui/include/rtgui/rtgui_system.h
+++ b/rtgui/include/rtgui/rtgui_system.h
@@ -31,6 +31,9 @@ struct rtgui_thread
/* the owner of thread */
struct rtgui_widget* widget;
+
+ /* quit of thread */
+ rt_bool_t is_quit;
};
typedef struct rtgui_thread rtgui_thread_t;
struct rtgui_timer;
diff --git a/rtgui/include/rtgui/widgets/window.h b/rtgui/include/rtgui/widgets/window.h
index ee7f8a6b66..243ab75d26 100644
--- a/rtgui/include/rtgui/widgets/window.h
+++ b/rtgui/include/rtgui/widgets/window.h
@@ -47,6 +47,9 @@ struct rtgui_win
/* inherit from toplevel */
struct rtgui_toplevel parent;
+ /* parent toplevel */
+ rtgui_toplevel_t* parent_toplevel;
+
/* top window style */
rt_uint32_t style;
@@ -64,7 +67,8 @@ struct rtgui_win
rtgui_type_t *rtgui_win_type_get(void);
-rtgui_win_t* rtgui_win_create(const char* title, rtgui_rect_t *rect, rt_uint32_t flag);
+rtgui_win_t* rtgui_win_create(rtgui_toplevel_t* parent_toplevel, const char* title,
+ rtgui_rect_t *rect, rt_uint32_t flag);
void rtgui_win_destroy(rtgui_win_t* win);
void rtgui_win_show(rtgui_win_t* win);
diff --git a/rtgui/server/topwin.c b/rtgui/server/topwin.c
index 0deadae976..caf374b41f 100644
--- a/rtgui/server/topwin.c
+++ b/rtgui/server/topwin.c
@@ -752,10 +752,15 @@ static void rtgui_topwin_redraw(struct rtgui_rect* rect)
if (rtgui_rect_is_intersect(rect, &(panel->extent)) == RT_EOK)
{
- /* draw panel */
- epaint.wid = RT_NULL;
- rtgui_thread_send(rtgui_panel_get_active_thread(panel),
- &(epaint.parent), sizeof(epaint));
+ rt_thread_t tid;
+
+ tid = rtgui_panel_get_active_thread(panel);
+ if (tid != RT_NULL)
+ {
+ /* draw panel */
+ epaint.wid = RT_NULL;
+ rtgui_thread_send(tid, &(epaint.parent), sizeof(epaint));
+ }
}
}
}
diff --git a/rtgui/widgets/toplevel.c b/rtgui/widgets/toplevel.c
index 6823b66799..a20663ee24 100644
--- a/rtgui/widgets/toplevel.c
+++ b/rtgui/widgets/toplevel.c
@@ -84,12 +84,14 @@ rt_bool_t rtgui_toplevel_event_handler(rtgui_widget_t* widget, rtgui_event_t* ev
case RTGUI_EVENT_TIMER:
{
+ struct rtgui_timer* timer;
struct rtgui_event_timer* etimer = (struct rtgui_event_timer*) event;
- if (etimer->callback != RT_NULL)
+ timer = etimer->timer;
+ if (timer->timeout != RT_NULL)
{
/* call timeout function */
- etimer->callback(RT_NULL, etimer->parameter);
+ timer->timeout(timer, timer->user_data);
}
}
break;
diff --git a/rtgui/widgets/window.c b/rtgui/widgets/window.c
index d882181e17..d2cbcce286 100644
--- a/rtgui/widgets/window.c
+++ b/rtgui/widgets/window.c
@@ -110,7 +110,7 @@ rtgui_type_t *rtgui_win_type_get(void)
return win_type;
}
-rtgui_win_t* rtgui_win_create(const char* title, rtgui_rect_t *rect, rt_uint32_t style)
+rtgui_win_t* rtgui_win_create(rtgui_toplevel_t* parent_toplevel, const char* title, rtgui_rect_t *rect, rt_uint32_t style)
{
struct rtgui_win* win;
@@ -118,6 +118,9 @@ rtgui_win_t* rtgui_win_create(const char* title, rtgui_rect_t *rect, rt_uint32_t
win = (struct rtgui_win*) rtgui_widget_create (RTGUI_WIN_TYPE);
if (win != RT_NULL)
{
+ /* 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;
@@ -137,6 +140,14 @@ rtgui_win_t* rtgui_win_create(const char* title, rtgui_rect_t *rect, rt_uint32_t
void rtgui_win_destroy(struct rtgui_win* win)
{
+ if (win->parent_toplevel == RT_NULL)
+ {
+ rtgui_thread_t *rtgui_tid;
+
+ rtgui_tid = (rtgui_thread_t*) rt_thread_self()->user_data;
+ rtgui_tid->is_quit = RT_TRUE;
+ }
+
rtgui_widget_destroy(RTGUI_WIDGET(win));
}
@@ -368,22 +379,19 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_even
/* windows event loop */
void rtgui_win_event_loop(rtgui_win_t* wnd)
{
- int quit = 0;
-
+ rtgui_thread_t *rtgui_tid;
/* the buffer uses to receive event */
char event_buf[256];
struct rtgui_event* event = (struct rtgui_event*)&event_buf[0];
+ rtgui_tid = (rtgui_thread_t*) rt_thread_self()->user_data;
- while (!quit)
+ while (rtgui_tid->is_quit == RT_FALSE)
{
if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK)
{
- if (RTGUI_WIDGET(wnd)->event_handler != RT_NULL)
- {
- if (RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event) == RT_TRUE)
- quit = 1;
- }
+ if (RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event) == RT_TRUE)
+ rtgui_tid->is_quit = RT_TRUE;
}
}
}