| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- MODULE richtext ;
- (*
- m2-GTK4 example - text extras.
- A GtkTextView whose buffer is filled with Pango markup (bold/colour),
- with a named mark used to scroll back to the top, plus a GtkEntry with
- an attached GtkEntryCompletion.
- Build: make examples
- Run: ./build/examples/richtext
- *)
- FROM Gio IMPORT g_application_run;
- FROM GtkApplication IMPORT gtk_application_new;
- FROM GtkWindow IMPORT gtk_application_window_new, gtk_window_set_title,
- gtk_window_set_default_size, gtk_window_set_child, gtk_window_present;
- FROM GtkBox IMPORT gtk_box_new, gtk_box_append, gtk_box_set_spacing;
- FROM GtkEnums IMPORT GtkVertical, GtkWrapWordChar;
- FROM GtkScrolledWindow IMPORT gtk_scrolled_window_new,
- gtk_scrolled_window_set_child;
- FROM GtkTextView IMPORT gtk_text_view_new, gtk_text_view_get_buffer,
- gtk_text_view_set_wrap_mode, gtk_text_view_set_monospace,
- gtk_text_view_scroll_to_mark;
- FROM GtkTextBuffer IMPORT gtk_text_buffer_get_start_iter,
- gtk_text_buffer_create_mark, gtk_text_buffer_insert_markup;
- FROM GtkTextIter IMPORT GtkTextIter;
- FROM GtkEntry IMPORT gtk_entry_new, gtk_entry_set_completion;
- FROM GtkEntryCompletion IMPORT gtk_entry_completion_new,
- gtk_entry_completion_set_text_column,
- gtk_entry_completion_set_minimum_key_length,
- gtk_entry_completion_set_popup_completion;
- FROM GtkWidget IMPORT gtk_widget_set_vexpand;
- FROM GtkClosures IMPORT Connect2;
- FROM SYSTEM IMPORT ADDRESS, ADR;
- FROM libc IMPORT printf;
- CONST
- AppId = "org.example.m2gtk4.RichText";
- Markup = "<b>Rich text</b> from GNU Modula-2 - <span foreground='#e01b24'>red</span>, <i>italic</i> and <tt>monospace</tt>.";
- PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
- VAR
- window, box, sw, view, buffer, entry, completion, mark: ADDRESS;
- start: GtkTextIter;
- BEGIN
- view := gtk_text_view_new();
- gtk_text_view_set_wrap_mode(view, GtkWrapWordChar);
- gtk_text_view_set_monospace(view, 0);
- buffer := gtk_text_view_get_buffer(view);
- gtk_text_buffer_get_start_iter(buffer, start);
- gtk_text_buffer_insert_markup(buffer, start, Markup, -1);
- mark := gtk_text_buffer_create_mark(buffer, "top", start, 1);
- gtk_text_view_scroll_to_mark(view, mark, 0.0, 0, 0.0, 0.0);
- entry := gtk_entry_new();
- completion := gtk_entry_completion_new();
- gtk_entry_completion_set_text_column(completion, 0);
- gtk_entry_completion_set_minimum_key_length(completion, 2);
- gtk_entry_completion_set_popup_completion(completion, 1);
- gtk_entry_set_completion(entry, completion);
- sw := gtk_scrolled_window_new();
- gtk_scrolled_window_set_child(sw, view);
- gtk_widget_set_vexpand(sw, 1);
- box := gtk_box_new(GtkVertical, 8);
- gtk_box_set_spacing(box, 8);
- gtk_box_append(box, entry);
- gtk_box_append(box, sw);
- window := gtk_application_window_new(application);
- gtk_window_set_title(window, "m2-GTK4 Rich Text");
- gtk_window_set_default_size(window, 460, 260);
- gtk_window_set_child(window, box);
- gtk_window_present(window)
- END OnActivate;
- VAR
- app: ADDRESS;
- BEGIN
- app := gtk_application_new(AppId, 0);
- IF app = NIL THEN
- printf("gtk_application_new failed\n");
- HALT(1)
- END;
- Connect2(app, "activate", OnActivate, NIL);
- g_application_run(app, 0, NIL)
- END richtext.
|