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