Use std::swap instead of temporary values
[geeqie.git] / src / view-file / view-file-icon.cc
index 8fc272f..fe7c180 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "main.h"
 #include "view-file-icon.h"
 
+#include <cstring>
+#include <utility>
+
+#include <glib-object.h>
+
 #include "cellrenderericon.h"
 #include "collect.h"
+#include "compat.h"
+#include "debug.h"
 #include "dnd.h"
+#include "filedata.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"
 
+namespace
+{
+
 /* between these, the icon width is increased by thumb_max_width / 2 */
-#define THUMB_MIN_ICON_WIDTH 128
-#define THUMB_MAX_ICON_WIDTH 160
-#define THUMB_MIN_ICON_WIDTH_WITH_MARKS TOGGLE_SPACING * FILEDATA_MARKS_SIZE
+constexpr gint THUMB_MIN_ICON_WIDTH = 128;
+constexpr gint THUMB_MAX_ICON_WIDTH = 160;
 
-#define VFICON_MAX_COLUMNS 32
-#define THUMB_BORDER_PADDING 2
+constexpr gint THUMB_MIN_ICON_WIDTH_WITH_MARKS = TOGGLE_SPACING * FILEDATA_MARKS_SIZE;
 
-#define VFICON_TIP_DELAY 500
+constexpr gint VFICON_MAX_COLUMNS = 32;
+
+constexpr gint THUMB_BORDER_PADDING = 2;
+
+constexpr gint VFICON_TIP_DELAY = 500;
 
 enum {
-       FILE_COLUMN_POINTER = 0,
+       FILE_COLUMN_POINTER = VIEW_FILE_COLUMN_POINTER,
        FILE_COLUMN_COUNT
 };
 
+struct ColumnData
+{
+       ViewFile *vf;
+       gint number;
+};
+
+} // namespace
+
 static void vficon_toggle_filenames(ViewFile *vf);
 static void vficon_selection_remove(ViewFile *vf, FileData *fd, SelectionType mask, GtkTreeIter *iter);
 static void vficon_move_focus(ViewFile *vf, gint row, gint col, gboolean relative);
@@ -232,7 +255,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 +355,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;
@@ -368,7 +393,7 @@ static void tip_show(ViewFile *vf)
 
 static void tip_hide(ViewFile *vf)
 {
-       if (VFICON(vf)->tip_window) g_object_unref(VFICON(vf)->tip_window);
+       if (VFICON(vf)->tip_window) gq_gtk_widget_destroy(VFICON(vf)->tip_window);
        VFICON(vf)->tip_window = nullptr;
 }
 
@@ -426,7 +451,8 @@ 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);
 
@@ -743,10 +769,12 @@ 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 t;
-       gint i, j;
+       gint row1;
+       gint col1;
+       gint row2;
+       gint col2;
+       gint i;
+       gint j;
 
        if (!vficon_find_position(vf, start, &row1, &col1) ||
            !vficon_find_position(vf, end, &row2, &col2) ) return;
@@ -759,9 +787,7 @@ static void vficon_select_region_util(ViewFile *vf, FileData *start, FileData *e
 
                if (g_list_index(vf->list, start) > g_list_index(vf->list, end))
                        {
-                       FileData *tmp = start;
-                       start = end;
-                       end = tmp;
+                       std::swap(start, end);
                        }
 
                work = g_list_find(vf->list, start);
@@ -781,15 +807,11 @@ static void vficon_select_region_util(ViewFile *vf, FileData *start, FileData *e
        // rectangular_selection==true.
        if (row2 < row1)
                {
-               t = row1;
-               row1 = row2;
-               row2 = t;
+               std::swap(row1, row2);
                }
        if (col2 < col1)
                {
-               t = col1;
-               col1 = col2;
-               col2 = t;
+               std::swap(col1, col2);
                }
 
        DEBUG_1("table: %d x %d to %d x %d", row1, col1, row2, col2);
@@ -915,7 +937,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);
 
@@ -1088,7 +1111,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))
                {
@@ -1498,7 +1522,7 @@ static void vficon_populate(ViewFile *vf, gboolean resize, gboolean keep_positio
        GtkTreePath *tpath;
        GList *work;
        FileData *visible_fd = nullptr;
-       gint r, c;
+       gint r;
        gboolean valid;
        GtkTreeIter iter;
 
@@ -1557,7 +1581,6 @@ static void vficon_populate(ViewFile *vf, gboolean resize, gboolean keep_positio
                }
 
        r = -1;
-       c = 0;
 
        valid = gtk_tree_model_iter_children(store, &iter, nullptr);
 
@@ -1566,7 +1589,6 @@ static void vficon_populate(ViewFile *vf, gboolean resize, gboolean keep_positio
                {
                GList *list;
                r++;
-               c = 0;
                if (valid)
                        {
                        gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &list, -1);
@@ -1585,7 +1607,6 @@ static void vficon_populate(ViewFile *vf, gboolean resize, gboolean keep_positio
                                {
                                fd = static_cast<FileData *>(work->data);
                                work = work->next;
-                               c++;
                                }
                        else
                                {
@@ -1886,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;
@@ -2051,12 +2073,6 @@ gboolean vficon_refresh(ViewFile *vf)
  *-----------------------------------------------------------------------------
  */
 
-struct ColumnData
-{
-       ViewFile *vf;
-       gint number;
-};
-
 static void vficon_cell_data_cb(GtkTreeViewColumn *, GtkCellRenderer *cell,
                                GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
 {
@@ -2078,8 +2094,6 @@ static void vficon_cell_data_cb(GtkTreeViewColumn *, GtkCellRenderer *cell,
                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;
 
@@ -2136,11 +2150,8 @@ static void vficon_cell_data_cb(GtkTreeViewColumn *, GtkCellRenderer *cell,
                        state = GTK_STATE_SELECTED;
                        }
 
-               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));
+               convert_gdkcolor_to_gdkrgba(&style->text[state], &color_fg);
+               convert_gdkcolor_to_gdkrgba(&style->base[state], &color_bg);
 
                if (fd->selected & SELECTION_PRELIGHT)
                        {