Use std::swap instead of temporary values
[geeqie.git] / src / view-file / view-file-icon.cc
index ae27a33..fe7c180 100644 (file)
 
 #include "view-file-icon.h"
 
-#include <config.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 "utilops.h"
 #include "view-file.h"
 
+namespace
+{
+
 /* between these, the icon width is increased by thumb_max_width / 2 */
-enum {
-       THUMB_MIN_ICON_WIDTH = 128,
-       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;
 
-enum {
-       VFICON_MAX_COLUMNS = 32,
-       THUMB_BORDER_PADDING = 2
-};
+constexpr gint THUMB_MIN_ICON_WIDTH_WITH_MARKS = TOGGLE_SPACING * FILEDATA_MARKS_SIZE;
 
-enum {
-       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);
@@ -382,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;
 }
 
@@ -762,7 +773,6 @@ static void vficon_select_region_util(ViewFile *vf, FileData *start, FileData *e
        gint col1;
        gint row2;
        gint col2;
-       gint t;
        gint i;
        gint j;
 
@@ -777,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);
@@ -799,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);
@@ -1519,7 +1523,6 @@ static void vficon_populate(ViewFile *vf, gboolean resize, gboolean keep_positio
        GList *work;
        FileData *visible_fd = nullptr;
        gint r;
-       gint c;
        gboolean valid;
        GtkTreeIter iter;
 
@@ -1578,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);
 
@@ -1587,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);
@@ -1606,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
                                {
@@ -2073,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)
 {
@@ -2100,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;
 
@@ -2158,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)
                        {