[gtk+/native-layout-incubator-2] Separated the width and height requests into proper 2 methods, consequently fixing a bug in the hscr
- From: Tristan Van Berkom <tvb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/native-layout-incubator-2] Separated the width and height requests into proper 2 methods, consequently fixing a bug in the hscr
- Date: Wed, 30 Jun 2010 15:31:52 +0000 (UTC)
commit 73ba914d4c4835cfde5d7c5f4565153adddb49f1
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date: Wed Jun 30 11:23:26 2010 -0400
Separated the width and height requests into proper 2 methods,
consequently fixing a bug in the hscrollbar allocation.
gtk/gtkscrolledwindow.c | 245 ++++++++++++++++++++++++++--------------------
1 files changed, 138 insertions(+), 107 deletions(-)
---
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 612ff23..8928312 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -1716,105 +1716,72 @@ _gtk_scrolled_window_get_scrollbar_spacing (GtkScrolledWindow *scrolled_window)
}
}
+static GtkSizeRequestIface *parent_size_request_iface;
static void
gtk_scrolled_window_size_request_init (GtkSizeRequestIface *iface)
{
+ parent_size_request_iface = g_type_interface_peek_parent (iface);
iface->get_width = gtk_scrolled_window_get_width;
iface->get_height = gtk_scrolled_window_get_height;
iface->get_height_for_width = gtk_scrolled_window_get_height_for_width;
iface->get_width_for_height = gtk_scrolled_window_get_width_for_height;
}
-static void
-gtk_scrolled_window_get_size (GtkSizeRequest *widget,
- GtkOrientation orientation,
- gint *minimum_size,
- gint *natural_size)
+static void
+gtk_scrolled_window_get_width (GtkSizeRequest *widget,
+ gint *minimum_size,
+ gint *natural_size)
{
+
GtkScrolledWindow *scrolled_window;
- GtkBin *bin;
- gint extra_width;
- gint extra_height;
- gint scrollbar_spacing;
GtkRequisition hscrollbar_requisition;
GtkRequisition vscrollbar_requisition;
- GtkRequisition minimum_req, natural_req;
+ GtkWidget *child;
+ gint min_width, nat_width;
gint min_child_size, nat_child_size;
+ gint extra_width;
+ gint scrollbar_spacing;
scrolled_window = GTK_SCROLLED_WINDOW (widget);
- bin = GTK_BIN (scrolled_window);
+ child = gtk_bin_get_child (GTK_BIN (scrolled_window));
scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
extra_width = 0;
- extra_height = 0;
- minimum_req.width = 0;
- minimum_req.height = 0;
- natural_req.width = 0;
- natural_req.height = 0;
+ min_width = 0;
+ nat_width = 0;
gtk_widget_size_request (scrolled_window->hscrollbar,
&hscrollbar_requisition);
gtk_widget_size_request (scrolled_window->vscrollbar,
&vscrollbar_requisition);
- if (bin->child && gtk_widget_get_visible (bin->child))
+ if (child && gtk_widget_get_visible (child))
{
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ gtk_size_request_get_width (GTK_SIZE_REQUEST (child),
+ &min_child_size,
+ &nat_child_size);
+
+ if (scrolled_window->hscrollbar_policy == GTK_POLICY_NEVER)
{
- gtk_size_request_get_width (GTK_SIZE_REQUEST (bin->child),
- &min_child_size,
- &nat_child_size);
-
- if (scrolled_window->hscrollbar_policy == GTK_POLICY_NEVER)
- {
- minimum_req.width += min_child_size;
- natural_req.width += nat_child_size;
- }
- else
- {
- GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (bin->child, FALSE);
-
- if (aux_info && aux_info->width > 0)
- {
- minimum_req.width += aux_info->width;
- natural_req.width += aux_info->width;
- extra_width = -1;
- }
- else
- {
- minimum_req.width += vscrollbar_requisition.width;
- natural_req.width += vscrollbar_requisition.width;
- }
- }
+ min_width += min_child_size;
+ nat_width += nat_child_size;
}
- else /* GTK_ORIENTATION_VERTICAL */
+ else
{
- gtk_size_request_get_height (GTK_SIZE_REQUEST (bin->child),
- &min_child_size,
- &nat_child_size);
+ GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (child, FALSE);
- if (scrolled_window->vscrollbar_policy == GTK_POLICY_NEVER)
+ if (aux_info && aux_info->width > 0)
{
- minimum_req.height += min_child_size;
- natural_req.height += nat_child_size;
+ min_width += aux_info->width;
+ nat_width += aux_info->width;
+ extra_width = -1;
}
else
{
- GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (bin->child, FALSE);
-
- if (aux_info && aux_info->height > 0)
- {
- minimum_req.height += aux_info->height;
- natural_req.height += aux_info->height;
- extra_height = -1;
- }
- else
- {
- minimum_req.height += hscrollbar_requisition.height;
- natural_req.height += hscrollbar_requisition.height;
- }
+ min_width += vscrollbar_requisition.width;
+ nat_width += vscrollbar_requisition.width;
}
}
}
@@ -1822,56 +1789,30 @@ gtk_scrolled_window_get_size (GtkSizeRequest *widget,
if (scrolled_window->hscrollbar_policy == GTK_POLICY_AUTOMATIC ||
scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS)
{
- minimum_req.width = MAX (minimum_req.width, hscrollbar_requisition.width);
- natural_req.width = MAX (natural_req.width, hscrollbar_requisition.width);
- if (!extra_height || scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS)
- extra_height = scrollbar_spacing + hscrollbar_requisition.height;
+ min_width = MAX (min_width, hscrollbar_requisition.width);
+ nat_width = MAX (nat_width, hscrollbar_requisition.width);
}
if (scrolled_window->vscrollbar_policy == GTK_POLICY_AUTOMATIC ||
scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS)
{
- minimum_req.height = MAX (minimum_req.height, vscrollbar_requisition.height);
- natural_req.height = MAX (natural_req.height, vscrollbar_requisition.height);
- if (!extra_height || scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS)
+ if (!extra_width || scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS)
extra_width = scrollbar_spacing + vscrollbar_requisition.width;
}
- minimum_req.width += GTK_CONTAINER (widget)->border_width * 2 + MAX (0, extra_width);
- minimum_req.height += GTK_CONTAINER (widget)->border_width * 2 + MAX (0, extra_height);
- natural_req.width += GTK_CONTAINER (widget)->border_width * 2 + MAX (0, extra_width);
- natural_req.height += GTK_CONTAINER (widget)->border_width * 2 + MAX (0, extra_height);
+ min_width += GTK_CONTAINER (widget)->border_width * 2 + MAX (0, extra_width);
+ nat_width += GTK_CONTAINER (widget)->border_width * 2 + MAX (0, extra_width);
if (scrolled_window->shadow_type != GTK_SHADOW_NONE)
{
- minimum_req.width += 2 * GTK_WIDGET (widget)->style->xthickness;
- minimum_req.height += 2 * GTK_WIDGET (widget)->style->ythickness;
- natural_req.width += 2 * GTK_WIDGET (widget)->style->xthickness;
- natural_req.height += 2 * GTK_WIDGET (widget)->style->ythickness;
+ min_width += 2 * GTK_WIDGET (widget)->style->xthickness;
+ nat_width += 2 * GTK_WIDGET (widget)->style->xthickness;
}
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- if (minimum_size)
- *minimum_size = minimum_req.width;
- if (natural_size)
- *natural_size = natural_req.width;
- }
- else
- {
- if (minimum_size)
- *minimum_size = minimum_req.height;
- if (natural_size)
- *natural_size = natural_req.height;
- }
-}
-
-static void
-gtk_scrolled_window_get_width (GtkSizeRequest *widget,
- gint *minimum_size,
- gint *natural_size)
-{
- gtk_scrolled_window_get_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
+ if (minimum_size)
+ *minimum_size = min_width;
+ if (natural_size)
+ *natural_size = nat_width;
}
static void
@@ -1879,7 +1820,85 @@ gtk_scrolled_window_get_height (GtkSizeRequest *widget,
gint *minimum_size,
gint *natural_size)
{
- gtk_scrolled_window_get_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
+ GtkScrolledWindow *scrolled_window;
+ GtkRequisition hscrollbar_requisition;
+ GtkRequisition vscrollbar_requisition;
+ GtkWidget *child;
+ gint min_height, nat_height;
+ gint min_child_size, nat_child_size;
+ gint extra_height;
+ gint scrollbar_spacing;
+
+ scrolled_window = GTK_SCROLLED_WINDOW (widget);
+ child = gtk_bin_get_child (GTK_BIN (scrolled_window));
+
+ scrollbar_spacing = _gtk_scrolled_window_get_scrollbar_spacing (scrolled_window);
+
+ extra_height = 0;
+ min_height = 0;
+ nat_height = 0;
+
+ gtk_widget_size_request (scrolled_window->hscrollbar,
+ &hscrollbar_requisition);
+ gtk_widget_size_request (scrolled_window->vscrollbar,
+ &vscrollbar_requisition);
+
+ if (child && gtk_widget_get_visible (child))
+ {
+ gtk_size_request_get_height (GTK_SIZE_REQUEST (child),
+ &min_child_size,
+ &nat_child_size);
+
+ if (scrolled_window->vscrollbar_policy == GTK_POLICY_NEVER)
+ {
+ min_height += min_child_size;
+ nat_height += nat_child_size;
+ }
+ else
+ {
+ GtkWidgetAuxInfo *aux_info = _gtk_widget_get_aux_info (child, FALSE);
+
+ if (aux_info && aux_info->height > 0)
+ {
+ min_height += aux_info->height;
+ nat_height += aux_info->height;
+ extra_height = -1;
+ }
+ else
+ {
+ min_height += hscrollbar_requisition.height;
+ nat_height += hscrollbar_requisition.height;
+ }
+ }
+ }
+
+ if (scrolled_window->hscrollbar_policy == GTK_POLICY_AUTOMATIC ||
+ scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS)
+ {
+ if (!extra_height || scrolled_window->hscrollbar_policy == GTK_POLICY_ALWAYS)
+ extra_height = scrollbar_spacing + hscrollbar_requisition.height;
+ }
+
+ if (scrolled_window->vscrollbar_policy == GTK_POLICY_AUTOMATIC ||
+ scrolled_window->vscrollbar_policy == GTK_POLICY_ALWAYS)
+ {
+ min_height = MAX (min_height, vscrollbar_requisition.height);
+ nat_height = MAX (nat_height, vscrollbar_requisition.height);
+ }
+
+ min_height += GTK_CONTAINER (widget)->border_width * 2 + MAX (0, extra_height);
+ nat_height += GTK_CONTAINER (widget)->border_width * 2 + MAX (0, extra_height);
+
+ if (scrolled_window->shadow_type != GTK_SHADOW_NONE)
+ {
+ min_height += 2 * GTK_WIDGET (widget)->style->ythickness;
+ nat_height += 2 * GTK_WIDGET (widget)->style->ythickness;
+ }
+
+ if (minimum_size)
+ *minimum_size = min_height;
+ if (natural_size)
+ *natural_size = nat_height;
}
static void
@@ -1887,10 +1906,16 @@ gtk_scrolled_window_get_height_for_width (GtkSizeRequest *widget,
gint width,
gint *minimum_height,
gint *natural_height)
-{
- g_return_if_fail (GTK_IS_WIDGET (widget));
+{
+ GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
- GTK_SIZE_REQUEST_GET_IFACE (widget)->get_height (widget, minimum_height, natural_height);
+ /* In the unlikely case that both scrollbars are disabled; forward the child's
+ * height-for-width request via the GtkBin generic method */
+ if (scrolled_window->hscrollbar_policy == GTK_POLICY_NEVER &&
+ scrolled_window->vscrollbar_policy == GTK_POLICY_NEVER)
+ parent_size_request_iface->get_height_for_width (widget, width, minimum_height, natural_height);
+ else
+ gtk_size_request_get_height (widget, minimum_height, natural_height);
}
static void
@@ -1898,10 +1923,16 @@ gtk_scrolled_window_get_width_for_height (GtkSizeRequest *widget,
gint height,
gint *minimum_width,
gint *natural_width)
-{
- g_return_if_fail (GTK_IS_WIDGET (widget));
+{
+ GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
- GTK_SIZE_REQUEST_GET_IFACE (widget)->get_width (widget, minimum_width, natural_width);
+ /* In the unlikely case that both scrollbars are disabled; forward the child's
+ * width-for-height request via the GtkBin generic method */
+ if (scrolled_window->hscrollbar_policy == GTK_POLICY_NEVER &&
+ scrolled_window->vscrollbar_policy == GTK_POLICY_NEVER)
+ parent_size_request_iface->get_width_for_height (widget, height, minimum_width, natural_width);
+ else
+ gtk_size_request_get_width (widget, minimum_width, natural_width);
}
#define __GTK_SCROLLED_WINDOW_C__
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]