prepare webview

6 weeks ago

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 09 Feb 2025 20:21:52 +0100 (6 weeks ago)
changeset 463
e8ee57cc052e
parent 462
9e499276136a
child 464
e06714e6fa12

prepare webview

application/main.c file | annotate | diff | comparison | revisions
configure file | annotate | diff | comparison | revisions
make/project.xml file | annotate | diff | comparison | revisions
ui/gtk/objs.mk file | annotate | diff | comparison | revisions
ui/gtk/webview.c file | annotate | diff | comparison | revisions
ui/gtk/webview.h file | annotate | diff | comparison | revisions
ui/ui/ui.h file | annotate | diff | comparison | revisions
ui/ui/webview.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Sat Feb 08 21:42:56 2025 +0100
+++ b/application/main.c	Sun Feb 09 20:21:52 2025 +0100
@@ -478,6 +478,13 @@
                 ui_button(obj, .label = "Button 2");
             }
         }
+      ui_tab(obj, "Tab 9") {
+#ifdef UI_WEBVIEW
+          ui_webview(obj, .fill = UI_ON);
+#else
+          ui_label(obj, "Webview is not supported");
+#endif
+      }  
     }
     
     /*
--- a/configure	Sat Feb 08 21:42:56 2025 +0100
+++ b/configure	Sun Feb 09 20:21:52 2025 +0100
@@ -408,6 +408,39 @@
     dep_checked_libadwaita=1
     return 0
 }
+dependency_error_webkitgtk6()
+{
+    print_check_msg "$dep_checked_webkitgtk6" "checking for webkitgtk6... "
+    # dependency webkitgtk6
+    while true
+    do
+        if [ -z "$PKG_CONFIG" ]; then
+            break
+        fi
+        if test_pkg_config "webkitgtk-6.0" "" "" "" ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags webkitgtk-6.0`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs webkitgtk-6.0`"
+        else
+            break
+        fi
+        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_WEBVIEW"
+        print_check_msg "$dep_checked_webkitgtk6" "yes\n"
+        dep_checked_webkitgtk6=1
+        return 1
+    done
+
+    # dependency webkitgtk6
+    while true
+    do
+        print_check_msg "$dep_checked_webkitgtk6" "yes\n"
+        dep_checked_webkitgtk6=1
+        return 1
+    done
+
+    print_check_msg "$dep_checked_webkitgtk6" "no\n"
+    dep_checked_webkitgtk6=1
+    return 0
+}
 dependency_error_motif()
 {
     print_check_msg "$dep_checked_motif" "checking for motif... "
@@ -438,6 +471,57 @@
     dep_checked_motif=1
     return 0
 }
+dependency_error_webkit2gtk4()
+{
+    print_check_msg "$dep_checked_webkit2gtk4" "checking for webkit2gtk4... "
+    # dependency webkit2gtk4
+    while true
+    do
+        if [ -z "$PKG_CONFIG" ]; then
+            break
+        fi
+        if test_pkg_config "webkit2gtk-4.1" "" "" "" ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags webkit2gtk-4.1`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs webkit2gtk-4.1`"
+        else
+            break
+        fi
+        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_WEBVIEW"
+        print_check_msg "$dep_checked_webkit2gtk4" "yes\n"
+        dep_checked_webkit2gtk4=1
+        return 1
+    done
+
+    # dependency webkit2gtk4
+    while true
+    do
+        if [ -z "$PKG_CONFIG" ]; then
+            break
+        fi
+        if test_pkg_config "webkit2gtk-4.0" "" "" "" ; then
+            TEMP_CFLAGS="$TEMP_CFLAGS `"$PKG_CONFIG" --cflags webkit2gtk-4.0`"
+            TEMP_LDFLAGS="$TEMP_LDFLAGS `"$PKG_CONFIG" --libs webkit2gtk-4.0`"
+        else
+            break
+        fi
+        TEMP_CFLAGS="$TEMP_CFLAGS -DUI_WEBVIEW"
+        print_check_msg "$dep_checked_webkit2gtk4" "yes\n"
+        dep_checked_webkit2gtk4=1
+        return 1
+    done
+
+    # dependency webkit2gtk4
+    while true
+    do
+        print_check_msg "$dep_checked_webkit2gtk4" "yes\n"
+        dep_checked_webkit2gtk4=1
+        return 1
+    done
+
+    print_check_msg "$dep_checked_webkit2gtk4" "no\n"
+    dep_checked_webkit2gtk4=1
+    return 0
+}
 dependency_error_cocoa()
 {
     print_check_msg "$dep_checked_cocoa" "checking for cocoa... "
@@ -573,6 +657,9 @@
     if dependency_error_libadwaita ; then
         VERR=1
     fi
+    if dependency_error_webkitgtk6 ; then
+        VERR=1
+    fi
     if [ $VERR -ne 0 ]; then
         return 1
     fi
@@ -588,6 +675,9 @@
     if dependency_error_gtk4 ; then
         VERR=1
     fi
+    if dependency_error_webkitgtk6 ; then
+        VERR=1
+    fi
     if [ $VERR -ne 0 ]; then
         return 1
     fi
@@ -603,6 +693,9 @@
     if dependency_error_gtk3 ; then
         VERR=1
     fi
+    if dependency_error_webkit2gtk4 ; then
+        VERR=1
+    fi
     if [ $VERR -ne 0 ]; then
         return 1
     fi
--- a/make/project.xml	Sat Feb 08 21:42:56 2025 +0100
+++ b/make/project.xml	Sun Feb 09 20:21:52 2025 +0100
@@ -62,6 +62,29 @@
 		<ldflags>-lXm -lXt -lX11 -lpthread</ldflags>
 	</dependency>
 	
+	<dependency name="webkitgtk6">
+		<pkgconfig>webkitgtk-6.0</pkgconfig>
+		<cflags>-DUI_WEBVIEW</cflags>
+	</dependency>
+	
+	<dependency name="webkitgtk6">
+		<!-- webview unsupported -->
+	</dependency>
+	
+	<dependency name="webkit2gtk4">
+		<pkgconfig>webkit2gtk-4.1</pkgconfig>
+		<cflags>-DUI_WEBVIEW</cflags>
+	</dependency>
+	
+	<dependency name="webkit2gtk4">
+		<pkgconfig>webkit2gtk-4.0</pkgconfig>
+		<cflags>-DUI_WEBVIEW</cflags>
+	</dependency>
+	
+	<dependency name="webkit2gtk4">
+		<!-- webview unsupported -->
+	</dependency>
+	
 	<dependency platform="macos">
 		<make>OBJ_EXT = .o</make>
 		<make>LIB_EXT = .a</make>
@@ -81,17 +104,17 @@
 	<target name="tk">
 		<option arg="toolkit">
 			<value str="libadwaita">
-				<dependencies>libadwaita</dependencies>
+				<dependencies>libadwaita,webkitgtk6</dependencies>
 				<make>TOOLKIT = gtk</make>
 				<make>GTKOBJ = draw_cairo.o</make>
 			</value>
 			<value str="gtk4">
-				<dependencies>gtk4</dependencies>
+				<dependencies>gtk4,webkitgtk6</dependencies>
 				<make>TOOLKIT = gtk</make>
 				<make>GTKOBJ = draw_cairo.o</make>
 			</value>
 			<value str="gtk3">
-				<dependencies>gtk3</dependencies>
+				<dependencies>gtk3,webkit2gtk4</dependencies>
 				<make>TOOLKIT = gtk</make>
 				<make>GTKOBJ = draw_cairo.o</make>
 			</value>
--- a/ui/gtk/objs.mk	Sat Feb 08 21:42:56 2025 +0100
+++ b/ui/gtk/objs.mk	Sun Feb 09 20:21:52 2025 +0100
@@ -46,6 +46,7 @@
 GTKOBJ += entry.o
 GTKOBJ += dnd.o
 GTKOBJ += headerbar.o
+GTKOBJ += webview.o
 
 TOOLKITOBJS += $(GTKOBJ:%=$(GTK_OBJPRE)%)
 TOOLKITSOURCE += $(GTKOBJ:%.o=gtk/%.c)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/gtk/webview.c	Sun Feb 09 20:21:52 2025 +0100
@@ -0,0 +1,53 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "toolkit.h"
+#include "container.h"
+#include "../ui/webview.h"
+
+#ifdef UI_WEBVIEW
+
+#include <webkit/webkit.h>
+
+UIWIDGET ui_webview_create(UiObject *obj, UiWebviewArgs args) {
+    UiObject* current = uic_current_obj(obj);
+    
+    GtkWidget *webview = webkit_web_view_new();
+    webkit_web_view_load_uri(WEBKIT_WEB_VIEW(webview), "https://code.unixwork.de");
+    
+    ui_set_name_and_style(webview, args.name, args.style_class);
+    
+    ui_set_widget_groups(obj->ctx, webview, args.groups);
+    UI_APPLY_LAYOUT1(current, args);
+    current->container->add(current->container, webview, FALSE);
+    
+    return webview;
+}
+
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/gtk/webview.h	Sun Feb 09 20:21:52 2025 +0100
@@ -0,0 +1,43 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef WEBVIEW_H
+#define WEBVIEW_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* WEBVIEW_H */
+
--- a/ui/ui/ui.h	Sat Feb 08 21:42:56 2025 +0100
+++ b/ui/ui/ui.h	Sun Feb 09 20:21:52 2025 +0100
@@ -47,5 +47,7 @@
 #include "dnd.h"
 #include "icons.h"
 
+#include "webview.h"
+
 #endif	/* UI_H */
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ui/ui/webview.h	Sun Feb 09 20:21:52 2025 +0100
@@ -0,0 +1,65 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2025 Olaf Wintermann. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef UI_WEBVIEW_H
+#define UI_WEBVIEW_H
+
+#include "toolkit.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+    
+typedef struct UiWebviewArgs {
+    UiTri fill;
+    UiBool hexpand;
+    UiBool vexpand;
+    UiBool hfill;
+    UiBool vfill;
+    int colspan;
+    int rowspan;
+    const char *name;
+    const char *style_class;
+    
+    const int* groups;
+} UiWebviewArgs;
+
+#define ui_webview(obj, ...) ui_webview_create(obj, (UiWebviewArgs){ __VA_ARGS__ } )
+
+UIWIDGET ui_webview_create(UiObject *obj, UiWebviewArgs args);
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* UI_WEBVIEW_H */
+

mercurial