| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- MODULE test_adw ;
- (*
- m2-GTK4 test - libadwaita widgets: application window, toolbar view,
- header bar, preferences page/group, the settings rows, status page,
- banner, clamp, toast and message dialog. Requires a display and
- libadwaita.
- *)
- FROM Gio IMPORT g_application_run, g_application_quit;
- FROM AdwApplication IMPORT adw_application_new;
- FROM AdwApplicationWindow IMPORT adw_application_window_new,
- adw_application_window_set_content;
- FROM AdwHeaderBar IMPORT adw_header_bar_new,
- adw_header_bar_set_title_widget, adw_header_bar_get_title_widget,
- adw_header_bar_set_show_title, adw_header_bar_get_show_title,
- adw_header_bar_set_centering_policy, adw_header_bar_get_centering_policy,
- AdwCenteringStrict;
- FROM AdwToolbarView IMPORT adw_toolbar_view_new, adw_toolbar_view_add_top_bar,
- adw_toolbar_view_set_content, adw_toolbar_view_set_top_bar_style,
- adw_toolbar_view_get_top_bar_style, AdwToolbarRaised;
- FROM AdwPreferencesPage IMPORT adw_preferences_page_new,
- adw_preferences_page_add, adw_preferences_page_set_title,
- adw_preferences_page_get_title, adw_preferences_page_set_banner;
- FROM AdwPreferencesGroup IMPORT adw_preferences_group_new,
- adw_preferences_group_add, adw_preferences_group_set_title,
- adw_preferences_group_get_title;
- FROM AdwPreferencesRow IMPORT adw_preferences_row_set_title,
- adw_preferences_row_get_title;
- FROM AdwActionRow IMPORT adw_action_row_new, adw_action_row_set_subtitle,
- adw_action_row_get_subtitle;
- FROM AdwSwitchRow IMPORT adw_switch_row_new, adw_switch_row_set_active,
- adw_switch_row_get_active;
- FROM AdwEntryRow IMPORT adw_entry_row_new, adw_entry_row_set_max_length,
- adw_entry_row_get_max_length;
- FROM AdwComboRow IMPORT adw_combo_row_new, adw_combo_row_set_model,
- adw_combo_row_set_selected, adw_combo_row_get_selected;
- FROM AdwExpanderRow IMPORT adw_expander_row_new, adw_expander_row_set_expanded,
- adw_expander_row_get_expanded;
- FROM AdwStatusPage IMPORT adw_status_page_new, adw_status_page_set_title,
- adw_status_page_get_title;
- FROM AdwBanner IMPORT adw_banner_new, adw_banner_set_revealed,
- adw_banner_get_revealed;
- FROM AdwClamp IMPORT adw_clamp_new, adw_clamp_set_maximum_size,
- adw_clamp_get_maximum_size;
- FROM AdwToast IMPORT adw_toast_new, adw_toast_set_timeout,
- adw_toast_get_timeout;
- FROM AdwToastOverlay IMPORT adw_toast_overlay_new,
- adw_toast_overlay_add_toast, adw_toast_overlay_set_child;
- FROM AdwAboutWindow IMPORT adw_about_window_new,
- adw_about_window_set_application_name,
- adw_about_window_get_application_name;
- FROM AdwMessageDialog IMPORT adw_message_dialog_new,
- adw_message_dialog_add_response, adw_message_dialog_has_response,
- adw_message_dialog_set_response_appearance,
- adw_message_dialog_get_response_appearance,
- adw_message_dialog_get_heading, AdwResponseDestructive;
- FROM GtkLabel IMPORT gtk_label_new;
- FROM GtkStringList IMPORT gtk_string_list_new, gtk_string_list_append;
- FROM GtkUtils IMPORT Connect, CStrToM2;
- FROM SYSTEM IMPORT ADDRESS, ADR;
- FROM libc IMPORT printf;
- CONST
- AppId = "org.example.m2gtk4.TestAdw";
- VAR
- app: ADDRESS;
- passed: BOOLEAN;
- PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
- VAR
- window, toolbar, header, title, page, group, row, sw, er, combo, list,
- exp, sp, banner, clamp, toast, overlay, about, msg: ADDRESS;
- buf: ARRAY [0..63] OF CHAR;
- ok: BOOLEAN;
- BEGIN
- ok := TRUE;
- window := adw_application_window_new(application);
- (* header bar *)
- title := gtk_label_new("Title");
- header := adw_header_bar_new();
- adw_header_bar_set_title_widget(header, title);
- IF adw_header_bar_get_title_widget(header) # title THEN ok := FALSE END;
- adw_header_bar_set_show_title(header, 0);
- IF adw_header_bar_get_show_title(header) # 0 THEN ok := FALSE END;
- adw_header_bar_set_centering_policy(header, AdwCenteringStrict);
- IF adw_header_bar_get_centering_policy(header) # AdwCenteringStrict THEN
- printf("centering policy wrong\n"); ok := FALSE
- END;
- (* toolbar view *)
- toolbar := adw_toolbar_view_new();
- adw_toolbar_view_add_top_bar(toolbar, header);
- adw_toolbar_view_set_top_bar_style(toolbar, AdwToolbarRaised);
- IF adw_toolbar_view_get_top_bar_style(toolbar) # AdwToolbarRaised THEN
- printf("toolbar style wrong\n"); ok := FALSE
- END;
- (* preferences page / group / rows *)
- page := adw_preferences_page_new();
- adw_preferences_page_set_title(page, "Settings");
- CStrToM2(adw_preferences_page_get_title(page), buf);
- IF (buf[0] # 'S') OR (buf[8] # 0C) THEN
- printf("page title wrong: [%s]\n", buf); ok := FALSE
- END;
- group := adw_preferences_group_new();
- adw_preferences_group_set_title(group, "General");
- CStrToM2(adw_preferences_group_get_title(group), buf);
- IF (buf[0] # 'G') OR (buf[7] # 0C) THEN
- printf("group title wrong: [%s]\n", buf); ok := FALSE
- END;
- row := adw_action_row_new();
- adw_preferences_row_set_title(row, "Appearance");
- adw_action_row_set_subtitle(row, "Theme");
- CStrToM2(adw_action_row_get_subtitle(row), buf);
- IF (buf[0] # 'T') OR (buf[5] # 0C) THEN
- printf("subtitle wrong: [%s]\n", buf); ok := FALSE
- END;
- adw_preferences_group_add(group, row);
- sw := adw_switch_row_new();
- adw_switch_row_set_active(sw, 1);
- IF adw_switch_row_get_active(sw) # 1 THEN ok := FALSE END;
- adw_preferences_group_add(group, sw);
- er := adw_entry_row_new();
- adw_entry_row_set_max_length(er, 10);
- IF adw_entry_row_get_max_length(er) # 10 THEN ok := FALSE END;
- adw_preferences_group_add(group, er);
- list := gtk_string_list_new(NIL);
- gtk_string_list_append(list, "One");
- gtk_string_list_append(list, "Two");
- combo := adw_combo_row_new();
- adw_combo_row_set_model(combo, list);
- adw_combo_row_set_selected(combo, 1);
- IF adw_combo_row_get_selected(combo) # 1 THEN ok := FALSE END;
- adw_preferences_group_add(group, combo);
- exp := adw_expander_row_new();
- adw_expander_row_set_expanded(exp, 1);
- IF adw_expander_row_get_expanded(exp) # 1 THEN ok := FALSE END;
- adw_preferences_group_add(group, exp);
- adw_preferences_page_add(page, group);
- adw_toolbar_view_set_content(toolbar, page);
- (* status page / banner / clamp *)
- sp := adw_status_page_new();
- adw_status_page_set_title(sp, "Empty");
- CStrToM2(adw_status_page_get_title(sp), buf);
- IF (buf[0] # 'E') OR (buf[5] # 0C) THEN ok := FALSE END;
- banner := adw_banner_new("Heads up");
- adw_banner_set_revealed(banner, 1);
- IF adw_banner_get_revealed(banner) # 1 THEN ok := FALSE END;
- clamp := adw_clamp_new();
- adw_clamp_set_maximum_size(clamp, 600);
- IF adw_clamp_get_maximum_size(clamp) # 600 THEN ok := FALSE END;
- (* toast overlay *)
- toast := adw_toast_new("Saved");
- adw_toast_set_timeout(toast, 2);
- IF adw_toast_get_timeout(toast) # 2 THEN ok := FALSE END;
- overlay := adw_toast_overlay_new();
- adw_toast_overlay_set_child(overlay, toolbar);
- adw_toast_overlay_add_toast(overlay, toast);
- adw_application_window_set_content(window, overlay);
- (* about window *)
- about := adw_about_window_new();
- adw_about_window_set_application_name(about, "m2-GTK4");
- CStrToM2(adw_about_window_get_application_name(about), buf);
- IF (buf[0] # 'm') OR (buf[7] # 0C) THEN
- printf("about name wrong: [%s]\n", buf); ok := FALSE
- END;
- (* message dialog *)
- msg := adw_message_dialog_new(window, "Delete?", "Are you sure?");
- adw_message_dialog_add_response(msg, "cancel", "Cancel");
- adw_message_dialog_add_response(msg, "ok", "Delete");
- IF adw_message_dialog_has_response(msg, "ok") # 1 THEN
- printf("response missing\n"); ok := FALSE
- END;
- adw_message_dialog_set_response_appearance(msg, "ok", AdwResponseDestructive);
- IF adw_message_dialog_get_response_appearance(msg, "ok") # AdwResponseDestructive THEN
- printf("response appearance wrong\n"); ok := FALSE
- END;
- CStrToM2(adw_message_dialog_get_heading(msg), buf);
- IF (buf[0] # 'D') OR (buf[7] # 0C) THEN
- printf("message heading wrong: [%s]\n", buf); ok := FALSE
- END;
- (* keep the built widgets alive in the window tree *)
- adw_preferences_page_set_banner(page, banner);
- passed := ok;
- g_application_quit(application)
- END OnActivate;
- VAR
- rc: INTEGER;
- BEGIN
- passed := FALSE;
- app := adw_application_new(AppId, 0);
- IF app = NIL THEN
- printf("test_adw: FAIL (no app)\n");
- HALT(1)
- END;
- Connect(app, "activate", ADR(OnActivate), NIL);
- rc := g_application_run(app, 0, NIL);
- IF passed THEN
- printf("test_adw: PASS\n");
- HALT(0)
- ELSE
- printf("test_adw: FAIL\n");
- HALT(1)
- END
- END test_adw.
|