-/* cellrenderericon.c, based on:
+/*
+ * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
+ * Copyright (C) 2008 - 2016 The Geeqie Team
*
- * gtkcellrendererpixbuf.c
- * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
+ * 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 library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
+ * 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
- * Library General Public License for more details.
+ * 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 Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * 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.
*/
#include <stdlib.h>
static void gqv_cell_renderer_icon_init(GQvCellRendererIcon *celltext);
static void gqv_cell_renderer_icon_class_init(GQvCellRendererIconClass *class);
static void gqv_cell_renderer_icon_finalize(GObject *object);
-static void gqv_cell_renderer_icon_get_size(GtkCellRenderer *cell,
- GtkWidget *widget,
- const GdkRectangle *rectangle,
- gint *x_offset,
- gint *y_offset,
- gint *width,
- gint *height);
+#if GTK_CHECK_VERSION(3,0,0)
+static void gqv_cell_renderer_icon_get_size(GtkCellRenderer *cell,
+ GtkWidget *widget,
+ const GdkRectangle *rectangle,
+ gint *x_offset,
+ gint *y_offset,
+ gint *width,
+ gint *height);
+#else
+static void gqv_cell_renderer_icon_get_size(GtkCellRenderer *cell,
+ GtkWidget *widget,
+ GdkRectangle *rectangle,
+ gint *x_offset,
+ gint *y_offset,
+ gint *width,
+ gint *height);
+#endif
#if GTK_CHECK_VERSION(3,0,0)
static void gqv_cell_renderer_icon_render(GtkCellRenderer *cell,
cairo_t *cr,
#endif
+#if GTK_CHECK_VERSION(3,0,0)
+static gboolean gqv_cell_renderer_icon_activate(GtkCellRenderer *cell,
+ GdkEvent *event,
+ GtkWidget *widget,
+ const gchar *path,
+ const GdkRectangle *background_area,
+ const GdkRectangle *cell_area,
+ GtkCellRendererState flags);
+#else
static gboolean gqv_cell_renderer_icon_activate(GtkCellRenderer *cell,
- GdkEvent *event,
- GtkWidget *widget,
- const gchar *path,
- const GdkRectangle *background_area,
- const GdkRectangle *cell_area,
- GtkCellRendererState flags);
+ GdkEvent *event,
+ GtkWidget *widget,
+ const gchar *path,
+ GdkRectangle *background_area,
+ GdkRectangle *cell_area,
+ GtkCellRendererState flags);
+#endif
enum {
TOGGLED,
return g_object_new(GQV_TYPE_CELL_RENDERER_ICON, NULL);
}
-static void
-gqv_cell_renderer_icon_get_size(GtkCellRenderer *cell,
- GtkWidget *widget,
- const GdkRectangle *cell_area,
- gint *x_offset,
- gint *y_offset,
- gint *width,
- gint *height)
+#if GTK_CHECK_VERSION(3,0,0)
+static void gqv_cell_renderer_icon_get_size(GtkCellRenderer *cell,
+ GtkWidget *widget,
+ const GdkRectangle *cell_area,
+ gint *x_offset,
+ gint *y_offset,
+ gint *width,
+ gint *height)
+#else
+static void gqv_cell_renderer_icon_get_size(GtkCellRenderer *cell,
+ GtkWidget *widget,
+ GdkRectangle *cell_area,
+ gint *x_offset,
+ gint *y_offset,
+ gint *width,
+ gint *height)
+#endif
{
GQvCellRendererIcon *cellicon = (GQvCellRendererIcon *) cell;
gint calc_width;
gint calc_height;
gint xpad, ypad;
gfloat xalign, yalign;
-
+
gtk_cell_renderer_get_padding(cell, &xpad, &ypad);
gtk_cell_renderer_get_alignment(cell, &xalign, &yalign);
GdkPixbuf *pixbuf;
const gchar *text;
GdkRectangle cell_rect;
+#if GTK_CHECK_VERSION(3,0,0)
+ GtkStateFlags state;
+#else
GtkStateType state;
+#endif
gint xpad, ypad;
-
+
pixbuf = cellicon->pixbuf;
text = cellicon->text;
- if (!pixbuf && !text) return;
+ if (!pixbuf && !text)
+ {
+#if !GTK_CHECK_VERSION(3,0,0)
+ cairo_destroy(cr);
+#endif
+ return;
+ }
gtk_cell_renderer_get_padding(cell, &xpad, &ypad);
if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
{
if (gtk_widget_has_focus(widget))
+#if GTK_CHECK_VERSION(3,0,0)
+ state = GTK_STATE_FLAG_SELECTED;
+ else
+ state = GTK_STATE_FLAG_ACTIVE;
+#else
state = GTK_STATE_SELECTED;
else
state = GTK_STATE_ACTIVE;
+#endif
}
else
{
if (gtk_widget_get_state(widget) == GTK_STATE_INSENSITIVE)
+#if GTK_CHECK_VERSION(3,0,0)
+ state = GTK_STATE_FLAG_INSENSITIVE;
+ else
+ state = GTK_STATE_FLAG_NORMAL;
+#else
state = GTK_STATE_INSENSITIVE;
else
state = GTK_STATE_NORMAL;
+#endif
}
#if GTK_CHECK_VERSION(3,0,0)
pix_rect.height = text_rect.height;
pix_rect.x = cell_area->x + xpad + (cell_rect.width - text_rect.width + 1) / 2;
pix_rect.y = cell_area->y + ypad + (cell_rect.height - text_rect.height);
-
+
if (cellicon->show_marks)
{
pix_rect.y -= TOGGLE_SPACING;
pix_rect.height = TOGGLE_SPACING;
pix_rect.x = cell_area->x + xpad + (cell_rect.width - pix_rect.width + 1) / 2 + (TOGGLE_SPACING - TOGGLE_WIDTH) / 2;
pix_rect.y = cell_area->y + ypad + (cell_rect.height - pix_rect.height) + (TOGGLE_SPACING - TOGGLE_WIDTH) / 2;
-
+
if (gdk_rectangle_intersect(cell_area, &pix_rect, &draw_rect)
#if !GTK_CHECK_VERSION(3,0,0)
&& gdk_rectangle_intersect(expose_area, &draw_rect, &draw_rect)
for (i = 0; i < cellicon->num_marks; i++)
{
#if GTK_CHECK_VERSION(3,0,0)
+#if GTK_CHECK_VERSION(3,14,0)
+ state &= ~(GTK_STATE_FLAG_CHECKED);
+
+ if ((cellicon->marks & (1 << i)))
+ state |= GTK_STATE_FLAG_CHECKED;
+#else
state &= ~(GTK_STATE_FLAG_ACTIVE);
if ((cellicon->marks & (1 << i)))
state |= GTK_STATE_FLAG_ACTIVE;
-
+#endif
cairo_save (cr);
cairo_rectangle(cr,
gtk_style_context_add_class(context, GTK_STYLE_CLASS_CHECK);
+ gtk_style_context_add_class(context, "marks");
+ GtkStyleProvider *provider;
+ provider = (GtkStyleProvider *)gtk_css_provider_new();
+ gtk_css_provider_load_from_data(GTK_CSS_PROVIDER(provider),
+ ".marks {\n"
+ "border-color: #808080;\n"
+ "border-style: solid;\n"
+ "border-width: 1px;\n"
+ "border-radius: 0px;\n"
+ "}\n"
+ ,-1, NULL);
+ gtk_style_context_add_provider(context, provider,
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
gtk_render_check(context, cr,
pix_rect.x + i * TOGGLE_SPACING + (TOGGLE_WIDTH - TOGGLE_SPACING) / 2,
pix_rect.y,
TOGGLE_WIDTH, TOGGLE_WIDTH);
+ gtk_render_frame(context, cr,
+ pix_rect.x + i * TOGGLE_SPACING + (TOGGLE_WIDTH - TOGGLE_SPACING) / 2,
+ pix_rect.y,
+ TOGGLE_WIDTH, TOGGLE_WIDTH);
+
+ if (cellicon->focused && gtk_widget_has_focus(widget))
+ {
+ gtk_render_focus(context, cr,
+ pix_rect.x + i * TOGGLE_SPACING + (TOGGLE_WIDTH - TOGGLE_SPACING) / 2,
+ pix_rect.y, TOGGLE_WIDTH, TOGGLE_WIDTH);
+ }
gtk_style_context_restore(context);
cairo_restore(cr);
#endif
}
}
- }
+ }
+#if !GTK_CHECK_VERSION(3,0,0)
if (cellicon->focused && gtk_widget_has_focus(widget))
{
-#if GTK_CHECK_VERSION(3,0,0)
-#else
gtk_paint_focus(gtk_widget_get_style(widget), window,
state,
cell_area, widget,
"cellrendererfocus",
cell_area->x, cell_area->y,
cell_area->width, cell_area->height);
-#endif
}
-#if !GTK_CHECK_VERSION(3,0,0)
cairo_destroy(cr);
#endif
}
-static gboolean
-gqv_cell_renderer_icon_activate(GtkCellRenderer *cell,
- GdkEvent *event,
- GtkWidget *widget,
- const gchar *path,
- const GdkRectangle *background_area,
- const GdkRectangle *cell_area,
- GtkCellRendererState flags)
+#if GTK_CHECK_VERSION(3,0,0)
+static gboolean gqv_cell_renderer_icon_activate(GtkCellRenderer *cell,
+ GdkEvent *event,
+ GtkWidget *widget,
+ const gchar *path,
+ const GdkRectangle *background_area,
+ const GdkRectangle *cell_area,
+ GtkCellRendererState flags)
+#else
+static gboolean gqv_cell_renderer_icon_activate(GtkCellRenderer *cell,
+ GdkEvent *event,
+ GtkWidget *widget,
+ const gchar *path,
+ GdkRectangle *background_area,
+ GdkRectangle *cell_area,
+ GtkCellRendererState flags)
+#endif
{
GQvCellRendererIcon *cellicon = (GQvCellRendererIcon *) cell;
GdkEventButton *bevent = &event->button;
gint xpad, ypad;
gtk_cell_renderer_get_padding(cell, &xpad, &ypad);
-
+
gqv_cell_renderer_icon_get_size(cell, widget, cell_area,
&cell_rect.x, &cell_rect.y,
&cell_rect.width, &cell_rect.height);
for (i = 0; i < cellicon->num_marks; i++)
{
rect.x = cell_area->x + xpad + (cell_rect.width - TOGGLE_SPACING * cellicon->num_marks + 1) / 2 + i * TOGGLE_SPACING;
-
+
if (bevent->x >= rect.x && bevent->x < rect.x + rect.width &&
bevent->y >= rect.y && bevent->y < rect.y + rect.height)
{