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
This commit is contained in:
bernard.xiong 2009-10-20 23:55:50 +00:00
parent 9a7ae65085
commit a65a0c70ac
10 changed files with 162 additions and 26 deletions

View File

@ -15,7 +15,87 @@
#include <rtgui/filerw.h> #include <rtgui/filerw.h>
#include <rtgui/rtgui_system.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> #include <stdio.h>
/* standard file read/write */ /* standard file read/write */
@ -74,14 +154,14 @@ static int stdio_write(struct rtgui_filerw *context, const void *ptr, rt_size_t
return nwrote; 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; struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
return ftell(stdio_filerw->fp); 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; 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 */ /* 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) struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode)
{ {
FILE *fp; FILE *fp;

View File

@ -23,6 +23,8 @@
#define PNG_NO_WRITE_SUPPORTED #define PNG_NO_WRITE_SUPPORTED
#define PNG_NO_STDIO #define PNG_NO_STDIO
#define PNG_MAX_MALLOC_64K #define PNG_MAX_MALLOC_64K
#define malloc rtgui_malloc
#define free rtgui_free
#endif #endif
#define PNG_1_2_X #define PNG_1_2_X

View File

@ -19,6 +19,8 @@
#include <rtgui/rtgui_server.h> #include <rtgui/rtgui_server.h>
#include <rtgui/widgets/window.h> #include <rtgui/widgets/window.h>
#define RTGUI_EVENT_DEBUG
#ifdef __WIN32__ #ifdef __WIN32__
#define RTGUI_EVENT_DEBUG #define RTGUI_EVENT_DEBUG
#define RTGUI_MEM_TRACE #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->tid = tid;
thread->mq = mq; thread->mq = mq;
thread->widget = RT_NULL; thread->widget = RT_NULL;
thread->is_quit = RT_FALSE;
/* take semaphore */ /* take semaphore */
rt_sem_take(&_rtgui_thread_hash_semaphore, RT_WAITING_FOREVER); 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.type = RTGUI_EVENT_TIMER;
event.parent.sender = RT_NULL; event.parent.sender = RT_NULL;
event.callback = timer->timeout; event.timer = timer;
event.parameter = timer->user_data;
rtgui_thread_send(timer->tid, &(event.parent), sizeof(struct rtgui_event_timer)); rtgui_thread_send(timer->tid, &(event.parent), sizeof(struct rtgui_event_timer));
} }

View File

@ -283,8 +283,7 @@ struct rtgui_event_timer
{ {
struct rtgui_event parent; struct rtgui_event parent;
void (*callback)(struct rtgui_timer* timer, void* parameter); struct rtgui_timer *timer;
void *parameter;
}; };
struct rtgui_event_clip_info struct rtgui_event_clip_info

View File

@ -24,7 +24,8 @@
/* #define RTGUI_USING_FONT16 */ /* #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_IMAGE_PNG
#define RTGUI_SVR_THREAD_PRIORITY 15 #define RTGUI_SVR_THREAD_PRIORITY 15

View File

@ -31,6 +31,9 @@ struct rtgui_thread
/* the owner of thread */ /* the owner of thread */
struct rtgui_widget* widget; struct rtgui_widget* widget;
/* quit of thread */
rt_bool_t is_quit;
}; };
typedef struct rtgui_thread rtgui_thread_t; typedef struct rtgui_thread rtgui_thread_t;
struct rtgui_timer; struct rtgui_timer;

View File

@ -47,6 +47,9 @@ struct rtgui_win
/* inherit from toplevel */ /* inherit from toplevel */
struct rtgui_toplevel parent; struct rtgui_toplevel parent;
/* parent toplevel */
rtgui_toplevel_t* parent_toplevel;
/* top window style */ /* top window style */
rt_uint32_t style; rt_uint32_t style;
@ -64,7 +67,8 @@ struct rtgui_win
rtgui_type_t *rtgui_win_type_get(void); 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_destroy(rtgui_win_t* win);
void rtgui_win_show(rtgui_win_t* win); void rtgui_win_show(rtgui_win_t* win);

View File

@ -752,10 +752,15 @@ static void rtgui_topwin_redraw(struct rtgui_rect* rect)
if (rtgui_rect_is_intersect(rect, &(panel->extent)) == RT_EOK) if (rtgui_rect_is_intersect(rect, &(panel->extent)) == RT_EOK)
{ {
/* draw panel */ rt_thread_t tid;
epaint.wid = RT_NULL;
rtgui_thread_send(rtgui_panel_get_active_thread(panel), tid = rtgui_panel_get_active_thread(panel);
&(epaint.parent), sizeof(epaint)); if (tid != RT_NULL)
{
/* draw panel */
epaint.wid = RT_NULL;
rtgui_thread_send(tid, &(epaint.parent), sizeof(epaint));
}
} }
} }
} }

View File

@ -84,12 +84,14 @@ rt_bool_t rtgui_toplevel_event_handler(rtgui_widget_t* widget, rtgui_event_t* ev
case RTGUI_EVENT_TIMER: case RTGUI_EVENT_TIMER:
{ {
struct rtgui_timer* timer;
struct rtgui_event_timer* etimer = (struct rtgui_event_timer*) event; 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 */ /* call timeout function */
etimer->callback(RT_NULL, etimer->parameter); timer->timeout(timer, timer->user_data);
} }
} }
break; break;

View File

@ -110,7 +110,7 @@ rtgui_type_t *rtgui_win_type_get(void)
return win_type; 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; 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); win = (struct rtgui_win*) rtgui_widget_create (RTGUI_WIN_TYPE);
if (win != RT_NULL) if (win != RT_NULL)
{ {
/* set parent toplevel */
win->parent_toplevel = parent_toplevel;
/* set title, rect and style */ /* set title, rect and style */
if (title != RT_NULL) win->title = rt_strdup(title); if (title != RT_NULL) win->title = rt_strdup(title);
else win->title = RT_NULL; 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) 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)); 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 */ /* windows event loop */
void rtgui_win_event_loop(rtgui_win_t* wnd) void rtgui_win_event_loop(rtgui_win_t* wnd)
{ {
int quit = 0; rtgui_thread_t *rtgui_tid;
/* the buffer uses to receive event */ /* the buffer uses to receive event */
char event_buf[256]; char event_buf[256];
struct rtgui_event* event = (struct rtgui_event*)&event_buf[0]; 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_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)
{ rtgui_tid->is_quit = RT_TRUE;
if (RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event) == RT_TRUE)
quit = 1;
}
} }
} }
} }