Uses custom hash/equals functions so that we can actually fetch equivalent FileDatas...
[geeqie.git] / src / ui_tree_edit.c
index a6a4798..464a0ad 100644 (file)
@@ -1,13 +1,22 @@
 /*
- * (SLIK) SimpLIstic sKin functions
- * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2012 The Geeqie Team
+ * Copyright (C) 2004 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: John Ellis
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -22,6 +31,8 @@
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
+#include "compat.h"
+
 #include "ui_tree_edit.h"
 
 /*
@@ -186,20 +197,12 @@ gboolean tree_edit_by_path(GtkTreeView *tree, GtkTreePath *tpath, gint column, c
        GList *work;
 
        if (!edit_func) return FALSE;
-#if GTK_CHECK_VERSION(2,20,0)
        if (!gtk_widget_get_visible(GTK_WIDGET(tree))) return FALSE;
-#else
-       if (!GTK_WIDGET_VISIBLE(tree)) return FALSE;
-#endif
 
        tcolumn = gtk_tree_view_get_column(tree, column);
        if (!tcolumn) return FALSE;
 
-#if GTK_CHECK_VERSION(2,18,0)
        list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(tcolumn));
-#else
-       list = gtk_tree_view_column_get_cell_renderers(tcolumn);
-#endif
        work = list;
        while (work && !cell)
                {
@@ -275,11 +278,7 @@ gboolean tree_view_get_cell_origin(GtkTreeView *widget, GtkTreePath *tpath, gint
         * use x_offset instead for X scroll (sigh)
         */
        gtk_tree_view_get_cell_area(widget, tpath, tv_column, &rect);
-#if GTK_CHECK_VERSION(2,12,0)
        gtk_tree_view_convert_tree_to_widget_coords(widget, 0, 0, &x_offset, &y_offset);
-#else
-       gtk_tree_view_tree_to_widget_coords(widget, 0, 0, &x_offset, &y_offset);
-#endif
        gdk_window_get_origin(gtk_widget_get_window(GTK_WIDGET(widget)), &x_origin, &y_origin);
 
        if (gtk_tree_view_get_headers_visible(widget))
@@ -305,11 +304,7 @@ gboolean tree_view_get_cell_origin(GtkTreeView *widget, GtkTreePath *tpath, gint
                gint cell_x;
                gint cell_width;
 
-#if GTK_CHECK_VERSION(2,18,0)
                renderers = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(tv_column));
-#else
-               renderers = gtk_tree_view_column_get_cell_renderers(tv_column);
-#endif
                work = renderers;
                while (work && !cell)
                        {
@@ -366,7 +361,6 @@ void tree_view_get_cell_clamped(GtkTreeView *widget, GtkTreePath *tpath, gint co
        *height = MIN(*height, wy + wh - (*y));
 }
 
-#if GTK_CHECK_VERSION(2,8,0)
 /* an implementation that uses gtk_tree_view_get_visible_range */
 gint tree_view_row_get_visibility(GtkTreeView *widget, GtkTreeIter *iter, gboolean fully_visible)
 {
@@ -408,47 +402,6 @@ gint tree_view_row_get_visibility(GtkTreeView *widget, GtkTreeIter *iter, gboole
        return ret;
 }
 
-#else 
-/* an implementation that uses gtk_tree_view_get_visible_rect, it seems to be more error prone than the variant above */
-
-gint tree_view_row_get_visibility(GtkTreeView *widget, GtkTreeIter *iter, gboolean fully_visible)
-{
-       GtkTreeModel *store;
-       GtkTreePath *tpath;
-       gint cx, cy;
-
-       GdkRectangle vrect;
-       GdkRectangle crect;
-
-       if (!GTK_WIDGET_REALIZED(GTK_WIDGET(widget))) return -1; /* we will most probably scroll down, needed for tree_view_row_make_visible */
-
-       store = gtk_tree_view_get_model(widget);
-       tpath = gtk_tree_model_get_path(store, iter);
-
-       gtk_tree_view_get_visible_rect(widget, &vrect);
-       gtk_tree_view_get_cell_area(widget, tpath, NULL, &crect);
-       gtk_tree_path_free(tpath);
-
-
-#if GTK_CHECK_VERSION(2,12,0)
-       gtk_tree_view_convert_widget_to_tree_coords(widget, crect.x, crect.y, &cx, &cy);
-#else
-       gtk_tree_view_widget_to_tree_coords(widget, crect.x, crect.y, &cx, &cy);
-#endif
-
-       if (fully_visible)
-               {
-               if (cy < vrect.y) return -1;
-               if (cy + crect.height > vrect.y + vrect.height) return 1;
-               return 0;
-               }
-
-       if (cy + crect.height < vrect.y) return -1;
-       if (cy > vrect.y + vrect.height) return 1;
-       return 0;
-}
-#endif
-
 gint tree_view_row_make_visible(GtkTreeView *widget, GtkTreeIter *iter, gboolean center)
 {
        GtkTreePath *tpath;
@@ -543,6 +496,7 @@ gint tree_path_to_row(GtkTreePath *tpath)
 void shift_color(GdkColor *src, gshort val, gint direction)
 {
        gshort cs;
+       static gshort COLOR_MAX = 0xffff;
 
        if (val == -1)
                {
@@ -552,11 +506,11 @@ void shift_color(GdkColor *src, gshort val, gint direction)
                {
                val = CLAMP(val, 1, 100);
                }
-       cs = 0xffff / 100 * val;
+       cs = COLOR_MAX / 100 * val;
 
        /* up or down ? */
        if (direction < 0 ||
-           (direction == 0 &&((gint)src->red + (gint)src->green + (gint)src->blue) / 3 > 0xffff / 2))
+           (direction == 0 &&((gint)src->red + (gint)src->green + (gint)src->blue) / 3 > COLOR_MAX / 2))
                {
                src->red = MAX(0 , src->red - cs);
                src->green = MAX(0 , src->green - cs);
@@ -564,9 +518,9 @@ void shift_color(GdkColor *src, gshort val, gint direction)
                }
        else
                {
-               src->red = MIN(0xffff, src->red + cs);
-               src->green = MIN(0xffff, src->green + cs);
-               src->blue = MIN(0xffff, src->blue + cs);
+               src->red = MIN(COLOR_MAX, src->red + cs);
+               src->green = MIN(COLOR_MAX, src->green + cs);
+               src->blue = MIN(COLOR_MAX, src->blue + cs);
                }
 }
 
@@ -622,6 +576,10 @@ static gboolean widget_auto_scroll_cb(gpointer data)
        gint x, y;
        gint w, h;
        gint amt = 0;
+#if GTK_CHECK_VERSION(3,0,0)
+       GdkDeviceManager *device_manager;
+       GdkDevice *device;
+#endif
 
        if (sd->max_step < sd->region_size)
                {
@@ -629,7 +587,13 @@ static gboolean widget_auto_scroll_cb(gpointer data)
                }
 
        window = gtk_widget_get_window(sd->widget);
+#if GTK_CHECK_VERSION(3,0,0)
+       device_manager = gdk_display_get_device_manager(gdk_window_get_display(window));
+       device = gdk_device_manager_get_client_pointer(device_manager);
+       gdk_window_get_device_position(window, device, &x, &y, NULL);
+#else
        gdk_window_get_pointer(window, &x, &y, NULL);
+#endif
        w = gdk_window_get_width(window);
        h = gdk_window_get_height(window);