# HG changeset patch # User Olaf Wintermann # Date 1781428058 -7200 # Node ID 5bb4366b0c326ef1ddf05876ff8615b048eaeb35 # Parent 4bbf0487509fa44a1b58bb3c4a1fe094350ea78f add UiText setreadonly method (GTK) diff -r 4bbf0487509f -r 5bb4366b0c32 ui/common/context.c --- a/ui/common/context.c Sun Jun 14 10:52:28 2026 +0200 +++ b/ui/common/context.c Sun Jun 14 11:07:38 2026 +0200 @@ -945,6 +945,17 @@ } + +void ui_context_onattach(UiContext *ctx, ui_callback cb, void *data) { + ctx->onattach = cb; + ctx->onattachdata = data; +} + +void ui_context_ondetach(UiContext *ctx, ui_callback cb, void *data) { + ctx->ondetach = cb; + ctx->ondetachdata = data; +} + static void attachment_action_callback(UiEvent *event, void *action) { if(event->document) { UiContext *ctx = ui_document_context(event->document); diff -r 4bbf0487509f -r 5bb4366b0c32 ui/common/context.h --- a/ui/common/context.h Sun Jun 14 10:52:28 2026 +0200 +++ b/ui/common/context.h Sun Jun 14 11:07:38 2026 +0200 @@ -173,6 +173,8 @@ void uic_add_state_widget_i(UiContext *ctx, void *widget, ui_enablefunc enable, const int *states, size_t numstates); void uic_remove_state_widget(UiContext *ctx, void *widget); +UIEXPORT void ui_context_onattach(UiContext *ctx, ui_callback cb, void *data); +UIEXPORT void ui_context_ondetach(UiContext *ctx, ui_callback cb, void *data); UIEXPORT void ui_context_onattach_action(UiContext *ctx, const char *action); UIEXPORT void ui_context_ondetach_action(UiContext *ctx, const char *action); diff -r 4bbf0487509f -r 5bb4366b0c32 ui/common/document.c --- a/ui/common/document.c Sun Jun 14 10:52:28 2026 +0200 +++ b/ui/common/document.c Sun Jun 14 11:07:38 2026 +0200 @@ -89,14 +89,12 @@ void ui_document_onattach(void *doc, ui_callback cb, void *data) { UiContext *ctx = ui_document_context(doc); - ctx->onattach = cb; - ctx->onattachdata = data; + ui_context_onattach(ctx, cb, data); } void ui_document_ondetach(void *doc, ui_callback cb, void *data) { UiContext *ctx = ui_document_context(doc); - ctx->ondetach = cb; - ctx->ondetachdata = data; + ui_context_ondetach(ctx, cb, data); } void ui_document_onattach_action(void *doc, const char *action) { diff -r 4bbf0487509f -r 5bb4366b0c32 ui/common/types.c --- a/ui/common/types.c Sun Jun 14 10:52:28 2026 +0200 +++ b/ui/common/types.c Sun Jun 14 11:07:38 2026 +0200 @@ -438,6 +438,9 @@ } static void text_destroy(UiText *t) { + if(t->value.free) { + t->value.free(t->value.ptr); + } if(t->destroy) { t->destroy(t); } @@ -1081,3 +1084,11 @@ text->remove(text, begin, end); } } + +void ui_text_setreadonly(UiText *text, int readonly) { + if(text->setreadonly) { + text->setreadonly(text, readonly); + } else { + text->readonly = readonly; + } +} diff -r 4bbf0487509f -r 5bb4366b0c32 ui/gtk/text.c --- a/ui/gtk/text.c Sun Jun 14 10:52:28 2026 +0200 +++ b/ui/gtk/text.c Sun Jun 14 11:07:38 2026 +0200 @@ -192,6 +192,11 @@ value->value.free(value->value.ptr); } } + + if(value->readonly) { + gtk_text_view_set_editable(GTK_TEXT_VIEW(text_area), FALSE); + } + gtk_text_view_set_buffer(GTK_TEXT_VIEW(text_area), buf); value->obj = text_area; value->save = ui_textarea_save; @@ -209,6 +214,7 @@ value->selection = ui_textarea_selection; value->length = ui_textarea_length; value->remove = ui_textarea_remove; + value->setreadonly = ui_textarea_setreadonly; value->data1 = buf; value->data2 = NULL; value->datatype == UI_TEXT_TYPE_BUFFER; @@ -341,6 +347,7 @@ text->datatype = UI_TEXT_TYPE_BUFFER; } gtk_text_view_set_buffer(GTK_TEXT_VIEW(textarea), text->data1); + gtk_text_view_set_editable(GTK_TEXT_VIEW(textarea), !text->readonly); } void ui_textarea_text_destroy(UiText *text) { @@ -465,6 +472,13 @@ gtk_text_buffer_delete(buf, &ib, &ie); } +void ui_textarea_setreadonly(UiText *text, int readonly) { + if(text->obj) { + gtk_text_view_set_editable(GTK_TEXT_VIEW(text->obj), !readonly); + } + text->readonly = readonly; +} + void ui_textarea_realize_event(GtkWidget *widget, gpointer data) { gtk_widget_grab_focus(widget); } diff -r 4bbf0487509f -r 5bb4366b0c32 ui/gtk/text.h --- a/ui/gtk/text.h Sun Jun 14 10:52:28 2026 +0200 +++ b/ui/gtk/text.h Sun Jun 14 11:07:38 2026 +0200 @@ -132,6 +132,7 @@ void ui_textarea_selection(UiText *text, int *begin, int *end); int ui_textarea_length(UiText *text); void ui_textarea_remove(UiText *text, int begin, int end); +void ui_textarea_setreadonly(UiText *text, int readonly); void ui_textarea_realize_event(GtkWidget *widget, gpointer data); //void ui_textbuf_changed(GtkTextBuffer *textbuffer, UiTextArea *textarea); diff -r 4bbf0487509f -r 5bb4366b0c32 ui/ui/toolkit.h --- a/ui/ui/toolkit.h Sun Jun 14 10:52:28 2026 +0200 +++ b/ui/ui/toolkit.h Sun Jun 14 11:07:38 2026 +0200 @@ -408,8 +408,10 @@ void (*selection)(UiText*, int*, int*); /* text, begin, end */ int (*length)(UiText*); void (*remove)(UiText*, int, int); /* text, begin, end */ + void (*setreadonly)(UiText*, int); UiStr value; int pos; + int readonly; void *obj; int datatype; void *data1; @@ -745,6 +747,7 @@ UIEXPORT void ui_text_selection(UiText *text, int *begin, int *end); UIEXPORT int ui_text_length(UiText *text); UIEXPORT void ui_text_remove(UiText *text, int begin, int end); +UIEXPORT void ui_text_setreadonly(UiText *text, int readonly); UIEXPORT UiStr ui_str(char *cstr); UIEXPORT UiStr ui_str_free(char *str, void (*free)(void *v));