[libgda] gdaui-grid: removed private from public API



commit 26dc24f80a8d78afea120aa39038eaeb0f8c3aae
Author: Daniel Espinosa <esodan gmail com>
Date:   Mon Sep 10 09:04:35 2018 -0500

    gdaui-grid: removed private from public API

 libgda-ui/gdaui-grid.c | 173 ++++++++++++++++++++++++-------------------------
 libgda-ui/gdaui-grid.h |  21 +-----
 2 files changed, 88 insertions(+), 106 deletions(-)
---
diff --git a/libgda-ui/gdaui-grid.c b/libgda-ui/gdaui-grid.c
index 9b58158f5..b26098352 100644
--- a/libgda-ui/gdaui-grid.c
+++ b/libgda-ui/gdaui-grid.c
@@ -2,6 +2,7 @@
  * Copyright (C) 2009 - 2015 Vivien Malerba <malerba gnome-db org>
  * Copyright (C) 2010 David King <davidk openismus com>
  * Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
+ * Copyright (C) 2018 Daniel Espinosa <esodan gmail com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -29,8 +30,6 @@
 #include "gdaui-data-proxy-info.h"
 #include "gdaui-enum-types.h"
 
-static void gdaui_grid_class_init (GdauiGridClass * class);
-static void gdaui_grid_init (GdauiGrid *wid);
 static void gdaui_grid_dispose (GObject *object);
 
 static void gdaui_grid_set_property (GObject *object,
@@ -61,14 +60,17 @@ static gboolean          gdaui_grid_selector_select_row (GdauiDataSelector *ifac
 static void              gdaui_grid_selector_unselect_row (GdauiDataSelector *iface, gint row);
 static void              gdaui_grid_selector_set_column_visible (GdauiDataSelector *iface, gint column, 
gboolean visible);
 
-struct _GdauiGridPriv
+typedef struct
 {
        GtkWidget *raw_grid;
        GtkWidget *info;
-};
+} GdauiGridPrivate;
+
+G_DEFINE_TYPE_WITH_CODE(GdauiGrid, gdaui_grid, GTK_TYPE_BOX,
+                        G_ADD_PRIVATE (GdauiGrid)
+                        G_IMPLEMENT_INTERFACE(GDAUI_TYPE_DATA_PROXY, gdaui_grid_widget_init)
+                        G_IMPLEMENT_INTERFACE(GDAUI_TYPE_DATA_SELECTOR, gdaui_grid_selector_init))
 
-/* get a pointer to the parents to be able to call their destructor */
-static GObjectClass *parent_class = NULL;
 
 /* properties */
 enum {
@@ -79,45 +81,6 @@ enum {
        PROP_INFO_FLAGS
 };
 
-GType
-gdaui_grid_get_type (void)
-{
-       static GType type = 0;
-
-       if (G_UNLIKELY (type == 0)) {
-               static const GTypeInfo info = {
-                       sizeof (GdauiGridClass),
-                       (GBaseInitFunc) NULL,
-                       (GBaseFinalizeFunc) NULL,
-                       (GClassInitFunc) gdaui_grid_class_init,
-                       NULL,
-                       NULL,
-                       sizeof (GdauiGrid),
-                       0,
-                       (GInstanceInitFunc) gdaui_grid_init,
-                       0
-               };
-
-               static const GInterfaceInfo proxy_info = {
-                        (GInterfaceInitFunc) gdaui_grid_widget_init,
-                        NULL,
-                        NULL
-                };
-
-               static const GInterfaceInfo selector_info = {
-                        (GInterfaceInitFunc) gdaui_grid_selector_init,
-                        NULL,
-                        NULL
-                };
-
-               type = g_type_register_static (GTK_TYPE_BOX, "GdauiGrid", &info, 0);
-               g_type_add_interface_static (type, GDAUI_TYPE_DATA_PROXY, &proxy_info);
-               g_type_add_interface_static (type, GDAUI_TYPE_DATA_SELECTOR, &selector_info);
-
-       }
-
-       return type;
-}
 
 static void
 gdaui_grid_widget_init (GdauiDataProxyInterface *iface)
@@ -147,7 +110,6 @@ gdaui_grid_class_init (GdauiGridClass *class)
 {
        GObjectClass   *object_class = G_OBJECT_CLASS (class);
 
-       parent_class = g_type_class_peek_parent (class);
        object_class->dispose = gdaui_grid_dispose;
 
        /* Properties */
@@ -183,9 +145,9 @@ gdaui_grid_init (GdauiGrid *grid)
 {
        GtkWidget *sw;
 
-       grid->priv = g_new0 (GdauiGridPriv, 1);
-       grid->priv->raw_grid = NULL;
-       grid->priv->info = NULL;
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
+       priv->raw_grid = NULL;
+       priv->info = NULL;
 
        gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
 
@@ -195,19 +157,19 @@ gdaui_grid_init (GdauiGrid *grid)
        gtk_box_pack_start (GTK_BOX (grid), sw, TRUE, TRUE, 0);
        gtk_widget_show (sw);
 
-       grid->priv->raw_grid = gdaui_raw_grid_new (NULL);
-       gtk_container_add (GTK_CONTAINER (sw), grid->priv->raw_grid);
-       gtk_widget_show (grid->priv->raw_grid);
-       g_signal_connect (grid->priv->raw_grid, "selection-changed",
+       priv->raw_grid = gdaui_raw_grid_new (NULL);
+       gtk_container_add (GTK_CONTAINER (sw), priv->raw_grid);
+       gtk_widget_show (priv->raw_grid);
+       g_signal_connect (priv->raw_grid, "selection-changed",
                          G_CALLBACK (raw_grid_selection_changed_cb), grid);
 
-       grid->priv->info = gdaui_data_proxy_info_new (GDAUI_DATA_PROXY (grid->priv->raw_grid),
+       priv->info = gdaui_data_proxy_info_new (GDAUI_DATA_PROXY (priv->raw_grid),
                                                      GDAUI_DATA_PROXY_INFO_CURRENT_ROW);
-       gtk_widget_set_halign (grid->priv->info, GTK_ALIGN_START);
-       gtk_style_context_add_class (gtk_widget_get_style_context (grid->priv->info), "inline-toolbar");
+       gtk_widget_set_halign (priv->info, GTK_ALIGN_START);
+       gtk_style_context_add_class (gtk_widget_get_style_context (priv->info), "inline-toolbar");
 
-       gtk_box_pack_start (GTK_BOX (grid), grid->priv->info, FALSE, TRUE, 0);
-       gtk_widget_show (grid->priv->info);
+       gtk_box_pack_start (GTK_BOX (grid), priv->info, FALSE, TRUE, 0);
+       gtk_widget_show (priv->info);
 }
 
 static void
@@ -217,18 +179,14 @@ gdaui_grid_dispose (GObject *object)
 
        g_return_if_fail (GDAUI_IS_GRID (object));
        grid = GDAUI_GRID (object);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
 
-       if (grid->priv) {
-               g_signal_handlers_disconnect_by_func (grid->priv->raw_grid,
-                                                     G_CALLBACK (raw_grid_selection_changed_cb), grid);
+       g_signal_handlers_disconnect_by_func (priv->raw_grid,
+                           G_CALLBACK (raw_grid_selection_changed_cb), grid);
 
-               /* the private area itself */
-               g_free (grid->priv);
-               grid->priv = NULL;
-       }
 
        /* for the parent class */
-       parent_class->dispose (object);
+       G_OBJECT_CLASS (gdaui_grid_parent_class)->dispose (object);
 }
 
 /**
@@ -265,14 +223,15 @@ gdaui_grid_set_property (GObject *object,
        GdaDataModel *model;
 
        grid = GDAUI_GRID (object);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
 
        switch (param_id) {
        case PROP_MODEL:
                model = GDA_DATA_MODEL (g_value_get_object (value));
-               g_object_set (G_OBJECT (grid->priv->raw_grid), "model", model, NULL);
+               g_object_set (G_OBJECT (priv->raw_grid), "model", model, NULL);
                break;
        case PROP_INFO_FLAGS:
-               g_object_set (G_OBJECT (grid->priv->info), "flags", g_value_get_flags (value), NULL);
+               g_object_set (G_OBJECT (priv->info), "flags", g_value_get_flags (value), NULL);
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -290,22 +249,23 @@ gdaui_grid_get_property (GObject *object,
        GdaDataModel *model;
 
        grid = GDAUI_GRID (object);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
 
        switch (param_id) {
        case PROP_RAW_GRID:
-               g_value_set_object (value, grid->priv->raw_grid);
+               g_value_set_object (value, priv->raw_grid);
                break;
        case PROP_INFO:
-               g_value_set_object (value, grid->priv->info);
+               g_value_set_object (value, priv->info);
                break;
        case PROP_INFO_FLAGS: {
                        GdauiDataProxyInfoFlag flags;
-                       g_object_get (G_OBJECT (grid->priv->info), "flags", &flags, NULL);
+                       g_object_get (G_OBJECT (priv->info), "flags", &flags, NULL);
                        g_value_set_flags (value, flags);
                        break;
                }
        case PROP_MODEL:
-               g_object_get (G_OBJECT (grid->priv->raw_grid), "model", &model, NULL);
+               g_object_get (G_OBJECT (priv->raw_grid), "model", &model, NULL);
                g_value_take_object (value, G_OBJECT (model));
                break;
        default:
@@ -328,90 +288,129 @@ void
 gdaui_grid_set_sample_size (GdauiGrid *grid, gint sample_size)
 {
        g_return_if_fail (grid && GDAUI_IS_GRID (grid));
-       g_return_if_fail (grid->priv);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
 
-       gdaui_raw_grid_set_sample_size (GDAUI_RAW_GRID (grid->priv->raw_grid), sample_size);
+       gdaui_raw_grid_set_sample_size (GDAUI_RAW_GRID (priv->raw_grid), sample_size);
 }
 
 /* GdauiDataProxy interface */
 static GdaDataProxy *
 gdaui_grid_get_proxy (GdauiDataProxy *iface)
 {
-       return gdaui_data_proxy_get_proxy ((GdauiDataProxy*) GDAUI_GRID (iface)->priv->raw_grid);
+       g_return_val_if_fail (GDAUI_IS_GRID (iface), NULL);
+       GdauiGrid *grid = GDAUI_GRID (iface);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
+       return gdaui_data_proxy_get_proxy ((GdauiDataProxy*) priv->raw_grid);
 }
 
 static void
 gdaui_grid_set_column_editable (GdauiDataProxy *iface, gint column, gboolean editable)
 {
-       gdaui_data_proxy_column_set_editable ((GdauiDataProxy*) GDAUI_GRID (iface)->priv->raw_grid,
+       g_return_if_fail (GDAUI_IS_GRID (iface));
+       GdauiGrid *grid = GDAUI_GRID (iface);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
+       gdaui_data_proxy_column_set_editable ((GdauiDataProxy*) priv->raw_grid,
                                              column, editable);
 }
 
 static gboolean
 gdaui_grid_supports_action (GdauiDataProxy *iface, GdauiAction action)
 {
-       return gdaui_data_proxy_supports_action ((GdauiDataProxy*) GDAUI_GRID (iface)->priv->raw_grid, 
action);
+       g_return_val_if_fail (GDAUI_IS_GRID (iface), FALSE);
+       GdauiGrid *grid = GDAUI_GRID (iface);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
+       return gdaui_data_proxy_supports_action ((GdauiDataProxy*) priv->raw_grid, action);
 }
 
 static void
 gdaui_grid_perform_action (GdauiDataProxy *iface, GdauiAction action)
 {
-       gdaui_data_proxy_perform_action ((GdauiDataProxy*) GDAUI_GRID (iface)->priv->raw_grid, action);
+       g_return_if_fail (GDAUI_IS_GRID (iface));
+       GdauiGrid *grid = GDAUI_GRID (iface);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
+       gdaui_data_proxy_perform_action ((GdauiDataProxy*) priv->raw_grid, action);
 }
 
 
 static gboolean
 gdaui_grid_widget_set_write_mode (GdauiDataProxy *iface, GdauiDataProxyWriteMode mode)
 {
-       return gdaui_data_proxy_set_write_mode ((GdauiDataProxy*) GDAUI_GRID (iface)->priv->raw_grid, mode);
+       g_return_val_if_fail (GDAUI_IS_GRID (iface), FALSE);
+       GdauiGrid *grid = GDAUI_GRID (iface);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
+       return gdaui_data_proxy_set_write_mode ((GdauiDataProxy*) priv->raw_grid, mode);
 }
 
 static GdauiDataProxyWriteMode
 gdaui_grid_widget_get_write_mode (GdauiDataProxy *iface)
 {
-       return gdaui_data_proxy_get_write_mode ((GdauiDataProxy*) GDAUI_GRID (iface)->priv->raw_grid);
+       g_return_val_if_fail (GDAUI_IS_GRID (iface), GDAUI_DATA_PROXY_WRITE_ON_DEMAND);
+       GdauiGrid *grid = GDAUI_GRID (iface);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
+       return gdaui_data_proxy_get_write_mode ((GdauiDataProxy*) priv->raw_grid);
 }
 
 /* GdauiDataSelector interface */
 static GdaDataModel *
 gdaui_grid_selector_get_model (GdauiDataSelector *iface)
 {
-       return gdaui_data_selector_get_model ((GdauiDataSelector*) GDAUI_GRID (iface)->priv->raw_grid);
+       g_return_val_if_fail (GDAUI_IS_GRID (iface), NULL);
+       GdauiGrid *grid = GDAUI_GRID (iface);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
+       return gdaui_data_selector_get_model ((GdauiDataSelector*) priv->raw_grid);
 }
 
 static void
 gdaui_grid_selector_set_model (GdauiDataSelector *iface, GdaDataModel *model)
 {
-       gdaui_data_selector_set_model ((GdauiDataSelector*) GDAUI_GRID (iface)->priv->raw_grid, model);
+       g_return_if_fail (GDAUI_IS_GRID (iface));
+       GdauiGrid *grid = GDAUI_GRID (iface);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
+       gdaui_data_selector_set_model ((GdauiDataSelector*) priv->raw_grid, model);
 }
 
 static GArray *
 gdaui_grid_selector_get_selected_rows (GdauiDataSelector *iface)
 {
-       return gdaui_data_selector_get_selected_rows ((GdauiDataSelector*) GDAUI_GRID 
(iface)->priv->raw_grid);
+       g_return_val_if_fail (GDAUI_IS_GRID (iface), NULL);
+       GdauiGrid *grid = GDAUI_GRID (iface);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
+       return gdaui_data_selector_get_selected_rows ((GdauiDataSelector*) priv->raw_grid);
 }
 
 static GdaDataModelIter *
 gdaui_grid_selector_get_data_set (GdauiDataSelector *iface)
 {
-       return gdaui_data_selector_get_data_set ((GdauiDataSelector*) GDAUI_GRID (iface)->priv->raw_grid);
+       g_return_val_if_fail (GDAUI_IS_GRID (iface), NULL);
+       GdauiGrid *grid = GDAUI_GRID (iface);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
+       return gdaui_data_selector_get_data_set ((GdauiDataSelector*) priv->raw_grid);
 }
 
 static gboolean
 gdaui_grid_selector_select_row (GdauiDataSelector *iface, gint row)
 {
-       return gdaui_data_selector_select_row ((GdauiDataSelector*) GDAUI_GRID (iface)->priv->raw_grid, row);
+       g_return_val_if_fail (GDAUI_IS_GRID (iface), FALSE);
+       GdauiGrid *grid = GDAUI_GRID (iface);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
+       return gdaui_data_selector_select_row ((GdauiDataSelector*) priv->raw_grid, row);
 }
 
 static void
 gdaui_grid_selector_unselect_row (GdauiDataSelector *iface, gint row)
 {
-       gdaui_data_selector_unselect_row ((GdauiDataSelector*) GDAUI_GRID (iface)->priv->raw_grid, row);
+       g_return_if_fail (GDAUI_IS_GRID (iface));
+       GdauiGrid *grid = GDAUI_GRID (iface);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
+       gdaui_data_selector_unselect_row ((GdauiDataSelector*) priv->raw_grid, row);
 }
 
 static void
 gdaui_grid_selector_set_column_visible (GdauiDataSelector *iface, gint column, gboolean visible)
 {
-       gdaui_data_selector_set_column_visible ((GdauiDataSelector*) GDAUI_GRID (iface)->priv->raw_grid,
+       g_return_if_fail (GDAUI_IS_GRID (iface));
+       GdauiGrid *grid = GDAUI_GRID (iface);
+       GdauiGridPrivate *priv = gdaui_grid_get_instance_private (grid);
+       gdaui_data_selector_set_column_visible ((GdauiDataSelector*) priv->raw_grid,
                                                column, visible);
 }
diff --git a/libgda-ui/gdaui-grid.h b/libgda-ui/gdaui-grid.h
index cc5c9609b..1826df5c0 100644
--- a/libgda-ui/gdaui-grid.h
+++ b/libgda-ui/gdaui-grid.h
@@ -26,27 +26,12 @@
 G_BEGIN_DECLS
 
 #define GDAUI_TYPE_GRID          (gdaui_grid_get_type())
-#define GDAUI_GRID(obj)          G_TYPE_CHECK_INSTANCE_CAST (obj, gdaui_grid_get_type(), GdauiGrid)
-#define GDAUI_GRID_CLASS(klass)  G_TYPE_CHECK_CLASS_CAST (klass, gdaui_grid_get_type (), GdauiGridClass)
-#define GDAUI_IS_GRID(obj)       G_TYPE_CHECK_INSTANCE_TYPE (obj, gdaui_grid_get_type ())
-#define GDAUI_IS_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GDAUI_TYPE_GRID))
-
-typedef struct _GdauiGrid      GdauiGrid;
-typedef struct _GdauiGridClass GdauiGridClass;
-typedef struct _GdauiGridPriv  GdauiGridPriv;
-
-/* struct for the object's data */
-struct _GdauiGrid
-{
-       GtkBox             object;
-
-       GdauiGridPriv     *priv;
-};
-
+G_DECLARE_DERIVABLE_TYPE(GdauiGrid, gdaui_grid, GDAUI, GRID, GtkBox)
 /* struct for the object's class */
 struct _GdauiGridClass
 {
        GtkBoxClass       parent_class;
+       gpointer            padding[12];
 };
 
 /**
@@ -58,8 +43,6 @@ struct _GdauiGridClass
  * @see_also: The #GdauiRawGrid widget which is used by the #GdaGrid widget.
  */
 
-GType             gdaui_grid_get_type            (void) G_GNUC_CONST;
-
 GtkWidget        *gdaui_grid_new                 (GdaDataModel *model);
 void              gdaui_grid_set_sample_size     (GdauiGrid *grid, gint sample_size);
 


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