Skip to content

Commit

Permalink
Make highlighting of file names work with gtk3
Browse files Browse the repository at this point in the history
  • Loading branch information
wandrien committed May 16, 2013
1 parent 409f1bd commit e16d3d0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
17 changes: 16 additions & 1 deletion src/gtk/fm-cell-renderer-text.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
}
Expand Down
20 changes: 18 additions & 2 deletions src/gtk/fm-folder-model.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 10 additions & 1 deletion src/gtk/fm-standard-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e16d3d0

Please sign in to comment.