--- /dev/null
+/*
+ * 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 "gtk-image.h"
+
+
+#if GTK_MAJOR_VERSION >= 4
+
+GtkWidget* embedded_image_create(GdkPixbuf *pix) {
+ GdkTexture *texture = gdk_texture_new_for_pixbuf(pixbuf);
+ GtkWidget *image = gtk_image_new_from_paintable(GDK_PAINTABLE(texture));
+
+ int width = gdk_texture_get_width(texture);
+ int height = gdk_texture_get_height(texture);
+ gtk_widget_set_size_request(image, width, height);
+
+ return image;
+}
+
+#else
+
+GtkWidget* embedded_image_create(GdkPixbuf *pix) {
+ GtkWidget *image = gtk_image_new_from_pixbuf(pix);
+
+ int width = gdk_pixbuf_get_width(pix);
+ int height = gdk_pixbuf_get_height(pix);
+ gtk_widget_set_size_request(image, width, height);
+
+ return image;
+}
+
+
+#endif
\ No newline at end of file
--- /dev/null
+/*
+ * 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 GTK_IMAGE_H
+#define GTK_IMAGE_H
+
+#include "application.h"
+#include "note.h"
+#include "attachment.h"
+
+GtkWidget* embedded_image_create(GdkPixbuf *pix);
+
+#endif /* GTK_IMAGE_H */
+
*/
#include "gtk-text.h"
+#include "gtk-image.h"
#include "editor.h"
#include "note.h"
#include "attachment.h"
gtk_text_buffer_get_iter_at_mark(buffer, &iter, cursor);
GtkTextChildAnchor *anchor = gtk_text_buffer_create_child_anchor(buffer, &iter);
- GdkTexture *texture = gdk_texture_new_for_pixbuf(pixbuf);
- GtkWidget *image = gtk_image_new_from_paintable(GDK_PAINTABLE(texture));
-
- int width = gdk_texture_get_width(texture);
- int height = gdk_texture_get_height(texture);
- gtk_widget_set_size_request(image, width, height);
-
+ GtkWidget *image = embedded_image_create(pixbuf);
gtk_text_view_add_child_at_anchor(textview, image, anchor);
// remember widget and store a reference in the textbuffer
TOOLKIT = gtk
GTKOBJ = draw_cairo.o
APP_PLATFORM_SRC = gtk-text.c
+APP_PLATFORM_SRC += gtk-image.c
__EOF__
return 0
}
GTKOBJ = draw_cairo.o
GTKOBJ = draw_cairo.o
APP_PLATFORM_SRC = gtk-text.c
+APP_PLATFORM_SRC += gtk-image.c
__EOF__
return 0
}
<make>TOOLKIT = gtk</make>
<make>GTKOBJ = draw_cairo.o</make>
<make>APP_PLATFORM_SRC = gtk-text.c</make>
+ <make>APP_PLATFORM_SRC += gtk-image.c</make>
</value>
<value str="gtk3">
<dependencies>gtk3,webkit2gtk4</dependencies>
<make>GTKOBJ = draw_cairo.o</make>
<make>GTKOBJ = draw_cairo.o</make>
<make>APP_PLATFORM_SRC = gtk-text.c</make>
+ <make>APP_PLATFORM_SRC += gtk-image.c</make>
</value>
<value str="cocoa">
<dependencies>cocoa</dependencies>