PageRenderTime 271ms CodeModel.GetById 110ms app.highlight 10ms RepoModel.GetById 141ms app.codeStats 0ms

/src/demos/demo_dialog.c

http://ftk.googlecode.com/
C | 126 lines | 96 code | 25 blank | 5 comment | 4 complexity | f2ced2c1afe01c416b72b0be4c3b57da MD5 | raw file
  1#include "ftk.h"
  2
  3#ifdef FTK_AS_PLUGIN
  4#include "ftk_app_demo.h"
  5FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
  6FtkApp* ftk_app_demo_dialog_create()
  7{
  8	return ftk_app_demo_create(_("dialog"), ftk_main);
  9}
 10#else
 11#define FTK_HIDE extern
 12#endif /*FTK_AS_PLUGIN*/
 13
 14static Ret button_quit_clicked(void* ctx, void* obj)
 15{
 16	if(ctx != NULL)
 17	{
 18		/*modal*/
 19		*(int*)ctx = ftk_widget_id(obj);
 20	}
 21	else
 22	{
 23		/*modal-less*/
 24		ftk_widget_unref(ftk_widget_toplevel(obj));
 25	}
 26
 27	return RET_QUIT;
 28}
 29
 30static Ret button_close_clicked(void* ctx, void* obj)
 31{
 32	ftk_widget_unref(ctx);
 33
 34	return RET_OK;
 35}
 36
 37static Ret button_dialog_clicked(void* ctx, void* obj)
 38{
 39	int id = 0;
 40	int width = 0;
 41	int height = 0;
 42//	FtkWidget* label = NULL;
 43	FtkWidget* button = NULL;
 44	FtkWidget* dialog = NULL;
 45	FtkBitmap* icon = NULL;
 46	FtkWidget* combo_box = NULL;
 47	int modal = (int)ctx;
 48	
 49	ftk_logd("%s:%d begin\n", __func__, __LINE__);
 50	dialog = ftk_dialog_create(0, 40, 320, 240);
 51	
 52	icon = ftk_theme_load_image(ftk_default_theme(), "info"FTK_STOCK_IMG_SUFFIX);
 53	ftk_dialog_set_icon(dialog, icon);
 54
 55	width = ftk_widget_width(dialog);
 56	height = ftk_widget_height(dialog);
 57//	label = ftk_label_create(dialog, width/6, height/4, 5*width/6, 20);
 58//	ftk_widget_set_text(label, "Are you sure to quit?");
 59	
 60	combo_box = ftk_combo_box_create(dialog, width/6, height/4, 2*width/3, 30);
 61	ftk_combo_box_set_text(combo_box, "1 second");
 62	ftk_combo_box_append(combo_box, NULL, "1 second");
 63	ftk_combo_box_append(combo_box, NULL, "2 seconds");
 64	ftk_combo_box_append(combo_box, NULL, "3 seconds");
 65	ftk_entry_set_readonly(ftk_combo_box_get_entry(combo_box), modal);
 66
 67	button = ftk_button_create(dialog, width/6, height/2, width/3, 50);
 68	ftk_widget_set_text(button, "yes");
 69	ftk_button_set_clicked_listener(button, button_quit_clicked, modal ? &id : NULL);
 70	
 71	button = ftk_button_create(dialog, width/2, height/2, width/3, 50);
 72	ftk_widget_set_text(button, "no");
 73	ftk_button_set_clicked_listener(button, button_quit_clicked, modal ? &id : NULL);
 74	ftk_window_set_focus(dialog, button);
 75
 76	ftk_widget_set_text(dialog, modal ? "model dialog" : "normal dialog");
 77
 78	if(modal)
 79	{
 80		assert(ftk_dialog_run(dialog) == id);
 81		ftk_widget_unref(dialog);
 82	}
 83	else
 84	{
 85		ftk_widget_show_all(dialog, 1);
 86	}
 87	ftk_logd("%s:%d end\n", __func__, __LINE__);
 88
 89	return RET_OK;
 90}
 91
 92FTK_HIDE int FTK_MAIN(int argc, char* argv[])
 93{
 94	int width = 0;
 95	int height = 0;
 96	FtkWidget* win = NULL;
 97	FtkWidget* button = NULL;
 98	
 99	FTK_INIT(argc, argv);
100
101	win = ftk_app_window_create();
102	ftk_window_set_animation_hint(win, "app_main_window");
103	width = ftk_widget_width(win);
104	height = ftk_widget_height(win);
105
106	button = ftk_button_create(win, 0, height/6, width/3, 50);
107	ftk_widget_set_text(button, "Normal");
108	ftk_button_set_clicked_listener(button, button_dialog_clicked, NULL);
109
110	button = ftk_button_create(win, 2*width/3, height/6, width/3, 50);
111	ftk_widget_set_text(button, "Modal");
112	ftk_button_set_clicked_listener(button, button_dialog_clicked, (void*)1);
113
114	button = ftk_button_create(win, width/4, height/2, width/2, 60);
115	ftk_widget_set_text(button, "quit");
116	ftk_button_set_clicked_listener(button, button_close_clicked, win);
117
118	ftk_widget_set_text(win, "demo dialog");
119	ftk_widget_show_all(win, 1);
120	FTK_QUIT_WHEN_WIDGET_CLOSE(win);
121
122	FTK_RUN();
123
124	return 0;
125}
126