sync RTGUI with github(https://github.com/RT-Thread/RTGUI) 126336387561442a0508b661595134deb28ad34b

As always, full log is in GitHub.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2265 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
dzzxzz@gmail.com 2012-08-27 07:57:19 +00:00
parent a2c5b92151
commit 64b0cd34fe
30 changed files with 763 additions and 200 deletions

View File

@ -38,6 +38,7 @@ void rtgui_dc_destory(struct rtgui_dc* dc)
dc->engine->fini(dc); dc->engine->fini(dc);
rtgui_free(dc); rtgui_free(dc);
} }
RTM_EXPORT(rtgui_dc_destory);
void rtgui_dc_draw_line (struct rtgui_dc* dc, int x1, int y1, int x2, int y2) void rtgui_dc_draw_line (struct rtgui_dc* dc, int x1, int y1, int x2, int y2)
{ {
@ -106,6 +107,7 @@ void rtgui_dc_draw_line (struct rtgui_dc* dc, int x1, int y1, int x2, int y2)
} }
} }
} }
RTM_EXPORT(rtgui_dc_draw_line);
void rtgui_dc_draw_horizontal_line(struct rtgui_dc* dc, int x1, int x2, int y) void rtgui_dc_draw_horizontal_line(struct rtgui_dc* dc, int x1, int x2, int y)
{ {
@ -127,6 +129,7 @@ void rtgui_dc_draw_horizontal_line(struct rtgui_dc* dc, int x1, int x2, int y)
/* restore color */ /* restore color */
RTGUI_DC_FC(dc) = color; RTGUI_DC_FC(dc) = color;
} }
RTM_EXPORT(rtgui_dc_draw_horizontal_line);
void rtgui_dc_draw_vertical_line(struct rtgui_dc* dc, int x, int y1, int y2) void rtgui_dc_draw_vertical_line(struct rtgui_dc* dc, int x, int y1, int y2)
{ {
@ -148,6 +151,7 @@ void rtgui_dc_draw_vertical_line(struct rtgui_dc* dc, int x, int y1, int y2)
/* restore color */ /* restore color */
RTGUI_DC_FC(dc) = color; RTGUI_DC_FC(dc) = color;
} }
RTM_EXPORT(rtgui_dc_draw_vertical_line);
void rtgui_dc_draw_rect (struct rtgui_dc* dc, struct rtgui_rect* rect) void rtgui_dc_draw_rect (struct rtgui_dc* dc, struct rtgui_rect* rect)
{ {
@ -157,6 +161,7 @@ void rtgui_dc_draw_rect (struct rtgui_dc* dc, struct rtgui_rect* rect)
rtgui_dc_draw_vline(dc, rect->x1, rect->y1, rect->y2); rtgui_dc_draw_vline(dc, rect->x1, rect->y1, rect->y2);
rtgui_dc_draw_vline(dc, rect->x2 - 1, rect->y1, rect->y2); rtgui_dc_draw_vline(dc, rect->x2 - 1, rect->y1, rect->y2);
} }
RTM_EXPORT(rtgui_dc_draw_rect);
void rtgui_dc_fill_rect_forecolor(struct rtgui_dc* dc, struct rtgui_rect* rect) void rtgui_dc_fill_rect_forecolor(struct rtgui_dc* dc, struct rtgui_rect* rect)
{ {
@ -169,6 +174,7 @@ void rtgui_dc_fill_rect_forecolor(struct rtgui_dc* dc, struct rtgui_rect* rect)
i++; i++;
}while(!(rect->y1+i == rect->y2)); }while(!(rect->y1+i == rect->y2));
} }
RTM_EXPORT(rtgui_dc_fill_rect_forecolor);
void rtgui_dc_draw_round_rect(struct rtgui_dc* dc, struct rtgui_rect* rect, int r) void rtgui_dc_draw_round_rect(struct rtgui_dc* dc, struct rtgui_rect* rect, int r)
{ {
@ -198,6 +204,7 @@ void rtgui_dc_draw_round_rect(struct rtgui_dc* dc, struct rtgui_rect* rect, int
rtgui_dc_draw_vline(dc, rect->x2, rect->y1 + r, rect->y2 - r); rtgui_dc_draw_vline(dc, rect->x2, rect->y1 + r, rect->y2 - r);
} }
} }
RTM_EXPORT(rtgui_dc_draw_round_rect);
void rtgui_dc_fill_round_rect(struct rtgui_dc* dc, struct rtgui_rect* rect, int r) void rtgui_dc_fill_round_rect(struct rtgui_dc* dc, struct rtgui_rect* rect, int r)
{ {
@ -231,6 +238,7 @@ void rtgui_dc_fill_round_rect(struct rtgui_dc* dc, struct rtgui_rect* rect, int
rtgui_dc_fill_circle(dc, rect->x1 + r, rect->y2 - r, r); rtgui_dc_fill_circle(dc, rect->x1 + r, rect->y2 - r, r);
} }
} }
RTM_EXPORT(rtgui_dc_fill_round_rect);
void rtgui_dc_draw_shaded_rect(struct rtgui_dc* dc, rtgui_rect_t* rect, void rtgui_dc_draw_shaded_rect(struct rtgui_dc* dc, rtgui_rect_t* rect,
rtgui_color_t c1, rtgui_color_t c2) rtgui_color_t c1, rtgui_color_t c2)
@ -245,6 +253,7 @@ void rtgui_dc_draw_shaded_rect(struct rtgui_dc* dc, rtgui_rect_t* rect,
rtgui_dc_draw_vline(dc, rect->x2 - 1, rect->y1, rect->y2); rtgui_dc_draw_vline(dc, rect->x2 - 1, rect->y1, rect->y2);
rtgui_dc_draw_hline(dc, rect->x1, rect->x2, rect->y2 - 1); rtgui_dc_draw_hline(dc, rect->x1, rect->x2, rect->y2 - 1);
} }
RTM_EXPORT(rtgui_dc_draw_shaded_rect);
void rtgui_dc_draw_focus_rect(struct rtgui_dc* dc, rtgui_rect_t* rect) void rtgui_dc_draw_focus_rect(struct rtgui_dc* dc, rtgui_rect_t* rect)
{ {
@ -266,6 +275,7 @@ void rtgui_dc_draw_focus_rect(struct rtgui_dc* dc, rtgui_rect_t* rect)
rtgui_dc_draw_point(dc, rect->x2-1, y); rtgui_dc_draw_point(dc, rect->x2-1, y);
} }
} }
RTM_EXPORT(rtgui_dc_draw_focus_rect);
void rtgui_dc_draw_text (struct rtgui_dc* dc, const char* text, struct rtgui_rect* rect) void rtgui_dc_draw_text (struct rtgui_dc* dc, const char* text, struct rtgui_rect* rect)
{ {
@ -289,6 +299,7 @@ void rtgui_dc_draw_text (struct rtgui_dc* dc, const char* text, struct rtgui_rec
len = strlen((const char*)text); len = strlen((const char*)text);
rtgui_font_draw(font, dc, text, len, &text_rect); rtgui_font_draw(font, dc, text, len, &text_rect);
} }
RTM_EXPORT(rtgui_dc_draw_text);
void rtgui_dc_draw_text_stroke (struct rtgui_dc* dc, const char* text, struct rtgui_rect* rect, void rtgui_dc_draw_text_stroke (struct rtgui_dc* dc, const char* text, struct rtgui_rect* rect,
rtgui_color_t color_stroke, rtgui_color_t color_core) rtgui_color_t color_stroke, rtgui_color_t color_core)
@ -314,6 +325,7 @@ void rtgui_dc_draw_text_stroke (struct rtgui_dc* dc, const char* text, struct rt
rtgui_dc_draw_text(dc, text, rect); rtgui_dc_draw_text(dc, text, rect);
RTGUI_DC_FC(dc) = fc; RTGUI_DC_FC(dc) = fc;
} }
RTM_EXPORT(rtgui_dc_draw_text_stroke);
/* /*
* draw a monochrome color bitmap data * draw a monochrome color bitmap data
@ -332,16 +344,19 @@ void rtgui_dc_draw_mono_bmp(struct rtgui_dc* dc, int x, int y, int w, int h, con
if ( ((data[i*w + j] >> (7-k)) & 0x01) != 0) if ( ((data[i*w + j] >> (7-k)) & 0x01) != 0)
rtgui_dc_draw_point(dc, x + 8*j + k, y + i); rtgui_dc_draw_point(dc, x + 8*j + k, y + i);
} }
RTM_EXPORT(rtgui_dc_draw_mono_bmp);
void rtgui_dc_draw_byte(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data) void rtgui_dc_draw_byte(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data)
{ {
rtgui_dc_draw_mono_bmp(dc, x, y, 8, h, data); rtgui_dc_draw_mono_bmp(dc, x, y, 8, h, data);
} }
RTM_EXPORT(rtgui_dc_draw_byte);
void rtgui_dc_draw_word(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data) void rtgui_dc_draw_word(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data)
{ {
rtgui_dc_draw_mono_bmp(dc, x, y, 16, h, data); rtgui_dc_draw_mono_bmp(dc, x, y, 16, h, data);
} }
RTM_EXPORT(rtgui_dc_draw_word);
void rtgui_dc_draw_border(struct rtgui_dc* dc, rtgui_rect_t* rect, int flag) void rtgui_dc_draw_border(struct rtgui_dc* dc, rtgui_rect_t* rect, int flag)
{ {
@ -395,6 +410,7 @@ void rtgui_dc_draw_border(struct rtgui_dc* dc, rtgui_rect_t* rect, int flag)
/* restore color */ /* restore color */
RTGUI_DC_FC(dc) = color; RTGUI_DC_FC(dc) = color;
} }
RTM_EXPORT(rtgui_dc_draw_border);
void rtgui_dc_draw_polygon(struct rtgui_dc* dc, const int *vx, const int *vy, int count) void rtgui_dc_draw_polygon(struct rtgui_dc* dc, const int *vx, const int *vy, int count)
{ {
@ -427,6 +443,7 @@ void rtgui_dc_draw_polygon(struct rtgui_dc* dc, const int *vx, const int *vy, in
} }
rtgui_dc_draw_line(dc, *x1, *y1, *vx, *vy); rtgui_dc_draw_line(dc, *x1, *y1, *vx, *vy);
} }
RTM_EXPORT(rtgui_dc_draw_polygon);
void rtgui_dc_draw_regular_polygon(struct rtgui_dc* dc, int x, int y, int r, int count, rt_uint16_t angle) void rtgui_dc_draw_regular_polygon(struct rtgui_dc* dc, int x, int y, int r, int count, rt_uint16_t angle)
{ {
@ -474,6 +491,7 @@ void rtgui_dc_draw_regular_polygon(struct rtgui_dc* dc, int x, int y, int r, int
rtgui_free(y_head); rtgui_free(y_head);
} }
RTM_EXPORT(rtgui_dc_draw_regular_polygon);
void rtgui_dc_fill_polygon(struct rtgui_dc* dc, const int* vx, const int* vy, int count) void rtgui_dc_fill_polygon(struct rtgui_dc* dc, const int* vx, const int* vy, int count)
{ {
@ -556,6 +574,7 @@ void rtgui_dc_fill_polygon(struct rtgui_dc* dc, const int* vx, const int* vy, in
/* release memory */ /* release memory */
rtgui_free(poly_ints); rtgui_free(poly_ints);
} }
RTM_EXPORT(rtgui_dc_fill_polygon);
void rtgui_dc_draw_circle(struct rtgui_dc* dc, int x, int y, int r) void rtgui_dc_draw_circle(struct rtgui_dc* dc, int x, int y, int r)
{ {
@ -632,6 +651,7 @@ void rtgui_dc_draw_circle(struct rtgui_dc* dc, int x, int y, int r)
cx++; cx++;
}while (cx <= cy); }while (cx <= cy);
} }
RTM_EXPORT(rtgui_dc_draw_circle);
void rtgui_dc_fill_circle(struct rtgui_dc* dc, rt_int16_t x, rt_int16_t y, rt_int16_t r) void rtgui_dc_fill_circle(struct rtgui_dc* dc, rt_int16_t x, rt_int16_t y, rt_int16_t r)
{ {
@ -707,6 +727,7 @@ void rtgui_dc_fill_circle(struct rtgui_dc* dc, rt_int16_t x, rt_int16_t y, rt_in
cx++; cx++;
} while (cx <= cy); } while (cx <= cy);
} }
RTM_EXPORT(rtgui_dc_fill_circle);
void rtgui_dc_draw_arc(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end) void rtgui_dc_draw_arc(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end)
{ {
@ -926,6 +947,7 @@ void rtgui_dc_draw_arc(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16
cx++; cx++;
} while (cx <= cy); } while (cx <= cy);
} }
RTM_EXPORT(rtgui_dc_draw_arc);
void rtgui_dc_draw_annulus(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r1, rt_int16_t r2, rt_int16_t start, rt_int16_t end) void rtgui_dc_draw_annulus(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r1, rt_int16_t r2, rt_int16_t start, rt_int16_t end)
{ {
@ -977,6 +999,7 @@ void rtgui_dc_draw_annulus(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_i
rtgui_dc_draw_line(dc, start_x, start_y, end_x, end_y); rtgui_dc_draw_line(dc, start_x, start_y, end_x, end_y);
} }
RTM_EXPORT(rtgui_dc_draw_annulus);
void rtgui_dc_draw_sector(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end) void rtgui_dc_draw_sector(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end)
{ {
@ -1010,6 +1033,7 @@ void rtgui_dc_draw_sector(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_in
rtgui_dc_draw_line(dc, x, y, start_x, start_y); rtgui_dc_draw_line(dc, x, y, start_x, start_y);
rtgui_dc_draw_line(dc, x, y, end_x, end_y); rtgui_dc_draw_line(dc, x, y, end_x, end_y);
} }
RTM_EXPORT(rtgui_dc_draw_sector);
void rtgui_dc_fill_sector(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end) void rtgui_dc_fill_sector(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t r, rt_int16_t start, rt_int16_t end)
{ {
@ -1044,6 +1068,7 @@ void rtgui_dc_fill_sector(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_in
rtgui_dc_draw_line(dc, x, y, start_x, start_y); rtgui_dc_draw_line(dc, x, y, start_x, start_y);
}while(!((start_x == end_x) && (start_y == end_y))); }while(!((start_x == end_x) && (start_y == end_y)));
} }
RTM_EXPORT(rtgui_dc_fill_sector);
void rtgui_dc_draw_ellipse(struct rtgui_dc* dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry) void rtgui_dc_draw_ellipse(struct rtgui_dc* dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry)
{ {
@ -1192,6 +1217,7 @@ void rtgui_dc_draw_ellipse(struct rtgui_dc* dc, rt_int16_t x, rt_int16_t y, rt_i
} while (i > h); } while (i > h);
} }
} }
RTM_EXPORT(rtgui_dc_draw_ellipse);
void rtgui_dc_fill_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry) void rtgui_dc_fill_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_int16_t rx, rt_int16_t ry)
{ {
@ -1300,5 +1326,5 @@ void rtgui_dc_fill_ellipse(struct rtgui_dc *dc, rt_int16_t x, rt_int16_t y, rt_i
} while (i > h); } while (i > h);
} }
} }
RTM_EXPORT(rtgui_dc_fill_ellipse);

View File

@ -62,12 +62,14 @@ struct rtgui_dc* rtgui_dc_begin_drawing(rtgui_widget_t* owner)
return dc; return dc;
} }
RTM_EXPORT(rtgui_dc_begin_drawing);
void rtgui_dc_end_drawing(struct rtgui_dc* dc) void rtgui_dc_end_drawing(struct rtgui_dc* dc)
{ {
dc->engine->fini(dc); dc->engine->fini(dc);
rtgui_screen_unlock(); rtgui_screen_unlock();
} }
RTM_EXPORT(rtgui_dc_end_drawing);
const struct rtgui_dc_engine dc_client_engine = const struct rtgui_dc_engine dc_client_engine =
{ {

View File

@ -16,7 +16,6 @@
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
#ifdef RTGUI_USING_DFS_FILERW #ifdef RTGUI_USING_DFS_FILERW
#include <dfs_posix.h>
/* standard file read/write */ /* standard file read/write */
struct rtgui_filerw_stdio struct rtgui_filerw_stdio
@ -95,93 +94,7 @@ static int stdio_close(struct rtgui_filerw *context)
return -1; return -1;
} }
#elif defined(RTGUI_USING_STDIO_FILERW)
#include <stdio.h>
/* standard file read/write */
struct rtgui_filerw_stdio
{
/* inherit from rtgui_filerw */
struct rtgui_filerw parent;
FILE* fp;
};
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;
}
if (fseek(stdio_filerw->fp, offset, stdio_whence[whence]) == 0)
{
return ftell(stdio_filerw->fp);
}
return -1;
}
static int stdio_read(struct rtgui_filerw *context, void *ptr, rt_size_t size, rt_size_t maxnum)
{
size_t nread;
struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
nread = fread(ptr, size, maxnum, stdio_filerw->fp);
if (nread == 0 && ferror(stdio_filerw->fp))
{
return -1;
}
return nread;
}
static int stdio_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num)
{
size_t nwrote;
struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
nwrote = fwrite(ptr, size, num, stdio_filerw->fp);
if ( nwrote == 0 && ferror(stdio_filerw->fp) )
{
return -1;
}
return nwrote;
}
static int stdio_tell(struct rtgui_filerw* context)
{
struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
return ftell(stdio_filerw->fp);
}
static int stdio_eof(struct rtgui_filerw* context)
{
struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
return feof(stdio_filerw->fp);
}
static int stdio_close(struct rtgui_filerw *context)
{
struct rtgui_filerw_stdio* stdio_filerw = (struct rtgui_filerw_stdio *)context;
if (stdio_filerw)
{
fclose(stdio_filerw->fp);
rtgui_free(stdio_filerw);
return 0;
}
return -1;
}
#endif #endif
/* memory file read/write */ /* memory file read/write */
@ -302,7 +215,11 @@ static int parse_mode(const char *mode)
switch (*mode) switch (*mode)
{ {
case 0: return f; case 0: return f;
case 'b': break; #ifdef _WIN32
case 'b': f|=O_BINARY;break;
#else
case 'b': break;
#endif
case 'r': f=O_RDONLY; break; case 'r': f=O_RDONLY; break;
case 'w': f=O_WRONLY|O_CREAT|O_TRUNC; break; case 'w': f=O_WRONLY|O_CREAT|O_TRUNC; break;
case 'a': f=O_WRONLY|O_CREAT|O_APPEND; break; case 'a': f=O_WRONLY|O_CREAT|O_APPEND; break;
@ -321,7 +238,11 @@ struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char*
RT_ASSERT(filename != RT_NULL); RT_ASSERT(filename != RT_NULL);
rw = RT_NULL; rw = RT_NULL;
#ifdef _WIN32
fd = _open(filename, parse_mode(mode), 0);
#else
fd = open(filename, parse_mode(mode), 0); fd = open(filename, parse_mode(mode), 0);
#endif
if ( fd >= 0 ) if ( fd >= 0 )
{ {
@ -342,35 +263,7 @@ struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char*
return &(rw->parent); return &(rw->parent);
} }
#elif defined(RTGUI_USING_STDIO_FILERW)
struct rtgui_filerw* rtgui_filerw_create_file(const char* filename, const char* mode)
{
FILE *fp;
struct rtgui_filerw_stdio *rw;
RT_ASSERT(filename != RT_NULL);
rw = RT_NULL;
fp = fopen(filename, mode);
if ( fp != NULL )
{
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->fp = fp;
}
}
return &(rw->parent);
}
#endif #endif
struct rtgui_filerw* rtgui_filerw_create_mem(const rt_uint8_t* mem, rt_size_t size) struct rtgui_filerw* rtgui_filerw_create_mem(const rt_uint8_t* mem, rt_size_t size)
@ -447,3 +340,12 @@ int rtgui_filerw_close(struct rtgui_filerw* context)
return 0; return 0;
} }
int rtgui_filerw_unlink(const char *filename)
{
#ifdef _WIN32
return _unlink(filename);
#else
return unlink(filename);
#endif
}

View File

@ -7,7 +7,19 @@
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
#ifdef RTGUI_USING_HZ_FILE #ifdef RTGUI_USING_HZ_FILE
#ifdef _WIN32
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#define open _open
#define close _close
#define read _read
#define write _write
#define unlink _unlink
#else
#include <dfs_posix.h> #include <dfs_posix.h>
#endif
#define HZ_CACHE_MAX 64 #define HZ_CACHE_MAX 64

View File

@ -81,7 +81,7 @@ static struct rtgui_image_engine* rtgui_image_get_engine(const char* type)
return RT_NULL; return RT_NULL;
} }
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW) #if defined(RTGUI_USING_DFS_FILERW)
struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn) struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn)
{ {
struct rtgui_list_node *node; struct rtgui_list_node *node;
@ -105,6 +105,7 @@ struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn)
return RT_NULL; return RT_NULL;
} }
RTM_EXPORT(rtgui_image_get_engine_by_filename);
struct rtgui_image* rtgui_image_create_from_file(const char* type, const char* filename, rt_bool_t load) struct rtgui_image* rtgui_image_create_from_file(const char* type, const char* filename, rt_bool_t load)
{ {
@ -153,6 +154,7 @@ struct rtgui_image* rtgui_image_create_from_file(const char* type, const char* f
return image; return image;
} }
RTM_EXPORT(rtgui_image_create_from_file);
struct rtgui_image* rtgui_image_create(const char* filename, rt_bool_t load) struct rtgui_image* rtgui_image_create(const char* filename, rt_bool_t load)
{ {
@ -201,6 +203,7 @@ struct rtgui_image* rtgui_image_create(const char* filename, rt_bool_t load)
return image; return image;
} }
RTM_EXPORT(rtgui_image_create);
#endif #endif
struct rtgui_image* rtgui_image_create_from_mem(const char* type, const rt_uint8_t* data, rt_size_t length, rt_bool_t load) struct rtgui_image* rtgui_image_create_from_mem(const char* type, const rt_uint8_t* data, rt_size_t length, rt_bool_t load)
@ -250,6 +253,7 @@ struct rtgui_image* rtgui_image_create_from_mem(const char* type, const rt_uint8
return image; return image;
} }
RTM_EXPORT(rtgui_image_create_from_mem);
void rtgui_image_destroy(struct rtgui_image* image) void rtgui_image_destroy(struct rtgui_image* image)
{ {
@ -260,6 +264,7 @@ void rtgui_image_destroy(struct rtgui_image* image)
rtgui_free(image->palette); rtgui_free(image->palette);
rtgui_free(image); rtgui_free(image);
} }
RTM_EXPORT(rtgui_image_destroy);
/* register an image engine */ /* register an image engine */
void rtgui_image_register_engine(struct rtgui_image_engine* engine) void rtgui_image_register_engine(struct rtgui_image_engine* engine)
@ -268,6 +273,7 @@ void rtgui_image_register_engine(struct rtgui_image_engine* engine)
rtgui_list_append(&_rtgui_system_image_list, &(engine->list)); rtgui_list_append(&_rtgui_system_image_list, &(engine->list));
} }
RTM_EXPORT(rtgui_image_register_engine);
void rtgui_image_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* rect) void rtgui_image_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* rect)
{ {
@ -282,6 +288,7 @@ void rtgui_image_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtg
image->engine->image_blit(image, dc, rect); image->engine->image_blit(image, dc, rect);
} }
} }
RTM_EXPORT(rtgui_image_blit);
struct rtgui_image_palette* rtgui_image_palette_create(rt_uint32_t ncolors) struct rtgui_image_palette* rtgui_image_palette_create(rt_uint32_t ncolors)
{ {
@ -296,6 +303,7 @@ struct rtgui_image_palette* rtgui_image_palette_create(rt_uint32_t ncolors)
return palette; return palette;
} }
RTM_EXPORT(rtgui_image_palette_create);
void rtgui_image_get_rect(struct rtgui_image* image, struct rtgui_rect* rect) void rtgui_image_get_rect(struct rtgui_image* image, struct rtgui_rect* rect)
{ {
@ -305,4 +313,5 @@ void rtgui_image_get_rect(struct rtgui_image* image, struct rtgui_rect* rect)
rect->x1 = 0; rect->y1 = 0; rect->x1 = 0; rect->y1 = 0;
rect->x2 = image->w; rect->y2 = image->h; rect->x2 = image->w; rect->y2 = image->h;
} }
RTM_EXPORT(rtgui_image_get_rect);

View File

@ -832,6 +832,178 @@ static void rtgui_image_bmp_blit(struct rtgui_image *image, struct rtgui_dc *dc,
while (0); while (0);
} }
/*
* config bitmap header.
*/
void rtgui_image_bmp_header_cfg(struct rtgui_image_bmp_header *bhr, rt_int32_t w, rt_int32_t h, rt_uint16_t bits_per_pixel)
{
int image_size = w * h * bits_per_pixel/8;
int header_size = sizeof(struct rtgui_image_bmp_header);
bhr->bfType = 0x4d42; /* BM */
bhr->bfSize = header_size + image_size; /* data size */
bhr->bfReserved1 = 0;
bhr->bfReserved2 = 0;
bhr->bfOffBits = header_size;
bhr->biSize = 40; /* sizeof BITMAPINFOHEADER */
bhr->biWidth = w;
bhr->biHeight = h;
bhr->biPlanes = 1;
bhr->biBitCount = bits_per_pixel;
bhr->biCompression = BI_BITFIELDS;
bhr->biSizeImage = image_size;
bhr->biXPelsPerMeter = 0;
bhr->biYPelsPerMeter = 0;
bhr->biClrUsed = 0;
bhr->biClrImportant = 0;
if(bhr->biBitCount == 16 && bhr->biCompression == BI_BITFIELDS)
{
bhr->bfSize += 12;
bhr->bfOffBits += 12;
}
}
#define WRITE_CLUSTER_SIZE 2048
void bmp_align_write(struct rtgui_filerw *file, char *dest, char *src, rt_int32_t len, rt_int32_t *count)
{
rt_int32_t len_bak = len;
while(len)
{
if(*count >= WRITE_CLUSTER_SIZE)
{
rtgui_filerw_write(file, dest, WRITE_CLUSTER_SIZE, 1);
*count = 0;
}
*(dest + *count) = *(src + (len_bak-len));
len --;
(*count) ++;
}
}
/*
* Grab screen and save as a BMP file
* MACRO RGB_CONVERT_TO_BGR: If the pixel of colors is BGR mode, defined it.
*/
void screenshot(const char *filename)
{
struct rtgui_filerw *file;
int w, h, i, pitch;
rt_uint16_t *src;
rt_uint32_t mask;
struct rtgui_image_bmp_header bhr;
struct rtgui_graphic_driver *grp = hw_driver;
#ifdef RGB_CONVERT_TO_BGR
int j;
rt_uint16_t *line_buf;
rt_uint16_t color, tmp;
#endif
char *pixel_buf;
rt_int32_t write_count=0;
file = rtgui_filerw_create_file(filename, "wb");
if(file == RT_NULL)
{
rt_kprintf("create file failed\n");
return;
}
w = grp->width;
h = grp->height;
pitch = w * sizeof(rt_uint16_t);
#ifdef RGB_CONVERT_TO_BGR
line_buf = rt_malloc(pitch);
if(line_buf == RT_NULL)
{
rt_kprintf("no memory!\n");
return;
}
#endif
pixel_buf = rt_malloc(WRITE_CLUSTER_SIZE);
if(pixel_buf == RT_NULL)
{
rt_kprintf("no memory!\n");
#ifdef RGB_CONVERT_TO_BGR
rt_free(line_buf);
#endif
return;
}
rtgui_image_bmp_header_cfg(&bhr, w, h, grp->bits_per_pixel);
bmp_align_write(file, pixel_buf, (char*)&bhr,
sizeof(struct rtgui_image_bmp_header), &write_count);
if(bhr.biCompression == BI_BITFIELDS)
{
mask = 0xF800; /* Red Mask */
bmp_align_write(file, pixel_buf, (char*)&mask, 4, &write_count);
mask = 0x07E0; /* Green Mask */
bmp_align_write(file, pixel_buf, (char*)&mask, 4, &write_count);
mask = 0x001F; /* Blue Mask */
bmp_align_write(file, pixel_buf, (char*)&mask, 4, &write_count);
}
rtgui_screen_lock(RT_WAITING_FOREVER);
if(grp->framebuffer != RT_NULL)
{
src = (rt_uint16_t*)grp->framebuffer;
src += w * h;
for(i=0; i<h; i++)
{
src -= w;
#ifdef RGB_CONVERT_TO_BGR
for(j=0; j<w; j++)
{
tmp = *(src + j);
color = (tmp & 0x001F)<<11;
color += (tmp & 0x07E0);
color += (tmp & 0xF800)>>11;
*(line_buf + i) = color;
}
bmp_align_write(file, pixel_buf, (char*)line_buf, pitch, &write_count);
#else
bmp_align_write(file, pixel_buf, (char*)src, pitch, &write_count);
#endif
}
}
else
{
rtgui_color_t pixel_color;
rt_uint16_t write_color;
int x;
for(i=h-1; i>=0; i--)
{
x = 0;
if(i%10==0)rt_kprintf(">",i);
while(x < w)
{
grp->ops->get_pixel(&pixel_color, x, i);
write_color = rtgui_color_to_565p(pixel_color);
bmp_align_write(file, pixel_buf, (char*)&write_color,
sizeof(rt_uint16_t), &write_count);
x++;
}
}
}
/* write The tail of the last */
if(write_count < WRITE_CLUSTER_SIZE)
rtgui_filerw_write(file, pixel_buf, write_count, 1);
rtgui_screen_unlock();
#ifdef RGB_CONVERT_TO_BGR
rt_free(line_buf);
#endif
rt_free(pixel_buf);
rt_kprintf("bmp create succeed.\n");
rtgui_filerw_close(file);
}
#ifdef RT_USING_FINSH
#include <finsh.h>
FINSH_FUNCTION_EXPORT(screenshot, usage: screenshot(filename));
#endif
void rtgui_image_bmp_init() void rtgui_image_bmp_init()
{ {
/* register bmp on image system */ /* register bmp on image system */

View File

@ -112,6 +112,7 @@ __mq_err:
tid->user_data = 0; tid->user_data = 0;
return RT_NULL; return RT_NULL;
} }
RTM_EXPORT(rtgui_app_create);
#define _rtgui_application_check(app) \ #define _rtgui_application_check(app) \
do { \ do { \
@ -152,6 +153,7 @@ void rtgui_app_destroy(struct rtgui_app *app)
rt_mq_delete(app->mq); rt_mq_delete(app->mq);
rtgui_object_destroy(RTGUI_OBJECT(app)); rtgui_object_destroy(RTGUI_OBJECT(app));
} }
RTM_EXPORT(rtgui_app_destroy);
struct rtgui_app* rtgui_app_self(void) struct rtgui_app* rtgui_app_self(void)
{ {
@ -164,6 +166,7 @@ struct rtgui_app* rtgui_app_self(void)
return app; return app;
} }
RTM_EXPORT(rtgui_app_self);
void rtgui_app_set_onidle(rtgui_idle_func_t onidle) void rtgui_app_set_onidle(rtgui_idle_func_t onidle)
{ {
@ -173,6 +176,7 @@ void rtgui_app_set_onidle(rtgui_idle_func_t onidle)
if (app != RT_NULL) if (app != RT_NULL)
app->on_idle = onidle; app->on_idle = onidle;
} }
RTM_EXPORT(rtgui_app_set_onidle);
rtgui_idle_func_t rtgui_app_get_onidle(void) rtgui_idle_func_t rtgui_app_get_onidle(void)
{ {
@ -184,6 +188,7 @@ rtgui_idle_func_t rtgui_app_get_onidle(void)
else else
return RT_NULL; return RT_NULL;
} }
RTM_EXPORT(rtgui_app_get_onidle);
rt_inline rt_bool_t _rtgui_application_dest_handle( rt_inline rt_bool_t _rtgui_application_dest_handle(
struct rtgui_app *app, struct rtgui_app *app,
@ -339,12 +344,14 @@ rt_base_t rtgui_app_run(struct rtgui_app *app)
return app->exit_code; return app->exit_code;
} }
RTM_EXPORT(rtgui_app_run);
void rtgui_app_exit(struct rtgui_app* app, rt_uint16_t code) void rtgui_app_exit(struct rtgui_app* app, rt_uint16_t code)
{ {
--app->ref_count; --app->ref_count;
app->exit_code = code; app->exit_code = code;
} }
RTM_EXPORT(rtgui_app_exit);
void rtgui_app_activate(struct rtgui_app *app) void rtgui_app_activate(struct rtgui_app *app)
{ {
@ -355,6 +362,7 @@ void rtgui_app_activate(struct rtgui_app *app)
rtgui_send(app->tid, RTGUI_EVENT(&event), sizeof(struct rtgui_event_application)); rtgui_send(app->tid, RTGUI_EVENT(&event), sizeof(struct rtgui_event_application));
} }
RTM_EXPORT(rtgui_app_activate);
void rtgui_app_close(struct rtgui_app *app) void rtgui_app_close(struct rtgui_app *app)
{ {
@ -365,6 +373,7 @@ void rtgui_app_close(struct rtgui_app *app)
rtgui_send(app->tid, RTGUI_EVENT(&event), sizeof(struct rtgui_event_application)); rtgui_send(app->tid, RTGUI_EVENT(&event), sizeof(struct rtgui_event_application));
} }
RTM_EXPORT(rtgui_app_close);
/** /**
* set this application as window manager * set this application as window manager
@ -389,6 +398,7 @@ rt_err_t rtgui_app_set_as_wm(void)
return RT_ERROR; return RT_ERROR;
} }
RTM_EXPORT(rtgui_app_set_as_wm);
void rtgui_app_set_main_win(struct rtgui_win* win) void rtgui_app_set_main_win(struct rtgui_win* win)
{ {
@ -400,3 +410,5 @@ void rtgui_app_set_main_win(struct rtgui_win* win)
app->main_object = RTGUI_OBJECT(win); app->main_object = RTGUI_OBJECT(win);
} }
} }
RTM_EXPORT(rtgui_app_set_main_win);

View File

@ -34,6 +34,7 @@ DEFINE_CLASS_TYPE(object, "object",
_rtgui_object_constructor, _rtgui_object_constructor,
_rtgui_object_destructor, _rtgui_object_destructor,
sizeof(struct rtgui_object)); sizeof(struct rtgui_object));
RTM_EXPORT(_rtgui_object);
void rtgui_type_object_construct(const rtgui_type_t *type, rtgui_object_t *object) void rtgui_type_object_construct(const rtgui_type_t *type, rtgui_object_t *object)
{ {
@ -121,6 +122,7 @@ rtgui_object_t *rtgui_object_create(rtgui_type_t *object_type)
return new_object; return new_object;
} }
RTM_EXPORT(rtgui_object_create);
/** /**
* @brief Destroys the object: it first sets the weak-pointers to RT_NULL, emits the "destroyed" signal, and then * @brief Destroys the object: it first sets the weak-pointers to RT_NULL, emits the "destroyed" signal, and then
@ -146,6 +148,7 @@ void rtgui_object_destroy(rtgui_object_t *object)
/* release object */ /* release object */
rtgui_free(object); rtgui_free(object);
} }
RTM_EXPORT(rtgui_object_destroy);
/** /**
* @brief Checks if @a object can be cast to @a type. * @brief Checks if @a object can be cast to @a type.
@ -166,6 +169,8 @@ rtgui_object_t *rtgui_object_check_cast(rtgui_object_t *obj, rtgui_type_t *obj_t
return obj; return obj;
} }
RTM_EXPORT(rtgui_object_check_cast);
/** /**
* @brief Gets the type of the object * @brief Gets the type of the object
@ -178,6 +183,7 @@ const rtgui_type_t *rtgui_object_object_type_get(rtgui_object_t *object)
return object->type; return object->type;
} }
RTM_EXPORT(rtgui_object_object_type_get);
void rtgui_object_set_event_handler(struct rtgui_object *object, rtgui_event_handler_ptr handler) void rtgui_object_set_event_handler(struct rtgui_object *object, rtgui_event_handler_ptr handler)
{ {
@ -185,9 +191,11 @@ void rtgui_object_set_event_handler(struct rtgui_object *object, rtgui_event_han
object->event_handler = handler; object->event_handler = handler;
} }
RTM_EXPORT(rtgui_object_set_event_handler);
rt_bool_t rtgui_object_event_handler(struct rtgui_object *object, struct rtgui_event* event) rt_bool_t rtgui_object_event_handler(struct rtgui_object *object, struct rtgui_event* event)
{ {
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_object_event_handler);

View File

@ -87,6 +87,7 @@ rtgui_timer_t* rtgui_timer_create(rt_int32_t time, rt_int32_t flag, rtgui_timeou
return timer; return timer;
} }
RTM_EXPORT(rtgui_timer_create);
void rtgui_timer_destory(rtgui_timer_t* timer) void rtgui_timer_destory(rtgui_timer_t* timer)
{ {
@ -100,6 +101,7 @@ void rtgui_timer_destory(rtgui_timer_t* timer)
rtgui_free(timer); rtgui_free(timer);
} }
RTM_EXPORT(rtgui_timer_destory);
void rtgui_timer_start(rtgui_timer_t* timer) void rtgui_timer_start(rtgui_timer_t* timer)
{ {
@ -108,6 +110,7 @@ void rtgui_timer_start(rtgui_timer_t* timer)
/* start rt-thread timer */ /* start rt-thread timer */
rt_timer_start(&(timer->timer)); rt_timer_start(&(timer->timer));
} }
RTM_EXPORT(rtgui_timer_start);
void rtgui_timer_stop (rtgui_timer_t* timer) void rtgui_timer_stop (rtgui_timer_t* timer)
{ {
@ -116,6 +119,7 @@ void rtgui_timer_stop (rtgui_timer_t* timer)
/* stop rt-thread timer */ /* stop rt-thread timer */
rt_timer_stop(&(timer->timer)); rt_timer_stop(&(timer->timer));
} }
RTM_EXPORT(rtgui_timer_stop);
/************************************************************************/ /************************************************************************/
/* RTGUI Memory Management */ /* RTGUI Memory Management */
@ -267,6 +271,7 @@ void* rtgui_malloc(rt_size_t size)
return ptr; return ptr;
} }
RTM_EXPORT(rtgui_malloc);
void* rtgui_realloc(void* ptr, rt_size_t size) void* rtgui_realloc(void* ptr, rt_size_t size)
{ {
@ -285,6 +290,7 @@ void* rtgui_realloc(void* ptr, rt_size_t size)
return new_ptr; return new_ptr;
} }
RTM_EXPORT(rtgui_realloc);
void rtgui_free(void* ptr) void rtgui_free(void* ptr)
{ {
@ -295,6 +301,7 @@ void rtgui_free(void* ptr)
rt_free(ptr); rt_free(ptr);
} }
RTM_EXPORT(rtgui_free);
#if defined(RTGUI_MEM_TRACE) && defined(RT_USING_FINSH) #if defined(RTGUI_MEM_TRACE) && defined(RT_USING_FINSH)
#include <finsh.h> #include <finsh.h>
@ -560,6 +567,7 @@ rt_err_t rtgui_send(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
return result; return result;
} }
RTM_EXPORT(rtgui_send);
rt_err_t rtgui_send_urgent(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size) rt_err_t rtgui_send_urgent(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
{ {
@ -583,6 +591,7 @@ rt_err_t rtgui_send_urgent(rt_thread_t tid, rtgui_event_t* event, rt_size_t even
return result; return result;
} }
RTM_EXPORT(rtgui_send_urgent);
rt_err_t rtgui_send_sync(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size) rt_err_t rtgui_send_sync(rt_thread_t tid, rtgui_event_t* event, rt_size_t event_size)
{ {
@ -631,6 +640,7 @@ __return:
rt_mb_detach(&ack_mb); rt_mb_detach(&ack_mb);
return r; return r;
} }
RTM_EXPORT(rtgui_send_sync);
rt_err_t rtgui_ack(rtgui_event_t* event, rt_int32_t status) rt_err_t rtgui_ack(rtgui_event_t* event, rt_int32_t status)
{ {
@ -641,6 +651,7 @@ rt_err_t rtgui_ack(rtgui_event_t* event, rt_int32_t status)
return RT_EOK; return RT_EOK;
} }
RTM_EXPORT(rtgui_ack);
rt_err_t rtgui_recv(rtgui_event_t* event, rt_size_t event_size) rt_err_t rtgui_recv(rtgui_event_t* event, rt_size_t event_size)
{ {
@ -658,6 +669,7 @@ rt_err_t rtgui_recv(rtgui_event_t* event, rt_size_t event_size)
return r; return r;
} }
RTM_EXPORT(rtgui_recv);
rt_err_t rtgui_recv_nosuspend(rtgui_event_t* event, rt_size_t event_size) rt_err_t rtgui_recv_nosuspend(rtgui_event_t* event, rt_size_t event_size)
{ {
@ -675,6 +687,7 @@ rt_err_t rtgui_recv_nosuspend(rtgui_event_t* event, rt_size_t event_size)
return r; return r;
} }
RTM_EXPORT(rtgui_recv_nosuspend);
rt_err_t rtgui_recv_filter(rt_uint32_t type, rtgui_event_t* event, rt_size_t event_size) rt_err_t rtgui_recv_filter(rt_uint32_t type, rtgui_event_t* event, rt_size_t event_size)
{ {
@ -704,33 +717,41 @@ rt_err_t rtgui_recv_filter(rt_uint32_t type, rtgui_event_t* event, rt_size_t eve
return -RT_ERROR; return -RT_ERROR;
} }
RTM_EXPORT(rtgui_recv_filter);
rt_thread_t rtgui_get_server(void) rt_thread_t rtgui_get_server(void)
{ {
return rt_thread_find("rtgui"); return rt_thread_find("rtgui");
} }
RTM_EXPORT(rtgui_get_server);
void rtgui_set_mainwin_rect(struct rtgui_rect *rect) void rtgui_set_mainwin_rect(struct rtgui_rect *rect)
{ {
_mainwin_rect = *rect; _mainwin_rect = *rect;
} }
RTM_EXPORT(rtgui_set_mainwin_rect);
void rtgui_get_mainwin_rect(struct rtgui_rect *rect) void rtgui_get_mainwin_rect(struct rtgui_rect *rect)
{ {
*rect = _mainwin_rect; *rect = _mainwin_rect;
} }
RTM_EXPORT(rtgui_get_mainwin_rect);
void rtgui_get_screen_rect(struct rtgui_rect *rect) void rtgui_get_screen_rect(struct rtgui_rect *rect)
{ {
rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), rect); rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), rect);
} }
RTM_EXPORT(rtgui_get_screen_rect);
void rtgui_screen_lock(rt_int32_t timeout) void rtgui_screen_lock(rt_int32_t timeout)
{ {
rt_mutex_take(&_screen_lock, timeout); rt_mutex_take(&_screen_lock, timeout);
} }
RTM_EXPORT(rtgui_screen_lock);
void rtgui_screen_unlock(void) void rtgui_screen_unlock(void)
{ {
rt_mutex_release(&_screen_lock); rt_mutex_release(&_screen_lock);
} }
RTM_EXPORT(rtgui_screen_unlock);

View File

@ -14,6 +14,16 @@
#ifndef __RTGUI_FILERW_H__ #ifndef __RTGUI_FILERW_H__
#define __RTGUI_FILERW_H__ #define __RTGUI_FILERW_H__
#ifdef _WIN32
#pragma warning(disable: 4996)
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#else
#include <dfs_posix.h>
#endif
#include <rtgui/rtgui.h> #include <rtgui/rtgui.h>
#define RTGUI_FILE_SEEK_SET 0 #define RTGUI_FILE_SEEK_SET 0
@ -40,6 +50,7 @@ int rtgui_filerw_write(struct rtgui_filerw* context, const void* buffer, rt_size
int rtgui_filerw_tell (struct rtgui_filerw* context); int rtgui_filerw_tell (struct rtgui_filerw* context);
int rtgui_filerw_eof (struct rtgui_filerw* context); int rtgui_filerw_eof (struct rtgui_filerw* context);
int rtgui_filerw_close(struct rtgui_filerw* context); int rtgui_filerw_close(struct rtgui_filerw* context);
int rtgui_filerw_unlink(const char *filename);
/* get memory data from filerw memory object */ /* get memory data from filerw memory object */
const rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context); const rt_uint8_t* rtgui_filerw_mem_getdata(struct rtgui_filerw* context);

View File

@ -59,7 +59,7 @@ typedef struct rtgui_image rtgui_image_t;
/* init rtgui image system */ /* init rtgui image system */
void rtgui_system_image_init(void); void rtgui_system_image_init(void);
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW) #if defined(RTGUI_USING_DFS_FILERW)
struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn); struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn);
struct rtgui_image* rtgui_image_create_from_file(const char* type, const char* filename, rt_bool_t load); struct rtgui_image* rtgui_image_create_from_file(const char* type, const char* filename, rt_bool_t load);
struct rtgui_image* rtgui_image_create(const char* filename, rt_bool_t load); struct rtgui_image* rtgui_image_create(const char* filename, rt_bool_t load);

View File

@ -14,6 +14,33 @@
#ifndef __RTGUI_IMAGE_BMP_H__ #ifndef __RTGUI_IMAGE_BMP_H__
#define __RTGUI_IMAGE_BMP_H__ #define __RTGUI_IMAGE_BMP_H__
#pragma pack(2)
struct rtgui_image_bmp_header
{
/* The Win32 BMP file header (14 bytes) */
rt_uint16_t bfType;
rt_uint32_t bfSize;
rt_uint16_t bfReserved1;
rt_uint16_t bfReserved2;
rt_uint32_t bfOffBits;
/* The Win32 BITMAPINFOHEADER struct (40 bytes) */
rt_uint32_t biSize;
rt_int32_t biWidth;
rt_int32_t biHeight;
rt_uint16_t biPlanes;
rt_uint16_t biBitCount;
rt_uint32_t biCompression;
rt_uint32_t biSizeImage;
rt_int32_t biXPelsPerMeter;
rt_int32_t biYPelsPerMeter;
rt_uint32_t biClrUsed;
rt_uint32_t biClrImportant;
};
#ifdef _WIN32
#pragma warning(disable : 4103)
#endif
void rtgui_image_bmp_init(void); void rtgui_image_bmp_init(void);
#endif #endif

View File

@ -35,7 +35,7 @@
#define RTGUI_DEFAULT_FONT_SIZE 12 #define RTGUI_DEFAULT_FONT_SIZE 12
#define RTGUI_USING_STDIO_FILERW #define RTGUI_USING_STDIO_FILERW
// #define RTGUI_USING_DFS_FILERW #define RTGUI_USING_DFS_FILERW
#define RTGUI_IMAGE_CONTAINER #define RTGUI_IMAGE_CONTAINER
#define RTGUI_IMAGE_XPM #define RTGUI_IMAGE_XPM
#define RTGUI_IMAGE_BMP #define RTGUI_IMAGE_BMP
@ -47,7 +47,7 @@
#define RTGUI_MEM_TRACE #define RTGUI_MEM_TRACE
#define RTGUI_USING_WINMOVE #define RTGUI_USING_WINMOVE
#define RTGUI_USING_NOTEBOOK_IMAGE #define RTGUI_USING_NOTEBOOK_IMAGE
// #define RTGUI_USING_HZ_FILE
#else #else
/* native running under RT-Thread */ /* native running under RT-Thread */
#ifndef RT_USING_DFS #ifndef RT_USING_DFS

View File

@ -50,8 +50,13 @@ void* rtgui_malloc(rt_size_t size);
void rtgui_free(void* ptr); void rtgui_free(void* ptr);
void* rtgui_realloc(void* ptr, rt_size_t size); void* rtgui_realloc(void* ptr, rt_size_t size);
#ifdef _WIN32
#define rtgui_enter_critical()
#define rtgui_exit_critical()
#else
#define rtgui_enter_critical rt_enter_critical #define rtgui_enter_critical rt_enter_critical
#define rtgui_exit_critical rt_exit_critical #define rtgui_exit_critical rt_exit_critical
#endif
rt_thread_t rtgui_get_server(void); rt_thread_t rtgui_get_server(void);
void rtgui_set_mainwin_rect(struct rtgui_rect *rect); void rtgui_set_mainwin_rect(struct rtgui_rect *rect);

View File

@ -17,27 +17,10 @@
#include <rtgui/widgets/widget.h> #include <rtgui/widgets/widget.h>
#include <rtgui/widgets/container.h> #include <rtgui/widgets/container.h>
#ifdef _WIN32
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#else
#include <dfs_posix.h>
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#ifdef _WIN32
#define open _open
#define close _close
#define read _read
#define write _write
#define unlink _unlink
#endif
DECLARE_CLASS_TYPE(edit); DECLARE_CLASS_TYPE(edit);
/** Gets the type of a edit */ /** Gets the type of a edit */
@ -65,11 +48,11 @@ struct edit_update
struct edit_line struct edit_line
{ {
rt_size_t zsize; /* zone size */ rt_int16_t zsize; /* zone size */
rt_uint32_t len; rt_int16_t len;
struct edit_line *prev; struct edit_line *prev;
struct edit_line *next; struct edit_line *next;
char *text; char *text;
}; };
struct rtgui_edit struct rtgui_edit
@ -79,21 +62,22 @@ struct rtgui_edit
/* edit flag */ /* edit flag */
rt_uint32_t flag; rt_uint32_t flag;
rt_uint32_t max_rows, max_cols; rt_int16_t max_rows, max_cols;
rt_uint16_t row_per_page, col_per_page; rt_int16_t row_per_page, col_per_page;
rtgui_point_t upleft; rtgui_point_t upleft;
rtgui_point_t visual; rtgui_point_t visual;
rt_uint8_t tabsize; rt_uint8_t tabsize;
rt_uint8_t item_height; rt_uint8_t item_height;
rt_uint8_t font_width,font_height; rt_uint8_t font_width,font_height;
rt_uint8_t margin; rt_uint8_t margin;
rt_size_t bzsize; /* base zone size */ rt_int16_t bzsize; /* base zone size */
struct rtgui_timer *caret_timer; struct rtgui_timer *caret_timer;
rtgui_color_t *caret; rtgui_color_t *caret;
rtgui_rect_t caret_rect; rtgui_rect_t caret_rect;
struct edit_update update; struct edit_update update;
char *update_buf; /* speed up renewal process */ char *update_buf; /* speed up renewal process */
struct rtgui_dc *dbl_buf;
struct edit_line *head; struct edit_line *head;
struct edit_line *tail; struct edit_line *tail;
@ -118,7 +102,8 @@ void rtgui_edit_update(struct rtgui_edit *edit);
void rtgui_edit_ondraw(struct rtgui_edit *edit); void rtgui_edit_ondraw(struct rtgui_edit *edit);
rt_bool_t rtgui_edit_event_handler(struct rtgui_object* object, rtgui_event_t* event); rt_bool_t rtgui_edit_event_handler(struct rtgui_object* object, rtgui_event_t* event);
void rtgui_edit_set_text(struct rtgui_edit *edit, const char* text); void rtgui_edit_set_text(struct rtgui_edit *edit, const char* text);
rtgui_point_t rtgui_edit_get_current_point(struct rtgui_edit *edit);
rt_uint32_t rtgui_edit_get_mem_consume(struct rtgui_edit *edit);
rt_bool_t rtgui_edit_readin_file(struct rtgui_edit *edit, const char *filename); rt_bool_t rtgui_edit_readin_file(struct rtgui_edit *edit, const char *filename);
rt_bool_t rtgui_edit_saveas_file(struct rtgui_edit *edit, const char *filename); rt_bool_t rtgui_edit_saveas_file(struct rtgui_edit *edit, const char *filename);

View File

@ -3,7 +3,7 @@
#include <rtgui/widgets/container.h> #include <rtgui/widgets/container.h>
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW) #if defined(RTGUI_USING_DFS_FILERW)
#define RTGUI_FITEM_FILE 0x0 #define RTGUI_FITEM_FILE 0x0
#define RTGUI_FITEM_DIR 0x1 #define RTGUI_FITEM_DIR 0x1
struct rtgui_file_item struct rtgui_file_item

View File

@ -24,6 +24,7 @@ struct rtgui_graphic_driver* rtgui_graphic_driver_get_default()
{ {
return &_driver; return &_driver;
} }
RTM_EXPORT(rtgui_graphic_driver_get_default);
void rtgui_graphic_driver_get_rect(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect) void rtgui_graphic_driver_get_rect(const struct rtgui_graphic_driver *driver, rtgui_rect_t *rect)
{ {
@ -34,6 +35,7 @@ void rtgui_graphic_driver_get_rect(const struct rtgui_graphic_driver *driver, rt
rect->x2 = driver->width; rect->x2 = driver->width;
rect->y2 = driver->height; rect->y2 = driver->height;
} }
RTM_EXPORT(rtgui_graphic_driver_get_rect);
rt_err_t rtgui_graphic_set_device(rt_device_t device) rt_err_t rtgui_graphic_set_device(rt_device_t device)
{ {
@ -70,6 +72,7 @@ rt_err_t rtgui_graphic_set_device(rt_device_t device)
return RT_EOK; return RT_EOK;
} }
RTM_EXPORT(rtgui_graphic_set_device);
/* screen update */ /* screen update */
void rtgui_graphic_driver_screen_update(const struct rtgui_graphic_driver* driver, rtgui_rect_t *rect) void rtgui_graphic_driver_screen_update(const struct rtgui_graphic_driver* driver, rtgui_rect_t *rect)
@ -81,14 +84,18 @@ void rtgui_graphic_driver_screen_update(const struct rtgui_graphic_driver* drive
rect_info.height = rect->y2 - rect->y1; rect_info.height = rect->y2 - rect->y1;
rt_device_control(driver->device, RTGRAPHIC_CTRL_RECT_UPDATE, &rect_info); rt_device_control(driver->device, RTGRAPHIC_CTRL_RECT_UPDATE, &rect_info);
} }
RTM_EXPORT(rtgui_graphic_driver_screen_update);
/* get video frame buffer */ /* get video frame buffer */
rt_uint8_t* rtgui_graphic_driver_get_framebuffer(const struct rtgui_graphic_driver* driver) rt_uint8_t* rtgui_graphic_driver_get_framebuffer(const struct rtgui_graphic_driver* driver)
{ {
return (rt_uint8_t*)driver->framebuffer; return (rt_uint8_t*)driver->framebuffer;
} }
RTM_EXPORT(rtgui_graphic_driver_get_framebuffer);
rt_uint8_t* rtgui_graphic_driver_get_default_framebuffer(void) rt_uint8_t* rtgui_graphic_driver_get_default_framebuffer(void)
{ {
return rtgui_graphic_driver_get_framebuffer(&_driver); return rtgui_graphic_driver_get_framebuffer(&_driver);
} }
RTM_EXPORT(rtgui_graphic_driver_get_default_framebuffer);

View File

@ -44,11 +44,13 @@ struct rtgui_box* rtgui_box_create(int orientation, int border_size)
return box; return box;
} }
RTM_EXPORT(rtgui_box_create);
void rtgui_box_destroy(struct rtgui_box* box) void rtgui_box_destroy(struct rtgui_box* box)
{ {
rtgui_object_destroy(RTGUI_OBJECT(box)); rtgui_object_destroy(RTGUI_OBJECT(box));
} }
RTM_EXPORT(rtgui_box_destroy);
static void rtgui_box_layout_vertical(struct rtgui_box* box, struct rtgui_rect* extent) static void rtgui_box_layout_vertical(struct rtgui_box* box, struct rtgui_rect* extent)
{ {
@ -259,6 +261,7 @@ void rtgui_box_layout(rtgui_box_t* box)
rtgui_widget_update_clip(RTGUI_WIDGET(box->container)); rtgui_widget_update_clip(RTGUI_WIDGET(box->container));
} }
} }
RTM_EXPORT(rtgui_box_layout);
void rtgui_box_layout_rect(rtgui_box_t* box, struct rtgui_rect* rect) void rtgui_box_layout_rect(rtgui_box_t* box, struct rtgui_rect* rect)
{ {
@ -281,3 +284,5 @@ void rtgui_box_layout_rect(rtgui_box_t* box, struct rtgui_rect* rect)
rtgui_widget_update_clip(RTGUI_WIDGET(box->container)); rtgui_widget_update_clip(RTGUI_WIDGET(box->container));
} }
} }
RTM_EXPORT(rtgui_box_layout_rect);

View File

@ -195,6 +195,7 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_object* object, struct rtgui_e
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_button_event_handler);
rtgui_button_t* rtgui_button_create(const char* text) rtgui_button_t* rtgui_button_create(const char* text)
{ {
@ -215,6 +216,7 @@ rtgui_button_t* rtgui_button_create(const char* text)
return btn; return btn;
} }
RTM_EXPORT(rtgui_button_create);
rtgui_button_t* rtgui_pushbutton_create(const char* text) rtgui_button_t* rtgui_pushbutton_create(const char* text)
{ {
@ -225,11 +227,13 @@ rtgui_button_t* rtgui_pushbutton_create(const char* text)
return btn; return btn;
} }
RTM_EXPORT(rtgui_pushbutton_create);
void rtgui_button_destroy(rtgui_button_t* btn) void rtgui_button_destroy(rtgui_button_t* btn)
{ {
rtgui_widget_destroy(RTGUI_WIDGET(btn)); rtgui_widget_destroy(RTGUI_WIDGET(btn));
} }
RTM_EXPORT(rtgui_button_destroy);
void rtgui_button_set_pressed_image(rtgui_button_t* btn, rtgui_image_t* image) void rtgui_button_set_pressed_image(rtgui_button_t* btn, rtgui_image_t* image)
{ {
@ -237,6 +241,7 @@ void rtgui_button_set_pressed_image(rtgui_button_t* btn, rtgui_image_t* image)
btn->pressed_image = image; btn->pressed_image = image;
} }
RTM_EXPORT(rtgui_button_set_pressed_image);
void rtgui_button_set_unpressed_image(rtgui_button_t* btn, rtgui_image_t* image) void rtgui_button_set_unpressed_image(rtgui_button_t* btn, rtgui_image_t* image)
{ {
@ -244,6 +249,7 @@ void rtgui_button_set_unpressed_image(rtgui_button_t* btn, rtgui_image_t* image)
btn->unpressed_image = image; btn->unpressed_image = image;
} }
RTM_EXPORT(rtgui_button_set_unpressed_image);
void rtgui_button_set_onbutton(rtgui_button_t* btn, rtgui_onbutton_func_t func) void rtgui_button_set_onbutton(rtgui_button_t* btn, rtgui_onbutton_func_t func)
{ {
@ -251,4 +257,5 @@ void rtgui_button_set_onbutton(rtgui_button_t* btn, rtgui_onbutton_func_t func)
btn->on_button = func; btn->on_button = func;
} }
RTM_EXPORT(rtgui_button_set_onbutton);

View File

@ -43,6 +43,7 @@ DEFINE_CLASS_TYPE(container, "container",
_rtgui_container_constructor, _rtgui_container_constructor,
_rtgui_container_destructor, _rtgui_container_destructor,
sizeof(struct rtgui_container)); sizeof(struct rtgui_container));
RTM_EXPORT(_rtgui_container);
rt_bool_t rtgui_container_dispatch_event(rtgui_container_t *container, rtgui_event_t* event) rt_bool_t rtgui_container_dispatch_event(rtgui_container_t *container, rtgui_event_t* event)
{ {
@ -61,6 +62,7 @@ rt_bool_t rtgui_container_dispatch_event(rtgui_container_t *container, rtgui_eve
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_container_dispatch_event);
/* broadcast means that the return value of event handlers will be ignored. The /* broadcast means that the return value of event handlers will be ignored. The
* events will always reach every child.*/ * events will always reach every child.*/
@ -79,6 +81,7 @@ rt_bool_t rtgui_container_broadcast_event(struct rtgui_container *container, str
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_container_broadcast_event);
rt_bool_t rtgui_container_dispatch_mouse_event(rtgui_container_t *container, struct rtgui_event_mouse* event) rt_bool_t rtgui_container_dispatch_mouse_event(rtgui_container_t *container, struct rtgui_event_mouse* event)
{ {
@ -106,6 +109,7 @@ rt_bool_t rtgui_container_dispatch_mouse_event(rtgui_container_t *container, str
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_container_dispatch_mouse_event);
rt_bool_t rtgui_container_event_handler(struct rtgui_object* object, struct rtgui_event* event) rt_bool_t rtgui_container_event_handler(struct rtgui_object* object, struct rtgui_event* event)
{ {
@ -176,6 +180,7 @@ rt_bool_t rtgui_container_event_handler(struct rtgui_object* object, struct rtgu
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_container_event_handler);
rtgui_container_t* rtgui_container_create(void) rtgui_container_t* rtgui_container_create(void)
{ {
@ -185,11 +190,13 @@ rtgui_container_t* rtgui_container_create(void)
container = (struct rtgui_container*) rtgui_widget_create (RTGUI_CONTAINER_TYPE); container = (struct rtgui_container*) rtgui_widget_create (RTGUI_CONTAINER_TYPE);
return container; return container;
} }
RTM_EXPORT(rtgui_container_create);
void rtgui_container_destroy(rtgui_container_t* container) void rtgui_container_destroy(rtgui_container_t* container)
{ {
rtgui_widget_destroy(RTGUI_WIDGET(container)); rtgui_widget_destroy(RTGUI_WIDGET(container));
} }
RTM_EXPORT(rtgui_container_destroy);
/* /*
* This function will add a child to a container widget * This function will add a child to a container widget
@ -216,6 +223,7 @@ void rtgui_container_add_child(rtgui_container_t *container, rtgui_widget_t* chi
rtgui_container_broadcast_event(container, (struct rtgui_event*)&eup); rtgui_container_broadcast_event(container, (struct rtgui_event*)&eup);
} }
} }
RTM_EXPORT(rtgui_container_add_child);
/* remove a child to widget */ /* remove a child to widget */
void rtgui_container_remove_child(rtgui_container_t *container, rtgui_widget_t* child) void rtgui_container_remove_child(rtgui_container_t *container, rtgui_widget_t* child)
@ -232,6 +240,7 @@ void rtgui_container_remove_child(rtgui_container_t *container, rtgui_widget_t*
child->parent = RT_NULL; child->parent = RT_NULL;
child->toplevel = RT_NULL; child->toplevel = RT_NULL;
} }
RTM_EXPORT(rtgui_container_remove_child);
/* destroy all children of container */ /* destroy all children of container */
void rtgui_container_destroy_children(rtgui_container_t *container) void rtgui_container_destroy_children(rtgui_container_t *container)
@ -272,6 +281,7 @@ void rtgui_container_destroy_children(rtgui_container_t *container)
/* update widget clip */ /* update widget clip */
rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(RTGUI_WIDGET(container)->toplevel)); rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(RTGUI_WIDGET(container)->toplevel));
} }
RTM_EXPORT(rtgui_container_destroy_children);
rtgui_widget_t* rtgui_container_get_first_child(rtgui_container_t* container) rtgui_widget_t* rtgui_container_get_first_child(rtgui_container_t* container)
{ {
@ -286,6 +296,7 @@ rtgui_widget_t* rtgui_container_get_first_child(rtgui_container_t* container)
return child; return child;
} }
RTM_EXPORT(rtgui_container_get_first_child);
void rtgui_container_set_box(rtgui_container_t* container, struct rtgui_box* box) void rtgui_container_set_box(rtgui_container_t* container, struct rtgui_box* box)
{ {
@ -295,6 +306,7 @@ void rtgui_container_set_box(rtgui_container_t* container, struct rtgui_box* box
container->layout_box = box; container->layout_box = box;
box->container = container; box->container = container;
} }
RTM_EXPORT(rtgui_container_set_box);
void rtgui_container_layout(struct rtgui_container* container) void rtgui_container_layout(struct rtgui_container* container)
{ {
@ -303,4 +315,5 @@ void rtgui_container_layout(struct rtgui_container* container)
rtgui_box_layout(container->layout_box); rtgui_box_layout(container->layout_box);
} }
RTM_EXPORT(rtgui_container_layout);

View File

@ -16,13 +16,17 @@
#include <rtgui/widgets/edit.h> #include <rtgui/widgets/edit.h>
#include <rtgui/widgets/scrollbar.h> #include <rtgui/widgets/scrollbar.h>
#include <rtgui/rtgui_system.h> #include <rtgui/rtgui_system.h>
#include <rtgui/filerw.h>
extern int isprint(unsigned char ch); /* Quote from shell.c */
static void rtgui_edit_draw_caret(struct rtgui_edit *edit); static void rtgui_edit_draw_caret(struct rtgui_edit *edit);
static void rtgui_edit_timeout(struct rtgui_timer* timer, void* parameter); static void rtgui_edit_timeout(struct rtgui_timer* timer, void* parameter);
static rt_bool_t rtgui_edit_onfocus(struct rtgui_object* object, rtgui_event_t* event); static rt_bool_t rtgui_edit_onfocus(struct rtgui_object* object, rtgui_event_t* event);
static rt_bool_t rtgui_edit_onunfocus(struct rtgui_object* object, rtgui_event_t* event); static rt_bool_t rtgui_edit_onunfocus(struct rtgui_object* object, rtgui_event_t* event);
#ifdef RTGUI_EDIT_USING_SCROLL
static rt_bool_t rtgui_edit_hscroll_handle(struct rtgui_widget* widget, rtgui_event_t* event); static rt_bool_t rtgui_edit_hscroll_handle(struct rtgui_widget* widget, rtgui_event_t* event);
static rt_bool_t rtgui_edit_vscroll_handle(struct rtgui_widget* widget, rtgui_event_t* event); static rt_bool_t rtgui_edit_vscroll_handle(struct rtgui_widget* widget, rtgui_event_t* event);
#endif
void _rtgui_edit_constructor(struct rtgui_edit *edit) void _rtgui_edit_constructor(struct rtgui_edit *edit)
{ {
@ -61,6 +65,8 @@ void _rtgui_edit_constructor(struct rtgui_edit *edit)
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(edit), "H", &font_rect); rtgui_font_get_metrics(RTGUI_WIDGET_FONT(edit), "H", &font_rect);
edit->font_width = rtgui_rect_width(font_rect); edit->font_width = rtgui_rect_width(font_rect);
edit->font_height = rtgui_rect_height(font_rect); edit->font_height = rtgui_rect_height(font_rect);
edit->dbl_buf = rtgui_dc_buffer_create(edit->font_width*2+1, edit->font_height+1);
edit->head = RT_NULL; edit->head = RT_NULL;
edit->tail = RT_NULL; edit->tail = RT_NULL;
@ -88,6 +94,8 @@ void _rtgui_edit_deconstructor(struct rtgui_edit *edit)
edit->caret = RT_NULL; edit->caret = RT_NULL;
if(edit->update_buf != RT_NULL) if(edit->update_buf != RT_NULL)
rtgui_free(edit->update_buf); rtgui_free(edit->update_buf);
rtgui_dc_destory(edit->dbl_buf);
} }
DEFINE_CLASS_TYPE(edit, "edit", DEFINE_CLASS_TYPE(edit, "edit",
@ -156,6 +164,7 @@ void rtgui_edit_adjust_scroll(rtgui_scrollbar_t *bar)
rtgui_widget_set_rect(bar,&rect); rtgui_widget_set_rect(bar,&rect);
} }
} }
RTM_EXPORT(rtgui_edit_adjust_scroll);
#endif #endif
struct rtgui_edit* rtgui_edit_create(struct rtgui_container* container, int left, int top, int w, int h) struct rtgui_edit* rtgui_edit_create(struct rtgui_container* container, int left, int top, int w, int h)
@ -233,11 +242,13 @@ struct rtgui_edit* rtgui_edit_create(struct rtgui_container* container, int left
return edit; return edit;
} }
RTM_EXPORT(rtgui_edit_create);
void rtgui_edit_destroy(struct rtgui_edit* edit) void rtgui_edit_destroy(struct rtgui_edit* edit)
{ {
rtgui_widget_destroy(RTGUI_WIDGET(edit)); rtgui_widget_destroy(RTGUI_WIDGET(edit));
} }
RTM_EXPORT(rtgui_edit_destroy);
/** /**
* calc line buffer alloc length * calc line buffer alloc length
@ -247,7 +258,7 @@ void rtgui_edit_destroy(struct rtgui_edit* edit)
* *
* @return get a proper standard values * @return get a proper standard values
*/ */
rt_inline rt_size_t rtgui_edit_alloc_len(rt_size_t n, rt_size_t m) rt_inline rt_int16_t rtgui_edit_alloc_len(rt_int16_t n, rt_int16_t m)
{ {
if(n > m) return n; if(n > m) return n;
#ifndef RTGUI_USING_SMALL_SIZE #ifndef RTGUI_USING_SMALL_SIZE
@ -261,7 +272,7 @@ rt_inline rt_size_t rtgui_edit_alloc_len(rt_size_t n, rt_size_t m)
* please use it to replace rt_strlen * please use it to replace rt_strlen
* especially in reading the source file. * especially in reading the source file.
*/ */
rt_inline rt_size_t rtgui_edit_line_strlen(const char *s) rt_inline rt_int16_t rtgui_edit_line_strlen(const char *s)
{ {
const char *sc; const char *sc;
/* ascii text end of 0x0A or 0x0D-0x0A*/ /* ascii text end of 0x0A or 0x0D-0x0A*/
@ -271,7 +282,7 @@ rt_inline rt_size_t rtgui_edit_line_strlen(const char *s)
rt_bool_t rtgui_edit_append_line(struct rtgui_edit* edit, const char *text) rt_bool_t rtgui_edit_append_line(struct rtgui_edit* edit, const char *text)
{ {
rt_size_t len; rt_int16_t len;
struct edit_line *line, *node; struct edit_line *line, *node;
RT_ASSERT(edit != RT_NULL); RT_ASSERT(edit != RT_NULL);
@ -296,6 +307,7 @@ rt_bool_t rtgui_edit_append_line(struct rtgui_edit* edit, const char *text)
edit->head = line; edit->head = line;
edit->tail = line; edit->tail = line;
line->prev = RT_NULL; line->prev = RT_NULL;
edit->first_line = line;
return RT_TRUE; return RT_TRUE;
} }
while(node->next != RT_NULL) node = node->next; while(node->next != RT_NULL) node = node->next;
@ -307,10 +319,11 @@ rt_bool_t rtgui_edit_append_line(struct rtgui_edit* edit, const char *text)
return RT_TRUE; return RT_TRUE;
} }
RTM_EXPORT(rtgui_edit_append_line);
rt_bool_t rtgui_edit_insert_line(struct rtgui_edit *edit, struct edit_line *p, char *text) rt_bool_t rtgui_edit_insert_line(struct rtgui_edit *edit, struct edit_line *p, char *text)
{ {
rt_size_t len; rt_int16_t len;
struct edit_line *line; struct edit_line *line;
RT_ASSERT(edit != RT_NULL); RT_ASSERT(edit != RT_NULL);
@ -346,6 +359,7 @@ rt_bool_t rtgui_edit_insert_line(struct rtgui_edit *edit, struct edit_line *p, c
return RT_TRUE; return RT_TRUE;
} }
RTM_EXPORT(rtgui_edit_insert_line);
rt_bool_t rtgui_edit_delete_line(struct rtgui_edit* edit, struct edit_line *line) rt_bool_t rtgui_edit_delete_line(struct rtgui_edit* edit, struct edit_line *line)
{ {
@ -396,10 +410,11 @@ rt_bool_t rtgui_edit_delete_line(struct rtgui_edit* edit, struct edit_line *line
return RT_TRUE; return RT_TRUE;
} }
RTM_EXPORT(rtgui_edit_delete_line);
rt_bool_t rtgui_edit_connect_line(struct rtgui_edit* edit, struct edit_line *line, struct edit_line *connect) rt_bool_t rtgui_edit_connect_line(struct rtgui_edit* edit, struct edit_line *line, struct edit_line *connect)
{ {
rt_size_t len1,len2; rt_int16_t len1,len2;
RT_ASSERT(edit != RT_NULL); RT_ASSERT(edit != RT_NULL);
RT_ASSERT(line != RT_NULL); RT_ASSERT(line != RT_NULL);
@ -416,6 +431,7 @@ rt_bool_t rtgui_edit_connect_line(struct rtgui_edit* edit, struct edit_line *lin
line->len = rtgui_edit_line_strlen(line->text); line->len = rtgui_edit_line_strlen(line->text);
return RT_TRUE; return RT_TRUE;
} }
RTM_EXPORT(rtgui_edit_connect_line);
static void rtgui_edit_get_caret_rect(struct rtgui_edit *edit, rtgui_rect_t *rect, rtgui_point_t visual) static void rtgui_edit_get_caret_rect(struct rtgui_edit *edit, rtgui_rect_t *rect, rtgui_point_t visual)
{ {
@ -536,6 +552,7 @@ struct edit_line* rtgui_edit_get_line_by_index(struct rtgui_edit *edit, rt_uint3
} }
return line; return line;
} }
RTM_EXPORT(rtgui_edit_get_line_by_index);
rt_uint32_t rtgui_edit_get_index_by_line(struct rtgui_edit *edit, struct edit_line *line) rt_uint32_t rtgui_edit_get_index_by_line(struct rtgui_edit *edit, struct edit_line *line)
{ {
@ -559,6 +576,71 @@ rt_uint32_t rtgui_edit_get_index_by_line(struct rtgui_edit *edit, struct edit_li
} }
return index; return index;
} }
RTM_EXPORT(rtgui_edit_get_index_by_line);
enum {
EDIT_IDENT_DIR_BOTH,
EDIT_IDENT_DIR_LEFT,
EDIT_IDENT_DIR_RIGHT
};
/*
* identify a byte is double byte
* @param dir set direction.
* @param *p record the position of the effective.
* @return RT_TRUE is Got it, else not found.
*/
static rt_bool_t identify_double_byte(struct rtgui_edit *edit, struct edit_line *line,
rt_uint32_t dir, rt_int16_t *p)
{
int index, effe_nums;
RT_ASSERT(edit != RT_NULL);
RT_ASSERT(line != RT_NULL);
if(dir == EDIT_IDENT_DIR_BOTH)
{
}
else if(dir == EDIT_IDENT_DIR_LEFT)
{
if(edit->upleft.x == 0 && edit->visual.x == 0)
return RT_FALSE;
index = edit->upleft.x + edit->visual.x;
effe_nums = 0;
while(index--)
{
if(*(line->text + index) >= 0x80)
effe_nums ++;
else
break;
}
if(effe_nums > 0)
{
*p = 2-effe_nums%2;
return RT_TRUE;
}
}
else if(dir == EDIT_IDENT_DIR_RIGHT)
{
if(edit->upleft.x + edit->visual.x == line->len)
return RT_FALSE;
index = edit->upleft.x + edit->visual.x;
effe_nums = 0;
while(index < line->len)
{
if(*(line->text + index) >= 0x80)
effe_nums ++;
else
break;
index ++;
}
if(effe_nums > 0)
{
*p = 2-effe_nums%2;
return RT_TRUE;
}
}
return RT_FALSE;
}
static void rtgui_edit_onmouse(struct rtgui_edit* edit, struct rtgui_event_mouse* emouse) static void rtgui_edit_onmouse(struct rtgui_edit* edit, struct rtgui_event_mouse* emouse)
{ {
@ -580,6 +662,7 @@ static void rtgui_edit_onmouse(struct rtgui_edit* edit, struct rtgui_event_mouse
if(emouse->button & RTGUI_MOUSE_BUTTON_DOWN) if(emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
{ {
struct edit_line *line; struct edit_line *line;
rt_int16_t tmp_pos=0;
edit->visual.x = x; edit->visual.x = x;
edit->visual.y = y; edit->visual.y = y;
@ -590,7 +673,16 @@ static void rtgui_edit_onmouse(struct rtgui_edit* edit, struct rtgui_event_mouse
if(edit->visual.x > line->len) if(edit->visual.x > line->len)
edit->visual.x = line->len; edit->visual.x = line->len;
if(edit->upleft.x > 0)
{
if(edit->upleft.x >= line->len)
edit->upleft.x = 0;
else
edit->visual.x -= edit->upleft.x;
rtgui_edit_ondraw(edit);
}
if(identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
edit->visual.x -= (2-tmp_pos);
if(edit->flag & RTGUI_EDIT_CARET) if(edit->flag & RTGUI_EDIT_CARET)
{ {
if(edit->caret_timer != RT_NULL) if(edit->caret_timer != RT_NULL)
@ -820,9 +912,11 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
else else
{ {
char *c; char *c;
rt_int16_t tmp_pos=1;
identify_double_byte(edit, line, EDIT_IDENT_DIR_RIGHT, &tmp_pos);
/* remove character */ /* remove character */
for(c = &line->text[ofs]; c[1] != '\0'; c++) for(c = &line->text[ofs]; c[tmp_pos] != '\0'; c++)
*c = c[1]; *c = c[tmp_pos];
*c = '\0'; *c = '\0';
} }
update_type = EDIT_UPDATE; update_type = EDIT_UPDATE;
@ -873,19 +967,23 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
/* delete front character */ /* delete front character */
if(edit->visual.x == line->len) if(edit->visual.x == line->len)
{ {
line->text[edit->visual.x-1] = '\0'; rt_int16_t tmp_pos=1;
edit->visual.x --; identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
line->text[edit->visual.x-tmp_pos] = '\0';
edit->visual.x -= tmp_pos;
} }
else if(edit->visual.x != 0) else if(edit->visual.x != 0)
{ /* remove current character */ { /* remove current character */
char *c; char *c;
rt_int16_t tmp_pos=1;
identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
/* remove character */ /* remove character */
for(c = &line->text[edit->visual.x - 1]; c[1] != '\0'; c++) for(c = &line->text[edit->visual.x - tmp_pos]; c[tmp_pos] != '\0'; c++)
{ {
*c = c[1]; *c = c[tmp_pos];
} }
*c = '\0'; *c = '\0';
edit->visual.x --; edit->visual.x -= tmp_pos;
} }
/* adjusted line buffer length */ /* adjusted line buffer length */
if(rtgui_edit_alloc_len(edit->bzsize, line->len+2) < line->zsize) if(rtgui_edit_alloc_len(edit->bzsize, line->len+2) < line->zsize)
@ -924,15 +1022,38 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
{ {
if(prev_line->len <= edit->upleft.x) if(prev_line->len <= edit->upleft.x)
{ {
edit->upleft.x = 0; if(prev_line->len <= edit->col_per_page)
edit->visual.x = prev_line->len; {
edit->upleft.x = 0;
edit->visual.x = prev_line->len;
}
else
{
edit->upleft.x = prev_line->len - (edit->col_per_page-1);
edit->visual.x = edit->col_per_page-1;
}
update_type = EDIT_ONDRAW; update_type = EDIT_ONDRAW;
} }
else if(prev_line->len - edit->upleft.x < edit->col_per_page) else if(prev_line->len - edit->upleft.x < edit->col_per_page)
edit->visual.x = prev_line->len - edit->upleft.x; {
if(edit->visual.x > prev_line->len - edit->upleft.x)
edit->visual.x = prev_line->len - edit->upleft.x;
else
{
rt_int16_t tmp_pos=0;
if(identify_double_byte(edit, prev_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
edit->visual.x -= (2-tmp_pos);
}
}
} }
else if(edit->visual.x > prev_line->len) else if(edit->visual.x > prev_line->len)
edit->visual.x = prev_line->len; edit->visual.x = prev_line->len;
else if(prev_line->len >= 2)
{
rt_int16_t tmp_pos=0;
if(identify_double_byte(edit, prev_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
edit->visual.x -= (2-tmp_pos);
}
#ifdef RTGUI_EDIT_USING_SCROLL #ifdef RTGUI_EDIT_USING_SCROLL
/* update vscroll */ /* update vscroll */
@ -974,15 +1095,38 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
{ {
if(next_line->len <= edit->upleft.x) if(next_line->len <= edit->upleft.x)
{ {
edit->upleft.x = 0; if(next_line->len <= edit->col_per_page)
edit->visual.x = next_line->len; {
edit->upleft.x = 0;
edit->visual.x = next_line->len;
}
else
{
edit->upleft.x = next_line->len - (edit->col_per_page-1);
edit->visual.x = edit->col_per_page-1;
}
update_type = EDIT_ONDRAW; update_type = EDIT_ONDRAW;
} }
else if(next_line->len - edit->upleft.x < edit->col_per_page) else if(next_line->len - edit->upleft.x < edit->col_per_page)
edit->visual.x = next_line->len - edit->upleft.x; {
if(edit->visual.x > next_line->len - edit->upleft.x)
edit->visual.x = next_line->len - edit->upleft.x;
else
{
rt_int16_t tmp_pos=0;
if(identify_double_byte(edit, next_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
edit->visual.x -= (2-tmp_pos);
}
}
} }
else if(edit->visual.x > next_line->len) else if(edit->visual.x > next_line->len)
edit->visual.x = next_line->len; edit->visual.x = next_line->len;
else if(next_line->len >= 2)
{
rt_int16_t tmp_pos=0;
if(identify_double_byte(edit, next_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
edit->visual.x -= (2-tmp_pos);
}
#ifdef RTGUI_EDIT_USING_SCROLL #ifdef RTGUI_EDIT_USING_SCROLL
/* update vscroll */ /* update vscroll */
@ -996,12 +1140,24 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
else if(ekbd->key == RTGUIK_LEFT) else if(ekbd->key == RTGUIK_LEFT)
{ /* move to prev char */ { /* move to prev char */
if(edit->visual.x > 0) if(edit->visual.x > 0)
edit->visual.x --; {
rt_int16_t tmp_pos=1;
identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
edit->visual.x -= tmp_pos;
if(edit->visual.x == -1)
{
edit->visual.x = 0;
edit->upleft.x --;
update_type = EDIT_ONDRAW;
}
}
else else
{ {
if(edit->upleft.x > 0) if(edit->upleft.x > 0)
{ {
edit->upleft.x --; rt_int16_t tmp_pos=1;
identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
edit->upleft.x -= tmp_pos;
update_type = EDIT_ONDRAW; update_type = EDIT_ONDRAW;
} }
else else
@ -1028,7 +1184,11 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
if(edit->upleft.x+edit->col_per_page <= line->len) if(edit->upleft.x+edit->col_per_page <= line->len)
{ {
if(edit->visual.x < edit->col_per_page-1) if(edit->visual.x < edit->col_per_page-1)
edit->visual.x ++; {
rt_int16_t tmp_pos=1;
identify_double_byte(edit, line, EDIT_IDENT_DIR_RIGHT, &tmp_pos);
edit->visual.x += tmp_pos;
}
else if(edit->visual.x == edit->col_per_page-1) else if(edit->visual.x == edit->col_per_page-1)
{ {
if(edit->upleft.x+edit->col_per_page < line->len) if(edit->upleft.x+edit->col_per_page < line->len)
@ -1051,7 +1211,11 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
else else
{ {
if(edit->visual.x < line->len) if(edit->visual.x < line->len)
edit->visual.x ++; {
rt_int16_t tmp_pos=1;
identify_double_byte(edit, line, EDIT_IDENT_DIR_RIGHT, &tmp_pos);
edit->visual.x += tmp_pos;
}
else else
{ {
struct rtgui_event_kbd event_kbd; struct rtgui_event_kbd event_kbd;
@ -1105,9 +1269,6 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
{ {
struct edit_line *update_end_line; struct edit_line *update_end_line;
struct rtgui_event_kbd event_kbd; struct rtgui_event_kbd event_kbd;
update_type = EDIT_UPDATE;
edit->update.start = edit->visual;
/* insert a new line buffer */ /* insert a new line buffer */
rtgui_edit_insert_line(edit, line, line->text + edit->upleft.x + edit->visual.x); rtgui_edit_insert_line(edit, line, line->text + edit->upleft.x + edit->visual.x);
@ -1115,8 +1276,10 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
line->len = rtgui_edit_line_strlen(line->text); line->len = rtgui_edit_line_strlen(line->text);
/* adjust update line end position */ /* adjust update line end position */
if((edit->max_rows-edit->upleft.y) >= edit->row_per_page) if((edit->max_rows-edit->upleft.y) > edit->row_per_page)
{ {
update_type = EDIT_UPDATE;
edit->update.start = edit->visual;
update_end_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->row_per_page-1); update_end_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->row_per_page-1);
if(update_end_line != RT_NULL) if(update_end_line != RT_NULL)
{ {
@ -1124,11 +1287,18 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
edit->update.end.y = edit->upleft.y + edit->row_per_page; edit->update.end.y = edit->upleft.y + edit->row_per_page;
} }
} }
else else if((edit->max_rows-edit->upleft.y) < edit->row_per_page)
{ {
int update_end_index = rtgui_edit_get_index_by_line(edit, edit->tail); int update_end_index = rtgui_edit_get_index_by_line(edit, edit->tail);
update_type = EDIT_UPDATE;
edit->update.start = edit->visual;
edit->update.end.x = edit->tail->len; edit->update.end.x = edit->tail->len;
edit->update.end.y = update_end_index; edit->update.end.y = update_end_index;
}
else
{
/* nothing */
/* it will be adjusted upleft.y when entering DOWN case */
} }
/* move the caret to the next line head */ /* move the caret to the next line head */
@ -1139,7 +1309,7 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
} }
else else
{ {
if(isprint(ekbd->key)) if(isprint((unsigned char)ekbd->key))
{ /* it's may print character */ { /* it's may print character */
update_type = EDIT_UPDATE; update_type = EDIT_UPDATE;
edit->update.start = edit->visual; edit->update.start = edit->visual;
@ -1164,7 +1334,7 @@ static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* ev
for(c = &line->text[line->len]; c != &line->text[ofs]; c--) for(c = &line->text[line->len]; c != &line->text[ofs]; c--)
*c = *(c-1); *c = *(c-1);
} }
line->text[ofs] = ekbd->key; line->text[ofs] = (char)ekbd->key;
if(edit->visual.x < edit->col_per_page-1) if(edit->visual.x < edit->col_per_page-1)
edit->visual.x ++; edit->visual.x ++;
line->text[line->len+1] = '\0'; line->text[line->len+1] = '\0';
@ -1282,7 +1452,7 @@ static rt_bool_t rtgui_edit_vscroll_handle(struct rtgui_widget* widget, rtgui_ev
/* local area update */ /* local area update */
void rtgui_edit_update(struct rtgui_edit *edit) void rtgui_edit_update(struct rtgui_edit *edit)
{ {
rt_uint32_t i,cpy_len=0,prev_len; rt_int16_t i,cpy_len=0,prev_len;
rtgui_rect_t rect, r; rtgui_rect_t rect, r;
struct rtgui_dc *dc; struct rtgui_dc *dc;
char *src; char *src;
@ -1381,8 +1551,10 @@ void rtgui_edit_ondraw(struct rtgui_edit *edit)
{ {
rtgui_rect_t rect, r; rtgui_rect_t rect, r;
struct rtgui_dc *dc; struct rtgui_dc *dc;
#ifdef RTGUI_EDIT_USING_SCROLL
int hscroll_flag=0; int hscroll_flag=0;
int vscroll_flag=0; int vscroll_flag=0;
#endif
RT_ASSERT(edit != RT_NULL); RT_ASSERT(edit != RT_NULL);
@ -1424,8 +1596,39 @@ void rtgui_edit_ondraw(struct rtgui_edit *edit)
rect.y2 = rect.y1 + edit->item_height; rect.y2 = rect.y1 + edit->item_height;
while(line) while(line)
{ {
rt_int16_t tmp_pos=0, ofs;
char *str = line->text+edit->upleft.x;
if(edit->upleft.x < line->len) if(edit->upleft.x < line->len)
rtgui_dc_draw_text(dc, line->text+edit->upleft.x, &rect); {
rtgui_point_t p = edit->visual; /* backup */
edit->visual.x = 0;
identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
ofs = tmp_pos % 2;
if(ofs == 1)
{ /* use dc_buffer draw the left half of double byte */
char dbl_bmp[3];
rtgui_point_t pot = {0};
rtgui_rect_t r = {0};
pot.x = edit->font_width;
r.x2 = edit->font_width*2;
r.y2 = edit->font_height;
dbl_bmp[0] = *(str-1);
dbl_bmp[1] = *str;
dbl_bmp[2] = '\0';
RTGUI_DC_BC(edit->dbl_buf) = RTGUI_WIDGET_BACKGROUND(edit);
rtgui_dc_fill_rect(edit->dbl_buf, &r);
RTGUI_DC_FC(edit->dbl_buf) = RTGUI_WIDGET_FOREGROUND(edit);
rtgui_dc_draw_text(edit->dbl_buf, dbl_bmp, &r);
rtgui_dc_blit(edit->dbl_buf, &pot, dc, &rect);
}
rect.x1 += ofs * edit->font_width;
rtgui_dc_draw_text(dc, line->text+edit->upleft.x+ofs, &rect);
rect.x1 -= ofs * edit->font_width;
edit->visual = p; /* restore */
}
line = line->next; line = line->next;
rect.y1 += edit->item_height; rect.y1 += edit->item_height;
if((rect.y1 + edit->item_height) < r.y2) if((rect.y1 + edit->item_height) < r.y2)
@ -1469,8 +1672,10 @@ void rtgui_edit_ondraw(struct rtgui_edit *edit)
void rtgui_edit_set_text(struct rtgui_edit* edit, const char* text) void rtgui_edit_set_text(struct rtgui_edit* edit, const char* text)
{ {
const char *begin, *ptr; const char *begin, *ptr;
#ifdef RTGUI_EDIT_USING_SCROLL
int hscroll_flag=0; int hscroll_flag=0;
int vscroll_flag=0; int vscroll_flag=0;
#endif
RT_ASSERT(edit != RT_NULL); RT_ASSERT(edit != RT_NULL);
@ -1497,7 +1702,6 @@ void rtgui_edit_set_text(struct rtgui_edit* edit, const char* text)
if(begin < ptr) if(begin < ptr)
rtgui_edit_append_line(edit, begin); rtgui_edit_append_line(edit, begin);
} }
edit->first_line = edit->head;
#ifdef RTGUI_EDIT_USING_SCROLL #ifdef RTGUI_EDIT_USING_SCROLL
if(edit->hscroll != RT_NULL) if(edit->hscroll != RT_NULL)
@ -1539,11 +1743,12 @@ void rtgui_edit_set_text(struct rtgui_edit* edit, const char* text)
{ {
rtgui_edit_adjust_scroll(edit->vscroll); rtgui_edit_adjust_scroll(edit->vscroll);
} }
#endif
if(hscroll_flag || vscroll_flag) if(hscroll_flag || vscroll_flag)
{ {
rtgui_widget_update_clip(RTGUI_WIDGET(edit)); rtgui_widget_update_clip(RTGUI_WIDGET(edit));
} }
#endif
} }
rt_bool_t rtgui_edit_event_handler(struct rtgui_object* object, rtgui_event_t* event) rt_bool_t rtgui_edit_event_handler(struct rtgui_object* object, rtgui_event_t* event)
@ -1587,21 +1792,56 @@ rt_bool_t rtgui_edit_event_handler(struct rtgui_object* object, rtgui_event_t* e
return RT_FALSE; return RT_FALSE;
} }
rtgui_point_t rtgui_edit_get_current_point(struct rtgui_edit *edit)
{
rtgui_point_t p;
RT_ASSERT(edit != RT_NULL);
p.x = edit->upleft.x + edit->visual.x;
p.y = edit->upleft.y + edit->visual.y;
return p;
}
rt_uint32_t rtgui_edit_get_mem_consume(struct rtgui_edit *edit)
{
rt_uint32_t mem_size;
struct edit_line *line;
mem_size = sizeof(struct rtgui_edit);
mem_size += edit->col_per_page + 1; /* update_buf */
if(edit->head != RT_NULL)
{
line = edit->head;
while(line)
{
mem_size += line->zsize;
mem_size += sizeof(struct edit_line);
line = line->next;
}
}
return mem_size;
}
/** /**
* File access component, General File Access Interface * File access component, General File Access Interface
*/ */
rt_bool_t rtgui_edit_readin_file(struct rtgui_edit *edit, const char *filename) rt_bool_t rtgui_edit_readin_file(struct rtgui_edit *edit, const char *filename)
{ {
int fd, num=0, read_bytes, size ,len=0; struct rtgui_filerw *filerw;
int num=0, read_bytes, size ,len=0;
char *text ,ch; char *text ,ch;
fd = open(filename, O_RDONLY, 0); filerw = rtgui_filerw_create_file(filename, "rb");
if (fd < 0) if (filerw == RT_NULL) return RT_FALSE;
{ /**
return RT_FALSE; * If it was in the debug of the win32, If document encode is UTF-8 or Unicode,
} * Will read to garbled code when using the function read documents.
* You can Change of the document contains the source code for ANSI.
*/
while(edit->max_rows > 0) while(edit->max_rows > 0)
rtgui_edit_delete_line(edit, edit->head); rtgui_edit_delete_line(edit, edit->head);
edit->max_rows = 0; edit->max_rows = 0;
@ -1611,8 +1851,8 @@ rt_bool_t rtgui_edit_readin_file(struct rtgui_edit *edit, const char *filename)
if(text == RT_NULL) return RT_FALSE; if(text == RT_NULL) return RT_FALSE;
do { do {
if ( (read_bytes = read(fd, &ch, 1)) > 0 ) if ( (read_bytes = rtgui_filerw_read(filerw, &ch, 1, 1)) > 0 )
{ { /* rt_kprintf("ch=%02X ",ch); DEBUG */
if(num >= size - 1) if(num >= size - 1)
text = rt_realloc(text, rtgui_edit_alloc_len(size, num)); text = rt_realloc(text, rtgui_edit_alloc_len(size, num));
if(ch == 0x09) //Tab if(ch == 0x09) //Tab
@ -1630,9 +1870,14 @@ rt_bool_t rtgui_edit_readin_file(struct rtgui_edit *edit, const char *filename)
} }
} }
else if(num > 0)
{ /* last line does not exist the end operator */
*(text + num) = '\0';
rtgui_edit_append_line(edit, text);
}
} while(read_bytes); } while(read_bytes);
close(fd); rtgui_filerw_close(filerw);
rtgui_free(text); rtgui_free(text);
rtgui_edit_ondraw(edit); rtgui_edit_ondraw(edit);
@ -1641,26 +1886,23 @@ rt_bool_t rtgui_edit_readin_file(struct rtgui_edit *edit, const char *filename)
rt_bool_t rtgui_edit_saveas_file(struct rtgui_edit *edit, const char *filename) rt_bool_t rtgui_edit_saveas_file(struct rtgui_edit *edit, const char *filename)
{ {
int fd; struct rtgui_filerw *filerw;
char ch_tailed = 0x0A; char ch_tailed = 0x0A;
struct edit_line *line; struct edit_line *line;
fd = open(filename, O_WRONLY | O_CREAT, 0); filerw = rtgui_filerw_create_file(filename, "wb");
if (fd < 0) if (filerw == RT_NULL) return RT_FALSE;
{
return RT_FALSE;
}
line = edit->head; line = edit->head;
while(line) while(line)
{ {
write(fd, line->text, line->len); rtgui_filerw_write(filerw, line->text, line->len, 1);
if(line != edit->tail) if(line != edit->tail)
write(fd, &ch_tailed, 1); rtgui_filerw_write(filerw, &ch_tailed, 1, 1);
line = line->next; line = line->next;
} }
close(fd); rtgui_filerw_close(filerw);
return RT_TRUE; return RT_TRUE;
} }

View File

@ -24,7 +24,7 @@
#include <rtgui/widgets/listbox.h> #include <rtgui/widgets/listbox.h>
#include <rtgui/widgets/window.h> #include <rtgui/widgets/window.h>
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW) #if defined(RTGUI_USING_DFS_FILERW)
#ifdef _WIN32 #ifdef _WIN32
#include <io.h> #include <io.h>
#include <dirent.h> #include <dirent.h>

View File

@ -56,6 +56,7 @@ rt_bool_t rtgui_label_event_handler(struct rtgui_object *object, struct rtgui_ev
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_label_event_handler);
rtgui_label_t* rtgui_label_create(const char* text) rtgui_label_t* rtgui_label_create(const char* text)
{ {
@ -78,11 +79,13 @@ rtgui_label_t* rtgui_label_create(const char* text)
return label; return label;
} }
RTM_EXPORT(rtgui_label_create);
void rtgui_label_destroy(rtgui_label_t* label) void rtgui_label_destroy(rtgui_label_t* label)
{ {
rtgui_widget_destroy(RTGUI_WIDGET(label)); rtgui_widget_destroy(RTGUI_WIDGET(label));
} }
RTM_EXPORT(rtgui_label_destroy);
char* rtgui_label_get_text(rtgui_label_t* label) char* rtgui_label_get_text(rtgui_label_t* label)
{ {
@ -90,6 +93,7 @@ char* rtgui_label_get_text(rtgui_label_t* label)
return label->text; return label->text;
} }
RTM_EXPORT(rtgui_label_get_text);
void rtgui_label_set_text(rtgui_label_t* label, const char* text) void rtgui_label_set_text(rtgui_label_t* label, const char* text)
{ {
@ -110,4 +114,5 @@ void rtgui_label_set_text(rtgui_label_t* label, const char* text)
/* update widget */ /* update widget */
rtgui_theme_draw_label(label); rtgui_theme_draw_label(label);
} }
RTM_EXPORT(rtgui_label_set_text);

View File

@ -303,6 +303,7 @@ void rtgui_list_view_update_list(struct rtgui_list_view* view, rt_int16_t old_it
rtgui_dc_end_drawing(dc); rtgui_dc_end_drawing(dc);
} }
RTM_EXPORT(rtgui_list_view_update_list);
void rtgui_list_view_ondraw(struct rtgui_list_view* view) void rtgui_list_view_ondraw(struct rtgui_list_view* view)
{ {
@ -328,6 +329,7 @@ void rtgui_list_view_ondraw(struct rtgui_list_view* view)
rtgui_dc_end_drawing(dc); rtgui_dc_end_drawing(dc);
} }
RTM_EXPORT(rtgui_list_view_ondraw);
static rt_bool_t rtgui_list_view_onmouse(struct rtgui_list_view* view, struct rtgui_event_mouse* emouse) static rt_bool_t rtgui_list_view_onmouse(struct rtgui_list_view* view, struct rtgui_event_mouse* emouse)
{ {
@ -564,6 +566,7 @@ rt_bool_t rtgui_list_view_event_handler(struct rtgui_object* widget, struct rtgu
/* use view event handler */ /* use view event handler */
return rtgui_container_event_handler(widget, event); return rtgui_container_event_handler(widget, event);
} }
RTM_EXPORT(rtgui_list_view_event_handler);
static void rtgui_list_view_calc(struct rtgui_list_view* view) static void rtgui_list_view_calc(struct rtgui_list_view* view)
{ {
@ -628,9 +631,12 @@ rtgui_list_view_t* rtgui_list_view_create(const struct rtgui_list_item* items, r
return view; return view;
} }
RTM_EXPORT(rtgui_list_view_create);
void rtgui_list_view_destroy(rtgui_list_view_t* view) void rtgui_list_view_destroy(rtgui_list_view_t* view)
{ {
/* destroy view */ /* destroy view */
rtgui_widget_destroy(RTGUI_WIDGET(view)); rtgui_widget_destroy(RTGUI_WIDGET(view));
} }
RTM_EXPORT(rtgui_list_view_destroy);

View File

@ -102,6 +102,7 @@ void rtgui_listbox_ondraw(struct rtgui_listbox* box)
} }
rtgui_dc_end_drawing(dc); rtgui_dc_end_drawing(dc);
} }
RTM_EXPORT(rtgui_listbox_ondraw);
static void rtgui_listbox_update_current(struct rtgui_listbox* box, rt_int16_t old_item) static void rtgui_listbox_update_current(struct rtgui_listbox* box, rt_int16_t old_item)
{ {
@ -324,6 +325,7 @@ rt_bool_t rtgui_listbox_event_handler(struct rtgui_object* object, struct rtgui_
/* use box event handler */ /* use box event handler */
return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event); return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
} }
RTM_EXPORT(rtgui_listbox_event_handler);
rtgui_listbox_t* rtgui_listbox_create(const struct rtgui_listbox_item* items, rt_uint16_t count, rtgui_rect_t *rect) rtgui_listbox_t* rtgui_listbox_create(const struct rtgui_listbox_item* items, rt_uint16_t count, rtgui_rect_t *rect)
{ {
@ -342,12 +344,14 @@ rtgui_listbox_t* rtgui_listbox_create(const struct rtgui_listbox_item* items, rt
return box; return box;
} }
RTM_EXPORT(rtgui_listbox_create);
void rtgui_listbox_destroy(rtgui_listbox_t* box) void rtgui_listbox_destroy(rtgui_listbox_t* box)
{ {
/* destroy box */ /* destroy box */
rtgui_widget_destroy(RTGUI_WIDGET(box)); rtgui_widget_destroy(RTGUI_WIDGET(box));
} }
RTM_EXPORT(rtgui_listbox_destroy);
void rtgui_listbox_set_onitem(rtgui_listbox_t* box, rtgui_event_handler_ptr func) void rtgui_listbox_set_onitem(rtgui_listbox_t* box, rtgui_event_handler_ptr func)
{ {
@ -355,6 +359,7 @@ void rtgui_listbox_set_onitem(rtgui_listbox_t* box, rtgui_event_handler_ptr func
box->on_item = func; box->on_item = func;
} }
RTM_EXPORT(rtgui_listbox_set_onitem);
void rtgui_listbox_set_items(rtgui_listbox_t* box, struct rtgui_listbox_item* items, rt_uint16_t count) void rtgui_listbox_set_items(rtgui_listbox_t* box, struct rtgui_listbox_item* items, rt_uint16_t count)
{ {
@ -369,6 +374,7 @@ void rtgui_listbox_set_items(rtgui_listbox_t* box, struct rtgui_listbox_item* it
rtgui_widget_update(RTGUI_WIDGET(box)); rtgui_widget_update(RTGUI_WIDGET(box));
} }
RTM_EXPORT(rtgui_listbox_set_items);
void rtgui_listbox_set_current_item(rtgui_listbox_t* box, int index) void rtgui_listbox_set_current_item(rtgui_listbox_t* box, int index)
{ {
@ -384,4 +390,5 @@ void rtgui_listbox_set_current_item(rtgui_listbox_t* box, int index)
rtgui_listbox_update_current(box, old_item); rtgui_listbox_update_current(box, old_item);
} }
} }
RTM_EXPORT(rtgui_listbox_set_current_item);

View File

@ -207,6 +207,7 @@ void rtgui_listctrl_update_current(struct rtgui_listctrl* ctrl, rt_uint16_t old_
rtgui_dc_end_drawing(dc); rtgui_dc_end_drawing(dc);
} }
RTM_EXPORT(rtgui_listctrl_update_current);
rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object* object, struct rtgui_event* event) rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object* object, struct rtgui_event* event)
{ {
@ -361,6 +362,7 @@ rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object* object, struct rtgui
/* use ctrl event handler */ /* use ctrl event handler */
return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event); return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
} }
RTM_EXPORT(rtgui_listctrl_event_handler);
rtgui_listctrl_t* rtgui_listctrl_create(rt_uint32_t items, rt_uint16_t count, rtgui_rect_t *rect, rtgui_listctrl_t* rtgui_listctrl_create(rt_uint32_t items, rt_uint16_t count, rtgui_rect_t *rect,
rtgui_onitem_draw_t ondraw) rtgui_onitem_draw_t ondraw)
@ -380,12 +382,14 @@ rtgui_listctrl_t* rtgui_listctrl_create(rt_uint32_t items, rt_uint16_t count, rt
return ctrl; return ctrl;
} }
RTM_EXPORT(rtgui_listctrl_create);
void rtgui_listctrl_destroy(rtgui_listctrl_t* ctrl) void rtgui_listctrl_destroy(rtgui_listctrl_t* ctrl)
{ {
/* destroy ctrl */ /* destroy ctrl */
rtgui_widget_destroy(RTGUI_WIDGET(ctrl)); rtgui_widget_destroy(RTGUI_WIDGET(ctrl));
} }
RTM_EXPORT(rtgui_listctrl_destroy);
void rtgui_listctrl_set_onitem(rtgui_listctrl_t* ctrl, rtgui_event_handler_ptr func) void rtgui_listctrl_set_onitem(rtgui_listctrl_t* ctrl, rtgui_event_handler_ptr func)
{ {
@ -393,6 +397,7 @@ void rtgui_listctrl_set_onitem(rtgui_listctrl_t* ctrl, rtgui_event_handler_ptr f
ctrl->on_item = func; ctrl->on_item = func;
} }
RTM_EXPORT(rtgui_listctrl_set_onitem);
void rtgui_listctrl_set_items(rtgui_listctrl_t* ctrl, rt_uint32_t items, rt_uint16_t count) void rtgui_listctrl_set_items(rtgui_listctrl_t* ctrl, rt_uint32_t items, rt_uint16_t count)
{ {
@ -407,6 +412,7 @@ void rtgui_listctrl_set_items(rtgui_listctrl_t* ctrl, rt_uint32_t items, rt_uint
rtgui_widget_update(RTGUI_WIDGET(ctrl)); rtgui_widget_update(RTGUI_WIDGET(ctrl));
} }
RTM_EXPORT(rtgui_listctrl_set_items);
rt_bool_t rtgui_listctrl_get_item_rect(rtgui_listctrl_t* ctrl, rt_uint16_t item, rtgui_rect_t* item_rect) rt_bool_t rtgui_listctrl_get_item_rect(rtgui_listctrl_t* ctrl, rt_uint16_t item, rtgui_rect_t* item_rect)
{ {
@ -427,6 +433,7 @@ rt_bool_t rtgui_listctrl_get_item_rect(rtgui_listctrl_t* ctrl, rt_uint16_t item,
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_listctrl_get_item_rect);
void rtgui_listctrl_set_itemheight(struct rtgui_listctrl* ctrl, int height) void rtgui_listctrl_set_itemheight(struct rtgui_listctrl* ctrl, int height)
{ {
@ -436,4 +443,5 @@ void rtgui_listctrl_set_itemheight(struct rtgui_listctrl* ctrl, int height)
ctrl->item_height = height; ctrl->item_height = height;
ctrl->page_items = rtgui_rect_height(RTGUI_WIDGET(ctrl)->extent) / (2 + ctrl->item_height); ctrl->page_items = rtgui_rect_height(RTGUI_WIDGET(ctrl)->extent) / (2 + ctrl->item_height);
} }
RTM_EXPORT(rtgui_listctrl_set_itemheight);

View File

@ -192,6 +192,7 @@ rt_bool_t rtgui_slider_event_handler(struct rtgui_object *object, struct rtgui_e
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_slider_event_handler);
struct rtgui_slider* rtgui_slider_create(rt_size_t min, rt_size_t max, int orient) struct rtgui_slider* rtgui_slider_create(rt_size_t min, rt_size_t max, int orient)
{ {
@ -213,6 +214,7 @@ struct rtgui_slider* rtgui_slider_create(rt_size_t min, rt_size_t max, int orien
return slider; return slider;
} }
RTM_EXPORT(rtgui_slider_create);
void rtgui_slider_set_range(struct rtgui_slider* slider, rt_size_t min, rt_size_t max) void rtgui_slider_set_range(struct rtgui_slider* slider, rt_size_t min, rt_size_t max)
{ {
@ -221,6 +223,7 @@ void rtgui_slider_set_range(struct rtgui_slider* slider, rt_size_t min, rt_size_
slider->max = max; slider->max = max;
slider->min = min; slider->min = min;
} }
RTM_EXPORT(rtgui_slider_set_range);
void rtgui_slider_set_value(struct rtgui_slider* slider, rt_size_t value) void rtgui_slider_set_value(struct rtgui_slider* slider, rt_size_t value)
{ {
@ -238,6 +241,7 @@ void rtgui_slider_set_value(struct rtgui_slider* slider, rt_size_t value)
} }
} }
} }
RTM_EXPORT(rtgui_slider_set_value);
void rtgui_slider_set_orientation(struct rtgui_slider* slider, int orientation) void rtgui_slider_set_orientation(struct rtgui_slider* slider, int orientation)
{ {
@ -260,6 +264,7 @@ void rtgui_slider_set_orientation(struct rtgui_slider* slider, int orientation)
} }
#endif #endif
} }
RTM_EXPORT(rtgui_slider_set_orientation);
rt_size_t rtgui_slider_get_value(struct rtgui_slider* slider) rt_size_t rtgui_slider_get_value(struct rtgui_slider* slider)
{ {
@ -267,3 +272,5 @@ rt_size_t rtgui_slider_get_value(struct rtgui_slider* slider)
return slider->value; return slider->value;
} }
RTM_EXPORT(rtgui_slider_get_value);

View File

@ -42,6 +42,7 @@ rt_bool_t rtgui_staticline_event_handler(struct rtgui_object* object, struct rtg
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_staticline_event_handler);
rtgui_staticline_t * rtgui_staticline_create(int orientation) rtgui_staticline_t * rtgui_staticline_create(int orientation)
{ {
@ -55,11 +56,13 @@ rtgui_staticline_t * rtgui_staticline_create(int orientation)
return staticline; return staticline;
} }
RTM_EXPORT(rtgui_staticline_create);
void rtgui_staticline_destroy(rtgui_staticline_t* staticline) void rtgui_staticline_destroy(rtgui_staticline_t* staticline)
{ {
rtgui_widget_destroy(RTGUI_WIDGET(staticline)); rtgui_widget_destroy(RTGUI_WIDGET(staticline));
} }
RTM_EXPORT(rtgui_staticline_destroy);
void rtgui_staticline_set_orientation(rtgui_staticline_t* staticline, int orientation) void rtgui_staticline_set_orientation(rtgui_staticline_t* staticline, int orientation)
{ {
@ -81,3 +84,5 @@ void rtgui_staticline_set_orientation(rtgui_staticline_t* staticline, int orient
} }
#endif #endif
} }
RTM_EXPORT(rtgui_staticline_set_orientation);

View File

@ -91,6 +91,7 @@ DEFINE_CLASS_TYPE(widget, "widget",
_rtgui_widget_constructor, _rtgui_widget_constructor,
_rtgui_widget_destructor, _rtgui_widget_destructor,
sizeof(struct rtgui_widget)); sizeof(struct rtgui_widget));
RTM_EXPORT(_rtgui_widget);
rtgui_widget_t *rtgui_widget_create(rtgui_type_t *widget_type) rtgui_widget_t *rtgui_widget_create(rtgui_type_t *widget_type)
{ {
@ -100,11 +101,13 @@ rtgui_widget_t *rtgui_widget_create(rtgui_type_t *widget_type)
return widget; return widget;
} }
RTM_EXPORT(rtgui_widget_create);
void rtgui_widget_destroy(rtgui_widget_t* widget) void rtgui_widget_destroy(rtgui_widget_t* widget)
{ {
rtgui_object_destroy(RTGUI_OBJECT(widget)); rtgui_object_destroy(RTGUI_OBJECT(widget));
} }
RTM_EXPORT(rtgui_widget_destroy);
void rtgui_widget_set_rect(rtgui_widget_t* widget, const rtgui_rect_t* rect) void rtgui_widget_set_rect(rtgui_widget_t* widget, const rtgui_rect_t* rect)
{ {
@ -142,6 +145,7 @@ void rtgui_widget_set_rect(rtgui_widget_t* widget, const rtgui_rect_t* rect)
rtgui_widget_update_clip(widget->parent); rtgui_widget_update_clip(widget->parent);
} }
} }
RTM_EXPORT(rtgui_widget_set_rect);
void rtgui_widget_set_rectangle(rtgui_widget_t* widget, int x, int y, int width, int height) void rtgui_widget_set_rectangle(rtgui_widget_t* widget, int x, int y, int width, int height)
{ {
@ -152,12 +156,14 @@ void rtgui_widget_set_rectangle(rtgui_widget_t* widget, int x, int y, int width,
rtgui_widget_set_rect(widget, &rect); rtgui_widget_set_rect(widget, &rect);
} }
RTM_EXPORT(rtgui_widget_set_rectangle);
void rtgui_widget_set_parent(rtgui_widget_t* widget, rtgui_widget_t* parent) void rtgui_widget_set_parent(rtgui_widget_t* widget, rtgui_widget_t* parent)
{ {
/* set parent and toplevel widget */ /* set parent and toplevel widget */
widget->parent = parent; widget->parent = parent;
} }
RTM_EXPORT(rtgui_widget_set_parent);
void rtgui_widget_get_extent(rtgui_widget_t* widget, rtgui_rect_t *rect) void rtgui_widget_get_extent(rtgui_widget_t* widget, rtgui_rect_t *rect)
{ {
@ -166,6 +172,7 @@ void rtgui_widget_get_extent(rtgui_widget_t* widget, rtgui_rect_t *rect)
*rect = widget->extent; *rect = widget->extent;
} }
RTM_EXPORT(rtgui_widget_get_extent);
void rtgui_widget_set_miniwidth(rtgui_widget_t* widget, int width) void rtgui_widget_set_miniwidth(rtgui_widget_t* widget, int width)
{ {
@ -173,6 +180,7 @@ void rtgui_widget_set_miniwidth(rtgui_widget_t* widget, int width)
widget->mini_width = width; widget->mini_width = width;
} }
RTM_EXPORT(rtgui_widget_set_miniwidth);
void rtgui_widget_set_miniheight(rtgui_widget_t* widget, int height) void rtgui_widget_set_miniheight(rtgui_widget_t* widget, int height)
{ {
@ -180,6 +188,7 @@ void rtgui_widget_set_miniheight(rtgui_widget_t* widget, int height)
widget->mini_height = height; widget->mini_height = height;
} }
RTM_EXPORT(rtgui_widget_set_miniheight);
/* /*
* This function moves widget and its children to a logic point * This function moves widget and its children to a logic point
@ -204,6 +213,7 @@ void rtgui_widget_move_to_logic(rtgui_widget_t* widget, int dx, int dy)
} }
} }
} }
RTM_EXPORT(rtgui_widget_move_to_logic);
void rtgui_widget_get_rect(rtgui_widget_t* widget, rtgui_rect_t *rect) void rtgui_widget_get_rect(rtgui_widget_t* widget, rtgui_rect_t *rect)
{ {
@ -216,6 +226,7 @@ void rtgui_widget_get_rect(rtgui_widget_t* widget, rtgui_rect_t *rect)
rect->y2 = widget->extent.y2 - widget->extent.y1; rect->y2 = widget->extent.y2 - widget->extent.y1;
} }
} }
RTM_EXPORT(rtgui_widget_get_rect);
/** /**
* set widget draw style * set widget draw style
@ -247,6 +258,7 @@ void rtgui_widget_set_border(rtgui_widget_t* widget, rt_uint32_t style)
break; break;
} }
} }
RTM_EXPORT(rtgui_widget_set_border);
void rtgui_widget_set_onfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler) void rtgui_widget_set_onfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{ {
@ -254,6 +266,7 @@ void rtgui_widget_set_onfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr ha
widget->on_focus_in = handler; widget->on_focus_in = handler;
} }
RTM_EXPORT(rtgui_widget_set_onfocus);
void rtgui_widget_set_onunfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler) void rtgui_widget_set_onunfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{ {
@ -261,6 +274,7 @@ void rtgui_widget_set_onunfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr
widget->on_focus_out = handler; widget->on_focus_out = handler;
} }
RTM_EXPORT(rtgui_widget_set_onunfocus);
void rtgui_widget_set_onshow(rtgui_widget_t* widget, rtgui_event_handler_ptr handler) void rtgui_widget_set_onshow(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{ {
@ -268,6 +282,7 @@ void rtgui_widget_set_onshow(rtgui_widget_t* widget, rtgui_event_handler_ptr han
widget->on_show = handler; widget->on_show = handler;
} }
RTM_EXPORT(rtgui_widget_set_onshow);
void rtgui_widget_set_onhide(rtgui_widget_t* widget, rtgui_event_handler_ptr handler) void rtgui_widget_set_onhide(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{ {
@ -275,6 +290,7 @@ void rtgui_widget_set_onhide(rtgui_widget_t* widget, rtgui_event_handler_ptr han
widget->on_hide = handler; widget->on_hide = handler;
} }
RTM_EXPORT(rtgui_widget_set_onhide);
#ifndef RTGUI_USING_SMALL_SIZE #ifndef RTGUI_USING_SMALL_SIZE
void rtgui_widget_set_ondraw(rtgui_widget_t* widget, rtgui_event_handler_ptr handler) void rtgui_widget_set_ondraw(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
@ -283,6 +299,7 @@ void rtgui_widget_set_ondraw(rtgui_widget_t* widget, rtgui_event_handler_ptr han
widget->on_draw = handler; widget->on_draw = handler;
} }
RTM_EXPORT(rtgui_widget_set_ondraw);
void rtgui_widget_set_onmouseclick(rtgui_widget_t* widget, rtgui_event_handler_ptr handler) void rtgui_widget_set_onmouseclick(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{ {
@ -290,6 +307,7 @@ void rtgui_widget_set_onmouseclick(rtgui_widget_t* widget, rtgui_event_handler_p
widget->on_mouseclick = handler; widget->on_mouseclick = handler;
} }
RTM_EXPORT(rtgui_widget_set_onmouseclick);
void rtgui_widget_set_onkey(rtgui_widget_t* widget, rtgui_event_handler_ptr handler) void rtgui_widget_set_onkey(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{ {
@ -297,6 +315,7 @@ void rtgui_widget_set_onkey(rtgui_widget_t* widget, rtgui_event_handler_ptr hand
widget->on_key = handler; widget->on_key = handler;
} }
RTM_EXPORT(rtgui_widget_set_onkey);
void rtgui_widget_set_onsize(rtgui_widget_t* widget, rtgui_event_handler_ptr handler) void rtgui_widget_set_onsize(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{ {
@ -304,6 +323,7 @@ void rtgui_widget_set_onsize(rtgui_widget_t* widget, rtgui_event_handler_ptr han
widget->on_size = handler; widget->on_size = handler;
} }
RTM_EXPORT(rtgui_widget_set_onsize);
void rtgui_widget_set_oncommand(rtgui_widget_t* widget, rtgui_event_handler_ptr handler) void rtgui_widget_set_oncommand(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{ {
@ -311,6 +331,7 @@ void rtgui_widget_set_oncommand(rtgui_widget_t* widget, rtgui_event_handler_ptr
widget->on_command = handler; widget->on_command = handler;
} }
RTM_EXPORT(rtgui_widget_set_oncommand);
#endif #endif
/** /**
@ -343,6 +364,7 @@ void rtgui_widget_focus(rtgui_widget_t *widget)
if (widget->on_focus_in != RT_NULL) if (widget->on_focus_in != RT_NULL)
widget->on_focus_in(RTGUI_OBJECT(widget), RT_NULL); widget->on_focus_in(RTGUI_OBJECT(widget), RT_NULL);
} }
RTM_EXPORT(rtgui_widget_focus);
/** /**
* @brief Unfocused the widget * @brief Unfocused the widget
@ -366,6 +388,7 @@ void rtgui_widget_unfocus(rtgui_widget_t *widget)
/* refresh widget */ /* refresh widget */
rtgui_widget_update(widget); rtgui_widget_update(widget);
} }
RTM_EXPORT(rtgui_widget_unfocus);
void rtgui_widget_point_to_device(rtgui_widget_t* widget, rtgui_point_t* point) void rtgui_widget_point_to_device(rtgui_widget_t* widget, rtgui_point_t* point)
{ {
@ -377,6 +400,7 @@ void rtgui_widget_point_to_device(rtgui_widget_t* widget, rtgui_point_t* point)
point->y += widget->extent.y1; point->y += widget->extent.y1;
} }
} }
RTM_EXPORT(rtgui_widget_point_to_device);
void rtgui_widget_rect_to_device(rtgui_widget_t* widget, rtgui_rect_t* rect) void rtgui_widget_rect_to_device(rtgui_widget_t* widget, rtgui_rect_t* rect)
{ {
@ -391,6 +415,7 @@ void rtgui_widget_rect_to_device(rtgui_widget_t* widget, rtgui_rect_t* rect)
rect->y2 += widget->extent.y1; rect->y2 += widget->extent.y1;
} }
} }
RTM_EXPORT(rtgui_widget_rect_to_device);
void rtgui_widget_point_to_logic(rtgui_widget_t* widget, rtgui_point_t* point) void rtgui_widget_point_to_logic(rtgui_widget_t* widget, rtgui_point_t* point)
{ {
@ -402,6 +427,7 @@ void rtgui_widget_point_to_logic(rtgui_widget_t* widget, rtgui_point_t* point)
point->y -= widget->extent.y1; point->y -= widget->extent.y1;
} }
} }
RTM_EXPORT(rtgui_widget_point_to_logic);
void rtgui_widget_rect_to_logic(rtgui_widget_t* widget, rtgui_rect_t* rect) void rtgui_widget_rect_to_logic(rtgui_widget_t* widget, rtgui_rect_t* rect)
{ {
@ -416,6 +442,7 @@ void rtgui_widget_rect_to_logic(rtgui_widget_t* widget, rtgui_rect_t* rect)
rect->y2 -= widget->extent.y1; rect->y2 -= widget->extent.y1;
} }
} }
RTM_EXPORT(rtgui_widget_rect_to_logic);
struct rtgui_win* rtgui_widget_get_toplevel(rtgui_widget_t* widget) struct rtgui_win* rtgui_widget_get_toplevel(rtgui_widget_t* widget)
{ {
@ -437,6 +464,7 @@ struct rtgui_win* rtgui_widget_get_toplevel(rtgui_widget_t* widget)
return RTGUI_WIN(r); return RTGUI_WIN(r);
} }
RTM_EXPORT(rtgui_widget_get_toplevel);
rt_bool_t rtgui_widget_onupdate_toplvl(struct rtgui_object *object, struct rtgui_event *event) rt_bool_t rtgui_widget_onupdate_toplvl(struct rtgui_object *object, struct rtgui_event *event)
{ {
@ -453,6 +481,7 @@ rt_bool_t rtgui_widget_onupdate_toplvl(struct rtgui_object *object, struct rtgui
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_widget_onupdate_toplvl);
rt_bool_t rtgui_widget_event_handler(struct rtgui_object* object, rtgui_event_t* event) rt_bool_t rtgui_widget_event_handler(struct rtgui_object* object, rtgui_event_t* event)
{ {
@ -496,6 +525,7 @@ rt_bool_t rtgui_widget_event_handler(struct rtgui_object* object, rtgui_event_t*
return rtgui_object_event_handler(object, event); return rtgui_object_event_handler(object, event);
} }
RTM_EXPORT(rtgui_widget_event_handler);
/* /*
* This function updates the clip info of widget * This function updates the clip info of widget
@ -558,6 +588,7 @@ void rtgui_widget_update_clip(rtgui_widget_t* widget)
rtgui_widget_update_clip(rtgui_notebook_get_current(RTGUI_NOTEBOOK(widget))); rtgui_widget_update_clip(rtgui_notebook_get_current(RTGUI_NOTEBOOK(widget)));
} }
} }
RTM_EXPORT(rtgui_widget_update_clip);
void rtgui_widget_show(struct rtgui_widget *widget) void rtgui_widget_show(struct rtgui_widget *widget)
{ {
@ -575,6 +606,7 @@ void rtgui_widget_show(struct rtgui_widget *widget)
&eshow); &eshow);
} }
} }
RTM_EXPORT(rtgui_widget_show);
rt_bool_t rtgui_widget_onshow(struct rtgui_object *object, struct rtgui_event *event) rt_bool_t rtgui_widget_onshow(struct rtgui_object *object, struct rtgui_event *event)
{ {
@ -590,6 +622,7 @@ rt_bool_t rtgui_widget_onshow(struct rtgui_object *object, struct rtgui_event *e
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_widget_onshow);
rt_bool_t rtgui_widget_onhide(struct rtgui_object *object, struct rtgui_event *event) rt_bool_t rtgui_widget_onhide(struct rtgui_object *object, struct rtgui_event *event)
{ {
@ -621,6 +654,7 @@ rt_bool_t rtgui_widget_onhide(struct rtgui_object *object, struct rtgui_event *e
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_widget_onhide);
void rtgui_widget_hide(struct rtgui_widget *widget) void rtgui_widget_hide(struct rtgui_widget *widget)
{ {
@ -638,6 +672,7 @@ void rtgui_widget_hide(struct rtgui_widget *widget)
&ehide); &ehide);
} }
} }
RTM_EXPORT(rtgui_widget_hide);
rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t* widget) rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t* widget)
{ {
@ -654,6 +689,7 @@ rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t* widget)
return RTGUI_WIDGET_FOREGROUND(widget); return RTGUI_WIDGET_FOREGROUND(widget);
} }
RTM_EXPORT(rtgui_widget_get_parent_foreground);
rtgui_color_t rtgui_widget_get_parent_background(rtgui_widget_t* widget) rtgui_color_t rtgui_widget_get_parent_background(rtgui_widget_t* widget)
{ {
@ -670,6 +706,7 @@ rtgui_color_t rtgui_widget_get_parent_background(rtgui_widget_t* widget)
return RTGUI_WIDGET_BACKGROUND(widget); return RTGUI_WIDGET_BACKGROUND(widget);
} }
RTM_EXPORT(rtgui_widget_get_parent_background);
void rtgui_widget_update(rtgui_widget_t* widget) void rtgui_widget_update(rtgui_widget_t* widget)
{ {
@ -689,6 +726,7 @@ void rtgui_widget_update(rtgui_widget_t* widget)
&paint.parent); &paint.parent);
} }
} }
RTM_EXPORT(rtgui_widget_update);
rtgui_widget_t* rtgui_widget_get_next_sibling(rtgui_widget_t* widget) rtgui_widget_t* rtgui_widget_get_next_sibling(rtgui_widget_t* widget)
{ {
@ -701,6 +739,7 @@ rtgui_widget_t* rtgui_widget_get_next_sibling(rtgui_widget_t* widget)
return sibling; return sibling;
} }
RTM_EXPORT(rtgui_widget_get_next_sibling);
rtgui_widget_t* rtgui_widget_get_prev_sibling(rtgui_widget_t* widget) rtgui_widget_t* rtgui_widget_get_prev_sibling(rtgui_widget_t* widget)
{ {
@ -723,6 +762,7 @@ rtgui_widget_t* rtgui_widget_get_prev_sibling(rtgui_widget_t* widget)
return sibling; return sibling;
} }
RTM_EXPORT(rtgui_widget_get_prev_sibling);
#ifdef RTGUI_WIDGET_DEBUG #ifdef RTGUI_WIDGET_DEBUG
#include <rtgui/widgets/label.h> #include <rtgui/widgets/label.h>

View File

@ -143,6 +143,7 @@ __on_err:
rtgui_widget_destroy(RTGUI_WIDGET(win)); rtgui_widget_destroy(RTGUI_WIDGET(win));
return RT_NULL; return RT_NULL;
} }
RTM_EXPORT(rtgui_win_create);
rtgui_win_t* rtgui_mainwin_create(struct rtgui_win *parent_window, const char* title, rt_uint16_t style) rtgui_win_t* rtgui_mainwin_create(struct rtgui_win *parent_window, const char* title, rt_uint16_t style)
{ {
@ -153,6 +154,7 @@ rtgui_win_t* rtgui_mainwin_create(struct rtgui_win *parent_window, const char* t
return rtgui_win_create(parent_window, title, &rect, style); return rtgui_win_create(parent_window, title, &rect, style);
} }
RTM_EXPORT(rtgui_mainwin_create);
static rt_bool_t _rtgui_win_deal_close(struct rtgui_win *win, static rt_bool_t _rtgui_win_deal_close(struct rtgui_win *win,
struct rtgui_event *event, struct rtgui_event *event,
@ -215,6 +217,7 @@ void rtgui_win_destroy(struct rtgui_win* win)
rtgui_widget_destroy(RTGUI_WIDGET(win)); rtgui_widget_destroy(RTGUI_WIDGET(win));
} }
} }
RTM_EXPORT(rtgui_win_destroy);
/* send a close event to myself to get a consistent behavior */ /* send a close event to myself to get a consistent behavior */
rt_bool_t rtgui_win_close(struct rtgui_win* win) rt_bool_t rtgui_win_close(struct rtgui_win* win)
@ -227,6 +230,7 @@ rt_bool_t rtgui_win_close(struct rtgui_win* win)
(struct rtgui_event*)&eclose, (struct rtgui_event*)&eclose,
RT_FALSE); RT_FALSE);
} }
RTM_EXPORT(rtgui_win_close);
rt_base_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal) rt_base_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal)
{ {
@ -298,6 +302,7 @@ rt_base_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal)
return exit_code; return exit_code;
} }
RTM_EXPORT(rtgui_win_show);
void rtgui_win_end_modal(struct rtgui_win* win, rtgui_modal_code_t modal_code) void rtgui_win_end_modal(struct rtgui_win* win, rtgui_modal_code_t modal_code)
{ {
@ -309,6 +314,7 @@ void rtgui_win_end_modal(struct rtgui_win* win, rtgui_modal_code_t modal_code)
/* remove modal mode */ /* remove modal mode */
win->flag &= ~RTGUI_WIN_FLAG_MODAL; win->flag &= ~RTGUI_WIN_FLAG_MODAL;
} }
RTM_EXPORT(rtgui_win_end_modal);
void rtgui_win_hiden(struct rtgui_win* win) void rtgui_win_hiden(struct rtgui_win* win)
{ {
@ -333,6 +339,7 @@ void rtgui_win_hiden(struct rtgui_win* win)
win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE; win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
} }
} }
RTM_EXPORT(rtgui_win_hiden);
rt_err_t rtgui_win_activate(struct rtgui_win *win) rt_err_t rtgui_win_activate(struct rtgui_win *win)
{ {
@ -343,6 +350,7 @@ rt_err_t rtgui_win_activate(struct rtgui_win *win)
return rtgui_server_post_event_sync(RTGUI_EVENT(&eact), return rtgui_server_post_event_sync(RTGUI_EVENT(&eact),
sizeof(eact)); sizeof(eact));
} }
RTM_EXPORT(rtgui_win_activate);
rt_bool_t rtgui_win_is_activated(struct rtgui_win* win) rt_bool_t rtgui_win_is_activated(struct rtgui_win* win)
{ {
@ -352,6 +360,7 @@ rt_bool_t rtgui_win_is_activated(struct rtgui_win* win)
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_win_is_activated);
void rtgui_win_move(struct rtgui_win* win, int x, int y) void rtgui_win_move(struct rtgui_win* win, int x, int y)
{ {
@ -385,6 +394,7 @@ void rtgui_win_move(struct rtgui_win* win, int x, int y)
rtgui_widget_show(RTGUI_WIDGET(win)); rtgui_widget_show(RTGUI_WIDGET(win));
return; return;
} }
RTM_EXPORT(rtgui_win_move);
static rt_bool_t rtgui_win_ondraw(struct rtgui_win* win) static rt_bool_t rtgui_win_ondraw(struct rtgui_win* win)
{ {
@ -585,6 +595,7 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_object* object, struct rtgui_even
return RT_FALSE; return RT_FALSE;
} }
RTM_EXPORT(rtgui_win_event_handler);
void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect) void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect)
{ {
@ -604,6 +615,7 @@ void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect)
rtgui_server_post_event(&(event.parent), sizeof(struct rtgui_event_win_resize)); rtgui_server_post_event(&(event.parent), sizeof(struct rtgui_event_win_resize));
} }
} }
RTM_EXPORT(rtgui_win_set_rect);
void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler) void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler)
{ {
@ -612,6 +624,7 @@ void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler)
win->on_activate = handler; win->on_activate = handler;
} }
} }
RTM_EXPORT(rtgui_win_set_onactivate);
void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler) void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler)
{ {
@ -620,6 +633,7 @@ void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handle
win->on_deactivate = handler; win->on_deactivate = handler;
} }
} }
RTM_EXPORT(rtgui_win_set_ondeactivate);
void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler) void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler)
{ {
@ -628,6 +642,7 @@ void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler)
win->on_close = handler; win->on_close = handler;
} }
} }
RTM_EXPORT(rtgui_win_set_onclose);
void rtgui_win_set_onkey(rtgui_win_t* win, rtgui_event_handler_ptr handler) void rtgui_win_set_onkey(rtgui_win_t* win, rtgui_event_handler_ptr handler)
{ {
@ -636,6 +651,7 @@ void rtgui_win_set_onkey(rtgui_win_t* win, rtgui_event_handler_ptr handler)
win->on_key = handler; win->on_key = handler;
} }
} }
RTM_EXPORT(rtgui_win_set_onkey);
void rtgui_win_set_title(rtgui_win_t* win, const char *title) void rtgui_win_set_title(rtgui_win_t* win, const char *title)
{ {
@ -656,6 +672,7 @@ void rtgui_win_set_title(rtgui_win_t* win, const char *title)
win->title = rt_strdup(title); win->title = rt_strdup(title);
} }
} }
RTM_EXPORT(rtgui_win_set_title);
char* rtgui_win_get_title(rtgui_win_t* win) char* rtgui_win_get_title(rtgui_win_t* win)
{ {
@ -663,3 +680,5 @@ char* rtgui_win_get_title(rtgui_win_t* win)
return win->title; return win->title;
} }
RTM_EXPORT(rtgui_win_get_title);