/*
- * (SLIK) SimpLIstic sKin functions
- * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2009 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
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
+#include "compat.h"
+
#include "ui_tree_edit.h"
/*
}
}
-static gint tree_edit_click_end_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
+static gboolean tree_edit_click_end_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
TreeEditData *ted = data;
return TRUE;
}
-static gint tree_edit_click_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
+static gboolean tree_edit_click_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
TreeEditData *ted = data;
+ GdkWindow *window = gtk_widget_get_window(ted->window);
gint x, y;
gint w, h;
xr = (gint)event->x_root;
yr = (gint)event->y_root;
- gdk_window_get_origin(ted->window->window, &x, &y);
- gdk_drawable_get_size(ted->window->window, &w, &h);
+ gdk_window_get_origin(window, &x, &y);
+ w = gdk_window_get_width(window);
+ h = gdk_window_get_height(window);
if (xr < x || yr < y || xr > x + w || yr > y + h)
{
return FALSE;
}
-static gint tree_edit_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
+static gboolean tree_edit_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
TreeEditData *ted = data;
switch (event->keyval)
{
- case GDK_Return:
- case GDK_KP_Enter:
- case GDK_Tab: /* ok, we are going to intercept the focus change
+ case GDK_KEY_Return:
+ case GDK_KEY_KP_Enter:
+ case GDK_KEY_Tab: /* ok, we are going to intercept the focus change
from keyboard and act like return was hit */
- case GDK_ISO_Left_Tab:
- case GDK_Up:
- case GDK_Down:
- case GDK_KP_Up:
- case GDK_KP_Down:
- case GDK_KP_Left:
- case GDK_KP_Right:
+ case GDK_KEY_ISO_Left_Tab:
+ case GDK_KEY_Up:
+ case GDK_KEY_Down:
+ case GDK_KEY_KP_Up:
+ case GDK_KEY_KP_Down:
+ case GDK_KEY_KP_Left:
+ case GDK_KEY_KP_Right:
tree_edit_do(ted);
tree_edit_close(ted);
break;
- case GDK_Escape:
+ case GDK_KEY_Escape:
tree_edit_close(ted);
break;
default:
/* explicitely set the focus flag for the entry, for some reason on popup windows this
* is not set, and causes no edit cursor to appear ( popups not allowed focus? )
*/
- GTK_WIDGET_SET_FLAGS(ted->entry, GTK_HAS_FOCUS);
+ gtk_widget_grab_focus(ted->entry);
gtk_grab_add(ted->window);
- gdk_pointer_grab(ted->window->window, TRUE,
+ gdk_pointer_grab(gtk_widget_get_window(ted->window), TRUE,
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK,
NULL, NULL, GDK_CURRENT_TIME);
- gdk_keyboard_grab(ted->window->window, TRUE, GDK_CURRENT_TIME);
+ gdk_keyboard_grab(gtk_widget_get_window(ted->window), TRUE, GDK_CURRENT_TIME);
return FALSE;
}
-gint tree_edit_by_path(GtkTreeView *tree, GtkTreePath *tpath, gint column, const gchar *text,
- gint (*edit_func)(TreeEditData *, const gchar *, const gchar *, gpointer), gpointer data)
+gboolean tree_edit_by_path(GtkTreeView *tree, GtkTreePath *tpath, gint column, const gchar *text,
+ gboolean (*edit_func)(TreeEditData *, const gchar *, const gchar *, gpointer), gpointer data)
{
TreeEditData *ted;
GtkTreeViewColumn *tcolumn;
GList *work;
if (!edit_func) return FALSE;
- if (!GTK_WIDGET_VISIBLE(tree)) return FALSE;
+ if (!gtk_widget_get_visible(GTK_WIDGET(tree))) return FALSE;
tcolumn = gtk_tree_view_get_column(tree, column);
if (!tcolumn) return FALSE;
- list = gtk_tree_view_column_get_cell_renderers(tcolumn);
+ list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(tcolumn));
work = list;
while (work && !cell)
{
*-------------------------------------------------------------------
*/
-gint tree_view_get_cell_origin(GtkTreeView *widget, GtkTreePath *tpath, gint column, gint text_cell_only,
- gint *x, gint *y, gint *width, gint *height)
+gboolean tree_view_get_cell_origin(GtkTreeView *widget, GtkTreePath *tpath, gint column, gboolean text_cell_only,
+ gint *x, gint *y, gint *width, gint *height)
{
gint x_origin, y_origin;
gint x_offset, y_offset;
* 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(widget)->window, &x_origin, &y_origin);
+ gdk_window_get_origin(gtk_widget_get_window(GTK_WIDGET(widget)), &x_origin, &y_origin);
if (gtk_tree_view_get_headers_visible(widget))
{
- header_size = tv_column->button->allocation.height;
+ GtkAllocation allocation;
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_widget_get_allocation(gtk_tree_view_column_get_button(tv_column), &allocation);
+#else
+ gtk_widget_get_allocation(tv_column->button, &allocation);
+#endif
+ header_size = allocation.height;
}
else
{
gint cell_x;
gint cell_width;
- renderers = gtk_tree_view_column_get_cell_renderers(tv_column);
+ renderers = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(tv_column));
work = renderers;
while (work && !cell)
{
return TRUE;
}
-void tree_view_get_cell_clamped(GtkTreeView *widget, GtkTreePath *tpath, gint column, gint text_cell_only,
+void tree_view_get_cell_clamped(GtkTreeView *widget, GtkTreePath *tpath, gint column, gboolean text_cell_only,
gint *x, gint *y, gint *width, gint *height)
{
gint wx, wy, ww, wh;
GdkWindow *window;
- window = GTK_WIDGET(widget)->window;
+ window = gtk_widget_get_window(GTK_WIDGET(widget));
gdk_window_get_origin(window, &wx, &wy);
- gdk_drawable_get_size(window, &ww, &wh);
+
+ ww = gdk_window_get_width(window);
+ wh = gdk_window_get_height(window);
+
if (!tree_view_get_cell_origin(widget, tpath, column, text_cell_only, x, y, width, height))
{
*x = wx;
*height = MIN(*height, wy + wh - (*y));
}
-gint tree_view_row_get_visibility(GtkTreeView *widget, GtkTreeIter *iter, gint fully_visible)
+/* an implementation that uses gtk_tree_view_get_visible_range */
+gint tree_view_row_get_visibility(GtkTreeView *widget, GtkTreeIter *iter, gboolean fully_visible)
{
GtkTreeModel *store;
- GtkTreePath *tpath;
- gint cx, cy;
+ GtkTreePath *tpath, *start_path, *end_path;
+ gint ret = 0;
- 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 */
+ if (!gtk_tree_view_get_visible_range(widget, &start_path, &end_path)) 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 (gtk_tree_path_compare(tpath, start_path) <= 0)
+ {
+ ret = -1;
+ }
+ else if (gtk_tree_path_compare(tpath, end_path) >= 0)
+ {
+ ret = 1;
+ }
+ }
+ else
+ {
+ if (gtk_tree_path_compare(tpath, start_path) < 0)
+ {
+ ret = -1;
+ }
+ else if (gtk_tree_path_compare(tpath, end_path) > 0)
+ {
+ ret = 1;
+ }
}
- if (cy + crect.height < vrect.y) return -1;
- if (cy > vrect.y + vrect.height) return 1;
- return 0;
+ gtk_tree_path_free(tpath);
+ gtk_tree_path_free(start_path);
+ gtk_tree_path_free(end_path);
+ return ret;
}
-gint tree_view_row_make_visible(GtkTreeView *widget, GtkTreeIter *iter, gint center)
+gint tree_view_row_make_visible(GtkTreeView *widget, GtkTreeIter *iter, gboolean center)
{
GtkTreePath *tpath;
gint vis;
return vis;
}
-gint tree_view_move_cursor_away(GtkTreeView *widget, GtkTreeIter *iter, gint only_selected)
+gboolean tree_view_move_cursor_away(GtkTreeView *widget, GtkTreeIter *iter, gboolean only_selected)
{
GtkTreeModel *store;
GtkTreePath *tpath;
void shift_color(GdkColor *src, gshort val, gint direction)
{
gshort cs;
+ static gshort COLOR_MAX = 0xffff;
if (val == -1)
{
{
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);
}
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);
}
}
typedef struct _AutoScrollData AutoScrollData;
struct _AutoScrollData
{
- gint timer_id;
+ guint timer_id; /* event source id */
gint region_size;
GtkWidget *widget;
GtkAdjustment *adj;
if (!sd) return;
g_object_set_data(G_OBJECT(widget), "autoscroll", NULL);
- if (sd->timer_id != -1) g_source_remove(sd->timer_id);
+ if (sd->timer_id) g_source_remove(sd->timer_id);
g_free(sd);
}
-static gint widget_auto_scroll_cb(gpointer data)
+static gboolean widget_auto_scroll_cb(gpointer data)
{
AutoScrollData *sd = data;
GdkWindow *window;
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)
{
sd->max_step = MIN(sd->region_size, sd->max_step + 2);
}
- window = sd->widget->window;
+ 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);
- gdk_drawable_get_size(window, &w, &h);
+#endif
+ w = gdk_window_get_width(window);
+ h = gdk_window_get_height(window);
if (x < 0 || x >= w || y < 0 || y >= h)
{
- sd->timer_id = -1;
+ sd->timer_id = 0;
widget_auto_scroll_stop(sd->widget);
return FALSE;
}
{
amt = CLAMP(amt, 0 - sd->max_step, sd->max_step);
- if (sd->adj->value != CLAMP(sd->adj->value + amt, sd->adj->lower, sd->adj->upper - sd->adj->page_size))
+ if (gtk_adjustment_get_value(sd->adj) != CLAMP(gtk_adjustment_get_value(sd->adj) + amt, gtk_adjustment_get_lower(sd->adj), gtk_adjustment_get_upper(sd->adj) - gtk_adjustment_get_page_size(sd->adj)))
{
/* only notify when scrolling is needed */
if (sd->notify_func && !sd->notify_func(sd->widget, x, y, sd->notify_data))
{
- sd->timer_id = -1;
+ sd->timer_id = 0;
widget_auto_scroll_stop(sd->widget);
return FALSE;
}
gtk_adjustment_set_value(sd->adj,
- CLAMP(sd->adj->value + amt, sd->adj->lower, sd->adj->upper - sd->adj->page_size));
+ CLAMP(gtk_adjustment_get_value(sd->adj) + amt, gtk_adjustment_get_lower(sd->adj), gtk_adjustment_get_upper(sd->adj) - gtk_adjustment_get_page_size(sd->adj)));
}
}