test_lastwidgets.mod 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. MODULE test_lastwidgets ;
  2. (*
  3. m2-GTK4 test - the last few widgets: GtkAssistant, GtkIconView and
  4. GtkEmojiChooser. Requires a display.
  5. *)
  6. FROM Gio IMPORT g_application_run, g_application_quit;
  7. FROM GtkApplication IMPORT gtk_application_new;
  8. FROM GtkWindow IMPORT gtk_application_window_new, gtk_window_set_child,
  9. gtk_window_present;
  10. FROM GtkBox IMPORT gtk_box_new, gtk_box_append;
  11. FROM GtkEnums IMPORT GtkVertical, GtkSelectionMultiple;
  12. FROM GtkLabel IMPORT gtk_label_new;
  13. FROM GtkAssistant IMPORT gtk_assistant_new, gtk_assistant_append_page,
  14. gtk_assistant_get_n_pages, gtk_assistant_get_nth_page,
  15. gtk_assistant_set_page_title, gtk_assistant_set_page_complete,
  16. gtk_assistant_set_page_type, gtk_assistant_set_current_page,
  17. gtk_assistant_get_current_page, gtk_assistant_previous_page,
  18. gtk_assistant_commit, AssistantPageContent;
  19. FROM GtkIconView IMPORT gtk_icon_view_new, gtk_icon_view_set_columns,
  20. gtk_icon_view_get_columns, gtk_icon_view_set_text_column,
  21. gtk_icon_view_get_text_column, gtk_icon_view_set_item_width,
  22. gtk_icon_view_set_spacing, gtk_icon_view_set_selection_mode;
  23. FROM GtkEmojiChooser IMPORT gtk_emoji_chooser_new;
  24. FROM GtkUtils IMPORT Connect;
  25. FROM SYSTEM IMPORT ADDRESS, ADR;
  26. FROM libc IMPORT printf;
  27. CONST
  28. AppId = "org.example.m2gtk4.TestLastWidgets";
  29. VAR
  30. app: ADDRESS;
  31. passed: BOOLEAN;
  32. PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
  33. VAR
  34. window, box, assistant, p1, p2, iconview, emoji: ADDRESS;
  35. ok: BOOLEAN;
  36. BEGIN
  37. ok := TRUE;
  38. (* GtkAssistant *)
  39. assistant := gtk_assistant_new();
  40. IF assistant = NIL THEN printf("assistant NIL\n"); ok := FALSE END;
  41. p1 := gtk_label_new("Step one");
  42. p2 := gtk_label_new("Step two");
  43. IF gtk_assistant_append_page(assistant, p1) # 0 THEN
  44. printf("first page index wrong\n"); ok := FALSE
  45. END;
  46. IF gtk_assistant_append_page(assistant, p2) # 1 THEN
  47. printf("second page index wrong\n"); ok := FALSE
  48. END;
  49. IF gtk_assistant_get_n_pages(assistant) # 2 THEN
  50. printf("assistant page count wrong\n"); ok := FALSE
  51. END;
  52. IF gtk_assistant_get_nth_page(assistant, 1) # p2 THEN
  53. printf("assistant nth page wrong\n"); ok := FALSE
  54. END;
  55. gtk_assistant_set_page_title(assistant, p1, "One");
  56. gtk_assistant_set_page_complete(assistant, p1, 1);
  57. gtk_assistant_set_page_type(assistant, p1, AssistantPageContent);
  58. gtk_assistant_set_current_page(assistant, 1);
  59. IF gtk_assistant_get_current_page(assistant) # 1 THEN
  60. printf("assistant current page wrong\n"); ok := FALSE
  61. END;
  62. gtk_assistant_commit(assistant);
  63. (* GtkIconView *)
  64. iconview := gtk_icon_view_new();
  65. IF iconview = NIL THEN printf("icon view NIL\n"); ok := FALSE END;
  66. gtk_icon_view_set_columns(iconview, 3);
  67. IF gtk_icon_view_get_columns(iconview) # 3 THEN
  68. printf("icon view columns wrong\n"); ok := FALSE
  69. END;
  70. gtk_icon_view_set_text_column(iconview, 0);
  71. IF gtk_icon_view_get_text_column(iconview) # 0 THEN
  72. printf("icon view text column wrong\n"); ok := FALSE
  73. END;
  74. gtk_icon_view_set_item_width(iconview, 64);
  75. gtk_icon_view_set_spacing(iconview, 6);
  76. gtk_icon_view_set_selection_mode(iconview, GtkSelectionMultiple);
  77. (* GtkEmojiChooser *)
  78. emoji := gtk_emoji_chooser_new();
  79. IF emoji = NIL THEN printf("emoji chooser NIL\n"); ok := FALSE END;
  80. box := gtk_box_new(GtkVertical, 4);
  81. gtk_box_append(box, iconview);
  82. window := gtk_application_window_new(application);
  83. gtk_window_set_child(window, box);
  84. gtk_window_present(window);
  85. passed := ok;
  86. g_application_quit(application)
  87. END OnActivate;
  88. VAR
  89. rc: INTEGER;
  90. BEGIN
  91. passed := FALSE;
  92. app := gtk_application_new(AppId, 0);
  93. IF app = NIL THEN
  94. printf("test_lastwidgets: FAIL (no app)\n");
  95. HALT(1)
  96. END;
  97. Connect(app, "activate", ADR(OnActivate), NIL);
  98. rc := g_application_run(app, 0, NIL);
  99. IF passed THEN
  100. printf("test_lastwidgets: PASS\n");
  101. HALT(0)
  102. ELSE
  103. printf("test_lastwidgets: FAIL\n");
  104. HALT(1)
  105. END
  106. END test_lastwidgets.