PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/src/demos/demo_file_browser.c

http://ftk.googlecode.com/
C | 100 lines | 77 code | 23 blank | 0 comment | 0 complexity | a10b3161e0b7ffbd90bcae591ba2776d MD5 | raw file
  1#include "ftk.h"
  2#include "ftk_file_browser.h"
  3
  4static Ret on_file_selected(void* ctx, int index, const char* path)
  5{
  6	ftk_logd("%s: [%d] %s\n", __func__, index, path);
  7
  8	return RET_OK;
  9}
 10
 11#define IDC_TEST_BUTTON 1000
 12static Ret button_quit_clicked(void* ctx, void* obj)
 13{
 14	ftk_widget_unref(ctx);
 15
 16	return RET_OK;
 17}
 18
 19static Ret button_browser_clicked(void* ctx, void* obj)
 20{
 21	FtkWidget* win = ftk_file_browser_create(FTK_FILE_BROWER_APP);
 22	ftk_file_browser_set_path(win, "./");
 23	ftk_file_browser_load(win);
 24
 25	return RET_OK;
 26}
 27
 28static Ret button_single_choose_clicked(void* ctx, void* obj)
 29{
 30	FtkWidget* win = ftk_file_browser_create(FTK_FILE_BROWER_SINGLE_CHOOSER);
 31	ftk_file_browser_set_choosed_handler(win, on_file_selected, NULL);
 32	ftk_file_browser_set_path(win, "./");
 33	ftk_file_browser_load(win);
 34
 35	return RET_OK;
 36}
 37
 38static Ret button_multi_choose_clicked(void* ctx, void* obj)
 39{
 40	FtkWidget* win = ftk_file_browser_create(FTK_FILE_BROWER_MULTI_CHOOSER);
 41	ftk_file_browser_set_choosed_handler(win, on_file_selected, NULL);
 42	ftk_file_browser_set_path(win, "./");
 43	ftk_file_browser_load(win);
 44
 45
 46	return RET_OK;
 47}
 48
 49#ifdef FTK_AS_PLUGIN
 50#include "ftk_app_demo.h"
 51FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
 52FtkApp* ftk_app_demo_file_browser_create()
 53{
 54	return ftk_app_demo_create(_("file_browser"), ftk_main);
 55}
 56#else
 57#define FTK_HIDE extern
 58#endif /*FTK_AS_PLUGIN*/
 59
 60FTK_HIDE int FTK_MAIN(int argc, char* argv[])
 61{
 62	int width = 0;
 63	int height = 0;
 64	FtkWidget* win = NULL;
 65	FtkWidget* button = NULL;
 66
 67	FTK_INIT(argc, argv);
 68	
 69	win = ftk_app_window_create();
 70	ftk_window_set_animation_hint(win, "app_main_window");
 71	width = ftk_widget_width(win);
 72	height = ftk_widget_height(win);
 73	
 74	width = width/2 - 10;
 75	button = ftk_button_create(win, 0, height/4, width, 50);
 76	ftk_widget_set_text(button, "Single Choose");
 77	ftk_button_set_clicked_listener(button, button_single_choose_clicked, win);
 78
 79	button = ftk_button_create(win, width + 10, height/4, width, 50);
 80	ftk_widget_set_text(button, "Browser");
 81	ftk_button_set_clicked_listener(button, button_browser_clicked, win);
 82	
 83	button = ftk_button_create(win, 0, height/2, width, 50);
 84	ftk_widget_set_text(button, "Multi Choose");
 85	ftk_button_set_clicked_listener(button, button_multi_choose_clicked, win);
 86
 87	button = ftk_button_create(win, width + 10, height/2, width, 50);
 88	ftk_widget_set_text(button, "Quit");
 89	ftk_button_set_clicked_listener(button, button_quit_clicked, win);
 90	ftk_window_set_focus(win, button);
 91
 92	ftk_widget_set_text(win, "FileBrowser");
 93	ftk_widget_show_all(win, 1);
 94	FTK_QUIT_WHEN_WIDGET_CLOSE(win);
 95
 96	FTK_RUN();
 97
 98	return 0;
 99}
100