[gnome-control-center/wip/jsparber/background: 28/45] background: change base obj of CcBackgroundGridItem



commit ec00a1558ddb112f89cc2ed31ea30e67e8029099
Author: Julian Sparber <julian sparber net>
Date:   Thu Feb 1 13:44:03 2018 +0100

    background: change base obj of CcBackgroundGridItem
    
    CcBackgroundGridItem derives directly from GtkDrawingWidget.
    And some small code style fixes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=788515

 panels/background/cc-background-grid-item.c |   39 ++++++++++----------------
 panels/background/cc-background-grid-item.h |    6 ++--
 panels/background/cc-background-panel.c     |    6 ++--
 3 files changed, 21 insertions(+), 30 deletions(-)
---
diff --git a/panels/background/cc-background-grid-item.c b/panels/background/cc-background-grid-item.c
index e665097..d18068f 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_item 
(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,11 +133,10 @@ on_gallery_item_draw (GtkWidget            *widget,
   return TRUE;
 }
 
-GtkWidget*
+GtkDrawingArea*
 cc_background_grid_item_new (CcBackgroundItem *item,
                              GdkPixbuf        *pixbuf)
 {
-
   return g_object_new (CC_TYPE_BACKGROUND_GRID_ITEM,
                        "item", item,
                        "cached_pixbuf", pixbuf,
@@ -147,22 +146,19 @@ cc_background_grid_item_new (CcBackgroundItem *item,
 CcBackgroundItem*
 cc_background_grid_item_get_item (GtkWidget *widget)
 {
-  CcBackgroundGridItem *self = (CcBackgroundGridItem *) widget;
-  return self->item;
-}
-static void
-cc_background_grid_item_set_item (GtkWidget        *widget,
-                                  CcBackgroundItem *item)
-{
-  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
@@ -247,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 32316c0..f67736c 100644
--- a/panels/background/cc-background-grid-item.h
+++ b/panels/background/cc-background-grid-item.h
@@ -29,11 +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             *,
+GtkDrawingArea         *cc_background_grid_item_new             (CcBackgroundItem             *,
                                                                  GdkPixbuf                    *);
-CcBackgroundItem *      cc_background_grid_item_get_item        (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 c0b1736..883e7b7 100644
--- a/panels/background/cc-background-panel.c
+++ b/panels/background/cc-background-panel.c
@@ -589,10 +589,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_item (selected);
+  item = cc_background_grid_item_get_item (widget);
 
   set_background (panel, panel->settings, item);
   set_background (panel, panel->lock_settings, item);
@@ -705,7 +705,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]