[libgda] gdaui-entry-common-time: ported to G_DECLARE/G_DEFINE



commit 65fc3f3edae9b63cd108fb22d68e80eb9c318d29
Author: Daniel Espinosa <esodan gmail com>
Date:   Thu Sep 20 17:37:56 2018 -0500

    gdaui-entry-common-time: ported to G_DECLARE/G_DEFINE

 libgda-ui/data-entries/gdaui-entry-common-time.c | 262 +++++++++--------------
 libgda-ui/data-entries/gdaui-entry-common-time.h |  20 +-
 2 files changed, 98 insertions(+), 184 deletions(-)
---
diff --git a/libgda-ui/data-entries/gdaui-entry-common-time.c 
b/libgda-ui/data-entries/gdaui-entry-common-time.c
index a92c53a0e..67b86a0d4 100644
--- a/libgda-ui/data-entries/gdaui-entry-common-time.c
+++ b/libgda-ui/data-entries/gdaui-entry-common-time.c
@@ -37,11 +37,6 @@
 /*
  * Main static functions 
  */
-static void gdaui_entry_common_time_class_init (GdauiEntryCommonTimeClass * class);
-static void gdaui_entry_common_time_init (GdauiEntryCommonTime * srv);
-static void gdaui_entry_common_time_dispose (GObject *object);
-static void gdaui_entry_common_time_finalize (GObject *object);
-
 static void gdaui_entry_common_time_set_property (GObject *object,
                                                  guint param_id,
                                                  const GValue *value,
@@ -71,12 +66,8 @@ static void       connect_signals(GdauiEntryWrapper *mgwrap, GCallback modify_cb
 static void       set_editable (GdauiEntryWrapper *mgwrap, gboolean editable);
 static void       grab_focus (GdauiEntryWrapper *mgwrap);
 
-/* get a pointer to the parents to be able to call their destructor */
-static GObjectClass  *parent_class = NULL;
-
-
 /* private structure */
-struct _GdauiEntryCommonTimePrivate
+typedef struct
 {
        GtkWidget *entry;
        GtkWidget *cal_popover;
@@ -86,7 +77,11 @@ struct _GdauiEntryCommonTimePrivate
        gulong     value_fraction;
 
        gboolean   editing_canceled;
-};
+} GdauiEntryCommonTimePrivate;
+
+G_DEFINE_TYPE_WITH_CODE (GdauiEntryCommonTime, gdaui_entry_common_time, GDAUI_TYPE_ENTRY_WRAPPER,
+                         G_ADD_PRIVATE (GdauiEntryCommonTime)
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_CELL_EDITABLE, 
gdaui_entry_common_time_cell_editable_init))
 
 static void
 gdaui_entry_common_time_cell_editable_init (GtkCellEditableIface *iface)
@@ -94,47 +89,11 @@ gdaui_entry_common_time_cell_editable_init (GtkCellEditableIface *iface)
        iface->start_editing = gdaui_entry_common_time_start_editing;
 }
 
-GType
-gdaui_entry_common_time_get_type (void)
-{
-       static GType type = 0;
-
-       if (G_UNLIKELY (type == 0)) {
-               static const GTypeInfo info = {
-                       sizeof (GdauiEntryCommonTimeClass),
-                       (GBaseInitFunc) NULL,
-                       (GBaseFinalizeFunc) NULL,
-                       (GClassInitFunc) gdaui_entry_common_time_class_init,
-                       NULL,
-                       NULL,
-                       sizeof (GdauiEntryCommonTime),
-                       0,
-                       (GInstanceInitFunc) gdaui_entry_common_time_init,
-                       0
-               };
-
-               static const GInterfaceInfo cell_editable_info = {
-                       (GInterfaceInitFunc) gdaui_entry_common_time_cell_editable_init,    /* interface_init 
*/
-                       NULL,                                                 /* interface_finalize */
-                       NULL                                                  /* interface_data */
-               };
-       
-               type = g_type_register_static (GDAUI_TYPE_ENTRY_WRAPPER, "GdauiEntryCommonTime", &info, 0);
-               g_type_add_interface_static (type, GTK_TYPE_CELL_EDITABLE, &cell_editable_info);
-       }
-       return type;
-}
-
 static void
 gdaui_entry_common_time_class_init (GdauiEntryCommonTimeClass * class)
 {
        GObjectClass   *object_class = G_OBJECT_CLASS (class);
 
-       parent_class = g_type_class_peek_parent (class);
-
-       object_class->dispose = gdaui_entry_common_time_dispose;
-       object_class->finalize = gdaui_entry_common_time_finalize;
-
        GDAUI_ENTRY_WRAPPER_CLASS (class)->create_entry = create_entry;
        GDAUI_ENTRY_WRAPPER_CLASS (class)->real_set_value = real_set_value;
        GDAUI_ENTRY_WRAPPER_CLASS (class)->real_get_value = real_get_value;
@@ -157,8 +116,9 @@ gdaui_entry_common_time_class_init (GdauiEntryCommonTimeClass * class)
 static gboolean
 key_press_event_cb (GdauiEntryCommonTime *mgtim, GdkEventKey *key_event, G_GNUC_UNUSED gpointer data)
 {
+       GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private (mgtim);
        if (key_event->keyval == GDK_KEY_Escape)
-               mgtim->priv->editing_canceled = TRUE;
+               priv->editing_canceled = TRUE;
        return FALSE;
 }
 
@@ -230,13 +190,13 @@ compute_localtime_tz (void)
 static void
 gdaui_entry_common_time_init (GdauiEntryCommonTime *mgtim)
 {
-       mgtim->priv = g_new0 (GdauiEntryCommonTimePrivate, 1);
-       mgtim->priv->entry = NULL;
-       mgtim->priv->calendar = NULL;
-       mgtim->priv->editing_canceled = FALSE;
-       mgtim->priv->value_tz = 0; /* safe init value */
-       mgtim->priv->value_fraction = 0; /* safe init value */
-       mgtim->priv->displayed_tz = compute_localtime_tz ();
+       GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private (mgtim);
+       priv->entry = NULL;
+       priv->calendar = NULL;
+       priv->editing_canceled = FALSE;
+       priv->value_tz = 0; /* safe init value */
+       priv->value_fraction = 0; /* safe init value */
+       priv->displayed_tz = compute_localtime_tz ();
        g_signal_connect (mgtim, "key-press-event",
                          G_CALLBACK (key_press_event_cb), NULL);
 }
@@ -267,51 +227,17 @@ gdaui_entry_common_time_new (GdaDataHandler *dh, GType type)
 }
 
 
-static void
-gdaui_entry_common_time_dispose (GObject   * object)
-{
-       GdauiEntryCommonTime *gdaui_entry_common_time;
-
-       g_return_if_fail (object != NULL);
-       g_return_if_fail (GDAUI_IS_ENTRY_COMMON_TIME (object));
-
-       gdaui_entry_common_time = GDAUI_ENTRY_COMMON_TIME (object);
-       if (gdaui_entry_common_time->priv) {
-       }
-
-       /* parent class */
-       parent_class->dispose (object);
-}
-
-static void
-gdaui_entry_common_time_finalize (GObject   * object)
-{
-       GdauiEntryCommonTime *gdaui_entry_common_time;
-
-       g_return_if_fail (object != NULL);
-       g_return_if_fail (GDAUI_IS_ENTRY_COMMON_TIME (object));
-
-       gdaui_entry_common_time = GDAUI_ENTRY_COMMON_TIME (object);
-       if (gdaui_entry_common_time->priv) {
-               g_free (gdaui_entry_common_time->priv);
-               gdaui_entry_common_time->priv = NULL;
-       }
-
-       /* parent class */
-       parent_class->finalize (object);
-}
-
 static void
 gdaui_entry_common_time_set_property (GObject *object,
                                      guint param_id,
                                      const GValue *value,
                                      GParamSpec *pspec)
 {
-       GdauiEntryCommonTime *mgtim;
+       /* GdauiEntryCommonTime *mgtim; */
 
-       mgtim = GDAUI_ENTRY_COMMON_TIME (object);
-       if (mgtim->priv) {
-               switch (param_id) {
+       /* mgtim = GDAUI_ENTRY_COMMON_TIME (object); */
+       /* GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private (mgtim); */
+       switch (param_id) {
                case PROP_TYPE:
                        gdaui_data_entry_set_value_type (GDAUI_DATA_ENTRY (object), g_value_get_uint (value));
                        break;
@@ -321,7 +247,6 @@ gdaui_entry_common_time_set_property (GObject *object,
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                        break;
-               }
        }
 }
 
@@ -334,10 +259,10 @@ gdaui_entry_common_time_get_property (GObject *object,
        GdauiEntryCommonTime *mgtim;
 
        mgtim = GDAUI_ENTRY_COMMON_TIME (object);
-       if (mgtim->priv) {
-               switch (param_id) {
+       GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private (mgtim);
+       switch (param_id) {
                case PROP_EDITING_CANCELED:
-                       g_value_set_boolean (value, mgtim->priv->editing_canceled);
+                       g_value_set_boolean (value, priv->editing_canceled);
                        break;
                case PROP_TYPE:
                        g_value_set_uint (value, gdaui_data_entry_get_value_type (GDAUI_DATA_ENTRY (object)));
@@ -345,7 +270,6 @@ gdaui_entry_common_time_get_property (GObject *object,
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                        break;
-               }
        }
 }
 
@@ -355,12 +279,13 @@ static void date_day_selected_double_click (GtkCalendar *calendar, GdauiEntryCom
 static void
 icon_press_cb (GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event, GdauiEntryCommonTime *mgtim)
 {
+       GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private (mgtim);
        if (icon_pos == GTK_ENTRY_ICON_PRIMARY) {
-               if (! mgtim->priv->cal_popover) {
+               if (! priv->cal_popover) {
                        /* calendar */
                        GtkWidget *wid;
                        wid = gtk_calendar_new ();
-                       mgtim->priv->calendar = wid;
+                       priv->calendar = wid;
                        gtk_widget_show (wid);
                        g_signal_connect (G_OBJECT (wid), "day-selected",
                                          G_CALLBACK (date_day_selected), mgtim);
@@ -369,9 +294,9 @@ icon_press_cb (GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event,
 
                        /* popover */
                        GtkWidget *popover;
-                       popover = gtk_popover_new (mgtim->priv->entry);
-                       gtk_container_add (GTK_CONTAINER (popover), mgtim->priv->calendar);
-                       mgtim->priv->cal_popover = popover;
+                       popover = gtk_popover_new (priv->entry);
+                       gtk_container_add (GTK_CONTAINER (popover), priv->calendar);
+                       priv->cal_popover = popover;
                }
 
                /* set calendar to current value */
@@ -435,27 +360,28 @@ icon_press_cb (GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event,
                }
 
                if (! unset) {
-                       g_signal_handlers_block_by_func (G_OBJECT (mgtim->priv->calendar),
+                       g_signal_handlers_block_by_func (G_OBJECT (priv->calendar),
                                                         G_CALLBACK (date_day_selected), mgtim);
-                       g_signal_handlers_block_by_func (G_OBJECT (mgtim->priv->calendar),
+                       g_signal_handlers_block_by_func (G_OBJECT (priv->calendar),
                                                         G_CALLBACK (date_day_selected_double_click), mgtim);
                }
-               gtk_calendar_select_month (GTK_CALENDAR (mgtim->priv->calendar), month, year);
-               gtk_calendar_select_day (GTK_CALENDAR (mgtim->priv->calendar), day);
+               gtk_calendar_select_month (GTK_CALENDAR (priv->calendar), month, year);
+               gtk_calendar_select_day (GTK_CALENDAR (priv->calendar), day);
                if (! unset) {
-                       g_signal_handlers_unblock_by_func (G_OBJECT (mgtim->priv->calendar),
+                       g_signal_handlers_unblock_by_func (G_OBJECT (priv->calendar),
                                                           G_CALLBACK (date_day_selected), mgtim);
-                       g_signal_handlers_unblock_by_func (G_OBJECT (mgtim->priv->calendar),
+                       g_signal_handlers_unblock_by_func (G_OBJECT (priv->calendar),
                                                           G_CALLBACK (date_day_selected_double_click), 
mgtim);
                }
 
-               gtk_widget_show (mgtim->priv->cal_popover);
+               gtk_widget_show (priv->cal_popover);
        }
 }
 
 static void
 date_day_selected (GtkCalendar *calendar, GdauiEntryCommonTime *mgtim)
 {
+       GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private (mgtim);
        char buffer [256];
         guint year, month, day;
         struct tm mtm = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
@@ -477,7 +403,7 @@ date_day_selected (GtkCalendar *calendar, GdauiEntryCommonTime *mgtim)
                gchar *tmpstr;
                GdaDataHandler *dh;
                dh = gdaui_data_entry_get_handler (GDAUI_DATA_ENTRY (mgtim));
-               tmpstr = gdaui_formatted_entry_get_text (GDAUI_FORMATTED_ENTRY (mgtim->priv->entry));
+               tmpstr = gdaui_formatted_entry_get_text (GDAUI_FORMATTED_ENTRY (priv->entry));
                if (tmpstr) {
                        value = gda_data_handler_get_value_from_str (dh, tmpstr, type);
                        g_free (tmpstr);
@@ -517,17 +443,18 @@ date_day_selected (GtkCalendar *calendar, GdauiEntryCommonTime *mgtim)
        if (buffer [0]) {
                char *str_utf8;
                str_utf8 = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
-               gdaui_entry_set_text (GDAUI_ENTRY (mgtim->priv->entry), str_utf8);
+               gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), str_utf8);
                g_free (str_utf8);
        }
        else
-               gdaui_entry_set_text (GDAUI_ENTRY (mgtim->priv->entry), "");
+               gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), "");
 }
 
 static void
 date_day_selected_double_click (GtkCalendar *calendar, GdauiEntryCommonTime *mgtim)
 {
-       gtk_widget_hide (mgtim->priv->cal_popover);
+       GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private (mgtim);
+       gtk_widget_hide (priv->cal_popover);
 }
 
 static glong
@@ -555,6 +482,7 @@ create_entry (GdauiEntryWrapper *mgwrap)
        GdauiEntryCommonTime *mgtim;
        g_return_val_if_fail (GDAUI_IS_ENTRY_COMMON_TIME (mgwrap), NULL);
        mgtim = GDAUI_ENTRY_COMMON_TIME (mgwrap);
+       GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private (mgtim);
 
        GtkWidget *wid, *hb;
        GdaDataHandler *dh;
@@ -581,7 +509,7 @@ create_entry (GdauiEntryWrapper *mgwrap)
 
                gchar *tmp;
                gulong tz;
-               tz = mgtim->priv->displayed_tz;
+               tz = priv->displayed_tz;
                if (tz == 0)
                        tmp = g_strdup ("GMT");
                else if ((tz % 3600) == 0)
@@ -604,7 +532,7 @@ create_entry (GdauiEntryWrapper *mgwrap)
                wid = gdaui_entry_new (NULL, NULL);
        gtk_box_pack_start (GTK_BOX (hb), wid, FALSE, FALSE, 0);
        gtk_widget_show (wid);
-       mgtim->priv->entry = wid;
+       priv->entry = wid;
        g_signal_connect_swapped (wid, "event-after",
                                  G_CALLBACK (event_after_cb), hb);
 
@@ -619,7 +547,7 @@ create_entry (GdauiEntryWrapper *mgwrap)
 }
 
 /*
- * NB: the displayed value is relative to mgtim->priv->displayed_tz
+ * NB: the displayed value is relative to priv->displayed_tz
  */
 static void
 real_set_value (GdauiEntryWrapper *mgwrap, const GValue *value)
@@ -630,7 +558,7 @@ real_set_value (GdauiEntryWrapper *mgwrap, const GValue *value)
 
        g_return_if_fail (GDAUI_IS_ENTRY_COMMON_TIME (mgwrap));
        mgtim = GDAUI_ENTRY_COMMON_TIME (mgwrap);
-       g_return_if_fail (mgtim->priv);
+       GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private (mgtim);
 
        dh = gdaui_data_entry_get_handler (GDAUI_DATA_ENTRY (mgwrap));
        type = gdaui_data_entry_get_value_type (GDAUI_DATA_ENTRY (mgtim));
@@ -638,34 +566,34 @@ real_set_value (GdauiEntryWrapper *mgwrap, const GValue *value)
        if (type == G_TYPE_DATE) {
                if (value) {
                        if (gda_value_is_null ((GValue *) value))
-                               gdaui_entry_set_text (GDAUI_ENTRY (mgtim->priv->entry), NULL);
+                               gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), NULL);
                        else {
                                gchar *str;
                                
                                str = gda_data_handler_get_str_from_value (dh, value);
-                               gdaui_entry_set_text (GDAUI_ENTRY (mgtim->priv->entry), str);
+                               gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), str);
                                g_free (str);
                        }
                }
                else 
-                       gdaui_entry_set_text (GDAUI_ENTRY (mgtim->priv->entry), NULL);
+                       gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), NULL);
        }
        else if (type == GDA_TYPE_TIME) {
                if (value) {
                        if (gda_value_is_null ((GValue *) value)) {
-                               gdaui_entry_set_text (GDAUI_ENTRY (mgtim->priv->entry), NULL);
-                               mgtim->priv->value_tz = mgtim->priv->displayed_tz;
-                               mgtim->priv->value_fraction = 0;
+                               gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), NULL);
+                               priv->value_tz = priv->displayed_tz;
+                               priv->value_fraction = 0;
                        }
                        else {
                                const GdaTime *gtim;
                                GdaTime* copy;
                                gtim = gda_value_get_time (value);
-                               mgtim->priv->value_tz = fit_tz (gda_time_get_timezone (gtim));
-                               mgtim->priv->value_fraction = gda_time_get_fraction (gtim);
+                               priv->value_tz = fit_tz (gda_time_get_timezone (gtim));
+                               priv->value_fraction = gda_time_get_fraction (gtim);
 
                                copy = gda_time_copy (gtim);
-                               gda_time_change_timezone (copy, mgtim->priv->displayed_tz);
+                               gda_time_change_timezone (copy, priv->displayed_tz);
 
                                GValue *copy_value;
                                copy_value = g_new0 (GValue, 1);
@@ -675,36 +603,36 @@ real_set_value (GdauiEntryWrapper *mgwrap, const GValue *value)
                                str = gda_data_handler_get_str_from_value (dh, copy_value);
                                gda_value_free (copy_value);
 
-                               gdaui_entry_set_text (GDAUI_ENTRY (mgtim->priv->entry), str);
+                               gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), str);
                                g_free (str);
                                gda_time_free (copy);
                        }
                }
                else 
-                       gdaui_entry_set_text (GDAUI_ENTRY (mgtim->priv->entry), NULL);
+                       gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), NULL);
        }
        else if (type == G_TYPE_DATE_TIME) {
                if (value) {
                        if (gda_value_is_null ((GValue *) value)) {
-                               gdaui_entry_set_text (GDAUI_ENTRY (mgtim->priv->entry), NULL);
-                               mgtim->priv->value_tz = mgtim->priv->displayed_tz;
-                               mgtim->priv->value_fraction = 0;
+                               gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), NULL);
+                               priv->value_tz = priv->displayed_tz;
+                               priv->value_fraction = 0;
                        }
                        else {
                                GDateTime *gts;
                                GDateTime *copy;
                                gts = g_value_get_boxed (value);
-                               mgtim->priv->value_tz = fit_tz (g_date_time_get_utc_offset (gts) / 1000000);
-                               mgtim->priv->value_fraction = (glong) ((g_date_time_get_seconds (gts) - 
g_date_time_get_second (gts)) * 1000000);
+                               priv->value_tz = fit_tz (g_date_time_get_utc_offset (gts) / 1000000);
+                               priv->value_fraction = (glong) ((g_date_time_get_seconds (gts) - 
g_date_time_get_second (gts)) * 1000000);
 
-                               gint itz = mgtim->priv->displayed_tz;
+                               gint itz = priv->displayed_tz;
                                if (itz < 0)
                                        itz *= -1;
                                gint h = itz/60/60;
                                gint m = itz/60 - h*60;
                                gint s = itz - h*60*60 - m*60;
                                gchar *stz = g_strdup_printf ("%s%02d:%02d:%02d",
-                                                                                                             
                                          mgtim->priv->displayed_tz < 0 ? "-" : "+",
+                                                                                                             
                                          priv->displayed_tz < 0 ? "-" : "+",
                                                                                                              
                                          h, m, s);
                                GTimeZone *tz = g_time_zone_new (stz);
                                g_free (stz);
@@ -718,13 +646,13 @@ real_set_value (GdauiEntryWrapper *mgwrap, const GValue *value)
                                str = gda_data_handler_get_str_from_value (dh, copy_value);
                                gda_value_free (copy_value);
 
-                               gdaui_entry_set_text (GDAUI_ENTRY (mgtim->priv->entry), str);
+                               gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), str);
                                g_free (str);
                                g_date_time_unref (copy);
                        }
                }
                else
-                       gdaui_entry_set_text (GDAUI_ENTRY (mgtim->priv->entry), NULL);
+                       gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), NULL);
        }
        else
                g_assert_not_reached ();
@@ -741,20 +669,20 @@ real_get_value (GdauiEntryWrapper *mgwrap)
 
        g_return_val_if_fail (mgwrap && GDAUI_IS_ENTRY_COMMON_TIME (mgwrap), NULL);
        mgtim = GDAUI_ENTRY_COMMON_TIME (mgwrap);
-       g_return_val_if_fail (mgtim->priv, NULL);
+       GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private (mgtim);
 
        type = gdaui_data_entry_get_value_type (GDAUI_DATA_ENTRY (mgtim));
        dh = gdaui_data_entry_get_handler (GDAUI_DATA_ENTRY (mgwrap));
 
        if (type == G_TYPE_DATE) {
-               str2 = gdaui_formatted_entry_get_text (GDAUI_FORMATTED_ENTRY (mgtim->priv->entry));
+               str2 = gdaui_formatted_entry_get_text (GDAUI_FORMATTED_ENTRY (priv->entry));
                if (str2) {
                        value = gda_data_handler_get_value_from_str (dh, str2, type);
                        g_free (str2);
                }
        }
        else if (type == GDA_TYPE_TIME) {
-               str2 = gdaui_formatted_entry_get_text (GDAUI_FORMATTED_ENTRY (mgtim->priv->entry));
+               str2 = gdaui_formatted_entry_get_text (GDAUI_FORMATTED_ENTRY (priv->entry));
                if (str2) {
                        value = gda_data_handler_get_value_from_str (dh, str2, type);
                        g_free (str2);
@@ -764,8 +692,8 @@ real_get_value (GdauiEntryWrapper *mgwrap)
                        const GdaTime *gdatime;
                        gdatime = gda_value_get_time (value);
                        GdaTime *time_copy = gda_time_copy (gdatime);
-                       gda_time_set_timezone (time_copy, mgtim->priv->displayed_tz);
-                       gda_time_change_timezone (time_copy, mgtim->priv->value_tz);
+                       gda_time_set_timezone (time_copy, priv->displayed_tz);
+                       gda_time_change_timezone (time_copy, priv->value_tz);
                        gda_value_set_time (value, time_copy);
                        gda_time_free (time_copy);
                }
@@ -773,7 +701,7 @@ real_get_value (GdauiEntryWrapper *mgwrap)
        else if (type == G_TYPE_DATE_TIME) {
                gchar *tmpstr;
 
-               tmpstr = gdaui_formatted_entry_get_text (GDAUI_FORMATTED_ENTRY (mgtim->priv->entry));
+               tmpstr = gdaui_formatted_entry_get_text (GDAUI_FORMATTED_ENTRY (priv->entry));
                if (tmpstr) {
                        value = gda_data_handler_get_value_from_str (dh, tmpstr, type);
                        g_free (tmpstr);
@@ -784,18 +712,18 @@ real_get_value (GdauiEntryWrapper *mgwrap)
                        GDateTime *gdatime = NULL;
                        GDateTime *copy;
                        g_value_take_boxed (value, gdatime);
-                       gint tzi = mgtim->priv->displayed_tz; // FIXME: This is always positive
+                       gint tzi = priv->displayed_tz; // FIXME: This is always positive
                        if (tzi < 0)
                                tzi *= -1;
                        gint h = tzi/60/60;
                        gint m = tzi/60 - h*60;
                        gint s = tzi - h*60*60 - m*60;
                        gchar *stz = g_strdup_printf ("%s%02d:%02d:%02d",
-                                                                                                             
                                  mgtim->priv->displayed_tz < 0 ? "-" : "+",
+                                                                                                             
                                  priv->displayed_tz < 0 ? "-" : "+",
                                                                                                              
                                  h, m, s);
                        GTimeZone *tz = g_time_zone_new (stz);
                        g_free (stz);
-                       gdouble seconds = g_date_time_get_second (gdatime) + mgtim->priv->value_fraction / 
1000000.0;
+                       gdouble seconds = g_date_time_get_second (gdatime) + priv->value_fraction / 1000000.0;
                        copy = g_date_time_new (tz,
                                                                                                              
          g_date_time_get_year (gdatime),
                                                                                                              
          g_date_time_get_month (gdatime),
@@ -807,7 +735,7 @@ real_get_value (GdauiEntryWrapper *mgwrap)
                        g_date_time_unref (gdatime);
                        g_value_set_boxed (value, copy);
                        /* FIXME: Original code change timezone, but before set a displayed one, so 
inconsistency
-                       gda_timestamp_change_timezone (gdatime, mgtim->priv->value_tz);
+                       gda_timestamp_change_timezone (gdatime, priv->value_tz);
                         */
                }
        }
@@ -829,10 +757,11 @@ connect_signals (GdauiEntryWrapper *mgwrap, GCallback modify_cb, GCallback activ
        GdauiEntryCommonTime *mgtim;
        g_return_if_fail (GDAUI_IS_ENTRY_COMMON_TIME (mgwrap));
        mgtim = GDAUI_ENTRY_COMMON_TIME (mgwrap);
+       GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private (mgtim);
 
-       g_signal_connect_swapped (G_OBJECT (mgtim->priv->entry), "changed",
+       g_signal_connect_swapped (G_OBJECT (priv->entry), "changed",
                                  modify_cb, mgwrap);
-       g_signal_connect_swapped (G_OBJECT (mgtim->priv->entry), "activate",
+       g_signal_connect_swapped (G_OBJECT (priv->entry), "activate",
                                  activate_cb, mgwrap);
 }
 
@@ -843,12 +772,13 @@ set_editable (GdauiEntryWrapper *mgwrap, gboolean editable)
 
        g_return_if_fail (GDAUI_IS_ENTRY_COMMON_TIME (mgwrap));
        mgtim = GDAUI_ENTRY_COMMON_TIME (mgwrap);
+       GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private (mgtim);
 
-       if (mgtim->priv->entry)
-               gtk_editable_set_editable (GTK_EDITABLE (mgtim->priv->entry), editable);
+       if (priv->entry)
+               gtk_editable_set_editable (GTK_EDITABLE (priv->entry), editable);
 
-       gtk_entry_set_icon_sensitive (GTK_ENTRY (mgtim->priv->entry), GTK_ENTRY_ICON_PRIMARY, editable);
-       gtk_entry_set_icon_sensitive (GTK_ENTRY (mgtim->priv->entry), GTK_ENTRY_ICON_SECONDARY, editable);
+       gtk_entry_set_icon_sensitive (GTK_ENTRY (priv->entry), GTK_ENTRY_ICON_PRIMARY, editable);
+       gtk_entry_set_icon_sensitive (GTK_ENTRY (priv->entry), GTK_ENTRY_ICON_SECONDARY, editable);
 }
 
 static void
@@ -858,8 +788,9 @@ grab_focus (GdauiEntryWrapper *mgwrap)
 
        g_return_if_fail (GDAUI_IS_ENTRY_COMMON_TIME (mgwrap));
        mgtim = GDAUI_ENTRY_COMMON_TIME (mgwrap);
+       GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private (mgtim);
 
-       gtk_widget_grab_focus (mgtim->priv->entry);
+       gtk_widget_grab_focus (priv->entry);
 }
 
 static void
@@ -898,12 +829,13 @@ entry_insert_func (G_GNUC_UNUSED GdauiFormattedEntry *fentry, gunichar insert_ch
                        GValue *tsvalue;
                        //gchar *str;
                        //GdauiEntryCommonTime *mgtim = GDAUI_ENTRY_COMMON_TIME (data);
-                       //str = gdaui_formatted_entry_get_text (GDAUI_FORMATTED_ENTRY (mgtim->priv->entry));
+                       // GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private 
(mgtim);
+                       //str = gdaui_formatted_entry_get_text (GDAUI_FORMATTED_ENTRY (priv->entry));
                        tsvalue = gda_value_new_date_time_from_timet (time (NULL));
                        real_set_value (GDAUI_ENTRY_WRAPPER (data), tsvalue);
                        gda_value_free (tsvalue);
                        //if (str && g_ascii_isdigit (*str))
-                       //      gdaui_entry_set_text (GDAUI_ENTRY (mgtim->priv->entry), str);
+                       //      gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), str);
                        //g_free (str);
                }
        }
@@ -988,19 +920,19 @@ gdaui_entry_common_time_start_editing (GtkCellEditable *iface, GdkEvent *event)
 
        g_return_if_fail (GDAUI_IS_ENTRY_COMMON_TIME (iface));
        mgtim = GDAUI_ENTRY_COMMON_TIME (iface);
-       g_return_if_fail (mgtim->priv);
+       GdauiEntryCommonTimePrivate *priv = gdaui_entry_common_time_get_instance_private (mgtim);
 
-       mgtim->priv->editing_canceled = FALSE;
+       priv->editing_canceled = FALSE;
 
-       if (mgtim->priv->entry) {
-               g_object_set (G_OBJECT (mgtim->priv->entry), "has-frame", FALSE, NULL);
-               gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (mgtim->priv->entry), event);
-               g_signal_connect (G_OBJECT (mgtim->priv->entry), "editing-done",
+       if (priv->entry) {
+               g_object_set (G_OBJECT (priv->entry), "has-frame", FALSE, NULL);
+               gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (priv->entry), event);
+               g_signal_connect (G_OBJECT (priv->entry), "editing-done",
                                  G_CALLBACK (gtk_cell_editable_entry_editing_done_cb), mgtim);
-               g_signal_connect (G_OBJECT (mgtim->priv->entry), "remove-widget",
+               g_signal_connect (G_OBJECT (priv->entry), "remove-widget",
                                  G_CALLBACK (gtk_cell_editable_entry_remove_widget_cb), mgtim);
        }
 
-       gtk_widget_grab_focus (mgtim->priv->entry);
+       gtk_widget_grab_focus (priv->entry);
        //gtk_widget_queue_draw (GTK_WIDGET (mgtim)); useful ?
 }
diff --git a/libgda-ui/data-entries/gdaui-entry-common-time.h 
b/libgda-ui/data-entries/gdaui-entry-common-time.h
index d27acd354..76f03ebab 100644
--- a/libgda-ui/data-entries/gdaui-entry-common-time.h
+++ b/libgda-ui/data-entries/gdaui-entry-common-time.h
@@ -26,31 +26,13 @@
 G_BEGIN_DECLS
 
 #define GDAUI_TYPE_ENTRY_COMMON_TIME          (gdaui_entry_common_time_get_type())
-#define GDAUI_ENTRY_COMMON_TIME(obj)          G_TYPE_CHECK_INSTANCE_CAST (obj, 
gdaui_entry_common_time_get_type(), GdauiEntryCommonTime)
-#define GDAUI_ENTRY_COMMON_TIME_CLASS(klass)  G_TYPE_CHECK_CLASS_CAST (klass, 
gdaui_entry_common_time_get_type (), GdauiEntryCommonTimeClass)
-#define GDAUI_IS_ENTRY_COMMON_TIME(obj)       G_TYPE_CHECK_INSTANCE_TYPE (obj, 
gdaui_entry_common_time_get_type ())
-
-
-typedef struct _GdauiEntryCommonTime GdauiEntryCommonTime;
-typedef struct _GdauiEntryCommonTimeClass GdauiEntryCommonTimeClass;
-typedef struct _GdauiEntryCommonTimePrivate GdauiEntryCommonTimePrivate;
-
-
-/* struct for the object's data */
-struct _GdauiEntryCommonTime
-{
-       GdauiEntryWrapper              object;
-       GdauiEntryCommonTimePrivate   *priv;
-};
-
+G_DECLARE_DERIVABLE_TYPE(GdauiEntryCommonTime, gdaui_entry_common_time, GDAUI,ENTRY_COMMON_TIME, 
GdauiEntryWrapper)
 /* struct for the object's class */
 struct _GdauiEntryCommonTimeClass
 {
        GdauiEntryWrapperClass         parent_class;
 };
 
-GType  gdaui_entry_common_time_get_type (void) G_GNUC_CONST;
-
 G_END_DECLS
 
 #endif


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