test_adw.mod 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. MODULE test_adw ;
  2. (*
  3. m2-GTK4 test - libadwaita widgets: application window, toolbar view,
  4. header bar, preferences page/group, the settings rows, status page,
  5. banner, clamp, toast and message dialog. Requires a display and
  6. libadwaita.
  7. *)
  8. FROM Gio IMPORT g_application_run, g_application_quit;
  9. FROM AdwApplication IMPORT adw_application_new;
  10. FROM AdwApplicationWindow IMPORT adw_application_window_new,
  11. adw_application_window_set_content;
  12. FROM AdwHeaderBar IMPORT adw_header_bar_new,
  13. adw_header_bar_set_title_widget, adw_header_bar_get_title_widget,
  14. adw_header_bar_set_show_title, adw_header_bar_get_show_title,
  15. adw_header_bar_set_centering_policy, adw_header_bar_get_centering_policy,
  16. AdwCenteringStrict;
  17. FROM AdwToolbarView IMPORT adw_toolbar_view_new, adw_toolbar_view_add_top_bar,
  18. adw_toolbar_view_set_content, adw_toolbar_view_set_top_bar_style,
  19. adw_toolbar_view_get_top_bar_style, AdwToolbarRaised;
  20. FROM AdwPreferencesPage IMPORT adw_preferences_page_new,
  21. adw_preferences_page_add, adw_preferences_page_set_title,
  22. adw_preferences_page_get_title, adw_preferences_page_set_banner;
  23. FROM AdwPreferencesGroup IMPORT adw_preferences_group_new,
  24. adw_preferences_group_add, adw_preferences_group_set_title,
  25. adw_preferences_group_get_title;
  26. FROM AdwPreferencesRow IMPORT adw_preferences_row_set_title,
  27. adw_preferences_row_get_title;
  28. FROM AdwActionRow IMPORT adw_action_row_new, adw_action_row_set_subtitle,
  29. adw_action_row_get_subtitle;
  30. FROM AdwSwitchRow IMPORT adw_switch_row_new, adw_switch_row_set_active,
  31. adw_switch_row_get_active;
  32. FROM AdwEntryRow IMPORT adw_entry_row_new, adw_entry_row_set_max_length,
  33. adw_entry_row_get_max_length;
  34. FROM AdwComboRow IMPORT adw_combo_row_new, adw_combo_row_set_model,
  35. adw_combo_row_set_selected, adw_combo_row_get_selected;
  36. FROM AdwExpanderRow IMPORT adw_expander_row_new, adw_expander_row_set_expanded,
  37. adw_expander_row_get_expanded;
  38. FROM AdwStatusPage IMPORT adw_status_page_new, adw_status_page_set_title,
  39. adw_status_page_get_title;
  40. FROM AdwBanner IMPORT adw_banner_new, adw_banner_set_revealed,
  41. adw_banner_get_revealed;
  42. FROM AdwClamp IMPORT adw_clamp_new, adw_clamp_set_maximum_size,
  43. adw_clamp_get_maximum_size;
  44. FROM AdwToast IMPORT adw_toast_new, adw_toast_set_timeout,
  45. adw_toast_get_timeout;
  46. FROM AdwToastOverlay IMPORT adw_toast_overlay_new,
  47. adw_toast_overlay_add_toast, adw_toast_overlay_set_child;
  48. FROM AdwAboutWindow IMPORT adw_about_window_new,
  49. adw_about_window_set_application_name,
  50. adw_about_window_get_application_name;
  51. FROM AdwMessageDialog IMPORT adw_message_dialog_new,
  52. adw_message_dialog_add_response, adw_message_dialog_has_response,
  53. adw_message_dialog_set_response_appearance,
  54. adw_message_dialog_get_response_appearance,
  55. adw_message_dialog_get_heading, AdwResponseDestructive;
  56. FROM GtkLabel IMPORT gtk_label_new;
  57. FROM GtkStringList IMPORT gtk_string_list_new, gtk_string_list_append;
  58. FROM GtkUtils IMPORT Connect, CStrToM2;
  59. FROM SYSTEM IMPORT ADDRESS, ADR;
  60. FROM libc IMPORT printf;
  61. CONST
  62. AppId = "org.example.m2gtk4.TestAdw";
  63. VAR
  64. app: ADDRESS;
  65. passed: BOOLEAN;
  66. PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
  67. VAR
  68. window, toolbar, header, title, page, group, row, sw, er, combo, list,
  69. exp, sp, banner, clamp, toast, overlay, about, msg: ADDRESS;
  70. buf: ARRAY [0..63] OF CHAR;
  71. ok: BOOLEAN;
  72. BEGIN
  73. ok := TRUE;
  74. window := adw_application_window_new(application);
  75. (* header bar *)
  76. title := gtk_label_new("Title");
  77. header := adw_header_bar_new();
  78. adw_header_bar_set_title_widget(header, title);
  79. IF adw_header_bar_get_title_widget(header) # title THEN ok := FALSE END;
  80. adw_header_bar_set_show_title(header, 0);
  81. IF adw_header_bar_get_show_title(header) # 0 THEN ok := FALSE END;
  82. adw_header_bar_set_centering_policy(header, AdwCenteringStrict);
  83. IF adw_header_bar_get_centering_policy(header) # AdwCenteringStrict THEN
  84. printf("centering policy wrong\n"); ok := FALSE
  85. END;
  86. (* toolbar view *)
  87. toolbar := adw_toolbar_view_new();
  88. adw_toolbar_view_add_top_bar(toolbar, header);
  89. adw_toolbar_view_set_top_bar_style(toolbar, AdwToolbarRaised);
  90. IF adw_toolbar_view_get_top_bar_style(toolbar) # AdwToolbarRaised THEN
  91. printf("toolbar style wrong\n"); ok := FALSE
  92. END;
  93. (* preferences page / group / rows *)
  94. page := adw_preferences_page_new();
  95. adw_preferences_page_set_title(page, "Settings");
  96. CStrToM2(adw_preferences_page_get_title(page), buf);
  97. IF (buf[0] # 'S') OR (buf[8] # 0C) THEN
  98. printf("page title wrong: [%s]\n", buf); ok := FALSE
  99. END;
  100. group := adw_preferences_group_new();
  101. adw_preferences_group_set_title(group, "General");
  102. CStrToM2(adw_preferences_group_get_title(group), buf);
  103. IF (buf[0] # 'G') OR (buf[7] # 0C) THEN
  104. printf("group title wrong: [%s]\n", buf); ok := FALSE
  105. END;
  106. row := adw_action_row_new();
  107. adw_preferences_row_set_title(row, "Appearance");
  108. adw_action_row_set_subtitle(row, "Theme");
  109. CStrToM2(adw_action_row_get_subtitle(row), buf);
  110. IF (buf[0] # 'T') OR (buf[5] # 0C) THEN
  111. printf("subtitle wrong: [%s]\n", buf); ok := FALSE
  112. END;
  113. adw_preferences_group_add(group, row);
  114. sw := adw_switch_row_new();
  115. adw_switch_row_set_active(sw, 1);
  116. IF adw_switch_row_get_active(sw) # 1 THEN ok := FALSE END;
  117. adw_preferences_group_add(group, sw);
  118. er := adw_entry_row_new();
  119. adw_entry_row_set_max_length(er, 10);
  120. IF adw_entry_row_get_max_length(er) # 10 THEN ok := FALSE END;
  121. adw_preferences_group_add(group, er);
  122. list := gtk_string_list_new(NIL);
  123. gtk_string_list_append(list, "One");
  124. gtk_string_list_append(list, "Two");
  125. combo := adw_combo_row_new();
  126. adw_combo_row_set_model(combo, list);
  127. adw_combo_row_set_selected(combo, 1);
  128. IF adw_combo_row_get_selected(combo) # 1 THEN ok := FALSE END;
  129. adw_preferences_group_add(group, combo);
  130. exp := adw_expander_row_new();
  131. adw_expander_row_set_expanded(exp, 1);
  132. IF adw_expander_row_get_expanded(exp) # 1 THEN ok := FALSE END;
  133. adw_preferences_group_add(group, exp);
  134. adw_preferences_page_add(page, group);
  135. adw_toolbar_view_set_content(toolbar, page);
  136. (* status page / banner / clamp *)
  137. sp := adw_status_page_new();
  138. adw_status_page_set_title(sp, "Empty");
  139. CStrToM2(adw_status_page_get_title(sp), buf);
  140. IF (buf[0] # 'E') OR (buf[5] # 0C) THEN ok := FALSE END;
  141. banner := adw_banner_new("Heads up");
  142. adw_banner_set_revealed(banner, 1);
  143. IF adw_banner_get_revealed(banner) # 1 THEN ok := FALSE END;
  144. clamp := adw_clamp_new();
  145. adw_clamp_set_maximum_size(clamp, 600);
  146. IF adw_clamp_get_maximum_size(clamp) # 600 THEN ok := FALSE END;
  147. (* toast overlay *)
  148. toast := adw_toast_new("Saved");
  149. adw_toast_set_timeout(toast, 2);
  150. IF adw_toast_get_timeout(toast) # 2 THEN ok := FALSE END;
  151. overlay := adw_toast_overlay_new();
  152. adw_toast_overlay_set_child(overlay, toolbar);
  153. adw_toast_overlay_add_toast(overlay, toast);
  154. adw_application_window_set_content(window, overlay);
  155. (* about window *)
  156. about := adw_about_window_new();
  157. adw_about_window_set_application_name(about, "m2-GTK4");
  158. CStrToM2(adw_about_window_get_application_name(about), buf);
  159. IF (buf[0] # 'm') OR (buf[7] # 0C) THEN
  160. printf("about name wrong: [%s]\n", buf); ok := FALSE
  161. END;
  162. (* message dialog *)
  163. msg := adw_message_dialog_new(window, "Delete?", "Are you sure?");
  164. adw_message_dialog_add_response(msg, "cancel", "Cancel");
  165. adw_message_dialog_add_response(msg, "ok", "Delete");
  166. IF adw_message_dialog_has_response(msg, "ok") # 1 THEN
  167. printf("response missing\n"); ok := FALSE
  168. END;
  169. adw_message_dialog_set_response_appearance(msg, "ok", AdwResponseDestructive);
  170. IF adw_message_dialog_get_response_appearance(msg, "ok") # AdwResponseDestructive THEN
  171. printf("response appearance wrong\n"); ok := FALSE
  172. END;
  173. CStrToM2(adw_message_dialog_get_heading(msg), buf);
  174. IF (buf[0] # 'D') OR (buf[7] # 0C) THEN
  175. printf("message heading wrong: [%s]\n", buf); ok := FALSE
  176. END;
  177. (* keep the built widgets alive in the window tree *)
  178. adw_preferences_page_set_banner(page, banner);
  179. passed := ok;
  180. g_application_quit(application)
  181. END OnActivate;
  182. VAR
  183. rc: INTEGER;
  184. BEGIN
  185. passed := FALSE;
  186. app := adw_application_new(AppId, 0);
  187. IF app = NIL THEN
  188. printf("test_adw: FAIL (no app)\n");
  189. HALT(1)
  190. END;
  191. Connect(app, "activate", ADR(OnActivate), NIL);
  192. rc := g_application_run(app, 0, NIL);
  193. IF passed THEN
  194. printf("test_adw: PASS\n");
  195. HALT(0)
  196. ELSE
  197. printf("test_adw: FAIL\n");
  198. HALT(1)
  199. END
  200. END test_adw.