spelling.mod 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. MODULE spelling ;
  2. (*
  3. m2-GTK4 example - a GtkSourceView 5 editor with libspelling
  4. spell-checking attached to its buffer:
  5. GtkApplicationWindow > GtkScrolledWindow > GtkSourceView
  6. buffer <- SpellingTextBufferAdapter <- SpellingChecker
  7. Build: make examples
  8. Run: ./build/examples/spelling
  9. *)
  10. FROM Gio IMPORT g_application_run;
  11. FROM GtkApplication IMPORT gtk_application_new;
  12. FROM GtkWindow IMPORT gtk_application_window_new, gtk_window_set_title,
  13. gtk_window_set_default_size, gtk_window_set_child, gtk_window_present;
  14. FROM GtkScrolledWindow IMPORT gtk_scrolled_window_new,
  15. gtk_scrolled_window_set_child;
  16. FROM GtkWidget IMPORT gtk_widget_set_vexpand;
  17. FROM GtkTextBuffer IMPORT gtk_text_buffer_set_text;
  18. FROM GtkUtils IMPORT Connect;
  19. FROM GtkSourceFunctions IMPORT gtk_source_init;
  20. FROM GtkSourceBuffer IMPORT gtk_source_buffer_new;
  21. FROM GtkSourceView IMPORT gtk_source_view_new_with_buffer,
  22. gtk_source_view_set_show_line_numbers;
  23. FROM SpellingFunctions IMPORT spelling_init;
  24. FROM SpellingChecker IMPORT spelling_checker_get_default;
  25. FROM SpellingTextBufferAdapter IMPORT spelling_text_buffer_adapter_new;
  26. FROM SYSTEM IMPORT ADDRESS, ADR;
  27. FROM libc IMPORT printf;
  28. CONST
  29. AppId = "org.example.m2gtk4.Spelling";
  30. Sample =
  31. "Spell checking is attatched to this bufer and underlines misspeled words.\n" +
  32. "Right-click (or press the menu key) on a underlined word to see the\n" +
  33. "corrections offered by the default libspelling provider.\n";
  34. PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
  35. VAR
  36. window, sw, view, buffer, checker, adapter: ADDRESS;
  37. BEGIN
  38. buffer := gtk_source_buffer_new(NIL);
  39. gtk_text_buffer_set_text(buffer, Sample, -1);
  40. checker := spelling_checker_get_default();
  41. IF checker # NIL THEN
  42. adapter := spelling_text_buffer_adapter_new(buffer, checker)
  43. END;
  44. view := gtk_source_view_new_with_buffer(buffer);
  45. gtk_source_view_set_show_line_numbers(view, 1);
  46. sw := gtk_scrolled_window_new();
  47. gtk_scrolled_window_set_child(sw, view);
  48. gtk_widget_set_vexpand(sw, 1);
  49. window := gtk_application_window_new(application);
  50. gtk_window_set_title(window, "m2-GTK4 - libspelling");
  51. gtk_window_set_default_size(window, 600, 400);
  52. gtk_window_set_child(window, sw);
  53. gtk_window_present(window)
  54. END OnActivate;
  55. VAR
  56. app: ADDRESS;
  57. BEGIN
  58. gtk_source_init();
  59. spelling_init();
  60. app := gtk_application_new(AppId, 0);
  61. IF app = NIL THEN
  62. printf("gtk_application_new failed\n");
  63. HALT(1)
  64. END;
  65. Connect(app, "activate", ADR(OnActivate), NIL);
  66. g_application_run(app, 0, NIL)
  67. END spelling.