diff options
author | Timm Bäder <mail@baedert.org> | 2018-03-18 13:52:55 +0100 |
---|---|---|
committer | Timm Bäder <mail@baedert.org> | 2018-03-20 09:37:59 +0100 |
commit | 25ab5b9f0b694599e45f1df9748a583ddef3ab1f (patch) | |
tree | 8911c5583f12347318ba4a66920a485684387d6c /gtk/gtklevelbar.c | |
parent | f261bf2fc609b3f8aaa96c2ca4d52d79885a1902 (diff) | |
download | gtk+-25ab5b9f0b694599e45f1df9748a583ddef3ab1f.tar.gz |
levelbar: Remove priv pointer
Diffstat (limited to 'gtk/gtklevelbar.c')
-rw-r--r-- | gtk/gtklevelbar.c | 167 |
1 files changed, 100 insertions, 67 deletions
diff --git a/gtk/gtklevelbar.c b/gtk/gtklevelbar.c index f8193239ba..251d48808c 100644 --- a/gtk/gtklevelbar.c +++ b/gtk/gtklevelbar.c @@ -164,6 +164,7 @@ typedef struct { gdouble value; } GtkLevelBarOffset; +typedef struct _GtkLevelBarPrivate GtkLevelBarPrivate; struct _GtkLevelBarPrivate { GtkOrientation orientation; @@ -237,11 +238,12 @@ gtk_level_bar_ensure_offset (GtkLevelBar *self, const gchar *name, gdouble value) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); GList *existing; GtkLevelBarOffset *offset = NULL; GtkLevelBarOffset *new_offset; - existing = g_list_find_custom (self->priv->offsets, name, offset_find_func); + existing = g_list_find_custom (priv->offsets, name, offset_find_func); if (existing) offset = existing->data; @@ -253,10 +255,10 @@ gtk_level_bar_ensure_offset (GtkLevelBar *self, if (offset) { gtk_level_bar_offset_free (offset); - self->priv->offsets = g_list_delete_link (self->priv->offsets, existing); + priv->offsets = g_list_delete_link (priv->offsets, existing); } - self->priv->offsets = g_list_insert_sorted (self->priv->offsets, new_offset, offset_sort_func); + priv->offsets = g_list_insert_sorted (priv->offsets, new_offset, offset_sort_func); return TRUE; } @@ -265,17 +267,21 @@ static gboolean gtk_level_bar_value_in_interval (GtkLevelBar *self, gdouble value) { - return ((value >= self->priv->min_value) && - (value <= self->priv->max_value)); + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + + return ((value >= priv->min_value) && + (value <= priv->max_value)); } static gint gtk_level_bar_get_num_blocks (GtkLevelBar *self) { - if (self->priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + + if (priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) return 1; - else if (self->priv->bar_mode == GTK_LEVEL_BAR_MODE_DISCRETE) - return MAX (1, (gint) (round (self->priv->max_value) - round (self->priv->min_value))); + else if (priv->bar_mode == GTK_LEVEL_BAR_MODE_DISCRETE) + return MAX (1, (gint) (round (priv->max_value) - round (priv->min_value))); return 0; } @@ -283,7 +289,8 @@ gtk_level_bar_get_num_blocks (GtkLevelBar *self) static gint gtk_level_bar_get_num_block_nodes (GtkLevelBar *self) { - if (self->priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + if (priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) return 2; else return gtk_level_bar_get_num_blocks (self); @@ -294,6 +301,7 @@ gtk_level_bar_get_min_block_size (GtkLevelBar *self, gint *block_width, gint *block_height) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); guint i, n_blocks; gint width, height; @@ -302,12 +310,12 @@ gtk_level_bar_get_min_block_size (GtkLevelBar *self, for (i = 0; i < n_blocks; i++) { - gtk_widget_measure (self->priv->block_widget[i], + gtk_widget_measure (priv->block_widget[i], GTK_ORIENTATION_HORIZONTAL, -1, &width, NULL, NULL, NULL); - gtk_widget_measure (self->priv->block_widget[i], + gtk_widget_measure (priv->block_widget[i], GTK_ORIENTATION_VERTICAL, -1, &height, NULL, @@ -321,11 +329,12 @@ gtk_level_bar_get_min_block_size (GtkLevelBar *self, static gboolean gtk_level_bar_get_real_inverted (GtkLevelBar *self) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); if (gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_RTL && - self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) - return !self->priv->inverted; + priv->orientation == GTK_ORIENTATION_HORIZONTAL) + return !priv->inverted; - return self->priv->inverted; + return priv->inverted; } static gboolean @@ -334,19 +343,20 @@ gtk_level_bar_render_trough (GtkGizmo *gizmo, { GtkWidget *widget = GTK_WIDGET (gizmo); GtkLevelBar *self = GTK_LEVEL_BAR (gtk_widget_get_parent (GTK_WIDGET (gizmo))); + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); - if (self->priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) + if (priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) { gboolean inverted; inverted = gtk_level_bar_get_real_inverted (self); /* render the empty (unfilled) part */ - gtk_widget_snapshot_child (widget, self->priv->block_widget[inverted ? 0 : 1], snapshot); + gtk_widget_snapshot_child (widget, priv->block_widget[inverted ? 0 : 1], snapshot); /* now render the filled part on top of it */ - if (self->priv->cur_value != 0) - gtk_widget_snapshot_child (widget, self->priv->block_widget[inverted ? 1 : 0], snapshot); + if (priv->cur_value != 0) + gtk_widget_snapshot_child (widget, priv->block_widget[inverted ? 1 : 0], snapshot); } else { @@ -355,7 +365,7 @@ gtk_level_bar_render_trough (GtkGizmo *gizmo, num_blocks = gtk_level_bar_get_num_blocks (self); for (i = 0; i < num_blocks; i++) - gtk_widget_snapshot_child (widget, self->priv->block_widget[i], snapshot); + gtk_widget_snapshot_child (widget, priv->block_widget[i], snapshot); } return FALSE; @@ -366,8 +376,9 @@ gtk_level_bar_snapshot (GtkWidget *widget, GtkSnapshot *snapshot) { GtkLevelBar *self = GTK_LEVEL_BAR (widget); + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); - gtk_widget_snapshot_child (widget, self->priv->trough_widget, snapshot); + gtk_widget_snapshot_child (widget, priv->trough_widget, snapshot); } static void @@ -381,6 +392,7 @@ gtk_level_bar_measure_trough (GtkGizmo *gizmo, { GtkWidget *widget = GTK_WIDGET (gizmo); GtkLevelBar *self = GTK_LEVEL_BAR (gtk_widget_get_parent (widget)); + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); gint num_blocks, size; gint block_width, block_height; @@ -389,14 +401,14 @@ gtk_level_bar_measure_trough (GtkGizmo *gizmo, if (orientation == GTK_ORIENTATION_HORIZONTAL) { - if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) size = num_blocks * block_width; else size = block_width; } else { - if (self->priv->orientation == GTK_ORIENTATION_VERTICAL) + if (priv->orientation == GTK_ORIENTATION_VERTICAL) size = num_blocks * block_height; else size = block_height; @@ -415,7 +427,9 @@ gtk_level_bar_measure (GtkWidget *widget, int *minimum_baseline, int *natural_baseline) { - gtk_widget_measure (GTK_LEVEL_BAR (widget)->priv->trough_widget, + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (GTK_LEVEL_BAR (widget)); + + gtk_widget_measure (priv->trough_widget, orientation, for_size, minimum, natural, @@ -423,11 +437,12 @@ gtk_level_bar_measure (GtkWidget *widget, } static void -gtk_level_bar_allocate_trough_continuous (GtkLevelBar *self, +gtk_level_bar_allocate_trough_continuous (GtkLevelBar *self, const GtkAllocation *allocation, - int baseline, - GtkAllocation *out_clip) + int baseline, + GtkAllocation *out_clip) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); GtkAllocation block_area, clip; gdouble fill_percentage; gboolean inverted; @@ -436,25 +451,25 @@ gtk_level_bar_allocate_trough_continuous (GtkLevelBar *self, inverted = gtk_level_bar_get_real_inverted (self); /* allocate the empty (unfilled) part */ - gtk_widget_size_allocate (self->priv->block_widget[inverted ? 0 : 1], + gtk_widget_size_allocate (priv->block_widget[inverted ? 0 : 1], allocation, baseline, out_clip); - if (self->priv->cur_value == 0) + if (priv->cur_value == 0) return; /* now allocate the filled part */ block_area = *allocation; - fill_percentage = (self->priv->cur_value - self->priv->min_value) / - (self->priv->max_value - self->priv->min_value); + fill_percentage = (priv->cur_value - priv->min_value) / + (priv->max_value - priv->min_value); - gtk_widget_measure (self->priv->block_widget[inverted ? 1 : 0], - self->priv->orientation, -1, + gtk_widget_measure (priv->block_widget[inverted ? 1 : 0], + priv->orientation, -1, &block_min, NULL, NULL, NULL); - if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { block_area.width = (gint) floor (block_area.width * fill_percentage); block_area.width = MAX (block_area.width, block_min); @@ -471,7 +486,7 @@ gtk_level_bar_allocate_trough_continuous (GtkLevelBar *self, block_area.y += allocation->height - block_area.height; } - gtk_widget_size_allocate (self->priv->block_widget[inverted ? 1 : 0], + gtk_widget_size_allocate (priv->block_widget[inverted ? 1 : 0], &block_area, baseline, &clip); @@ -484,6 +499,7 @@ gtk_level_bar_allocate_trough_discrete (GtkLevelBar *self, int baseline, GtkAllocation *out_clip) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); GtkAllocation block_area, clip; gint num_blocks, i; gint block_width, block_height; @@ -494,7 +510,7 @@ gtk_level_bar_allocate_trough_discrete (GtkLevelBar *self, if (num_blocks == 0) return; - if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { block_width = MAX (block_width, (gint) floor (allocation->width / num_blocks)); block_height = allocation->height; @@ -512,13 +528,13 @@ gtk_level_bar_allocate_trough_discrete (GtkLevelBar *self, for (i = 0; i < num_blocks; i++) { - gtk_widget_size_allocate (self->priv->block_widget[i], + gtk_widget_size_allocate (priv->block_widget[i], &block_area, baseline, &clip); gdk_rectangle_intersect (out_clip, &clip, out_clip); - if (self->priv->orientation == GTK_ORIENTATION_HORIZONTAL) + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) block_area.x += block_area.width; else block_area.y += block_area.height; @@ -533,8 +549,9 @@ gtk_level_bar_allocate_trough (GtkGizmo *gizmo, { GtkWidget *widget = GTK_WIDGET (gizmo); GtkLevelBar *self = GTK_LEVEL_BAR (gtk_widget_get_parent (widget)); + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); - if (self->priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) + if (priv->bar_mode == GTK_LEVEL_BAR_MODE_CONTINUOUS) gtk_level_bar_allocate_trough_continuous (self, allocation, baseline, out_clip); else gtk_level_bar_allocate_trough_discrete (self, allocation, baseline, out_clip); @@ -554,7 +571,7 @@ gtk_level_bar_size_allocate (GtkWidget *widget, static void update_block_nodes (GtkLevelBar *self) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); guint n_blocks; guint i; @@ -586,7 +603,7 @@ update_block_nodes (GtkLevelBar *self) static void update_mode_style_classes (GtkLevelBar *self) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); GtkCssNode *widget_node; widget_node = gtk_widget_get_css_node (GTK_WIDGET (self)); @@ -605,7 +622,7 @@ update_mode_style_classes (GtkLevelBar *self) static void update_level_style_classes (GtkLevelBar *self) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); gdouble value; const gchar *value_class = NULL; GtkLevelBarOffset *offset, *prev_offset; @@ -689,18 +706,19 @@ gtk_level_bar_direction_changed (GtkWidget *widget, static void gtk_level_bar_ensure_offsets_in_range (GtkLevelBar *self) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); GtkLevelBarOffset *offset; - GList *l = self->priv->offsets; + GList *l = priv->offsets; while (l != NULL) { offset = l->data; l = l->next; - if (offset->value < self->priv->min_value) - gtk_level_bar_ensure_offset (self, offset->name, self->priv->min_value); - else if (offset->value > self->priv->max_value) - gtk_level_bar_ensure_offset (self, offset->name, self->priv->max_value); + if (offset->value < priv->min_value) + gtk_level_bar_ensure_offset (self, offset->name, priv->min_value); + else if (offset->value > priv->max_value) + gtk_level_bar_ensure_offset (self, offset->name, priv->max_value); } } @@ -837,9 +855,10 @@ static void gtk_level_bar_set_orientation (GtkLevelBar *self, GtkOrientation orientation) { - if (self->priv->orientation != orientation) + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + if (priv->orientation != orientation) { - self->priv->orientation = orientation; + priv->orientation = orientation; _gtk_orientable_set_style_classes (GTK_ORIENTABLE (self)); gtk_widget_queue_resize (GTK_WIDGET (self)); g_object_notify (G_OBJECT (self), "orientation"); @@ -853,6 +872,7 @@ gtk_level_bar_get_property (GObject *obj, GParamSpec *pspec) { GtkLevelBar *self = GTK_LEVEL_BAR (obj); + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); switch (property_id) { @@ -872,7 +892,7 @@ gtk_level_bar_get_property (GObject *obj, g_value_set_boolean (value, gtk_level_bar_get_inverted (self)); break; case PROP_ORIENTATION: - g_value_set_enum (value, self->priv->orientation); + g_value_set_enum (value, priv->orientation); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); @@ -918,7 +938,7 @@ static void gtk_level_bar_finalize (GObject *obj) { GtkLevelBar *self = GTK_LEVEL_BAR (obj); - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); gint i; g_list_free_full (priv->offsets, (GDestroyNotify) gtk_level_bar_offset_free); @@ -1053,9 +1073,7 @@ gtk_level_bar_class_init (GtkLevelBarClass *klass) static void gtk_level_bar_init (GtkLevelBar *self) { - GtkLevelBarPrivate *priv; - - priv = self->priv = gtk_level_bar_get_instance_private (self); + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); priv->cur_value = 0.0; priv->min_value = 0.0; @@ -1132,9 +1150,11 @@ gtk_level_bar_new_for_interval (gdouble min_value, gdouble gtk_level_bar_get_min_value (GtkLevelBar *self) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + g_return_val_if_fail (GTK_IS_LEVEL_BAR (self), 0.0); - return self->priv->min_value; + return priv->min_value; } /** @@ -1148,9 +1168,11 @@ gtk_level_bar_get_min_value (GtkLevelBar *self) gdouble gtk_level_bar_get_max_value (GtkLevelBar *self) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + g_return_val_if_fail (GTK_IS_LEVEL_BAR (self), 0.0); - return self->priv->max_value; + return priv->max_value; } /** @@ -1165,18 +1187,22 @@ gtk_level_bar_get_max_value (GtkLevelBar *self) gdouble gtk_level_bar_get_value (GtkLevelBar *self) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + g_return_val_if_fail (GTK_IS_LEVEL_BAR (self), 0.0); - return self->priv->cur_value; + return priv->cur_value; } static void gtk_level_bar_set_value_internal (GtkLevelBar *self, gdouble value) { - self->priv->cur_value = value; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + + priv->cur_value = value; g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_VALUE]); - gtk_widget_queue_allocate (GTK_WIDGET (self->priv->trough_widget)); + gtk_widget_queue_allocate (GTK_WIDGET (priv->trough_widget)); } /** @@ -1193,7 +1219,7 @@ void gtk_level_bar_set_min_value (GtkLevelBar *self, gdouble value) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); g_return_if_fail (GTK_IS_LEVEL_BAR (self)); g_return_if_fail (value >= 0.0); @@ -1225,7 +1251,7 @@ void gtk_level_bar_set_max_value (GtkLevelBar *self, gdouble value) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); g_return_if_fail (GTK_IS_LEVEL_BAR (self)); g_return_if_fail (value >= 0.0); @@ -1256,9 +1282,11 @@ void gtk_level_bar_set_value (GtkLevelBar *self, gdouble value) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + g_return_if_fail (GTK_IS_LEVEL_BAR (self)); - if (value == self->priv->cur_value) + if (value == priv->cur_value) return; gtk_level_bar_set_value_internal (self, value); @@ -1276,9 +1304,11 @@ gtk_level_bar_set_value (GtkLevelBar *self, GtkLevelBarMode gtk_level_bar_get_mode (GtkLevelBar *self) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + g_return_val_if_fail (GTK_IS_LEVEL_BAR (self), 0); - return self->priv->bar_mode; + return priv->bar_mode; } /** @@ -1292,7 +1322,7 @@ void gtk_level_bar_set_mode (GtkLevelBar *self, GtkLevelBarMode mode) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); g_return_if_fail (GTK_IS_LEVEL_BAR (self)); @@ -1320,9 +1350,11 @@ gtk_level_bar_set_mode (GtkLevelBar *self, gboolean gtk_level_bar_get_inverted (GtkLevelBar *self) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); + g_return_val_if_fail (GTK_IS_LEVEL_BAR (self), FALSE); - return self->priv->inverted; + return priv->inverted; } /** @@ -1336,7 +1368,7 @@ void gtk_level_bar_set_inverted (GtkLevelBar *self, gboolean inverted) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); g_return_if_fail (GTK_IS_LEVEL_BAR (self)); @@ -1361,7 +1393,7 @@ void gtk_level_bar_remove_offset_value (GtkLevelBar *self, const gchar *name) { - GtkLevelBarPrivate *priv = self->priv; + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); GList *existing; g_return_if_fail (GTK_IS_LEVEL_BAR (self)); @@ -1424,12 +1456,13 @@ gtk_level_bar_get_offset_value (GtkLevelBar *self, const gchar *name, gdouble *value) { + GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (self); GList *existing; GtkLevelBarOffset *offset = NULL; g_return_val_if_fail (GTK_IS_LEVEL_BAR (self), 0.0); - existing = g_list_find_custom (self->priv->offsets, name, offset_find_func); + existing = g_list_find_custom (priv->offsets, name, offset_find_func); if (existing) offset = existing->data; |