Fix clang compile errors
[geeqie.git] / src / cellrenderericon.c
index 8f439f0..5f42e1c 100644 (file)
@@ -1,22 +1,20 @@
-/* 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>
@@ -685,14 +683,24 @@ gqv_cell_renderer_icon_render(GtkCellRenderer             *cell,
        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);
 
@@ -708,16 +716,28 @@ gqv_cell_renderer_icon_render(GtkCellRenderer             *cell,
        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)
@@ -820,11 +840,17 @@ gqv_cell_renderer_icon_render(GtkCellRenderer             *cell,
                        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,
@@ -838,10 +864,35 @@ gqv_cell_renderer_icon_render(GtkCellRenderer             *cell,
 
                                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);
 
@@ -855,21 +906,18 @@ gqv_cell_renderer_icon_render(GtkCellRenderer             *cell,
 #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
 }