[gtk+/wip/csoriano/pathbar-bin-view-window] Experiment with a view and bin window
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/csoriano/pathbar-bin-view-window] Experiment with a view and bin window
- Date: Thu, 2 Jun 2016 15:03:38 +0000 (UTC)
commit f37d93931f919adb1c621571c5dc78ca90b5a0e1
Author: Carlos Soriano <csoriano gnome org>
Date: Thu Jun 2 17:01:49 2016 +0200
Experiment with a view and bin window
gtk/gtkhidingbox.c | 182 ++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 147 insertions(+), 35 deletions(-)
---
diff --git a/gtk/gtkhidingbox.c b/gtk/gtkhidingbox.c
index 2417741..bab112c 100644
--- a/gtk/gtkhidingbox.c
+++ b/gtk/gtkhidingbox.c
@@ -56,7 +56,9 @@ struct _GtkHidingBoxPrivate
gboolean invert_animation;
- GtkWidget *scrolled_window;
+ GdkWindow *bin_window;
+ GdkWindow *view_window;
+
GtkWidget *box;
GtkAdjustment *hadjustment;
@@ -173,7 +175,8 @@ gtk_hiding_box_add (GtkContainer *container,
g_print ("box fine? %s \n", G_OBJECT_TYPE_NAME (priv->box));
gtk_container_add (GTK_CONTAINER (priv->box), revealer);
priv->children = g_list_append (priv->children, widget);
- gtk_widget_show (revealer);
+ gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), TRUE);
+ gtk_widget_show_all (revealer);
g_print ("add\n");
}
@@ -255,7 +258,7 @@ gtk_hiding_box_forall (GtkContainer *container,
if (include_internals)
{
- (* callback) (priv->scrolled_window, callback_data);
+ (* callback) (priv->box, callback_data);
for (child = priv->widgets_to_remove; child != NULL; child = child->next)
(* callback) (child->data, callback_data);
@@ -263,6 +266,54 @@ gtk_hiding_box_forall (GtkContainer *container,
}
static void
+get_children_allocation (GtkHidingBox *self,
+ GtkAllocation *allocation,
+ GtkAllocation *child_allocation)
+{
+ GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (self);
+ GtkWidget *child_widget;
+ GList *child;
+ GtkRequestedSize *sizes_temp;
+ gint i;
+ GList *children;
+ gint current_children_min_width = 0;
+ gint current_children_nat_width = 0;
+
+ children = g_list_copy (priv->children);
+ sizes_temp = g_newa (GtkRequestedSize, g_list_length (priv->children));
+ child_allocation->x = 0;
+ child_allocation->y = 0;
+ child_allocation->height = allocation->height;
+
+ if (priv->inverted)
+ children = g_list_reverse (children);
+
+ /* Retrieve desired size for visible children. */
+ for (i = 0, child = children; child != NULL; i++, child = child->next)
+ {
+ child_widget = GTK_WIDGET (child->data);
+
+ /* If we are in the middle of a revealer animation, get the revealer
+ * allocation */
+ gtk_widget_get_preferred_width_for_height (gtk_widget_get_parent (child_widget),
+ allocation->height,
+ &sizes_temp[i].minimum_size,
+ &sizes_temp[i].natural_size);
+
+ current_children_min_width += sizes_temp[i].minimum_size;
+ current_children_nat_width += sizes_temp[i].natural_size;
+ }
+
+ if (current_children_nat_width > allocation->width)
+ child_allocation->width = current_children_min_width;
+ else
+ child_allocation->width = current_children_nat_width;
+
+ g_list_free (children);
+}
+
+#if 0
+static void
update_children_visibility (GtkHidingBox *box,
GtkAllocation *allocation)
{
@@ -391,13 +442,13 @@ idle_update_revealers (GtkHidingBox *box)
gdouble max_real_adjustment;
max_real_adjustment = gtk_adjustment_get_upper (priv->hadjustment) -
- gtk_widget_get_allocated_width (priv->scrolled_window);
+ gtk_widget_get_allocated_width (priv->bin_window);
g_print ("animation velocity %f %f\n", max_real_adjustment, velocity);
- revealer_animation_time = (gtk_widget_get_allocated_width (priv->scrolled_window) -
+ revealer_animation_time = (gtk_widget_get_allocated_width (priv->bin_window) -
priv->allocated_children_width) /
velocity;
- g_print ("animation time %d %d %d\n", priv->allocated_children_width,
gtk_widget_get_allocated_width (priv->scrolled_window), revealer_animation_time);
+ g_print ("animation time %d %d %d\n", priv->allocated_children_width,
gtk_widget_get_allocated_width (priv->bin_window), revealer_animation_time);
add_opacity_class (revealer, "pathbar-invert-animation-opacity-off");
g_signal_connect (revealer, "notify::child-revealed", (GCallback) opacity_off, box);
gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), revealer_animation_time);
@@ -468,31 +519,37 @@ idle_update_revealers (GtkHidingBox *box)
}
+#endif
+
static void
gtk_hiding_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
- GtkHidingBox *box = GTK_HIDING_BOX (widget);
- GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (box);
+ GtkHidingBox *self = GTK_HIDING_BOX (widget);
+ GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (self);
GtkAllocation child_allocation;
GtkRequestedSize *sizes;
gtk_widget_set_allocation (widget, allocation);
+ gdk_window_move_resize (priv->view_window,
+ allocation->x, allocation->y,
+ allocation->width, allocation->height);
+
sizes = g_newa (GtkRequestedSize, g_list_length (priv->children));
- update_children_visibility (box, allocation);
+ //update_children_visibility (self, allocation);
- idle_update_revealers (box);
+ //idle_update_revealers (self);
- child_allocation.x = allocation->x;
- child_allocation.y = allocation->y;
- child_allocation.width = allocation->width;
- child_allocation.height = allocation->height;
- gtk_widget_size_allocate (priv->scrolled_window, &child_allocation);
+ get_children_allocation (self, allocation, &child_allocation);
+ gtk_widget_size_allocate (priv->box, &child_allocation);
- _gtk_widget_set_simple_clip (widget, NULL);
+ gdk_window_move_resize (priv->bin_window,
+ 20, 0,
+ child_allocation.width, child_allocation.height);
}
+#if 0
static void
update_hadjustment (GtkHidingBox *self)
{
@@ -501,9 +558,9 @@ update_hadjustment (GtkHidingBox *self)
gdouble max_real_adjustment;
max_real_adjustment = gtk_adjustment_get_upper (priv->hadjustment) -
- gtk_widget_get_allocated_width (priv->scrolled_window);
+ gtk_widget_get_allocated_width (priv->bin_window);
- g_print ("aligment changed %f %f %d %f\n", max_real_adjustment, gtk_adjustment_get_upper
(priv->hadjustment), gtk_widget_get_allocated_width (priv->scrolled_window), gtk_adjustment_get_lower
(priv->hadjustment));
+ g_print ("aligment changed %f %f %d %f\n", max_real_adjustment, gtk_adjustment_get_upper
(priv->hadjustment), gtk_widget_get_allocated_width (priv->bin_window), gtk_adjustment_get_lower
(priv->hadjustment));
if (priv->invert_animation)
{
if (priv->inverted)
@@ -542,7 +599,7 @@ finish_invert_animation (GtkHidingBox *self)
idle_update_revealers (self);
priv->invert_animation = FALSE;
priv->invert_animation_initial_time = 0;
- gtk_widget_remove_tick_callback (priv->scrolled_window,
+ gtk_widget_remove_tick_callback (priv->bin_window,
priv->invert_animation_tick_id);
priv->invert_animation_tick_id = 0;
}
@@ -559,14 +616,14 @@ invert_animation_on_tick (GtkWidget *widget,
gdouble max_real_adjustment;
max_real_adjustment = gtk_adjustment_get_upper (priv->hadjustment) -
- (gdouble) gtk_widget_get_allocated_width (priv->scrolled_window);
+ (gdouble) gtk_widget_get_allocated_width (priv->bin_window);
if (priv->invert_animation_initial_time == 0)
priv->invert_animation_initial_time = gdk_frame_clock_get_frame_time (frame_clock);
elapsed = gdk_frame_clock_get_frame_time (frame_clock) - priv->invert_animation_initial_time;
priv->invert_animation_progress = elapsed * INVERT_ANIMATION_SPEED / (1000. * max_real_adjustment);
- g_print ("################animation progres %d %f %f %f\n", gtk_widget_get_allocated_width
(priv->scrolled_window), max_real_adjustment, elapsed / 1000., priv->invert_animation_progress);
+ g_print ("################animation progres %d %f %f %f\n", gtk_widget_get_allocated_width
(priv->bin_window), max_real_adjustment, elapsed / 1000., priv->invert_animation_progress);
update_hadjustment (self);
if (priv->invert_animation_progress >= 1)
@@ -602,7 +659,7 @@ start_invert_animation (GtkHidingBox *self)
gtk_revealer_set_reveal_child (GTK_REVEALER (revealer), TRUE);
}
- priv->invert_animation_tick_id = gtk_widget_add_tick_callback (priv->scrolled_window,
+ priv->invert_animation_tick_id = gtk_widget_add_tick_callback (priv->bin_window,
(GtkTickCallback) invert_animation_on_tick,
self, NULL);
}
@@ -613,6 +670,7 @@ hadjustment_on_changed (GtkAdjustment *hadjustment,
{
update_hadjustment (GTK_HIDING_BOX (user_data));
}
+#endif
static void
gtk_hiding_box_get_preferred_width (GtkWidget *widget,
@@ -698,21 +756,75 @@ on_what (gpointer data,
}
static void
+gtk_hiding_box_unrealize (GtkWidget *widget)
+{
+ GtkHidingBox *self = GTK_HIDING_BOX (widget);
+ GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (self);
+
+ gtk_widget_unregister_window (widget, priv->bin_window);
+ gdk_window_destroy (priv->bin_window);
+ priv->view_window = NULL;
+
+ GTK_WIDGET_CLASS (gtk_hiding_box_parent_class)->unrealize (widget);
+}
+
+static void
+gtk_hiding_box_realize (GtkWidget *widget)
+{
+ GtkHidingBox *self = GTK_HIDING_BOX (widget);
+ GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (self);
+ GtkAllocation allocation;
+ GtkAllocation child_allocation;
+ GdkWindowAttr attributes = { 0 };
+ GdkWindowAttributesType attributes_mask;
+
+ gtk_widget_set_realized (widget, TRUE);
+
+ gtk_widget_get_allocation (widget, &allocation);
+
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.wclass = GDK_INPUT_OUTPUT;
+ attributes.visual = gtk_widget_get_visual (widget);
+ attributes.event_mask = gtk_widget_get_events (widget);
+ attributes_mask = (GDK_WA_X | GDK_WA_Y) | GDK_WA_VISUAL;
+
+ priv->view_window = gdk_window_new (gtk_widget_get_parent_window ((GtkWidget*) self),
+ &attributes, attributes_mask);
+ gtk_widget_set_window (widget, priv->view_window);
+ gtk_widget_register_window (widget, priv->view_window);
+
+ get_children_allocation (self, &allocation, &child_allocation);
+ attributes.x = 0;
+ attributes.y = 0;
+ attributes.width = child_allocation.width;
+ attributes.height = child_allocation.height;
+
+ priv->bin_window = gdk_window_new (priv->view_window, &attributes,
+ attributes_mask);
+ gtk_widget_register_window (widget, priv->bin_window);
+
+ gtk_widget_set_parent_window (priv->box, priv->bin_window);
+
+ gdk_window_show (priv->bin_window);
+ gdk_window_show (priv->view_window);
+ gtk_widget_show_all (priv->box);
+}
+
+static void
gtk_hiding_box_init (GtkHidingBox *box)
{
GtkHidingBoxPrivate *priv = gtk_hiding_box_get_instance_private (box);
- GtkWidget *hscrollbar;
-
- gtk_widget_set_has_window (GTK_WIDGET (box), FALSE);
- priv->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- priv->hadjustment = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (priv->scrolled_window));
- g_signal_connect (priv->hadjustment, "changed", (GCallback) hadjustment_on_changed, box);
- hscrollbar = gtk_scrolled_window_get_hscrollbar (GTK_SCROLLED_WINDOW (priv->scrolled_window));
- gtk_widget_hide (hscrollbar);
+
+ gtk_widget_set_has_window (GTK_WIDGET (box), TRUE);
+ gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), TRUE);
+
priv->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_widget_show (priv->box);
g_object_weak_ref (G_OBJECT (priv->box), on_what, NULL);
- gtk_container_add (GTK_CONTAINER (priv->scrolled_window), priv->box);
- gtk_widget_set_parent (priv->scrolled_window, GTK_WIDGET (box));
priv->invert_animation = FALSE;
priv->spacing = 0;
@@ -721,8 +833,6 @@ gtk_hiding_box_init (GtkHidingBox *box)
priv->widgets_to_hide = NULL;
priv->widgets_to_show = NULL;
priv->widgets_to_remove = NULL;
-
- gtk_widget_show_all (priv->scrolled_window);
}
static void
@@ -739,6 +849,8 @@ gtk_hiding_box_class_init (GtkHidingBoxClass *class)
widget_class->get_preferred_width = gtk_hiding_box_get_preferred_width;
widget_class->get_preferred_height = gtk_hiding_box_get_preferred_height;
widget_class->get_request_mode = gtk_hiding_box_get_request_mode;
+ widget_class->realize = gtk_hiding_box_realize;
+ widget_class->unrealize = gtk_hiding_box_unrealize;
container_class->add = gtk_hiding_box_add;
container_class->remove = gtk_hiding_box_remove;
@@ -839,7 +951,7 @@ gtk_hiding_box_set_inverted (GtkHidingBox *box,
g_object_notify (G_OBJECT (box), "inverted");
- start_invert_animation (box);
+ //start_invert_animation (box);
gtk_widget_queue_resize (GTK_WIDGET (box));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]