Bug fix: SAR window crashes when escape pressed
[geeqie.git] / src / cellrenderericon.cc
index 843f1ae..cdd3f02 100644 (file)
@@ -32,13 +32,13 @@ static void gqv_cell_renderer_icon_set_property(GObject             *object,
                                                const GValue    *value,
                                                GParamSpec      *pspec);
 static void gqv_cell_renderer_icon_init_wrapper(void *, void *);
-static void gqv_cell_renderer_icon_init(GQvCellRendererIcon *celltext);
+static void gqv_cell_renderer_icon_init(GQvCellRendererIcon *cellicon);
 static void gqv_cell_renderer_icon_class_init_wrapper(void *, void *);
 static void gqv_cell_renderer_icon_class_init(GQvCellRendererIconClass *icon_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,
+                                           const GdkRectangle *cell_area,
                                            gint               *x_offset,
                                            gint               *y_offset,
                                            gint               *width,
@@ -87,7 +87,7 @@ static guint toggle_cell_signals[LAST_SIGNAL] = { 0 };
 static gpointer parent_class;
 
 GType
-gqv_cell_renderer_icon_get_type(void)
+gqv_cell_renderer_icon_get_type()
 {
        static GType cell_icon_type = 0;
 
@@ -96,27 +96,27 @@ gqv_cell_renderer_icon_get_type(void)
                static const GTypeInfo cell_icon_info =
                        {
                        sizeof(GQvCellRendererIconClass), /* class_size */
-                       NULL,           /* base_init */
-                       NULL,           /* base_finalize */
+                       nullptr,                /* base_init */
+                       nullptr,                /* base_finalize */
                        static_cast<GClassInitFunc>(gqv_cell_renderer_icon_class_init_wrapper), /* class_init */
-                       NULL,           /* class_finalize */
-                       NULL,           /* class_data */
+                       nullptr,                /* class_finalize */
+                       nullptr,                /* class_data */
                        sizeof(GQvCellRendererIcon), /* instance_size */
                        0,              /* n_preallocs */
                        reinterpret_cast<GInstanceInitFunc>(gqv_cell_renderer_icon_init_wrapper), /* instance_init */
-                       NULL,           /* value_table */
+                       nullptr,                /* value_table */
                        };
 
                cell_icon_type = g_type_register_static(GTK_TYPE_CELL_RENDERER,
                                                        "GQvCellRendererIcon",
-                                                       &cell_icon_info, GTypeFlags(0));
+                                                       &cell_icon_info, static_cast<GTypeFlags>(0));
                }
 
        return cell_icon_type;
 }
 
 static void
-gqv_cell_renderer_icon_init_wrapper(void *data, void *UNUSED(user_data))
+gqv_cell_renderer_icon_init_wrapper(void *data, void *)
 {
        gqv_cell_renderer_icon_init(static_cast<GQvCellRendererIcon *>(data));
 }
@@ -129,7 +129,7 @@ gqv_cell_renderer_icon_init(GQvCellRendererIcon *cellicon)
 }
 
 static void
-gqv_cell_renderer_icon_class_init_wrapper(void *data, void *UNUSED(user_data))
+gqv_cell_renderer_icon_class_init_wrapper(void *data, void *)
 {
        gqv_cell_renderer_icon_class_init(static_cast<GQvCellRendererIconClass *>(data));
 }
@@ -164,23 +164,23 @@ gqv_cell_renderer_icon_class_init(GQvCellRendererIconClass *icon_class)
                                        g_param_spec_string("text",
                                                        "Text",
                                                        "Text to render",
-                                                       NULL,
+                                                       nullptr,
                                                        G_PARAM_READWRITE));
 
        g_object_class_install_property(object_class,
                                        PROP_BACKGROUND_GDK,
-                                       g_param_spec_boxed("background_gdk",
+                                       g_param_spec_boxed("background_rgba",
                                                        "Background color",
-                                                       "Background color as a GdkColor",
-                                                       GDK_TYPE_COLOR,
+                                                       "Background color as a GdkRGBA",
+                                                       GDK_TYPE_RGBA,
                                                        G_PARAM_READWRITE));
 
        g_object_class_install_property(object_class,
                                        PROP_FOREGROUND_GDK,
-                                       g_param_spec_boxed("foreground_gdk",
+                                       g_param_spec_boxed("foreground_rgba",
                                                        "Foreground color",
-                                                       "Foreground color as a GdkColor",
-                                                       GDK_TYPE_COLOR,
+                                                       "Foreground color as a GdkRGBA",
+                                                       GDK_TYPE_RGBA,
                                                        G_PARAM_READWRITE));
 
        g_object_class_install_property(object_class,
@@ -272,7 +272,7 @@ gqv_cell_renderer_icon_class_init(GQvCellRendererIconClass *icon_class)
                G_OBJECT_CLASS_TYPE (object_class),
                G_SIGNAL_RUN_LAST,
                G_STRUCT_OFFSET (GQvCellRendererIconClass, toggled),
-               NULL, NULL,
+               nullptr, nullptr,
                g_cclosure_marshal_VOID__STRING,
                G_TYPE_NONE, 1,
                G_TYPE_STRING);
@@ -302,29 +302,29 @@ gqv_cell_renderer_icon_get_property(GObject       *object,
        switch (param_id)
        {
        case PROP_PIXBUF:
-               g_value_set_object(value, cellicon->pixbuf ? G_OBJECT(cellicon->pixbuf) : NULL);
+               g_value_set_object(value, cellicon->pixbuf ? G_OBJECT(cellicon->pixbuf) : nullptr);
                break;
        case PROP_TEXT:
                g_value_set_string(value, cellicon->text);
                break;
        case PROP_BACKGROUND_GDK:
                {
-               GdkColor color;
+               GdkRGBA color;
 
-               color.red = cellicon->background.red;
-               color.green = cellicon->background.green;
-               color.blue = cellicon->background.blue;
+               color.red = cellicon->background.red / 65535;
+               color.green = cellicon->background.green / 65535;
+               color.blue = cellicon->background.blue / 65535;
 
                g_value_set_boxed(value, &color);
                }
                break;
        case PROP_FOREGROUND_GDK:
                {
-               GdkColor color;
+               GdkRGBA color;
 
-               color.red = cellicon->foreground.red;
-               color.green = cellicon->foreground.green;
-               color.blue = cellicon->foreground.blue;
+               color.red = cellicon->foreground.red / 65535;
+               color.green = cellicon->foreground.green / 65535;
+               color.blue = cellicon->foreground.blue / 65535;
 
                g_value_set_boxed(value, &color);
                }
@@ -365,9 +365,7 @@ gqv_cell_renderer_icon_get_property(GObject *object,
        }
 }
 
-static void
-set_bg_color(GQvCellRendererIcon *cellicon,
-            GdkColor             *color)
+static void set_bg_color(GQvCellRendererIcon *cellicon, GdkRGBA *color)
 {
        if (color)
                {
@@ -377,9 +375,9 @@ set_bg_color(GQvCellRendererIcon *cellicon,
                        g_object_notify(G_OBJECT(cellicon), "background_set");
                        }
 
-               cellicon->background.red = color->red;
-               cellicon->background.green = color->green;
-               cellicon->background.blue = color->blue;
+               cellicon->background.red = color->red * 65535;
+               cellicon->background.green = color->green * 65535;
+               cellicon->background.blue = color->blue * 65535;
                }
        else
                {
@@ -391,8 +389,7 @@ set_bg_color(GQvCellRendererIcon *cellicon,
                }
 }
 
-static void set_fg_color(GQvCellRendererIcon *cellicon,
-                        GdkColor             *color)
+static void set_fg_color(GQvCellRendererIcon *cellicon, GdkRGBA *color)
 {
        if (color)
                {
@@ -401,10 +398,9 @@ static void set_fg_color(GQvCellRendererIcon *cellicon,
                        cellicon->foreground_set = TRUE;
                        g_object_notify(G_OBJECT(cellicon), "foreground_set");
                        }
-
-               cellicon->foreground.red = color->red;
-               cellicon->foreground.green = color->green;
-               cellicon->foreground.blue = color->blue;
+               cellicon->foreground.red = color->red * 65535;
+               cellicon->foreground.green = color->green * 65535;
+               cellicon->foreground.blue = color->blue * 65535;
                }
        else
                {
@@ -448,10 +444,10 @@ gqv_cell_renderer_icon_set_property(GObject               *object,
                }
                break;
        case PROP_BACKGROUND_GDK:
-               set_bg_color(cellicon, static_cast<GdkColor *>(g_value_get_boxed(value)));
+               set_bg_color(cellicon, static_cast<GdkRGBA *>(g_value_get_boxed(value)));
                break;
        case PROP_FOREGROUND_GDK:
-               set_fg_color(cellicon, static_cast<GdkColor *>(g_value_get_boxed(value)));
+               set_fg_color(cellicon, static_cast<GdkRGBA *>(g_value_get_boxed(value)));
                break;
        case PROP_FOCUSED:
                cellicon->focused = g_value_get_boolean(value);
@@ -540,9 +536,9 @@ gqv_cell_renderer_icon_get_layout(GQvCellRendererIcon *cellicon, GtkWidget *widg
  * Return value: the new cell renderer
  **/
 GtkCellRenderer *
-gqv_cell_renderer_icon_new(void)
+gqv_cell_renderer_icon_new()
 {
-       return static_cast<GtkCellRenderer *>(g_object_new(GQV_TYPE_CELL_RENDERER_ICON, NULL));
+       return static_cast<GtkCellRenderer *>(g_object_new(GQV_TYPE_CELL_RENDERER_ICON, nullptr));
 }
 
 static void gqv_cell_renderer_icon_get_size(GtkCellRenderer    *cell,
@@ -586,7 +582,7 @@ static void gqv_cell_renderer_icon_get_size(GtkCellRenderer    *cell,
                PangoRectangle rect;
 
                layout = gqv_cell_renderer_icon_get_layout(cellicon, widget, FALSE);
-               pango_layout_get_pixel_extents(layout, NULL, &rect);
+               pango_layout_get_pixel_extents(layout, nullptr, &rect);
                g_object_unref(layout);
 
                calc_width = MAX(calc_width, rect.width);
@@ -626,7 +622,7 @@ static void gqv_cell_renderer_icon_get_size(GtkCellRenderer    *cell,
 static void gqv_cell_renderer_icon_render(GtkCellRenderer *cell,
                                           cairo_t *cr,
                                           GtkWidget *widget,
-                                          const GdkRectangle *UNUSED(background_area),
+                                          const GdkRectangle *,
                                           const GdkRectangle *cell_area,
                                           GtkCellRendererState flags)
 
@@ -667,7 +663,7 @@ static void gqv_cell_renderer_icon_render(GtkCellRenderer *cell,
                }
        else
                {
-               if (gtk_widget_get_state(widget) == GTK_STATE_INSENSITIVE)
+               if (!gtk_widget_is_sensitive(widget))
                        state = GTK_STATE_FLAG_INSENSITIVE;
                else
                        state = GTK_STATE_FLAG_NORMAL;
@@ -713,7 +709,7 @@ static void gqv_cell_renderer_icon_render(GtkCellRenderer *cell,
                GdkRectangle pix_rect;
                GdkRectangle draw_rect;
                layout = gqv_cell_renderer_icon_get_layout(cellicon, widget, TRUE);
-               pango_layout_get_pixel_extents(layout, NULL, &text_rect);
+               pango_layout_get_pixel_extents(layout, nullptr, &text_rect);
 
                pix_rect.width = text_rect.width;
                pix_rect.height = text_rect.height;
@@ -765,18 +761,6 @@ static void 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 = reinterpret_cast<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);
 
                                if (state & GTK_STATE_FLAG_CHECKED)
                                        {
@@ -798,8 +782,6 @@ static void gqv_cell_renderer_icon_render(GtkCellRenderer *cell,
                                        }
                                gtk_style_context_restore(context);
                                cairo_restore(cr);
-                               gtk_style_context_remove_provider(context, provider);
-                               g_object_unref(provider);
                                }
                        }
                }
@@ -809,9 +791,9 @@ static gboolean gqv_cell_renderer_icon_activate(GtkCellRenderer      *cell,
                                                GdkEvent             *event,
                                                GtkWidget            *widget,
                                                const gchar          *path,
-                                               const GdkRectangle   *UNUSED(background_area),
+                                               const GdkRectangle   *,
                                                const GdkRectangle   *cell_area,
-                                               GtkCellRendererState  UNUSED(flags))
+                                               GtkCellRendererState)
 {
        auto cellicon = reinterpret_cast<GQvCellRendererIcon *>(cell);
        GdkEventButton *bevent = &event->button;