[gimp/gtk3-port: 197/227] app: port GimpComboTagEntry to GtkStyleContext



commit 1b79e5a452f71de2e6c7152e4ffea2e16427cd31
Author: Michael Natterer <mitch gimp org>
Date:   Wed Feb 9 11:44:32 2011 +0100

    app: port GimpComboTagEntry to GtkStyleContext

 app/widgets/gimpcombotagentry.c |   86 +++++++++++++++++++--------------------
 app/widgets/gimpcombotagentry.h |    2 +-
 app/widgets/gimptagpopup.c      |    4 +-
 3 files changed, 45 insertions(+), 47 deletions(-)
---
diff --git a/app/widgets/gimpcombotagentry.c b/app/widgets/gimpcombotagentry.c
index 7b7e531..2b9d397 100644
--- a/app/widgets/gimpcombotagentry.c
+++ b/app/widgets/gimpcombotagentry.c
@@ -44,8 +44,7 @@ static void     gimp_combo_tag_entry_dispose           (GObject              *ob
 
 static gboolean gimp_combo_tag_entry_draw              (GtkWidget            *widget,
                                                         cairo_t              *cr);
-static void     gimp_combo_tag_entry_style_set         (GtkWidget            *widget,
-                                                        GtkStyle             *previous_style);
+static void     gimp_combo_tag_entry_style_updated     (GtkWidget            *widget);
 
 static void     gimp_combo_tag_entry_icon_press        (GtkWidget            *widget,
                                                         GtkEntryIconPosition  icon_pos,
@@ -71,11 +70,11 @@ gimp_combo_tag_entry_class_init (GimpComboTagEntryClass *klass)
   GObjectClass   *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
-  object_class->constructed = gimp_combo_tag_entry_constructed;
-  object_class->dispose     = gimp_combo_tag_entry_dispose;
+  object_class->constructed   = gimp_combo_tag_entry_constructed;
+  object_class->dispose       = gimp_combo_tag_entry_dispose;
 
-  widget_class->draw        = gimp_combo_tag_entry_draw;
-  widget_class->style_set   = gimp_combo_tag_entry_style_set;
+  widget_class->draw          = gimp_combo_tag_entry_draw;
+  widget_class->style_updated = gimp_combo_tag_entry_style_updated;
 }
 
 static void
@@ -142,9 +141,9 @@ static gboolean
 gimp_combo_tag_entry_draw (GtkWidget *widget,
                            cairo_t   *cr)
 {
-  GtkStyle     *style = gtk_widget_get_style (widget);
-  GdkRectangle  icon_area;
-  gint          x, y;
+  GtkStyleContext *style = gtk_widget_get_style_context (widget);
+  GdkRectangle     icon_area;
+  gint             x, y;
 
   cairo_save (cr);
   GTK_WIDGET_CLASS (parent_class)->draw (widget, cr);
@@ -153,72 +152,71 @@ gimp_combo_tag_entry_draw (GtkWidget *widget,
   gtk_entry_get_icon_area (GTK_ENTRY (widget), GTK_ENTRY_ICON_SECONDARY,
                            &icon_area);
 
-  gdk_cairo_rectangle (cr, &icon_area);
-  cairo_clip (cr);
-
-  gdk_cairo_set_source_color (cr, &style->base[GTK_STATE_NORMAL]);
-  cairo_paint (cr);
-
   x = icon_area.x + (icon_area.width  - 8) / 2;
   y = icon_area.y + (icon_area.height - 8) / 2;
 
-  gtk_paint_arrow (style, cr,
-                   GTK_STATE_NORMAL,
-                   GTK_SHADOW_NONE, widget, NULL,
-                   GTK_ARROW_DOWN, TRUE,
-                   x, y, 8, 8);
+  gtk_render_arrow (style, cr, G_PI, x, y, 8);
 
   return FALSE;
 }
 
 static void
-gimp_combo_tag_entry_style_set (GtkWidget *widget,
-                                GtkStyle  *previous_style)
+gimp_combo_tag_entry_style_updated (GtkWidget *widget)
 {
-  GimpComboTagEntry *entry = GIMP_COMBO_TAG_ENTRY (widget);
-  GtkStyle          *style = gtk_widget_get_style (widget);
-  GdkColor           color;
-  PangoAttribute    *attribute;
+  GimpComboTagEntry          *entry = GIMP_COMBO_TAG_ENTRY (widget);
+  GtkStyleContext            *style = gtk_widget_get_style_context (widget);
+  GdkRGBA                     color;
+  const PangoFontDescription *font_desc;
+  PangoAttribute             *attribute;
 
-  if (GTK_WIDGET_CLASS (parent_class)->style_set)
-    GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
+  GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
 
   if (entry->normal_item_attr)
     pango_attr_list_unref (entry->normal_item_attr);
   entry->normal_item_attr = pango_attr_list_new ();
 
-  if (style->font_desc)
-    {
-      attribute = pango_attr_font_desc_new (style->font_desc);
-      pango_attr_list_insert (entry->normal_item_attr, attribute);
-    }
-  color = style->text[GTK_STATE_NORMAL];
-  attribute = pango_attr_foreground_new (color.red, color.green, color.blue);
+  font_desc = gtk_style_context_get_font (style, 0);
+  attribute = pango_attr_font_desc_new (font_desc);
+  pango_attr_list_insert (entry->normal_item_attr, attribute);
+
+  gtk_style_context_get_color (style, 0, &color);
+  attribute = pango_attr_foreground_new (color.red   * 65535.99,
+                                         color.green * 65535.99,
+                                         color.blue  * 65535.99);
   pango_attr_list_insert (entry->normal_item_attr, attribute);
 
   if (entry->selected_item_attr)
     pango_attr_list_unref (entry->selected_item_attr);
   entry->selected_item_attr = pango_attr_list_copy (entry->normal_item_attr);
 
-  color = style->text[GTK_STATE_SELECTED];
-  attribute = pango_attr_foreground_new (color.red, color.green, color.blue);
+  gtk_style_context_get_color (style, GTK_STATE_FLAG_SELECTED, &color);
+  attribute = pango_attr_foreground_new (color.red   * 65535.99,
+                                         color.green * 65535.99,
+                                         color.blue  * 65535.99);
   pango_attr_list_insert (entry->selected_item_attr, attribute);
-  color = style->base[GTK_STATE_SELECTED];
-  attribute = pango_attr_background_new (color.red, color.green, color.blue);
+  gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED, &color);
+  attribute = pango_attr_background_new (color.red   * 65535.99,
+                                         color.green * 65535.99,
+                                         color.blue  * 65535.99);
   pango_attr_list_insert (entry->selected_item_attr, attribute);
 
   if (entry->insensitive_item_attr)
     pango_attr_list_unref (entry->insensitive_item_attr);
   entry->insensitive_item_attr = pango_attr_list_copy (entry->normal_item_attr);
 
-  color = style->text[GTK_STATE_INSENSITIVE];
-  attribute = pango_attr_foreground_new (color.red, color.green, color.blue);
+  gtk_style_context_get_color (style, GTK_STATE_FLAG_INSENSITIVE, &color);
+  attribute = pango_attr_foreground_new (color.red   * 65535.99,
+                                         color.green * 65535.99,
+                                         color.blue  * 65535.99);
   pango_attr_list_insert (entry->insensitive_item_attr, attribute);
-  color = style->base[GTK_STATE_INSENSITIVE];
-  attribute = pango_attr_background_new (color.red, color.green, color.blue);
+  gtk_style_context_get_background_color (style, GTK_STATE_FLAG_INSENSITIVE, &color);
+  attribute = pango_attr_background_new (color.red   * 65535.99,
+                                         color.green * 65535.99,
+                                         color.blue  * 65535.99);
   pango_attr_list_insert (entry->insensitive_item_attr, attribute);
 
-  entry->selected_item_color = style->base[GTK_STATE_SELECTED];
+  gtk_style_context_get_background_color (style, GTK_STATE_FLAG_SELECTED,
+                                          &entry->selected_item_color);
 }
 
 /**
diff --git a/app/widgets/gimpcombotagentry.h b/app/widgets/gimpcombotagentry.h
index 01e136e..c64c091 100644
--- a/app/widgets/gimpcombotagentry.h
+++ b/app/widgets/gimpcombotagentry.h
@@ -41,7 +41,7 @@ struct _GimpComboTagEntry
   PangoAttrList  *normal_item_attr;
   PangoAttrList  *selected_item_attr;
   PangoAttrList  *insensitive_item_attr;
-  GdkColor        selected_item_color;
+  GdkRGBA         selected_item_color;
 };
 
 struct _GimpComboTagEntryClass
diff --git a/app/widgets/gimptagpopup.c b/app/widgets/gimptagpopup.c
index 6c019eb..bea2d83 100644
--- a/app/widgets/gimptagpopup.c
+++ b/app/widgets/gimptagpopup.c
@@ -781,8 +781,8 @@ gimp_tag_popup_list_draw (GtkWidget    *widget,
 
       if (tag_data->state == GTK_STATE_SELECTED)
         {
-          gdk_cairo_set_source_color (cr,
-                                      &popup->combo_entry->selected_item_color);
+          gdk_cairo_set_source_rgba (cr,
+                                     &popup->combo_entry->selected_item_color);
 
           cairo_rectangle (cr,
                            tag_data->bounds.x - 1,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]