[gtkhtml] Bug #668215 - Selection not highlighted with recent gtk+
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkhtml] Bug #668215 - Selection not highlighted with recent gtk+
- Date: Tue, 24 Jan 2012 18:14:01 +0000 (UTC)
commit 48f02e92acc3bbfc933b484378cf9152743fe09a
Author: Milan Crha <mcrha redhat com>
Date: Tue Jan 24 19:12:14 2012 +0100
Bug #668215 - Selection not highlighted with recent gtk+
components/editor/gtkhtml-color-swatch.c | 25 +++---
components/editor/gtkhtml-editor-private.c | 10 ++-
gtkhtml/gtkhtml.c | 17 ++--
gtkhtml/htmlcolorset.c | 125 ++++++++++++++++++----------
gtkhtml/htmlpainter.c | 7 ++-
gtkhtml/htmlprinter.c | 10 ++-
gtkhtml/htmltextarea.c | 8 +-
7 files changed, 127 insertions(+), 75 deletions(-)
---
diff --git a/components/editor/gtkhtml-color-swatch.c b/components/editor/gtkhtml-color-swatch.c
index 03bf499..f484af6 100644
--- a/components/editor/gtkhtml-color-swatch.c
+++ b/components/editor/gtkhtml-color-swatch.c
@@ -39,18 +39,18 @@ static gboolean
color_swatch_draw_cb (GtkWidget *drawing_area,
cairo_t *cr)
{
- GtkStyle *style;
- GdkColor *color;
+ GtkStyleContext *style_context;
+ GdkRGBA rgba;
GdkRectangle rect;
- style = gtk_widget_get_style (drawing_area);
- if (!style)
+ style_context = gtk_widget_get_style_context (drawing_area);
+ if (!style_context)
return FALSE;
- color = &style->bg[GTK_STATE_NORMAL];
+ gtk_style_context_get_background_color (style_context, GTK_STATE_FLAG_NORMAL, &rgba);
gdk_cairo_get_clip_rectangle (cr, &rect);
- gdk_cairo_set_source_color (cr, color);
+ gdk_cairo_set_source_rgba (cr, &rgba);
gdk_cairo_rectangle (cr, &rect);
cairo_fill (cr);
@@ -266,17 +266,20 @@ void
gtkhtml_color_swatch_get_color (GtkhtmlColorSwatch *swatch,
GdkColor *color)
{
- GtkStyle *style;
+ GtkStyleContext *style_context;
GtkWidget *drawing_area;
+ GdkRGBA rgba;
g_return_if_fail (GTKHTML_IS_COLOR_SWATCH (swatch));
g_return_if_fail (color != NULL);
drawing_area = swatch->priv->drawing_area;
- style = gtk_widget_get_style (drawing_area);
- color->red = style->bg[GTK_STATE_NORMAL].red;
- color->green = style->bg[GTK_STATE_NORMAL].green;
- color->blue = style->bg[GTK_STATE_NORMAL].blue;
+ style_context = gtk_widget_get_style_context (drawing_area);
+ gtk_style_context_get_background_color (style_context, GTK_STATE_FLAG_NORMAL, &rgba);
+
+ color->red = rgba.red * 65535;
+ color->green = rgba.green * 65535;
+ color->blue = rgba.blue * 65535;
}
void
diff --git a/components/editor/gtkhtml-editor-private.c b/components/editor/gtkhtml-editor-private.c
index f9c5d3d..293aebc 100644
--- a/components/editor/gtkhtml-editor-private.c
+++ b/components/editor/gtkhtml-editor-private.c
@@ -220,6 +220,7 @@ gtkhtml_editor_private_constructed (GtkhtmlEditor *editor)
GtkHTML *html;
GtkWidget *widget;
+ GtkStyleContext *style_context;
GtkToolbar *toolbar;
GtkToolItem *tool_item;
@@ -235,9 +236,10 @@ gtkhtml_editor_private_constructed (GtkhtmlEditor *editor)
priv->main_toolbar = g_object_ref (widget);
gtk_widget_show (widget);
- gtk_style_context_add_class (
- gtk_widget_get_style_context (widget),
- GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
+ style_context = gtk_widget_get_style_context (widget);
+ gtk_style_context_save (style_context);
+
+ gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_PRIMARY_TOOLBAR);
widget = gtkhtml_editor_get_managed_widget (editor, "/edit-toolbar");
gtk_toolbar_set_style (GTK_TOOLBAR (widget), GTK_TOOLBAR_BOTH_HORIZ);
@@ -368,6 +370,8 @@ gtkhtml_editor_private_constructed (GtkhtmlEditor *editor)
widget = WIDGET (TABLE_PROPERTIES_COLOR_COMBO);
gtkhtml_color_combo_set_palette (
GTKHTML_COLOR_COMBO (widget), priv->palette);
+
+ gtk_style_context_restore (style_context);
}
void
diff --git a/gtkhtml/gtkhtml.c b/gtkhtml/gtkhtml.c
index c194d2e..697b16e 100644
--- a/gtkhtml/gtkhtml.c
+++ b/gtkhtml/gtkhtml.c
@@ -880,9 +880,10 @@ gtk_html_set_fonts (GtkHTML *html,
HTMLPainter *painter)
{
GtkWidget *top_level;
- GtkStyle *style;
+ GtkStyleContext *style_context;
GdkScreen *screen;
PangoFontDescription *fixed_desc = NULL;
+ const PangoFontDescription *font_desc;
gchar *fixed_name = NULL;
const gchar *fixed_family = NULL;
gint fixed_size = 0;
@@ -892,11 +893,12 @@ gtk_html_set_fonts (GtkHTML *html,
gboolean font_var_points = FALSE;
top_level = GTK_WIDGET (gtk_html_get_top_html (html));
- style = gtk_widget_get_style (top_level);
+ style_context = gtk_widget_get_style_context (top_level);
+ font_desc = gtk_style_context_get_font (style_context, GTK_STATE_FLAG_NORMAL);
- font_var = pango_font_description_get_family (style->font_desc);
- font_var_size = pango_font_description_get_size (style->font_desc);
- font_var_points = !pango_font_description_get_size_is_absolute (style->font_desc);
+ font_var = pango_font_description_get_family (font_desc);
+ font_var_size = pango_font_description_get_size (font_desc);
+ font_var_points = !pango_font_description_get_size_is_absolute (font_desc);
gtk_widget_style_get (GTK_WIDGET (top_level), "fixed_font_name", &fixed_name, NULL);
if (fixed_name) {
@@ -1142,7 +1144,6 @@ static void
realize (GtkWidget *widget)
{
GtkHTML *html;
- GtkStyle *style;
GdkWindow *window;
GdkWindow *bin_window;
GtkAdjustment *hadjustment;
@@ -1161,10 +1162,6 @@ realize (GtkWidget *widget)
window = gtk_widget_get_window (widget);
bin_window = gtk_layout_get_bin_window (&html->layout);
- style = gtk_widget_get_style (widget);
- style = gtk_style_attach (style, window);
- gtk_widget_set_style (widget, style);
-
gdk_window_set_events (bin_window,
(gdk_window_get_events (bin_window)
| GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK
diff --git a/gtkhtml/htmlcolorset.c b/gtkhtml/htmlcolorset.c
index 0f5fb25..494a0ac 100644
--- a/gtkhtml/htmlcolorset.c
+++ b/gtkhtml/htmlcolorset.c
@@ -35,7 +35,7 @@ html_colorset_new (GtkWidget *w)
/* these are default color settings */
- if (w && gtk_widget_get_style (w)) {
+ if (w && gtk_widget_get_style_context (w)) {
html_colorset_set_style (s, w);
} else {
s->color[HTMLLinkColor] = html_color_new_from_rgb (0, 0, 0xffff);
@@ -142,64 +142,101 @@ html_colorset_set_unchanged (HTMLColorSet *s,
}
}
-static GdkColor *
+static void
+copy_to_rgba (GdkColor *in_color,
+ GdkRGBA *out_rgba)
+{
+ g_return_if_fail (in_color != NULL);
+ g_return_if_fail (out_rgba != NULL);
+
+ out_rgba->alpha = 1.0;
+ out_rgba->red = in_color->red / 65535.0;
+ out_rgba->green = in_color->green / 65535.0;
+ out_rgba->blue = in_color->blue / 65535.0;
+}
+
+static void
get_prop_color (GtkWidget *w,
const gchar *name,
const gchar *dv,
- GdkColor *gdk_color)
+ gboolean silent_fallback,
+ GdkRGBA *out_color)
{
- GdkColor c;
GdkColor *color = NULL;
- GtkStyle *style;
+ GtkStyleContext *style_context = gtk_widget_get_style_context (w);
- style = gtk_widget_get_style (w);
gtk_widget_style_get (w, name, &color, NULL);
- if (color)
- return color;
+ if (color) {
+ copy_to_rgba (color, out_color);
+ gdk_color_free (color);
+ return;
+ }
- if (dv && gdk_color_parse (dv, &c))
- return gdk_color_copy (&c);
+ if (dv && gdk_rgba_parse (out_color, dv))
+ return;
- if (gdk_color)
- return gdk_color_copy (gdk_color);
+ if (!silent_fallback)
+ g_warning ("falling back to text color");
- g_warning ("falling back to text color");
- return (gdk_color_copy (&style->text[GTK_STATE_NORMAL]));
+ gtk_style_context_get_color (style_context, GTK_STATE_FLAG_NORMAL, out_color);
}
-#define SET_GCOLOR(t,c) \
- if (!s->changed[HTML ## t ## Color]) { \
- if (s->color[HTML ## t ## Color]) html_color_unref (s->color[HTML ## t ## Color]); \
- s->color[HTML ## t ## Color] = html_color_new_from_gdk_color (&c); \
- }
-
void
html_colorset_set_style (HTMLColorSet *s,
GtkWidget *w)
{
- GdkColor *color = NULL;
- GtkStyle *style = gtk_widget_get_style (w);
-
- SET_GCOLOR (Bg, style->base[GTK_STATE_NORMAL]);
- SET_GCOLOR (Text, style->text[GTK_STATE_NORMAL]);
- SET_GCOLOR (Highlight, style->base[GTK_STATE_SELECTED]);
- SET_GCOLOR (HighlightText, style->text[GTK_STATE_SELECTED]);
- SET_GCOLOR (HighlightNF, style->base[GTK_STATE_ACTIVE]);
- SET_GCOLOR (HighlightTextNF, style->text[GTK_STATE_ACTIVE]);
- color = get_prop_color (w, "link_color", "#0000ff", NULL);
- SET_GCOLOR (Link, *color);
- gdk_color_free (color);
- color = get_prop_color (w, "alink_color", "#0000ff", NULL);
- SET_GCOLOR (ALink, *color);
- gdk_color_free (color);
- color = get_prop_color (w, "vlink_color", "#ff0000", NULL);
- SET_GCOLOR (VLink, *color);
- gdk_color_free (color);
- color = get_prop_color (w, "spell_error_color", "#ff0000", NULL);
- SET_GCOLOR (SpellError, *color);
- gdk_color_free (color);
- color = get_prop_color (w, "cite_color", NULL, &style->text [GTK_STATE_NORMAL]);
- SET_GCOLOR (Cite, *color);
- gdk_color_free (color);
+#define SET_GCOLOR(t,rgba) \
+ if (!s->changed[HTML ## t ## Color]) { \
+ GdkColor gc; \
+ \
+ gc.pixel = -1; \
+ gc.red = rgba.red * 65535.0; \
+ gc.green = rgba.green * 65535.0; \
+ gc.blue = rgba.blue * 65535.0; \
+ \
+ if (s->color[HTML ## t ## Color]) html_color_unref (s->color[HTML ## t ## Color]); \
+ s->color[HTML ## t ## Color] = html_color_new_from_gdk_color (&gc); \
+ }
+#define SET_COLOR_FUNC(t,st,func) \
+ if (!s->changed[HTML ## t ## Color]) { \
+ GdkRGBA color_rgba; \
+ \
+ func (style_context, st, &color_rgba); \
+ \
+ SET_GCOLOR (t, color_rgba); \
+ }
+
+#define SET_COLOR_BG(t,st) SET_COLOR_FUNC (t, st, gtk_style_context_get_background_color)
+#define SET_COLOR_FG(t,st) SET_COLOR_FUNC (t, st, gtk_style_context_get_color)
+
+ GdkRGBA color;
+ GtkStyleContext *style_context = gtk_widget_get_style_context (w);
+
+ /* have text background and foreground colors same as GtkEntry */
+ gtk_style_context_save (style_context);
+ gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_ENTRY);
+ SET_COLOR_BG (Bg, GTK_STATE_FLAG_NORMAL);
+ SET_COLOR_FG (Text, GTK_STATE_FLAG_NORMAL);
+ gtk_style_context_restore (style_context);
+
+ SET_COLOR_BG (Highlight, GTK_STATE_FLAG_SELECTED);
+ SET_COLOR_FG (HighlightText, GTK_STATE_FLAG_SELECTED);
+ SET_COLOR_BG (HighlightNF, GTK_STATE_FLAG_ACTIVE);
+ SET_COLOR_FG (HighlightTextNF, GTK_STATE_FLAG_ACTIVE);
+ get_prop_color (w, "link_color", "#0000ff", FALSE, &color);
+ SET_GCOLOR (Link, color);
+ get_prop_color (w, "alink_color", "#0000ff", FALSE, &color);
+ SET_GCOLOR (ALink, color);
+ get_prop_color (w, "vlink_color", "#ff0000", FALSE, &color);
+ SET_GCOLOR (VLink, color);
+ get_prop_color (w, "spell_error_color", "#ff0000", FALSE, &color);
+ SET_GCOLOR (SpellError, color);
+ get_prop_color (w, "cite_color", NULL, TRUE, &color);
+ SET_GCOLOR (Cite, color);
+
+#undef SET_COLOR_FG
+#undef SET_COLOR_BG
+#undef SET_COLOR_FUNC
+#undef SET_GCOLOR
}
diff --git a/gtkhtml/htmlpainter.c b/gtkhtml/htmlpainter.c
index f549683..e63aabe 100644
--- a/gtkhtml/htmlpainter.c
+++ b/gtkhtml/htmlpainter.c
@@ -908,10 +908,15 @@ html_painter_alloc_font (HTMLPainter *painter,
}
if (!desc || !pango_font_description_get_family (desc)) {
+ GtkStyleContext *style_context;
+ const PangoFontDescription *font_desc;
+
if (desc)
pango_font_description_free (desc);
- desc = pango_font_description_copy (gtk_widget_get_style (painter->widget)->font_desc);
+ style_context = gtk_widget_get_style_context (painter->widget);
+ font_desc = gtk_style_context_get_font (style_context, GTK_STATE_FLAG_NORMAL);
+ desc = pango_font_description_copy (font_desc);
}
if (points)
diff --git a/gtkhtml/htmlprinter.c b/gtkhtml/htmlprinter.c
index d7a4cf5..fcd21e7 100644
--- a/gtkhtml/htmlprinter.c
+++ b/gtkhtml/htmlprinter.c
@@ -706,7 +706,8 @@ HTMLPainter *
html_printer_new (GtkWidget *widget,
GtkPrintContext *context)
{
- GtkStyle *style;
+ GtkStyleContext *style_context;
+ const PangoFontDescription *font_desc;
HTMLPrinter *printer;
HTMLPainter *painter;
@@ -715,11 +716,14 @@ html_printer_new (GtkWidget *widget,
painter = HTML_PAINTER (printer);
html_painter_set_widget (painter, widget);
- style = gtk_widget_get_style (widget);
+
+ style_context = gtk_widget_get_style_context (widget);
+ font_desc = gtk_style_context_get_font (style_context, GTK_STATE_FLAG_NORMAL);
+
painter->pango_context =
gtk_print_context_create_pango_context (context);
pango_context_set_font_description (
- painter->pango_context, style->font_desc);
+ painter->pango_context, font_desc);
return painter;
diff --git a/gtkhtml/htmltextarea.c b/gtkhtml/htmltextarea.c
index 93db07c..ef7116e 100644
--- a/gtkhtml/htmltextarea.c
+++ b/gtkhtml/htmltextarea.c
@@ -133,7 +133,8 @@ html_textarea_init (HTMLTextArea *ta,
gint col)
{
GtkWidget *sw;
- GtkStyle *style;
+ GtkStyleContext *style_context;
+ const PangoFontDescription *font_desc;
HTMLEmbedded *element;
PangoLayout *layout;
gint width, height;
@@ -156,9 +157,10 @@ html_textarea_init (HTMLTextArea *ta,
gtk_widget_show_all (sw);
html_embedded_set_widget (element, sw);
- style = gtk_widget_get_style (ta->text);
+ style_context = gtk_widget_get_style_context (ta->text);
+ font_desc = gtk_style_context_get_font (style_context, GTK_STATE_FLAG_NORMAL);
layout = pango_layout_new (gtk_widget_get_pango_context (ta->text));
- pango_layout_set_font_description (layout, style->font_desc);
+ pango_layout_set_font_description (layout, font_desc);
pango_layout_set_text (layout, "0", 1);
pango_layout_get_size (layout, &width, &height);
g_object_unref (layout);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]