[gimp/gtk3-port: 204/247] libgimpwidgets: move all GimpMemsizeEntry members to a private struct
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gtk3-port: 204/247] libgimpwidgets: move all GimpMemsizeEntry members to a private struct
- Date: Sat, 5 Mar 2011 20:49:20 +0000 (UTC)
commit 6dbca94c01aac37d3cd92adfb30a2776186a5d58
Author: Michael Natterer <mitch gimp org>
Date: Mon Jan 3 14:03:00 2011 +0100
libgimpwidgets: move all GimpMemsizeEntry members to a private struct
libgimpwidgets/gimpmemsizeentry.c | 149 ++++++++++++++++++++++++------------
libgimpwidgets/gimpmemsizeentry.h | 29 +++-----
libgimpwidgets/gimppropwidgets.c | 4 +-
3 files changed, 111 insertions(+), 71 deletions(-)
---
diff --git a/libgimpwidgets/gimpmemsizeentry.c b/libgimpwidgets/gimpmemsizeentry.c
index c5c7d17..a693ebe 100644
--- a/libgimpwidgets/gimpmemsizeentry.c
+++ b/libgimpwidgets/gimpmemsizeentry.c
@@ -50,6 +50,26 @@ enum
};
+typedef struct _GimpMemsizeEntryPrivate GimpMemsizeEntryPrivate;
+
+struct _GimpMemsizeEntryPrivate
+{
+ guint64 value;
+ guint64 lower;
+ guint64 upper;
+
+ guint shift;
+
+ GtkAdjustment *adjustment;
+ GtkWidget *spinbutton;
+ GtkWidget *menu;
+};
+
+#define GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE (obj, \
+ GIMP_TYPE_MEMSIZE_ENTRY, \
+ GimpMemsizeEntryPrivate)
+
+
static void gimp_memsize_entry_finalize (GObject *object);
static void gimp_memsize_entry_adj_callback (GtkAdjustment *adj,
@@ -82,33 +102,37 @@ gimp_memsize_entry_class_init (GimpMemsizeEntryClass *klass)
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+
+ g_type_class_add_private (object_class, sizeof (GimpMemsizeEntryPrivate));
}
static void
gimp_memsize_entry_init (GimpMemsizeEntry *entry)
{
+ GimpMemsizeEntryPrivate *private = GET_PRIVATE (entry);
+
gtk_orientable_set_orientation (GTK_ORIENTABLE (entry),
GTK_ORIENTATION_HORIZONTAL);
gtk_box_set_spacing (GTK_BOX (entry), 4);
- entry->value = 0;
- entry->lower = 0;
- entry->upper = 0;
- entry->shift = 0;
- entry->adjustment = NULL;
- entry->menu = NULL;
+ private->value = 0;
+ private->lower = 0;
+ private->upper = 0;
+ private->shift = 0;
+ private->adjustment = NULL;
+ private->menu = NULL;
}
static void
gimp_memsize_entry_finalize (GObject *object)
{
- GimpMemsizeEntry *entry = (GimpMemsizeEntry *) object;
+ GimpMemsizeEntryPrivate *private = GET_PRIVATE (object);
- if (entry->adjustment)
+ if (private->adjustment)
{
- g_object_unref (entry->adjustment);
- entry->adjustment = NULL;
+ g_object_unref (private->adjustment);
+ private->adjustment = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -118,9 +142,10 @@ static void
gimp_memsize_entry_adj_callback (GtkAdjustment *adj,
GimpMemsizeEntry *entry)
{
- guint64 size = gtk_adjustment_get_value (adj);
+ GimpMemsizeEntryPrivate *private = GET_PRIVATE (entry);
+ guint64 size = gtk_adjustment_get_value (adj);
- entry->value = size << entry->shift;
+ private->value = size << private->shift;
g_signal_emit (entry, gimp_memsize_entry_signals[VALUE_CHANGED], 0);
}
@@ -129,7 +154,8 @@ static void
gimp_memsize_entry_unit_callback (GtkWidget *widget,
GimpMemsizeEntry *entry)
{
- guint shift;
+ GimpMemsizeEntryPrivate *private = GET_PRIVATE (entry);
+ guint shift;
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), (gint *) &shift);
@@ -139,17 +165,17 @@ gimp_memsize_entry_unit_callback (GtkWidget *widget,
# define CAST
#endif
- if (shift != entry->shift)
+ if (shift != private->shift)
{
- entry->shift = shift;
-
- gtk_adjustment_configure (entry->adjustment,
- CAST entry->value >> shift,
- CAST entry->lower >> shift,
- CAST entry->upper >> shift,
- gtk_adjustment_get_step_increment (entry->adjustment),
- gtk_adjustment_get_page_increment (entry->adjustment),
- gtk_adjustment_get_page_size (entry->adjustment));
+ private->shift = shift;
+
+ gtk_adjustment_configure (private->adjustment,
+ CAST private->value >> shift,
+ CAST private->lower >> shift,
+ CAST private->upper >> shift,
+ gtk_adjustment_get_step_increment (private->adjustment),
+ gtk_adjustment_get_page_increment (private->adjustment),
+ gtk_adjustment_get_page_size (private->adjustment));
}
#undef CAST
@@ -172,9 +198,10 @@ gimp_memsize_entry_new (guint64 value,
guint64 lower,
guint64 upper)
{
- GimpMemsizeEntry *entry;
- GtkAdjustment *adj;
- guint shift;
+ GimpMemsizeEntry *entry;
+ GimpMemsizeEntryPrivate *private;
+ GtkAdjustment *adj;
+ guint shift;
#if _MSC_VER < 1300
# define CAST (gint64)
@@ -186,6 +213,8 @@ gimp_memsize_entry_new (guint64 value,
entry = g_object_new (GIMP_TYPE_MEMSIZE_ENTRY, NULL);
+ private = GET_PRIVATE (entry);
+
for (shift = 30; shift > 10; shift -= 10)
{
if (value > (G_GUINT64_CONSTANT (1) << shift) &&
@@ -193,12 +222,12 @@ gimp_memsize_entry_new (guint64 value,
break;
}
- entry->value = value;
- entry->lower = lower;
- entry->upper = upper;
- entry->shift = shift;
+ private->value = value;
+ private->lower = lower;
+ private->upper = upper;
+ private->shift = shift;
- entry->spinbutton = gimp_spin_button_new (&adj,
+ private->spinbutton = gimp_spin_button_new (&adj,
CAST (value >> shift),
CAST (lower >> shift),
CAST (upper >> shift),
@@ -206,30 +235,30 @@ gimp_memsize_entry_new (guint64 value,
#undef CAST
- entry->adjustment = GTK_ADJUSTMENT (adj);
- g_object_ref_sink (entry->adjustment);
+ private->adjustment = GTK_ADJUSTMENT (adj);
+ g_object_ref_sink (private->adjustment);
- gtk_entry_set_width_chars (GTK_ENTRY (entry->spinbutton), 7);
- gtk_box_pack_start (GTK_BOX (entry), entry->spinbutton, FALSE, FALSE, 0);
- gtk_widget_show (entry->spinbutton);
+ gtk_entry_set_width_chars (GTK_ENTRY (private->spinbutton), 7);
+ gtk_box_pack_start (GTK_BOX (entry), private->spinbutton, FALSE, FALSE, 0);
+ gtk_widget_show (private->spinbutton);
- g_signal_connect (entry->adjustment, "value-changed",
+ g_signal_connect (private->adjustment, "value-changed",
G_CALLBACK (gimp_memsize_entry_adj_callback),
entry);
- entry->menu = gimp_int_combo_box_new (_("Kilobytes"), 10,
+ private->menu = gimp_int_combo_box_new (_("Kilobytes"), 10,
_("Megabytes"), 20,
_("Gigabytes"), 30,
NULL);
- gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (entry->menu), shift);
+ gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (private->menu), shift);
- g_signal_connect (entry->menu, "changed",
+ g_signal_connect (private->menu, "changed",
G_CALLBACK (gimp_memsize_entry_unit_callback),
entry);
- gtk_box_pack_start (GTK_BOX (entry), entry->menu, FALSE, FALSE, 0);
- gtk_widget_show (entry->menu);
+ gtk_box_pack_start (GTK_BOX (entry), private->menu, FALSE, FALSE, 0);
+ gtk_widget_show (private->menu);
return GTK_WIDGET (entry);
}
@@ -246,10 +275,14 @@ void
gimp_memsize_entry_set_value (GimpMemsizeEntry *entry,
guint64 value)
{
- guint shift;
+ GimpMemsizeEntryPrivate *private;
+ guint shift;
g_return_if_fail (GIMP_IS_MEMSIZE_ENTRY (entry));
- g_return_if_fail (value >= entry->lower && value <= entry->upper);
+
+ private = GET_PRIVATE (entry);
+
+ g_return_if_fail (value >= private->lower && value <= private->upper);
for (shift = 30; shift > 10; shift -= 10)
{
@@ -258,12 +291,12 @@ gimp_memsize_entry_set_value (GimpMemsizeEntry *entry,
break;
}
- if (shift != entry->shift)
+ if (shift != private->shift)
{
- entry->shift = shift;
- entry->value = value;
+ private->shift = shift;
+ private->value = value;
- gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (entry->menu), shift);
+ gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (private->menu), shift);
}
#if _MSC_VER < 1300
@@ -272,7 +305,7 @@ gimp_memsize_entry_set_value (GimpMemsizeEntry *entry,
# define CAST
#endif
- gtk_adjustment_set_value (entry->adjustment, CAST (value >> shift));
+ gtk_adjustment_set_value (private->adjustment, CAST (value >> shift));
#undef CASE
}
@@ -290,5 +323,21 @@ gimp_memsize_entry_get_value (GimpMemsizeEntry *entry)
{
g_return_val_if_fail (GIMP_IS_MEMSIZE_ENTRY (entry), 0);
- return entry->value;
+ return GET_PRIVATE (entry)->value;
+}
+
+/**
+ * gimp_memsize_entry_get_spinbutton:
+ * @entry: a #GimpMemsizeEntry
+ *
+ * Returns: the entry's #GtkSpinbutton.
+ *
+ * Since: GIMP 3.0
+ **/
+GtkWidget *
+gimp_memsize_entry_get_spinbutton (GimpMemsizeEntry *entry)
+{
+ g_return_val_if_fail (GIMP_IS_MEMSIZE_ENTRY (entry), 0);
+
+ return GET_PRIVATE (entry)->spinbutton;
}
diff --git a/libgimpwidgets/gimpmemsizeentry.h b/libgimpwidgets/gimpmemsizeentry.h
index 5f1e9fb..5a14e8a 100644
--- a/libgimpwidgets/gimpmemsizeentry.h
+++ b/libgimpwidgets/gimpmemsizeentry.h
@@ -37,18 +37,7 @@ typedef struct _GimpMemsizeEntryClass GimpMemsizeEntryClass;
struct _GimpMemsizeEntry
{
- GtkBox parent_instance;
-
- /*< private >*/
- guint64 value;
- guint64 lower;
- guint64 upper;
-
- guint shift;
-
- GtkAdjustment *adjustment;
- GtkWidget *spinbutton;
- GtkWidget *menu;
+ GtkBox parent_instance;
};
struct _GimpMemsizeEntryClass
@@ -65,14 +54,16 @@ struct _GimpMemsizeEntryClass
};
-GType gimp_memsize_entry_get_type (void) G_GNUC_CONST;
+GType gimp_memsize_entry_get_type (void) G_GNUC_CONST;
+
+GtkWidget * gimp_memsize_entry_new (guint64 value,
+ guint64 lower,
+ guint64 upper);
+void gimp_memsize_entry_set_value (GimpMemsizeEntry *entry,
+ guint64 value);
+guint64 gimp_memsize_entry_get_value (GimpMemsizeEntry *entry);
-GtkWidget * gimp_memsize_entry_new (guint64 value,
- guint64 lower,
- guint64 upper);
-void gimp_memsize_entry_set_value (GimpMemsizeEntry *entry,
- guint64 value);
-guint64 gimp_memsize_entry_get_value (GimpMemsizeEntry *entry);
+GtkWidget * gimp_memsize_entry_get_spinbutton (GimpMemsizeEntry *entry);
G_END_DECLS
diff --git a/libgimpwidgets/gimppropwidgets.c b/libgimpwidgets/gimppropwidgets.c
index e718733..3fe7f6d 100644
--- a/libgimpwidgets/gimppropwidgets.c
+++ b/libgimpwidgets/gimppropwidgets.c
@@ -1498,7 +1498,7 @@ gimp_prop_memsize_entry_new (GObject *config,
uint64_spec->maximum);
set_param_spec (G_OBJECT (entry),
- GIMP_MEMSIZE_ENTRY (entry)->spinbutton,
+ gimp_memsize_entry_get_spinbutton (GIMP_MEMSIZE_ENTRY (entry)),
param_spec);
g_signal_connect (entry, "value-changed",
@@ -1543,7 +1543,7 @@ gimp_prop_memsize_notify (GObject *config,
param_spec->name, &value,
NULL);
- if (entry->value != value)
+ if (gimp_memsize_entry_get_value (entry) != value)
{
g_signal_handlers_block_by_func (entry,
gimp_prop_memsize_callback,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]