|
|
@@ -0,0 +1,123 @@
|
|
|
+MODULE test_widgets3 ;
|
|
|
+
|
|
|
+(*
|
|
|
+ m2-GTK4 test - common widgets: GtkFlowBox, GtkFixed, GtkPicture,
|
|
|
+ GtkToggleButton, GtkLinkButton, GtkCalendar, GtkLevelBar and
|
|
|
+ GtkScrollbar. Requires a display.
|
|
|
+*)
|
|
|
+
|
|
|
+FROM Gio IMPORT g_application_run, g_application_quit;
|
|
|
+FROM GtkApplication IMPORT gtk_application_new;
|
|
|
+FROM GtkWindow IMPORT gtk_application_window_new, gtk_window_set_child;
|
|
|
+FROM GtkBox IMPORT gtk_box_new, gtk_box_append;
|
|
|
+FROM GtkLabel IMPORT gtk_label_new;
|
|
|
+FROM GtkEnums IMPORT GtkVertical, GtkHorizontal, GtkSelectionSingle;
|
|
|
+FROM GtkFlowBox IMPORT gtk_flow_box_new, gtk_flow_box_append,
|
|
|
+ gtk_flow_box_set_max_children_per_line, gtk_flow_box_set_selection_mode,
|
|
|
+ gtk_flow_box_child_new, gtk_flow_box_child_set_child;
|
|
|
+FROM GtkFixed IMPORT gtk_fixed_new, gtk_fixed_put;
|
|
|
+FROM GtkPicture IMPORT gtk_picture_new, gtk_picture_set_can_shrink,
|
|
|
+ gtk_picture_set_content_fit, GtkContentFitContain;
|
|
|
+FROM GtkToggleButton IMPORT gtk_toggle_button_new_with_label,
|
|
|
+ gtk_toggle_button_set_active, gtk_toggle_button_get_active;
|
|
|
+FROM GtkLinkButton IMPORT gtk_link_button_new, gtk_link_button_get_uri;
|
|
|
+FROM GtkCalendar IMPORT gtk_calendar_new;
|
|
|
+FROM GtkLevelBar IMPORT gtk_level_bar_new, gtk_level_bar_set_value,
|
|
|
+ gtk_level_bar_get_value;
|
|
|
+FROM GtkScrollbar IMPORT gtk_scrollbar_new;
|
|
|
+FROM GtkUtils IMPORT Connect, CStrToM2;
|
|
|
+FROM SYSTEM IMPORT ADDRESS, ADR;
|
|
|
+FROM libc IMPORT printf;
|
|
|
+
|
|
|
+CONST
|
|
|
+ AppId = "org.example.m2gtk4.TestWidgets3";
|
|
|
+
|
|
|
+VAR
|
|
|
+ app: ADDRESS;
|
|
|
+ passed: BOOLEAN;
|
|
|
+
|
|
|
+PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
|
|
|
+VAR
|
|
|
+ window, box, flow, child, fixed, picture, toggle, link, calendar,
|
|
|
+ level, scrollbar: ADDRESS;
|
|
|
+ buf: ARRAY [0..63] OF CHAR;
|
|
|
+ ok: BOOLEAN;
|
|
|
+BEGIN
|
|
|
+ ok := TRUE;
|
|
|
+
|
|
|
+ flow := gtk_flow_box_new();
|
|
|
+ gtk_flow_box_append(flow, gtk_label_new("a"));
|
|
|
+ gtk_flow_box_append(flow, gtk_label_new("b"));
|
|
|
+ child := gtk_flow_box_child_new();
|
|
|
+ gtk_flow_box_child_set_child(child, gtk_label_new("c"));
|
|
|
+ gtk_flow_box_append(flow, child);
|
|
|
+ gtk_flow_box_set_max_children_per_line(flow, 3);
|
|
|
+ gtk_flow_box_set_selection_mode(flow, GtkSelectionSingle);
|
|
|
+
|
|
|
+ fixed := gtk_fixed_new();
|
|
|
+ gtk_fixed_put(fixed, gtk_label_new("at 10,20"), 10.0, 20.0);
|
|
|
+
|
|
|
+ picture := gtk_picture_new();
|
|
|
+ gtk_picture_set_can_shrink(picture, 1);
|
|
|
+ gtk_picture_set_content_fit(picture, GtkContentFitContain);
|
|
|
+
|
|
|
+ toggle := gtk_toggle_button_new_with_label("Toggle");
|
|
|
+ gtk_toggle_button_set_active(toggle, 1);
|
|
|
+ IF gtk_toggle_button_get_active(toggle) # 1 THEN
|
|
|
+ printf("toggle active wrong\n"); ok := FALSE
|
|
|
+ END;
|
|
|
+
|
|
|
+ link := gtk_link_button_new("https://example.org");
|
|
|
+ CStrToM2(gtk_link_button_get_uri(link), buf);
|
|
|
+ IF (buf[0] # 'h') OR (buf[4] # 's') OR (buf[19] # 0C) THEN
|
|
|
+ printf("link uri wrong: [%s]\n", buf); ok := FALSE
|
|
|
+ END;
|
|
|
+
|
|
|
+ calendar := gtk_calendar_new();
|
|
|
+ IF calendar = NIL THEN printf("calendar NIL\n"); ok := FALSE END;
|
|
|
+
|
|
|
+ level := gtk_level_bar_new();
|
|
|
+ gtk_level_bar_set_value(level, 0.5);
|
|
|
+ IF ABS(gtk_level_bar_get_value(level) - 0.5) > 0.001 THEN
|
|
|
+ printf("level value wrong\n"); ok := FALSE
|
|
|
+ END;
|
|
|
+
|
|
|
+ scrollbar := gtk_scrollbar_new(GtkHorizontal, NIL);
|
|
|
+ IF scrollbar = NIL THEN printf("scrollbar NIL\n"); ok := FALSE END;
|
|
|
+
|
|
|
+ box := gtk_box_new(GtkVertical, 6);
|
|
|
+ gtk_box_append(box, flow);
|
|
|
+ gtk_box_append(box, fixed);
|
|
|
+ gtk_box_append(box, picture);
|
|
|
+ gtk_box_append(box, toggle);
|
|
|
+ gtk_box_append(box, link);
|
|
|
+ gtk_box_append(box, calendar);
|
|
|
+ gtk_box_append(box, level);
|
|
|
+ gtk_box_append(box, scrollbar);
|
|
|
+ window := gtk_application_window_new(application);
|
|
|
+ gtk_window_set_child(window, box);
|
|
|
+
|
|
|
+ passed := ok;
|
|
|
+ g_application_quit(application)
|
|
|
+END OnActivate;
|
|
|
+
|
|
|
+VAR
|
|
|
+ rc: INTEGER;
|
|
|
+BEGIN
|
|
|
+ passed := FALSE;
|
|
|
+ app := gtk_application_new(AppId, 0);
|
|
|
+ IF app = NIL THEN
|
|
|
+ printf("test_widgets3: 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_widgets3: PASS\n");
|
|
|
+ HALT(0)
|
|
|
+ ELSE
|
|
|
+ printf("test_widgets3: FAIL\n");
|
|
|
+ HALT(1)
|
|
|
+ END
|
|
|
+END test_widgets3.
|