| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- MODULE test_headerbar ;
- (*
- m2-GTK4 test - GtkHeaderBar, GtkMenuButton and gtk_window_set_titlebar.
- Builds a header bar with a title widget, a start button and an
- end-packed menu button, installs it as the window titlebar, and
- checks the getters (title widget identity, show-title-buttons flag,
- decoration layout string, menu model identity). Requires a display.
- *)
- FROM Gio IMPORT g_application_run, g_application_quit;
- FROM GtkApplication IMPORT gtk_application_new;
- FROM GtkApplicationWindow IMPORT gtk_application_window_new;
- FROM GtkWindow IMPORT gtk_window_set_titlebar, gtk_window_get_titlebar,
- gtk_window_set_child;
- FROM GtkHeaderBar IMPORT gtk_header_bar_new,
- gtk_header_bar_set_title_widget, gtk_header_bar_get_title_widget,
- gtk_header_bar_pack_start, gtk_header_bar_pack_end,
- gtk_header_bar_set_show_title_buttons,
- gtk_header_bar_get_show_title_buttons,
- gtk_header_bar_set_decoration_layout,
- gtk_header_bar_get_decoration_layout;
- FROM GtkMenuButton IMPORT gtk_menu_button_new,
- gtk_menu_button_set_menu_model, gtk_menu_button_get_menu_model,
- gtk_menu_button_set_label;
- FROM GtkLabel IMPORT gtk_label_new;
- FROM GtkButton IMPORT gtk_button_new_with_label;
- FROM GMenu IMPORT g_menu_new, g_menu_append;
- FROM GtkUtils IMPORT Connect, CStrToM2;
- FROM SYSTEM IMPORT ADDRESS, ADR;
- FROM libc IMPORT printf;
- CONST
- AppId = "org.example.m2gtk4.TestHeaderBar";
- VAR
- app: ADDRESS;
- passed: BOOLEAN;
- PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
- VAR
- window, bar, titleWidget, startButton, menuButton, menu: ADDRESS;
- layout: ARRAY [0..63] OF CHAR;
- ok: BOOLEAN;
- BEGIN
- ok := TRUE;
- titleWidget := gtk_label_new("Title");
- bar := gtk_header_bar_new();
- gtk_header_bar_set_title_widget(bar, titleWidget);
- IF gtk_header_bar_get_title_widget(bar) # titleWidget THEN
- printf("title widget wrong\n");
- ok := FALSE
- END;
- startButton := gtk_button_new_with_label("New");
- gtk_header_bar_pack_start(bar, startButton);
- menu := g_menu_new();
- g_menu_append(menu, "Quit", "app.quit");
- menuButton := gtk_menu_button_new();
- gtk_menu_button_set_label(menuButton, "Menu");
- gtk_menu_button_set_menu_model(menuButton, menu);
- IF gtk_menu_button_get_menu_model(menuButton) # menu THEN
- printf("menu model wrong\n");
- ok := FALSE
- END;
- gtk_header_bar_pack_end(bar, menuButton);
- gtk_header_bar_set_show_title_buttons(bar, 0);
- IF gtk_header_bar_get_show_title_buttons(bar) # 0 THEN
- printf("show title buttons wrong\n");
- ok := FALSE
- END;
- gtk_header_bar_set_decoration_layout(bar, "menu:");
- CStrToM2(gtk_header_bar_get_decoration_layout(bar), layout);
- IF (layout[0] # 'm') OR (layout[4] # ':') OR (layout[5] # 0C) THEN
- printf("decoration layout wrong: [%s]\n", layout);
- ok := FALSE
- END;
- window := gtk_application_window_new(application);
- gtk_window_set_titlebar(window, bar);
- IF gtk_window_get_titlebar(window) # bar THEN
- printf("titlebar wrong\n");
- ok := FALSE
- END;
- gtk_window_set_child(window, gtk_label_new("content"));
- 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_headerbar: 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_headerbar: PASS\n");
- HALT(0)
- ELSE
- printf("test_headerbar: FAIL\n");
- HALT(1)
- END
- END test_headerbar.
|