From e16d3d0e4e0724fe4de77acbeda1217cb4af2196 Mon Sep 17 00:00:00 2001 From: Vadim Ushakov Date: Thu, 16 May 2013 16:35:51 +0800 Subject: [PATCH] Make highlighting of file names work with gtk3 --- src/gtk/fm-cell-renderer-text.c | 17 ++++++++++++++++- src/gtk/fm-folder-model.c | 20 ++++++++++++++++++-- src/gtk/fm-standard-view.c | 11 ++++++++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/gtk/fm-cell-renderer-text.c b/src/gtk/fm-cell-renderer-text.c index 7fd86da..3228a4e 100644 --- a/src/gtk/fm-cell-renderer-text.c +++ b/src/gtk/fm-cell-renderer-text.c @@ -205,6 +205,7 @@ static void fm_cell_renderer_text_render(GtkCellRenderer *cell, #if GTK_CHECK_VERSION(3, 0, 0) GtkStyleContext* style; GtkStateFlags state; + GdkRGBA * foreground_color = NULL; #else GtkStyle* style; GtkStateType state; @@ -228,7 +229,11 @@ static void fm_cell_renderer_text_render(GtkCellRenderer *cell, "wrap-width", &wrap_width, "alignment" , &alignment, "text", &text, +#if GTK_CHECK_VERSION(3, 0, 0) + "foreground-rgba", &foreground_color, +#else "foreground-gdk", &foreground_color, +#endif NULL); #if 0 @@ -246,7 +251,17 @@ static void fm_cell_renderer_text_render(GtkCellRenderer *cell, { PangoAttrList * attr_list = pango_attr_list_new(); add_attr(attr_list, - pango_attr_foreground_new(foreground_color->red, foreground_color->green, foreground_color->blue)); +#if GTK_CHECK_VERSION(3, 0, 0) + pango_attr_foreground_new( + foreground_color->red * 65535, + foreground_color->green * 65535, + foreground_color->blue * 65535)); +#else + pango_attr_foreground_new( + foreground_color->red, + foreground_color->green, + foreground_color->blue)); +#endif pango_layout_set_attributes(layout, attr_list); pango_attr_list_unref(attr_list); } diff --git a/src/gtk/fm-folder-model.c b/src/gtk/fm-folder-model.c index 8bf46c1..a7bccbf 100644 --- a/src/gtk/fm-folder-model.c +++ b/src/gtk/fm-folder-model.c @@ -88,7 +88,12 @@ struct _FmFolderItem gboolean is_thumbnail : 1; gboolean thumbnail_loading : 1; gboolean thumbnail_failed : 1; + gboolean color_valid : 1; +#if GTK_CHECK_VERSION(3, 0, 0) + GdkRGBA color; +#else GdkColor color; +#endif }; typedef struct _FmFolderModelFilterItem @@ -330,7 +335,12 @@ static void fm_folder_model_tree_model_init(GtkTreeModelIface *iface) column_infos[FM_FOLDER_MODEL_COL_INFO]->type= G_TYPE_POINTER; column_infos[FM_FOLDER_MODEL_COL_ICON]->type= GDK_TYPE_PIXBUF; column_infos[FM_FOLDER_MODEL_COL_GICON]->type= G_TYPE_ICON; +#if GTK_CHECK_VERSION(3, 0, 0) + column_infos[FM_FOLDER_MODEL_COL_COLOR]->type= GDK_TYPE_RGBA; +#else column_infos[FM_FOLDER_MODEL_COL_COLOR]->type= GDK_TYPE_COLOR; +#endif + } static void fm_folder_model_tree_sortable_init(GtkTreeSortableIface *iface) @@ -752,13 +762,19 @@ static void fm_folder_model_get_value(GtkTreeModel *tree_model, case FM_FOLDER_MODEL_COL_COLOR: if (model->use_custom_colors) { - if (!item->color.pixel) + if (!item->color_valid) { unsigned long color = fm_file_info_get_color(info); +#if GTK_CHECK_VERSION(3, 0, 0) + item->color.red = ((color >> 16) & 0xFF) / 255.0; + item->color.green = ((color >> 8) & 0xFF) / 255.0; + item->color.blue = ((color) & 0xFF) / 255.0; +#else item->color.red = ((color >> 16) & 0xFF) * 257; item->color.green = ((color >> 8) & 0xFF) * 257; item->color.blue = ((color) & 0xFF) * 257; - item->color.pixel = 1; +#endif + item->color_valid = TRUE; } g_value_set_boxed(value, &item->color); } diff --git a/src/gtk/fm-standard-view.c b/src/gtk/fm-standard-view.c index f19ce1f..bfddd97 100644 --- a/src/gtk/fm-standard-view.c +++ b/src/gtk/fm-standard-view.c @@ -600,9 +600,13 @@ static inline void create_icon_view(FmStandardView* fv, GList* sels) gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(fv->view), render, "text", FM_FOLDER_MODEL_COL_NAME ); +#if GTK_CHECK_VERSION(3, 0, 0) + gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(fv->view), render, + "foreground-rgba", FM_FOLDER_MODEL_COL_COLOR); +#else gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(fv->view), render, "foreground-gdk", FM_FOLDER_MODEL_COL_COLOR); - +#endif // g_object_set(G_OBJECT(render), "foreground-set", TRUE, NULL); @@ -918,7 +922,12 @@ static GtkTreeViewColumn* create_list_view_column(FmStandardView* fv, gtk_tree_view_column_pack_start(col, render, TRUE); gtk_tree_view_column_set_attributes(col, render, "text", col_id, NULL); +#if GTK_CHECK_VERSION(3, 0, 0) + gtk_tree_view_column_add_attribute(col, render, "foreground-rgba", FM_FOLDER_MODEL_COL_COLOR); +#else gtk_tree_view_column_add_attribute(col, render, "foreground-gdk", FM_FOLDER_MODEL_COL_COLOR); +#endif + gtk_tree_view_column_set_resizable(col, TRUE); /* Unfortunately if we don't set it sortable we cannot right-click it too