demo_msgbox.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "ftk.h"
  2. static const char* buttons1[] = {"Yes", NULL};
  3. static const char* buttons2[] = {"Yes", "No", NULL};
  4. static const char* buttons3[] = {"Yes", "No", "Cancel", NULL};
  5. static Ret button_warning(void* ctx, void* obj)
  6. {
  7. int ret = ftk_warning("Warning", "December 31, 2008: patchwork.kernel.org is now available for general use. It is currently only monitoring the Linux Kernel mailing-list, but should be useful to kernel developers in dealing with patches flying across the wire.", buttons1);
  8. ftk_logd("%s: ret = %d\n", __func__, ret);
  9. return RET_OK;
  10. }
  11. static Ret button_info(void* ctx, void* obj)
  12. {
  13. int ret = ftk_infomation("Infomation", "September 19, 2008: mirrors.kernel.org has been flipped over to using our new GeoDNS based bind server (named-geodns). This means that, at the dns query level, our servers will attempt to direct you to the nearest / fastest kernel.org mirror for your request. This means that you no longer have to use mirrors.us.kernel.org or mirrors.eu.kernel.org to generally route you to the right place. This does mean a change to mirrors.kernel.org no longer explicitly pointing at mirrors.us.kernel.org. Additional information on named-geodns will be forth coming, check back here for an addendum soon.", buttons2);
  14. ftk_logd("%s: ret = %d\n", __func__, ret);
  15. return RET_OK;
  16. }
  17. static Ret button_question(void* ctx, void* obj)
  18. {
  19. int ret = ftk_question("Question", "Are you sure to quit?", buttons3);
  20. ftk_logd("%s: ret = %d\n", __func__, ret);
  21. return RET_OK;
  22. }
  23. static Ret button_tips(void* ctx, void* obj)
  24. {
  25. int ret = ftk_tips("The dialog will quit in 3 seconds.");
  26. ftk_logd("%s: ret = %d\n", __func__, ret);
  27. return RET_OK;
  28. }
  29. static Ret button_quit(void* ctx, void* obj)
  30. {
  31. ftk_widget_unref(ctx);
  32. return RET_OK;
  33. }
  34. #ifdef FTK_AS_PLUGIN
  35. #include "ftk_app_demo.h"
  36. FTK_HIDE int FTK_MAIN(int argc, char* argv[]);
  37. FtkApp* ftk_app_demo_msgbox_create()
  38. {
  39. return ftk_app_demo_create(_("msgbox"), ftk_main);
  40. }
  41. #else
  42. #define FTK_HIDE extern
  43. #endif /*FTK_AS_PLUGIN*/
  44. FTK_HIDE int FTK_MAIN(int argc, char* argv[])
  45. {
  46. int y = 0;
  47. int width = 0;
  48. int height = 0;
  49. FtkWidget* win = NULL;
  50. FtkWidget* button = NULL;
  51. FTK_INIT(argc, argv);
  52. win = ftk_app_window_create();
  53. width = ftk_widget_width(win);
  54. height = ftk_widget_height(win);
  55. y = (height - 240)/2;
  56. y = y > 0 ? y : 0;
  57. button = ftk_button_create(win, 0, y, width/2, 50);
  58. ftk_widget_set_text(button, "question");
  59. ftk_button_set_clicked_listener(button, button_question, win);
  60. button = ftk_button_create(win, width/2, y, width/2, 50);
  61. ftk_widget_set_text(button, "warning");
  62. ftk_button_set_clicked_listener(button, button_warning, win);
  63. button = ftk_button_create(win, 0, y+60, width/2, 50);
  64. ftk_widget_set_text(button, "info");
  65. ftk_button_set_clicked_listener(button, button_info, win);
  66. button = ftk_button_create(win, width/2, y+60, width/2, 50);
  67. ftk_widget_set_text(button, "tips");
  68. ftk_button_set_clicked_listener(button, button_tips, win);
  69. button = ftk_button_create(win, width/4, y+120, width/2, 50);
  70. ftk_widget_set_text(button, "quit");
  71. ftk_button_set_clicked_listener(button, button_quit, win);
  72. ftk_widget_set_text(win, "message box demo");
  73. ftk_widget_show_all(win, 1);
  74. FTK_QUIT_WHEN_WIDGET_CLOSE(win);
  75. FTK_RUN();
  76. return 0;
  77. }