提交 96049b7e 编写于 作者: qiuyiuestc's avatar qiuyiuestc

add module support for cortex-m3 feature

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1731 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 9bb329da
example:
1.edit rtconfig.py to config toolchain and bsp
2.scons --app=basicapp
3.copy basicapp/build/$bsp/basicapp.so to filesystem
import os
import sys
import SCons.cpp
import rtconfig
if os.getenv('RTT_ROOT'):
RTT_ROOT = os.getenv('RTT_ROOT')
else:
RTT_ROOT = os.path.normpath(os.getcwd() + '/../../..')
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
from building import *
Export('RTT_ROOT')
# add target option
AddOption('--app',
dest='app',
nargs=1, type='string',
action='store',
metavar='DIR',
help='installation prefix')
# add target option
AddOption('--type',
dest='type',
nargs=1, type='string',
action='store',
metavar='DIR',
help='installation prefix')
app = GetOption('app')
if GetOption('type') == 'ext':
linkflags = rtconfig.LFLAGS + ' -e 0'
else:
linkflags = rtconfig.LFLAGS + ' -e main'
env = Environment(tools = ['mingw'],
AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
CXX = rtconfig.CXX,
AR = rtconfig.AR, ARFLAGS = '-rc',
LINK = rtconfig.LINK, LINKFLAGS = linkflags,
CPPPATH = [
RTT_ROOT + '/include',
RTT_ROOT + '/bsp/' + rtconfig.BSP,
RTT_ROOT + '/components/finsh',
RTT_ROOT + '/components/rtgui/include',
RTT_ROOT + '/components/rgtui/common',
RTT_ROOT + '/components/rtgui/server',
RTT_ROOT + '/components/rtgui/widgets',
RTT_ROOT + '/components/libdl',
RTT_ROOT + '/components/external/ftk/ftk/src/os/rt-thread',
RTT_ROOT + '/components/external/ftk/ftk/src/demos',
RTT_ROOT + '/components/external/ftk/ftk/apps/common',
RTT_ROOT + '/components/external/ftk/ftk/src',
RTT_ROOT + '/components/dfs',
RTT_ROOT + '/components/dfs/include',
RTT_ROOT + '/components/libc/newlib',
RTT_ROOT + '/components/external/cairo/cairo-1.10.2/src',
RTT_ROOT + '/components/external/cairo/'
])
env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
PrepareModuleBuilding(env, RTT_ROOT)
dir = app + '/build/' + rtconfig.BSP
objs = SConscript(app + '/Sconscript', variant_dir=dir, duplicate=0)
TARGET = dir + '/' + app + '.' + rtconfig.TARGET_EXT
# build program
env.Program(TARGET, objs)
import os
import sys
EXEC_PATH = '/home/shaolin/CodeSourcery/Sourcery_G++_Lite/bin'
RTT_ROOT = os.path.normpath(os.getcwd() + '/../../..')
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
PREFIX = 'arm-none-eabi-'
env = Environment(tools = ['mingw'],
AS = PREFIX + 'gcc',
ASFLAGS = '',
CC = PREFIX + 'gcc',
CCFLAGS = '-mcpu=arm920t -O0 -fPIC' ,
AR = PREFIX + 'ar',
ARFLAGS = '-rc',
LINK = PREFIX + 'ld',
LINKFLAGS = '-z max-page-size=0x4 -shared -fPIC -e rt_application_init -nostdlib -s',
CPPPATH = [
RTT_ROOT + '/include',
RTT_ROOT + '/bsp/mini2440'
])
env.PrependENVPath('PATH', EXEC_PATH)
target = 'basicapp.so'
src = Glob('*.c')
env.Program(target, src)
import rtconfig
Import('RTT_ROOT')
from building import *
src = Glob('*.c')
group = DefineGroup('', src, depend = [''])
Return('group')
\ No newline at end of file
#include <rtthread.h> #include <rtthread.h>
int a = 0; static int a = 0;
int b = 1000000; static int b = 1000000;
int c = 0; int c = 100;
static void function(int count1, int count2, int count3) static void function(int count1, int count2, int count3)
{ {
rt_kprintf("Hello RT-Thread %d %d\n", count1, count2, count3); rt_kprintf("Hello RT-Thread %d %d\n", count1, count2, count3);
} }
int rt_application_init(void) int main(void)
{ {
int i; int i;
rt_kprintf("application entry\n"); rt_kprintf("application entry\n");
rt_kprintf("[addr]a-0x%x,b-0x%x,c-0x%x\n", &a, &b, &c);
rt_kprintf("[value]a-%d,b-%d,c-%d\n", a, b, c);
for(i=0; i<100; i++) for(i=0; i<100; i++)
{ {
a++; a++;
......
import os
import sys
EXEC_PATH = '/home/shaolin/CodeSourcery/Sourcery_G++_Lite/bin'
RTT_ROOT = os.path.normpath(os.getcwd() + '/../../..')
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
PREFIX = 'arm-none-eabi-'
env = Environment(tools = ['mingw'],
AS = PREFIX + 'gcc',
ASFLAGS = '',
CC = PREFIX + 'gcc',
CCFLAGS = '-mcpu=arm920t -O0 -fPIC' ,
AR = PREFIX + 'ar',
ARFLAGS = '-rc',
LINK = PREFIX + 'ld',
LINKFLAGS = '-z max-page-size=0x4 -shared -fPIC -e rt_application_init -nostdlib -s',
CPPPATH = [RTT_ROOT + '/include', RTT_ROOT + '/examples/module', RTT_ROOT + '/bsp/mini2440', RTT_ROOT + '/components/libdl'])
env.PrependENVPath('PATH', EXEC_PATH)
target = 'extapp.so'
src = Glob('extapp.c')
env.Program(target, src)
import rtconfig
Import('RTT_ROOT')
from building import *
src = Glob('*.c')
group = DefineGroup('', src, depend = [''])
Return('group')
\ No newline at end of file
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
typedef void (*func)(void); typedef void (*func)(void);
int rt_application_init(void) int main(void)
{ {
func f1, f2, f3, f4, f5; func f1, f2, f3, f4, f5;
......
Import('env')
Import('projects')
Import('RTT_ROOT')
Import('rtconfig')
Import('TARGET')
RTMLINKER = RTT_ROOT + '/tools/rtmlinker.exe '
# group definitions
group = {}
group['name'] = 'examples'
group['src'] = Glob('*.c')
group['CCFLAGS'] = ''
group['CPPPATH'] = [RTT_ROOT + '/include', RTT_ROOT + '/examples/module']
group['CPPDEFINES'] = ''
target = 'extension.so'
POST_ACTION = RTMLINKER + '-l ' + TARGET + ' -o extension.mo ' + '$TARGET'
# add group to project list
projects.append(group)
src_local = Glob('extension.c')
env.Append(CCFLAGS = group['CCFLAGS'])
env.Append(CPPPATH = group['CPPPATH'])
env.Append(CPPDEFINES = group['CPPDEFINES'])
module_env = env.Clone(CCFLAGS = ' -mcpu=arm920t -O0 -fPIC')
module_env.Replace(LINKFLAGS = '-z max-page-size=0x4 -shared -fPIC -e 0 -nostdlib -s')
module_env.Program(target, src_local)
module_env.AddPostAction(target, POST_ACTION)
import os
import sys
EXEC_PATH = '/home/shaolin/CodeSourcery/Sourcery_G++_Lite/bin'
RTT_ROOT = os.path.normpath(os.getcwd() + '/../../..')
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
PREFIX = 'arm-none-eabi-'
env = Environment(tools = ['mingw'],
AS = PREFIX + 'gcc',
ASFLAGS = '',
CC = PREFIX + 'gcc',
CCFLAGS = '-mcpu=arm920t -O0 -fPIC' ,
AR = PREFIX + 'ar',
ARFLAGS = '-rc',
LINK = PREFIX + 'ld',
LINKFLAGS = '-z max-page-size=0x4 -shared -fPIC -e 0 -nostdlib -s',
CPPPATH = [
RTT_ROOT + '/include',
RTT_ROOT + '/bsp/mini2440'
])
env.PrependENVPath('PATH', EXEC_PATH)
target = 'extension.so'
src = Glob('*.c')
env.Program(target, src)
#include <rtthread.h>
#include <rtm.h>
void function1(void)
{
rt_kprintf("Hello RT-Thread function1\n");
}
void function2(void)
{
rt_kprintf("Hello RT-Thread function2\n");
}
void function3(void)
{
rt_kprintf("Hello RT-Thread function3\n");
}
void function4(void)
{
rt_kprintf("Hello RT-Thread function4\n");
}
void function5(void)
{
rt_kprintf("Hello RT-Thread function5\n");
}
RTM_EXPORT(function1)
RTM_EXPORT(function2)
RTM_EXPORT(function3)
RTM_EXPORT(function4)
RTM_EXPORT(function5)
\ No newline at end of file
import os
import sys
EXEC_PATH = '/home/shaolin/CodeSourcery/Sourcery_G++_Lite/bin'
RTT_ROOT = os.path.normpath(os.getcwd() + '/../../../..')
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
PREFIX = 'arm-none-eabi-'
env = Environment(tools = ['mingw'],
AS = PREFIX + 'gcc',
ASFLAGS = '',
CC = PREFIX + 'gcc',
CCFLAGS = '-DRT_THREAD -DFTK_AS_PLUGIN -mcpu=arm920t -O0 -fPIC' ,
AR = PREFIX + 'ar',
ARFLAGS = '-rc',
LINK = PREFIX + 'ld',
LINKFLAGS = '-z max-page-size=0x4 -shared -fPIC -e 0 -nostdlib -s',
CPPPATH = [
RTT_ROOT + '/include',
RTT_ROOT + '/bsp/mini2440',
RTT_ROOT + '/components/external/ftk/ftk/src/os/rt-thread',
RTT_ROOT + '/components/external/ftk/ftk/src/demos',
RTT_ROOT + '/components/external/ftk/ftk/apps/common',
RTT_ROOT + '/components/external/ftk/ftk/src',
RTT_ROOT + '/components/dfs',
RTT_ROOT + '/components/dfs/include',
RTT_ROOT + '/components/libc/newlib'
])
env.PrependENVPath('PATH', EXEC_PATH)
target = 'calculator.so'
src = Glob('*.c')
env.Program(target, src)
<applications>
<application name="calc" exec="/ftk/apps/calculator.so" init="ftk_app_calc_create" />
</applications>
#include "ftk_xul.h"
#include "ftk_expr.h"
#include "ftk_app_calc.h"
typedef struct _PrivInfo
{
FtkBitmap* icon;
}PrivInfo;
#define IDC_ENTRY 100
static Ret ftk_calc_on_button_clicked(void* ctx, void* obj);
const char* ftk_translate_path(const char* path, char out_path[FTK_MAX_PATH+1])
{
snprintf(out_path, FTK_MAX_PATH, "%s/%s", APP_DATA_DIR, path);
if(access(out_path, R_OK) < 0)
{
snprintf(out_path, FTK_MAX_PATH, "%s/%s", APP_LOCAL_DATA_DIR, path);
}
ftk_logd("%s->%s\n", path, out_path);
return out_path;
}
const char* buttons[] =
{
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
".",
"+",
"-",
"*",
"/",
"(",
")",
"=",
"<--",
"Quit"
};
static FtkWidget* ftk_calc_create_window(void)
{
int i = 0;
int j = 0;
int x = 0;
int y = 0;
int row = 0;
int col = 0;
int small = 0;
int xoffset = 0;
int yoffset = 0;
int width = 0;
int height = 0;
int v_margin = 5;
int h_margin = 5;
int item_width = 0;
int item_height = 0;
FtkGc gc = {0};
FtkWidget* entry = NULL;
FtkWidget* button = NULL;
FtkBitmap* bitmap_normal = NULL;
FtkBitmap* bitmap_active = NULL;
FtkBitmap* bitmap_focus = NULL;
char path[FTK_MAX_PATH+1] = {0};
FtkWidget* win = ftk_app_window_create();
ftk_window_set_animation_hint(win, "app_main_window");
width = ftk_widget_width(win);
height = ftk_widget_height(win);
entry = ftk_entry_create(win, 0, 0, width, 30);
ftk_widget_set_id(entry, IDC_ENTRY);
height -= ftk_widget_height(entry);
row = width > height ? 4 : 5;
col = width > height ? 5 : 4;
item_width = width / col;
item_height = height /row;
small = (item_width < 60 || item_height < 60) ? 1 : 0;
item_width = item_height = small ? 36 : 60;
h_margin = width/col - item_width;
h_margin = h_margin > 5 ? 5 : h_margin;
v_margin = height/row - item_height;
v_margin = v_margin > 5 ? 5 : v_margin;
xoffset = (width - (h_margin + item_width) * col) >> 1;
yoffset = (height - (v_margin + item_height) * row) >> 1;
xoffset = xoffset < 0 ? 0 : xoffset;
yoffset = yoffset < 0 ? 0 : yoffset;
yoffset += ftk_widget_height(entry);
gc.mask = FTK_GC_BITMAP;
if(small)
{
bitmap_normal = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-small.png", path));
bitmap_active = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-pressed-small.png", path));
bitmap_focus = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-selected-small.png", path));
}
else
{
bitmap_normal = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button.png", path));
bitmap_active = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-pressed.png", path));
bitmap_focus = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), ftk_translate_path("icons/button-selected.png", path));
}
for(i = 0; i < row; i++)
{
y = yoffset + i * (item_height + v_margin);
for(j = 0; j < col; j++)
{
const char* text = buttons[i * col + j];
if(text != NULL)
{
x = xoffset + j * (item_width + h_margin);
button = ftk_button_create(win, x, y, item_width, item_height);
ftk_widget_set_text(button, text);
ftk_button_set_clicked_listener(button, ftk_calc_on_button_clicked, win);
gc.bitmap = bitmap_normal;
ftk_widget_set_gc(button, FTK_WIDGET_NORMAL, &gc);
gc.bitmap = bitmap_focus;
ftk_widget_set_gc(button, FTK_WIDGET_FOCUSED, &gc);
gc.bitmap = bitmap_active;
ftk_widget_set_gc(button, FTK_WIDGET_ACTIVE, &gc);
}
}
}
ftk_bitmap_unref(bitmap_normal);
ftk_bitmap_unref(bitmap_active);
ftk_bitmap_unref(bitmap_focus);
return win;
}
static Ret ftk_calc_on_shutdown(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
static Ret ftk_calc_on_prepare_options_menu(void* ctx, FtkWidget* menu_panel)
{
FtkWidget* item = ftk_menu_item_create(menu_panel);
ftk_widget_set_text(item, _("Quit"));
ftk_menu_item_set_clicked_listener(item, ftk_calc_on_shutdown, ctx);
ftk_widget_show(item, 1);
return RET_OK;
}
static Ret ftk_calc_on_button_clicked(void* ctx, void* obj)
{
FtkWidget* entry = ftk_widget_lookup(ctx, IDC_ENTRY);
const char* text = ftk_widget_get_text(obj);
return_val_if_fail(text != NULL && entry != NULL, RET_FAIL);
if(text[0] == '=')
{
char buff[32] = {0};
double val = ftk_expr_eval(ftk_entry_get_text(entry));
ftk_snprintf(buff, sizeof(buff), "%lf", val);
ftk_entry_set_text(entry, buff);
}
else if(text[0] == '<')
{
ftk_entry_set_text(entry, "");
}
else if(text[0] == 'Q' || strcmp(text, _("Quit")) == 0)
{
ftk_widget_unref(ctx);
}
else
{
ftk_entry_insert_text(entry, -1, text);
}
return RET_OK;
}
static FtkBitmap* ftk_app_calc_get_icon(FtkApp* thiz)
{
DECL_PRIV(thiz, priv);
const char* name="calc.png";
char file_name[FTK_MAX_PATH + 1] = {0};
return_val_if_fail(priv != NULL, NULL);
if(priv->icon != NULL) return priv->icon;
snprintf(file_name, FTK_MAX_PATH, "%s/icons/%s", APP_DATA_DIR, name);
priv->icon = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), file_name);
if(priv->icon != NULL) return priv->icon;
snprintf(file_name, FTK_MAX_PATH, "%s/icons/%s", APP_LOCAL_DATA_DIR, name);
priv->icon = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), file_name);
return priv->icon;
}
static const char* ftk_app_calc_get_name(FtkApp* thiz)
{
return _("Calculator");
}
static Ret ftk_app_calc_run(FtkApp* thiz, int argc, char* argv[])
{
DECL_PRIV(thiz, priv);
FtkWidget* win = NULL;
return_val_if_fail(priv != NULL, RET_FAIL);
win = ftk_calc_create_window();
ftk_app_window_set_on_prepare_options_menu(win, ftk_calc_on_prepare_options_menu, win);
ftk_widget_show_all(win, 1);
#ifdef HAS_MAIN
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
#endif
return RET_OK;
}
static void ftk_app_calc_destroy(FtkApp* thiz)
{
if(thiz != NULL)
{
DECL_PRIV(thiz, priv);
ftk_bitmap_unref(priv->icon);
FTK_FREE(thiz);
}
return;
}
FtkApp* ftk_app_calc_create(void)
{
FtkApp* thiz = FTK_ZALLOC(sizeof(FtkApp) + sizeof(PrivInfo));
if(thiz != NULL)
{
thiz->run = ftk_app_calc_run;
thiz->get_icon = ftk_app_calc_get_icon;
thiz->get_name = ftk_app_calc_get_name;
thiz->destroy = ftk_app_calc_destroy;
}
return thiz;
}
#ifndef FTK_APP_CALC_H
#define FTK_APP_CALC_H
#include "ftk_app.h"
FTK_BEGIN_DECLS
FtkApp* ftk_app_calc_create(void);
FTK_END_DECLS
#endif/*FTK_APP_CALC_H*/
import os
import sys
EXEC_PATH = '/home/shaolin/CodeSourcery/Sourcery_G++_Lite/bin'
RTT_ROOT = os.path.normpath(os.getcwd() + '/../../../..')
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
PREFIX = 'arm-none-eabi-'
env = Environment(tools = ['mingw'],
AS = PREFIX + 'gcc',
ASFLAGS = '',
CC = PREFIX + 'gcc',
CCFLAGS = '-DRT_THREAD -DFTK_AS_PLUGIN -mcpu=arm920t -O0 -fPIC' ,
AR = PREFIX + 'ar',
ARFLAGS = '-rc',
LINK = PREFIX + 'ld',
LINKFLAGS = '-z max-page-size=0x4 -shared -fPIC -e 0 -nostdlib -s',
CPPPATH = [
RTT_ROOT + '/include',
RTT_ROOT + '/bsp/mini2440',
RTT_ROOT + '/components/external/ftk/ftk/src/os/rt-thread',
RTT_ROOT + '/components/external/ftk/ftk/src/demos',
RTT_ROOT + '/components/external/ftk/ftk/apps/common',
RTT_ROOT + '/components/external/ftk/ftk/src',
RTT_ROOT + '/components/dfs',
RTT_ROOT + '/components/dfs/include',
RTT_ROOT + '/components/libc/newlib'
])
env.PrependENVPath('PATH', EXEC_PATH)
target = 'libftk_demos.so'
src = Glob('*.c')
env.Program(target, src)
#include "ftk.h"
#define IDC_TEST_BUTTON 1000
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
static Ret button_hide_clicked(void* ctx, void* obj)
{
ftk_widget_show(ftk_widget_lookup(ctx, IDC_TEST_BUTTON), 0);
return RET_OK;
}
static Ret button_show_clicked(void* ctx, void* obj)
{
ftk_widget_show(ftk_widget_lookup(ctx, IDC_TEST_BUTTON), 1);
return RET_OK;
}
static Ret button_default_clicked(void* ctx, void* obj)
{
printf("%s: button %s is clicked.\n", __func__, ftk_widget_get_text(obj));
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_button_create()
{
return ftk_app_demo_create(_("button"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
ftk_window_set_animation_hint(win, "app_main_window");
width = ftk_widget_width(win);
height = ftk_widget_height(win);
width = width/3 - 10;
button = ftk_button_create(win, 0, 30, width, 50);
ftk_widget_set_text(button, "show");
ftk_button_set_clicked_listener(button, button_show_clicked, win);
button = ftk_button_create(win, width + 10, 30, width, 50);
ftk_widget_set_text(button, "hide");
ftk_button_set_clicked_listener(button, button_hide_clicked, win);
button = ftk_button_create(win, 2*(width + 10), 30, width, 50);
ftk_widget_set_text(button, "按钮测试");
ftk_widget_set_id(button, IDC_TEST_BUTTON);
ftk_button_set_clicked_listener(button, button_default_clicked, win);
button = ftk_button_create(win, 0, 130, width, 40);
ftk_widget_set_text(button, "yes");
ftk_button_set_clicked_listener(button, button_default_clicked, win);
button = ftk_button_create(win, 2*(width + 10), 130, width, 40);
ftk_widget_set_text(button, "no");
ftk_button_set_clicked_listener(button, button_default_clicked, win);
button = ftk_button_create(win, width + 10, height/2, width, 60);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
ftk_window_set_focus(win, button);
ftk_widget_set_text(win, "button demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
static Ret button_clicked(void* ctx, void* obj)
{
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_check_button_create()
{
return ftk_app_demo_create(_("check_button"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FtkWidget* group = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
ftk_window_set_animation_hint(win, "app_main_window");
width = ftk_widget_width(win);
height = ftk_widget_height(win);
width = width/2 - 10;
button = ftk_check_button_create(win,0, 10, width, 50);
ftk_widget_set_text(button, "show");
ftk_check_button_set_clicked_listener(button, button_clicked, win);
button = ftk_check_button_create(win, width + 10, 10, width, 50);
ftk_widget_set_text(button, "hide");
ftk_check_button_set_clicked_listener(button, button_clicked, win);
group = ftk_radio_group_create(win, 0, 60, 2 * width, 60);
button = ftk_check_button_create_radio(group,0, 10, width, 50);
ftk_widget_set_text(button, "Male");
ftk_check_button_set_clicked_listener(button, button_clicked, win);
button = ftk_check_button_create_radio(group, width + 10, 10, width, 50);
ftk_widget_set_text(button, "Female");
ftk_check_button_set_clicked_listener(button, button_clicked, win);
group = ftk_radio_group_create(win, 0, 120, 2 * width, 60);
button = ftk_check_button_create_radio(group,0, 10, width, 50);
ftk_widget_set_text(button, "1(图标右)");
ftk_check_button_set_icon_position(button, 1);
ftk_check_button_set_clicked_listener(button, button_clicked, win);
button = ftk_check_button_create_radio(group, width + 10, 10, width, 50);
ftk_widget_set_text(button, "2(图标右)");
ftk_check_button_set_icon_position(button, 1);
ftk_check_button_set_clicked_listener(button, button_clicked, win);
button = ftk_button_create(win, width/2, 3*height/4, width, 60);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
ftk_window_set_focus(win, button);
ftk_widget_set_text(win, "check button demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
#define IDC_TEST_BUTTON 1000
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_combo_box_create()
{
return ftk_app_demo_create(_("combo_box"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FtkWidget* combo_box = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
ftk_window_set_animation_hint(win, "app_main_window");
width = ftk_widget_width(win);
height = ftk_widget_height(win);
width = width/2 - 10;
combo_box = ftk_combo_box_create(win, 0, height/4, width, 50);
ftk_combo_box_set_text(combo_box, "1 second");
ftk_combo_box_append(combo_box, NULL, "1 second");
ftk_combo_box_append(combo_box, NULL, "2 seconds");
ftk_combo_box_append(combo_box, NULL, "3 seconds");
combo_box = ftk_combo_box_create(win, width + 10, height/4, width, 50);
ftk_combo_box_set_text(combo_box, "1 second");
ftk_combo_box_append(combo_box, NULL, "1 second");
ftk_combo_box_append(combo_box, NULL, "2 seconds");
ftk_combo_box_append(combo_box, NULL, "3 seconds");
ftk_combo_box_append(combo_box, NULL, "4 seconds");
ftk_combo_box_append(combo_box, NULL, "5 seconds");
ftk_combo_box_append(combo_box, NULL, "6 seconds");
ftk_combo_box_append(combo_box, NULL, "7 seconds");
ftk_combo_box_append(combo_box, NULL, "8 seconds");
ftk_combo_box_append(combo_box, NULL, "9 seconds");
ftk_combo_box_append(combo_box, NULL, "0 seconds");
ftk_combo_box_append(combo_box, NULL, "0 seconds");
button = ftk_button_create(win, width/2, height/2, width, 60);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
ftk_window_set_focus(win, button);
combo_box = ftk_combo_box_create(win, 0, 3*height/4+5, width, 50);
ftk_combo_box_set_text(combo_box, "1 second");
ftk_combo_box_append(combo_box, NULL, "1 second");
ftk_combo_box_append(combo_box, NULL, "2 seconds");
ftk_combo_box_append(combo_box, NULL, "3 seconds");
combo_box = ftk_combo_box_create(win, width + 10, 3*height/4+5, width, 50);
ftk_combo_box_set_text(combo_box, "1 second");
ftk_combo_box_append(combo_box, NULL, "1 second");
ftk_combo_box_append(combo_box, NULL, "2 seconds");
ftk_combo_box_append(combo_box, NULL, "3 seconds");
ftk_combo_box_append(combo_box, NULL, "4 seconds");
ftk_combo_box_append(combo_box, NULL, "5 seconds");
ftk_combo_box_append(combo_box, NULL, "6 seconds");
ftk_combo_box_append(combo_box, NULL, "7 seconds");
ftk_combo_box_append(combo_box, NULL, "8 seconds");
ftk_combo_box_append(combo_box, NULL, "9 seconds");
ftk_combo_box_append(combo_box, NULL, "0 seconds");
ftk_combo_box_append(combo_box, NULL, "0 seconds");
ftk_widget_set_text(win, "ComboBox Demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_dialog_create()
{
return ftk_app_demo_create(_("dialog"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
static Ret button_quit_clicked(void* ctx, void* obj)
{
if(ctx != NULL)
{
/*modal*/
*(int*)ctx = ftk_widget_id(obj);
}
else
{
/*modal-less*/
ftk_widget_unref(ftk_widget_toplevel(obj));
}
return RET_QUIT;
}
static Ret button_close_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
static Ret button_dialog_clicked(void* ctx, void* obj)
{
int id = 0;
int width = 0;
int height = 0;
FtkWidget* label = NULL;
FtkWidget* button = NULL;
FtkWidget* dialog = NULL;
FtkBitmap* icon = NULL;
int modal = (int)ctx;
ftk_logd("%s:%d begin\n", __func__, __LINE__);
dialog = ftk_dialog_create(0, 40, 320, 240);
icon = ftk_theme_load_image(ftk_default_theme(), "info-icon"FTK_STOCK_IMG_SUFFIX);
ftk_dialog_set_icon(dialog, icon);
width = ftk_widget_width(dialog);
height = ftk_widget_height(dialog);
label = ftk_label_create(dialog, width/6, height/4, 5*width/6, 20);
ftk_widget_set_text(label, "Are you sure to quit?");
button = ftk_button_create(dialog, width/6, height/2, width/3, 50);
ftk_widget_set_text(button, "yes");
ftk_button_set_clicked_listener(button, button_quit_clicked, modal ? &id : NULL);
button = ftk_button_create(dialog, width/2, height/2, width/3, 50);
ftk_widget_set_text(button, "no");
ftk_button_set_clicked_listener(button, button_quit_clicked, modal ? &id : NULL);
ftk_window_set_focus(dialog, button);
ftk_widget_set_text(dialog, modal ? "model dialog" : "normal dialog");
ftk_widget_show_all(dialog, 1);
if(modal)
{
assert(ftk_dialog_run(dialog) == id);
ftk_widget_unref(dialog);
}
else
{
ftk_widget_show_all(dialog, 1);
}
ftk_logd("%s:%d end\n", __func__, __LINE__);
return RET_OK;
}
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
ftk_window_set_animation_hint(win, "app_main_window");
width = ftk_widget_width(win);
height = ftk_widget_height(win);
button = ftk_button_create(win, 0, height/6, width/3, 50);
ftk_widget_set_text(button, "Normal");
ftk_button_set_clicked_listener(button, button_dialog_clicked, NULL);
button = ftk_button_create(win, 2*width/3, height/6, width/3, 50);
ftk_widget_set_text(button, "Modal");
ftk_button_set_clicked_listener(button, button_dialog_clicked, (void*)1);
button = ftk_button_create(win, width/4, height/2, width/2, 60);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_close_clicked, win);
ftk_widget_set_text(win, "demo dialog");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_logd("%s: %s\n", __func__, ftk_widget_get_text(ftk_widget_lookup(ctx, 100)));
ftk_widget_unref(ctx);
return RET_OK;
}
static Ret ftk_digit_only_filter(void* ctx, void* data)
{
FtkEvent* event = data;
if(event->type == FTK_EVT_KEY_UP || event->type == FTK_EVT_KEY_DOWN)
{
int code = event->u.key.code;
if(code >= FTK_KEY_0 && code <= FTK_KEY_9)
{
return RET_OK;
}
else if(code == FTK_KEY_UP
|| code == FTK_KEY_DOWN
|| code == FTK_KEY_LEFT
|| code == FTK_KEY_RIGHT
|| code == FTK_KEY_BACKSPACE
|| code == FTK_KEY_DELETE
|| code == FTK_KEY_HOME
|| code == FTK_KEY_END
|| code == FTK_KEY_TAB)
{
return RET_OK;
}
return RET_REMOVE;
}
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_entry_create()
{
return ftk_app_demo_create(_("entry"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
#define STR_TEXT1 "Single line editor, that means you can input a one line only."
#define STR_TEXT2 "Single line editor, 也就是说你只能输入一行文字."
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FtkWidget* entry = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
ftk_window_set_animation_hint(win, "app_main_window");
width = ftk_widget_width(win);
height = ftk_widget_height(win);
entry = ftk_entry_create(win, 10, 30, ftk_widget_width(win) - 20, 30);
ftk_widget_set_id(entry, 100);
ftk_widget_set_text(entry, "1234");
ftk_widget_set_event_listener(entry, ftk_digit_only_filter, NULL);
ftk_entry_set_tips(entry, "Please input some digits.");
entry = ftk_entry_create(win, 10, 80, ftk_widget_width(win) - 20, 30);
ftk_widget_set_text(entry, STR_TEXT1);
assert(strcmp(STR_TEXT1, ftk_widget_get_text(entry)) == 0);
entry = ftk_entry_create(win, 10, 130, ftk_widget_width(win) - 20, 30);
ftk_widget_set_text(entry, STR_TEXT2);
assert(strcmp(STR_TEXT2, ftk_widget_get_text(entry)) == 0);
button = ftk_button_create(win, width/4, 3*height/4, width/2, 60);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
ftk_window_set_focus(win, button);
ftk_widget_set_text(win, "entry demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
#include "ftk_file_browser.h"
static Ret on_file_selected(void* ctx, int index, const char* path)
{
ftk_logd("%s: [%d] %s\n", __func__, index, path);
return RET_OK;
}
#define IDC_TEST_BUTTON 1000
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
static Ret button_browser_clicked(void* ctx, void* obj)
{
FtkWidget* win = ftk_file_browser_create(FTK_FILE_BROWER_APP);
ftk_file_browser_set_path(win, "./");
ftk_file_browser_load(win);
return RET_OK;
}
static Ret button_single_choose_clicked(void* ctx, void* obj)
{
FtkWidget* win = ftk_file_browser_create(FTK_FILE_BROWER_SINGLE_CHOOSER);
ftk_file_browser_set_choosed_handler(win, on_file_selected, NULL);
ftk_file_browser_set_path(win, "./");
ftk_file_browser_load(win);
return RET_OK;
}
static Ret button_multi_choose_clicked(void* ctx, void* obj)
{
FtkWidget* win = ftk_file_browser_create(FTK_FILE_BROWER_MULTI_CHOOSER);
ftk_file_browser_set_choosed_handler(win, on_file_selected, NULL);
ftk_file_browser_set_path(win, "./");
ftk_file_browser_load(win);
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_file_browser_create()
{
return ftk_app_demo_create(_("file_browser"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
ftk_window_set_animation_hint(win, "app_main_window");
width = ftk_widget_width(win);
height = ftk_widget_height(win);
width = width/2 - 10;
button = ftk_button_create(win, 0, height/4, width, 50);
ftk_widget_set_text(button, "Single Choose");
ftk_button_set_clicked_listener(button, button_single_choose_clicked, win);
button = ftk_button_create(win, width + 10, height/4, width, 50);
ftk_widget_set_text(button, "Browser");
ftk_button_set_clicked_listener(button, button_browser_clicked, win);
button = ftk_button_create(win, 0, height/2, width, 50);
ftk_widget_set_text(button, "Multi Choose");
ftk_button_set_clicked_listener(button, button_multi_choose_clicked, win);
button = ftk_button_create(win, width + 10, height/2, width, 50);
ftk_widget_set_text(button, "Quit");
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
ftk_window_set_focus(win, button);
ftk_widget_set_text(win, "FileBrowser");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
static Ret on_prepare_options_menu(void* ctx, FtkWidget* menu_panel)
{
int i = 0;
for(i = 0; i < 3; i++)
{
char text[32] = {0};
FtkWidget* item = ftk_menu_item_create(menu_panel);
ftk_snprintf(text, sizeof(text), "Menu%02d", i);
ftk_widget_set_text(item, text);
ftk_widget_show(item, 1);
}
return i > 0 ? RET_OK : RET_FAIL;
}
#define IDC_TEST_BUTTON 1000
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
static const char* buttons[] = {"OK", NULL};
static Ret button_unfullscreen_clicked(void* ctx, void* obj)
{
if(!ftk_window_is_fullscreen(ctx))
{
ftk_infomation("Infomation", "Windows is not fullscreen.", buttons);
}
else
{
ftk_window_set_fullscreen(ctx, 0);
}
return RET_OK;
}
static Ret button_fullscreen_clicked(void* ctx, void* obj)
{
if(ftk_window_is_fullscreen(ctx))
{
ftk_infomation("Infomation", "Windows is fullscreen.", buttons);
}
else
{
ftk_window_set_fullscreen(ctx, 1);
}
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_fullscreen_create()
{
return ftk_app_demo_create(_("fullscreen"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
ftk_window_set_animation_hint(win, "app_main_window");
width = ftk_widget_width(win);
height = ftk_widget_height(win);
width = width/2 - 10;
button = ftk_button_create(win, 0, height/4, width, 50);
ftk_widget_set_text(button, "Fullscreen");
ftk_button_set_clicked_listener(button, button_fullscreen_clicked, win);
button = ftk_button_create(win, width + 10, height/4, width, 50);
ftk_widget_set_text(button, "Unfullscreen");
ftk_button_set_clicked_listener(button, button_unfullscreen_clicked, win);
button = ftk_button_create(win, width/2, height/2, width, 60);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
ftk_window_set_focus(win, button);
ftk_widget_set_text(win, "fullscreen");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
ftk_app_window_set_on_prepare_options_menu(win, on_prepare_options_menu, win);
FTK_RUN();
return 0;
}
#include "ftk.h"
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_hello_create()
{
return ftk_app_demo_create(_("hello"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
FtkWidget* win = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
ftk_window_set_animation_hint(win, "app_main_window");
ftk_widget_set_text(win, "Hello FTK!");
ftk_widget_show(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
#define IDC_TEST_BUTTON 1000
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
static int i = 0;
static Ret button_more_clicked(void* ctx, void* obj)
{
int j = 0;
FtkIconViewItem item;
FtkWidget* icon_view = ftk_widget_lookup(ctx, 100);
item.icon = ftk_theme_load_image(ftk_default_theme(), "flag-32.png");
for(j=0; j < 4; j++)
{
char text[100] = {0};
ftk_snprintf(text, sizeof(text), "%d", i);
item.text = text;
ftk_bitmap_ref(item.icon);
item.user_data = (void*)i;
ftk_icon_view_add(icon_view, &item);
i+=1000;
}
ftk_bitmap_unref(item.icon);
return RET_OK;
}
static Ret item_clicked(void* ctx, void* obj)
{
FtkIconViewItem* item = obj;
ftk_logd("%s: %s: user_data=%d\n", __func__, item->text, item->user_data);
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_icon_view_create()
{
return ftk_app_demo_create(_("icon_view"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FtkWidget* icon_view = NULL;
FtkIconViewItem item;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
ftk_window_set_animation_hint(win, "app_main_window");
width = ftk_widget_width(win);
height = ftk_widget_height(win);
button = ftk_button_create(win, 10, 0, width/3-10, 60);
ftk_widget_set_text(button, "more");
ftk_button_set_clicked_listener(button, button_more_clicked, win);
ftk_window_set_focus(win, button);
button = ftk_button_create(win, 2*width/3, 0, width/3-10, 60);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
ftk_window_set_focus(win, button);
item.icon = ftk_theme_load_image(ftk_default_theme(), "flag-32.png");
icon_view = ftk_icon_view_create(win, 5, 70, width-10, height-80);
ftk_widget_set_id(icon_view, 100);
ftk_icon_view_set_clicked_listener(icon_view, item_clicked, win);
for(; i < 4; i++)
{
char text[100] = {0};
ftk_snprintf(text, sizeof(text), "%d", i);
item.text = text;
item.user_data = (void*)i;
ftk_icon_view_add(icon_view, &item);
}
ftk_bitmap_unref(item.icon);
ftk_widget_set_text(win, "icon view demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_image_create()
{
return ftk_app_demo_create(_("image"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
FtkWidget* image = NULL;
FtkWidget* win = NULL;
char filename[FTK_MAX_PATH+1] = {0};
FTK_INIT(argc, argv);
win = ftk_app_window_create();
ftk_window_set_animation_hint(win, "app_main_window");
ftk_snprintf(filename, FTK_MAX_PATH, "%s/earth.png",
ftk_config_get_test_data_dir(ftk_default_config()));
image = ftk_image_create(win, 0, 0, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
ftk_image_set_image(image,
ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
ftk_snprintf(filename, FTK_MAX_PATH, "%s/png_RGB_tRNS.png",
ftk_config_get_test_data_dir(ftk_default_config()));
image = ftk_image_create(win, 0, 0, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
ftk_image_set_image(image,
ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
ftk_widget_set_attr(image, FTK_ATTR_TRANSPARENT);
ftk_snprintf(filename, FTK_MAX_PATH, "%s/Calculator.png",
ftk_config_get_test_data_dir(ftk_default_config()));
image = ftk_image_create(win, ftk_widget_width(win)/2, 0, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
ftk_image_set_image(image,
ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
ftk_widget_set_attr(image, FTK_ATTR_BG_TILE);
ftk_snprintf(filename, FTK_MAX_PATH, "%s/t8.bmp",
ftk_config_get_test_data_dir(ftk_default_config()));
image = ftk_image_create(win, 0, ftk_widget_height(win)/2, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
ftk_image_set_image(image,
ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
ftk_widget_set_attr(image, FTK_ATTR_BG_CENTER);
ftk_snprintf(filename, FTK_MAX_PATH, "%s/jpeg1.jpg",
ftk_config_get_test_data_dir(ftk_default_config()));
image = ftk_image_create(win, ftk_widget_width(win)/2, ftk_widget_height(win)/2, ftk_widget_width(win)/2, ftk_widget_height(win)/2);
ftk_image_set_image(image,
ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename));
ftk_widget_set_attr(image, FTK_ATTR_BG_TILE);
ftk_widget_set_text(win, "image demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
const char* pngs[] =
{
"/Camera.png",
"/Notes.png",
"/RSS.png",
"/Calculator.png",
"/Twitter.png",
"/Clock.png",
"/Games.png",
"/Youtube.png",
"/AIM.png",
"/LastFm.png",
"/IP.png",
"/Acrobat.png",
"/Settings.png",
"/App",
"/Customize.png",
"/Skype.png",
"/Linkedin.png",
"/Calender.png",
"/Call.png",
"/Install.png",
"/Facebook.png",
"/iPod.png",
"/Chat.png",
"/WLM.png",
"/Flickr.png",
"/Photos.png",
"/Stock.png",
"/Delicious.png",
"/Maps.png",
"/iTunes.png",
"/Memory.png",
"/Weather.png",
"/Wordpress.png",
"/iradio.png",
"/Safari.png",
"/Google.png",
"/Yahoo.png",
"/VLC.png",
"/Sms.png",
"/Mail.png",
NULL
};
static Ret button_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_image_button_create()
{
return ftk_app_demo_create(_("image_button"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int i = 0;
int j = 0;
int width = 0;
int height = 0;
char filename[FTK_MAX_PATH] = {0};
FtkGc gc = {0};
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FTK_INIT(argc, argv);
gc.mask = FTK_GC_BITMAP;
win = ftk_app_window_create();
ftk_window_set_animation_hint(win, "app_main_window");
width = ftk_widget_width(win);
height = ftk_widget_height(win);
for(i = 0; i < height/80; i++)
{
for(j = 0; j < width/80; j++)
{
ftk_snprintf(filename, sizeof(filename), "%s%s",
ftk_config_get_test_data_dir(ftk_default_config()), pngs[i + 2]);
gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
button = ftk_button_create(win, j * 80, i * 80, ftk_bitmap_width(gc.bitmap), ftk_bitmap_height(gc.bitmap));
if(i == 0)
{
ftk_widget_unset_attr(button, FTK_ATTR_TRANSPARENT);
}
ftk_widget_set_gc(button, FTK_WIDGET_NORMAL, &gc);
ftk_bitmap_unref(gc.bitmap);
ftk_snprintf(filename, sizeof(filename), "%s%s",
ftk_config_get_test_data_dir(ftk_default_config()), pngs[1]);
gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
ftk_widget_set_gc(button, FTK_WIDGET_FOCUSED, &gc);
ftk_bitmap_unref(gc.bitmap);
ftk_snprintf(filename, sizeof(filename), "%s%s",
ftk_config_get_test_data_dir(ftk_default_config()), pngs[0]);
gc.bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
ftk_widget_set_gc(button, FTK_WIDGET_ACTIVE, &gc);
ftk_bitmap_unref(gc.bitmap);
if(i == 0 && j == 0)
{
ftk_button_set_clicked_listener(button, button_clicked, win);
ftk_widget_set_text(button, "Quit");
}
}
}
ftk_widget_set_text(win, "image button demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_ime_create()
{
return ftk_app_demo_create(_("ime"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FtkWidget* entry = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
ftk_window_set_animation_hint(win, "app_main_window");
width = ftk_widget_width(win);
height = ftk_widget_height(win);
entry = ftk_entry_create(win, 10, 30, ftk_widget_width(win) - 20, 30);
ftk_entry_set_text(entry, "Single line editor");
ftk_input_method_manager_set_current(ftk_default_input_method_manager(), 0);
entry = ftk_entry_create(win, 10, 80, ftk_widget_width(win) - 20, 30);
ftk_entry_set_text(entry, "Single line editor, that means you can input a one line only.");
entry = ftk_entry_create(win, 10, 130, ftk_widget_width(win) - 20, 30);
ftk_entry_set_text(entry, "Single line editor, 也就是说你只能输入一行文字.");
button = ftk_button_create(win, width/4, height/2, width/2, 60);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
ftk_window_set_focus(win, button);
entry = ftk_entry_create(win, 10, height-60, ftk_widget_width(win) - 20, 30);
ftk_entry_set_text(entry, "Single line editor");
ftk_widget_set_text(win, "entry demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
typedef struct _TimerInfo
{
int times;
FtkWidget* label;
}TimerInfo;
static Ret timeout(void* ctx)
{
TimerInfo* info = ctx;
char buffer[32] = {0};
if(info->times > 0)
{
ftk_snprintf(buffer, sizeof(buffer), "Quit after %d seconds", info->times);
ftk_widget_set_text(info->label, buffer);
info->times--;
return RET_OK;
}
else
{
ftk_widget_unref(ftk_widget_toplevel(info->label));
ftk_logd("%s: timeout and quit.\n", __func__);
FTK_FREE(info);
FTK_QUIT();
return RET_REMOVE;
}
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_label_create()
{
return ftk_app_demo_create(_("label"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkGc gc = {0};
TimerInfo* info = NULL;
FtkSource* timer = NULL;
FtkWidget* win = NULL;
FtkWidget* label = NULL;
gc.mask = FTK_GC_BG;
FTK_INIT(argc, argv);
info = (TimerInfo*)FTK_ZALLOC(sizeof(TimerInfo));
info->times = 5;
timer = ftk_source_timer_create(1000, timeout, info);
win = ftk_app_window_create();
ftk_window_set_animation_hint(win, "app_main_window");
width = ftk_widget_width(win);
height = ftk_widget_height(win);
#ifdef WIN32
label = ftk_label_create(win, 10, 10, width - 20, 20);
ftk_widget_set_text(label, "中文文本");
#else
#endif
label = ftk_label_create(win, 10, 40, width - 20, 20);
ftk_widget_set_text(label, "English Text(center)");
ftk_label_set_alignment(label, FTK_ALIGN_CENTER);
assert(strcmp(ftk_widget_get_text(label), "English Text(center)") == 0);
label = ftk_label_create(win, 10, 70, width - 20, 20);
ftk_widget_set_text(label, "English Text(right)");
ftk_label_set_alignment(label, FTK_ALIGN_RIGHT);
gc.bg.a = 0xff;
gc.bg.r = 0xF0;
gc.bg.g = 0xF0;
gc.bg.b = 0x80;
label = ftk_label_create(win, 10, height/2, width - 20, 120);
ftk_widget_set_gc(label, FTK_WIDGET_INSENSITIVE, &gc);
ftk_widget_unset_attr(label, FTK_ATTR_TRANSPARENT);
#ifdef WIN32
ftk_widget_set_text(label, "The linux mobile development(with background color)");
#else
ftk_widget_set_text(label, "中英文混合多行文本显示:the linux mobile development.带有背景颜色。");
#endif
label = ftk_label_create(win, 50, height/2-30, width, 20);
info->label = label;
ftk_widget_set_text(win, "label demo");
ftk_widget_show_all(win, 1);
ftk_widget_set_attr(win, FTK_ATTR_IGNORE_CLOSE);
ftk_main_loop_add_source(ftk_default_main_loop(), timer);
FTK_RUN();
return 0;
}
#include "ftk.h"
#include "ftk_list_view.h"
#include "ftk_list_render_default.h"
#include "ftk_list_model_default.h"
#define IDC_TEST_BUTTON 1000
static int g_index = 0;
static FtkBitmap* left_icon = NULL;
static FtkBitmap* right_icon = NULL;
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
static Ret button_more_clicked(void* ctx, void* obj)
{
int i = 0;
char text[32] = {0};
FtkListItemInfo info = {0};
FtkListModel* model = ctx;
for(i = 0; i < 4; i++)
{
g_index++;
ftk_snprintf(text, sizeof(text), "item%04d", g_index);
info.text = (text);
info.left_icon = left_icon;
info.right_icon = right_icon;
info.type = g_index%4;
ftk_list_model_add(model, &info);
}
return RET_OK;
}
Ret on_item_clicked(void* ctx, void* list)
{
FtkListItemInfo* info = NULL;
FtkListModel* model = ftk_list_view_get_model(list);
int i = ftk_list_view_get_selected(list);
ftk_list_model_get_data(model, i, (void**)&info);
if(info != NULL)
{
info->state = !info->state;
}
ftk_logd("%s: %d/%d\n", __func__,
ftk_list_view_get_selected(list),
ftk_list_model_get_total(model));
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_listview_create()
{
return ftk_app_demo_create(_("listview"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FtkWidget* list = NULL;
FtkListModel* model = NULL;
FtkListRender* render = NULL;
FtkListItemInfo info = {0};
char filename[FTK_MAX_PATH+1] = {0};
FTK_INIT(argc, argv);
win = ftk_app_window_create();
width = ftk_widget_width(win);
height = ftk_widget_height(win);
list = ftk_list_view_create(win, 10, 5, width - 20, 3 * height/4-5);
ftk_list_view_set_clicked_listener(list, on_item_clicked, NULL);
model = ftk_list_model_default_create(10);
render = ftk_list_render_default_create();
ftk_snprintf(filename, FTK_MAX_PATH, "%s/alarm/%s",
ftk_config_get_test_data_dir(ftk_default_config()), FTK_STOCK_IMG_SUFFIX);
left_icon = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
ftk_snprintf(filename, FTK_MAX_PATH, "%s/search/%s",
ftk_config_get_test_data_dir(ftk_default_config()), FTK_STOCK_IMG_SUFFIX);
right_icon = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
g_index = 0;
for(g_index = 0; g_index < 4; g_index++)
{
info.text = "滚动文字:Only those who attempt the absurd can achieve the impossible.";
info.left_icon = left_icon;
info.right_icon = right_icon;
info.type = g_index%4;
ftk_list_model_add(model, &info);
}
ftk_list_render_default_set_marquee_attr(render, FTK_MARQUEE_AUTO | FTK_MARQUEE_RIGHT2LEFT | FTK_MARQUEE_FOREVER);
ftk_list_view_init(list, model, render, 40);
ftk_list_model_unref(model);
button = ftk_button_create(win, width/4, 3 * height/4 + 5, width/4, 60);
ftk_widget_set_text(button, "more");
ftk_widget_set_font_size(button, 20);
ftk_button_set_clicked_listener(button, button_more_clicked, model);
button = ftk_button_create(win, width/2, 3 * height/4 + 5, width/4, 60);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
ftk_window_set_focus(win, button);
ftk_widget_set_text(win, "list view demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
static void create_app_window(void);
static Ret button_open_clicked(void* ctx, void* obj)
{
create_app_window();
return RET_OK;
}
static Ret button_close_clicked(void* ctx, void* obj)
{
FtkWidget* win = ctx;
ftk_logd("%s: close window %s\n", __func__, ftk_widget_get_text(win));
ftk_widget_unref(win);
return RET_OK;
}
static int g_index = 0;
static void on_window_close(void* user_data)
{
g_index--;
ftk_logd("%s: g_index=%d\n", __func__, g_index);
if(g_index == 0)
{
FTK_QUIT();
}
return ;
}
static Ret on_prepare_options_menu(void* ctx, FtkWidget* menu_panel)
{
int i = 0;
for(i = 0; i < g_index && i < 8; i++)
{
char text[32] = {0};
FtkWidget* item = ftk_menu_item_create(menu_panel);
ftk_snprintf(text, sizeof(text), "Menu%02d", i);
ftk_widget_set_text(item, text);
ftk_widget_show(item, 1);
}
return i > 0 ? RET_OK : RET_FAIL;
}
static void create_app_window(void)
{
int width = 0;
int height = 0;
char title[128] = {0};
FtkWidget* win = ftk_app_window_create();
FtkWidget* label = NULL;
FtkWidget* button = NULL;
width = ftk_widget_width(win);
height = ftk_widget_height(win);
button = ftk_button_create(win, 0, height/6, width/2-5, 50);
ftk_widget_set_text(button, "创建窗口");
ftk_button_set_clicked_listener(button, button_open_clicked, win);
button = ftk_button_create(win, width/2+5, height/6, width/2-5, 50);
ftk_widget_set_text(button, "关闭窗口");
ftk_button_set_clicked_listener(button, button_close_clicked, win);
label = ftk_label_create(win, 10, height/2, width-20, 60);
ftk_snprintf(title, sizeof(title),
"Press F2 to open menu, Presss F3 close window%02d", g_index++);
ftk_widget_set_text(label, title);
ftk_snprintf(title, sizeof(title), "window%02d", g_index++);
ftk_widget_set_text(win, title);
ftk_widget_show_all(win, 1);
ftk_widget_set_user_data(win, on_window_close, win);
ftk_app_window_set_on_prepare_options_menu(win, on_prepare_options_menu, win);
return;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_menu_create()
{
return ftk_app_demo_create(_("menu"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
FTK_INIT(argc, argv);
create_app_window();
FTK_RUN();
return 0;
}
#include "ftk.h"
static const char* buttons1[] = {"Yes", NULL};
static const char* buttons2[] = {"Yes", "No", NULL};
static const char* buttons3[] = {"Yes", "No", "Cancel", NULL};
static Ret button_warning(void* ctx, void* obj)
{
int ret = ftk_warning("Warning", "December 31, 2008: patchwork.kernel.org is now available for general use. It is currently only monitoring the Linux Kernel mailing-list, but should be useful to kernel developers in dealing with patches flying across the wire.", buttons1);
ftk_logd("%s: ret = %d\n", __func__, ret);
return RET_OK;
}
static Ret button_info(void* ctx, void* obj)
{
int ret = ftk_infomation("Infomation", "September 19, 2008: mirrors.kernel.org has been flipped over to using our new GeoDNS based bind server (named-geodns). This means that, at the dns query level, our servers will attempt to direct you to the nearest / fastest kernel.org mirror for your request. This means that you no longer have to use mirrors.us.kernel.org or mirrors.eu.kernel.org to generally route you to the right place. This does mean a change to mirrors.kernel.org no longer explicitly pointing at mirrors.us.kernel.org. Additional information on named-geodns will be forth coming, check back here for an addendum soon.", buttons2);
ftk_logd("%s: ret = %d\n", __func__, ret);
return RET_OK;
}
static Ret button_question(void* ctx, void* obj)
{
int ret = ftk_question("Question", "Are you sure to quit?", buttons3);
ftk_logd("%s: ret = %d\n", __func__, ret);
return RET_OK;
}
static Ret button_tips(void* ctx, void* obj)
{
int ret = ftk_tips("The dialog will quit in 3 seconds.");
ftk_logd("%s: ret = %d\n", __func__, ret);
return RET_OK;
}
static Ret button_quit(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_msgbox_create()
{
return ftk_app_demo_create(_("msgbox"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int y = 0;
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
width = ftk_widget_width(win);
height = ftk_widget_height(win);
y = (height - 240)/2;
y = y > 0 ? y : 0;
button = ftk_button_create(win, 0, y, width/2, 50);
ftk_widget_set_text(button, "question");
ftk_button_set_clicked_listener(button, button_question, win);
button = ftk_button_create(win, width/2, y, width/2, 50);
ftk_widget_set_text(button, "warning");
ftk_button_set_clicked_listener(button, button_warning, win);
button = ftk_button_create(win, 0, y+60, width/2, 50);
ftk_widget_set_text(button, "info");
ftk_button_set_clicked_listener(button, button_info, win);
button = ftk_button_create(win, width/2, y+60, width/2, 50);
ftk_widget_set_text(button, "tips");
ftk_button_set_clicked_listener(button, button_tips, win);
button = ftk_button_create(win, width/4, y+120, width/2, 50);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_quit, win);
ftk_widget_set_text(win, "message box demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
static void create_app_window(void);
static Ret button_open_clicked(void* ctx, void* obj)
{
create_app_window();
return RET_OK;
}
static Ret button_close_clicked(void* ctx, void* obj)
{
FtkWidget* win = ctx;
ftk_logd("%s: close window %s\n", __func__, ftk_widget_get_text(win));
ftk_widget_unref(win);
return RET_OK;
}
static int g_index = 0;
static void on_window_close(void* user_data)
{
g_index--;
ftk_logd("%s: g_index=%d\n", __func__, g_index);
if(g_index == 0)
{
FTK_QUIT();
}
return ;
}
static void create_app_window(void)
{
char title[32] = {0};
int width = 0;
int height = 0;
FtkWidget* win = ftk_app_window_create();
FtkWidget* label = NULL;
FtkWidget* button = NULL;
width = ftk_widget_width(win);
height = ftk_widget_height(win);
button = ftk_button_create(win, 0, height/6, width/3, 50);
ftk_widget_set_text(button, "创建窗口");
ftk_button_set_clicked_listener(button, button_open_clicked, win);
button = ftk_button_create(win, 2*width/3, height/6, width/3, 50);
ftk_widget_set_text(button, "关闭窗口");
ftk_button_set_clicked_listener(button, button_close_clicked, win);
ftk_snprintf(title, sizeof(title), "window%02d", g_index++);
label = ftk_label_create(win, width/4, height/2, width/2, 30);
ftk_widget_set_text(label, title);
ftk_widget_set_text(win, title);
ftk_widget_show_all(win, 1);
ftk_widget_set_user_data(win, on_window_close, win);
return;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_multi_win_create()
{
return ftk_app_demo_create(_("multi_win"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
FTK_INIT(argc, argv);
create_app_window();
FTK_RUN();
return 0;
}
#include "ftk.h"
static Ret button_close_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
static FtkListItemInfo g_infos[4];
static Ret on_menu_item_clicked(void* ctx, void* data)
{
FtkListItemInfo* info = data;
ftk_logd("%s: %s is selected\n", __func__, info->text);
return RET_OK;
}
static Ret button_normal_clicked(void* ctx, void* obj)
{
FtkBitmap* icon = ftk_theme_load_image(ftk_default_theme(), "info"FTK_STOCK_IMG_SUFFIX);
FtkWidget* thiz = ftk_popup_menu_create(0, 0, 0, 200, icon, "Edit");
size_t i = 0;
for(i = 0; i < FTK_ARRAY_SIZE(g_infos); i++)
{
g_infos[i].type = FTK_LIST_ITEM_NORMAL;
ftk_popup_menu_add(thiz, g_infos+i);
}
ftk_bitmap_unref(icon);
ftk_widget_show_all(thiz, 1);
return RET_OK;
}
static Ret button_radio_clicked(void* ctx, void* obj)
{
FtkBitmap* icon = ftk_theme_load_image(ftk_default_theme(), "info"FTK_STOCK_IMG_SUFFIX);
FtkWidget* thiz = ftk_popup_menu_create(0, 0, 0, 200, icon, "Edit");
size_t i = 0;
for(i = 0; i < FTK_ARRAY_SIZE(g_infos); i++)
{
g_infos[i].type = FTK_LIST_ITEM_RADIO;
g_infos[i].state = i == 0;
ftk_popup_menu_add(thiz, g_infos+i);
}
ftk_bitmap_unref(icon);
ftk_widget_show_all(thiz, 1);
return RET_OK;
}
static Ret button_check_clicked(void* ctx, void* obj)
{
FtkBitmap* icon = ftk_theme_load_image(ftk_default_theme(), "info"FTK_STOCK_IMG_SUFFIX);
FtkWidget* thiz = ftk_popup_menu_create(0, 0, 0, 200, icon, "Edit");
size_t i = 0;
for(i = 0; i < FTK_ARRAY_SIZE(g_infos); i++)
{
g_infos[i].type = FTK_LIST_ITEM_CHECK;
g_infos[i].state = i%2;
ftk_popup_menu_add(thiz, g_infos+i);
}
ftk_bitmap_unref(icon);
ftk_widget_show_all(thiz, 1);
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_popup_create()
{
return ftk_app_demo_create(_("popup"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FTK_INIT(argc, argv);
g_infos[0].text = "Copy";
g_infos[1].text = "Paste";
g_infos[2].text = "Cut";
g_infos[3].text = "Select All";
g_infos[0].extra_user_data = on_menu_item_clicked;
g_infos[1].extra_user_data = on_menu_item_clicked;
g_infos[2].extra_user_data = on_menu_item_clicked;
g_infos[3].extra_user_data = on_menu_item_clicked;
win = ftk_app_window_create();
width = ftk_widget_width(win);
height = ftk_widget_height(win);
button = ftk_button_create(win, 0, height/6, width/3, 50);
ftk_widget_set_text(button, "Normal");
ftk_button_set_clicked_listener(button, button_normal_clicked, NULL);
button = ftk_button_create(win, 2*width/3, height/6, width/3, 50);
ftk_widget_set_text(button, "Radio");
ftk_button_set_clicked_listener(button, button_radio_clicked, NULL);
button = ftk_button_create(win, 0, height/2, width/3, 50);
ftk_widget_set_text(button, "CheckBox");
ftk_button_set_clicked_listener(button, button_check_clicked, NULL);
button = ftk_button_create(win, 2*width/3, height/2, width/3, 50);
ftk_widget_set_text(button, "Quit");
ftk_button_set_clicked_listener(button, button_close_clicked, win);
ftk_widget_set_text(win, "pupup");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
#include "ftk_util.h"
static void on_window_destroy(void* user_data)
{
FtkSource* timer = user_data;
ftk_source_disable(timer);
ftk_main_loop_remove_source(ftk_default_main_loop(), timer);
return;
}
static Ret update_progress(void* ctx)
{
int percent = 0;
char text[32] = {0};
FtkWidget* progress_bar = ctx;
percent = ftk_progress_bar_get_percent(progress_bar);
if(percent == 100)
{
return RET_REMOVE;
}
ftk_progress_bar_set_percent(progress_bar, percent + 10);
ftk_itoa(text, sizeof(text), ftk_progress_bar_get_percent(progress_bar));
strcat(text, "%");
ftk_widget_set_text(progress_bar, text);
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_progress_bar_create()
{
return ftk_app_demo_create(_("progress_bar"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* progress_bar = NULL;
FtkSource* timer = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
width = ftk_widget_width(win);
height = ftk_widget_height(win);
width = width - 20;
progress_bar = ftk_progress_bar_create(win, 10, height/6, width, 32);
ftk_progress_bar_set_percent(progress_bar, 20);
timer = ftk_source_timer_create(1000, update_progress, progress_bar);
ftk_main_loop_add_source(ftk_default_main_loop(), timer);
ftk_widget_set_user_data(progress_bar, on_window_destroy, timer);
progress_bar = ftk_progress_bar_create(win, 10, height/3, width, 20);
ftk_progress_bar_set_percent(progress_bar, 20);
timer = ftk_source_timer_create(1000, update_progress, progress_bar);
ftk_main_loop_add_source(ftk_default_main_loop(), timer);
ftk_widget_set_user_data(progress_bar, on_window_destroy, timer);
ftk_progress_bar_set_interactive(progress_bar, 1);
progress_bar = ftk_progress_bar_create(win, 10, height/2, width, 32);
ftk_progress_bar_set_percent(progress_bar, 20);
timer = ftk_source_timer_create(1000, update_progress, progress_bar);
ftk_main_loop_add_source(ftk_default_main_loop(), timer);
ftk_widget_set_user_data(progress_bar, on_window_destroy, timer);
ftk_widget_set_text(win, "progress_bar demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
static Ret scroll_bar_on_scroll(void* ctx, void* scroll_bar)
{
ftk_logd("%s: value=%d\n", __func__, ftk_scroll_bar_get_value(scroll_bar));
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_scroll_bar_create()
{
return ftk_app_demo_create(_("scroll_bar"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FtkWidget* scroll_bar = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
width = ftk_widget_width(win);
height = ftk_widget_height(win);
/*v*/
scroll_bar = ftk_scroll_bar_create(win, width/8, 5, 0, height/2);
ftk_scroll_bar_set_param(scroll_bar, 0, 120, 120);
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
scroll_bar = ftk_scroll_bar_create(win, width/4, 5, 0, height/2);
ftk_scroll_bar_set_param(scroll_bar, 40, 120, 60);
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
scroll_bar = ftk_scroll_bar_create(win, 3*width/8, 5, 0, height/2);
ftk_scroll_bar_set_param(scroll_bar, 110, 120, 30);
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
scroll_bar = ftk_scroll_bar_create(win, width/2, 5, 0, height/2);
ftk_scroll_bar_set_param(scroll_bar, 120, 120, 20);
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
/*h*/
scroll_bar = ftk_scroll_bar_create(win, 5, height/2 + 10, width - 10, 0);
ftk_scroll_bar_set_param(scroll_bar, 120, 120, 20);
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
scroll_bar = ftk_scroll_bar_create(win, 5, height/2 + 30, width - 10, 0);
ftk_scroll_bar_set_param(scroll_bar, 110, 120, 30);
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
scroll_bar = ftk_scroll_bar_create(win, 5, height/2 + 50, width - 10, 0);
ftk_scroll_bar_set_param(scroll_bar, 40, 120, 60);
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
scroll_bar = ftk_scroll_bar_create(win, 5, height/2 + 80, width - 10, 0);
ftk_scroll_bar_set_param(scroll_bar, 0, 120, 120);
ftk_scroll_bar_set_listener(scroll_bar, scroll_bar_on_scroll, NULL);
button = ftk_button_create(win, 2*width/3, height/4, width/3-5, 50);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
ftk_window_set_focus(win, button);
ftk_widget_set_text(win, "scroll_bar demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
Ret on_move(void* ctx, void* obj)
{
ftk_logd("%s: %d %d\n", __func__, ftk_sprite_get_x(obj), ftk_sprite_get_y(obj));
return RET_OK;
}
Ret move_cursor(void* ctx, void* obj)
{
FtkEvent* event = obj;
if(event->type == FTK_EVT_MOUSE_MOVE)
{
ftk_sprite_move(ctx, event->u.mouse.x, event->u.mouse.y);
}
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_sprite_create()
{
return ftk_app_demo_create(_("sprite"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FtkSprite* sprite = NULL;
FtkBitmap* icon = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
width = ftk_widget_width(win);
height = ftk_widget_height(win);
button = ftk_button_create(win, width/4, height/2, width/2, 60);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
ftk_window_set_focus(win, button);
ftk_widget_set_text(win, "sprite demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
#if 0
/*multi sprite still has some problems.*/
sprite = ftk_sprite_create();
icon=ftk_theme_load_image(ftk_default_theme(), "flag-32"FTK_STOCK_IMG_SUFFIX);
ftk_sprite_set_icon(sprite, icon);
ftk_sprite_move(sprite, width/2, 0);
ftk_sprite_set_move_listener(sprite, on_move, NULL);
ftk_sprite_show(sprite, 1);
ftk_main_loop_add_source(ftk_default_main_loop(), ftk_source_timer_create(200, timer, sprite));
#endif
sprite = ftk_sprite_create();
icon=ftk_theme_load_image(ftk_default_theme(), "cursor"FTK_STOCK_IMG_SUFFIX);
ftk_sprite_set_icon(sprite, icon);
ftk_sprite_show(sprite, 1);
ftk_wnd_manager_add_global_listener(ftk_default_wnd_manager(), move_cursor, sprite);
FTK_RUN();
return 0;
}
#include "ftk.h"
#include <time.h>
#define IDC_TIME_ITEM 2000
static Ret update_time(void* ctx)
{
char text[10] = {0};
FtkWidget* item = NULL;
FtkWidget* panel = NULL;
time_t now = time(0);
struct tm* t = localtime(&now);
panel = ftk_default_status_panel();
ftk_snprintf(text, sizeof(text)-1, "%2d:%2d", t->tm_hour, t->tm_min);
item = ftk_widget_lookup(panel, IDC_TIME_ITEM);
ftk_widget_set_text(item, text);
ftk_logd("%s: %s\n", __func__, text);
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_statusbar_create()
{
return ftk_app_demo_create(_("status_bar"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
FtkSource* timer = NULL;
FtkWidget* win = NULL;
FtkWidget* item = NULL;
FtkWidget* panel = NULL;
FTK_INIT(argc, argv);
/*create a time widget in statusbar.*/
panel = ftk_default_status_panel();
item = ftk_status_item_create(panel, -2, 60);
ftk_widget_set_id(item, IDC_TIME_ITEM);
ftk_widget_show(item, 1);
win = ftk_app_window_create();
ftk_widget_set_text(win, "Hello FTK!");
ftk_widget_show(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
update_time(NULL);
timer = ftk_source_timer_create(60000, update_time, NULL);
ftk_main_loop_add_source(ftk_default_main_loop(), timer);
FTK_RUN();
return 0;
}
#include "ftk.h"
#include "ftk_tab.h"
static Ret button_default_clicked(void* ctx, void* obj)
{
printf("%s: button %s is clicked.\n", __func__, ftk_widget_get_text(obj));
return RET_OK;
}
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_tab_create()
{
return ftk_app_demo_create(_("tab"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
static void add_page(FtkWidget* tab, const char* text, FtkBitmap* bitmap)
{
int width = 0;
int height = 0;
FtkWidget* page = NULL;
FtkWidget* button = NULL;
page = ftk_tab_add_page(tab, text, bitmap);
width = ftk_widget_width(page);
height = ftk_widget_height(page);
button = ftk_button_create(page, 0, height/2-30, width/2, 60);
ftk_widget_set_text(button, text);
ftk_widget_show(button, 1);
ftk_button_set_clicked_listener(button, button_default_clicked, tab);
button = ftk_button_create(page, width/2, height/2-30, width/2, 60);
ftk_widget_set_text(button, text);
ftk_widget_show(button, 1);
ftk_button_set_clicked_listener(button, button_default_clicked, tab);
return;
}
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* tab = NULL;
FtkWidget* button = NULL;
FtkBitmap* bitmap = NULL;
FTK_INIT(argc, argv);
bitmap = ftk_theme_load_image(ftk_default_theme(), "mime_audio"FTK_STOCK_IMG_SUFFIX);
win = ftk_app_window_create();
width = ftk_widget_width(win);
height = ftk_widget_height(win);
tab = ftk_tab_create(win, 0, 0, width, height - 50);
add_page(tab, "General", bitmap);
add_page(tab, "Graphic", bitmap);
add_page(tab, "Audio", bitmap);
ftk_tab_set_active_page(tab, 0);
button = ftk_button_create(win, width/4, height - 50, width/2, 50);
ftk_widget_set_text(button, _("Quit"));
ftk_widget_show(button, 1);
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_BITMAP_UNREF(bitmap);
FTK_RUN();
return 0;
}
#include "ftk.h"
#include <assert.h>
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
#define TEXT_STR "libpng is the official PNG reference library. It supports almost all PNG features, is extensible, and has been extensively tested for over 15 years. The home site for development versions (i.e., may be buggy or subject to change or include experimental features) is http://libpng.sourceforge.net/, and the place to go for questions about the library is the png-mng-implement mailing list.\n\nlibpng is available as ANSI C (C89) source code and requires zlib 1.0.4 or later (1.2.3 or later recommended for performance and security reasons). The current public release, libpng 1.4.3, contains fixes for two potential security issues: "
#define TEXT1_STR "Several versions of libpng through 1.4.2 (and through 1.2.43 in the older series) contain a bug whereby progressive applications such as web browsers (or the rpng2 demo app included in libpng) could receive an extra row of image data beyond the height reported in the header, potentially leading to an out-of-bounds write to memory (depending on how the application is written) and the possibility of execution of an attacker's code with the privileges of the libpng user (including remote compromise in the case of a libpng-based browser visiting a hostile web site). This vulnerability has been assigned ID CVE-2010-1205 (via Mozilla). \n\n4\n5\n6\n7\n8\nlast line"
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_text_view_create()
{
return ftk_app_demo_create(_("text_view"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FtkWidget* text_view = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
width = ftk_widget_width(win);
height = ftk_widget_height(win);
text_view = ftk_text_view_create(win, 10, 10, ftk_widget_width(win) - 20, height/3);
ftk_widget_set_text(text_view, TEXT1_STR);
assert(strcmp(TEXT1_STR, ftk_widget_get_text(text_view)) == 0);
text_view = ftk_text_view_create(win, 10, 15 + height/3, ftk_widget_width(win) - 20, height/3);
ftk_widget_set_text(text_view, TEXT_STR);
assert(strcmp(TEXT_STR, ftk_widget_get_text(text_view)) == 0);
ftk_text_view_set_readonly(text_view, 1);
button = ftk_button_create(win, width/4, 3*height/4, width/2, 60);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
ftk_window_set_focus(win, button);
ftk_widget_set_text(win, "text_view demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
void create_dialog(FtkBitmap* bitmap, FtkColor bg);
static void create_app_window(void);
static Ret button_open_image_dialog(void* ctx, void* obj)
{
char filename[FTK_MAX_PATH+1] = {0};
FtkBitmap* bitmap = NULL;
FtkColor bg = {0};
bg.r = 0xff;
bg.g = 0xff;
bg.b = 0xff;
ftk_snprintf(filename, FTK_MAX_PATH, "%s/earth.png",
ftk_config_get_test_data_dir(ftk_default_config()));
bitmap = ftk_bitmap_factory_load(ftk_default_bitmap_factory(), filename);
bg.a = 0x0;
create_dialog(bitmap, bg);
return RET_OK;
}
static Ret button_open_transparent_dialog(void* ctx, void* obj)
{
FtkColor bg = {0};
bg.a = 0x80;
bg.r = 0xff;
bg.g = 0xff;
bg.b = 0xff;
create_dialog(NULL, bg);
return RET_OK;
}
static Ret button_quit_clicked(void* ctx, void* obj)
{
*(int*)ctx = ftk_widget_id(obj);
return RET_QUIT;
}
static Ret button_close_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
void create_dialog(FtkBitmap* bitmap, FtkColor bg)
{
int id = 0;
int width = ftk_display_width(ftk_default_display());
int height = ftk_display_height(ftk_default_display());
FtkWidget* button = NULL;
FtkWidget* label = NULL;
FtkWidget* dialog = ftk_dialog_create(0, 5, 320, height-60);
ftk_widget_set_attr(dialog, FTK_ATTR_BG_CENTER);
ftk_window_set_background_with_alpha(dialog, bitmap, bg);
width = ftk_widget_width(dialog);
height = ftk_widget_height(dialog);
//label = ftk_label_create(dialog, width/8, height/4, 3*width/4, 20);
//ftk_widget_set_text(label, "Are you sure to quit?");
label = ftk_label_create(dialog, width/8, height/2, 3*width/4, 20);
ftk_widget_set_text(label, "Are you sure to quit?");
button = ftk_button_create(dialog, width/6, 3*height/4, width/3, 50);
ftk_widget_set_text(button, "yes");
ftk_button_set_clicked_listener(button, button_quit_clicked, &id);
button = ftk_button_create(dialog, width/2, 3*height/4, width/3, 50);
ftk_widget_set_text(button, "no");
ftk_button_set_clicked_listener(button, button_quit_clicked, &id);
ftk_window_set_focus(dialog, button);
ftk_widget_set_text(dialog, "transparent demo");
ftk_widget_show_all(dialog, 1);
assert(ftk_dialog_run(dialog) == id);
ftk_widget_unref(dialog);
return;
}
static void create_app_window(void)
{
int width = 0;
int height = 0;
FtkWidget* win = ftk_app_window_create();
FtkWidget* button = NULL;
width = ftk_widget_width(win);
height = ftk_widget_height(win);
button = ftk_button_create(win, 0, height/6, width/3, 50);
ftk_widget_set_text(button, "图片背景");
ftk_button_set_clicked_listener(button, button_open_image_dialog, win);
button = ftk_button_create(win, 2*width/3, height/6, width/3, 50);
ftk_widget_set_text(button, "半透明效果");
ftk_button_set_clicked_listener(button, button_open_transparent_dialog, win);
button = ftk_button_create(win, width/4, height/2, width/2, 60);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_close_clicked, win);
ftk_widget_set_text(win, "transparent");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
return;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_transparent_create()
{
return ftk_app_demo_create(_("transparent"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
FTK_INIT(argc, argv);
create_app_window();
FTK_RUN();
return 0;
}
#include "ftk.h"
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
static Ret button_start_clicked(void* ctx, void* obj)
{
ftk_widget_show(ctx, 1);
ftk_wait_box_start_waiting(ctx);
return RET_OK;
}
static Ret button_stop_clicked(void* ctx, void* obj)
{
ftk_wait_box_stop_waiting(ctx);
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_wait_box_create()
{
return ftk_app_demo_create(_("wait_box"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
int width = 0;
int height = 0;
FtkWidget* win = NULL;
FtkWidget* button = NULL;
FtkWidget* wait_box = NULL;
FTK_INIT(argc, argv);
win = ftk_app_window_create();
width = ftk_widget_width(win);
height = ftk_widget_height(win);
wait_box = ftk_wait_box_create(win, width/2 - 16, height/4);
button = ftk_button_create(win, 0, height/2, width/3, 50);
ftk_widget_set_text(button, "start");
ftk_button_set_clicked_listener(button, button_start_clicked, wait_box);
button = ftk_button_create(win, 2*width/3, height/2, width/3, 50);
ftk_widget_set_text(button, "stop");
ftk_button_set_clicked_listener(button, button_stop_clicked, wait_box);
button = ftk_button_create(win, width/4, 3*height/4, width/2, 60);
ftk_widget_set_text(button, "quit");
ftk_button_set_clicked_listener(button, button_quit_clicked, win);
ftk_window_set_focus(win, button);
ftk_widget_set_text(win, "wait_box demo");
ftk_widget_show_all(win, 1);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
FTK_RUN();
return 0;
}
#include "ftk.h"
#include "ftk_xul.h"
const char* t1 = "<window> </window>";
#define IDC_QUIT 100
static Ret button_quit_clicked(void* ctx, void* obj)
{
ftk_widget_unref(ctx);
return RET_OK;
}
#ifdef FTK_AS_PLUGIN
#include "ftk_app_demo.h"
FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
FtkApp* ftk_app_demo_xul_create()
{
return ftk_app_demo_create(_("xul"), ftk_main);
}
#else
#define FTK_HIDE extern
#endif /*FTK_AS_PLUGIN*/
FTK_HIDE int FTK_MAIN(int argc, char* argv[])
{
if(argc > 1)
{
FtkWidget* win = NULL;
FtkWidget* quit = NULL;
FtkXulCallbacks callbacks;
FTK_INIT(argc, argv);
callbacks.translate_text = NULL;
callbacks.load_image = (FtkXulLoadImage)ftk_icon_cache_load;
callbacks.ctx = ftk_icon_cache_create(NULL, "testdata");
win = ftk_xul_load_file(argv[1], &callbacks);
ftk_icon_cache_destroy(callbacks.ctx);
FTK_QUIT_WHEN_WIDGET_CLOSE(win);
quit = ftk_widget_lookup(win, IDC_QUIT);
ftk_button_set_clicked_listener(quit, button_quit_clicked, win);
ftk_widget_show_all(win, 1);
FTK_RUN();
}
else
{
ftk_logd("Usage: %s xul\n", argv[0]);
return 0;
}
return 0;
}
<application name="button" exec="ftk_demos" init="ftk_app_demo_button_create" />
<application name="check_button" exec="ftk_demos" init="ftk_app_demo_check_button_create" />
<application name="combo_box" exec="ftk_demos" init="ftk_app_demo_combo_box_create" />
<application name="dialog" exec="ftk_demos" init="ftk_app_demo_dialog_create" />
<application name="entry" exec="ftk_demos" init="ftk_app_demo_entry_create" />
<application name="file_browser" exec="ftk_demos" init="ftk_app_demo_file_browser_create" />
<application name="fullscreen" exec="ftk_demos" init="ftk_app_demo_fullscreen_create" />
<application name="hello" exec="ftk_demos" init="ftk_app_demo_hello_create" />
<application name="icon_view" exec="ftk_demos" init="ftk_app_demo_icon_view_create" />
<application name="image_button" exec="ftk_demos" init="ftk_app_demo_image_button_create" />
<application name="image" exec="ftk_demos" init="ftk_app_demo_image_create" />
<application name="ime" exec="ftk_demos" init="ftk_app_demo_ime_create" />
<application name="label" exec="ftk_demos" init="ftk_app_demo_label_create" />
<application name="listview" exec="ftk_demos" init="ftk_app_demo_listview_create" />
<application name="menu" exec="ftk_demos" init="ftk_app_demo_menu_create" />
<application name="msgbox" exec="ftk_demos" init="ftk_app_demo_msgbox_create" />
<application name="multi_win" exec="ftk_demos" init="ftk_app_demo_multi_win_create" />
<application name="popup" exec="ftk_demos" init="ftk_app_demo_popup_create" />
<application name="progress_bar" exec="ftk_demos" init="ftk_app_demo_progress_bar_create" />
<application name="scroll_bar" exec="ftk_demos" init="ftk_app_demo_scroll_bar_create" />
<application name="sprite" exec="ftk_demos" init="ftk_app_demo_sprite_create" />
<application name="statusbar" exec="ftk_demos" init="ftk_app_demo_statusbar_create" />
<application name="text_view" exec="ftk_demos" init="ftk_app_demo_text_view_create" />
<application name="transparent" exec="ftk_demos" init="ftk_app_demo_transparent_create" />
<application name="wait_box" exec="ftk_demos" init="ftk_app_demo_wait_box_create" />
<application name="tab" exec="ftk_demos" init="ftk_app_demo_tab_create" />
#include "ftk_app_demo.h"
typedef struct _PrivInfo
{
char* name;
FtkMain ftk_main;
FtkBitmap* icon;
}PrivInfo;
static FtkBitmap* ftk_app_demo_get_icon(FtkApp* thiz)
{
DECL_PRIV(thiz, priv);
return_val_if_fail(priv != NULL, NULL);
return priv->icon;
}
static const char* ftk_app_demo_get_name(FtkApp* thiz)
{
DECL_PRIV(thiz, priv);
return_val_if_fail(priv != NULL, NULL);
return priv->name;
}
static Ret ftk_app_demo_run(FtkApp* thiz, int argc, char* argv[])
{
DECL_PRIV(thiz, priv);
return_val_if_fail(priv != NULL, RET_FAIL);
priv->ftk_main(argc, argv);
return RET_OK;
}
static void ftk_app_demo_destroy(FtkApp* thiz)
{
if(thiz != NULL)
{
DECL_PRIV(thiz, priv);
FTK_FREE(priv->name);
ftk_bitmap_unref(priv->icon);
FTK_FREE(thiz);
}
return;
}
FtkApp* ftk_app_demo_create(const char* name, FtkMain ftk_main)
{
FtkApp* thiz = FTK_ZALLOC(sizeof(FtkApp) + sizeof(PrivInfo));
if(thiz != NULL)
{
DECL_PRIV(thiz, priv);
priv->ftk_main = ftk_main;
priv->name = ftk_strdup(name);
priv->icon = ftk_theme_load_image(ftk_default_theme(), "flag-32"FTK_STOCK_IMG_SUFFIX);
thiz->get_icon = ftk_app_demo_get_icon;
thiz->get_name = ftk_app_demo_get_name;
thiz->run = ftk_app_demo_run;
thiz->destroy = ftk_app_demo_destroy;
}
return thiz;
}
#ifndef FTK_APP_DEMO_H
#define FTK_APP_DEMO_H
#include "ftk_app.h"
#define FTK_HIDE static
typedef int (*FtkMain)(int argc, char* argv[]);
FtkApp* ftk_app_demo_create(const char* name, FtkMain main);
#endif/*FTK_APP_DEMO_H*/
<?xml version="1.0" encoding="utf-8"?>
<window value="Entry Label" visible="1">
<label id="1" x="5" y="5" w="$ww/4" h="30" value="Name" />
<entry id="2" x="$ww/4+5" y="5" w="3*$ww/4-15" h="30" value="Li XianJing" />
<label id="3" x="5" y="40" w="$ww/4" h="30" value="EMail" />
<entry id="4" x="$ww/4+5" y="40" w="3*$ww/4-15" h="30" value="xianjimli@hotmail.com" />
<label id="5" x="5" y="75" w="$ww/4" h="30" value="Mobile" />
<entry id="6" x="$ww/4+5" y="75" w="3*$ww/4-15" h="30" value="+8613911112222" />
<button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" attr="$FTK_ATTR_INSENSITIVE" value="Save" />
<button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" attr="$FTK_ATTR_FOCUSED" value="Quit" />
</window>
<?xml version="1.0" encoding="utf-8"?>
<window value="ProgressBar">
<label id="1" x="5" y="5" w="$ww/4" h="30" value="Progress1" />
<progress_bar id="2" x="$ww/4+5" y="5" w="3*$ww/4-15" h="30" value="0" />
<label id="3" x="5" y="40" w="$ww/4" h="30" value="Progress2" />
<progress_bar id="4" x="$ww/4+5" y="40" w="3*$ww/4-15" h="30" value="50" />
<label id="5" x="5" y="75" w="$ww/4" h="30" value="Progress3" />
<progress_bar id="6" x="$ww/4+5" y="75" w="3*$ww/4-15" h="30" value="100" />
<button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" value="Save" />
<button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" value="Quit" />
</window>
<?xml version="1.0" encoding="utf-8"?>
<window value="Wait box">
<wait_box id="1" x="5" y="5" w="$ww/4" h="30" value="1" />
<progress_bar id="2" x="$ww/4+5" y="5" w="3*$ww/4-15" h="30" value="0" />
<wait_box id="3" x="5" y="40" w="$ww/4" h="30" value="0" />
<progress_bar id="4" x="$ww/4+5" y="40" w="3*$ww/4-15" h="30" value="50" />
<wait_box id="5" x="5" y="75" w="$ww/4" h="30" value="1" />
<progress_bar id="6" x="$ww/4+5" y="75" w="3*$ww/4-15" h="30" value="100" />
<button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" value="Save" />
<button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" value="Quit" />
</window>
<?xml version="1.0" encoding="utf-8"?>
<window value="Image">
<image id="1" x="0" y="5" w="$ww/2" h="3*$wh/4-5" value="jpeg1.jpg" />
<image id="1" x="$ww/2" y="5" w="$ww/2" h="3*$wh/4-5" attr="$FTK_ATTR_BG_CENTER" value="Acrobat.png" />
<button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" value="Save" />
<button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" value="Quit" />
</window>
<?xml version="1.0" encoding="utf-8"?>
<window value="Check button">
<check_button id="1" x="5" y="10" w="$ww/2" h="50" checked="1" value="Check Option1" />
<check_button id="3" x="5" y="60" w="$ww/2" h="50" checked="0" value="Check Option2" />
<check_button id="5" x="5" y="110" w="$ww/2" h="50" checked="1" value="Check Option3" />
<button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" value="Save" />
<button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" value="Quit" />
</window>
<?xml version="1.0" encoding="utf-8"?>
<window value="Radio button">
<radio_group x="0" y="0" w="$ww" h="$wh/3">
<radio_button id="1" x="5" y="10" w="$ww/2" h="50" checked="1" value="Radio Option1" />
<radio_button id="3" x="5" y="60" w="$ww/2" h="50" checked="0" value="Radio Option2" />
</radio_group>
<radio_group x="0" y="$wh/3+5" w="$ww" h="$wh/3">
<radio_button id="1" x="5" y="10" w="$ww/2" h="50" checked="1" value="Radio Option1" />
<radio_button id="3" x="5" y="60" w="$ww/2" h="50" checked="0" value="Radio Option2" />
</radio_group>
<button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" value="Save" />
<button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" value="Quit" />
</window>
<?xml version="1.0" encoding="utf-8"?>
<window value="background">
<button id="99" x="5" y="30" w="64" h="64" attr="$FTK_ATTR_INSENSITIVE"
bg_image[disable]="Flickr.png" bg[disable]="ffff0000"/>
<button id="99" x="$ww/2-32" y="30" w="64" h="64"
bg[normal]="ffff0000" bg[focused]="ff00ff00" bg[active]="ff0000ff"
bg_image[normal]="Acrobat.png" bg_image[focused]="Chat.png" bg_image[active]="Flickr.png" />
<button id="99" x="$ww-70" y="30" w="64" h="64"
bg_image[normal]="Acrobat.png" bg_image[focused]="Chat.png" bg_image[active]="Flickr.png" />
<button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" value="Save" />
<button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" value="Quit" />
</window>
# bsp name
BSP = 'mini2440'
# toolchains
EXEC_PATH = 'C:/Program Files/CodeSourcery/Sourcery G++ Lite/bin'
PREFIX = 'arm-none-eabi-'
CC = PREFIX + 'gcc'
CXX = PREFIX + 'g++'
AS = PREFIX + 'gcc'
AR = PREFIX + 'ar'
LINK = PREFIX + 'gcc'
TARGET_EXT = 'so'
SIZE = PREFIX + 'size'
OBJDUMP = PREFIX + 'objdump'
OBJCPY = PREFIX + 'objcopy'
DEVICE = ' -mcpu=arm920t'
CFLAGS = DEVICE + ' -O0 -fPIC -DFTK_AS_PLUGIN -DRT_THREAD '
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
LFLAGS = DEVICE + ' -Wl,-z,max-page-size=0x4 -shared -fPIC -nostdlib -s'
CPATH = ''
LPATH = ''
# bsp name
BSP = 'lm3s8962'
# toolchains
EXEC_PATH = 'C:/Program Files/CodeSourcery/Sourcery G++ Lite/bin'
PREFIX = 'arm-none-eabi-'
CC = PREFIX + 'gcc'
CXX = PREFIX + 'g++'
AS = PREFIX + 'gcc'
AR = PREFIX + 'ar'
LINK = PREFIX + 'gcc'
TARGET_EXT = 'so'
SIZE = PREFIX + 'size'
OBJDUMP = PREFIX + 'objdump'
OBJCPY = PREFIX + 'objcopy'
DEVICE = ' -mcpu=cortex-m3'
CFLAGS = DEVICE + ' -mthumb -Dsourcerygxx -O0 -fPIC'
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
LFLAGS = DEVICE + ' -mthumb -Wl,-z,max-page-size=0x4 -shared -fPIC -e main -nostdlib'
CPATH = ''
LPATH = ''
import os
import sys
EXEC_PATH = '/home/shaolin/CodeSourcery/Sourcery_G++_Lite/bin'
RTT_ROOT = os.path.normpath(os.getcwd() + '/../../../..')
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
PREFIX = 'arm-none-eabi-'
env = Environment(tools = ['mingw'],
AS = PREFIX + 'gcc',
ASFLAGS = '',
CC = PREFIX + 'gcc',
CCFLAGS = '-mcpu=arm920t -O0 -fPIC' ,
AR = PREFIX + 'ar',
ARFLAGS = '-rc',
LINK = PREFIX + 'ld',
LINKFLAGS = '-z max-page-size=0x4 -shared -fPIC -e rt_application_init -nostdlib -s',
CPPPATH = [
RTT_ROOT + '/include',
RTT_ROOT + '/bsp/mini2440',
RTT_ROOT + '/components/rtgui/include',
RTT_ROOT + '/components/rgtui/common',
RTT_ROOT + '/components/rtgui/server',
RTT_ROOT + '/components/rtgui/widgets'
])
env.PrependENVPath('PATH', EXEC_PATH)
target = 'tetris.so'
src = Glob('*.c')
env.Program(target, src)
import rtconfig
Import('RTT_ROOT')
from building import *
src = Glob('*.c')
group = DefineGroup('', src, depend = [''])
Return('group')
\ No newline at end of file
...@@ -194,7 +194,7 @@ static const struct rtgui_list_item function_list[] = ...@@ -194,7 +194,7 @@ static const struct rtgui_list_item function_list[] =
{"退出游戏", RT_NULL, listitem_action_return, RT_NULL}, {"退出游戏", RT_NULL, listitem_action_return, RT_NULL},
}; };
void rt_application_init(void* parameter) void main(void)
{ {
rt_mq_t mq; rt_mq_t mq;
rtgui_rect_t rect; rtgui_rect_t rect;
......
...@@ -53,8 +53,10 @@ struct rt_page_info ...@@ -53,8 +53,10 @@ struct rt_page_info
rt_uint32_t npage; rt_uint32_t npage;
}; };
#ifdef RT_USING_SLAB
static void *rt_module_malloc_page(rt_size_t npages); static void *rt_module_malloc_page(rt_size_t npages);
static void rt_module_free_page(void *page_ptr, rt_size_t npages); static void rt_module_free_page(rt_module_t module, void *page_ptr, rt_size_t npages);
#endif
static rt_module_t rt_current_module = RT_NULL; static rt_module_t rt_current_module = RT_NULL;
static struct rt_semaphore mod_sem; static struct rt_semaphore mod_sem;
...@@ -157,21 +159,18 @@ rt_err_t rt_module_set(rt_module_t module) ...@@ -157,21 +159,18 @@ rt_err_t rt_module_set(rt_module_t module)
static int rt_module_arm_relocate(struct rt_module *module, Elf32_Rel *rel, Elf32_Addr sym_val) static int rt_module_arm_relocate(struct rt_module *module, Elf32_Rel *rel, Elf32_Addr sym_val)
{ {
Elf32_Addr *where, tmp; Elf32_Addr *where, tmp;
Elf32_Sword addend; Elf32_Sword addend, offset;
rt_uint32_t upper, lower, sign, j1, j2;
where = (Elf32_Addr *)((rt_uint8_t *)module->module_space + rel->r_offset); where = (Elf32_Addr *)((rt_uint8_t *)module->module_space + rel->r_offset);
switch (ELF32_R_TYPE(rel->r_info)) switch (ELF32_R_TYPE(rel->r_info))
{ {
case R_ARM_NONE: case R_ARM_NONE:
break; break;
case R_ARM_ABS32: case R_ARM_ABS32:
*where += (Elf32_Addr)sym_val; *where += (Elf32_Addr)sym_val;
RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_ARM_ABS32: %x -> %x\n", where, *where)); RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_ARM_ABS32: %x -> %x\n", where, *where));
break; break;
case R_ARM_PC24: case R_ARM_PC24:
case R_ARM_PLT32: case R_ARM_PLT32:
case R_ARM_CALL: case R_ARM_CALL:
...@@ -182,11 +181,12 @@ static int rt_module_arm_relocate(struct rt_module *module, Elf32_Rel *rel, Elf3 ...@@ -182,11 +181,12 @@ static int rt_module_arm_relocate(struct rt_module *module, Elf32_Rel *rel, Elf3
tmp = sym_val - (Elf32_Addr)where + (addend << 2); tmp = sym_val - (Elf32_Addr)where + (addend << 2);
tmp >>= 2; tmp >>= 2;
*where = (*where & 0xff000000) | (tmp & 0x00ffffff); *where = (*where & 0xff000000) | (tmp & 0x00ffffff);
RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_ARM_PC24: %x -> %x\n", where, *where)); RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_ARM_PC24: %x -> %x\n", where, *where));
break; break;
case R_ARM_REL32:
*where += sym_val - (Elf32_Addr)where;
RT_DEBUG_LOG(RT_DEBUG_MODULE,("R_ARM_REL32: %x -> %x, sym %x, offset %x\n", where, *where, sym_val, rel->r_offset));
break;
case R_ARM_V4BX: case R_ARM_V4BX:
*where &= 0xf000000f; *where &= 0xf000000f;
*where |= 0x01a0f000; *where |= 0x01a0f000;
...@@ -194,18 +194,56 @@ static int rt_module_arm_relocate(struct rt_module *module, Elf32_Rel *rel, Elf3 ...@@ -194,18 +194,56 @@ static int rt_module_arm_relocate(struct rt_module *module, Elf32_Rel *rel, Elf3
case R_ARM_GLOB_DAT: case R_ARM_GLOB_DAT:
case R_ARM_JUMP_SLOT: case R_ARM_JUMP_SLOT:
*where = (Elf32_Addr)sym_val; *where = (Elf32_Addr)sym_val;
RT_DEBUG_LOG(RT_DEBUG_MODULE, RT_DEBUG_LOG(RT_DEBUG_MODULE,
("R_ARM_JUMP_SLOT: 0x%x -> 0x%x 0x%x\n", where, *where, sym_val)); ("R_ARM_JUMP_SLOT: 0x%x -> 0x%x 0x%x\n", where, *where, sym_val));
break;
break; #if 0 /* To do */
case R_ARM_GOT_BREL:
temp = (Elf32_Addr)sym_val;
*where = (Elf32_Addr)&temp;
RT_DEBUG_LOG(RT_DEBUG_MODULE,
("R_ARM_GOT_BREL: 0x%x -> 0x%x 0x%x\n", where, *where, sym_val));
break;
#endif
case R_ARM_RELATIVE: case R_ARM_RELATIVE:
*where += (Elf32_Addr)sym_val; *where += (Elf32_Addr)sym_val;
//RT_DEBUG_LOG(RT_DEBUG_MODULE,
RT_DEBUG_LOG(RT_DEBUG_MODULE, //("R_ARM_RELATIVE: 0x%x -> 0x%x 0x%x\n", where, *where, sym_val));
("R_ARM_RELATIVE: 0x%x -> 0x%x 0x%x\n", where, *where, sym_val)); break;
case R_ARM_THM_CALL:
break; case R_ARM_THM_JUMP24:
upper = *(rt_uint16_t *)where;
lower = *(rt_uint16_t *)((Elf32_Addr)where + 2);
sign = (upper >> 10) & 1;
j1 = (lower >> 13) & 1;
j2 = (lower >> 11) & 1;
offset = (sign << 24) | ((~(j1 ^ sign) & 1) << 23) |
((~(j2 ^ sign) & 1) << 22) |
((upper & 0x03ff) << 12) |
((lower & 0x07ff) << 1);
if (offset & 0x01000000)
offset -= 0x02000000;
offset += sym_val - (Elf32_Addr)where;
if (!(offset & 1) || offset <= (rt_int32_t)0xff000000 ||
offset >= (rt_int32_t)0x01000000)
{
rt_kprintf("only Thumb addresses allowed\n");
return -1;
}
sign = (offset >> 24) & 1;
j1 = sign ^ (~(offset >> 23) & 1);
j2 = sign ^ (~(offset >> 22) & 1);
*(rt_uint16_t *)where = (rt_uint16_t)((upper & 0xf800) | (sign << 10) |
((offset >> 12) & 0x03ff));
*(rt_uint16_t *)(where + 2) = (rt_uint16_t)((lower & 0xd000) |
(j1 << 13) | (j2 << 11) |
((offset >> 1) & 0x07ff));
upper = *(rt_uint16_t *)where;
lower = *(rt_uint16_t *)((Elf32_Addr)where + 2);
break;
default: default:
return -1; return -1;
} }
...@@ -311,44 +349,20 @@ void rt_module_unload_sethook(void (*hook)(rt_module_t module)) ...@@ -311,44 +349,20 @@ void rt_module_unload_sethook(void (*hook)(rt_module_t module))
/*@}*/ /*@}*/
#endif #endif
/** static struct rt_module* _load_shared_object(const char* name, void* module_ptr)
* This function will load a module from memory and create a thread for it
*
* @param name the name of module, which shall be unique
* @param module_ptr the memory address of module image
*
* @return the module object
*
*/
rt_module_t rt_module_load(const char *name, void *module_ptr)
{ {
rt_uint8_t *ptr = RT_NULL; rt_uint8_t *ptr = RT_NULL;
rt_module_t module = RT_NULL; rt_module_t module = RT_NULL;
rt_bool_t linked = RT_FALSE; rt_bool_t linked = RT_FALSE;
rt_uint32_t index, module_size = 0; rt_uint32_t index, module_size = 0;
RT_DEBUG_NOT_IN_INTERRUPT; RT_ASSERT(module_ptr != RT_NULL);
rt_kprintf("rt_module_load: %s ,", name); if(rt_memcmp(elf_module->e_ident, RTMMAG, SELFMAG) == 0)
/* check ELF header */
if (rt_memcmp(elf_module->e_ident, RTMMAG, SELFMAG) == 0)
{ {
/* rtmlinke finished */ /* rtmlinker finished */
linked = RT_TRUE; linked = RT_TRUE;
} }
else if (rt_memcmp(elf_module->e_ident, ELFMAG, SELFMAG) != 0)
{
rt_kprintf(" module magic error\n");
return RT_NULL;
}
/* check ELF class */
if(elf_module->e_ident[EI_CLASS] != ELFCLASS32)
{
rt_kprintf(" module class error\n");
return RT_NULL;
}
/* get the ELF image size */ /* get the ELF image size */
for (index = 0; index < elf_module->e_phnum; index++) for (index = 0; index < elf_module->e_phnum; index++)
...@@ -408,9 +422,9 @@ rt_module_t rt_module_load(const char *name, void *module_ptr) ...@@ -408,9 +422,9 @@ rt_module_t rt_module_load(const char *name, void *module_ptr)
rel = (Elf32_Rel *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset); rel = (Elf32_Rel *)((rt_uint8_t *)module_ptr + shdr[index].sh_offset);
/* locate .rel.plt and .rel.dyn section */ /* locate .rel.plt and .rel.dyn section */
symtab =(Elf32_Sym *)((rt_uint8_t *)module_ptr + shdr[shdr[index].sh_link].sh_offset); symtab =(Elf32_Sym *) ((rt_uint8_t*)module_ptr + shdr[shdr[index].sh_link].sh_offset);
strtab = (rt_uint8_t*)module_ptr + shdr[shdr[shdr[index].sh_link].sh_link].sh_offset; strtab = (rt_uint8_t*) module_ptr + shdr[shdr[shdr[index].sh_link].sh_link].sh_offset;
nr_reloc = (rt_uint32_t)(shdr[index].sh_size / sizeof(Elf32_Rel)); nr_reloc = (rt_uint32_t) (shdr[index].sh_size / sizeof(Elf32_Rel));
/* relocate every items */ /* relocate every items */
for (i = 0; i < nr_reloc; i ++) for (i = 0; i < nr_reloc; i ++)
...@@ -420,14 +434,14 @@ rt_module_t rt_module_load(const char *name, void *module_ptr) ...@@ -420,14 +434,14 @@ rt_module_t rt_module_load(const char *name, void *module_ptr)
RT_DEBUG_LOG(RT_DEBUG_MODULE, RT_DEBUG_LOG(RT_DEBUG_MODULE,
("relocate symbol %s shndx %d\n", strtab + sym->st_name, sym->st_shndx)); ("relocate symbol %s shndx %d\n", strtab + sym->st_name, sym->st_shndx));
if ((sym->st_shndx != SHT_NULL) || (ELF_ST_BIND(sym->st_info) == STB_LOCAL)) if((sym->st_shndx != SHT_NULL) || (ELF_ST_BIND(sym->st_info) == STB_LOCAL))
rt_module_arm_relocate(module, rel, (Elf32_Addr)(module->module_space + sym->st_value)); rt_module_arm_relocate(module, rel, (Elf32_Addr)(module->module_space + sym->st_value));
else if (!linked) else if(!linked)
{ {
Elf32_Addr addr; Elf32_Addr addr;
RT_DEBUG_LOG(RT_DEBUG_MODULE, RT_DEBUG_LOG(RT_DEBUG_MODULE,
("unresolved relocate symbol: %s\n", strtab + sym->st_name)); ("relocate symbol: %s\n", strtab + sym->st_name));
/* need to resolve symbol in kernel symbol table */ /* need to resolve symbol in kernel symbol table */
addr = rt_module_symbol_find((const char *)(strtab + sym->st_name)); addr = rt_module_symbol_find((const char *)(strtab + sym->st_name));
...@@ -450,6 +464,19 @@ rt_module_t rt_module_load(const char *name, void *module_ptr) ...@@ -450,6 +464,19 @@ rt_module_t rt_module_load(const char *name, void *module_ptr)
} }
} }
#if 0
for (index = 0; index < elf_module->e_shnum; index ++)
{
/* find .dynsym section */
rt_uint8_t* shstrab = (rt_uint8_t*) module_ptr + shdr[elf_module->e_shstrndx].sh_offset;
if (rt_strcmp((const char *)(shstrab + shdr[index].sh_name), ELF_GOT) == 0)
{
rt_hw_set_got_base(module->module_space + shdr[index].sh_offset);
break;
}
}
#endif
/* construct module symbol table */ /* construct module symbol table */
for (index = 0; index < elf_module->e_shnum; index ++) for (index = 0; index < elf_module->e_shnum; index ++)
{ {
...@@ -489,8 +516,243 @@ rt_module_t rt_module_load(const char *name, void *module_ptr) ...@@ -489,8 +516,243 @@ rt_module_t rt_module_load(const char *name, void *module_ptr)
count ++; count ++;
} }
} }
} }
return module;
}
static struct rt_module* _load_relocated_object(const char* name, void* module_ptr)
{
rt_uint32_t index, rodata_addr = 0, bss_addr = 0, data_addr = 0;
rt_uint32_t module_addr = 0, module_size = 0;
struct rt_module* module = RT_NULL;
rt_uint8_t *ptr, *strtab, *shstrab;
rt_bool_t linked = RT_FALSE;
if(rt_memcmp(elf_module->e_ident, RTMMAG, SELFMAG) == 0)
{
/* rtmlinker finished */
linked = RT_TRUE;
}
/* get the ELF image size */
for (index = 0; index < elf_module->e_shnum; index++)
{
/* text */
if (IS_PROG(shdr[index]) && IS_AX(shdr[index]))
{
module_size += shdr[index].sh_size;
module_addr = shdr[index].sh_addr;
}
/* rodata */
if (IS_PROG(shdr[index]) && IS_ALLOC(shdr[index]))
{
module_size += shdr[index].sh_size;
}
/* data */
if (IS_PROG(shdr[index]) && IS_AW(shdr[index]))
{
module_size += shdr[index].sh_size;
}
/* bss */
if (IS_NOPROG(shdr[index]) && IS_AW(shdr[index]))
{
module_size += shdr[index].sh_size;
}
}
/* no text, data and bss on image */
if (module_size == 0) return RT_NULL;
/* allocate module */
module = (struct rt_module *)rt_object_allocate(RT_Object_Class_Module, (const char*)name);
if (module == RT_NULL) return RT_NULL;
/* allocate module space */
module->module_space = rt_malloc(module_size);
if (module->module_space == RT_NULL)
{
rt_object_delete(&(module->parent));
return RT_NULL;
}
/* zero all space */
ptr = module->module_space;
rt_memset(ptr, 0, module_size);
/* load text and data section */
for (index = 0; index < elf_module->e_shnum; index++)
{
/* load text section */
if (IS_PROG(shdr[index]) && IS_AX(shdr[index]))
{
rt_memcpy(ptr, (rt_uint8_t*)elf_module + shdr[index].sh_offset, shdr[index].sh_size);
RT_DEBUG_LOG(RT_DEBUG_MODULE,("load text 0x%x, size %d\n", ptr, shdr[index].sh_size));
ptr += shdr[index].sh_size;
}
/* load rodata section */
if (IS_PROG(shdr[index]) && IS_ALLOC(shdr[index]))
{
rt_memcpy(ptr, (rt_uint8_t*)elf_module + shdr[index].sh_offset, shdr[index].sh_size);
rodata_addr = (rt_uint32_t)ptr;
RT_DEBUG_LOG(RT_DEBUG_MODULE,("load rodata 0x%x, size %d, rodata 0x%x\n", ptr, shdr[index].sh_size, *(rt_uint32_t*)data_addr));
ptr += shdr[index].sh_size;
}
/* load data section */
if (IS_PROG(shdr[index]) && IS_AW(shdr[index]))
{
rt_memcpy(ptr, (rt_uint8_t*)elf_module + shdr[index].sh_offset, shdr[index].sh_size);
data_addr = (rt_uint32_t)ptr;
RT_DEBUG_LOG(RT_DEBUG_MODULE,("load data 0x%x, size %d, data 0x%x\n", ptr, shdr[index].sh_size, *(rt_uint32_t*)data_addr));
ptr += shdr[index].sh_size;
}
/* load bss section */
if (IS_NOPROG(shdr[index]) && IS_AW(shdr[index]))
{
rt_memset(ptr, 0, shdr[index].sh_size);
bss_addr = (rt_uint32_t)ptr;
RT_DEBUG_LOG(RT_DEBUG_MODULE,("load bss 0x%x, size %d,\n", ptr, shdr[index].sh_size));
}
}
/* set module entry */
module->module_entry = (rt_uint8_t*)module->module_space + elf_module->e_entry - module_addr;
/* handle relocation section */
for (index = 0; index < elf_module->e_shnum; index ++)
{
if (IS_REL(shdr[index]))
{
rt_uint32_t i, nr_reloc;
Elf32_Sym *symtab;
Elf32_Rel *rel;
/* get relocate item */
rel = (Elf32_Rel *) ((rt_uint8_t*)module_ptr + shdr[index].sh_offset);
/* locate .dynsym and .dynstr */
symtab =(Elf32_Sym *) ((rt_uint8_t*)module_ptr + shdr[shdr[index].sh_link].sh_offset);
strtab = (rt_uint8_t*) module_ptr + shdr[shdr[shdr[index].sh_link].sh_link].sh_offset;
shstrab = (rt_uint8_t*) module_ptr + shdr[elf_module->e_shstrndx].sh_offset;
nr_reloc = (rt_uint32_t) (shdr[index].sh_size / sizeof(Elf32_Rel));
/* relocate every items */
for (i = 0; i < nr_reloc; i ++)
{
Elf32_Sym *sym = &symtab[ELF32_R_SYM(rel->r_info)];
RT_DEBUG_LOG(RT_DEBUG_MODULE,("relocate symbol: %s\n", strtab + sym->st_name));
if (sym->st_shndx != STN_UNDEF)
{
if((ELF_ST_TYPE(sym->st_info) == STT_SECTION)
|| (ELF_ST_TYPE(sym->st_info) == STT_OBJECT))
{
if (rt_strncmp(shstrab + shdr[sym->st_shndx].sh_name, ELF_RODATA, 8) == 0)
{
/* relocate rodata section */
RT_DEBUG_LOG(RT_DEBUG_MODULE,("rodata\n"));
rt_module_arm_relocate(module, rel,(Elf32_Addr)(rodata_addr + sym->st_value));
}
else if(strncmp(shstrab + shdr[sym->st_shndx].sh_name, ELF_BSS, 5) == 0)
{
/* relocate bss section */
RT_DEBUG_LOG(RT_DEBUG_MODULE,("bss\n"));
rt_module_arm_relocate(module, rel, (Elf32_Addr)bss_addr + sym->st_value);
}
else if(strncmp(shstrab + shdr[sym->st_shndx].sh_name, ELF_DATA, 6) == 0)
{
/* relocate data section */
RT_DEBUG_LOG(RT_DEBUG_MODULE,("data\n"));
rt_module_arm_relocate(module, rel, (Elf32_Addr)data_addr + sym->st_value);
}
}
}
else if(ELF_ST_TYPE(sym->st_info) == STT_FUNC )
{
/* relocate function */
rt_module_arm_relocate(module, rel,
(Elf32_Addr)((rt_uint8_t*)module->module_space - module_addr + sym->st_value));
}
else
{
Elf32_Addr addr;
if(ELF32_R_TYPE(rel->r_info) != R_ARM_V4BX)
{
RT_DEBUG_LOG(RT_DEBUG_MODULE,("relocate symbol: %s\n", strtab + sym->st_name));
/* need to resolve symbol in kernel symbol table */
addr = rt_module_symbol_find(strtab + sym->st_name);
if (addr != (Elf32_Addr)RT_NULL)
{
rt_module_arm_relocate(module, rel, addr);
RT_DEBUG_LOG(RT_DEBUG_MODULE,("symbol addr 0x%x\n", addr));
}
else rt_kprintf("can't find %s in kernel symbol table\n", strtab + sym->st_name);
}
else
{
rt_module_arm_relocate(module, rel, addr);
}
}
rel ++;
}
}
}
return module;
}
/**
* This function will load a module from memory and create a thread for it
*
* @param name the name of module, which shall be unique
* @param module_ptr the memory address of module image
*
* @return the module object
*
*/
rt_module_t rt_module_load(const char* name, void* module_ptr)
{
rt_module_t module;
RT_DEBUG_NOT_IN_INTERRUPT;
rt_kprintf("rt_module_load: %s ,", name);
/* check ELF header */
if(rt_memcmp(elf_module->e_ident, RTMMAG, SELFMAG) != 0
&& rt_memcmp(elf_module->e_ident, ELFMAG, SELFMAG) != 0)
{
rt_kprintf(" module magic error\n");
return RT_NULL;
}
/* check ELF class */
if(elf_module->e_ident[EI_CLASS] != ELFCLASS32)
{
rt_kprintf(" module class error\n");
return RT_NULL;
}
if(elf_module->e_type == ET_REL)
{
module = _load_relocated_object(name, module_ptr);
}
else if(elf_module->e_type == ET_DYN)
{
module = _load_shared_object(name, module_ptr);
}
else
{
rt_kprintf("unsupported elf type\n");
return RT_NULL;
}
if(module == RT_NULL) return RT_NULL;
/* init module object container */ /* init module object container */
rt_module_init_object_container(module); rt_module_init_object_container(module);
...@@ -502,10 +764,12 @@ rt_module_t rt_module_load(const char *name, void *module_ptr) ...@@ -502,10 +764,12 @@ rt_module_t rt_module_load(const char *name, void *module_ptr)
/* init module memory allocator */ /* init module memory allocator */
module->mem_list = RT_NULL; module->mem_list = RT_NULL;
#ifdef RT_USING_SLAB
/* create page array */ /* create page array */
module->page_array = (void *)rt_malloc(PAGE_COUNT_MAX * sizeof(struct rt_page_info)); module->page_array = (void *)rt_malloc(PAGE_COUNT_MAX * sizeof(struct rt_page_info));
module->page_cnt = 0; module->page_cnt = 0;
#endif
/* create module thread */ /* create module thread */
module->stack_size = 2048; module->stack_size = 2048;
module->thread_priority = 25; module->thread_priority = 25;
...@@ -598,10 +862,11 @@ rt_module_t rt_module_open(const char *path) ...@@ -598,10 +862,11 @@ rt_module_t rt_module_open(const char *path)
return RT_NULL; return RT_NULL;
} }
name = _strip_name(path); //name = _strip_name(path);
name = path;
module = rt_module_load(name, (void *)buffer); module = rt_module_load(name, (void *)buffer);
rt_free(buffer); rt_free(buffer);
rt_free(name); //rt_free(name);
return module; return module;
} }
...@@ -802,20 +1067,19 @@ rt_err_t rt_module_unload(rt_module_t module) ...@@ -802,20 +1067,19 @@ rt_err_t rt_module_unload(rt_module_t module)
} }
} }
if (module->page_cnt > 0) #ifdef RT_USING_SLAB
if(module->page_cnt > 0)
{ {
int i;
struct rt_page_info *page = (struct rt_page_info *)module->page_array; struct rt_page_info *page = (struct rt_page_info *)module->page_array;
rt_kprintf("warning: some module memory still hasn't be freed\n"); rt_kprintf("warning: module memory still hasn't been free finished\n");
//list_memlist("tetris");
for(i=0; i<module->page_cnt; i++) while(module->page_cnt != 0)
{ {
rt_module_free_page(page[i].page_ptr, page[i].npage); rt_module_free_page(module, page[0].page_ptr, page[0].npage);
} }
} }
#endif
/* release module space memory */ /* release module space memory */
rt_free(module->module_space); rt_free(module->module_space);
...@@ -902,6 +1166,7 @@ static void *rt_module_malloc_page(rt_size_t npages) ...@@ -902,6 +1166,7 @@ static void *rt_module_malloc_page(rt_size_t npages)
rt_current_module->page_cnt ++; rt_current_module->page_cnt ++;
RT_ASSERT(rt_current_module->page_cnt <= PAGE_COUNT_MAX); RT_ASSERT(rt_current_module->page_cnt <= PAGE_COUNT_MAX);
rt_kprintf("rt_module_malloc_page 0x%x %d\n", chunk, npages);
return chunk; return chunk;
} }
...@@ -915,37 +1180,39 @@ static void *rt_module_malloc_page(rt_size_t npages) ...@@ -915,37 +1180,39 @@ static void *rt_module_malloc_page(rt_size_t npages)
* *
* @note this function is used for RT-Thread Application Module * @note this function is used for RT-Thread Application Module
*/ */
static void rt_module_free_page(void *page_ptr, rt_size_t npages) static void rt_module_free_page(rt_module_t module, void *page_ptr, rt_size_t npages)
{ {
int i, index; int i, index;
struct rt_page_info *page; struct rt_page_info *page;
//rt_kprintf("rt_module_free_page 0x%x %d\n", page_ptr, npages); rt_kprintf("rt_module_free_page 0x%x %d\n", page_ptr, npages);
rt_page_free(page_ptr, npages); rt_page_free(page_ptr, npages);
page = (struct rt_page_info *)rt_current_module->page_array; page = (struct rt_page_info*)module->page_array;
for (i=0; i<rt_current_module->page_cnt; i++) for(i=0; i<module->page_cnt; i++)
{ {
if (page[i].page_ptr == page_ptr) if (page[i].page_ptr == page_ptr)
{ {
if (page[i].npage == npages + 1) if (page[i].npage == npages + 1)
{ {
page[i].page_ptr += npages * RT_MM_PAGE_SIZE / sizeof(rt_uint32_t); page[i].page_ptr += npages * RT_MM_PAGE_SIZE / sizeof(rt_uint32_t);
page[i].npage -= npages;
} }
else if (page[i].npage == npages) else if(page[i].npage == npages)
{ {
for (index=i; index<rt_current_module->page_cnt-1; index++) for(index=i; index<module->page_cnt-1; index++)
{ {
page[index].page_ptr = page[index + 1].page_ptr; page[index].page_ptr = page[index + 1].page_ptr;
page[index].npage = page[index + 1].npage; page[index].npage = page[index + 1].npage;
} }
page[rt_current_module->page_cnt - 1].page_ptr = RT_NULL; page[module->page_cnt - 1].page_ptr = RT_NULL;
page[rt_current_module->page_cnt - 1].npage = 0; page[module->page_cnt - 1].npage = 0;
module->page_cnt--;
} }
else RT_ASSERT(RT_FALSE); else RT_ASSERT(RT_FALSE);
rt_current_module->page_cnt--;
rt_current_module->page_cnt --;
return; return;
} }
...@@ -985,9 +1252,8 @@ void *rt_module_malloc(rt_size_t size) ...@@ -985,9 +1252,8 @@ void *rt_module_malloc(rt_size_t size)
b->size = nunits; b->size = nunits;
*prev = n; *prev = n;
//rt_kprintf("rt_module_malloc 0x%x, %d\n",b + 1, size); rt_kprintf("rt_module_malloc 0x%x, %d\n",b + 1, size);
rt_sem_release(&mod_sem); rt_sem_release(&mod_sem);
//list_memlist("tetris");
return (void *)(b + 1); return (void *)(b + 1);
} }
...@@ -997,7 +1263,7 @@ void *rt_module_malloc(rt_size_t size) ...@@ -997,7 +1263,7 @@ void *rt_module_malloc(rt_size_t size)
*prev = b->next; *prev = b->next;
rt_kprintf("rt_module_malloc 0x%x, %d\n",b + 1, size); rt_kprintf("rt_module_malloc 0x%x, %d\n",b + 1, size);
//list_memlist("tetris");
rt_sem_release(&mod_sem); rt_sem_release(&mod_sem);
return (void *)(b + 1); return (void *)(b + 1);
} }
...@@ -1035,7 +1301,7 @@ void rt_module_free(rt_module_t module, void *addr) ...@@ -1035,7 +1301,7 @@ void rt_module_free(rt_module_t module, void *addr)
RT_ASSERT(addr); RT_ASSERT(addr);
RT_ASSERT((((rt_uint32_t)addr) & (sizeof(struct rt_mem_head) -1)) == 0); RT_ASSERT((((rt_uint32_t)addr) & (sizeof(struct rt_mem_head) -1)) == 0);
//rt_kprintf("rt_module_free 0x%x\n", addr); rt_kprintf("rt_module_free 0x%x\n", addr);
rt_sem_take(&mod_sem, RT_WAITING_FOREVER); rt_sem_take(&mod_sem, RT_WAITING_FOREVER);
...@@ -1075,13 +1341,12 @@ void rt_module_free(rt_module_t module, void *addr) ...@@ -1075,13 +1341,12 @@ void rt_module_free(rt_module_t module, void *addr)
*prev = b->next; *prev = b->next;
} }
rt_module_free_page(b, npage); rt_module_free_page(module, b, npage);
} }
} }
/* unlock */ /* unlock */
rt_sem_release(&mod_sem); rt_sem_release(&mod_sem);
////list_memlist("tetris");
return; return;
} }
...@@ -1107,7 +1372,7 @@ void rt_module_free(rt_module_t module, void *addr) ...@@ -1107,7 +1372,7 @@ void rt_module_free(rt_module_t module, void *addr)
} }
else *prev = n->next; else *prev = n->next;
rt_module_free_page(n, npage); rt_module_free_page(module, n, npage);
} }
} }
else else
...@@ -1117,7 +1382,6 @@ void rt_module_free(rt_module_t module, void *addr) ...@@ -1117,7 +1382,6 @@ void rt_module_free(rt_module_t module, void *addr)
/* unlock */ /* unlock */
rt_sem_release(&mod_sem); rt_sem_release(&mod_sem);
//list_memlist("tetris");
return; return;
} }
...@@ -1131,7 +1395,7 @@ void rt_module_free(rt_module_t module, void *addr) ...@@ -1131,7 +1395,7 @@ void rt_module_free(rt_module_t module, void *addr)
int npage = n->size * sizeof(struct rt_page_info) / RT_MM_PAGE_SIZE; int npage = n->size * sizeof(struct rt_page_info) / RT_MM_PAGE_SIZE;
if (npage > 0) if (npage > 0)
{ {
rt_module_free_page(n, npage); rt_module_free_page(module, n, npage);
if (n->size % RT_MM_PAGE_SIZE != 0) if (n->size % RT_MM_PAGE_SIZE != 0)
{ {
rt_size_t nunits = npage * RT_MM_PAGE_SIZE / sizeof(struct rt_mem_head); rt_size_t nunits = npage * RT_MM_PAGE_SIZE / sizeof(struct rt_mem_head);
...@@ -1155,7 +1419,6 @@ void rt_module_free(rt_module_t module, void *addr) ...@@ -1155,7 +1419,6 @@ void rt_module_free(rt_module_t module, void *addr)
/* unlock */ /* unlock */
rt_sem_release(&mod_sem); rt_sem_release(&mod_sem);
//list_memlist("tetris");
} }
/* /*
......
...@@ -56,6 +56,12 @@ typedef rt_uint16_t Elf32_Half; /* Unsigned medium integer */ ...@@ -56,6 +56,12 @@ typedef rt_uint16_t Elf32_Half; /* Unsigned medium integer */
(ehdr).e_ident[EI_MAG2] == ELFMAG2 && \ (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
(ehdr).e_ident[EI_MAG3] == ELFMAG3) (ehdr).e_ident[EI_MAG3] == ELFMAG3)
#define ET_NONE 0 /* No file type */
#define ET_REL 1 /* Relocatable file */
#define ET_EXEC 2 /* Executable file */
#define ET_DYN 3 /* Shared object file */
#define ET_CORE 4 /* Core file */
/* ELF Header */ /* ELF Header */
typedef struct elfhdr typedef struct elfhdr
{ {
...@@ -148,6 +154,7 @@ typedef struct elf32_sym ...@@ -148,6 +154,7 @@ typedef struct elf32_sym
#define STT_LOPROC 13 /* processor specific range */ #define STT_LOPROC 13 /* processor specific range */
#define STT_HIPROC 15 #define STT_HIPROC 15
#define STN_UNDEF 0 /* undefined */
#define ELF_ST_BIND(info) ((info) >> 4) #define ELF_ST_BIND(info) ((info) >> 4)
#define ELF_ST_TYPE(info) ((info) & 0xf) #define ELF_ST_TYPE(info) ((info) & 0xf)
...@@ -176,16 +183,20 @@ typedef struct ...@@ -176,16 +183,20 @@ typedef struct
/* /*
* Relocation type for arm * Relocation type for arm
*/ */
#define R_ARM_NONE 0 #define R_ARM_NONE 0
#define R_ARM_PC24 1 #define R_ARM_PC24 1
#define R_ARM_ABS32 2 #define R_ARM_ABS32 2
#define R_ARM_GLOB_DAT 21 #define R_ARM_REL32 3
#define R_ARM_JUMP_SLOT 22 #define R_ARM_THM_CALL 10
#define R_ARM_RELATIVE 23 #define R_ARM_GLOB_DAT 21
#define R_ARM_PLT32 27 #define R_ARM_JUMP_SLOT 22
#define R_ARM_CALL 28 #define R_ARM_RELATIVE 23
#define R_ARM_JUMP24 29 #define R_ARM_GOT_BREL 26
#define R_ARM_V4BX 40 #define R_ARM_PLT32 27
#define R_ARM_CALL 28
#define R_ARM_JUMP24 29
#define R_ARM_THM_JUMP24 30
#define R_ARM_V4BX 40
/* Program Header */ /* Program Header */
typedef struct typedef struct
......
/* /*
* File : rtm.c * File : rtm.c
* This file is part of RT-Thread RTOS * This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team * COPYRIGHT (C) 2006 - 2010, RT-Thread Development Team
* *
* The license and distribution terms for this file may be * The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at * found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE * http://www.rt-thread.org/license/LICENSE
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2010-04-12 yi.qiu first version * 2010-04-12 yi.qiu first version
*/ */
#include <rtthread.h> #include <rtthread.h>
#include <stdlib.h> #include <assert.h>
#include <string.h> #include <stdlib.h>
#include <stdio.h> #include <string.h>
#include <stdio.h>
/* some buildin kernel symbol */
/* some buildin kernel symbol */
#ifdef RT_USING_MODULE
#include <rtm.h> #ifdef RT_USING_MODULE
#include <rtm.h>
RTM_EXPORT(rt_object_get_information);
RTM_EXPORT(rt_object_get_information);
/*
* thread interface symbol /*
*/ * thread interface symbol
*/
RTM_EXPORT(rt_thread_init);
RTM_EXPORT(rt_thread_detach); RTM_EXPORT(rt_thread_init);
RTM_EXPORT(rt_thread_create); RTM_EXPORT(rt_thread_detach);
RTM_EXPORT(rt_thread_self); RTM_EXPORT(rt_thread_create);
RTM_EXPORT(rt_thread_find); RTM_EXPORT(rt_thread_self);
RTM_EXPORT(rt_thread_startup); RTM_EXPORT(rt_thread_find);
RTM_EXPORT(rt_thread_delete); RTM_EXPORT(rt_thread_startup);
RTM_EXPORT(rt_thread_yield); RTM_EXPORT(rt_thread_delete);
RTM_EXPORT(rt_thread_delay); RTM_EXPORT(rt_thread_yield);
RTM_EXPORT(rt_thread_control); RTM_EXPORT(rt_thread_delay);
RTM_EXPORT(rt_thread_suspend); RTM_EXPORT(rt_thread_control);
RTM_EXPORT(rt_thread_resume); RTM_EXPORT(rt_thread_suspend);
RTM_EXPORT(rt_thread_timeout); RTM_EXPORT(rt_thread_resume);
RTM_EXPORT(rt_thread_timeout);
#ifdef RT_USING_SEMAPHORE
/* #ifdef RT_USING_SEMAPHORE
* semaphore interface symbol /*
*/ * semaphore interface symbol
RTM_EXPORT(rt_sem_init); */
RTM_EXPORT(rt_sem_detach); RTM_EXPORT(rt_sem_init);
RTM_EXPORT(rt_sem_create); RTM_EXPORT(rt_sem_detach);
RTM_EXPORT(rt_sem_delete); RTM_EXPORT(rt_sem_create);
RTM_EXPORT(rt_sem_take); RTM_EXPORT(rt_sem_delete);
RTM_EXPORT(rt_sem_trytake); RTM_EXPORT(rt_sem_take);
RTM_EXPORT(rt_sem_release); RTM_EXPORT(rt_sem_trytake);
RTM_EXPORT(rt_sem_control); RTM_EXPORT(rt_sem_release);
#endif RTM_EXPORT(rt_sem_control);
#endif
#ifdef RT_USING_MUTEX
/* #ifdef RT_USING_MUTEX
* mutex interface symbol /*
*/ * mutex interface symbol
RTM_EXPORT(rt_mutex_init); */
RTM_EXPORT(rt_mutex_detach); RTM_EXPORT(rt_mutex_init);
RTM_EXPORT(rt_mutex_create); RTM_EXPORT(rt_mutex_detach);
RTM_EXPORT(rt_mutex_delete); RTM_EXPORT(rt_mutex_create);
RTM_EXPORT(rt_mutex_take); RTM_EXPORT(rt_mutex_delete);
RTM_EXPORT(rt_mutex_release); RTM_EXPORT(rt_mutex_take);
RTM_EXPORT(rt_mutex_control); RTM_EXPORT(rt_mutex_release);
#endif RTM_EXPORT(rt_mutex_control);
#endif
#ifdef RT_USING_EVENT
/* #ifdef RT_USING_EVENT
* event interface symbol /*
*/ * event interface symbol
RTM_EXPORT(rt_event_init); */
RTM_EXPORT(rt_event_detach); RTM_EXPORT(rt_event_init);
RTM_EXPORT(rt_event_create); RTM_EXPORT(rt_event_detach);
RTM_EXPORT(rt_event_delete); RTM_EXPORT(rt_event_create);
RTM_EXPORT(rt_event_send); RTM_EXPORT(rt_event_delete);
RTM_EXPORT(rt_event_recv); RTM_EXPORT(rt_event_send);
RTM_EXPORT(rt_event_control); RTM_EXPORT(rt_event_recv);
#endif RTM_EXPORT(rt_event_control);
#endif
#ifdef RT_USING_MAILBOX
/* #ifdef RT_USING_MAILBOX
* mailbox interface symbol /*
*/ * mailbox interface symbol
RTM_EXPORT(rt_mb_init); */
RTM_EXPORT(rt_mb_detach); RTM_EXPORT(rt_mb_init);
RTM_EXPORT(rt_mb_create); RTM_EXPORT(rt_mb_detach);
RTM_EXPORT(rt_mb_delete); RTM_EXPORT(rt_mb_create);
RTM_EXPORT(rt_mb_send); RTM_EXPORT(rt_mb_delete);
RTM_EXPORT(rt_mb_recv); RTM_EXPORT(rt_mb_send);
RTM_EXPORT(rt_mb_control); RTM_EXPORT(rt_mb_recv);
#endif RTM_EXPORT(rt_mb_control);
#endif
#ifdef RT_USING_MESSAGEQUEUE
/* #ifdef RT_USING_MESSAGEQUEUE
* message queue interface symbol /*
*/ * message queue interface symbol
RTM_EXPORT(rt_mq_init); */
RTM_EXPORT(rt_mq_detach); RTM_EXPORT(rt_mq_init);
RTM_EXPORT(rt_mq_create); RTM_EXPORT(rt_mq_detach);
RTM_EXPORT(rt_mq_delete); RTM_EXPORT(rt_mq_create);
RTM_EXPORT(rt_mq_send); RTM_EXPORT(rt_mq_delete);
RTM_EXPORT(rt_mq_urgent); RTM_EXPORT(rt_mq_send);
RTM_EXPORT(rt_mq_recv); RTM_EXPORT(rt_mq_urgent);
RTM_EXPORT(rt_mq_control); RTM_EXPORT(rt_mq_recv);
#endif RTM_EXPORT(rt_mq_control);
#endif
#ifdef RT_USING_MEMPOOL
/* #ifdef RT_USING_MEMPOOL
* memory pool interface symbol /*
*/ * memory pool interface symbol
RTM_EXPORT(rt_mp_init); */
RTM_EXPORT(rt_mp_detach); RTM_EXPORT(rt_mp_init);
RTM_EXPORT(rt_mp_create); RTM_EXPORT(rt_mp_detach);
RTM_EXPORT(rt_mp_delete); RTM_EXPORT(rt_mp_create);
RTM_EXPORT(rt_mp_alloc); RTM_EXPORT(rt_mp_delete);
RTM_EXPORT(rt_mp_free); RTM_EXPORT(rt_mp_alloc);
#endif RTM_EXPORT(rt_mp_free);
#endif
#ifdef RT_USING_HEAP
/* #ifdef RT_USING_HEAP
* heap memory interface symbol /*
*/ * heap memory interface symbol
RTM_EXPORT(rt_malloc); */
RTM_EXPORT(rt_free); RTM_EXPORT(rt_malloc);
RTM_EXPORT(rt_realloc); RTM_EXPORT(rt_free);
RTM_EXPORT(rt_calloc); RTM_EXPORT(rt_realloc);
#endif RTM_EXPORT(rt_calloc);
/* #endif
* clock & timer interface symbol /*
*/ * clock & timer interface symbol
RTM_EXPORT(rt_tick_get); */
RTM_EXPORT(rt_tick_from_millisecond); RTM_EXPORT(rt_tick_get);
RTM_EXPORT(rt_system_timer_init); RTM_EXPORT(rt_tick_from_millisecond);
RTM_EXPORT(rt_system_timer_thread_init); RTM_EXPORT(rt_system_timer_init);
RTM_EXPORT(rt_timer_init); RTM_EXPORT(rt_system_timer_thread_init);
RTM_EXPORT(rt_timer_detach); RTM_EXPORT(rt_timer_init);
RTM_EXPORT(rt_timer_create); RTM_EXPORT(rt_timer_detach);
RTM_EXPORT(rt_timer_delete); RTM_EXPORT(rt_timer_create);
RTM_EXPORT(rt_timer_start); RTM_EXPORT(rt_timer_delete);
RTM_EXPORT(rt_timer_stop); RTM_EXPORT(rt_timer_start);
RTM_EXPORT(rt_timer_control); RTM_EXPORT(rt_timer_stop);
RTM_EXPORT(rt_timer_control);
/*
* kservice interface symbol /*
*/ * kservice interface symbol
RTM_EXPORT(rt_memcpy); */
RTM_EXPORT(rt_memcmp); RTM_EXPORT(rt_memcpy);
RTM_EXPORT(rt_memset); RTM_EXPORT(rt_memcmp);
RTM_EXPORT(rt_kprintf); RTM_EXPORT(rt_memset);
RTM_EXPORT(rt_sprintf); RTM_EXPORT(rt_kprintf);
RTM_EXPORT(rt_strstr); RTM_EXPORT(rt_sprintf);
RTM_EXPORT(rt_snprintf); RTM_EXPORT(rt_strstr);
RTM_EXPORT(rt_snprintf);
/*
* misc interface symbol /*
*/ * misc interface symbol
extern int __aeabi_idiv; */
extern int __aeabi_ddiv; extern int __aeabi_idiv;
extern int __aeabi_dmul; extern int __aeabi_ddiv;
extern int __aeabi_i2d; extern int __aeabi_dmul;
extern int __aeabi_uidiv; extern int __aeabi_i2d;
extern int __aeabi_uidivmod; extern int __aeabi_uidiv;
extern int __aeabi_idivmod; extern int __aeabi_uidivmod;
extern int __aeabi_d2iz; extern int __aeabi_idivmod;
extern int __aeabi_d2iz;
RTM_EXPORT(__aeabi_ddiv);
RTM_EXPORT(__aeabi_dmul); RTM_EXPORT(__aeabi_ddiv);
RTM_EXPORT(__aeabi_i2d); RTM_EXPORT(__aeabi_dmul);
RTM_EXPORT(__aeabi_uidiv); RTM_EXPORT(__aeabi_i2d);
RTM_EXPORT(__aeabi_idiv); RTM_EXPORT(__aeabi_uidiv);
RTM_EXPORT(__aeabi_idivmod); RTM_EXPORT(__aeabi_idiv);
RTM_EXPORT(__aeabi_uidivmod); RTM_EXPORT(__aeabi_idivmod);
RTM_EXPORT(__aeabi_d2iz); RTM_EXPORT(__aeabi_uidivmod);
RTM_EXPORT(strcmp); RTM_EXPORT(__aeabi_d2iz);
RTM_EXPORT(strcpy); RTM_EXPORT(strcmp);
RTM_EXPORT(strlen); RTM_EXPORT(strcpy);
RTM_EXPORT(rand); RTM_EXPORT(strlen);
RTM_EXPORT(memset); RTM_EXPORT(rand);
RTM_EXPORT(memcpy); RTM_EXPORT(memset);
RTM_EXPORT(memcpy);
#ifdef RT_USING_NEWLIB
#if defined(RT_USING_NEWLIB) && defined(RT_USING_PTHREADS)
#include <unistd.h>
#include <assert.h> #include <unistd.h>
RTM_EXPORT(snprintf); RTM_EXPORT(printf);
RTM_EXPORT(access); RTM_EXPORT(snprintf);
RTM_EXPORT(__assert_func); RTM_EXPORT(access);
RTM_EXPORT(__assert_func);
#include <time.h>
RTM_EXPORT(localtime); #include <time.h>
RTM_EXPORT(time); RTM_EXPORT(localtime);
RTM_EXPORT(time);
#endif
#include <math.h>
#ifdef RT_USING_DFS RTM_EXPORT(sin);
#include <dfs_posix.h> RTM_EXPORT(cos);
RTM_EXPORT(open); #endif
RTM_EXPORT(close);
RTM_EXPORT(read); #ifdef RT_USING_DFS
RTM_EXPORT(write); #include <dfs_posix.h>
RTM_EXPORT(stat);
#endif RTM_EXPORT(open);
RTM_EXPORT(close);
#ifdef RT_USING_RTGUI RTM_EXPORT(read);
/* FIX ME , should be removed from here */ RTM_EXPORT(write);
#include <rtgui/dc.h> RTM_EXPORT(stat);
#include <rtgui/rtgui_server.h> #endif
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h> #ifdef RT_USING_RTGUI
#include <rtgui/widgets/workbench.h> /* FIX ME , should be removed from here */
#include <rtgui/widgets/widget.h> #include <rtgui/dc.h>
#include <rtgui/widgets/button.h> #include <rtgui/rtgui_server.h>
#include <rtgui/widgets/label.h> #include <rtgui/rtgui_system.h>
#include <rtgui/widgets/list_view.h> #include <rtgui/widgets/view.h>
#include <rtgui/widgets/listctrl.h> #include <rtgui/widgets/workbench.h>
#include <rtgui/widgets/filelist_view.h> #include <rtgui/widgets/widget.h>
#include <rtgui/widgets/button.h>
RTM_EXPORT(rtgui_label_create); #include <rtgui/widgets/label.h>
RTM_EXPORT(rtgui_view_show); #include <rtgui/widgets/list_view.h>
RTM_EXPORT(rtgui_view_create); #include <rtgui/widgets/listctrl.h>
RTM_EXPORT(rtgui_view_destroy); #include <rtgui/widgets/filelist_view.h>
RTM_EXPORT(rtgui_view_event_handler);
RTM_EXPORT(rtgui_dc_draw_text); RTM_EXPORT(rtgui_label_create);
RTM_EXPORT(rtgui_dc_begin_drawing); RTM_EXPORT(rtgui_view_show);
RTM_EXPORT(rtgui_dc_end_drawing); RTM_EXPORT(rtgui_view_create);
RTM_EXPORT(rtgui_workbench_event_loop); RTM_EXPORT(rtgui_view_destroy);
RTM_EXPORT(rtgui_workbench_event_handler); RTM_EXPORT(rtgui_view_event_handler);
RTM_EXPORT(rtgui_workbench_add_view); RTM_EXPORT(rtgui_dc_draw_text);
RTM_EXPORT(rtgui_workbench_create); RTM_EXPORT(rtgui_dc_begin_drawing);
RTM_EXPORT(rtgui_workbench_destroy); RTM_EXPORT(rtgui_dc_end_drawing);
RTM_EXPORT(rtgui_workbench_close); RTM_EXPORT(rtgui_workbench_event_loop);
RTM_EXPORT(rtgui_timer_start); RTM_EXPORT(rtgui_workbench_event_handler);
RTM_EXPORT(rtgui_timer_create); RTM_EXPORT(rtgui_workbench_add_view);
RTM_EXPORT(rtgui_timer_destory); RTM_EXPORT(rtgui_workbench_create);
RTM_EXPORT(rtgui_timer_stop); RTM_EXPORT(rtgui_workbench_destroy);
RTM_EXPORT(rtgui_thread_register); RTM_EXPORT(rtgui_workbench_close);
RTM_EXPORT(rtgui_thread_deregister); RTM_EXPORT(rtgui_timer_start);
RTM_EXPORT(rtgui_widget_focus); RTM_EXPORT(rtgui_timer_create);
RTM_EXPORT(rtgui_widget_set_event_handler); RTM_EXPORT(rtgui_timer_destory);
RTM_EXPORT(rtgui_widget_rect_to_device); RTM_EXPORT(rtgui_timer_stop);
RTM_EXPORT(rtgui_widget_update); RTM_EXPORT(rtgui_thread_register);
RTM_EXPORT(rtgui_widget_get_rect); RTM_EXPORT(rtgui_thread_deregister);
RTM_EXPORT(rtgui_widget_set_rect); RTM_EXPORT(rtgui_widget_focus);
RTM_EXPORT(rtgui_widget_get_toplevel); RTM_EXPORT(rtgui_widget_set_event_handler);
RTM_EXPORT(rtgui_panel_register); RTM_EXPORT(rtgui_widget_rect_to_device);
RTM_EXPORT(rtgui_panel_set_default_focused); RTM_EXPORT(rtgui_widget_update);
RTM_EXPORT(rtgui_button_create); RTM_EXPORT(rtgui_widget_get_rect);
RTM_EXPORT(rtgui_button_destroy); RTM_EXPORT(rtgui_widget_set_rect);
RTM_EXPORT(rtgui_button_set_onbutton); RTM_EXPORT(rtgui_widget_get_toplevel);
RTM_EXPORT(rtgui_container_add_child); RTM_EXPORT(rtgui_panel_register);
RTM_EXPORT(rtgui_filelist_view_create); RTM_EXPORT(rtgui_panel_set_default_focused);
RTM_EXPORT(rtgui_filelist_view_get_fullpath); RTM_EXPORT(rtgui_button_create);
RTM_EXPORT(rtgui_list_view_create); RTM_EXPORT(rtgui_button_destroy);
RTM_EXPORT(rtgui_list_view_destroy); RTM_EXPORT(rtgui_button_set_onbutton);
RTM_EXPORT(rtgui_listctrl_set_onitem); RTM_EXPORT(rtgui_container_add_child);
RTM_EXPORT(rtgui_image_create_from_mem); RTM_EXPORT(rtgui_filelist_view_create);
RTM_EXPORT(rtgui_listctrl_create); RTM_EXPORT(rtgui_filelist_view_get_fullpath);
RTM_EXPORT(rtgui_list_view_create);
#endif RTM_EXPORT(rtgui_list_view_destroy);
#endif RTM_EXPORT(rtgui_listctrl_set_onitem);
RTM_EXPORT(rtgui_image_create_from_mem);
RTM_EXPORT(rtgui_listctrl_create);
RTM_EXPORT(rtgui_listctrl_set_items);
#endif
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册