sizerequest: Split out a common function

This commit is contained in:
Benjamin Otte 2013-04-22 17:37:05 -04:00
parent 009aadf378
commit 3450388ff0
5 changed files with 38 additions and 65 deletions

View File

@ -50,6 +50,7 @@
#include "gtkintl.h" #include "gtkintl.h"
#include "gtkprivate.h" #include "gtkprivate.h"
#include "gtktypebuiltins.h" #include "gtktypebuiltins.h"
#include "gtkwidgetprivate.h"
/* Properties */ /* Properties */
enum { enum {
@ -308,25 +309,6 @@ gtk_menu_bar_get_property (GObject *object,
} }
} }
static void
get_preferred_size_for_size (GtkWidget *widget,
GtkOrientation orientation,
gint size,
gint *minimum,
gint *natural)
{
if (orientation == GTK_ORIENTATION_HORIZONTAL)
if (size < 0)
gtk_widget_get_preferred_width (widget, minimum, natural);
else
gtk_widget_get_preferred_width_for_height (widget, size, minimum, natural);
else
if (size < 0)
gtk_widget_get_preferred_height (widget, minimum, natural);
else
gtk_widget_get_preferred_height_for_width (widget, size, minimum, natural);
}
static void static void
gtk_menu_bar_size_request (GtkWidget *widget, gtk_menu_bar_size_request (GtkWidget *widget,
GtkOrientation orientation, GtkOrientation orientation,
@ -374,7 +356,7 @@ gtk_menu_bar_size_request (GtkWidget *widget,
if (gtk_widget_get_visible (child)) if (gtk_widget_get_visible (child))
{ {
get_preferred_size_for_size (child, orientation, size, &child_minimum, &child_natural); _gtk_widget_get_preferred_size_for_size (child, orientation, size, &child_minimum, &child_natural);
if (use_toggle_size) if (use_toggle_size)
{ {

View File

@ -2214,25 +2214,6 @@ gtk_notebook_get_preferred_tabs_size (GtkNotebook *notebook,
} }
} }
static void
get_preferred_size_for_size (GtkWidget *widget,
GtkOrientation orientation,
gint size,
gint *minimum,
gint *natural)
{
if (orientation == GTK_ORIENTATION_HORIZONTAL)
if (size < 0)
gtk_widget_get_preferred_width (widget, minimum, natural);
else
gtk_widget_get_preferred_width_for_height (widget, size, minimum, natural);
else
if (size < 0)
gtk_widget_get_preferred_height (widget, minimum, natural);
else
gtk_widget_get_preferred_height_for_width (widget, size, minimum, natural);
}
static void static void
get_padding_and_border (GtkNotebook *notebook, get_padding_and_border (GtkNotebook *notebook,
GtkBorder *border) GtkBorder *border)
@ -2282,11 +2263,11 @@ gtk_notebook_size_request (GtkWidget *widget,
if (gtk_widget_get_visible (page->child)) if (gtk_widget_get_visible (page->child))
{ {
vis_pages++; vis_pages++;
get_preferred_size_for_size (page->child, _gtk_widget_get_preferred_size_for_size (page->child,
orientation, orientation,
size, size,
&child_minimum, &child_minimum,
&child_natural); &child_natural);
*minimum = MAX (*minimum, child_minimum); *minimum = MAX (*minimum, child_minimum);
*natural = MAX (*natural, child_natural); *natural = MAX (*natural, child_natural);

View File

@ -35,6 +35,7 @@
#include "gtkorientableprivate.h" #include "gtkorientableprivate.h"
#include "gtkprivate.h" #include "gtkprivate.h"
#include "gtkintl.h" #include "gtkintl.h"
#include "gtkwidgetprivate.h"
#include "a11y/gtkpanedaccessible.h" #include "a11y/gtkpanedaccessible.h"
/** /**
@ -869,25 +870,6 @@ gtk_paned_finalize (GObject *object)
G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object); G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object);
} }
static void
get_preferred_size_for_size (GtkWidget *widget,
GtkOrientation orientation,
gint size,
gint *minimum,
gint *natural)
{
if (orientation == GTK_ORIENTATION_HORIZONTAL)
if (size < 0)
gtk_widget_get_preferred_width (widget, minimum, natural);
else
gtk_widget_get_preferred_width_for_height (widget, size, minimum, natural);
else
if (size < 0)
gtk_widget_get_preferred_height (widget, minimum, natural);
else
gtk_widget_get_preferred_height_for_width (widget, size, minimum, natural);
}
static void static void
gtk_paned_get_preferred_size (GtkWidget *widget, gtk_paned_get_preferred_size (GtkWidget *widget,
GtkOrientation orientation, GtkOrientation orientation,
@ -903,7 +885,7 @@ gtk_paned_get_preferred_size (GtkWidget *widget,
if (priv->child1 && gtk_widget_get_visible (priv->child1)) if (priv->child1 && gtk_widget_get_visible (priv->child1))
{ {
get_preferred_size_for_size (priv->child1, orientation, size, &child_min, &child_nat); _gtk_widget_get_preferred_size_for_size (priv->child1, orientation, size, &child_min, &child_nat);
if (priv->child1_shrink && priv->orientation == orientation) if (priv->child1_shrink && priv->orientation == orientation)
*minimum = 0; *minimum = 0;
else else
@ -913,7 +895,7 @@ gtk_paned_get_preferred_size (GtkWidget *widget,
if (priv->child2 && gtk_widget_get_visible (priv->child2)) if (priv->child2 && gtk_widget_get_visible (priv->child2))
{ {
get_preferred_size_for_size (priv->child2, orientation, size, &child_min, &child_nat); _gtk_widget_get_preferred_size_for_size (priv->child2, orientation, size, &child_min, &child_nat);
if (priv->orientation == orientation) if (priv->orientation == orientation)
{ {

View File

@ -657,3 +657,26 @@ gtk_distribute_natural_allocation (gint extra_space,
return extra_space; return extra_space;
} }
void
_gtk_widget_get_preferred_size_for_size (GtkWidget *widget,
GtkOrientation orientation,
gint size,
gint *minimum,
gint *natural)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (size >= -1);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
if (size < 0)
gtk_widget_get_preferred_width (widget, minimum, natural);
else
gtk_widget_get_preferred_width_for_height (widget, size, minimum, natural);
else
if (size < 0)
gtk_widget_get_preferred_height (widget, minimum, natural);
else
gtk_widget_get_preferred_height_for_width (widget, size, minimum, natural);
}

View File

@ -70,6 +70,11 @@ void _gtk_widget_compute_size_for_orientation (GtkWidget *widget,
gint for_size, gint for_size,
gint *minimum_size, gint *minimum_size,
gint *natural_size); gint *natural_size);
void _gtk_widget_get_preferred_size_for_size (GtkWidget *widget,
GtkOrientation orientation,
gint size,
gint *minimum,
gint *natural);
gboolean _gtk_widget_get_translation_to_window (GtkWidget *widget, gboolean _gtk_widget_get_translation_to_window (GtkWidget *widget,
GdkWindow *window, GdkWindow *window,