Sort headers using clang-tidy
[geeqie.git] / src / image.cc
index cebb38b..5cd517b 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "main.h"
 #include "image.h"
 
+#include <config.h>
+
 #include "collect-table.h"
 #include "color-man.h"
+#include "compat.h"
+#include "debug.h"
 #include "exif.h"
-#include "metadata.h"
+#include "filecache.h"
 #include "history-list.h"
 #include "image-load.h"
-#include "layout.h"
+#include "intl.h"
 #include "layout-image.h"
+#include "layout.h"
+#include "metadata.h"
 #include "pixbuf-renderer.h"
 #include "pixbuf-util.h"
 #include "ui-fileops.h"
-#include "filecache.h"
+#include "ui-misc.h"
 
-#include <math.h>
+#include <cmath>
 
 static GList *image_list = nullptr;
 
-void image_update_title(ImageWindow *imd);
 static void image_read_ahead_start(ImageWindow *imd);
 static void image_cache_set(ImageWindow *imd, FileData *fd);
 
@@ -57,7 +61,7 @@ static gint rect_id = 0;
  *-------------------------------------------------------------------
  */
 
-static void image_click_cb(PixbufRenderer *UNUSED(pr), GdkEventButton *event, gpointer data)
+static void image_click_cb(PixbufRenderer *, GdkEventButton *event, gpointer data)
 {
        auto imd = static_cast<ImageWindow *>(data);
        if (!options->image_lm_click_nav && event->button == MOUSE_BUTTON_MIDDLE)
@@ -141,7 +145,8 @@ static void image_press_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer d
 {
        auto imd = static_cast<ImageWindow *>(data);
        LayoutWindow *lw;
-       gint x_pixel, y_pixel;
+       gint x_pixel;
+       gint y_pixel;
 
        if(options->draw_rectangle)
                {
@@ -187,15 +192,32 @@ static void image_press_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer d
                }
 }
 
+static void image_release_cb(PixbufRenderer *, GdkEventButton *event, gpointer data)
+{
+       auto imd = static_cast<ImageWindow *>(data);
+       LayoutWindow *lw;
+
+       lw = layout_find_by_image(imd);
+       if (!lw)
+               {
+               layout_valid(&lw);
+               }
+
+       defined_mouse_buttons(nullptr, event, lw);
+}
+
 static void image_drag_cb(PixbufRenderer *pr, GdkEventMotion *event, gpointer data)
 {
        auto imd = static_cast<ImageWindow *>(data);
-       gint width, height;
+       gint width;
+       gint height;
        gint rect_width;
        gint rect_height;
        GdkPixbuf *rect_pixbuf;
-       gint x_pixel, y_pixel;
-       gint image_x_pixel, image_y_pixel;
+       gint x_pixel;
+       gint y_pixel;
+       gint image_x_pixel;
+       gint image_y_pixel;
 
        if (options->draw_rectangle)
                {
@@ -290,7 +312,7 @@ static void image_complete_util(ImageWindow *imd, gboolean preload)
        if (imd->func_complete) imd->func_complete(imd, preload, imd->data_complete);
 }
 
-static void image_render_complete_cb(PixbufRenderer *UNUSED(pr), gpointer data)
+static void image_render_complete_cb(PixbufRenderer *, gpointer data)
 {
        auto imd = static_cast<ImageWindow *>(data);
 
@@ -316,7 +338,7 @@ static void image_state_unset(ImageWindow *imd, ImageState state)
        if (imd->func_state) imd->func_state(imd, state, imd->data_state);
 }
 
-static void image_zoom_cb(PixbufRenderer *UNUSED(pr), gdouble UNUSED(zoom), gpointer data)
+static void image_zoom_cb(PixbufRenderer *, gdouble, gpointer data)
 {
        auto imd = static_cast<ImageWindow *>(data);
 
@@ -567,7 +589,7 @@ static gboolean image_post_process_color(ImageWindow *imd, gint start_row, gbool
 }
 
 
-static void image_post_process_tile_color_cb(PixbufRenderer *UNUSED(pr), GdkPixbuf **pixbuf, gint x, gint y, gint w, gint h, gpointer data)
+static void image_post_process_tile_color_cb(PixbufRenderer *, GdkPixbuf **pixbuf, gint x, gint y, gint w, gint h, gpointer data)
 {
        auto imd = static_cast<ImageWindow *>(data);
        if (imd->cm) color_man_correct_region(static_cast<ColorMan *>(imd->cm), *pixbuf, x, y, w, h);
@@ -674,7 +696,7 @@ void image_alter_orientation(ImageWindow *imd, FileData *fd_n, AlterType type)
                        }
                }
 
-       if (imd->image_fd == fd_n && !(options->metadata.write_orientation && !options->image.exif_rotate_enable))
+       if (imd->image_fd == fd_n && (!options->metadata.write_orientation || options->image.exif_rotate_enable))
                {
                imd->orientation = orientation;
                pixbuf_renderer_set_orientation(reinterpret_cast<PixbufRenderer *>(imd->pr), orientation);
@@ -706,11 +728,6 @@ void image_set_overunderexposed(ImageWindow *imd, gboolean overunderexposed)
        pixbuf_renderer_set_orientation(reinterpret_cast<PixbufRenderer *>(imd->pr), imd->orientation);
 }
 
-gboolean image_get_overunderexposed(ImageWindow *imd)
-{
-       return imd->overunderexposed;
-}
-
 void image_set_ignore_alpha(ImageWindow *imd, gboolean ignore_alpha)
 {
    pixbuf_renderer_set_ignore_alpha(reinterpret_cast<PixbufRenderer *>(imd->pr), ignore_alpha);
@@ -733,7 +750,7 @@ static void image_read_ahead_cancel(ImageWindow *imd)
        imd->read_ahead_fd = nullptr;
 }
 
-static void image_read_ahead_done_cb(ImageLoader *UNUSED(il), gpointer data)
+static void image_read_ahead_done_cb(ImageLoader *, gpointer data)
 {
        auto imd = static_cast<ImageWindow *>(data);
 
@@ -811,7 +828,7 @@ static void image_cache_release_cb(FileData *fd)
        fd->pixbuf = nullptr;
 }
 
-static FileCacheData *image_get_cache(void)
+static FileCacheData *image_get_cache()
 {
        static FileCacheData *cache = nullptr;
        if (!cache) cache = file_cache_new(image_cache_release_cb, 1);
@@ -819,7 +836,7 @@ static FileCacheData *image_get_cache(void)
        return cache;
 }
 
-static void image_cache_set(ImageWindow *UNUSED(imd), FileData *fd)
+static void image_cache_set(ImageWindow *, FileData *fd)
 {
        g_assert(fd->pixbuf);
 
@@ -838,7 +855,6 @@ static gint image_cache_get(ImageWindow *imd)
                image_change_pixbuf(imd, imd->image_fd->pixbuf, image_zoom_get(imd), FALSE);
                }
 
-//     file_cache_dump(image_get_cache());
        return success;
 }
 
@@ -873,7 +889,7 @@ static void image_load_area_cb(ImageLoader *il, guint x, guint y, guint w, guint
        pixbuf_renderer_area_changed(pr, x, y, w, h);
 }
 
-static void image_load_done_cb(ImageLoader *UNUSED(il), gpointer data)
+static void image_load_done_cb(ImageLoader *, gpointer data)
 {
        auto imd = static_cast<ImageWindow *>(data);
 
@@ -890,31 +906,7 @@ static void image_load_done_cb(ImageLoader *UNUSED(il), gpointer data)
 
        if (!image_loader_get_pixbuf(imd->il))
                {
-               GdkPixbuf *pixbuf;
-
-               switch (imd->image_fd->format_class)
-                       {
-                       case FORMAT_CLASS_UNKNOWN:
-                               pixbuf = pixbuf_inline(PIXBUF_INLINE_UNKNOWN);
-                               break;
-                       case FORMAT_CLASS_META:
-                               pixbuf = pixbuf_inline(PIXBUF_INLINE_METADATA);
-                               break;
-                       case FORMAT_CLASS_VIDEO:
-                               pixbuf = pixbuf_inline(PIXBUF_INLINE_VIDEO);
-                               break;
-                       case FORMAT_CLASS_COLLECTION:
-                               pixbuf = pixbuf_inline(PIXBUF_INLINE_COLLECTION);
-                               break;
-                       case FORMAT_CLASS_DOCUMENT:
-                               pixbuf = pixbuf_inline(PIXBUF_INLINE_ICON_PDF);
-                               break;
-                       case FORMAT_CLASS_ARCHIVE:
-                               pixbuf = pixbuf_inline(PIXBUF_INLINE_ARCHIVE);
-                               break;
-                       default:
-                               pixbuf = pixbuf_inline(PIXBUF_INLINE_BROKEN);
-                       }
+               GdkPixbuf *pixbuf = pixbuf_fallback(imd->image_fd, 0, 0);
 
                image_change_pixbuf(imd, pixbuf, image_zoom_get(imd), FALSE);
                g_object_unref(pixbuf);
@@ -931,12 +923,10 @@ static void image_load_done_cb(ImageLoader *UNUSED(il), gpointer data)
        image_loader_free(imd->il);
        imd->il = nullptr;
 
-//     image_post_process(imd, TRUE);
-
        image_read_ahead_start(imd);
 }
 
-static void image_load_size_cb(ImageLoader *UNUSED(il), guint width, guint height, gpointer data)
+static void image_load_size_cb(ImageLoader *, guint width, guint height, gpointer data)
 {
        auto imd = static_cast<ImageWindow *>(data);
 
@@ -1003,14 +993,13 @@ static gboolean image_read_ahead_check(ImageWindow *imd)
                imd->read_ahead_fd = nullptr;
                return TRUE;
                }
-       else if (imd->read_ahead_fd->pixbuf)
+       if (imd->read_ahead_fd->pixbuf)
                {
                image_change_pixbuf(imd, imd->read_ahead_fd->pixbuf, image_zoom_get(imd), FALSE);
 
                file_data_unref(imd->read_ahead_fd);
                imd->read_ahead_fd = nullptr;
 
-//             image_post_process(imd, FALSE);
                return TRUE;
                }
 
@@ -1184,7 +1173,7 @@ static void image_change_real(ImageWindow *imd, FileData *fd,
  *-------------------------------------------------------------------
  */
 
-static gboolean image_focus_in_cb(GtkWidget *UNUSED(widget), GdkEventFocus *UNUSED(event), gpointer data)
+static gboolean image_focus_in_cb(GtkWidget *, GdkEventFocus *, gpointer data)
 {
        auto imd = static_cast<ImageWindow *>(data);
 
@@ -1196,7 +1185,7 @@ static gboolean image_focus_in_cb(GtkWidget *UNUSED(widget), GdkEventFocus *UNUS
        return TRUE;
 }
 
-static gboolean image_scroll_cb(GtkWidget *UNUSED(widget), GdkEventScroll *event, gpointer data)
+static gboolean image_scroll_cb(GtkWidget *, GdkEventScroll *event, gpointer data)
 {
        auto imd = static_cast<ImageWindow *>(data);
        gboolean in_lw = FALSE;
@@ -1235,11 +1224,9 @@ static gboolean image_scroll_cb(GtkWidget *UNUSED(widget), GdkEventScroll *event
                                }
                        return TRUE;
                        }
-               else
-                       {
-                       imd->func_scroll(imd, event, imd->data_scroll);
-                       return TRUE;
-                       }
+
+               imd->func_scroll(imd, event, imd->data_scroll);
+               return TRUE;
                }
 
        return FALSE;
@@ -1321,13 +1308,16 @@ void image_set_scroll_func(ImageWindow *imd,
        imd->data_scroll = data;
 }
 
-//void image_set_scroll_notify_func(ImageWindow *imd,
-                                 //void (*func)(ImageWindow *imd, gint x, gint y, gint width, gint height, gpointer data),
-                                 //gpointer data)
-//{
-       //imd->func_scroll_notify = func;
-       //imd->data_scroll_notify = data;
-//}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+void image_set_scroll_notify_func_unused(ImageWindow *imd,
+                                 void (*func)(ImageWindow *imd, gint x, gint y, gint width, gint height, gpointer data),
+                                 gpointer data)
+{
+       imd->func_scroll_notify = func;
+       imd->data_scroll_notify = data;
+}
+#pragma GCC diagnostic pop
 
 void image_set_focus_in_func(ImageWindow *imd,
                           void (*func)(ImageWindow *, gpointer),
@@ -1710,7 +1700,8 @@ void image_zoom_set_fill_geometry(ImageWindow *imd, gboolean vertical)
 {
        PixbufRenderer *pr;
        gdouble zoom;
-       gint width, height;
+       gint width;
+       gint height;
 
        pr = reinterpret_cast<PixbufRenderer *>(imd->pr);
 
@@ -1804,10 +1795,14 @@ gdouble image_zoom_get_default(ImageWindow *imd)
 }
 
 /* stereo */
-//gint image_stereo_get(ImageWindow *imd)
-//{
-       //return pixbuf_renderer_stereo_get((PixbufRenderer *)imd->pr);
-//}
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+gint image_stereo_get_unused(ImageWindow *imd)
+{
+       return pixbuf_renderer_stereo_get((PixbufRenderer *)imd->pr);
+}
+#pragma GCC diagnostic pop
 
 void image_stereo_set(ImageWindow *imd, gint stereo_mode)
 {
@@ -1815,12 +1810,15 @@ void image_stereo_set(ImageWindow *imd, gint stereo_mode)
        pixbuf_renderer_stereo_set(reinterpret_cast<PixbufRenderer *>(imd->pr), stereo_mode);
 }
 
-//void image_stereo_swap(ImageWindow *imd)
-//{
-       //gint stereo_mode = pixbuf_renderer_stereo_get((PixbufRenderer *)imd->pr);
-       //stereo_mode ^= PR_STEREO_SWAP;
-       //pixbuf_renderer_stereo_set((PixbufRenderer *)imd->pr, stereo_mode);
-//}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+void image_stereo_swap_unused(ImageWindow *imd)
+{
+       gint stereo_mode = pixbuf_renderer_stereo_get((PixbufRenderer *)imd->pr);
+       stereo_mode ^= PR_STEREO_SWAP;
+       pixbuf_renderer_stereo_set((PixbufRenderer *)imd->pr, stereo_mode);
+}
+#pragma GCC diagnostic pop
 
 StereoPixbufData image_stereo_pixbuf_get(ImageWindow *imd)
 {
@@ -1891,15 +1889,15 @@ void image_top_window_set_sync(ImageWindow *imd, gboolean allow_sync)
        g_object_set(G_OBJECT(imd->pr), "window_fit", allow_sync, NULL);
 }
 
-void image_background_set_color(ImageWindow *imd, GdkColor *color)
+void image_background_set_color(ImageWindow *imd, GdkRGBA *color)
 {
        pixbuf_renderer_set_color(reinterpret_cast<PixbufRenderer *>(imd->pr), color);
 }
 
 void image_background_set_color_from_options(ImageWindow *imd, gboolean fullscreen)
 {
-       GdkColor *color = nullptr;
-       GdkColor theme_color;
+       GdkRGBA *color = nullptr;
+       GdkRGBA theme_color;
        GdkRGBA bg_color;
        GtkStyleContext *style_context;
        LayoutWindow *lw = nullptr;
@@ -1917,9 +1915,9 @@ void image_background_set_color_from_options(ImageWindow *imd, gboolean fullscre
                style_context = gtk_widget_get_style_context(lw->window);
                gtk_style_context_get_background_color(style_context, GTK_STATE_FLAG_NORMAL, &bg_color);
 
-               theme_color.red = bg_color.red * 65535;
-               theme_color.green = bg_color.green * 65535;
-               theme_color.blue = bg_color.blue * 65535;
+               theme_color.red = bg_color.red * 1;
+               theme_color.green = bg_color.green * 1;
+               theme_color.blue = bg_color.blue * 1;
 
                color = &theme_color;
                }
@@ -2002,7 +2000,7 @@ void image_set_delay_flip(ImageWindow *imd, gboolean delay)
                }
 }
 
-void image_to_root_window(ImageWindow *UNUSED(imd), gboolean UNUSED(scaled))
+void image_to_root_window(ImageWindow *, gboolean)
 {
 }
 
@@ -2023,7 +2021,7 @@ void image_set_selectable(ImageWindow *imd, gboolean selectable)
 {
        if (!imd->has_frame) return;
 
-       gtk_frame_set_shadow_type(GTK_FRAME(imd->frame), GTK_SHADOW_NONE);
+       gq_gtk_frame_set_shadow_type(GTK_FRAME(imd->frame), GTK_SHADOW_NONE);
        gtk_container_set_border_width(GTK_CONTAINER(imd->frame), selectable ? 4 : 0);
 }
 
@@ -2071,7 +2069,7 @@ static void image_options_set(ImageWindow *imd)
                                        options->stereo.fixed_x2, options->stereo.fixed_y2);
 }
 
-void image_options_sync(void)
+void image_options_sync()
 {
        GList *work;
 
@@ -2112,38 +2110,27 @@ static void image_free(ImageWindow *imd)
        g_free(imd);
 }
 
-static void image_destroy_cb(GtkWidget *UNUSED(widget), gpointer data)
+static void image_destroy_cb(GtkWidget *, gpointer data)
 {
        auto imd = static_cast<ImageWindow *>(data);
        image_free(imd);
 }
 
-gboolean selectable_frame_draw_cb(GtkWidget *widget, cairo_t *cr, gpointer UNUSED(data))
+gboolean selectable_frame_draw_cb(GtkWidget *widget, cairo_t *cr, gpointer)
 {
        GtkAllocation allocation;
        gtk_widget_get_allocation(widget, &allocation);
-       gtk_paint_flat_box(gtk_widget_get_style(widget),
-                          cr,
-                          gtk_widget_get_state(widget),
-                          gtk_frame_get_shadow_type(GTK_FRAME(widget)),
-                          widget,
-                          nullptr,
-                          allocation.x + 3, allocation.y + 3,
-                          allocation.width - 6, allocation.height - 6);
+
+       gtk_render_frame(gtk_widget_get_style_context(widget), cr, allocation.x + 3, allocation.y + 3, allocation.width - 6, allocation.height - 6);
+       gtk_render_background(gtk_widget_get_style_context(widget), cr, allocation.x + 3, allocation.y + 3, allocation.width - 6, allocation.height - 6);
 
        if (gtk_widget_has_focus(widget))
                {
-               gtk_paint_focus(gtk_widget_get_style(widget), cr, GTK_STATE_ACTIVE,
-                               widget, "image_window",
-                               allocation.x, allocation.y,
-                               allocation.width - 1, allocation.height - 1);
+               gtk_render_focus(gtk_widget_get_style_context(widget), cr, allocation.x, allocation.y, allocation.width - 1, allocation.height - 1);
                }
        else
                {
-               gtk_paint_shadow(gtk_widget_get_style(widget), cr, GTK_STATE_NORMAL, GTK_SHADOW_IN,
-                                widget, "image_window",
-                                allocation.x, allocation.y,
-                                allocation.width - 1, allocation.height - 1);
+               gtk_render_frame(gtk_widget_get_style_context(widget), cr, allocation.x, allocation.y, allocation.width - 1, allocation.height - 1);
                }
        return FALSE;
 }
@@ -2162,7 +2149,7 @@ void image_set_frame(ImageWindow *imd, gboolean frame)
                DEBUG_NAME(imd->frame);
                g_object_ref(imd->pr);
                if (imd->has_frame != -1) gtk_container_remove(GTK_CONTAINER(imd->widget), imd->pr);
-               gtk_container_add(GTK_CONTAINER(imd->frame), imd->pr);
+               gq_gtk_container_add(GTK_WIDGET(imd->frame), imd->pr);
 
                g_object_unref(imd->pr);
                gtk_widget_set_can_focus(imd->frame, TRUE);
@@ -2173,7 +2160,7 @@ void image_set_frame(ImageWindow *imd, gboolean frame)
                g_signal_connect(G_OBJECT(imd->frame), "focus_in_event",
                                 G_CALLBACK(image_focus_in_cb), imd);
 
-               gtk_box_pack_start(GTK_BOX(imd->widget), imd->frame, TRUE, TRUE, 0);
+               gq_gtk_box_pack_start(GTK_BOX(imd->widget), imd->frame, TRUE, TRUE, 0);
                gtk_widget_show(imd->frame);
                }
        else
@@ -2182,10 +2169,10 @@ void image_set_frame(ImageWindow *imd, gboolean frame)
                if (imd->frame)
                        {
                        gtk_container_remove(GTK_CONTAINER(imd->frame), imd->pr);
-                       gtk_widget_destroy(imd->frame);
+                       g_object_unref(imd->frame);
                        imd->frame = nullptr;
                        }
-               gtk_box_pack_start(GTK_BOX(imd->widget), imd->pr, TRUE, TRUE, 0);
+               gq_gtk_box_pack_start(GTK_BOX(imd->widget), imd->pr, TRUE, TRUE, 0);
 
                g_object_unref(imd->pr);
                }
@@ -2224,6 +2211,8 @@ ImageWindow *image_new(gboolean frame)
                         G_CALLBACK(image_click_cb), imd);
        g_signal_connect(G_OBJECT(imd->pr), "button_press_event",
                         G_CALLBACK(image_press_cb), imd);
+       g_signal_connect(G_OBJECT(imd->pr), "button_release_event",
+                        G_CALLBACK(image_release_cb), imd);
        g_signal_connect(G_OBJECT(imd->pr), "scroll_notify",
                         G_CALLBACK(image_scroll_notify_cb), imd);