Sun, 07 Apr 2024 12:36:07 +0200
implement ui_dialog_create (GTK)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/gtk/button.c | file | annotate | diff | comparison | revisions | |
ui/gtk/graphics.c | file | annotate | diff | comparison | revisions | |
ui/gtk/menu.c | file | annotate | diff | comparison | revisions | |
ui/gtk/range.c | file | annotate | diff | comparison | revisions | |
ui/gtk/toolbar.c | file | annotate | diff | comparison | revisions | |
ui/gtk/toolkit.h | file | annotate | diff | comparison | revisions | |
ui/gtk/tree.c | file | annotate | diff | comparison | revisions | |
ui/gtk/window.c | file | annotate | diff | comparison | revisions |
--- a/application/main.c Sun Apr 07 11:26:38 2024 +0200 +++ b/application/main.c Sun Apr 07 12:36:07 2024 +0200 @@ -50,7 +50,13 @@ } void action_button(UiEvent *event, void *userdata) { - + ui_dialog(event->obj, + .title = "My Title", + .button1_label = "OK", + .button2_label = "Test", + .closebutton_label = "Cancel", + .content = "Hello World!", + .input = true); } void action_switch(UiEvent *event, void *userdata) { @@ -98,7 +104,7 @@ MyDocument *doc = create_doc(); ui_attach_document(obj->ctx, doc); - ui_button(obj, .label = "Test Button", .icon = "application-x-generic"); + ui_button(obj, .label = "Test Button", .icon = "application-x-generic", .onclick = action_button); ui_togglebutton(obj, .label = "Toggle"); ui_checkbox(obj, .label = "Checkbox");
--- a/ui/gtk/button.c Sun Apr 07 11:26:38 2024 +0200 +++ b/ui/gtk/button.c Sun Apr 07 12:36:07 2024 +0200 @@ -69,6 +69,7 @@ event->userdata = args.onclickdata; event->callback = args.onclick; event->value = 0; + event->customdata = NULL; g_signal_connect( button,
--- a/ui/gtk/graphics.c Sun Apr 07 11:26:38 2024 +0200 +++ b/ui/gtk/graphics.c Sun Apr 07 12:36:07 2024 +0200 @@ -104,6 +104,8 @@ event->obj = obj; event->callback = f; event->userdata = u; + event->customdata = NULL; + event->value = 0; g_signal_connect(G_OBJECT(widget), "button-press-event",
--- a/ui/gtk/menu.c Sun Apr 07 11:26:38 2024 +0200 +++ b/ui/gtk/menu.c Sun Apr 07 12:36:07 2024 +0200 @@ -109,6 +109,7 @@ event->userdata = i->userdata; event->callback = i->callback; event->value = 0; + event->customdata = NULL; g_signal_connect( widget, @@ -192,7 +193,8 @@ event->userdata = ci->userdata; event->callback = ci->callback; event->value = 0; - + event->customdata = NULL; + g_signal_connect( widget, "toggled", @@ -291,6 +293,7 @@ event->userdata = list->userdata; event->callback = list->callback; event->value = i - 1; + event->customdata = NULL; g_signal_connect( widget, @@ -415,6 +418,7 @@ event->userdata = userdata; event->callback = f; event->value = 0; + event->customdata = NULL; g_signal_connect( widget, @@ -469,6 +473,7 @@ event->userdata = userdata; event->callback = f; event->value = 0; + event->customdata = NULL; g_signal_connect( widget,
--- a/ui/gtk/range.c Sun Apr 07 11:26:38 2024 +0200 +++ b/ui/gtk/range.c Sun Apr 07 12:36:07 2024 +0200 @@ -61,6 +61,7 @@ event->userdata = userdata; event->callback = f; event->value = 0; + event->customdata = NULL; g_signal_connect( G_OBJECT(scrollbar),
--- a/ui/gtk/toolbar.c Sun Apr 07 11:26:38 2024 +0200 +++ b/ui/gtk/toolbar.c Sun Apr 07 12:36:07 2024 +0200 @@ -150,6 +150,8 @@ event->obj = obj; event->callback = item->args.onclick; event->userdata = item->args.onclickdata; + event->customdata = NULL; + event->value = 0; g_signal_connect( button,
--- a/ui/gtk/toolkit.h Sun Apr 07 11:26:38 2024 +0200 +++ b/ui/gtk/toolkit.h Sun Apr 07 12:36:07 2024 +0200 @@ -44,6 +44,7 @@ ui_callback callback; void *userdata; int value; + void *customdata; } UiEventData; typedef struct UiVarEventData {
--- a/ui/gtk/tree.c Sun Apr 07 11:26:38 2024 +0200 +++ b/ui/gtk/tree.c Sun Apr 07 12:36:07 2024 +0200 @@ -616,6 +616,7 @@ event->userdata = udata; event->callback = f; event->value = 0; + event->customdata = NULL; g_signal_connect( combobox,
--- a/ui/gtk/window.c Sun Apr 07 11:26:38 2024 +0200 +++ b/ui/gtk/window.c Sun Apr 07 12:36:07 2024 +0200 @@ -155,6 +155,76 @@ return create_window(title, window_data, TRUE); } +static void ui_dialog_response (GtkDialog* self, gint response_id, gpointer user_data) { + UiEventData *data = user_data; + UiEvent evt; + evt.obj = data->obj; + evt.document = evt.obj->ctx->document; + evt.window = evt.obj->window; + evt.eventdata = NULL; + evt.intval = 0; + + if(data->customdata) { + GtkWidget *entry = data->customdata; + evt.eventdata = (void*)gtk_entry_get_text(GTK_ENTRY(entry)); + + } + + if(response_id == 1 || response_id == 2) { + evt.intval = response_id; + } + + + if(data->callback) { + data->callback(&evt, data->userdata); + } + + gtk_widget_destroy(GTK_WIDGET(self)); +} + +void ui_dialog_create(UiObject *parent, UiDialogArgs args) { + GtkDialog *dialog = GTK_DIALOG(gtk_dialog_new()); + GtkWidget *dialog_w = GTK_WIDGET(dialog); + if(args.title) { + gtk_window_set_title(GTK_WINDOW(dialog), args.title); + } + if(args.button1_label) { + gtk_dialog_add_button(dialog, args.button1_label, 1); + } + if(args.button2_label) { + gtk_dialog_add_button(dialog, args.button2_label, 2); + } + if(args.closebutton_label) { + gtk_dialog_add_button(dialog, args.closebutton_label, 0); + } + + GtkWidget *content_area = gtk_dialog_get_content_area(dialog); + if(args.content) { + GtkWidget *label = gtk_label_new(args.content); + gtk_container_add(GTK_CONTAINER(content_area), label); + } + + GtkWidget *textfield = NULL; + if(args.input) { + textfield = gtk_entry_new(); + gtk_container_add(GTK_CONTAINER(content_area), textfield); + } + + UiEventData *event = malloc(sizeof(UiEventData)); + event->obj = parent; + event->callback = args.result; + event->userdata = args.resultdata; + event->value = 0; + event->customdata = textfield; + + g_signal_connect(dialog_w, + "response", + G_CALLBACK(ui_dialog_response), + event); + + gtk_widget_show_all(GTK_WIDGET(dialog_w)); +} + static char* ui_gtkfilechooser(UiObject *obj, GtkFileChooserAction action) { char *button; char *title;