[libdazzle] suggestion: add API to get generated icon surface



commit 294d8dc7e6a30e9c7115f2e8e082d99b50a445dd
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jul 17 15:27:41 2018 -0700

    suggestion: add API to get generated icon surface
    
    This API allows suggestions to generate a cairo surface to be used when
    displaying the row to the user. The widget is provided so that any scale
    or style information may be extracted.

 src/suggestions/dzl-suggestion-row.c | 14 ++++++++--
 src/suggestions/dzl-suggestion.c     | 28 +++++++++++++++++++
 src/suggestions/dzl-suggestion.h     | 54 +++++++++++++++++++-----------------
 3 files changed, 68 insertions(+), 28 deletions(-)
---
diff --git a/src/suggestions/dzl-suggestion-row.c b/src/suggestions/dzl-suggestion-row.c
index a623395..7005281 100644
--- a/src/suggestions/dzl-suggestion-row.c
+++ b/src/suggestions/dzl-suggestion-row.c
@@ -61,14 +61,22 @@ static void
 dzl_suggestion_row_connect (DzlSuggestionRow *self)
 {
   DzlSuggestionRowPrivate *priv = dzl_suggestion_row_get_instance_private (self);
-  g_autoptr(GIcon) icon = NULL;
+  cairo_surface_t *surface;
   const gchar *subtitle;
 
   g_return_if_fail (DZL_IS_SUGGESTION_ROW (self));
   g_return_if_fail (priv->suggestion != NULL);
 
-  icon = dzl_suggestion_get_icon (priv->suggestion);
-  gtk_image_set_from_gicon (priv->image, icon, GTK_ICON_SIZE_MENU);
+  if ((surface = dzl_suggestion_get_icon_surface (priv->suggestion, GTK_WIDGET (priv->image))))
+    {
+      gtk_image_set_from_surface (priv->image, surface);
+      cairo_surface_destroy (surface);
+    }
+  else
+    {
+      g_autoptr(GIcon) icon = dzl_suggestion_get_icon (priv->suggestion);
+      gtk_image_set_from_gicon (priv->image, icon, GTK_ICON_SIZE_MENU);
+    }
 
   gtk_label_set_label (priv->title, dzl_suggestion_get_title (priv->suggestion));
 
diff --git a/src/suggestions/dzl-suggestion.c b/src/suggestions/dzl-suggestion.c
index 6d9b949..1b6e70e 100644
--- a/src/suggestions/dzl-suggestion.c
+++ b/src/suggestions/dzl-suggestion.c
@@ -403,3 +403,31 @@ dzl_suggestion_get_icon (DzlSuggestion *self)
 
   return DZL_SUGGESTION_GET_CLASS (self)->get_icon (self);
 }
+
+/**
+ * dzl_suggestion_get_icon_surface:
+ * @self: a #DzlSuggestion
+ * @widget: a widget that may contain the surface
+ *
+ * This function allows subclasses to dynamicly generate content for the
+ * suggestion such as may be required when integrating with favicons or
+ * similar.
+ *
+ * @widget is provided so that the implementation may determine scale or
+ * any other style-specific settings from the style context.
+ *
+ * Returns: (transfer full) (nullable): a #cairo_surface_t or %NULL
+ *
+ * Since: 3.30
+ */
+cairo_surface_t *
+dzl_suggestion_get_icon_surface (DzlSuggestion *self,
+                                 GtkWidget     *widget)
+{
+  g_return_val_if_fail (DZL_IS_SUGGESTION (self), NULL);
+
+  if (DZL_SUGGESTION_GET_CLASS (self)->get_icon_surface)
+    return DZL_SUGGESTION_GET_CLASS (self)->get_icon_surface (self, widget);
+
+  return NULL;
+}
diff --git a/src/suggestions/dzl-suggestion.h b/src/suggestions/dzl-suggestion.h
index 5fc141b..442dac5 100644
--- a/src/suggestions/dzl-suggestion.h
+++ b/src/suggestions/dzl-suggestion.h
@@ -20,7 +20,7 @@
 #ifndef DZL_SUGGESTION_H
 #define DZL_SUGGESTION_H
 
-#include <gio/gio.h>
+#include <gtk/gtk.h>
 
 #include "dzl-version-macros.h"
 
@@ -35,47 +35,51 @@ struct _DzlSuggestionClass
 {
   GObjectClass parent_class;
 
-  gchar *(*suggest_suffix)     (DzlSuggestion *self,
-                                const gchar   *typed_text);
-  gchar *(*replace_typed_text) (DzlSuggestion *self,
-                                const gchar   *typed_text);
-  GIcon *(*get_icon)           (DzlSuggestion *self);
+  gchar           *(*suggest_suffix)     (DzlSuggestion *self,
+                                          const gchar   *typed_text);
+  gchar           *(*replace_typed_text) (DzlSuggestion *self,
+                                          const gchar   *typed_text);
+  GIcon           *(*get_icon)           (DzlSuggestion *self);
+  cairo_surface_t *(*get_icon_surface)   (DzlSuggestion *self,
+                                          GtkWidget     *widget);
 
-  gpointer _reserved2;
   gpointer _reserved3;
   gpointer _reserved4;
 };
 
 DZL_AVAILABLE_IN_ALL
-DzlSuggestion *dzl_suggestion_new                (void);
+DzlSuggestion   *dzl_suggestion_new                (void);
 DZL_AVAILABLE_IN_ALL
-const gchar   *dzl_suggestion_get_id             (DzlSuggestion *self);
+const gchar     *dzl_suggestion_get_id             (DzlSuggestion *self);
 DZL_AVAILABLE_IN_ALL
-void           dzl_suggestion_set_id             (DzlSuggestion *self,
-                                                  const gchar   *id);
+void             dzl_suggestion_set_id             (DzlSuggestion *self,
+                                                    const gchar   *id);
 DZL_AVAILABLE_IN_ALL
-const gchar   *dzl_suggestion_get_icon_name      (DzlSuggestion *self);
+const gchar     *dzl_suggestion_get_icon_name      (DzlSuggestion *self);
 DZL_AVAILABLE_IN_ALL
-void           dzl_suggestion_set_icon_name      (DzlSuggestion *self,
-                                                  const gchar   *icon_name);
+void             dzl_suggestion_set_icon_name      (DzlSuggestion *self,
+                                                    const gchar   *icon_name);
 DZL_AVAILABLE_IN_ALL
-const gchar   *dzl_suggestion_get_title          (DzlSuggestion *self);
+const gchar     *dzl_suggestion_get_title          (DzlSuggestion *self);
 DZL_AVAILABLE_IN_ALL
-void           dzl_suggestion_set_title          (DzlSuggestion *self,
-                                                  const gchar   *title);
+void             dzl_suggestion_set_title          (DzlSuggestion *self,
+                                                    const gchar   *title);
 DZL_AVAILABLE_IN_ALL
-const gchar   *dzl_suggestion_get_subtitle       (DzlSuggestion *self);
+const gchar     *dzl_suggestion_get_subtitle       (DzlSuggestion *self);
 DZL_AVAILABLE_IN_ALL
-void           dzl_suggestion_set_subtitle       (DzlSuggestion *self,
-                                                  const gchar   *subtitle);
+void             dzl_suggestion_set_subtitle       (DzlSuggestion *self,
+                                                    const gchar   *subtitle);
 DZL_AVAILABLE_IN_ALL
-gchar         *dzl_suggestion_suggest_suffix     (DzlSuggestion *self,
-                                                  const gchar   *typed_text);
+gchar           *dzl_suggestion_suggest_suffix     (DzlSuggestion *self,
+                                                    const gchar   *typed_text);
 DZL_AVAILABLE_IN_ALL
-gchar         *dzl_suggestion_replace_typed_text (DzlSuggestion *self,
-                                                  const gchar   *typed_text);
+gchar           *dzl_suggestion_replace_typed_text (DzlSuggestion *self,
+                                                    const gchar   *typed_text);
 DZL_AVAILABLE_IN_3_30
-GIcon         *dzl_suggestion_get_icon           (DzlSuggestion *self);
+GIcon           *dzl_suggestion_get_icon           (DzlSuggestion *self);
+DZL_AVAILABLE_IN_3_30
+cairo_surface_t *dzl_suggestion_get_icon_surface   (DzlSuggestion *self,
+                                                    GtkWidget     *widget);
 
 G_END_DECLS
 


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