[gtk+/wip/baedert/widget-templates: 9/9] recentchooserwidget: Inherit from GtkWidget



commit 6f7f102fcb9f7615cfd945d4a15a348d0f44d345
Author: Timm Bäder <mail baedert org>
Date:   Sat Mar 25 21:19:44 2017 +0100

    recentchooserwidget: Inherit from GtkWidget

 gtk/gtkrecentchooserdialog.c |    2 +-
 gtk/gtkrecentchooserwidget.c |   55 +++++++++++++++++++++++++++++++++++++----
 gtk/gtkrecentchooserwidget.h |    6 ++--
 3 files changed, 53 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkrecentchooserdialog.c b/gtk/gtkrecentchooserdialog.c
index 63c3351..d53c554 100644
--- a/gtk/gtkrecentchooserdialog.c
+++ b/gtk/gtkrecentchooserdialog.c
@@ -25,6 +25,7 @@
 #include "gtktypebuiltins.h"
 #include "gtksettings.h"
 #include "gtkdialogprivate.h"
+#include "gtkbox.h"
 
 #include <stdarg.h>
 
@@ -206,7 +207,6 @@ gtk_recent_chooser_dialog_constructed (GObject *object)
 
   gtk_box_pack_start (GTK_BOX (content_area),
                       priv->chooser, TRUE, TRUE);
-  gtk_widget_show (priv->chooser);
 
   _gtk_recent_chooser_set_delegate (GTK_RECENT_CHOOSER (object),
                                    GTK_RECENT_CHOOSER (priv->chooser));
diff --git a/gtk/gtkrecentchooserwidget.c b/gtk/gtkrecentchooserwidget.c
index 2209a07..fa527db 100644
--- a/gtk/gtkrecentchooserwidget.c
+++ b/gtk/gtkrecentchooserwidget.c
@@ -62,7 +62,7 @@ static void     gtk_recent_chooser_widget_finalize     (GObject               *o
 
 G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserWidget,
                         gtk_recent_chooser_widget,
-                        GTK_TYPE_BOX,
+                         GTK_TYPE_WIDGET,
                          G_ADD_PRIVATE (GtkRecentChooserWidget)
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
                                                _gtk_recent_chooser_delegate_iface_init))
@@ -74,8 +74,8 @@ gtk_recent_chooser_widget_constructed (GObject *gobject)
 
   self->priv->chooser = _gtk_recent_chooser_default_new (self->priv->manager);
 
-  gtk_container_add (GTK_CONTAINER (self), self->priv->chooser);
-  gtk_widget_show (self->priv->chooser);
+  gtk_widget_set_parent (self->priv->chooser, GTK_WIDGET (self));
+
   _gtk_recent_chooser_set_delegate (GTK_RECENT_CHOOSER (self),
                                    GTK_RECENT_CHOOSER (self->priv->chooser));
 }
@@ -120,20 +120,64 @@ gtk_recent_chooser_widget_finalize (GObject *object)
   GtkRecentChooserWidget *self = GTK_RECENT_CHOOSER_WIDGET (object);
 
   self->priv->manager = NULL;
-  
+
+  gtk_widget_unparent (self->priv->chooser);
+
   G_OBJECT_CLASS (gtk_recent_chooser_widget_parent_class)->finalize (object);
 }
 
 static void
+gtk_recent_chooser_widget_measure (GtkWidget       *widget,
+                                 GtkOrientation  orientation,
+                                 int             for_size,
+                                 int            *minimum,
+                                 int            *natural,
+                                 int            *minimum_baseline,
+                                 int            *natural_baseline)
+{
+  GtkRecentChooserWidget *self = GTK_RECENT_CHOOSER_WIDGET (widget);
+  GtkRecentChooserWidgetPrivate *priv = gtk_recent_chooser_widget_get_instance_private (self);
+
+  gtk_widget_measure (priv->chooser, orientation, for_size,
+                      minimum, natural,
+                      minimum_baseline, natural_baseline);
+}
+
+static void
+gtk_recent_chooser_widget_snapshot (GtkWidget   *widget,
+                                  GtkSnapshot *snapshot)
+{
+  GtkRecentChooserWidget *self = GTK_RECENT_CHOOSER_WIDGET (widget);
+  GtkRecentChooserWidgetPrivate *priv = gtk_recent_chooser_widget_get_instance_private (self);
+
+  gtk_widget_snapshot_child (widget, priv->chooser, snapshot);
+}
+
+static void
+gtk_recent_chooser_widget_size_allocate (GtkWidget     *widget,
+                                       GtkAllocation *allocation)
+{
+  GtkRecentChooserWidget *self = GTK_RECENT_CHOOSER_WIDGET (widget);
+  GtkRecentChooserWidgetPrivate *priv = gtk_recent_chooser_widget_get_instance_private (self);
+
+  gtk_widget_size_allocate (priv->chooser, allocation);
+}
+
+static void
 gtk_recent_chooser_widget_class_init (GtkRecentChooserWidgetClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   gobject_class->constructed = gtk_recent_chooser_widget_constructed;
   gobject_class->set_property = gtk_recent_chooser_widget_set_property;
   gobject_class->get_property = gtk_recent_chooser_widget_get_property;
   gobject_class->finalize = gtk_recent_chooser_widget_finalize;
 
+  widget_class->measure = gtk_recent_chooser_widget_measure;
+  widget_class->size_allocate = gtk_recent_chooser_widget_size_allocate;
+  widget_class->snapshot = gtk_recent_chooser_widget_snapshot;
+
   _gtk_recent_chooser_install_properties (gobject_class);
 }
 
@@ -142,8 +186,7 @@ gtk_recent_chooser_widget_init (GtkRecentChooserWidget *widget)
 {
   widget->priv = gtk_recent_chooser_widget_get_instance_private (widget);
 
-  gtk_orientable_set_orientation (GTK_ORIENTABLE (widget),
-                                  GTK_ORIENTATION_VERTICAL);
+  gtk_widget_set_has_window (GTK_WIDGET (widget), FALSE);
 }
 
 /*
diff --git a/gtk/gtkrecentchooserwidget.h b/gtk/gtkrecentchooserwidget.h
index b4331be..c5dcc65 100644
--- a/gtk/gtkrecentchooserwidget.h
+++ b/gtk/gtkrecentchooserwidget.h
@@ -24,7 +24,7 @@
 #endif
 
 #include <gtk/gtkrecentchooser.h>
-#include <gtk/gtkbox.h>
+#include <gtk/gtkwidget.h>
 
 G_BEGIN_DECLS
 
@@ -42,7 +42,7 @@ typedef struct _GtkRecentChooserWidgetPrivate GtkRecentChooserWidgetPrivate;
 
 struct _GtkRecentChooserWidget
 {
-  GtkBox parent_instance;
+  GtkWidget parent_instance;
 
   /*< private >*/
   GtkRecentChooserWidgetPrivate *priv;
@@ -50,7 +50,7 @@ struct _GtkRecentChooserWidget
 
 struct _GtkRecentChooserWidgetClass
 {
-  GtkBoxClass parent_class;
+  GtkWidgetClass parent_class;
 
   /* Padding for future expansion */
   void (*_gtk_reserved1) (void);


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