test_headerbar.mod 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. MODULE test_headerbar ;
  2. (*
  3. m2-GTK4 test - GtkHeaderBar, GtkMenuButton and gtk_window_set_titlebar.
  4. Builds a header bar with a title widget, a start button and an
  5. end-packed menu button, installs it as the window titlebar, and
  6. checks the getters (title widget identity, show-title-buttons flag,
  7. decoration layout string, menu model identity). Requires a display.
  8. *)
  9. FROM Gio IMPORT g_application_run, g_application_quit;
  10. FROM GtkApplication IMPORT gtk_application_new;
  11. FROM GtkApplicationWindow IMPORT gtk_application_window_new;
  12. FROM GtkWindow IMPORT gtk_window_set_titlebar, gtk_window_get_titlebar,
  13. gtk_window_set_child;
  14. FROM GtkHeaderBar IMPORT gtk_header_bar_new,
  15. gtk_header_bar_set_title_widget, gtk_header_bar_get_title_widget,
  16. gtk_header_bar_pack_start, gtk_header_bar_pack_end,
  17. gtk_header_bar_set_show_title_buttons,
  18. gtk_header_bar_get_show_title_buttons,
  19. gtk_header_bar_set_decoration_layout,
  20. gtk_header_bar_get_decoration_layout;
  21. FROM GtkMenuButton IMPORT gtk_menu_button_new,
  22. gtk_menu_button_set_menu_model, gtk_menu_button_get_menu_model,
  23. gtk_menu_button_set_label;
  24. FROM GtkLabel IMPORT gtk_label_new;
  25. FROM GtkButton IMPORT gtk_button_new_with_label;
  26. FROM GMenu IMPORT g_menu_new, g_menu_append;
  27. FROM GtkUtils IMPORT Connect, CStrToM2;
  28. FROM SYSTEM IMPORT ADDRESS, ADR;
  29. FROM libc IMPORT printf;
  30. CONST
  31. AppId = "org.example.m2gtk4.TestHeaderBar";
  32. VAR
  33. app: ADDRESS;
  34. passed: BOOLEAN;
  35. PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
  36. VAR
  37. window, bar, titleWidget, startButton, menuButton, menu: ADDRESS;
  38. layout: ARRAY [0..63] OF CHAR;
  39. ok: BOOLEAN;
  40. BEGIN
  41. ok := TRUE;
  42. titleWidget := gtk_label_new("Title");
  43. bar := gtk_header_bar_new();
  44. gtk_header_bar_set_title_widget(bar, titleWidget);
  45. IF gtk_header_bar_get_title_widget(bar) # titleWidget THEN
  46. printf("title widget wrong\n");
  47. ok := FALSE
  48. END;
  49. startButton := gtk_button_new_with_label("New");
  50. gtk_header_bar_pack_start(bar, startButton);
  51. menu := g_menu_new();
  52. g_menu_append(menu, "Quit", "app.quit");
  53. menuButton := gtk_menu_button_new();
  54. gtk_menu_button_set_label(menuButton, "Menu");
  55. gtk_menu_button_set_menu_model(menuButton, menu);
  56. IF gtk_menu_button_get_menu_model(menuButton) # menu THEN
  57. printf("menu model wrong\n");
  58. ok := FALSE
  59. END;
  60. gtk_header_bar_pack_end(bar, menuButton);
  61. gtk_header_bar_set_show_title_buttons(bar, 0);
  62. IF gtk_header_bar_get_show_title_buttons(bar) # 0 THEN
  63. printf("show title buttons wrong\n");
  64. ok := FALSE
  65. END;
  66. gtk_header_bar_set_decoration_layout(bar, "menu:");
  67. CStrToM2(gtk_header_bar_get_decoration_layout(bar), layout);
  68. IF (layout[0] # 'm') OR (layout[4] # ':') OR (layout[5] # 0C) THEN
  69. printf("decoration layout wrong: [%s]\n", layout);
  70. ok := FALSE
  71. END;
  72. window := gtk_application_window_new(application);
  73. gtk_window_set_titlebar(window, bar);
  74. IF gtk_window_get_titlebar(window) # bar THEN
  75. printf("titlebar wrong\n");
  76. ok := FALSE
  77. END;
  78. gtk_window_set_child(window, gtk_label_new("content"));
  79. passed := ok;
  80. g_application_quit(application)
  81. END OnActivate;
  82. VAR
  83. rc: INTEGER;
  84. BEGIN
  85. passed := FALSE;
  86. app := gtk_application_new(AppId, 0);
  87. IF app = NIL THEN
  88. printf("test_headerbar: FAIL (no app)\n");
  89. HALT(1)
  90. END;
  91. Connect(app, "activate", ADR(OnActivate), NIL);
  92. rc := g_application_run(app, 0, NIL);
  93. IF passed THEN
  94. printf("test_headerbar: PASS\n");
  95. HALT(0)
  96. ELSE
  97. printf("test_headerbar: FAIL\n");
  98. HALT(1)
  99. END
  100. END test_headerbar.