PageRenderTime 255ms CodeModel.GetById 151ms app.highlight 7ms RepoModel.GetById 94ms app.codeStats 0ms

/src/demos/demo_multi_win.c

http://ftk.googlecode.com/
C | 87 lines | 66 code | 21 blank | 0 comment | 2 complexity | 241b32819cfd0b582204871eecdf9267 MD5 | raw file
 1#include "ftk.h"
 2
 3static void create_app_window(void);
 4static Ret button_open_clicked(void* ctx, void* obj)
 5{
 6	create_app_window();
 7
 8	return RET_OK;
 9}
10
11static Ret button_close_clicked(void* ctx, void* obj)
12{
13	FtkWidget* win = ctx;
14	ftk_logd("%s: close window %s\n", __func__, ftk_widget_get_text(win));
15	ftk_widget_unref(win);
16
17	return RET_OK;
18}
19
20static int g_index = 0;
21static void on_window_close(void* user_data)
22{
23	g_index--;
24
25	ftk_logd("%s: g_index=%d\n", __func__, g_index);
26	if(g_index == 0)
27	{
28		FTK_QUIT();
29	}
30
31	return ;
32}
33
34
35static void create_app_window(void)
36{
37	char title[32] = {0};
38	int width = 0;
39	int height = 0;
40	FtkWidget* win = ftk_app_window_create();
41	FtkWidget* label = NULL;
42	FtkWidget* button = NULL;
43	
44	width = ftk_widget_width(win);
45	height = ftk_widget_height(win);
46
47	button = ftk_button_create(win, 0, height/6, width/3, 50);
48	ftk_widget_set_text(button, "????");
49	ftk_button_set_clicked_listener(button, button_open_clicked, win);
50
51	button = ftk_button_create(win, 2*width/3, height/6, width/3, 50);
52	ftk_widget_set_text(button, "????");
53	ftk_button_set_clicked_listener(button, button_close_clicked, win);
54
55	ftk_snprintf(title, sizeof(title), "window%02d", g_index++);
56	label = ftk_label_create(win, width/4, height/2, width/2, 30);
57	ftk_widget_set_text(label, title);
58	
59	ftk_widget_set_text(win, title);
60	ftk_widget_show_all(win, 1);
61	ftk_widget_set_user_data(win, on_window_close, win);
62
63	return;
64}
65
66#ifdef FTK_AS_PLUGIN
67#include "ftk_app_demo.h"
68FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
69FtkApp* ftk_app_demo_multi_win_create()
70{
71	return ftk_app_demo_create(_("multi_win"), ftk_main);
72}
73#else
74#define FTK_HIDE extern
75#endif /*FTK_AS_PLUGIN*/
76
77FTK_HIDE int FTK_MAIN(int argc, char* argv[])
78{
79	FTK_INIT(argc, argv);
80	
81	create_app_window();
82
83	FTK_RUN();
84
85	return 0;
86}
87