[glade/tintou/more-g-declare: 5/11] gladeui: Use G_DECLARE_DERIVABLE_TYPE for GladeClipboard



commit 6d4b1905de9103e94cf510d7321f7735e4cfa2a0
Author: Corentin Noël <corentin noel collabora com>
Date:   Fri Aug 16 16:48:57 2019 +0200

    gladeui: Use G_DECLARE_DERIVABLE_TYPE for GladeClipboard

 gladeui/glade-clipboard.c | 40 ++++++++++++++++++++++++----------------
 gladeui/glade-clipboard.h | 24 +++---------------------
 2 files changed, 27 insertions(+), 37 deletions(-)
---
diff --git a/gladeui/glade-clipboard.c b/gladeui/glade-clipboard.c
index a77c72b5..93af915b 100644
--- a/gladeui/glade-clipboard.c
+++ b/gladeui/glade-clipboard.c
@@ -40,11 +40,11 @@
 #include "glade-placeholder.h"
 #include "glade-project.h"
 
-struct _GladeClipboardPrivate
+typedef struct _GladeClipboardPrivate
 {
   GList     *widgets;       /* A list of GladeWidget's on the clipboard */
   gboolean   has_selection; /* TRUE if clipboard has selection */
-};
+} GladeClipboardPrivate;
 
 enum
 {
@@ -64,11 +64,12 @@ glade_project_get_property (GObject    *object,
                             GParamSpec *pspec)
 {
   GladeClipboard *clipboard = GLADE_CLIPBOARD (object);
+  GladeClipboardPrivate *priv = glade_clipboard_get_instance_private (clipboard);
 
   switch (prop_id)
     {
       case PROP_HAS_SELECTION:
-        g_value_set_boolean (value, clipboard->priv->has_selection);
+        g_value_set_boolean (value, priv->has_selection);
         break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -99,19 +100,21 @@ glade_clipboard_class_init (GladeClipboardClass * klass)
 static void
 glade_clipboard_init (GladeClipboard *clipboard)
 {
-  clipboard->priv = glade_clipboard_get_instance_private (clipboard);
+  GladeClipboardPrivate *priv = glade_clipboard_get_instance_private (clipboard);
 
-  clipboard->priv->widgets = NULL;
-  clipboard->priv->has_selection = FALSE;
+  priv->widgets = NULL;
+  priv->has_selection = FALSE;
 }
 
 static void
 glade_clipboard_set_has_selection (GladeClipboard *clipboard,
                                    gboolean        has_selection)
 {
-  if (clipboard->priv->has_selection != has_selection)
+  GladeClipboardPrivate *priv = glade_clipboard_get_instance_private (clipboard);
+
+  if (priv->has_selection != has_selection)
     {
-      clipboard->priv->has_selection = has_selection;
+      priv->has_selection = has_selection;
       g_object_notify_by_pspec (G_OBJECT (clipboard), properties[PROP_HAS_SELECTION]);
     }
 
@@ -126,9 +129,11 @@ glade_clipboard_set_has_selection (GladeClipboard *clipboard,
 gboolean
 glade_clipboard_get_has_selection (GladeClipboard *clipboard)
 {
+  GladeClipboardPrivate *priv = glade_clipboard_get_instance_private (clipboard);
+
   g_return_val_if_fail (GLADE_IS_CLIPBOARD (clipboard), FALSE);
 
-  return clipboard->priv->has_selection;
+  return priv->has_selection;
 }
 
 /**
@@ -140,10 +145,11 @@ glade_clipboard_get_has_selection (GladeClipboard *clipboard)
 GList *
 glade_clipboard_widgets (GladeClipboard *clipboard)
 {
-  g_return_val_if_fail (GLADE_IS_CLIPBOARD (clipboard), NULL);
+  GladeClipboardPrivate *priv = glade_clipboard_get_instance_private (clipboard);
 
+  g_return_val_if_fail (GLADE_IS_CLIPBOARD (clipboard), NULL);
 
-  return clipboard->priv->widgets;
+  return priv->widgets;
 }
 
 /**
@@ -168,6 +174,7 @@ glade_clipboard_new (void)
 void
 glade_clipboard_add (GladeClipboard *clipboard, GList *widgets)
 {
+  GladeClipboardPrivate *priv = glade_clipboard_get_instance_private (clipboard);
   GladeWidget *widget;
   GList *list;
 
@@ -181,8 +188,8 @@ glade_clipboard_add (GladeClipboard *clipboard, GList *widgets)
   for (list = widgets; list && list->data; list = list->next)
     {
       widget = list->data;
-      clipboard->priv->widgets =
-          g_list_prepend (clipboard->priv->widgets, g_object_ref_sink (G_OBJECT (widget)));
+      priv->widgets =
+          g_list_prepend (priv->widgets, g_object_ref_sink (G_OBJECT (widget)));
     }
 
   glade_clipboard_set_has_selection (clipboard, TRUE);
@@ -197,20 +204,21 @@ glade_clipboard_add (GladeClipboard *clipboard, GList *widgets)
 void
 glade_clipboard_clear (GladeClipboard *clipboard)
 {
+  GladeClipboardPrivate *priv = glade_clipboard_get_instance_private (clipboard);
   GladeWidget *widget;
   GList *list;
 
   g_return_if_fail (GLADE_IS_CLIPBOARD (clipboard));
 
-  for (list = clipboard->priv->widgets; list && list->data; list = list->next)
+  for (list = priv->widgets; list && list->data; list = list->next)
     {
       widget = list->data;
 
       g_object_unref (G_OBJECT (widget));
     }
 
-  clipboard->priv->widgets = 
-    (g_list_free (clipboard->priv->widgets), NULL);
+  priv->widgets = 
+    (g_list_free (priv->widgets), NULL);
 
   glade_clipboard_set_has_selection (clipboard, FALSE);
 }
diff --git a/gladeui/glade-clipboard.h b/gladeui/glade-clipboard.h
index b0d23299..e61712f5 100644
--- a/gladeui/glade-clipboard.h
+++ b/gladeui/glade-clipboard.h
@@ -5,34 +5,16 @@
 
 G_BEGIN_DECLS
 
-#define GLADE_TYPE_CLIPBOARD    (glade_clipboard_get_type ())
-#define GLADE_CLIPBOARD(obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_CLIPBOARD, GladeClipboard))
-#define GLADE_IS_CLIPBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_CLIPBOARD))
-
-typedef struct _GladeClipboard        GladeClipboard;
-typedef struct _GladeClipboardClass   GladeClipboardClass;
-typedef struct _GladeClipboardPrivate GladeClipboardPrivate;
-
-struct _GladeClipboard
-{
-  GObject    parent_instance;
-
-  GladeClipboardPrivate *priv;
-};
+#define GLADE_TYPE_CLIPBOARD glade_clipboard_get_type ()
+G_DECLARE_DERIVABLE_TYPE (GladeClipboard, glade_clipboard, GLADE, CLIPBOARD, GObject)
 
 struct _GladeClipboardClass
 {
   GObjectClass parent_class;
 
-  void   (* glade_reserved1)   (void);
-  void   (* glade_reserved2)   (void);
-  void   (* glade_reserved3)   (void);
-  void   (* glade_reserved4)   (void);
+  gpointer padding[4];
 };
 
-
-GType           glade_clipboard_get_type         (void);
-
 GladeClipboard *glade_clipboard_new              (void);
 void            glade_clipboard_add              (GladeClipboard *clipboard, 
                                                   GList          *widgets);


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