[gtk+/wip/baedert/drawing: 49/50] entry: Replace progress gadget with a progressbar
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/baedert/drawing: 49/50] entry: Replace progress gadget with a progressbar
- Date: Fri, 16 Jun 2017 14:20:33 +0000 (UTC)
commit 0efc57f4f3fecf43b40bc83182c838f3c2357940
Author: Timm Bäder <mail baedert org>
Date: Fri Jun 16 15:27:08 2017 +0200
entry: Replace progress gadget with a progressbar
gtk/gtkentry.c | 252 +++++++++++++-------------------------------------------
1 files changed, 59 insertions(+), 193 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 7b5f63b..cbe513b 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -67,7 +67,6 @@
#include "gtktoolbar.h"
#include "gtkmagnifierprivate.h"
#include "gtkcssnodeprivate.h"
-#include "gtkcsscustomgadgetprivate.h"
#include "gtkprogresstrackerprivate.h"
#include "gtkimageprivate.h"
@@ -214,7 +213,7 @@ struct _GtkEntryPrivate
GtkGesture *drag_gesture;
GtkGesture *multipress_gesture;
- GtkCssGadget *progress_gadget;
+ GtkWidget *progress_widget;
GtkCssNode *selection_node;
GtkCssNode *undershoot_node[2];
@@ -2694,7 +2693,8 @@ gtk_entry_finalize (GObject *object)
if (priv->attrs)
pango_attr_list_unref (priv->attrs);
- g_clear_object (&priv->progress_gadget);
+ if (priv->progress_widget)
+ gtk_widget_unparent (priv->progress_widget);
G_OBJECT_CLASS (gtk_entry_parent_class)->finalize (object);
}
@@ -2857,8 +2857,6 @@ update_node_state (GtkEntry *entry)
state = gtk_widget_get_state_flags (GTK_WIDGET (entry));
state &= ~GTK_STATE_FLAG_DROP_ACTIVE;
- if (priv->progress_gadget)
- gtk_css_gadget_set_state (priv->progress_gadget, state);
if (priv->selection_node)
gtk_css_node_set_state (priv->selection_node, state);
@@ -2874,10 +2872,10 @@ update_node_ordering (GtkEntry *entry)
GtkEntryIconPosition icon_pos;
GtkCssNode *sibling, *parent;
- if (priv->progress_gadget)
+ if (priv->progress_widget)
{
gtk_css_node_insert_before (gtk_widget_get_css_node (GTK_WIDGET (entry)),
- gtk_css_gadget_get_node (priv->progress_gadget),
+ gtk_widget_get_css_node (priv->progress_widget),
NULL);
}
@@ -3099,15 +3097,15 @@ gtk_entry_measure (GtkWidget *widget,
pango_font_metrics_unref (metrics);
- if (priv->progress_gadget && gtk_css_gadget_get_visible (priv->progress_gadget))
+ if (priv->progress_widget && gtk_widget_get_visible (priv->progress_widget))
{
int prog_min, prog_nat;
- gtk_css_gadget_get_preferred_size (priv->progress_gadget,
- orientation,
- for_size,
- &prog_min, &prog_nat,
- NULL, NULL);
+ gtk_widget_measure (priv->progress_widget,
+ orientation,
+ for_size,
+ &prog_min, &prog_nat,
+ NULL, NULL);
*minimum = MAX (*minimum, prog_min);
*natural = MAX (*natural, prog_nat);
@@ -3169,37 +3167,24 @@ gtk_entry_size_allocate (GtkWidget *widget,
gdk_rectangle_union (&child_clip, &clip, &clip);
}
- if (priv->progress_gadget && gtk_css_gadget_get_visible (priv->progress_gadget))
+ if (priv->progress_widget && gtk_widget_get_visible (priv->progress_widget))
{
- int extra_width, req_width;
+ int req_width;
GtkAllocation progress_alloc;
- gtk_css_gadget_get_preferred_size (priv->progress_gadget,
- GTK_ORIENTATION_HORIZONTAL,
- allocation->height,
- &req_width, NULL,
- NULL, NULL);
- extra_width = allocation->width - req_width;
-
- progress_alloc = *allocation;
-
- if (priv->progress_pulse_mode)
- {
- gdouble value = priv->progress_pulse_current;
-
- progress_alloc.x += (gint) floor (value * extra_width);
- progress_alloc.width = req_width + (gint) ceil (priv->progress_pulse_fraction * extra_width);
- }
- else
- {
- gdouble value = priv->progress_fraction;
+ gtk_widget_measure (priv->progress_widget,
+ GTK_ORIENTATION_HORIZONTAL,
+ allocation->height,
+ &req_width, NULL,
+ NULL, NULL);
- progress_alloc.width = req_width + (gint) nearbyint (value * extra_width);
- if (gtk_widget_get_direction (GTK_WIDGET (entry)) == GTK_TEXT_DIR_RTL)
- progress_alloc.x += allocation->width - progress_alloc.width;
- }
+ progress_alloc.x = 0;
+ progress_alloc.y = 0;
+ progress_alloc.width = MAX (allocation->width, req_width);
+ progress_alloc.height = allocation->height;
- gtk_css_gadget_allocate (priv->progress_gadget, &progress_alloc, -1, &child_clip);
+ gtk_widget_size_allocate (priv->progress_widget, &progress_alloc);
+ gtk_widget_get_clip (priv->progress_widget, &child_clip);
gdk_rectangle_union (&child_clip, &clip, &clip);
}
@@ -3299,8 +3284,8 @@ gtk_entry_snapshot (GtkWidget *widget,
allocation.height = content_allocation.height;
/* Draw progress */
- if (priv->progress_gadget && gtk_css_gadget_get_visible (priv->progress_gadget))
- gtk_css_gadget_snapshot (priv->progress_gadget, snapshot);
+ if (priv->progress_widget && gtk_widget_get_visible (priv->progress_widget))
+ gtk_widget_snapshot_child (widget, priv->progress_widget, snapshot);
/* Draw text and cursor */
cr = gtk_snapshot_append_cairo (snapshot,
@@ -9379,142 +9364,21 @@ gtk_entry_get_cursor_hadjustment (GtkEntry *entry)
return g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
}
-static gboolean
-tick_cb (GtkWidget *widget,
- GdkFrameClock *frame_clock,
- gpointer user_data)
-{
- GtkEntry *entry = GTK_ENTRY (widget);
- GtkEntryPrivate *priv = entry->priv;
- gint64 frame_time;
- gdouble iteration, pulse_iterations, current_iterations, fraction;
-
- if (priv->pulse2 == 0 && priv->pulse1 == 0)
- return G_SOURCE_CONTINUE;
-
- frame_time = gdk_frame_clock_get_frame_time (frame_clock);
- gtk_progress_tracker_advance_frame (&priv->tracker, frame_time);
-
- g_assert (priv->pulse2 > priv->pulse1);
-
- pulse_iterations = (priv->pulse2 - priv->pulse1) / (gdouble) G_USEC_PER_SEC;
- current_iterations = (frame_time - priv->pulse1) / (gdouble) G_USEC_PER_SEC;
-
- iteration = gtk_progress_tracker_get_iteration (&priv->tracker);
- /* Determine the fraction to move the block from one frame
- * to the next when pulse_fraction is how far the block should
- * move between two calls to gtk_entry_progress_pulse().
- */
- fraction = priv->progress_pulse_fraction * (iteration - priv->last_iteration) / MAX (pulse_iterations,
current_iterations);
- priv->last_iteration = iteration;
-
- if (current_iterations > 3 * pulse_iterations)
- return G_SOURCE_CONTINUE;
-
- /* advance the block */
- if (priv->progress_pulse_way_back)
- {
- priv->progress_pulse_current -= fraction;
-
- if (priv->progress_pulse_current < 0.0)
- {
- priv->progress_pulse_current = 0.0;
- priv->progress_pulse_way_back = FALSE;
- }
- }
- else
- {
- priv->progress_pulse_current += fraction;
-
- if (priv->progress_pulse_current > 1.0 - priv->progress_pulse_fraction)
- {
- priv->progress_pulse_current = 1.0 - priv->progress_pulse_fraction;
- priv->progress_pulse_way_back = TRUE;
- }
- }
-
- gtk_widget_queue_allocate (widget);
-
- return G_SOURCE_CONTINUE;
-}
-
-static void
-gtk_entry_ensure_progress_gadget (GtkEntry *entry)
-{
- GtkEntryPrivate *priv = entry->priv;
-
- if (priv->progress_gadget)
- return;
-
- priv->progress_gadget = gtk_css_custom_gadget_new ("progress",
- GTK_WIDGET (entry),
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL);
- gtk_css_gadget_set_state (priv->progress_gadget,
- gtk_css_node_get_state (gtk_widget_get_css_node (GTK_WIDGET (entry))));
-
- update_node_ordering (entry);
-}
-
static void
-gtk_entry_start_pulse_mode (GtkEntry *entry)
+gtk_entry_ensure_progress_widget (GtkEntry *entry)
{
GtkEntryPrivate *priv = entry->priv;
- if (priv->progress_pulse_mode)
+ if (priv->progress_widget)
return;
- gtk_entry_ensure_progress_gadget (entry);
- gtk_css_gadget_set_visible (priv->progress_gadget, TRUE);
- gtk_css_gadget_add_class (priv->progress_gadget, GTK_STYLE_CLASS_PULSE);
-
- priv->progress_pulse_mode = TRUE;
- /* How long each pulse should last depends on calls to gtk_entry_progress_pulse.
- * Just start the tracker to repeat forever with iterations every second. */
- gtk_progress_tracker_start (&priv->tracker, G_USEC_PER_SEC, 0, INFINITY);
- priv->tick_id = gtk_widget_add_tick_callback (GTK_WIDGET (entry), tick_cb, NULL, NULL);
-
- priv->progress_fraction = 0.0;
- priv->progress_pulse_way_back = FALSE;
- priv->progress_pulse_current = 0.0;
-
- priv->pulse2 = 0;
- priv->pulse1 = 0;
- priv->last_iteration = 0;
-}
-
-static void
-gtk_entry_stop_pulse_mode (GtkEntry *entry)
-{
- GtkEntryPrivate *priv = entry->priv;
+ priv->progress_widget = g_object_new (GTK_TYPE_PROGRESS_BAR,
+ "css-name", "progress",
+ NULL);
- if (priv->progress_pulse_mode)
- {
- gtk_css_gadget_set_visible (priv->progress_gadget, FALSE);
- gtk_css_gadget_remove_class (priv->progress_gadget, GTK_STYLE_CLASS_PULSE);
-
- priv->progress_pulse_mode = FALSE;
- gtk_widget_remove_tick_callback (GTK_WIDGET (entry), priv->tick_id);
- priv->tick_id = 0;
- }
-}
-
-static void
-gtk_entry_update_pulse (GtkEntry *entry)
-{
- GtkEntryPrivate *priv = entry->priv;
- gint64 pulse_time = g_get_monotonic_time ();
+ gtk_widget_set_parent (priv->progress_widget, GTK_WIDGET (entry));
- if (priv->pulse2 == pulse_time)
- return;
-
- priv->pulse1 = priv->pulse2;
- priv->pulse2 = pulse_time;
+ update_node_ordering (entry);
}
/**
@@ -9532,34 +9396,23 @@ void
gtk_entry_set_progress_fraction (GtkEntry *entry,
gdouble fraction)
{
- GtkWidget *widget;
GtkEntryPrivate *private;
gdouble old_fraction;
g_return_if_fail (GTK_IS_ENTRY (entry));
- widget = GTK_WIDGET (entry);
private = entry->priv;
- if (private->progress_pulse_mode)
- old_fraction = -1;
- else
- old_fraction = private->progress_fraction;
-
- gtk_entry_stop_pulse_mode (entry);
-
- gtk_entry_ensure_progress_gadget (entry);
-
+ gtk_entry_ensure_progress_widget (entry);
+ old_fraction = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (private->progress_widget));
fraction = CLAMP (fraction, 0.0, 1.0);
- private->progress_fraction = fraction;
- private->progress_pulse_current = 0.0;
if (fraction != old_fraction)
{
- gtk_css_gadget_set_visible (private->progress_gadget, fraction > 0);
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (private->progress_widget), fraction);
+ gtk_widget_set_visible (private->progress_widget, fraction > 0);
g_object_notify_by_pspec (G_OBJECT (entry), entry_props[PROP_PROGRESS_FRACTION]);
- gtk_widget_queue_allocate (widget);
}
}
@@ -9577,9 +9430,14 @@ gtk_entry_set_progress_fraction (GtkEntry *entry,
gdouble
gtk_entry_get_progress_fraction (GtkEntry *entry)
{
+ GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
+
g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
- return entry->priv->progress_fraction;
+ if (priv->progress_widget)
+ return gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (priv->progress_widget));
+
+ return 0.0;
}
/**
@@ -9596,17 +9454,18 @@ void
gtk_entry_set_progress_pulse_step (GtkEntry *entry,
gdouble fraction)
{
- GtkEntryPrivate *private;
+ GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
g_return_if_fail (GTK_IS_ENTRY (entry));
- private = entry->priv;
-
fraction = CLAMP (fraction, 0.0, 1.0);
- if (fraction != private->progress_pulse_fraction)
+ if (priv->progress_widget)
+ gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR (priv->progress_widget), fraction);
+
+ if (fraction != priv->progress_pulse_fraction)
{
- private->progress_pulse_fraction = fraction;
+ priv->progress_pulse_fraction = fraction;
g_object_notify_by_pspec (G_OBJECT (entry), entry_props[PROP_PROGRESS_PULSE_STEP]);
}
}
@@ -9624,9 +9483,14 @@ gtk_entry_set_progress_pulse_step (GtkEntry *entry,
gdouble
gtk_entry_get_progress_pulse_step (GtkEntry *entry)
{
+ GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
+
g_return_val_if_fail (GTK_IS_ENTRY (entry), 0.0);
- return entry->priv->progress_pulse_fraction;
+ if (priv->progress_widget)
+ return gtk_progress_bar_get_pulse_step (GTK_PROGRESS_BAR (priv->progress_widget));
+
+ return 0.0;
}
/**
@@ -9645,10 +9509,12 @@ gtk_entry_get_progress_pulse_step (GtkEntry *entry)
void
gtk_entry_progress_pulse (GtkEntry *entry)
{
+ GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
+
g_return_if_fail (GTK_IS_ENTRY (entry));
- gtk_entry_start_pulse_mode (entry);
- gtk_entry_update_pulse (entry);
+ if (priv->progress_widget)
+ gtk_progress_bar_pulse (GTK_PROGRESS_BAR (priv->progress_widget));
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]