PageRenderTime 213ms CodeModel.GetById 100ms app.highlight 8ms RepoModel.GetById 103ms app.codeStats 0ms

/src/demos/demo_tab.c

http://ftk.googlecode.com/
C | 89 lines | 69 code | 20 blank | 0 comment | 0 complexity | 6aeb078a211fb45d0c9aea14865d19a1 MD5 | raw file
 1#include "ftk.h"
 2#include "ftk_tab.h"
 3
 4static Ret button_default_clicked(void* ctx, void* obj)
 5{
 6	printf("%s: button %s is clicked.\n", __func__, ftk_widget_get_text(obj));
 7
 8	return RET_OK;
 9}
10
11static Ret button_quit_clicked(void* ctx, void* obj)
12{
13	ftk_widget_unref(ctx);
14
15	return RET_OK;
16}
17
18#ifdef FTK_AS_PLUGIN
19#include "ftk_app_demo.h"
20FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
21FtkApp* ftk_app_demo_tab_create()
22{
23	return ftk_app_demo_create(_("tab"), ftk_main);
24}
25#else
26#define FTK_HIDE extern
27#endif /*FTK_AS_PLUGIN*/
28
29static void add_page(FtkWidget* tab, const char* text, FtkBitmap* bitmap)
30{
31	int width = 0;
32	int height = 0;
33	FtkWidget* page = NULL;
34	FtkWidget* button = NULL;
35	
36	page = ftk_tab_add_page(tab, text, bitmap);
37	width = ftk_widget_width(page);
38	height = ftk_widget_height(page);
39
40	button = ftk_button_create(page, 0, height/2-30, width/2, 60);
41	ftk_widget_set_text(button, text); 
42	ftk_widget_show(button, 1);
43	ftk_button_set_clicked_listener(button, button_default_clicked, tab);
44	
45	button = ftk_button_create(page, width/2, height/2-30, width/2, 60);
46	ftk_widget_set_text(button, text); 
47	ftk_widget_show(button, 1);
48	ftk_button_set_clicked_listener(button, button_default_clicked, tab);
49
50	return;
51}
52
53FTK_HIDE int FTK_MAIN(int argc, char* argv[])
54{
55	int width = 0;
56	int height = 0;
57	FtkWidget* win = NULL;
58	FtkWidget* tab = NULL;
59	FtkWidget* button = NULL;
60	FtkBitmap* bitmap = NULL;
61	FTK_INIT(argc, argv);
62	
63	bitmap = ftk_theme_load_image(ftk_default_theme(), "mime_audio"FTK_STOCK_IMG_SUFFIX);
64	win = ftk_app_window_create();
65	width = ftk_widget_width(win);
66	height = ftk_widget_height(win);
67
68	tab = ftk_tab_create(win, 0, 0, width, height - 50);
69
70	add_page(tab, "General", bitmap);
71	add_page(tab, "Graphic", bitmap);
72	add_page(tab, "Audio", bitmap);
73
74	ftk_tab_set_active_page(tab, 0);
75	
76	button = ftk_button_create(win, width/4, height - 50, width/2, 50);
77	ftk_widget_set_text(button, _("Quit")); 
78	ftk_widget_show(button, 1);
79
80	ftk_button_set_clicked_listener(button, button_quit_clicked, win);
81
82	ftk_widget_show_all(win, 1);
83	FTK_QUIT_WHEN_WIDGET_CLOSE(win);
84	FTK_BITMAP_UNREF(bitmap);
85
86	FTK_RUN();
87
88	return 0;
89}