Sort headers using clang-tidy
[geeqie.git] / src / view-file / view-file-icon.cc
index b2a97cb..ae27a33 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "main.h"
 #include "view-file-icon.h"
 
+#include <config.h>
+
 #include "cellrenderericon.h"
 #include "collect.h"
+#include "compat.h"
+#include "debug.h"
 #include "dnd.h"
 #include "img-view.h"
+#include "intl.h"
 #include "layout-image.h"
+#include "main-defines.h"
 #include "metadata.h"
 #include "misc.h"
-#include "utilops.h"
+#include "options.h"
 #include "ui-fileops.h"
 #include "ui-misc.h"
 #include "ui-tree-edit.h"
 #include "uri-utils.h"
+#include "utilops.h"
 #include "view-file.h"
 
 /* between these, the icon width is increased by thumb_max_width / 2 */
-#define THUMB_MIN_ICON_WIDTH 128
-#define THUMB_MAX_ICON_WIDTH 160
+enum {
+       THUMB_MIN_ICON_WIDTH = 128,
+       THUMB_MAX_ICON_WIDTH = 160
+};
 #define THUMB_MIN_ICON_WIDTH_WITH_MARKS TOGGLE_SPACING * FILEDATA_MARKS_SIZE
 
-#define VFICON_MAX_COLUMNS 32
-#define THUMB_BORDER_PADDING 2
+enum {
+       VFICON_MAX_COLUMNS = 32,
+       THUMB_BORDER_PADDING = 2
+};
 
-#define VFICON_TIP_DELAY 500
+enum {
+       VFICON_TIP_DELAY = 500
+};
 
 enum {
        FILE_COLUMN_POINTER = 0,
@@ -232,7 +244,8 @@ static gboolean vficon_find_position(ViewFile *vf, FileData *fd, gint *row, gint
 static gboolean vficon_find_iter(ViewFile *vf, FileData *fd, GtkTreeIter *iter, gint *column)
 {
        GtkTreeModel *store;
-       gint row, col;
+       gint row;
+       gint col;
 
        store = gtk_tree_view_get_model(GTK_TREE_VIEW(vf->listview));
        if (!vficon_find_position(vf, fd, &row, &col)) return FALSE;
@@ -331,7 +344,8 @@ static void vficon_mark_toggled_cb(GtkCellRendererToggle *cell, gchar *path_str,
 static void tip_show(ViewFile *vf)
 {
        GtkWidget *label;
-       gint x, y;
+       gint x;
+       gint y;
        GdkDisplay *display;
        GdkSeat *seat;
        GdkDevice *device;
@@ -353,7 +367,7 @@ static void tip_show(ViewFile *vf)
        label = gtk_label_new(VFICON(vf)->tip_fd->name);
 
        g_object_set_data(G_OBJECT(VFICON(vf)->tip_window), "tip_label", label);
-       gtk_container_add(GTK_CONTAINER(VFICON(vf)->tip_window), label);
+       gq_gtk_container_add(GTK_WIDGET(VFICON(vf)->tip_window), label);
        gtk_widget_show(label);
 
        display = gdk_display_get_default();
@@ -362,13 +376,13 @@ static void tip_show(ViewFile *vf)
        gdk_device_get_position(device, nullptr, &x, &y);
 
        if (!gtk_widget_get_realized(VFICON(vf)->tip_window)) gtk_widget_realize(VFICON(vf)->tip_window);
-       gtk_window_move(GTK_WINDOW(VFICON(vf)->tip_window), x + 16, y + 16);
+       gq_gtk_window_move(GTK_WINDOW(VFICON(vf)->tip_window), x + 16, y + 16);
        gtk_widget_show(VFICON(vf)->tip_window);
 }
 
 static void tip_hide(ViewFile *vf)
 {
-       if (VFICON(vf)->tip_window) gtk_widget_destroy(VFICON(vf)->tip_window);
+       if (VFICON(vf)->tip_window) g_object_unref(VFICON(vf)->tip_window);
        VFICON(vf)->tip_window = nullptr;
 }
 
@@ -426,11 +440,12 @@ static void tip_update(ViewFile *vf, FileData *fd)
 
        if (VFICON(vf)->tip_window)
                {
-               gint x, y;
+               gint x;
+               gint y;
 
                gdk_device_get_position(device, nullptr, &x, &y);
 
-               gtk_window_move(GTK_WINDOW(VFICON(vf)->tip_window), x + 16, y + 16);
+               gq_gtk_window_move(GTK_WINDOW(VFICON(vf)->tip_window), x + 16, y + 16);
 
                if (fd != VFICON(vf)->tip_fd)
                        {
@@ -743,10 +758,13 @@ static void vficon_select_util(ViewFile *vf, FileData *fd, gboolean select)
 
 static void vficon_select_region_util(ViewFile *vf, FileData *start, FileData *end, gboolean select)
 {
-       gint row1, col1;
-       gint row2, col2;
+       gint row1;
+       gint col1;
+       gint row2;
+       gint col2;
        gint t;
-       gint i, j;
+       gint i;
+       gint j;
 
        if (!vficon_find_position(vf, start, &row1, &col1) ||
            !vficon_find_position(vf, end, &row2, &col2) ) return;
@@ -808,7 +826,7 @@ static void vficon_select_region_util(ViewFile *vf, FileData *start, FileData *e
 #pragma GCC diagnostic ignored "-Wunused-function"
 gboolean vficon_index_is_selected_unused(ViewFile *vf, gint row)
 {
-       FileData *fd = static_cast<FileData *>(g_list_nth_data(vf->list, row));
+       auto *fd = static_cast<FileData *>(g_list_nth_data(vf->list, row));
 
        if (!fd) return FALSE;
 
@@ -842,29 +860,16 @@ guint vficon_selection_count(ViewFile *vf, gint64 *bytes)
 GList *vficon_selection_get_list(ViewFile *vf)
 {
        GList *list = nullptr;
-       GList *work, *work2;
 
-       work = VFICON(vf)->selection;
-       while (work)
+       for (GList *work = g_list_last(VFICON(vf)->selection); work; work = work->prev)
                {
                auto fd = static_cast<FileData *>(work->data);
                g_assert(fd->magick == FD_MAGICK);
 
+               list = g_list_concat(filelist_copy(fd->sidecar_files), list);
                list = g_list_prepend(list, file_data_ref(fd));
-
-               work2 = fd->sidecar_files;
-               while (work2)
-                       {
-                       fd = static_cast<FileData *>(work2->data);
-                       list = g_list_prepend(list, file_data_ref(fd));
-                       work2 = work2->next;
-                       }
-
-               work = work->next;
                }
 
-       list = g_list_reverse(list);
-
        return list;
 }
 
@@ -928,7 +933,8 @@ void vficon_mark_to_selection(ViewFile *vf, gint mark, MarkToSelectionMode mode)
        while (work)
                {
                auto fd = static_cast<FileData *>(work->data);
-               gboolean mark_val, selected;
+               gboolean mark_val;
+               gboolean selected;
 
                g_assert(fd->magick == FD_MAGICK);
 
@@ -1101,7 +1107,8 @@ static void vficon_move_focus(ViewFile *vf, gint row, gint col, gboolean relativ
 static void vficon_set_focus(ViewFile *vf, FileData *fd)
 {
        GtkTreeIter iter;
-       gint row, col;
+       gint row;
+       gint col;
 
        if (g_list_find(vf->list, VFICON(vf)->focus_fd))
                {
@@ -1333,36 +1340,39 @@ gboolean vficon_press_cb(GtkWidget *, GdkEventButton *bevent, gpointer data)
 
        fd = vficon_find_data_by_coord(vf, static_cast<gint>(bevent->x), static_cast<gint>(bevent->y), &iter);
 
-       VFICON(vf)->click_fd = fd;
-       vficon_selection_add(vf, VFICON(vf)->click_fd, SELECTION_PRELIGHT, &iter);
-
-       switch (bevent->button)
+       if (fd)
                {
-               case MOUSE_BUTTON_LEFT:
-                       if (!gtk_widget_has_focus(vf->listview))
-                               {
-                               gtk_widget_grab_focus(vf->listview);
-                               }
+               VFICON(vf)->click_fd = fd;
+               vficon_selection_add(vf, VFICON(vf)->click_fd, SELECTION_PRELIGHT, &iter);
 
-                       if (bevent->type == GDK_2BUTTON_PRESS && vf->layout)
-                               {
-                               if (VFICON(vf)->click_fd->format_class == FORMAT_CLASS_COLLECTION)
+               switch (bevent->button)
+                       {
+                       case MOUSE_BUTTON_LEFT:
+                               if (!gtk_widget_has_focus(vf->listview))
                                        {
-                                       collection_window_new(VFICON(vf)->click_fd->path);
+                                       gtk_widget_grab_focus(vf->listview);
                                        }
-                               else
+
+                               if (bevent->type == GDK_2BUTTON_PRESS && vf->layout)
                                        {
-                                       vficon_selection_remove(vf, VFICON(vf)->click_fd, SELECTION_PRELIGHT, &iter);
-                                       layout_image_full_screen_start(vf->layout);
+                                       if (VFICON(vf)->click_fd->format_class == FORMAT_CLASS_COLLECTION)
+                                               {
+                                               collection_window_new(VFICON(vf)->click_fd->path);
+                                               }
+                                       else
+                                               {
+                                               vficon_selection_remove(vf, VFICON(vf)->click_fd, SELECTION_PRELIGHT, &iter);
+                                               layout_image_full_screen_start(vf->layout);
+                                               }
                                        }
-                               }
-                       break;
-               case MOUSE_BUTTON_RIGHT:
-                       vf->popup = vf_pop_menu(vf);
-                       gtk_menu_popup_at_pointer(GTK_MENU(vf->popup), nullptr);
-                       break;
-               default:
-                       break;
+                               break;
+                       case MOUSE_BUTTON_RIGHT:
+                               vf->popup = vf_pop_menu(vf);
+                               gtk_menu_popup_at_pointer(GTK_MENU(vf->popup), nullptr);
+                               break;
+                       default:
+                               break;
+                       }
                }
 
        return FALSE;
@@ -1508,7 +1518,8 @@ static void vficon_populate(ViewFile *vf, gboolean resize, gboolean keep_positio
        GtkTreePath *tpath;
        GList *work;
        FileData *visible_fd = nullptr;
-       gint r, c;
+       gint r;
+       gint c;
        gboolean valid;
        GtkTreeIter iter;
 
@@ -1896,7 +1907,8 @@ gint vficon_index_by_fd(ViewFile *vf, FileData *in_fd)
 static gboolean vficon_refresh_real(ViewFile *vf, gboolean keep_position)
 {
        gboolean ret = TRUE;
-       GList *work, *new_work;
+       GList *work;
+       GList *new_work;
        FileData *first_selected = nullptr;
        GList *new_filelist = nullptr;
        GList *new_fd_list = nullptr;
@@ -2070,11 +2082,11 @@ struct ColumnData
 static void vficon_cell_data_cb(GtkTreeViewColumn *, GtkCellRenderer *cell,
                                GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
 {
-       GList *list;
-       FileData *fd;
        auto cd = static_cast<ColumnData *>(data);
-       ViewFile *vf = cd->vf;
+       FileData *fd;
        gchar *star_rating;
+       GList *list;
+       ViewFile *vf = cd->vf;
 
        if (!GQV_IS_CELL_RENDERER_ICON(cell)) return;
 
@@ -2084,12 +2096,14 @@ static void vficon_cell_data_cb(GtkTreeViewColumn *, GtkCellRenderer *cell,
 
        if (fd)
                {
-               GdkColor color_fg;
-               GdkColor color_bg;
-               GtkStyle *style;
-               gchar *name_sidecars = nullptr;
                const gchar *link;
+               gchar *name_sidecars = nullptr;
+               GdkRGBA color_bg;
+               GdkRGBA color_fg;
+               GdkRGBA color_bg_style;
+               GdkRGBA color_fg_style;
                GtkStateType state = GTK_STATE_NORMAL;
+               GtkStyle *style;
 
                g_assert(fd->magick == FD_MAGICK);
 
@@ -2144,21 +2158,24 @@ static void vficon_cell_data_cb(GtkTreeViewColumn *, GtkCellRenderer *cell,
                        state = GTK_STATE_SELECTED;
                        }
 
-               memcpy(&color_fg, &style->text[state], sizeof(color_fg));
-               memcpy(&color_bg, &style->base[state], sizeof(color_bg));
+               convert_gdkcolor_to_gdkrgba(&style->text[state], &color_fg_style);
+               convert_gdkcolor_to_gdkrgba(&style->base[state], &color_bg_style);
+
+               memcpy(&color_fg, &color_fg_style, sizeof(color_fg));
+               memcpy(&color_bg, &color_bg_style, sizeof(color_bg));
 
                if (fd->selected & SELECTION_PRELIGHT)
                        {
                        shift_color(&color_bg, -1, 0);
                        }
 
-               g_object_set(cell,      "pixbuf", fd->thumb_pixbuf,
+               g_object_set(cell, "pixbuf", fd->thumb_pixbuf,
                                        "text", name_sidecars,
                                        "marks", file_data_get_marks(fd),
                                        "show_marks", vf->marks_enabled,
-                                       "cell-background-gdk", &color_bg,
+                                       "cell-background-rgba", &color_bg,
                                        "cell-background-set", TRUE,
-                                       "foreground-gdk", &color_fg,
+                                       "foreground-rgba", &color_fg,
                                        "foreground-set", TRUE,
                                        "has-focus", (VFICON(vf)->focus_fd == fd), NULL);
                g_free(name_sidecars);