update toolkit

Sun, 16 Jun 2024 11:36:27 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 16 Jun 2024 11:36:27 +0200
changeset 42
9af327d0e0e4
parent 41
7ada3db4cfa8
child 43
ef01d2c90128

update toolkit

ui/common/context.c file | annotate | diff | comparison | revisions
ui/common/context.h file | annotate | diff | comparison | revisions
ui/gtk/container.h file | annotate | diff | comparison | revisions
ui/gtk/draw_cairo.c file | annotate | diff | comparison | revisions
ui/gtk/menu.c file | annotate | diff | comparison | revisions
ui/gtk/toolbar.c file | annotate | diff | comparison | revisions
ui/gtk/toolbar.h file | annotate | diff | comparison | revisions
ui/gtk/toolkit.c file | annotate | diff | comparison | revisions
ui/gtk/toolkit.h file | annotate | diff | comparison | revisions
ui/ui/toolkit.h file | annotate | diff | comparison | revisions
--- a/ui/common/context.c	Fri Jun 14 18:24:31 2024 +0200
+++ b/ui/common/context.c	Sun Jun 16 11:36:27 2024 +0200
@@ -67,7 +67,7 @@
     ctx->attach_document = uic_context_attach_document;
     ctx->detach_document2 = uic_context_detach_document2;
     
-#ifdef UI_GTK
+#if UI_GTK2 || UI_GTK3
     if(toplevel && toplevel->widget) {
         ctx->accel_group = gtk_accel_group_new();
         gtk_window_add_accel_group(GTK_WINDOW(toplevel->widget), ctx->accel_group);
--- a/ui/common/context.h	Fri Jun 14 18:24:31 2024 +0200
+++ b/ui/common/context.h	Sun Jun 16 11:36:27 2024 +0200
@@ -77,7 +77,7 @@
     
     char          *title;
     
-#ifdef UI_GTK
+#if UI_GTK2 || UI_GTK3
     GtkAccelGroup *accel_group;
 #endif
     
--- a/ui/gtk/container.h	Fri Jun 14 18:24:31 2024 +0200
+++ b/ui/gtk/container.h	Sun Jun 16 11:36:27 2024 +0200
@@ -67,7 +67,7 @@
 
 struct UiContainer {
     GtkWidget *widget;
-    GtkMenu *menu;
+    UIMENU menu;
     GtkWidget *current;
     
     void (*add)(UiContainer*, GtkWidget*, UiBool);
--- a/ui/gtk/draw_cairo.c	Fri Jun 14 18:24:31 2024 +0200
+++ b/ui/gtk/draw_cairo.c	Sun Jun 16 11:36:27 2024 +0200
@@ -33,11 +33,16 @@
 
 #include "draw_cairo.h"
 
-#ifdef UI_GTK3
+#if UI_GTK3 || UI_GTK4
 gboolean ui_drawingarea_expose(GtkWidget *w, cairo_t *cr, void *data) {
     UiCairoGraphics g;
+#ifdef UI_GTK4
+    g.g.width = gtk_widget_get_width(w);
+    g.g.height = gtk_widget_get_height(w);
+#else
     g.g.width = gtk_widget_get_allocated_width(w);
     g.g.height = gtk_widget_get_allocated_height(w);
+#endif
     g.widget = w;
     g.cr = cr;
     
@@ -51,7 +56,8 @@
     
     return FALSE;
 }
-#else
+#endif
+#ifdef UI_GTK2
 gboolean ui_canvas_expose(GtkWidget *w, GdkEventExpose *e, void *data) {
     UiCairoGraphics g;
     g.g.width = w->allocation.width;
@@ -74,7 +80,7 @@
 // function from graphics.h
 
 void ui_connect_draw_handler(GtkWidget *widget, UiDrawEvent *event) {
-#ifdef UI_GTK3
+#if UI_GTK3 || UI_GTK4
     g_signal_connect(G_OBJECT(widget),
             "draw",
             G_CALLBACK(ui_drawingarea_expose),
--- a/ui/gtk/menu.c	Fri Jun 14 18:24:31 2024 +0200
+++ b/ui/gtk/menu.c	Sun Jun 16 11:36:27 2024 +0200
@@ -42,6 +42,8 @@
 #include <cx/linked_list.h>
 #include <cx/array_list.h>
 
+#if UI_GTK2 || UI_GTK3
+
 
 static ui_menu_add_f createMenuItem[] = {
     /* UI_MENU                 */ add_menu_widget,
@@ -498,3 +500,5 @@
         cxListDestroy(groups);
     }
 }
+
+#endif /* UI_GTK2 || UI_GTK3 */
--- a/ui/gtk/toolbar.c	Fri Jun 14 18:24:31 2024 +0200
+++ b/ui/gtk/toolbar.c	Sun Jun 16 11:36:27 2024 +0200
@@ -42,6 +42,8 @@
 #include "../common/context.h"
 
 
+#if UI_GTK2 || UI_GTK3
+
 GtkWidget* ui_create_toolbar(UiObject *obj) {
     GtkWidget *toolbar = gtk_toolbar_new();
 #ifdef UI_GTK3
@@ -417,4 +419,6 @@
     
 }
 
-#endif
+#endif /* UI_GTK3 */
+
+#endif /* UI_GTK2 || UI_GTK3 */
--- a/ui/gtk/toolbar.h	Fri Jun 14 18:24:31 2024 +0200
+++ b/ui/gtk/toolbar.h	Sun Jun 16 11:36:27 2024 +0200
@@ -40,6 +40,8 @@
 extern "C" {
 #endif
 
+#if UI_GTK2 || UI_GTK3
+    
 typedef struct UiToolItemI      UiToolItemI;
 typedef struct UiToolItem       UiToolItem;
 typedef struct UiStToolItem     UiStToolItem;
@@ -139,6 +141,8 @@
 void ui_combobox_update(UiEvent *event, void *combobox);
 */
 
+#endif
+
 #ifdef	__cplusplus
 }
 #endif
--- a/ui/gtk/toolkit.c	Fri Jun 14 18:24:31 2024 +0200
+++ b/ui/gtk/toolkit.c	Sun Jun 16 11:36:27 2024 +0200
@@ -304,6 +304,8 @@
 
 void ui_css_init(void) {
     ui_gtk_css_provider = gtk_css_provider_new();
+    
+#ifdef UI_GTK3
     gtk_css_provider_load_from_data(ui_gtk_css_provider, ui_gtk_css, -1, NULL);
     
     GdkScreen *screen = gdk_screen_get_default();
@@ -311,6 +313,21 @@
             screen,
             GTK_STYLE_PROVIDER(ui_gtk_css_provider),
             GTK_STYLE_PROVIDER_PRIORITY_USER);
+#endif /* UI_GTK3 */
+    
+#ifdef UI_GTK4
+    
+    
+#if GTK_MINOR_VERSION < 12
+    gtk_css_provider_load_from_data(ui_gtk_css_provider, ui_gtk_css, -1);
+#else
+    gtk_css_provider_load_from_string(ui_gtk_css_provider, ui_gtk_css);
+#endif /* GTK_MINOR_VERSION < 12 */
+    
+    GdkDisplay *display = gdk_display_get_default();
+    gtk_style_context_add_provider_for_display(display, GTK_STYLE_PROVIDER(ui_gtk_css_provider), GTK_STYLE_PROVIDER_PRIORITY_USER);
+    
+#endif /* UI_GTK4 */
 }
 
 
--- a/ui/gtk/toolkit.h	Fri Jun 14 18:24:31 2024 +0200
+++ b/ui/gtk/toolkit.h	Sun Jun 16 11:36:27 2024 +0200
@@ -55,9 +55,11 @@
     void        *userdata;
 } UiVarEventData;
 
+#ifndef UI_GTK4
 struct UiSelection {
     GtkSelectionData *data;
 };
+#endif
 
 typedef enum UiOrientation UiOrientation;
 enum UiOrientation { UI_HORIZONTAL = 0, UI_VERTICAL };
--- a/ui/ui/toolkit.h	Fri Jun 14 18:24:31 2024 +0200
+++ b/ui/ui/toolkit.h	Sun Jun 16 11:36:27 2024 +0200
@@ -42,11 +42,18 @@
 typedef void* UIMENU;
 #endif
 
-#elif UI_GTK2 || UI_GTK3
+#elif UI_GTK2 || UI_GTK3 || UI_GTK4
 
 #include <gtk/gtk.h>
 #define UIWIDGET GtkWidget*
+
+#if UI_GTK2 || UI_GTK3
 #define UIMENU   GtkMenu*
+#endif
+#ifdef UI_GTK4
+#define UIMENU   GtkPopoverMenu*
+#endif
+
 #define UI_GTK
 
 #elif UI_MOTIF

mercurial