Hello,
I'm trying to retrieve the selection background color of a entry widget but the RGB values I get does not look like the one used by the widget. The reason I want to get the selection background is because we have some custom widgets and we want to use the same color for highlighting text as other widgets.
Here is the code I use, please note that I'm currently using GDK version 2 so my problem occurs in the #else of the following code:
Code:
PCLColor GTKGetSelectedBackground(GtkWidget * wWidget)
{
#if GDK_MAJOR_VERSION > 2
GdkRGBA sColor;
GtkStyleContext * wStyle = gtk_widget_get_style_context(wWidget);
gtk_style_context_get_background_color(wStyle, GTK_STATE_FLAG_SELECTED,
&sColor);
return PCLColor((uchar) (sColor.red * 255),
(uchar) (sColor.green * 255),
(uchar) (sColor.blue * 255));
#else
GdkColor sColor = gtk_widget_get_style(wWidget)->bg[GTK_STATE_SELECTED];
return PCLColor((uchar) ((double) sColor.red / USHRT_MAX * 255),
(uchar) ((double) sColor.green / USHRT_MAX * 255),
(uchar) ((double) sColor.blue / USHRT_MAX * 255));
#endif
}
GtkWidget * wOffScreenWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
// Highlight Color.
GtkWidget * wTextList = gtk_tree_view_new();
gtk_container_add(GTK_CONTAINER(wOffScreenWindow), wTextList);
oHighlightBackground = GTKGetSelectedBackground(wTextList);
oHighlightForeground = GTKGetSelectedForeground(wTextList);
gtk_widget_destroy(wTextList);
gtk_widget_destroy(wOffScreenWindow);
The returned color is Red=75, Green=105, Blue=131, but it doesn't look like the color used by the entry widget. I tried to get the color from the "base" array of the GtkStyle but the values are the same. I even tried to use the color map of the widget, but the pixel RGB values are the same. What am I missing?
Thanks,
Phelippe Neveu