[gnome-control-center/wip/jsparber/background: 1/10] background: refactor cc-background-grid-item



commit 4814bf13d4c0b7b541cb57451dd439247204f55d
Author: Julian Sparber <julian sparber net>
Date:   Mon Jan 15 15:49:49 2018 +0100

    background: refactor cc-background-grid-item
    
    - make cc_background_grid_item_set_ref static and private
    - change cc_background_grid_item_get_ref to cc_background_grid_item_get_item
    - change base obj of CcBackgroundGridItem
      CcBackgroundGridItem derives directly from GtkDrawingWidget
    - CcBackgroundGridItem::new returns its own type
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788515

 panels/background/cc-background-grid-item.c | 42 ++++++++++++-----------------
 panels/background/cc-background-grid-item.h |  8 +++---
 panels/background/cc-background-panel.c     |  6 ++---
 3 files changed, 23 insertions(+), 33 deletions(-)
---
diff --git a/panels/background/cc-background-grid-item.c b/panels/background/cc-background-grid-item.c
index 87eeb8b08..5fc28e2d2 100644
--- a/panels/background/cc-background-grid-item.c
+++ b/panels/background/cc-background-grid-item.c
@@ -33,7 +33,7 @@ struct _CcBackgroundGridItem
   GdkPixbuf             *cached_pixbuf;
 };
 
-G_DEFINE_TYPE (CcBackgroundGridItem, cc_background_grid_item, GTK_TYPE_FLOW_BOX_CHILD)
+G_DEFINE_TYPE (CcBackgroundGridItem, cc_background_grid_item, GTK_TYPE_DRAWING_AREA)
 
     enum {
       PROP_0,
@@ -96,7 +96,7 @@ on_gallery_item_draw (GtkWidget            *widget,
                       cairo_t              *cr,
                       CcBackgroundGridItem *item)
 {
-  GdkPixbuf *pixbuf = item->cached_pixbuf;
+  GdkPixbuf *pixbuf = ((CcBackgroundGridItem *) widget)->cached_pixbuf;
   GdkPixbuf *new_pixbuf;
   const gint space_width = gtk_widget_get_allocated_width (widget);
   const gint space_height = gtk_widget_get_allocated_height ( (widget));
@@ -118,7 +118,7 @@ on_gallery_item_draw (GtkWidget            *widget,
                                         new_height,
                                         GDK_INTERP_BILINEAR);
 
-  if (cc_background_item_changes_with_time (cc_background_grid_item_get_ref 
(gtk_widget_get_parent(widget)))) {
+  if (cc_background_item_changes_with_time (cc_background_grid_item_get_item (widget))) {
     add_slideshow_emblem (new_pixbuf, (space_width + new_width) / 2, (space_height + new_height)/2, 
scale_factor);
   }
 
@@ -133,35 +133,32 @@ on_gallery_item_draw (GtkWidget            *widget,
   return TRUE;
 }
 
-GtkWidget*
+CcBackgroundGridItem *
 cc_background_grid_item_new (CcBackgroundItem *item,
                              GdkPixbuf        *pixbuf)
 {
-
   return g_object_new (CC_TYPE_BACKGROUND_GRID_ITEM,
                        "item", item,
                        "cached_pixbuf", pixbuf,
                        NULL);
 }
 
-CcBackgroundItem * cc_background_grid_item_get_ref (GtkWidget *widget)
-{
-  CcBackgroundGridItem *self = (CcBackgroundGridItem *) widget;
-  return self->item;
-}
-void
-cc_background_grid_item_set_ref (GtkWidget        *widget,
-                                 CcBackgroundItem *item)
+CcBackgroundItem*
+cc_background_grid_item_get_item (GtkWidget *widget)
 {
-  CcBackgroundGridItem *self = (CcBackgroundGridItem *) widget;
-  self->item = item;
+  if (GTK_IS_DRAWING_AREA (widget)) {
+    CcBackgroundGridItem *self = (CcBackgroundGridItem *) widget;
+    return self->item;
+  }
+  else {
+    return NULL;
+  }
 }
 
 static void
 cc_background_grid_item_finalize (GObject *object)
 {
   G_OBJECT_CLASS (cc_background_grid_item_parent_class)->finalize (object);
-
 }
 
 static void
@@ -246,15 +243,10 @@ cc_background_grid_item_class_init (CcBackgroundGridItemClass *klass)
 static void
 cc_background_grid_item_init (CcBackgroundGridItem *self)
 {
-  GtkWidget *drawing;
-
-  drawing = gtk_drawing_area_new ();
-  gtk_widget_set_hexpand(drawing, TRUE);
-  gtk_widget_set_vexpand(drawing, TRUE);
-  g_signal_connect (G_OBJECT (drawing), "draw",
-                    G_CALLBACK (on_gallery_item_draw), self);
+  gtk_widget_set_hexpand(GTK_WIDGET (self), TRUE);
+  gtk_widget_set_vexpand(GTK_WIDGET (self), TRUE);
+  g_signal_connect (G_OBJECT (self), "draw",
+                    G_CALLBACK (on_gallery_item_draw), NULL);
 
   gtk_widget_set_size_request (GTK_WIDGET(self), 250, 200);
-  gtk_widget_show (drawing);
-  gtk_container_add (GTK_CONTAINER (self), drawing);
 }
diff --git a/panels/background/cc-background-grid-item.h b/panels/background/cc-background-grid-item.h
index af1b92fb6..3778f55a2 100644
--- a/panels/background/cc-background-grid-item.h
+++ b/panels/background/cc-background-grid-item.h
@@ -29,13 +29,11 @@ G_BEGIN_DECLS
 
 #define CC_TYPE_BACKGROUND_GRID_ITEM (cc_background_grid_item_get_type())
 
-G_DECLARE_FINAL_TYPE (CcBackgroundGridItem, cc_background_grid_item, CC, BACKGROUND_GRID_LIST, 
GtkFlowBoxChild)
+G_DECLARE_FINAL_TYPE (CcBackgroundGridItem, cc_background_grid_item, CC, BACKGROUND_GRID_LIST, 
GtkDrawingArea)
 
-GtkWidget *             cc_background_grid_item_new             (CcBackgroundItem             *,
+CcBackgroundGridItem   *cc_background_grid_item_new             (CcBackgroundItem             *,
                                                                  GdkPixbuf                    *);
-void                    cc_background_grid_item_set_ref         (GtkWidget                    *,
-                                                                 CcBackgroundItem             *);
-CcBackgroundItem *      cc_background_grid_item_get_ref         (GtkWidget                    *);
+CcBackgroundItem       *cc_background_grid_item_get_item        (GtkWidget                    *);
 
 G_END_DECLS
 
diff --git a/panels/background/cc-background-panel.c b/panels/background/cc-background-panel.c
index 47d69c0ec..d8ed1fa6a 100644
--- a/panels/background/cc-background-panel.c
+++ b/panels/background/cc-background-panel.c
@@ -379,10 +379,10 @@ on_background_select (GtkFlowBox      *box,
                       GtkFlowBoxChild *child,
                       gpointer         user_data)
 {
-  GtkWidget *selected = GTK_WIDGET (child);
+  GtkWidget *widget = gtk_bin_get_child (GTK_BIN (child));
   CcBackgroundPanel *panel = user_data;
   CcBackgroundItem *item;
-  item = cc_background_grid_item_get_ref (selected);
+  item = cc_background_grid_item_get_item (widget);
 
   set_background (panel, panel->settings, item);
   set_background (panel, panel->lock_settings, item);
@@ -495,7 +495,7 @@ create_gallery_item (gpointer item,
                                                    preview_height,
                                                    scale_factor,
                                                    -2, TRUE);
-  flow = cc_background_grid_item_new(self, pixbuf);
+  flow = GTK_WIDGET (cc_background_grid_item_new(self, pixbuf));
   return flow;
 }
 


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