pui4.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*--------------------------------------------------------------------------
  2. DEPUI-GFX-TK 3.0 - GPL portable source code libraries
  3. http://www.deleveld.dds.nl/depui.htm
  4. See file docs/copying for copyright details
  5. ---------------------------------------------------------------------------*/
  6. #define MXMODULE_THEME_ROUNDED
  7. #define MXMODULE_FONT_ALL
  8. #define MXMODULE_SYSMENU
  9. #define MXMODULE_FONTSEL
  10. #include "depui/depui.c"
  11. typedef struct APP {
  12. union {
  13. MX_WIN_DATA win;
  14. MX_TEXTUAL_DATA textual;
  15. MX_OBJ_DATA obj;
  16. MX_RECTATOM_DATA rectatom;
  17. MX_ATOM atom;
  18. } base;
  19. MX_BUTTON choose;
  20. MX_TEXTUAL filename;
  21. } APP;
  22. static void handler(MX_WIN * win)
  23. {
  24. APP *app = (APP *) win;
  25. /* Start the file selector to choose a filename */
  26. if ((mx.event == MX_SELECT) && (mx.data)
  27. && (MXOBJ(mx.obj) == MXOBJ(&app->choose))) {
  28. MX_FONTSEL *fontsel = mx_fontselwin(0, 0, 0, 0);
  29. mx_modal(fontsel);
  30. mx_fontsel_refresh(fontsel);
  31. mx_defaultrect(fontsel, 0);
  32. mx_layout(fontsel, MX_LAYOUT_CENTER, (MX_OBJ *)0, 0, 0);
  33. mx_geometry(fontsel);
  34. mx_win_dirty(fontsel);
  35. return;
  36. /* When a filename has been chosen, copy the text for the button */
  37. } else if (mx.event == MX_FONTSEL_OK) {
  38. MX_GUIFONT *font = mx_fontsel_info(0);
  39. /* Make a copy of the filename text */
  40. if (font) {
  41. char *text;
  42. const char *name = mx_guifont_text(font);
  43. mx_guifont_default(font);
  44. text = mx_malloc(strlen(name) + 1);
  45. assert(text);
  46. strcpy(text, name);
  47. /* Change the text to be displayed */
  48. mx_text_set(&app->filename, text, -1, mx_free);
  49. mx_defaultrect(&app->filename, 0);
  50. mx_geometry(&app->filename);
  51. mx_dirty(&app->filename, true);
  52. }
  53. }
  54. mx_win_handler(win);
  55. }
  56. static APP *newapp(void)
  57. {
  58. /* Create the window for the app */
  59. APP *app = (APP *) mx_win((MX_WIN *)0, sizeof(APP), handler, 0);
  60. if (app) {
  61. /* Make the button */
  62. mx_button(&app->choose, 0, app, 0);
  63. mx_text_set(&app->choose, "choose", -1, 0);
  64. mx_defaultrect(&app->choose, 0);
  65. /* Make the filename text */
  66. mx_textual(&app->filename, 0, app, 0);
  67. mx_text_set(&app->filename, "No font chosen", -1, 0);
  68. mx_defaultrect(&app->filename, 0);
  69. /* Place the button and text */
  70. mx_move(&app->choose, 5, 5);
  71. mx_layout(&app->filename, (MX_LAYOUT) (MX_LAYOUT_X1 | MX_LAYOUT_BOTTOM),
  72. &app->choose, 0, 5);
  73. }
  74. return app;
  75. }
  76. int main(int argc, char *argv[])
  77. {
  78. APP *app;
  79. (void) argc;
  80. (void) argv;
  81. if (!mx_start())
  82. return EXIT_FAILURE;
  83. mx_sysmenu();
  84. app = newapp();
  85. assert(app);
  86. mx_position(app, 50, 50, 200, 250);
  87. mx_text_set(app, "Font and filename test", -1, 0);
  88. mx_geometry(app);
  89. return mx_execute();
  90. }