--- a/ui/gtk/window.c Sat Apr 05 17:57:04 2025 +0200 +++ b/ui/gtk/window.c Sun Jul 20 22:04:39 2025 +0200 @@ -102,9 +102,7 @@ #endif static UiObject* create_window(const char *title, void *window_data, UiBool sidebar, UiBool simple) { - CxMempool *mp = cxMempoolCreateSimple(256); - UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); - obj->ref = 0; + UiObject *obj = uic_object_new_toplevel(); #ifdef UI_LIBADWAITA obj->widget = adw_application_window_new(ui_get_application()); @@ -114,8 +112,6 @@ obj->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); #endif - - obj->ctx = uic_context(obj, mp); obj->window = window_data; #if GTK_CHECK_VERSION(4, 0, 0) @@ -316,6 +312,8 @@ evt.document = evt.obj->ctx->document; evt.window = evt.obj->window; evt.eventdata = NULL; + evt.eventdatatype = 0; + evt.eventdatatype = 0; evt.intval = 0; if(!strcmp(response, "btn1")) { @@ -327,6 +325,7 @@ if(data->customdata) { GtkWidget *entry = data->customdata; evt.eventdata = (void*)ENTRY_GET_TEXT(GTK_ENTRY(entry)); + evt.eventdatatype = UI_EVENT_DATA_STRING; } if(data->callback) { @@ -334,37 +333,39 @@ } } -void ui_dialog_create(UiObject *parent, UiDialogArgs args) { - AdwDialog *dialog = adw_alert_dialog_new(args.title, args.content); +void ui_dialog_create(UiObject *parent, UiDialogArgs *args) { + AdwDialog *dialog = adw_alert_dialog_new(args->title, args->content); UiEventData *event = malloc(sizeof(UiEventData)); - event->callback = args.result; - event->userdata = args.resultdata; + event->callback = args->result; + event->userdata = args->resultdata; event->customdata = NULL; + event->customint = 0; event->value = 0; event->obj = parent; - if(args.button1_label) { - adw_alert_dialog_add_response(ADW_ALERT_DIALOG(dialog), "btn1", args.button1_label); + if(args->button1_label) { + adw_alert_dialog_add_response(ADW_ALERT_DIALOG(dialog), "btn1", args->button1_label); } - if(args.button2_label) { - adw_alert_dialog_add_response(ADW_ALERT_DIALOG(dialog), "btn2", args.button2_label); + if(args->button2_label) { + adw_alert_dialog_add_response(ADW_ALERT_DIALOG(dialog), "btn2", args->button2_label); } - if(args.closebutton_label) { - adw_alert_dialog_add_response(ADW_ALERT_DIALOG(dialog), "close", args.closebutton_label); + if(args->closebutton_label) { + adw_alert_dialog_add_response(ADW_ALERT_DIALOG(dialog), "close", args->closebutton_label); adw_alert_dialog_set_close_response(ADW_ALERT_DIALOG(dialog), "close"); } GtkWidget *entry = NULL; - if(args.input || args.password) { + if(args->input || args->password) { entry = gtk_entry_new(); - if(args.password) { + if(args->password) { gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); } - if(args.input_value) { - ENTRY_SET_TEXT(entry, args.input_value); + if(args->input_value) { + ENTRY_SET_TEXT(entry, args->input_value); } adw_alert_dialog_set_extra_child(ADW_ALERT_DIALOG(dialog), entry); event->customdata = entry; + event->customint = 0; } g_signal_connect( @@ -415,41 +416,41 @@ gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); GtkWidget *dialog_w = GTK_WIDGET(dialog); - if(args.title) { - gtk_window_set_title(GTK_WINDOW(dialog), args.title); + 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->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->button2_label) { + gtk_dialog_add_button(dialog, args->button2_label, 2); } - if(args.closebutton_label) { - gtk_dialog_add_button(dialog, args.closebutton_label, 0); + 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); + if(args->content) { + GtkWidget *label = gtk_label_new(args->content); BOX_ADD(content_area, label); } GtkWidget *textfield = NULL; - if(args.input || args.password) { + if(args->input || args->password) { textfield = gtk_entry_new(); - if(args.password) { + if(args->password) { gtk_entry_set_visibility(GTK_ENTRY(textfield), FALSE); } - if(args.input_value) { - ENTRY_SET_TEXT(textfield, args.input_value); + if(args->input_value) { + ENTRY_SET_TEXT(textfield, args->input_value); } BOX_ADD(content_area, textfield); } UiEventData *event = malloc(sizeof(UiEventData)); event->obj = parent; - event->callback = args.result; - event->userdata = args.resultdata; + event->callback = args->result; + event->userdata = args->resultdata; event->value = 0; event->customdata = textfield; @@ -521,6 +522,7 @@ flist.files = NULL; flist.nfiles = 0; evt.eventdata = &flist; + evt.eventdatatype = UI_EVENT_DATA_FILE_LIST; if(selection) { flist = listmodel2filelist(selection); @@ -555,6 +557,7 @@ event->callback = file_selected_callback; event->userdata = cbdata; event->customdata = NULL; + event->customint = 0; event->value = mode; event->obj = obj; @@ -746,38 +749,36 @@ -UiObject* ui_dialog_window_create(UiObject *parent, UiDialogWindowArgs args) { +UiObject* ui_dialog_window_create(UiObject *parent, UiDialogWindowArgs *args) { GtkWidget *dialog = DIALOG_NEW(); - if(args.width > 0 || args.height > 0) { + if(args->width > 0 || args->height > 0) { gtk_window_set_default_size( GTK_WINDOW(dialog), - args.width, - args.height); + args->width, + args->height); } gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent->widget)); - if(args.modal != UI_OFF) { + if(args->modal != UI_OFF) { gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); } - CxMempool *mp = cxMempoolCreateSimple(256); - UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); - obj->ctx = uic_context(obj, mp); + UiObject *obj = uic_object_new_toplevel(); obj->widget = dialog; obj->ref = 0; obj->destroy = ui_window_widget_destroy; nwindows++; - if(args.title != NULL) { - gtk_window_set_title(GTK_WINDOW(dialog), args.title); + if(args->title != NULL) { + gtk_window_set_title(GTK_WINDOW(dialog), args->title); } #if ! GTK_CHECK_VERSION(4, 10, 0) UiEventData *event = malloc(sizeof(UiEventData)); event->obj = obj; - event->userdata = args.onclickdata; - event->callback = args.onclick; + event->userdata = args->onclickdata; + event->callback = args->onclick; event->value = 0; event->customdata = NULL; @@ -815,44 +816,44 @@ GtkWidget *content_vbox = ui_gtk_vbox_new(0); obj->container = ui_box_container(obj, content_vbox, UI_CONTAINER_VBOX); - if(args.lbutton1 || args.lbutton2 || args.rbutton3 || args.rbutton4) { + if(args->lbutton1 || args->lbutton2 || args->rbutton3 || args->rbutton4) { #if GTK_CHECK_VERSION(3, 10, 0) - if(args.titlebar_buttons != UI_OFF) { + if(args->titlebar_buttons != UI_OFF) { GtkWidget *headerbar = gtk_header_bar_new(); gtk_window_set_titlebar(GTK_WINDOW(dialog), headerbar); - if(args.show_closebutton == UI_OFF) { + if(args->show_closebutton == UI_OFF) { HEADERBAR_SHOW_CLOSEBUTTON(headerbar, FALSE); } - if(args.lbutton1) { - GtkWidget *button = ui_create_button(obj, args.lbutton1, NULL, args.onclick, args.onclickdata, 1, args.default_button == 1); + if(args->lbutton1) { + GtkWidget *button = ui_create_button(obj, args->lbutton1, NULL, args->onclick, args->onclickdata, 1, args->default_button == 1); gtk_header_bar_pack_start(GTK_HEADER_BAR(headerbar), button); - if(args.default_button == 1) { + if(args->default_button == 1) { WIDGET_ADD_CSS_CLASS(button, "suggested-action"); DEFAULT_BUTTON(dialog, button); } } - if(args.lbutton2) { - GtkWidget *button = ui_create_button(obj, args.lbutton2, NULL, args.onclick, args.onclickdata, 2, args.default_button == 2); + if(args->lbutton2) { + GtkWidget *button = ui_create_button(obj, args->lbutton2, NULL, args->onclick, args->onclickdata, 2, args->default_button == 2); gtk_header_bar_pack_start(GTK_HEADER_BAR(headerbar), button); - if(args.default_button == 2) { + if(args->default_button == 2) { WIDGET_ADD_CSS_CLASS(button, "suggested-action"); DEFAULT_BUTTON(dialog, button); } } - if(args.rbutton4) { - GtkWidget *button = ui_create_button(obj, args.rbutton4, NULL, args.onclick, args.onclickdata, 4, args.default_button == 4); + if(args->rbutton4) { + GtkWidget *button = ui_create_button(obj, args->rbutton4, NULL, args->onclick, args->onclickdata, 4, args->default_button == 4); gtk_header_bar_pack_end(GTK_HEADER_BAR(headerbar), button); - if(args.default_button == 4) { + if(args->default_button == 4) { WIDGET_ADD_CSS_CLASS(button, "suggested-action"); DEFAULT_BUTTON(dialog, button); } } - if(args.rbutton3) { - GtkWidget *button = ui_create_button(obj, args.rbutton3, NULL, args.onclick, args.onclickdata, 3, args.default_button == 3); + if(args->rbutton3) { + GtkWidget *button = ui_create_button(obj, args->rbutton3, NULL, args->onclick, args->onclickdata, 3, args->default_button == 3); gtk_header_bar_pack_end(GTK_HEADER_BAR(headerbar), button); - if(args.default_button == 3) { + if(args->default_button == 3) { WIDGET_ADD_CSS_CLASS(button, "suggested-action"); DEFAULT_BUTTON(dialog, button); } @@ -870,18 +871,18 @@ GtkWidget *widget = ui_box_set_margin(grid, 16); gtk_grid_set_column_homogeneous(GTK_GRID(grid), TRUE); - if(args.lbutton1) { - GtkWidget *button = ui_create_button(obj, args.lbutton1, NULL, args.onclick, args.onclickdata, 1, args.default_button == 1); + if(args->lbutton1) { + GtkWidget *button = ui_create_button(obj, args->lbutton1, NULL, args->onclick, args->onclickdata, 1, args->default_button == 1); gtk_grid_attach(GTK_GRID(grid), button, 0, 0, 1, 1); - if(args.default_button == 1) { + if(args->default_button == 1) { WIDGET_ADD_CSS_CLASS(button, "suggested-action"); DEFAULT_BUTTON(dialog, button); } } - if(args.lbutton2) { - GtkWidget *button = ui_create_button(obj, args.lbutton2, NULL, args.onclick, args.onclickdata, 2, args.default_button == 2); + if(args->lbutton2) { + GtkWidget *button = ui_create_button(obj, args->lbutton2, NULL, args->onclick, args->onclickdata, 2, args->default_button == 2); gtk_grid_attach(GTK_GRID(grid), button, 1, 0, 1, 1); - if(args.default_button == 2) { + if(args->default_button == 2) { WIDGET_ADD_CSS_CLASS(button, "suggested-action"); DEFAULT_BUTTON(dialog, button); } @@ -889,18 +890,18 @@ GtkWidget *space = gtk_label_new(NULL); gtk_widget_set_hexpand(space, TRUE); gtk_grid_attach(GTK_GRID(grid), space, 2, 0, 1, 1); - if(args.rbutton3) { - GtkWidget *button = ui_create_button(obj, args.rbutton3, NULL, args.onclick, args.onclickdata, 3, args.default_button == 3); + if(args->rbutton3) { + GtkWidget *button = ui_create_button(obj, args->rbutton3, NULL, args->onclick, args->onclickdata, 3, args->default_button == 3); gtk_grid_attach(GTK_GRID(grid), button, 3, 0, 1, 1); - if(args.default_button == 3) { + if(args->default_button == 3) { WIDGET_ADD_CSS_CLASS(button, "suggested-action"); DEFAULT_BUTTON(dialog, button); } } - if(args.rbutton4) { - GtkWidget *button = ui_create_button(obj, args.rbutton4, NULL, args.onclick, args.onclickdata, 4, args.default_button == 4); + if(args->rbutton4) { + GtkWidget *button = ui_create_button(obj, args->rbutton4, NULL, args->onclick, args->onclickdata, 4, args->default_button == 4); gtk_grid_attach(GTK_GRID(grid), button, 4, 0, 1, 1); - if(args.default_button == 4) { + if(args->default_button == 4) { WIDGET_ADD_CSS_CLASS(button, "suggested-action"); DEFAULT_BUTTON(dialog, button); }