ui/gtk/window.c

changeset 44
473954dc6b74
parent 32
e5f4d8af567e
child 45
ab71409644b0
--- a/ui/gtk/window.c	Mon Jun 17 21:20:58 2024 +0200
+++ b/ui/gtk/window.c	Sun Sep 29 13:32:51 2024 +0200
@@ -41,6 +41,7 @@
 #include "menu.h"
 #include "toolbar.h"
 #include "container.h"
+#include "headerbar.h"
 
 static int nwindows = 0;
 
@@ -72,8 +73,10 @@
 static UiObject* create_window(const char *title, void *window_data, UiBool simple) {
     CxMempool *mp = cxBasicMempoolCreate(256);
     UiObject *obj = cxCalloc(mp->allocator, 1, sizeof(UiObject)); 
-    
-#ifndef UI_GTK2
+   
+#ifdef UI_LIBADWAITA
+    obj->widget = adw_application_window_new(ui_get_application());
+#elif !defined(UI_GTK2)
     obj->widget = gtk_application_window_new(ui_get_application());
 #else
     obj->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
@@ -83,6 +86,10 @@
     obj->ctx = uic_context(obj, mp);
     obj->window = window_data;
     
+#if GTK_CHECK_VERSION(4, 0, 0)
+    obj->ctx->action_map = G_ACTION_MAP(obj->widget);
+#endif
+    
     if(title != NULL) {
         gtk_window_set_title(GTK_WINDOW(obj->widget), title);
     }
@@ -108,6 +115,18 @@
             obj);
     
     GtkWidget *vbox = ui_gtk_vbox_new(0);
+#ifdef UI_LIBADWAITA
+    GtkWidget *toolbar_view = adw_toolbar_view_new();
+    adw_application_window_set_content(ADW_APPLICATION_WINDOW(obj->widget), toolbar_view);
+    adw_toolbar_view_set_content(ADW_TOOLBAR_VIEW(toolbar_view), vbox);
+    
+    GtkWidget *headerbar = adw_header_bar_new();
+    adw_toolbar_view_add_top_bar(ADW_TOOLBAR_VIEW(toolbar_view), headerbar);
+    
+    ui_fill_headerbar(obj, headerbar);
+#elif GTK_MAJOR_VERSION >= 4
+    WINDOW_SET_CONTENT(obj->widget, vbox);
+#else
     gtk_container_add(GTK_CONTAINER(obj->widget), vbox);
     
     if(!simple) {
@@ -130,9 +149,12 @@
         //GtkWidget *hb = ui_create_headerbar(obj);
         //gtk_window_set_titlebar(GTK_WINDOW(obj->widget), hb);
     }
+#endif
     
     // window content
     // the content has a (TODO: not yet) configurable frame
+    // TODO: really? why
+    /*
     GtkWidget *frame = gtk_frame_new(NULL);
     gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE);
     gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
@@ -141,6 +163,10 @@
     GtkWidget *content_box = ui_gtk_vbox_new(0);
     gtk_container_add(GTK_CONTAINER(frame), content_box);
     obj->container = ui_box_container(obj, content_box);
+    */
+    GtkWidget *content_box = ui_gtk_vbox_new(0);
+    BOX_ADD(GTK_BOX(vbox), content_box);
+    obj->container = ui_box_container(obj, content_box, UI_CONTAINER_VBOX);
     
     nwindows++;
     return obj;
@@ -173,7 +199,7 @@
     
     if(data->customdata) {
         GtkWidget *entry = data->customdata;
-        evt.eventdata = (void*)gtk_entry_get_text(GTK_ENTRY(entry));
+        evt.eventdata = (void*)ENTRY_GET_TEXT(GTK_ENTRY(entry));
         
     }
     
@@ -186,7 +212,7 @@
         data->callback(&evt, data->userdata);
     }
     
-    gtk_widget_destroy(GTK_WIDGET(self));
+    WINDOW_DESTROY(GTK_WIDGET(self));
 }
 
 void ui_dialog_create(UiObject *parent, UiDialogArgs args) {
@@ -208,13 +234,13 @@
     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);
+        BOX_ADD(content_area, label);
     }
     
     GtkWidget *textfield = NULL;
     if(args.input) {
         textfield = gtk_entry_new();
-        gtk_container_add(GTK_CONTAINER(content_area), textfield);
+        BOX_ADD(content_area, textfield);
     }
     
     UiEventData *event = malloc(sizeof(UiEventData));
@@ -229,9 +255,15 @@
                            G_CALLBACK(ui_dialog_response),
                            event);
     
-    gtk_widget_show_all(GTK_WIDGET(dialog_w));
+    WINDOW_SHOW(GTK_WIDGET(dialog_w));
 }
 
+
+#if GTK_MAJOR_VERSION >= 4
+static void ui_gtkfilechooser(UiObject *obj, GtkFileChooserAction action, unsigned int mode, ui_callback file_selected_callback, void *cbdata) {
+    // TODO
+}
+#else
 static void ui_gtkfilechooser(UiObject *obj, GtkFileChooserAction action, unsigned int mode, ui_callback file_selected_callback, void *cbdata) {
     char *button;
     char *title;
@@ -272,7 +304,7 @@
     if((mode & UI_FILEDIALOG_SELECT_MULTI) == UI_FILEDIALOG_SELECT_MULTI) {
         gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
     }
-       
+    
     UiEvent evt;
     evt.obj = obj;
     evt.document = evt.obj->ctx->document;
@@ -310,6 +342,7 @@
     
     gtk_widget_destroy(dialog);
 }
+#endif
 
 void ui_openfiledialog(UiObject *obj, unsigned int mode, ui_callback file_selected_callback, void *cbdata) {
     ui_gtkfilechooser(obj, GTK_FILE_CHOOSER_ACTION_OPEN, mode, file_selected_callback, cbdata);

mercurial