]> uap-core.de Git - note.git/commitdiff
move text embedded image creation to separate file
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 5 Apr 2025 19:10:24 +0000 (21:10 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 5 Apr 2025 19:10:24 +0000 (21:10 +0200)
application/gtk-image.c [new file with mode: 0644]
application/gtk-image.h [new file with mode: 0644]
application/gtk-text.c
configure
make/project.xml

diff --git a/application/gtk-image.c b/application/gtk-image.c
new file mode 100644 (file)
index 0000000..94cba30
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * 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
diff --git a/application/gtk-image.h b/application/gtk-image.h
new file mode 100644 (file)
index 0000000..af6cb07
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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 */
+
index 91d2c9e96c1ee548bb3777b3218bab572f63c031..43f755c81b85b907aa322c866ed68b188a142a26 100644 (file)
@@ -27,6 +27,7 @@
  */
 
 #include "gtk-text.h"
+#include "gtk-image.h"
 #include "editor.h"
 #include "note.h"
 #include "attachment.h"
@@ -289,13 +290,7 @@ static void editor_attach_image(NoteEditor *editor, GdkPixbuf *pixbuf, char *att
     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
index 32aae079595ae253f24cf0256b8409c18ea9cf37..3238d8cde7e1697d1faa8ed1b455abcc8915aed1 100755 (executable)
--- a/configure
+++ b/configure
@@ -967,6 +967,7 @@ checkopt_toolkit_gtk4()
 TOOLKIT = gtk
 GTKOBJ = draw_cairo.o
 APP_PLATFORM_SRC = gtk-text.c
+APP_PLATFORM_SRC += gtk-image.c
 __EOF__
     return 0
 }
@@ -987,6 +988,7 @@ TOOLKIT = gtk
 GTKOBJ = draw_cairo.o
 GTKOBJ = draw_cairo.o
 APP_PLATFORM_SRC = gtk-text.c
+APP_PLATFORM_SRC += gtk-image.c
 __EOF__
     return 0
 }
index 29773682eec796d3da9020f8ee193e20779f9945..0efbc908331db322711c082eeefab47b30ff02f1 100644 (file)
                                <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>