PageRenderTime 53ms CodeModel.GetById 21ms app.highlight 10ms RepoModel.GetById 20ms app.codeStats 0ms

/src/demos/demo_popup.c

http://ftk.googlecode.com/
C | 135 lines | 102 code | 33 blank | 0 comment | 4 complexity | 2f4b264d4201b384b424cded70e8ebb6 MD5 | raw file
  1#include "ftk.h"
  2
  3static Ret button_close_clicked(void* ctx, void* obj)
  4{
  5	ftk_widget_unref(ctx);
  6
  7	return RET_OK;
  8}
  9
 10static FtkListItemInfo g_infos[4];
 11static Ret on_menu_item_clicked(void* ctx, void* data)
 12{
 13	FtkListItemInfo* info = data;
 14
 15	ftk_logd("%s: %s is selected\n", __func__, info->text);
 16
 17	return RET_OK;
 18}
 19
 20static Ret button_normal_clicked(void* ctx, void* obj)
 21{
 22	FtkBitmap* icon = ftk_theme_load_image(ftk_default_theme(), "info"FTK_STOCK_IMG_SUFFIX); 
 23	FtkWidget* thiz = ftk_popup_menu_create(0, 0, 0, 200, icon, "Edit");
 24	
 25	size_t i = 0;
 26	for(i = 0; i < FTK_ARRAY_SIZE(g_infos); i++)
 27	{
 28		g_infos[i].type = FTK_LIST_ITEM_NORMAL;
 29		ftk_popup_menu_add(thiz, g_infos+i);
 30	}
 31	ftk_bitmap_unref(icon);
 32
 33	ftk_popup_menu_set_clicked_listener(thiz, on_menu_item_clicked, NULL);
 34
 35	ftk_widget_show_all(thiz, 1);
 36
 37	return RET_OK;
 38}
 39
 40static Ret button_radio_clicked(void* ctx, void* obj)
 41{
 42	FtkBitmap* icon = ftk_theme_load_image(ftk_default_theme(), "info"FTK_STOCK_IMG_SUFFIX); 
 43	FtkWidget* thiz = ftk_popup_menu_create(0, 0, 0, 200, icon, "Edit");
 44	
 45	size_t i = 0;
 46	for(i = 0; i < FTK_ARRAY_SIZE(g_infos); i++)
 47	{
 48		g_infos[i].type = FTK_LIST_ITEM_RADIO;
 49		g_infos[i].state = i == 0;
 50		ftk_popup_menu_add(thiz, g_infos+i);
 51	}
 52	ftk_bitmap_unref(icon);
 53	
 54	ftk_popup_menu_set_clicked_listener(thiz, on_menu_item_clicked, NULL);
 55
 56	ftk_widget_show_all(thiz, 1);
 57
 58	return RET_OK;
 59}
 60
 61static Ret button_check_clicked(void* ctx, void* obj)
 62{
 63	FtkBitmap* icon = ftk_theme_load_image(ftk_default_theme(), "info"FTK_STOCK_IMG_SUFFIX); 
 64	FtkWidget* thiz = ftk_popup_menu_create(0, 0, 0, 200, icon, "Edit");
 65	
 66	size_t i = 0;
 67	for(i = 0; i < FTK_ARRAY_SIZE(g_infos); i++)
 68	{
 69		g_infos[i].type = FTK_LIST_ITEM_CHECK;
 70		g_infos[i].state = i%2;
 71		ftk_popup_menu_add(thiz, g_infos+i);
 72	}
 73	ftk_bitmap_unref(icon);
 74
 75	ftk_popup_menu_set_clicked_listener(thiz, on_menu_item_clicked, NULL);
 76
 77	ftk_widget_show_all(thiz, 1);
 78
 79	return RET_OK;
 80}
 81
 82#ifdef FTK_AS_PLUGIN
 83#include "ftk_app_demo.h"
 84FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
 85FtkApp* ftk_app_demo_popup_create()
 86{
 87	return ftk_app_demo_create(_("popup"), ftk_main);
 88}
 89#else
 90#define FTK_HIDE extern
 91#endif /*FTK_AS_PLUGIN*/
 92
 93FTK_HIDE int FTK_MAIN(int argc, char* argv[])
 94{
 95	int width = 0;
 96	int height = 0;
 97	FtkWidget* win = NULL;
 98	FtkWidget* button = NULL;
 99	
100	FTK_INIT(argc, argv);
101
102	g_infos[0].text = "Copy";
103	g_infos[1].text = "Paste";
104	g_infos[2].text = "Cut";
105	g_infos[3].text = "Select All";
106
107	win = ftk_app_window_create();
108	width = ftk_widget_width(win);
109	height = ftk_widget_height(win);
110
111	button = ftk_button_create(win, 0, height/6, width/3, 50);
112	ftk_widget_set_text(button, "Normal");
113	ftk_button_set_clicked_listener(button, button_normal_clicked, NULL);
114
115	button = ftk_button_create(win, 2*width/3, height/6, width/3, 50);
116	ftk_widget_set_text(button, "Radio");
117	ftk_button_set_clicked_listener(button, button_radio_clicked, NULL);
118
119	button = ftk_button_create(win, 0, height/2, width/3, 50);
120	ftk_widget_set_text(button, "CheckBox");
121	ftk_button_set_clicked_listener(button, button_check_clicked, NULL);
122	
123	button = ftk_button_create(win, 2*width/3, height/2, width/3, 50);
124	ftk_widget_set_text(button, "Quit");
125	ftk_button_set_clicked_listener(button, button_close_clicked, win);
126	
127	ftk_widget_set_text(win, "pupup");
128	ftk_widget_show_all(win, 1);
129	FTK_QUIT_WHEN_WIDGET_CLOSE(win);
130
131	FTK_RUN();
132
133	return 0;
134}
135